@useanvil/claude-code 0.9.1 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +703 -0
- package/README.md +128 -38
- package/dist/Anvil +0 -0
- package/dist/claude-approve.js +23 -0
- package/dist/claude-conditions.js +19 -12
- package/dist/claude-helpers.js +9 -9
- package/dist/claude-hook-core.js +88 -80
- package/dist/claude-hook.js +38 -37
- package/dist/claude-meter.js +52 -48
- package/dist/claude-powershell.cjs +17 -17
- package/dist/claude-sync.js +26 -26
- package/dist/cli/claude-main.js +5392 -2510
- package/docs/coding-agents/YOUR-RULES.md +507 -654
- package/package.json +1 -1
package/dist/claude-hook-core.js
CHANGED
|
@@ -1,89 +1,97 @@
|
|
|
1
|
-
import{posix as
|
|
2
|
-
`||l==="\r"){o=!0;break}s+=l,a+=2;continue}(i==="`"||e.startsWith("$(",a)||e.startsWith("${",a)||e.startsWith("<(",a)||e.startsWith(">(",a))&&(o=!0),s+=i,a++}return{delimiter:s,quoted:r,next:a,ambiguous:o}}function
|
|
3
|
-
`&&e[o]!=="\r";){let a=e[o]??"";if(a===s)return{text:r,next:o+1,closed:!0};if(s==='"'&&a==="\\"&&e[o+1]){let i=e[o+1]??"";r+=["$","`",'"',"\\"].includes(i)?i:`\\${i}`,o+=2;continue}r+=a,o++}return{text:r,next:o,closed:!1}}function
|
|
4
|
-
`;)s++;let r=s>=
|
|
5
|
-
`||
|
|
6
|
-
`?
|
|
7
|
-
`){
|
|
8
|
-
`&&e[
|
|
9
|
-
`){i+=2;continue}a
|
|
10
|
-
`){
|
|
11
|
-
`){
|
|
12
|
-
`||l==="\r")&&a.length>0){let
|
|
13
|
-
`?i+2:i+1,
|
|
14
|
-
`&&e[a+1]!=="\r";)a++;return a}function
|
|
15
|
-
`,
|
|
16
|
-
`,
|
|
17
|
-
`,i+=l==="\\"?2:1;continue}let c=
|
|
18
|
-
`],["r","\r"],["t"," "],["v","\v"],["\\","\\"],["'","'"],['"','"']]);return r.has(s)?{text:r.get(s)??s,next:t+1}:s==="x"?rs(e,t+1,n,16,2,t+1):s==="u"?rs(e,t+1,n,16,4,t+1):s==="U"?rs(e,t+1,n,16,8,t+1):/[0-7]/.test(s)?rs(e,t,n,8,3,t+1):{text:s,next:t+1}}function rs(e,t,n,s,r,o){let a=s===16?/[0-9a-fA-F]/:/[0-7]/,i="",l=t;for(;l<n&&i.length<r&&a.test(e[l]??"");)i+=e[l],l++;if(!i)return{text:e[o-1]??"",next:o};let c=Number.parseInt(i,s);return c>1114111||c>=55296&&c<=57343?{text:"\uFFFD",next:l,invalidCodePoint:c}:{text:String.fromCodePoint(c),next:l}}function ls(e,t=!1){return t?"limited":e.some(n=>n.code==="invalid-ansi-c-code-point"||n.code==="missing-heredoc-delimiter"||n.code==="ambiguous-heredoc-delimiter"||n.code==="unterminated-heredoc"||n.code==="unsupported-heredoc-context"||n.code==="unsupported-function-substitution"||n.code==="unsupported-backtick-escape"||n.code==="unclosed-parameter-expansion"||n.code==="unsupported-parameter-expansion"||n.code==="unsupported-blank")?"invalid":e.length>0?"partial":"complete"}function Pi(e,t,n,s,r){let o=ji(e,t,n);return{text:s+e.slice(t,o),provenance:$n(r,"variable"),next:o}}function $d(e,t,n){let s=gi(e),r=t,o=!1,a=!1,i=t;for(;i<n;){let l=e[i];if(l==="\\"&&!o){i+=2;continue}if(!a&&l==="'"){o=!o,i++;continue}if(!o&&l==='"'){a=!a,i++;continue}if(o){i++;continue}let c=e.startsWith("$((",i),u=e.startsWith("$(",i)&&!c,f=!a&&(e.startsWith("<(",i)||e.startsWith(">(",i)),p=l==="`";if(c||u||f||p){let d=c?3:p?1:2,h=c?"))":p?"`":")",g=Cr(e,i+d,n,h),y=g===-1?n:g+h.length;s.push(r,i,"literal"),s.push(i,y,c?"arithmetic":"command-substitution"),i=y,r=y;continue}if(l==="$"){let d=ji(e,i,n);if(d>i+1){s.push(r,i,"literal"),s.push(i,d,"variable"),i=d,r=d;continue}}if(!a&&(l==="*"||l==="?"||l==="[")){s.push(r,i,"literal"),s.push(i,i+1,"glob"),i++,r=i;continue}i++}return s.push(r,n,"literal"),s.parts}function $n(e,t){return t==="command-substitution"||e==="command-substitution"?"command-substitution":t==="arithmetic"||e==="arithmetic"?"arithmetic":t==="variable"||e==="variable"?"variable":t==="glob"||e==="glob"?"glob":e}function xd(e,t,n){return t+1>=n||xn(e[t+1]??"")||as(e,t+1)!==null}var _d=new Set(["-u","--unset","-C","--chdir","-S","--split-string","-P"]),Sd=new Set(["-u","-g","-C","-D","-h","-p","-r","-t","-T","-U"]),ki=new WeakSet,vi=256;function Cd(e){if(ki.has(e))return!1;let t=0;for(;t<=e.length;){for(;/^[A-Za-z_][A-Za-z0-9_]*=/.test(e[t]?.text??"");)t++;if(t===e.length)return!0;let n=Ad(e,t);if((n===void 0||n===null&&e[t]?.text.toLowerCase()==="command")&&ki.add(e),n==null)return!1;t=n}return!1}function Ad(e,t){let n=e[t]?.text.toLowerCase();if(n==="command")return Ed(e,t);if(n==="env")return Rd(e,t);if(n==="sudo")return Od(e,t)}function Ed(e,t){if(e[t+1]?.text==="-v")return null;for(let n=t+1;n<e.length;n++){let s=e[n]?.text??"";if(s==="--")return n+1;if(!(s==="-p"||s==="-v"||s==="-V"||/^-[pvV]+$/.test(s)))return n}return e.length}function Rd(e,t){for(let n=t+1;n<e.length;n++){let s=e[n]?.text??"";if(s==="--")return n+1;if(_d.has(s)){if(e[n+1]===void 0)return null;n++;continue}if(!(s.startsWith("-u=")||s.startsWith("--unset=")||s.startsWith("-C")&&s.length>2||s.startsWith("--chdir=")||s.startsWith("-S")&&s.length>2||s.startsWith("--split-string=")||s.startsWith("-P"))&&!(s.startsWith("-")||/^[A-Za-z_][A-Za-z0-9_]*=/.test(s)))return n}return e.length}function Od(e,t){for(let n=t+1;n<e.length;n++){let s=e[n]?.text??"";if(s==="--")return n+1;if(Sd.has(s)){if(e[n+1]===void 0)return null;n++;continue}if(!s.startsWith("-"))return n}return e.length}function jd(e,t,n,s,r){if(t.provenance!=="literal"||!t.raw.includes("{"))return;let o=Pd(t.raw,n,s,r,!1);if(!o)return;if("limited"in o)return o.limited==="expansions"?{limitCode:"depth-limit"}:{limitCode:o.limited==="length"?"brace-expansion-limit":"word-limit"};let a=o.values.map(i=>Td(i,s));if(!a.some(i=>i===null))return{words:a.filter(i=>i!==null&&i!=="").map(i=>ss(e,t.span.start,t.span.end,i,"literal",!1))}}function Pd(e,t,n,s,r){let o=[e],a=e.length,i=0;for(;;){let l=o.findIndex(d=>$i(d,r));if(l===-1)break;if(++i>n)return{limited:"expansions"};let c=o[l]??"",u=$i(c,r);if(!u||u.kind==="range")return{limited:"expansions"};let f=u.start+c.length-u.end,p=u.alternatives.reduce((d,h)=>d+f+h.length,0);if(a-c.length+p>s)return{limited:"length"};if(o.length-1+u.alternatives.length>t)return{limited:"words"};o.splice(l,1,...Wd(c,u)),a+=p-c.length}return i===0?void 0:{values:o}}function $i(e,t){let n=[],s,r=null,o=!1;for(let a=0;a<e.length;a++){let i=e[a];if(o){o=!1;continue}if(i==="\\"&&r!=="'"){o=!0;continue}if(i===r){r=null;continue}if(r===null&&(i==="'"||i==='"')){r=i;continue}if(r!==null)continue;if(i==="{"){n.push({start:a,commas:[]});continue}if(i===","&&n.length>0){n.at(-1)?.commas.push(a);continue}if(i!=="}"||n.length===0)continue;let l=n.pop();if(!l)continue;let c=l.commas.length>0?{kind:"alternatives",start:l.start,end:a+1,commas:l.commas}:t&&Ld(e.slice(l.start+1,a))?{kind:"range",start:l.start,end:a+1}:void 0;c&&(!s||c.start<s.start)&&(s=c)}return!s||s.kind==="range"?s:{kind:s.kind,start:s.start,end:s.end,alternatives:Nd(e,s)}}function Wd(e,t){return t.alternatives.map(n=>`${e.slice(0,t.start)}${n}${e.slice(t.end)}`)}function Nd(e,t){let n=[t.start,...t.commas,t.end-1];return n.slice(0,-1).map((s,r)=>e.slice(s+1,n[r+1]))}function Ld(e){return/^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(e)||/^[A-Za-z]\.\.[A-Za-z](?:\.\.-?\d+)?$/.test(e)}function Td(e,t){let n=`x${e}`,s=$r(n,0,n.length,{maxInputLength:n.length,maxWords:1,maxDepth:t},{wordsUsed:0,maxWords:1,quotedExpansionEnd:1/0},0);return s.limited||s.issues.length>0||s.next!==n.length||s.word.provenance!=="literal"?null:s.word.text.slice(1)}function Id(e,t,n,s){return{kind:"program",dialect:"posix",source:e.slice(t,n),span:{start:t,end:n},status:"limited",issues:[{code:s,message:"command structure exceeds parser limit"}],nodes:[]}}function Rt(e,t,n,s,r){return{nodes:e,issues:[...t,{code:s,message:`command structure exceeds parser limit ${r}`}],next:n,closed:!1,limited:!0,pendingHeredocs:[]}}function os(e,t,n){return{nodes:e,issues:t,next:n,closed:!1,limited:!0,pendingHeredocs:[]}}function kr(e){return e.wordsUsed++,e.wordsUsed<=e.maxWords}function Dd(e,t,n){let s=e.slice(t,n),r=/^(?:function[ \t]+)?([A-Za-z_][A-Za-z0-9_]*)[ \t]*\([ \t]*\)[ \t]*\{/.exec(s)??/^function[ \t]+([A-Za-z_][A-Za-z0-9_]*)[ \t]+\{/.exec(s),o=r?.[1];if(!(!r||!o))return{name:o,braceIndex:t+r[0].lastIndexOf("{")}}function _n(e){return e.some(t=>t.kind==="command"?t.redirections.some(n=>n.heredoc)||t.nested.some(n=>_n(n.nodes)):(t.kind==="group"||t.kind==="function")&&_n(t.body.nodes))}function Fd(e){return e.map(t=>({code:"unterminated-heredoc",message:`heredoc delimiter ${t.delimiter} was not found`}))}function Wi(e){return e?.kind==="command"||e?.kind==="group"||e?.kind==="function"}function xi(e,t){let n=e.at(-1);n?.kind!=="connector"||!_i.has(n.operator)||t.push({code:"missing-command-after-connector",message:`connector ${n.operator} requires a following command`})}function Ni(e){return e?.provenance==="literal"&&!e.quoted&&e.raw===e.text&&ld.has(e.text)}function vr(e,t){let n=e.at(-1);Wi(n)&&(n?.kind==="command"&&Ni(n.words[0])||t.push({code:"missing-command-connector",message:"adjacent commands require a connector"}))}function zd(e,t,n){return t===n||/[\s;&|()]/u.test(e[t-1]??"")}import{createRequire as Md}from"module";var Cn,Ud="Anvil's PowerShell reader (claude-powershell.cjs) is missing or won't load";function Li(){if(Cn===void 0){Cn=null;let e=Md(import.meta.url);for(let t of["./claude-powershell.cjs","../claude-powershell.cjs"])try{let n=e(t);if(typeof n.readPowerShell=="function"&&typeof n.readCmd=="function"){Cn=n;break}}catch{}}if(Cn===null)throw new Error(Ud);return Cn}function Vt(e,t){return Li().readPowerShell(e,t)}function Ti(e,t){return Li().readCmd(e,t)}import{posix as Di}from"path";var qd=null;function V(){return qd??process.platform==="win32"}var Ii=/^([A-Za-z]):(.*)$/s,Hd=/^\/(?:cygdrive\/)?([A-Za-z])(\/.*)?$/s;function Ar(e,t){let n=Di.normalize(`/${t}`);return n==="/"?e:`${e}${n.replace(/\/$/,"")}`}function Zt(e,t){return e.split("/").map(n=>{if(n===""||n==="."||n===".."||/[\u0000\u0001]/.test(n))return n;let s=n.indexOf(":"),r=s>=0?n.slice(0,s):n,o=t?r:r.replace(/[. ]+$/,"");return o===""?".":o}).join("/")}function We(e){if(!V())return e;let t=e.replace(/^(?:Microsoft\.PowerShell\.Core\\)?FileSystem::/i,""),n=!1,s=/^[\\/]{2}([?.])[\\/](.*)$/s.exec(t);if(s){let l=s[2];if(s[1]===".")return`/dev/${l.replace(/[\\/]+/g,"/").replace(/\/$/,"").toLowerCase()}`;if(/^unc[\\/]/i.test(l))t=`\\\\${l.slice(4)}`;else if(Ii.test(l))t=l;else return`/dev/${l.replace(/[\\/]+/g,"/").replace(/\/$/,"").toLowerCase()}`;n=!0}t=t.replace(/\\/g,"/");let r=/^\/\/([^/]+)(?:\/([^/]+))?(\/.*)?$/s.exec(t);if(r){let l=`/unc/${Zt(r[1],n).toLowerCase()}${r[2]?`/${Zt(r[2],n).toLowerCase()}`:""}`;return Ar(l,Zt(r[3]??"",n).toLowerCase())}let o=Ii.exec(t);if(o){let l=o[2];return l===""?`/${o[1].toLowerCase()}`:l.startsWith("/")?Ar(`/${o[1].toLowerCase()}`,Zt(l,n).toLowerCase()):null}let a=Hd.exec(t);if(a)return Ar(`/${a[1].toLowerCase()}`,Zt(a[2]??"",n).toLowerCase());let i=Zt(t,n).toLowerCase();if(i.startsWith("/")){let l=Di.normalize(i);return l.length>1&&l.endsWith("/")?l.slice(0,-1):l}return i}function Ne(e){return We(e)??e}function cs(e){return V()&&/^\/dev\/(?:nul|con|conin\$|conout\$|(?:pipe|mailslot)\/.+)$/.test(e)}function Fi(e){return/^\/[a-z]$/.test(e)||/^\/unc\/[^/]+(?:\/[^/]+)?$/.test(e)}function Je(e){if(!V())return e;let t=/^\/([a-z])(\/.*)?$/s.exec(e);if(t)return`${t[1].toUpperCase()}:${(t[2]??"/").replace(/\//g,"\\")}`;let n=/^\/unc\/(.+)$/s.exec(e);return n?`\\\\${n[1].replace(/\//g,"\\")}`:null}function Gt(e){return V()?Je(e)??e:e}function us(e){return V()?Je(e)??e:e}var Er=["windows","windows/system32","windows/syswow64","program files","program files (x86)","programdata","users","recovery","boot","perflogs","system volume information","$recycle.bin","documents and settings"],Rr=new Set(["desktop","documents","downloads","pictures","music","videos","favorites","contacts","links","saved games","searches","onedrive","appdata","3d objects","source",".ssh",".gnupg",".aws",".azure",".config",".claude",".local",".kube",".docker"]);function oe(e){return Object.assign(Object.create(null),e)}var ie="\0",le="",Bd=/\brailway\s+(variables|variable|vars)\b|\bheroku\s+config\b|\bdoppler\s+secrets\b|\bop\s+read\b|\baws\s+secretsmanager\b|\bgcloud\s+secrets\b|\bvault\s+(kv\s+get|read)\b/,Pe="\0$OLDPWD",Wr=8,Vd=32,Zd=8,Gd=16,Kd=64,Yt=new Set(["bash","sh","zsh","dash","ksh","fish","ash","csh","tcsh","mksh","yash"]);function ys(e,t,n){for(let s=0;e.deferred.length>0;s++){if(s>=Vd){e.bodyRead||(e.depthLimit.hit=!0),e.deferred.length=0;break}let r=e.deferred.shift();fe(r.code,{...e,vars:new Map(e.vars),cwd:Pe,depth:e.depth+1,via:"shell-string",captured:!1,frames:[],outerGuards:r.parent.guards,andGuards:[],parent:r.parent,errexit:r.errexit},t,n)}}var Yd=new Set([":",".","eval","exec","exit","export","readonly","return","set","shift","trap","unset","break","continue","times"]),zi=new Set(["sh","dash","ksh","ash","mksh","yash"]),zr=/^([0-9]+|[@*#])$/,Xi=new Set(["do","then","else","elif","if","while","until","!","{","(","time"]),Jd=new Set(["done","fi","esac","}",")","in","case",";;"]),Xd=new Set(["sudo","doas","pkexec","run0","env","nohup","time","nice","ionice","timeout","gtimeout","command","builtin","exec","caffeinate","stdbuf","unbuffer","chronic","script","npx","pnpx","bunx","uv","uvx","pipx","busybox","bundle","poetry","pdm","rye","op","doppler","infisical","dotenvx","dotenv","sshpass","aws-vault","cross-env","setsid","sandbox-exec","flock","taskset","chrt","prlimit","unshare","systemd-inhibit","launchctl"]),Qi=new Set(["-w","--timeout","-E","--conflict-exit-code"]),Qd=new Set(["npx","pnpx","bunx","uv","uvx","pipx"]),ef=oe({"eas-cli":"eas","expo-cli":"expo","@expo/cli":"expo","netlify-cli":"netlify","firebase-tools":"firebase","@railway/cli":"railway",localtunnel:"lt","@anthropic-ai/claude-code":"claude","@useanvil/sdk":"anvil","@useanvil/claude-code":"anvil-claude","@openai/codex":"codex","@google/gemini-cli":"gemini","appcenter-cli":"appcenter","snowflake-cli":"snow","snowflake-cli-labs":"snow","databricks-cli":"databricks","@ngrok/ngrok":"ngrok","@capgo/cli":"capgo","@smithery/cli":"smithery","@github/copilot":"copilot","@qwen-code/qwen-code":"qwen","chrome-webstore-upload-cli":"chrome-webstore-upload"});function bs(e){let t=new Set(["-w","--workspace","--filter","-F","-C","--dir","--prefix","--cwd","--recursive-filter"]),n=1;for(;n<e.length&&e[n].startsWith("-");)n+=t.has(e[n])?2:1;return e[0]!==void 0&&/(^|\/)yarn$/.test(e[0])&&e[n]==="workspace"&&(n+=2),{sub:e[n]??"",at:n}}function Mi(e){let t=/^((?:@[^/@\s]+\/)?[^@\s=/]+)(?:@[^\s/]*|==[^\s]*)$/.exec(e),n=t?t[1]:e;return ef[n]??n}var tf=new Set(["python","python3","node","ruby","perl","php","bun","deno","tsx","ts-node"]);function fe(e,t,n,s){let r=_r(e,yr);r.status==="limited"&&!t.bodyRead&&(t.depthLimit.hit=!0),Pt(r,t,n,s)}function dt(e,t){let n=[],s=_r(e,yr),r={vars:new Map,functions:new Map,called:new Set,cwd:t.cwd,depth:0,via:"top",remote:null,productionEnv:!1,captured:!1,frames:[],outerGuards:[],andGuards:[],cds:[],cdpath:!1,errexit:!1,ifs:null,posixOnly:!1,maybeRuns:!1,partial:s.status!=="complete",subshell:!1,inFunction:!1,newProcess:!1,deferred:[],locals:new Set,files:new Map(Object.entries(t.knownFiles??{})),loopBudget:{left:Kd},depthLimit:{hit:!1},parent:null,oldCwd:Pe,dirStack:[]};Pt(s,r,t,n);for(let[o,a]of r.functions)r.called.has(o)||Pt(a,{...r,vars:new Map(r.vars),depth:1,via:"shell-string",captured:!1,frames:[],andGuards:[]},t,n);return ys(r,t,n),{commands:n,status:r.depthLimit.hit?"limited":s.status}}function et(e){let t=[...e.outerGuards];for(let n of e.frames)n.phase!=="body"||n.negate||(n.kind==="case"?t.push(`case ${n.word??""} in ${n.pattern??""}`):t.push(...n.cond));return[...t,...e.andGuards]}var Nr=class{passed=[];joiner=null;open=!1;text=null;exits=!1;beforeOr=[];orExits=!1;runPassed=[];get afterOr(){return this.joiner==="||"}get joined(){return this.joiner!==null}start(){this.close(),this.runPassed=this.joiner==="&&"?this.passed:[],this.open=!0,this.text=null,this.exits=!1}set(t,n=!1){this.text=t,this.exits=n}extend(t){this.text=this.text!==null&&t!==null?`${this.text} | ${t}`:null,this.exits=!1}join(t){this.close(),t==="||"&&(this.beforeOr=this.passed),this.joiner=t}end(){this.close();let t={passed:this.passed,past:this.orExits?this.beforeOr:[],lone:this.elements===1&&this.lastText!==null&&!this.lastText.startsWith("! ")?this.lastText:null};return this.passed=[],this.beforeOr=[],this.orExits=!1,this.elements=0,this.joiner=null,t}elements=0;lastText=null;close(){if(!this.open)return;let t=this.text;this.elements++,this.lastText=t,this.joiner==="&&"?(t!==null&&(this.passed=[...this.passed,t]),this.orExits=!1):this.joiner==="||"?(this.passed=[],this.orExits=this.exits):(this.passed=t===null?[]:[t],this.orExits=!1),this.open=!1,this.joiner=null}};function nf(e){return e!==null&&(e.name==="exit"||e.name==="return")&&e.wrappers.length===0&&e.argv.length<=2&&e.via!=="xargs"}function sf(e){for(let t of e.words){if(t.provenance!=="literal"||t.quoted||!Xi.has(t.text))return!1;if(t.text==="!")return!0}return!1}function ut(e,t){for(let n=e.frames.length-1;n>=0;n--)if(e.frames[n].kind===t)return e.frames[n]}function ps(e,t){for(let n=e.frames.length-1;n>=0;n--)if(e.frames[n].kind===t){e.closed=e.frames[n],e.frames.splice(n,1);return}}function ea(e){let t=[];for(let n=e;n&&t.length<8;n=n.pipeFrom)t.push(n.text);return t.reverse().join(" | ")}function rf(e,t,n,s){let r=e[t];if(r.kind!=="command")return null;let o=r.words;if(!o[0]||o[0].text!=="for"||o[0].provenance!=="literal"||o[0].quoted)return null;let a=o[1]?.text,i=o.findIndex(x=>x.text==="in"&&x.provenance==="literal"),l=i>0?o.slice(i+1):[],c=l.length===1&&l[0].provenance==="command-substitution"?/^\$\(\s*(?:echo|printf)\s+([\w./ -]+?)\s*\)$/.exec(l[0].raw)?.[1]:void 0,u=x=>x.provenance==="literal"||x.provenance==="glob",f=x=>u(x)||/^"[^"`]*"$/.test(x.raw)&&!/\$\{?[@*]|\[[@*]\]/.test(x.raw)&&!S(Ee(x,n,s).text);if(!a||!/^[A-Za-z_][A-Za-z0-9_]*$/.test(a)||l.length===0||!c&&!l.every(f))return null;let p=-1,d=0,h=-1;for(let x=t+1;x<e.length;x++){let b=e[x];if(b.kind!=="command")continue;let j=b.words[0];if(!(!j||j.provenance!=="literal"||j.quoted)){if(p<0){if(j.text==="do"&&b.words.length===1)p=x;else if(j.text!=="do")return null;continue}if(["for","while","until","select"].includes(j.text)&&d++,j.text==="done"){if(d===0){h=x;break}d--}}}if(p<0||h<0)return null;let g=c?c.split(/\s+/).filter(Boolean):l.map(x=>u(x)?x.text:Ee(x,n,s).text),y=ia(n,aa(l.map(x=>x.raw).join(" "))),$=g.map((x,b)=>{let j=l[b];return y.length===0||c||!j||u(j)?[]:[...new Set(y.map(C=>Ee(j,{...n,vars:C},s).text))].filter(C=>C!==x)}),E=Math.min(g.length,Gd,n.loopBudget.left);return E<=0?null:(n.loopBudget.left-=E,{name:a,values:g.slice(0,E),alts:$.slice(0,E),truncated:E<g.length,body:e.slice(p+1,h),end:h})}function of(e,t){let n=0;for(let s=t;s<e.length;s++){let r=e[s];if(r.kind!=="command")continue;let o=r.words[0];if(!(!o||o.provenance!=="literal"||o.quoted)&&(["while","until","for","select"].includes(o.text)&&n++,o.text==="done")){if(n>0){n--;continue}let a=r.redirections.find(c=>(c.operator==="<"||c.operator==="<<<")&&c.target);if(!a||!a.target)return null;let i=a.target.raw.replace(/^"|"$/g,""),l=/^(?:<\(|\$\()([\s\S]*)\)$/.exec(i);return l?l[1]:a.operator==="<"?`cat ${i}`:i}}return null}function Ui(e,t,n,s,r){let o=e.words,a=0;for(;a<o.length&&o[a].provenance==="literal"&&!o[a].quoted;){let i=o[a].text;if(i==="if")t.frames.push({kind:"if",phase:"cond",cond:[],negate:!1});else if(i==="while"||i==="until")t.frames.push({kind:"loop",phase:"cond",cond:[],negate:i==="until",input:r?ea(r):of(n,s+1)});else if(i==="then"){let l=ut(t,"if");l&&(l.phase="body")}else if(i==="elif"){let l=ut(t,"if");l&&Object.assign(l,{phase:"cond",cond:[],negate:!1})}else if(i==="else"){let l=ut(t,"if");l&&(l.phase="else")}else if(i==="fi")ps(t,"if");else if(i==="do"){let l=ut(t,"loop");l&&(l.phase="body")}else if(i==="done")ps(t,"loop");else if(i==="esac")ps(t,"case");else if(i==="!"&&t.frames.length&&t.frames[t.frames.length-1].phase==="cond")t.frames[t.frames.length-1].negate=!0;else if(!["{","}","(",")","time"].includes(i))break;a++}return a>0&&a===o.length}var ds=new WeakMap;function Pt(e,t,n,s){if(t.depth>Wr){t.bodyRead||(t.depthLimit.hit=!0);return}let r=null,o=[],a=!1,i=t.andGuards,l=t.maybeRuns,c=t.subshell,u=new Nr,f=[],p=C=>C.length<=t.frames.length&&C.every(([A,U],I)=>t.frames[I]===A&&A.phase===U),d=new Set,h=C=>{for(let A=C;A<t.frames.length;A++)d.add(t.frames[A])},g=()=>{u.start();let C=t.frames[t.frames.length-1];C&&C.phase==="cond"&&d.has(C)&&(C.cond=[])},y=()=>{t.andGuards=[...i,...f.filter(C=>p(C.at)).map(C=>C.text),...u.runPassed]},$=()=>{t.andGuards=i},E=0,x=!1,b=null,j=t.posixOnly?e.nodes:af(e.nodes);for(let C=0;C<j.length;C++){let A=j[C],U=x;x=!1;let I=b;b=null;for(let H of t.frames)ds.has(H)||ds.set(H,s.length);if(A.kind==="command"&&A.words.length===1&&A.words[0].text==="!"&&A.words[0].provenance==="literal"&&!A.words[0].quoted){let H=t.frames.length;Ui(A,t,j,C,null),h(H),x=!0;continue}if(A.kind==="connector"){if(a=A.operator==="|"||A.operator==="|&",A.operator==="&")for(let H of o)H.background=!0;if(!a)if(r=null,A.operator==="&&"||A.operator==="||")u.join(A.operator);else{let H=u.end(),Z=t.frames[t.frames.length-1];Z&&Z.phase==="cond"&&d.has(Z)&&(Z.cond=[...H.passed]);let ge=t.frames.map(L=>[L,L.phase]),ne=t.frames.some(L=>L.phase==="cond"),ee=t.errexit&&!ne&&H.lone!==null?[H.lone]:[];A.operator!=="&"&&(f=[...f,...[...H.past,...ee].map(L=>({text:L,at:ge}))])}if(E=A.operator===";"?E+1:0,E>=2){let H=ut(t,"case");H&&Object.assign(H,{phase:"pattern",pattern:""})}continue}E=0;let D=ut(t,"case");if(A.kind!=="command"&&D&&D.phase==="pattern"){D.phase="body";continue}if(A.kind==="group"){let H=e.source.slice(A.span.start-e.span.start,A.span.end-e.span.start);if(H.startsWith("(("))for(let F of H.matchAll(/(?<![A-Za-z0-9_])([A-Za-z_][A-Za-z0-9_]*)\s*(?:[-+*\/%&|^]|<<|>>)?=(?!=)|(?<![A-Za-z0-9_])([A-Za-z_][A-Za-z0-9_]*)\s*(?:\+\+|--)|(?:\+\+|--)\s*([A-Za-z_][A-Za-z0-9_]*)/g))Xe(t,F[1]??F[2]??F[3],{kind:"unknown"});a||g(),y();let Z=A.style==="subshell"?{...t,vars:new Map(t.vars),functions:new Map(t.functions),outerGuards:et(t),frames:[],andGuards:[],deferred:[]}:t,ge=s.length,ne=j[C+1];Z.maybeRuns=l||u.afterOr||a||ne?.kind==="connector"&&["|","|&","&"].includes(ne.operator),Pt(A.body,Z,n,s),Z!==t&&ys(Z,n,s),Z.maybeRuns=l,o=s.slice(ge);let ee=j[C+1];if(ee?.kind==="command"&&ee.words.length===0&&ee.redirections.some(lf)){let F=new Set(o),gr=new Set(o.map(we=>we.parent)),mr=we=>{for(let je=we;je&&F.has(je);je=je.parent)if(je.captured||je.pipeTo!==null||je.redirects.some(Y=>fs(Y))||Pr.has(je))return!0;return!1};b=o.some(we=>we.name==="exec"&&we.redirects.some(je=>fs(je)))||na(A.body)?[]:o.filter(we=>!gr.has(we)&&!mr(we));for(let we of b)Pr.add(we)}else if(ee?.kind==="command"&&ee.words.length===0&&ee.redirections.some(hs)||ee?.kind==="connector"&&(ee.operator==="|"||ee.operator==="|&"))for(let F of o)Pr.add(F);let L=ee?.kind==="command"&&ee.words.length===0?ee.redirections.find(F=>(F.operator==="<"||F.operator==="<>")&&(F.fd===void 0||F.fd===0)&&F.target):void 0;L?.target&&sa(o,Ee(L.target,t,n).text),$(),a?u.extend(null):u.set(null),r=null,a=!1;continue}if(A.kind==="function"){t.functions.set(A.name,A.body);let H=ws.get(t.functions)??new Set;ws.set(t.functions,H);let Z=j[C+1],ge=a||Z?.kind==="connector"&&["&","|","|&"].includes(Z.operator);t.depth===0&&!t.subshell&&!t.maybeRuns&&!u.joined&&!ge&&t.frames.length===0&&et(t).length===0?H.add(A.name):H.delete(A.name),a||g(),u.set(null),r=null,a=!1;continue}if(A.kind!=="command")continue;let z=rf(j,C,t,n);if(z){a||g(),y();let H=[...z.values.map(ne=>({kind:"value",value:ne})),...z.truncated?[{kind:"unknown"}]:[]],Z=s.length;for(let[ne,ee]of H.entries())t.vars.set(z.name,ee),Ir(ee,z.alts[ne]??[]),t.frames.push({kind:"loop",phase:"body",cond:[],negate:!1}),Pt({...e,nodes:z.body},{...t},n,s),ps(t,"loop");!z.truncated&&z.values.length>1&&t.vars.set(z.name,Ir({kind:"value",value:z.values.at(-1)},[...z.values.slice(0,-1),...z.alts.flat()]));let ge=j[z.end];if(ge?.kind==="command"&&ge.words[0]?.text==="done"&&ge.redirections.some(hs)){let ne=s.slice(Z).filter(ee=>!ee.captured&&ee.pipeTo===null&&!ee.redirects.some(L=>fs(L)));gs({...ge,words:[]},t,n,s,null,ne)}$(),u.set(null),C=z.end,r=null,a=!1;continue}let B=A.words[0];if(B&&B.text==="case"&&B.provenance==="literal"&&!B.quoted){let H=A.words[1]?Ee(A.words[1],t,n).text:"",Z=A.words.slice(3).map(ee=>Ee(ee,t,n).text).join(" "),ge=j[C+1],ne=ge?.kind==="connector"&&ge.operator==="|";t.frames.push({kind:"case",phase:Z&&!ne?"body":"pattern",cond:[],negate:!1,word:H,pattern:Z}),h(t.frames.length-1),Z&&!ne&&ge&&ge.kind!=="command"&&C++,a||g(),u.set(null),r=null,a=!1;continue}if(D&&D.phase==="pattern"&&!(B&&B.text==="esac")){let H=A.words.map(Z=>Ee(Z,t,n).text).join(" ");D.pattern=D.pattern?`${D.pattern}|${H}`:H,a=!1,r=null;continue}let Q=t.frames.length;t.closed=null;let ce=Ui(A,t,j,C,a?r:null);if(h(Q),ce){let H=t.closed,Z=H?s.slice(ds.get(H)??s.length):null;if(H&&A.redirections.some(hs)){let ge=s.slice(ds.get(H)??s.length).filter(ne=>!ne.captured&&ne.pipeTo===null&&!ne.redirects.some(ee=>fs(ee)));gs({...A,words:[]},t,n,s,null,ge)}a||g(),u.set(null),a=!1,r=null,Z&&(o=Z);continue}a||g(),y();let te=t.frames.length,ze=j[C+1],Oe=a||ze?.kind==="connector"&&["|","|&","&"].includes(ze.operator);t.maybeRuns=l||u.afterOr||Oe,t.subshell=c||Oe;let K=gs(A,t,n,s,a?r:null,I);t.maybeRuns=l,t.subshell=c,h(te),$();let Ye=U||sf(A),Me=K?`${Ye?"! ":""}${Rn(K)}`:null;a?u.extend(Me):u.set(Me,!Ye&&nf(K)),r=K??r,o=K?[K]:[],a=!1}}function ta(e,t,n){let s=new Set;for(let r of e.cds){let o=r.to===null?s.size>0?[Pe]:[]:"abs"in r.to?[]:[...s].map(a=>M(r.to.rel,a,n));s=new Set(t.includes(r.text)?o:[r.before,...s,...o]);for(let a of r.extra??[])s.add(a);s.size>8&&(s=new Set([Pe]))}return s.delete(e.cwd),[...s]}function Or(e,t,n){if(!t.subshell)for(let[s,r]of e.vars){if(zr.test(s)||e.locals.has(s)||n.get(s)===r)continue;let o={...r},a=t.vars.get(s)??null;t.vars.set(s,o),Qe.set(o,{at:t.frames.map(i=>[i,i.phase]),guards:et(t),maybe:!0,prev:a})}}function jr(e,t){t.cwd=e.cwd,t.oldCwd=e.oldCwd,t.dirStack=e.dirStack,t.cds=e.cds,t.cdpath=e.cdpath}function af(e){let t=[];for(let n=0;n<e.length;n++){let s=e[n],r=e[n+1],o=e[n+2],a=s.kind==="command"&&["done","fi","esac"].includes(s.words[0]?.text??"");if((s.kind==="command"||s.kind==="group")&&!a&&r?.kind==="connector"&&r.operator==="&"&&o?.kind==="command"&&o.words.length===0&&r.span.end===o.span.start&&o.source.startsWith(">")){s.kind==="command"?t.push({...s,source:`${s.source} &${o.source}`,redirections:[...s.redirections,...o.redirections]}):t.push(s,o),n+=2;continue}t.push(s)}return t}function hs(e){return e.fd===1||e.fd===void 0&&[">",">>",">|",">&"].includes(e.operator)}function na(e){return e.nodes.some(t=>t.kind==="command"&&["done","fi","esac"].includes(t.words[0]?.text??"")&&t.redirections.some(hs)||t.kind==="group"&&na(t.body))}function sa(e,t){for(let n of e)n.stdinFile===null&&n.stdin===null&&n.pipeFrom===null&&!n.captured&&(n.stdinFile=t)}function lf(e){return(e.operator===">"||e.operator===">>"||e.operator===">|")&&(e.fd===void 0||e.fd===1)}function fs(e){return e.fd===1||e.fd===null&&(e.op===">"||e.op===">>"||e.op===">|"||e.op===">&")}var Pr=new WeakSet;function Rn(e){return e.argv.map(k).join(" ")}function gs(e,t,n,s,r,o=null){for(let w of e.nested){let _={...t,vars:new Map(t.vars),depth:t.depth+1,via:"substitution",captured:!0,frames:[],outerGuards:et(t),andGuards:[],errexit:!1,deferred:[]};Pt(w,_,n,s),ys(_,n,s)}let a=[...e.words];for(;a.length&&Xi.has(a[0].text)&&a[0].provenance==="literal"&&!a[0].quoted;)a.shift();if(a.length&&Jd.has(a[0].text)&&a.length===1)return null;if(a[0]?.text==="for"||a[0]?.text==="select"){t.frames.push({kind:"loop",phase:"header",cond:[],negate:!1});let w=a[1]?.text,_=a.slice(a.findIndex(N=>N.text==="in")+1);w&&t.vars.set(w,_.length>0&&a.some(N=>N.text==="in")&&_.some(N=>N.provenance==="command-substitution")?{kind:"value",value:`${ie}${_.map(N=>Fr(N.raw,t,n)).join(" ")}${le}`}:_.length>0&&_.every(N=>N.provenance==="literal"||N.provenance==="glob")?{kind:"list",values:_.map(N=>N.text)}:{kind:"unknown"});let O=a.findIndex((N,W)=>W>1&&N.text==="do"&&N.provenance==="literal"&&!N.quoted);if(O>0&&O<a.length-1){let N=ut(t,"loop");return N&&(N.phase="body"),gs({...e,words:a.slice(O+1)},t,n,s,null)}return null}let i=a.findIndex(w=>!/^[A-Za-z_][A-Za-z0-9_]*=/.test(w.raw)&&w.text!=="command"&&w.text!=="builtin");if(i>0&&["read","mapfile","readarray"].includes(a[i].text)&&(a=[...a.slice(i)]),(a[0]?.text==="mapfile"||a[0]?.text==="readarray")&&a[0].provenance==="literal"){let w=a.slice(1).filter((_,O,N)=>!_.text.startsWith("-")&&!["-d","-n","-O","-s","-u","-C","-c"].includes(N[O-1]?.text??"")).pop()?.text??"MAPFILE";/^[A-Za-z_][A-Za-z0-9_]*$/.test(w)&&Xe(t,w,{kind:"unknown"})}if(a[0]?.text==="read"&&a[0].provenance==="literal"){let w=ut(t,"loop"),_=w&&w.phase==="cond"?w.input??null:null,O=e.redirections.find(G=>G.operator==="<"&&G.target),N=e.redirections.find(G=>G.operator==="<<<"&&G.target),W=r?ea(r):O?.target?`cat ${Ee(O.target,t,n).text}`:N?.target?k(Ee(N.target,t,n).text):_,q=new Set(["-p","-d","-n","-N","-t","-u","-i"]);for(let G=1;G<a.length;G++){let J=a[G].text;if(q.has(J)){G++;continue}J==="-a"||J.startsWith("-")||/^[A-Za-z_][A-Za-z0-9_]*$/.test(J)&&t.vars.set(J,W?{kind:"value",value:`${ie}$(${W})${le}`}:{kind:"unknown"})}}let l=0,c=[],u=new Set;for(;l<a.length&&/^[A-Za-z_][A-Za-z0-9_]*\+?=/.test(a[l].raw);){let w=a[l],_=w.raw.indexOf("=");w.raw[_-1]==="+"&&u.add(w),c.push([w.raw.slice(0,w.raw[_-1]==="+"?_-1:_),w]),l++}let f=a[l];if(f?.text==="getopts"&&a[l+2]&&Xe(t,a[l+2].text,{kind:"unknown"}),f?.text==="let"||f?.raw.startsWith("(("))for(let w of a.slice(l))for(let _ of w.raw.matchAll(/(?<![A-Za-z0-9_])([A-Za-z_][A-Za-z0-9_]*)\s*(?:[-+*\/%&|^]|<<|>>)?=(?!=)|(?<![A-Za-z0-9_])([A-Za-z_][A-Za-z0-9_]*)\s*(?:\+\+|--)|(?:\+\+|--)\s*([A-Za-z_][A-Za-z0-9_]*)/g))Xe(t,_[1]??_[2]??_[3],{kind:"unknown"});let p=a.slice(l);if(p.length&&["export","local","declare","readonly","typeset"].includes(p[0].text)){let w=p[0].text,_=p.slice(1).filter(W=>W.text.startsWith("-")).map(W=>W.text),O=t.inFunction&&(w==="local"||(w==="declare"||w==="typeset")&&!_.some(W=>W.includes("g"))),N=_.some(W=>/^-[a-zA-Z]*n/.test(W));for(let W of p.slice(1)){let q=/^([A-Za-z_][A-Za-z0-9_]*)(=|$)/.exec(W.text);q&&(O&&t.locals.add(q[1]),N?Xe(t,q[1],{kind:"unknown"}):q[2]==="="&&c.push([q[1],W]))}p=[]}let d=t.productionEnv,h=[];for(let[w,_]of c){let O=Cf(_,w,t,n),N=t.vars.get(w),W=u.has(_)?N?.kind==="value"&&O.kind==="value"?{kind:"value",value:N.value+O.value}:{kind:"unknown"}:O;if(p.length>0){W.production&&(d=!0),h.push([w,W]);continue}Xe(t,w,W),w==="OLDPWD"&&p.length===0&&(t.oldCwd=W.kind==="value"&&!S(W.value)?W.value:Pe),w==="CDPATH"&&p.length===0&&(t.cdpath=!(W.kind==="value"&&W.value==="")),w==="IFS"&&p.length===0&&(t.ifs=W.kind==="value"&&W.value!==""&&!S(W.value)?W.value:null)}if(p.length===0&&c.length===0&&e.redirections.length>0&&(p=[{kind:"word",text:":",raw:":",span:e.span,provenance:"literal",quoted:!1,parts:[]}]),p.length===0)return null;let g=p.map(w=>Ee(w,t,n)),y=t.ifs??`
|
|
19
|
-
|
|
20
|
-
`);for(let
|
|
21
|
-
`)):
|
|
22
|
-
`):
|
|
23
|
-
`)}if(e.name==="base64"&&e.argv.some(
|
|
24
|
-
`):null}function
|
|
25
|
-
`||o==="\r"){r++;continue}o==="|"&&
|
|
1
|
+
import{posix as Ut}from"path";import m0 from"vm";import{isMainThread as lp,parentPort as io,workerData as Kn}from"worker_threads";import{createHash as Eu}from"crypto";import{posix as O}from"path";function fp(e){return(typeof e=="string"?e:"").trim().replace(/\/+$/,"")}function wa(e){try{let n=new URL(fp(e)).hostname.toLowerCase().replace(/^\[|\]$/g,"");return n==="localhost"||n.endsWith(".localhost")||n==="::1"||/^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(n)}catch{return!1}}import{posix as Le}from"path";import{posix as ss}from"path";var lo=Object.freeze({maxInputLength:131072,maxWords:16384,maxDepth:64});function ka(){return{words:[],redirections:[],nested:[],start:-1,end:-1,reset(){this.words=[],this.redirections=[],this.nested=[],this.start=-1,this.end=-1}}}function va(e,n,t){e.push(t),n.reset()}function $a(e){let n=[];return{parts:n,push:(t,s,r)=>{s<=t||n.push({raw:e.slice(t,s),span:{start:t,end:s},provenance:r})}}}function pp(e){let n=e.parts??[{raw:e.raw,span:e.span,provenance:e.provenance}];return{kind:"word",...e,parts:n}}function qs(e,n,t,s,r,o,a){return pp({text:s,raw:e.slice(n,t),span:{start:n,end:t},provenance:r,quoted:o,...a?{parts:a}:{}})}function co(e,n,t){if(n>=t||_a(e[n]??""))return null;let s="",r=!1,o=!1,a=n;for(;a<t&&!_a(e[a]??"");){let i=e[a]??"";if(i==="'"){r=!0;let l=xa(e,a+1,t,"'");s+=l.text,o||=!l.closed,a=l.next;continue}if(i==='"'){r=!0;let l=xa(e,a+1,t,'"');s+=l.text,o||=!l.closed,a=l.next;continue}if(i==="\\"){r=!0;let l=e[a+1];if(!l||l===`
|
|
2
|
+
`||l==="\r"){o=!0;break}s+=l,a+=2;continue}(i==="`"||e.startsWith("$(",a)||e.startsWith("${",a)||e.startsWith("<(",a)||e.startsWith(">(",a))&&(o=!0),s+=i,a++}return{delimiter:s,quoted:r,next:a,ambiguous:o}}function uo(e,n,t,s){let r=[],o=n;for(let a of s){let i=o,l=!1;for(;o<t;){let c=hp(e,o,t);if((a.stripTabs?c.text.replace(/^\t+/,""):c.text)===a.delimiter){a.attach({body:a.stripTabs?gp(e.slice(i,o)):e.slice(i,o),delimiter:a.delimiter,quotedDelimiter:a.quotedDelimiter,bodySpan:{start:i,end:o},terminatorSpan:{start:o,end:c.contentEnd}}),o=c.next,l=!0;break}if(c.next<=o)break;o=c.next}if(!l)return r.push({code:"unterminated-heredoc",message:`heredoc delimiter ${a.delimiter} was not found`}),{next:t,issues:r,terminated:!1}}return{next:o,issues:r,terminated:!0}}function xa(e,n,t,s){let r="",o=n;for(;o<t&&e[o]!==`
|
|
3
|
+
`&&e[o]!=="\r";){let a=e[o]??"";if(a===s)return{text:r,next:o+1,closed:!0};if(s==='"'&&a==="\\"&&e[o+1]){let i=e[o+1]??"";r+=["$","`",'"',"\\"].includes(i)?i:`\\${i}`,o+=2;continue}r+=a,o++}return{text:r,next:o,closed:!1}}function _a(e){return e!=="\r"&&(/[\s;&|<>)]/u.test(e)||e==="`")}function hp(e,n,t){let s=n;for(;s<t&&e[s]!==`
|
|
4
|
+
`;)s++;let r=s>=t?t:s+1;return{text:e.slice(n,s),contentEnd:s,next:r}}function gp(e){return e.replace(/(^|\r\n?|\n)\t+/g,"$1")}var ja=new Set(["&&","||","|","|&"]),mp=new Set(["!","do","elif","else","if","then","until","while"]);function mo(e,n){let t={start:0,end:e.length};if(e.length>n.maxInputLength)return{kind:"program",dialect:"posix",source:e,span:t,status:"limited",issues:[{code:"input-limit",message:`command exceeds ${n.maxInputLength} UTF-16 code units`}],nodes:[]};let s={wordsUsed:0,maxWords:n.maxWords,quotedExpansionEnd:1/0},r=Vs(e,0,e.length,n,s,0),o=[...r.issues,...Cp(e,s.quotedExpansionEnd,r.nodes)?[La]:[],..._p.test(e)?[Na]:[]];return{kind:"program",dialect:"posix",source:e,span:t,status:Zs(o,r.limited),issues:o,nodes:r.nodes}}function Vs(e,n,t,s,r,o,a){let i=[],l=[],c=ka(),u=[],p=()=>{if(c.words.length===0&&c.redirections.length===0)return;let f={start:c.start,end:c.end},h=c.words.map(g=>g.text);va(i,c,{kind:"command",dialect:"posix",source:e.slice(f.start,f.end),span:f,words:c.words,redirections:c.redirections,nested:c.nested,displayText:l.length>0&&i.length===0?e.slice(n,t):h.join(" ")})},d=n;for(;d<t;){let f=e[d];if(!f)break;if(a&&f===a)return p(),Oa(i,l),{nodes:i,issues:l,next:d+1,closed:!0,limited:!1,pendingHeredocs:u};if(Jn(f)){if(f.charCodeAt(0)>127&&l.push(Na),f===`
|
|
5
|
+
`||f==="\r"){p();let v=f==="\r"&&e[d+1]===`
|
|
6
|
+
`?d+2:d+1,C=i.at(-1);if((C?.kind!=="connector"||!ja.has(C.operator))&&i.push({kind:"connector",operator:e.slice(d,v),span:{start:d,end:v}}),u.length>0){let N=uo(e,v,t,u.splice(0));l.push(...N.issues),d=N.next;continue}d=v;continue}d++;continue}if(f==="\\"&&e[d+1]===`
|
|
7
|
+
`){d+=2;continue}if(f==="#"){for(;d<t&&e[d]!==`
|
|
8
|
+
`&&e[d]!=="\r";)d++;continue}let h=c.start===-1?Vp(e,d,t):void 0;if(h){if(po(i,l),o>=s.maxDepth)return qt(i,l,d,"depth-limit",s.maxDepth);if(!fo(r))return qt(i,l,d,"word-limit",s.maxWords);let v=Vs(e,h.braceIndex+1,t,s,r,o+1,"}"),C=v.next,N={start:h.braceIndex+1,end:v.closed?C-1:C},q=Sa(e,N,v);if(i.push({kind:"function",name:h.name,span:{start:d,end:C},body:q}),l.push(...v.issues),(v.pendingHeredocs.length>0||Xn(v.nodes))&&l.push({code:"unsupported-heredoc-context",message:"heredocs attached inside function bodies are not supported safely"}),u.push(...v.pendingHeredocs),v.limited)return Bs(i,l,v.next);v.closed||l.push({code:"unclosed-function-body",message:"function body is not closed"}),d=C;continue}let g=Gs(e,d);if(g){p(),Ma(i.at(-1))||l.push({code:"unexpected-connector",message:`connector ${g} has no preceding command`}),i.push({kind:"connector",operator:g,span:{start:d,end:d+g.length}}),d+=g.length;continue}if(f===")"){p(),l.push({code:"unexpected-closing-delimiter",message:"closing parenthesis has no matching opening parenthesis"}),i.push({kind:"unknown",source:f,span:{start:d,end:d+1}}),d++;continue}if((f==="("||f==="{"&&jp(e,d,t))&&c.start===-1){if(po(i,l),o>=s.maxDepth)return qt(i,l,d,"depth-limit",s.maxDepth);let v=f==="("?")":"}",C=Vs(e,d+1,t,s,r,o+1,v),N=C.next,q={start:d+1,end:C.closed?N-1:N},B=Sa(e,q,C);if(i.push({kind:"group",style:f==="("?"subshell":"brace",span:{start:d,end:N},body:B}),l.push(...C.issues),(C.pendingHeredocs.length>0||Xn(C.nodes))&&l.push({code:"unsupported-heredoc-context",message:"heredocs attached inside command groups are not supported safely"}),u.push(...C.pendingHeredocs),C.limited)return Bs(i,l,C.next);C.closed||l.push({code:f==="("?"unclosed-subshell":"unclosed-brace-group",message:`${f} group is not closed`}),d=N;continue}let b=(f==="<"||f===">")&&e[d+1]!=="("?kp(e,d):null;if(b){let v=c.words.at(-1),C=v&&v.span.end===d&&/^[0-9]+$/.test(v.raw)?Number(v.raw):void 0;C!==void 0&&c.words.pop();let N=C===void 0?d:v?.span.start??d;c.start=c.start===-1?d:c.start;let q=d+b.length;for(;q<t&&/[ \t]/.test(e[q]??"");)q++;let B=e[q],V=q>d+b.length&&B==="#",F=!B||Jn(B)||!!Gs(e,q)||B===a||B===")"||V||(B==="<"||B===">")&&e[q+1]!=="(",U=b==="<<"||b==="<<-",X=U?co(e,q,t):void 0,z=X?{word:qs(e,q,X.next,X.delimiter,"literal",X.quoted),nested:[],issues:[],next:X.next,limited:!1}:F?void 0:ho(e,q,t,s,r,o);if(z){if(l.push(...z.issues),z.limited)return Bs(i,l,z.next);if(!fo(r))return qt(i,l,z.next,"word-limit",s.maxWords)}let G=z?.next??d+b.length,ve={kind:"redirection",operator:b,span:{start:N,end:G},...C===void 0?{}:{fd:C},...z?{target:z.word}:{}};if(c.redirections.push(ve),U&&!X&&l.push({code:"missing-heredoc-delimiter",message:"heredoc redirection requires a delimiter word"}),X){(X.ambiguous||X.delimiter.length===0)&&l.push({code:"ambiguous-heredoc-delimiter",message:"heredoc delimiter cannot be determined safely"});let ue=c.nested;u.push({delimiter:X.delimiter,quotedDelimiter:X.quoted,stripTabs:b==="<<-",attach:Se=>{if(ve.heredoc=Se,Se.quotedDelimiter)return;let xe=bp(e,Se.bodySpan.start,Se.bodySpan.end,s,r,o+1);ue.push(...xe.programs),l.push(...xe.issues)}})}!U&&!z&&l.push({code:"missing-redirection-target",message:`redirection ${b} requires a target word`}),z&&c.nested.push(...z.nested),c.end=G,d=G;continue}let k=c.start===-1;k&&po(i,l);let E=ho(e,d,t,s,r,o);if(l.push(...E.issues),E.limited)return Bs(i,l,E.next);let y=Np(c.words);if(y&&c.words.length>=Ea)return qt(i,l,E.next,"word-limit",Ea);let m=y?Fp(e,E.word,r.maxWords-r.wordsUsed,s.maxDepth,s.maxInputLength):void 0;if(m?.limitCode)return qt(i,l,E.next,m.limitCode,m.limitCode==="word-limit"?s.maxWords:m.limitCode==="depth-limit"?s.maxDepth:s.maxInputLength);let R=m?.words??[E.word];for(let v of R){if(!fo(r))return qt(i,l,E.next,"word-limit",s.maxWords);c.words.push(v)}c.start=c.start===-1?d:c.start,c.end=E.next,c.nested.push(...E.nested),k&&za(E.word)&&p(),d=E.next>d?E.next:d+1}return p(),Oa(i,l),l.push(...Gp(u)),{nodes:i,issues:l,next:d,closed:a===void 0,limited:!1,pendingHeredocs:[]}}function Sa(e,n,t){return{kind:"program",dialect:"posix",source:e.slice(n.start,n.end),span:n,status:Zs(t.issues,t.limited),issues:t.issues,nodes:t.nodes}}function ho(e,n,t,s,r,o){let a="",i=n,l=!1,c="literal",u=[],p=[],d=!1;for(;i<t;){let f=e[i],h=(f==="<"||f===">")&&e[i+1]==="(";if(!f||Jn(f)||(f===";"||f==="|"||f==="&")&&Gs(e,i)||(f==="<"||f===">")&&!h||f===")")break;if(f==="'"){l=!0;let k=e.indexOf("'",i+1);if(k===-1||k>=t){a+=e.slice(i+1,t),p.push({code:"unclosed-single-quote",message:"single-quoted word is not closed"}),i=t;break}a+=e.slice(i+1,k),i=k+1;continue}if(f==='"'){l=!0;let k=yp(e,i,t,s,r,o);if(a+=k.text,u.push(...k.nested),p.push(...k.issues),d||=k.limited,c=Yn(c,k.provenance),i=k.next,d)break;continue}if(e.startsWith("$'",i)){l=!0;let k=Ep(e,i+2,t);a+=k.text,p.push(...k.issues),k.closed||p.push({code:"unclosed-ansi-c-quote",message:"ANSI-C quoted word is not closed"}),i=k.next;continue}if(f==="\\"){let k=e[i+1];if(!k){p.push({code:"trailing-escape",message:"escape has no following character"}),i++;break}if(k===`
|
|
9
|
+
`){i+=2;continue}a+=k,i+=2;continue}Bt(e,i)&&p.push(Ht);let g=f==="$"||f==="<"||f===">"||f==="`"?Qn(e,i,t,s,r,o):null,b=g?yo(g,u,p):Ta(e,i,t,s,r,o,u,p);if(b){if(b.provenance==="variable"&&(a+=e.slice(i,b.next)),d||=b.limited,c=Yn(c,b.provenance),i=b.next,d)break;continue}if(f==="$"){let k=Fa(e,i,t,a,c);a=k.text,c=k.provenance,i=k.next;continue}(f==="*"||f==="?"||f==="[")&&(c=Yn(c,"glob")),a+=f,i++}return{word:qs(e,n,i,a,c,l,c==="literal"?void 0:Op(e,n,i)),nested:u,issues:p,next:i,limited:d}}function yp(e,n,t,s,r,o){let a="",i="literal",l=[],c=[],u=!1,p=n+1;for(;p<t;){let d=e[p];if(d==='"')return{text:a,provenance:i,nested:l,issues:c,next:p+1,limited:u};if(d==="\\"&&e[p+1]){let g=e[p+1]??"";if(g===`
|
|
10
|
+
`){p+=2;continue}if(g==="\r"&&e[p+2]===`
|
|
11
|
+
`){p+=3;continue}a+=["$","`",'"',"\\"].includes(g)?g:`\\${g}`,p+=2;continue}Bt(e,p)&&c.push(Ht);let f=Qn(e,p,t,s,r,o),h=f?yo(f,l,c):Ta(e,p,t,s,r,o,l,c);if(h){if(h.provenance!=="command-substitution"&&(a+=e.slice(p,h.next)),p=h.next,u||=h.limited,i=Yn(i,h.provenance),u)return{text:a,provenance:i,nested:l,issues:c,next:p,limited:u};continue}if(d==="$"){let g=Fa(e,p,t,a,i);a=g.text,i=g.provenance,p=g.next;continue}a+=d??"",p++}return c.push({code:"unclosed-double-quote",message:"double-quoted word is not closed"}),{text:a,provenance:i,nested:l,issues:c,next:t,limited:u}}function Qn(e,n,t,s,r,o){let a=Wa(e,n);if(!a)return null;let i=a.length,l=a.closing,c=l==="))",u=l==="`",p=e[n]==="<"||e[n]===">",d=bo(e,n+i,t,l),f=d===-1?t:d,h=d===-1?t:d+l.length;if(o>=s.maxDepth)return{program:Bp(e,n+i,f,"depth-limit"),next:h,provenance:c?"arithmetic":"command-substitution"};if(c){let m=[],R=[],v=!1,C=n+i;for(;C<f;){let N=Qn(e,C,f,s,r,o+1);if(!N){Bt(e,C)&&R.push(Ht),C++;continue}if(m.push(...N.program.nodes),R.push(...N.program.issues),v||=N.program.status==="limited",C=N.next,v)break}return d===-1&&R.push({code:"unclosed-arithmetic",message:"$(( substitution is not closed"}),{program:{kind:"program",dialect:"posix",source:e.slice(n+i,f),span:{start:n+i,end:f},status:Zs(R,v),issues:R,nodes:m},next:h,provenance:"arithmetic"}}let g=Vs(e,n+i,f,s,r,o+1),b=d===-1?[{code:"unclosed-command-substitution",message:`${e.slice(n,n+i)} substitution is not closed`}]:[],k=(u||p)&&Xn(g.nodes)?[{code:"unsupported-heredoc-context",message:"heredocs are supported only in ordinary commands and $(...) substitutions"}]:[],E=u&&/\\[\\$`\n]/.test(e.slice(n+i,f))?[Ap]:[],y=[...g.issues,...b,...k,...E];return{program:{kind:"program",dialect:"posix",source:e.slice(n+i,f),span:{start:n+i,end:f},status:Zs(y,g.limited),issues:y,nodes:g.nodes},next:h,provenance:"command-substitution"}}function bp(e,n,t,s,r,o){let a=[],i=[],l=n;for(;l<t;){let c=e[l];if(c==="\\"){l+=2;continue}let u=c==="$"||c==="`"?Qn(e,l,t,s,r,o):null;if(!u){Bt(e,l)&&i.push(Ht),l++;continue}a.push(u.program),vp(e,l,u.next)&&$p(u.program)&&i.push(Ht),l=u.next}return{programs:a,issues:i}}function yo(e,n,t){return n.push(e.program),t.push(...e.program.issues),{provenance:e.provenance,next:e.next,limited:e.program.status==="limited"}}function bo(e,n,t,s){if(s==="`"){for(let i=n;i<t;i++){if(e[i]==="\\"){i++;continue}if(e[i]==="`")return i}return-1}let r={single:!1,double:!1},o=[],a=[];for(let i=n;i<t;i++){let l=e[i];if((l===`
|
|
12
|
+
`||l==="\r")&&a.length>0){let p=l==="\r"&&e[i+1]===`
|
|
13
|
+
`?i+2:i+1,d=uo(e,p,t,a.splice(0));if(!d.terminated)return-1;i=d.next-1;continue}let c=Pa(e,i,n,t,r);if(c!==null){i=c;continue}if(!r.double&&e.startsWith("$((",i)){let p=wp(e,i+3,t);if(p===-1)return-1;i=p+1;continue}if(s===")"&&!r.double&&l==="<"&&e[i+1]==="<"&&e[i+2]!=="<"){let p=e[i+2]==="-",d=i+(p?3:2);for(;d<t&&/[ \t]/.test(e[d]??"");)d++;let f=co(e,d,t);if(f){a.push({delimiter:f.delimiter,quotedDelimiter:f.quoted,stripTabs:p,attach:()=>{}}),i=f.next-1;continue}}if(e.startsWith("$(",i)&&!e.startsWith("$((",i)){o.push(r),r={single:!1,double:!1},i++;continue}if(l==="("&&!r.double){o.push(r),r={single:!1,double:!1};continue}if(l!==")"||r.double)continue;let u=o.pop();if(u){r=u;continue}return s==="))"&&e[i+1]!==")"?-1:i}return-1}function wp(e,n,t){let s=1,r={single:!1,double:!1};for(let o=n;o<t;o++){let a=e[o],i=Pa(e,o,n,t,r);if(i!==null){o=i;continue}if(e.startsWith("$(",o)&&!e.startsWith("$((",o)){s++,o++;continue}if(a==="("&&!r.double&&s++,!(a!==")"||r.double)&&(s--,s===0))return e[o+1]===")"?o:-1}return-1}function Pa(e,n,t,s,r){let o=e[n];if(o==="\\"&&!r.single)return n+1;if(!r.double&&o==="'"&&(r.single=!r.single),!r.single&&o==='"'&&(r.double=!r.double),r.single)return n;if(r.double||o!=="#"||!Zp(e,n,t))return null;let a=n;for(;a+1<s&&e[a+1]!==`
|
|
14
|
+
`&&e[a+1]!=="\r";)a++;return a}function Gs(e,n){let t=e[n];return t===";"?";":t==="&"?e[n+1]==="&"?"&&":"&":t==="|"?e[n+1]==="|"?"||":e[n+1]==="&"?"|&":"|":null}function kp(e,n){let t=e[n];return t===">"?e[n+1]===">"?">>":e[n+1]==="&"?">&":e[n+1]==="|"?">|":">":t!=="<"?null:e.startsWith("<<<",n)?"<<<":e.startsWith("<<-",n)?"<<-":e[n+1]==="<"?"<<":e[n+1]==="&"?"<&":e[n+1]===">"?"<>":"<"}function Jn(e){let n=e.charCodeAt(0);return n===32||n>=9&&n<=13?!0:n<128?!1:/\s/u.test(e)}var Ht=Object.freeze({code:"unsupported-function-substitution",message:"${ list; } function substitutions run in the current shell and cannot be analyzed"});function Bt(e,n){if(e[n]!=="$")return!1;let t=Ca(e,n+1);if(e[t]!=="{")return!1;let s=e[Ca(e,t+1)]??"";return s==="|"||Jn(s)}function vp(e,n,t){for(let s=e.indexOf("$",n);s!==-1&&s<t;s=e.indexOf("$",s+1))if(Bt(e,s))return!0;return!1}function $p(e){return e?.status==="limited"||(e?.issues??[]).some(n=>n.code===Ht.code)}function Ca(e,n){let t=n;for(;e.startsWith(`\\
|
|
15
|
+
`,t)||e.startsWith(`\\\r
|
|
16
|
+
`,t);)t+=e[t+1]==="\r"?3:2;return t}function Wa(e,n){return e.startsWith("$((",n)?{length:3,closing:"))"}:e.startsWith("$(",n)||e.startsWith("<(",n)||e.startsWith(">(",n)?{length:2,closing:")"}:e[n]==="`"?{length:1,closing:"`"}:null}var xp=Object.freeze({code:"unclosed-parameter-expansion",message:"${ parameter expansion is not closed"}),_p=/[\v\f\r]/,Na=Object.freeze({code:"unsupported-blank",message:"a vertical tab, form feed, carriage return or Unicode space is part of a word in bash and zsh, not a separator"}),La=Object.freeze({code:"unsupported-parameter-expansion",message:"a line continuation inside ${ }, or a quote or backslash inside ${ } with a substitution in or after it, cannot be analyzed"}),Sp=/\$\(|`|[<>]\(/g;function Cp(e,n,t){let s=go(t);return[...e.slice(n).matchAll(Sp)].some(r=>{let o=n+r.index;return!s.some(a=>o>=a.start&&o<a.end)})}function go(e){return e.flatMap(n=>n.kind==="command"?[...n.redirections.flatMap(t=>t.heredoc?[t.heredoc.bodySpan]:[]),...n.nested.flatMap(t=>go(t.nodes))]:n.kind==="group"||n.kind==="function"?go(n.body.nodes):[])}var Ap=Object.freeze({code:"unsupported-backtick-escape",message:"a backslash escape inside backticks changes the command the shell runs and cannot be analyzed"});function Ta(e,n,t,s,r,o,a,i){if(e[n]!=="$"||e[n+1]!=="{")return null;let l=Da(e,n+2,t),c=l.close===-1?t:l.close+1;l.close===-1&&i.push(xp),(l.quoted&&l.substitutions.length>0||l.continued)&&i.push(La),l.quoted&&(r.quotedExpansionEnd=Math.min(r.quotedExpansionEnd,c));let u=l.substitutions.some(p=>{if(Bt(e,p))return i.push(Ht),!1;let d=Qn(e,p,c,s,r,o);return d!==null&&yo(d,a,i).limited});return{provenance:"variable",next:c,limited:u}}function Da(e,n,t){let s=[],r=!1,o=!1,a=1,i=n;for(;i<t;){let l=e[i];if(l==="$"&&Bt(e,i)&&s.push(i),l==="\\"||l==="'"||l==='"'){r=!0,o||=l==="\\"&&e[i+1]===`
|
|
17
|
+
`,i+=l==="\\"?2:1;continue}let c=Wa(e,i);if(c){s.push(i);let u=bo(e,i+c.length,t,c.closing);if(u===-1)break;i=u+c.closing.length;continue}if(l==="$"&&e[i+1]==="{"){a++,i+=2;continue}if(l==="}"&&--a===0)return{close:i,substitutions:s,quoted:r,continued:o};i++}return{close:-1,substitutions:s,quoted:r,continued:o}}function Ia(e,n,t){if(e[n+1]==="{"){let r=Da(e,n+2,t).close;return r===-1?t:r+1}if(e[n+1]==="$")return n+2;let s=n+1;for(;s<t&&/[A-Za-z0-9_?@#!*-]/.test(e[s]??"");)s++;return s===n+1?n+1:s}function Ep(e,n,t){let s="",r=[],o=n;for(;o<t;){let a=e[o];if(a==="'")return{text:s,next:o+1,closed:!0,issues:r};if(a!=="\\"){s+=a??"",o++;continue}let i=Rp(e,o+1,t);s+=i.text,i.invalidCodePoint!==void 0&&r.push({code:"invalid-ansi-c-code-point",message:`ANSI-C escape is not a valid Unicode scalar value: ${i.invalidCodePoint}`}),o=i.next}return{text:s,next:t,closed:!1,issues:r}}function Rp(e,n,t){let s=e[n];if(!s||n>=t)return{text:"\\",next:n};let r=new Map([["a","\x07"],["b","\b"],["e","\x1B"],["E","\x1B"],["f","\f"],["n",`
|
|
18
|
+
`],["r","\r"],["t"," "],["v","\v"],["\\","\\"],["'","'"],['"','"']]);return r.has(s)?{text:r.get(s)??s,next:n+1}:s==="x"?Hs(e,n+1,t,16,2,n+1):s==="u"?Hs(e,n+1,t,16,4,n+1):s==="U"?Hs(e,n+1,t,16,8,n+1):/[0-7]/.test(s)?Hs(e,n,t,8,3,n+1):{text:s,next:n+1}}function Hs(e,n,t,s,r,o){let a=s===16?/[0-9a-fA-F]/:/[0-7]/,i="",l=n;for(;l<t&&i.length<r&&a.test(e[l]??"");)i+=e[l],l++;if(!i)return{text:e[o-1]??"",next:o};let c=Number.parseInt(i,s);return c>1114111||c>=55296&&c<=57343?{text:"\uFFFD",next:l,invalidCodePoint:c}:{text:String.fromCodePoint(c),next:l}}function Zs(e,n=!1){return n?"limited":e.some(t=>t.code==="invalid-ansi-c-code-point"||t.code==="missing-heredoc-delimiter"||t.code==="ambiguous-heredoc-delimiter"||t.code==="unterminated-heredoc"||t.code==="unsupported-heredoc-context"||t.code==="unsupported-function-substitution"||t.code==="unsupported-backtick-escape"||t.code==="unclosed-parameter-expansion"||t.code==="unsupported-parameter-expansion"||t.code==="unsupported-blank")?"invalid":e.length>0?"partial":"complete"}function Fa(e,n,t,s,r){let o=Ia(e,n,t);return{text:s+e.slice(n,o),provenance:Yn(r,"variable"),next:o}}function Op(e,n,t){let s=$a(e),r=n,o=!1,a=!1,i=n;for(;i<t;){let l=e[i];if(l==="\\"&&!o){i+=2;continue}if(!a&&l==="'"){o=!o,i++;continue}if(!o&&l==='"'){a=!a,i++;continue}if(o){i++;continue}let c=e.startsWith("$((",i),u=e.startsWith("$(",i)&&!c,p=!a&&(e.startsWith("<(",i)||e.startsWith(">(",i)),d=l==="`";if(c||u||p||d){let f=c?3:d?1:2,h=c?"))":d?"`":")",g=bo(e,i+f,t,h),b=g===-1?t:g+h.length;s.push(r,i,"literal"),s.push(i,b,c?"arithmetic":"command-substitution"),i=b,r=b;continue}if(l==="$"){let f=Ia(e,i,t);if(f>i+1){s.push(r,i,"literal"),s.push(i,f,"variable"),i=f,r=f;continue}}if(!a&&(l==="*"||l==="?"||l==="[")){s.push(r,i,"literal"),s.push(i,i+1,"glob"),i++,r=i;continue}i++}return s.push(r,t,"literal"),s.parts}function Yn(e,n){return n==="command-substitution"||e==="command-substitution"?"command-substitution":n==="arithmetic"||e==="arithmetic"?"arithmetic":n==="variable"||e==="variable"?"variable":n==="glob"||e==="glob"?"glob":e}function jp(e,n,t){return n+1>=t||Jn(e[n+1]??"")||Gs(e,n+1)!==null}var Pp=new Set(["-u","--unset","-C","--chdir","-S","--split-string","-P"]),Wp=new Set(["-u","-g","-C","-D","-h","-p","-r","-t","-T","-U"]),Aa=new WeakSet,Ea=256;function Np(e){if(Aa.has(e))return!1;let n=0;for(;n<=e.length;){for(;/^[A-Za-z_][A-Za-z0-9_]*=/.test(e[n]?.text??"");)n++;if(n===e.length)return!0;let t=Lp(e,n);if((t===void 0||t===null&&e[n]?.text.toLowerCase()==="command")&&Aa.add(e),t==null)return!1;n=t}return!1}function Lp(e,n){let t=e[n]?.text.toLowerCase();if(t==="command")return Tp(e,n);if(t==="env")return Dp(e,n);if(t==="sudo")return Ip(e,n)}function Tp(e,n){if(e[n+1]?.text==="-v")return null;for(let t=n+1;t<e.length;t++){let s=e[t]?.text??"";if(s==="--")return t+1;if(!(s==="-p"||s==="-v"||s==="-V"||/^-[pvV]+$/.test(s)))return t}return e.length}function Dp(e,n){for(let t=n+1;t<e.length;t++){let s=e[t]?.text??"";if(s==="--")return t+1;if(Pp.has(s)){if(e[t+1]===void 0)return null;t++;continue}if(!(s.startsWith("-u=")||s.startsWith("--unset=")||s.startsWith("-C")&&s.length>2||s.startsWith("--chdir=")||s.startsWith("-S")&&s.length>2||s.startsWith("--split-string=")||s.startsWith("-P"))&&!(s.startsWith("-")||/^[A-Za-z_][A-Za-z0-9_]*=/.test(s)))return t}return e.length}function Ip(e,n){for(let t=n+1;t<e.length;t++){let s=e[t]?.text??"";if(s==="--")return t+1;if(Wp.has(s)){if(e[t+1]===void 0)return null;t++;continue}if(!s.startsWith("-"))return t}return e.length}function Fp(e,n,t,s,r){if(n.provenance!=="literal"||!n.raw.includes("{"))return;let o=Mp(n.raw,t,s,r,!1);if(!o)return;if("limited"in o)return o.limited==="expansions"?{limitCode:"depth-limit"}:{limitCode:o.limited==="length"?"brace-expansion-limit":"word-limit"};let a=o.values.map(i=>Hp(i,s));if(!a.some(i=>i===null))return{words:a.filter(i=>i!==null&&i!=="").map(i=>qs(e,n.span.start,n.span.end,i,"literal",!1))}}function Mp(e,n,t,s,r){let o=[e],a=e.length,i=0;for(;;){let l=o.findIndex(f=>Ra(f,r));if(l===-1)break;if(++i>t)return{limited:"expansions"};let c=o[l]??"",u=Ra(c,r);if(!u||u.kind==="range")return{limited:"expansions"};let p=u.start+c.length-u.end,d=u.alternatives.reduce((f,h)=>f+p+h.length,0);if(a-c.length+d>s)return{limited:"length"};if(o.length-1+u.alternatives.length>n)return{limited:"words"};o.splice(l,1,...zp(c,u)),a+=d-c.length}return i===0?void 0:{values:o}}function Ra(e,n){let t=[],s,r=null,o=!1;for(let a=0;a<e.length;a++){let i=e[a];if(o){o=!1;continue}if(i==="\\"&&r!=="'"){o=!0;continue}if(i===r){r=null;continue}if(r===null&&(i==="'"||i==='"')){r=i;continue}if(r!==null)continue;if(i==="{"){t.push({start:a,commas:[]});continue}if(i===","&&t.length>0){t.at(-1)?.commas.push(a);continue}if(i!=="}"||t.length===0)continue;let l=t.pop();if(!l)continue;let c=l.commas.length>0?{kind:"alternatives",start:l.start,end:a+1,commas:l.commas}:n&&qp(e.slice(l.start+1,a))?{kind:"range",start:l.start,end:a+1}:void 0;c&&(!s||c.start<s.start)&&(s=c)}return!s||s.kind==="range"?s:{kind:s.kind,start:s.start,end:s.end,alternatives:Up(e,s)}}function zp(e,n){return n.alternatives.map(t=>`${e.slice(0,n.start)}${t}${e.slice(n.end)}`)}function Up(e,n){let t=[n.start,...n.commas,n.end-1];return t.slice(0,-1).map((s,r)=>e.slice(s+1,t[r+1]))}function qp(e){return/^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(e)||/^[A-Za-z]\.\.[A-Za-z](?:\.\.-?\d+)?$/.test(e)}function Hp(e,n){let t=`x${e}`,s=ho(t,0,t.length,{maxInputLength:t.length,maxWords:1,maxDepth:n},{wordsUsed:0,maxWords:1,quotedExpansionEnd:1/0},0);return s.limited||s.issues.length>0||s.next!==t.length||s.word.provenance!=="literal"?null:s.word.text.slice(1)}function Bp(e,n,t,s){return{kind:"program",dialect:"posix",source:e.slice(n,t),span:{start:n,end:t},status:"limited",issues:[{code:s,message:"command structure exceeds parser limit"}],nodes:[]}}function qt(e,n,t,s,r){return{nodes:e,issues:[...n,{code:s,message:`command structure exceeds parser limit ${r}`}],next:t,closed:!1,limited:!0,pendingHeredocs:[]}}function Bs(e,n,t){return{nodes:e,issues:n,next:t,closed:!1,limited:!0,pendingHeredocs:[]}}function fo(e){return e.wordsUsed++,e.wordsUsed<=e.maxWords}function Vp(e,n,t){let s=e.slice(n,t),r=/^(?:function[ \t]+)?([A-Za-z_][A-Za-z0-9_]*)[ \t]*\([ \t]*\)[ \t]*\{/.exec(s)??/^function[ \t]+([A-Za-z_][A-Za-z0-9_]*)[ \t]+\{/.exec(s),o=r?.[1];if(!(!r||!o))return{name:o,braceIndex:n+r[0].lastIndexOf("{")}}function Xn(e){return e.some(n=>n.kind==="command"?n.redirections.some(t=>t.heredoc)||n.nested.some(t=>Xn(t.nodes)):(n.kind==="group"||n.kind==="function")&&Xn(n.body.nodes))}function Gp(e){return e.map(n=>({code:"unterminated-heredoc",message:`heredoc delimiter ${n.delimiter} was not found`}))}function Ma(e){return e?.kind==="command"||e?.kind==="group"||e?.kind==="function"}function Oa(e,n){let t=e.at(-1);t?.kind!=="connector"||!ja.has(t.operator)||n.push({code:"missing-command-after-connector",message:`connector ${t.operator} requires a following command`})}function za(e){return e?.provenance==="literal"&&!e.quoted&&e.raw===e.text&&mp.has(e.text)}function po(e,n){let t=e.at(-1);Ma(t)&&(t?.kind==="command"&&za(t.words[0])||n.push({code:"missing-command-connector",message:"adjacent commands require a connector"}))}function Zp(e,n,t){return n===t||/[\s;&|()]/u.test(e[n-1]??"")}import{createRequire as Kp}from"module";var es,Yp="Anvil's PowerShell reader (claude-powershell.cjs) is missing or won't load";function Ua(){if(es===void 0){es=null;let e=Kp(import.meta.url);for(let n of["./claude-powershell.cjs","../claude-powershell.cjs"])try{let t=e(n);if(typeof t.readPowerShell=="function"&&typeof t.readCmd=="function"){es=t;break}}catch{}}if(es===null)throw new Error(Yp);return es}function pn(e,n){return Ua().readPowerShell(e,n)}function qa(e,n){return Ua().readCmd(e,n)}import{posix as Ba}from"path";var Jp=null;function Z(){return Jp??process.platform==="win32"}var Ha=/^([A-Za-z]):(.*)$/s,Xp=/^\/(?:cygdrive\/)?([A-Za-z])(\/.*)?$/s;function wo(e,n){let t=Ba.normalize(`/${n}`);return t==="/"?e:`${e}${t.replace(/\/$/,"")}`}function hn(e,n){return e.split("/").map(t=>{if(t===""||t==="."||t===".."||/[\u0000\u0001]/.test(t))return t;let s=t.indexOf(":"),r=s>=0?t.slice(0,s):t,o=n?r:r.replace(/[. ]+$/,"");return o===""?".":o}).join("/")}function Ge(e){if(!Z())return e;let n=e.replace(/^(?:Microsoft\.PowerShell\.Core\\)?FileSystem::/i,""),t=!1,s=/^[\\/]{2}([?.])[\\/](.*)$/s.exec(n);if(s){let l=s[2];if(s[1]===".")return`/dev/${l.replace(/[\\/]+/g,"/").replace(/\/$/,"").toLowerCase()}`;if(/^unc[\\/]/i.test(l))n=`\\\\${l.slice(4)}`;else if(Ha.test(l))n=l;else return`/dev/${l.replace(/[\\/]+/g,"/").replace(/\/$/,"").toLowerCase()}`;t=!0}n=n.replace(/\\/g,"/");let r=/^\/\/([^/]+)(?:\/([^/]+))?(\/.*)?$/s.exec(n);if(r){let l=`/unc/${hn(r[1],t).toLowerCase()}${r[2]?`/${hn(r[2],t).toLowerCase()}`:""}`;return wo(l,hn(r[3]??"",t).toLowerCase())}let o=Ha.exec(n);if(o){let l=o[2];return l===""?`/${o[1].toLowerCase()}`:l.startsWith("/")?wo(`/${o[1].toLowerCase()}`,hn(l,t).toLowerCase()):null}let a=Xp.exec(n);if(a)return wo(`/${a[1].toLowerCase()}`,hn(a[2]??"",t).toLowerCase());let i=hn(n,t).toLowerCase();if(i.startsWith("/")){let l=Ba.normalize(i);return l.length>1&&l.endsWith("/")?l.slice(0,-1):l}return i}function Ie(e){return Ge(e)??e}function ts(e){return Z()&&/^\/dev\/(?:nul|con|conin\$|conout\$|(?:pipe|mailslot)\/.+)$/.test(e)}function Va(e){return/^\/[a-z]$/.test(e)||/^\/unc\/[^/]+(?:\/[^/]+)?$/.test(e)}function pt(e){if(!Z())return e;let n=/^\/([a-z])(\/.*)?$/s.exec(e);if(n)return`${n[1].toUpperCase()}:${(n[2]??"/").replace(/\//g,"\\")}`;let t=/^\/unc\/(.+)$/s.exec(e);return t?`\\\\${t[1].replace(/\//g,"\\")}`:null}function Fe(e){return Z()?pt(e)??e:e}function gn(e){return Z()?pt(e)??e:e}var ko=["windows","windows/system32","windows/syswow64","program files","program files (x86)","programdata","users","recovery","boot","perflogs","system volume information","$recycle.bin","documents and settings"],vo=new Set(["desktop","documents","downloads","pictures","music","videos","favorites","contacts","links","saved games","searches","onedrive","appdata","3d objects","source",".ssh",".gnupg",".aws",".azure",".config",".claude",".local",".kube",".docker"]);function ae(e){return Object.assign(Object.create(null),e)}var J="\0",ee="",Qp=/\brailway\s+(variables|variable|vars)\b|\bheroku\s+config\b|\bdoppler\s+secrets\b|\bop\s+read\b|\baws\s+secretsmanager\b|\bgcloud\s+secrets\b|\bvault\s+(kv\s+get|read)\b/,He="\0$OLDPWD",So=8,eh=32,th=8,nh=16,sh=64,yn=new Set(["bash","sh","zsh","dash","ksh","fish","ash","csh","tcsh","mksh","yash"]);function tr(e,n,t){for(let s=0;e.deferred.length>0;s++){if(s>=eh){e.bodyRead||(e.depthLimit.hit=!0),e.deferred.length=0;break}let r=e.deferred.shift();be(r.code,{...e,vars:new Map(e.vars),cwd:He,depth:e.depth+1,via:"shell-string",captured:!1,frames:[],outerGuards:r.parent.guards,andGuards:[],parent:r.parent,errexit:r.errexit},n,t)}}var rh=new Set([":",".","eval","exec","exit","export","readonly","return","set","shift","trap","unset","break","continue","times"]),Ga=new Set(["sh","dash","ksh","ash","mksh","yash"]),Po=/^([0-9]+|[@*#])$/,il=new Set(["do","then","else","elif","if","while","until","!","{","(","time"]),oh=new Set(["done","fi","esac","}",")","in","case",";;"]),ih=new Set(["sudo","doas","pkexec","run0","env","nohup","time","nice","ionice","timeout","gtimeout","command","builtin","exec","caffeinate","stdbuf","unbuffer","chronic","script","npx","pnpx","bunx","uv","uvx","pipx","busybox","bundle","poetry","pdm","rye","op","doppler","infisical","dotenvx","dotenv","sshpass","aws-vault","cross-env","setsid","sandbox-exec","flock","taskset","chrt","prlimit","unshare","systemd-inhibit","launchctl"]),al=new Set(["-w","--timeout","-E","--conflict-exit-code"]),Za=new Set(["npx","pnpx","bunx","uv","uvx","pipx"]),ah=ae({"eas-cli":"eas","expo-cli":"expo","@expo/cli":"expo","netlify-cli":"netlify","firebase-tools":"firebase","@railway/cli":"railway",localtunnel:"lt","@anthropic-ai/claude-code":"claude","@useanvil/sdk":"anvil","@useanvil/claude-code":"anvil-claude","@openai/codex":"codex","@google/gemini-cli":"gemini","appcenter-cli":"appcenter","snowflake-cli":"snow","snowflake-cli-labs":"snow","databricks-cli":"databricks","@ngrok/ngrok":"ngrok","@capgo/cli":"capgo","@smithery/cli":"smithery","@github/copilot":"copilot","@qwen-code/qwen-code":"qwen","chrome-webstore-upload-cli":"chrome-webstore-upload"});function nr(e){let n=new Set(["-w","--workspace","--filter","-F","-C","--dir","--prefix","--cwd","--recursive-filter"]),t=1;for(;t<e.length&&e[t].startsWith("-");)t+=n.has(e[t])?2:1;return e[0]!==void 0&&/(^|\/)yarn$/.test(e[0])&&e[t]==="workspace"&&(t+=2),{sub:e[t]??"",at:t}}function Ka(e){let n=/^((?:@[^/@\s]+\/)?[^@\s=/]+)(?:@[^\s/]*|==[^\s]*)$/.exec(e),t=n?n[1]:e;return ah[t]??t}var lh=new Set(["python","python3","node","ruby","perl","php","bun","deno","tsx","ts-node"]);function be(e,n,t,s){let r=mo(e,lo);r.status==="limited"&&!n.bodyRead&&(n.depthLimit.hit=!0),Vt(r,n,t,s)}function At(e,n){let t=[],s=mo(e,lo),r={vars:new Map,functions:new Map,called:new Set,cwd:n.cwd,depth:0,via:"top",remote:null,productionEnv:!1,captured:!1,frames:[],outerGuards:[],andGuards:[],cds:[],cdpath:!1,errexit:!1,ifs:null,posixOnly:!1,maybeRuns:!1,partial:s.status!=="complete",subshell:!1,inFunction:!1,newProcess:!1,deferred:[],locals:new Set,files:new Map(Object.entries(n.knownFiles??{})),loopBudget:{left:sh},depthLimit:{hit:!1},parent:null,oldCwd:He,dirStack:[]};Vt(s,r,n,t);for(let[o,a]of r.functions)r.called.has(o)||Vt(a,{...r,vars:new Map(r.vars),depth:1,via:"shell-string",captured:!1,frames:[],andGuards:[]},n,t);return tr(r,n,t),{commands:t,status:r.depthLimit.hit?"limited":s.status}}function mt(e){let n=[...e.outerGuards];for(let t of e.frames)t.phase!=="body"||t.negate||(t.kind==="case"?n.push(`case ${t.word??""} in ${t.pattern??""}`):n.push(...t.cond));return[...n,...e.andGuards]}var Co=class{passed=[];joiner=null;open=!1;text=null;exits=!1;beforeOr=[];orExits=!1;runPassed=[];get afterOr(){return this.joiner==="||"}get joined(){return this.joiner!==null}start(){this.close(),this.runPassed=this.joiner==="&&"?this.passed:[],this.open=!0,this.text=null,this.exits=!1}set(n,t=!1){this.text=n,this.exits=t}extend(n){this.text=this.text!==null&&n!==null?`${this.text} | ${n}`:null,this.exits=!1}join(n){this.close(),n==="||"&&(this.beforeOr=this.passed),this.joiner=n}end(){this.close();let n={passed:this.passed,past:this.orExits?this.beforeOr:[],lone:this.elements===1&&this.lastText!==null&&!this.lastText.startsWith("! ")?this.lastText:null};return this.passed=[],this.beforeOr=[],this.orExits=!1,this.elements=0,this.joiner=null,n}elements=0;lastText=null;close(){if(!this.open)return;let n=this.text;this.elements++,this.lastText=n,this.joiner==="&&"?(n!==null&&(this.passed=[...this.passed,n]),this.orExits=!1):this.joiner==="||"?(this.passed=[],this.orExits=this.exits):(this.passed=n===null?[]:[n],this.orExits=!1),this.open=!1,this.joiner=null}};function ch(e){return e!==null&&(e.name==="exit"||e.name==="return")&&e.wrappers.length===0&&e.argv.length<=2&&e.via!=="xargs"}function uh(e){for(let n of e.words){if(n.provenance!=="literal"||n.quoted||!il.has(n.text))return!1;if(n.text==="!")return!0}return!1}function Ct(e,n){for(let t=e.frames.length-1;t>=0;t--)if(e.frames[t].kind===n)return e.frames[t]}function Js(e,n){for(let t=e.frames.length-1;t>=0;t--)if(e.frames[t].kind===n){e.closed=e.frames[t],e.frames.splice(t,1);return}}function ll(e){let n=[];for(let t=e;t&&n.length<8;t=t.pipeFrom)n.push(t.text);return n.reverse().join(" | ")}function dh(e,n,t,s){let r=e[n];if(r.kind!=="command")return null;let o=r.words;if(!o[0]||o[0].text!=="for"||o[0].provenance!=="literal"||o[0].quoted)return null;let a=o[1]?.text,i=o.findIndex(y=>y.text==="in"&&y.provenance==="literal"),l=i>0?o.slice(i+1):[],c=l.length===1&&l[0].provenance==="command-substitution"?/^\$\(\s*(?:echo|printf)\s+([\w./ -]+?)\s*\)$/.exec(l[0].raw)?.[1]:void 0,u=y=>y.provenance==="literal"||y.provenance==="glob",p=y=>u(y)||/^"[^"`]*"$/.test(y.raw)&&!/\$\{?[@*]|\[[@*]\]/.test(y.raw)&&!S(Me(y,t,s).text);if(!a||!/^[A-Za-z_][A-Za-z0-9_]*$/.test(a)||l.length===0||!c&&!l.every(p))return null;let d=-1,f=0,h=-1;for(let y=n+1;y<e.length;y++){let m=e[y];if(m.kind!=="command")continue;let R=m.words[0];if(!(!R||R.provenance!=="literal"||R.quoted)){if(d<0){if(R.text==="do"&&m.words.length===1)d=y;else if(R.text!=="do")return null;continue}if(["for","while","until","select"].includes(R.text)&&f++,R.text==="done"){if(f===0){h=y;break}f--}}}if(d<0||h<0)return null;let g=c?c.split(/\s+/).filter(Boolean):l.map(y=>u(y)?y.text:Me(y,t,s).text),b=hl(t,gl(l.map(y=>y.raw).join(" "))),k=g.map((y,m)=>{let R=l[m];return b.length===0||c||!R||u(R)?[]:[...new Set(b.map(v=>Me(R,{...t,vars:v},s).text))].filter(v=>v!==y)}),E=Math.min(g.length,nh,t.loopBudget.left);return E<=0?null:(t.loopBudget.left-=E,{name:a,values:g.slice(0,E),alts:k.slice(0,E),truncated:E<g.length,body:e.slice(d+1,h),end:h})}function fh(e,n){let t=0;for(let s=n;s<e.length;s++){let r=e[s];if(r.kind!=="command")continue;let o=r.words[0];if(!(!o||o.provenance!=="literal"||o.quoted)&&(["while","until","for","select"].includes(o.text)&&t++,o.text==="done")){if(t>0){t--;continue}let a=r.redirections.find(c=>(c.operator==="<"||c.operator==="<<<")&&c.target);if(!a||!a.target)return null;let i=a.target.raw.replace(/^"|"$/g,""),l=/^(?:<\(|\$\()([\s\S]*)\)$/.exec(i);return l?l[1]:a.operator==="<"?`cat ${i}`:i}}return null}function Ya(e,n,t,s,r){let o=e.words,a=0;for(;a<o.length&&o[a].provenance==="literal"&&!o[a].quoted;){let i=o[a].text;if(i==="if")n.frames.push({kind:"if",phase:"cond",cond:[],negate:!1});else if(i==="while"||i==="until")n.frames.push({kind:"loop",phase:"cond",cond:[],negate:i==="until",input:r?ll(r):fh(t,s+1)});else if(i==="then"){let l=Ct(n,"if");l&&(l.phase="body")}else if(i==="elif"){let l=Ct(n,"if");l&&Object.assign(l,{phase:"cond",cond:[],negate:!1})}else if(i==="else"){let l=Ct(n,"if");l&&(l.phase="else")}else if(i==="fi")Js(n,"if");else if(i==="do"){let l=Ct(n,"loop");l&&(l.phase="body")}else if(i==="done")Js(n,"loop");else if(i==="esac")Js(n,"case");else if(i==="!"&&n.frames.length&&n.frames[n.frames.length-1].phase==="cond")n.frames[n.frames.length-1].negate=!0;else if(!["{","}","(",")","time"].includes(i))break;a++}return a>0&&a===o.length}var Ks=new WeakMap;function Vt(e,n,t,s){if(n.depth>So){n.bodyRead||(n.depthLimit.hit=!0);return}let r=null,o=[],a=!1,i=n.andGuards,l=n.maybeRuns,c=n.subshell,u=new Co,p=[],d=v=>v.length<=n.frames.length&&v.every(([C,N],q)=>n.frames[q]===C&&C.phase===N),f=new Set,h=v=>{for(let C=v;C<n.frames.length;C++)f.add(n.frames[C])},g=()=>{u.start();let v=n.frames[n.frames.length-1];v&&v.phase==="cond"&&f.has(v)&&(v.cond=[])},b=()=>{n.andGuards=[...i,...p.filter(v=>d(v.at)).map(v=>v.text),...u.runPassed]},k=()=>{n.andGuards=i},E=0,y=!1,m=null,R=n.posixOnly?e.nodes:ph(e.nodes);for(let v=0;v<R.length;v++){let C=R[v],N=y;y=!1;let q=m;m=null;for(let D of n.frames)Ks.has(D)||Ks.set(D,s.length);if(C.kind==="command"&&C.words.length===1&&C.words[0].text==="!"&&C.words[0].provenance==="literal"&&!C.words[0].quoted){let D=n.frames.length;Ya(C,n,R,v,null),h(D),y=!0;continue}if(C.kind==="connector"){if(a=C.operator==="|"||C.operator==="|&",C.operator==="&")for(let D of o)D.background=!0;if(!a)if(r=null,C.operator==="&&"||C.operator==="||")u.join(C.operator);else{let D=u.end(),H=n.frames[n.frames.length-1];H&&H.phase==="cond"&&f.has(H)&&(H.cond=[...D.passed]);let ye=n.frames.map(We=>[We,We.phase]),ne=n.frames.some(We=>We.phase==="cond"),oe=n.errexit&&!ne&&D.lone!==null?[D.lone]:[];C.operator!=="&"&&(p=[...p,...[...D.past,...oe].map(We=>({text:We,at:ye}))])}if(E=C.operator===";"?E+1:0,E>=2){let D=Ct(n,"case");D&&Object.assign(D,{phase:"pattern",pattern:""})}continue}E=0;let B=Ct(n,"case");if(C.kind!=="command"&&B&&B.phase==="pattern"){B.phase="body";continue}if(C.kind==="group"){let D=e.source.slice(C.span.start-e.span.start,C.span.end-e.span.start);if(D.startsWith("(("))for(let T of D.matchAll(/(?<![A-Za-z0-9_])([A-Za-z_][A-Za-z0-9_]*)\s*(?:[-+*\/%&|^]|<<|>>)?=(?!=)|(?<![A-Za-z0-9_])([A-Za-z_][A-Za-z0-9_]*)\s*(?:\+\+|--)|(?:\+\+|--)\s*([A-Za-z_][A-Za-z0-9_]*)/g))ht(n,T[1]??T[2]??T[3],{kind:"unknown"});a||g(),b();let H=C.style==="subshell"?{...n,vars:new Map(n.vars),functions:new Map(n.functions),outerGuards:mt(n),frames:[],andGuards:[],deferred:[]}:n,ye=s.length,ne=R[v+1];H.maybeRuns=l||u.afterOr||a||ne?.kind==="connector"&&["|","|&","&"].includes(ne.operator),Vt(C.body,H,t,s),H!==n&&tr(H,t,s),H.maybeRuns=l,o=s.slice(ye);let oe=R[v+1];if(oe?.kind==="command"&&oe.words.length===0&&oe.redirections.some(hh)){let T=new Set(o),Y=new Set(o.map(de=>de.parent)),ao=de=>{for(let Ne=de;Ne&&T.has(Ne);Ne=Ne.parent)if(Ne.captured||Ne.pipeTo!==null||Ne.redirects.some(Us=>Ys(Us))||_o.has(Ne))return!0;return!1};m=o.some(de=>de.name==="exec"&&de.redirects.some(Ne=>Ys(Ne)))||ul(C.body)?[]:o.filter(de=>!Y.has(de)&&!ao(de));for(let de of m)_o.add(de)}else if(oe?.kind==="command"&&oe.words.length===0&&oe.redirections.some(Xs)||oe?.kind==="connector"&&(oe.operator==="|"||oe.operator==="|&"))for(let T of o)_o.add(T);let We=oe?.kind==="command"&&oe.words.length===0?oe.redirections.find(T=>(T.operator==="<"||T.operator==="<>")&&(T.fd===void 0||T.fd===0)&&T.target):void 0;We?.target&&dl(o,Me(We.target,n,t).text),k(),a?u.extend(null):u.set(null),r=null,a=!1;continue}if(C.kind==="function"){n.functions.set(C.name,C.body);let D=sr.get(n.functions)??new Set;sr.set(n.functions,D);let H=R[v+1],ye=a||H?.kind==="connector"&&["&","|","|&"].includes(H.operator);n.depth===0&&!n.subshell&&!n.maybeRuns&&!u.joined&&!ye&&n.frames.length===0&&mt(n).length===0?D.add(C.name):D.delete(C.name),a||g(),u.set(null),r=null,a=!1;continue}if(C.kind!=="command")continue;let V=dh(R,v,n,t);if(V){a||g(),b();let D=[...V.values.map(ne=>({kind:"value",value:ne})),...V.truncated?[{kind:"unknown"}]:[]],H=s.length;for(let[ne,oe]of D.entries())n.vars.set(V.name,oe),Ro(oe,V.alts[ne]??[]),n.frames.push({kind:"loop",phase:"body",cond:[],negate:!1}),Vt({...e,nodes:V.body},{...n},t,s),Js(n,"loop");!V.truncated&&V.values.length>1&&n.vars.set(V.name,Ro({kind:"value",value:V.values.at(-1)},[...V.values.slice(0,-1),...V.alts.flat()]));let ye=R[V.end];if(ye?.kind==="command"&&ye.words[0]?.text==="done"&&ye.redirections.some(Xs)){let ne=s.slice(H).filter(oe=>!oe.captured&&oe.pipeTo===null&&!oe.redirects.some(We=>Ys(We)));Qs({...ye,words:[]},n,t,s,null,ne)}k(),u.set(null),v=V.end,r=null,a=!1;continue}let F=C.words[0];if(F&&F.text==="case"&&F.provenance==="literal"&&!F.quoted){let D=C.words[1]?Me(C.words[1],n,t).text:"",H=C.words.slice(3).map(oe=>Me(oe,n,t).text).join(" "),ye=R[v+1],ne=ye?.kind==="connector"&&ye.operator==="|";n.frames.push({kind:"case",phase:H&&!ne?"body":"pattern",cond:[],negate:!1,word:D,pattern:H}),h(n.frames.length-1),H&&!ne&&ye&&ye.kind!=="command"&&v++,a||g(),u.set(null),r=null,a=!1;continue}if(B&&B.phase==="pattern"&&!(F&&F.text==="esac")){let D=C.words.map(H=>Me(H,n,t).text).join(" ");B.pattern=B.pattern?`${B.pattern}|${D}`:D,a=!1,r=null;continue}let U=n.frames.length;n.closed=null;let X=Ya(C,n,R,v,a?r:null);if(h(U),X){let D=n.closed,H=D?s.slice(Ks.get(D)??s.length):null;if(D&&C.redirections.some(Xs)){let ye=s.slice(Ks.get(D)??s.length).filter(ne=>!ne.captured&&ne.pipeTo===null&&!ne.redirects.some(oe=>Ys(oe)));Qs({...C,words:[]},n,t,s,null,ye)}a||g(),u.set(null),a=!1,r=null,H&&(o=H);continue}a||g(),b();let z=n.frames.length,G=R[v+1],ve=a||G?.kind==="connector"&&["|","|&","&"].includes(G.operator);n.maybeRuns=l||u.afterOr||ve,n.subshell=c||ve;let ue=Qs(C,n,t,s,a?r:null,q);n.maybeRuns=l,n.subshell=c,h(z),k();let Se=N||uh(C),xe=ue?`${Se?"! ":""}${bn(ue)}`:null;a?u.extend(xe):u.set(xe,!Se&&ch(ue)),r=ue??r,o=ue?[ue]:[],a=!1}}function cl(e,n,t){let s=new Set;for(let r of e.cds){let o=r.to===null?s.size>0?[He]:[]:"abs"in r.to?[]:[...s].map(a=>M(r.to.rel,a,t));s=new Set(n.includes(r.text)?o:[r.before,...s,...o]);for(let a of r.extra??[])s.add(a);s.size>8&&(s=new Set([He]))}return s.delete(e.cwd),[...s]}function $o(e,n,t){if(!n.subshell)for(let[s,r]of e.vars){if(Po.test(s)||e.locals.has(s)||t.get(s)===r)continue;let o={...r},a=n.vars.get(s)??null;n.vars.set(s,o),gt.set(o,{at:n.frames.map(i=>[i,i.phase]),guards:mt(n),maybe:!0,prev:a})}}function xo(e,n){n.cwd=e.cwd,n.oldCwd=e.oldCwd,n.dirStack=e.dirStack,n.cds=e.cds,n.cdpath=e.cdpath}function ph(e){let n=[];for(let t=0;t<e.length;t++){let s=e[t],r=e[t+1],o=e[t+2],a=s.kind==="command"&&["done","fi","esac"].includes(s.words[0]?.text??"");if((s.kind==="command"||s.kind==="group")&&!a&&r?.kind==="connector"&&r.operator==="&"&&o?.kind==="command"&&o.words.length===0&&r.span.end===o.span.start&&o.source.startsWith(">")){s.kind==="command"?n.push({...s,source:`${s.source} &${o.source}`,redirections:[...s.redirections,...o.redirections]}):n.push(s,o),t+=2;continue}n.push(s)}return n}function Xs(e){return e.fd===1||e.fd===void 0&&[">",">>",">|",">&"].includes(e.operator)}function ul(e){return e.nodes.some(n=>n.kind==="command"&&["done","fi","esac"].includes(n.words[0]?.text??"")&&n.redirections.some(Xs)||n.kind==="group"&&ul(n.body))}function dl(e,n){for(let t of e)t.stdinFile===null&&t.stdin===null&&t.pipeFrom===null&&!t.captured&&(t.stdinFile=n)}function hh(e){return(e.operator===">"||e.operator===">>"||e.operator===">|")&&(e.fd===void 0||e.fd===1)}function Ys(e){return e.fd===1||e.fd===null&&(e.op===">"||e.op===">>"||e.op===">|"||e.op===">&")}var _o=new WeakSet;function bn(e){return e.argv.map($).join(" ")}function Qs(e,n,t,s,r,o=null){for(let x of e.nested){let A={...n,vars:new Map(n.vars),depth:n.depth+1,via:"substitution",captured:!0,frames:[],outerGuards:mt(n),andGuards:[],errexit:!1,deferred:[]};Vt(x,A,t,s),tr(A,t,s)}let a=[...e.words];for(;a.length&&il.has(a[0].text)&&a[0].provenance==="literal"&&!a[0].quoted;)a.shift();if(a.length&&oh.has(a[0].text)&&a.length===1)return null;if(a[0]?.text==="for"||a[0]?.text==="select"){n.frames.push({kind:"loop",phase:"header",cond:[],negate:!1});let x=a[1]?.text,A=a.slice(a.findIndex(L=>L.text==="in")+1);x&&n.vars.set(x,A.length>0&&a.some(L=>L.text==="in")&&A.some(L=>L.provenance==="command-substitution")?{kind:"value",value:`${J}${A.map(L=>jo(L.raw,n,t)).join(" ")}${ee}`}:A.length>0&&A.every(L=>L.provenance==="literal"||L.provenance==="glob")?{kind:"list",values:A.map(L=>L.text)}:{kind:"unknown"});let j=a.findIndex((L,W)=>W>1&&L.text==="do"&&L.provenance==="literal"&&!L.quoted);if(j>0&&j<a.length-1){let L=Ct(n,"loop");return L&&(L.phase="body"),Qs({...e,words:a.slice(j+1)},n,t,s,null)}return null}let i=a.findIndex(x=>!/^[A-Za-z_][A-Za-z0-9_]*=/.test(x.raw)&&x.text!=="command"&&x.text!=="builtin");if(i>0&&["read","mapfile","readarray"].includes(a[i].text)&&(a=[...a.slice(i)]),(a[0]?.text==="mapfile"||a[0]?.text==="readarray")&&a[0].provenance==="literal"){let x=a.slice(1).filter((A,j,L)=>!A.text.startsWith("-")&&!["-d","-n","-O","-s","-u","-C","-c"].includes(L[j-1]?.text??"")).pop()?.text??"MAPFILE";/^[A-Za-z_][A-Za-z0-9_]*$/.test(x)&&ht(n,x,{kind:"unknown"})}if(a[0]?.text==="read"&&a[0].provenance==="literal"){let x=Ct(n,"loop"),A=x&&x.phase==="cond"?x.input??null:null,j=e.redirections.find(Q=>Q.operator==="<"&&Q.target),L=e.redirections.find(Q=>Q.operator==="<<<"&&Q.target),W=r?ll(r):j?.target?`cat ${Me(j.target,n,t).text}`:L?.target?$(Me(L.target,n,t).text):A,K=new Set(["-p","-d","-n","-N","-t","-u","-i"]);for(let Q=1;Q<a.length;Q++){let se=a[Q].text;if(K.has(se)){Q++;continue}se==="-a"||se.startsWith("-")||/^[A-Za-z_][A-Za-z0-9_]*$/.test(se)&&n.vars.set(se,W?{kind:"value",value:`${J}$(${W})${ee}`}:{kind:"unknown"})}}let l=0,c=[],u=new Set;for(;l<a.length&&/^[A-Za-z_][A-Za-z0-9_]*\+?=/.test(a[l].raw);){let x=a[l],A=x.raw.indexOf("=");x.raw[A-1]==="+"&&u.add(x),c.push([x.raw.slice(0,x.raw[A-1]==="+"?A-1:A),x]),l++}let p=a[l];if(p?.text==="getopts"&&a[l+2]&&ht(n,a[l+2].text,{kind:"unknown"}),p?.text==="let"||p?.raw.startsWith("(("))for(let x of a.slice(l))for(let A of x.raw.matchAll(/(?<![A-Za-z0-9_])([A-Za-z_][A-Za-z0-9_]*)\s*(?:[-+*\/%&|^]|<<|>>)?=(?!=)|(?<![A-Za-z0-9_])([A-Za-z_][A-Za-z0-9_]*)\s*(?:\+\+|--)|(?:\+\+|--)\s*([A-Za-z_][A-Za-z0-9_]*)/g))ht(n,A[1]??A[2]??A[3],{kind:"unknown"});let d=a.slice(l);if(d.length&&["export","local","declare","readonly","typeset"].includes(d[0].text)){let x=d[0].text,A=d.slice(1).filter(W=>W.text.startsWith("-")).map(W=>W.text),j=n.inFunction&&(x==="local"||(x==="declare"||x==="typeset")&&!A.some(W=>W.includes("g"))),L=A.some(W=>/^-[a-zA-Z]*n/.test(W));for(let W of d.slice(1)){let K=/^([A-Za-z_][A-Za-z0-9_]*)(=|$)/.exec(W.text);K&&(j&&n.locals.add(K[1]),L?ht(n,K[1],{kind:"unknown"}):K[2]==="="&&c.push([K[1],W]))}d=[]}let f=n.productionEnv,h=[];for(let[x,A]of c){let j=Ph(A,x,n,t),L=n.vars.get(x),W=u.has(A)?L?.kind==="value"&&j.kind==="value"?{kind:"value",value:L.value+j.value}:{kind:"unknown"}:j;if(d.length>0){W.production&&(f=!0),h.push([x,W]);continue}ht(n,x,W),x==="OLDPWD"&&d.length===0&&(n.oldCwd=W.kind==="value"&&!S(W.value)?W.value:He),x==="CDPATH"&&d.length===0&&(n.cdpath=!(W.kind==="value"&&W.value==="")),x==="IFS"&&d.length===0&&(n.ifs=W.kind==="value"&&W.value!==""&&!S(W.value)?W.value:null)}if(d.length===0&&c.length===0&&e.redirections.length>0&&(d=[{kind:"word",text:":",raw:":",span:e.span,provenance:"literal",quoted:!1,parts:[]}]),d.length===0)return null;let g=d.map(x=>Me(x,n,t)),b=n.ifs??`
|
|
19
|
+
`,k=new RegExp(`[${b.replace(/[\]\\^-]/g,"\\$&")}]+`),E=(x,A)=>x.flatMap((j,L)=>/^"?\$(@|\{@\})"?$/.test(d[L].raw)&&Oo.has(A.get("@"))?[...Oo.get(A.get("@"))]:/\$(@|\{@\})/.test(d[L].raw)&&!S(j.text)?j.text.split(/\s+/).filter(Boolean):!d[L].quoted&&(d[L].provenance==="variable"||d[L].provenance==="command-substitution")&&!S(j.text)&&k.test(j.text.trim())?j.text.trim().split(k).filter(Boolean):[j.text]),y=(x,A)=>Z()?E(x,A).map(nl):E(x,A),m=y(g,n.vars),R=mt(n),v=gl(d.map(x=>x.raw).join(" ")),C=n.frames.map(x=>[x,x.phase]),N=cl(n,R,t),q=v.has("PWD")&&!n.vars.has("PWD")?N.filter(x=>x!==null&&!S(x)):[],V=q.length>0||[...v].some(x=>{let A=n.vars.get(x);return A!==void 0&&!Eo(A,n,R,C)})?{...n,vars:new Map(n.vars)}:null,F=m,U=null,X=()=>U??=V?[...hl(V,v,C,R),...q.map(x=>new Map(V.vars).set("PWD",{kind:"value",value:x}))].map(x=>y(d.map(A=>Me(A,{...V,vars:x},t)),x)).filter(x=>x.join("\0")!==F.join("\0")):[],z=m.length;if(n.partial||n.posixOnly&&rh.has(d[0]?.text??""))for(let[x,A]of h)ht(n,x,A);let G=[...new Set(g.flatMap(x=>x.unresolved))],ve=e.redirections.map(x=>({op:x.operator,target:x.target?nl(Me(x.target,n,t).text):null,fd:x.fd??null})),ue=ve.find(x=>x.op==="<&"&&(x.fd===null||x.fd===0)&&/^\d+$/.test(x.target??"")),Se=(ue?ve.find(x=>(x.op==="<"||x.op==="<>")&&x.fd===Number(ue.target))?.target:ve.find(x=>(x.op==="<"||x.op==="<>")&&(x.fd===null||x.fd===0)&&x.target)?.target)??null,xe=e.redirections.find(x=>x.heredoc)?.heredoc??null,D=e.redirections.find(x=>x.operator==="<<<"&&x.target),H=xe?xe.body:D?.target?Me(D.target,n,t).text:null,ye=xe?"heredoc":D?"here-string":null,ne=[],oe=[],We;for(let x=0;m.length;x++){let A=he(m[0]);if(!ih.has(A))break;if(x>=th){n.bodyRead||(n.depthLimit.hit=!0);break}let j=A==="env"?m.findIndex(W=>W==="-S"||W==="--split-string"||W.startsWith("--split-string=")):-1;if(j>0){let W=m[j].startsWith("--split-string=")?m[j].slice(15):m[j+1]??"",K=m.slice(j+(m[j].includes("=")?1:2));ne.push(A),m=[...W.trim().split(/\s+/).filter(Boolean),...K];continue}if(A==="flock"){let W=1;for(;W<m.length&&m[W].startsWith("-")&&m[W]!=="--";)W+=al.has(m[W])?2:1;if((m[W+1]==="-c"||m[W+1]==="--command")&&m[W+2]!==void 0){ne.push(A),oe.push(...m.slice(1,W+2)),m=["sh","-c",m[W+2]];continue}}let L=yh(A,m);if(L===null)break;ne.push(A),oe.push(...m.slice(1,L)),Za.has(A)&&(We=m.slice(0,L+1)),m=m.slice(L),Za.has(A)&&m[0]!==void 0&&(m=[Ka(m[0]),...m.slice(1)])}m.length===0&&(m=[ne.pop()??""]);let T=Ch(he(m[0]??"")),Y={argv:m,name:T,wrappers:ne,wrapperArgs:oe,...We?{fetched:We}:{},cwd:n.cwd,redirects:ve,groupWriters:o,stdin:H,stdinKind:ye,stdinExpands:xe?!xe.quotedDelimiter:D!==void 0,via:n.via,remote:n.remote,productionEnv:f,pipeFrom:r,pipeTo:null,captured:n.captured,background:!1,unresolved:G,unreadableCode:null,text:e.source,guards:R,cwdFallbacks:N,altArgvs:[],stdinFile:Se,functionCall:!1,scriptText:null,scriptPath:null,parent:n.parent},ao=m.length,ba=null;V&&Object.defineProperty(Y,"altArgvs",{enumerable:!0,get:()=>ba??=X().map(x=>x.length===z?x.slice(z-ao):x)}),r&&(r.pipeTo=Y),s.push(Y),Dh(Y,n,t);let de=Ih(Y,n,t);de!==null&&(Y.scriptText=de.text,Y.scriptPath=de.path);let Ne=n.functions.get(m[0]??"");if(Ne&&ne.length===0&&!n.newProcess&&sr.get(n.functions)?.has(m[0])&&(Y.functionCall=!0),Ne&&n.depth>=So&&!n.called.has(m[0])&&!n.bodyRead&&(n.depthLimit.hit=!0),Ne&&n.depth<So){let x=n.called.has(m[0]);n.called.add(m[0]);let A=new Map([...n.vars,...h]);m.slice(1).forEach((W,K)=>A.set(String(K+1),Ro({kind:"value",value:W},[...new Set(Y.altArgvs.filter(Q=>Q.length===m.length).map(Q=>Q[K+1]).filter(Q=>Q!==W))]))),A.set("@",ol(m.slice(1)));let j={...n,vars:A,depth:n.depth+1,via:"shell-string",captured:!1,frames:[],outerGuards:Y.guards,andGuards:[],parent:Y,locals:new Set,inFunction:!0,bodyRead:n.bodyRead||x},L=new Map(A);Vt(Ne,j,t,s),xo(j,n),$o(j,n,L)}if((T==="cd"||T==="pushd"||T==="popd")&&ne.every(x=>x==="command"||x==="builtin")){let x=m.slice(1),A=x.find(se=>!se.startsWith("-")&&!se.startsWith("+")),j=x.some(se=>/^[+-]\d+$/.test(se)),L=n.cwd,W=null;T==="popd"?j?(n.cwd=He,n.dirStack=n.dirStack.map(()=>He)):n.dirStack.length>0&&(x.includes("-n")||(n.cwd=n.dirStack[n.dirStack.length-1]),n.dirStack=n.dirStack.slice(0,-1)):T==="pushd"&&x.includes("-n")?A!==void 0&&(n.dirStack=[...n.dirStack,M(A,n.cwd,t)]):T==="pushd"&&(j||A===void 0)?!j&&n.dirStack.length>0?(n.cwd=n.dirStack[n.dirStack.length-1],n.dirStack=[...n.dirStack.slice(0,-1),L]):j&&(n.cwd=He,n.dirStack=[...n.dirStack.map(()=>He),He]):(x.includes("-")?n.cwd=n.oldCwd:A!==void 0&&/^~[-+](\/|$)/.test(A)?n.cwd=M(`.${A.slice(2)}`,A[1]==="-"?n.oldCwd:n.cwd,t):A!==void 0&&n.cdpath&&!A.startsWith("/")&&!A.startsWith("~")?n.cwd=He:n.cwd=A===void 0?t.home:M(A,n.cwd,t),T==="pushd"&&(n.dirStack=[...n.dirStack,L]),!x.includes("-")&&!n.cdpath&&(W=A===void 0||A.startsWith("/")||/^~(\/|$)/.test(A)?{abs:n.cwd??""}:/^~[-+]/.test(A)?null:{rel:A}));let K=A===void 0?-1:m.indexOf(A),Q=K<0?[]:[...new Set(Y.altArgvs.filter(se=>se.length===m.length).map(se=>se[K]).filter(se=>se!==A))].map(se=>se===""?L:M(se,L,t));(n.cwd!==L||Q.length>0)&&(n.cwd!==L&&(n.oldCwd=L),n.cds=[...n.cds,{text:bn(Y),before:L,to:W,extra:Q}])}if(T==="dirs"&&ne.length===0&&m.slice(1).some(x=>/^-[a-z]*c/.test(x))&&(n.dirStack=[]),T==="unset"&&!m.slice(1).some(x=>/^-[a-z]*f/.test(x)))for(let x of m.slice(1))/^[A-Za-z_][A-Za-z0-9_]*$/.test(x)&&ht(n,x,{kind:"value",value:""});if(T==="unset"||T==="unfunction")for(let x of m.slice(1))sr.get(n.functions)?.delete(x);if((T==="shift"||T==="set"&&m.slice(1).some(x=>x==="--"||!/^[-+]./.test(x)))&&er(n.vars),T==="printf"){let x=m.findIndex(j=>j==="-v"),A=x>0?m[x+1]:m.find(j=>/^-v[A-Za-z_]/.test(j))?.slice(2);A&&/^[A-Za-z_][A-Za-z0-9_]*$/.test(A)&&ht(n,A,{kind:"unknown"})}if(T==="set"&&ne.length===0){let x=m.slice(1);x.some((A,j)=>/^-[a-zA-Z]*e[a-zA-Z]*$/.test(A)||A==="-o"&&x[j+1]==="errexit")&&(n.errexit=!0),x.some((A,j)=>/^\+[a-zA-Z]*e[a-zA-Z]*$/.test(A)||A==="+o"&&x[j+1]==="errexit")&&(n.errexit=!1)}let Us=[],ie=(x,A={})=>{let j={...n,vars:new Map([...n.vars,...h]),locals:new Set,maybeRuns:!1,subshell:!1,inFunction:!1,newProcess:!0,depth:n.depth+1,via:x,captured:!1,frames:[],outerGuards:Y.guards,andGuards:[],parent:Y,errexit:!1,deferred:[],...A};return j.deferred!==n.deferred&&Us.push(j),j};if(de!==null&&de.shell&&Z()&&/\.(?:ps1|psm1|bat|cmd)$/i.test(de.path))ns(/\.(?:bat|cmd)$/i.test(de.path)?"cmd":"powershell",de.text,Y,n,t,x=>be(x,ie("shell-string"),t,s));else if(de!==null&&de.shell){let x=de.direct?0:m.findIndex((Q,se)=>se>0&&!Q.startsWith("-")),A=new Map([...n.vars,...h]),j=x>=0?m.slice(x+1):[];j.forEach((Q,se)=>A.set(String(se+1),{kind:"value",value:Q})),A.set("@",ol(j));let L=de.direct&&/^#!\s*\S*\/(?:env\s+)?(sh|dash|ksh|ash|mksh)\b/.test(de.text),W=ie("shell-string",{vars:A,posixOnly:Ga.has(T)||L||(T==="source"||T===".")&&n.posixOnly,...T==="source"||T==="."?{errexit:n.errexit,deferred:n.deferred,newProcess:n.newProcess}:{}}),K=new Map(A);be(de.text,W,t,s),(T==="source"||T===".")&&(xo(W,n),$o(W,n,K))}else if((T==="source"||T===".")&&ne.length===0){n.cwd=He;for(let x of[...n.vars.keys()])n.vars.set(x,{kind:"unknown"})}if(T==="osascript"){let x=m.slice(1).filter((A,j,L)=>L[j-1]==="-e").join(`
|
|
20
|
+
`);for(let A of x.matchAll(/do\s+shell\s+script\s+"((?:\\.|[^"\\])*)"/gi))be(A[1].replace(/\\(.)/g,"$1"),ie("shell-string"),t,s)}if(Ah.has(T)){let x=Wo(m);if(x!==null)for(let A of Eh(x))be(A,ie("shell-string"),t,s)}if(yn.has(T)||T==="at"||T==="batch"){let x=yn.has(T)?wn(m):null,A=x?.command??null,j=T==="at"||T==="batch"||(x?.stdin??!1),L=Ga.has(T);if(A!==null){Xa(A)&&!Ja(A)&&(Y.unreadableCode=`${T} -c ${$(A).slice(0,80)}`);let W=m.slice(m.indexOf(A)+1),K=new Map([...n.vars,...h]);W.length>0&&(er(K),/\bshift\b/.test(A)||W.forEach((Q,se)=>K.set(String(se),Q.includes("{}")?{kind:"unknown"}:{kind:"value",value:Q}))),be(A,ie("shell-string",{posixOnly:L,vars:K}),t,s)}else if(H!==null&&j)be(H,ie("stdin-script",{posixOnly:L}),t,s);else if(r&&j){let W=Ao(r);W!==null?be(W,ie("stdin-script",{posixOnly:L}),t,s):["curl","wget","fetch","http","https","xh","aria2c"].includes(r.name)||(Y.unreadableCode=`${T} reading a script from ${r.name}`)}}else if(T==="trap"&&m.length>=3&&!m[1].startsWith("-"))n.deferred.push({code:m[1],parent:Y,errexit:n.errexit});else if(T==="eval"){let x=/^"?\$\{?([A-Za-z_][A-Za-z0-9_]*)\}?"?$/.exec(d[1]?.raw??"")?.[1],A=x?n.vars.get(x):void 0,j=A?.kind==="list"&&d.length===2?[...A.values]:[m.slice(1).join(" ")];for(let L of j){Xa(L)&&!Ja(L)&&(Y.unreadableCode=`eval ${$(L).slice(0,80)}`);let W=ie("shell-string",{errexit:n.errexit,locals:n.locals,inFunction:n.inFunction,newProcess:n.newProcess,deferred:n.deferred}),K=new Map(W.vars);if(be(L,W,t,s),S(L)){n.cwd=He;for(let Q of[...n.vars.keys()])n.vars.set(Q,{kind:"unknown"})}else xo(W,n),$o(W,n,K),[...W.vars].some(([Q,se])=>Po.test(Q)&&K.get(Q)!==se)&&er(n.vars)}}else if(T==="flock"||T==="script"){let x=m.findIndex(A=>A==="-c"||A==="--command");if(x>0&&m[x+1]!==void 0)be(m[x+1],ie("shell-string"),t,s);else if(T==="flock"){let A=1;for(;A<m.length&&m[A].startsWith("-");)A+=["-w","--timeout","-E","--conflict-exit-code"].includes(m[A])?2:1;A+1<m.length&&it(m.slice(A+1),ie("shell-string"),t,s,null)}}else if(Z()&&(T==="cmd"||T==="powershell"||T==="pwsh")){let x=Oh(T,m),A=j=>ns(T==="cmd"?"cmd":"powershell",j,Y,n,t,L=>be(L,ie("shell-string"),t,s));if(x?.kind==="line")A(x.text);else if(x?.kind==="file"){let j=sl(x.path,Y,n,t);j!==null&&A(j)}else if(x?.kind==="unreadable")Y.unreadableCode=`${T}: ${x.why}`;else if(H!==null)A(H);else if(r){let j=Ao(r);j!==null?A(j):Y.unreadableCode=`${T} reading its commands from ${r.name}`}else if(Y.stdinFile!==null){let j=sl(Y.stdinFile,Y,n,t);j!==null&&A(j)}}else if(Z()&&T==="wmic"&&m.some(x=>/^process$/i.test(x))&&m.some(x=>/^create$/i.test(x))){let x=m.findIndex(A=>/^create$/i.test(A));m[x+1]!==void 0&&ns("cmd",m.slice(x+1).join(" "),Y,n,t,A=>be(A,ie("shell-string"),t,s))}else if(Z()&&T==="robocopy"&&m.some(x=>/^\/{1,2}mov(?:e)?$/i.test(x))){let[x,A]=m.slice(1).filter(L=>!/^\/{1,2}[A-Za-z]+(?::.*)?$/.test(L)),j=L=>`'${L.replace(/'/g,"'\\''")}'`;x!==void 0&&A!==void 0&&be(`mv ${j(x)} ${j(A)}`,ie("shell-string"),t,s)}else if(Z()&&T==="forfiles"){let x=K=>{let Q=m.findIndex(se=>new RegExp(`^/{1,2}${K}$`,"i").test(se));return Q>0?m[Q+1]:m.find(se=>new RegExp(`^/{1,2}${K}\\S`,"i").test(se))?.replace(new RegExp(`^/{1,2}${K}`,"i"),"")},A=(x("p")??".").replace(/(?<![\\/])[\\/]+$/,""),j=x("m")??"*",W=(x("c")??"cmd /c echo @file").replace(/@path/gi,`"${A}\\${j}"`).replace(/@relpath/gi,`".\\${j}"`).replace(/@(?:file|fname)/gi,`"${j}"`).replace(/@ext/gi,'"*"');ns("cmd",W,Y,n,t,K=>be(K,ie("shell-string"),t,s))}else if(Z()&&T==="schtasks"&&m.some(x=>/^\/{1,2}(?:create|change)$/i.test(x))){let x=m.findIndex(A=>/^\/{1,2}tr$/i.test(A));x>0&&m[x+1]!==void 0&&ns("cmd",m[x+1],Y,n,t,A=>be(A,ie("shell-string"),t,s))}else if(T==="watch"){let x=new Set(["-n","--interval","-d","--differences","-q","--equexit","-g","-c","-x","-t","-b","-e","-p"]),A=1;for(;A<m.length&&m[A].startsWith("-");)A+=["-n","--interval","-q","--equexit"].includes(m[A])?2:1;A<m.length&&be(m.slice(A).join(" "),ie("shell-string"),t,s)}else if(T==="git"&&m.some((x,A)=>m[A-1]==="-c"&&x.startsWith("alias."))){let x=gh(m);x&&be(x,ie("shell-string"),t,s)}else if(T==="xargs"){let x=kh(m),A=m.find((W,K)=>m[K-1]==="-d"||m[K-1]==="--delimiter")??m.find(W=>/^-d./.test(W))?.slice(2)??m.find(W=>W.startsWith("--delimiter="))?.slice(12),j=H!==null&&!S(H)?(m.includes("-0")?H.split("\0"):A?H.split(A.replace(/^\\n$/,`
|
|
21
|
+
`)):H.split(/\s+/)).map(W=>W.trim()).filter(Boolean):null,L=m.find((W,K)=>m[K-1]==="-I")??m.find(W=>/^-I./.test(W))?.slice(2)??m.find(W=>W.startsWith("--replace="))?.slice(10)??(m.includes("-i")||m.includes("--replace")?"{}":null);if(x.length&&j&&L)for(let W of j)it(x.map(K=>K.split(L).join(W)),ie("xargs"),t,s,Y);else x.length&&it(j?[...x,...j]:x,ie("xargs"),t,s,Y)}else if(T==="find")for(let x of vh(m))it(x,ie("find-exec"),t,s,null);else if(T==="fd"||T==="fdfind")for(let x of $h(m))it(x,ie("find-exec"),t,s,null);else if(T==="ssh"){let x=xh(m);x&&x.command&&be(x.command,ie("remote",{remote:x.host,cwd:null}),t,s)}else if((T==="docker"||T==="podman")&&m[1]==="run"&&tl(m).length>0){let x=_h(m);if(x){let A=tl(m),j=x.map(L=>A.reduce((W,K)=>W.replace(new RegExp(`(^|[\\s'"=])${K.target.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}(?=/|$|[\\s'"])`,"g"),`$1${K.source}`),L));it(j,ie("remote",{remote:null,cwd:null}),t,s,null)}}else if((T==="docker"||T==="podman")&&el(m).sub==="exec"){let{at:x,remoteHost:A}=el(m),j=Sh([m[0],...m.slice(x)]);j&&it(j.argv,ie("remote",{remote:A!==null?`docker:${A}`:`container:${j.container}`,cwd:null}),t,s,null)}else if((T==="kubectl"||T==="oc")&&Qa(m,bh)==="exec"){let x=m.indexOf("--");x>0&&it(m.slice(x+1),ie("remote",{remote:"kubernetes",cwd:null}),t,s,null)}else if((T==="fly"||T==="flyctl")&&Qa(m,wh)==="ssh"){let x=m.findIndex(L=>L==="-C"||L==="--command"),A=x>0?m[x+1]:m.find(L=>L.startsWith("--command="))?.slice(10),j=m.find((L,W)=>m[W-1]==="-a"||m[W-1]==="--app")??m.find(L=>L.startsWith("--app="))?.slice(6);A&&be(A,ie("remote",{remote:j&&/^[\w.-]+$/.test(j)?`the Fly app ${j}`:"a Fly machine",cwd:null}),t,s)}else if(T==="railway"&&m[1]==="run"){let x=m.slice(2).filter((j,L,W)=>!(j.startsWith("-")&&L===0)||W.length===1),A=m.slice(2).findIndex(j=>!j.startsWith("-"));A>=0&&it(m.slice(2+A),ie("shell-string",{productionEnv:!0}),t,s,null)}else if(["doppler","infisical"].includes(T)&&m[1]==="run"){let x=m.findIndex(j=>j==="--command"||j.startsWith("--command=")),A=x<0?null:m[x].startsWith("--command=")?m[x].slice(10):m[x+1]??null;A&&be(A,ie("shell-string"),t,s)}else if(["npm","pnpm","yarn","bun"].includes(T)&&["exec","dlx","x"].includes(nr(m).sub)){let x=nr(m).at,A=m.slice(x+1).findIndex(j=>!j.startsWith("-"));A>=0&&it([Ka(m[x+1+A]),...m.slice(x+2+A)],ie("shell-string"),t,s,null)}for(let x of Us)tr(x,t,s);return Y.stdinFile!==null&&dl(s.filter(x=>{for(let A=x.parent;A;A=A.parent)if(A===Y)return!0;return!1}),Y.stdinFile),Y}function Ja(e){let n=$(e.trim()),t=/^\$\(\s*([^\s)]+)([^)]*)\)?/.exec(n)??/^`\s*([^\s`]+)([^`]*)`?/.exec(n);if(!t)return!1;let s=he(t[1]),r=t[2].split(/\s+/);return["ssh-agent","direnv","starship","fnm","mise","rtx","pyenv","rbenv","nodenv","goenv","jenv","opam","zoxide","atuin","thefuck","keychain","gpg-agent"].includes(s)||r.some(o=>["shellenv","activate","hook"].includes(o))||r[0]==="init"&&r.length<=3}function Xa(e){return e.trimStart().startsWith(J)}function Ao(e){if(e.name==="echo"||e.name==="printf"){let n=e.argv.slice(1).filter(t=>!/^-[neE]+$/.test(t));return n.some(S)?null:e.name==="printf"&&n[0]?.includes("%")?n.slice(1).join(`
|
|
22
|
+
`):n.join(" ").replace(/\\n/g,`
|
|
23
|
+
`)}if(e.name==="base64"&&e.argv.some(n=>n==="-d"||n==="-D"||n==="--decode")&&e.pipeFrom){let n=Ao(e.pipeFrom);if(n===null)return null;try{return Buffer.from(n.trim(),"base64").toString("utf8")}catch{return null}}if(e.stdin!==null&&e.name==="base64"&&e.argv.some(n=>n==="-d"||n==="-D"||n==="--decode"))try{return Buffer.from(e.stdin.trim(),"base64").toString("utf8")}catch{return null}return null}function gh(e){let n=new Map,t=1;for(;t<e.length&&e[t].startsWith("-");)if(e[t]==="-c"&&e[t+1]){let a=/^alias\.([^=]+)=(.*)$/s.exec(e[t+1]);a&&n.set(a[1],a[2]),t+=2}else t+=e[t]==="-C"?2:1;let s=e[t],r=s?n.get(s):void 0;if(r===void 0)return null;let o=e.slice(t+1).join(" ");return r.startsWith("!")?`${r.slice(1)} ${o}`:`git ${r} ${o}`}function it(e,n,t,s,r){if(!e.length)return;let o=e.map(mh).join(" "),a=s.length;be(o,n,t,s);let i=s[a];i&&r?.pipeFrom?i.pipeFrom=r.pipeFrom:i&&r?.stdinFile&&(i.stdinFile=r.stdinFile)}function mh(e){return/^[A-Za-z0-9_\-./=:@%+,~]+$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}function wn(e){let n=!1,t=!1;for(let s=1;s<e.length;s++){let r=e[s];if(r==="--"||r==="-"){let o=e[s+1];return n?{command:o??null,script:null,stdin:!1}:{command:null,script:t?null:o??null,stdin:t||o===void 0}}if(r==="--rcfile"||r==="--init-file"){s++;continue}if(!r.startsWith("--")){if(/^[-+][a-zA-Z]+$/.test(r)){r.startsWith("-")&&r.includes("c")&&(n=!0),r.startsWith("-")&&r.includes("s")&&(t=!0),/[oO]/.test(r.slice(1))&&s++;continue}return n?{command:r,script:null,stdin:!1}:{command:null,script:t?null:r,stdin:t}}}return{command:null,script:null,stdin:!n}}function yh(e,n){let t=1,r={sudo:new Set(["-u","-g","-C","-D","-h","-p","-r","-t","-U","--user","--group","--host","--prompt"]),doas:new Set(["-u","-C"]),pkexec:new Set(["--user","-u"]),run0:new Set(["-u","--user","-g","--group","-D","--chdir","--unit","--property","--description","--slice","--nice","--setenv"]),env:new Set(["-u","-C","-S","--unset","--chdir","--split-string"]),nice:new Set(["-n","--adjustment"]),ionice:new Set(["-c","-n","-p"]),timeout:new Set(["-s","-k","--signal","--kill-after"]),gtimeout:new Set(["-s","-k","--signal","--kill-after"]),stdbuf:new Set(["-i","-o","-e"]),exec:new Set(["-a"]),script:new Set(["-c","-t"]),npx:new Set(["-p","--package","-c","--call","--registry","--cache","--prefix","--userconfig","--workspace","-w","--node-options"]),pnpx:new Set(["--package","--registry","--cache","--prefix","--userconfig","--workspace","-w"]),bunx:new Set(["-p","--package","--cwd","--registry","--cache-dir"]),uv:new Set(["--from","--with","--python","-p","--directory","--project","--index","--index-url","--env-file"]),uvx:new Set(["--from","--with","--python","-p","--directory","--index","--index-url"]),pipx:new Set(["--spec","--python","--index-url","--pip-args"]),poetry:new Set(["-C","--directory","-P","--project"]),pdm:new Set(["-p","--project"]),op:new Set(["--env-file","--account","--cache","--config","--encoding","--session"]),doppler:new Set(["-c","--config","-p","--project","--command","--mount","--mount-format","--mount-template","--mount-max-reads","--fallback","--token","--scope","--name-transformer"]),infisical:new Set(["--env","--projectId","--path","--token","--domain","--command","--tags"]),dotenvx:new Set(["-f","--env-file","-e","--env","--convention"]),dotenv:new Set(["-e","-c","-v","-p","-f","--file"]),sshpass:new Set(["-p","-f","-d","-P"]),"aws-vault":new Set(["-d","--duration","--region","-t","--mfa-token","--backend","--prompt"]),"sandbox-exec":new Set(["-f","-n","-p","-D"]),flock:al,chrt:new Set(["-T","--sched-runtime","-P","--sched-period","-D","--sched-deadline"]),unshare:new Set(["-S","--setuid","-G","--setgid","-R","--root","-w","--wd"]),"systemd-inhibit":new Set(["--what","--who","--why","--mode"])}[e]??new Set;if(e==="launchctl")return(n[1]==="asuser"||n[1]==="bsexec")&&n.length>3?3:null;if((e==="taskset"||e==="chrt"||e==="prlimit")&&n.slice(1).some(a=>a==="-p"||a==="--pid"||a.startsWith("--pid="))||e==="systemd-inhibit"&&n.includes("--list"))return null;if(e==="uv")if(n[1]==="run")t=2;else if(n[1]==="tool"&&n[2]==="run")t=3;else return null;let o={bundle:"exec",poetry:"run",pdm:"run",rye:"run",pipx:"run",op:"run",doppler:"run",infisical:"run",dotenvx:"run"};if(o[e]!==void 0){let a=1;for(;a<n.length&&n[a].startsWith("-");)a+=r.has(n[a])?2:1;if(n[a]!==o[e])return null;t=a+1}if(e==="aws-vault"){if(n[1]!=="exec")return null;for(t=2;t<n.length&&n[t].startsWith("-")&&n[t]!=="--";)t+=r.has(n[t])?2:1;return t++,n[t]==="--"&&t++,t<n.length?t:null}if(e==="cross-env"){for(;t<n.length&&/^[A-Za-z_][A-Za-z0-9_]*=/.test(n[t]);)t++;return t<n.length?t:null}for(;t<n.length;){let a=n[t];if(a==="--")return t+1<n.length?t+1:null;if(e==="env"&&/^[A-Za-z_][A-Za-z0-9_]*=/.test(a)){t++;continue}if((e==="timeout"||e==="gtimeout")&&/^\d+(\.\d+)?[smhd]?$/.test(a)&&!n.slice(1,t).some(i=>/^\d/.test(i))){t++;continue}if(e==="nice"&&/^-\d+$/.test(a)){t++;continue}if(a.startsWith("-")&&a.length>1){t+=r.has(a)?2:1;continue}break}if(e==="dotenv"){if(["list","get","set","unset"].includes(n[t]??""))return null;if(n[t]==="run"){for(t++;t<n.length&&n[t].startsWith("-")&&n[t]!=="--";)t++;n[t]==="--"&&t++}return t<n.length?t:null}return e==="npx"||e==="pnpx"||e==="bunx"?t<n.length?t:null:e==="script"?n.slice(1,t).some(a=>a==="-c"||a==="--command")?null:t+1<n.length?t+1:null:e==="taskset"||e==="chrt"||e==="flock"?t+1<n.length?t+1:null:t<n.length?t:null}var bh=new Set(["-n","--namespace","--context","--cluster","--kubeconfig","--user","-s","--server","--as","--request-timeout"]),wh=new Set(["-a","--app","-c","--config","-t","--access-token","-r","--region","--org"]);function Qa(e,n){for(let t=1;t<e.length;t++){let s=e[t];if(s==="--")return;if(!s.startsWith("-"))return s;!s.includes("=")&&n.has(s)&&t++}}function el(e){let n=new Set(["-H","--host","--context","-c","--config","-l","--log-level","--tlscacert","--tlscert","--tlskey"]),t=1,s=null;for(;t<e.length&&e[t].startsWith("-");){let r=e[t],o=r.indexOf("="),a=o>0?r.slice(0,o):r,i=o>0?r.slice(o+1):e[t+1];["-H","--host","--context","-c"].includes(a)&&i&&!/^(default|desktop-linux|colima|orbstack|unix:\/\/.*)$/.test(i)&&(s=i),t+=o<0&&n.has(r)?2:1}return{sub:e[t]??"",at:t,remoteHost:s}}function kh(e){let n=new Set(["-n","-P","-L","-s","-I","-E","-d","-a","--max-args","--max-procs","--delimiter","--arg-file","--replace"]),t=1;for(;t<e.length&&e[t].startsWith("-");)t+=n.has(e[t])?2:1;return e.slice(t)}function vh(e){let n=[];for(let t=1;t<e.length;t++)if(["-exec","-execdir","-ok","-okdir"].includes(e[t])){let s=e.findIndex((r,o)=>o>t&&(r===";"||r==="+"||r==="\\;"));n.push(e.slice(t+1,s===-1?e.length:s)),s!==-1&&(t=s)}return n}function $h(e){let n=e.findIndex((s,r)=>r>0&&["-x","--exec","-X","--exec-batch"].includes(s));if(n<0)return[];let t=e.findIndex((s,r)=>r>n&&(s===";"||s==="\\;"));return[e.slice(n+1,t===-1?e.length:t)]}function xh(e){let n=new Set(["-b","-c","-D","-E","-e","-F","-I","-i","-J","-L","-l","-m","-O","-o","-p","-Q","-R","-S","-W","-w","-B"]),t=1;for(;t<e.length&&e[t].startsWith("-");)t+=n.has(e[t])?2:1;let s=e[t];if(!s)return null;let r=e.slice(t+1);return{host:s,command:r.length?r.join(" "):null}}function tl(e){let n=[];for(let t=2;t<e.length;t++){let s=e[t],r=s==="-v"||s==="--volume"?e[t+1]:s.startsWith("--volume=")?s.slice(9):/^-v./.test(s)?s.slice(2):null;if(r){let[a,i]=r.split(":");a&&i&&(a.startsWith("/")||a.startsWith("~")||S(a))&&n.push({source:a,target:i.replace(/\/$/,"")||"/"})}let o=s==="--mount"?e[t+1]:s.startsWith("--mount=")?s.slice(8):null;if(o&&/type=bind/.test(o)){let a=/(?:source|src)=([^,]+)/.exec(o)?.[1],i=/(?:target|dst|destination)=([^,]+)/.exec(o)?.[1];a&&i&&n.push({source:a,target:i.replace(/\/$/,"")||"/"})}}return n}function _h(e){let n=new Set(["-v","--volume","--mount","-e","--env","-w","--workdir","--name","-p","--publish","--network","--net","-u","--user","--entrypoint","--env-file","-l","--label","--platform","--memory","-m","--cpus","--add-host","--hostname","-h","--device","--restart","--pid","--ipc","--cap-add","--cap-drop","--security-opt","--tmpfs","--log-driver","--ulimit"]),t=2;for(;t<e.length&&e[t].startsWith("-");)t+=n.has(e[t])?2:1;return t+1<e.length?e.slice(t+1):null}function Sh(e){let n=new Set(["-e","--env","-u","--user","-w","--workdir","--env-file"]),t=2;for(;t<e.length&&e[t].startsWith("-");)t+=n.has(e[t])?2:1;let s=e[t];return!s||t+1>=e.length?null:{container:s,argv:e.slice(t+1)}}function he(e){let n=e.lastIndexOf("/"),t=n>=0?e.slice(n+1):e;return Z()?t.slice(t.lastIndexOf("\\")+1).toLowerCase().replace(/\.(?:exe|cmd|bat|com)$/,""):t}function nl(e){if(!Z()||!e.includes("\\")||/^(?:HK(?:LM|CU|CR|U|CC)|HKEY_|Registry::)/i.test(e))return e;let n=/^(-[\w-]*=)?(.*)$/s.exec(e),t=n[2];return/^(?:[A-Za-z]:\\|\\\\|\.{1,2}\\|~\\)/.test(t)||/^[\w .()$@{}~-]+(?:\\[\w .()$@{}~-]+)+\\?$/.test(t)?`${n[1]??""}${t.replace(/\\/g,"/")}`:e}function Ch(e){if(e==="python"||e==="python3")return e;if(/^python\d+(?:\.\d+)*[tdmu]?$/.test(e)||/^pypy\d*(?:\.\d+)*$/.test(e))return"python3";if(/^node(?:js|\d+(?:\.\d+)*)$/.test(e))return"node";let n=/^(ruby|perl|php|bash|zsh|ksh|gawk)\d+(?:\.\d+)*$/.exec(e);return n?n[1]:e}var Ah=new Set(["awk","gawk","mawk","nawk","busybox-awk"]);function Wo(e){let n=[];for(let t=1;t<e.length;t++){let s=e[t];if(s==="-f"||s==="--file"||s.startsWith("--file="))return null;if(s==="-e"||s==="--source")n.push(e[++t]??"");else if(s.startsWith("--source="))n.push(s.slice(9));else if(["-F","-v","-i","--include","-l","--load","--assign","--field-separator"].includes(s))t++;else if(s==="--"){n.length===0&&e[t+1]!==void 0&&n.push(e[t+1]);break}else if(!s.startsWith("-")){n.length===0&&n.push(s);break}}return n.length>0?n.join(`
|
|
24
|
+
`):null}function Eh(e){let n=s=>{let r="";for(let o of s.matchAll(/"((?:\\.|[^"\\])*)"|([^\s"]+)/g))r+=o[1]!==void 0?o[1].replace(/\\(.)/g,"$1"):'"$(unknown)"';return r},t=[];for(let s of e.matchAll(/\bsystem\s*\(([^()]*)\)/g))t.push(n(s[1]));for(let s of e.matchAll(/\|&?\s*((?:"(?:\\.|[^"\\])*"\s*)+)/g))t.push(n(s[1]));for(let s of Rh(e))t.push(n(s));for(let s of e.matchAll(/\bprintf?\s*\(?\s*((?:"(?:\\.|[^"\\])*"|[^;}|"()])+?)\)?\s*\|&?\s*"\s*(?:\/\S*\/)?(?:ba|z|da|k|mk|a)?sh\b[^"]*"/g))t.push(n(s[1]));return[...new Set(t.map(s=>s.trim()).filter(Boolean))]}function S(e){return e.includes(J)}function $(e){return e.replace(new RegExp(`${J}([^${ee}]*)${ee}`,"g"),"$1")}function Rh(e){let n=[],t=-1,s=-1,r=0;for(;r<e.length;){let o=e[r];if(o==='"'){let a=r+1;for(;a<e.length&&e[a]!=='"';)a+=e[a]==="\\"?2:1;if(a>=e.length)break;t<0&&(t=r),s=a+1,r=a+1;continue}if(o===" "||o===" "||o===`
|
|
25
|
+
`||o==="\r"){r++;continue}o==="|"&&t>=0&&/^\|&?\s*getline\b/.test(e.slice(r,r+64))&&n.push(e.slice(t,s)),t=-1,r++}return n}function M(e,n,t){if(Z())return jh(e,n,t);let s=e;if(s==="~"||s.startsWith("~/"))s=t.home+s.slice(1);else if(s.startsWith("~")){let o=s.indexOf("/");return`${J}${o<0?s:s.slice(0,o)}${ee}${o<0?"":s.slice(o)}`}if(S(s)&&!s.startsWith("/"))return s;s.startsWith("/")||(s=ss.join(n??".",s));let r=ss.normalize(s);return r.length>1&&r.endsWith("/")?r.slice(0,-1):r}function Oh(e,n){let t=n.map((a,i)=>i===0?a:/^\/\/[^/]+$/s.test(a)?a.slice(1):a.replace(/^\/([A-Za-z])(?=\/)/,(l,c)=>`${c.toUpperCase()}:`));if(e==="cmd"){for(let a=1;a<t.length;a++){let i=/^\/([ck])(.*)$/is.exec(t[a]);if(i)return{kind:"line",text:[i[2],...t.slice(a+1)].filter(l=>l!=="").join(" ")};if(!t[a].startsWith("/"))break}return null}let s=a=>/^(?:--|[-\u2013\u2014\u2015/])[A-Za-z]/.test(a)?a.replace(/^(?:--|[-\u2013\u2014\u2015/])/,"").toLowerCase():null,r=(a,i,l)=>{let c=s(a);return c!==null&&c.length>=l&&i.startsWith(c)},o=[["executionpolicy",2],["ep",2],["windowstyle",1],["version",1],["inputformat",2],["outputformat",1],["psconsolefile",2],["configurationname",4],["workingdirectory",2],["wd",2],["settingsfile",2],["custompipename",2]];for(let a=1;a<t.length;a++){let i=t[a];if(r(i,"encodedcommand",1)||/^(?:--|[-\u2013\u2014\u2015/])(?:ec|enc)$/i.test(i)){let l=t[a+1]??"";return!/^[A-Za-z0-9+/]+={0,2}$/.test(l)||l.length%4!==0?{kind:"unreadable",why:"an encoded command that is not base64"}:{kind:"line",text:Buffer.from(l,"base64").toString("utf16le")}}if(r(i,"command",1)){let l=t.slice(a+1);return l.length===1&&l[0]==="-"?null:{kind:"line",text:l.join(" ")}}if(r(i,"file",1))return t[a+1]===void 0||t[a+1]==="-"?null:{kind:"file",path:t[a+1]};if(s(i)!==null){o.some(([l,c])=>r(i,l,c))&&a++;continue}return e==="pwsh"?{kind:"file",path:i}:{kind:"line",text:t.slice(a).join(" ")}}return null}function ns(e,n,t,s,r,o){let a=s.cwd!==null&&!S(s.cwd)?pt(s.cwd):null,i=e==="cmd"?qa(n,{cwd:a}):pn(n,{cwd:a});i.kind==="shell"?o(i.text):t.unreadableCode=`${e==="cmd"?"cmd":"PowerShell"}: ${i.why}`}function sl(e,n,t,s){if(S(e))return n.unreadableCode=`a script whose name the line does not show (${$(e).slice(0,80)})`,null;let r=M(e,n.cwd,s),o=t.files.get(r);return o!==void 0?o:(S(r)||s.wantFiles?.add(r),s.unreadableFiles?.includes(r)&&(n.unreadableCode=`${he(r)}, a script this session wrote that could not be read`),null)}function jh(e,n,t){if(/^nul(?:\.[^\\/]*)?$/i.test(e))return"/dev/null";let s=Ge(e);if(s===null)return`${J}${e.slice(0,2)}${ee}/${e.slice(2).replace(/\\/g,"/")}`;let r=s;if(r==="~"||r.startsWith("~/"))r=t.home+r.slice(1);else if(r.startsWith("~")){let o=r.indexOf("/");return`${J}${o<0?r:r.slice(0,o)}${ee}${o<0?"":r.slice(o)}`}if(S(r)&&!r.startsWith("/"))return r;if(!r.startsWith("/")){let o=n!==null?/^(\/[a-z]|\/unc\/[^/]+\/[^/]+)(\/.*)?$/s.exec(n):null;r=o?`${o[1]}${ss.normalize(`/${o[2]??""}/${r}`)}`:ss.join(n??".",r)}return Ge(r)??r}function Ph(e,n,t,s){let r=e.raw.slice(e.raw.indexOf("=")+1);if(Qp.test(r))return{kind:"unknown",production:!0};if([...r.matchAll(/\$\{?([A-Za-z_][A-Za-z0-9_]*)/g)].some(l=>t.vars.get(l[1])?.production))return{kind:"unknown",production:!0};if(/^["']?\$\(\s*mktemp\b/.test(r)||/^["']?`\s*mktemp\b/.test(r))return{kind:"value",value:ss.join(s.tmpdir,`${n}.mktemp`)};if(/^["']?(\$\(\s*pwd\s*\)|`\s*pwd\s*`)["']?$/.test(r)||/^["']?\$(PWD|\{PWD\})["']?$/.test(r)&&!t.vars.has("PWD")){if(!t.cwd)return{kind:"unknown"};let l={kind:"value",value:t.cwd},c=Lh(t,mt(t),s);return c.length>0&&pl.set(l,c),l}if(/^["']?\$\(\s*git rev-parse --show-toplevel\s*\)["']?$/.test(r)){let l=fl(t.cwd,s);return l?{kind:"value",value:l}:{kind:"unknown"}}if(/^["']?\$!["']?$/.test(r))return{kind:"value",value:"$!"};let a=Me(e,t,s),i=a.text.slice(a.text.indexOf("=")+1);return S(i)?{kind:"value",value:i}:{kind:"value",value:i==="~"||i.startsWith("~/")?s.home+i.slice(1):i}}function fl(e,n){let t=n.projectDir?n.projectDir.replace(/(?<!\/)\/+$/,""):null;return e&&t&&!S(t)&&(e===t||e.startsWith(`${t}/`))?t:e}var rl=/^(?:\$\(\s*pwd(?:\s+-[LP])?\s*\)|`\s*pwd(?:\s+-[LP])?\s*`)$/,Wh=/^(?:\$\(\s*git rev-parse --show-toplevel\s*\)|`\s*git rev-parse --show-toplevel\s*`)$/;function Me(e,n,t){if(e.provenance==="literal"||e.parts.length===0)return{text:e.text,unresolved:[]};let s="",r=!1,o=[],a=null;for(let i of e.parts){if(i.provenance==="command-substitution"&&s===""&&a===null&&(rl.test(i.raw)||Wh.test(i.raw))){let u=rl.test(i.raw)?null:fl(n.cwd,t);a={raw:i.raw,path:u!==null&&u!==n.cwd?u:"."};continue}if(i.provenance==="variable"){let u=Nh(i.raw,n,t);u===null?(o.push(i.raw),s+=`${J}${i.raw}${ee}`):s+=u;continue}let l=i.provenance==="command-substitution"?/^(?:\$\(|`)\s*(?:echo|printf)\s+([A-Za-z0-9_./~ -]+?)\s*(?:\)|`)$/.exec(i.raw):null;if(l){s+=l[1].trim();continue}if(i.provenance==="command-substitution"||i.provenance==="arithmetic"||i.provenance==="unknown"){o.push(i.raw),s+=`${J}${i.provenance==="command-substitution"?jo(i.raw,n,t):i.raw}${ee}`;continue}let c=Fh(i.raw,r);s+=c.text,r=c.inDouble}return a?s===""||s.startsWith("/")?{text:a.path+s,unresolved:o}:{text:`${J}${jo(a.raw,n,t)}${ee}${s}`,unresolved:[a.raw,...o]}:{text:s,unresolved:o}}function Nh(e,n,t){let s=/^\$([A-Za-z_][A-Za-z0-9_]*|[0-9!$?#@*-])(.*)$/s.exec(e);if(s&&!e.startsWith("${")){let u=s[1]==="IFS"?" ":mn(s[1],n,t);return u===null?null:u+s[2]}if(e==="${IFS}")return" ";let r=/^\$\{([A-Za-z_][A-Za-z0-9_]*)(%%?|##?)([^}*?[]*)\}$/.exec(e);if(r){let u=mn(r[1],n,t);if(u===null)return null;let p=r[3];return r[2].startsWith("%")?p&&u.endsWith(p)?u.slice(0,-p.length):u:p&&u.startsWith(p)?u.slice(p.length):u}let o=/^\$\{([A-Za-z_][A-Za-z0-9_]*)(%%?|##?|\/\/?|:[\s\d-])/.exec(e);if(o){let u=mn(o[1],n,t);if(u!==null&&S(u))return u}let a=/^\$\{([A-Za-z_][A-Za-z0-9_]*):?\?[^}]*\}$/.exec(e);if(a)return mn(a[1],n,t);let i=/^\$\{([A-Za-z_][A-Za-z0-9_]*|[0-9!$?#@*-])(?:(:?[-=])([^}]*))?\}$/.exec(e);if(!i)return null;let l=i[1],c=mn(l,n,t);if(c!==null&&!(c===""&&i[2]?.startsWith(":")))return c;if(i[2]&&i[3]!==void 0&&(c===""||!n.vars.has(l))){let u=i[3];if(!u.includes("$")&&!u.includes("`"))return u==="~"||u.startsWith("~/")?t.home+u.slice(1):u}return null}var gt=new WeakMap,sr=new WeakMap,pl=new WeakMap;function Lh(e,n,t){return cl(e,n,t).filter(s=>s!==null&&!S(s))}function er(e){for(let n of[...e.keys()])Po.test(n)&&e.set(n,{kind:"unknown"})}function ht(e,n,t){/^argv\b/.test(n)&&er(e.vars);let s=e.vars.get(n)??null;e.vars.set(n,t);let r={at:e.frames.map(a=>[a,a.phase]),guards:mt(e),maybe:e.maybeRuns,prev:s},o=null;for(let a of[...pl.get(t)??[]].reverse()){let i={kind:"value",value:a};gt.set(i,o?{...r,maybe:!0,prev:o}:r),o=i}gt.set(t,o?{...r,maybe:!0,prev:o}:r)}function Eo(e,n,t,s){let r=gt.get(e);if(!r)return!0;if(r.maybe)return!1;let o=s??n.frames.map(l=>[l,l.phase]);if(!(r.at.length<=o.length&&r.at.every(([l,c],u)=>o[u][0]===l&&o[u][1]===c)))return!1;if(r.guards.length===0)return!0;let i=t??mt(n);return r.guards.every(l=>i.includes(l))}function hl(e,n,t,s){let r=[],o=new Map,a;for(let[i,l]of e.vars){if(n&&!n.has(i)||!gt.has(l)||(a??=s??mt(e),Eo(l,e,a,t)))continue;let c=new Set;for(let u=gt.get(l)?.prev??null;r.length<16;u=u?gt.get(u)?.prev??null:null){let p=u??{kind:"value",value:""};o.has(i)||o.set(i,p);let d=p.kind==="value"?p.value:`\0${p.kind}`;if(c.has(d)||(c.add(d),r.push(new Map(e.vars).set(i,p))),!u||Eo(u,e,a,t))break}if(r.length>=16)break}return o.size>1&&r.unshift(new Map([...e.vars,...o])),r}function gl(e){return new Set([...e.matchAll(/\$\{?#?([A-Za-z_][A-Za-z0-9_]*|[0-9@*#])/g)].map(n=>n[1]))}function Ro(e,n){let t=null;for(let s of[...n].reverse()){let r={kind:"value",value:s};t&>.set(r,{at:[],guards:[],maybe:!0,prev:t}),t=r}return t&>.set(e,{at:[],guards:[],maybe:!0,prev:t}),e}var Oo=new WeakMap;function ol(e){let n={kind:"value",value:e.join(" ")};return Oo.set(n,e),n}function mn(e,n,t){let s=n.vars.get(e);return s?s.kind==="value"?s.value:null:e==="HOME"?t.home:e==="TMPDIR"?t.tmpdir:e==="PWD"?n.cwd:e==="OLDPWD"?n.oldCwd:e==="CLAUDE_PROJECT_DIR"?t.projectDir??null:e==="CLAUDE_CONFIG_DIR"?t.claudeConfigDir??null:e==="!"?"$!":Z()?Th(e,t):null}function Th(e,n){switch(e.toUpperCase()){case"USERPROFILE":return n.home;case"TEMP":case"TMP":return n.tmpdir;case"SYSTEMROOT":case"WINDIR":return"/c/windows";case"SYSTEMDRIVE":return"/c";case"PROGRAMFILES":return"/c/program files";case"PROGRAMFILES(X86)":return"/c/program files (x86)";case"PROGRAMDATA":case"ALLUSERSPROFILE":return"/c/programdata";case"APPDATA":return`${n.home}/appdata/roaming`;case"LOCALAPPDATA":return`${n.home}/appdata/local`;default:return null}}function jo(e,n,t){let s="",r=0,o=!1;for(;r<e.length;){let a=e[r];if(a==="'"&&!o){(s.split('"').length-1)%2===0&&(o=!0),s+=a,r++;continue}if(a==="'"&&o){o=!1,s+=a,r++;continue}if(!o&&a==="\\"&&r+1<e.length){s+=e.slice(r,r+2),r+=2;continue}if(!o&&a==="$"){let i=/^\$(?:\{([A-Za-z_][A-Za-z0-9_]*)\}|([A-Za-z_][A-Za-z0-9_]*))/.exec(e.slice(r));if(i){let l=mn(i[1]??i[2],n,t);if(l!==null&&l!=="$!"&&!S(l)){s+=l,r+=i[0].length;continue}}}s+=a,r++}return s}function Dh(e,n,t){let s=e.redirects.find(l=>(l.op===">"||l.op===">>"||l.op===">|")&&l.target&&!S(l.target)),r=e.name==="tee"?e.argv.slice(1).find(l=>!l.startsWith("-")&&!S(l)):void 0,o=s?.target??r;if(!o||o.startsWith("/dev/"))return;let a=null;if((e.name==="cat"||e.name==="tee")&&e.stdin!==null&&e.argv.length<=2)a=e.stdin;else if(e.name==="echo"||e.name==="printf"){let l=e.argv.slice(1).filter(c=>!/^-[neE]+$/.test(c));l.some(S)||(a=e.name==="printf"&&l[0]?.includes("%")?l.slice(1).join(`
|
|
26
26
|
`):l.join(" ").replace(/\\n/g,`
|
|
27
|
-
`))}if(a===null)return;let i=M(o,e.cwd,
|
|
28
|
-
`&&(
|
|
29
|
-
`&&(
|
|
30
|
-
`,t:" ",r:"\r","\\":"\\","'":"'",'"':'"',a:"\x07",b:"\b",e:"\x1B",E:"\x1B",f:"\f",v:"\v",0:"\0"},s="",r=t;for(;r<e.length&&e[r]!=="'";){if(e[r]==="\\"&&r+1<e.length){let o=e[r+1];if(o==="x"){let a=/^[0-9a-fA-F]{1,2}/.exec(e.slice(r+2))?.[0]??"";s+=a?String.fromCharCode(parseInt(a,16)):"x",r+=2+a.length;continue}s+=n[o]??o,r+=2;continue}s+=e[r],r++}return{text:s,next:r+1}}var On="what this session made earlier";function ks(e,t,n){if(!t||S(e)||!e.startsWith("/"))return null;let s=n?"full":"parent";t.touched?.[s].add(e);let r=t.real?.[s][e];return r!==void 0&&r!==e?r:null}var la={catastrophic:3,normal:2,disposable:1},ua=new Set(["node_modules","dist","build","out",".next",".nuxt",".output",".svelte-kit",".turbo",".parcel-cache",".vite",".cache","coverage",".nyc_output","__pycache__",".pytest_cache",".mypy_cache",".ruff_cache",".tox",".venv","venv","target",".gradle","tmp",".tmp","temp",".vscode-test",".vscode-test-web","test-results","playwright-report","storybook-static",".docusaurus",".angular",".expo",".astro",".wrangler",".serverless",".terraform",".dart_tool",".stack-work","htmlcov",".hypothesis",".benchmarks",".pnpm-store",".webpack",".esbuild",".vinxi",".contentlayer",".velite",".nx",".yarn-cache",".eslintcache",".vitest-reports"]),Lf=/^\.?(tmp|temp)([-_.].*)?$|[-_.](tmp|temp)$/i,da=new Set(["Desktop","Documents","Downloads","Library","Pictures","Movies","Music","Applications","Public",".ssh",".gnupg",".aws",".config",".claude",".local",".kube",".docker"]),fa=new Set(["/bin","/sbin","/usr","/etc","/var","/opt","/System","/Library","/Applications","/Users","/private","/Volumes","/home","/root","/lib","/boot","/srv","/cores","/dev"]);function pa(e){let t=["/tmp","/private/tmp","/var/tmp","/private/var/tmp","/var/folders","/private/var/folders"],n=e.tmpdir.replace(/(?<!\/)\/+$/,"");return n&&t.push(n,n.startsWith("/private/")?n.slice(8):`/private${n}`),V()&&t.push("/c/windows/temp"),t}function Tf(e,t){if(Fi(e))return{kind:"catastrophic",path:e,token:"fs.root",why:e.startsWith("/unc/")?`a network share (${us(e)})`:`the drive ${us(e)}`};let n=/^\/[a-z]\/(.+)$/s.exec(e);return n&&Er.includes(n[1])?{kind:"catastrophic",path:e,token:"fs.system",why:`the system folder ${us(e)}`}:xe.dirname(e)===t&&Rr.has(xe.basename(e))?{kind:"catastrophic",path:e,token:"fs.home",why:`the ${xe.basename(e)} folder in home`}:null}var If=[..."abcdefghijklmnopqrstuvwxyz"].map(e=>`/${e}`).concat(Er.map(e=>`/c/${e}`)),ha=(e,t)=>e===t||e.startsWith(t.endsWith("/")?t:`${t}/`);function X(e,t,n){let s=ca(e,t,n);if(!n.onDisk)return s;let r=M(e,t??n.base??n.projectRoot,n),o=xe.basename(e.replace(/(?<!\/)\/+$/,"")),a=ks(r,n.onDisk,e.endsWith("/")||/[*?[]/.test(o));if(a===null)return s;let i=ca(a,null,n);return la[i.kind]>la[s.kind]?{...i,why:`${i.why}, through a link`}:s}function ca(e,t,n){let s=M(e,t??n.base??n.projectRoot,n),r=s.replace(new RegExp(`[${ie}${le}]`,"g"),"");return s.startsWith("/dev/")&&!["/dev/null","/dev/stdout","/dev/stderr","/dev/tty"].includes(s)&&!cs(s)?{kind:"catastrophic",path:r,token:"fs.device",why:`a raw device (${r})`}:S(s)?zf(s,r,n,t??n.base??null):ga(s,n)}function Df(e){let t="",n=!1;for(let r=0;r<e.length;r++){let o=e[r];if(o==="*"||o==="?"){t+=o==="*"?"[^/]*":"[^/]",n=!0;continue}if(o==="["){let a=e.indexOf("]",r+(e[r+1]==="!"||e[r+1]==="^"?3:2));if(a>r){let i=e.slice(r+1,a),l=i.startsWith("!")||i.startsWith("^"),c=(l?i.slice(1):i).replace(/[\\\]^]/g,"\\$&");t+=`[${l?"^/":""}${c}]`,n=!0,r=a;continue}}t+=o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}if(!n)return null;let s;try{s=new RegExp(`^${t}$`,"s")}catch{return()=>!1}return r=>(!r.startsWith(".")||e.startsWith("."))&&s.test(r)}function Ff(e,t){let n=e.split("/").filter(Boolean),s=n.map(Df);if(s.every(i=>i===null))return null;let r=t.home.replace(/(?<!\/)\/+$/,""),o=t.projectRoot&&!S(t.projectRoot)?t.projectRoot.replace(/(?<!\/)\/+$/,""):null,a=[];if(o){a.push(`${o}/.git`);for(let i=o;i.length>1;i=xe.dirname(i))a.push(i)}r&&a.push(r,...[...V()?Rr:da].map(i=>`${r}/${i}`)),a.push(...fa),V()&&a.push(...If);for(let i of a){let l=i.split("/").filter(Boolean);if(l.length!==n.length||!l.every((p,d)=>s[d]?s[d](p):p===n[d]))continue;let c=ga(i,t),u=e.split("/"),f=u.slice(Math.max(0,u.findIndex(p=>/[*?[]/.test(p)))).join("/");if(c.kind==="catastrophic")return{...c,path:e,why:`${c.why} (${f} matches it)`}}return null}function ga(e,t){if(/[*?[]/.test(e)){let o=Ff(e,t);if(o)return o}let n=t.home.replace(/(?<!\/)\/+$/,"");if(e==="/"||e==="")return{kind:"catastrophic",path:"/",token:"fs.root",why:"the filesystem root"};if(V()){let o=Tf(e,n);if(o)return o}if(e===n)return{kind:"catastrophic",path:e,token:"fs.home",why:"the home folder"};if(xe.dirname(e)===n&&da.has(xe.basename(e)))return{kind:"catastrophic",path:e,token:"fs.home",why:`the ${xe.basename(e)} folder in home`};for(let o of pa(t)){if(ha(e,o)&&e!==o)return{kind:"disposable",path:e,token:null,why:"a temp folder"};if(e===o)return{kind:"catastrophic",path:e,token:"fs.system",why:`the system temp root ${o}`}}if(/\/scratchpad(\/|$)/.test(e))return{kind:"disposable",path:e,token:null,why:"a session scratchpad"};if(e.startsWith(`${n}/Library/Caches/`))return{kind:"disposable",path:e,token:null,why:"an app cache folder"};if(xe.basename(e)===".git")return{kind:"catastrophic",path:e,token:"fs.git_dir",why:"a .git folder (the repository history)"};if(t.projectRoot&&e===t.projectRoot.replace(/(?<!\/)\/+$/,"")&&e!==n)return{kind:"catastrophic",path:e,token:"fs.project_root",why:"the project root"};if(t.projectRoot&&t.projectRoot.replace(/(?<!\/)\/+$/,"").startsWith(`${e}/`)&&e!==n)return{kind:"catastrophic",path:e,token:"fs.project_root",why:`a folder holding the project (${e})`};let s=e.split("/").filter(Boolean);if(s.some(o=>ua.has(o)))return{kind:"disposable",path:e,token:null,why:"build or cache output"};if(/\.tsbuildinfo$/.test(xe.basename(e)))return{kind:"disposable",path:e,token:null,why:"build output"};if(xe.basename(e)===".auth"&&/(^|\/)(e2e|playwright|tests?|cypress)(\/|$)/.test(xe.dirname(e)))return{kind:"disposable",path:e,token:null,why:"a browser test's saved sign-in state"};if(s.some(o=>Lf.test(o)))return{kind:"disposable",path:e,token:null,why:"a folder named as temporary"};if(/\.lock$/.test(xe.basename(e))&&!/(^|\/)(Cargo|Gemfile|poetry|uv|yarn|pnpm-lock|package-lock|composer|Pipfile|flake|mix|pubspec)\.lock$/.test(e))return{kind:"disposable",path:e,token:null,why:"a lock folder (a convention, not data)"};if(fa.has(e))return{kind:"catastrophic",path:e,token:"fs.system",why:`the system folder ${e}`};if(t.made&&t.made.some(o=>e===o||e.startsWith(`${o}/`)))return{kind:"disposable",path:e,token:null,why:On};let r=xe.basename(e);return(r==="bin"||r==="obj")&&t.projectRoot&&t.projectRoot.replace(/(?<!\/)\/+$/,"")!==n&&e.startsWith(`${t.projectRoot.replace(/(?<!\/)\/+$/,"")}/`)&&t.ignored?.(e)?{kind:"disposable",path:e,token:null,why:"build output git ignores"}:{kind:"normal",path:e,token:null,why:/\.[A-Za-z0-9]{1,8}$/.test(xe.basename(e))&&!/\/$/.test(e)?"a real file":"a real folder"}}function zf(e,t,n,s){let r=new RegExp(`^${ie}([^${le}]*)${le}(/.+)$`).exec(e);if(r&&/tmpdir\(\)|gettempdir\(\)|\bmktemp\b|\$TMPDIR\b|\$\{TMPDIR\}/.test(r[1])&&!r[2].split("/").includes(".."))return{kind:"disposable",path:t,token:null,why:"a temp folder (computed)"};let o=e.replace(new RegExp(`^${ie}[^${le}]*${le}`),"");if(e.startsWith(ie)&&(o==="/"||o==="/*"||o==="/.*"))return{kind:"catastrophic",path:t,token:"fs.root",why:`${t}: if the variable is empty, this is the filesystem root`};let a=e.replace(new RegExp(`${ie}[^${le}]*${le}`,"g"),"");if(a.split("/").filter(c=>c&&!c.includes("")).some(c=>ua.has(c))||/\/scratchpad(\/|$)/.test(a))return{kind:"disposable",path:t,token:null,why:"build, cache or scratch output under a variable"};let l=e.slice(0,e.indexOf(ie));return l&&pa(n).some(c=>ha(l.replace(/\/$/,""),c))?{kind:"disposable",path:t,token:null,why:"a temp folder"}:{kind:"normal",path:t,token:null,why:`a path that could not be resolved (${t})`}}function _e(e){let t=e.replace(/\/{2,}/g,"/");return t.length>1&&t.endsWith("/")?t.slice(0,-1):t}var Mf=/^--(?:count|instance-count|num-nodes|nodes|num-workers|replicas|max-count|node-count)$/,Uf=/^--(?:max-run-duration|max-duration|duration|time-limit|hours)$/,qf=/^--(?:gpus?|accelerators?|accelerator-type|gpu-type|gpu-count)$/,Hf=/gpu|a100|h100|h200|v100|l40|a10g|b200|tpu/i,Bf=/(?:^|[^a-z0-9])(?:t4|l4)(?:$|[^a-z0-9])/i,ma=e=>Hf.test(e)||Bf.test(e),Vf=/^--(?:machine-type|instance-type|vm-size|size)$/;function Zf(e,t){let n=/^(\d{1,3}):(\d{2})(?::(\d{2}))?$/.exec(e);if(n)return Number(n[1])+Number(n[2])/60+Number(n[3]??0)/3600;let s=/^(\d+(?:\.\d+)?)(h|m|s|d)?$/i.exec(e);if(!s)return null;let r=Number(s[1]),o=(s[2]??(t==="hours"?"h":"s")).toLowerCase(),a=o==="h"?r:o==="m"?r/60:o==="d"?r*24:r/3600;return Number.isFinite(a)&&a>0?a:null}function ya(e){let t=(e??"").split(/\s+/).filter(Boolean).slice(0,400),n=null,s=null,r=null,o=a=>{let i=t[a],l=i.indexOf("=");return l>0?[i.slice(0,l),i.slice(l+1)]:[i,t[a+1]]};for(let a=0;a<t.length;a++){let[i,l]=o(a);if(l===void 0)continue;let c=l.replace(/^["']|["']$/g,"");Mf.test(i)&&/^\d{1,5}$/.test(c)&&Number(c)>0?n=Math.max(n??0,Number(c)):Uf.test(i)?s=Math.max(s??0,Zf(c,i==="--hours"?"hours":"seconds")??0)||s:(qf.test(i)||Vf.test(i)&&ma(c))&&(r=!0)}for(let a=0;a<t.length;a++){if(t[a]!=="create"||!t.slice(Math.max(0,a-3),a).includes("instances"))continue;let i=0;for(let l=a+1;l<t.length&&!t[l].startsWith("-")&&!/^(?:&&|\|\|?|;|&)$/.test(t[l])&&(i++,!t[l].endsWith(";"));l++);i>0&&(n=Math.max(n??0,i))}return r===null&&t.some(ma)&&(r=!0),{machines:n??1,hours:s??1,gpu:r,estimated:n===null||s===null}}import{posix as tt}from"path";var vs={paths:[],launched:[]},jn=600;function ba(e,t,n){if(!e||S(e)||e.startsWith("-")||/[*?[\]{}]/.test(e))return null;let s=M(e,t.cwd,n).replace(/(?<!\/)\/+$/,"");return!s.startsWith("/")||s==="/"||s===n.home||s.startsWith("/dev/")?null:tt.normalize(s)}function Xt(e,t=new Set){let n=[],s=!1;for(let r=1;r<e.length;r++){let o=e[r];if(!s&&o==="--"){s=!0;continue}if(!s&&o.startsWith("-")){t.has(o)&&r++;continue}n.push(o)}return n}var Gf=new Set(["--out","--output","--out-dir","--outdir","--output-dir","--dest","--destination","--target-dir","--results-dir","--report-dir","--save-dir","--log-dir","--out-file","--output-file","--pack-destination"]),Kf=new Set(["gcc","clang","cc","go","rustc","esbuild","tsc","curl","wget","pandoc","ffmpeg"]);function Yf(e,t){let n=[],s=r=>{let o=r?ba(r,e,t):null;o&&n.push(o)};for(let r of e.redirects)r.target&&/^(>|>>|>\||&>|&>>)$/.test(r.op)&&(r.fd===null||r.fd===1||r.fd===2)&&s(r.target);for(let r=1;r<e.argv.length;r++){let o=e.argv[r],a=o.indexOf("="),i=a>0?o.slice(0,a):o;!Gf.has(i)&&!(i==="-o"&&(qr.has(tt.basename(e.name))||Kf.has(e.name)))||s(a>0?o.slice(a+1):e.argv[r+1])}switch(e.name){case"mkdir":for(let r of Xt(e.argv,new Set(["-m","--mode"])))s(r);break;case"touch":for(let r of Xt(e.argv,new Set(["-r","-t","-d","--reference","--date"])))s(r);break;case"tee":for(let r of Xt(e.argv))s(r);break;case"cp":case"rsync":case"ditto":case"install":{let r=Xt(e.argv,new Set(["-t","--target-directory","-e","--exclude","--include","-m","--mode","-o","-g","--chmod","--rsh"]));r.length>=2&&s(r[r.length-1]);break}case"git":{let r=e.argv.slice(1),o=0,a=null;for(;o<r.length&&r[o].startsWith("-");)r[o]==="-C"&&(a=r[o+1]??null),o+=r[o]==="-C"||r[o]==="-c"?2:1;let i=a===null?e:{...e,cwd:S(a)?null:M(a,e.cwd,t)},l=c=>{let u=c?ba(c,i,t):null;u&&n.push(u)};if(r[o]==="worktree"&&r[o+1]==="add"&&l(Xt(["git",...r.slice(o+2)],new Set(["-b","-B","--reason"]))[0]),r[o]==="clone"){let c=Xt(["git",...r.slice(o+1)],new Set(["-b","--branch","--depth","-o","--origin","--reference","-c","--config","--filter","--separate-git-dir"]));c.length>=2?l(c[1]):c[0]&&l(tt.basename(c[0]).replace(/\.git$/,""))}break}case"npm":case"pnpm":case"yarn":{let r=e.argv.indexOf("--pack-destination");r>0&&s(e.argv[r+1]);break}case"tar":{let r=e.argv.findIndex(a=>a==="-C"||a==="--directory");r>0&&e.argv.slice(1).some(a=>/^-?[a-zA-Z]*x/.test(a)||a==="--extract")&&s(e.argv[r+1]);let o=e.argv.findIndex(a=>a==="-f"||a==="--file"||/^-[a-zA-Z]*c[a-zA-Z]*f$/.test(a));o>0&&e.argv.slice(1).some(a=>/^-?[a-zA-Z]*c/.test(a)||a==="--create")&&s(e.argv[o+1]);break}default:break}return n}function ka(e,t,n,s){let r=t&&typeof t=="object"?t:{};if(e==="Write"||e==="NotebookEdit"){let c=typeof r.file_path=="string"?r.file_path:typeof r.notebook_path=="string"?r.notebook_path:null;return c&&c.startsWith("/")&&c!==s.home?{paths:[tt.normalize(c)],launched:[]}:vs}if(e!=="Bash"||typeof r.command!="string")return vs;let o=r.command;if(o.length>64*1024)return vs;let a;try{a=dt(o,{home:s.home,tmpdir:s.tmpdir,cwd:n,projectDir:s.projectDir??null})}catch{return vs}let i=new Set,l=[];for(let c of a.commands){let u=Hr(c,s);for(let f of u.paths)i.add(f);l.push(...u.launched)}if(r.run_in_background===!0){l.push(o.slice(0,jn));for(let c of a.commands)!S(c.argv.join(" "))&&c.argv.length>1&&l.push(c.argv.map(u=>k(u)).join(" ").slice(0,jn))}return{paths:[...i].slice(0,64),launched:[...new Set(l)].slice(0,16)}}var $s=new Set(["serve","server","start","preview","develop","watch","install","update","build","test","tests","runner","worker","workers","python3","python","module","script","scripts","index.js","main.py","app.py","server.js","index.ts","main.ts","railway","vercel","heroku","kubectl","supabase","wrangler","netlify","firebase","stripe","ngrok","monitor","stream","follow","logs","runserver","uvicorn","gunicorn","hypercorn","daphne","nodemon","webpack","webpack-dev-server","http-server","live-server","browser-sync","celery","sidekiq","puma","unicorn","rackup","flask","rails","manage.py","artisan","storybook","jupyter","notebook","streamlit","gradio"]),qr=new Set(["node","nodejs","npx","tsx","ts-node","python","python3","uv","bun","deno","ruby","perl","bash","sh","zsh","pnpm","yarn","npm"]);function Hr(e,t){let n=[];if(e.background||e.wrappers.includes("nohup")||e.wrappers.includes("setsid")){n.push(e.text.slice(0,jn));let s=e.argv.map(r=>k(r)).join(" ");s!==e.text&&!S(e.argv.join(" "))&&n.push(s.slice(0,jn))}else!S(e.argv.join(" "))&&(qr.has(tt.basename(e.name))?e.argv.slice(1).some(s=>!s.startsWith("-")&&Pn(s)):Pn(e.argv[0]??"")&&(e.argv[0]??"").includes("/"))&&n.push(e.argv.join(" ").slice(0,jn));return{paths:Yf(e,t),launched:n}}var xs=new Set(["node","nodejs","python","python3","python2","ruby","perl","php","java","go","deno","bun","uv","npm","npx","pnpm","yarn","sh","bash","zsh","fish","dash","claude","code","docker","postgres","redis-server","mysqld","vite","next","tsx","ts-node","vitest","jest","make","cargo","git","ssh","tail","sleep","cat","less","watch","top","login","launchd","kernel_task","Finder","Dock"]);function va(e,t,n,s){if((!t||t.length===0)&&(!s||s.length===0))return!1;let r=e.replace(/^["']|["']$/g,"").trim();if(r.length<4||xs.has(r)||/[|()?*+[\]{}\\^$]/.test(r.replace(/\\\./g,"."))||/^\.?\w{1,6}$/.test(r)&&r.startsWith("."))return!1;let o=r.split(/\s+/).some(i=>i.length>=6&&!i.startsWith("-")&&!xs.has(tt.basename(i))&&!qr.has(i)&&!$s.has(i)&&!$s.has(tt.basename(i))&&!_s.test(tt.basename(i))&&!/^[\d.:]+$|^(localhost|0\.0\.0\.0|127\.0\.0\.1)(:\d+)?$|^[\w.]+:(app|application|server|api|asgi|wsgi|main)$/i.test(i));if((n?o&&(/[/.]/.test(r)&&/\w{3}[/.]|[/.]\w{3}/.test(r)||r.length>=8&&/\s/.test(r)||r.length>=10):!xs.has(r)&&!$s.has(r)&&!_s.test(r)&&r.length>=4)&&t&&Ur(r.replace(/\\\./g,"."),t))return!0;if(!n)return!1;for(let i of r.split(/\s+/)){let l=i.replace(/\\\./g,".").replace(/^\.\//,"");if(!(l.startsWith("-")||l.includes("="))){if(l.includes("/")&&s&&wa(l,s))return!0;if(Pn(l)&&(t&&Ur(l,t)||s&&wa(l,s)))return!0}}return!1}function Pn(e){let t=tt.basename(e);return e.length>=6&&/\.[A-Za-z0-9]{1,5}$/.test(t)&&!xs.has(t)&&!$s.has(t)&&!_s.test(t)&&!/^\.[A-Za-z0-9]+$/.test(t)&&!e.includes("node_modules/.bin/")}var _s=/^(server|app|main|index|worker|run|start|dev|cli|manage|setup|test|tests|build|serve|api|bot|job|task|script|wsgi|asgi|entry|entrypoint|bootstrap)\.[A-Za-z0-9]{1,5}$/i;function Ur(e,t){let n=new RegExp(`(^|[\\s/'"=])${e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}($|[\\s'";&|)@])`);return t.some(s=>n.test(s))}function wa(e,t){for(let n of t){if(e.startsWith("/")&&(e===n||e.startsWith(`${n}/`)))return!0;let s=n.split("/").filter(r=>r!=="");for(let r=1;r<=s.length;r++){let o=s.slice(-r).join("/");if(!(o.length<6||r===1&&!Pn(o))&&(e===o||e.startsWith(`${o}/`)||e.endsWith(`/${o}`)))return!0}}return!1}function $a(e,t){let n=a=>a.replace(/\s+/g," ").trim(),s=n(e);if(t.some(a=>n(a).length>=24&&s.includes(n(a))))return!0;let r=a=>{let i=n(a),l=i.indexOf(" ");if(l<0)return null;let c=(i.slice(0,l).split("/").pop()??"").toLowerCase(),u=c.length;for(;u>0&&"0123456789.".includes(c[u-1]);)u--;return{prog:c.slice(0,u),args:i.slice(l+1)}},o=r(e);if(o&&t.some(a=>{let i=r(a);return i!==null&&i.args.length>=24&&i.prog===o.prog&&i.args===o.args}))return!0;for(let a of t)if(a.split(/\s+/).map(l=>l.replace(/^["']+|["';&|)]+$/g,"").replace(/^(\.\.?\/)+/,"")).flatMap(l=>{let c=l.split("/").filter(u=>u!=="");return c.length>2?[l,c.slice(-2).join("/")]:[l]}).filter(l=>!l.startsWith("-")&&!l.includes("=")&&Pn(l)&&!/^\/(dev|tmp|var|usr|bin|opt)\b/.test(l)).some(l=>new RegExp(`(^|\\s${l.includes("/")?"|/":""})${l.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}(\\s|$)`).test(e)))return!0;return!1}function Jf(e,t){return[...new Set(t.flatMap(s=>s.split(/\s+/).map(r=>r.replace(/^["']+|["';&|)]+$/g,"").split("/").pop()??"")).filter(s=>_s.test(s)))].some(s=>Ur(s,[e]))}var Br=e=>e.trim().split(/\s+/).filter(t=>t!=="");function ft(e){let t=(e.split("/").pop()??"").toLowerCase(),n=t.length;for(;n>0&&"0123456789.".includes(t[n-1]);)n--;return t.slice(0,n)}function xa(e){let t=[],n=Br(e.replace(/["']/g,""));for(let s=0;s<n.length;s++){let r=n[s].endsWith("&")&&!/[<>]&$/.test(n[s])?n[s].slice(0,-1):n[s];/^\d*(>>?|<)&?$/.test(r)?s++:r!==""&&!/^\d*(>>?|<)/.test(r)&&!(t.length===0&&(/^\w+=/.test(r)||r==="nohup"))&&t.push(r)}return t}function Vr(e,t){let n=Br(e);if(n.length===0)return!1;let s=ft(n[0]),r=n[1]?ft(n[1]):"";return t.some(o=>{let a=xa(o);return a.length>0&&(ft(a[0])===s||ft(a[0])===r)})}function _a(e,t){let n=r=>r.replace(/\s+/g," ").trim(),s=n(e);return t.some(r=>n(r).length>=24&&s.includes(n(r)))}function Sa(e,t){if(Jf(e,t)&&Vr(e,t))return!0;let n=Br(e);return t.some(s=>{let r=xa(s);if(r.length===0||r.length===1&&!r[0].includes("/"))return!1;let o=n.length>r.length&&ft(n[1])===ft(r[0])?n.slice(1):n;if(o.length!==r.length||ft(o[0])!==ft(r[0]))return!1;let a=r.length===1;for(let i=1;i<r.length;i++)if(r[i].includes("$")){if(!Xf(r[i],o[i]))return!1}else{if(r[i]!==o[i])return!1;a=!0}return a})}function Xf(e,t){let n=[],s=0,r="";for(;s<e.length;){if(e[s]!=="$"){r+=e[s++];continue}if(n.push(r),r="",s++,e[s]==="{"){let a=e.indexOf("}",s);if(a<0)return!1;s=a+1}else if(e[s]==="("){let a=e.indexOf(")",s);if(a<0)return!1;s=a+1}else for(;s<e.length&&/\w/.test(e[s]);)s++}if(n.push(r),!t.startsWith(n[0])||!t.endsWith(n[n.length-1])||t.length<n[0].length+n[n.length-1].length)return!1;let o=n[0].length;for(let a of n.slice(1,-1)){let i=t.indexOf(a,o);if(i<0)return!1;o=i+a.length}return o<=t.length-n[n.length-1].length}var Pv=10080*60*1e3;var Wv=3600*1e3;var Wn=e=>`${e.kind}\0${e.cwd??""}\0${e.arg??""}`;import{realpathSync as Yv}from"fs";import{readdir as Xv,stat as Qv}from"fs/promises";import{homedir as t$}from"os";import{join as s$,relative as r$,resolve as o$,sep as i$}from"path";import{closeSync as Iv,openSync as Dv,readSync as Fv}from"fs";var Ca=64*1024*1024;var zv=Buffer.from('"tool_use"'),Mv=Buffer.from('"tool_result"'),Uv=Buffer.from('"permissionMode"'),qv=1024*1024;var Hv=256*1024;var l$=3600*1e3;function Aa(e){return e.replace(/[^A-Za-z0-9]/g,"-")}var Nn="anvil-claude",Qf=new Set(["login","logout","open"]);function Ea(e){let t=e[0];return t==="claude"||t!==void 0&&Qf.has(t)?[...e]:["claude",...e]}function Se(e){let t=e.trim();return t===Nn||t.endsWith(` ${Nn}`)||t.endsWith(`/${Nn}`)||/(^|[\s/])@useanvil\/claude-code(@\S+)?$/.test(t)||/(^|\s)claude$/.test(t)?t:`${t} claude`}function Ln(e){return e[0]==="logout"?"anvil logout signs this machine out, so its rules stop following your workspace":e[0]==="remove"?"anvil remove puts an action in ghost in your workspace and hides it":e[0]==="login"?"anvil login changes the workspace whose rules this machine follows":e[0]==="control"&&e[1]==="kill-switch"&&!["off","status","show"].includes(e[2]??"")?"anvil control kill-switch puts every action in ghost, this agent's included":e[0]==="control"&&["set-action-mode","set-service-mode","set-mode"].includes(e[1]??"")&&e.includes("ghost")?`anvil control ${e[1]} ghost switches off a rule your workspace enforces`:e[0]!=="claude"?null:e[1]==="allow"?"anvil claude allow approves a call Anvil held":e[1]==="off"||e[1]==="ghost"?`anvil claude ${e[1]} switches off Anvil's checks on this agent`:e[1]==="rules"&&e[2]==="remove"?"anvil claude rules remove deletes one of the developer's rules":e[1]==="sync"?"anvil claude sync applies changes to your rules.md":e[1]==="rules"&&(e[2]==="add"||e[2]==="import")?`anvil claude rules ${e[2]} changes your rules`:e[1]===void 0||e[1].startsWith("-")?"anvil claude opens the screen that changes your rules":e[1]==="rules"&&e[2]==="edit"?"anvil claude rules edit opens the screen that changes your rules":e[1]==="on"?"anvil claude on reinstalls Anvil and recompiles your rules":e[1]==="statusline"?"anvil claude statusline feeds the meter your budgets count":null}function Ss(e,t=e){if(e.length===0&&t.some(s=>s==="--version"||s==="-v"||s==="--help"||s==="-h"))return null;let n=Ln(Ea(e));return n===null?null:n.replace(/^anvil( claude)?\b/,Nn)}var ep=["prod","production","prd","live","main","master"],tp=["staging","stage","dev","development","preview","test","qa","sandbox"],Ce=e=>new Set(e.split(" ")),np=new Set(ep),Ra=new Set(tp),Nt={environment:null,said:null};function Da(e,t){try{return Rp(e,t)}catch{return Nt}}function Fa(e,t,n){try{return Dp(e,t,n)}catch{return Nt}}function Es(e){return e.normalize("NFKC").toLowerCase().split(/[^a-z0-9]+/).filter(Boolean)}var Oa="\u0430a\u0435e\u043Eo\u0440p\u0441c\u0456i\u0455s\u0501d\u04CFl\u043Cm\u0442t\u043Fn\u0443u\u03BDv\u03BFo\u03C1p\u03B9i\u03B1a\u03B5e\u03C4t\u03C5u\u03BCm",sp=e=>e.normalize("NFKC").replace(new RegExp("\\p{Cf}","gu"),"").replace(/[^\u0000-\u007f]/g,t=>{let n=Oa.indexOf(t.toLowerCase());return n>=0&&n%2===0?Oa[n+1]:t}),rp=/(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])|(?<=[A-Za-z])(?=\d)|(?<=\d)(?=[A-Za-z])/;function Tt(e){for(let t of sp(e).split(/[^A-Za-z0-9]+/))for(let n of[t,...t.split(rp)])if(np.has(n.toLowerCase()))return n.toLowerCase();return null}function en(e){let t=e.normalize("NFKC").replace(/^([a-z][\w+.-]*:\/\/)?[^@/\s:]*@/i,"$1");if(/[^\u0000-\u007f]/.test(t))return!1;if(t.includes("/")&&(/^(\/|~|\$\{?HOME\b)/.test(t)||t.split("/").includes(".."))){let n=t.replace(/\/+$/,"").split("/"),s=n.pop()??"";return Es(s).some(r=>Ra.has(r)&&(!/^(dev|test)$/.test(r)||/^(envs?|environments?|stages?|deploy(ments?)?|overlays?)$/.test(n.pop()??"")))}return Es(t).some(n=>Ra.has(n))}var It=e=>/[$`*]|\{[^}]*(,|\.\.)|[<>]\(/.test(e),op=Ce("env environment stage target tier profile context namespace ns cluster app application project stack site service alias workspace destination dest channel track deployment inventory limit host hosts server to config configuration"),za=e=>e.replace(/^-+/,"").replace(/([a-z])([A-Z])/g,"$1_$2").toLowerCase().split(/[-_.]/).filter(t=>!["name","id","file"].includes(t)).pop()??"",Rs=e=>!/^(NODE|BABEL|RAILS|RACK|FLASK|MIX|SENTRY|APP|ASPNETCORE|DOTNET|SPRING|DJANGO)_/i.test(e)&&op.has(za(e)),ip=Ce("app application project stack site cluster host hosts server destination dest deployment to target"),ap=e=>/^-[ap]$/.test(e)||ip.has(za(e)),lp=/^-[esadncpPESADilHCfF]$/,ja=e=>/^-[A-Za-z]$/.test(e)?lp.test(e):Rs(e),cp=/^--?(staging|preview|qa|sandbox|dev|development)$/i,up={frame:[],guards:[],first:!0,cond:!1,fresh:!1},dp=/(?:^|[\s;&|(){}])(?:function\s+[^\s(){};&|]+|[^\s(){};&|]+\s*\(\s*\))\s*[{(]/,fp=e=>({pipes:0,ids:0,frames:0,compound:0,functions:dp.test(e)}),pp=Ce("if while until case select for"),hp=Ce("fi done esac");function Gr(e,t,n,s){let r=s.length,o=[],a=[],i="",l=!1,c="word",u=[],f=[{frame:n.frame,base:n.guards,first:n.first}],p={guards:n.guards,first:n.first,joined:""},d=()=>{l&&(c==="heredoc"?u.push({end:i,fed:a}):c==="fed"?a.push(i):c==="word"&&o.push(i),i="",l=!1,c="word")},h=y=>{d();let $=f[f.length-1];if(o.length>0||a.length>0){let E=t.compound,x=!1;for(let j of o)if(pp.has(j))E++,x=!0;else if(hp.has(j))E=Math.max(0,E-1);else if(!Ua.has(j))break;let b={words:o,fed:a,pipe:t.pipes,id:t.ids++,frame:y==="&"?[...$.frame,t.frames++]:[...$.frame],guards:p.guards,first:p.first,cond:n.cond||t.functions||x||t.compound>0,fresh:n.fresh};t.compound=E,s.push(b),y==="&&"?p={guards:p.joined==="||"?$.base:[...b.guards,b.id],first:!1,joined:"&&"}:y==="||"?p={guards:$.base,first:!1,joined:"||"}:y==="|"?p={guards:b.guards,first:!1,joined:p.joined}:p={guards:$.base,first:$.first,joined:""}}else y==="list"||y==="&"?p={guards:$.base,first:$.first,joined:""}:(y==="&&"||y==="||")&&(p={guards:y==="||"?$.base:p.guards,first:!1,joined:y});o=[],a=[],y!=="|"&&t.pipes++};for(let y=0;y<e.length;y++){let $=e[y],E=e[y+1]??"";if($==="\\")E!==`
|
|
27
|
+
`))}if(a===null)return;let i=M(o,e.cwd,t);n.files.set(i,s?.op===">>"?(n.files.get(i)??"")+a:a)}function Ih(e,n,t){if(n.files.size===0&&!t.wantFiles&&!t.unreadableFiles?.length)return null;let s=l=>l&&!S(l)?M(l,e.cwd,t):null,r=l=>{let c=s(l),u=c===null?void 0:n.files.get(c);return u===void 0&&c!==null&&!S(c)&&(t.wantFiles?.add(c),t.unreadableFiles?.includes(c)&&(e.unreadableCode=`${he(c)}, a script this session wrote that could not be read`)),u===void 0||c===null?null:{text:u,path:c}};if(e.argv[0].includes("/")){let l=r(e.argv[0]);if(l!==null){let c=/^#!\s*(\S+)(?:\s+(\S+))?/.exec(l.text),u=c?he(c[1])==="env"?c[2]??"":he(c[1]):"sh";return{...l,shell:yn.has(u),direct:!0}}}if(e.name==="source"||e.name==="."){let l=r(e.argv[1]);return l===null?null:{...l,shell:!0,direct:!1}}let o=e.argv.slice(1),a=o.slice(0,Math.max(0,o.findIndex(l=>!l.startsWith("-"))));if(yn.has(e.name)&&a.some(l=>/^-[a-zA-Z]*n[a-zA-Z]*$/.test(l))||e.name==="node"&&a.some(l=>l==="--check"||l==="-c")||["ruby","perl"].includes(e.name)&&a.includes("-c")||e.name==="php"&&a.includes("-l"))return null;if(yn.has(e.name)||lh.has(e.name)){let l=e.name==="deno"&&e.argv.slice(1).find(u=>!u.startsWith("-"))==="run"?e.argv.slice(2).find(u=>!u.startsWith("-")):e.argv.slice(1).find(u=>!u.startsWith("-")),c=r(l);return c===null?null:{...c,shell:yn.has(e.name),direct:!1}}return null}function Fh(e,n){let t="",s=n,r=0;for(;r<e.length;){let o=e[r];if(s){o==='"'?(s=!1,r++):o==="\\"&&r+1<e.length&&'$`"\\\n'.includes(e[r+1])?(e[r+1]!==`
|
|
28
|
+
`&&(t+=e[r+1]),r+=2):(t+=o,r++);continue}if(o==="'"){let a=e.indexOf("'",r+1),i=a===-1?e.length:a;t+=e.slice(r+1,i),r=i+1;continue}if(o==="$"&&e[r+1]==="'"){let a=Mh(e,r+2);t+=a.text,r=a.next;continue}if(o==='"'){s=!0,r++;continue}if(o==="\\"){r+1<e.length&&e[r+1]!==`
|
|
29
|
+
`&&(t+=e[r+1]),r+=2;continue}t+=o,r++}return{text:t,inDouble:s}}function Mh(e,n){let t={n:`
|
|
30
|
+
`,t:" ",r:"\r","\\":"\\","'":"'",'"':'"',a:"\x07",b:"\b",e:"\x1B",E:"\x1B",f:"\f",v:"\v",0:"\0"},s="",r=n;for(;r<e.length&&e[r]!=="'";){if(e[r]==="\\"&&r+1<e.length){let o=e[r+1];if(o==="x"){let a=/^[0-9a-fA-F]{1,2}/.exec(e.slice(r+2))?.[0]??"";s+=a?String.fromCharCode(parseInt(a,16)):"x",r+=2+a.length;continue}s+=t[o]??o,r+=2;continue}s+=e[r],r++}return{text:s,next:r+1}}var rs="what this session made earlier";function os(e,n,t){if(!n||S(e)||!e.startsWith("/"))return null;let s=t?"full":"parent";n.touched?.[s].add(e);let r=n.real?.[s][e];return r!==void 0&&r!==e?r:null}function No(e,n,t){return!n||S(e)||!e.startsWith("/")?[]:(n.touched?.[t]?.add(e),n.real?.[t]?.[e]??[])}var ml={catastrophic:3,normal:2,disposable:1},bl=new Set(["node_modules","dist","build","out",".next",".nuxt",".output",".svelte-kit",".turbo",".parcel-cache",".vite",".cache","coverage",".nyc_output","__pycache__",".pytest_cache",".mypy_cache",".ruff_cache",".tox",".venv","venv","target",".gradle","tmp",".tmp","temp",".vscode-test",".vscode-test-web","test-results","playwright-report","storybook-static",".docusaurus",".angular",".expo",".astro",".wrangler",".serverless",".terraform",".dart_tool",".stack-work","htmlcov",".hypothesis",".benchmarks",".pnpm-store",".webpack",".esbuild",".vinxi",".contentlayer",".velite",".nx",".yarn-cache",".eslintcache",".vitest-reports"]),zh=/^\.?(tmp|temp)([-_.].*)?$|[-_.](tmp|temp)$/i,wl=new Set(["Desktop","Documents","Downloads","Library","Pictures","Movies","Music","Applications","Public",".ssh",".gnupg",".aws",".config",".claude",".local",".kube",".docker"]),kl=new Set(["/bin","/sbin","/usr","/etc","/var","/opt","/System","/Library","/Applications","/Users","/private","/Volumes","/home","/root","/lib","/boot","/srv","/cores","/dev"]);function vl(e){let n=["/tmp","/private/tmp","/var/tmp","/private/var/tmp","/var/folders","/private/var/folders"],t=e.tmpdir.replace(/(?<!\/)\/+$/,"");return t&&n.push(t,t.startsWith("/private/")?t.slice(8):`/private${t}`),Z()&&n.push("/c/windows/temp"),n}function Uh(e,n){if(Va(e))return{kind:"catastrophic",path:e,token:"fs.root",why:e.startsWith("/unc/")?`a network share (${gn(e)})`:`the drive ${gn(e)}`};let t=/^\/[a-z]\/(.+)$/s.exec(e);return t&&ko.includes(t[1])?{kind:"catastrophic",path:e,token:"fs.system",why:`the system folder ${gn(e)}`}:Le.dirname(e)===n&&vo.has(Le.basename(e))?{kind:"catastrophic",path:e,token:"fs.home",why:`the ${Le.basename(e)} folder in home`}:null}var qh=[..."abcdefghijklmnopqrstuvwxyz"].map(e=>`/${e}`).concat(ko.map(e=>`/c/${e}`)),$l=(e,n)=>e===n||e.startsWith(n.endsWith("/")?n:`${n}/`);function te(e,n,t){let s=yl(e,n,t);if(!t.onDisk)return s;let r=M(e,n??t.base??t.projectRoot,t),o=Le.basename(e.replace(/(?<!\/)\/+$/,"")),a=os(r,t.onDisk,e.endsWith("/")||/[*?[]/.test(o));if(a===null)return s;let i=yl(a,null,t);return ml[i.kind]>ml[s.kind]?{...i,why:`${i.why}, through a link`}:s}function yl(e,n,t){let s=M(e,n??t.base??t.projectRoot,t),r=s.replace(new RegExp(`[${J}${ee}]`,"g"),"");return s.startsWith("/dev/")&&!["/dev/null","/dev/stdout","/dev/stderr","/dev/tty"].includes(s)&&!ts(s)?{kind:"catastrophic",path:r,token:"fs.device",why:`a raw device (${r})`}:S(s)?Vh(s,r,t,n??t.base??null):xl(s,t)}function Hh(e){let n="",t=!1;for(let r=0;r<e.length;r++){let o=e[r];if(o==="*"||o==="?"){n+=o==="*"?"[^/]*":"[^/]",t=!0;continue}if(o==="["){let a=e.indexOf("]",r+(e[r+1]==="!"||e[r+1]==="^"?3:2));if(a>r){let i=e.slice(r+1,a),l=i.startsWith("!")||i.startsWith("^"),c=(l?i.slice(1):i).replace(/[\\\]^]/g,"\\$&");n+=`[${l?"^/":""}${c}]`,t=!0,r=a;continue}}n+=o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}if(!t)return null;let s;try{s=new RegExp(`^${n}$`,"s")}catch{return()=>!1}return r=>(!r.startsWith(".")||e.startsWith("."))&&s.test(r)}function Bh(e,n){let t=e.split("/").filter(Boolean),s=t.map(Hh);if(s.every(i=>i===null))return null;let r=n.home.replace(/(?<!\/)\/+$/,""),o=n.projectRoot&&!S(n.projectRoot)?n.projectRoot.replace(/(?<!\/)\/+$/,""):null,a=[];if(o){a.push(`${o}/.git`);for(let i=o;i.length>1;i=Le.dirname(i))a.push(i)}r&&a.push(r,...[...Z()?vo:wl].map(i=>`${r}/${i}`)),a.push(...kl),Z()&&a.push(...qh);for(let i of a){let l=i.split("/").filter(Boolean);if(l.length!==t.length||!l.every((d,f)=>s[f]?s[f](d):d===t[f]))continue;let c=xl(i,n),u=e.split("/"),p=u.slice(Math.max(0,u.findIndex(d=>/[*?[]/.test(d)))).join("/");if(c.kind==="catastrophic")return{...c,path:e,why:`${c.why} (${p} matches it)`}}return null}function xl(e,n){if(/[*?[]/.test(e)){let o=Bh(e,n);if(o)return o}let t=n.home.replace(/(?<!\/)\/+$/,"");if(e==="/"||e==="")return{kind:"catastrophic",path:"/",token:"fs.root",why:"the filesystem root"};if(Z()){let o=Uh(e,t);if(o)return o}if(e===t)return{kind:"catastrophic",path:e,token:"fs.home",why:"the home folder"};if(Le.dirname(e)===t&&wl.has(Le.basename(e)))return{kind:"catastrophic",path:e,token:"fs.home",why:`the ${Le.basename(e)} folder in home`};for(let o of vl(n)){if($l(e,o)&&e!==o)return{kind:"disposable",path:e,token:null,why:"a temp folder"};if(e===o)return{kind:"catastrophic",path:e,token:"fs.system",why:`the system temp root ${o}`}}if(/\/scratchpad(\/|$)/.test(e))return{kind:"disposable",path:e,token:null,why:"a session scratchpad"};if(e.startsWith(`${t}/Library/Caches/`))return{kind:"disposable",path:e,token:null,why:"an app cache folder"};if(Le.basename(e)===".git")return{kind:"catastrophic",path:e,token:"fs.git_dir",why:"a .git folder (the repository history)"};if(n.projectRoot&&e===n.projectRoot.replace(/(?<!\/)\/+$/,"")&&e!==t)return{kind:"catastrophic",path:e,token:"fs.project_root",why:"the project root"};if(n.projectRoot&&n.projectRoot.replace(/(?<!\/)\/+$/,"").startsWith(`${e}/`)&&e!==t)return{kind:"catastrophic",path:e,token:"fs.project_root",why:`a folder holding the project (${e})`};let s=e.split("/").filter(Boolean);if(s.some(o=>bl.has(o)))return{kind:"disposable",path:e,token:null,why:"build or cache output"};if(/\.tsbuildinfo$/.test(Le.basename(e)))return{kind:"disposable",path:e,token:null,why:"build output"};if(Le.basename(e)===".auth"&&/(^|\/)(e2e|playwright|tests?|cypress)(\/|$)/.test(Le.dirname(e)))return{kind:"disposable",path:e,token:null,why:"a browser test's saved sign-in state"};if(s.some(o=>zh.test(o)))return{kind:"disposable",path:e,token:null,why:"a folder named as temporary"};if(/\.lock$/.test(Le.basename(e))&&!/(^|\/)(Cargo|Gemfile|poetry|uv|yarn|pnpm-lock|package-lock|composer|Pipfile|flake|mix|pubspec)\.lock$/.test(e))return{kind:"disposable",path:e,token:null,why:"a lock folder (a convention, not data)"};if(kl.has(e))return{kind:"catastrophic",path:e,token:"fs.system",why:`the system folder ${e}`};if(n.made&&n.made.some(o=>e===o||e.startsWith(`${o}/`)))return{kind:"disposable",path:e,token:null,why:rs};let r=Le.basename(e);return(r==="bin"||r==="obj")&&n.projectRoot&&n.projectRoot.replace(/(?<!\/)\/+$/,"")!==t&&e.startsWith(`${n.projectRoot.replace(/(?<!\/)\/+$/,"")}/`)&&n.ignored?.(e)?{kind:"disposable",path:e,token:null,why:"build output git ignores"}:{kind:"normal",path:e,token:null,why:/\.[A-Za-z0-9]{1,8}$/.test(Le.basename(e))&&!/\/$/.test(e)?"a real file":"a real folder"}}function Vh(e,n,t,s){let r=new RegExp(`^${J}([^${ee}]*)${ee}(/.+)$`).exec(e);if(r&&/tmpdir\(\)|gettempdir\(\)|\bmktemp\b|\$TMPDIR\b|\$\{TMPDIR\}/.test(r[1])&&!r[2].split("/").includes(".."))return{kind:"disposable",path:n,token:null,why:"a temp folder (computed)"};let o=e.replace(new RegExp(`^${J}[^${ee}]*${ee}`),"");if(e.startsWith(J)&&(o==="/"||o==="/*"||o==="/.*"))return{kind:"catastrophic",path:n,token:"fs.root",why:`${n}: if the variable is empty, this is the filesystem root`};let a=e.replace(new RegExp(`${J}[^${ee}]*${ee}`,"g"),"");if(a.split("/").filter(c=>c&&!c.includes("")).some(c=>bl.has(c))||/\/scratchpad(\/|$)/.test(a))return{kind:"disposable",path:n,token:null,why:"build, cache or scratch output under a variable"};let l=e.slice(0,e.indexOf(J));return l&&vl(t).some(c=>$l(l.replace(/\/$/,""),c))?{kind:"disposable",path:n,token:null,why:"a temp folder"}:{kind:"normal",path:n,token:null,why:`a path that could not be resolved (${n})`}}function re(e){let n=e.replace(/\/{2,}/g,"/");return n.length>1&&n.endsWith("/")?n.slice(0,-1):n}var Gh=/^--(?:count|instance-count|num-nodes|nodes|num-workers|replicas|max-count|node-count)$/,Zh=/^--(?:max-run-duration|max-duration|duration|time-limit|hours)$/,Kh=/^--(?:gpus?|accelerators?|accelerator-type|gpu-type|gpu-count)$/,Yh=/gpu|a100|h100|h200|v100|l40|a10g|b200|tpu/i,Jh=/(?:^|[^a-z0-9])(?:t4|l4)(?:$|[^a-z0-9])/i,_l=e=>Yh.test(e)||Jh.test(e),Xh=/^--(?:machine-type|instance-type|vm-size|size)$/;function Qh(e,n){let t=/^(\d{1,3}):(\d{2})(?::(\d{2}))?$/.exec(e);if(t)return Number(t[1])+Number(t[2])/60+Number(t[3]??0)/3600;let s=/^(\d+(?:\.\d+)?)(h|m|s|d)?$/i.exec(e);if(!s)return null;let r=Number(s[1]),o=(s[2]??(n==="hours"?"h":"s")).toLowerCase(),a=o==="h"?r:o==="m"?r/60:o==="d"?r*24:r/3600;return Number.isFinite(a)&&a>0?a:null}function Sl(e){let n=(e??"").split(/\s+/).filter(Boolean).slice(0,400),t=null,s=null,r=null,o=a=>{let i=n[a],l=i.indexOf("=");return l>0?[i.slice(0,l),i.slice(l+1)]:[i,n[a+1]]};for(let a=0;a<n.length;a++){let[i,l]=o(a);if(l===void 0)continue;let c=l.replace(/^["']|["']$/g,"");Gh.test(i)&&/^\d{1,5}$/.test(c)&&Number(c)>0?t=Math.max(t??0,Number(c)):Zh.test(i)?s=Math.max(s??0,Qh(c,i==="--hours"?"hours":"seconds")??0)||s:(Kh.test(i)||Xh.test(i)&&_l(c))&&(r=!0)}for(let a=0;a<n.length;a++){if(n[a]!=="create"||!n.slice(Math.max(0,a-3),a).includes("instances"))continue;let i=0;for(let l=a+1;l<n.length&&!n[l].startsWith("-")&&!/^(?:&&|\|\|?|;|&)$/.test(n[l])&&(i++,!n[l].endsWith(";"));l++);i>0&&(t=Math.max(t??0,i))}return r===null&&n.some(_l)&&(r=!0),{machines:t??1,hours:s??1,gpu:r,estimated:t===null||s===null}}import{posix as yt}from"path";var rr={paths:[],launched:[]},is=600;function Cl(e,n,t){if(!e||S(e)||e.startsWith("-")||/[*?[\]{}]/.test(e))return null;let s=M(e,n.cwd,t).replace(/(?<!\/)\/+$/,"");return!s.startsWith("/")||s==="/"||s===t.home||s.startsWith("/dev/")?null:yt.normalize(s)}function kn(e,n=new Set){let t=[],s=!1;for(let r=1;r<e.length;r++){let o=e[r];if(!s&&o==="--"){s=!0;continue}if(!s&&o.startsWith("-")){n.has(o)&&r++;continue}t.push(o)}return t}var eg=new Set(["--out","--output","--out-dir","--outdir","--output-dir","--dest","--destination","--target-dir","--results-dir","--report-dir","--save-dir","--log-dir","--out-file","--output-file","--pack-destination"]),tg=new Set(["gcc","clang","cc","go","rustc","esbuild","tsc","curl","wget","pandoc","ffmpeg"]);function ng(e,n){let t=[],s=r=>{let o=r?Cl(r,e,n):null;o&&t.push(o)};for(let r of e.redirects)r.target&&/^(>|>>|>\||&>|&>>)$/.test(r.op)&&(r.fd===null||r.fd===1||r.fd===2)&&s(r.target);for(let r=1;r<e.argv.length;r++){let o=e.argv[r],a=o.indexOf("="),i=a>0?o.slice(0,a):o;!eg.has(i)&&!(i==="-o"&&(To.has(yt.basename(e.name))||tg.has(e.name)))||s(a>0?o.slice(a+1):e.argv[r+1])}switch(e.name){case"mkdir":for(let r of kn(e.argv,new Set(["-m","--mode"])))s(r);break;case"touch":for(let r of kn(e.argv,new Set(["-r","-t","-d","--reference","--date"])))s(r);break;case"tee":for(let r of kn(e.argv))s(r);break;case"cp":case"rsync":case"ditto":case"install":{let r=kn(e.argv,new Set(["-t","--target-directory","-e","--exclude","--include","-m","--mode","-o","-g","--chmod","--rsh"]));r.length>=2&&s(r[r.length-1]);break}case"git":{let r=e.argv.slice(1),o=0,a=null;for(;o<r.length&&r[o].startsWith("-");)r[o]==="-C"&&(a=r[o+1]??null),o+=r[o]==="-C"||r[o]==="-c"?2:1;let i=a===null?e:{...e,cwd:S(a)?null:M(a,e.cwd,n)},l=c=>{let u=c?Cl(c,i,n):null;u&&t.push(u)};if(r[o]==="worktree"&&r[o+1]==="add"&&l(kn(["git",...r.slice(o+2)],new Set(["-b","-B","--reason"]))[0]),r[o]==="clone"){let c=kn(["git",...r.slice(o+1)],new Set(["-b","--branch","--depth","-o","--origin","--reference","-c","--config","--filter","--separate-git-dir"]));c.length>=2?l(c[1]):c[0]&&l(yt.basename(c[0]).replace(/\.git$/,""))}break}case"npm":case"pnpm":case"yarn":{let r=e.argv.indexOf("--pack-destination");r>0&&s(e.argv[r+1]);break}case"tar":{let r=e.argv.findIndex(a=>a==="-C"||a==="--directory");r>0&&e.argv.slice(1).some(a=>/^-?[a-zA-Z]*x/.test(a)||a==="--extract")&&s(e.argv[r+1]);let o=e.argv.findIndex(a=>a==="-f"||a==="--file"||/^-[a-zA-Z]*c[a-zA-Z]*f$/.test(a));o>0&&e.argv.slice(1).some(a=>/^-?[a-zA-Z]*c/.test(a)||a==="--create")&&s(e.argv[o+1]);break}default:break}return t}function El(e,n,t,s){let r=n&&typeof n=="object"?n:{};if(e==="Write"||e==="NotebookEdit"){let c=typeof r.file_path=="string"?r.file_path:typeof r.notebook_path=="string"?r.notebook_path:null;return c&&c.startsWith("/")&&c!==s.home?{paths:[yt.normalize(c)],launched:[]}:rr}if(e!=="Bash"||typeof r.command!="string")return rr;let o=r.command;if(o.length>64*1024)return rr;let a;try{a=At(o,{home:s.home,tmpdir:s.tmpdir,cwd:t,projectDir:s.projectDir??null})}catch{return rr}let i=new Set,l=[];for(let c of a.commands){let u=Do(c,s);for(let p of u.paths)i.add(p);l.push(...u.launched)}if(r.run_in_background===!0){l.push(o.slice(0,is));for(let c of a.commands)!S(c.argv.join(" "))&&c.argv.length>1&&l.push(c.argv.map(u=>$(u)).join(" ").slice(0,is))}return{paths:[...i].slice(0,64),launched:[...new Set(l)].slice(0,16)}}var or=new Set(["serve","server","start","preview","develop","watch","install","update","build","test","tests","runner","worker","workers","python3","python","module","script","scripts","index.js","main.py","app.py","server.js","index.ts","main.ts","railway","vercel","heroku","kubectl","supabase","wrangler","netlify","firebase","stripe","ngrok","monitor","stream","follow","logs","runserver","uvicorn","gunicorn","hypercorn","daphne","nodemon","webpack","webpack-dev-server","http-server","live-server","browser-sync","celery","sidekiq","puma","unicorn","rackup","flask","rails","manage.py","artisan","storybook","jupyter","notebook","streamlit","gradio"]),To=new Set(["node","nodejs","npx","tsx","ts-node","python","python3","uv","bun","deno","ruby","perl","bash","sh","zsh","pnpm","yarn","npm"]);function Do(e,n){let t=[];if(e.background||e.wrappers.includes("nohup")||e.wrappers.includes("setsid")){t.push(e.text.slice(0,is));let s=e.argv.map(r=>$(r)).join(" ");s!==e.text&&!S(e.argv.join(" "))&&t.push(s.slice(0,is))}else!S(e.argv.join(" "))&&(To.has(yt.basename(e.name))?e.argv.slice(1).some(s=>!s.startsWith("-")&&as(s)):as(e.argv[0]??"")&&(e.argv[0]??"").includes("/"))&&t.push(e.argv.join(" ").slice(0,is));return{paths:ng(e,n),launched:t}}var ir=new Set(["node","nodejs","python","python3","python2","ruby","perl","php","java","go","deno","bun","uv","npm","npx","pnpm","yarn","sh","bash","zsh","fish","dash","claude","code","docker","postgres","redis-server","mysqld","vite","next","tsx","ts-node","vitest","jest","make","cargo","git","ssh","tail","sleep","cat","less","watch","top","login","launchd","kernel_task","Finder","Dock"]);function Rl(e,n,t,s){if((!n||n.length===0)&&(!s||s.length===0))return!1;let r=e.replace(/^["']|["']$/g,"").trim();if(r.length<4||ir.has(r)||/[|()?*+[\]{}\\^$]/.test(r.replace(/\\\./g,"."))||/^\.?\w{1,6}$/.test(r)&&r.startsWith("."))return!1;let o=r.split(/\s+/).some(i=>i.length>=6&&!i.startsWith("-")&&!ir.has(yt.basename(i))&&!To.has(i)&&!or.has(i)&&!or.has(yt.basename(i))&&!ar.test(yt.basename(i))&&!/^[\d.:]+$|^(localhost|0\.0\.0\.0|127\.0\.0\.1)(:\d+)?$|^[\w.]+:(app|application|server|api|asgi|wsgi|main)$/i.test(i));if((t?o&&(/[/.]/.test(r)&&/\w{3}[/.]|[/.]\w{3}/.test(r)||r.length>=8&&/\s/.test(r)||r.length>=10):!ir.has(r)&&!or.has(r)&&!ar.test(r)&&r.length>=4)&&n&&Lo(r.replace(/\\\./g,"."),n))return!0;if(!t)return!1;for(let i of r.split(/\s+/)){let l=i.replace(/\\\./g,".").replace(/^\.\//,"");if(!(l.startsWith("-")||l.includes("="))){if(l.includes("/")&&s&&Al(l,s))return!0;if(as(l)&&(n&&Lo(l,n)||s&&Al(l,s)))return!0}}return!1}function as(e){let n=yt.basename(e);return e.length>=6&&/\.[A-Za-z0-9]{1,5}$/.test(n)&&!ir.has(n)&&!or.has(n)&&!ar.test(n)&&!/^\.[A-Za-z0-9]+$/.test(n)&&!e.includes("node_modules/.bin/")}var ar=/^(server|app|main|index|worker|run|start|dev|cli|manage|setup|test|tests|build|serve|api|bot|job|task|script|wsgi|asgi|entry|entrypoint|bootstrap)\.[A-Za-z0-9]{1,5}$/i;function Lo(e,n){let t=new RegExp(`(^|[\\s/'"=])${e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}($|[\\s'";&|)@])`);return n.some(s=>t.test(s))}function Al(e,n){for(let t of n){if(e.startsWith("/")&&(e===t||e.startsWith(`${t}/`)))return!0;let s=t.split("/").filter(r=>r!=="");for(let r=1;r<=s.length;r++){let o=s.slice(-r).join("/");if(!(o.length<6||r===1&&!as(o))&&(e===o||e.startsWith(`${o}/`)||e.endsWith(`/${o}`)))return!0}}return!1}function Ol(e,n){let t=a=>a.replace(/\s+/g," ").trim(),s=t(e);if(n.some(a=>t(a).length>=24&&s.includes(t(a))))return!0;let r=a=>{let i=t(a),l=i.indexOf(" ");if(l<0)return null;let c=(i.slice(0,l).split("/").pop()??"").toLowerCase(),u=c.length;for(;u>0&&"0123456789.".includes(c[u-1]);)u--;return{prog:c.slice(0,u),args:i.slice(l+1)}},o=r(e);if(o&&n.some(a=>{let i=r(a);return i!==null&&i.args.length>=24&&i.prog===o.prog&&i.args===o.args}))return!0;for(let a of n)if(a.split(/\s+/).map(l=>l.replace(/^["']+|["';&|)]+$/g,"").replace(/^(\.\.?\/)+/,"")).flatMap(l=>{let c=l.split("/").filter(u=>u!=="");return c.length>2?[l,c.slice(-2).join("/")]:[l]}).filter(l=>!l.startsWith("-")&&!l.includes("=")&&as(l)&&!/^\/(dev|tmp|var|usr|bin|opt)\b/.test(l)).some(l=>new RegExp(`(^|\\s${l.includes("/")?"|/":""})${l.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}(\\s|$)`).test(e)))return!0;return!1}function sg(e,n){return[...new Set(n.flatMap(s=>s.split(/\s+/).map(r=>r.replace(/^["']+|["';&|)]+$/g,"").split("/").pop()??"")).filter(s=>ar.test(s)))].some(s=>Lo(s,[e]))}var Io=e=>e.trim().split(/\s+/).filter(n=>n!=="");function Et(e){let n=(e.split("/").pop()??"").toLowerCase(),t=n.length;for(;t>0&&"0123456789.".includes(n[t-1]);)t--;return n.slice(0,t)}function jl(e){let n=[],t=Io(e.replace(/["']/g,""));for(let s=0;s<t.length;s++){let r=t[s].endsWith("&")&&!/[<>]&$/.test(t[s])?t[s].slice(0,-1):t[s];/^\d*(>>?|<)&?$/.test(r)?s++:r!==""&&!/^\d*(>>?|<)/.test(r)&&!(n.length===0&&(/^\w+=/.test(r)||r==="nohup"))&&n.push(r)}return n}function Fo(e,n){let t=Io(e);if(t.length===0)return!1;let s=Et(t[0]),r=t[1]?Et(t[1]):"";return n.some(o=>{let a=jl(o);return a.length>0&&(Et(a[0])===s||Et(a[0])===r)})}function Pl(e,n){let t=r=>r.replace(/\s+/g," ").trim(),s=t(e);return n.some(r=>t(r).length>=24&&s.includes(t(r)))}function Wl(e,n){if(sg(e,n)&&Fo(e,n))return!0;let t=Io(e);return n.some(s=>{let r=jl(s);if(r.length===0||r.length===1&&!r[0].includes("/"))return!1;let o=t.length>r.length&&Et(t[1])===Et(r[0])?t.slice(1):t;if(o.length!==r.length||Et(o[0])!==Et(r[0]))return!1;let a=r.length===1;for(let i=1;i<r.length;i++)if(r[i].includes("$")){if(!rg(r[i],o[i]))return!1}else{if(r[i]!==o[i])return!1;a=!0}return a})}function rg(e,n){let t=[],s=0,r="";for(;s<e.length;){if(e[s]!=="$"){r+=e[s++];continue}if(t.push(r),r="",s++,e[s]==="{"){let a=e.indexOf("}",s);if(a<0)return!1;s=a+1}else if(e[s]==="("){let a=e.indexOf(")",s);if(a<0)return!1;s=a+1}else for(;s<e.length&&/\w/.test(e[s]);)s++}if(t.push(r),!n.startsWith(t[0])||!n.endsWith(t[t.length-1])||n.length<t[0].length+t[t.length-1].length)return!1;let o=t[0].length;for(let a of t.slice(1,-1)){let i=n.indexOf(a,o);if(i<0)return!1;o=i+a.length}return o<=n.length-t[t.length-1].length}var y_=10080*60*1e3;var b_=3600*1e3;var Gt="late",Zt="gone",ls=e=>`${e.kind}\0${e.cwd??""}\0${e.arg??""}`;import{realpathSync as L_}from"fs";import{readdir as D_,stat as I_}from"fs/promises";import{homedir as M_}from"os";import{join as U_,relative as q_,resolve as H_,sep as B_}from"path";import{closeSync as $_,openSync as x_,readSync as __}from"fs";var Nl=64*1024*1024;var S_=Buffer.from('"tool_use"'),C_=Buffer.from('"tool_result"'),A_=Buffer.from('"permissionMode"'),E_=1024*1024;var R_=256*1024;var G_=3600*1e3;function Ll(e){return e.replace(/[^A-Za-z0-9]/g,"-")}var cs="anvil-claude",og=new Set(["login","logout","open"]);function Tl(e){let n=e[0];return n==="claude"||n!==void 0&&og.has(n)?[...e]:["claude",...e]}function Be(e){let n=e.trim();return n===cs||n.endsWith(` ${cs}`)||n.endsWith(`/${cs}`)||/(^|[\s/])@useanvil\/claude-code(@\S+)?$/.test(n)||/(^|\s)claude$/.test(n)?n:`${n} claude`}function us(e){return e[0]==="logout"?"anvil logout signs this machine out, so its rules stop following your workspace":e[0]==="remove"?"anvil remove puts an action in ghost in your workspace and hides it":e[0]==="login"?"anvil login changes the workspace whose rules this machine follows":e[0]==="control"&&e[1]==="kill-switch"&&!["off","status","show"].includes(e[2]??"")?"anvil control kill-switch puts every action in ghost, this agent's included":e[0]==="control"&&["set-action-mode","set-service-mode","set-mode"].includes(e[1]??"")&&e.includes("ghost")?`anvil control ${e[1]} ghost switches off a rule your workspace enforces`:e[0]!=="claude"?null:e[1]==="allow"?"anvil claude allow approves a call Anvil held":e[1]==="off"||e[1]==="ghost"||e[1]==="watch"?`anvil claude ${e[1]} switches off Anvil's checks on this agent`:e[1]==="rules"&&e[2]==="remove"?"anvil claude rules remove deletes one of the developer's rules":e[1]==="sync"?"anvil claude sync applies changes to your rules.md":e[1]==="rules"&&(e[2]==="add"||e[2]==="import")?`anvil claude rules ${e[2]} changes your rules`:e[1]===void 0||e[1].startsWith("-")?"anvil claude opens the screen that changes your rules":e[1]==="rules"&&e[2]==="edit"?"anvil claude rules edit opens the screen that changes your rules":e[1]==="on"?"anvil claude on reinstalls Anvil and recompiles your rules":e[1]==="statusline"?"anvil claude statusline feeds the meter your budgets count":null}function lr(e,n=e){if(e.length===0&&n.some(s=>s==="--version"||s==="-v"||s==="--help"||s==="-h"))return null;let t=us(Tl(e));return t===null?null:t.replace(/^anvil( claude)?\b/,cs)}var Zl=["prod","production","prd","live","main","master"],ig=["staging","stage","dev","development","preview","test","qa","sandbox"],ge=e=>new Set(e.split(" ")),Kl=new Set(Zl),dr=new Set(ig),Kt={environment:null,said:null},Yl=new Set(Zl.filter(e=>e!=="main"&&e!=="master")),ze={words:Kl,names:[],strict:!1};function Go(e,n,t,s){let r=ze;ze={words:n?Yl:Kl,names:e,strict:n};try{return s()}catch{return t}finally{ze=r}}function Zo(e,n,t=[],s=!1){return Go(t,s,Kt,()=>Ng(e,n))}function Ko(e,n,t,s=[],r=!1){return Go(s,r,Kt,()=>Ug(e,n,t))}function Xt(e){return e.normalize("NFKC").toLowerCase().split(/[^a-z0-9]+/).filter(Boolean)}var Dl="\u0430a\u0435e\u043Eo\u0440p\u0441c\u0456i\u0455s\u0501d\u04CFl\u043Cm\u0442t\u043Fn\u0443u\u03BDv\u03BFo\u03C1p\u03B9i\u03B1a\u03B5e\u03C4t\u03C5u\u03BCm",xn=e=>e.normalize("NFKC").replace(new RegExp("\\p{Cf}","gu"),"").replace(/[^\u0000-\u007f]/g,n=>{let t=Dl.indexOf(n.toLowerCase());return t>=0&&t%2===0?Dl[t+1]:n}),ag=/(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])|(?<=[A-Za-z])(?=\d)|(?<=\d)(?=[A-Za-z])/,lg=ge("non pre not no un"),cg=e=>/^(non|pre|not|no|un)[-_]?(prod|production|prd|live)$/i.test(e)||Xt(e).some(n=>dr.has(n))&&!Xt(e).some(n=>Yl.has(n));function Jl(e){let n=e.replace(/(?<![\w-])live\.(?:com|net)(?![\w-])/gi,"");return n.replace(/(^|[^A-Za-z0-9])live(?=\/)/gi,(t,s,r)=>n.slice(r+t.length+1).split(/[\s'"]/,1)[0].split("/").some(cg)?s:t)}var ug=/^\.?(env|config|values|vars|secrets|terraform|settings|hosts|inventory|token|credentials)(\.\w+)?$/i;function Xl(e,n=!1){let t=e.replace(/^(?:--?[\w-]+|[A-Za-z_]\w*)=/,"").split("/"),s=t.pop();for(let a of t){let i=ze.words.has(xn(a).toLowerCase())?a.toLowerCase():fr(xn(a));if(i)return i}let r=n||/\.[A-Za-z]\w{0,9}$/.test(s);return(r&&ug.test(s)&&t.length>0?$e(t[t.length-1]):null)??(r||ze.words.has(xn(s).toLowerCase())?$e(s):fr(xn(e)))}function $e(e){let n=/live/i.test(e)?Jl(e):e;if(ze.strict&&n.includes("/")&&!n.includes("://"))return Xl(n);let t=xn(n),s="";for(let r of t.split(/[^A-Za-z0-9]+/)){let o=r.split(ag);for(let a=-1;a<o.length;a++){let i=(a<0?r:o[a]).toLowerCase();if(ze.words.has(i)&&!(ze.strict&&lg.has(a>0?o[a-1].toLowerCase():s)))return i}s=o[o.length-1].toLowerCase()}return fr(t)}function fr(e){let n=e.toLowerCase();for(let t of ze.names){if(n===t)return t;for(let s=n.indexOf(t);s>=0;s=n.indexOf(t,s+1))if(!/[a-z0-9]/.test(n[s-1]??"")&&!/[a-z0-9]/.test(n[s+t.length]??"")&&!Xt(n).some(r=>dr.has(r)))return t}return null}function _n(e){let n=e.normalize("NFKC").replace(/^([a-z][\w+.-]*:\/\/)?[^@/\s:]*@/i,"$1");if(/[^\u0000-\u007f]/.test(n))return!1;if(n.includes("/")&&(/^(\/|~|\$\{?HOME\b)/.test(n)||n.split("/").includes(".."))){let t=n.replace(/\/+$/,"").split("/"),s=t.pop()??"";return Xt(s).some(r=>dr.has(r)&&(!/^(dev|test)$/.test(r)||/^(envs?|environments?|stages?|deploy(ments?)?|overlays?)$/.test(t.pop()??"")))}return Xt(n).some(t=>dr.has(t))}var Qt=e=>/[$`*]|\{[^}]*(,|\.\.)|[<>]\(/.test(e),dg=ge("env environment stage target tier profile context namespace ns cluster app application project stack site service alias workspace destination dest channel track deployment inventory limit host hosts server to config configuration"),pr=e=>e.replace(/^-+/,"").replace(/([a-z])([A-Z])/g,"$1_$2").toLowerCase().split(/[-_.]/).filter(n=>!["name","id","file"].includes(n)).pop()??"",hr=e=>!/^(NODE|BABEL|RAILS|RACK|FLASK|MIX|SENTRY|APP|ASPNETCORE|DOTNET|SPRING|DJANGO)_/i.test(e)&&dg.has(pr(e)),fg=ge("app application project stack site cluster host hosts server destination dest deployment to target"),pg=e=>/^-[ap]$/.test(e)||fg.has(pr(e)),hg=/^-[esadncpPESADilHCfF]$/,Il=e=>/^-[A-Za-z]$/.test(e)?hg.test(e):hr(e),gg=/^--?(staging|preview|qa|sandbox|dev|development)$/i,mg={frame:[],guards:[],first:!0,cond:!1,fresh:!1},yg=/(?:^|[\s;&|(){}])(?:function\s+[^\s(){};&|]+|[^\s(){};&|]+\s*\(\s*\))\s*[{(]/,bg=e=>({pipes:0,ids:0,frames:0,compound:0,functions:yg.test(e)}),wg=ge("if while until case select for"),kg=ge("fi done esac");function Uo(e,n,t,s){let r=s.length,o=[],a=[],i="",l=!1,c="word",u=[],p=[{frame:t.frame,base:t.guards,first:t.first}],d={guards:t.guards,first:t.first,joined:""},f=()=>{l&&(c==="heredoc"?u.push({end:i,fed:a}):c==="fed"?a.push(i):c==="word"&&o.push(i),i="",l=!1,c="word")},h=b=>{f();let k=p[p.length-1];if(o.length>0||a.length>0){let E=n.compound,y=!1;for(let R of o)if(wg.has(R))E++,y=!0;else if(kg.has(R))E=Math.max(0,E-1);else if(!ec.has(R))break;let m={words:o,fed:a,pipe:n.pipes,id:n.ids++,frame:b==="&"?[...k.frame,n.frames++]:[...k.frame],guards:d.guards,first:d.first,cond:t.cond||n.functions||y||n.compound>0,fresh:t.fresh};n.compound=E,s.push(m),b==="&&"?d={guards:d.joined==="||"?k.base:[...m.guards,m.id],first:!1,joined:"&&"}:b==="||"?d={guards:k.base,first:!1,joined:"||"}:b==="|"?d={guards:m.guards,first:!1,joined:d.joined}:d={guards:k.base,first:k.first,joined:""}}else b==="list"||b==="&"?d={guards:k.base,first:k.first,joined:""}:(b==="&&"||b==="||")&&(d={guards:b==="||"?k.base:d.guards,first:!1,joined:b});o=[],a=[],b!=="|"&&n.pipes++};for(let b=0;b<e.length;b++){let k=e[b],E=e[b+1]??"";if(k==="\\")E!==`
|
|
31
31
|
`&&(i+=E),l||=E!==`
|
|
32
|
-
`,
|
|
33
|
-
`,
|
|
34
|
-
`)h("list"),
|
|
32
|
+
`,b++;else if(k==="'"){let y=gr(e,b+1,"'");i+=e.slice(b+1,y),l=!0,b=y}else if(k==='"'){let y=b+1;for(;y<e.length&&e[y]!=='"';y++)e[y]==="\\"&&/["\\$`]/.test(e[y+1]??"")&&y++,i+=e[y]??"";l=!0,b=y}else if(E==="("&&(k==="$"||k==="<"||k===">")||k==="$"&&E==="{"){let y=Ql(e,b+1);i+=e.slice(b,y+1),l=!0,b=y}else if(k==="`"){let y=gr(e,b+1,"`");i+=e.slice(b,y+1),l=!0,b=y}else if(k==="#"&&!l){let y=e.indexOf(`
|
|
33
|
+
`,b);b=(y<0?e.length:y)-1}else if(k===" "||k===" "||k==="\r")f();else if(k===`
|
|
34
|
+
`)h("list"),b=vg(e,b,u);else if(k==="<"||k===">"||k==="&"&&E===">")if(l&&/^\d+$/.test(i)?(i="",l=!1):f(),e.startsWith("<<<",b))c="fed",b+=2;else if(e.startsWith("<<",b))c="heredoc",b+=e[b+2]==="-"?2:1;else for(c=k==="<"?"fed":"drop";/[<>&|]/.test(e[b+1]??"");)b++;else if(k==="&"&&E==="&")h("&&"),b++;else if(k==="|"&&E==="|")h("||"),b++;else if(k==="|")E==="&"&&b++,h("|");else if(k==="&")h("&");else if(k===";")(E===";"||E==="&")&&b++,h("list");else if(k==="("){f(),(o.length>0||a.length>0)&&h("list");let y=p[p.length-1];p.push({frame:[...y.frame,n.frames++],base:d.guards,first:d.first}),d={...d,joined:""}}else k===")"?(h("list"),p.length>1&&p.pop(),d={guards:p[p.length-1].base,first:!1,joined:""}):(i+=k,l=!0)}h("list");let g=new Map;for(let b of s.slice(r))g.set(b.pipe,(g.get(b.pipe)??0)+1);for(let b of s.slice(r))(g.get(b.pipe)??0)>1&&(b.frame=[...b.frame,n.frames++]);return s}function gr(e,n,t){let s=e.indexOf(t,n);return s<0?e.length:s}function Ql(e,n){let t=e[n],s=t==="("?")":"}",r=0;for(let o=n;o<e.length;o++){let a=e[o];if(a==="\\")o++;else if(a==="'")o=gr(e,o+1,"'");else if(a===t)r++;else if(a===s&&--r===0)return o}return e.length}function vg(e,n,t){let s=n;for(let r of t.splice(0)){let o=[];for(;s<e.length;){let a=e.indexOf(`
|
|
35
35
|
`,s+1),i=e.slice(s+1,a<0?e.length:a);if(s=a<0?e.length:a,i.replace(/^\t+/,"")===r.end)break;o.push(i)}r.fed.push(o.join(`
|
|
36
|
-
`))}return s}var Lt=/^[A-Za-z_][A-Za-z0-9_]*=/,Ua=Ce("if then else elif fi do done while until esac ! { } time"),Pa=Ce("sh bash zsh dash ksh ash"),Wa=oe({sudo:"-u -g -C -D -h -p -r -t -U --user --group --chdir",doas:"-u -C",env:"-u -C -S --unset --chdir",nohup:"",nice:"-n",timeout:"-s -k --signal --kill-after",command:"",builtin:"",exec:"-a",xargs:"-I -n -P -L -d -E -s -a",watch:"-n -d",flock:"-w -E",npx:"-p --package -c --call",bunx:"-p --package",op:"--env-file --account",doppler:"-c --config -p --project --token",infisical:"--env --projectId --path --token",dotenv:"-e -c -v",dotenvx:"-f --env-file","aws-vault":"--duration -d","cross-env":""}),mp=oe({timeout:1,flock:1,"aws-vault":2,op:1,doppler:1,infisical:1,dotenvx:1}),Kr=Ce("op doppler infisical dotenv dotenvx aws-vault mise asdf"),yp=oe({npm:"exec",pnpm:"dlx exec",yarn:"dlx exec",bun:"x",uv:"run",poetry:"run",pipenv:"run",bundle:"exec",mise:"exec x",asdf:"exec",railway:"run"}),bp=oe({flyctl:"fly","netlify-cli":"netlify","firebase-tools":"firebase","@railway/cli":"railway",tofu:"terraform",terragrunt:"terraform","docker-compose":"docker",oc:"kubectl",kubecolor:"kubectl"});function Ze(e){let t=/^((?:@[^/@\s]+\/)?[^@\s=/]+)(?:@[^\s/]*|==\S*)$/.exec(e),n=t?t[1]:e.startsWith("@")?e:e.slice(e.lastIndexOf("/")+1);return bp[n]??n}function Na(e,t,n){let s=n.split(" "),r=t;for(;r<e.length&&e[r].startsWith("-")&&e[r]!=="--";)r+=!e[r].includes("=")&&s.includes(e[r])?2:1;return e[r]==="--"?r+1:r}function qa(e){let t=0;for(let n=0;n<12&&t<e.length;n++){let s=e[t];if(Lt.test(s)){t++;continue}let r=Ze(s),o=e.indexOf("--",t);if(yp[r]?.split(" ").includes(e[t+1]??""))t=Kr.has(r)&&o>t?o+1:Na(e,t+2,"");else if(Wa[r]!==void 0)Kr.has(r)&&o>t?t=o+1:(t=Na(e,t+1,Wa[r])+(mp[r]??0),e[t]==="--"&&t++);else return(r==="yarn"||r==="pnpm")&&tn[Ze(e[t+1]??"")]&&t++,t}return t<e.length?t:-1}function Yr(e,t,n){return e.flatMap(s=>{let r=0;for(;r<s.words.length&&Ua.has(s.words[r]);)r++;let o=s.words.slice(r);if(n>=3)return[{...s,words:o}];let a=(h,g)=>({frame:g?[...s.frame,t.frames++]:s.frame,guards:s.guards,first:s.first&&!s.cond,cond:s.cond,fresh:s.fresh||h}),i=o.flatMap(wp).flatMap(h=>Yr(Gr(h,t,a(!1,!0),[]),t,n+1)),l=qa(o),c=l<0?"":Ze(o[l]),u=null;if(Pa.has(c)){let h=o.findIndex((g,y)=>y>l&&/^-[a-zA-Z]*c[a-zA-Z]*$/.test(g));u=h>0?o[h+1]??null:null}else c==="eval"&&(u=o.slice(l+1).join(" "));if(u===null)return[...i,{...s,words:o}];let f=o.slice(0,l).filter(h=>Lt.test(h)),p=Pa.has(c)?a(!0,!0):a(!1,!1),d=c==="eval"&&It(u)?[{...s,words:[],wild:!0}]:[];return[...i,...d,...Yr(Gr(u,t,p,[]),t,n+1).map(h=>({...h,words:[...f,...h.words]}))]})}function wp(e){let t=[];for(let n=0;n<e.length;n++)if("$<>".includes(e[n])&&e[n+1]==="("&&e[n+2]!=="("){let s=Ma(e,n+1);t.push(e.slice(n+2,s)),n=s}else if(e[n]==="`"){let s=Os(e,n+1,"`");t.push(e.slice(n+1,s)),n=s}return t}var js=(e,t)=>e.frame.length<=t.frame.length&&e.frame.every((n,s)=>t.frame[s]===n),Ha=(e,t)=>js(e,t)&&!e.cond&&(t.guards.includes(e.id)||e.first),st="${?}";function Ba(e,t,n){let s=n.filter(l=>(l.name===e||l.name==="*")&&js(l.part,t)&&(!t.fresh||l.part.fresh||l.exported||l.name==="*"));if(!s.some(l=>l.name===e))return null;let r=-1;for(let l=s.length-1;l>=0;l--){let c=s[l];if(c.name===e&&!c.unknown&&(c.loop||Ha(c.part,t))){r=l;break}}let o=r>=0?[...s[r].values]:[],a=r>=0;for(let l of s.slice(r+1))l.unknown?a=!1:o.push(...l.values);let i=s.filter(l=>l.name===e).pop().said;return{values:[...new Set(o)].slice(0,16),certain:a,said:i}}var kp=(e,t,n)=>e.replace(/\$(?:\{([A-Za-z_]\w*)\}|([A-Za-z_]\w*))/g,(s,r,o)=>{let a=Ba(r??o,t,n);return!a||a.values.length===0?s:a.certain&&a.values.length===1&&!/\s/.test(a.values[0])?a.values[0]:`${a.values.join(st)}${st}`}),Tn=e=>e.slice(0,e.indexOf("=")),In=e=>e.slice(e.indexOf("=")+1),vp=Ce("export declare typeset local readonly");function $p(e){let t=[];return e.map(n=>{let s=n.words.map(u=>kp(u,n,t)),r=qa(s),o=r<0?"":Ze(s[r]),a=new Map,i=s.slice(0,Math.max(r,0)).some(u=>/^(-[a-zA-Z]*[iu]|--unset.*|--ignore-environment|-)$/.test(u)||["sudo","doas"].includes(Ze(u)));for(let u of i?[]:new Set(t.filter(f=>f.exported&&f.name!=="*").map(f=>f.name))){let f=Ba(u,n,t);f&&f.values.length>0&&a.set(u,{said:f.said,value:f.certain&&f.values.length===1?f.values[0]:`${f.values.join(" ")}${st}`})}for(let u of r<0?[]:s.slice(0,r))Lt.test(u)&&a.set(Tn(u),{said:u,value:In(u)});let l=u=>t.some(f=>f.name===u&&f.exported&&js(f.part,n)),c=(u,f,p,d={})=>{t.push({name:u,values:f,unknown:d.unknown??!1,exported:(d.exported??!1)||l(u),loop:d.loop??!1,part:n,said:p})};if(n.wild)c("*",[],"eval",{unknown:!0});else if(r<0)for(let u of s.filter(f=>Lt.test(f)))c(Tn(u),[In(u)],u);else if(vp.has(o)){let u=s.slice(r+1).filter(d=>/^[-+]/.test(d)),f=o==="export"||u.some(d=>/^-[a-zA-Z]*x/.test(d)),p=u.some(d=>/^(-[a-zA-Z]*n|\+[a-zA-Z]*x)/.test(d));for(let d of s.slice(r+1))p&&/^[A-Za-z_]\w*(=|$)/.test(d)?c(d.replace(/=.*/s,""),[],o,{unknown:!0}):Lt.test(d)?c(Tn(d),[In(d)],`${o} ${d}`,{exported:f}):f&&/^[A-Za-z_]\w*$/.test(d)&&t.push(...t.filter(h=>h.name===d).slice(-1).map(h=>({...h,exported:!0,part:n})))}else if(o==="for"&&s[r+2]==="in")c(s[r+1],s.slice(r+3),s.slice(r).join(" "),{loop:!0});else if(o==="source"||o==="."||o==="eval"&&s.slice(r+1).some(It)||o==="set"&&s.slice(r+1).some(u=>/^-[a-zA-Z]*a/.test(u)))c("*",[],o,{unknown:!0});else for(let u of s.slice(r+1))/^[A-Za-z_]\w*$/.test(u)&&t.some(f=>f.name===u)&&c(u,[],o,{unknown:!0});return{part:n,words:s,fed:n.fed,pipe:n.pipe,at:r,tool:o,env:a}})}var xp=(e,t)=>Ha(e.part,t.part)&&t.part.guards.includes(e.part.id),_p=Ce("version help status logs log list ls info show get describe whoami auth login logout doctor history inspect open ps top explain plan validate fmt init output graph providers preview diff synth config context use link pull build template lint package search repo dependency dep workspace stack"),Sp=Ce("cd pushd popd export declare typeset local readonly unset source . echo printf sleep true false set test [ [[ for case git cat ls grep tee read wait exit return mkdir cp mv rm touch chmod which pwd date kubectx kubens alias unalias"),Cp=[Ce("deploy deploys deploying deployment deployments redeploy"),Ce("release releases ship publish rollout promote apply provision rollback destroy")],Ap=e=>Wt(e.words.slice(e.at+1),Ve[e.tool]??"")[0]??"";function Ep(e,t){let n=e.map((i,l)=>l),s=i=>!_p.has(Ap(e[i]))||e[i].words.some(l=>/^(delete|rm|remove|destroy|drop|purge|prune|uninstall|reset)$/.test(l)),r=t?Ze(t.toLowerCase()):null;if(r){let i=n.filter(l=>e[l].at>=0&&e[l].tool===r);if(i.length>0)return i.some(s)?i.filter(s):i;for(let l of e){let c=l.words.findIndex((u,f)=>f>l.at&&Ze(u)===r);if(l.at>=0&&c>0)return l.at=c,l.tool=r,[e.indexOf(l)]}}let o=n.filter(i=>e[i].at>=0&&!Sp.has(e[i].tool)),a=o.filter(i=>e[i].words.some(l=>Es(l).some(Xr))||tn[e[i].tool]!==void 0&&s(i));return a.length>0?a:o}function Va(e){let t=fp(e);return $p(Yr(Gr(e,t,up,[]),t,0))}function Rp(e,t){let n=Va(e),s=Ep(n,t);if(s.length===0){for(let l of n)for(let c of[...l.words,...l.fed])if(Tt(c))return{environment:"production",said:pt(c)};return Nt}let r=s.map(l=>Wp(n,l,t)),o=r.find(l=>l.environment==="production")??(r.some(l=>l.environment===null)?Nt:r[0]);if(o.environment!=="non-production")return o;let a=e.replace(/["']/g,"").split(/[\s`;&|()<>{}$\\]+/),i=[t?Ze(t.toLowerCase()):"",...s.map(l=>n[l].tool)].some(l=>l&&a.filter(c=>Ze(c)===l).length>n.filter(c=>c.tool===l).length);return Tt(e)||i||n.some(l=>l.tool==="alias")?Nt:o}var pt=e=>{let t=e.split(st).join("");return t.length>80?`${t.slice(0,79)}\u2026`:t};function La(e,t){for(let n=0;n<e.length;n++){let s=e[n];if(!Tt(s))continue;let r=e[n-1]??"",o=r.startsWith("-")&&!r.includes("=")&&!s.startsWith("-")&&(t===void 0||t.split(" ").includes(r));return pt(o?`${r} ${s}`:s)}return null}var Za="terraform workspace select|terraform workspace new|terraform init:-backend-config|kubectl config use-context|kubectx|pulumi stack select|firebase use|gcloud config set project|gcloud config configurations activate|docker context use|railway environment|railway link:-e --environment".split("|").map(e=>{let[t,n]=e.split(":"),s=t.split(" ")[0];return[s==="kubectx"?"kubectl":s,t,n]}),Op=Ce("terraform pulumi fly vercel netlify wrangler firebase railway docker");function jp(e,t){let n=e.tool,s=n==="helm"?"kubectl":n,r=[],o=[],a=i=>[{said:i,value:st}];for(let i of t){if(i.at<0||!js(i.part,e.part))continue;let l=xp(i,e),c=i.words.slice(i.at),u=pt(c.join(" "));if(["cd","pushd","popd"].includes(i.tool)||(i.tool==="source"||i.tool===".")&&!tn[n]){let p=Wt(c.slice(1),"")[0];r=l&&p&&p!=="-"&&i.tool!=="popd"?[{said:u,value:p}]:a(u)}let f=Za.filter(([p,d])=>p===s&&d.split(" ").every((h,g)=>(g>0?c[g]:i.tool)===h)).flatMap(([,p,d])=>{let h=c.slice(p.split(" ").length);return d?he(h,d):Wt(h,"").slice(0,1).map(g=>({said:u,value:g}))});f.length>0&&(o=l?f:a(u))}return r.length>0&&e.words.some((i,l)=>i==="-C"||l<e.at&&i==="-D"||i==="-d"&&/^(task|just)$/.test(e.tool)||/^--(chdir|cwd|prefix|dir|directory|working-dir)(=|$)/.test(i))&&(r=a("")),{folders:Op.has(n)||!tn[n]?r:[],picks:o}}var Pp=Ce("cd pushd export declare typeset local readonly source . test [ [[ kubectx kubens case alias");function Wp(e,t,n){let s=e[t],r=e.slice(0,t),o=s.tool==="helm"?"kubectl":s.tool,a=r.filter(d=>d.at<0||Pp.has(d.tool)||d.tool===s.tool&&tn[s.tool]||Za.some(([h,g])=>h===o&&`${g} `.startsWith(`${d.tool} `))),i=La(s.words,Ve[s.tool]);if(i)return{environment:"production",said:i};for(let d of[...s.fed,...r.filter(h=>h.pipe===s.pipe).flatMap(h=>[...h.words,...h.fed])]){let h=Tt(d);if(h)return{environment:"production",said:h}}for(let d of a)if(La(d.words))return{environment:"production",said:pt(d.words.slice(Math.max(d.at,0)).join(" "))};if(n&&Tt(n))return{environment:"production",said:n};let l=jp(s,r),c={args:s.words.slice(s.at+1),env:s.env,chosen:[...l.folders,...l.picks],folders:l.folders,picks:l.picks},u=tn[s.tool]?.(c)??Tp(c,s.words.slice(Math.max(0,s.words.findIndex((d,h)=>h===s.at||Kr.has(Ze(d))))),s.tool);if(u.production)return{environment:"production",said:u.production};let f=u.first?u.sels.filter(d=>d.rank===u.sels[0].rank):u.sels,p=f.length>0&&f.every(d=>!It(d.value)&&en(d.value))?f[0]:void 0;return p?{environment:"non-production",said:pt(p.said)}:u.preview?{environment:"non-production",said:u.preview}:Nt}function he(e,t){let n=t.split(" "),s=[];return e.forEach((r,o)=>{let a=r.indexOf("=");a>0&&n.includes(r.slice(0,a))?s.push({said:r,value:r.slice(a+1)}):n.includes(r)&&o+1<e.length?s.push({said:`${r} ${e[o+1]}`,value:e[o+1]}):/^-[A-Za-z]$/.test(r.slice(0,2))&&r.length>2&&!r.startsWith("--")&&n.includes(r.slice(0,2))&&s.push({said:r,value:r.slice(2)})}),s}function Wt(e,t){let n=t.split(" "),s=[];for(let r=0;r<e.length;r++){let o=e[r];if(o==="--")return[...s,...e.slice(r+1)];!o.startsWith("-")||o==="-"?s.push(o):!o.includes("=")&&n.includes(o)&&r++}return s}function Np(e,t){let n=t.split(" "),s=[];for(let r=0;r<e.length;r++){let o=e[r];if(o==="--")return[...s,...e.slice(r+1)];!o.startsWith("-")||o==="-"?/^-./.test(e[r-1]??"")&&!e[r-1].includes("=")||s.push(o):!o.includes("=")&&n.includes(o)&&r++}return s}var Cs=e=>e.map(t=>({said:t,value:t})),Qt=(e,t)=>t.split(" ").flatMap(n=>e.env.get(n)??[]),Ta=(e,t)=>he(e.args,t).map(n=>({...n,value:st})),Ia=e=>e.env.has("KUBECONFIG")||e.args.some(t=>t.startsWith("--kubeconfig"))?[]:e.picks,nt=(...e)=>{let t=e.findIndex(n=>n.length>0);return{sels:t<0?[]:e[t].map(n=>({...n,rank:t})),first:!0}},Jr=e=>e.flatMap(t=>{let n=t.value.split(/[\s,]+/).filter(s=>Lt.test(s));return n.length===0?[t]:n.filter(s=>Rs(Tn(s))).map(s=>({said:t.said,value:In(s)}))}),Zr=(e,t)=>{let n=t.split(" ");return e.every((s,r)=>!It(s)||s.startsWith("-")||n.includes(e[r-1]??""))},Ve=oe({vercel:"--token -t --scope -S --cwd --local-config -A --global-config -Q --team -T --build-env -b --env -e --meta -m --regions --archive --target --name -n",netlify:"--dir -d --functions -f --site -s --auth --alias --branch -b --context --message -m --filter --timeout",fly:"-a --app -c --config -i --image -e --env --build-arg --build-secret --dockerfile --strategy -r --region --vm-size --wait-timeout --image-label -t --access-token -o --org",terraform:"-var -var-file -target -replace -state -state-out -backup -lock-timeout -parallelism",firebase:"-P --project --only --except -m --message --token --account --expires -e"}),tn=oe({vercel:e=>{let t=Wt(e.args,Ve.vercel),n=/^(deploy)?$|[/.]/.test(t[0]??"")?"deploy":t[0];if(n==="rollback"||n==="promote")return{sels:[],production:n};let s=[...he(e.args,"--target"),...Zr(e.args,Ve.vercel)?[]:[{said:"",value:st}]];return n!=="deploy"?{sels:[...s,...Cs(n==="env"?t.slice(3,4):t.slice(1)),...e.chosen]}:{sels:s,...s.length===0?{preview:"no --prod"}:{}}},netlify:e=>e.args.some(n=>/^-[a-z]*p[a-z]*$/.test(n))?{sels:[],production:"-p"}:{sels:[...he(e.args,"--context --alias --branch -b --site -s"),...e.chosen],...Wt(e.args,Ve.netlify)[0]==="deploy"&&Zr(e.args,Ve.netlify)?{preview:"no --prod"}:{}},fly:e=>{let t=Wt(e.args,Ve.fly),n=t[0]==="apps"||t[0]==="app"?t.slice(2,3):[];return nt([...he(e.args,"-a --app"),...Cs(n)],Qt(e,"FLY_APP"),he(e.args,"-c --config"),t[0]==="deploy"&&t[1]?[{said:"",value:st}]:[],e.folders)},railway:e=>nt(he(e.args,"-e --environment"),e.picks),kubectl:e=>nt(he(e.args,"--context --cluster --server -s"),Ia(e)),helm:e=>nt([...he(e.args,"--kube-context --kube-apiserver"),...Qt(e,"HELM_KUBEAPISERVER")],Qt(e,"HELM_KUBECONTEXT"),Ia(e)),terraform:e=>{let t=Np(e.args,Ve.terraform),n=["apply","destroy"].includes(t[0]??"")?t.slice(1):[],s=[...he(e.args,"-chdir --chdir --terragrunt-working-dir --working-dir"),...Qt(e,"TF_WORKSPACE"),...Cs(n),...e.chosen];return{sels:s.length>0?[...s,...he(e.args,"-var-file --var-file"),...Jr(he(e.args,"-var --var"))]:[]}},pulumi:e=>nt(he(e.args,"-s --stack"),e.picks,[...he(e.args,"-C --cwd"),...e.folders]),firebase:e=>{let t=Wt(e.args,Ve.firebase),n=/^hosting:channel:deploy/.test(t[0]??"");return{sels:[...nt(he(e.args,"-P --project"),e.picks,Ta(e,"--config"),e.folders).sels,...n?Cs(t.slice(1,2)).map(r=>({...r,rank:9})):[]],first:!0,...n&&Zr(e.args,Ve.firebase)?{preview:t[0]}:{}}},wrangler:e=>nt(he(e.args,"--name --route --routes"),he(e.args,"-e --env --branch --project-name"),Ta(e,"-c --config"),e.chosen),docker:e=>{let t=e.args.findIndex((n,s)=>!n.startsWith("-")&&!["-c","--context","-H","--host","--config"].includes(e.args[s-1]??""));return nt([...he(t<0?e.args:e.args.slice(0,t),"-c"),...he(e.args,"--context -H --host")],Qt(e,"DOCKER_HOST DOCKER_CONTEXT"),e.picks)},modal:e=>nt(he(e.args,"-e --env"),Qt(e,"MODAL_ENVIRONMENT"))}),Lp=Ce("make gmake rake just task cap"),Xr=e=>Cp.some(t=>t.has(e.toLowerCase()));function Tp(e,t,n){let s=[],r=[],o=(d,h)=>{s.push(...h),ap(d)&&r.push(...h)},a=[],i=!1;for(let d=0;d<t.length;d++){let h=t[d];if(h==="--")i=!0;else if(h.startsWith("-")&&h.length>1){let g=h.indexOf("="),y=n==="npm"&&!i;h==="--all"&&r.push({said:h,value:h}),g>0?o(h.slice(0,g),ja(h.slice(0,g))&&!y?Jr([{said:h,value:h.slice(g+1)}]):[]):cp.test(h)?s.push(...y?[]:[{said:h,value:h}]):t[d+1]!==void 0&&!t[d+1].startsWith("-")&&(d++,ja(h)&&!y&&o(h,Jr([{said:`${h} ${t[d]}`,value:t[d]}])))}else Lt.test(h)?Lp.has(n)&&Rs(Tn(h))&&s.push({said:h,value:In(h)}):(It(h)||!/\s/.test(h)&&!/^v?\d+(\.\d+)+/.test(h))&&(s.push({said:h,value:d>0?h:h.slice(h.lastIndexOf("/")+1)}),d>0&&a.push(h))}for(let[d,h]of e.env)Rs(d)&&o(d,[h]);let l=[...s,...e.chosen],c=a.filter(d=>Es(d).some(Xr)),u=a.findIndex(Xr),f=a.slice(u<0?a.length:u+1).filter(d=>!/[/.]/.test(d));return{sels:l.some(d=>It(d.value))||[c,f].some(d=>d.length>1&&!d.every(en))||!r.every(d=>en(d.value))?[{said:"",value:st}]:l.filter(d=>en(d.value))}}function Qr(e){let t=/^[a-z][a-z0-9+.-]*:\/\/(?:[^@/\s]*@)?([^/?#\s]*)(\/[^?#\s]*)?/i.exec(e.trim());return t?`${t[1]??""} ${(t[2]??"").replace(/^\//,"")}`:e}var As=null;function Ip(e){if(As?.command===e)return As;let t=Va(e).flatMap(s=>[...s.words,...s.fed]),n=t.flatMap((s,r)=>[.../^(-h|--host)$/.test(t[r-1]??"")?[s]:[],...[...s.matchAll(/(?:^--host=|^-h(?=.)|(?:^|[\s;='"])host(?:addr)?=|^\w*HOST(?:ADDR)?=)([^\s;]*)|[a-z][\w+.-]*:\/\/\S*/gi)].map(o=>o[1]??o[0])]);return As={command:e,prod:t.find(s=>Tt(s))??null,servers:n.every(s=>!It(s)&&s.split(",").every(r=>en(Qr(r))))},As}function Dp(e,t,n){let s=[n,t].filter(a=>typeof a=="string"&&a.length>0);for(let a of s)if(Tt(Qr(a)))return{environment:"production",said:pt(a)};let r=Ip(e);if(r.prod!==null)return{environment:"production",said:pt(r.prod)};let o=s.find(a=>en(Qr(a)));return o&&r.servers?{environment:"non-production",said:pt(o)}:Nt}var Fp=["fs.root","fs.home","fs.system","fs.project_root","fs.git_dir","fs.device","git.main","proc.all"],zp=new Set(Fp),uo={"claude.bash.fs.delete_recursive":10,"claude.bash.db.destructive":9,"claude.bash.git.force_push":9,"claude.bash.git.discard":8,"claude.bash.git.push_main":8,"claude.bash.deploy":8,"claude.bash.publish":7,"claude.bash.secrets.print":7,"claude.bash.privilege":7,"claude.file.write_secret":6,"claude.file.read_secret":6,"claude.bash.process.kill_by_name":6,"claude.bash.external_write":6,"claude.bash.spend":6,"claude.bash.crypto.transaction":8,"claude.bash.secrets.expose":9,"claude.agent.controls":7,"claude.bash.net.expose":6,"claude.bash.data.export":6,"claude.bash.persistence":6,"claude.mcp.side_effect":6,"claude.bash.fs.delete_disposable":1,"claude.agent.helper":1,"claude.mcp.call":0,"claude.tool.other":0,"claude.bash.unclassified":0};var mt=new Set(["Write","Edit","MultiEdit","NotebookEdit"]),fo=new Set(["Read","Grep","NotebookRead"]),Mp=new Set(["Agent","Task","Workflow"]),Up=new Set(["Agent","Task"]),qp="claude.agent.helper";function Jl(e,t){return mn({tool:e.tool,command:e.command_local,target:e.target,cwd:e.cwd,git_branch:e.git_branch,project_dir:Hp(e),session_id:e.session_id??null},t)}function Hp(e){let t=e.source_file.split("/")[0];if(!t||!e.cwd)return null;for(let n=e.cwd;;n=R.dirname(n)){if(Aa(n)===t)return n;if(n==="/"||n==="."||n===R.dirname(n))return null}}function Bp(e,t){let n=r=>typeof r=="string"&&r!==""?Ne(r):r??null,s=typeof e.target=="string"&&(mt.has(e.tool)||fo.has(e.tool))?We(e.target)??e.target:e.target;return{input:{...e,cwd:n(e.cwd),...e.project_dir===void 0?{}:{project_dir:n(e.project_dir)},target:s},ctx:{...t,home:Ne(t.home),tmpdir:Ne(t.tmpdir),claudeConfigDir:n(t.claudeConfigDir)}}}function mn(e,t){let{input:n,ctx:s}=V()?Bp(e,t):{input:e,ctx:t},r=typeof s.claudeConfigDir=="string"&&s.claudeConfigDir.startsWith("/")?_e(s.claudeConfigDir):s.claudeConfigDir??null,o=s.home!==_e(s.home)||s.tmpdir!==_e(s.tmpdir)||(s.claudeConfigDir??null)!==r?{...s,home:_e(s.home),tmpdir:_e(s.tmpdir),claudeConfigDir:r}:s,a=I=>typeof I=="string"&&I.startsWith("/")?_e(I):I??null,i=n.cwd!==a(n.cwd)||(n.project_dir??null)!==a(n.project_dir)?{...n,cwd:a(n.cwd),project_dir:a(n.project_dir)}:n,l=uh(i),c=new Map,u=(I,D=!1)=>{let z=I.action==="claude.bash.db.destructive";if(i.tool!=="Bash"||!i.command||!z&&I.action!=="claude.bash.deploy")return{};if(D)return{environment:null,environment_said:null};let B=z?Fa(i.command,I.target,I.host):c.get(I.host);return B||c.set(I.host,B=Da(i.command,I.host)),{environment:B.environment,environment_said:B.said}},f=(I,D,z=[],B=[])=>{let Q=I??{action:"claude.bash.unclassified",service:null,target:null,branch:null,host:null,is_local:null,why:"no rule applies"},ce=B.find(K=>K.catastrophic),te=ce&&B.indexOf(ce)>15?[...B.slice(0,15),ce]:B.slice(0,16),ze=K=>u(K,B.length>16),Oe=K=>K.push&&B.length>16?{...K.push,repo_dir:null}:K.push;return{action:Q.action,service:Q.service,attributes:{target:Q.target,branch:Q.branch,host:Q.host,is_local:Q.is_local,args_hash:l,...ze(Q),...Oe(Q)},why:Q.why,parse:D,also:z,...B.length>1?{findings:te.map(K=>({action:K.action,service:K.service,target:K.target,why:K.why,...K.catastrophic?{catastrophic:!0}:{},...ze(K),...Oe(K),...K.host?{host:K.host}:{}}))}:{},...Q.catastrophic?{catastrophic:!0}:{},...i.tool==="Bash"&&(Q.action==="claude.bash.spend"||z.includes("claude.bash.spend"))?{units:ya(i.command)}:{},...(B.length>1?B.filter(K=>K.action===Q.action).every(K=>K.housekeeping):Q.housekeeping)?{housekeeping:!0}:{}}},p=i.tool;if(Up.has(p))return f(ch(i.args),"not-shell");if(Mp.has(p))return f(eo(p,"a subagent or workflow launch (its text is never read)"),"not-shell");if(p.startsWith("mcp__")){let I={hit:!1},D=Ch(i,o,I);return D.also&&D.also.length>0?f(D,I.hit?"limited":"not-shell",[...new Set(D.also.filter(z=>z!==D.action))]):f(D,I.hit?"limited":"not-shell")}if(mt.has(p)||fo.has(p)){let I=i.target??fh(i.args),D=I!==null&&V()?We(I)??I:I,z=[i.cwd,i.project_dir??null].find(te=>typeof te=="string"&&te.startsWith("/")&&!S(te))??null,B=D?D.startsWith("/")||D.startsWith("~")?M(D,null,o):z!==null?M(D,z,o):null:null,Q=te=>({...te,attributes:{...te.attributes,path:B!==null&&B.startsWith("/")&&!S(B)?B:null}});if(D&&mt.has(p)&&V()&&/^\/dev\/(?!(?:null|stdout|stderr|tty)$)/.test(D)&&!cs(D))return Q(f({action:"claude.bash.fs.delete_recursive",service:"fs.device",target:D,branch:null,host:null,is_local:!0,why:`writes a raw disk or volume (${D})`},"not-shell"));let ce=D&&mt.has(p)?Vn(D,o,[i.project_dir??null,i.cwd]):null;if(ce)return Q(f(ce,"not-shell"));if(D&&mt.has(p)&&lu(D,o)&&au.test(Rl(i.args)))return Q(f({action:"claude.agent.controls",service:null,target:D,branch:null,host:null,is_local:!0,why:`gives a subagent, command or skill its own bypass or unrestricted shell (${R.basename(D)})`},"not-shell"));if(D&&mt.has(p)&&(ot.test(D)||ot.test(Ey(D,o)))&&(pn(Rl(i.args))||pn(JSON.stringify(i.args??""))))return Q(f({action:"claude.agent.controls",service:null,target:D,branch:null,host:null,is_local:!0,why:`changes how every later Claude Code session starts (${R.basename(D)})`},"not-shell"));if(B!==null&&fo.has(p)&&!S(B)&&xu(B,o.home,p==="Grep"))return Q(f({action:"claude.agent.controls",service:null,target:B,branch:null,host:null,is_local:!0,why:$u},"not-shell"));if(D&&(mt.has(p)?ye(D):ko(D))){let te=mt.has(p);return Q(f({action:te?"claude.file.write_secret":"claude.file.read_secret",service:null,target:D,branch:null,host:null,is_local:!0,why:`${te?"writes":"reads"} a secrets file (${R.basename(D)})`},"not-shell"))}return Q(f(eo(p,`${p} of a regular file`),"not-shell"))}if(p==="PowerShell"&&i.command){let I=Vt(i.command,{cwd:i.cwd!==null?Je(i.cwd):null});return I.kind==="unreadable"?f(m("claude.bash.privilege",`runs PowerShell Anvil can't read (${I.why})`,{target:i.command.slice(0,200),is_local:null}),"partial"):mn({...i,tool:"Bash",command:I.text},o)}if(p!=="Bash"||!i.command)return f(eo(p,`the ${p} tool`),"not-shell");let d=i.project_dir??null,h=dt(i.command,{home:o.home,tmpdir:o.tmpdir,cwd:i.cwd,projectDir:d,claudeConfigDir:o.claudeConfigDir??null,...Ao(o)}),g={ctx:o,projectRoot:d,base:i.cwd,branch:i.git_branch,branchDir:i.cwd,createdBranches:new Map,stashApplied:new Set,stashCreated:!1,stashPushes:0,sessionId:i.session_id??null,lineText:i.command,lineMade:[],lineLaunched:[],secretCopies:new Set,links:new Map,downloads:new Set,cut:{hit:!1}},y=[];g.lineCommands=h.commands;for(let I of h.commands){Ng(I,g);for(let D of Gn(I,g))y.push(ty(D,I));Ft(g,()=>lh(I,g)),eh(I,g),th(I,g),nh(I,g)}Qp(i.command)&&y.push(m("claude.agent.controls","runs a command without Claude Code's session marker (CLAUDECODE), which Anvil uses to tell this session from the person's own terminal",{target:"CLAUDECODE",is_local:!0}));let $=g.cut.hit?"limited":h.status;if(y.length===0)return f(null,$);let E=[...y].sort((I,D)=>Ka(D)-Ka(I)),x=E[0],b=[...new Set(E.slice(1).map(I=>I.action).filter(I=>I!==x.action&&uo[I]>1))],j=f(x,$,b,E.filter(I=>uo[I.action]>1)),C=x.is_local===!0||x.host!==null&&Pc.test(x.host),A=Vp.has(x.action)&&x.catastrophic!==!0&&!x.housekeeping&&!C?Yp(i.args,x.target==="no server shown"):null;if(A===null)return j;let U=`${j.why} (Claude's description says ${A})`;return{...j,why:U,catastrophic:!0,...j.findings?{findings:j.findings.map((I,D)=>D===0?{...I,why:U,catastrophic:!0}:I)}:{}}}var Vp=new Set(["claude.bash.deploy","claude.bash.db.destructive","claude.bash.external_write","claude.bash.git.push_main","claude.bash.git.force_push","claude.bash.publish","claude.bash.secrets.print","claude.bash.secrets.expose","claude.bash.data.export","claude.bash.crypto.transaction","claude.bash.spend","claude.bash.net.expose"]),Zp=/(?<![A-Za-z0-9])(?<!(?:non|pre|not|no|un)[\s_-]?)(?:(?:prod|production)(?![A-Za-z0-9])(?![\s_-]+(?:build|bundle|ready|grade|quality|mode|deps|dependencies|code|like|image|assets|shape|parity|optimi[sz]\w*)\b)|go(?:es|ing)?[\s-]+live\b|went[\s-]+live\b|live[\s-]+(?:site|app|application|environment|env|database|db|cluster|servers?|system|stack|account|customers?|users?|traffic|instance|deployment|mode|store|services?|keys?)\b)/i,Gp=/\b(?:drop|wipe|truncate|destroy|erase|purge|nuke|delete)\w*\s+(?:(?:the|all|every|entire|whole)\s+)*(?:(?:all|every|entire|whole)\s+(?:\w+\s+)?(?:tables|databases?|dbs?|schemas?|collections|keyspaces?|clusters?)|(?:database|db|cluster)\b(?![.-]\w)(?!\s+(?:file|connection|client|config|entry|row|record|column|migration|pod|node|member|replica|shard|user|role|secret|namespace|context)s?\b))/i,Kp=/\b(local|localhost|dev|development|test|testing|tests|sandbox|scratch|temp|tmp|throwaway)\b/i;function Yp(e,t=!1){let n=e!==null&&typeof e=="object"?e.description:void 0;if(typeof n!="string")return null;let s=Math.min(n.length,500);if(n.length>500)for(;s>0&&/[A-Za-z0-9_]/.test(n[s-1]);)s--;let r=n.slice(0,s),o=r.toLowerCase();return(o.includes("prod")||o.includes("prd")||o.includes("live"))&&Zp.test(r)?"production":!t&&["drop","wipe","truncate","destroy","erase","purge","nuke","delete"].some(a=>o.includes(a))&&Gp.test(r)&&!Kp.test(r)?"a whole database or cluster is wiped":null}var Jp=/(^|\/)\.git\/(worktrees\/[^/]+\/)?((logs|refs)(\/|$)|(packed-refs|HEAD|ORIG_HEAD|FETCH_HEAD)$)/,Dn="(?:CLAUDECODE|CLAUDE_CODE_ENTRYPOINT)",Ps=String.raw`(?:^|[;&|(\n{]\s*|\$\(\s*)(?:(?:nohup|sudo|exec|command|time|nice|builtin)\s+)*`,Xp=new RegExp([String.raw`${Ps}(?:(?:export|declare\s+-x|typeset\s+-x|local|readonly)\s+)?(?:[A-Za-z_][A-Za-z0-9_]*=\S*\s+)*(?:CLAUDECODE=(?!1(?:[\s;&|)]|$))|CLAUDE_CODE_ENTRYPOINT=)`,String.raw`${Ps}setenv\s+${Dn}\b`,String.raw`${Ps}unset\s+(?:-[vf]\s+)?(?:\w+\s+){0,8}${Dn}\b`,String.raw`${Ps}env\s+(?:\S+\s+){0,8}?(?:-u\s*${Dn}\b|--unset[=\s]\s*${Dn}\b|CLAUDECODE=(?!1(?:\s|$))|CLAUDE_CODE_ENTRYPOINT=)`,String.raw`(?:del\s+os\.environ|delete\s+process\.env|environ\.pop|unsetenv|Remove-Item\s+Env:)[^;\n]{0,24}${Dn}`].join("|"));function Qp(e){return Xp.test(e.slice(0,65536))}function Ao(e){return{knownFiles:e.session?.scripts??null,unreadableFiles:e.session?.unreadableScripts??null,wantFiles:e.wantScripts??null}}function Jn(e,t,n,s=n.projectRoot){let r=dt(e,{home:n.ctx.home,tmpdir:n.ctx.tmpdir,cwd:t,projectDir:s,claudeConfigDir:n.ctx.claudeConfigDir??null,...Ao(n.ctx)});return r.status==="limited"&&(n.cut.hit=!0),r}function Xl(e,t){let n=t.lineMade.length+t.lineLaunched.length>0?{...t.ctx,session:{...t.ctx.session??{made:[],launched:[]},made:ec(t),launched:Ql(t)}}:t.ctx,s=mn(e,n);return s.parse==="limited"&&(t.cut.hit=!0),s}var Ga=200;function Ge(e,t){return e.length>Ga&&(t.hit=!0),e.slice(0,Ga)}function eh(e,t){let n=e.argv;if(e.name!=="ln"||!n.slice(1).some(l=>/^-[a-zA-Z]*s/.test(l)||l==="--symbolic"))return;let s=n.findIndex(l=>l==="--target-directory"||/^-[a-zA-Z]*t$/.test(l)),r=s>0?n[s+1]:n.find(l=>l.startsWith("--target-directory="))?.slice(19),o=n.slice(1).filter((l,c)=>!l.startsWith("-")&&c+1!==s+1&&!["-S","--suffix"].includes(n[c]??""));if(o.some(S)||r!==void 0&&S(r))return;let a=(l,c)=>R.normalize(X(l,c,se(t)).path??l),i=r!==void 0?o.map(l=>[l,R.join(r,R.basename(l))]):o.length===1?[[o[0],R.basename(o[0])]]:o.length===2?[[o[0],o[1]]]:[];for(let[l,c]of i){let u=a(c,e.cwd);t.links.set(u,a(l,R.dirname(u)))}}function th(e,t){if(!nr.has(e.name))return;let n=e.argv,s=n.find(a=>un(a));if(!s||Re(s))return;let r=e.name==="wget"?["-O","--output-document"]:["-o","--output"],o=n.find((a,i)=>r.includes(n[i-1]??""))??n.find(a=>a.startsWith(`${r[1]}=`))?.split("=")[1];o&&!S(o)&&o!=="-"&&t.downloads.add(X(o,e.cwd,se(t)).path)}function nh(e,t){if(t.lineMade.length+t.lineLaunched.length>64)return;let n=Hr(e,{home:t.ctx.home,tmpdir:t.ctx.tmpdir,projectDir:t.projectRoot});t.lineMade.push(...n.paths),t.lineLaunched.push(...n.launched)}function Ql(e){let t=e.ctx.session?.launched??[];return e.lineLaunched.length>0?[...t,...e.lineLaunched]:t}function ec(e){let t=e.ctx.session?.made??[];return e.lineMade.length>0?[...t,...e.lineMade]:t}function it(e,t){let n=e.ctx.session?.probed,s=Wn(t);if(n&&s in n)return n[s]??null;e.ctx.wantProbes?.set(s,t)}function Eo(e){let t=e.ctx.session?.startedAt;return typeof t=="number"&&t>0?t-1e3:null}function tc(e){let t=r=>{if(!r||S(r)||_e(r)===_e(e.ctx.home))return null;let o=it(e,{kind:"file",arg:r});return typeof o=="string"?o.split(" ")[0]:o},n=t(e.base),s=e.projectRoot?t(e.projectRoot):null;return n===void 0||s===void 0?null:{here:n,project:s}}function sh(e,t,n){let s=o=>o.replace(/^\/private(?=\/(?:var|tmp)\/)/,""),r=s(e);return an(r,t.here&&s(t.here))||an(r,t.project&&s(t.project))||(n.ctx.session?.made??[]).some(o=>an(r,s(o)))}var $t=e=>e.wrappers.some(t=>["sudo","doas","pkexec","run0"].includes(t)),an=(e,t)=>!!t&&(e===t||e.startsWith(`${t}/`));function Ro(e){let t=it(e,{kind:"ps"});if(typeof t!="string")return null;let n=new Map;for(let s of t.split(`
|
|
37
|
-
`)){let r=/^\s*(\d+)\s+(\d+)\s+(.*)$/.exec(s);r&&
|
|
38
|
-
`).map(l=>l.trim()).filter(l=>/^\d+$/.test(l)))];if(a.length===0)return"own";let i=a.filter(l=>
|
|
39
|
-
`).filter(f=>f!=="").map(f=>Number(/@\{(\d+)\}/.exec(f)?.[1]??NaN)*1e3);if(l.some(f=>Number.isNaN(f)))return!1;if(t)return l.every(f=>f>=a);let c=/^stash@\{(\d+)\}$/.exec(e)?.[1];if(c===void 0)return!1;let u=l[Number(c)]??(s.stashCreated?l[Number(c)-1]:void 0);return u===void 0||u>=a}function ih(e,t,n){let s=Eo(n);if(/\bbranch\b[^;&|\n]*\s(-[a-zA-Z]*[mMcC][a-zA-Z]*|--move|--copy)(\s|$)/.test(n.lineText)||s===null||!t||!/^[\w./-]+$/.test(e)||e.startsWith("-"))return!1;let r=it(n,{kind:"branch",arg:e,cwd:t}),o=typeof r=="string"?r.trim().split(`
|
|
40
|
-
`).pop()??"":"",a=/@\{(\d+)\} branch: Created from /.exec(o);return a!==null&&Number(a[1])*1e3>=s}function oc(e,t){return it(t,{kind:"ignored",arg:e,cwd:R.dirname(e)})===""}function ah(e,t){if(S(e))return null;let n=Eo(t),s=it(t,{kind:"file",arg:e}),r=tc(t),o=oc(e,t);if(typeof s!="string"||!r||!o)return null;let[a,i]=s.split(" ");return!an(a,r.here)&&!an(a,r.project)?null:n!==null&&Number(i)>=n?"own":"dev"}function Ie(e,t,n){if(n.links.size===0||S(e))return e;let s=e.startsWith("/")?e:e.startsWith("~/")?n.ctx.home+e.slice(1):t.cwd?`${t.cwd}/${e}`:e;if(!s.startsWith("/"))return e;let r=s.split("/").filter(i=>i!==""),o="/",a=!1;for(let[i,l]of r.entries()){if(l===".")continue;o=l===".."?R.dirname(o):R.join(o,l);let c=i===r.length-1&&!s.endsWith("/");for(let u=0;!c&&u<8&&n.links.has(o);u++)o=n.links.get(o),a=!0}return a?o+(s.endsWith("/")?"/":""):e}function lh(e,t){let n=e.argv.slice(1).filter(a=>!a.startsWith("-")),s=a=>t.secretCopies.add(X(a,e.cwd,se(t)).path);if(["cp","mv","install","ditto","rsync"].includes(e.name)&&n.length>=2&&n.slice(0,-1).some(a=>ye(a)||t.secretCopies.has(X(a,e.cwd,se(t)).path))&&s(n[n.length-1]),e.name==="cat"&&n.some(a=>ye(a)))for(let a of e.redirects)(a.op===">"||a.op===">>")&&a.target&&s(a.target);let r=[];for(let a=1,i=!1;a<e.argv.length;a++){let l=e.argv[a];if(["--exclude","--exclude-from","-X"].includes(l))a++;else{if(l.startsWith("--exclude"))continue;e.name==="zip"&&(l==="-x"||l==="--exclude")?i=!0:l.startsWith("-")?i=!1:i||r.push(l)}}if(["tar","gtar","bsdtar","zip","7z"].includes(e.name)&&r.some(a=>ye(a)||/(^|\/)\.(ssh|aws|gnupg|kube)\/?$/.test(k(a)))){let a=/^[A-Za-z]+$/.test(e.argv[1]??"")&&(e.argv[1]??"").includes("f")?e.argv[2]:void 0,i=P(e.argv,"-f","--file")??Bs(e.argv,"f")??a??(e.name==="zip"||e.name==="7z"?n.find(l=>/\.(zip|7z)$/.test(l)):n[0]);i&&s(i)}let o=e.stdinFile!==null&&ye(e.stdinFile)||e.pipeFrom!==null&&e.pipeFrom.name==="cat"&&e.pipeFrom.argv.slice(1).some(a=>ye(a));if(e.name==="tee"&&o)for(let a of n)s(a)}function Ka(e){return(e.service&&zp.has(e.service)?100:0)+uo[e.action]}function ch(e){let t=e&&typeof e=="object"?e:{},n=typeof t.subagent_type=="string"&&t.subagent_type.trim()?t.subagent_type.trim():"general-purpose",s=/^[A-Za-z0-9_.:-]{1,64}$/.test(n)?n:`type-${Yl("sha256").update(n).digest("hex").slice(0,8)}`,r=typeof t.model=="string"&&/^[a-z0-9.\-[\]]{1,40}$/i.test(t.model)?t.model:null;return{action:qp,service:null,target:s,branch:null,host:null,is_local:null,why:`launches a helper agent (${s}${r?`, ${r}`:""})`}}function eo(e,t){return{action:"claude.tool.other",service:null,target:e,branch:null,host:null,is_local:null,why:t}}function uh(e){if(e.args===void 0&&e.command===null&&e.tool.startsWith("mcp__"))return null;let t=e.args!==void 0?po(e.args):e.command??e.target??"";return Yl("sha256").update(JSON.stringify([e.tool,t])).digest("hex").slice(0,16)}var dh=64;function po(e,t=0){return t>dh?"[nested too deep]":Array.isArray(e)?e.map(n=>po(n,t+1)):e&&typeof e=="object"?Object.fromEntries(Object.keys(e).sort().map(n=>[n,po(e[n],t+1)])):e}function fh(e){if(!e||typeof e!="object")return null;let t=e;for(let n of["file_path","notebook_path","path"])if(typeof t[n]=="string")return t[n];return null}var zn=new Set(["ask","get","list","search","read","fetch","find","query","describe","view","show","lookup","check","count","browse","preview","inspect","status","info","details","stats","history","logs","index","guide","help","export","download","screenshot","validate","diff","compare","estimate","explain","summarize","extract","scrape","research","retrieve","whoami","analyze","analyse","aggregate","size","health","usage","schema","metadata","metrics","overview","summary","parse"]),wt=new Set(["send","reply","forward","post","publish","deploy","merge","delete","remove","destroy","purge","trash","wipe","drop","purchase","buy","pay","payout","refund","charge","transfer","withdraw","cancel","revoke","archive","unpublish","create","update","write","insert","append","upload","share","grant","execute","exec","upsert","submit","invite","modify","patch","put","replace","schedule","approve","provision","trigger","enable","disable","assign","import","add","set","close","stop","scale","rollout","transition","restore","invoke","fork","move","rename","clear","discard","clean","edit","run","change","save","store","commit","push","start","restart","pause","resume","reopen","resolve","mark","pin","unpin","react","star","follow","subscribe","unsubscribe","link","unlink","attach","detach","lock","unlock","block","ban","mute","duplicate","copy","sync","apply","rebase","draft","notify","reserve","register","claim","redeem","capture","void","mint","broadcast","swap","stake","activate","deactivate","suspend","reset","rotate","generate","train","launch","spawn","kill","terminate","reboot","shutdown","setup","manage","configure","initialize","init","install","uninstall","upgrade","migrate","seed","reindex"]),vt=new Set(["delete","remove","destroy","purge","trash","wipe","drop","terminate","reset","flush","rollback","revert","rotate","revoke","kill","truncate","erase","push","apply","merge","deploy","publish","refund","charge","pay","payout","transfer","clear","restore","discard"]),ph=/^(ccd_(turn|view|window|sidebar|session|directory)|visualize|claude_browser|claude_in_chrome|computer_use)$/,hh=/^ccd_pr__(set_monitor|bind_pr|unbind_pr|get_status)$/,Ya=/^(playwright|puppeteer|browser|browsermcp|browser_use|chrome_devtools|chrome|everything|filesystem|fs|files|desktop_commander|desktopcommander|git|docker|sqlite)$/,gh=/^(memory|sequential_thinking|sequentialthinking|time)$/,mh=new Set(["push","delete","clean","force","rebase","prune","gc","filter"]),yh=new Set(["env","environment","secret","secrets","credential","credentials","password","passwords"]),bh=new Set(["backups","deployments","releases","migrations","payments","payouts","refunds","transfers","charges","subscriptions","jobs","runs","builds","workflows","stacks","instances","clusters","resources","records","messages","emails","invites","invitations","webhooks","keys","tokens","secrets","domains","dns","databases","tables","volumes","buckets","users","members","roles","permissions"]),wh=new Set(["hget","hgetall","hexists","hkeys","hvals","hlen","lrange","llen","lindex","smembers","sismember","scard","zrange","zscore","zcard","exists","ttl","pttl","type","dbsize","xrange","xlen","mget","scan","keys"]),kh=/^(context7|brave_search|brave|fetch|deepwiki|ref|microsoft_docs|aws_docs|mcp_registry)$/,vh=/^(filesystem|fs|files|desktop_commander|desktopcommander)$/;function ic(e){return e.replace(/([a-z0-9])([A-Z])/g,"$1_$2").toLowerCase().split(/[^a-z0-9]+/).filter(Boolean)}function zs(e){let t=ic(e);if(t.length===0)return"unknown";let n=t[0],s=t[t.length-1],r=t.find(a=>zn.has(a)||wt.has(a)||vt.has(a))??n;return t.some(a=>vt.has(a))&&!zn.has(r)||t.findIndex((a,i)=>i>0&&["or","and","then"].includes(a)&&t.slice(i+1).some(l=>wt.has(l)||vt.has(l)))>0?"write":zn.has(r)||zn.has(s)&&!t.slice(0,-2).some(a=>wt.has(a))&&!wt.has(n)?"read":t.some(a=>wt.has(a))?"write":t.length===1&&wh.has(n)||t.length>1&&/[a-z]{3}s$/.test(s)&&!/(ss|us|is)$/.test(s)&&!bh.has(s)?"read":"unknown"}function $h(e){return e.length===1?["bash","shell","terminal","sh","zsh"].includes(e[0]):(e.includes("write")||e.includes("send"))&&e.includes("terminal")||e.includes("bash")&&e.includes("command")?!0:e.some(t=>["run","exec","execute","start","interact"].includes(t))&&e.some(t=>["command","commands","terminal","shell","script","cmd","bash","process"].includes(t))}function xh(e){let t=e.args!==void 0?e.args:e.command?ac(e.command):void 0;return t&&typeof t=="object"&&!Array.isArray(t)?t:null}function ac(e){try{return JSON.parse(e)}catch{return}}function nn(e,t){for(let n of t)if(e&&typeof e[n]=="string")return e[n];return null}function Ja(e){if(!e)return[];let t=[];for(let n of["path","file_path","filePath","relative_path","relativePath","pathInProject","repo_path","repoPath","source","destination","target","targetPath","sourcePath","destinationPath","file","filename","dest","from","to","old_path","new_path","oldPath","newPath","paths","files"]){let s=e[n];if(typeof s=="string")t.push(s);else if(Array.isArray(s))for(let r of s.slice(0,64))typeof r=="string"&&t.push(r)}return V()?t.map(n=>We(n)??n):t}function lc(e,t){if(e.action==="claude.bash.unclassified")return[];let n={action:e.action,service:e.service,target:e.attributes.target,branch:e.attributes.branch,host:e.attributes.host,is_local:e.attributes.is_local,why:`${e.why} ${t}`};return[n,...e.also.filter(s=>s!==e.action).map(s=>({...n,action:s,service:null}))]}var _h=new Set(["supabase","neon","planetscale","turso","bigquery","snowflake","databricks","motherduck","xata","cloudflare","d1","upstash","spanner","redshift","tinybird","firebase","railway","render","heroku","vercel","nile","tidb","aiven","aws","azure","gcp"]),Sh=/^(database|db|database_?name|db_?name|branch|branch_?name|branch_?id|project|project_?id|project_?ref|env|environment|schema|catalog|dataset|instance)$/i;function Ch(e,t,n){let[,s="",r=""]=e.tool.split("__"),o=Qa(s),a=`mcp.${o}.${Qa(r)}`,i=ic(r),l=xh(e),c=p=>({action:"claude.mcp.call",service:null,target:a,branch:null,host:o,is_local:null,why:p}),u=p=>({action:"claude.mcp.side_effect",service:null,target:a,branch:null,host:o,is_local:null,why:p});if($h(i)||nn(l,["cli_command"])!==null){let p=l?.action_json,d=typeof p=="string"?ac(p):p,h=nn(l,["command","cmd","script","input","code","cli_command"])??nn(d&&typeof d=="object"&&!Array.isArray(d)?d:null,["command","cmd"]);if(h===null)return u(`an MCP tool that runs shell commands, with no command to read (${a})`);let g=nn(l,["cwd","workdir","directory"])??e.cwd,y=mn({tool:"Bash",command:h,target:null,cwd:g,git_branch:e.git_branch,project_dir:e.project_dir??null,session_id:e.session_id??null},t);return y.parse==="limited"&&(n.hit=!0),ku(h,g,t,e.project_dir??null,n,i.includes("terminal"))?y.action==="claude.bash.unclassified"?c(`an MCP tool running a command no rule flags (${a})`):{action:y.action,service:y.service,target:y.attributes.target,branch:y.attributes.branch,host:y.attributes.host,is_local:y.attributes.is_local,why:`${y.why} (run by ${a})`,also:y.also}:{action:"claude.agent.controls",service:null,target:a,branch:null,host:o,is_local:!0,why:`hands a command to ${a}, which may run it outside this session, and Anvil cannot read that command here`}}if(zs(r)!=="read"){let p=Ja(l).map(h=>Vn(h,t,[e.project_dir??null,e.cwd])).filter(h=>h!==null),d=p.find(h=>h.action==="claude.agent.controls")??p[0];if(d)return{...d,host:o,also:[...new Set(p.map(h=>h.action))]};for(let h of Ja(l))if(ot.test(h)&&pn(JSON.stringify(l)))return{action:"claude.agent.controls",service:null,target:h,branch:null,host:o,is_local:!0,why:`changes how every later Claude Code session starts (${R.basename(h)}, through ${a})`}}if(vh.test(o)){let p=nn(l,["path","file_path","filePath","destination","target"]),d=zs(r);if(p&&ye(p)){let h=d!=="read";return{action:h?"claude.file.write_secret":"claude.file.read_secret",service:null,target:p,branch:null,host:o,is_local:!0,why:`${h?"writes":"reads"} a secrets file (${R.basename(p)}) through ${a}`}}}if(i.some(p=>["sql","query"].includes(p))&&i.some(p=>["run","execute","exec","query"].includes(p))){let p=nn(l,["sql","query","statement"]);if(p!==null&&!(Mo.test(p)||be.test(p)))return c(`an MCP tool running a read-only query (${a})`);let d=on(p),h=o.split("_").some(y=>_h.has(y))&&!o.split("_").includes("local"),g=d===null?void 0:[...Object.entries(l??{}).filter(([y,$])=>Sh.test(y)&&typeof $=="string"&&$.length<200&&!/\s/.test($)).map(([,y])=>y)].find(or);if(p!==null)return d!==null&&(h||g!==void 0)?{...u(`an MCP tool running destructive SQL (${d}) on ${g!==void 0?`${g}, named for production`:`${o}'s hosted database`} (${a})`),catastrophic:!0}:u(`an MCP tool running SQL that writes (${a})`)}if((i.includes("sql")||i.includes("query")&&i.some(p=>["database","db","d1","sql"].includes(p)))&&!Ya.test(o))return u(`an MCP tool that runs SQL, with no statement to read (${a})`);if(hh.test(`${o}__${r}`))return c(`a setting of this machine's own app (${a})`);if(ph.test(o)){let p=i.find(d=>["upload","send","submit","purchase","buy","publish"].includes(d));return p?u(`a browser tool that ${p}s something to a website (${a})`):c(`a tool of this machine's own app (${a})`)}if(gh.test(o))return c(`the agent's own notes or thinking (${a})`);let f=zs(r);if(i.some(p=>yh.has(p))&&f!=="write")return u(`an MCP tool that reads secrets or the environment (${a})`);if(kh.test(o)){let p=i.find(d=>vt.has(d)||["upload","send","submit","publish","post","create","update","write"].includes(d));return p?u(`an MCP tool that ${p}s (${a})`):c(`a documentation tool (${a})`)}if(Ya.test(o)){let p=o==="git"?i.find(h=>mh.has(h)):i.find(h=>vt.has(h));if(p&&!zn.has(i[0]??""))return u(`a local MCP tool that ${p}s (${a})`);if(o==="docker"&&i.some(h=>["run","exec","execute"].includes(h)))return u(`a local MCP tool that runs a container or a command in one (${a})`);let d=i.find(h=>["upload","send","submit","purchase","buy","publish","post"].includes(h));return d?u(`a local MCP tool that ${d}s something to another service (${a})`):f==="write"&&i.some(h=>["config","configuration","settings","setting","permission","permissions","policy"].includes(h))?u(`a local MCP tool that changes its own configuration (${a})`):c(`a tool that acts on this machine (${a})`)}return f==="read"?c(`an MCP tool that reads (${a})`):Ph(i,l)?c(`an MCP edit to a document's content (${a})`):f==="unknown"&&["profile","me","whoami"].includes(i[i.length-1]??"")&&!i.some(p=>wt.has(p)||vt.has(p))?c(`an MCP tool that returns the caller's profile (${a})`):u(f==="write"?`an MCP tool that ${i.find(p=>vt.has(p))??i.find(p=>wt.has(p))}s (${a})`:`an MCP tool whose name does not say it only reads (${a})`)}var Ah=new Set(["update","edit","append","insert","write","replace","patch","save","create","batch","add","set","modify","change","draft","rename"]),Eh=new Set(["doc","docs","document","documents","page","pages","block","blocks","note","notes","section","sections","tab","tabs","paragraph","paragraphs","wiki","article","articles","markdown","prose"]),Rh=new Set(["delete","remove","destroy","purge","trash","archive","share","unshare","publish","unpublish","send","post","comment","invite","grant","permission","permissions","move","transfer","email","notify","export"]),Oh=/^(share|shares|sharing|shared_with|permission|permissions|visibility|public|is_public|publish|published|invite|invites|invitees|recipient|recipients|to|cc|bcc|email|emails|role|roles|grant|grants|notify|send|send_notification|acl|access|access_level|link_sharing)$/i,Xa=/share|publish|permission|invite|send|notify|email|trash|archive|transfer|(delete|remove)[-_ ]?(doc|document|page|file|project)/i,jh=/^(page_?id|document_?id|doc_?id|block_?id|note_?id|documentId|pageId|docId|blockId|noteId)$/i;function Ph(e,t){if(!t||e.length===0||!e.some(a=>Ah.has(a))||e.some(a=>Rh.has(a)))return!1;let n=!1,s=!1,r=!1,o=(a,i)=>{if(!(n||i>12||a===null||typeof a!="object")){if(Array.isArray(a)){for(let l of a.slice(0,500))o(l,i+1);return}for(let[l,c]of Object.entries(a))Oh.test(l)&&(n=!0),jh.test(l)&&(s=!0),["op","type","action","operation"].includes(l)&&typeof c=="string"&&Xa.test(c)&&(n=!0),(l==="kind"&&typeof c=="string"&&/^(blocks?|text|tabs?|range|paragraphs?|sections?|heading|inline|markdown)$/.test(c)||l==="engine"&&typeof c=="string")&&(r=!0),i===0&&l==="container"&&c&&typeof c=="object"&&typeof c.kind=="string"&&(r=!0),i===0&&l==="ref"&&c&&typeof c=="object"&&/^(project|tab|node|doc|document|page|block)$/.test(String(c.object))&&(r=!0),l==="kind"&&typeof c=="string"&&Xa.test(c)&&(n=!0),o(c,i+1)}};return o(t,0),n?!1:e.some(a=>Eh.has(a))||s||r}function Qa(e){return e.toLowerCase().replace(/[^a-z0-9_]+/g,"_").replace(/^_+|_+$/g,"")||"unknown"}var cc=new Set(["main","master"]),Wh=new Set(["production","prod","live"]);function m(e,t,n={}){let s=t.replace(/[\u0000-\u0008\u000b-\u001f\u007f-\u009f--]/g,""),r=s.length>300?`${s.slice(0,297)}\u2026`:s,o=typeof n.target=="string"&&n.target.length>200?{...n,target:`${n.target.slice(0,197)}\u2026`}:n;return{action:e,service:null,target:null,branch:null,host:null,is_local:null,why:r,...o}}function Nh(e,t){if(!S(e.argv[0]??""))return[];let n=e.argv.slice(1),s=[];n.some(o=>/^-[rRfviIdP]*[rR][rRfviIdP]*$/.test(o)||o==="--recursive")&&n.some(o=>!o.startsWith("-"))&&s.push(...Io({...e,name:"rm",argv:["rm",...n]},t)),(n.includes("manage.py")||n.some(o=>/^db:(drop|reset)/.test(o)))&&s.push(...Hs({...e,name:"python",argv:["python",...n]}));let r=o=>({...e,name:o,argv:[o,...n]});return["push","reset","clean","branch","stash","checkout","restore"].includes(n[0]??"")&&s.push(...Ac(r("git"),t)),["destroy","apply"].includes(n[0]??"")&&n.some(o=>o.startsWith("-auto-approve")||o==="-auto-approve")&&s.push(...Hs(r("terraform"))),["delete","apply","replace","drain"].includes(n[0]??"")&&s.push(...Hs(r("kubectl"))),["publish","unpublish"].includes(n[0]??"")&&s.push(...qc(r("npm"))),n.includes("-c")&&be.test(ke(n.join(" ")))&&s.push(...Ho(r("psql"),t)),s.map(o=>o.why.includes("cannot name")?o:{...o,why:`${o.why} (by a program it cannot name: ${k(e.argv[0])})`})}function Gn(e,t){if(e.functionCall)return[...Kl(e,t),...El(e,t),...tr(e,t)];let n=Bm(e.argv);if(n!==null)return Gn({...e,name:ue(n[0]),argv:n},t);if(["pnpm","yarn","bun"].includes(e.name)){let{sub:o,at:a}=bs(e.argv);if(a>0&&!qo.has(o)&&Em.has(o))return Gn({...e,name:o,argv:[o,...e.argv.slice(a+1)]},t)}if(e.argv.slice(1).some((o,a)=>(o==="--help"||o==="--version"&&a===0)&&!/^-/.test(e.argv[a]??""))||["help","--help"].includes(e.argv[1]??""))return e.redirects.length>0?tr({...e,name:"echo",argv:["echo"]},t):[];let s=[];s.push(...Bb(e,t)),s.push(...ew(e)),s.push(...lw(e,t)),s.push(...Nh(e,t)),s.push(...Kl(e,t));let r=e.name;switch(r){case"rm":case"unlink":case"shred":case"srm":case"rimraf":s.push(...Io(e,t));break;case"rsync":s.push(...$c(e,t));break;case"find":s.push(...Rg(e,t));break;case"fd":case"fdfind":s.push(...jg(e,t));break;case"dd":case"mkfs":case"diskutil":case"wipefs":case"fdisk":case"newfs_apfs":case"newfs_hfs":s.push(...fl(e,t));break;case"git":s.push(...Ac(e,t));break;case"gh":s.push(...zg(e,t.lineText,t));break;case"curl":case"wget":case"http":case"https":case"xh":s.push(...Mg(e));break;case"pkill":case"killall":case"kill":case"fuser":case"colima":case"launchctl":case"tmux":case"systemctl":case"shutdown":case"reboot":case"halt":case"osascript":s.push(...Yg(e,t));break;default:break}if(r.startsWith("mkfs.")&&s.push(...fl(e,t)),s.length===0&&s.push(...Mh(e,t)),s.push(...Hs(e)),(r==="docker"||r==="podman"||r==="docker-compose")&&!s.some(o=>o.action==="claude.bash.deploy")&&s.push(...wm(e,t.lineText)),s.length===0&&s.push(...Uh(e)),s.push(...Ho(e,t)),s.push(...Ft(t,()=>dy(e,t))),s.push(...El(e,t)),s.push(...Ft(t,()=>hy(e,t))),s.push(...qb(e,t)),s.push(...Yb(e,t)),V()&&s.push(...lb(e,t)),s.push(...fg(e)),s.length===0&&s.push(...Vm(e)),s.length===0&&s.push(...Lh(e)),s.length===0&&s.push(...Bh(e)),s.length===0&&s.push(...Ft(t,()=>kg(e,t))),!s.some(o=>o.action==="claude.bash.db.destructive"&&!o.why.includes(" runs SQL that changes data ("))){let o=Hm(e,t);if(o.length>0){for(let a=s.length-1;a>=0;a--)s[a].why.includes(" runs SQL that changes data (")&&s.splice(a,1);s.push(...o)}}return["aws","gcloud","az"].includes(e.name)&&e.argv.some(o=>o==="update-kubeconfig"||o==="get-credentials")&&P(e.argv,"--file","-f")!=="-"&&!T(e.argv,"--dry-run")?s.filter(o=>o.action!=="claude.bash.deploy"&&o.action!=="claude.bash.secrets.print"):s}var Oo=new Set(["npm","pnpm","yarn","bun","npx","pnpx","bunx","deno","node","nodejs","pip","pip3","pipx","poetry","uv","pdm","hatch","rye","conda","mamba","micromamba","brew","apt","apt-get","yum","dnf","pacman","apk","port","nix","nix-env","flatpak","snap","cargo","rustup","gem","bundle","bundler","go","composer","pod","carthage","flutter","dart","dotnet","mvn","gradle","make","cmake","ninja","bazel","xcodebuild","xcrun","swift","nvm","fnm","volta","asdf","mise","rbenv","pyenv","sdk","direnv","pre-commit","husky","lefthook","git","hg","svn","docker","podman","colima","minikube","kind","k3d","vagrant","tmux","screen","code","cursor","vim","nvim","emacs","jest","vitest","pytest","mocha","eslint","prettier","tsc","python","python3","ruby","perl","php","java","echo","printf","ls","cat","grep","rg","sed","awk","jq","yq","sort","uniq","head","tail","wc","cut","tr","tee","touch","mkdir","cp","mv","ln","chmod","chown","tar","zip","unzip","gzip","gunzip","open","say","defaults","du","df","stat","file","which","type","command","test","true","false","sleep","wait","date","seq","basename","dirname","realpath","readlink","cd","export","unset","set","source","eval","exec","trap","read","history","sqlite3","redis-server","pg_ctl","initdb","ollama","anvil","anvil-claude","claude","pm2","nodemon","turbo","nx","lerna","changeset","rimraf","trash","kubectx","kubens","corepack","tsx","ts-node","esbuild","vite","next","webpack","rollup","parcel","storybook","playwright","cypress","lsof","ps","top","pgrep","pkill","kill"]),el=null;function Zs(e){return el??=new Set([...Object.keys(Tc),...nr,"aws","az","gcloud","gsutil","bq","kubectl","helm","terraform","tofu","pulumi","psql","mysql","mariadb","mongosh","mongo","mongoimport","mongorestore","pg_restore","pg_dump","redis-cli","clickhouse","clickhouse-client","cqlsh","snowsql","snow","beeline","impala-shell","spark-sql","heroku","railway","vercel","wrangler","fly","flyctl","firebase","doppler","infisical","vault","op","security","gpg","gpg2","prisma","alembic","artisan","rails","rake","flask","rsync","find","fd","dd","gh","ssh","scp","sftp","crontab","systemctl","launchctl","ngrok","cloudflared","tailscale","stripe","cast","forge","solana","fastlane","eas","7z","7za","7zr","7zz","aider","amp","anchor","anvil","anvil-claude","ape","aptos","artisan","at","autossh","awk","aws","az","azcopy","base64","batch","bcp","beeline","bitcoin-cli","bore","bq","branch","brew","brownie","bsdtar","bun","cardano-cli","cast","checkout","chflags","chgrp","chmod","chown","claude","clean","clickhouse","clickhouse-client","cloudflared","cmp","cockroach","code","code-insiders","codex","colima","copilot","cp","cqlsh","croc","crontab","crush","curl","cursor-agent","cut","databricks","dbt","dd","ddev","deno","devtunnel","diff","diskutil","ditto","docker","droid","dropdb","dropuser","duckdb","ed","egrep","emacs","ex","expo","fastmcp","fd","fdfind","fdisk","ffsend","filter-branch","filter-repo","find","firebase","fish","fly","flyctl","flyway","forge","frpc","fuser","gawk","gc","gcloud","gcp","gemini","gh","git","glab","gmv","gpg","gpg2","grep","gsed","gsutil","gtar","halt","hardhat","head","herd","heroku","http","https","impala-shell","install","install-mcp","jq","kill","killall","knex","kubectl","launchctl","liquibase","ln","lncli","localxpose","loclx","lt","mariadb","mariadb-dump","mawk","mc","mcp-get","md5","md5sum","mix","mkfifo","mkfs","mknod","mongo","mongodump","mongoexport","mongosh","mv","mydumper","mysql","mysqladmin","mysqldump","mysqlpump","nawk","nc","ncat","near","neon","neonctl","netcat","newfs_apfs","newfs_hfs","ngrok","node","nvim","oc","openssl","osascript","patch","pbcopy","perl","pg_basebackup","pg_dump","pg_dumpall","pgcli","php","pkill","plutil","pm2","podman","powershell","powershell.exe","presto","prisma","pscale","psql","push","pwsh","pwsh.exe","python","python3","q","qwen","rclone","reboot","red","redis-cli","reflog","reset","restore","rg","rimraf","rm","rsync","ruby","s3cmd","schtasks","schtasks.exe","scp","security","sed","sequelize","sequelize-cli","set","sftp","sha256sum","shasum","shred","shutdown","smithery","snow","snowsql","socat","solana","soroban","sort","spark-sql","spl-token","sponge","sqlcmd","sqlite","sqlite3","srm","ssh","starkli","stash","stellar","stripe","sui","supabase","switch","symbolic-ref","systemctl","tailscale","tar","tee","telnet","tmole","tmux","touch","trash","trino","true","truffle","truncate","ts-node","tsx","tunnelmole","turso","typeorm","typeorm-ts-node-commonjs","typeorm-ts-node-esm","unlink","untun","unzip","update-ref","valet","vi","vim","wc","wget","wipefs","worktree","wormhole","wrangler","xclip","xh","yq","zrok","format","format-volume","clear-disk","initialize-disk","remove-partition","clear-recyclebin","diskpart","vssadmin","wmic","wbadmin","wsl","bcdedit","reg","set-itemproperty","new-itemproperty","remove-itemproperty","remove-item","sc","new-service","remove-service","set-service","stop-service","register-scheduledtask","set-scheduledtask","unregister-scheduledtask","new-scheduledtask","set-executionpolicy","set-mppreference","add-mppreference","netsh","set-netfirewallprofile","new-netfirewallrule","disable-netfirewallrule","remove-netfirewallrule","takeown","icacls","taskkill","runas","gsudo","mountvol","robocopy","setx","forfiles"]),ab.has(e)?V():el.has(e)}var rn=new Set(["delete","destroy","drop","purge","wipe","terminate","nuke","erase","truncate","flushall","flushdb","teardown","decommission","deprovision","deregister","tombstone"]),to=new Set(["rm","remove","reset","revoke"]),uc=new Set(["app","apps","application","applications","project","projects","bucket","buckets","database","databases","db","dbs","cluster","clusters","service","services","instance","instances","volume","volumes","branch","branches","environment","environments","env","envs","secret","secrets","domain","domains","zone","zones","record","records","dns","repo","repos","repository","repositories","deployment","deployments","function","functions","table","tables","queue","queues","topic","topics","stream","streams","namespace","namespaces","org","orgs","organization","organizations","team","teams","user","users","member","members","workspace","workspaces","site","sites","server","servers","machine","machines","vm","vms","droplet","droplets","pool","pools","stack","stacks","schema","schemas","collection","collections","keyspace","keyspaces","storage","backup","backups","snapshot","snapshots","token","tokens","webhook","webhooks","subscription","subscriptions","account","accounts","pg","postgres","mysql","redis","kv","d1","r2","s3","index","indexes","indices","key","keys","certificate","certificates","cert","certs","distribution","distributions","role","roles","policy","policies","vpc","subnet","subnets","gateway","node","nodes","worker","workers","job","jobs","pipeline","pipelines","model","models","endpoint","endpoints","volume-snapshot","organization-member","tenant","tenants","serverless","store","stores","region","regions","replica","replicas","shard","shards","partition","partitions","tablet","tablets","broker","brokers","changefeed","changefeeds","network","networks","firewall","firewalls","disk","disks","peer","peers","keyring","keyrings","vault","vaults"]),jo=new Set(["database","databases","db","dbs","table","tables","schema","schemas","collection","collections","keyspace","keyspaces","pg","postgres","mysql","redis","kv","d1","index","indexes","indices","backup","backups","snapshot","snapshots","bucket","buckets","storage","r2","s3","volume","volumes","store","stores","region","regions","replica","replicas","shard","shards","partition","partitions","tablet","tablets","disk","disks","vault","vaults"]),Po=/^--?(dry-?run|plan|preview|what-?if|check|diff|validate|help|version|list|ls)$/i;function dc(e){let t=[];for(let n=1;n<e.length&&t.length<6;n++){let s=k(e[n]);if(!s.startsWith("-")&&/^[a-z][a-z0-9_-]*(:[a-z0-9_-]+)*$/.test(s))for(let r of s.split(":"))r&&t.push(r)}return t}function Wo(e){let t=R.basename(e.name);return["const","let","var"].includes(t)&&k(e.argv[2]??"")==="="?!0:/^[A-Z][a-z]+$/.test(t)&&e.argv.length>=4&&e.argv.slice(1).some(n=>/[a-z]\.$/.test(k(n)))}function Lh(e){let t=R.basename(e.name);if(!t||Oo.has(t)||Zs(t)||e.functionCall||e.via==="substitution"||S(e.argv[0]??"")||e.argv[0]?.includes("/"))return[];if(Wo(e))return[];let n=dc(e.argv);if(n.length===0||e.argv.some(u=>Po.test(u)))return[];let s=u=>rn.has(u)||to.has(u)?u:rn.has(u.split("-")[0]??"")||to.has(u.split("-")[0]??"")&&!Ks.has(u.split("-").slice(1).join("-"))?u.split("-")[0]:null,r=n.findIndex(u=>s(u)!==null);if(r>=0){let u=s(n[r]);n[r].includes("-")&&!rn.has(n[r])&&n.splice(r+1,0,n[r].slice(u.length+1));let f=n.flatMap(h=>[h,...h.split("-")]).find(h=>uc.has(h)),p=n.filter((h,g)=>g!==r||h.includes("-")).flatMap(h=>h.split("-")).filter(h=>h!==u);if(f===void 0&&p.length>0&&p.every(h=>mc.has(h)))return[];let d=n.length>r+1||e.argv.some(h=>/^--?(app|project|name|id|db|database|bucket|cluster|service|instance|env|environment|org|zone|branch)(=|$)/.test(h)||Lo.test(k(h)));if(rn.has(u)&&(f!==void 0||d)||to.has(u)&&f!==void 0){let h=jo.has(f??"")||["drop","truncate","flushall","flushdb","purge","wipe"].includes(u);return[m(h?"claude.bash.db.destructive":"claude.bash.deploy",`${t} ${qs(u)} ${f?mo(f):"what it names"} (a command with no rule of its own, read by its words)`,{target:`${t} ${n.slice(0,3).join(" ")}`,is_local:!1})]}}let o="(a command with no rule of its own, read by its words)",a=e.argv.some(u=>/\b(localhost|127\.0\.0\.1|::1)\b|^--local$/.test(k(u))),i=e.argv.map(u=>k(u)),l=i.slice(1).find((u,f)=>/\s/.test(u)&&!/^(i?like|=|!=|<>)$/i.test(i[f]??"")&&be.test(ke(u)));if(l!==void 0&&!a)return[m("claude.bash.db.destructive",`${t} runs SQL that changes data (${(be.exec(ke(l))?.[1]??"").replace(/\s+/g," ").toUpperCase()}) ${o}`,{target:t,is_local:!1})];let c=n.findIndex(u=>Ks.has(u));return c>=0&&n.some(u=>kc.has(u))&&ae(e)?[m("claude.bash.secrets.print",`${t} prints ${mo(n[c])} ${o}`,{target:`${t} ${n.slice(0,3).join(" ")}`,is_local:!0})]:n.slice(0,3).some(u=>_u.test(u))?[m("claude.bash.deploy",`${t} ${n.slice(0,2).join(" ")} deploys or publishes ${o}`,{target:`${t} ${n.slice(0,2).join(" ")}`,is_local:!1})]:n.some(u=>["tunnel","expose","funnel"].includes(u))&&e.argv.some(u=>/^(\d{2,5}|localhost:\d{2,5}|127\.0\.0\.1:\d{2,5}|https?:\/\/(localhost|127\.0\.0\.1):\d{2,5})$/.test(k(u)))?[m("claude.bash.net.expose",`${t} opens a local port to the internet ${o}`,{target:t,is_local:!1})]:[]}var Th=new Set(["-c","-F","-i","-J","-l","-o","-P","-S","-D","-X"]),Ih=new Set(["-e","-f","-T","-B","-M","--rsh","--exclude","--include","--filter","--exclude-from","--include-from","--files-from","--rsync-path","--password-file","--chmod","--chown","--log-file","--temp-dir","--partial-dir","--backup-dir","--suffix","--port","--bwlimit","--timeout","--max-size","--min-size","--compare-dest","--copy-dest","--link-dest"]),fc=new Set(["--config","--transfers","--checkers","--include","--exclude","--filter","--include-from","--exclude-from","--filter-from","--files-from","--max-age","--min-age","--max-size","--min-size","--log-file","--log-level","--bwlimit","--backup-dir","--suffix","--max-depth","--order-by","--tpslimit","--retries"]),Dh=/^(localhost|127\.0\.0\.1|\[::1\]|::1)$/i,Fh=new Set(["copy","copyto","move","moveto","sync","bisync","rcat","copyurl","delete","deletefile","purge","rmdir","rmdirs","cleanup","dedupe"]),zh=new Set(["rcat","delete","deletefile","purge","rmdir","rmdirs","cleanup","dedupe"]);function Mh(e,t){let n=R.basename(e.name);if(!["scp","rsync","rclone"].includes(n))return[];let s=e.argv.map(u=>k(u));if(s.some(u=>u==="-n"||u==="--dry-run"||n==="rsync"&&/^-[a-zA-Z]*n[a-zA-Z]*$/.test(u)))return[];let o=pe(s,1,n==="scp"?Th:n==="rsync"?Ih:fc),a=u=>Te(u)&&!Dh.test(Zn(u));if(n==="rclone"){let u=o.findIndex(g=>Fh.has(g));if(u<0)return[];let f=o[u],p=o.slice(u+1,u+1+(zh.has(f)?1:2));if(p.length===0)return[];if(p.every(g=>!Te(g))){if(["delete","deletefile","purge","rmdir","rmdirs"].includes(f))return Io({...e,name:"rm",argv:["rm","-rf",...p]},t).map(g=>({...g,why:`rclone ${f}: ${g.why}`}));if(f==="sync"&&p.length>=2){let g=Ys(p[p.length-1],e,t);return g.kind==="disposable"?[]:[{...xt([g],e),why:`rclone sync replaces what is in ${g.why}`}]}return[]}let d=p[p.length-1];if(f==="sync"&&p.length===2&&Te(p[0])&&!Te(d)){let g=Ys(d,e,t);return g.kind==="disposable"?[]:[{...xt([g],e),why:`rclone sync replaces what is in ${g.why}`}]}if(!["copy","copyto","move","moveto","sync","bisync","rcat","copyurl"].includes(f)||f!=="rcat"&&p.length<2||!a(d))return[];let h=d.split(":")[0];return f==="sync"||f==="bisync"?[m("claude.bash.db.destructive",`rclone ${f} makes ${h}: match the source, deleting what is not in it`,{target:d,host:h,is_local:!1})]:[m("claude.bash.external_write",`rclone ${f} copies files to ${h}:`,{target:d,host:h,is_local:!1})]}let i=o.filter(u=>Te(u)||/[/.~]/.test(u));if(i.length<2)return[];let l=i[i.length-1];if(!a(l))return[];let c=Zn(l);return[m("claude.bash.external_write",`${n} copies files to another machine (${c})`,{target:l,host:c,is_local:!1})]}function Uh(e){let t=Un.has(R.basename(e.name))?e.argv.slice(1).map(a=>k(a)).find(a=>!a.startsWith("-"))??"":k(e.argv[0]??""),n=R.basename(t).replace(/\.sh$/,"");if(!/^kafka-[a-z-]+$/.test(n)||["kafka-server-start","kafka-server-stop","kafka-storage","kafka-run-class","kafka-console-consumer","kafka-dump-log"].includes(n))return[];let s=e.argv.map(a=>k(a));if(s.some(a=>/^--(help|version|dry-run)$/.test(a)))return[];let r=n==="kafka-delete-records"?"(its one action)":s.find(a=>/^--(delete|delete-[a-z-]+|purge)$/.test(a));if(r)return[m("claude.bash.db.destructive",`${n} ${r} deletes from a live Kafka cluster`,{target:n,is_local:!1})];if(n==="kafka-leader-election")return[m("claude.bash.deploy","kafka-leader-election moves partition leaders on a live Kafka cluster",{target:n,is_local:!1})];let o=s.find(a=>/^--(create|alter|add|remove|execute|reset-offsets|reassign|elect|grant|revoke|expire|renew|cancel)$/.test(a));return o&&!(o==="--reset-offsets"&&!s.includes("--execute"))?[m("claude.bash.deploy",`${n} ${o} changes a live Kafka cluster`,{target:n,is_local:!1})]:n==="kafka-console-producer"?[m("claude.bash.external_write","kafka-console-producer writes messages to a topic",{target:n,is_local:!1})]:[]}var qh=/^--?(?!no-|skip-|keep-|without-|dry-|preview-|show-|list-|exclude-|disable-|dont-|don-t-|prevent-|protect-|avoid-|never-)([a-z0-9]+-)*(purge|destroy|wipe|drop|nuke|erase|truncate|delete)(-(all|data|tables?|database|databases|db|volumes?|everything|existing|objects?|records?|rows?|keys?|files?|snapshots?|backups?|indexes|indices|schemas?|clusters?|namespaces?|buckets?|branch(es)?|resources?|old))?(=.*)?$/,Hh=new Set(["magick","convert","mogrify","montage","composite","gm"]);function Bh(e){let t=R.basename(e.name);if(!t||Oo.has(t)||Hh.has(t)||e.functionCall||e.via==="substitution"||S(e.argv[0]??"")||Wo(e))return[];let n=e.argv.map(u=>k(u));if(n.some(u=>Po.test(u)))return[];let s="(what its own words say it does)",r=dc(n),o=Zs(t)?-1:r.findIndex(u=>u.split("-").includes("unsafe"));if(o>=0&&(r[o].includes("-")||r.length>o+1)&&!r.slice(o+1).some(u=>ln.has(u)))return[m("claude.bash.db.destructive",`${t} runs a subcommand it calls unsafe (${r.slice(0,3).join(" ")}) ${s}`,{target:`${t} ${r.slice(0,3).join(" ")}`,is_local:!1})];if(Zs(t))return[];let i=n.slice(1).find((u,f)=>qh.test(u)&&!/=(false|0|no|none|off|never)$/i.test(u)&&!/^(false|0|no|none|off|never)$/i.test(n[f+2]??""));if(i===void 0)return[];let l=/(purge|destroy|wipe|drop|nuke|erase|truncate|delete)/.exec(i)[1],c=["drop","truncate","purge","wipe"].includes(l)||r.flatMap(u=>[u,...u.split("-")]).some(u=>jo.has(u));return[m(c?"claude.bash.db.destructive":"claude.bash.deploy",`${t} is told to ${l} (${i.split("=")[0]}) ${s}`,{target:`${t} ${r.slice(0,2).join(" ")}`.trim(),is_local:!1})]}var ho=new Set([...rn,"rollback","unpublish"]),Ms=new Set(["rm","remove","reset","revoke","uninstall"]),Vh=new Set(["cluster","clusters","kube","k8s","kubernetes","infra","infrastructure","eks","gke","aks"]),Zh=new Set(["kind","minikube","k3d","microk8s","local","dev","docker","compose"]),no=new Set(["drop","truncate","flushall","flushdb","teardown","deprovision","decommission"]),go=new Set(["deploy","release","publish","promote","rollout","ship"]),pc=new Set(["create","add","set","update","put","attach","scale","enable","disable","rotate"]),Ws=new Set(["bucket","buckets","cluster","clusters","database","databases","db","namespace","namespaces","instance","instances","volume","volumes","service","services","function","functions","fn","lambda","addon","addons","lifecycle","environment","environments","domain","domains","zone","zones","record","records","dns","app","apps","deployment","deployments","queue","queues","topic","topics","stack","stacks","vpc","subnet","subnets","gateway","pool","pools","certificate","certificates","distribution","distributions","worker","workers","machine","machines","droplet","droplets","server","servers","site","sites","project","projects","table","tables","schema","schemas","identity","identities","layer","layers","kv","d1","r2","s3","broker","brokers","partition","partitions","replica","replicas","shard","shards","region","regions","store","stores","serverless","tablet","tablets"]),ln=new Set(["plan","verify","check","validate","list","ls","status","diff","extract","describe","view","lint","test","tests","dry","dryrun","notes","changelog","preview","smoke","inspect","show","get","help","download","fetch","pull","template","render","history","logs","log","info","url","urls","open","browse","wait","watch","tail","search","find","explain"]),No=new Set([...ln,"doctor","whoami","version","completion","login","logout","install","init"]),hc=new Set(["test","tests","e2e","spec","specs","check","checks","verify","validate","lint","dry","plan","diff","preview","smoke","generate","gen","codegen","mock","mocks","fake","stub","example","examples","sample","docs","notes","changelog","build","watch","dev","local","list","ls","status","show","get","inspect","count","find","search","report","help","storybook","bench","benchmark","prepare","eval","evals","evaluate","scan","audit","probe","probes"]),Gh=new Set(["detect","find","get","next","determine","should","is","has","needs","parse","extract","wait","print","read","info"]),Kh=new Set([...hc,"start","serve","bundle","compile","analyze","typecheck","format","copy","env","logs","log"]),Yh=new Set(["prod","production"]),Jh=new Set(["fn","func","lambda","lambdas","addon","addons","identity","identities","layer","layers","relationship","relationships","lifecycle","data","migrate","migration","migrations","seed","seeds"]),tl=new Set([...jo,"data","migrate","migration","migrations","seed","seeds"]),Us=new Set(["config","configure","configuration","context","profile","alias","completion","completions","auth","login","local"]),Lo=/^--?(app|project|project-?id|db|database|bucket|cluster|service|instance|env|environment|org|zone|branch|deployment|deployment-?id|identity|stack|namespace|site|([a-z][a-z0-9]*[-.])+(id|ids|name|arn|uri))(=|$)/,Xh=new Set(["ssh","scp","sftp","mosh","autossh","rsync","curl","wget","http","https","xh","git","nc","ncat","netcat","telnet","socat","xargs","env","sudo","doas","time","timeout","nohup","watch","nice","caffeinate","stdbuf","command","builtin","exec"]),sn=/\.(sh|bash|zsh|py|rb|js|mjs|cjs|ts|mts|cts|pl|ps1)$/,Qh=new Set(["dotenv","dotenvx","env-cmd","cross-env","with-env","mise","asdf","op","doppler","infisical","railway","kubectl","oc","uv","poetry","pipenv","direnv","nix","nix-shell","devbox","flox","aws-vault","sops","chamber","teller","envchain"]),Gs=/\$\{?[A-Za-z_]*(TOKEN|API_?KEY|SECRET|PAT|PASSWORD|CREDENTIALS?)[A-Za-z_]*\}?/,gc=new Set(["skill","skills","plugin","plugins","completion","completions","toolchain","toolchains","font","fonts","venv","virtualenv","shim","shims"]),mc=new Set([...Us,...gc,"cache","caches","history","log","logs","tmp","temp","session-cache","settings","setting","shell","workspace-cache","extension","extensions","download","downloads"]),eg=new Set(["repo","repos","remote","remotes","source","sources","registry","registries","tap","taps","channel","channels","index","indexes"]);function nl(e){return e.argv.some(t=>{let n=k(t);return Gs.test(t)||Gs.test(n)||Lo.test(n)||/^[a-z][a-z0-9+.-]*:\/\//.test(n)&&!Re(n)})}var tg=/\b(claude|anvil|mcp|codex|cursor|copilot|gemini|aider|settings|permissions?)\b/i,sl=/(^|[-_.:/])(prod|production|live|mainnet)([-_.:/]|$)/i,rl=/^(\w+:\/\/)?([^@/\s]*@)?(localhost|127\.0\.0\.1|\[::1\])(:\d+)?(\/\S*)?$/i;function ng(e){let t=e.text,n=[],s=i=>i===" "||i===" ",r=i=>i!==void 0&&(i>="A"&&i<="Z"||i>="a"&&i<="z"||i==="_"),o=i=>r(i)||i!==void 0&&i>="0"&&i<="9",a=0;for(;n.length<32;){for(;s(t[a]);)a++;let i=a;if(!r(t[i]))break;for(;o(t[i]);)i++;if(t[i]!=="=")break;let l=t.slice(a,i);i++;let c;if(t[i]==='"'||t[i]==="'"){let u=t.indexOf(t[i],i+1);if(u<0)break;c=t.slice(i+1,u),i=u+1}else{let u=i;for(;u<t.length&&!s(t[u])&&t[u]!==`
|
|
41
|
-
`;)u++;c=t.slice(i,u),i=u}if(i<t.length&&!s(t[i]))break;n.push([l,c]),a=i}return n}function sg(e,t){let n=e.argv.map(x=>k(x)),s=x=>/^--?[a-z][\w-]*=/i.test(x)?x.slice(x.indexOf("=")+1):x;if(n.some(x=>Po.test(x)||/^--dry-?run=(true|1|yes|client|server|all)$/i.test(x)))return{strict:!0,ship:!0};if(n.some(x=>/^--(snapshot|skip-publish|no-publish|skip-push)$|^--skip=([\w,]*,)?(publish|push)\b/.test(x)))return{strict:!1,ship:!0};if(["make","gmake"].includes(R.basename(e.name))&&n.some(x=>/^-[a-zA-Z]*n[a-zA-Z]*$|^--(just-print|recon)$/.test(x)))return{strict:!0,ship:!0};let r=ng(e);if(n.slice(1).some(x=>sl.test(s(x)))||r.some(([,x])=>sl.test(x)))return{strict:!1,ship:!1};let o=x=>n.flatMap((b,j)=>x.test(b)?[n[j+1]??""]:/^--?[a-z][\w-]*=/i.test(b)&&x.test(b.slice(0,b.indexOf("=")))?[s(b)]:[]),a=n.findIndex((x,b)=>b>0&&!x.startsWith("-")),i=o(/^--?(db-url|database-url|url|host|registry|endpoint|server|api-url|connection|connection-string|dsn)$/i),l=r.some(([x,b])=>/(DATABASE|DB|POSTGRES|PG|MYSQL|MONGO|REDIS)_?(URL|URI|HOST)$/i.test(x)&&!rl.test(b)),c=r.some(([x,b])=>/^(NODE_ENV|APP_ENV|RAILS_ENV|RACK_ENV|MIX_ENV|FLASK_ENV|DJANGO_ENV|ENVIRONMENT|STAGE)$/.test(x)&&/^(test|testing|dev|development|local)$/i.test(b))&&!l;if(n.slice(1,a<0?void 0:a).includes("--local")||i.length>0&&i.every(x=>rl.test(x))||c)return{strict:!0,ship:!0};let f=o(/^--?(channel|track|deployment|network|net|chain)$/i),p=o(/^--?([\w-]+\.)?cluster$/i),h=n.some(x=>/^code-?push(-standalone)?$/.test(x))||/code-?push/.test(R.basename(e.name))?o(/^-d$/):[],g=[...f.map(x=>ol.test(x)),...p.map(x=>og.test(x)),...h.map(x=>ol.test(x))],y=g.length>0&&g.every(Boolean),$=t.lineText.indexOf(e.text),E=R.basename(e.name);if(!y&&g.length===0&&$>0&&/^[a-z][a-z0-9_-]*$/.test(E)){let x=[...t.lineText.slice(0,$).matchAll(new RegExp(`\\b${E}\\s[^;&|]*\\b(?:config\\s+set|switch|use)\\b[^;&|]*\\s--?(?:url|u|env|network|cluster)[= ]([\\w:/.-]+)`,"g"))],b=x[x.length-1]?.[1];y=b!==void 0&&/^(devnet|testnet|localnet|localhost|http:\/\/(localhost|127\.0\.0\.1)(:\d+)?)$/.test(b)}return{strict:!1,ship:y}}var rg=new Set(["sequelize","sequelize-cli","knex","typeorm","typeorm-ts-node-commonjs","typeorm-ts-node-esm","mix","artisan","php","rails","rake","alembic","flask","flyway","liquibase"]),ol=/^([\w-]+:)?(staging|stage|stg|dev|develop|development|test|testing|qa|uat|preview|sandbox|devnet|testnet|localnet|local|ci|sepolia|goerli|holesky|hoodi|mumbai|amoy|fuji|chiado|alfajores|shasta|nile)$/i,og=/^([\w-]+:)?(devnet|testnet|localnet|sepolia|goerli|holesky|hoodi|mumbai|amoy|fuji|chiado|alfajores|shasta)$/i,il=/^--(publish|deploy|promote)(=true)?$/,ig=new Set(["npx","pnpx","bunx"]),ag=new Set(["--import","--require","-r","--loader","--experimental-loader","--env-file","--project","-P","--tsconfig","--inspect-port"]);function mo(e){return/s$/.test(e)?e:`a ${e}`}function rt(e){return e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase().split(/[-:_./]+/).filter(t=>/^[a-z][a-z0-9]*$/.test(t))}function al(e,t,n=!1){let s=[],r=t;for(;n&&r<e.length&&k(e[r]).startsWith("-")&&k(e[r])!=="--";){let a=k(e[r]);r+=!a.includes("=")&&r+1<e.length&&/[/.$~=]|^\d/.test(k(e[r+1]))&&!k(e[r+1]).startsWith("-")?2:1}for(let a=0;a<2&&r<e.length&&/^\$/.test(k(e[r]));a++)r++;for(;r<e.length&&s.length<6;r++){let a=k(e[r]);if(a==="--"||a.startsWith("-")||a.includes("://")||a.includes("@")||!/^[a-z][a-z0-9_.:/-]*$/.test(a)||a.includes("/")||/\.[a-z0-9]{1,5}(:[\d,-]+)?$/.test(a))break;let i=rt(a);i.length>0&&s.push(i)}let o=0;for(;r<e.length;r++){let a=k(e[r]);if(a==="--")break;a.startsWith("-")||o++}return{groups:s,values:o}}function lg(e){let t=e.argv.map(f=>k(f)),n=R.basename(e.name),s=[],r=[],o=(f,p)=>({...e,name:f,argv:[f,...p]}),a=(f,p)=>{let d=al(t,p),h=t.flatMap((g,y)=>y>=p&&/^--?(command|cmd|action|task|step|op|operation|job)$/.test(g)?[rt(t[y+1]??"")]:/^--?(command|cmd|action|task|step|op|operation|job)=/.test(g)?[rt(g.slice(g.indexOf("=")+1))]:[]).filter(g=>g.length>0);return{name:R.basename(f),groups:[rt(R.basename(f).replace(/\.[^.]+$/,"")),...d.groups.slice(0,1),...h],values:d.values+Math.max(0,d.groups.length-1),script:!0}},i=f=>({name:f,groups:[rt(f)],values:0,script:!0});if(t[0]?.includes("/")&&sn.test(t[0]))return{readings:[a(t[0],1)],nested:r};if((n==="."||n==="source")&&sn.test(t[1]??""))return{readings:[a(t[1],2)],nested:r};let l=t.indexOf("--");if(Qh.has(n)&&l>0&&/^[a-z][a-z0-9._-]*$/.test(t[l+1]??"")){let f=o(t[l+1],t.slice(l+2));(n==="kubectl"||n==="oc"||n==="railway")&&/^(exec|run)$/.test(v(t)[0]??"")&&Qs.add(f),r.push(f)}if(Qo.has(n)||n==="zsh"){for(let f=1;f<t.length;f++){let p=t[f];if(["-c","-e","--eval","-p","--print","-m"].includes(p))return{readings:s,nested:r};if(ag.has(p)){f++;continue}if(!p.startsWith("-")){if(sn.test(p))return Su(n,t.slice(1,f))?{readings:s,nested:r}:{readings:[a(p,f+1)],nested:r};break}}if(n!=="bun")return{readings:s,nested:r}}let c=ig.has(n)?1:["npm","pnpm","yarn","bun"].includes(n)&&["exec","dlx","x"].includes(t[1]??"")?2:-1;if(c>0){let f=c;for(;f<t.length&&t[f].startsWith("-");)f+=["-p","--package"].includes(t[f])?2:1;let p=(t[f]??"").replace(/^@[^/]+\//,"").replace(/@[^/]*$/,"");return/^[a-z][a-z0-9._-]*$/i.test(p)&&r.push(o(p,t.slice(f+1))),{readings:s,nested:r}}if(["npm","pnpm","yarn","bun"].includes(n)){let f=Uc(t),p=f[0]??"";if((p==="run"||p==="run-script")&&f[1])s.push(n==="bun"&&sn.test(f[1])?a(f[1],t.indexOf(f[1])+1):i(f[1])),n!=="npm"&&/^[a-z][a-z0-9._-]*$/.test(f[1])&&!sn.test(f[1])&&r.push(o(f[1],t.slice(t.indexOf(f[1])+1)));else if(p==="npm"&&n==="yarn")r.push(o("npm",t.slice(t.indexOf("npm")+1)));else{if(n==="pnpm"&&p==="deploy")return{readings:s,nested:r};n!=="npm"&&p&&!qo.has(p)&&(s.push(i(p)),/^[a-z][a-z0-9._-]*$/.test(p)&&r.push(o(p,t.slice(t.indexOf(p)+1))))}let d=t.indexOf("--");return d>0&&/^[a-z][a-z0-9._-]*$/.test(t[d+1]??"")&&r.push(o(t[d+1],t.slice(d+2))),{readings:s,nested:r}}if(["nx","turbo","mise","make","just","task","lerna","run-s","run-p","npm-run-all"].includes(n)){let p=n==="mise"&&!["run","r","watch","w"].includes(t[1]??"")&&!/^(\/\/|:)/.test(t[1]??"")?[]:t.slice(1).filter((h,g,y)=>!h.startsWith("-")&&!h.includes("=")&&!h.startsWith("$")&&!["-C","-f","--file","-j","--projects","-p"].includes(y[g-1]??"")),d=t.flatMap((h,g)=>["-t","--target","--targets"].includes(h)?(t[g+1]??"").split(","):/^--targets?=/.test(h)?h.slice(h.indexOf("=")+1).split(","):[]);for(let h of[...p,...d])h&&h!=="run"&&h!=="run-many"&&h!=="affected"&&!["-t","--target","--targets"].includes(h)&&s.push(i(h));return{readings:s,nested:r}}if(Oo.has(n)||Xh.has(n)||!/^[a-z][a-z0-9._-]*$/.test(n)||/^\/[a-z-]+$/.test(t[0]??""))return{readings:s,nested:r};if(rt(n).some(f=>No.has(f)||["print","echo"].includes(f)))return{readings:s,nested:r};let u=al(t,1,!0);return s.push({name:n,groups:u.groups.slice(0,4),values:u.values+Math.max(0,u.groups.length-4),script:!1}),{readings:s,nested:r}}var cg=oe({mix:["release","assets.deploy"]});function ug(e,t){let n=e.groups.flat();if(n.length===0||!e.script&&cg[e.name]?.includes(e.groups[0].join(".")))return null;let s=e.script?`runs ${e.name}`:`${e.name} ${e.groups.map(C=>C.join("-")).slice(0,4).join(" ")}`,r=e.script?"(read by its name)":"(read by its words)",o=e.script?e.name:s,a=t.argv.some(C=>Gs.test(C)||Gs.test(k(C))),i=a||t.argv.some(C=>Lo.test(k(C)));if(e.script&&(n.some(C=>hc.has(C))||Gh.has(n[0]??"")))return null;if(e.script&&t.argv.some(C=>il.test(k(C))))return m("claude.bash.deploy",`${s}, told to ${t.argv.map(C=>k(C)).find(C=>il.test(C)).slice(2).replace(/=true$/,"")} ${r}`,{target:o,is_local:!1});if(!e.script){if(e.groups[0].length===1&&No.has(n[0])&&!Ks.has(n[1]??""))return null;let C=n.findIndex(A=>Ks.has(A));if(C>=0&&!n.slice(0,C).some(A=>Us.has(A))){if(n.some(A=>kc.has(A))&&ae(t))return m("claude.bash.secrets.print",`${s} prints ${mo(n[C])} ${r}`,{target:o,is_local:!0});if(n.some(A=>["create","lease","issue","generate","mint"].includes(A))&&ae(t))return m("claude.bash.secrets.print",`${s} makes a credential and prints it ${r}`,{target:o,is_local:!1});if(n.some(A=>["set","update","put","add","rotate","delete","remove","rm","unset","revoke","reset","reencrypt","rekey"].includes(A)))return m("claude.bash.deploy",`${s} changes a secret a service keeps ${r}`,{target:o,is_local:!1})}if(["post","put","patch"].includes(n[0]??"")&&t.argv.slice(2).some(A=>k(A).includes("/")))return m("claude.bash.external_write",`${e.name} ${n[0]} sends a write to its service's API ${r}`,{target:o,is_local:!1})}if(e.script&&n.includes("down")&&n.some(C=>Vh.has(C))&&!n.some(C=>Zh.has(C)))return m("claude.bash.deploy",`${s}: named to take down ${n.some(C=>C.startsWith("infra"))?"its infrastructure":"a cluster"} ${r}`,{target:o,is_local:!1});let l=-1;for(let C=0;C<n.length;C++){let A=n[C];(ho.has(A)||Ms.has(A)||go.has(A)||!e.script&&(pc.has(A)||A==="apply"||A==="push"))&&(l=C)}let c=e.script&&n.some(C=>Yh.has(C))&&!n.some(C=>Kh.has(C)||ln.has(C)),u=t.argv.some(C=>["--force","-f","--yes","-y","--overwrite"].includes(k(C))||k(C)==="--force=true"),f=t.argv.some(C=>/\.(tar|tgz|tar\.gz|sql|dump|bak|gz|zip|bson|archive)$/i.test(k(C)));if(!e.script&&l<0&&u&&n.some(C=>["import","restore","load"].includes(C))&&(f||n.some(C=>tl.has(C)))&&!n.some(C=>ln.has(C)))return m("claude.bash.db.destructive",`${s}: forced, over the data it holds ${r}`,{target:o,is_local:!1});if(l<0)return c?m("claude.bash.deploy",`${s}, named for production ${r}`,{target:o,is_local:!1,host:"production"}):null;let p=n[l];if(n.slice(l+1).some(C=>ln.has(C)))return null;let d=C=>uc.has(C)||Jh.has(C),h=[...n.slice(0,l)].reverse().find(d)??n.slice(l+1).find(d)??n.find(d),g=n.some(C=>tl.has(C)),y=C=>/s$/.test(C)?C:`a ${C}`,$=e.groups.flatMap((C,A)=>C.map(()=>A))[l]??0,E=e.groups.length-1-$,x=t.argv.some((C,A)=>/^--?[a-z][\w-]*=./.test(k(C))||/^--?[a-z][\w-]*$/.test(k(C))&&/^[^-]/.test(k(t.argv[A+1]??"-")));if(ho.has(p)||Ms.has(p)){if(!e.script&&n.slice(0,l).some(U=>Us.has(U))||!e.script&&h===void 0&&n.length>1&&n.every((U,I)=>I===l||mc.has(U))||!e.script&&["remove","rm"].includes(p)&&n.slice(0,l).some(U=>eg.has(U))&&!nl(t))return null;let C;if(Ms.has(p)?C=h!==void 0||(e.script?no.has(p):!1):e.script?$>0?C=["nuke","wipe","purge","destroy","erase",...no].includes(p)||h!==void 0||e.values>0||x||a:C=no.has(p)||h!==void 0||p==="destroy"||["purge","wipe","nuke","erase"].includes(p)&&e.groups[0].length>1:C=h!==void 0||e.values>0||i||E>0||l>0&&rn.has(p),!C||h===void 0&&n.some(U=>gc.has(U))&&!nl(t)&&!tg.test(t.text))return null;let A=g||["drop","truncate","flushall","flushdb","purge","wipe"].includes(p)?"claude.bash.db.destructive":"claude.bash.deploy";return m(A,`${s}: ${e.script?`named to ${p}`:qs(p)} ${h?y(h):"what it names"} ${r}`,{target:o,is_local:!1})}if(go.has(p))return["build","gen","generate","new","scaffold","init","template"].includes(n[l-1]??"")?null:m(p==="publish"?"claude.bash.publish":"claude.bash.deploy",`${s}: ${e.script?`named to ${p}`:qs(p)} ${r}`,{target:o,is_local:!1});if(p==="push"){if(t.argv.some(A=>["--force","-f","--yes","-y"].includes(k(A))))return m("claude.bash.deploy",`${s}: a forced push to its service ${r}`,{target:o,is_local:!1});let C=t.argv.map(A=>k(A)).find(A=>/^[a-z][a-z0-9+.-]*:\/\//.test(A)&&!Re(A));return C?m("claude.bash.publish",`${s}: pushes to ${C.split("/").slice(0,3).join("/")} ${r}`,{target:o,is_local:!1}):null}if(p==="apply")return m("claude.bash.deploy",`${s}: applies a configuration to its service ${r}`,{target:o,is_local:!1});if(n.slice(0,l).some(C=>Us.has(C)))return null;let b=[...n.slice(0,l)].reverse().find(C=>Ws.has(C))??n.slice(l+1).find(C=>Ws.has(C))??(a?"a service it signs in to":void 0);if(b===void 0)return null;let j=Ws.has(b)?/\d/.test(b)||b.length<=2?`changes ${b.toUpperCase()}, a live service`:`${qs(p)} ${y(b)} on a live service`:b;return m("claude.bash.deploy",`${s}: ${Ws.has(b)?j:`changes something on ${b}`} ${r}`,{target:o,is_local:!1})}function yc(e,t,n){return[e,...n!==void 0&&n!==e?[n]:[]].map(r=>r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).some(r=>new RegExp(`(^|[^>\\w./-])(>|\\btee\\s+)\\s*["']?${r}["']?(\\s|;|&|\\||$)`).test(t.lineText))&&/<<-?\s*['"]?\w+|\bprintf\b|\becho\b|\btee\b/.test(t.lineText)}function bc(e,t){let n=R.basename(t);return e.text.split(/\s+/).map(s=>s.replace(/^["']|["']$/g,"")).find(s=>s===t||s.endsWith(`/${n}`)||s===n)}function dg(e,t,n){let s=t.argv.map(a=>k(a)).find(a=>R.basename(a)===e.name);if(s===void 0)return!1;let r=X(s,t.cwd,se(n)).path??"",o=n.sessionId;return o!==null&&/^[\w-]{8,}$/.test(o)&&new RegExp(`^/(private/)?tmp/claude-\\d+/[^/]+/${o}/scratchpad/`).test(r)}function qs(e){return{rollback:"rolls back",rollout:"rolls out",teardown:"tears down",rm:"removes",push:"pushes",flushall:"flushes all of",flushdb:"flushes",set:"sets",put:"puts"}[e]??(/(sh|ch|s|x)$/.test(e)?`${e}es`:`${e}s`)}function fg(e){let t=R.basename(e.name),n=e.argv.map(r=>k(r)),s=r=>[m("claude.agent.controls",`sends keystrokes into a terminal or another app (${r}), which can answer prompts meant for the person`,{target:r,is_local:!0})];return t==="tmux"&&n.some(r=>/^(send-keys|send|send-prefix|paste-buffer|pasteb)$/.test(r))?s("tmux send-keys"):t==="screen"&&n.some((r,o)=>r==="-X"&&/^(stuff|paste|readbuf)$/.test(n[o+1]??""))?s("screen -X stuff"):t==="osascript"&&n.some(r=>/\b(keystroke|key code|key down)\b/i.test(r))?s("osascript keystrokes"):["xdotool","ydotool","wtype","dotool"].includes(t)&&n.slice(1).some(r=>/^(type|key|keydown|keyup)$/.test(r)||t==="wtype")?s(t):t==="kitty"&&n.includes("@")&&n.some(r=>/^send-(text|key)$/.test(r))?s("kitty @ send-text"):t==="wezterm"&&n.includes("cli")&&n.includes("send-text")?s("wezterm cli send-text"):[]}var wc=new Set(["dokku","kamal","fly","flyctl","netlify","serverless","sls","caprover","cap","flux","argocd","eb","doctl","hcloud","linode-cli","scw","vultr-cli","civo","koyeb","okteto","porter","northflank","render","sst","amplify"]),ll=new Set([...No,"get","describe","logs","log","top","explain","versions","info","port","forward","proxy","wait","diff","events","kustomize","completion","options","print","docs","open","whoami","status","ls","list","show","current","help","version","doctor","details","audit","lint","validate","template","render","search","history","watch","tail","metrics","inspect","check","report","dashboard","export","can","login","logout","auth","context","contexts","use","switch","link","unlink","plugin","console","ssh","exec","shell","debugger","dev","build","test","package"]),pg=new Set(["local","offline","mock"]),hg=new Set(["api","resources","cluster","config","apps","domains","certs","volumes","ps","releases","storage","secrets","env","i"]),gg=new Set([...ho,...Ms,...go,...pc,"apply","prune","import","fork","mount","unmount","clear","set","unset","restart","reboot","boot","stop","start","scale","invoke","run","rolling","reconcile","cordon","drain","taint","label","annotate","patch","replace","expose","autoscale","launch","reset","uninstall","upgrade","sync","suspend","resume","enable","disable","detach","attach","join","leave","rotate","renew","issue","revoke","promote","release","redeploy","restore","backup","move","rename","transfer","swap","bootstrap","extend","resize","allocate","clone"]),mg=new Set(["apply","create","delete","edit","patch","replace","scale","autoscale","label","annotate","taint","drain","cordon","uncordon","expose","run","debug","set","rollout","certificate","new-app","new-project","new-build","start-build","cancel-build","rollback","tag","import-image","policy","adm","idle"]),yg=new Set(["-n","--namespace","--context","--cluster","--kubeconfig","--user","-o","--output","-l","--selector","-a","--app","-c","--config","-r","--region","--org","-s","--stage","--profile","--token","--project","--server","-e","--env","--environment","--team","--site","-f","--filename","--function","-d","--destination","--field-selector","--tail","--since","--container","--host","-H","--as","--request-timeout"]);function cl(e,t){let n=[];for(let s=1;s<e.length&&n.length<t;s++){let r=e[s];if(r==="--")break;if(r.startsWith("-")){!r.includes("=")&&yg.has(r)&&s++;continue}if(r.includes("://")||r.includes("@")||r.includes("/")||!/^[a-z][a-z0-9_.:-]*$/.test(r))break;n.push(r)}return n}function bg(e){let t=R.basename(e.name);if(t!=="docker"&&t!=="docker-compose"&&t!=="podman")return[];let n=e.argv.map(l=>k(l)),s=n.slice(1).filter((l,c,u)=>!l.startsWith("-")&&!["-f","--file","-p","--project-name","--context","-c","-H","--host","--env-file"].includes(u[c-1]??"")),r=t==="docker-compose"||s[0]==="compose",o=r&&t==="docker"?s.slice(1):s,a=o[0]??"",i=(l,c)=>[m(l,`${t} ${o.slice(0,2).join(" ")} ${c}`,{target:`${t} ${o.slice(0,2).join(" ")}`,is_local:!1})];return r?a==="down"&&n.some(l=>l==="-v"||l==="--volumes"||/^-[a-z]*v[a-z]*$/.test(l)&&l!=="-v"&&!l.startsWith("--"))?i("claude.bash.fs.delete_recursive","deletes the project's data volumes"):a==="publish"?i("claude.bash.publish","publishes the project to a registry"):[]:["service","stack","node","secret","config"].includes(a)&&["create","rm","remove","update","scale","deploy","rollback","promote","demote"].includes(o[1]??"")?i("claude.bash.deploy","changes a live swarm"):a==="swarm"&&["join","leave","init","update","unlock-key","ca"].includes(o[1]??"")?i("claude.bash.deploy","changes swarm membership"):a==="buildx"&&o[1]==="imagetools"&&o[2]==="create"&&!n.includes("--dry-run")?i("claude.bash.publish","pushes a manifest to a registry"):a==="trust"&&(["sign","revoke"].includes(o[1]??"")||o[1]==="signer"&&["add","remove"].includes(o[2]??""))?i("claude.bash.publish","changes who can sign images in a registry"):a==="scout"&&o[1]==="repo"&&["enable","disable"].includes(o[2]??"")?i("claude.bash.external_write","changes a registry setting"):[]}function wg(e,t){let n=R.basename(e.name);if(t.ship)return[];let s=e.argv.map(u=>k(u));if(n==="kubectl"||n==="oc"){let[u="",f=""]=cl(s,2);if(!mg.has(u))return[];if(u==="run"&&Rc(s))return[];if((u==="rollout"||u==="adm")&&ll.has(rt(f)[0]??""))return[];if(u==="certificate"&&!["approve","deny"].includes(f))return[];let p=["rollout","set","certificate","adm","create"].includes(u)&&f?`${n} ${u} ${f}`:`${n} ${u}`;return[m("claude.bash.deploy",`${p} changes a live cluster`,{target:p,is_local:!1})]}if(!wc.has(n))return[];let r=cl(s,3).filter(u=>!/^\d/.test(u)),o=r.flatMap(u=>rt(u));if(o.length===0||o.some(u=>pg.has(u)))return[];if(o.find(u=>["deploy","create","issue","mint","add","generate"].includes(u))!==void 0&&o.some(u=>/^(tokens?|keys?|credentials?)$/.test(u))){let u=`${n} ${r.slice(0,2).join(" ")}`;return[ae(e)?m("claude.bash.secrets.print",`${u} makes a credential and prints it`,{target:u,is_local:!1}):m("claude.bash.deploy",`${u} makes a credential for a live account`,{target:u,is_local:!1})]}if(o.includes("secrets")&&o.some(u=>["extract","print","fetch","get","show"].includes(u)))return ae(e)?[m("claude.bash.secrets.print",`${n} ${r.slice(0,2).join(" ")} prints a secret`,{target:`${n} ${r.slice(0,2).join(" ")}`,is_local:!0})]:[];if(n!=="dokku"&&o.some(u=>u==="plugin"||u==="plugins"))return[];let i=o.find(u=>gg.has(u));if(i===void 0&&o.some(u=>ll.has(u)))return[];if(i===void 0&&o.every(u=>hg.has(u)))return[];if(i!==void 0&&ln.has(o[o.indexOf(i)+1]??""))return[];let l=i!==void 0?r.findIndex(u=>rt(u).includes(i)):0,c=`${n} ${r.slice(0,Math.max(l,0)+1).join(" ")}`;return[m("claude.bash.deploy",i!==void 0?`${c} changes a live deployment`:`${c} is not a read, and ${n} works on live deployments`,{target:c,is_local:!1})]}function kg(e,t){let n=e.argv.map(c=>k(c)).find((c,u)=>u<=3&&sn.test(c));if(n!==void 0){let c=X(n,e.cwd,se(t)).path;if(c&&t.lineMade.includes(c)&&yc(n,t,bc(e,n)))return[]}if(e.functionCall||S(e.argv[0]??""))return[];if(Wo(e))return[];let s=e.argv.slice(1).map(c=>k(c)).find(c=>!c.startsWith("-")&&!/^[A-Za-z_]\w*=/.test(c))??"";if(rg.has(R.basename(e.name))&&(/^(db|migrate|migration|migrations|seed|schema|ecto)([:.]|$)/i.test(s)||["manage.py","artisan"].includes(R.basename(s))))return[];let r=sg(e,t);if(r.strict)return[];let o=bg(e);if(o.length>0)return o;let a=wg(e,r);if(a.length>0)return a;let{readings:i,nested:l}=lg(e);for(let c of i){if(c.script&&dg(c,e,t))continue;let u=ug(c,e);if(!(u&&r.ship&&(u.action==="claude.bash.publish"||/: (named to )?(deploy|release|publish|promote|rollout|ship)/.test(u.why)))&&u)return[u]}for(let c of l){if(c.argv.length>=e.argv.length&&c.name===e.name)continue;let u=Gn(c,t);if(u.length>0)return u.map(f=>({...f,why:`${f.why} (run by ${R.basename(e.name)})`}))}return[]}var Ks=new Set(["secret","secrets","token","tokens","credential","credentials","password","passwords","apikey","api-key","api_key","apikeys","api-keys"]),kc=new Set(["get","show","reveal","print","read","view","cat","dump","export","decrypt","download","value","access"]),To=/(^|\/)\*\.(egg-info|pyc|pyo|log|tmp|o|class|orig|rej|bak|swp|tsbuildinfo)$|(^|\/)\*~$/,vc=/^(node_modules|dist|build|out|\.next|coverage|__pycache__|\.pytest_cache|\.mypy_cache|\.ruff_cache|\.cache|\.turbo|\.DS_Store|target|\.tox|\.venv|venv|[\w.-]*\.tsbuildinfo|\*\.(egg-info|pyc|pyo|log|tmp|o|class|orig|rej|bak|swp|tsbuildinfo))$/;function Io(e,t){let n=e.argv.slice(1),s=e.name==="rimraf",r=!1,o=[],a=new Map;for(let[f,p]of n.entries()){if(!r&&p==="--"){r=!0;continue}if(!r&&p.startsWith("--")){p==="--recursive"&&(s=!0);continue}if(!r&&/^-[A-Za-z]+$/.test(p)){/[rR]/.test(p)&&(s=!0);continue}e.via==="find-exec"&&p==="{}"||(o.push(p),a.set(p,f+1))}e.via==="xargs"&&e.pipeFrom&&o.push(...xg(e.pipeFrom,t));let i=new Map;for(let f of o){let p=qn(f),d=xc(f,e,a.get(f)).flatMap(qn);for(let h of p)i.set(h,d)}if(o.splice(0,o.length,...o.flatMap(qn)),o.length===0)return[];let l=o.find(f=>$g(Ie(f,e,t),e,t));if(l!==void 0)return[m("claude.bash.fs.delete_recursive",`${e.name==="shred"?"shreds":"deletes"} a key or credentials file (${k(l)})`,{target:k(l),is_local:e.remote===null,host:e.remote})];let c=f=>f==="*"||f===".*"||f.endsWith("/*")||f.endsWith("/.*");if(!s&&!o.some(c))return[];let u=o.map(f=>{if(To.test(f))return{kind:"disposable",path:f,token:null,why:"build or cache artifacts"};let p=Ie(f,e,t),d=h=>c(h)?h==="*"||h===".*"?"./":`${h.replace(/\/\.?\*$/,"")}/`:h;return He(d(p),e,t,(i.get(f)??[]).map(h=>d(Ie(h,e,t))))});return[xt(u,e)]}var vg=/^\.(ssh\/(?!known_hosts(\.old)?$|config$)[^/]+|gnupg\/.+|aws\/(credentials|config)|kube\/config|docker\/config\.json|config\/gcloud\/.+|azure\/.+|netrc|git-credentials|npmrc|pypirc)$/;function $g(e,t,n){let s=M(e,t.cwd,n.ctx);if(S(s))return!1;let r=n.ctx.home.replace(/(?<!\/)\/+$/,""),o=s.startsWith(`${r}/`)?s.slice(r.length+1):null;if(o!==null&&vg.test(o))return!0;if(!ye(s)||X(s,null,se(n)).kind==="disposable")return!1;let a=n.projectRoot;return!(a&&!S(a)&&(s===a||s.startsWith(`${a}/`)))}var ul=64;function qn(e){let t=[],n=!1,s=r=>{if(t.length>=ul){n=!0;return}let o=/^(.*?)\{([^{}]*,[^{}]*)\}(.*)$/s.exec(r);if(!o){t.push(r);return}for(let a of o[2].split(","))s(`${o[1]}${a}${o[3]}`)};return s(e),n?[...t.slice(0,ul-1),`${ie}(more words from a brace expansion)${le}`]:t}function $c(e,t){let n=e.argv.slice(1);if(!n.some(a=>a==="--del"||a.startsWith("--delete")||a==="--remove-source-files"))return[];if(n.some(a=>a==="-n"||a==="--dry-run"||/^-[a-zA-Z]*n[a-zA-Z]*$/.test(a)))return[];let s=n.filter(a=>!a.startsWith("-")),r=s[s.length-1];if(!r||s.length<2)return[];if(/^[^/]*:/.test(r)&&!r.startsWith("/")&&!(V()&&/^[A-Za-z]:(?:[\\/]|$)/.test(r)))return[m("claude.bash.fs.delete_recursive",`rsync --delete removes files on ${r.split(":")[0]}`,{target:r,host:r.split(":")[0]??null,is_local:!1})];let o=He(r,e,t);return[{...xt([o],e),why:`rsync --delete into ${o.why}`}]}function xg(e,t){if(e.name==="echo"||e.name==="printf")return e.argv.slice(1).filter(n=>!n.startsWith("-")||n==="-");if(e.name==="find"){let n=_c(e);return n.disposableFilter?["/tmp/__find_matches_disposable__"]:n.roots}return[`${ie}(paths from ${e.name})${le}`]}function xt(e,t){let n={catastrophic:2,normal:1,disposable:0},s=[...e].sort((o,a)=>n[a.kind]-n[o.kind])[0],r=t.remote!==null;return s.kind==="disposable"&&!r?m("claude.bash.fs.delete_disposable",`deletes ${e.length>1?"temp, build or scratch paths":s.why}`,{target:s.path,is_local:!0}):m("claude.bash.fs.delete_recursive",`deletes ${s.why}${r?` on ${t.remote}`:""}`,{target:s.path,service:s.kind==="catastrophic"&&!r?s.token:null,is_local:!r,host:t.remote})}function He(e,t,n,s=xc(e,t)){let r=Ie(e,t,n),o=X(r,t.cwd,se(n));if(o.kind==="catastrophic")return o;for(let a of t.cwdFallbacks){let i=X(r,a,se(n));if(i.kind==="catastrophic")return{...i,why:`${i.why} if the cd before it failed`}}for(let a of s){if(a===""||a===e)continue;let i=X(Ie(a,t,n),t.cwd,se(n)),l=t.cwdFallbacks.some(c=>c!==null&&(a===c||a.startsWith(`${c}/`)));if(i.kind==="catastrophic")return{...i,why:`${i.why} ${l?"if the cd before it failed":"if an assignment before it did not run"}`}}return o}function xc(e,t,n){let s=n??t.argv.indexOf(e);return t.altArgvs.flatMap(r=>r.length===t.argv.length&&s>=0?[r[s]]:r.slice(1))}function se(e){return{home:e.ctx.home,tmpdir:e.ctx.tmpdir,projectRoot:e.projectRoot,base:e.base,onDisk:e.ctx.onDisk??null,made:e.ctx.session?.made??null,ignored:t=>oc(t,e)}}function cn(e,t,n=e.base){let s=e.ctx.onDisk,r=S(t)&&!t.startsWith("/")&&!t.startsWith(ie)&&n!==null&&n.startsWith("/")&&!S(n)?R.join(n,t):t;S(r)?s?.unknown?.add(r):r.startsWith("/")&&s?.written?.add(r)}function Ft(e,t){let n=e.ctx.onDisk;if(!n?.touched||!n.read)return t();let s=new Set([...n.touched.full,...n.touched.parent]),r=t();for(let o of[...n.touched.full,...n.touched.parent])s.has(o)||n.read.add(o);return r}var _g=new Set(["go","cargo","docker","podman","gradle","gradlew","mvn","mvnw","deno","poetry","uv","pipenv","dotnet","swift","flutter","dart","mix","npx","bunx","pnpx"]),Sg=new Set(["npm","pnpm","yarn","bun"]),Cg=new Set(["make","gmake","just","task","rake","mage"]);function Ag(e){let t=ue(e.name),n=e.argv.slice(1).filter(r=>!r.startsWith("-")),s=r=>/^[\w:@+-]+$/.test(r);return Cg.has(t)?new Set(n.filter(s)):Sg.has(t)?new Set((["run","run-script"].includes(n[0]??"")?n.slice(0,2):n.slice(0,1)).filter(s)):_g.has(t)?new Set(n.slice(0,1).filter(s)):new Set}function Ys(e,t,n){return cn(n,M(Ie(e,t,n),t.cwd??n.base??n.projectRoot,n.ctx)),He(e,t,n)}var dl=new Set(["-name","-iname","-path","-ipath","-wholename","-iwholename","-regex","-iregex","-empty","-mtime","-mmin","-atime","-amin","-ctime","-cmin","-newer","-anewer","-cnewer","-size","-user","-group","-perm","-links","-inum","-samefile","-nouser","-nogroup"]);function Eg(e){let t=[[]];for(let a of e)a==="-o"||a==="-or"||a===","?t.push([]):t[t.length-1].push(a);let n=[],s=!1,r=!0,o=!0;for(let a of t){let i=!1,l=!1;for(let c=0;c<a.length;c++){let u=a[c];if(u==="!"||u==="-not"){(a[c+1]==="("||a[c+1]==="\\(")&&(s=!0),c+=dl.has(a[c+1]??"")||["-type","-maxdepth","-mindepth"].includes(a[c+1]??"")?2:1;continue}dl.has(u)&&(i=!0,["-name","-iname","-path","-ipath","-wholename"].includes(u)&&a[c+1]!==void 0&&(n.push(a[c+1]),l=!0))}i||(r=!1,a.some(c=>c==="!"||c==="-not")&&(s=!0)),l||(o=!1)}return t.length>1&&!r&&(s=!0),{names:n,narrows:r&&!s,everyBranchNamed:o,invertible:s}}function _c(e){let t=e.argv.slice(1),n=[],s=0;for(;s<t.length&&!/^[-(!]/.test(t[s]);)n.push(t[s++]);n.length===0&&n.push(".");let r=!1;for(let g=s;g<t.length;g++){let y=t[g];y==="-delete"&&(r=!0),["-exec","-execdir","-ok","-okdir"].includes(y)&&["rm","unlink","shred","rmdir"].includes(ue(t[g+1]??""))&&(r=!0)}let o=t.slice(s),a=Eg(o),i=a.names,l=i.length>0&&i.every(g=>vc.test(R.basename(g.replace(/\/$/,"")))||To.test(g))&&!a.invertible&&a.everyBranchNamed,c=a.invertible,u=a.narrows,f=u&&o.includes("-empty"),p=o.some((g,y)=>g==="-type"&&o[y+1]==="d"),d=g=>/[*?[]/.test(g),h=u?f?p?"empty folders":"empty files and folders":i.length>0?`${i.every(g=>!d(g))?(i.length===1,"every file named"):"the files matching"} ${i.slice(0,3).join(", ")}${i.length>3?", \u2026":""}`:"the files its filters match":null;return{roots:n,deletes:r,disposableFilter:l,narrowed:h,emptyOnly:f,filesOnly:!u&&o.some((g,y)=>g==="-type"&&o[y+1]==="f"),invertible:c}}function Rg(e,t){let n=_c(e);if(!n.deletes)return[];let s=n.roots.map(l=>Ys(l,e,t)),r=s.find(l=>l.token==="fs.root"||l.token==="fs.home"||l.token==="fs.system");if(n.disposableFilter&&r)return[m("claude.bash.fs.delete_recursive",`find deletes matching files under ${r.path}`,{target:n.roots.join(" "),is_local:!0})];if(n.disposableFilter)return[m("claude.bash.fs.delete_disposable","find deletes build or cache artifacts",{target:n.roots.join(" "),is_local:!0})];let o=r??s.find(l=>l.kind==="catastrophic")??s.find(l=>l.kind==="normal")??s[0],a=o.token==="fs.home"&&o.path===t.ctx.home.replace(/(?<!\/)\/+$/,"")?"your home folder":o.token==="fs.project_root"?"the project":o.token==="fs.root"?"the whole disk":k(o.path);if(n.narrowed!==null){let l=`find deletes ${n.narrowed} under ${a}`;return n.emptyOnly&&!r?[m("claude.bash.fs.delete_disposable",l,{target:n.roots.join(" "),is_local:!0})]:s.every(c=>c.kind==="disposable")?[m("claude.bash.fs.delete_disposable",l,{target:n.roots.join(" "),is_local:!0})]:[m("claude.bash.fs.delete_recursive",l,{target:n.roots.join(" "),is_local:!0})]}let i=xt(s,e);return i.action==="claude.bash.fs.delete_recursive"&&n.filesOnly?[{...i,why:`find deletes every file under ${a}`}]:i.action==="claude.bash.fs.delete_recursive"&&n.invertible?[{...i,why:`find deletes everything under ${a} except what its filter keeps`}]:[i]}var Og=new Set(["-t","--type","-e","--extension","-d","--max-depth","--min-depth","--exact-depth","-E","--exclude","-S","--size","--changed-within","--changed-before","-o","--owner","-j","--threads","--path-separator","-c","--color","--ignore-file","--max-results","--batch-size"]);function jg(e,t){let n=e.argv.slice(1),s=n.findIndex(g=>["-x","--exec","-X","--exec-batch"].includes(g));if(s<0||!["rm","unlink","shred","rmdir"].includes(ue(n[s+1]??"")))return[];if(ue(n[s+1]??"")==="rmdir")return[];let r=n.slice(0,s).flatMap((g,y)=>g==="-t"||g==="--type"?[n[y+1]??""]:/^-t./.test(g)?[g.slice(2)]:g.startsWith("--type=")?[g.slice(7)]:[]);if(r.some(g=>g==="e"||g==="empty"))return[m("claude.bash.fs.delete_disposable","fd deletes empty files or folders",{target:".",is_local:!0})];let o=[],a=[],i=[],l=!1;for(let g=0;g<s;g++){let y=n[g];y==="--search-path"||y==="--base-directory"?(n[g+1]!==void 0&&a.push(n[g+1]),g++):y==="-e"||y==="--extension"?(n[g+1]!==void 0&&i.push(`*.${n[g+1].replace(/^\./,"")}`),g++):y.startsWith("--extension=")?i.push(`*.${y.slice(12).replace(/^\./,"")}`):y==="-g"||y==="--glob"?l=!0:y.startsWith("-")?Og.has(y)&&g++:o.push(y)}let c=o[0]??"";if(c!==""&&c!=="."&&c!=="^"){let g=/^\\?\.([\w-]+)\$$/.exec(c);i.push(l?c:g?`*.${g[1]}`:c.replace(/^\^|\$$/g,"").replace(/\\(.)/g,"$1"))}let u=[...o.slice(1),...a];u.length===0&&u.push(".");let f=u.map(g=>Ys(g,e,t)),p=f.find(g=>g.token==="fs.root"||g.token==="fs.home"||g.token==="fs.system"),d=i.length>0&&i.every(g=>vc.test(R.basename(g))||To.test(g));return d&&p?[m("claude.bash.fs.delete_recursive",`fd deletes matching files under ${p.path}`,{target:u.join(" "),is_local:!0})]:d?[m("claude.bash.fs.delete_disposable","fd deletes build or cache artifacts",{target:u.join(" "),is_local:!0})]:i.length>0||r.length>0||n.slice(0,s).some(g=>/^(-S|--size|--changed-(within|before)|--newer|--older)(=|$)/.test(g))?[m("claude.bash.fs.delete_recursive",`fd deletes the files matching ${i.join(", ")||"its filters"} under ${u.join(" ")}`,{target:u.join(" "),is_local:!0})]:[xt(f,e)]}function fl(e,t){let n=e.argv.slice(1);if(e.name==="dd"){let s=n.find(o=>o.startsWith("of="))?.slice(3);if(!s)return[];let r=He(s,e,t);return r.token==="fs.device"?[m("claude.bash.fs.delete_recursive",`overwrites a raw disk (${s})`,{target:s,service:"fs.device",is_local:!0})]:Cu.test(s)&&r.kind!=="disposable"?[m("claude.bash.fs.delete_recursive",`dd overwrites a data file (${R.basename(s)})`,{target:r.path,is_local:!0})]:[]}return e.name==="diskutil"?n.some(s=>/^(erase|zeroDisk|randomDisk|secureErase|partitionDisk|reformat)/i.test(s))?[m("claude.bash.fs.delete_recursive","erases a disk",{target:n.join(" "),service:"fs.device",is_local:!0})]:[]:[m("claude.bash.fs.delete_recursive",`formats or repartitions a disk (${e.name})`,{target:n.join(" "),service:"fs.device",is_local:!0})]}function _t(e){let t=e.argv,n=1,s=null;for(;n<t.length;){let o=t[n];if(o==="-C"&&t[n+1])s=t[n+1],n+=2;else if(o==="-c"||o==="--git-dir"||o==="--work-tree"||o==="--namespace")o==="--work-tree"&&t[n+1]&&(s=t[n+1]),n+=2;else if(o.startsWith("--work-tree="))s=o.slice(12),n++;else if(o.startsWith("-"))n++;else break}let r=t[n];return r?{sub:r,args:t.slice(n+1),dir:s}:null}function Sc(e,t){return e.cwdFallbacks.length>0||e.altArgvs.length>0||/\bgit\s+(?:-[cC]\s+\S+\s+|--?[\w-]+=\S+\s+|-(?![cC]\s)[\w-]+\s+)*(?:remote\s+(?:add|set-url|rename|remove|rm|set-head|set-branches)\b|config\s+(?!--get|--list|-l\b)|clone\b|init\b|submodule\b)|\bgh\s+repo\s+(?:clone|set-default|create|fork)\b|\b(?:HOME|XDG_CONFIG_HOME)=|\bGIT_(?:CONFIG|DIR|WORK_TREE|COMMON_DIR)|--git-dir|--work-tree/.test(t)}function zt(e,t,n){if(/\bGIT_(DIR|WORK_TREE|COMMON_DIR)\b|--git-dir/.test(n.lineText)||e.wrappers.includes("env")&&e.wrapperArgs.some(r=>/^-C/.test(r)||r.startsWith("--chdir")))return null;let s=t.dir?Ec(t.dir,e,n):e.cwd;return s===null||S(s)?null:s}function Pg(e,t,n){let s=e[t];if(!/^-[a-zA-Z]/.test(s))return null;for(let r=1;r<s.length;r++)if(n.includes(s[r]))return{letter:s[r],value:s.slice(r+1)||e[t+1]};return null}function Cc(e,t){let[n,s,r]=t==="switch"?["c","C","--create"]:["b","B",""],o=[];for(let a=0;a<e.length;a++){let i=e[a];if(i==="--")break;if(i==="--force-create"&&e[a+1])o.push({letter:s,branch:e[++a]});else if(i.startsWith("--force-create="))o.push({letter:s,branch:i.slice(15)});else if(r&&i===r&&e[a+1])o.push({letter:n,branch:e[++a]});else if(r&&i.startsWith(`${r}=`))o.push({letter:n,branch:i.slice(r.length+1)});else{let l=Pg(e,a,n+s);l&&l.value!==void 0&&(o.push({letter:l.letter,branch:l.value}),l.value===e[a+1]&&a++)}}return o}function Wg(e,t){return Cc(e,t).at(-1)??null}function Ng(e,t){if(e.name!=="git")return;let n=_t(e);if(!n)return;let s=n.dir??e.cwd;if(n.sub==="stash"){let r=n.args[0];(r===void 0||r==="push"||r==="save"||r.startsWith("-"))&&(t.stashCreated=!0,t.stashPushes++),r==="apply"&&t.stashApplied.add(yo(n.args.slice(1)))}if(n.sub==="worktree"&&n.args[0]==="add"){let r=n.args.lastIndexOf("-b");r>=0&&n.args[r+1]&&t.createdBranches.set(n.args[r+1],{by:Rn(e),repo:zt(e,n,t)})}if(n.sub==="checkout"||n.sub==="switch"){if(n.args.includes("--"))return;let r=Wg(n.args,n.sub);if(r){t.branch=r.branch,t.branchDir=s,(r.letter==="b"||r.letter==="c")&&t.createdBranches.set(t.branch,{by:Rn(e),repo:zt(e,n,t)});return}let o=n.args.find(a=>!a.startsWith("-"));o&&!o.includes("/")&&o!=="."&&!S(o)&&(t.branch=o,t.branchDir=s)}}function Lg(e,t){return t===e.branchDir?e.branch:null}function Do(e){return e!==null&&/\/scratchpad(\/|$)/.test(e)}function kt(e,t){return e===null?!1:Do(e)?!0:X(e,null,se(t)).kind==="disposable"}function pl(e,t,n,s){let r=t!==null&&!S(t)?t.replace(/(?<!\/)\/+$/,""):null,a=(n.ctx.projectControls??[]).filter(l=>typeof l=="object"&&l!==null&&typeof l.path=="string").filter(l=>(r===null||l.path.startsWith(`${r}/`))&&(l.staged===!0?s.staged:l.ignored===!0?s.ignored:s.untracked)).map(l=>l.path);if(a.length===0)return[];let i=k(a[0]);return[m("claude.agent.controls",`${e} takes this project's own ${R.basename(i)} away, so later sessions here run without it`,{target:i,is_local:!0})]}function Ac(e,t){let n=_t(e);if(!n)return[];let s=n.dir?Ec(n.dir,e,t):e.cwd,r=i=>n.args.some(l=>i.includes(l)),o=i=>n.args.some(l=>/^-[a-zA-Z]+$/.test(l)&&l.includes(i)),a=n.sub.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();if(/(^|-)(delete|del|remove|rm|prune|purge|drop|nuke|wipe|clean|cleanup)(-|$)/.test(a)&&/(^|-)(branch|branches|tag|tags|gone|merged|stale|worktree|worktrees)(-|$)/.test(a))return[m("claude.bash.git.discard",`git ${n.sub}: a command named for deleting branches or tags (an alias or extension)`,{target:[n.sub,...n.args.filter(i=>!i.startsWith("-"))].join(" "),is_local:!0})];switch(n.sub){case"push":{let i=Sc(e,t.lineText)||e.argv.filter(l=>l==="-C").length>1||e.argv.some(l=>/^(-c|--config-env)/.test(l))?null:zt(e,n,t);return Tg(n.args,t,e,Lg(t,n.dir??e.cwd),i)}case"reset":return r(["--hard"])&&!Do(s)?[m("claude.bash.git.discard","git reset --hard discards uncommitted work",{target:n.args.find(i=>!i.startsWith("-"))??"HEAD",branch:t.branch,is_local:!0})]:[];case"checkout":{let i=n.args.indexOf("--"),l=i>=0?n.args.slice(i+1):n.args.filter(u=>!u.startsWith("-"));return(l.some(u=>u==="."||u==="./"||u===":/"||u==="*"||u===":(top)")||r(["-f","--force"]))&&!kt(s,t)?[m("claude.bash.git.discard","git checkout discards every uncommitted change",{target:l.join(" ")||".",branch:t.branch,is_local:!0})]:hl(n.args,"checkout",e,t)}case"rm":{let i=n.args.filter(c=>!c.startsWith("-"));return i.some(c=>c==="."||c==="./"||c==="./*"||c===":/"||c==="*"||c===":(top)")&&(r(["-f","--force"])||o("f"))&&!r(["--cached","-n","--dry-run"])&&!o("n")&&!kt(s,t)?[m("claude.bash.git.discard","git rm -f deletes every tracked file, uncommitted changes too",{target:i.join(" "),branch:t.branch,is_local:!0})]:[]}case"restore":{if((r(["--staged"])||o("S"))&&!r(["--worktree"])&&!o("W"))return[];let i=n.args.filter(l=>!l.startsWith("-"));return i.some(l=>l==="."||l==="./"||l===":/"||l==="*")&&!kt(s,t)?[m("claude.bash.git.discard","git restore discards every uncommitted change",{target:i.join(" "),branch:t.branch,is_local:!0})]:[]}case"branch":{let i=n.args.filter(d=>!d.startsWith("-")),l=r(["-f","--force"])||o("f"),c=r(["-d","--delete","-D"])||n.args.some(d=>/^-[a-zA-Z]*[dD]/.test(d)&&/^-[a-zA-Z]+$/.test(d)),u=c&&(r(["-D"])||n.args.some(d=>/^-[a-zA-Z]*D/.test(d))||l);if(u&&i.length>0&&i.every(d=>Mn(d,e,t)||ih(d,zt(e,n,t),t)))return[];if(u)return[m("claude.bash.git.discard","git branch force-deletes a branch",{target:i.join(" "),is_local:!0})];let f=d=>n.args.some(h=>/^-[a-zA-Z]{2,}$/.test(h)&&d.test(h.slice(1))),p=r(["-m","--move","-c","--copy"])||f(/[mc]/);return r(["-M","-C"])||f(/[MC]/)||l&&p?[m("claude.bash.git.discard","git branch -M / -C overwrites a branch",{target:i.join(" "),is_local:!0})]:l&&!c&&i[0]!==void 0&&!Mn(i[0],e,t)?[m("claude.bash.git.discard",`git branch -f moves ${i[0]}`,{target:i.join(" "),branch:i[0],is_local:!0})]:[]}case"stash":{if(n.args[0]==="drop"){let u=yo(n.args.slice(1));if(t.stashApplied.has(u))return[];if(u.startsWith("computed:")&&t.stashCreated&&t.stashApplied.size>0)return[]}if((n.args[0]==="drop"||n.args[0]==="clear")&&oh(yo(n.args.slice(1)),n.args[0]==="clear",zt(e,n,t),t,e))return[];if(n.args[0]==="drop"||n.args[0]==="clear")return[m("claude.bash.git.discard",`git stash ${n.args[0]} deletes stashed work`,{target:n.args.slice(1).join(" ")||"stash",is_local:!0})];let i=n.args.length===0||["push","save"].includes(n.args[0])||n.args[0].startsWith("-"),l=r(["--all"])||o("a"),c=/\bgit\s+add\s+(?:[^;&|\n]*\s)?(-A|--all|\.)(\s|$)/.test(t.lineText.slice(0,65536));return i?pl("git stash",null,t,{untracked:l||c||r(["--include-untracked"])||o("u"),ignored:l,staged:!0}):[]}case"clean":{if(r(["--dry-run"])||o("n"))return[];if(!(r(["--force"])||o("f"))||kt(s,t))return[];let i={untracked:!o("X"),ignored:o("x")||o("X"),staged:!1},l=s??e.cwd;return[m("claude.bash.git.discard","git clean -f deletes untracked files",{target:s??".",is_local:!0,housekeeping:l!==null&&t.lineMade.some(c=>an(c,l))}),...pl("git clean -f",s,t,i)]}case"reflog":return n.args[0]==="delete"||n.args[0]==="expire"&&n.args.some(i=>/^--expire=(now|all|0)/.test(i)||i==="--all")?[m("claude.bash.git.discard",`git reflog ${n.args[0]} removes the record of lost commits`,{is_local:!0})]:[];case"gc":return n.args.some(i=>i==="--prune=now"||i==="--prune=all")?[m("claude.bash.git.discard","git gc --prune=now makes lost commits unrecoverable",{is_local:!0})]:[];case"filter-branch":case"filter-repo":return[m("claude.bash.git.discard",`git ${n.sub} rewrites history`,{is_local:!0})];case"symbolic-ref":{let i=n.args.filter(l=>!l.startsWith("-"));return!r(["-d","--delete"])&&i.length>=2&&i[0]!=="HEAD"?[m("claude.bash.git.discard",`git symbolic-ref points ${i[0]} at ${i[1]}`,{target:i[0],is_local:!0})]:[]}case"update-ref":{if(r(["-d"]))return[m("claude.bash.git.discard","git update-ref -d deletes a ref",{target:n.args.find(l=>!l.startsWith("-"))??null,is_local:!0})];let i=n.args.filter((l,c)=>!l.startsWith("-")&&n.args[c-1]!=="-m")[0]??"";return r(["--stdin"])||i.startsWith("refs/heads/")&&!Mn(i.slice(11),e,t)?[m("claude.bash.git.discard",`git update-ref moves ${i||"refs from stdin"}`,{target:i||"stdin",is_local:!0})]:[]}case"worktree":if(n.args[0]==="add"){let i=n.args.findIndex(c=>c==="-B"),l=i>0?n.args[i+1]:void 0;if(l!==void 0&&!Mn(l,e,t))return[m("claude.bash.git.discard",`git worktree add -B resets ${l}`,{target:l,branch:l,is_local:!0})]}if(n.args[0]==="remove"&&(r(["--force"])||o("f"))){let i=n.args.slice(1).find(u=>!u.startsWith("-"))??"",l=n.dir&&!S(n.dir)?X(n.dir,e.cwd,se(t)).path??e.cwd:e.cwd,c=X(i,l,se(t));return kt(c.path,t)||c.why===On?[]:e.guards.some(u=>/\bgit\b[^;&|]*\bworktree\s+add\b/.test(u)&&u.split(/\s+/).some(f=>f.replace(/^["']|["']$/g,"")===i))?[]:[m("claude.bash.git.discard","git worktree remove --force discards its changes",{target:i,is_local:!0})]}return[];case"switch":return r(["--discard-changes","-f","--force"])?[m("claude.bash.git.discard","git switch discards uncommitted changes",{branch:t.branch,is_local:!0})]:hl(n.args,"switch",e,t);default:return[]}}function hl(e,t,n,s){let r=Cc(e,t).find(o=>(o.letter==="B"||o.letter==="C")&&!Mn(o.branch,n,s));return r?[m("claude.bash.git.discard",`git ${t} -${r.letter} resets ${r.branch}`,{target:r.branch,branch:r.branch,is_local:!0})]:[]}function Mn(e,t,n){let s=n.createdBranches.get(e),r=_t(t),o=r?zt(t,r,n):null;return s!==void 0&&t.guards.includes(s.by)&&s.repo!==null&&s.repo===o}function yo(e){let t=e.find(n=>!n.startsWith("-"));return t===void 0?"stash@{0}":/^\d+$/.test(t)?`stash@{${t}}`:S(t)?`computed:${k(t)}`:t}function Ec(e,t,n){let s=`${e.replace(/\/$/,"")}/_`,r=Ie(s,t,n);return X(r!==s&&r.endsWith("/_")?r.slice(0,-2):e,t.cwd,se(n)).path}function Tg(e,t,n,s,r=null){let o=!1,a=!1,i=!1,l=[],c=null,u=new Set(["--repo","--receive-pack","--exec","-o","--push-option","--signed"]);for(let y=0;y<e.length;y++){let $=e[y];if($==="-n"||$==="--dry-run")return[];if($==="-f"||$==="--force"||$.startsWith("--force-with-lease")||$==="--force-if-includes"||$==="--mirror")o=!0;else if($==="-d"||$==="--delete")a=!0;else if($==="--all"||$==="--branches")i=!0;else if(/^-[a-zA-Z]+$/.test($)){if($.includes("f")&&(o=!0),$.includes("n"))return[];$.includes("d")&&(a=!0)}else $==="--repo"?c=e[++y]??null:$.startsWith("--repo=")?c=$.slice(7):u.has($)?y++:$.startsWith("-")||l.push($)}let f=l[0]??c,p={repo_dir:r===null||S(r)?null:r,repo_remote:f===null?null:S(f)?"$?":k(f),repo_via:"git"};if(e.includes("--mirror"))return[m("claude.bash.git.force_push","mirrors every branch and tag to the remote, overwriting or deleting what differs (main included)",{branch:null,target:"every branch and tag",service:null,is_local:!1})];let d=l.slice(1),h=[];d.length===0&&h.push({branch:i?"main":s,plus:!1,deleting:!1});for(let y of d){let $=y.startsWith("+"),E=$?y.slice(1):y,x=E.indexOf(":"),b=x>=0?E.slice(0,x):E,j=x>=0?E.slice(x+1):E,C=x===0,A=U=>S(U)&&/git\s+(branch\s+--show-current|rev-parse\s+--abbrev-ref\s+HEAD|symbolic-ref\s+--short\s+HEAD)/.test(k(U));(j==="HEAD"||x<0&&b==="HEAD"||A(j))&&(j=s??""),j=j.replace(/^refs\/heads\//,""),h.push({branch:j||null,plus:$,deleting:C||a})}let g=[];for(let y of h){let $=y.branch!==null&&cc.has(y.branch),E=y.branch??"the current branch";y.deleting?g.push($?m("claude.bash.git.force_push",`deletes the remote ${E} branch`,{branch:y.branch,target:E,service:"git.main",is_local:!1}):m("claude.bash.git.discard",`deletes the remote branch ${E}`,{branch:y.branch,target:E,is_local:!1})):o||y.plus?g.push(m("claude.bash.git.force_push",`force-pushes ${E}`,{branch:y.branch,target:E,service:$?"git.main":null,is_local:!1})):$?g.push(m("claude.bash.git.push_main",`pushes to ${y.branch} (a deploy)`,{branch:y.branch,target:y.branch,is_local:!1,push:p})):y.branch!==null&&Wh.has(y.branch)&&g.push(m("claude.bash.deploy",`pushes to ${y.branch} (a deploy branch)`,{branch:y.branch,target:y.branch,is_local:!1}))}return g}function Rc(e){let t=e.indexOf("--"),s=(t<0?e:e.slice(0,t)).filter(r=>r==="--rm"||r.startsWith("--rm="));return s.length>0&&!/^--rm=(false|0)$/i.test(s[s.length-1])}function Ig(e,t){let n=t.ctx.session?.repoRemotes;if(!n||!e.cwd||S(e.cwd))return null;let s=Object.keys(n).filter(r=>e.cwd===r||e.cwd.startsWith(`${r}/`)).sort((r,o)=>o.length-r.length)[0];return s===void 0?null:n[s]??null}function Dg(e,t){let n=Ig(e,t)?.filter(Boolean);if(!n||n.length===0)return!1;let s=[];return e.argv.forEach((r,o)=>{r==="-R"||r==="--repo"?s.push(e.argv[o+1]??null):r.startsWith("--repo=")?s.push(r.slice(7)):/^-R\S/.test(r)&&s.push(r.slice(2))}),s.length===0?!1:s.every(r=>!r||S(r)?!1:n.includes((Fg(r)??r).toLowerCase().replace(/^github\.com\//,"")))}function Fg(e){let t=/github\.com[:/]+([\w.-]+)\/([\w.-]+?)(?:\.git)?\/?$/.exec(e.trim());return t?`${t[1]}/${t[2]}`:null}function Ns(e,t){let n=[];e.argv.forEach((l,c)=>{l==="-R"||l==="--repo"?n.push(e.argv[c+1]??""):l.startsWith("--repo=")?n.push(l.slice(7)):/^-R\S/.test(l)?n.push(l.slice(2).replace(/^=/,"")):/^-[A-Za-z]+R/.test(l)&&n.push("$?")});let s=e.argv.slice(3).find(l=>/^https?:\/\/[^/]+\/[^/]+\/[^/]+\/(?:pulls?|issues)\/\d+/.test(k(l))),o=[...e.text.slice(0,Math.max(0,e.text.search(/(?:^|\s)(?:\S*\/)?gh\s/))).matchAll(/\bGH_REPO=("[^"]*"|'[^']*'|[^\s;&|)]+)/g)].pop()?.[1]?.replace(/^["']|["']$/g,""),a=s??n[n.length-1]??o??null;return{repo_dir:e.cwd!==null&&!S(e.cwd)&&(a!==null||!(Sc(e,t)||/\bGH_REPO\b/.test(t)))?e.cwd:null,repo_remote:a===null?null:S(a)?"$?":k(a),repo_via:"gh"}}function zg(e,t,n){let[,s="",r=""]=e.argv,o=e.argv.slice(3),a=(...l)=>e.argv.some(c=>l.includes(c)||l.some(u=>c.startsWith(`${u}=`)));if(s==="pr"&&r==="merge")return[m("claude.bash.git.push_main","gh pr merge merges a pull request into its base branch (main, unless it says otherwise: a deploy)",{target:o.find(l=>!l.startsWith("-"))??"current PR",branch:"main",is_local:!1,host:"github.com",push:Ns(e,t)})];if(s==="pr"&&(r==="create"||r==="edit"))if(a("-R","--repo")||e.argv.some(c=>/^-R\S/.test(c))||/\bGH_REPO=/.test(t)){if(n&&!/\bGH_REPO=/.test(t)&&Dg(e,n))return[]}else return[];let i={pr:new Set(["create","comment","review","close","reopen","edit","ready","lock","unlock"]),issue:new Set(["create","comment","close","reopen","edit","delete","transfer","lock","unlock","pin","unpin","develop"]),release:new Set(["delete","edit","upload","delete-asset"]),repo:new Set(["create","delete","edit","fork","rename","archive","unarchive"]),secret:new Set(["set","delete","remove"]),variable:new Set(["set","delete"]),workflow:new Set(["run","enable","disable"]),run:new Set(["cancel","delete"]),gist:new Set(["create","edit","delete"]),label:new Set(["create","edit","delete","clone"]),cache:new Set(["delete"])};if(s==="release"&&r==="create")return a("--draft","-d")?[m("claude.bash.external_write","gh release create makes a draft release on GitHub (nothing is published until someone publishes it)",{target:o.find(l=>!l.startsWith("-"))??null,is_local:!1,host:"github.com",push:Ns(e,t)})]:[m("claude.bash.publish","gh release create publishes a release",{target:o.find(l=>!l.startsWith("-"))??null,is_local:!1,host:"github.com",push:Ns(e,t)})];if(s==="workflow"&&r==="run"){let l=e.argv.findIndex(h=>h==="--ref"||h==="-r"),c=l>=0?e.argv[l+1]:e.argv.find(h=>h.startsWith("--ref="))?.slice(6),u=e.argv.slice(3).some(h=>!h.startsWith("-")&&/deploy|release|publish|prod/i.test(h)),f="";for(let h=3;h<e.argv.length&&!f;h++)/^(--ref|-r|-f|-F|--field|--raw-field|--repo|-R)$/.test(e.argv[h])?h++:e.argv[h].startsWith("-")||(f=e.argv[h]);let p=/deploy|release|publish|promot|rollout|(?:^|[^a-z])(?:prod(?:uction)?|ship)(?:[^a-z]|$)/i.test(f),d=e.argv.flatMap((h,g)=>/^(-f|-F|--field|--raw-field)$/.test(e.argv[g-1]??"")?[h]:/^(--field|--raw-field)=/.test(h)?[h.slice(h.indexOf("=")+1)]:[]);if(p||d.some(h=>/^(environment|env|stage|deploy_env|target)=/i.test(h)))return[m("claude.bash.deploy",p?"gh workflow run starts a deploy or release workflow":"gh workflow run starts a workflow for an environment",{target:o.find(h=>!h.startsWith("-"))??null,is_local:!1,host:"gh"})];if(c&&!S(c)&&!cc.has(c.replace(/^refs\/heads\//,""))&&!u)return[]}if(s==="run"&&r==="rerun"&&/(?<![\w-])[\w-]*(deploy|release|publish|prod)[\w-]*\.ya?ml\b|--workflow[= ]+['"]?[\w -]*(deploy|release|publish|prod)/i.test(t))return[m("claude.bash.external_write","gh run rerun next to a deploy or release workflow can redo a release",{target:"run rerun",is_local:!1,host:"github.com"})];if(i[s]?.has(r))return[m("claude.bash.external_write",`gh ${s} ${r} changes GitHub`,{target:`${s} ${r}`,is_local:!1,host:"github.com",push:Ns(e,t),...s==="repo"&&r==="delete"?{catastrophic:!0}:{}})];if(s==="auth"&&r==="setup-git")return[m("claude.bash.persistence","gh auth setup-git makes gh the git credential helper for every repository",{target:"credential.helper",is_local:!0})];if(s==="auth"&&(r==="token"||r==="status"&&a("-t","--show-token")))return ae(e)?[m("claude.bash.secrets.print","prints the GitHub token",{target:"gh auth token",is_local:!0})]:[];if(s==="api"){let l=e.argv.findIndex(p=>p==="-X"||p==="--method"),c=(l>=0?e.argv[l+1]:e.argv.find(p=>p.startsWith("--method="))?.slice(9)??e.argv.find(p=>/^-X[A-Z]+$/.test(p))?.slice(2)??null)?.toUpperCase()??null,u=a("-f","-F","--field","--raw-field","--input"),f=e.argv.slice(2).find((p,d,h)=>!p.startsWith("-")&&!["-X","--method"].includes(h[d-1]??""))??"";if(c==="GET"||c==="HEAD")return[];if(f==="graphql"){let p=e.argv.join(" ");return/\bmutation\b/.test(p)?[m("claude.bash.external_write","gh api runs a GraphQL mutation",{target:"graphql",is_local:!1,host:"github.com"})]:[]}if(c&&c!=="GET"||u)return[m("claude.bash.external_write",`gh api ${c??"POST"} ${f}`,{target:f,is_local:!1,host:"github.com",...c==="DELETE"&&!jc.test(f)?{catastrophic:!0}:{}})]}return[]}var Js=new Set(["-X","-H","-d","-F","-o","-u","-A","-e","-b","-c","-m","-w","-x","-T","-K","-r","-C","-Y","-y","-z","-E","-U","-P","-Q","--request","--header","--data","--data-raw","--data-binary","--data-ascii","--data-urlencode","--json","--form","--form-string","--output","--user","--user-agent","--referer","--cookie","--cookie-jar","--max-time","--connect-timeout","--write-out","--proxy","--upload-file","--config","--range","--retry","--retry-delay","--resolve","--cert","--key","--cacert","--limit-rate","--url","--oauth2-bearer"]),Mt=["-d","--data","--data-raw","--data-binary","--data-ascii","--data-urlencode","--json","-F","--form","--form-string","-T","--upload-file"],Fo=/(?:(?:https?:\/\/)?(?<![\w.-])(?:[\w-]{1,63}\.){0,5}anvilcontrol\.ai(?::\d+)?|ANVIL_API(?:_BASE)?_URL)[\s\S]{0,60}?(\/v1\/(?:modes|kill-switch)|\/anvil\/actions\/(?:mode|removal-confirm)|\/api\/control\/kill-switch)\b/;function zo(e){return e.includes("anvilcontrol.ai")||e.includes("ANVIL_API")}function Oc(e,t,n){if(!zo(e))return null;let s=Fo.exec(e)?.[1];return s===void 0?null:t==="DELETE"||s.endsWith("removal-confirm")?s:s.endsWith("kill-switch")?/\bon["']?\s*[:=]\s*(false|False)\b/.test(n)&&!/\bon["']?\s*[:=]\s*(true|True)\b/.test(n)?null:s:/\bmode["']?\s*[:=]\s*["']enforce["']/.test(n)&&!/["']ghost["']/.test(n)?null:s}function Mg(e){let t=e.argv,n=null,s=!1,r=!1,o=[];if(e.name==="curl"){for(let p=1;p<t.length;p++){let d=t[p];if(d==="-X"||d==="--request"?n=(t[p+1]??"").toUpperCase():/^-X[A-Za-z]+$/.test(d)?n=d.slice(2).toUpperCase():d.startsWith("--request=")?n=d.slice(10).toUpperCase():d[0]==="-"&&d[1]!=="-"&&d.includes("X")&&/^-[a-zA-Z]+X$/.test(d)?n=(t[p+1]??"").toUpperCase():d[0]==="-"&&d[1]!=="-"&&d.includes("X")&&/^-[a-zA-Z]+X[A-Z]+$/.test(d)&&(n=d.slice(d.indexOf("X")+1)),(Mt.includes(d)||Mt.some(h=>h.startsWith("--")&&d.startsWith(`${h}=`))||/^-d./.test(d))&&(s=!0),(d==="-G"||d==="--get")&&(r=!0),(d==="-I"||d==="--head")&&(n="HEAD"),d==="--url"&&t[p+1]&&o.push(t[p+1]),Js.has(d)||d.endsWith("X")&&/^-[a-zA-Z]+X$/.test(d)){p++;continue}!d.startsWith("-")&&un(d)&&o.push(d)}n||(n=s&&!r?"POST":"GET")}else if(e.name==="wget"){for(let[p,d]of t.entries())(d.startsWith("--post-data")||d.startsWith("--post-file")||d.startsWith("--body-data")||d.startsWith("--body-file"))&&(s=!0),d.startsWith("--method=")&&(n=d.slice(9).toUpperCase()),d==="--method"&&t[p+1]&&(n=t[p+1].toUpperCase()),p>0&&!d.startsWith("-")&&un(d)&&o.push(d);n||(n=s?"POST":"GET")}else{let p=t.slice(1).filter((d,h)=>!d.startsWith("-")&&!((t[h]??"").startsWith("-")&&qg.test(t[h])));p[0]&&/^(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)$/i.test(p[0])&&(n=p.shift().toUpperCase()),p[0]&&o.push(p[0]),n||(n=p.slice(1).some(d=>/^[^=:@]+(:?=|@)/.test(d))?"POST":"GET")}if(!["POST","PUT","PATCH","DELETE"].includes(n))return[];if(n==="POST"&&(Zg(t)||Kg(o,t)))return[];let a=o.filter(p=>!Re(p));if(o.length>0&&a.length===0)return[];let i=a[0]??o[0]??null,l=t.filter((p,d)=>d>0&&(Mt.includes(t[d-1])||/^--(data|json)[\w-]*=/.test(p)||/^-d./.test(p))).join(" "),c=t.find(p=>zo(p)&&Fo.test(p)),u=c!==void 0?Oc(c,n,l):null;return c!==void 0&&u!==null?[m("claude.agent.controls",`changes your Anvil workspace's modes through its API (${n} ${u})`,{target:c,host:i?de(i):null,is_local:!1})]:(a.length>0?a.slice(0,64):[i]).flatMap(p=>Ug(p,n,t))}function Ug(e,t,n){let s=e?de(e):null;if(e&&/\/(batches|fine_tuning|fine-tunes|fine_tunes|predictions|training_jobs|jobs\/(create|submit))\b/.test(e))return[m("claude.bash.spend",`starts a paid job (${t} ${s??"an API"})`,{target:e,host:s,is_local:!1})];let r=t!=="DELETE"?null:s??/^\$\{?(\w+)/.exec(k(n.find((l,c)=>c>0&&!l.startsWith("-")&&S(l)&&!Js.has(n[c-1])&&!/^(--(http-user|http-password|user|password|header|output-document|output-file)|-[oOU])$/.test(n[c-1]))??""))?.[1]??null,o=e?k(e).replace(/^[a-z]+:\/\/[^/?#]*/i,""):"",a=/\.(execute-api\.[\w-]+|elb(\.[\w-]+)?)\.amazonaws\.com$/i.test(r??"")||/^\/rest\/v1\/[^?]*\?[^#]*=/.test(o)||r==="api.github.com"&&jc.test(o.replace(/^\//,"")),i=r!==null&&!a&&!Pc.test(r)&&(gl.test(r)||or(r));return[m("claude.bash.external_write",i?`DELETE to ${s??`a URL in $${r}`} removes what it names (${gl.test(r)?"a provider's API":"a host named for production"})`:`${t} to ${s??"an external host"}`,{target:e,host:s,is_local:!1,service:s,...i?{catastrophic:!0}:{}})]}var jc=/(^|\/)(user\/(starred|following)|notifications|subscriptions?|actions\/caches|reactions)(\/|\?|$)/,Pc=/^(localhost|127\.\d+\.\d+\.\d+|\[?::1\]?|0\.0\.0\.0|host\.docker\.internal)$|\.(local|test|localhost)$/i,qg=/^(-a|--auth|-A|--auth-type|--bearer|-o|--output|--session|--session-read-only|--cert|--cert-key|--verify|--proxy|--timeout|-s|--style|-p|--print|--pretty|--format-options|--default-scheme|--max-redirects)$/,gl=/(^|\.)(api\.github\.com|uploads\.github\.com|gitlab\.com|api\.bitbucket\.org|amazonaws\.com|googleapis\.com|management\.azure\.com|graph\.microsoft\.com|core\.windows\.net|api\.cloudflare\.com|api\.vercel\.com|api\.netlify\.com|api\.heroku\.com|api\.fly\.io|api\.machines\.dev|api\.render\.com|backboard\.railway\.(app|com)|supabase\.(co|com)|api\.planetscale\.com|neon\.tech|api\.digitalocean\.com|api\.linode\.com|api\.hetzner\.cloud|api\.vultr\.com|api\.scaleway\.com|upstash\.(com|io)|turso\.(tech|io)|cloud\.mongodb\.com|hub\.docker\.com)$/i;function Wc(e){let t=[];for(let n=1;n<e.length;n++){let s=e[n];Mt.includes(s)&&e[n+1]!==void 0?t.push(e[n+1]):Mt.some(r=>r.startsWith("--")&&s.startsWith(`${r}=`))&&t.push(s.slice(s.indexOf("=")+1))}return t}var ml=new Set(["query","variables","operationName","extensions"]),Hg=new Set(["jsonrpc","method","params","id"]),Bg=/(^|[/._])(list|get|read|search|query|describe|status|ping|initialize|lookup|find)/i,yl=(e,t)=>typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.keys(e).every(n=>t.has(n));function Vg(e){let t;try{t=JSON.parse(e)}catch{let s=e.split("&").map(o=>o.split("=")[0]??""),r="";try{r=decodeURIComponent((/^query=([^&]*)/.exec(e)?.[1]??"").replace(/\+/g," "))}catch{return!1}return s.every(o=>ml.has(o))&&/^\s*(query\b|\{)/.test(r)}let n=Array.isArray(t)?t:[t];return n.length>0&&n.every(s=>{if(yl(s,Hg)&&typeof s.method=="string"){if(s.method==="tools/call"){let r=s.params,o=typeof r=="object"&&r!==null?r.name:void 0;return typeof o=="string"&&zs(o)==="read"}return Bg.test(s.method)}return yl(s,ml)&&typeof s.query=="string"&&/^\s*(query\b|\{)/.test(s.query)})}function Zg(e){let t=Wc(e);if(t.length===0)return!1;let n=t.join(" ");return/\bmutation\b/i.test(n)||/\bsubscription\b/i.test(n)||Mo.test(n)?!1:t.every(Vg)}var Mo=/\b(drop\s+(table|database|schema|index|view)|truncate\s|delete\s+from|insert\s+into|update\s+[\w."]+\s+set|alter\s+table|create\s+(table|index|database)|grant\s|revoke\s)/i,Gg=new Set(["query","queries","search","autocomplete","suggest","suggestions","lookup","find","list","get","fetch","load","read","info","describe","count","explain","preview"]);function Kg(e,t){if(e.length===0)return!1;let n=Wc(t).join(" ");return Mo.test(n)||/\bmutation\b/i.test(n)?!1:e.every(s=>{if(S(s))return!1;let o=s.replace(/^[a-z]+:\/\/[^/]*/i,"").replace(/[?#].*$/,"").split("/").filter(Boolean),a=o.flatMap(l=>l.replace(/([a-z0-9])([A-Z])/g,"$1_$2").toLowerCase().split(/[^a-z0-9]+/).filter(Boolean));if(a.some(l=>wt.has(l)||vt.has(l)||["redeem","subscribe","unsubscribe","enroll","register","signup","checkout","notify","verify","generate","run"].includes(l)))return!1;let i=(o[o.length-1]??"").toLowerCase();return a.some(l=>Gg.has(l))||/(query|search|lookup|autocomplete)$/.test(i)})}function un(e){return/^https?:\/\//i.test(e)||/^(localhost|127\.|\[::1\]|<host>|[\w-]+(\.[\w-]+)+)(:\d+)?(\/|$)/i.test(e)}function Re(e){if(/^(\[?::1\]?|0\.0\.0\.0)$/.test(e))return!0;let t=/^[a-z]+:\/\//i.test(e)?e:`http://${e}`;return fi(t)}function de(e){return/^(?:[a-z][a-z0-9+.-]*:\/\/)?(?:[^@/]*@)?(\[[^\]]+\]|[^/:?#]+)/i.exec(e)?.[1]?.toLowerCase()??null}function Yg(e,t){let n=e.argv.slice(1);switch(e.name){case"pkill":case"killall":{if(n.includes("-0")||n.includes("-l")||n.length===0)return[];let s=new Set(["-u","-U","--euid","--uid","-g","-G","-t","-s","-P","--signal","-F"]),r=[];for(let f=0;f<n.length;f++)s.has(n[f])?f++:n[f].startsWith("-")||r.push(n[f]);let o=n.some(f=>["-u","-U","--euid","--uid"].includes(f));if(e.name==="pkill"&&n.some(f=>/^-[a-zA-Z]*v[a-zA-Z]*$/.test(f)||f.length>=4&&"--inverse".startsWith(f)))return[m("claude.bash.process.kill_by_name","pkill -v kills every process that does not match",{target:n.join(" "),service:"proc.all",is_local:!0})];if(o&&r.length===0)return[m("claude.bash.process.kill_by_name",`${e.name} -u kills every process the user owns`,{target:n.join(" "),service:"proc.all",is_local:!0})];let a=e.name==="pkill"&&n.some(f=>/^-[a-zA-Z]*f[a-zA-Z]*$/.test(f)||f==="--full");if(!o&&r.length>0&&r.every(f=>Uo(f,t,a)))return[];let i=n.some(f=>/^-[a-zA-Z]*i[a-zA-Z]*$/.test(f)||f==="--ignore-case"),l=e.name==="killall"&&n.some(f=>f==="-r"||f==="--regexp"||f==="-m"),c=o||$t(e)?null:sc(r,{full:a,exact:e.name==="killall"&&!l||n.some(f=>/^-[a-zA-Z]*x[a-zA-Z]*$/.test(f)||f==="--exact"),fold:i},t);if(c==="own")return[];let u=e.name==="pkill"&&r.length===0&&n.some(f=>f==="-P"||f==="--parent"||f.startsWith("--parent=")||/^-P./.test(f));return e.name==="pkill"&&!o&&!$t(e)&&Nc(n,e,t)?[]:u?[m("claude.bash.process.kill_by_name","pkill -P stops every process the named process started",{target:n.join(" "),is_local:!0})]:[m("claude.bash.process.kill_by_name",`${e.name} kills every process matching a name, other sessions' too`,{target:r.join(" "),is_local:!0,housekeeping:c==="some"})]}case"fuser":return n.some(s=>/^-[a-zA-Z]*k/.test(s))?[m("claude.bash.process.kill_by_name","fuser -k kills everything using the port or file, clients too",{target:n.filter(s=>!s.startsWith("-")).join(" "),is_local:!0})]:[];case"colima":return["stop","delete","restart","kill"].includes(n[0]??"")?[m("claude.bash.process.kill_by_name",`colima ${n[0]} stops the Docker VM other sessions share`,{target:"colima",is_local:!0})]:[];case"launchctl":return["stop","unload","bootout","kill","remove","disable"].includes(n[0]??"")||n[0]==="kickstart"&&n.includes("-k")?[m("claude.bash.process.kill_by_name",`launchctl ${n[0]} stops a system service`,{target:n.slice(1).join(" "),is_local:!0})]:[];case"tmux":return["kill-server","kill-session"].includes(n[0]??"")?[m("claude.bash.process.kill_by_name",`tmux ${n[0]} ends sessions it may not own`,{target:n.slice(1).join(" "),is_local:!0})]:[];case"systemctl":return["stop","restart","kill","disable","mask","poweroff","reboot","halt"].includes(n[0]??"")?[m("claude.bash.process.kill_by_name",`systemctl ${n[0]} stops a service`,{target:n.slice(1).join(" "),is_local:e.remote===null,host:e.remote})]:[];case"shutdown":case"reboot":case"halt":return[m("claude.bash.process.kill_by_name",`${e.name} stops the machine`,{target:e.name,service:"proc.all",is_local:e.remote===null,host:e.remote})];case"osascript":{let s=n.join(" ");return/\b(shut\s*down|restart|log\s*out)\b/i.test(s)&&/\b(System Events|Finder|loginwindow)\b/i.test(s)?[m("claude.bash.process.kill_by_name","osascript shuts down, restarts or logs out the machine",{target:s.slice(0,80),service:"proc.all",is_local:!0})]:/\bquit\b/i.test(s)?[m("claude.bash.process.kill_by_name","osascript quits an application",{target:s.slice(0,80),is_local:!0})]:[]}case"kill":return Jg(e,t);default:return[]}}function Jg(e,t){let n=e.argv.slice(1),s=0,r=!1;for(;s<n.length&&n[s].startsWith("-")&&!/^-\d+$/.test(n[s])||s<n.length&&/^-(\d+|[A-Z]+|s|n)$/.test(n[s])&&!(n[s]==="-1"&&s===n.length-1);){let l=n[s];(l==="-0"&&s===0||l==="-l"||l==="-L")&&(r=!0),(l==="-s"||l==="-n")&&s++,s++}if(r)return[];let o=n.slice(s),a=nm(e,t);if(e.via==="xargs"&&e.pipeFrom)return a?[]:om(e.pipeFrom,t);if(e.via==="xargs"&&e.stdinFile)return a?[]:Xs(e.stdinFile,e,t);let i=[];for(let l of n.slice(0,s).filter((c,u)=>(u>0||o.length===0)&&c!=="-1"&&(/^-\d+$/.test(c)?u>0&&n[u-1]!=="-s"&&n[u-1]!=="-n":c.startsWith("-")&&S(c))))a||i.push(m("claude.bash.process.kill_by_name",`kills the whole process group ${k(l).slice(1)}`,{target:k(l),is_local:!0}));for(let l of o)if(l==="-1")i.push(m("claude.bash.process.kill_by_name",e.wrappers.some(c=>["sudo","doas","pkexec","run0"].includes(c))?"kill -1 as root kills every process on the machine":"kill -1 kills every process you own",{target:"-1",service:"proc.all",is_local:!0}));else{if(a)continue;if(/^-\d+$/.test(l))i.push(m("claude.bash.process.kill_by_name",`kills the whole process group ${l.slice(1)}`,{target:l,is_local:!0}));else{if(/^\d+$/.test(l)&&(t.ctx.session?.ownPids?.includes(l)||!$t(e)&&nc(l,t)))continue;if(/^\d+$/.test(l))i.push(m("claude.bash.process.kill_by_name",`kills a hard-coded PID (${l}) this command did not start`,{target:l,is_local:!0}));else if(S(l)){let c=k(l);if(rm(c,t)||!$t(e)&&Qg(c,e,t))continue;if(/\b(pgrep|pidof)\b|\bps\b/.test(c))i.push(m("claude.bash.process.kill_by_name","kills processes found by name",{target:c,is_local:!0}));else if(/\blsof\b/.test(c)&&!/-sTCP:LISTEN/.test(c)){let u=/^\$\(\s*lsof\s+([^()$`|;&]*?)\s*\)$/.exec(c.trim()),f=u&&!$t(e)?rc(u[1].split(/\s+/),t):null;f!=="own"&&i.push(m("claude.bash.process.kill_by_name","kills by port without checking LISTEN, so clients die too",{target:c,is_local:!0,housekeeping:f==="some"}))}else if(/\bdocker\s+ps\b/.test(c))i.push(m("claude.bash.process.kill_by_name","kills every running container",{target:c,is_local:!0}));else{let u=Lc(l,e,t);u&&i.push(...Xs(u,e,t))}}}}return i}function Xg(e,t,n){if(/\$\{(#|!|\w+[^\w}])/.test(t.text))return!1;let s=k(e).trim();if(/^\d+$/.test(s))return Number(s)>1&&(n.ctx.session?.ownPids?.includes(s)===!0||nc(s,n));let r=/^(\$\(\s*(cat\s+|<\s*)|`\s*cat\s+)["']?[^\s;&|<>()`$"'\\]+["']?\s*[)`]$/.test(s)?Lc(e,t,n):null;return r!==null&&!S(r)&&Xs(r,t,n).length===0}function Nc(e,t,n){let s=[];return e.forEach((r,o)=>{let a=r==="-P"||r==="--parent"?e[o+1]??"":r.startsWith("--parent=")?r.slice(9):/^-P./.test(r)?r.slice(2):null;a!==null&&s.push(...S(a)?[a]:a.split(","))}),s.length>0&&s.length<=8&&!e.some(r=>/^-[a-zA-Z]*v[a-zA-Z]*$/.test(r)||r.length>=4&&"--inverse".startsWith(r))&&s.every(r=>Xg(r,t,n))}function Qg(e,t,n){let s=/^\$\(\s*pgrep\s+([^;&|\n`]*?)\s*\)$/.exec(e.trim());if(!s)return!1;let r=`pgrep ${s[1]}`,o=(n.lineCommands??[]).filter(i=>i.name==="pgrep"&&i.via==="substitution"&&i.text.trim()===r),a=o.length>0?o:Jn(r,t.cwd,n).commands.filter(i=>i.name==="pgrep").slice(0,1);return a.length>0&&a.every(i=>i.pipeTo===null&&Nc(i.argv.slice(1),t,n))}function Xs(e,t,n){return S(e)?[]:He(e,t,n).kind==="disposable"?[]:[m("claude.bash.process.kill_by_name",`kills the process in ${k(e)}, which this session did not start`,{target:k(e),is_local:!0})]}function Lc(e,t,n){let s=k(e).trim(),r=/^\$\(([\s\S]*)\)$/.exec(s)??/^`([\s\S]*)`$/.exec(s);if(!r)return null;let o=Jn(r[1],t.cwd,n);for(let a of o.commands){let l=(["cat","head","tail","sort","uniq"].includes(a.name)?a.argv.slice(1).find(c=>!c.startsWith("-")&&!/^\d+$/.test(c)):["sed","awk","jq","grep","cut","tr"].includes(a.name)?qt(a)[0]:void 0)??a.stdinFile??void 0;if(l)return l}return null}var em=/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\/scratchpad\b/i,tm=/(^|[\s;&|({])(function\s+[\w-]+|[\w-]+\s*\(\)\s*\{|alias\s|unalias\s|hash\s|enable\s)/;function nm(e,t){if(e.guards.length===0||tm.test(t.lineText))return!1;let n=String.raw`(lsof\b[^;|)]*\s-p\b|ps\b[^;|)]*\s-p\b|pwdx\b|(cat|readlink|ls)\b[^;|)]*\/proc\/)`,s=r=>new RegExp(`^${n}`).test(r)||new RegExp(String.raw`^(\[\[?|test)\s[^;|]*\$\(\s*${n}`).test(r);return e.guards.some(r=>{let o=/^case ([\s\S]*) in [\s\S]*$/.exec(r)?.[1];if(!s(o===void 0?r:k(o).replace(/^["']?\$\(\s*/,""))||/\bgrep\b[^;|]*\s-[a-zA-Z]*v|\[\[?\s*-z\b|\btest\s+-z\b|-eq\s*0\b|-lt\s*1\b|==?\s*0\b|(^|\s)!\s/.test(r))return!1;let a=/^case ([\s\S]*) in ([\s\S]*)$/.exec(r);return a?a[2].split("|").every(i=>bo(i,t)):bo(r,t)&&!/\\\||\s-e\s.*\s-e\s/.test(r)})}function Uo(e,t,n){let r=e.replace(/^["']|["']$/g,"").split(/(?<!\\)\|/);return r.length>8||r.some(o=>o.trim()==="")?!1:r.every(o=>sm(o,t)||va(o,Ql(t),n,ec(t)))}function sm(e,t){let n=e.replace(/^["']|["']$/g,"");if(/(^|[^\\])\|/.test(n))return!1;let s=/^[^|()?*+[\]{}\\^$]*/.exec(n.replace(/\\\./g,"."))[0];return bo(s,t)&&/\/scratchpad\//.test(`${s}/`)&&/\/scratchpad\b/.test(s)}function bo(e,t){let n=e.toLowerCase(),s=t.sessionId?.toLowerCase()??null;return s?n.includes(s)||/^[0-9a-f]{8}/.test(s)&&new RegExp(`(^|[^0-9a-f])${s.slice(0,8)}([^0-9a-f]|$)`).test(n):em.test(n)}function rm(e,t){let n=/^\$\(\s*pgrep\s+((?:-[a-zA-Z]+\s+)*)("[^"]*"|'[^']*'|\S+)\s*\)$/.exec(e.trim());if(!n||/[uUgGPtv]/.test(n[1]??""))return!1;let s=/f/.test(n[1]??"");return Uo(n[2],t,s)||rh([n[2]],{full:s,exact:/x/.test(n[1]??""),fold:/i/.test(n[1]??"")},t)}function om(e,t){let n=[];for(let i=e;i&&n.length<8;i=i.pipeFrom)n.push(i);if(n.length===1&&e.name==="pgrep"){let i=e.argv.slice(1).filter(c=>c.startsWith("-")),l=e.argv.slice(1).filter(c=>!c.startsWith("-"));if(l.length===1&&!i.some(c=>/[uUgGPtv]/.test(c)||c==="--inverse")&&Uo(l[0],t,i.some(c=>c.includes("f"))))return[]}let s=n.map(i=>i.name),r=n.find(i=>i.name==="lsof");if(r){if(r.argv.some(l=>l==="-sTCP:LISTEN"||l.includes("TCP:LISTEN")))return[];let i=n.length===1&&!$t(r)&&!$t(e)?rc(r.argv.slice(1),t):null;return i==="own"?[]:[m("claude.bash.process.kill_by_name","kills by port without checking LISTEN, so clients die too",{target:r.argv.slice(1).join(" "),is_local:!0,housekeeping:i==="some"})]}if(s.some(i=>i==="pgrep"||i==="pidof"||i==="ps"))return[m("claude.bash.process.kill_by_name","kills processes found by name",{target:n.map(i=>i.name).reverse().join(" | "),is_local:!0})];if(s.includes("docker"))return[m("claude.bash.process.kill_by_name","kills containers listed by docker",{target:"docker ps",is_local:!0})];let o=n[n.length-1],a=["cat","head","tail","sort","uniq","tr","cut"].includes(o.name)?o.argv.slice(1).find(i=>!i.startsWith("-")&&!/^\d+$/.test(i))??o.stdinFile:["awk","sed","jq","grep"].includes(o.name)?qt(o)[0]??o.stdinFile:null;return a?Xs(a,o,t):(o.name==="echo"||o.name==="printf")&&o.argv.slice(1).some(i=>/^\d+$/.test(i))?[m("claude.bash.process.kill_by_name","kills a hard-coded PID this command did not start",{target:o.argv.slice(1).join(" "),is_local:!0})]:[]}var im=oe({aws:new Set(["--profile","--region","--output","--endpoint-url","--query","--color","--ca-bundle","--cli-read-timeout","--cli-connect-timeout"]),kubectl:new Set(["--context","--namespace","-n","--kubeconfig","--cluster","--user","-s","--server","--token","--as","--as-group","--request-timeout","-l","--selector","-o","--output","-f","--filename","-v"]),helm:new Set(["--kube-context","--namespace","-n","--kubeconfig","--repo","--version","-f","--values","--set","-o","--output"]),fly:new Set(["-a","--app","-c","--config","-r","--region","-o","--org"]),flyctl:new Set(["-a","--app","-c","--config","-r","--region","-o","--org"]),railway:new Set(["-s","--service","-e","--environment","-p","--project"]),ngrok:new Set(["--config","--authtoken","--log","--log-format","--log-level","--region","--api-key","--url","--domain"]),cloudflared:new Set(["--config","--loglevel","--logfile","--metrics","--origincert","--credentials-file","--protocol","--edge-ip-version","--region","--hostname","--url"]),sui:new Set(["--client.env","--client.config","--gas-budget","--gas","--gas-price"]),bq:new Set(["--location","--project_id","--dataset_id","--format","--api","--job_id","--destination_table","--parameter","--label","--maximum_bytes_billed","-n","--max_rows"]),eas:new Set(["--branch","--channel","--message","-m","--platform","-p","--profile","-e","--id","--group","--runtime-version","--percent"]),hardhat:new Set(["--network","--config"]),truffle:new Set(["--network","--config"]),brownie:new Set(["--network"]),solana:new Set(["--url","-u","--keypair","-k","--fee-payer","--commitment","--with-compute-unit-price","--program-id","--upgrade-authority","--buffer"]),"spl-token":new Set(["--url","-u","--fee-payer","--owner","--program-id"]),cast:new Set(["--rpc-url","-r","--private-key","--from","-f","--value","--gas-limit","--gas-price","--chain","--keystore","--account","--nonce"]),forge:new Set(["--rpc-url","-r","--fork-url","-f","--private-key","--sender","--chain","--etherscan-api-key","--verifier","--sig","-s","--account","--keystore","--constructor-args"]),fastlane:new Set(["--env"]),claude:new Set(["--transport","-t","--scope","-s","-e","--env","-H","--header","--model","--permission-mode","--allowedTools","--allowed-tools","--disallowedTools","--disallowed-tools","--output-format","--append-system-prompt","--add-dir","--mcp-config","--settings","--resume","-r"]),vercel:new Set(["--token","-t","--scope","-S","--cwd","-A","--local-config","--team","-T","--target","-e","--env","-b","--build-env","-m","--meta","--regions","--archive"]),gcloud:new Set(["--project","--account","--configuration","--zone","--region","--format","--impersonate-service-account"]),az:new Set(["--subscription","--output","-o","--query"]),doctl:new Set(["--context","-t","--access-token","-o","--output"]),heroku:new Set(["-a","--app","-r","--remote"]),wrangler:new Set(["-c","--config","-e","--env"]),supabase:new Set(["--project-ref","--workdir","--profile"]),modal:new Set(["-e","--env"]),docker:new Set(["-H","--host","--context","-c","--config","--log-level"]),terraform:new Set([]),pulumi:new Set(["-s","--stack","-C","--cwd"]),stripe:new Set(["--api-key","--project-name","-p"])}),v=e=>{let t=im[ue(e[0]??"")]??new Set,n=[];for(let s=1;s<e.length;s++){let r=e[s];if(r.startsWith("-")){t.has(r)&&s++;continue}n.push(r)}return n},re=(...e)=>t=>e.every((n,s)=>v(t)[s]===n),T=(e,...t)=>e.some(n=>t.includes(n)||t.some(s=>n.startsWith(`${s}=`))),am=new Set(["--dry-run","--force","--yes","-y","--atomic","--wait","--wait-for-jobs","--all","--debug","--verbose","-v","--quiet","-q","--json","--allow-dirty","--no-verify","--locked","--frozen","--offline","--install","--create-namespace","--reuse-values","--reset-values","--cleanup-on-fail","--recursive","-R","--prune","--server-side","--keep-history","--no-hooks","--skip-crds","--devel","--dependency-update","--provenance","--ignore-scripts","--workspaces","--include-workspace-root","--linked","--local","--include-all","--include-roles","--include-seed"]);function Dt(e,t,n=["true"]){let s=i=>i.replace(/^--/,"").replace(/[A-Z]/g,l=>`-${l.toLowerCase()}`).replace(/_/g,"-"),r=t.map(s),o=i=>r.some(l=>l===i||l.replace(/-/g,"")===i.replace(/-/g,"")||i.length>=2&&l.startsWith(i)),a=null;for(let i=0;i<e.length;i++){let l=e[i];if(l==="--")break;if(!l.startsWith("--"))continue;let[c,...u]=l.slice(2).split("="),f=c.startsWith("no-")||/^no[A-Z]/.test(c),p=s(f?c.replace(/^no-?/,"").replace(/^./,y=>y.toLowerCase()):c);if(!o(p))continue;let d=t.includes(`--${c}`),h=e[i-1]??"",g=/^--?[a-zA-Z][\w-]*$/.test(h)&&!am.has(h);f?a="false":u.length?a=d?u.join("="):u.join("=")==="true"?null:"false":!d||g?a=a??null:a=e[i+1]==="false"?"false":"true"}return a!==null&&n.includes(a)}var Ae=e=>!Dt(e,["--dry-run","--dryrun","--plan","--preview"]),Tc=oe({railway:[{match:e=>["up","redeploy","deploy","down"].includes(v(e)[0]??""),action:"claude.bash.deploy",why:"railway deploys or removes a service"},{match:e=>["variables","variable","vars"].includes(v(e)[0]??"")&&(T(e,"--set")||["set","delete","remove"].includes(v(e)[1]??"")),action:"claude.bash.deploy",why:"railway changes production variables"},{match:e=>v(e)[0]==="domain",action:"claude.bash.deploy",why:"railway domain can create a public domain for a live service"},{match:e=>["service","environment","volume","project"].includes(v(e)[0]??"")&&["delete","remove","rm"].includes(v(e)[1]??""),action:"claude.bash.deploy",why:"railway deletes infrastructure"},{match:e=>v(e)[0]==="add",action:"claude.bash.deploy",why:"railway add creates a service"}],vercel:[{match:e=>["remove","rm"].includes(v(e)[0]??""),action:"claude.bash.deploy",why:"vercel removes a deployment"},{match:e=>v(e)[0]==="rollback",action:"claude.bash.deploy",why:"vercel rolls production back to an earlier deployment"},{match:e=>T(e,"--prod","--production")||v(e)[0]==="promote",action:"claude.bash.deploy",why:"vercel deploys to production"},{match:e=>v(e)[0]==="env"&&["add","rm","remove"].includes(v(e)[1]??"")||v(e)[0]==="alias"&&v(e)[1]==="set"||v(e)[0]==="domains"&&["add","rm","remove"].includes(v(e)[1]??""),action:"claude.bash.deploy",why:"vercel changes production settings"},{match:e=>P(e,"--target")!==null&&(v(e).length===0||v(e)[0]==="deploy"||/^[./~]/.test(v(e)[0])),action:"claude.bash.deploy",why:"vercel deploys to the environment --target names"}],wrangler:[{match:e=>["deploy","publish"].includes(v(e)[0]??"")&&!Dt(e,["--dry-run"])||v(e)[0]==="rollback"||re("pages","deploy")(e)||re("versions","deploy")(e)||v(e)[0]==="secret"&&["put","delete"].includes(v(e)[1]??""),action:"claude.bash.deploy",why:"wrangler deploys to Cloudflare"}],fly:[{match:e=>re("ssh","console")(e)&&/\b(printenv|env|set|export\s+-p|cat\s+\S*\.env)\b/.test(P(e,"-C","--command")??""),action:"claude.bash.secrets.print",why:"fly ssh console prints a live app's environment"},{match:e=>["deploy","scale","destroy"].includes(v(e)[0]??"")||["secrets","apps","machine","machines","volumes","postgres"].includes(v(e)[0]??"")&&["set","unset","destroy","delete","remove","stop","create"].includes(v(e)[1]??""),action:"claude.bash.deploy",why:"fly changes a live app"}],netlify:[{match:e=>v(e)[0]==="deploy"&&T(e,"--prod"),action:"claude.bash.deploy",why:"netlify deploys to production"}],firebase:[{match:e=>v(e)[0]==="deploy"||/^hosting:channel:deploy/.test(v(e)[0]??""),action:"claude.bash.deploy",why:"firebase deploys"},{match:e=>/^functions:delete/.test(v(e)[0]??""),action:"claude.bash.deploy",why:"firebase deletes live functions"},{match:e=>/^hosting:disable/.test(v(e)[0]??""),action:"claude.bash.deploy",why:"firebase takes the hosting site offline"},{match:e=>v(e)[0]==="appdistribution:distribute",action:"claude.bash.deploy",why:"firebase sends a build to testers"}],fastlane:[{match:kb,action:"claude.bash.deploy",why:"fastlane uploads or releases an app"}],eas:[{match:vb,action:"claude.bash.deploy",why:"eas sends an app or an over-the-air update to users"}],expo:[{match:e=>v(e)[0]==="publish",action:"claude.bash.deploy",why:"expo publish sends an over-the-air update to users"}],xcrun:[{match:e=>v(e)[0]==="altool"&&T(e,"--upload-app","--upload-package")||v(e)[0]==="iTMSTransporter"&&P(e,"-m")==="upload",action:"claude.bash.deploy",why:"uploads an app to App Store Connect"}],altool:[{match:e=>T(e,"--upload-app","--upload-package"),action:"claude.bash.deploy",why:"altool uploads an app to App Store Connect"}],appcenter:[{match:e=>v(e)[0]==="codepush"&&/^(release|release-react|release-cordova|release-electron|promote|patch|rollback)$/.test(v(e)[1]??"")&&oo(e)||re("distribute","release")(e),action:"claude.bash.deploy",why:"appcenter releases an app update to users"}],"code-push":[{match:e=>/^(release|release-react|release-cordova|release-electron|promote|patch|rollback)$/.test(v(e)[0]??"")&&oo(e),action:"claude.bash.deploy",why:"code-push releases an app update to users"}],"code-push-standalone":[{match:e=>/^(release|release-react|release-cordova|release-electron|promote|patch|rollback)$/.test(v(e)[0]??"")&&oo(e),action:"claude.bash.deploy",why:"code-push releases an app update to users"}],shorebird:[{match:e=>v(e)[0]==="patch"&&!/^(staging)$/i.test(P(e,"--track")??"")||re("patches","promote")(e),action:"claude.bash.deploy",why:"shorebird sends a patch to the app's users"}],capgo:[{match:e=>re("bundle","upload")(e)&&!bu.test(P(e,"--channel","-c")??""),action:"claude.bash.deploy",why:"capgo sends an over-the-air update to users"}],butler:[{match:e=>v(e)[0]==="push"&&Ae(e),action:"claude.bash.deploy",why:"butler pushes a build to itch.io"}],steamcmd:[{match:e=>e.some(t=>/^\+run_app_build(_http)?$|^\+set_?live/i.test(t)),action:"claude.bash.deploy",why:"steamcmd uploads a build to Steam"}],msstore:[{match:e=>v(e)[0]==="publish",action:"claude.bash.deploy",why:"msstore publishes to the Microsoft Store"}],"web-ext":[{match:e=>v(e)[0]==="sign"&&P(e,"--channel")==="listed",action:"claude.bash.deploy",why:"web-ext submits a listed add-on to addons.mozilla.org"}],"chrome-webstore-upload":[{match:e=>!["help"].includes(v(e)[0]??""),action:"claude.bash.deploy",why:"uploads an extension to the Chrome Web Store"}],gradlew:[{match:Dl,action:"claude.bash.deploy",why:"gradle publishes an app to Google Play"},{match:Fl,action:"claude.bash.publish",why:"gradle publishes artifacts to a package repository"}],gradle:[{match:Dl,action:"claude.bash.deploy",why:"gradle publishes an app to Google Play"},{match:Fl,action:"claude.bash.publish",why:"gradle publishes artifacts to a package repository"}],heroku:[{match:e=>/^apps:destroy$/.test(v(e)[0]??""),action:"claude.bash.deploy",why:"heroku deletes the app"},{match:e=>/^(config:set|config:unset|releases:rollback|ps:scale|ps:restart|ps:stop|maintenance:on|run)$/.test(v(e)[0]??""),action:"claude.bash.deploy",why:"heroku changes a live app"},{match:e=>/^pg:reset$/.test(v(e)[0]??""),action:"claude.bash.db.destructive",why:"heroku pg:reset wipes the database"}],kubectl:[{match:e=>v(e)[0]==="delete"&&!Dt(e,["--dry-run"],["true","client","server"]),action:"claude.bash.deploy",why:"kubectl deletes from a cluster"},{match:e=>(["apply","create","delete","replace","patch","scale","set","edit","label","annotate","drain","cordon","uncordon","taint","expose","autoscale"].includes(v(e)[0]??"")||v(e)[0]==="run"&&!Rc(e)||v(e)[0]==="rollout"&&["restart","undo","pause","resume"].includes(v(e)[1]??""))&&!Dt(e,["--dry-run"],["true","client","server"]),action:"claude.bash.deploy",why:"kubectl changes a cluster"}],helm:[{match:e=>["uninstall","delete"].includes(v(e)[0]??"")&&!Dt(e,["--dry-run"],["true","client","server"]),action:"claude.bash.deploy",why:"helm removes a release from a cluster"},{match:e=>["install","upgrade","rollback"].includes(v(e)[0]??"")&&!Dt(e,["--dry-run"],["true","client","server"]),action:"claude.bash.deploy",why:"helm changes a cluster"}],terraform:[{match:e=>v(e)[0]==="import"||v(e)[0]==="state"&&["rm","mv","push","replace-provider"].includes(v(e)[1]??"")||["taint","untaint","force-unlock"].includes(v(e)[0]??""),action:"claude.bash.deploy",why:"terraform changes the shared state that every later apply works from"},{match:e=>v(e)[0]==="destroy"||v(e)[0]==="apply"&&T(e,"-destroy","--destroy"),action:"claude.bash.deploy",why:"terraform destroy deletes real infrastructure"},{match:e=>v(e)[0]==="apply",action:"claude.bash.deploy",why:"terraform changes real infrastructure"}],tofu:[{match:e=>v(e)[0]==="destroy"||v(e)[0]==="apply"&&T(e,"-destroy","--destroy"),action:"claude.bash.deploy",why:"tofu destroy deletes real infrastructure"},{match:e=>["apply","import","taint"].includes(v(e)[0]??""),action:"claude.bash.deploy",why:"tofu changes real infrastructure"}],pulumi:[{match:e=>v(e)[0]==="destroy",action:"claude.bash.deploy",why:"pulumi destroy deletes real infrastructure"},{match:e=>["up","update","cancel"].includes(v(e)[0]??""),action:"claude.bash.deploy",why:"pulumi changes real infrastructure"}],cdk:[{match:e=>v(e)[0]==="destroy",action:"claude.bash.deploy",why:"cdk destroy deletes real infrastructure"},{match:e=>v(e)[0]==="deploy",action:"claude.bash.deploy",why:"cdk changes real infrastructure"}],serverless:[{match:e=>v(e)[0]==="remove",action:"claude.bash.deploy",why:"serverless remove deletes the deployed service"},{match:e=>v(e)[0]==="deploy",action:"claude.bash.deploy",why:"serverless deploys"}],sls:[{match:e=>v(e)[0]==="remove",action:"claude.bash.deploy",why:"serverless remove deletes the deployed service"},{match:e=>v(e)[0]==="deploy",action:"claude.bash.deploy",why:"serverless deploys"}],modal:[{match:e=>v(e)[0]==="deploy"||["app","secret"].includes(v(e)[0]??"")&&["stop","create","delete"].includes(v(e)[1]??""),action:"claude.bash.deploy",why:"modal deploys or changes a live app"},{match:e=>["run","shell","launch"].includes(v(e)[0]??""),action:"claude.bash.spend",why:"modal starts a paid cloud run"},{match:e=>v(e)[0]==="volume"&&["rm","delete"].includes(v(e)[1]??""),action:"claude.bash.db.destructive",why:"modal deletes stored data"}],supabase:[{match:e=>re("db","push")(e)&&!T(e,"--local")&&!Ic(e)&&!Dt(e,["--dry-run"])||re("functions","deploy")(e)||re("secrets","set")(e)||re("functions","delete")(e),action:"claude.bash.deploy",why:"supabase changes a live project"},{match:e=>re("db","reset")(e)&&T(e,"--linked","--db-url"),action:"claude.bash.db.destructive",why:"supabase db reset wipes a linked database"}],prisma:[{match:e=>re("migrate","reset")(e)||re("db","push")(e)&&T(e,"--accept-data-loss","--force-reset"),action:"claude.bash.db.destructive",why:"prisma wipes or drops database data"},{match:e=>re("migrate","deploy")(e),action:"claude.bash.deploy",why:"prisma migrate deploy changes the target database"}],"drizzle-kit":[{match:e=>v(e)[0]==="push"||v(e)[0]==="drop",action:"claude.bash.db.destructive",why:"drizzle-kit push can drop columns and tables to match the schema"}],docker:[{match:e=>(v(e)[0]==="push"||v(e)[0]==="image"&&v(e)[1]==="push"||v(e)[0]==="buildx"&&T(e,"--push"))&&!Cm(e),action:"claude.bash.publish",why:"docker push publishes an image"},{match:e=>["stop","kill","rm","restart"].includes(v(e)[0]??"")&&e.some(t=>S(t)&&/docker\s+ps\b/.test(k(t))),action:"claude.bash.process.kill_by_name",why:"docker stops every container, other sessions' too"},{match:e=>re("system","prune")(e)&&T(e,"--volumes")||v(e)[0]==="volume"&&(v(e)[1]==="prune"||v(e)[1]==="rm"&&!pm(v(e).slice(2)))||re("compose","down")(e)&&T(e,"-v","--volumes"),action:"claude.bash.fs.delete_recursive",why:"docker deletes volumes, and the data in them"},{match:e=>re("system","prune")(e)&&e.some(t=>/^-\w*f/.test(t)||t==="--force"),action:"claude.bash.fs.delete_recursive",why:"docker system prune deletes stopped containers and unused images"}],cargo:[{match:e=>(v(e)[0]==="publish"||v(e)[0]==="yank")&&Ae(e),action:"claude.bash.publish",why:"cargo publishes a crate"}],podman:[{match:e=>v(e)[0]==="push"||v(e)[0]==="image"&&v(e)[1]==="push"||v(e)[0]==="manifest"&&v(e)[1]==="push",action:"claude.bash.publish",why:"podman push publishes an image"}],buildah:[{match:e=>v(e)[0]==="push",action:"claude.bash.publish",why:"buildah push publishes an image"}],nerdctl:[{match:e=>v(e)[0]==="push",action:"claude.bash.publish",why:"nerdctl push publishes an image"}],glab:[{match:e=>v(e)[0]==="mr"&&v(e)[1]==="merge",action:"claude.bash.git.push_main",why:"glab mr merge merges into the default branch (a deploy)"},{match:e=>v(e)[0]==="release"&&v(e)[1]==="create",action:"claude.bash.publish",why:"glab release create publishes a release"}],twilio:[{match:e=>/:(buy|purchase)(:|$)/.test(v(e)[0]??"")||/^api:core:incoming-phone-numbers:create$/.test(v(e)[0]??""),action:"claude.bash.spend",why:"twilio buys a phone number"},{match:e=>/^api:[\w-]+:(messages|calls|conversations|notifications|verify[\w-]*):create$|^api:[\w-]+:[\w-]+:(messages|calls):create$/.test(v(e)[0]??""),action:"claude.bash.external_write",why:"twilio sends a message or places a call"}],twine:[{match:e=>v(e)[0]==="upload",action:"claude.bash.publish",why:"twine uploads a package"}],gem:[{match:e=>["push","yank"].includes(v(e)[0]??""),action:"claude.bash.publish",why:"gem publishes a package"}],poetry:[{match:e=>v(e)[0]==="publish"&&Ae(e),action:"claude.bash.publish",why:"poetry publishes a package"}],vsce:[{match:e=>["publish","unpublish"].includes(v(e)[0]??""),action:"claude.bash.publish",why:"vsce publishes an extension"}],ovsx:[{match:e=>v(e)[0]==="publish",action:"claude.bash.publish",why:"ovsx publishes an extension"}],changeset:[{match:e=>v(e)[0]==="publish",action:"claude.bash.publish",why:"changeset publishes packages"}],lerna:[{match:e=>v(e)[0]==="publish",action:"claude.bash.publish",why:"lerna publishes packages"}],jsr:[{match:e=>v(e)[0]==="publish"&&Ae(e),action:"claude.bash.publish",why:"jsr publishes a package"}],sky:[{match:e=>["launch","exec","jobs"].includes(v(e)[0]??""),action:"claude.bash.spend",why:"sky starts paid cloud machines"}],gcloud:[{match:e=>/\b(instances|clusters|tpus)\b/.test(v(e).join(" "))&&v(e).includes("create"),action:"claude.bash.spend",why:"gcloud starts paid machines"},{match:e=>v(e).includes("deploy")||v(e).includes("delete")&&!v(e).includes("describe"),action:"claude.bash.deploy",why:"gcloud changes cloud resources"},{match:e=>v(e).some(t=>/^(add|remove|set)-iam-policy(-binding)?$/.test(t)),action:"claude.bash.deploy",why:"gcloud changes who can reach cloud resources"},{match:e=>v(e)[0]==="auth"&&/^print-(access|identity)-token$/.test(v(e)[1]??"")||v(e)[0]==="secrets"&&v(e)[1]==="versions"&&v(e)[2]==="access",action:"claude.bash.secrets.print",why:"gcloud prints a credential"}],az:[{match:e=>re("vm","create")(e),action:"claude.bash.spend",why:"az starts a paid machine"},{match:e=>v(e).some(t=>["delete","deploy","create","update","set"].includes(t))&&!re("account","set")(e),action:"claude.bash.deploy",why:"az changes cloud resources"},{match:e=>re("account","get-access-token")(e),action:"claude.bash.secrets.print",why:"az prints an access token"}],doctl:[{match:e=>v(e).includes("create")||v(e).includes("delete"),action:"claude.bash.deploy",why:"doctl changes cloud resources"}],stripe:[{match:e=>["post","delete"].includes(v(e)[0]??"")||v(e).some(t=>["create","update","delete","cancel","refund","capture","pay","void"].includes(t)),action:"claude.bash.external_write",why:"stripe changes live payment data"}],mail:[{match:()=>!0,action:"claude.bash.external_write",why:"sends an email"}],uv:[{match:e=>v(e)[0]==="publish"&&Ae(e),action:"claude.bash.publish",why:"uv publishes a package"}],mvn:[{match:e=>v(e).some(t=>t==="deploy"||t==="release:perform"||t==="deploy:deploy-file"),action:"claude.bash.publish",why:"mvn deploy uploads artifacts to a package repository"}],mvnw:[{match:e=>v(e).some(t=>t==="deploy"||t==="release:perform"),action:"claude.bash.publish",why:"mvn deploy uploads artifacts to a package repository"}],argocd:[{match:e=>v(e)[0]==="app"&&["sync","rollback","delete","set","patch","terminate-op"].includes(v(e)[1]??"")&&Ae(e),action:"claude.bash.deploy",why:"argocd changes what a cluster runs"}],"ansible-playbook":[{match:e=>!T(e,"--check","-C","--syntax-check","--list-hosts","--list-tasks","--list-tags")&&!/^(?:localhost|127\.0\.0\.1),?$/.test(P(e,"-i","--inventory")??""),action:"claude.bash.deploy",why:"ansible-playbook changes the machines in its inventory"}],pm2:[{match:e=>["restart","reload","stop","delete","kill"].includes(v(e)[0]??"")&&(v(e)[0]==="kill"||v(e)[1]==="all"),action:"claude.bash.process.kill_by_name",why:"pm2 stops or restarts every process it manages"}],sendmail:[{match:()=>!0,action:"claude.bash.external_write",why:"sends an email"}],mailx:[{match:()=>!0,action:"claude.bash.external_write",why:"sends an email"}],mutt:[{match:e=>T(e,"-s","-a","-c","-b","-H","-i")||v(e).some(t=>t.includes("@")),action:"claude.bash.external_write",why:"sends an email"}],msmtp:[{match:e=>!T(e,"--help","--version","--serverinfo","-S","-P","--pretend","--rmqs"),action:"claude.bash.external_write",why:"sends an email"}],swaks:[{match:e=>!T(e,"--help","-h","--version"),action:"claude.bash.external_write",why:"sends an email"}]});function Ic(e){let t=e.findIndex(r=>r==="--db-url"||r==="--database-url"),n=t>=0?e[t+1]:e.find(r=>r.startsWith("--db-url=")||r.startsWith("--database-url="))?.split("=").slice(1).join("=");if(!n||S(n))return!1;let s=de(n);return s!==null&&Re(s)}var lm=new Set(["--exclude","--include","--cache-control","--acl","--content-type","--content-encoding","--content-disposition","--content-language","--expires","--sse","--sse-kms-key-id","--sse-c","--sse-c-key","--storage-class","--metadata","--metadata-directive","--grants","--website-redirect","--profile","--region","--endpoint-url","--expected-size","--source-region","--request-payer","--output","--query","--page-size","--color","--ca-bundle","--cli-read-timeout","--cli-connect-timeout"]);function wo(e){let t=e.findIndex((n,s)=>s>0&&["cp","sync","mv"].includes(n)&&e[s-1]==="s3");return t<0?[]:pe(e,t+1,lm)}var cm=/^(run-instances|request-spot-instances|create-training-job|create-cluster|create-db-instance|create-endpoint|purchase-[\w-]+|create-capacity-reservation)$/,um=/^(delete-|terminate-|remove-|deregister-|revoke-|detach-|put-|update-|create-|deploy|attach-|modify-|stop-|reboot-|start-|replace-|disable-|enable-|change-|authorize-|associate-|disassociate-|set-|add-|apply-|import-|restore-|rotate-|schedule-|cancel-|purge-|batch-delete-|batch-write-|reset-|admin-|initiate-|promote-|failover-|reject-|accept-)/,dm=/^(s3|s3api|s3control|kms|dynamodb|rds|backup|secretsmanager|ssm|ecr|ecr-public|sqs|kinesis|firehose|glacier|efs|fsx|elasticache|memorydb|redshift|redshift-serverless|docdb|neptune|opensearch|es|timestream-write|keyspaces|qldb|lightsail|athena|glue|logs|cloudtrail|codecommit|cognito-idp)$/,fm=/^(get-secret-value|get-session-token|assume-role|get-federation-token|get-parameter|get-parameters)$/;function Hs(e){let t=e.argv,n=e.name,s=[],r=_m(e);if(r.length>0)return r;let o=ym(e);if(o.length>0)return o;if(n==="aws"){let[l="",c=""]=v(t),u=c.split("-").some(f=>["delete","deletion","purge","terminate","drop","destroy","wipe","truncate"].includes(f))||/^(disable-key|schedule-key-deletion|remove-objects?)$/.test(c);if(l==="s3"&&["rm","rb"].includes(c))s.push(m("claude.bash.db.destructive",`aws s3 ${c} deletes stored data`,{target:v(t)[2]??null,is_local:!1}));else if(dm.test(l)&&u&&Ae(t))s.push(m("claude.bash.db.destructive",`aws ${l} ${c} deletes stored data`,{target:`${l} ${c}`,is_local:!1}));else if(l==="configure"&&c==="export-credentials")s.push(...ae(e)?[m("claude.bash.secrets.print","aws configure export-credentials prints AWS credentials",{target:"configure export-credentials",is_local:!0})]:[]);else if(/^authorize-security-group-ingress$|^modify-security-group-rules$/.test(c)&&t.some(f=>/(^|[=\s"'])(0\.0\.0\.0\/0|::\/0)\b/.test(f)))s.push(m("claude.bash.net.expose",`aws ${l} ${c} opens a port to the whole internet`,{target:`${l} ${c}`,is_local:!1}));else if(l==="s3"&&["cp","sync","mv"].includes(c)&&(wo(t).slice(-1)[0]??"").startsWith("s3://")&&wo(t).length>=2)s.push(m("claude.bash.deploy",`aws s3 ${c} writes to a bucket`,{target:v(t).slice(-1)[0]??null,is_local:!1}));else if(l==="configure"&&c==="get"&&/secret|key/i.test(v(t)[2]??""))s.push(...ae(e)?[m("claude.bash.secrets.print","prints an AWS credential",{target:v(t)[2]??null,is_local:!0})]:[]);else if(fm.test(c)&&(c!=="get-parameter"&&c!=="get-parameters"||T(t,"--with-decryption")))s.push(...ae(e)?[m("claude.bash.secrets.print",`aws ${l} ${c} prints a secret`,{target:`${l} ${c}`,is_local:!0})]:[]);else if(l==="athena"&&c==="start-query-execution"){let f=ke(P(t,"--query-string")??""),p=be.exec(f)??Hn.exec(f);p&&s.push(m("claude.bash.db.destructive",`aws athena runs destructive SQL (${p[1].replace(/\s+/g," ").toUpperCase()})`,{target:"athena",host:"athena",is_local:!1}))}else if(["redshift-data","rds-data"].includes(l)&&/execute-statement$/.test(c)){let f=ke([P(t,"--sql")??"",...t.filter((p,d)=>t[d-1]==="--sqls")].join(`
|
|
42
|
-
`));be.test(f)&&s.push(m("claude.bash.db.destructive",`aws ${l} runs destructive SQL (${(be.exec(f)?.[1]??"").replace(/\s+/g," ").toUpperCase()})`,{target:`${l} ${c}`,host:l,is_local:!1}))}else cm.test(c)?s.push(m("claude.bash.spend",`aws ${l} ${c} starts paid resources`,{target:`${l} ${c}`,is_local:!1})):["ses","sesv2","sns","sqs"].includes(l)&&/^(send|publish)/.test(c)?s.push(m("claude.bash.external_write",`aws ${l} ${c} sends a message`,{target:`${l} ${c}`,is_local:!1})):um.test(c)&&Ae(t)&&s.push(m("claude.bash.deploy",`aws ${l} ${c} changes cloud resources`,{target:`${l} ${c}`,is_local:!1}));return s}if(["npm","pnpm","yarn","bun"].includes(n))return qc(e);if(["nx","turbo","mise","lerna","run-s","run-p","npm-run-all"].includes(n))return Am(e);if(["make","just","task","mise"].includes(n)){let l=v(t).find(c=>!c.includes("="));return l&&/^(deploy|release|publish|ship)([-:_].*)?$/.test(l)&&!Mc.test(l)&&Ae(t)&&!T(t,"-n","--just-print","--recon")?[m("claude.bash.deploy",`${n} ${l} runs a deploy or release target`,{target:l,is_local:!1})]:[]}let a=Sm(e);if(a.length>0)return a;let i=xm(e);if(i.length>0)return i;if(n==="python"||n==="python3"){let l=t.indexOf("-m");if(l>0&&t[l+1]==="twine"&&t[l+2]==="upload")return[m("claude.bash.publish","twine uploads a package",{is_local:!1})];if(t.includes("manage.py")&&["flush","reset_db","sqlflush"].some(u=>t.includes(u)))return[m("claude.bash.db.destructive","manage.py wipes the database",{is_local:null})];let c=t.indexOf("migrate");if(t.includes("manage.py")&&c>0){let u=t.slice(c+1).filter(f=>!f.startsWith("-"));if(u[1]==="zero")return[m("claude.bash.db.destructive","manage.py migrate APP zero drops the app's tables",{target:u[0]??null,is_local:null})]}return[]}if(n==="alembic"&&v(t).includes("downgrade")&&!T(t,"--sql")||n==="flask"&&re("db","downgrade")(t)&&!T(t,"--sql"))return[m("claude.bash.db.destructive",`${n} downgrades the database schema (drops what the migrations made)`,{target:v(t).slice(-1)[0]??null,is_local:null})];if(n==="rails"||n==="rake"||n==="bin/rails"){let l=(/(?:^|\s)(?:RAILS_ENV|RACK_ENV)=["']?(\w+)/.exec(e.text)?.[1]??P(t,"-e","--environment")??"").toLowerCase();return/^(test|development|dev)$/.test(l)?[]:t.some(c=>/^db:(drop|reset|schema:load|migrate:reset|purge|truncate_all)$/.test(c))?[m("claude.bash.db.destructive","rails wipes or rebuilds the database",{is_local:null})]:/^prod(uction)?$/.test(l)&&t.some(c=>/^db:(migrate|rollback|seed|setup)(:|$)/.test(c))?[m("claude.bash.deploy","rails changes the production database",{target:t.find(c=>c.startsWith("db:"))??null,is_local:!1})]:[]}for(let l of Tc[n==="flyctl"?"fly":n]??[])if(l.match(t)){if(l.action==="claude.bash.secrets.print"&&!ae(e))continue;s.push(m(l.action,l.why,{target:v(t).slice(0,3).join(" ")||n,is_local:!1,host:n}));break}return n==="railway"&&["variables","variable","vars"].includes(v(t)[0]??"")&&s.length===0&&ae(e)&&s.push(m("claude.bash.secrets.print","railway variables prints live production secrets",{target:"railway variables",is_local:!0,host:"railway"})),n==="heroku"&&/^config(:get)?$/.test(v(t)[0]??"")&&s.length===0&&ae(e)&&s.push(m("claude.bash.secrets.print","heroku config prints live secrets",{target:"heroku config",is_local:!0,host:"heroku"})),s.length===0&&s.push(...mm(e),...gm(e)),s.length===0&&s.push(...vm(e),...$m(e)),s}function pm(e){return e.length>0&&e.every(t=>k(t).replace(/[${}"']/g,"").toLowerCase().split(/[-_.:]+/).some(n=>/^(cache|caches|test|tests|testing|tmp|temp|ci|fixture|fixtures|scratch)$/.test(n)))}var Dc=/^(delete|deletion|destroy|drop|purge|wipe|nuke|truncate|erase|rm|rb|remove|terminate|flush|flushall|flushdb|reset)$/i,hm=e=>e.split(/[-:_.]/).some(t=>Dc.test(t)),bl=/^(buckets?|blobs?|objects?|storage|tables?|datasets?|databases?|dbs?|collections?|documents?|docs|indexe?s|indices|topics?|queues?|streams?|keys?|kms|keyrings?|secrets?|backups?|snapshots?|volumes?|disks?|branch(es)?|firestore|datastore|bigtable|spanner|redis|memcache|memorystore|filestore|keyspaces?|schemas?|kv|keyvalue|file-?systems?|repositor(y|ies)|images?|vaults?|caches?|data|records?|rows?|partitions?|shards?|replicas?|buckets?|containers?)$/i,rr=new Set(["gsutil","bq","pscale","turso","neonctl","neon","upstash","xata","atlas","mongocli","snowsql","kafka-topics","kafka-topics.sh","kafka-configs","cqlsh","clickhouse-client","influx","cockroach","surreal","supabase","firebase","fauna","convex","rclone","restic","b2","mc","s3cmd","azcopy","cbq","couchbase-cli","arangosh","typesense","meilisearch","algolia","pinecone","weaviate","qdrant","chroma","elasticdump","curator","litestream","turso-cli","d1","pgbackrest","barman","wal-g"]),yn=new Set(["gcloud","az","doctl","linode-cli","hcloud","oci","ibmcloud","scw","vultr-cli","exo","aliyun","tccli","cf","render","koyeb","northflank","porter","qovery","okteto","nomad","consul","vault","eksctl","kops","flux","databricks","confluent","ccloud","heroku","fly","flyctl","railway","vercel","netlify","wrangler","glab","dokku","caprover","kamal","coolify","sst","amplify","copilot","crane","oras"]),Fc=new Set(["config","configure","auth","login","logout","components","alias","aliases","profile","profiles","context","contexts","completion","init","cache","plugin","plugins","extension","extensions","help","version"]);function gm(e){let t=e.name,n=rr.has(t);if(!n&&!yn.has(t))return[];let s=e.argv;if(!Ae(s)||T(s,"--what-if","--validate-only","--check","--simulate","--no-execute"))return[];let r=v(s).slice(0,6);if(r.length>0&&Fc.has(r[0]))return[];if(t==="rclone"&&pe(s.map(h=>k(h)),1,fc).slice(1).every(h=>!Te(h)))return[];let o=r.findIndex(hm),a=s.find(h=>/^--?(delete|drop|purge|wipe|truncate|destroy|flush|remove)(=|$)/.test(h));if(o<0&&!a)return[];if(o>0&&r.slice(0,o).some(h=>/^(list|ls|describe|get|show|info|logs?|cat|view|inspect|read|search|query)$/i.test(h)))return[];let i=r.slice(0,6),l=n||i.some(h=>bl.test(h)||h.split(/[-:_.]/).some(g=>bl.test(g))),c=o>=0?r[o]:a.split("=")[0],u=`${t} ${o>=0?r.slice(0,o+1).join(" "):c}`.trim(),f=o>=0?r.slice(o+1).find(h=>!h.includes("="))??null:r[0]??null,p=o>=0&&r[o].split(/[-:_.]/).every(h=>!Dc.test(h)||/^reset$/i.test(h));return!l&&o>=0&&r.slice(0,o+1).some(h=>h.split(/[-:_.]/).some(g=>/^(options?|configs?|settings?|labels?|tags?|annotations?|env|vars?|variables?|aliases?|metadata)$/i.test(g)))?[m("claude.bash.deploy",`${u} changes a live service's settings`,{target:f,is_local:!1,host:t})]:[l?m("claude.bash.db.destructive",`${u} ${p?"resets":"deletes"} stored data`,{target:f,is_local:!1,host:t}):m("claude.bash.deploy",`${u} ${p?"resets a cloud resource":"deletes cloud resources"}`,{target:f,is_local:!1,host:t})]}function mm(e){let t=e.argv,n=s=>!!s&&!S(s)&&Ut(s.replace(/:\d+$/,""));if(e.name==="pg_restore"){if(T(t,"-l","--list","-f","--file"))return[];let s=t.some(l=>l==="--clean"||/^-[A-Za-z]+$/.test(l)&&l.includes("c")),r=P(t,"-d","--dbname");if(r===null)return[];let o=P(t,"-h","--host")??(/^postgres(ql)?:\/\//i.test(r)?de(r):null),a=Xc(e,"");if(a===null&&(n(o)||o===null&&!S(r)&&!/^postgres(ql)?:\/\//i.test(r)))return[];let i=a??(o!==null&&!S(o)?fn(o):null);return[m("claude.bash.db.destructive",s?`pg_restore --clean drops the database's objects before it restores${i?` (${i})`:""}`:`pg_restore writes a dump into ${i??"a database the command does not name"}`,{target:i??k(r),is_local:!1,catastrophic:s&&i!==null})]}if(e.name==="mongorestore"||e.name==="mongoimport"){if(!T(t,"--drop"))return[];let s=P(t,"--uri","--host","-h"),r=s?/^mongodb(\+srv)?:\/\//.test(s)?de(s):s:"localhost";return n(r)?[]:[m("claude.bash.db.destructive",`${e.name} --drop drops ${e.name==="mongoimport"?"the collection before it imports":"each collection before it restores"}`,{target:S(r??"")?"a database the command does not name":r,is_local:!1})]}return[]}function ym(e){if(!yn.has(e.name)&&!rr.has(e.name)&&!["aws","kubectl"].includes(e.name))return[];let t=e.argv,n=v(t);if(!Ae(t)||n.some(o=>/^(list|ls|describe|get|show|view|what-if)$/.test(o)))return[];let s=`${e.name} ${n.slice(0,3).join(" ")}`.trim();if(t.some(o=>/(^|[=:,\s"'])all(Authenticated)?Users\b/.test(o))&&!n.some(o=>/^remove-/.test(o))&&!(e.name==="gsutil"&&T(t,"-d")))return[m("claude.bash.net.expose",`${s} makes a cloud resource readable by anyone on the internet`,{target:n.slice(0,4).join(" ")||e.name,host:e.name,is_local:!1})];let r=P(t,"--public-access","--allow-blob-public-access");return r!==null&&/^(blob|container|true)$/i.test(r)?[m("claude.bash.net.expose",`${s} opens a storage container to anonymous reads`,{target:n.slice(0,4).join(" ")||e.name,host:e.name,is_local:!1})]:e.name!=="aws"&&n.some(o=>/^(create|update|add|authorize|allow|set)/.test(o))&&t.some(o=>/(^|[=\s"',])(0\.0\.0\.0\/0|::\/0)\b/.test(o))?[m("claude.bash.net.expose",`${s} admits the whole internet (0.0.0.0/0)`,{target:n.slice(0,4).join(" ")||e.name,host:e.name,is_local:!1})]:[]}var bm=/^(?:default|colima(?:-[\w-]+)?|orbstack|desktop-linux|docker-desktop|rancher-desktop|podman[\w-]*|minikube|lima[\w-]*|(?:unix|npipe):\/\/.*|(?:tcp:\/\/)?(?:localhost|127\.0\.0\.1|\[::1\])(?::\d+)?)$/;function wm(e,t){let n=e.argv,s=v(n),r=R.basename(e.name)==="docker-compose"?s:s[0]==="compose"?s.slice(1):null;if(!(r?r.some(c=>/^(up|deploy|start|restart|run|create)$/.test(c)):/^(run|start|restart|create)$/.test(s[0]??"")||s[0]==="service"&&/^(create|update|scale|rollback)$/.test(s[1]??"")))return[];let a=n.indexOf(s[0]??"\0"),l=[...n.slice(0,a<0?n.length:a).flatMap((c,u,f)=>/^(-H|--host|--context|-c)$/.test(f[u-1]??"")?[c]:/^--(host|context)=/.test(c)?[c.slice(c.indexOf("=")+1)]:[]),...[...t.matchAll(/\bDOCKER_(?:HOST|CONTEXT)=["']?([^\s"';&|)]+)/g)].map(c=>c[1])].find(c=>!bm.test(c));return l?[m("claude.bash.deploy",`${R.basename(e.name)} ${s.slice(0,2).join(" ")} runs on another machine's docker (${l})`,{target:l,is_local:!1,host:"docker"})]:[]}var km=/^(deploy|deploys|deployment|deployments|promote|promotion|release|releases|rollout|rollback)$/i;function vm(e){let t=e.argv,n=v(t).slice(0,6);if(e.name==="docker"||e.name==="podman"){if(n[0]==="stack"&&n[1]==="deploy")return[m("claude.bash.deploy",`${e.name} stack deploy rolls out a swarm stack`,{target:n[2]??null,is_local:!1})];if(n[0]==="compose"&&(n.includes("up")||n.includes("deploy"))){let i=[P(t,"-f","--file")??"",P(t,"-p","--project-name")??"",Kn(e)];if(i.some(l=>Yn.test(R.basename(l).toLowerCase().replace(/\.(ya?ml)$/,""))||/(^|[._-])prod(uction)?([._-]|$)/i.test(R.basename(l))))return[m("claude.bash.deploy",`${e.name} compose starts the production stack (${R.basename(i.find(l=>l)??"")})`,{target:i.find(l=>l)??null,is_local:!1})]}return[]}if(!yn.has(e.name)&&!rr.has(e.name))return[];if(!Ae(t)||T(t,"--what-if","--validate-only","--check","--simulate","--preview"))return[];if(n.length>0&&Fc.has(n[0]))return[];let s=n.findIndex(i=>/^(run|exec|ssh|shell|console|connect|--)$/.test(i)),r=(s<0?n:n.slice(0,s)).filter(i=>!/[/.]/.test(i)||/^[\w-]+:[\w:-]+$/.test(i)),o=r.findIndex(i=>i.split(/[-:_.]/).some(l=>km.test(l)));if(o<0)return[];if(r.slice(0,o+1).some(i=>i.split(/[-:_.]/).some(l=>/^(tokens?|keys?|credentials?)$/i.test(l))))return[];if(n.some(i=>/^(list|ls|describe|get|show|info|logs?|status|history|view|inspect|what-if|validate|diff|plan|wait|cancel|close)$/i.test(i)))return[];if(/^(deploy|release)-(branch|key|keys|hook|hooks|setting|settings|config|target|env)$/i.test(r[o])&&r.slice(0,o).some(i=>/(^|:)(set|unset|config|configure)$/.test(i)))return[m("claude.bash.deploy",`${e.name} ${r.slice(0,o+1).join(" ")} changes a deploy setting`,{target:r.slice(o+1).find(i=>!i.includes("="))??null,host:e.name,is_local:!1})];let a=/(deploys|deployments?|deploy-requests?|releases)$/i.test(r[o])&&r[o+1]!==void 0?o+2:o+1;return[m("claude.bash.deploy",`${e.name} ${r.slice(0,a).join(" ")} starts a deploy`,{target:r.slice(a).find(i=>!i.includes("="))??null,host:e.name,is_local:!1})]}function $m(e){let t=e.argv;return["np","release-it","semantic-release"].includes(e.name)?!Ae(t)||T(t,"--preview","--dry-run","-d","--no-ci","--help","-h")||v(t)[0]==="init"?[]:[m("claude.bash.publish",`${e.name} publishes a release`,{target:v(t)[0]??null,is_local:!1})]:[]}function xm(e){let t=e.argv;return(e.name==="python"||e.name==="python3")&&t.includes("manage.py")&&t.includes("dumpdata")&&Yn.test(Kn(e))?[m("claude.bash.data.export","manage.py dumpdata copies the production database onto this machine",{target:"dumpdata",is_local:!1})]:e.name==="firebase"&&v(t)[0]==="auth:export"?[m("claude.bash.data.export","firebase auth:export copies every user account onto this machine",{target:v(t)[1]??null,host:"firebase",is_local:!1})]:e.name==="prisma"&&v(t)[0]==="db"&&v(t)[1]==="execute"&&(Yn.test(Kn(e))||/(?:^|\s)[A-Z_]*DATABASE_URL=["']?\$\{?[A-Z_]*PROD/i.test(e.text)||/prod/i.test(P(t,"--url")??""))?[m("claude.bash.deploy","prisma db execute runs SQL against the production database",{target:P(t,"--file")??null,is_local:!1})]:[]}function _m(e){let t=e.argv,n=v(t),s=(()=>{switch(e.name){case"gpg":case"gpg2":return t.some(o=>/^--export-secret-(sub)?keys$/.test(o))?"gpg prints a private key":null;case"security":return n[0]==="dump-keychain"?t.some(o=>/^-[a-z]*d/.test(o))?"security dumps the keychain with its secrets":null:/^find-(generic|internet)-password$/.test(n[0]??"")&&t.some(o=>/^-[a-z]*[wg]/.test(o))?"security prints a saved password":null;case"kubectl":case"oc":return n[0]==="config"&&n[1]==="view"&&T(t,"--raw","--flatten")?`${e.name} config view --raw prints the cluster credentials`:null;case"heroku":return n[0]==="auth:token"?"heroku auth:token prints an API token":null;case"stripe":return n[0]==="config"&&T(t,"--list")?"stripe config --list prints the API keys":null;case"az":return n[0]==="ad"&&n[1]==="sp"&&n[2]==="create-for-rbac"?"az ad sp create-for-rbac creates a service principal and prints its password":n[0]==="account"&&n[1]==="get-access-token"?"az account get-access-token prints a token":null;case"aws":return n[0]==="ecr"&&n[1]==="get-login-password"?"aws ecr get-login-password prints a registry password":n[0]==="iam"&&n[1]==="create-access-key"?"aws iam create-access-key creates a key and prints its secret":n[0]==="sts"&&/^(get-session-token|assume-role)$/.test(n[1]??"")?`aws sts ${n[1]} prints temporary credentials`:null;case"claude":return n[0]==="setup-token"?"claude setup-token prints a long-lived Claude token":null;case"glab":return n[0]==="auth"&&n[1]==="status"&&T(t,"-t","--show-token")?"glab auth status --show-token prints the GitLab token":null;case"firebase":return n[0]==="login:ci"?"firebase login:ci prints a CI token":null;case"neonctl":case"neon":return/^(connection-string|cs)$/.test(n[0]??"")?`${e.name} ${n[0]} prints a connection string with its password`:null;case"php":case"artisan":{let o=e.name==="artisan"?0:t.slice(1).findIndex(l=>/(^|\/)artisan$/.test(l))+1;if(e.name==="php"&&o<=0)return null;let[a="",i=""]=t.slice(o+1).filter(l=>!l.startsWith("-"));return a==="config:show"&&/^(app|database|mail|services|cache|queue|broadcasting|filesystems|session|logging)(\.|$)/.test(i)?`artisan config:show ${i} prints settings with their secrets`:null}default:return n.includes("diffsettings")&&(t.some(o=>/(^|\/)manage\.py$/.test(o))||R.basename(e.name)==="django-admin")?"manage.py diffsettings prints SECRET_KEY and the database password":n[0]==="auth"&&/^(token|print-token|show-token)$/.test(n[1]??"")?`${e.name} auth ${n[1]} prints a token`:n.slice(0,4).some(o=>/^print-(access|identity|id)-token$/.test(o))?`${e.name} prints an access token`:n[0]==="token"&&/^(create|new|generate)$/.test(n[1]??"")?`${e.name} token ${n[1]} makes a token and prints it`:null}})(),r=e.pipeTo;return r&&zc(r)?[]:s!==null&&ae(e)?[m("claude.bash.secrets.print",s,{target:n.slice(0,3).join(" ")||e.name,is_local:!0,host:e.name})]:[]}function zc(e){let t=v(e.argv);return["pbcopy","xclip","xsel","wl-copy","clip.exe","clip"].includes(e.name)?!0:["xargs","echo","printf","cat","tee"].includes(R.basename(e.name))||e.argv.some(s=>/^(-o|--output)(=|$)|^--dry-run(=|$)/.test(s))?!1:e.argv.includes("--password-stdin")&&t.includes("login")||["kubectl","oc"].includes(e.name)&&e.argv.some(s=>s==="--from-file=/dev/stdin")||(e.name==="gpg"||e.name==="gpg2")&&T(e.argv,"--import")?!0:["gh","glab"].includes(e.name)?(t[0]==="secret"||t[0]==="variable")&&t[1]==="set":e.name==="wrangler"?t[0]==="secret"&&(t[1]==="put"||t[1]==="bulk"):e.name==="fly"||e.name==="flyctl"?t[0]==="secrets"&&(t[1]==="set"||t[1]==="import"):e.name==="vercel"?t[0]==="env"&&t[1]==="add":!1}function Kn(e){return(/(?:^|\s)(?:NODE_ENV|APP_ENV|RAILS_ENV|RACK_ENV|MIX_ENV|FLASK_ENV|DJANGO_ENV|ENVIRONMENT|STAGE)=["']?([\w.-]+)/.exec(e.text)?.[1]??P(e.argv,"--env","--environment","--settings")??"").toLowerCase()}var Yn=/(^|[._-])(prod|production|live)($|[._-])/;function Sm(e){let t=e.argv,n=v(t),s=Yn.test(Kn(e)),r=a=>[m("claude.bash.db.destructive",a,{target:n.join(" ")||e.name,is_local:!1})],o=a=>s?r(`${a} in production`):[m("claude.bash.db.destructive",`${a}, with no server shown`,{target:n.join(" ")||e.name,is_local:null})];switch(e.name){case"sequelize":case"sequelize-cli":return n[0]==="db:drop"?o("sequelize db:drop drops the database"):s&&/^db:(drop|migrate:undo(:all)?|seed:undo(:all)?)$/.test(n[0]??"")?r(`sequelize ${n[0]} drops data in production`):[];case"knex":return s&&/^migrate:(rollback|down)$/.test(n[0]??"")?r(`knex ${n[0]} runs migrations backwards in production`):[];case"typeorm":case"typeorm-ts-node-commonjs":case"typeorm-ts-node-esm":return n[0]==="schema:drop"?o("typeorm schema:drop drops every table"):n[0]==="schema:sync"?o("typeorm schema:sync drops what the entities no longer name"):s&&/^(schema:drop|migration:revert)$/.test(n[0]??"")?r(`typeorm ${n[0]} drops data in production`):[];case"mix":return/^ecto\.(drop|reset)$/.test(n[0]??"")?o(`mix ${n[0]} drops the database`):s&&/^ecto\.(drop|reset|rollback)$/.test(n[0]??"")?r(`mix ${n[0]} drops data in production`):[];case"flyway":return n.includes("clean")?r("flyway clean drops every object in the schema"):[];case"liquibase":return n.some(a=>/^drop-?all$/i.test(a))?r("liquibase dropAll drops every object in the database"):[];case"php":case"artisan":{let a=e.name==="artisan"?0:t.slice(1).findIndex(l=>/(^|\/)artisan$/.test(l))+1;if(a<0||e.name==="php"&&a===0)return[];let i=t.slice(a+1).find(l=>!l.startsWith("-"))??"";return i==="db:seed"?s||T(t,"--force")?r(`artisan db:seed writes seed data into the database${s?" in production":" (--force: even in production)"}`):[]:/^(db:wipe|migrate:(fresh|reset|refresh|rollback))$/.test(i)?s||T(t,"--force")?r(`artisan ${i} drops the database's tables${s?" in production":" (--force: even in production)"}`):i==="migrate:rollback"?[]:o(`artisan ${i} drops every table`):[]}default:return[]}}function Cm(e){let t=v(e).filter(n=>n.includes("/")||n.includes(":")).filter(n=>!["push","image","buildx","build"].includes(n));return t.length>0&&t.every(n=>/^(localhost|127\.0\.0\.1|\[::1\]|host\.docker\.internal)(:\d+)?\//.test(n))}var Mc=/^(deploy|release|publish|ship)[-:_](notes|changelog|log|check|verify|lint|dry(-?run)?|plan|diff|status|info|list|test|smoke)$|^build[-:_]release$/;function Uc(e){let t=new Set(["--filter","-F","--workspace","-w","--cwd","-C","--dir","--prefix","--scope","--filter-prod"]),n=[];for(let s=1;s<e.length;s++){let r=e[s];if(t.has(r)&&!(r==="-w"&&e[0]!=="npm")){s++;continue}if(r==="--")break;r.startsWith("-")||n.push(r)}return n[0]==="workspace"&&n.length>=3?[n[2],...n.slice(3)]:n[0]==="workspaces"&&n[1]==="foreach"?n.slice(2):n}function qc(e){let t=Uc(e.argv),n=t[0]??"",s=P(e.argv,"--registry");if(["publish","unpublish","deprecate"].includes(n)&&s!==null&&Re(k(s)))return[];if(["publish","unpublish","deprecate"].includes(n)&&Ae(e.argv))return[m("claude.bash.publish",`${e.name} ${n} changes a published package`,{target:t[1]??null,is_local:!1})];if(n==="dist-tag"&&["add","rm"].includes(t[1]??""))return[m("claude.bash.publish",`${e.name} dist-tag moves a published tag`,{target:t.slice(2).join(" "),is_local:!1})];if(n==="owner"&&["add","rm"].includes(t[1]??""))return[m("claude.bash.external_write",`${e.name} owner changes who can publish`,{is_local:!1})];if(R.basename(e.name)==="pnpm"&&n==="deploy")return[];let r=n==="run"||n==="run-script"?t[1]:e.name!=="npm"&&!qo.has(n)?n:void 0;return r?Hc(r,e.argv):[]}function Hc(e,t){let n=!/^(check|verify|test|lint|validate|dry|preview|plan|diff|smoke|generate|prepare)([-:_]|$)/.test(e),s=Mc.test(e),r=t.indexOf("--"),o=r>=0&&!Ae(t.slice(r+1));return s||o?[]:/^(deploy|release|publish|ship)([-:_].*)?$/.test(e)||n&&/[-:_](deploy|release|publish)$/.test(e)?[m(/publish/.test(e)?"claude.bash.publish":"claude.bash.deploy",`the ${e} script deploys or releases`,{target:e,is_local:!1})]:n&&/^(promote|rollout|rollback)([-:_].*)?$|[-:_](promote|rollout|rollback)$/.test(e)?[m("claude.bash.deploy",`the ${e} script changes what is live`,{target:e,is_local:!1})]:/^db[-:_]?(push|reset|drop|wipe|nuke|truncate)\b|^(migrate|migration)[-:_]?(reset|fresh|drop)\b|[-:_](reset|drop|wipe)[-:_]?db$/.test(e)||/(^|[-:_])(db|database|schema|prisma|drizzle|clickhouse|postgres|mysql|mongo)[-:_](reset|drop|wipe|nuke|truncate|rollback|fresh)\b/.test(e)||/(^|[-:_])(migrate|migration|migrations)[-:_](deploy|prod|production|rollback|down|undo)\b/.test(e)?[m("claude.bash.db.destructive",`the ${e} script can drop, reset or change database data`,{target:e,is_local:null})]:[]}function Am(e){let t=R.basename(e.name),n=e.argv.slice(1).map(a=>k(a)),s=n.filter(a=>!a.startsWith("-")),r=(...a)=>n.flatMap((i,l)=>a.includes(i)?[n[l+1]??""]:a.some(c=>i.startsWith(`${c}=`))?[i.slice(i.indexOf("=")+1)]:[]).flatMap(i=>i.split(",")),o=[];if(t==="nx"){if(s[0]==="release"&&!n.includes("--dry-run")&&!n.includes("-d"))return[m("claude.bash.publish","nx release versions and publishes packages",{target:"nx release",is_local:!1})];o=s[0]==="run"?[(s[1]??"").split(":")[1]??""]:["run-many","affected"].includes(s[0]??"")?r("-t","--target","--targets"):s[0]?[s[0].includes(":")?s[0].split(":")[1]:s[0]]:[]}else if(t==="turbo"||t==="mise")o=s[0]==="run"?s.slice(1):t==="turbo"?s:[];else if(t==="lerna"){if(s[0]==="publish"&&!n.includes("--dry-run"))return[m("claude.bash.publish","lerna publish publishes packages",{target:"lerna publish",is_local:!1})];o=s[0]==="run"?s.slice(1,2):[]}else["run-s","run-p","npm-run-all"].includes(t)&&(o=s);for(let a of o.filter(Boolean)){let i=Hc(a,e.argv);if(i.length>0)return i.map(l=>({...l,why:`${l.why} (through ${t})`}))}return[]}var Em=new Set(["anvil","anvil-claude","hardhat","truffle","ape","forge","cast","anchor","prisma","drizzle-kit","supabase","wrangler","eas","expo","firebase","netlify","vercel","serverless","sls","cdk","dbt","ngrok","lt","untun","cloudflared","claude","codex","gemini","smithery","capgo","shorebird","web-ext","chrome-webstore-upload","changeset","lerna","vsce","ovsx","code-push","appcenter"]),qo=new Set(["install","i","add","remove","rm","uninstall","update","up","upgrade","test","t","build","exec","dlx","x","create","init","link","unlink","list","ls","why","outdated","audit","config","cache","info","view","pack","run","start","dev","lint","format","typecheck","version","help","login","logout","whoami","ci","prune","dedupe","store","setup","workspaces","workspace"]),be=/\b(drop\s+(table|database|schema|keyspace|view|materialized\s+view|index|user|role|column|type|function|trigger|sequence|extension|owned|policy)\b|truncate\b|delete\s+from\b|alter\s+table\s+\S+\s+(drop|delete)\b|update\s+\S+\s+set\b(?![\s\S]*\bwhere\b))/i,Rm=/\.(dropDatabase|drop|deleteMany|remove)\s*\(/;function wl(e,t){let n=e.slice(t).search(/[\n\r]/);return n<0?e.length:t+n}function ke(e,t="postgres"){if(/\b(execute|exec|sp_executesql|do)\b/i.test(e))return e;let n=t!=="postgres",s=t==="mysql"||t==="bigquery",r="";for(let o=0;o<e.length;o++){let a=e[o],i=e[o+1];if(a==="-"&&i==="-"&&(t!=="mysql"||o+2>=e.length||/\s/.test(e[o+2])))o=wl(e,o)-1;else if(a==="#"&&(t==="mysql"||t==="bigquery")||a==="/"&&i==="/"&&t==="snowflake")o=wl(e,o)-1;else if(a==="/"&&i==="*"){let l=e.indexOf("*/",o+2);t==="mysql"&&e[o+2]==="!"?r+=` ${e.slice(o+3,l<0?e.length:l)} `:r+=" ",o=l<0?e.length:l+1}else if(a==='"'&&!s||a==="`"&&(t==="mysql"||t==="bigquery")){let l=o+1;for(;l<e.length;l++)if(e[l]===a&&e[l+1]===a)l++;else if(e[l]===a)break;if(l>=e.length)return e;r+=a+a,o=l}else if(a==="$"&&(t==="postgres"||t==="snowflake")&&!/[\w$]/.test(e[o-1]??"")&&/^\$([A-Za-z_]\w*)?\$/.test(e.slice(o,o+64))){let l=/^\$([A-Za-z_]\w*)?\$/.exec(e.slice(o,o+64))[0],c=e.indexOf(l,o+l.length);if(c<0)return e;r+="''",o=c+l.length-1}else if(a==="'"||a==='"'&&s){let l=n||a==="'"&&/(^|[^\w])[eE]$/.test(r),c=o+1;for(;c<e.length;c++)if(l&&e[c]==="\\")c++;else if(e[c]===a&&e[c+1]===a)c++;else if(e[c]===a)break;if(c>=e.length)return e;r+=a+a,o=c}else r+=a}return r}function yt(e){if(/(?<![\w-])ssh(?![\w-])[^\n;&|]{0,200}\s-[A-Za-z]*L\s*\S/.exec(e))return"ssh -L";let n=/\b(DOCKER_(?:HOST|CONTEXT)=\S+|(?:docker|podman)\b[^\n;&|]{0,100}\s(?:-H|--host|--context)[\s=]\S+|cloudflared\s+access\s+(?:tcp|rdp|ssh)|fly(?:ctl)?\s+proxy|(?:kubectl|oc)\b[^\n;&|]{0,200}\bport-forward|cloud[-_]sql[-_]proxy|cloud_sql_proxy|aws\s+ssm\s+start-session\b[^\n;&|]{0,200}PortForward|tsh\s+proxy\s+db|start-iap-tunnel|railway\s+connect)/i.exec(e);return n?n[1].replace(/\s+/g," ").slice(0,40):null}var Om=/\b(create\s+or\s+replace\s+(table|schema|database)|insert\s+overwrite|delete\s+(?!from\b)[\w.`"-]+\s+where)\b/i,Hn={exec(e){let t=Om.exec(e);return t?[t[0],t[1]]:/\bmerge\b/i.test(e)&&/\bthen\s+delete\b/i.test(e)?["MERGE \u2026 THEN DELETE","MERGE \u2026 THEN DELETE"]:null},test(e){return this.exec(e)!==null}};function Ho(e,t){let n=Bc.has(e.name)?Zc(e):null,s=n!==null?{...e,stdin:n}:e;s!==e&&Qs.has(e)&&Qs.add(s);let r=s.argv,o=s.name,a=(...d)=>P(r,...d),i=s.pipeFrom&&["echo","printf","cat"].includes(s.pipeFrom.name)?s.pipeFrom.argv.slice(1).join(" ")+(s.pipeFrom.stdin??""):"",l="",c=null,u=null,f=!0;switch(o){case"psql":case"pgcli":{l=[...r.flatMap((g,y)=>g==="-c"||g==="--command"?[r[y+1]??""]:g.startsWith("--command=")?[g.slice(10)]:[]),s.stdin??"",i].join(`
|
|
43
|
-
|
|
44
|
-
|
|
36
|
+
`))}return s}var Yt=/^[A-Za-z_][A-Za-z0-9_]*=/,ec=ge("if then else elif fi do done while until esac ! { } time"),Fl=ge("sh bash zsh dash ksh ash"),Ml=ae({sudo:"-u -g -C -D -h -p -r -t -U --user --group --chdir",doas:"-u -C",env:"-u -C -S --unset --chdir",nohup:"",nice:"-n",timeout:"-s -k --signal --kill-after",command:"",builtin:"",exec:"-a",xargs:"-I -n -P -L -d -E -s -a",watch:"-n -d",flock:"-w -E",npx:"-p --package -c --call",bunx:"-p --package",op:"--env-file --account",doppler:"-c --config -p --project --token",infisical:"--env --projectId --path --token",dotenv:"-e -c -v",dotenvx:"-f --env-file","aws-vault":"--duration -d","cross-env":""}),$g=ae({timeout:1,flock:1,"aws-vault":2,op:1,doppler:1,infisical:1,dotenvx:1}),qo=ge("op doppler infisical dotenv dotenvx aws-vault mise asdf"),xg=ae({npm:"exec",pnpm:"dlx exec",yarn:"dlx exec",bun:"x",uv:"run",poetry:"run",pipenv:"run",bundle:"exec",mise:"exec x",asdf:"exec",railway:"run"}),_g=ae({flyctl:"fly","netlify-cli":"netlify","firebase-tools":"firebase","@railway/cli":"railway",tofu:"terraform",terragrunt:"terraform","docker-compose":"docker",oc:"kubectl",kubecolor:"kubectl"});function Ue(e){let n=/^((?:@[^/@\s]+\/)?[^@\s=/]+)(?:@[^\s/]*|==\S*)$/.exec(e),t=n?n[1]:e.startsWith("@")?e:e.slice(e.lastIndexOf("/")+1);return _g[t]??t}function zl(e,n,t){let s=t.split(" "),r=n;for(;r<e.length&&e[r].startsWith("-")&&e[r]!=="--";)r+=!e[r].includes("=")&&s.includes(e[r])?2:1;return e[r]==="--"?r+1:r}function tc(e){let n=0;for(let t=0;t<12&&n<e.length;t++){let s=e[n];if(Yt.test(s)){n++;continue}let r=Ue(s),o=e.indexOf("--",n);if(xg[r]?.split(" ").includes(e[n+1]??""))n=qo.has(r)&&o>n?o+1:zl(e,n+2,r==="railway"?"-e --environment -s --service":"");else if(Ml[r]!==void 0)qo.has(r)&&o>n?n=o+1:(n=zl(e,n+1,Ml[r])+($g[r]??0),e[n]==="--"&&n++);else return(r==="yarn"||r==="pnpm")&&Jt[Ue(e[n+1]??"")]&&n++,n}return n<e.length?n:-1}function Ho(e,n,t){return e.flatMap(s=>{let r=0;for(;r<s.words.length&&ec.has(s.words[r]);)r++;let o=s.words.slice(r);if(t>=3)return[{...s,words:o}];let a=(h,g)=>({frame:g?[...s.frame,n.frames++]:s.frame,guards:s.guards,first:s.first&&!s.cond,cond:s.cond,fresh:s.fresh||h}),i=o.flatMap(Sg).flatMap(h=>Ho(Uo(h,n,a(!1,!0),[]),n,t+1)),l=tc(o),c=l<0?"":Ue(o[l]),u=null;if(Fl.has(c)){let h=o.findIndex((g,b)=>b>l&&/^-[a-zA-Z]*c[a-zA-Z]*$/.test(g));u=h>0?o[h+1]??null:null}else c==="eval"&&(u=o.slice(l+1).join(" "));if(u===null)return[...i,{...s,words:o}];let p=o.slice(0,l).filter(h=>Yt.test(h)),d=Fl.has(c)?a(!0,!0):a(!1,!1),f=c==="eval"&&Qt(u)?[{...s,words:[],wild:!0}]:[];return[...i,...f,...Ho(Uo(u,n,d,[]),n,t+1).map(h=>({...h,words:[...p,...h.words]}))]})}function Sg(e){let n=[];for(let t=0;t<e.length;t++)if("$<>".includes(e[t])&&e[t+1]==="("&&e[t+2]!=="("){let s=Ql(e,t+1);n.push(e.slice(t+2,s)),t=s}else if(e[t]==="`"){let s=gr(e,t+1,"`");n.push(e.slice(t+1,s)),t=s}return n}var gs=(e,n)=>e.frame.length<=n.frame.length&&e.frame.every((t,s)=>n.frame[s]===t),nc=(e,n)=>gs(e,n)&&!e.cond&&(n.guards.includes(e.id)||e.first),lt="${?}";function sc(e,n,t){let s=t.filter(l=>(l.name===e||l.name==="*")&&gs(l.part,n)&&(!n.fresh||l.part.fresh||l.exported||l.name==="*"));if(!s.some(l=>l.name===e))return null;let r=-1;for(let l=s.length-1;l>=0;l--){let c=s[l];if(c.name===e&&!c.unknown&&(c.loop||nc(c.part,n))){r=l;break}}let o=r>=0?[...s[r].values]:[],a=r>=0;for(let l of s.slice(r+1))l.unknown?a=!1:o.push(...l.values);let i=s.filter(l=>l.name===e).pop().said;return{values:[...new Set(o)].slice(0,16),certain:a,said:i}}var Cg=(e,n,t)=>e.replace(/\$(?:\{([A-Za-z_]\w*)\}|([A-Za-z_]\w*))/g,(s,r,o)=>{let a=sc(r??o,n,t);return!a||a.values.length===0?s:a.certain&&a.values.length===1&&!/\s/.test(a.values[0])?a.values[0]:`${a.values.join(lt)}${lt}`}),fs=e=>e.slice(0,e.indexOf("=")),ps=e=>e.slice(e.indexOf("=")+1),Ag=ge("export declare typeset local readonly");function Eg(e){let n=[];return e.map(t=>{let s=t.words.map(u=>Cg(u,t,n)),r=tc(s),o=r<0?"":Ue(s[r]),a=new Map,i=s.slice(0,Math.max(r,0)).some(u=>/^(-[a-zA-Z]*[iu]|--unset.*|--ignore-environment|-)$/.test(u)||["sudo","doas"].includes(Ue(u)));for(let u of i?[]:new Set(n.filter(p=>p.exported&&p.name!=="*").map(p=>p.name))){let p=sc(u,t,n);p&&p.values.length>0&&a.set(u,{said:p.said,value:p.certain&&p.values.length===1?p.values[0]:`${p.values.join(" ")}${lt}`})}for(let u of r<0?[]:s.slice(0,r))Yt.test(u)&&a.set(fs(u),{said:u,value:ps(u)});let l=u=>n.some(p=>p.name===u&&p.exported&&gs(p.part,t)),c=(u,p,d,f={})=>{n.push({name:u,values:p,unknown:f.unknown??!1,exported:(f.exported??!1)||l(u),loop:f.loop??!1,part:t,said:d})};if(t.wild)c("*",[],"eval",{unknown:!0});else if(r<0)for(let u of s.filter(p=>Yt.test(p)))c(fs(u),[ps(u)],u);else if(Ag.has(o)){let u=s.slice(r+1).filter(f=>/^[-+]/.test(f)),p=o==="export"||u.some(f=>/^-[a-zA-Z]*x/.test(f)),d=u.some(f=>/^(-[a-zA-Z]*n|\+[a-zA-Z]*x)/.test(f));for(let f of s.slice(r+1))d&&/^[A-Za-z_]\w*(=|$)/.test(f)?c(f.replace(/=.*/s,""),[],o,{unknown:!0}):Yt.test(f)?c(fs(f),[ps(f)],`${o} ${f}`,{exported:p}):p&&/^[A-Za-z_]\w*$/.test(f)&&n.push(...n.filter(h=>h.name===f).slice(-1).map(h=>({...h,exported:!0,part:t})))}else if(o==="for"&&s[r+2]==="in")c(s[r+1],s.slice(r+3),s.slice(r).join(" "),{loop:!0});else if(o==="source"||o==="."||o==="eval"&&s.slice(r+1).some(Qt)||o==="set"&&s.slice(r+1).some(u=>/^-[a-zA-Z]*a/.test(u)))c("*",[],o,{unknown:!0});else for(let u of s.slice(r+1))/^[A-Za-z_]\w*$/.test(u)&&n.some(p=>p.name===u)&&c(u,[],o,{unknown:!0});return{part:t,words:s,fed:t.fed,pipe:t.pipe,at:r,tool:o,env:a}})}var Rg=(e,n)=>nc(e.part,n.part)&&n.part.guards.includes(e.part.id),Og=ge("version help status logs log list ls info show get describe whoami auth login logout doctor history inspect open ps top explain plan validate fmt init output graph providers preview diff synth config context use link pull build template lint package search repo dependency dep workspace stack"),rc=ge("cd pushd popd export declare typeset local readonly unset source . echo printf sleep true false set test [ [[ for case git cat ls grep tee read wait exit return mkdir cp mv rm touch chmod which pwd date kubectx kubens alias unalias"),jg=[ge("deploy deploys deploying deployment deployments redeploy"),ge("release releases ship publish rollout promote apply provision rollback destroy")],Pg=e=>tt(e.words.slice(e.at+1),at[e.tool]??"")[0]??"";function Wg(e,n){let t=e.map((i,l)=>l),s=i=>!Og.has(Pg(e[i]))||e[i].words.some(l=>/^(delete|rm|remove|destroy|drop|purge|prune|uninstall|reset)$/.test(l)),r=n?Ue(n.toLowerCase()):null;if(r){let i=t.filter(l=>e[l].at>=0&&e[l].tool===r);if(i.length>0)return i.some(s)?i.filter(s):i;for(let l of e){let c=l.words.findIndex((u,p)=>p>l.at&&Ue(u)===r);if(l.at>=0&&c>0)return l.at=c,l.tool=r,[e.indexOf(l)]}}let o=t.filter(i=>e[i].at>=0&&!rc.has(e[i].tool)),a=o.filter(i=>e[i].words.some(l=>Xt(l).some(Vo))||Jt[e[i].tool]!==void 0&&s(i));return a.length>0?a:o}function Yo(e){let n=bg(e);return Eg(Ho(Uo(e,n,mg,[]),n,0))}function Ng(e,n){let t=Yo(e),s=Wg(t,n);if(s.length===0){for(let l of t)for(let c of[...l.words,...l.fed])if($e(c))return{environment:"production",said:we(c)};return Kt}let r=s.map(l=>Dg(t,l,n)),o=r.find(l=>l.environment==="production")??(r.some(l=>l.environment===null)?Kt:r[0]);if(o.environment!=="non-production")return o;let a=e.replace(/["']/g,"").split(/[\s`;&|()<>{}$\\]+/),i=[n?Ue(n.toLowerCase()):"",...s.map(l=>t[l].tool)].some(l=>l&&a.filter(c=>Ue(c)===l).length>t.filter(c=>c.tool===l).length);return $e(e)||i||t.some(l=>l.tool==="alias")?Kt:o}var we=e=>{let n=e.split(lt).join("");return n.length>80?`${n.slice(0,79)}\u2026`:n};function Ul(e,n){for(let t=0;t<e.length;t++){let s=e[t];if(!$e(s))continue;let r=e[t-1]??"",o=r.startsWith("-")&&!r.includes("=")&&!s.startsWith("-")&&(n===void 0||n.split(" ").includes(r));return we(o?`${r} ${s}`:s)}return null}var Jo="terraform workspace select|terraform workspace new|terraform init:-backend-config|kubectl config use-context|kubectx|pulumi stack select|firebase use|gcloud config set project|gcloud config configurations activate|docker context use|railway environment|railway link:-e --environment|az account set:--subscription -s --name -n".split("|").map(e=>{let[n,t]=e.split(":"),s=n.split(" ")[0];return[s==="kubectx"?"kubectl":s,n,t]}),Lg=ge("terraform pulumi fly vercel netlify wrangler firebase railway docker");function Mo(e,n){let t=e.tool,s=t==="helm"?"kubectl":t,r=[],o=[],a=i=>[{said:i,value:lt}];for(let i of n){if(i.at<0||!gs(i.part,e.part))continue;let l=Rg(i,e),c=i.words.slice(i.at),u=we(c.join(" "));if(["cd","pushd","popd"].includes(i.tool)||(i.tool==="source"||i.tool===".")&&!Jt[t]){let d=tt(c.slice(1),"")[0];r=l&&d&&d!=="-"&&i.tool!=="popd"?[{said:u,value:d}]:a(u)}let p=Jo.filter(([d,f])=>d===s&&f.split(" ").every((h,g)=>(g>0?c[g]:i.tool)===h)).flatMap(([,d,f])=>{let h=c.slice(d.split(" ").length);return f?pe(h,f):tt(h,"").slice(0,1).map(g=>({said:u,value:g}))});p.length>0&&(o=l?p:a(u))}return r.length>0&&e.words.some((i,l)=>i==="-C"||l<e.at&&i==="-D"||i==="-d"&&/^(task|just)$/.test(e.tool)||/^--(chdir|cwd|prefix|dir|directory|working-dir)(=|$)/.test(i))&&(r=a("")),{folders:Lg.has(t)||!Jt[t]?r:[],picks:o}}var Tg=ge("cd pushd export declare typeset local readonly source . test [ [[ kubectx kubens case alias");function Dg(e,n,t){let s=e[n],r=e.slice(0,n),o=s.tool==="helm"?"kubectl":s.tool,a=r.filter(f=>f.at<0||Tg.has(f.tool)||f.tool===s.tool&&Jt[s.tool]||Jo.some(([h,g])=>h===o&&`${g} `.startsWith(`${f.tool} `)));if(ze.strict&&o==="kubectl"&&!s.words.some(f=>/^(--server|-s|--kube-apiserver)(=|$)/.test(f))){let f=[...pe(s.words.slice(s.at+1),"--context --kube-context"),...Mo(s,r).picks].find(h=>ms.test(h.value));if(f)return{environment:"non-production",said:we(f.said)}}if(ze.strict&&o==="docker"&&Jt.docker({args:s.words.slice(s.at+1),env:s.env,chosen:[],folders:[],picks:Mo(s,r).picks}).sels.every(f=>Xo.test(f.value)))return{environment:"non-production",said:"docker on this machine"};let i=Ul(s.words,at[s.tool]);if(i)return{environment:"production",said:i};for(let f of[...s.fed,...r.filter(h=>h.pipe===s.pipe).flatMap(h=>[...h.words,...h.fed])]){let h=$e(f);if(h)return{environment:"production",said:h}}for(let f of a)if(Ul(f.words))return{environment:"production",said:we(f.words.slice(Math.max(f.at,0)).join(" "))};if(t&&$e(t))return{environment:"production",said:t};let l=Mo(s,r),c={args:s.words.slice(s.at+1),env:s.env,chosen:[...l.folders,...l.picks],folders:l.folders,picks:l.picks},u=Jt[s.tool]?.(c)??Mg(c,s.words.slice(Math.max(0,s.words.findIndex((f,h)=>h===s.at||qo.has(Ue(f))))),s.tool);if(u.production)return{environment:"production",said:u.production};let p=u.first?u.sels.filter(f=>f.rank===u.sels[0].rank):u.sels,d=p.length>0&&p.every(f=>!Qt(f.value)&&_n(f.value))?p[0]:void 0;return d?{environment:"non-production",said:we(d.said)}:u.preview?{environment:"non-production",said:u.preview}:Kt}function pe(e,n){let t=n.split(" "),s=[];return e.forEach((r,o)=>{let a=r.indexOf("=");a>0&&t.includes(r.slice(0,a))?s.push({said:r,value:r.slice(a+1)}):t.includes(r)&&o+1<e.length?s.push({said:`${r} ${e[o+1]}`,value:e[o+1]}):/^-[A-Za-z]$/.test(r.slice(0,2))&&r.length>2&&!r.startsWith("--")&&t.includes(r.slice(0,2))&&s.push({said:r,value:r.slice(2)})}),s}function tt(e,n){let t=n.split(" "),s=[];for(let r=0;r<e.length;r++){let o=e[r];if(o==="--")return[...s,...e.slice(r+1)];!o.startsWith("-")||o==="-"?s.push(o):!o.includes("=")&&t.includes(o)&&r++}return s}function Ig(e,n){let t=n.split(" "),s=[];for(let r=0;r<e.length;r++){let o=e[r];if(o==="--")return[...s,...e.slice(r+1)];!o.startsWith("-")||o==="-"?/^-./.test(e[r-1]??"")&&!e[r-1].includes("=")||s.push(o):!o.includes("=")&&t.includes(o)&&r++}return s}var ds=e=>e.map(n=>({said:n,value:n})),vn=(e,n)=>n.split(" ").flatMap(t=>e.env.get(t)??[]),ql=(e,n)=>pe(e.args,n).map(t=>({...t,value:lt})),Hl=e=>e.env.has("KUBECONFIG")||e.args.some(n=>n.startsWith("--kubeconfig"))?[]:e.picks,bt=(...e)=>{let n=e.findIndex(t=>t.length>0);return{sels:n<0?[]:e[n].map(t=>({...t,rank:n})),first:!0}},Bo=e=>e.flatMap(n=>{let t=n.value.split(/[\s,]+/).filter(s=>Yt.test(s));return t.length===0?[n]:t.filter(s=>hr(fs(s))).map(s=>({said:n.said,value:ps(s)}))}),zo=(e,n)=>{let t=n.split(" ");return e.every((s,r)=>!Qt(s)||s.startsWith("-")||t.includes(e[r-1]??""))},at=ae({vercel:"--token -t --scope -S --cwd --local-config -A --global-config -Q --team -T --build-env -b --env -e --meta -m --regions --archive --target --name -n",netlify:"--dir -d --functions -f --site -s --auth --alias --branch -b --context --message -m --filter --timeout",fly:"-a --app -c --config -i --image -e --env --build-arg --build-secret --dockerfile --strategy -r --region --vm-size --wait-timeout --image-label -t --access-token -o --org",terraform:"-var -var-file -target -replace -state -state-out -backup -lock-timeout -parallelism",firebase:"-P --project --only --except -m --message --token --account --expires -e"}),Jt=ae({vercel:e=>{let n=tt(e.args,at.vercel),t=/^(deploy)?$|[/.]/.test(n[0]??"")?"deploy":n[0];if(t==="rollback"||t==="promote")return{sels:[],production:t};let s=[...pe(e.args,"--target"),...zo(e.args,at.vercel)?[]:[{said:"",value:lt}]];return t!=="deploy"?{sels:[...s,...ds(t==="env"?n.slice(3,4):n.slice(1)),...e.chosen]}:{sels:s,...s.length===0?{preview:"no --prod"}:{}}},netlify:e=>e.args.some(t=>/^-[a-z]*p[a-z]*$/.test(t))?{sels:[],production:"-p"}:{sels:[...pe(e.args,"--context --alias --branch -b --site -s"),...e.chosen],...tt(e.args,at.netlify)[0]==="deploy"&&zo(e.args,at.netlify)?{preview:"no --prod"}:{}},fly:e=>{let n=tt(e.args,at.fly),t=n[0]==="apps"||n[0]==="app"?n.slice(2,3):[];return bt([...pe(e.args,"-a --app"),...ds(t)],vn(e,"FLY_APP"),pe(e.args,"-c --config"),n[0]==="deploy"&&n[1]?[{said:"",value:lt}]:[],e.folders)},railway:e=>bt(pe(e.args,"-e --environment"),e.picks),kubectl:e=>bt(pe(e.args,"--context --cluster --server -s"),Hl(e)),helm:e=>bt([...pe(e.args,"--kube-context --kube-apiserver"),...vn(e,"HELM_KUBEAPISERVER")],vn(e,"HELM_KUBECONTEXT"),Hl(e)),terraform:e=>{let n=Ig(e.args,at.terraform),t=["apply","destroy"].includes(n[0]??"")?n.slice(1):[],s=[...pe(e.args,"-chdir --chdir --terragrunt-working-dir --working-dir"),...vn(e,"TF_WORKSPACE"),...ds(t),...e.chosen];return{sels:s.length>0?[...s,...pe(e.args,"-var-file --var-file"),...Bo(pe(e.args,"-var --var"))]:[]}},pulumi:e=>bt(pe(e.args,"-s --stack"),e.picks,[...pe(e.args,"-C --cwd"),...e.folders]),firebase:e=>{let n=tt(e.args,at.firebase),t=/^hosting:channel:deploy/.test(n[0]??"");return{sels:[...bt(pe(e.args,"-P --project"),e.picks,ql(e,"--config"),e.folders).sels,...t?ds(n.slice(1,2)).map(r=>({...r,rank:9})):[]],first:!0,...t&&zo(e.args,at.firebase)?{preview:n[0]}:{}}},wrangler:e=>bt(pe(e.args,"--name --route --routes"),pe(e.args,"-e --env --branch --project-name"),ql(e,"-c --config"),e.chosen),docker:e=>{let n=e.args.findIndex((t,s)=>!t.startsWith("-")&&!["-c","--context","-H","--host","--config"].includes(e.args[s-1]??""));return bt([...pe(n<0?e.args:e.args.slice(0,n),"-c"),...pe(e.args,"--context -H --host")],vn(e,"DOCKER_HOST DOCKER_CONTEXT"),e.picks)},modal:e=>bt(pe(e.args,"-e --env"),vn(e,"MODAL_ENVIRONMENT"))}),Fg=ge("make gmake rake just task cap"),Vo=e=>jg.some(n=>n.has(e.toLowerCase()));function Mg(e,n,t){let s=[],r=[],o=(f,h)=>{s.push(...h),pg(f)&&r.push(...h)},a=[],i=!1;for(let f=0;f<n.length;f++){let h=n[f];if(h==="--")i=!0;else if(h.startsWith("-")&&h.length>1){let g=h.indexOf("="),b=t==="npm"&&!i;h==="--all"&&r.push({said:h,value:h}),g>0?o(h.slice(0,g),Il(h.slice(0,g))&&!b?Bo([{said:h,value:h.slice(g+1)}]):[]):gg.test(h)?s.push(...b?[]:[{said:h,value:h}]):n[f+1]!==void 0&&!n[f+1].startsWith("-")&&(f++,Il(h)&&!b&&o(h,Bo([{said:`${h} ${n[f]}`,value:n[f]}])))}else Yt.test(h)?Fg.has(t)&&hr(fs(h))&&s.push({said:h,value:ps(h)}):(Qt(h)||!/\s/.test(h)&&!/^v?\d+(\.\d+)+/.test(h))&&(s.push({said:h,value:f>0?h:h.slice(h.lastIndexOf("/")+1)}),f>0&&a.push(h))}for(let[f,h]of e.env)hr(f)&&o(f,[h]);let l=[...s,...e.chosen],c=a.filter(f=>Xt(f).some(Vo)),u=a.findIndex(Vo),p=a.slice(u<0?a.length:u+1).filter(f=>!/[/.]/.test(f));return{sels:l.some(f=>Qt(f.value))||[c,p].some(f=>f.length>1&&!f.every(_n))||!r.every(f=>_n(f.value))?[{said:"",value:lt}]:l.filter(f=>_n(f.value))}}function Sn(e){let n=/^[a-z][a-z0-9+.-]*:\/\/(?:[^@/\s]*@)?([^/?#\s]*)(\/[^?#\s]*)?/i.exec(e.trim());return n?`${n[1]??""} ${(n[2]??"").replace(/^\//,"")}`:e}var $n=null;function zg(e){if($n?.command===e&&$n.vocab.strict===ze.strict&&$n.vocab.names===ze.names)return $n;let n=Yo(e).flatMap(s=>[...s.words,...s.fed]),t=n.flatMap((s,r)=>[.../^(-h|--host)$/.test(n[r-1]??"")?[s]:[],...[...s.matchAll(/(?:^--host=|^-h(?=.)|(?:^|[\s;='"])host(?:addr)?=|^\w*HOST(?:ADDR)?=)([^\s;]*)|[a-z][\w+.-]*:\/\/\S*/gi)].map(o=>o[1]??o[0])]);return $n={command:e,vocab:ze,prod:n.find(s=>$e(s))??null,servers:t.every(s=>!Qt(s)&&s.split(",").every(r=>_n(Sn(r))))},$n}function Ug(e,n,t){let s=[t,n].filter(a=>typeof a=="string"&&a.length>0);for(let a of s)if($e(Sn(a)))return{environment:"production",said:we(a)};let r=zg(e);if(r.prod!==null)return{environment:"production",said:we(r.prod)};let o=s.find(a=>_n(Sn(a)));return o&&r.servers?{environment:"non-production",said:we(o)}:Kt}function oc(e,n=[]){let t=e.toLowerCase();return/pro?d|live|[^\u0000-\u007f]/.test(t)||n.some(s=>t.includes(s))}function ic(e,n=[]){return Go(n,!0,[],()=>{let t=Yo(e).filter(o=>o.at>=0),s=new Map;for(let o of t)s.set(o.tool,(s.get(o.tool)??0)+1);let r=new Map;return t.flatMap((o,a)=>{let i=r.get(o.tool)??0;r.set(o.tool,i+1);let l=rc.has(o.tool)||qg.has(o.tool)?null:em(o,t.slice(0,a));return l?[{tool:o.tool,nth:i,of:s.get(o.tool),args:o.words.slice(o.at+1),said:l}]:[]})})}var qg=ge("head tail less wc jq yq sort uniq cut tr sed awk find stat file diff rg"),Hg="aws:--profile=AWS profile|gcloud:--project=Google Cloud project|bq:--project_id=Google Cloud project|az:--subscription=Azure subscription|kubectl:--context=Kubernetes context|helm:--kube-context=Kubernetes context|kubectl helm:--kubeconfig=kubeconfig|terraform:-var-file --var-file=Terraform var file|railway:-e --environment=Railway environment|fly:-a --app=Fly app|heroku:-a --app=Heroku app|dotenv:-e=env file|dotenvx env-cmd:-f --file=env file|doppler:-c --config=Doppler config|infisical:--env=Infisical environment|firebase:-P --project=Firebase project|supabase:--project-ref=Supabase project|docker:--context=Docker context|docker:-H --host=Docker host|ansible ansible-playbook:-i --inventory --inventory-file=Ansible inventory|ansible ansible-playbook:-l --limit=Ansible hosts|*:--env-file=env file",Bl=null,Bg=ge("--api-key --apikey --token --access-token --auth-token"),Vg=ge("aws gcloud gsutil bq az kubectl helm terraform"),Vl=ae({AWS_PROFILE:"AWS profile",AWS_DEFAULT_PROFILE:"AWS profile",CLOUDSDK_CORE_PROJECT:"Google Cloud project",KUBECONFIG:"kubeconfig",TF_WORKSPACE:"Terraform workspace"}),Gg=ge("url uri dsn host token key secret password pass pat credentials profile context account database db connection conn"),Zg=ae({kubectl:"Kubernetes context",terraform:"Terraform workspace",railway:"Railway environment",gcloud:"Google Cloud project",firebase:"Firebase project",pulumi:"Pulumi stack",docker:"Docker context",az:"Azure subscription"}),Kg=ge("aws gcloud az kubectl terraform pulumi docker railway fly heroku firebase vercel netlify wrangler supabase modal ssh mosh autossh scp sftp rsync curl wget http https xh ansible ansible-playbook"),Yg=(e,n)=>e===n||!Kg.has(n)&&!ur.has(n)||/^(terraform|pulumi)$/.test(n)&&/^(az|gcloud|kubectl)$/.test(e),ms=/^(kind-|k3d-|minikube$|docker-desktop$|rancher-desktop$|orbstack$|colima)/,Xo=/^(?:default|colima(?:-[\w-]+)?|orbstack|desktop-linux|docker-desktop|rancher-desktop|podman[\w-]*|minikube|lima[\w-]*|(?:unix|npipe):\/\/.*|(?:tcp:\/\/)?(?:localhost|127\.0\.0\.1|\[::1\])(?::\d+)?)$/,ur=ge("psql pg_dump pg_restore mysql mysqldump mariadb mongosh mongo redis-cli pgcli mycli clickhouse-client cqlsh sqlcmd"),Jg=ge("url uri dsn host hostname database db conn connection endpoint api server addr address base origin"),Xg=/^(?:postgres(?:ql)?|mysql|mariadb|mongodb(?:\+srv)?|rediss?|amqps?|clickhouse|cockroachdb|sqlserver|mssql):\/\/[^\s'"]+/i;function cr(e,n){let t=n.split(lt).join("");return/context$/.test(e)&&ms.test(t)?null:t&&(/file$|^kubeconfig$/.test(e)?hs(t):$e(t))?`the ${e} ${we(t)}`:null}function hs(e){let n=/live/i.test(e)?Jl(e):e;return!/example|sample|template/i.test(n.split("/").pop()??"")&&!!(n.includes("/")?Xl(n,!0):$e(n))}var Qg=e=>/(?:^|\/)\.env[\w.-]*$|\w\.env$/.test(e)&&hs(e),Gl=e=>e.join(" ").split(/[\s'"()$`|<>;=]+/).find(Qg);function em(e,n){let t=e.words;Bl??=new Map(Hg.split("|").flatMap(l=>{let[c,u]=l.split(":"),[p,d]=u.split("=");return c.split(" ").flatMap(f=>p.split(" ").map(h=>[`${f} ${h}`,d]))}));let s=[...t.slice(0,e.at).map(Ue),e.tool,"*"];for(let l=0;l<t.length;l++){let c=t[l],u=c.startsWith("-")&&c.includes("=")?c.slice(0,c.indexOf("=")):c,p=u===c?t[l+1]??"":c.slice(u.length+1);if(Bg.has(u)&&$e(p))return p.startsWith("$")?`the token ${we(p)}`:`the token given to ${u}`;if(c==="--live"&&e.tool==="stripe")return"Stripe's live mode";let d=c.startsWith("-")?s.map(h=>Bl.get(`${h} ${u}`)).find(Boolean):c==="exec"&&Ue(t[l-1]??"")==="aws-vault"?"AWS profile":void 0,f=d?cr(d,p):null;if(f)return f;if(l>e.at&&Vg.has(e.tool)&&fr(xn(c)))return we(c)}let r=e.tool==="ansible"?cr("Ansible hosts",tt(t.slice(e.at+1),"-i --inventory --inventory-file -m --module-name -a --args -l --limit -u --user -f --forks -e --extra-vars -c --connection -T --timeout --private-key")[0]??""):null;if(r)return r;for(let[l,c]of e.env){let u=/\$\(\s*(?:cat\s+|<\s*)([^)\s]+)/.exec(c.value)?.[1],p=Vl[l]?cr(Vl[l],c.value):Gg.has(pr(l))&&($e(l)||(u?hs(u):$e(c.value.includes("://")?Sn(c.value):c.value)))?`the variable ${l}`:null;if(p)return p}let o=e.tool==="helm"?"kubectl":e.tool==="gsutil"||e.tool==="bq"?"gcloud":e.tool;for(let l of n){let c=l.words.slice(l.at);for(let[p,d,f]of Jo){if(!Yg(p,o)||!d.split(" ").every((g,b)=>(b>0?c[b]:l.tool)===g))continue;let h=c.slice(d.split(" ").length);for(let g of f?pe(h,f).map(b=>b.value):tt(h,"").slice(0,1)){let b=cr(Zg[p],g);if(b)return b}}let u=/^(source|\.|export|set|eval)$/.test(l.tool)&&gs(l.part,e.part)?Gl(l.words):void 0;if(u)return`the env file ${we(u)}`}let a=Gl(t.slice(0,e.at));if(a)return`the env file ${we(a)}`;for(let l of t){let c=Xg.exec(l.replace(/^--?[\w-]+=/,""))?.[0];if(c&&$e(Sn(c)))return`the database at ${we(Sn(c).trim().replace(" ","/"))}`}if(ur.has(e.tool)||/^(curl|wget|https?|xh)$/.test(e.tool))for(let l of t.slice(e.at+1)){let c=/^\$\{?(\w+)/.exec(l)?.[1];if(c&&Jg.has(pr(c))&&$e(c))return`the ${ur.has(e.tool)?"database":"URL"} in ${we(l)}`}if(ur.has(e.tool)){for(let l of[...pe(t,"-h --host -d --dbname"),...t.flatMap(c=>[...c.matchAll(/\b(?:host|dbname)=([^\s'"]+)/g)].map(u=>({value:u[1]})))])if(!l.value.includes("://")&&$e(l.value))return`the database ${we(l.value)}`}if(/^(curl|wget|https?|xh)$/.test(e.tool)){for(let c of t){let u=/^(?:--?[\w-]+=)?https?:\/\/(?:[^@/\s]*@)?([^/?#\s:'"]+)/i.exec(c)?.[1];if(u&&$e(u))return`the host ${we(u)}`}let l=[...pe(t,"-H --header -u --user --oauth2-bearer"),.../^(curl|wget)$/.test(e.tool)?[]:[...pe(t,"-a --auth --bearer"),...ds(t.slice(e.at+1).filter(c=>/^[\w-]+:(?![=/@])/.test(c)))]];for(let c of l){if(c.value.startsWith("@")&&hs(c.value.slice(1)))return`the token in ${we(c.value.slice(1))}`;for(let u of c.value.matchAll(/\$\{?(\w+)|\$\(\s*(?:cat\s+|<\s*)([^)\s]+)/g)){if(u[1]&&$e(u[1]))return`the token $${u[1]}`;if(u[2]&&hs(u[2]))return`the token in ${we(u[2])}`}}}let i=/^(ssh|mosh|autossh)$/.test(e.tool)?tt(t.slice(e.at+1),"-b -c -D -E -e -F -I -i -J -L -l -m -O -o -p -Q -R -S -W -w -B").slice(0,1):/^(scp|sftp|rsync)$/.test(e.tool)?[...t.slice(e.at+1).filter(l=>/^[^-/][^/]*:/.test(l)),...e.tool==="sftp"?tt(t.slice(e.at+1),"-B -b -c -D -F -i -J -l -o -P -R -S -s -X").slice(0,1):[]]:[];for(let l of i){let c=l.replace(/^[^@]*@/,"").replace(/:.*$/,"");if($e(c))return`the server ${we(c)}`}return null}var en=/^(?:\.{1,2}(?:[\\/]|$)|[\\/]|~[\\/]|file:|link:|[A-Za-z]:[\\/])|\.(?:tgz|tar|tar\.gz|whl|zip|gem|deb|rpm|nupkg|rb)$/i,wt=/^(?:git\+|git:|git@|github:|gitlab:|bitbucket:|gist:|hg\+|svn\+|bzr\+|https?:|ssh:)/i,tm=new Set(["npm","pnpm","yarn","pip","setuptools","wheel"]),cc=/^https?:\/\/(?:registry\.npmjs\.org|registry\.yarnpkg\.com|pypi\.org\/simple|pypi\.python\.org\/simple|(?:repo\.)?packagist\.org)\/*$/i,nm={npm:/^(?:npm_config_registry|yarn_registry|yarn_npm_registry_server|bun_config_registry)$/i,pip:/^(?:PIP_INDEX_URL|PIP_EXTRA_INDEX_URL|PIP_FIND_LINKS|PIPENV_PYPI_MIRROR)$/,uv:/^UV_(?:INDEX_URL|EXTRA_INDEX_URL|DEFAULT_INDEX|INDEX|FIND_LINKS)$/},ct=(e,n)=>[...e].filter(([t])=>nm[n].test(t)).map(([,t])=>t),ys=["--registry","-i","--index-url","--extra-index-url","--index","--default-index","-f","--find-links","--pypi-mirror"];function tn(e){let n=e.filter(t=>typeof t=="string").map(t=>t.replace(/^[\w.-]+=(?=[a-z][\w+.-]*:)/i,"")).filter(sm);return n.length>0?[...new Set(n)].join(" or "):null}var sm=e=>e!==""&&!cc.test(e)&&!en.test(e),uc={npm:/^((?:@[\w.-]+\/)?[\w.-]+)(?:@.*)?$/,PyPI:/^([A-Za-z0-9](?:[\w.-]*[A-Za-z0-9])?)\s*(?:\[[^\]]*\])?\s*(?:[<>=!~;@,( ].*)?$/,"crates.io":/^([A-Za-z][\w-]*)(?:@.*)?$/,Go:/^([\w~-]+(?:\.[\w~-]+)+(?:\/[\w.~-]+)*)(?:@.*)?$/,RubyGems:/^([A-Za-z0-9][\w.-]*)(?::.*)?$/,Packagist:/^([\w.-]+\/[\w.-]+)(?:[:=@].*)?$/,NuGet:/^([A-Za-z0-9_][\w.-]*)$/},dc=/^(@?[\w][\w.+@:/-]*?)(?:[=:]\S*)?$/;function Qo(e,n){return n.length<=214&&!/[\s\0]|^[-.]|\.\./.test(n)&&(uc[e]??dc).test(n)}function Ce(e,n,t,s=!1){let r=[],o=[];for(;n<e.length;n++){let a=e[n];if(a==="--"||s&&r.length>0){r.push(...e.slice(a==="--"?n+1:n));break}let i=a.indexOf("=");a.length<2||a[0]!=="-"?r.push(a):i>0&&a.startsWith("--")?o.push([a.slice(0,i),a.slice(i+1)]):` ${t} `.includes(` ${a} `)?o.push([a,e[++n]??""]):o.push([a,!0])}return{ops:r,opt:(...a)=>o.find(([i])=>a.includes(i))?.[1],all:(...a)=>o.filter(([i,l])=>a.includes(i)&&l!==!0).map(([,i])=>i)}}function fc(e,n){return(e==="npm"?/^@?[^@]+@(.*)$/:e==="PyPI"?/^[\w.-]+\s*(?:\[[^\]]*\])?\s*@\s*(.*)$/:/^$/).exec(n)?.[1]??""}var rm=e=>en.test(e)&&!wt.test(e);function om(e,n){let t=fc(e,n);return t===""||wt.test(n)?null:wt.test(t)||/[:/]/.test(t)&&!en.test(t)&&!/^(?:portal|workspace|catalog):/.test(t)?t:null}function Ae(e,n,t,s,r={}){let o=[],a=[],i=[],l=[];for(let c of t){if(c===""||r.skip?.(c))continue;let u=fc(e,c),p=wt.test(c)||wt.test(u),d=(uc[e]??dc).exec(c),f=d?om(e,c):null;f!==null?l.push(`${d[1]} from ${f}`):!p&&(en.test(c)||en.test(u)||u.startsWith("portal:"))?i.push(c):!d||p||e==="npm"&&/^[\w.-]+\/[\w.-]+(?:#.*)?$/.test(c)?a.push(c):r.index?l.push(`${d[1]} from ${r.index}`):n!=="run"&&tm.has(d[1].toLowerCase())&&(e==="npm"||e==="PyPI")||o.push(d[1])}return{reg:e,how:n,names:o,other:a,local:i,dir:s,from:l,...r.index?{index:r.index}:{}}}function im(e){let n=/^(@[\w.-]+)(?:\/([\w.-]+))?(@.*)?$/.exec(e);return n?`${n[1]}/create${n[2]?`-${n[2]}`:""}${n[3]??""}`:e.startsWith("create-")?e:`create-${e}`}var am="-p --package -c --call -w --workspace --registry --cache --userconfig --shell";function Rt(e,n,t,s=am,r=["-p","--package"]){let o=Ce(e,n,s,!0);if(o.opt("--no","--no-install")===!0)return null;let a=o.all(...r).flatMap(i=>i.split(","));return Ae(r[0]==="--from"||r[0]==="--spec"?"PyPI":"npm","run",a.length>0?a:o.ops.slice(0,1),null,{index:tn([...o.all(...ys),...t])})}var lm=new Set(["add","i","in","ins","inst","insta","instal","install","isnt","isnta","isntal","isntall","it","install-test"]),ac="--prefix -C --dir --cwd --filter -F --registry --tag --omit --include --cache --userconfig --loglevel --location --reporter",pc=e=>e==="npm"?`-w --workspace --before --cpu --os --libc --install-strategy ${ac}`:ac;function cm(e,n,t,s){let r=n[t]??"",o=pc(e),a=ct(s,"npm");if(e==="npm"&&(r==="exec"||r==="x")||(e==="pnpm"||e==="yarn")&&r==="dlx")return Rt(n,t+1,a);if(e==="bun"&&r==="x")return Rt(n,t+1,a,"--package -p --cwd");let i=Ce(n.slice(0,t),1,o);if(r==="create"&&e!=="npm"||e==="npm"&&/^(?:init|create|innit)$/.test(r)||e==="bun"&&r==="c"){let g=Ce(n,t+1,o),b=g.ops[0];return b?Ae("npm","run",[/^[\w.-]+\/[\w.-]+$/.test(b)&&e==="bun"?b:im(b)],null,{index:tn([g.opt("--registry"),i.opt("--registry"),...a])}):null}if(e==="npm"&&r==="pkg"&&n[t+1]==="set"){let g=Ce(n,t+2,o).ops.flatMap(k=>{let E=/^(?:dev|optional|peer)?[dD]ependencies(?:\.([^=]+)|\[["']?([^\]"']+)["']?\])?=(.*)$/.exec(k);return E?E[1]??E[2]?[[E[1]??E[2],E[3]]]:[[k,null]]:[]}),b=g.map(([k,E])=>E===null?k:`${k}@${E}`);return b.length>0?{...Ae("npm","add",b,null),declares:g.filter(([,k])=>k!==null).map(([k,E])=>`${k} ${E}`)}:null}let l=e==="yarn"&&r==="global",c=l?t+1:t,u=n[c]??"";if(!(e==="npm"?lm.has(u):u==="add"||u==="install"||u==="i"||e==="bun"&&u==="a"))return null;let d=Ce(n,c+1,o),f=d.opt("--prefix","-C","--dir","--cwd")??i.opt("--prefix","-C","--dir","--cwd"),h=l||[d,i].some(g=>g.opt("-g","--global")===!0||g.opt("--location")==="global");return Ae("npm",h?"machine":"add",d.ops,typeof f=="string"?f:null,{index:tn([d.opt("--registry"),i.opt("--registry"),...a])})}var hc="-r --requirement -c --constraint -e --editable -i --index-url --extra-index-url -f --find-links -t --target --prefix --root --src --upgrade-strategy --python-version --platform --only-binary --no-binary --progress-bar --log --cache-dir --proxy --timeout --retries --trusted-host -C --config-settings --python -p --extra --group",um="-e --editable -r --requirements --python --pypi-mirror --categories --extra-pip-args -i --index";function gc(e,n){let t=n.filter(s=>!wt.test(s));return{...e,other:[...e.other,...n.filter(s=>wt.test(s))],...t.length>0?{reads:t}:{}}}function mr(e,n,t,s=hc){let r=Ce(e,n,s),o=r.all("-e","--editable"),a=Ae("PyPI","add",[...r.ops,...o.filter(i=>wt.test(i))],null,{index:tn([...r.all(...ys),...t])});return gc({...a,local:[...a.local,...o.filter(i=>!wt.test(i))]},r.all("-r","--requirement","--requirements"))}var yr="--group --optional --package --extra --index --default-index --index-url --extra-index-url --find-links -f --python -p --branch --tag --rev --marker -m --script -r --requirements -c --constraints --config-file --cache-dir --directory --project --from --with --with-editable --with-requirements --env-file";function dm(e,n){let t=e[1],s=ct(n,"uv");if(t==="pip"&&e[2]==="install")return mr(e,3,s,`${hc} --index --default-index`);if(t==="tool"&&e[2]==="run")return Rt(e,3,s,yr,["--from"]);let r=Ce(e,2,yr,t==="run"),o=r.opt("--directory","--project"),a=tn([...r.all(...ys),...s]);if(t==="add")return gc(Ae("PyPI","add",r.ops,typeof o=="string"?o:null,{index:a}),r.all("-r","--requirements"));if(t==="tool"&&e[2]==="install"){let i=Ce(e,3,yr);return Ae("PyPI","machine",i.ops.slice(0,1),null,{index:tn([...i.all(...ys),...s])})}if(t==="run"){let i=r.all("--with").flatMap(l=>l.split(","));return i.length>0?Ae("PyPI","run",i,typeof o=="string"?o:null,{index:a}):null}return null}function fm(e){let n=[],t=[],s=[];for(let o=3;o<e.length;o++){let a=/^--?(replace|require)(?:=(.*))?$/s.exec(e[o]);if(!a)continue;let i=a[2]??e[++o]??"",l=i.indexOf("="),[c,u]=[i.slice(0,l).replace(/@.*$/s,""),i.slice(l+1)];a[1]==="require"?n.push(i):l>0&&u!==""&&u.replace(/@.*$/s,"")!==c&&(en.test(u)?s:t).push(`${c} from ${u}`)}let r=Ae("Go","add",n,null);return n.length+t.length+s.length>0?{...r,from:[...r.from,...t],local:[...r.local,...s],...n.length>0?{declares:n.map(o=>o.replace("@"," "))}:{}}:null}function pm(e,n){let t=Ce(e,n,"--working-dir -d --file -f"),[s="",r="",o=""]=t.ops;if(!/^repo(?:sitorie)?s?\./.test(s))return null;let a={type:r,url:o};if(r.startsWith("{"))try{a=JSON.parse(r)}catch{a={package:r}}let i=t.opt("--working-dir","-d"),l={reg:"Packagist",how:"add",names:[],other:[],from:[],local:[],dir:typeof i=="string"?i:null};return a.package!==void 0?{...l,other:[r]}:typeof a.url!="string"||a.url===""||cc.test(a.url)?null:a.type==="path"||a.type==="artifact"||rm(a.url)?{...l,local:[a.url]}:{...l,from:[a.url]}}var hm={brew:"Homebrew",apt:"apt","apt-get":"apt",aptitude:"apt",dnf:"dnf",yum:"yum",microdnf:"dnf",winget:"winget",choco:"Chocolatey",scoop:"Scoop"},lc="-c --config --repo --enablerepo --disablerepo --setopt --releasever --installroot -x --exclude",gm={Homebrew:"--cc --appdir",apt:"-t --target-release -o --option -c --config-file",dnf:lc,yum:lc,winget:"--id --name --moniker -q --query -v --version -s --source --scope -a --architecture -l --location -o --log --override --custom --locale",Chocolatey:"-s --source --version --params --package-parameters --ia --install-arguments -u --user -p --password",Scoop:"-a --arch"};function br(e,n,t=new Map){let s=n[1]??"";switch(e){case"npm":case"pnpm":case"yarn":case"bun":{let r=1;for(;r<n.length&&n[r].startsWith("-");)r+=` ${pc(e)} `.includes(` ${n[r]} `)?2:1;return e==="yarn"&&n[r]==="workspace"&&(r+=2),cm(e,n,r,t)}case"npx":case"pnpx":return Rt(n,1,ct(t,"npm"));case"corepack":{let r=/^(npm|npx|pnpm|pnpx|yarn|yarnpkg)(?:@\S*)?$/.exec(s)?.[1];return r?br(r==="yarnpkg"?"yarn":r,[r,...n.slice(2)],t):null}case"bunx":return Rt(n,1,ct(t,"npm"),"--package -p --cwd");case"uvx":return Rt(n,1,ct(t,"uv"),yr,["--from"]);case"pip":case"pip3":return s==="install"?mr(n,2,ct(t,"pip")):null;case"pipenv":return s==="install"?mr(n,2,ct(t,"pip"),um):null;case"uv":return dm(n,t);case"pipx":{if(s==="run")return Rt(n,2,ct(t,"pip"),"--spec --python --index-url --pip-args",["--spec"]);if(s!=="install"&&s!=="inject")return null;let r=Ce(n,2,"--python --index-url --pip-args --suffix --spec");return Ae("PyPI","machine",s==="inject"?r.ops.slice(1):r.ops,null,{index:tn([...r.all(...ys),...ct(t,"pip")])})}case"poetry":case"pdm":case"rye":{let r=e==="poetry"&&s==="self";if((r?n[2]:s)!=="add")return null;let o=Ce(n,r?3:2,`--group -G --extras -E --source --python --platform --markers --directory -C --project -P${e==="rye"?" --optional":""}`),a=o.opt("--directory","-C","--project","-P");return Ae("PyPI",r?"machine":"add",o.ops,typeof a=="string"&&!r?a:null)}case"cargo":{if(s!=="add"&&s!=="install")return null;let r=Ce(n,2,"-p --package -F --features --rename --registry --target --manifest-path --branch --tag --rev --git --path --config -Z --root --version --vers --index --bin --example --profile -j --jobs --target-dir"),o=Ae("crates.io",s==="add"?"add":"machine",r.ops,null),a=r.opt("--git"),i=r.opt("--path");return{...o,other:typeof a=="string"?[a]:o.other,names:typeof a=="string"||typeof i=="string"?[]:o.names,local:typeof i=="string"?[i]:o.local}}case"go":{if(s==="mod"&&n[2]==="edit")return fm(n);if(s!=="get"&&s!=="install"&&s!=="run")return null;let r=Ce(n,2,"-C -o -modfile -pkgdir -tags -toolexec -gcflags -ldflags -asmflags -overlay -p -exec").ops,o=(s==="run"?r.slice(0,1):r).filter(a=>!/@none$/.test(a)&&!/^(?:all|std|cmd)$/.test(a)&&!a.startsWith(".")&&(s==="get"||a.includes("@")));return Ae("Go",s==="get"?"add":s==="run"?"run":"machine",o,null)}case"gem":return s==="install"?Ae("RubyGems","machine",Ce(n,2,"-v --version -i --install-dir -n --bindir --source -s -P --trust-policy --platform -g --file --build-root").ops,null):null;case"bundle":case"bundler":{if(s!=="add")return null;let r=Ce(n,2,"-v --version --group -g --source -s --git --branch --ref --path --require -r --glob"),o=r.opt("--git"),a=r.opt("--path"),i=Ae("RubyGems","add",r.ops,null);return typeof o=="string"||typeof a=="string"?{...i,names:[],other:typeof o=="string"?[o]:[],local:typeof a=="string"?[a]:[]}:i}case"composer":{let r=s==="global";if((r?n[2]:s)==="config")return pm(n,r?3:2);if((r?n[2]:s)!=="require")return null;let o=Ce(n,r?3:2,"--working-dir -d"),a=o.opt("--working-dir","-d");return Ae("Packagist",r?"machine":"add",o.ops,typeof a=="string"?a:null,{skip:i=>!i.includes("/")&&!en.test(i)})}case"dotnet":{let r=n.indexOf("package");return s!=="add"||r<2?null:Ae("NuGet","add",Ce(n,r+1,"-v --version -f --framework -s --source --package-directory").ops.slice(0,1),null)}default:{if(/^(?:py|python(?:\d+(?:\.\d+)*)?)$/.test(e)){let i=n.indexOf("-m");return i>0&&n[i+1]==="pip"&&n[i+2]==="install"?mr(n,i+3,ct(t,"pip")):null}let r=hm[e];if(!r||s!=="install"&&!(e==="scoop"&&s==="add"))return null;let o=Ce(n,2,gm[r]),a=r==="winget"?o.opt("--id","--name","-q","--query"):void 0;return Ae(r,"machine",typeof a=="string"?[a,...o.ops]:o.ops,null,{skip:i=>i.startsWith("@")&&r!=="npm"})}}}function mc(e,n=!1){return e==="package.json"||e==="pnpm-workspace.yaml"?"npm":/^(?:requirements[\w.-]*\.(?:txt|in)|pyproject\.toml|Pipfile)$/.test(e)||n&&/^[^/\\]+\.(?:txt|in)$/.test(e)?"PyPI":e==="Cargo.toml"?"crates.io":e==="go.mod"||e==="go.work"?"Go":e==="Gemfile"?"RubyGems":e==="composer.json"?"Packagist":/\.(?:cs|fs|vb)proj$|^Directory\.Packages\.props$|^packages\.config$/.test(e)?"NuGet":null}var ut="git.worktree",Os="secrets.shown",mm="fs.outside",ym=["fs.root","fs.home","fs.system","fs.project_root","fs.git_dir","fs.device","git.main","proc.all"],bm=new Set(ym),gi={"claude.bash.fs.delete_recursive":10,"claude.bash.db.destructive":9,"claude.bash.git.force_push":9,"claude.bash.git.discard":8,"claude.bash.git.push_main":8,"claude.bash.deploy":8,"claude.bash.publish":7,"claude.bash.secrets.print":7,"claude.bash.privilege":7,"claude.file.write_secret":6,"claude.file.read_secret":6,"claude.file.outside_project":5,"claude.bash.process.kill_by_name":6,"claude.bash.external_write":6,"claude.bash.spend":6,"claude.bash.crypto.transaction":8,"claude.bash.secrets.expose":9,"claude.agent.controls":7,"claude.bash.net.expose":6,"claude.bash.data.export":6,"claude.bash.persistence":6,"claude.bash.deps.add":5,"claude.bash.prod.target":7,"claude.mcp.side_effect":6,"claude.bash.fs.delete_disposable":1,"claude.agent.helper":1,"claude.mcp.call":0,"claude.tool.other":0,"claude.bash.unclassified":0};var dt=new Set(["Write","Edit","MultiEdit","NotebookEdit"]),mi=new Set(["Read","Grep","NotebookRead"]),wm=new Set(["Agent","Task","Workflow"]),km=new Set(["Agent","Task"]),vm="claude.agent.helper";function Ru(e,n){return qn({tool:e.tool,command:e.command_local,target:e.target,cwd:e.cwd,git_branch:e.git_branch,project_dir:$m(e),session_id:e.session_id??null},n)}function $m(e){let n=e.source_file.split("/")[0];if(!n||!e.cwd)return null;for(let t=e.cwd;;t=O.dirname(t)){if(Ll(t)===n)return t;if(t==="/"||t==="."||t===O.dirname(t))return null}}function xm(e,n){let t=r=>typeof r=="string"&&r!==""?Ie(r):r??null,s=typeof e.target=="string"&&(dt.has(e.tool)||mi.has(e.tool))?Ge(e.target)??e.target:e.target;return{input:{...e,cwd:t(e.cwd),...e.project_dir===void 0?{}:{project_dir:t(e.project_dir)},target:s},ctx:{...n,home:Ie(n.home),tmpdir:Ie(n.tmpdir),claudeConfigDir:t(n.claudeConfigDir)}}}function qn(e,n){let{input:t,ctx:s}=Z()?xm(e,n):{input:e,ctx:n},r=typeof s.claudeConfigDir=="string"&&s.claudeConfigDir.startsWith("/")?re(s.claudeConfigDir):s.claudeConfigDir??null,o=s.home!==re(s.home)||s.tmpdir!==re(s.tmpdir)||(s.claudeConfigDir??null)!==r?{...s,home:re(s.home),tmpdir:re(s.tmpdir),claudeConfigDir:r}:s,a=F=>typeof F=="string"&&F.startsWith("/")?re(F):F??null,i=t.cwd!==a(t.cwd)||(t.project_dir??null)!==a(t.project_dir)?{...t,cwd:a(t.cwd),project_dir:a(t.project_dir)}:t,l=zm(i),c=o.production??[],u=new Map,p=(F,U=!1)=>{let X=F.action==="claude.bash.db.destructive";if(i.tool!=="Bash"||!i.command||!X&&F.action!=="claude.bash.deploy")return{};if(U)return{environment:null,environment_said:null};let z=X?Ko(i.command,F.target,F.host,c):u.get(F.host);return z||u.set(F.host,z=Zo(i.command,F.host,c)),{environment:z.environment,environment_said:z.said}},d=(F,U,X=[],z=[])=>{let G=F??{action:"claude.bash.unclassified",service:null,target:null,branch:null,host:null,is_local:null,why:"no rule applies"},ve=[...new Set([z.find(D=>D.catastrophic),z.find(D=>D.prod)])].filter(D=>D!==void 0&&z.indexOf(D)>15),ue=[...z.slice(0,16-ve.length),...ve],Se=D=>p(D,z.length>16),xe=D=>D.push&&z.length>16?{...D.push,repo_dir:null}:D.push;return{action:G.action,service:G.service,attributes:{target:G.target,branch:G.branch,host:G.host,is_local:G.is_local,args_hash:l,...Se(G),...xe(G),...js(G)},why:G.why,parse:U,also:X,...z.length>1?{findings:ue.map(D=>({action:D.action,service:D.service,target:D.target,why:D.why,...D.catastrophic?{catastrophic:!0}:{},...Se(D),...xe(D),...D.host?{host:D.host}:{},...D.prod?{prod:D.prod}:{},...js(D),...D.copy?{copy:!0}:{}}))}:{},...G.catastrophic?{catastrophic:!0}:{},...G.prod?{prod:G.prod}:{},...i.tool==="Bash"&&(G.action==="claude.bash.spend"||X.includes("claude.bash.spend"))?{units:Sl(i.command)}:{},...(z.length>1?z.filter(D=>D.action===G.action).every(D=>D.housekeeping):G.housekeeping)?{housekeeping:!0}:{},...(z.length>1?z.filter(D=>D.action===G.action).every(D=>D.copy):G.copy)?{copy:!0}:{}}},f=i.tool;if(km.has(f))return d(Mm(i.args),"not-shell");if(wm.has(f))return d(ei(f,"a subagent or workflow launch (its text is never read)"),"not-shell");if(f.startsWith("mcp__")){let F={hit:!1},U=sy(i,o,F);return U.also&&U.also.length>0?d(U,F.hit?"limited":"not-shell",[...new Set(U.also.filter(X=>X!==U.action))]):d(U,F.hit?"limited":"not-shell")}if(dt.has(f)||mi.has(f)){let F=i.target??qm(i.args),U=F!==null&&Z()?Ge(F)??F:F,X=[i.cwd,i.project_dir??null].find(H=>typeof H=="string"&&H.startsWith("/")&&!S(H))??null,z=U?U.startsWith("/")||U.startsWith("~")?M(U,null,o):X!==null?M(U,X,o):null:null,G=H=>({...H,attributes:{...H.attributes,path:z!==null&&z.startsWith("/")&&!S(z)?z:null}});if(U&&dt.has(f)&&Z()&&/^\/dev\/(?!(?:null|stdout|stderr|tty)$)/.test(U)&&!ts(U))return G(d({action:"claude.bash.fs.delete_recursive",service:"fs.device",target:U,branch:null,host:null,is_local:!0,why:`writes a raw disk or volume (${U})`},"not-shell"));let ve=U&&dt.has(f)?Es(U,o,[i.project_dir??null,i.cwd]):null;if(ve)return G(d(ve,"not-shell"));if(U&&dt.has(f)&&sf(U,o)&&nf.test(ou(i.args)))return G(d({action:"claude.agent.controls",service:null,target:U,branch:null,host:null,is_local:!0,why:`gives a subagent, command or skill its own bypass or unrestricted shell (${O.basename(U)})`},"not-shell"));if(U&&dt.has(f)&&($t.test(U)||$t.test(Ik(U,o)))&&(Mn(ou(i.args))||Mn(JSON.stringify(i.args??""))))return G(d({action:"claude.agent.controls",service:null,target:U,branch:null,host:null,is_local:!0,why:`changes how every later Claude Code session starts (${O.basename(U)})`},"not-shell"));if(z!==null&&mi.has(f)&&!S(z)&&vf(z,o.home,f==="Grep"))return G(d({action:"claude.agent.controls",service:null,target:z,branch:null,host:null,is_local:!0,why:kf},"not-shell"));let ue=z!==null&&dt.has(f)?ea(z,f==="Write"?"w":"e",o,i.project_dir??null,!0):null,Se=f==="Grep"&&oi(i.args)?Qw(i.args,z??X):null;if(Se!==null)return G(d({action:"claude.file.read_secret",service:Os,target:Se,branch:null,host:null,is_local:!0,why:`reads a secrets file (${O.basename(Se)})`},"not-shell"));if(U&&(dt.has(f)?Re(U):Je(U))){let H=dt.has(f),ye=!H&&(f!=="Grep"||oi(i.args)),ne={action:H?"claude.file.write_secret":"claude.file.read_secret",service:ye?Ve(U):null,target:U,branch:null,host:null,is_local:!0,why:`${H?"writes":"reads"} a secrets file (${O.basename(U)})`};return G(ue?d(ne,"not-shell",[ue.action],[ne,ue]):d(ne,"not-shell"))}let xe=f==="Grep"&&oi(i.args)?ek(i.args,z??X,X,o):null;if(xe)return G(d(xe,"not-shell"));let D=z!==null&&dt.has(f)&&f!=="NotebookEdit"&&!S(z)?gy(z,i.args,o,i.project_dir??null):null;return G(D?ue?d(D,"not-shell",[ue.action],[D,ue]):d(D,"not-shell"):d(ue??ei(f,`${f} of a regular file`),"not-shell"))}if(f==="PowerShell"&&i.command){let F=pn(i.command,{cwd:i.cwd!==null?pt(i.cwd):null});return F.kind==="unreadable"?d(w("claude.bash.privilege",`runs PowerShell Anvil can't read (${F.why})`,{target:i.command.slice(0,200),is_local:null}),"partial"):qn({...i,tool:"Bash",command:F.text},{...o,powershell:!0})}if(f!=="Bash"||!i.command)return d(ei(f,`the ${f} tool`),"not-shell");let h=i.project_dir??null,g=At(i.command,{home:o.home,tmpdir:o.tmpdir,cwd:i.cwd,projectDir:h,claudeConfigDir:o.claudeConfigDir??null,...ji(o)}),b={ctx:o,projectRoot:h,base:i.cwd,branch:i.git_branch,branchDir:i.cwd,createdBranches:new Map,stashApplied:new Map,stashCreated:!1,sessionId:i.session_id??null,lineText:i.command,lineMade:[],lineLaunched:[],secretCopies:new Set,links:new Map,downloads:new Set,cut:{hit:!1}},k=[],E=new Map;b.lineCommands=g.commands,b.lineWhole=g.status==="complete";for(let F of g.commands){_b(F,b);for(let U of Ps(F,b)){let X=Gw(U,F);E.set(X,F),k.push(X)}rn(b,()=>Fm(F,b)),Pm(F,b),Wm(F,b),Nm(F,b)}jm(i.command)&&k.push(w("claude.agent.controls","runs a command without Claude Code's session marker (CLAUDECODE), which Anvil uses to tell this session from the person's own terminal",{target:"CLAUDECODE",is_local:!0})),(oc(i.command,c)||k.some(F=>p(F).environment==="production"))&&lb(k,E,g.commands,i.command,c);let y=b.cut.hit?"limited":g.status;if(k.length===0)return d(null,y);let m=[...k].sort((F,U)=>bc(U)-bc(F)),R=m[0],v=[...new Set(m.slice(1).map(F=>F.action).filter(F=>F!==R.action&&gi[F]>1))],C=d(R,y,v,m.filter(F=>gi[F.action]>1)),N=R.is_local===!0||R.host!==null&&hd.test(R.host),q=_m.has(R.action)&&R.catastrophic!==!0&&!R.housekeeping&&!N?Em(i.args,R.target==="no server shown"):null;if(q===null)return C;let V={why:`${C.why} (Claude's description says ${q})`,catastrophic:!0,described:!0};return{...C,...V,...C.findings?{findings:C.findings.map((F,U)=>U===0?{...F,...V}:F)}:{}}}var _m=new Set(["claude.bash.deploy","claude.bash.db.destructive","claude.bash.external_write","claude.bash.git.push_main","claude.bash.git.force_push","claude.bash.publish","claude.bash.secrets.print","claude.bash.secrets.expose","claude.bash.data.export","claude.bash.crypto.transaction","claude.bash.spend","claude.bash.net.expose"]),Sm=/(?<![A-Za-z0-9])(?<!(?:non|pre|not|no|un)[\s_-]?)(?:(?:prod|production)(?![A-Za-z0-9])(?![\s_-]+(?:build|bundle|ready|grade|quality|mode|deps|dependencies|code|like|image|assets|shape|parity|optimi[sz]\w*)\b)|go(?:es|ing)?[\s-]+live\b|went[\s-]+live\b|live[\s-]+(?:site|app|application|environment|env|database|db|cluster|servers?|system|stack|account|customers?|users?|traffic|instance|deployment|mode|store|services?|keys?)\b)/i,Cm=/\b(?:drop|wipe|truncate|destroy|erase|purge|nuke|delete)\w*\s+(?:(?:the|all|every|entire|whole)\s+)*(?:(?:all|every|entire|whole)\s+(?:\w+\s+)?(?:tables|databases?|dbs?|schemas?|collections|keyspaces?|clusters?)|(?:database|db|cluster)\b(?![.-]\w)(?!\s+(?:file|connection|client|config|entry|row|record|column|migration|pod|node|member|replica|shard|user|role|secret|namespace|context)s?\b))/i,Am=/\b(local|localhost|dev|development|test|testing|tests|sandbox|scratch|temp|tmp|throwaway)\b/i;function Em(e,n=!1){let t=e!==null&&typeof e=="object"?e.description:void 0;if(typeof t!="string")return null;let s=Math.min(t.length,500);if(t.length>500)for(;s>0&&/[A-Za-z0-9_]/.test(t[s-1]);)s--;let r=t.slice(0,s),o=r.toLowerCase();return(o.includes("prod")||o.includes("prd")||o.includes("live"))&&Sm.test(r)?"production":!n&&["drop","wipe","truncate","destroy","erase","purge","nuke","delete"].some(a=>o.includes(a))&&Cm.test(r)&&!Am.test(r)?"a whole database or cluster is wiped":null}var Rm=/(^|\/)\.git\/(worktrees\/[^/]+\/)?((logs|refs)(\/|$)|(packed-refs|HEAD|ORIG_HEAD|FETCH_HEAD)$)/,bs="(?:CLAUDECODE|CLAUDE_CODE_ENTRYPOINT)",wr=String.raw`(?:^|[;&|(\n{]\s*|\$\(\s*)(?:(?:nohup|sudo|exec|command|time|nice|builtin)\s+)*`,Om=new RegExp([String.raw`${wr}(?:(?:export|declare\s+-x|typeset\s+-x|local|readonly)\s+)?(?:[A-Za-z_][A-Za-z0-9_]*=\S*\s+)*(?:CLAUDECODE=(?!1(?:[\s;&|)]|$))|CLAUDE_CODE_ENTRYPOINT=)`,String.raw`${wr}setenv\s+${bs}\b`,String.raw`${wr}unset\s+(?:-[vf]\s+)?(?:\w+\s+){0,8}${bs}\b`,String.raw`${wr}env\s+(?:\S+\s+){0,8}?(?:-u\s*${bs}\b|--unset[=\s]\s*${bs}\b|CLAUDECODE=(?!1(?:\s|$))|CLAUDE_CODE_ENTRYPOINT=)`,String.raw`(?:del\s+os\.environ|delete\s+process\.env|environ\.pop|unsetenv|Remove-Item\s+Env:)[^;\n]{0,24}${bs}`].join("|"));function jm(e){return Om.test(e.slice(0,65536))}function ji(e){return{knownFiles:e.session?.scripts??null,unreadableFiles:e.session?.unreadableScripts??null,wantFiles:e.wantScripts??null}}function cn(e,n,t,s=t.projectRoot){let r=At(e,{home:t.ctx.home,tmpdir:t.ctx.tmpdir,cwd:n,projectDir:s,claudeConfigDir:t.ctx.claudeConfigDir??null,...ji(t.ctx)});return r.status==="limited"&&(t.cut.hit=!0),r}function Ou(e,n){let t=n.lineMade.length+n.lineLaunched.length>0?{...n.ctx,session:{...n.ctx.session??{made:[],launched:[]},made:Pu(n),launched:ju(n)}}:n.ctx,s=qn(e,{...t,nested:!0});return s.parse==="limited"&&(n.cut.hit=!0),s}var yc=200;function ft(e,n){return e.length>yc&&(n.hit=!0),e.slice(0,yc)}function Pm(e,n){let t=e.argv;if(e.name!=="ln"||!t.slice(1).some(l=>/^-[a-zA-Z]*s/.test(l)||l==="--symbolic"))return;let s=t.findIndex(l=>l==="--target-directory"||/^-[a-zA-Z]*t$/.test(l)),r=s>0?t[s+1]:t.find(l=>l.startsWith("--target-directory="))?.slice(19),o=t.slice(1).filter((l,c)=>!l.startsWith("-")&&c+1!==s+1&&!["-S","--suffix"].includes(t[c]??""));if(o.some(S)||r!==void 0&&S(r))return;let a=(l,c)=>O.normalize(te(l,c,le(n)).path??l),i=r!==void 0?o.map(l=>[l,O.join(r,O.basename(l))]):o.length===1?[[o[0],O.basename(o[0])]]:o.length===2?[[o[0],o[1]]]:[];for(let[l,c]of i){let u=a(c,e.cwd);n.links.set(u,a(l,O.dirname(u)))}}function Wm(e,n){if(!qr.has(e.name))return;let t=e.argv,s=t.find(a=>Tn(a));if(!s||qe(s))return;let r=e.name==="wget"?["-O","--output-document"]:["-o","--output"],o=t.find((a,i)=>r.includes(t[i-1]??""))??t.find(a=>a.startsWith(`${r[1]}=`))?.split("=")[1];o&&!S(o)&&o!=="-"&&n.downloads.add(te(o,e.cwd,le(n)).path)}function Nm(e,n){if(n.lineMade.length+n.lineLaunched.length>64)return;let t=Do(e,{home:n.ctx.home,tmpdir:n.ctx.tmpdir,projectDir:n.projectRoot});n.lineMade.push(...t.paths),n.lineLaunched.push(...t.launched)}function ju(e){let n=e.ctx.session?.launched??[];return e.lineLaunched.length>0?[...n,...e.lineLaunched]:n}function Pu(e){let n=e.ctx.session?.made??[];return e.lineMade.length>0?[...n,...e.lineMade]:n}function je(e,n){let t=e.ctx.session?.probed,s=ls(n);if(t&&s in t)return t[s]??null;e.ctx.wantProbes?.set(s,n)}function Wu(e){let n=e.ctx.session?.startedAt;return typeof n=="number"&&n>0?n-1e3:null}function Nu(e){let n=r=>{if(!r||S(r)||re(r)===re(e.ctx.home))return null;let o=je(e,{kind:"file",arg:r});return typeof o=="string"?o.split(" ")[0]:o},t=n(e.base),s=e.projectRoot?n(e.projectRoot):null;return t===void 0||s===void 0?null:{here:t,project:s}}function Lm(e,n,t){let s=o=>o.replace(/^\/private(?=\/(?:var|tmp)\/)/,""),r=s(e);return jn(r,n.here&&s(n.here))||jn(r,n.project&&s(n.project))||(t.ctx.session?.made??[]).some(o=>jn(r,s(o)))}var Dt=e=>e.wrappers.some(n=>["sudo","doas","pkexec","run0"].includes(n)),jn=(e,n)=>!!n&&(e===n||e.startsWith(`${n}/`));function Pi(e){let n=je(e,{kind:"ps"});if(typeof n!="string")return null;let t=new Map;for(let s of n.split(`
|
|
37
|
+
`)){let r=/^\s*(\d+)\s+(\d+)\s+(.*)$/.exec(s);r&&t.set(r[1],{ppid:r[2],command:r[3]})}return t.size>0?t:null}function Hr(e,n,t,s=0){let r=t.ctx.session?.launched??[],o=n.get(e);if(!o||r.length===0||s>8)return!1;if(Ol(o.command,r)&&(Pl(o.command,r)||Fo(o.command,r))||Wl(o.command,r)){let i=je(t,{kind:"cwd",arg:e}),l=Nu(t);if(typeof i=="string"&&l&&Lm(i,l,t))return!0}return o.ppid!=="0"&&o.ppid!=="1"&&o.ppid!==e&&Hr(o.ppid,n,t,s+1)}function Lu(e,n){let t=Pi(n);return t!==null&&(!t.has(e)||Hr(e,t,n))}function Tm(e,n,t){return Tu(e,n,t)==="own"}function Tu(e,n,t){let s=Pi(t);if(!s||e.length===0)return null;let r=!1;return e.every(a=>{let i=a.replace(/^["']|["']$/g,"");if(i===""||S(i)||/\\[A-Za-z]|\[:/.test(i))return!1;let l;try{l=new RegExp(n.exact?`^${i.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}$`:i,n.fold?"i":"")}catch{return!1}let c=[...s].filter(([,p])=>l.test(n.full?p.command:(p.command.split(/\s/)[0]??"").split("/").pop()));if(c.length===0)return n.full&&!n.exact&&/^[\w./ :=@,-]+$/.test(i);let u=c.slice(0,16).filter(([p])=>Hr(p,s,t));return u.length>0&&(r=!0),c.length<=16&&u.length===c.length})?"own":r?"some":null}function Du(e,n){let t=null,s=!1;for(let l=0;l<e.length;l++){let c=e[l],u=/^-([nPtw]*)i(.*)$/.exec(c);if(u){u[1].includes("t")&&(s=!0);let p=/^(?:tcp|udp)?:(\d{2,5})$/i.exec(u[2]!==""?u[2]:e[++l]??"");if(!p||t!==null)return null;t=p[1]}else if(/^-[nPtw]+$/.test(c))c.includes("t")&&(s=!0);else return null}if(t===null||!s)return null;let r=je(n,{kind:"port",arg:t}),o=Pi(n);if(typeof r!="string"||!o)return null;let a=[...new Set(r.split(`
|
|
38
|
+
`).map(l=>l.trim()).filter(l=>/^\d+$/.test(l)))];if(a.length===0)return"own";let i=a.filter(l=>Hr(l,o,n));return i.length===a.length?"own":i.length>0?"some":null}function Dm(e,n,t){let s=Wu(t);if(/\bbranch\b[^;&|\n]*\s(-[a-zA-Z]*[mMcC][a-zA-Z]*|--move|--copy)(\s|$)/.test(t.lineText)||s===null||!n||!/^[\w./-]+$/.test(e)||e.startsWith("-"))return!1;let r=je(t,{kind:"branch",arg:e,cwd:n}),o=typeof r=="string"?r.trim().split(`
|
|
39
|
+
`).pop()??"":"",a=/@\{(\d+)\} branch: Created from /.exec(o);return a!==null&&Number(a[1])*1e3>=s}function Iu(e,n){return je(n,{kind:"ignored",arg:e,cwd:O.dirname(e)})===""}function Im(e,n){if(S(e))return null;let t=Wu(n),s=je(n,{kind:"file",arg:e}),r=Nu(n),o=Iu(e,n);if(typeof s!="string"||!r||!o)return null;let[a,i]=s.split(" ");return!jn(a,r.here)&&!jn(a,r.project)?null:t!==null&&Number(i)>=t?"own":"dev"}function De(e,n,t){if(t.links.size===0||S(e))return e;let s=e.startsWith("/")?e:e.startsWith("~/")?t.ctx.home+e.slice(1):n.cwd?`${n.cwd}/${e}`:e;if(!s.startsWith("/"))return e;let r=s.split("/").filter(i=>i!==""),o="/",a=!1;for(let[i,l]of r.entries()){if(l===".")continue;o=l===".."?O.dirname(o):O.join(o,l);let c=i===r.length-1&&!s.endsWith("/");for(let u=0;!c&&u<8&&t.links.has(o);u++)o=t.links.get(o),a=!0}return a?o+(s.endsWith("/")?"/":""):e}function Fm(e,n){let t=e.argv.slice(1).filter(a=>!a.startsWith("-")),s=a=>n.secretCopies.add(te(a,e.cwd,le(n)).path);if(["cp","mv","install","ditto","rsync"].includes(e.name)&&t.length>=2&&t.slice(0,-1).some(a=>Re(a)||n.secretCopies.has(te(a,e.cwd,le(n)).path))&&s(t[t.length-1]),e.name==="cat"&&t.some(a=>Re(a)))for(let a of e.redirects)(a.op===">"||a.op===">>")&&a.target&&s(a.target);let r=[];for(let a=1,i=!1;a<e.argv.length;a++){let l=e.argv[a];if(["--exclude","--exclude-from","-X"].includes(l))a++;else{if(l.startsWith("--exclude"))continue;e.name==="zip"&&(l==="-x"||l==="--exclude")?i=!0:l.startsWith("-")?i=!1:i||r.push(l)}}if(["tar","gtar","bsdtar","zip","7z"].includes(e.name)&&r.some(a=>Re(a)||/(^|\/)\.(ssh|aws|gnupg|kube)\/?$/.test($(a)))){let a=/^[A-Za-z]+$/.test(e.argv[1]??"")&&(e.argv[1]??"").includes("f")?e.argv[2]:void 0,i=P(e.argv,"-f","--file")??Or(e.argv,"f")??a??(e.name==="zip"||e.name==="7z"?t.find(l=>/\.(zip|7z)$/.test(l)):t[0]);i&&s(i)}let o=e.stdinFile!==null&&Re(e.stdinFile)||e.pipeFrom!==null&&e.pipeFrom.name==="cat"&&e.pipeFrom.argv.slice(1).some(a=>Re(a));if(e.name==="tee"&&o)for(let a of t)s(a)}function bc(e){return(e.service&&bm.has(e.service)?100:0)+gi[e.action]}function Mm(e){let n=e&&typeof e=="object"?e:{},t=typeof n.subagent_type=="string"&&n.subagent_type.trim()?n.subagent_type.trim():"general-purpose",s=/^[A-Za-z0-9_.:-]{1,64}$/.test(t)?t:`type-${Eu("sha256").update(t).digest("hex").slice(0,8)}`,r=typeof n.model=="string"&&/^[a-z0-9.\-[\]]{1,40}$/i.test(n.model)?n.model:null;return{action:vm,service:null,target:s,branch:null,host:null,is_local:null,why:`launches a helper agent (${s}${r?`, ${r}`:""})`}}function ei(e,n){return{action:"claude.tool.other",service:null,target:e,branch:null,host:null,is_local:null,why:n}}function zm(e){if(e.args===void 0&&e.command===null&&e.tool.startsWith("mcp__"))return null;let n=e.args!==void 0?yi(e.args):e.command??e.target??"";return Eu("sha256").update(JSON.stringify([e.tool,n])).digest("hex").slice(0,16)}var Um=64;function yi(e,n=0){return n>Um?"[nested too deep]":Array.isArray(e)?e.map(t=>yi(t,n+1)):e&&typeof e=="object"?Object.fromEntries(Object.keys(e).sort().map(t=>[t,yi(e[t],n+1)])):e}function qm(e){if(!e||typeof e!="object")return null;let n=e;for(let t of["file_path","notebook_path","path"])if(typeof n[t]=="string")return n[t];return null}var ks=new Set(["ask","get","list","search","read","fetch","find","query","describe","view","show","lookup","check","count","browse","preview","inspect","status","info","details","stats","history","logs","index","guide","help","export","download","screenshot","validate","diff","compare","estimate","explain","summarize","extract","scrape","research","retrieve","whoami","analyze","analyse","aggregate","size","health","usage","schema","metadata","metrics","overview","summary","parse"]),Lt=new Set(["send","reply","forward","post","publish","deploy","merge","delete","remove","destroy","purge","trash","wipe","drop","purchase","buy","pay","payout","refund","charge","transfer","withdraw","cancel","revoke","archive","unpublish","create","update","write","insert","append","upload","share","grant","execute","exec","upsert","submit","invite","modify","patch","put","replace","schedule","approve","provision","trigger","enable","disable","assign","import","add","set","close","stop","scale","rollout","transition","restore","invoke","fork","move","rename","clear","discard","clean","edit","run","change","save","store","commit","push","start","restart","pause","resume","reopen","resolve","mark","pin","unpin","react","star","follow","subscribe","unsubscribe","link","unlink","attach","detach","lock","unlock","block","ban","mute","duplicate","copy","sync","apply","rebase","draft","notify","reserve","register","claim","redeem","capture","void","mint","broadcast","swap","stake","activate","deactivate","suspend","reset","rotate","generate","train","launch","spawn","kill","terminate","reboot","shutdown","setup","manage","configure","initialize","init","install","uninstall","upgrade","migrate","seed","reindex"]),Tt=new Set(["delete","remove","destroy","purge","trash","wipe","drop","terminate","reset","flush","rollback","revert","rotate","revoke","kill","truncate","erase","push","apply","merge","deploy","publish","refund","charge","pay","payout","transfer","clear","restore","discard"]),Hm=/^(ccd_(turn|view|window|sidebar|session|directory)|visualize|claude_browser|claude_in_chrome|computer_use)$/,Bm=/^ccd_pr__(set_monitor|bind_pr|unbind_pr|get_status)$/,wc=/^(playwright|puppeteer|browser|browsermcp|browser_use|chrome_devtools|chrome|everything|filesystem|fs|files|desktop_commander|desktopcommander|git|docker|sqlite)$/,Vm=/^(memory|sequential_thinking|sequentialthinking|time)$/,Gm=new Set(["push","delete","clean","force","rebase","prune","gc","filter"]),Zm=new Set(["env","environment","secret","secrets","credential","credentials","password","passwords"]),Km=new Set(["backups","deployments","releases","migrations","payments","payouts","refunds","transfers","charges","subscriptions","jobs","runs","builds","workflows","stacks","instances","clusters","resources","records","messages","emails","invites","invitations","webhooks","keys","tokens","secrets","domains","dns","databases","tables","volumes","buckets","users","members","roles","permissions"]),Ym=new Set(["hget","hgetall","hexists","hkeys","hvals","hlen","lrange","llen","lindex","smembers","sismember","scard","zrange","zscore","zcard","exists","ttl","pttl","type","dbsize","xrange","xlen","mget","scan","keys"]),Jm=/^(context7|brave_search|brave|fetch|deepwiki|ref|microsoft_docs|aws_docs|mcp_registry)$/,Xm=/^(filesystem|fs|files|desktop_commander|desktopcommander)$/;function Fu(e){return e.replace(/([a-z0-9])([A-Z])/g,"$1_$2").toLowerCase().split(/[^a-z0-9]+/).filter(Boolean)}function Ar(e){let n=Fu(e);if(n.length===0)return"unknown";let t=n[0],s=n[n.length-1],r=n.find(a=>ks.has(a)||Lt.has(a)||Tt.has(a))??t;return n.some(a=>Tt.has(a))&&!ks.has(r)||n.findIndex((a,i)=>i>0&&["or","and","then"].includes(a)&&n.slice(i+1).some(l=>Lt.has(l)||Tt.has(l)))>0?"write":ks.has(r)||ks.has(s)&&!n.slice(0,-2).some(a=>Lt.has(a))&&!Lt.has(t)?"read":n.some(a=>Lt.has(a))?"write":n.length===1&&Ym.has(t)||n.length>1&&/[a-z]{3}s$/.test(s)&&!/(ss|us|is)$/.test(s)&&!Km.has(s)?"read":"unknown"}function Qm(e){return e.length===1?["bash","shell","terminal","sh","zsh"].includes(e[0]):(e.includes("write")||e.includes("send"))&&e.includes("terminal")||e.includes("bash")&&e.includes("command")?!0:e.some(n=>["run","exec","execute","start","interact"].includes(n))&&e.some(n=>["command","commands","terminal","shell","script","cmd","bash","process"].includes(n))}function ey(e){let n=e.args!==void 0?e.args:e.command?Mu(e.command):void 0;return n&&typeof n=="object"&&!Array.isArray(n)?n:null}function Mu(e){try{return JSON.parse(e)}catch{return}}function Cn(e,n){for(let t of n)if(e&&typeof e[t]=="string")return e[t];return null}function ti(e){if(!e)return[];let n=[];for(let t of["path","file_path","filePath","relative_path","relativePath","pathInProject","repo_path","repoPath","source","destination","target","targetPath","sourcePath","destinationPath","file","filename","dest","from","to","old_path","new_path","oldPath","newPath","paths","files"]){let s=e[t];if(typeof s=="string")n.push(s);else if(Array.isArray(s))for(let r of s.slice(0,64))typeof r=="string"&&n.push(r)}return Z()?n.map(t=>Ge(t)??t):n}function zu(e,n){if(e.action==="claude.bash.unclassified")return[];let t={action:e.action,service:e.service,target:e.attributes.target,branch:e.attributes.branch,host:e.attributes.host,is_local:e.attributes.is_local,why:`${e.why} ${n}`};return[{...t,...js(e.attributes)},...e.also.filter(s=>s!==e.action).map(s=>({...t,action:s,service:null,...js(e.findings?.find(r=>r.action===s))}))]}var js=e=>e?.op?{op:e.op,...e.lands?{lands:e.lands}:{}}:{},ty=new Set(["supabase","neon","planetscale","turso","bigquery","snowflake","databricks","motherduck","xata","cloudflare","d1","upstash","spanner","redshift","tinybird","firebase","railway","render","heroku","vercel","nile","tidb","aiven","aws","azure","gcp"]),ny=/^(database|db|database_?name|db_?name|branch|branch_?name|branch_?id|project|project_?id|project_?ref|env|environment|schema|catalog|dataset|instance)$/i;function sy(e,n,t){let[,s="",r=""]=e.tool.split("__"),o=vc(s),a=`mcp.${o}.${vc(r)}`,i=Fu(r),l=ey(e),c=d=>({action:"claude.mcp.call",service:null,target:a,branch:null,host:o,is_local:null,why:d}),u=d=>({action:"claude.mcp.side_effect",service:null,target:a,branch:null,host:o,is_local:null,why:d});if(Qm(i)||Cn(l,["cli_command"])!==null){let d=l?.action_json,f=typeof d=="string"?Mu(d):d,h=Cn(l,["command","cmd","script","input","code","cli_command"])??Cn(f&&typeof f=="object"&&!Array.isArray(f)?f:null,["command","cmd"]);if(h===null)return u(`an MCP tool that runs shell commands, with no command to read (${a})`);let g=Cn(l,["cwd","workdir","directory"])??e.cwd,b=qn({tool:"Bash",command:h,target:null,cwd:g,git_branch:e.git_branch,project_dir:e.project_dir??null,session_id:e.session_id??null},{...n,nested:!0});return b.parse==="limited"&&(t.hit=!0),bf(h,g,n,e.project_dir??null,t,i.includes("terminal"))?b.action==="claude.bash.unclassified"?c(`an MCP tool running a command no rule flags (${a})`):{action:b.action,service:b.service,target:b.attributes.target,branch:b.attributes.branch,host:b.attributes.host,is_local:b.attributes.is_local,why:`${b.why} (run by ${a})`,also:b.also,...js(b.attributes)}:{action:"claude.agent.controls",service:null,target:a,branch:null,host:o,is_local:!0,why:`hands a command to ${a}, which may run it outside this session, and Anvil cannot read that command here`}}if(Ar(r)!=="read"){let d=ti(l).map(h=>Es(h,n,[e.project_dir??null,e.cwd])).filter(h=>h!==null),f=d.find(h=>h.action==="claude.agent.controls")??d[0];if(f)return{...f,host:o,also:[...new Set(d.map(h=>h.action))]};for(let h of ti(l))if($t.test(h)&&Mn(JSON.stringify(l)))return{action:"claude.agent.controls",service:null,target:h,branch:null,host:o,is_local:!0,why:`changes how every later Claude Code session starts (${O.basename(h)}, through ${a})`}}if(Xm.test(o))if(Ar(r)==="read"){let f=ti(l).find(g=>Je(g)),h=i.some(g=>["read","cat","view","content","contents","head","tail","open","show"].includes(g))&&!i.some(g=>["info","stat","stats","metadata","list","tree","search","find","exists","size"].includes(g));if(f)return{action:"claude.file.read_secret",service:h?Ve(f):null,target:f,branch:null,host:o,is_local:!0,why:`reads a secrets file (${O.basename(f)}) through ${a}`}}else{let f=Cn(l,["path","file_path","filePath","destination","target"]);if(f&&Re(f))return{action:"claude.file.write_secret",service:null,target:f,branch:null,host:o,is_local:!0,why:`writes a secrets file (${O.basename(f)}) through ${a}`}}if(i.some(d=>["sql","query"].includes(d))&&i.some(d=>["run","execute","exec","query"].includes(d))){let d=Cn(l,["sql","query","statement"]);if(d!==null&&!(Gr.test(d)||Ee.test(d)))return c(`an MCP tool running a read-only query (${a})`);let f=On(d),h=o.split("_").some(b=>ty.has(b))&&!o.split("_").includes("local"),g=f===null?void 0:[...Object.entries(l??{}).filter(([b,k])=>ny.test(b)&&typeof k=="string"&&k.length<200&&!/\s/.test(k)).map(([,b])=>b)].find(Kr);if(d!==null)return f!==null&&(h||g!==void 0)?{...u(`an MCP tool running destructive SQL (${f}) on ${g!==void 0?`${g}, named for production`:`${o}'s hosted database`} (${a})`),catastrophic:!0}:u(`an MCP tool running SQL that writes (${a})`)}if((i.includes("sql")||i.includes("query")&&i.some(d=>["database","db","d1","sql"].includes(d)))&&!wc.test(o))return u(`an MCP tool that runs SQL, with no statement to read (${a})`);if(Bm.test(`${o}__${r}`))return c(`a setting of this machine's own app (${a})`);if(Hm.test(o)){let d=i.find(f=>["upload","send","submit","purchase","buy","publish"].includes(f));return d?u(`a browser tool that ${d}s something to a website (${a})`):c(`a tool of this machine's own app (${a})`)}if(Vm.test(o))return c(`the agent's own notes or thinking (${a})`);let p=Ar(r);if(i.some(d=>Zm.has(d))&&p!=="write")return u(`an MCP tool that reads secrets or the environment (${a})`);if(Jm.test(o)){let d=i.find(f=>Tt.has(f)||["upload","send","submit","publish","post","create","update","write"].includes(f));return d?u(`an MCP tool that ${d}s (${a})`):c(`a documentation tool (${a})`)}if(wc.test(o)){let d=o==="git"?i.find(h=>Gm.has(h)):i.find(h=>Tt.has(h));if(d&&!ks.has(i[0]??""))return u(`a local MCP tool that ${d}s (${a})`);if(o==="docker"&&i.some(h=>["run","exec","execute"].includes(h)))return u(`a local MCP tool that runs a container or a command in one (${a})`);let f=i.find(h=>["upload","send","submit","purchase","buy","publish","post"].includes(h));return f?u(`a local MCP tool that ${f}s something to another service (${a})`):p==="write"&&i.some(h=>["config","configuration","settings","setting","permission","permissions","policy"].includes(h))?u(`a local MCP tool that changes its own configuration (${a})`):c(`a tool that acts on this machine (${a})`)}return p==="read"?c(`an MCP tool that reads (${a})`):cy(i,l)?c(`an MCP edit to a document's content (${a})`):p==="unknown"&&["profile","me","whoami"].includes(i[i.length-1]??"")&&!i.some(d=>Lt.has(d)||Tt.has(d))?c(`an MCP tool that returns the caller's profile (${a})`):u(p==="write"?`an MCP tool that ${i.find(d=>Tt.has(d))??i.find(d=>Lt.has(d))}s (${a})`:`an MCP tool whose name does not say it only reads (${a})`)}var ry=new Set(["update","edit","append","insert","write","replace","patch","save","create","batch","add","set","modify","change","draft","rename"]),oy=new Set(["doc","docs","document","documents","page","pages","block","blocks","note","notes","section","sections","tab","tabs","paragraph","paragraphs","wiki","article","articles","markdown","prose"]),iy=new Set(["delete","remove","destroy","purge","trash","archive","share","unshare","publish","unpublish","send","post","comment","invite","grant","permission","permissions","move","transfer","email","notify","export"]),ay=/^(share|shares|sharing|shared_with|permission|permissions|visibility|public|is_public|publish|published|invite|invites|invitees|recipient|recipients|to|cc|bcc|email|emails|role|roles|grant|grants|notify|send|send_notification|acl|access|access_level|link_sharing)$/i,kc=/share|publish|permission|invite|send|notify|email|trash|archive|transfer|(delete|remove)[-_ ]?(doc|document|page|file|project)/i,ly=/^(page_?id|document_?id|doc_?id|block_?id|note_?id|documentId|pageId|docId|blockId|noteId)$/i;function cy(e,n){if(!n||e.length===0||!e.some(a=>ry.has(a))||e.some(a=>iy.has(a)))return!1;let t=!1,s=!1,r=!1,o=(a,i)=>{if(!(t||i>12||a===null||typeof a!="object")){if(Array.isArray(a)){for(let l of a.slice(0,500))o(l,i+1);return}for(let[l,c]of Object.entries(a))ay.test(l)&&(t=!0),ly.test(l)&&(s=!0),["op","type","action","operation"].includes(l)&&typeof c=="string"&&kc.test(c)&&(t=!0),(l==="kind"&&typeof c=="string"&&/^(blocks?|text|tabs?|range|paragraphs?|sections?|heading|inline|markdown)$/.test(c)||l==="engine"&&typeof c=="string")&&(r=!0),i===0&&l==="container"&&c&&typeof c=="object"&&typeof c.kind=="string"&&(r=!0),i===0&&l==="ref"&&c&&typeof c=="object"&&/^(project|tab|node|doc|document|page|block)$/.test(String(c.object))&&(r=!0),l==="kind"&&typeof c=="string"&&kc.test(c)&&(t=!0),o(c,i+1)}};return o(n,0),t?!1:e.some(a=>oy.has(a))||s||r}function vc(e){return e.toLowerCase().replace(/[^a-z0-9_]+/g,"_").replace(/^_+|_+$/g,"")||"unknown"}var Uu=new Set(["main","master"]),uy=new Set(["production","prod","live"]);function w(e,n,t={}){let s=n.replace(/[\u0000-\u0008\u000b-\u001f\u007f-\u009f--]/g,""),r=s.length>300?`${s.slice(0,297)}\u2026`:s,o=typeof t.target=="string"&&t.target.length>200?{...t,target:`${t.target.slice(0,197)}\u2026`}:t;return{action:e,service:null,target:null,branch:null,host:null,is_local:null,why:r,...o}}function dy(e,n){if(!S(e.argv[0]??""))return[];let t=e.argv.slice(1),s=[];t.some(o=>/^-[rRfviIdP]*[rR][rRfviIdP]*$/.test(o)||o==="--recursive")&&t.some(o=>!o.startsWith("-"))&&s.push(...zi({...e,name:"rm",argv:["rm",...t]},n)),(t.includes("manage.py")||t.some(o=>/^db:(drop|reset)/.test(o)))&&s.push(...Rr({...e,name:"python",argv:["python",...t]}));let r=o=>({...e,name:o,argv:[o,...t]});return["push","reset","clean","branch","stash","checkout","restore"].includes(t[0]??"")&&s.push(...cd(r("git"),n)),["destroy","apply"].includes(t[0]??"")&&t.some(o=>o.startsWith("-auto-approve")||o==="-auto-approve")&&s.push(...Rr(r("terraform"))),["delete","apply","replace","drain"].includes(t[0]??"")&&s.push(...Rr(r("kubectl"))),["publish","unpublish"].includes(t[0]??"")&&s.push(...Sd(r("npm"))),t.includes("-c")&&Ee.test(Oe(t.join(" ")))&&s.push(...Ki(r("psql"),n)),s.map(o=>o.why.includes("cannot name")?o:{...o,why:`${o.why} (by a program it cannot name: ${$(e.argv[0])})`})}function Ps(e,n){if(e.functionCall)return[...Au(e,n),...ru(e,n),...Ur(e,n)];let t=Dw(e.argv);if(t!==null)return Ps({...e,name:he(t[0]),argv:t},n);if(["pnpm","yarn","bun"].includes(e.name)){let{sub:a,at:i}=nr(e.argv);if(i>0&&!Zi.has(a)&&kw.has(a))return Ps({...e,name:a,argv:[a,...e.argv.slice(i+1)]},n)}if(e.argv.slice(1).some((a,i)=>(a==="--help"||a==="--version"&&i===0)&&!/^-/.test(e.argv[i]??""))||["help","--help"].includes(e.argv[1]??""))return e.redirects.length>0?Ur({...e,name:"echo",argv:["echo"]},n):[];let s=[];s.push(...l$(e,n)),s.push(...y$(e)),s.push(...S$(e,n)),s.push(...dy(e,n)),s.push(...Au(e,n));let r=e.name;switch(r){case"rm":case"unlink":case"shred":case"srm":case"rimraf":s.push(...zi(e,n));break;case"rsync":s.push(...rd(e,n));break;case"find":s.push(...wb(e,n));break;case"fd":case"fdfind":s.push(...vb(e,n));break;case"dd":case"mkfs":case"diskutil":case"wipefs":case"fdisk":case"newfs_apfs":case"newfs_hfs":s.push(...Mc(e,n));break;case"git":s.push(...cd(e,n));break;case"gh":s.push(...Wb(e,n.lineText,n));break;case"curl":case"wget":case"http":case"https":case"xh":s.push(...Nb(e));break;case"pkill":case"killall":case"kill":case"fuser":case"colima":case"launchctl":case"tmux":case"systemctl":case"shutdown":case"reboot":case"halt":case"osascript":s.push(...qb(e,n));break;default:break}r.startsWith("mkfs.")&&s.push(...Mc(e,n)),s.length===0&&s.push(...Cy(e,n)),s.push(...Rr(e)),(r==="docker"||r==="podman"||r==="docker-compose")&&!s.some(a=>a.action==="claude.bash.deploy")&&s.push(...dw(e,n.lineText)),s.length===0&&s.push(...Ay(e)),s.push(...Ki(e,n)),s.push(...rn(n,()=>xk(e,n))),s.push(...ru(e,n)),s.push(...rn(n,()=>Sk(e,n))),s.push(...i$(e,n)),s.push(...p$(e,n)),Z()&&s.push(...Cv(e,n)),s.push(...Jy(e));let o=()=>s.every(a=>a.action==="claude.file.outside_project");if(o()&&s.push(...Iw(e)),o()&&s.push(...ky(e)),o()&&s.push(...Oy(e)),o()&&s.push(...rn(n,()=>ob(e,n))),!s.some(a=>a.action==="claude.bash.db.destructive"&&!a.why.includes(" runs SQL that changes data ("))){let a=Tw(e,n);if(a.length>0){for(let i=s.length-1;i>=0;i--)s[i].why.includes(" runs SQL that changes data (")&&s.splice(i,1);s.push(...a)}}return s.push(...hy(e,n)),["aws","gcloud","az"].includes(e.name)&&e.argv.some(a=>a==="update-kubeconfig"||a==="get-credentials")&&P(e.argv,"--file","-f")!=="-"&&!I(e.argv,"--dry-run")?s.filter(a=>a.action!=="claude.bash.deploy"&&a.action!=="claude.bash.secrets.print"):s}var xs="claude.bash.deps.add",En=(e,n="new package")=>e===1?`a ${n}`:`${e} ${n}s`;function bi(e){let n=e.map(r=>r.indexOf(" from ")),t=n[0]>0?e[0].slice(n[0]+6):null;if(e.length<2||t===null||e.some((r,o)=>n[o]<=0||r.slice(n[o]+6)!==t))return{from:"",list:e.join(", ")};let s=e.map((r,o)=>r.slice(0,n[o]));return{from:` from ${t}`,list:s.length>10?`${s.slice(0,10).join(", ")} and ${s.length-10} more`:s.join(", ")}}function fy(e,n,t,s){let r=e.indexOf(" from "),o=(r>0?e.slice(r+6):/^(?:@[^/@\s]+\/)?[^@\s/]+@((?:link:|file:|portal:|[./~]).*)$/s.exec(e)?.[1]??e).replace(/^(?:link|file|portal):/,"");if(t===null||n===null||S(o)||/^workspace(?::|$)|^[A-Za-z]:[\\/]/.test(o))return null;let a=M(o,n,s);return a===t||a.startsWith(t.endsWith("/")?t:`${t}/`)?null:a}function qu(e,n,t,s){let r=fy(e,n,t,s);if(r===null)return e;let o=e.indexOf(" from "),a=o>0?e.slice(0,o):/^((?:@[^/@\s]+\/)?[^@\s/]+)@(?:link:|file:|portal:|[./~])/s.exec(e)?.[1];return`${a?`${a} from `:""}${r}, outside this project`}function py(e,n){let t=n.lineText.lastIndexOf(e.text),s=t<0?n.lineText:n.lineText.slice(0,t+e.text.length),r=new Map;for(let o of s.matchAll(/(?:^|[\s;&|(){}`'"])([A-Za-z_]\w*)=((?:"[^"]*"|'[^']*'|\$\([^)]*\)|[^\s;&|()`"'])*)/g))r.set(o[1],o[2].replace(/["']/g,""));return r}function hy(e,n){if(e.remote!==null)return[];let t=i=>i.map(l=>S(l)?$(l):l),s,r=(i,l)=>br(i,l)&&br(i,l,s??=py(e,n)),o=e.fetched?r(he(e.fetched[0]),t([...e.fetched,...e.argv.slice(1)])):null,a=r(e.name,t(e.argv));return[...o?xc(o,e,n):[],...a?xc(a,e,n):[],...by(e,n)]}function $c(e,n){let t=e.cwd,s=t===null?"":$(t);if(t===null||!S(t)||!/^\$OLDPWD(?:\/|$)/.test(s))return t;let r=n.lineCommands??[],o=n.base;for(let a=r.indexOf(e)-1;a>=0;a--){let i=r[a].cwd;if(i!==null&&!S(i)){o=i;break}}return o===null?null:O.join(o,s.slice(7)||".")}function xc(e,n,t){let s=e.names.filter(R=>Qo(e.reg,R)),r=e.how==="run",o=[...e.other,...e.names.filter(R=>!Qo(e.reg,R)),...n.via==="xargs"&&!(r&&e.names.length+e.other.length+e.local.length>0)?["what xargs reads"]:[]],a=(R,v)=>[w(xs,R,{target:v.join(" "),is_local:!1,catastrophic:!0})];if(e.how==="machine"){for(let C=n.parent;C;C=C.parent)if(C.name==="docker"||C.name==="podman")return[];let R=[...s,...e.from,...o],v=bi(R);return R.length>0?a(`installs ${En(R.length,"package")} on this machine${v.from}: ${v.list} (${e.reg})`,R):e.local.length>0?[w(xs,`installs a local package on this machine: ${e.local.join(", ")} (${e.reg})`,{target:e.local.join(" "),is_local:!0,catastrophic:!1})]:[]}let i=e.dir===null?$c(n,t):M(e.dir,$c(n,t),t.ctx),l=i!==null&&i.startsWith("/")&&!S(i)?i:null,c=s.length===0?"":l===null?null:je(t,{kind:"deps",cwd:l,arg:[e.how==="run"?"r":"a",e.reg,...s].join(" ")}),u=typeof c=="string"?c.split(`
|
|
40
|
+
`).filter(R=>s.includes(R)):c===void 0&&!t.ctx.wantProbes?[]:null,p=e.reg!=="PyPI"||l===null?[]:(e.reads??[]).filter(R=>!S(R)).map(R=>M(R,l,t.ctx)),d=p.length===0?"":je(t,{kind:"deps",cwd:l,arg:[e.index?"I":"i",e.reg,...p].join(" ")}),f=typeof d=="string"&&d!==""?d.split(`
|
|
41
|
+
`):[],h=[...new Set([...e.index?[e.index]:[],...f.filter(R=>R.startsWith("from ")).map(R=>R.slice(5))])].join(" or "),g=[...d===null||d===void 0&&t.ctx.wantProbes?p.map(R=>`what ${O.basename(R)} lists`):[],...e.index&&e.how==="add"?e.local.map(R=>`what ${R} declares from ${e.index}`):[]],b=h?[...e.index?[]:s,...f.filter(R=>!R.startsWith("from "))].map(R=>`${R} from ${h}`):[],k=[...h?[]:u??s,...e.from,...b,...o,...g];if(k.length>0){if(!h&&u===null||o.length>0||g.length>0)return a(`${r?"downloads and runs":"adds"} ${k.join(", ")} (${e.reg}), which Anvil can't check against the project's manifests`,k);let R=bi(k);return a(r?`downloads and runs ${En(k.length,"package")} this project doesn't have${R.from}: ${R.list} (${e.reg})`:`adds ${En(k.length)} to this project${R.from}: ${R.list} (${e.reg})`,k)}if(r||s.length===0&&e.local.length===0)return[];let E=s.length>0,y=e.local.map(R=>qu(R,l,t.projectRoot,t.ctx)),m=e.declares?.length?`declares ${e.declares.join(", ")} in ${e.reg==="Go"?"go.mod":"package.json"} (${e.reg})`:E?`installs ${s.join(", ")} (${e.reg})${typeof c=="string"?", which this project already declares":""}`:`adds ${En(y.length,"local package")}: ${y.join(", ")} (${e.reg})`;return[w(xs,m,{target:[...s,...e.local].join(" "),is_local:!E,catastrophic:!1})]}function wi(e){let n=O.basename(e),t=mc(n,O.basename(O.dirname(e))==="requirements");return t===null||n==="pnpm-workspace.yaml"||n==="go.work"||e.includes("/node_modules/")?null:{file:n,reg:t}}function gy(e,n,t,s){return Hu(e,JSON.stringify(n??null),t,s)}function Hu(e,n,t,s){let r=wi(e);if(r===null)return null;let o=n===null||n.length>256*1024?null:je({ctx:t},{kind:"deps",cwd:O.dirname(e),arg:`e ${r.file} ${n}`});if(o===""||o===void 0&&!t.wantProbes)return null;let a=typeof o=="string"?o.split(`
|
|
42
|
+
`):[],i=a.filter(c=>!c.startsWith(" "));if(typeof o=="string"&&i.length===0){let c=a.map(u=>qu(u.slice(1),O.dirname(e),s,t));return w(xs,`adds ${En(c.length,"local package")}: ${c.join(", ")} (${r.reg}, ${r.file})`,{target:a.map(u=>u.slice(1)).join(" "),is_local:!0,catastrophic:!1})}let l=bi(i);return w(xs,i.length>0?`adds ${En(i.length)} to this project${l.from}: ${l.list} (${r.reg}, ${r.file})`:`changes ${r.file} (${r.reg}), and Anvil can't check which packages it adds`,{target:i.length>0?i.join(" "):e,is_local:!1,catastrophic:!0})}var _c=/(?:^|[\\/])(?:package\.json|requirements[\w.-]*|pyproject\.toml|Pipfile|Cargo\.toml|go\.mod|Gemfile|composer\.json|Directory\.Packages\.props|packages\.config)(?:$|[\\/])|\.(?:cs|fs|vb)proj$/,my=new Set(["touch","chmod","chown","chgrp","chflags","mkfifo","mknod","truncate"]),yy=new Set(["cp","mv","install","ln","ditto","gcp","gmv"]);function by(e,n){if(e.name==="git"||!(e.argv.some(d=>_c.test(d))||e.redirects.some(d=>d.target!==null&&_c.test(d.target))))return[];let t=d=>M(De(d,e,n),e.cwd,n.ctx),s=new Map,r=(d,f,h)=>{!s.has(d)&&!S(d)&&wi(d)&&s.set(d,h===null?null:JSON.stringify({[f]:h}))},o;for(let d of e.redirects){if(!d.target||!d.op.includes(">")||d.op.endsWith("&")&&/^(\d+|-)$/.test(d.target)||d.target==="-"||d.target.startsWith("/dev/"))continue;let f=d.fd===null||d.fd===1;f&&o===void 0&&(o=Wi(e)),r(t(d.target),d.op.startsWith(">>")?"append":"content",f&&d.op!=="<>"?o??null:null)}if(e.name==="tee"){let d=e.argv.slice(1),f=Bu(e),h=d.some(g=>g==="--append"||/^-[^-]*a/.test(g));for(let g of d.filter(b=>!b.startsWith("-")))r(t(g),h?"append":"content",f)}let a=new Map,i=new Map,l=my.has(e.name)?[]:tf(e,n,a,i),c=yy.has(e.name)&&P(e.argv,"-t","--target-directory")===null?e.argv.slice(1).filter(d=>!d.startsWith("-")):[],u=c.length>=2?c[c.length-1]:null,p=u!==null&&!/(?:^|\/)\.{0,2}$/.test(u)&&O.basename(u).includes(".")?t(u):null;for(let d of l){let f=a.get(d);if(f==="d"||f==="D"||f==="m"||e.name==="ln"&&f===void 0||p!==null&&O.dirname(d)===p)continue;let h=i.get(d);h!==void 0&&!S(h)&&wi(t(h))!==null&&Sc(t(h))===Sc(d)||r(d,"content",null)}return[...s].map(([d,f])=>Hu(d,f,n.ctx,n.projectRoot)).filter(d=>d!==null)}function Sc(e){let n=O.basename(e);return/\.(?:txt|in)$/.test(n)?"requirements":/\.(?:cs|fs|vb)proj$/.test(n)?"proj":n}function Wi(e,n=0){if(e.groupWriters){let s="";for(let r of e.groupWriters){let o=n>8?null:Wi(r,n+1);if(o===null)return null;s+=o}return s}let t=e.argv;if(n>8||e.via==="xargs"||e.altArgvs.length>0||t.some(S))return null;if(e.name==="echo"){let s=1,r=!0,o=!1;for(;s<t.length&&/^-[neE]+$/.test(t[s]);s++)for(let i of t[s].slice(1))i==="n"?r=!1:o=i==="E";let a=o?{text:t.slice(s).join(" "),stop:!1}:Vu(t.slice(s).join(" "),!1);return a===null?null:a.text+(r&&!a.stop?`
|
|
43
|
+
`:"")}return e.name==="printf"?wy(t.slice(1)):e.name==="cat"&&(t.length===1||t.length===2&&t[1]==="-")||e.name==="tee"?Bu(e,n):null}function Bu(e,n=0){return e.stdinKind==="heredoc"?e.stdin!==null&&!(e.stdinExpands&&/[$`]|\\[$`\\\n]/.test(e.stdin))?e.stdin:null:e.stdinKind==="here-string"?e.stdin!==null&&!S(e.stdin)?`${e.stdin}
|
|
44
|
+
`:null:e.stdinFile===null&&e.pipeFrom?Wi(e.pipeFrom,n+1):null}function Vu(e,n){let t={n:`
|
|
45
|
+
`,t:" ",r:"\r","\\":"\\",...n?{'"':'"',"'":"'"}:{}},s="";for(let r=0;r<e.length;r++)if(e[r]!=="\\")s+=e[r];else{if(e[r+1]==="c")return{text:s,stop:!0};if(t[e[r+1]??""]===void 0)return null;s+=t[e[++r]]}return{text:s,stop:!1}}function wy(e){let n=e[0]==="--"?e.slice(1):e.slice(),t=n.shift();if(t===void 0||/^-./.test(t))return null;let s=[],r="";for(let i=0;i<t.length;i++)if(t[i]!=="%")r+=t[i];else if(t[i+1]==="%")r+="%",i++;else if(t[i+1]==="s"||t[i+1]==="b")s.push(["text",r],[t[++i],""]),r="";else return null;s.push(["text",r]);let o="",a=0;do for(let[i,l]of s){let c=i==="s"?{text:n[a++]??"",stop:!1}:Vu(i==="b"?n[a++]??"":l,!0);if(c===null)return null;if(o+=c.text,c.stop)return o}while(a<n.length&&s.length>1);return o}var Ni=new Set(["npm","pnpm","yarn","bun","npx","pnpx","bunx","deno","node","nodejs","pip","pip3","pipx","poetry","uv","pdm","hatch","rye","conda","mamba","micromamba","brew","apt","apt-get","yum","dnf","pacman","apk","port","nix","nix-env","flatpak","snap","cargo","rustup","gem","bundle","bundler","go","composer","pod","carthage","flutter","dart","dotnet","mvn","gradle","make","cmake","ninja","bazel","xcodebuild","xcrun","swift","nvm","fnm","volta","asdf","mise","rbenv","pyenv","sdk","direnv","pre-commit","husky","lefthook","git","hg","svn","docker","podman","colima","minikube","kind","k3d","vagrant","tmux","screen","code","cursor","vim","nvim","emacs","jest","vitest","pytest","mocha","eslint","prettier","tsc","python","python3","ruby","perl","php","java","echo","printf","ls","cat","grep","rg","sed","awk","jq","yq","sort","uniq","head","tail","wc","cut","tr","tee","touch","mkdir","cp","mv","ln","chmod","chown","tar","zip","unzip","gzip","gunzip","open","say","defaults","du","df","stat","file","which","type","command","test","true","false","sleep","wait","date","seq","basename","dirname","realpath","readlink","cd","export","unset","set","source","eval","exec","trap","read","history","sqlite3","redis-server","pg_ctl","initdb","ollama","anvil","anvil-claude","claude","pm2","nodemon","turbo","nx","lerna","changeset","rimraf","trash","kubectx","kubens","corepack","tsx","ts-node","esbuild","vite","next","webpack","rollup","parcel","storybook","playwright","cypress","lsof","ps","top","pgrep","pkill","kill"]),Cc=null;function Pr(e){return Cc??=new Set([...Object.keys(bd),...qr,"aws","az","gcloud","gsutil","bq","kubectl","helm","terraform","tofu","pulumi","psql","mysql","mariadb","mongosh","mongo","mongoimport","mongorestore","pg_restore","pg_dump","redis-cli","clickhouse","clickhouse-client","cqlsh","snowsql","snow","beeline","impala-shell","spark-sql","heroku","railway","vercel","wrangler","fly","flyctl","firebase","doppler","infisical","vault","op","security","gpg","gpg2","prisma","alembic","artisan","rails","rake","flask","rsync","find","fd","dd","gh","ssh","scp","sftp","crontab","systemctl","launchctl","ngrok","cloudflared","tailscale","stripe","cast","forge","solana","fastlane","eas","7z","7za","7zr","7zz","aider","amp","anchor","anvil","anvil-claude","ape","aptos","artisan","at","autossh","awk","aws","az","azcopy","base64","batch","bcp","beeline","bitcoin-cli","bore","bq","branch","brew","brownie","bsdtar","bun","cardano-cli","cast","checkout","checkout-index","chflags","chgrp","chmod","chown","claude","clean","clickhouse","clickhouse-client","cloudflared","cmp","cockroach","code","code-insiders","codex","colima","copilot","cp","cqlsh","croc","crontab","crush","curl","cursor-agent","cut","databricks","dbt","dd","ddev","deno","devtunnel","diff","diskutil","ditto","docker","droid","dropdb","dropuser","duckdb","ed","egrep","emacs","ex","expo","fastmcp","fd","fdfind","fdisk","ffsend","filter-branch","filter-repo","find","firebase","fish","fly","flyctl","flyway","forge","frpc","fuser","gawk","gc","gcloud","gcp","gemini","gh","git","glab","gmv","gpg","gpg2","grep","gsed","gsutil","gtar","halt","hardhat","head","herd","heroku","http","https","impala-shell","install","install-mcp","jq","kill","killall","knex","kubectl","launchctl","liquibase","ln","lncli","localxpose","loclx","lt","mariadb","mariadb-dump","mawk","mc","mcp-get","md5","md5sum","mix","mkfifo","mkfs","mknod","mongo","mongodump","mongoexport","mongosh","mv","mydumper","mysql","mysqladmin","mysqldump","mysqlpump","nawk","nc","ncat","near","neon","neonctl","netcat","newfs_apfs","newfs_hfs","ngrok","node","nvim","oc","openssl","osascript","patch","pbcopy","perl","pg_basebackup","pg_dump","pg_dumpall","pgcli","php","pkill","plutil","pm2","podman","powershell","powershell.exe","presto","prisma","pscale","psql","push","pwsh","pwsh.exe","python","python3","q","qwen","rclone","read-tree","reboot","red","redis-cli","reflog","reset","restore","rg","rimraf","rm","rsync","ruby","s3cmd","schtasks","schtasks.exe","scp","security","sed","sequelize","sequelize-cli","set","sftp","sha256sum","shasum","shred","shutdown","smithery","snow","snowsql","socat","solana","soroban","sort","spark-sql","spl-token","sponge","sqlcmd","sqlite","sqlite3","srm","ssh","starkli","stash","stellar","stripe","sui","supabase","switch","symbolic-ref","systemctl","tailscale","tar","tee","telnet","tmole","tmux","touch","trash","trino","true","truffle","truncate","ts-node","tsx","tunnelmole","turso","typeorm","typeorm-ts-node-commonjs","typeorm-ts-node-esm","unlink","untun","unzip","update-ref","valet","vi","vim","wc","wget","wipefs","worktree","wormhole","wrangler","xclip","xh","yq","zrok","format","format-volume","clear-disk","initialize-disk","remove-partition","clear-recyclebin","diskpart","vssadmin","wmic","wbadmin","wsl","bcdedit","reg","set-itemproperty","new-itemproperty","remove-itemproperty","remove-item","sc","new-service","remove-service","set-service","stop-service","register-scheduledtask","set-scheduledtask","unregister-scheduledtask","new-scheduledtask","set-executionpolicy","set-mppreference","add-mppreference","netsh","set-netfirewallprofile","new-netfirewallrule","disable-netfirewallrule","remove-netfirewallrule","takeown","icacls","taskkill","runas","gsudo","mountvol","robocopy","setx","forfiles"]),Sv.has(e)?Z():Cc.has(e)}var Rn=new Set(["delete","destroy","drop","purge","wipe","terminate","nuke","erase","truncate","flushall","flushdb","teardown","decommission","deprovision","deregister","tombstone"]),ni=new Set(["rm","remove","reset","revoke"]),Gu=new Set(["app","apps","application","applications","project","projects","bucket","buckets","database","databases","db","dbs","cluster","clusters","service","services","instance","instances","volume","volumes","branch","branches","environment","environments","env","envs","secret","secrets","domain","domains","zone","zones","record","records","dns","repo","repos","repository","repositories","deployment","deployments","function","functions","table","tables","queue","queues","topic","topics","stream","streams","namespace","namespaces","org","orgs","organization","organizations","team","teams","user","users","member","members","workspace","workspaces","site","sites","server","servers","machine","machines","vm","vms","droplet","droplets","pool","pools","stack","stacks","schema","schemas","collection","collections","keyspace","keyspaces","storage","backup","backups","snapshot","snapshots","token","tokens","webhook","webhooks","subscription","subscriptions","account","accounts","pg","postgres","mysql","redis","kv","d1","r2","s3","index","indexes","indices","key","keys","certificate","certificates","cert","certs","distribution","distributions","role","roles","policy","policies","vpc","subnet","subnets","gateway","node","nodes","worker","workers","job","jobs","pipeline","pipelines","model","models","endpoint","endpoints","volume-snapshot","organization-member","tenant","tenants","serverless","store","stores","region","regions","replica","replicas","shard","shards","partition","partitions","tablet","tablets","broker","brokers","changefeed","changefeeds","network","networks","firewall","firewalls","disk","disks","peer","peers","keyring","keyrings","vault","vaults"]),Li=new Set(["database","databases","db","dbs","table","tables","schema","schemas","collection","collections","keyspace","keyspaces","pg","postgres","mysql","redis","kv","d1","index","indexes","indices","backup","backups","snapshot","snapshots","bucket","buckets","storage","r2","s3","volume","volumes","store","stores","region","regions","replica","replicas","shard","shards","partition","partitions","tablet","tablets","disk","disks","vault","vaults"]),Ti=/^--?(dry-?run|plan|preview|what-?if|check|diff|validate|help|version|list|ls)$/i;function Zu(e){let n=[];for(let t=1;t<e.length&&n.length<6;t++){let s=$(e[t]);if(!s.startsWith("-")&&/^[a-z][a-z0-9_-]*(:[a-z0-9_-]+)*$/.test(s))for(let r of s.split(":"))r&&n.push(r)}return n}function Di(e){let n=O.basename(e.name);return["const","let","var"].includes(n)&&$(e.argv[2]??"")==="="?!0:/^[A-Z][a-z]+$/.test(n)&&e.argv.length>=4&&e.argv.slice(1).some(t=>/[a-z]\.$/.test($(t)))}function ky(e){let n=O.basename(e.name);if(!n||Ni.has(n)||Pr(n)||e.functionCall||e.via==="substitution"||S(e.argv[0]??"")||e.argv[0]?.includes("/"))return[];if(Di(e))return[];let t=Zu(e.argv);if(t.length===0||e.argv.some(u=>Ti.test(u)))return[];let s=u=>Rn.has(u)||ni.has(u)?u:Rn.has(u.split("-")[0]??"")||ni.has(u.split("-")[0]??"")&&!Tr.has(u.split("-").slice(1).join("-"))?u.split("-")[0]:null,r=t.findIndex(u=>s(u)!==null);if(r>=0){let u=s(t[r]);t[r].includes("-")&&!Rn.has(t[r])&&t.splice(r+1,0,t[r].slice(u.length+1));let p=t.flatMap(h=>[h,...h.split("-")]).find(h=>Gu.has(h)),d=t.filter((h,g)=>g!==r||h.includes("-")).flatMap(h=>h.split("-")).filter(h=>h!==u);if(p===void 0&&d.length>0&&d.every(h=>Xu.has(h)))return[];let f=t.length>r+1||e.argv.some(h=>/^--?(app|project|name|id|db|database|bucket|cluster|service|instance|env|environment|org|zone|branch)(=|$)/.test(h)||Fi.test($(h)));if(Rn.has(u)&&(p!==void 0||f)||ni.has(u)&&p!==void 0){let h=Li.has(p??"")||["drop","truncate","flushall","flushdb","purge","wipe"].includes(u);return[w(h?"claude.bash.db.destructive":"claude.bash.deploy",`${n} ${Er(u)} ${p?ki(p):"what it names"} (a command with no rule of its own, read by its words)`,{target:`${n} ${t.slice(0,3).join(" ")}`,is_local:!1})]}}let o="(a command with no rule of its own, read by its words)",a=e.argv.some(u=>/\b(localhost|127\.0\.0\.1|::1)\b|^--local$/.test($(u))),i=e.argv.map(u=>$(u)),l=i.slice(1).find((u,p)=>/\s/.test(u)&&!/^(i?like|=|!=|<>)$/i.test(i[p]??"")&&Ee.test(Oe(u)));if(l!==void 0&&!a)return[w("claude.bash.db.destructive",`${n} runs SQL that changes data (${(Ee.exec(Oe(l))?.[1]??"").replace(/\s+/g," ").toUpperCase()}) ${o}`,{target:n,is_local:!1})];let c=t.findIndex(u=>Tr.has(u));return c>=0&&t.some(u=>nd.has(u))&&fe(e)?[w("claude.bash.secrets.print",`${n} prints ${ki(t[c])} ${o}`,{target:`${n} ${t.slice(0,3).join(" ")}`,is_local:!0})]:t.slice(0,3).some(u=>$f.test(u))?[w("claude.bash.deploy",`${n} ${t.slice(0,2).join(" ")} deploys or publishes ${o}`,{target:`${n} ${t.slice(0,2).join(" ")}`,is_local:!1})]:t.some(u=>["tunnel","expose","funnel"].includes(u))&&e.argv.some(u=>/^(\d{2,5}|localhost:\d{2,5}|127\.0\.0\.1:\d{2,5}|https?:\/\/(localhost|127\.0\.0\.1):\d{2,5})$/.test($(u)))?[w("claude.bash.net.expose",`${n} opens a local port to the internet ${o}`,{target:n,is_local:!1})]:[]}var vy=new Set(["-c","-F","-i","-J","-l","-o","-P","-S","-D","-X"]),$y=new Set(["-e","-f","-T","-B","-M","--rsh","--exclude","--include","--filter","--exclude-from","--include-from","--files-from","--rsync-path","--password-file","--chmod","--chown","--log-file","--temp-dir","--partial-dir","--backup-dir","--suffix","--port","--bwlimit","--timeout","--max-size","--min-size","--compare-dest","--copy-dest","--link-dest"]),Ku=new Set(["--config","--transfers","--checkers","--include","--exclude","--filter","--include-from","--exclude-from","--filter-from","--files-from","--max-age","--min-age","--max-size","--min-size","--log-file","--log-level","--bwlimit","--backup-dir","--suffix","--max-depth","--order-by","--tpslimit","--retries"]),xy=/^(localhost|127\.0\.0\.1|\[::1\]|::1)$/i,_y=new Set(["copy","copyto","move","moveto","sync","bisync","rcat","copyurl","delete","deletefile","purge","rmdir","rmdirs","cleanup","dedupe"]),Sy=new Set(["rcat","delete","deletefile","purge","rmdir","rmdirs","cleanup","dedupe"]);function Cy(e,n){let t=O.basename(e.name);if(!["scp","rsync","rclone"].includes(t))return[];let s=e.argv.map(u=>$(u));if(s.some(u=>u==="-n"||u==="--dry-run"||t==="rsync"&&/^-[a-zA-Z]*n[a-zA-Z]*$/.test(u)))return[];let o=ke(s,1,t==="scp"?vy:t==="rsync"?$y:Ku),a=u=>Ye(u)&&!xy.test(Rs(u));if(t==="rclone"){let u=o.findIndex(g=>_y.has(g));if(u<0)return[];let p=o[u],d=o.slice(u+1,u+1+(Sy.has(p)?1:2));if(d.length===0)return[];if(d.every(g=>!Ye(g))){if(["delete","deletefile","purge","rmdir","rmdirs"].includes(p))return zi({...e,name:"rm",argv:["rm","-rf",...d]},n).map(g=>({...g,why:`rclone ${p}: ${g.why}`}));if(p==="sync"&&d.length>=2){let g=Dr(d[d.length-1],e,n);return g.kind==="disposable"?[]:[{...Ft([g],e),why:`rclone sync replaces what is in ${g.why}`}]}return[]}let f=d[d.length-1];if(p==="sync"&&d.length===2&&Ye(d[0])&&!Ye(f)){let g=Dr(f,e,n);return g.kind==="disposable"?[]:[{...Ft([g],e),why:`rclone sync replaces what is in ${g.why}`}]}if(!["copy","copyto","move","moveto","sync","bisync","rcat","copyurl"].includes(p)||p!=="rcat"&&d.length<2||!a(f))return[];let h=f.split(":")[0];return p==="sync"||p==="bisync"?[w("claude.bash.db.destructive",`rclone ${p} makes ${h}: match the source, deleting what is not in it`,{target:f,host:h,is_local:!1})]:[w("claude.bash.external_write",`rclone ${p} copies files to ${h}:`,{target:f,host:h,is_local:!1})]}let i=o.filter(u=>Ye(u)||/[/.~]/.test(u));if(i.length<2)return[];let l=i[i.length-1];if(!a(l))return[];let c=Rs(l);return[w("claude.bash.external_write",`${t} copies files to another machine (${c})`,{target:l,host:c,is_local:!1})]}function Ay(e){let n=$s.has(O.basename(e.name))?e.argv.slice(1).map(a=>$(a)).find(a=>!a.startsWith("-"))??"":$(e.argv[0]??""),t=O.basename(n).replace(/\.sh$/,"");if(!/^kafka-[a-z-]+$/.test(t)||["kafka-server-start","kafka-server-stop","kafka-storage","kafka-run-class","kafka-console-consumer","kafka-dump-log"].includes(t))return[];let s=e.argv.map(a=>$(a));if(s.some(a=>/^--(help|version|dry-run)$/.test(a)))return[];let r=t==="kafka-delete-records"?"(its one action)":s.find(a=>/^--(delete|delete-[a-z-]+|purge)$/.test(a));if(r)return[w("claude.bash.db.destructive",`${t} ${r} deletes from a live Kafka cluster`,{target:t,is_local:!1})];if(t==="kafka-leader-election")return[w("claude.bash.deploy","kafka-leader-election moves partition leaders on a live Kafka cluster",{target:t,is_local:!1})];let o=s.find(a=>/^--(create|alter|add|remove|execute|reset-offsets|reassign|elect|grant|revoke|expire|renew|cancel)$/.test(a));return o&&!(o==="--reset-offsets"&&!s.includes("--execute"))?[w("claude.bash.deploy",`${t} ${o} changes a live Kafka cluster`,{target:t,is_local:!1})]:t==="kafka-console-producer"?[w("claude.bash.external_write","kafka-console-producer writes messages to a topic",{target:t,is_local:!1})]:[]}var Ey=/^--?(?!no-|skip-|keep-|without-|dry-|preview-|show-|list-|exclude-|disable-|dont-|don-t-|prevent-|protect-|avoid-|never-)([a-z0-9]+-)*(purge|destroy|wipe|drop|nuke|erase|truncate|delete)(-(all|data|tables?|database|databases|db|volumes?|everything|existing|objects?|records?|rows?|keys?|files?|snapshots?|backups?|indexes|indices|schemas?|clusters?|namespaces?|buckets?|branch(es)?|resources?|old))?(=.*)?$/,Ry=new Set(["magick","convert","mogrify","montage","composite","gm"]);function Oy(e){let n=O.basename(e.name);if(!n||Ni.has(n)||Ry.has(n)||e.functionCall||e.via==="substitution"||S(e.argv[0]??"")||Di(e))return[];let t=e.argv.map(u=>$(u));if(t.some(u=>Ti.test(u)))return[];let s="(what its own words say it does)",r=Zu(t),o=Pr(n)?-1:r.findIndex(u=>u.split("-").includes("unsafe"));if(o>=0&&(r[o].includes("-")||r.length>o+1)&&!r.slice(o+1).some(u=>Pn.has(u)))return[w("claude.bash.db.destructive",`${n} runs a subcommand it calls unsafe (${r.slice(0,3).join(" ")}) ${s}`,{target:`${n} ${r.slice(0,3).join(" ")}`,is_local:!1})];if(Pr(n))return[];let i=t.slice(1).find((u,p)=>Ey.test(u)&&!/=(false|0|no|none|off|never)$/i.test(u)&&!/^(false|0|no|none|off|never)$/i.test(t[p+2]??""));if(i===void 0)return[];let l=/(purge|destroy|wipe|drop|nuke|erase|truncate|delete)/.exec(i)[1],c=["drop","truncate","purge","wipe"].includes(l)||r.flatMap(u=>[u,...u.split("-")]).some(u=>Li.has(u));return[w(c?"claude.bash.db.destructive":"claude.bash.deploy",`${n} is told to ${l} (${i.split("=")[0]}) ${s}`,{target:`${n} ${r.slice(0,2).join(" ")}`.trim(),is_local:!1})]}var Wr=new Set([...Rn,"rollback","unpublish"]),_s=new Set(["rm","remove","reset","revoke","uninstall"]),jy=new Set(["cluster","clusters","kube","k8s","kubernetes","infra","infrastructure","eks","gke","aks"]),Py=new Set(["kind","minikube","k3d","microk8s","local","dev","docker","compose"]),si=new Set(["drop","truncate","flushall","flushdb","teardown","deprovision","decommission"]),Nr=new Set(["deploy","release","publish","promote","rollout","ship"]),Ii=new Set(["create","add","set","update","put","attach","scale","enable","disable","rotate"]),kr=new Set(["bucket","buckets","cluster","clusters","database","databases","db","namespace","namespaces","instance","instances","volume","volumes","service","services","function","functions","fn","lambda","addon","addons","lifecycle","environment","environments","domain","domains","zone","zones","record","records","dns","app","apps","deployment","deployments","queue","queues","topic","topics","stack","stacks","vpc","subnet","subnets","gateway","pool","pools","certificate","certificates","distribution","distributions","worker","workers","machine","machines","droplet","droplets","server","servers","site","sites","project","projects","table","tables","schema","schemas","identity","identities","layer","layers","kv","d1","r2","s3","broker","brokers","partition","partitions","replica","replicas","shard","shards","region","regions","store","stores","serverless","tablet","tablets"]),Pn=new Set(["plan","verify","check","validate","list","ls","status","diff","extract","describe","view","lint","test","tests","dry","dryrun","notes","changelog","preview","smoke","inspect","show","get","help","download","fetch","pull","template","render","history","logs","log","info","url","urls","open","browse","wait","watch","tail","search","find","explain"]),Br=new Set([...Pn,"doctor","whoami","version","completion","login","logout","install","init"]),Yu=new Set(["test","tests","e2e","spec","specs","check","checks","verify","validate","lint","dry","plan","diff","preview","smoke","generate","gen","codegen","mock","mocks","fake","stub","example","examples","sample","docs","notes","changelog","build","watch","dev","local","list","ls","status","show","get","inspect","count","find","search","report","help","storybook","bench","benchmark","prepare","eval","evals","evaluate","scan","audit","probe","probes"]),Wy=new Set(["detect","find","get","next","determine","should","is","has","needs","parse","extract","wait","print","read","info"]),Ny=new Set([...Yu,"start","serve","bundle","compile","analyze","typecheck","format","copy","env","logs","log"]),Ly=new Set(["prod","production"]),Ty=new Set(["fn","func","lambda","lambdas","addon","addons","identity","identities","layer","layers","relationship","relationships","lifecycle","data","migrate","migration","migrations","seed","seeds"]),Ac=new Set([...Li,"data","migrate","migration","migrations","seed","seeds"]),Wn=new Set(["config","configure","configuration","context","profile","alias","completion","completions","auth","login","local"]),Fi=/^--?(app|project|project-?id|db|database|bucket|cluster|service|instance|env|environment|org|zone|branch|deployment|deployment-?id|identity|stack|namespace|site|([a-z][a-z0-9]*[-.])+(id|ids|name|arn|uri))(=|$)/,Dy=new Set(["ssh","scp","sftp","mosh","autossh","rsync","curl","wget","http","https","xh","git","nc","ncat","netcat","telnet","socat","xargs","env","sudo","doas","time","timeout","nohup","watch","nice","caffeinate","stdbuf","command","builtin","exec"]),An=/\.(sh|bash|zsh|py|rb|js|mjs|cjs|ts|mts|cts|pl|ps1)$/,Iy=new Set(["dotenv","dotenvx","env-cmd","cross-env","with-env","mise","asdf","op","doppler","infisical","railway","kubectl","oc","uv","poetry","pipenv","direnv","nix","nix-shell","devbox","flox","aws-vault","sops","chamber","teller","envchain"]),Lr=/\$\{?[A-Za-z_]*(TOKEN|API_?KEY|SECRET|PAT|PASSWORD|CREDENTIALS?)[A-Za-z_]*\}?/,Ju=new Set(["skill","skills","plugin","plugins","completion","completions","toolchain","toolchains","font","fonts","venv","virtualenv","shim","shims"]),Xu=new Set([...Wn,...Ju,"cache","caches","history","log","logs","tmp","temp","session-cache","settings","setting","shell","workspace-cache","extension","extensions","download","downloads"]),Fy=new Set(["repo","repos","remote","remotes","source","sources","registry","registries","tap","taps","channel","channels","index","indexes"]);function Ec(e){return e.argv.some(n=>{let t=$(n);return Lr.test(n)||Lr.test(t)||Fi.test(t)||/^[a-z][a-z0-9+.-]*:\/\//.test(t)&&!qe(t)})}var My=/\b(claude|anvil|mcp|codex|cursor|copilot|gemini|aider|settings|permissions?)\b/i,Rc=/(^|[-_.:/])(prod|production|live|mainnet)([-_.:/]|$)/i,Oc=/^(\w+:\/\/)?([^@/\s]*@)?(localhost|127\.0\.0\.1|\[::1\])(:\d+)?(\/\S*)?$/i;function zy(e){let n=e.text,t=[],s=i=>i===" "||i===" ",r=i=>i!==void 0&&(i>="A"&&i<="Z"||i>="a"&&i<="z"||i==="_"),o=i=>r(i)||i!==void 0&&i>="0"&&i<="9",a=0;for(;t.length<32;){for(;s(n[a]);)a++;let i=a;if(!r(n[i]))break;for(;o(n[i]);)i++;if(n[i]!=="=")break;let l=n.slice(a,i);i++;let c;if(n[i]==='"'||n[i]==="'"){let u=n.indexOf(n[i],i+1);if(u<0)break;c=n.slice(i+1,u),i=u+1}else{let u=i;for(;u<n.length&&!s(n[u])&&n[u]!==`
|
|
46
|
+
`;)u++;c=n.slice(i,u),i=u}if(i<n.length&&!s(n[i]))break;t.push([l,c]),a=i}return t}function Uy(e,n){let t=e.argv.map(y=>$(y)),s=y=>/^--?[a-z][\w-]*=/i.test(y)?y.slice(y.indexOf("=")+1):y;if(t.some(y=>Ti.test(y)||/^--dry-?run=(true|1|yes|client|server|all)$/i.test(y)))return{strict:!0,ship:!0};if(t.some(y=>/^--(snapshot|skip-publish|no-publish|skip-push)$|^--skip=([\w,]*,)?(publish|push)\b/.test(y)))return{strict:!1,ship:!0};if(["make","gmake"].includes(O.basename(e.name))&&t.some(y=>/^-[a-zA-Z]*n[a-zA-Z]*$|^--(just-print|recon)$/.test(y)))return{strict:!0,ship:!0};let r=zy(e);if(t.slice(1).some(y=>Rc.test(s(y)))||r.some(([,y])=>Rc.test(y)))return{strict:!1,ship:!1};let o=y=>t.flatMap((m,R)=>y.test(m)?[t[R+1]??""]:/^--?[a-z][\w-]*=/i.test(m)&&y.test(m.slice(0,m.indexOf("=")))?[s(m)]:[]),a=t.findIndex((y,m)=>m>0&&!y.startsWith("-")),i=o(/^--?(db-url|database-url|url|host|registry|endpoint|server|api-url|connection|connection-string|dsn)$/i),l=r.some(([y,m])=>/(DATABASE|DB|POSTGRES|PG|MYSQL|MONGO|REDIS)_?(URL|URI|HOST)$/i.test(y)&&!Oc.test(m)),c=r.some(([y,m])=>/^(NODE_ENV|APP_ENV|RAILS_ENV|RACK_ENV|MIX_ENV|FLASK_ENV|DJANGO_ENV|ENVIRONMENT|STAGE)$/.test(y)&&/^(test|testing|dev|development|local)$/i.test(m))&&!l;if(t.slice(1,a<0?void 0:a).includes("--local")||i.length>0&&i.every(y=>Oc.test(y))||c)return{strict:!0,ship:!0};let p=o(/^--?(channel|track|deployment|network|net|chain)$/i),d=o(/^--?([\w-]+\.)?cluster$/i),h=t.some(y=>/^code-?push(-standalone)?$/.test(y))||/code-?push/.test(O.basename(e.name))?o(/^-d$/):[],g=[...p.map(y=>jc.test(y)),...d.map(y=>Hy.test(y)),...h.map(y=>jc.test(y))],b=g.length>0&&g.every(Boolean),k=n.lineText.indexOf(e.text),E=O.basename(e.name);if(!b&&g.length===0&&k>0&&/^[a-z][a-z0-9_-]*$/.test(E)){let y=[...n.lineText.slice(0,k).matchAll(new RegExp(`\\b${E}\\s[^;&|]*\\b(?:config\\s+set|switch|use)\\b[^;&|]*\\s--?(?:url|u|env|network|cluster)[= ]([\\w:/.-]+)`,"g"))],m=y[y.length-1]?.[1];b=m!==void 0&&/^(devnet|testnet|localnet|localhost|http:\/\/(localhost|127\.0\.0\.1)(:\d+)?)$/.test(m)}return{strict:!1,ship:b}}var qy=new Set(["sequelize","sequelize-cli","knex","typeorm","typeorm-ts-node-commonjs","typeorm-ts-node-esm","mix","artisan","php","rails","rake","alembic","flask","flyway","liquibase"]),jc=/^([\w-]+:)?(staging|stage|stg|dev|develop|development|test|testing|qa|uat|preview|sandbox|devnet|testnet|localnet|local|ci|sepolia|goerli|holesky|hoodi|mumbai|amoy|fuji|chiado|alfajores|shasta|nile)$/i,Hy=/^([\w-]+:)?(devnet|testnet|localnet|sepolia|goerli|holesky|hoodi|mumbai|amoy|fuji|chiado|alfajores|shasta)$/i,Pc=/^--(publish|deploy|promote)(=true)?$/,By=new Set(["npx","pnpx","bunx"]),Vy=new Set(["--import","--require","-r","--loader","--experimental-loader","--env-file","--project","-P","--tsconfig","--inspect-port"]);function ki(e){return/s$/.test(e)?e:`a ${e}`}function Ke(e){return e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase().split(/[-:_./]+/).filter(n=>/^[a-z][a-z0-9]*$/.test(n))}function Wc(e,n,t=!1){let s=[],r=n;for(;t&&r<e.length&&$(e[r]).startsWith("-")&&$(e[r])!=="--";){let a=$(e[r]);r+=!a.includes("=")&&r+1<e.length&&/[/.$~=]|^\d/.test($(e[r+1]))&&!$(e[r+1]).startsWith("-")?2:1}for(let a=0;a<2&&r<e.length&&/^\$/.test($(e[r]));a++)r++;for(;r<e.length&&s.length<6;r++){let a=$(e[r]);if(a==="--"||a.startsWith("-")||a.includes("://")||a.includes("@")||!/^[a-z][a-z0-9_.:/-]*$/.test(a)||a.includes("/")||/\.[a-z0-9]{1,5}(:[\d,-]+)?$/.test(a))break;let i=Ke(a);i.length>0&&s.push(i)}let o=0;for(;r<e.length;r++){let a=$(e[r]);if(a==="--")break;a.startsWith("-")||o++}return{groups:s,values:o}}function Gy(e){let n=e.argv.map(p=>$(p)),t=O.basename(e.name),s=[],r=[],o=(p,d)=>({...e,name:p,argv:[p,...d]}),a=(p,d)=>{let f=Wc(n,d),h=n.flatMap((g,b)=>b>=d&&/^--?(command|cmd|action|task|step|op|operation|job)$/.test(g)?[Ke(n[b+1]??"")]:/^--?(command|cmd|action|task|step|op|operation|job)=/.test(g)?[Ke(g.slice(g.indexOf("=")+1))]:[]).filter(g=>g.length>0);return{name:O.basename(p),groups:[Ke(O.basename(p).replace(/\.[^.]+$/,"")),...f.groups.slice(0,1),...h],values:f.values+Math.max(0,f.groups.length-1),script:!0}},i=p=>({name:p,groups:[Ke(p)],values:0,script:!0});if(n[0]?.includes("/")&&An.test(n[0]))return{readings:[a(n[0],1)],nested:r};if((t==="."||t==="source")&&An.test(n[1]??""))return{readings:[a(n[1],2)],nested:r};let l=n.indexOf("--");if(Iy.has(t)&&l>0&&/^[a-z][a-z0-9._-]*$/.test(n[l+1]??"")){let p=o(n[l+1],n.slice(l+2));(t==="kubectl"||t==="oc"||t==="railway")&&/^(exec|run)$/.test(_(n)[0]??"")&&Mr.add(p),r.push(p)}if(aa.has(t)||t==="zsh"){for(let p=1;p<n.length;p++){let d=n[p];if(["-c","-e","--eval","-p","--print","-m"].includes(d))return{readings:s,nested:r};if(Vy.has(d)){p++;continue}if(!d.startsWith("-")){if(An.test(d))return xf(t,n.slice(1,p))?{readings:s,nested:r}:{readings:[a(d,p+1)],nested:r};break}}if(t!=="bun")return{readings:s,nested:r}}let c=By.has(t)?1:["npm","pnpm","yarn","bun"].includes(t)&&["exec","dlx","x"].includes(n[1]??"")?2:-1;if(c>0){let p=c;for(;p<n.length&&n[p].startsWith("-");)p+=["-p","--package"].includes(n[p])?2:1;let d=(n[p]??"").replace(/^@[^/]+\//,"").replace(/@[^/]*$/,"");return/^[a-z][a-z0-9._-]*$/i.test(d)&&r.push(o(d,n.slice(p+1))),{readings:s,nested:r}}if(["npm","pnpm","yarn","bun"].includes(t)){let p=_d(n),d=p[0]??"";if((d==="run"||d==="run-script")&&p[1])s.push(t==="bun"&&An.test(p[1])?a(p[1],n.indexOf(p[1])+1):i(p[1])),t!=="npm"&&/^[a-z][a-z0-9._-]*$/.test(p[1])&&!An.test(p[1])&&r.push(o(p[1],n.slice(n.indexOf(p[1])+1)));else if(d==="npm"&&t==="yarn")r.push(o("npm",n.slice(n.indexOf("npm")+1)));else{if(t==="pnpm"&&d==="deploy")return{readings:s,nested:r};t!=="npm"&&d&&!Zi.has(d)&&(s.push(i(d)),/^[a-z][a-z0-9._-]*$/.test(d)&&r.push(o(d,n.slice(n.indexOf(d)+1))))}let f=n.indexOf("--");return f>0&&/^[a-z][a-z0-9._-]*$/.test(n[f+1]??"")&&r.push(o(n[f+1],n.slice(f+2))),{readings:s,nested:r}}if(["nx","turbo","mise","make","just","task","lerna","run-s","run-p","npm-run-all"].includes(t)){let d=t==="mise"&&!["run","r","watch","w"].includes(n[1]??"")&&!/^(\/\/|:)/.test(n[1]??"")?[]:n.slice(1).filter((h,g,b)=>!h.startsWith("-")&&!h.includes("=")&&!h.startsWith("$")&&!["-C","-f","--file","-j","--projects","-p"].includes(b[g-1]??"")),f=n.flatMap((h,g)=>["-t","--target","--targets"].includes(h)?(n[g+1]??"").split(","):/^--targets?=/.test(h)?h.slice(h.indexOf("=")+1).split(","):[]);for(let h of[...d,...f])h&&h!=="run"&&h!=="run-many"&&h!=="affected"&&!["-t","--target","--targets"].includes(h)&&s.push(i(h));return{readings:s,nested:r}}if(Ni.has(t)||Dy.has(t)||!/^[a-z][a-z0-9._-]*$/.test(t)||/^\/[a-z-]+$/.test(n[0]??""))return{readings:s,nested:r};if(Ke(t).some(p=>Br.has(p)||["print","echo"].includes(p)))return{readings:s,nested:r};let u=Wc(n,1,!0);return s.push({name:t,groups:u.groups.slice(0,4),values:u.values+Math.max(0,u.groups.length-4),script:!1}),{readings:s,nested:r}}var Zy=ae({mix:["release","assets.deploy"]});function Ky(e,n){let t=e.groups.flat();if(t.length===0||!e.script&&Zy[e.name]?.includes(e.groups[0].join(".")))return null;let s=e.script?`runs ${e.name}`:`${e.name} ${e.groups.map(v=>v.join("-")).slice(0,4).join(" ")}`,r=e.script?"(read by its name)":"(read by its words)",o=e.script?e.name:s,a=n.argv.some(v=>Lr.test(v)||Lr.test($(v))),i=a||n.argv.some(v=>Fi.test($(v)));if(e.script&&(t.some(v=>Yu.has(v))||Wy.has(t[0]??"")))return null;if(e.script&&n.argv.some(v=>Pc.test($(v))))return w("claude.bash.deploy",`${s}, told to ${n.argv.map(v=>$(v)).find(v=>Pc.test(v)).slice(2).replace(/=true$/,"")} ${r}`,{target:o,is_local:!1});if(!e.script){if(e.groups[0].length===1&&Br.has(t[0])&&!Tr.has(t[1]??""))return null;let v=t.findIndex(C=>Tr.has(C));if(v>=0&&!t.slice(0,v).some(C=>Wn.has(C))){if(t.some(C=>nd.has(C))&&fe(n))return w("claude.bash.secrets.print",`${s} prints ${ki(t[v])} ${r}`,{target:o,is_local:!0});if(t.some(C=>["create","lease","issue","generate","mint"].includes(C))&&fe(n))return w("claude.bash.secrets.print",`${s} makes a credential and prints it ${r}`,{target:o,is_local:!1});if(t.some(C=>["set","update","put","add","rotate","delete","remove","rm","unset","revoke","reset","reencrypt","rekey"].includes(C)))return w("claude.bash.deploy",`${s} changes a secret a service keeps ${r}`,{target:o,is_local:!1})}if(["post","put","patch"].includes(t[0]??"")&&n.argv.slice(2).some(C=>$(C).includes("/")))return w("claude.bash.external_write",`${e.name} ${t[0]} sends a write to its service's API ${r}`,{target:o,is_local:!1})}if(e.script&&t.includes("down")&&t.some(v=>jy.has(v))&&!t.some(v=>Py.has(v)))return w("claude.bash.deploy",`${s}: named to take down ${t.some(v=>v.startsWith("infra"))?"its infrastructure":"a cluster"} ${r}`,{target:o,is_local:!1});let l=-1;for(let v=0;v<t.length;v++){let C=t[v];(Wr.has(C)||_s.has(C)||Nr.has(C)||!e.script&&(Ii.has(C)||C==="apply"||C==="push"))&&(l=v)}let c=e.script&&t.some(v=>Ly.has(v))&&!t.some(v=>Ny.has(v)||Pn.has(v)),u=n.argv.some(v=>["--force","-f","--yes","-y","--overwrite"].includes($(v))||$(v)==="--force=true"),p=n.argv.some(v=>/\.(tar|tgz|tar\.gz|sql|dump|bak|gz|zip|bson|archive)$/i.test($(v)));if(!e.script&&l<0&&u&&t.some(v=>["import","restore","load"].includes(v))&&(p||t.some(v=>Ac.has(v)))&&!t.some(v=>Pn.has(v)))return w("claude.bash.db.destructive",`${s}: forced, over the data it holds ${r}`,{target:o,is_local:!1});if(l<0)return c?w("claude.bash.deploy",`${s}, named for production ${r}`,{target:o,is_local:!1,host:"production"}):null;let d=t[l];if(t.slice(l+1).some(v=>Pn.has(v)))return null;let f=v=>Gu.has(v)||Ty.has(v),h=[...t.slice(0,l)].reverse().find(f)??t.slice(l+1).find(f)??t.find(f),g=t.some(v=>Ac.has(v)),b=v=>/s$/.test(v)?v:`a ${v}`,k=e.groups.flatMap((v,C)=>v.map(()=>C))[l]??0,E=e.groups.length-1-k,y=n.argv.some((v,C)=>/^--?[a-z][\w-]*=./.test($(v))||/^--?[a-z][\w-]*$/.test($(v))&&/^[^-]/.test($(n.argv[C+1]??"-")));if(Wr.has(d)||_s.has(d)){if(!e.script&&t.slice(0,l).some(N=>Wn.has(N))||!e.script&&h===void 0&&t.length>1&&t.every((N,q)=>q===l||Xu.has(N))||!e.script&&["remove","rm"].includes(d)&&t.slice(0,l).some(N=>Fy.has(N))&&!Ec(n))return null;let v;if(_s.has(d)?v=h!==void 0||(e.script?si.has(d):!1):e.script?k>0?v=["nuke","wipe","purge","destroy","erase",...si].includes(d)||h!==void 0||e.values>0||y||a:v=si.has(d)||h!==void 0||d==="destroy"||["purge","wipe","nuke","erase"].includes(d)&&e.groups[0].length>1:v=h!==void 0||e.values>0||i||E>0||l>0&&Rn.has(d),!v||h===void 0&&t.some(N=>Ju.has(N))&&!Ec(n)&&!My.test(n.text))return null;let C=g||["drop","truncate","flushall","flushdb","purge","wipe"].includes(d)?"claude.bash.db.destructive":"claude.bash.deploy";return w(C,`${s}: ${e.script?`named to ${d}`:Er(d)} ${h?b(h):"what it names"} ${r}`,{target:o,is_local:!1})}if(Nr.has(d))return["build","gen","generate","new","scaffold","init","template"].includes(t[l-1]??"")?null:w(d==="publish"?"claude.bash.publish":"claude.bash.deploy",`${s}: ${e.script?`named to ${d}`:Er(d)} ${r}`,{target:o,is_local:!1});if(d==="push"){if(n.argv.some(C=>["--force","-f","--yes","-y"].includes($(C))))return w("claude.bash.deploy",`${s}: a forced push to its service ${r}`,{target:o,is_local:!1});let v=n.argv.map(C=>$(C)).find(C=>/^[a-z][a-z0-9+.-]*:\/\//.test(C)&&!qe(C));return v?w("claude.bash.publish",`${s}: pushes to ${v.split("/").slice(0,3).join("/")} ${r}`,{target:o,is_local:!1}):null}if(d==="apply")return w("claude.bash.deploy",`${s}: applies a configuration to its service ${r}`,{target:o,is_local:!1});if(t.slice(0,l).some(v=>Wn.has(v)))return null;let m=[...t.slice(0,l)].reverse().find(v=>kr.has(v))??t.slice(l+1).find(v=>kr.has(v))??(a?"a service it signs in to":void 0);if(m===void 0)return null;let R=kr.has(m)?/\d/.test(m)||m.length<=2?`changes ${m.toUpperCase()}, a live service`:`${Er(d)} ${b(m)} on a live service`:m;return w("claude.bash.deploy",`${s}: ${kr.has(m)?R:`changes something on ${m}`} ${r}`,{target:o,is_local:!1})}function Qu(e,n,t){return[e,...t!==void 0&&t!==e?[t]:[]].map(r=>r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).some(r=>new RegExp(`(^|[^>\\w./-])(>|\\btee\\s+)\\s*["']?${r}["']?(\\s|;|&|\\||$)`).test(n.lineText))&&/<<-?\s*['"]?\w+|\bprintf\b|\becho\b|\btee\b/.test(n.lineText)}function ed(e,n){let t=O.basename(n);return e.text.split(/\s+/).map(s=>s.replace(/^["']|["']$/g,"")).find(s=>s===n||s.endsWith(`/${t}`)||s===t)}function Yy(e,n,t){let s=n.argv.map(a=>$(a)).find(a=>O.basename(a)===e.name);if(s===void 0)return!1;let r=te(s,n.cwd,le(t)).path??"",o=t.sessionId;return o!==null&&/^[\w-]{8,}$/.test(o)&&new RegExp(`^/(private/)?tmp/claude-\\d+/[^/]+/${o}/scratchpad/`).test(r)}function Er(e){return{rollback:"rolls back",rollout:"rolls out",teardown:"tears down",rm:"removes",push:"pushes",flushall:"flushes all of",flushdb:"flushes",set:"sets",put:"puts"}[e]??(/(sh|ch|s|x)$/.test(e)?`${e}es`:`${e}s`)}function Jy(e){let n=O.basename(e.name),t=e.argv.map(r=>$(r)),s=r=>[w("claude.agent.controls",`sends keystrokes into a terminal or another app (${r}), which can answer prompts meant for the person`,{target:r,is_local:!0})];return n==="tmux"&&t.some(r=>/^(send-keys|send|send-prefix|paste-buffer|pasteb)$/.test(r))?s("tmux send-keys"):n==="screen"&&t.some((r,o)=>r==="-X"&&/^(stuff|paste|readbuf)$/.test(t[o+1]??""))?s("screen -X stuff"):n==="osascript"&&t.some(r=>/\b(keystroke|key code|key down)\b/i.test(r))?s("osascript keystrokes"):["xdotool","ydotool","wtype","dotool"].includes(n)&&t.slice(1).some(r=>/^(type|key|keydown|keyup)$/.test(r)||n==="wtype")?s(n):n==="kitty"&&t.includes("@")&&t.some(r=>/^send-(text|key)$/.test(r))?s("kitty @ send-text"):n==="wezterm"&&t.includes("cli")&&t.includes("send-text")?s("wezterm cli send-text"):[]}var td=new Set(["dokku","kamal","fly","flyctl","netlify","serverless","sls","caprover","cap","flux","argocd","eb","doctl","hcloud","linode-cli","scw","vultr-cli","civo","koyeb","okteto","porter","northflank","render","sst","amplify"]),Nc=new Set([...Br,"get","describe","logs","log","top","explain","versions","info","port","forward","proxy","wait","diff","events","kustomize","completion","options","print","docs","open","whoami","status","ls","list","show","current","help","version","doctor","details","audit","lint","validate","template","render","search","history","watch","tail","metrics","inspect","check","report","dashboard","export","can","login","logout","auth","context","contexts","use","switch","link","unlink","plugin","console","ssh","exec","shell","debugger","dev","build","test","package"]),Xy=new Set(["local","offline","mock"]),Qy=new Set(["api","resources","cluster","config","apps","domains","certs","volumes","ps","releases","storage","secrets","env","i"]),eb=new Set([...Wr,..._s,...Nr,...Ii,"apply","prune","import","fork","mount","unmount","clear","set","unset","restart","reboot","boot","stop","start","scale","invoke","run","rolling","reconcile","cordon","drain","taint","label","annotate","patch","replace","expose","autoscale","launch","reset","uninstall","upgrade","sync","suspend","resume","enable","disable","detach","attach","join","leave","rotate","renew","issue","revoke","promote","release","redeploy","restore","backup","move","rename","transfer","swap","bootstrap","extend","resize","allocate","clone"]),tb=new Set(["apply","create","delete","edit","patch","replace","scale","autoscale","label","annotate","taint","drain","cordon","uncordon","expose","run","debug","set","rollout","certificate","new-app","new-project","new-build","start-build","cancel-build","rollback","tag","import-image","policy","adm","idle"]),nb=new Set(["-n","--namespace","--context","--cluster","--kubeconfig","--user","-o","--output","-l","--selector","-a","--app","-c","--config","-r","--region","--org","-s","--stage","--profile","--token","--project","--server","-e","--env","--environment","--team","--site","-f","--filename","--function","-d","--destination","--field-selector","--tail","--since","--container","--host","-H","--as","--request-timeout"]);function Lc(e,n){let t=[];for(let s=1;s<e.length&&t.length<n;s++){let r=e[s];if(r==="--")break;if(r.startsWith("-")){!r.includes("=")&&nb.has(r)&&s++;continue}if(r.includes("://")||r.includes("@")||r.includes("/")||!/^[a-z][a-z0-9_.:-]*$/.test(r))break;t.push(r)}return t}function sb(e){let n=O.basename(e.name);if(n!=="docker"&&n!=="docker-compose"&&n!=="podman")return[];let t=e.argv.map(l=>$(l)),s=t.slice(1).filter((l,c,u)=>!l.startsWith("-")&&!["-f","--file","-p","--project-name","--context","-c","-H","--host","--env-file"].includes(u[c-1]??"")),r=n==="docker-compose"||s[0]==="compose",o=r&&n==="docker"?s.slice(1):s,a=o[0]??"",i=(l,c)=>[w(l,`${n} ${o.slice(0,2).join(" ")} ${c}`,{target:`${n} ${o.slice(0,2).join(" ")}`,is_local:!1})];return r?a==="down"&&t.some(l=>l==="-v"||l==="--volumes"||/^-[a-z]*v[a-z]*$/.test(l)&&l!=="-v"&&!l.startsWith("--"))?i("claude.bash.fs.delete_recursive","deletes the project's data volumes"):a==="publish"?i("claude.bash.publish","publishes the project to a registry"):[]:["service","stack","node","secret","config"].includes(a)&&["create","rm","remove","update","scale","deploy","rollback","promote","demote"].includes(o[1]??"")?i("claude.bash.deploy","changes a live swarm"):a==="swarm"&&["join","leave","init","update","unlock-key","ca"].includes(o[1]??"")?i("claude.bash.deploy","changes swarm membership"):a==="buildx"&&o[1]==="imagetools"&&o[2]==="create"&&!t.includes("--dry-run")?i("claude.bash.publish","pushes a manifest to a registry"):a==="trust"&&(["sign","revoke"].includes(o[1]??"")||o[1]==="signer"&&["add","remove"].includes(o[2]??""))?i("claude.bash.publish","changes who can sign images in a registry"):a==="scout"&&o[1]==="repo"&&["enable","disable"].includes(o[2]??"")?i("claude.bash.external_write","changes a registry setting"):[]}function rb(e,n){let t=O.basename(e.name);if(n.ship)return[];let s=e.argv.map(u=>$(u));if(t==="kubectl"||t==="oc"){let[u="",p=""]=Lc(s,2);if(!tb.has(u))return[];if(u==="run"&&dd(s))return[];if((u==="rollout"||u==="adm")&&Nc.has(Ke(p)[0]??""))return[];if(u==="certificate"&&!["approve","deny"].includes(p))return[];let d=["rollout","set","certificate","adm","create"].includes(u)&&p?`${t} ${u} ${p}`:`${t} ${u}`;return[w("claude.bash.deploy",`${d} changes a live cluster`,{target:d,is_local:!1})]}if(!td.has(t))return[];let r=Lc(s,3).filter(u=>!/^\d/.test(u)),o=r.flatMap(u=>Ke(u));if(o.length===0||o.some(u=>Xy.has(u)))return[];if(o.find(u=>["deploy","create","issue","mint","add","generate"].includes(u))!==void 0&&o.some(u=>/^(tokens?|keys?|credentials?)$/.test(u))){let u=`${t} ${r.slice(0,2).join(" ")}`;return[fe(e)?w("claude.bash.secrets.print",`${u} makes a credential and prints it`,{target:u,is_local:!1}):w("claude.bash.deploy",`${u} makes a credential for a live account`,{target:u,is_local:!1})]}if(o.includes("secrets")&&o.some(u=>["extract","print","fetch","get","show"].includes(u)))return fe(e)?[w("claude.bash.secrets.print",`${t} ${r.slice(0,2).join(" ")} prints a secret`,{target:`${t} ${r.slice(0,2).join(" ")}`,is_local:!0})]:[];if(t!=="dokku"&&o.some(u=>u==="plugin"||u==="plugins"))return[];let i=o.find(u=>eb.has(u));if(i===void 0&&o.some(u=>Nc.has(u)))return[];if(i===void 0&&o.every(u=>Qy.has(u)))return[];if(i!==void 0&&Pn.has(o[o.indexOf(i)+1]??""))return[];let l=i!==void 0?r.findIndex(u=>Ke(u).includes(i)):0,c=`${t} ${r.slice(0,Math.max(l,0)+1).join(" ")}`;return[w("claude.bash.deploy",i!==void 0?`${c} changes a live deployment`:`${c} is not a read, and ${t} works on live deployments`,{target:c,is_local:!1})]}function ob(e,n){let t=e.argv.map(c=>$(c)).find((c,u)=>u<=3&&An.test(c));if(t!==void 0){let c=te(t,e.cwd,le(n)).path;if(c&&n.lineMade.includes(c)&&Qu(t,n,ed(e,t)))return[]}if(e.functionCall||S(e.argv[0]??""))return[];if(Di(e))return[];let s=e.argv.slice(1).map(c=>$(c)).find(c=>!c.startsWith("-")&&!/^[A-Za-z_]\w*=/.test(c))??"";if(qy.has(O.basename(e.name))&&(/^(db|migrate|migration|migrations|seed|schema|ecto)([:.]|$)/i.test(s)||["manage.py","artisan"].includes(O.basename(s))))return[];let r=Uy(e,n);if(r.strict)return[];let o=sb(e);if(o.length>0)return o;let a=rb(e,r);if(a.length>0)return a;let{readings:i,nested:l}=Gy(e);for(let c of i){if(c.script&&Yy(c,e,n))continue;let u=Ky(c,e);if(!(u&&r.ship&&(u.action==="claude.bash.publish"||/: (named to )?(deploy|release|publish|promote|rollout|ship)/.test(u.why)))&&u)return[u]}for(let c of l){if(c.argv.length>=e.argv.length&&c.name===e.name)continue;let u=Ps(c,n);if(u.length>0)return u.map(p=>({...p,why:`${p.why} (run by ${O.basename(e.name)})`}))}return[]}var Tr=new Set(["secret","secrets","token","tokens","credential","credentials","password","passwords","apikey","api-key","api_key","apikeys","api-keys"]),nd=new Set(["get","show","reveal","print","read","view","cat","dump","export","decrypt","download","value","access"]),ib="claude.bash.prod.target",ab=new Set(["claude.bash.secrets.print","claude.bash.data.export","claude.file.read_secret"]);function lb(e,n,t,s,r){let o=(a,i)=>{let l=e[a];l.prod||(e[a]={...l,prod:/\bproduction\b/i.test(l.why)?l.why:`${l.why}, on production (${i})`})};for(let a of ic(s,r)){let i=t.filter(p=>!/^(remote|find-exec|stdin-script)$/.test(p.via)&&Ue(p.name)===a.tool),l=i.length===a.of?[i[a.nth]]:i,c=e.flatMap((p,d)=>{for(let f=n.get(p)??null;f;f=f.parent)if(l.includes(f))return[d];return[]});for(let p of c)ab.has(e[p].action)||o(p,a.said);let u=`${[a.tool,..._([a.tool,...a.args]).map(p=>$(p)).filter(p=>/^[a-z][\w./:-]{0,39}$/i.test(p)&&!p.includes("://")).slice(0,3)].join(" ")} uses ${a.said} (production)`;c.length===0&&e.push(w(ib,u,{target:a.said,is_local:!1,...db(a)?{}:{prod:u}}))}e.forEach((a,i)=>{if(a.prod||a.action!=="claude.bash.deploy"&&a.action!=="claude.bash.db.destructive")return;let l=p=>a.action==="claude.bash.deploy"?Zo(p,a.host,r,!0):Ko(p,a.target,a.host,r,!0),c=n.get(a)?.text;if(c!==void 0&&c!==s&&l(c).environment==="non-production")return;let u=l(s);u.environment==="production"&&o(i,u.said??"production")})}var Tc=null,cb=new Set("cat tail head less more grep egrep zgrep ls df du free uptime w who whoami id uname hostname date top htop ps pgrep journalctl stat wc find echo printenv env pwd ss netstat lsof dmesg nproc vmstat iostat which file".split(" ")),ub=new Set("build compile bundle typecheck types tsc lint format fmt prettier eslint docs storybook generate gen codegen analyze size".split(" "));function db(e){Tc??={reads:new Set([...Br,...Wn,"build","ps","images","top","events","port-forward","api-resources","cluster-info","read","scan","query","releases","regions","ips","checks","link","unlink","environment","workspace","select","output","fmt","providers","graph","can-i","variables","vars"]),acts:new Set([...Ii,...Wr,..._s,...Nr,"exec","execute","run","invoke","ssh","shell","console","connect","apply","push","post","patch","import","restore","migrate","seed","sync","upload","send","start","stop","restart","kill","edit","debug","cp","mv","psql"])};let{reads:n,acts:t}=Tc,s=[e.tool,...e.args],r=_(s).map(p=>$(p).toLowerCase());if(/^(curl|wget|https?|xh|scp|rsync)$/.test(e.tool))return!0;let o=p=>p.trim()!==""&&p.split(/&&|\|\||[;|\n]/).every(d=>{let f=d.trim().split(/\s+/).filter(h=>!/^(sudo|env|-\S*|\w+=\S*)$/.test(h));return cb.has(f[0]??"")||/^(systemctl|service|docker|kubectl)$/.test(f[0]??"")&&n.has(f[1]??"")});if(/^(ssh|mosh|autossh)$/.test(e.tool)){let p=0;for(;p<e.args.length&&e.args[p].startsWith("-");)p+=/^-[bcDEeFIiJLlmOopQRSWwB]$/.test(e.args[p])?2:1;return o(e.args.slice(p+1).join(" "))}if(e.tool==="ansible"){let p=(P(s,"-m","--module-name")??"command").replace(/^ansible\.builtin\./,"");return/^(ping|setup|debug|stat|gather_facts|service_facts|package_facts|find|slurp|fetch)$/.test(p)||/^(command|shell|raw)$/.test(p)&&o(P(s,"-a","--args")??"")}if(e.tool==="ansible-playbook")return e.args.some(p=>/^(-C|--check|--list-hosts|--list-tasks|--list-tags|--syntax-check)$/.test(p));let a=/^(npm|pnpm|yarn|bun)$/.test(e.tool)?/^run(-script)?$/.test(r[0]??"")?r[1]:r[0]:/^(make|gmake|just|task)$/.test(e.tool)?r.find(p=>!p.includes("=")):void 0;if(a!==void 0)return ub.has(Ke(a)[0]??"")&&!Ke(a).some(p=>t.has(p));let i=Dc[e.tool]?P(s,...Dc[e.tool].split(" ")):null;if(i!==null)return i.split(";").filter(p=>p.trim()).every(p=>/^\s*(select|show|explain|describe|desc|values|with|table)\b|^\s*\\/i.test(p))&&!Gr.test(i)&&!Ee.test(i);let l=/^(aws|gcloud|az)$/.test(e.tool);if(l&&(Wn.has(r[0]??"")||r[0]==="account"||e.tool==="aws"&&r[0]==="s3"&&/^(cp|sync)$/.test(r[1]??"")))return!0;let c=r.slice(l?1:0,l?4:3).filter(p=>!/[/.:=$]/.test(p)).flatMap(p=>[p,...Ke(p)]),u=p=>c.reduce((d,f,h)=>p.has(f)?h:d,-1);return u(n)>u(t)}var Dc=ae({psql:"-c --command",pgcli:"-c --command",mysql:"-e --execute",mariadb:"-e --execute",mycli:"-e --execute",sqlcmd:"-Q -q","clickhouse-client":"-q --query",cqlsh:"-e --execute"}),Mi=/(^|\/)\*\.(egg-info|pyc|pyo|log|tmp|o|class|orig|rej|bak|swp|tsbuildinfo)$|(^|\/)\*~$/,sd=/^(node_modules|dist|build|out|\.next|coverage|__pycache__|\.pytest_cache|\.mypy_cache|\.ruff_cache|\.cache|\.turbo|\.DS_Store|target|\.tox|\.venv|venv|[\w.-]*\.tsbuildinfo|\*\.(egg-info|pyc|pyo|log|tmp|o|class|orig|rej|bak|swp|tsbuildinfo))$/;function zi(e,n){let t=e.argv.slice(1),s=e.name==="rimraf",r=!1,o=[],a=new Map;for(let[p,d]of t.entries()){if(!r&&d==="--"){r=!0;continue}if(!r&&d.startsWith("--")){d==="--recursive"&&(s=!0);continue}if(!r&&/^-[A-Za-z]+$/.test(d)){/[rR]/.test(d)&&(s=!0);continue}e.via==="find-exec"&&d==="{}"||(o.push(d),a.set(d,p+1))}e.via==="xargs"&&e.pipeFrom&&o.push(...Ui(e.pipeFrom,n));let i=new Map;for(let p of o){let d=It(p),f=od(p,e,a.get(p)).flatMap(It);for(let h of d)i.set(h,f)}if(o.splice(0,o.length,...o.flatMap(It)),o.length===0)return[];let l=o.find(p=>pb(De(p,e,n),e,n));if(l!==void 0)return[w("claude.bash.fs.delete_recursive",`${e.name==="shred"?"shreds":"deletes"} a key or credentials file (${$(l)})`,{target:$(l),is_local:e.remote===null,host:e.remote})];let c=p=>p==="*"||p===".*"||p.endsWith("/*")||p.endsWith("/.*");if(!s&&!o.some(c))return[];let u=o.map(p=>{if(Mi.test(p))return{kind:"disposable",path:p,token:null,why:"build or cache artifacts"};let d=De(p,e,n),f=h=>c(h)?h==="*"||h===".*"?"./":`${h.replace(/\/\.?\*$/,"")}/`:h;return rt(f(d),e,n,(i.get(p)??[]).map(h=>f(De(h,e,n))))});return[Ft(u,e)]}var fb=/^\.(ssh\/(?!known_hosts(\.old)?$|config$)[^/]+|gnupg\/.+|aws\/(credentials|config)|kube\/config|docker\/config\.json|config\/gcloud\/.+|azure\/.+|netrc|git-credentials|npmrc|pypirc)$/;function pb(e,n,t){let s=M(e,n.cwd,t.ctx);if(S(s))return!1;let r=t.ctx.home.replace(/(?<!\/)\/+$/,""),o=s.startsWith(`${r}/`)?s.slice(r.length+1):null;if(o!==null&&fb.test(o))return!0;if(!Re(s)||te(s,null,le(t)).kind==="disposable")return!1;let a=t.projectRoot;return!(a&&!S(a)&&(s===a||s.startsWith(`${a}/`)))}var Ic=64;function It(e){let n=[],t=!1,s=r=>{if(n.length>=Ic){t=!0;return}let o=/^(.*?)\{([^{}]*,[^{}]*)\}(.*)$/s.exec(r);if(!o){n.push(r);return}for(let a of o[2].split(","))s(`${o[1]}${a}${o[3]}`)};return s(e),t?[...n.slice(0,Ic-1),`${J}(more words from a brace expansion)${ee}`]:n}function rd(e,n){let t=e.argv.slice(1);if(!t.some(a=>a==="--del"||a.startsWith("--delete")||a==="--remove-source-files"))return[];if(t.some(a=>a==="-n"||a==="--dry-run"||/^-[a-zA-Z]*n[a-zA-Z]*$/.test(a)))return[];let s=t.filter(a=>!a.startsWith("-")),r=s[s.length-1];if(!r||s.length<2)return[];if(/^[^/]*:/.test(r)&&!r.startsWith("/")&&!(Z()&&/^[A-Za-z]:(?:[\\/]|$)/.test(r)))return[w("claude.bash.fs.delete_recursive",`rsync --delete removes files on ${r.split(":")[0]}`,{target:r,host:r.split(":")[0]??null,is_local:!1})];let o=rt(r,e,n);return[{...Ft([o],e),why:`rsync --delete into ${o.why}`}]}function Ui(e,n){if(e.name==="echo"||e.name==="printf")return e.argv.slice(1).filter(t=>!t.startsWith("-")||t==="-");if(e.name==="find"){let t=Vr(e);return t.disposableFilter?["/tmp/__find_matches_disposable__"]:t.roots}return[`${J}(paths from ${e.name})${ee}`]}function Ft(e,n){let t={catastrophic:2,normal:1,disposable:0},s=[...e].sort((o,a)=>t[a.kind]-t[o.kind])[0],r=n.remote!==null;return s.kind==="disposable"&&!r?w("claude.bash.fs.delete_disposable",`deletes ${e.length>1?"temp, build or scratch paths":s.why}`,{target:s.path,is_local:!0}):w("claude.bash.fs.delete_recursive",`deletes ${s.why}${r?` on ${n.remote}`:""}`,{target:s.path,service:s.kind==="catastrophic"&&!r?s.token:null,is_local:!r,host:n.remote})}function rt(e,n,t,s=od(e,n)){let r=De(e,n,t),o=te(r,n.cwd,le(t));if(o.kind==="catastrophic")return o;for(let a of n.cwdFallbacks){let i=te(r,a,le(t));if(i.kind==="catastrophic")return{...i,why:`${i.why} if the cd before it failed`}}for(let a of s){if(a===""||a===e)continue;let i=te(De(a,n,t),n.cwd,le(t)),l=n.cwdFallbacks.some(c=>c!==null&&(a===c||a.startsWith(`${c}/`)));if(i.kind==="catastrophic")return{...i,why:`${i.why} ${l?"if the cd before it failed":"if an assignment before it did not run"}`}}return o}function od(e,n,t){let s=t??n.argv.indexOf(e);return n.altArgvs.flatMap(r=>r.length===n.argv.length&&s>=0?[r[s]]:r.slice(1))}function le(e){return{home:e.ctx.home,tmpdir:e.ctx.tmpdir,projectRoot:e.projectRoot,base:e.base,onDisk:e.ctx.onDisk??null,made:e.ctx.session?.made??null,ignored:n=>Iu(n,e)}}function Nn(e,n,t=e.base){let s=e.ctx.onDisk,r=S(n)&&!n.startsWith("/")&&!n.startsWith(J)&&t!==null&&t.startsWith("/")&&!S(t)?O.join(t,n):n;S(r)?s?.unknown?.add(r):r.startsWith("/")&&s?.written?.add(r)}function rn(e,n){let t=e.ctx.onDisk;if(!t?.touched||!t.read)return n();let s=new Set([...t.touched.full,...t.touched.parent]),r=n();for(let o of[...t.touched.full,...t.touched.parent])s.has(o)||t.read.add(o);return r}var hb=new Set(["go","cargo","docker","podman","gradle","gradlew","mvn","mvnw","deno","poetry","uv","pipenv","dotnet","swift","flutter","dart","mix","npx","bunx","pnpx"]),gb=new Set(["npm","pnpm","yarn","bun"]),mb=new Set(["make","gmake","just","task","rake","mage"]);function yb(e){let n=he(e.name),t=e.argv.slice(1).filter(r=>!r.startsWith("-")),s=r=>/^[\w:@+-]+$/.test(r);return mb.has(n)?new Set(t.filter(s)):gb.has(n)?new Set((["run","run-script"].includes(t[0]??"")?t.slice(0,2):t.slice(0,1)).filter(s)):hb.has(n)?new Set(t.slice(0,1).filter(s)):new Set}function Dr(e,n,t){return Nn(t,M(De(e,n,t),n.cwd??t.base??t.projectRoot,t.ctx)),rt(e,n,t)}var Fc=new Set(["-name","-iname","-path","-ipath","-wholename","-iwholename","-regex","-iregex","-empty","-mtime","-mmin","-atime","-amin","-ctime","-cmin","-newer","-anewer","-cnewer","-size","-user","-group","-perm","-links","-inum","-samefile","-nouser","-nogroup"]);function bb(e){let n=[[]];for(let a of e)a==="-o"||a==="-or"||a===","?n.push([]):n[n.length-1].push(a);let t=[],s=!1,r=!0,o=!0;for(let a of n){let i=!1,l=!1;for(let c=0;c<a.length;c++){let u=a[c];if(u==="!"||u==="-not"){(a[c+1]==="("||a[c+1]==="\\(")&&(s=!0),c+=Fc.has(a[c+1]??"")||["-type","-maxdepth","-mindepth"].includes(a[c+1]??"")?2:1;continue}Fc.has(u)&&(i=!0,["-name","-iname","-path","-ipath","-wholename"].includes(u)&&a[c+1]!==void 0&&(t.push(a[c+1]),l=!0))}i||(r=!1,a.some(c=>c==="!"||c==="-not")&&(s=!0)),l||(o=!1)}return n.length>1&&!r&&(s=!0),{names:t,narrows:r&&!s,everyBranchNamed:o,invertible:s}}function Vr(e){let n=e.argv.slice(1),t=[],s=0;for(;s<n.length&&(/^-(?:[HLPEX]|O\d+)$/.test(n[s])||n[s]==="-D");)s+=n[s]==="-D"?2:1;for(;s<n.length&&!/^[-(!]/.test(n[s]);)t.push(n[s++]);t.length===0&&t.push(".");let r=!1;for(let g=s;g<n.length;g++){let b=n[g];b==="-delete"&&(r=!0),["-exec","-execdir","-ok","-okdir"].includes(b)&&["rm","unlink","shred","rmdir"].includes(he(n[g+1]??""))&&(r=!0)}let o=n.slice(s),a=bb(o),i=a.names,l=i.length>0&&i.every(g=>sd.test(O.basename(g.replace(/\/$/,"")))||Mi.test(g))&&!a.invertible&&a.everyBranchNamed,c=a.invertible,u=a.narrows,p=u&&o.includes("-empty"),d=o.some((g,b)=>g==="-type"&&o[b+1]==="d"),f=g=>/[*?[]/.test(g),h=u?p?d?"empty folders":"empty files and folders":i.length>0?`${i.every(g=>!f(g))?(i.length===1,"every file named"):"the files matching"} ${i.slice(0,3).join(", ")}${i.length>3?", \u2026":""}`:"the files its filters match":null;return{roots:t,deletes:r,disposableFilter:l,narrowed:h,emptyOnly:p,filesOnly:!u&&o.some((g,b)=>g==="-type"&&o[b+1]==="f"),invertible:c}}function wb(e,n){let t=Vr(e);if(!t.deletes)return[];let s=t.roots.map(l=>Dr(l,e,n)),r=s.find(l=>l.token==="fs.root"||l.token==="fs.home"||l.token==="fs.system");if(t.disposableFilter&&r)return[w("claude.bash.fs.delete_recursive",`find deletes matching files under ${r.path}`,{target:t.roots.join(" "),is_local:!0})];if(t.disposableFilter)return[w("claude.bash.fs.delete_disposable","find deletes build or cache artifacts",{target:t.roots.join(" "),is_local:!0})];let o=r??s.find(l=>l.kind==="catastrophic")??s.find(l=>l.kind==="normal")??s[0],a=o.token==="fs.home"&&o.path===n.ctx.home.replace(/(?<!\/)\/+$/,"")?"your home folder":o.token==="fs.project_root"?"the project":o.token==="fs.root"?"the whole disk":$(o.path);if(t.narrowed!==null){let l=`find deletes ${t.narrowed} under ${a}`;return t.emptyOnly&&!r?[w("claude.bash.fs.delete_disposable",l,{target:t.roots.join(" "),is_local:!0})]:s.every(c=>c.kind==="disposable")?[w("claude.bash.fs.delete_disposable",l,{target:t.roots.join(" "),is_local:!0})]:[w("claude.bash.fs.delete_recursive",l,{target:t.roots.join(" "),is_local:!0})]}let i=Ft(s,e);return i.action==="claude.bash.fs.delete_recursive"&&t.filesOnly?[{...i,why:`find deletes every file under ${a}`}]:i.action==="claude.bash.fs.delete_recursive"&&t.invertible?[{...i,why:`find deletes everything under ${a} except what its filter keeps`}]:[i]}var kb=new Set(["-t","--type","-e","--extension","-d","--max-depth","--min-depth","--exact-depth","-E","--exclude","-S","--size","--changed-within","--changed-before","-o","--owner","-j","--threads","--path-separator","-c","--color","--ignore-file","--max-results","--batch-size"]);function vb(e,n){let t=e.argv.slice(1),s=t.findIndex(g=>["-x","--exec","-X","--exec-batch"].includes(g));if(s<0||!["rm","unlink","shred","rmdir"].includes(he(t[s+1]??"")))return[];if(he(t[s+1]??"")==="rmdir")return[];let r=t.slice(0,s).flatMap((g,b)=>g==="-t"||g==="--type"?[t[b+1]??""]:/^-t./.test(g)?[g.slice(2)]:g.startsWith("--type=")?[g.slice(7)]:[]);if(r.some(g=>g==="e"||g==="empty"))return[w("claude.bash.fs.delete_disposable","fd deletes empty files or folders",{target:".",is_local:!0})];let o=[],a=[],i=[],l=!1;for(let g=0;g<s;g++){let b=t[g];b==="--search-path"||b==="--base-directory"?(t[g+1]!==void 0&&a.push(t[g+1]),g++):b==="-e"||b==="--extension"?(t[g+1]!==void 0&&i.push(`*.${t[g+1].replace(/^\./,"")}`),g++):b.startsWith("--extension=")?i.push(`*.${b.slice(12).replace(/^\./,"")}`):b==="-g"||b==="--glob"?l=!0:b.startsWith("-")?kb.has(b)&&g++:o.push(b)}let c=o[0]??"";if(c!==""&&c!=="."&&c!=="^"){let g=/^\\?\.([\w-]+)\$$/.exec(c);i.push(l?c:g?`*.${g[1]}`:c.replace(/^\^|\$$/g,"").replace(/\\(.)/g,"$1"))}let u=[...o.slice(1),...a];u.length===0&&u.push(".");let p=u.map(g=>Dr(g,e,n)),d=p.find(g=>g.token==="fs.root"||g.token==="fs.home"||g.token==="fs.system"),f=i.length>0&&i.every(g=>sd.test(O.basename(g))||Mi.test(g));return f&&d?[w("claude.bash.fs.delete_recursive",`fd deletes matching files under ${d.path}`,{target:u.join(" "),is_local:!0})]:f?[w("claude.bash.fs.delete_disposable","fd deletes build or cache artifacts",{target:u.join(" "),is_local:!0})]:i.length>0||r.length>0||t.slice(0,s).some(g=>/^(-S|--size|--changed-(within|before)|--newer|--older)(=|$)/.test(g))?[w("claude.bash.fs.delete_recursive",`fd deletes the files matching ${i.join(", ")||"its filters"} under ${u.join(" ")}`,{target:u.join(" "),is_local:!0})]:[Ft(p,e)]}function Mc(e,n){let t=e.argv.slice(1);if(e.name==="dd"){let s=t.find(o=>o.startsWith("of="))?.slice(3);if(!s)return[];let r=rt(s,e,n);return r.token==="fs.device"?[w("claude.bash.fs.delete_recursive",`overwrites a raw disk (${s})`,{target:s,service:"fs.device",is_local:!0})]:_f.test(s)&&r.kind!=="disposable"?[w("claude.bash.fs.delete_recursive",`dd overwrites a data file (${O.basename(s)})`,{target:r.path,is_local:!0})]:[]}return e.name==="diskutil"?t.some(s=>/^(erase|zeroDisk|randomDisk|secureErase|partitionDisk|reformat)/i.test(s))?[w("claude.bash.fs.delete_recursive","erases a disk",{target:t.join(" "),service:"fs.device",is_local:!0})]:[]:[w("claude.bash.fs.delete_recursive",`formats or repartitions a disk (${e.name})`,{target:t.join(" "),service:"fs.device",is_local:!0})]}function Xe(e){let n=e.argv,t=1,s=null;for(;t<n.length;){let o=n[t];if(o==="-C"&&n[t+1])s=n[t+1],t+=2;else if(o==="-c"||o==="--git-dir"||o==="--work-tree"||o==="--namespace")o==="--work-tree"&&n[t+1]&&(s=n[t+1]),t+=2;else if(o.startsWith("--work-tree="))s=o.slice(12),t++;else if(o.startsWith("-"))t++;else break}let r=n[t];return r?{sub:r,args:n.slice(t+1),dir:s}:null}function id(e,n){return e.cwdFallbacks.length>0||e.altArgvs.length>0||/\bgit\s+(?:-[cC]\s+\S+\s+|--?[\w-]+=\S+\s+|-(?![cC]\s)[\w-]+\s+)*(?:remote\s+(?:add|set-url|rename|remove|rm|set-head|set-branches)\b|config\s+(?!--get|--list|-l\b)|clone\b|init\b|submodule\b)|\bgh\s+repo\s+(?:clone|set-default|create|fork)\b|\b(?:HOME|XDG_CONFIG_HOME)=|\bGIT_(?:CONFIG|DIR|WORK_TREE|COMMON_DIR)|--git-dir|--work-tree/.test(n)}function Ln(e,n,t){if(/\bGIT_(DIR|WORK_TREE|COMMON_DIR)\b|--git-dir/.test(t.lineText)||e.wrappers.includes("env")&&e.wrapperArgs.some(r=>/^-C/.test(r)||r.startsWith("--chdir")))return null;let s=n.dir?ud(n.dir,e,t):e.cwd;return s===null||S(s)?null:s}function $b(e,n,t){let s=e[n];if(!/^-[a-zA-Z]/.test(s))return null;for(let r=1;r<s.length;r++)if(t.includes(s[r]))return{letter:s[r],value:s.slice(r+1)||e[n+1]};return null}function ad(e,n){let[t,s,r]=n==="switch"?["c","C","--create"]:["b","B",""],o=[];for(let a=0;a<e.length;a++){let i=e[a];if(i==="--")break;if(i==="--force-create"&&e[a+1])o.push({letter:s,branch:e[++a]});else if(i.startsWith("--force-create="))o.push({letter:s,branch:i.slice(15)});else if(r&&i===r&&e[a+1])o.push({letter:t,branch:e[++a]});else if(r&&i.startsWith(`${r}=`))o.push({letter:t,branch:i.slice(r.length+1)});else{let l=$b(e,a,t+s);l&&l.value!==void 0&&(o.push({letter:l.letter,branch:l.value}),l.value===e[a+1]&&a++)}}return o}function xb(e,n){return ad(e,n).at(-1)??null}function _b(e,n){if(e.name!=="git")return;let t=Xe(e);if(!t)return;let s=t.dir??e.cwd;if(t.sub==="stash"){let r=t.args[0];(r===void 0||r==="push"||r==="save"||r.startsWith("-"))&&(n.stashCreated=!0),r==="apply"&&n.stashApplied.set(Hi(t.args.slice(1)),bn(e))}if(t.sub==="worktree"&&t.args[0]==="add"){let r=t.args.lastIndexOf("-b");r>=0&&t.args[r+1]&&n.createdBranches.set(t.args[r+1],{by:bn(e),repo:Ln(e,t,n)})}if(t.sub==="checkout"||t.sub==="switch"){if(t.args.includes("--"))return;let r=xb(t.args,t.sub);if(r){n.branch=r.branch,n.branchDir=s,(r.letter==="b"||r.letter==="c")&&n.createdBranches.set(n.branch,{by:bn(e),repo:Ln(e,t,n)});return}let o=t.args.find(a=>!a.startsWith("-"));o&&!o.includes("/")&&o!=="."&&!S(o)&&(n.branch=o,n.branchDir=s)}}function Sb(e,n){return n===e.branchDir?e.branch:null}function qi(e){return e!==null&&/\/scratchpad(\/|$)/.test(e)}function vt(e,n){return e===null?!1:qi(e)?!0:te(e,null,le(n)).kind==="disposable"}function zc(e,n,t,s){let r=n!==null&&!S(n)?n.replace(/(?<!\/)\/+$/,""):null,a=(t.ctx.projectControls??[]).filter(l=>typeof l=="object"&&l!==null&&typeof l.path=="string").filter(l=>(r===null||l.path.startsWith(`${r}/`))&&(l.staged===!0?s.staged:l.ignored===!0?s.ignored:s.untracked)).map(l=>l.path);if(a.length===0)return[];let i=$(a[0]);return[w("claude.agent.controls",`${e} takes this project's own ${O.basename(i)} away, so later sessions here run without it`,{target:i,is_local:!0})]}function ld(e,n,t){let s=/^:(?:\(([^)]*)\)|([/!^]*):?)/.exec(e),r=s?s[1]!==void 0?s[1].split(","):[...s[2]].map(c=>c==="/"?"top":"exclude"):[];if(r.includes("exclude"))return!1;let o=e.slice(s?s[0].length:0).replace(/(^|\/)\*+$/,"$1");if(S(o))return!1;let a=O.normalize(/^~(\/|$)/.test(o)?t+o.slice(1):o).replace(/(.)\/$/,"$1");if(r.includes("top"))return a===".";if(a==="."||/^\.\.(\/\.\.)*$/.test(a))return!0;if(n===null||S(n)||!n.startsWith("/"))return!1;let i=O.normalize(n).replace(/(.)\/$/,"$1"),l=O.resolve(i,a);return l==="/"||i===l||i.startsWith(`${l}/`)}var Cb=new RegExp(`^${J}(?:\\$\\(|\`)[^${ee}]*${ee}$`);function Uc(e,n,t,s,r,o){let a=s.via==="xargs"?s.pipeFrom:s.via==="find-exec"?s.parent:void 0,i=a===void 0?[]:a?Ui(a,o):[J];return i.some(S)||t.some(l=>l.startsWith("--pathspec-from-file"))?!0:[...e,...i].some(l=>n&&Cb.test(l)||ld(l,r,o.ctx.home))}function Ab(e){let n=[];for(let t=0;t<e.length;t++){let s=e[t];if(s==="--")return[...n,...e.slice(t+1)];/^(-[^-s]*s|--(source|conflict|pathspec-from-file))$/.test(s)?t++:s.startsWith("-")||n.push(s)}return n}var Eb=["cd","pushd","export","set","true",":"],ri=e=>e==="HEAD"||e==="@";function kt(e,n,t,s,r){let o=t.lineCommands??[],a=o.indexOf(n),i=Xe(n),l=i?n.argv.slice(1,n.argv.length-i.args.length-1):[],c=typeof r=="object"?(r.specs??[]).map(v=>/^~(\/|$)/.test(v)?t.ctx.home+v.slice(1):v):[];if(!i||t.ctx.nested||t.ctx.powershell||!t.lineWhole||a<0||o.slice(0,a).some(v=>!Eb.includes(v.name))||n.via!=="top"||n.parent||n.wrappers.length>0||n.cwdFallbacks.length>0||n.altArgvs.length>0||!/^(\S*\/)?git\s/.test(n.text)||n.argv.some(S)||l.length>0&&(l.length!==2||l[0]!=="-C")||/\bGIT_[A-Z_]+|\b(HOME|XDG_CONFIG_HOME)=|--recurse-submodules/.test(t.lineText)||c.some(v=>/^~|[{(]/.test(v))||s===null||!s.startsWith("/")||S(s))return e;let u=["git",i.sub,...i.args].join(" "),p=(v,C)=>({...e,why:w(e.action,`${v} (${u.length>80?`${u.slice(0,79)}\u2026`:u})`).why,service:C?ut:null}),d=(v,C)=>v>0?[`${v} ${C}${v===1?"":"s"}`]:[],f=v=>v.length<2?v.join(""):`${v.slice(0,-1).join(", ")} and ${v.at(-1)}`;if(typeof r=="string"){let v=je(t,{kind:"stashes",cwd:s});if(typeof v!="string")return e;let C=v.split(`
|
|
47
|
+
`).filter(B=>B!==""),N=B=>`stash@{${B}}: ${C[B].length>60?`${C[B].slice(0,59)}\u2026`:C[B]}`;if(C.length===0)return p("no stash to lose",!1);if(r==="clear")return p(`would throw away ${C.length===1?N(0):`${C.length} stashes`}`,!0);let q=/^stash@\{(\d+)\}$/.exec(Hi(i.args.slice(1)))?.[1];return q===void 0?e:Number(q)<C.length?p(`would throw away ${N(Number(q))}`,!0):p(`no stash@{${q}} to lose`,!1)}let h=je(t,{kind:"status",cwd:s,arg:`${r.ignored?"x":r.submodules?"s":"-"}${c.join("\0")}`});if(typeof h!="string")return e;let[g,b,k,E,y]=[0,0,0,0,0];for(let v of h.split(`
|
|
48
|
+
`)){if(v.length<4)continue;let C=v.endsWith("/");v.startsWith("??")?C?k++:b++:v.startsWith("!!")?C?y++:E++:(r.tracked==="all"||r.tracked==="unstaged"&&v[1]!==" ")&&g++}let m=[...d(g,"changed file"),...r.untracked==="gone"?[...d(b,"untracked file"),...d(k,"untracked folder")]:[],...r.ignored?[...d(E,"ignored file"),...d(y,"ignored folder")]:[]],R=r.untracked==="may"?d(b+k,"untracked file"):[];return m.length+R.length===0?p(r.tracked?"nothing uncommitted to lose":`no ${[r.untracked?"untracked":"",r.ignored?"ignored":""].filter(v=>v!=="").join(" or ")} files to lose`,!1):p([...m.length>0?[`would throw away ${f(m)}`]:[],...R.map(v=>`may overwrite ${v}`)].join(" and "),!0)}function cd(e,n){let t=Xe(e);if(!t)return[];let s=t.dir?ud(t.dir,e,n):e.cwd,r=i=>t.args.some(l=>i.includes(l)),o=i=>t.args.some(l=>/^-[a-zA-Z]+$/.test(l)&&l.includes(i)),a=t.sub.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();if(/(^|-)(delete|del|remove|rm|prune|purge|drop|nuke|wipe|clean|cleanup)(-|$)/.test(a)&&/(^|-)(branch|branches|tag|tags|gone|merged|stale|worktree|worktrees)(-|$)/.test(a))return[w("claude.bash.git.discard",`git ${t.sub}: a command named for deleting branches or tags (an alias or extension)`,{target:[t.sub,...t.args.filter(i=>!i.startsWith("-"))].join(" "),is_local:!0})];switch(t.sub){case"push":{let i=id(e,n.lineText)||e.argv.filter(l=>l==="-C").length>1||e.argv.some(l=>/^(-c|--config-env)/.test(l))?null:Ln(e,t,n);return Rb(t.args,n,e,Sb(n,t.dir??e.cwd),i)}case"reset":if(r(["--hard"])&&!qi(s)){let i=t.args.find(l=>!l.startsWith("-"))??"HEAD";return[kt(w("claude.bash.git.discard","git reset --hard discards uncommitted work",{target:i,branch:n.branch,is_local:!0,service:ut}),e,n,s,{tracked:"all",...ri(i)?{}:{untracked:"may"}})]}return[];case"checkout":{let i=t.args.indexOf("--"),l=i>=0?t.args.slice(i+1):t.args.filter(c=>!c.startsWith("-"));if((Uc(l,i>=0,t.args,e,s,n)||r(["--force"])||t.args.some(c=>/^-[^-bB]*f/.test(c)))&&!vt(s,n)){let c=(i>=0?t.args.slice(0,i):t.args).filter(d=>!d.startsWith("-")),p=(i>=0?c.length>0:c.length===0||c.some(d=>!/^[./]/.test(d)))?{tracked:"all",specs:i>=0?l:[],...c.every(ri)?{}:{untracked:"may"}}:{tracked:"unstaged",specs:l};return[kt(w("claude.bash.git.discard","git checkout discards every uncommitted change",{target:l.join(" ")||".",branch:n.branch,is_local:!0,service:ut}),e,n,s,p)]}return qc(t.args,"checkout",e,n)}case"rm":{let i=t.args.filter(c=>!c.startsWith("-"));return i.some(c=>ld(c,s,n.ctx.home))&&(r(["-f","--force"])||o("f"))&&!r(["--cached","-n","--dry-run"])&&!o("n")&&!vt(s,n)?[kt(w("claude.bash.git.discard","git rm -f deletes every tracked file, uncommitted changes too",{target:i.join(" "),branch:n.branch,is_local:!0,service:ut}),e,n,s,{tracked:"all",specs:i,submodules:!0})]:[]}case"restore":{let i=r(["--staged"])||o("S");if(i&&!r(["--worktree"])&&!o("W"))return[];let l=Ab(t.args);if(Uc(l,!0,t.args,e,s,n)&&!vt(s,n)){let c={tracked:i?"all":"unstaged",specs:l,...t.args.some(u=>/^(-[^-]*s|--source)/.test(u))?{untracked:"may"}:{}};return[kt(w("claude.bash.git.discard","git restore discards every uncommitted change",{target:l.join(" ")||".",branch:n.branch,is_local:!0,service:ut}),e,n,s,c)]}return[]}case"branch":{let i=t.args.filter(f=>!f.startsWith("-")),l=r(["-f","--force"])||o("f"),c=r(["-d","--delete","-D"])||t.args.some(f=>/^-[a-zA-Z]*[dD]/.test(f)&&/^-[a-zA-Z]+$/.test(f)),u=c&&(r(["-D"])||t.args.some(f=>/^-[a-zA-Z]*D/.test(f))||l);if(u&&i.length>0&&i.every(f=>vs(f,e,n)||Dm(f,Ln(e,t,n),n)))return[];if(u)return[w("claude.bash.git.discard","git branch force-deletes a branch",{target:i.join(" "),is_local:!0})];let p=f=>t.args.some(h=>/^-[a-zA-Z]{2,}$/.test(h)&&f.test(h.slice(1))),d=r(["-m","--move","-c","--copy"])||p(/[mc]/);return r(["-M","-C"])||p(/[MC]/)||l&&d?[w("claude.bash.git.discard","git branch -M / -C overwrites a branch",{target:i.join(" "),is_local:!0})]:l&&!c&&i[0]!==void 0&&!vs(i[0],e,n)?[w("claude.bash.git.discard",`git branch -f moves ${i[0]}`,{target:i.join(" "),branch:i[0],is_local:!0})]:[]}case"stash":{if(t.args[0]==="drop"){let u=Hi(t.args.slice(1)),p=d=>d!==void 0&&e.guards.includes(d);if(p(n.stashApplied.get(u)))return[];if(u.startsWith("computed:")&&n.stashCreated&&[...n.stashApplied.values()].some(p))return[]}if(t.args[0]==="drop"||t.args[0]==="clear")return[kt(w("claude.bash.git.discard",`git stash ${t.args[0]} deletes stashed work`,{target:t.args.slice(1).join(" ")||"stash",is_local:!0,service:ut}),e,n,s,t.args[0])];let i=t.args.length===0||["push","save"].includes(t.args[0])||t.args[0].startsWith("-"),l=r(["--all"])||o("a"),c=/\bgit\s+add\s+(?:[^;&|\n]*\s)?(-A|--all|\.)(\s|$)/.test(n.lineText.slice(0,65536));return i?zc("git stash",null,n,{untracked:l||c||r(["--include-untracked"])||o("u"),ignored:l,staged:!0}):[]}case"clean":{if(r(["--dry-run"])||o("n"))return[];let i=r(["--force"])||o("f"),l=e.argv.some((f,h)=>e.argv[h-1]==="-c"&&/^clean\.requireforce=(false|no|off|0|)$/i.test(f));if(!(i||l)||vt(s,n))return[];let c={untracked:!o("X"),ignored:o("x")||o("X"),staged:!1},u=s??e.cwd,p=i?"git clean -f":"git clean",d={tracked:null,specs:t.args.some(f=>!f.startsWith("-"))?[]:["."],...c.untracked?{untracked:"gone"}:{},ignored:c.ignored};return[kt(w("claude.bash.git.discard",`${p} deletes untracked files`,{target:s??".",is_local:!0,service:ut,housekeeping:u!==null&&n.lineMade.some(f=>jn(f,u))}),e,n,s,d),...zc(p,s,n,c)]}case"checkout-index":case"read-tree":{let i=t.sub==="read-tree"?r(["--reset"])&&o("u"):(r(["--all"])||o("a"))&&(r(["--force"])||o("f"))&&!t.args.some(c=>c==="--temp"||c.startsWith("--prefix")&&!/^--prefix=(\.\/?)?$/.test(c)),l=t.sub==="checkout-index"?{tracked:"unstaged"}:{tracked:"all",...t.args.filter(c=>!c.startsWith("-")).every(ri)?{}:{untracked:"may"}};return i&&!vt(s,n)?[kt(w("claude.bash.git.discard",`git ${t.sub} discards every uncommitted change`,{target:".",branch:n.branch,is_local:!0,service:ut}),e,n,s,l)]:[]}case"reflog":return t.args[0]==="delete"||t.args[0]==="expire"&&t.args.some(i=>/^--expire=(now|all|0)/.test(i)||i==="--all")?[w("claude.bash.git.discard",`git reflog ${t.args[0]} removes the record of lost commits`,{is_local:!0})]:[];case"gc":return t.args.some(i=>i==="--prune=now"||i==="--prune=all")?[w("claude.bash.git.discard","git gc --prune=now makes lost commits unrecoverable",{is_local:!0})]:[];case"filter-branch":case"filter-repo":return[w("claude.bash.git.discard",`git ${t.sub} rewrites history`,{is_local:!0})];case"symbolic-ref":{let i=t.args.filter(l=>!l.startsWith("-"));return!r(["-d","--delete"])&&i.length>=2&&i[0]!=="HEAD"?[w("claude.bash.git.discard",`git symbolic-ref points ${i[0]} at ${i[1]}`,{target:i[0],is_local:!0})]:[]}case"update-ref":{if(r(["-d"]))return[w("claude.bash.git.discard","git update-ref -d deletes a ref",{target:t.args.find(l=>!l.startsWith("-"))??null,is_local:!0})];let i=t.args.filter((l,c)=>!l.startsWith("-")&&t.args[c-1]!=="-m")[0]??"";return r(["--stdin"])||i.startsWith("refs/heads/")&&!vs(i.slice(11),e,n)?[w("claude.bash.git.discard",`git update-ref moves ${i||"refs from stdin"}`,{target:i||"stdin",is_local:!0})]:[]}case"worktree":if(t.args[0]==="add"){let i=t.args.findIndex(c=>c==="-B"),l=i>0?t.args[i+1]:void 0;if(l!==void 0&&!vs(l,e,n))return[w("claude.bash.git.discard",`git worktree add -B resets ${l}`,{target:l,branch:l,is_local:!0})]}if(t.args[0]==="remove"&&(r(["--force"])||o("f"))){let i=t.args.slice(1).find(u=>!u.startsWith("-"))??"",l=t.dir&&!S(t.dir)?te(t.dir,e.cwd,le(n)).path??e.cwd:e.cwd,c=te(i,l,le(n));return vt(c.path,n)||c.why===rs?[]:e.guards.some(u=>/\bgit\b[^;&|]*\bworktree\s+add\b/.test(u)&&u.split(/\s+/).some(p=>p.replace(/^["']|["']$/g,"")===i))?[]:[kt(w("claude.bash.git.discard","git worktree remove --force discards its changes",{target:i,is_local:!0,service:ut}),e,n,c.path,{tracked:"all",untracked:"gone",submodules:!0})]}return[];case"switch":return r(["--discard-changes","--force"])||t.args.some(i=>/^-[^-cC]*f/.test(i))?[kt(w("claude.bash.git.discard","git switch discards uncommitted changes",{branch:n.branch,is_local:!0,service:ut}),e,n,s,{tracked:"all",untracked:"may"})]:qc(t.args,"switch",e,n);default:return[]}}function qc(e,n,t,s){let r=ad(e,n).find(o=>(o.letter==="B"||o.letter==="C")&&!vs(o.branch,t,s));return r?[w("claude.bash.git.discard",`git ${n} -${r.letter} resets ${r.branch}`,{target:r.branch,branch:r.branch,is_local:!0})]:[]}function vs(e,n,t){let s=t.createdBranches.get(e),r=Xe(n),o=r?Ln(n,r,t):null;return s!==void 0&&n.guards.includes(s.by)&&s.repo!==null&&s.repo===o}function Hi(e){let n=e.find(t=>!t.startsWith("-"));return n===void 0?"stash@{0}":/^\d+$/.test(n)?`stash@{${n}}`:S(n)?`computed:${$(n)}`:n}function ud(e,n,t){let s=`${e.replace(/\/$/,"")}/_`,r=De(s,n,t);return te(r!==s&&r.endsWith("/_")?r.slice(0,-2):e,n.cwd,le(t)).path}function Rb(e,n,t,s,r=null){let o=!1,a=!1,i=!1,l=[],c=null,u=new Set(["--repo","--receive-pack","--exec","-o","--push-option","--signed"]);for(let b=0;b<e.length;b++){let k=e[b];if(k==="-n"||k==="--dry-run")return[];if(k==="-f"||k==="--force"||k.startsWith("--force-with-lease")||k==="--force-if-includes"||k==="--mirror")o=!0;else if(k==="-d"||k==="--delete")a=!0;else if(k==="--all"||k==="--branches")i=!0;else if(/^-[a-zA-Z]+$/.test(k)){if(k.includes("f")&&(o=!0),k.includes("n"))return[];k.includes("d")&&(a=!0)}else k==="--repo"?c=e[++b]??null:k.startsWith("--repo=")?c=k.slice(7):u.has(k)?b++:k.startsWith("-")||l.push(k)}let p=l[0]??c,d={repo_dir:r===null||S(r)?null:r,repo_remote:p===null?null:S(p)?"$?":$(p),repo_via:"git"};if(e.includes("--mirror"))return[w("claude.bash.git.force_push","mirrors every branch and tag to the remote, overwriting or deleting what differs (main included)",{branch:null,target:"every branch and tag",service:null,is_local:!1})];let f=l.slice(1),h=[];f.length===0&&h.push({branch:i?"main":s,plus:!1,deleting:!1});for(let b of f){let k=b.startsWith("+"),E=k?b.slice(1):b,y=E.indexOf(":"),m=y>=0?E.slice(0,y):E,R=y>=0?E.slice(y+1):E,v=y===0,C=N=>S(N)&&/git\s+(branch\s+--show-current|rev-parse\s+--abbrev-ref\s+HEAD|symbolic-ref\s+--short\s+HEAD)/.test($(N));(R==="HEAD"||y<0&&m==="HEAD"||C(R))&&(R=s??""),R=R.replace(/^refs\/heads\//,""),h.push({branch:R||null,plus:k,deleting:v||a})}let g=[];for(let b of h){let k=b.branch!==null&&Uu.has(b.branch),E=b.branch??"the current branch";b.deleting?g.push(k?w("claude.bash.git.force_push",`deletes the remote ${E} branch`,{branch:b.branch,target:E,service:"git.main",is_local:!1}):w("claude.bash.git.discard",`deletes the remote branch ${E}`,{branch:b.branch,target:E,is_local:!1})):o||b.plus?g.push(w("claude.bash.git.force_push",`force-pushes ${E}`,{branch:b.branch,target:E,service:k?"git.main":null,is_local:!1})):k?g.push(w("claude.bash.git.push_main",`pushes to ${b.branch} (a deploy)`,{branch:b.branch,target:b.branch,is_local:!1,push:d})):b.branch!==null&&uy.has(b.branch)&&g.push(w("claude.bash.deploy",`pushes to ${b.branch} (a deploy branch)`,{branch:b.branch,target:b.branch,is_local:!1}))}return g}function dd(e){let n=e.indexOf("--"),s=(n<0?e:e.slice(0,n)).filter(r=>r==="--rm"||r.startsWith("--rm="));return s.length>0&&!/^--rm=(false|0)$/i.test(s[s.length-1])}function Ob(e,n){let t=n.ctx.session?.repoRemotes;if(!t||!e.cwd||S(e.cwd))return null;let s=Object.keys(t).filter(r=>e.cwd===r||e.cwd.startsWith(`${r}/`)).sort((r,o)=>o.length-r.length)[0];return s===void 0?null:t[s]??null}function jb(e,n){let t=Ob(e,n)?.filter(Boolean);if(!t||t.length===0)return!1;let s=[];return e.argv.forEach((r,o)=>{r==="-R"||r==="--repo"?s.push(e.argv[o+1]??null):r.startsWith("--repo=")?s.push(r.slice(7)):/^-R\S/.test(r)&&s.push(r.slice(2))}),s.length===0?!1:s.every(r=>!r||S(r)?!1:t.includes((Pb(r)??r).toLowerCase().replace(/^github\.com\//,"")))}function Pb(e){let n=/github\.com[:/]+([\w.-]+)\/([\w.-]+?)(?:\.git)?\/?$/.exec(e.trim());return n?`${n[1]}/${n[2]}`:null}function vr(e,n){let t=[];e.argv.forEach((l,c)=>{l==="-R"||l==="--repo"?t.push(e.argv[c+1]??""):l.startsWith("--repo=")?t.push(l.slice(7)):/^-R\S/.test(l)?t.push(l.slice(2).replace(/^=/,"")):/^-[A-Za-z]+R/.test(l)&&t.push("$?")});let s=e.argv.slice(3).find(l=>/^https?:\/\/[^/]+\/[^/]+\/[^/]+\/(?:pulls?|issues)\/\d+/.test($(l))),o=[...e.text.slice(0,Math.max(0,e.text.search(/(?:^|\s)(?:\S*\/)?gh\s/))).matchAll(/\bGH_REPO=("[^"]*"|'[^']*'|[^\s;&|)]+)/g)].pop()?.[1]?.replace(/^["']|["']$/g,""),a=s??t[t.length-1]??o??null;return{repo_dir:e.cwd!==null&&!S(e.cwd)&&(a!==null||!(id(e,n)||/\bGH_REPO\b/.test(n)))?e.cwd:null,repo_remote:a===null?null:S(a)?"$?":$(a),repo_via:"gh"}}function Wb(e,n,t){let[,s="",r=""]=e.argv,o=e.argv.slice(3),a=(...l)=>e.argv.some(c=>l.includes(c)||l.some(u=>c.startsWith(`${u}=`)));if(s==="pr"&&r==="merge")return[w("claude.bash.git.push_main","gh pr merge merges a pull request into its base branch (main, unless it says otherwise: a deploy)",{target:o.find(l=>!l.startsWith("-"))??"current PR",branch:"main",is_local:!1,host:"github.com",push:vr(e,n)})];if(s==="pr"&&(r==="create"||r==="edit"))if(a("-R","--repo")||e.argv.some(c=>/^-R\S/.test(c))||/\bGH_REPO=/.test(n)){if(t&&!/\bGH_REPO=/.test(n)&&jb(e,t))return[]}else return[];let i={pr:new Set(["create","comment","review","close","reopen","edit","ready","lock","unlock"]),issue:new Set(["create","comment","close","reopen","edit","delete","transfer","lock","unlock","pin","unpin","develop"]),release:new Set(["delete","edit","upload","delete-asset"]),repo:new Set(["create","delete","edit","fork","rename","archive","unarchive"]),secret:new Set(["set","delete","remove"]),variable:new Set(["set","delete"]),workflow:new Set(["run","enable","disable"]),run:new Set(["cancel","delete"]),gist:new Set(["create","edit","delete"]),label:new Set(["create","edit","delete","clone"]),cache:new Set(["delete"])};if(s==="release"&&r==="create")return a("--draft","-d")?[w("claude.bash.external_write","gh release create makes a draft release on GitHub (nothing is published until someone publishes it)",{target:o.find(l=>!l.startsWith("-"))??null,is_local:!1,host:"github.com",push:vr(e,n)})]:[w("claude.bash.publish","gh release create publishes a release",{target:o.find(l=>!l.startsWith("-"))??null,is_local:!1,host:"github.com",push:vr(e,n)})];if(s==="workflow"&&r==="run"){let l=e.argv.findIndex(h=>h==="--ref"||h==="-r"),c=l>=0?e.argv[l+1]:e.argv.find(h=>h.startsWith("--ref="))?.slice(6),u=e.argv.slice(3).some(h=>!h.startsWith("-")&&/deploy|release|publish|prod/i.test(h)),p="";for(let h=3;h<e.argv.length&&!p;h++)/^(--ref|-r|-f|-F|--field|--raw-field|--repo|-R)$/.test(e.argv[h])?h++:e.argv[h].startsWith("-")||(p=e.argv[h]);let d=/deploy|release|publish|promot|rollout|(?:^|[^a-z])(?:prod(?:uction)?|ship)(?:[^a-z]|$)/i.test(p),f=e.argv.flatMap((h,g)=>/^(-f|-F|--field|--raw-field)$/.test(e.argv[g-1]??"")?[h]:/^(--field|--raw-field)=/.test(h)?[h.slice(h.indexOf("=")+1)]:[]);if(d||f.some(h=>/^(environment|env|stage|deploy_env|target)=/i.test(h)))return[w("claude.bash.deploy",d?"gh workflow run starts a deploy or release workflow":"gh workflow run starts a workflow for an environment",{target:o.find(h=>!h.startsWith("-"))??null,is_local:!1,host:"gh"})];if(c&&!S(c)&&!Uu.has(c.replace(/^refs\/heads\//,""))&&!u)return[]}if(s==="run"&&r==="rerun"&&/(?<![\w-])[\w-]*(deploy|release|publish|prod)[\w-]*\.ya?ml\b|--workflow[= ]+['"]?[\w -]*(deploy|release|publish|prod)/i.test(n))return[w("claude.bash.external_write","gh run rerun next to a deploy or release workflow can redo a release",{target:"run rerun",is_local:!1,host:"github.com"})];if(i[s]?.has(r))return[w("claude.bash.external_write",`gh ${s} ${r} changes GitHub`,{target:`${s} ${r}`,is_local:!1,host:"github.com",push:vr(e,n),...s==="repo"&&r==="delete"?{catastrophic:!0}:{}})];if(s==="auth"&&r==="setup-git")return[w("claude.bash.persistence","gh auth setup-git makes gh the git credential helper for every repository",{target:"credential.helper",is_local:!0})];if(s==="auth"&&(r==="token"||r==="status"&&a("-t","--show-token")))return fe(e)?[w("claude.bash.secrets.print","prints the GitHub token",{target:"gh auth token",is_local:!0})]:[];if(s==="api"){let l=e.argv.findIndex(d=>d==="-X"||d==="--method"),c=(l>=0?e.argv[l+1]:e.argv.find(d=>d.startsWith("--method="))?.slice(9)??e.argv.find(d=>/^-X[A-Z]+$/.test(d))?.slice(2)??null)?.toUpperCase()??null,u=a("-f","-F","--field","--raw-field","--input"),p=e.argv.slice(2).find((d,f,h)=>!d.startsWith("-")&&!["-X","--method"].includes(h[f-1]??""))??"";if(c==="GET"||c==="HEAD")return[];if(p==="graphql"){let d=e.argv.join(" ");return/\bmutation\b/.test(d)?[w("claude.bash.external_write","gh api runs a GraphQL mutation",{target:"graphql",is_local:!1,host:"github.com"})]:[]}if(c&&c!=="GET"||u)return[w("claude.bash.external_write",`gh api ${c??"POST"} ${p}`,{target:p,is_local:!1,host:"github.com",...c==="DELETE"&&!pd.test(p)?{catastrophic:!0}:{}})]}return[]}var Ir=new Set(["-X","-H","-d","-F","-o","-u","-A","-e","-b","-c","-m","-w","-x","-T","-K","-r","-C","-Y","-y","-z","-E","-U","-P","-Q","--request","--header","--data","--data-raw","--data-binary","--data-ascii","--data-urlencode","--json","--form","--form-string","--output","--user","--user-agent","--referer","--cookie","--cookie-jar","--max-time","--connect-timeout","--write-out","--proxy","--upload-file","--config","--range","--retry","--retry-delay","--resolve","--cert","--key","--cacert","--limit-rate","--url","--oauth2-bearer"]),on=["-d","--data","--data-raw","--data-binary","--data-ascii","--data-urlencode","--json","-F","--form","--form-string","-T","--upload-file"],Bi=/(?:(?:https?:\/\/)?(?<![\w.-])(?:[\w-]{1,63}\.){0,5}anvilcontrol\.ai(?::\d+)?|ANVIL_API(?:_BASE)?_URL)[\s\S]{0,60}?(\/v1\/(?:modes|kill-switch)|\/anvil\/actions\/(?:mode|removal-confirm)|\/api\/control\/kill-switch)\b/;function Vi(e){return e.includes("anvilcontrol.ai")||e.includes("ANVIL_API")}function fd(e,n,t){if(!Vi(e))return null;let s=Bi.exec(e)?.[1];return s===void 0?null:n==="DELETE"||s.endsWith("removal-confirm")?s:s.endsWith("kill-switch")?/\bon["']?\s*[:=]\s*(false|False)\b/.test(t)&&!/\bon["']?\s*[:=]\s*(true|True)\b/.test(t)?null:s:/\bmode["']?\s*[:=]\s*["']enforce["']/.test(t)&&!/["']ghost["']/.test(t)?null:s}function Nb(e){let n=e.argv,t=null,s=!1,r=!1,o=[];if(e.name==="curl"){for(let d=1;d<n.length;d++){let f=n[d];if(f==="-X"||f==="--request"?t=(n[d+1]??"").toUpperCase():/^-X[A-Za-z]+$/.test(f)?t=f.slice(2).toUpperCase():f.startsWith("--request=")?t=f.slice(10).toUpperCase():f[0]==="-"&&f[1]!=="-"&&f.includes("X")&&/^-[a-zA-Z]+X$/.test(f)?t=(n[d+1]??"").toUpperCase():f[0]==="-"&&f[1]!=="-"&&f.includes("X")&&/^-[a-zA-Z]+X[A-Z]+$/.test(f)&&(t=f.slice(f.indexOf("X")+1)),(on.includes(f)||on.some(h=>h.startsWith("--")&&f.startsWith(`${h}=`))||/^-d./.test(f))&&(s=!0),(f==="-G"||f==="--get")&&(r=!0),(f==="-I"||f==="--head")&&(t="HEAD"),f==="--url"&&n[d+1]&&o.push(n[d+1]),Ir.has(f)||f.endsWith("X")&&/^-[a-zA-Z]+X$/.test(f)){d++;continue}!f.startsWith("-")&&Tn(f)&&o.push(f)}t||(t=s&&!r?"POST":"GET")}else if(e.name==="wget"){for(let[d,f]of n.entries())(f.startsWith("--post-data")||f.startsWith("--post-file")||f.startsWith("--body-data")||f.startsWith("--body-file"))&&(s=!0),f.startsWith("--method=")&&(t=f.slice(9).toUpperCase()),f==="--method"&&n[d+1]&&(t=n[d+1].toUpperCase()),d>0&&!f.startsWith("-")&&Tn(f)&&o.push(f);t||(t=s?"POST":"GET")}else{let d=n.slice(1).filter((f,h)=>!f.startsWith("-")&&!((n[h]??"").startsWith("-")&&Tb.test(n[h])));d[0]&&/^(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)$/i.test(d[0])&&(t=d.shift().toUpperCase()),d[0]&&o.push(d[0]),t||(t=d.slice(1).some(f=>/^[^=:@]+(:?=|@)/.test(f))?"POST":"GET")}if(!["POST","PUT","PATCH","DELETE"].includes(t))return[];if(t==="POST"&&(Mb(n)||Ub(o,n)))return[];let a=o.filter(d=>!qe(d));if(o.length>0&&a.length===0)return[];let i=a[0]??o[0]??null,l=n.filter((d,f)=>f>0&&(on.includes(n[f-1])||/^--(data|json)[\w-]*=/.test(d)||/^-d./.test(d))).join(" "),c=n.find(d=>Vi(d)&&Bi.test(d)),u=c!==void 0?fd(c,t,l):null;return c!==void 0&&u!==null?[w("claude.agent.controls",`changes your Anvil workspace's modes through its API (${t} ${u})`,{target:c,host:i?me(i):null,is_local:!1})]:(a.length>0?a.slice(0,64):[i]).flatMap(d=>Lb(d,t,n))}function Lb(e,n,t){let s=e?me(e):null;if(e&&/\/(batches|fine_tuning|fine-tunes|fine_tunes|predictions|training_jobs|jobs\/(create|submit))\b/.test(e))return[w("claude.bash.spend",`starts a paid job (${n} ${s??"an API"})`,{target:e,host:s,is_local:!1})];let r=n!=="DELETE"?null:s??/^\$\{?(\w+)/.exec($(t.find((l,c)=>c>0&&!l.startsWith("-")&&S(l)&&!Ir.has(t[c-1])&&!/^(--(http-user|http-password|user|password|header|output-document|output-file)|-[oOU])$/.test(t[c-1]))??""))?.[1]??null,o=e?$(e).replace(/^[a-z]+:\/\/[^/?#]*/i,""):"",a=/\.(execute-api\.[\w-]+|elb(\.[\w-]+)?)\.amazonaws\.com$/i.test(r??"")||/^\/rest\/v1\/[^?]*\?[^#]*=/.test(o)||r==="api.github.com"&&pd.test(o.replace(/^\//,"")),i=r!==null&&!a&&!hd.test(r)&&(Hc.test(r)||Kr(r));return[w("claude.bash.external_write",i?`DELETE to ${s??`a URL in $${r}`} removes what it names (${Hc.test(r)?"a provider's API":"a host named for production"})`:`${n} to ${s??"an external host"}`,{target:e,host:s,is_local:!1,service:s,...i?{catastrophic:!0}:{}})]}var pd=/(^|\/)(user\/(starred|following)|notifications|subscriptions?|actions\/caches|reactions)(\/|\?|$)/,hd=/^(localhost|127\.\d+\.\d+\.\d+|\[?::1\]?|0\.0\.0\.0|host\.docker\.internal)$|\.(local|test|localhost)$/i,Tb=/^(-a|--auth|-A|--auth-type|--bearer|-o|--output|--session|--session-read-only|--cert|--cert-key|--verify|--proxy|--timeout|-s|--style|-p|--print|--pretty|--format-options|--default-scheme|--max-redirects)$/,Hc=/(^|\.)(api\.github\.com|uploads\.github\.com|gitlab\.com|api\.bitbucket\.org|amazonaws\.com|googleapis\.com|management\.azure\.com|graph\.microsoft\.com|api\.onedrive\.com|live\.com|live\.net|core\.windows\.net|api\.cloudflare\.com|api\.vercel\.com|api\.netlify\.com|api\.heroku\.com|api\.fly\.io|api\.machines\.dev|api\.render\.com|backboard\.railway\.(app|com)|supabase\.(co|com)|api\.planetscale\.com|neon\.tech|api\.digitalocean\.com|api\.linode\.com|api\.hetzner\.cloud|api\.vultr\.com|api\.scaleway\.com|upstash\.(com|io)|turso\.(tech|io)|cloud\.mongodb\.com|hub\.docker\.com)$/i;function gd(e){let n=[];for(let t=1;t<e.length;t++){let s=e[t];on.includes(s)&&e[t+1]!==void 0?n.push(e[t+1]):on.some(r=>r.startsWith("--")&&s.startsWith(`${r}=`))&&n.push(s.slice(s.indexOf("=")+1))}return n}var Bc=new Set(["query","variables","operationName","extensions"]),Db=new Set(["jsonrpc","method","params","id"]),Ib=/(^|[/._])(list|get|read|search|query|describe|status|ping|initialize|lookup|find)/i,Vc=(e,n)=>typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.keys(e).every(t=>n.has(t));function Fb(e){let n;try{n=JSON.parse(e)}catch{let s=e.split("&").map(o=>o.split("=")[0]??""),r="";try{r=decodeURIComponent((/^query=([^&]*)/.exec(e)?.[1]??"").replace(/\+/g," "))}catch{return!1}return s.every(o=>Bc.has(o))&&/^\s*(query\b|\{)/.test(r)}let t=Array.isArray(n)?n:[n];return t.length>0&&t.every(s=>{if(Vc(s,Db)&&typeof s.method=="string"){if(s.method==="tools/call"){let r=s.params,o=typeof r=="object"&&r!==null?r.name:void 0;return typeof o=="string"&&Ar(o)==="read"}return Ib.test(s.method)}return Vc(s,Bc)&&typeof s.query=="string"&&/^\s*(query\b|\{)/.test(s.query)})}function Mb(e){let n=gd(e);if(n.length===0)return!1;let t=n.join(" ");return/\bmutation\b/i.test(t)||/\bsubscription\b/i.test(t)||Gr.test(t)?!1:n.every(Fb)}var Gr=/\b(drop\s+(table|database|schema|index|view)|truncate\s|delete\s+from|insert\s+into|update\s+[\w."]+\s+set|alter\s+table|create\s+(table|index|database)|grant\s|revoke\s)/i,zb=new Set(["query","queries","search","autocomplete","suggest","suggestions","lookup","find","list","get","fetch","load","read","info","describe","count","explain","preview"]);function Ub(e,n){if(e.length===0)return!1;let t=gd(n).join(" ");return Gr.test(t)||/\bmutation\b/i.test(t)?!1:e.every(s=>{if(S(s))return!1;let o=s.replace(/^[a-z]+:\/\/[^/]*/i,"").replace(/[?#].*$/,"").split("/").filter(Boolean),a=o.flatMap(l=>l.replace(/([a-z0-9])([A-Z])/g,"$1_$2").toLowerCase().split(/[^a-z0-9]+/).filter(Boolean));if(a.some(l=>Lt.has(l)||Tt.has(l)||["redeem","subscribe","unsubscribe","enroll","register","signup","checkout","notify","verify","generate","run"].includes(l)))return!1;let i=(o[o.length-1]??"").toLowerCase();return a.some(l=>zb.has(l))||/(query|search|lookup|autocomplete)$/.test(i)})}function Tn(e){return/^https?:\/\//i.test(e)||/^(localhost|127\.|\[::1\]|<host>|[\w-]+(\.[\w-]+)+)(:\d+)?(\/|$)/i.test(e)}function qe(e){if(/^(\[?::1\]?|0\.0\.0\.0)$/.test(e))return!0;let n=/^[a-z]+:\/\//i.test(e)?e:`http://${e}`;return wa(n)}function me(e){return/^(?:[a-z][a-z0-9+.-]*:\/\/)?(?:[^@/]*@)?(\[[^\]]+\]|[^/:?#]+)/i.exec(e)?.[1]?.toLowerCase()??null}function qb(e,n){let t=e.argv.slice(1);switch(e.name){case"pkill":case"killall":{if(t.includes("-0")||t.includes("-l")||t.length===0)return[];let s=new Set(["-u","-U","--euid","--uid","-g","-G","-t","-s","-P","--signal","-F"]),r=[];for(let p=0;p<t.length;p++)s.has(t[p])?p++:t[p].startsWith("-")||r.push(t[p]);let o=t.some(p=>["-u","-U","--euid","--uid"].includes(p));if(e.name==="pkill"&&t.some(p=>/^-[a-zA-Z]*v[a-zA-Z]*$/.test(p)||p.length>=4&&"--inverse".startsWith(p)))return[w("claude.bash.process.kill_by_name","pkill -v kills every process that does not match",{target:t.join(" "),service:"proc.all",is_local:!0})];if(o&&r.length===0)return[w("claude.bash.process.kill_by_name",`${e.name} -u kills every process the user owns`,{target:t.join(" "),service:"proc.all",is_local:!0})];let a=e.name==="pkill"&&t.some(p=>/^-[a-zA-Z]*f[a-zA-Z]*$/.test(p)||p==="--full");if(!o&&r.length>0&&r.every(p=>Gi(p,n,a)))return[];let i=t.some(p=>/^-[a-zA-Z]*i[a-zA-Z]*$/.test(p)||p==="--ignore-case"),l=e.name==="killall"&&t.some(p=>p==="-r"||p==="--regexp"||p==="-m"),c=o||Dt(e)?null:Tu(r,{full:a,exact:e.name==="killall"&&!l||t.some(p=>/^-[a-zA-Z]*x[a-zA-Z]*$/.test(p)||p==="--exact"),fold:i},n);if(c==="own")return[];let u=e.name==="pkill"&&r.length===0&&t.some(p=>p==="-P"||p==="--parent"||p.startsWith("--parent=")||/^-P./.test(p));return e.name==="pkill"&&!o&&!Dt(e)&&md(t,e,n)?[]:u?[w("claude.bash.process.kill_by_name","pkill -P stops every process the named process started",{target:t.join(" "),is_local:!0})]:[w("claude.bash.process.kill_by_name",`${e.name} kills every process matching a name, other sessions' too`,{target:r.join(" "),is_local:!0,housekeeping:c==="some"})]}case"fuser":return t.some(s=>/^-[a-zA-Z]*k/.test(s))?[w("claude.bash.process.kill_by_name","fuser -k kills everything using the port or file, clients too",{target:t.filter(s=>!s.startsWith("-")).join(" "),is_local:!0})]:[];case"colima":return["stop","delete","restart","kill"].includes(t[0]??"")?[w("claude.bash.process.kill_by_name",`colima ${t[0]} stops the Docker VM other sessions share`,{target:"colima",is_local:!0})]:[];case"launchctl":return["stop","unload","bootout","kill","remove","disable"].includes(t[0]??"")||t[0]==="kickstart"&&t.includes("-k")?[w("claude.bash.process.kill_by_name",`launchctl ${t[0]} stops a system service`,{target:t.slice(1).join(" "),is_local:!0})]:[];case"tmux":return["kill-server","kill-session"].includes(t[0]??"")?[w("claude.bash.process.kill_by_name",`tmux ${t[0]} ends sessions it may not own`,{target:t.slice(1).join(" "),is_local:!0})]:[];case"systemctl":return["stop","restart","kill","disable","mask","poweroff","reboot","halt"].includes(t[0]??"")?[w("claude.bash.process.kill_by_name",`systemctl ${t[0]} stops a service`,{target:t.slice(1).join(" "),is_local:e.remote===null,host:e.remote})]:[];case"shutdown":case"reboot":case"halt":return[w("claude.bash.process.kill_by_name",`${e.name} stops the machine`,{target:e.name,service:"proc.all",is_local:e.remote===null,host:e.remote})];case"osascript":{let s=t.join(" ");return/\b(shut\s*down|restart|log\s*out)\b/i.test(s)&&/\b(System Events|Finder|loginwindow)\b/i.test(s)?[w("claude.bash.process.kill_by_name","osascript shuts down, restarts or logs out the machine",{target:s.slice(0,80),service:"proc.all",is_local:!0})]:/\bquit\b/i.test(s)?[w("claude.bash.process.kill_by_name","osascript quits an application",{target:s.slice(0,80),is_local:!0})]:[]}case"kill":return Hb(e,n);default:return[]}}function Hb(e,n){let t=e.argv.slice(1),s=0,r=!1;for(;s<t.length&&t[s].startsWith("-")&&!/^-\d+$/.test(t[s])||s<t.length&&/^-(\d+|[A-Z]+|s|n)$/.test(t[s])&&!(t[s]==="-1"&&s===t.length-1);){let l=t[s];(l==="-0"&&s===0||l==="-l"||l==="-L")&&(r=!0),(l==="-s"||l==="-n")&&s++,s++}if(r)return[];let o=t.slice(s),a=Kb(e,n);if(e.via==="xargs"&&e.pipeFrom)return a?[]:Xb(e.pipeFrom,n);if(e.via==="xargs"&&e.stdinFile)return a?[]:Fr(e.stdinFile,e,n);let i=[];for(let l of t.slice(0,s).filter((c,u)=>(u>0||o.length===0)&&c!=="-1"&&(/^-\d+$/.test(c)?u>0&&t[u-1]!=="-s"&&t[u-1]!=="-n":c.startsWith("-")&&S(c))))a||i.push(w("claude.bash.process.kill_by_name",`kills the whole process group ${$(l).slice(1)}`,{target:$(l),is_local:!0}));for(let l of o)if(l==="-1")i.push(w("claude.bash.process.kill_by_name",e.wrappers.some(c=>["sudo","doas","pkexec","run0"].includes(c))?"kill -1 as root kills every process on the machine":"kill -1 kills every process you own",{target:"-1",service:"proc.all",is_local:!0}));else{if(a)continue;if(/^-\d+$/.test(l))i.push(w("claude.bash.process.kill_by_name",`kills the whole process group ${l.slice(1)}`,{target:l,is_local:!0}));else{if(/^\d+$/.test(l)&&(n.ctx.session?.ownPids?.includes(l)||!Dt(e)&&Lu(l,n)))continue;if(/^\d+$/.test(l))i.push(w("claude.bash.process.kill_by_name",`kills a hard-coded PID (${l}) this command did not start`,{target:l,is_local:!0}));else if(S(l)){let c=$(l);if(Jb(c,n)||!Dt(e)&&Vb(c,e,n))continue;if(/\b(pgrep|pidof)\b|\bps\b/.test(c))i.push(w("claude.bash.process.kill_by_name","kills processes found by name",{target:c,is_local:!0}));else if(/\blsof\b/.test(c)&&!/-sTCP:LISTEN/.test(c)){let u=/^\$\(\s*lsof\s+([^()$`|;&]*?)\s*\)$/.exec(c.trim()),p=u&&!Dt(e)?Du(u[1].split(/\s+/),n):null;p!=="own"&&i.push(w("claude.bash.process.kill_by_name","kills by port without checking LISTEN, so clients die too",{target:c,is_local:!0,housekeeping:p==="some"}))}else if(/\bdocker\s+ps\b/.test(c))i.push(w("claude.bash.process.kill_by_name","kills every running container",{target:c,is_local:!0}));else{let u=yd(l,e,n);u&&i.push(...Fr(u,e,n))}}}}return i}function Bb(e,n,t){if(/\$\{(#|!|\w+[^\w}])/.test(n.text))return!1;let s=$(e).trim();if(/^\d+$/.test(s))return Number(s)>1&&(t.ctx.session?.ownPids?.includes(s)===!0||Lu(s,t));let r=/^(\$\(\s*(cat\s+|<\s*)|`\s*cat\s+)["']?[^\s;&|<>()`$"'\\]+["']?\s*[)`]$/.test(s)?yd(e,n,t):null;return r!==null&&!S(r)&&Fr(r,n,t).length===0}function md(e,n,t){let s=[];return e.forEach((r,o)=>{let a=r==="-P"||r==="--parent"?e[o+1]??"":r.startsWith("--parent=")?r.slice(9):/^-P./.test(r)?r.slice(2):null;a!==null&&s.push(...S(a)?[a]:a.split(","))}),s.length>0&&s.length<=8&&!e.some(r=>/^-[a-zA-Z]*v[a-zA-Z]*$/.test(r)||r.length>=4&&"--inverse".startsWith(r))&&s.every(r=>Bb(r,n,t))}function Vb(e,n,t){let s=/^\$\(\s*pgrep\s+([^;&|\n`]*?)\s*\)$/.exec(e.trim());if(!s)return!1;let r=`pgrep ${s[1]}`,o=(t.lineCommands??[]).filter(i=>i.name==="pgrep"&&i.via==="substitution"&&i.text.trim()===r),a=o.length>0?o:cn(r,n.cwd,t).commands.filter(i=>i.name==="pgrep").slice(0,1);return a.length>0&&a.every(i=>i.pipeTo===null&&md(i.argv.slice(1),n,t))}function Fr(e,n,t){return S(e)?[]:rt(e,n,t).kind==="disposable"?[]:[w("claude.bash.process.kill_by_name",`kills the process in ${$(e)}, which this session did not start`,{target:$(e),is_local:!0})]}function yd(e,n,t){let s=$(e).trim(),r=/^\$\(([\s\S]*)\)$/.exec(s)??/^`([\s\S]*)`$/.exec(s);if(!r)return null;let o=cn(r[1],n.cwd,t);for(let a of o.commands){let l=(["cat","head","tail","sort","uniq"].includes(a.name)?a.argv.slice(1).find(c=>!c.startsWith("-")&&!/^\d+$/.test(c)):["sed","awk","jq","grep","cut","tr"].includes(a.name)?Jr(a)[0]:void 0)??a.stdinFile??void 0;if(l)return l}return null}var Gb=/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\/scratchpad\b/i,Zb=/(^|[\s;&|({])(function\s+[\w-]+|[\w-]+\s*\(\)\s*\{|alias\s|unalias\s|hash\s|enable\s)/;function Kb(e,n){if(e.guards.length===0||Zb.test(n.lineText))return!1;let t=String.raw`(lsof\b[^;|)]*\s-p\b|ps\b[^;|)]*\s-p\b|pwdx\b|(cat|readlink|ls)\b[^;|)]*\/proc\/)`,s=r=>new RegExp(`^${t}`).test(r)||new RegExp(String.raw`^(\[\[?|test)\s[^;|]*\$\(\s*${t}`).test(r);return e.guards.some(r=>{let o=/^case ([\s\S]*) in [\s\S]*$/.exec(r)?.[1];if(!s(o===void 0?r:$(o).replace(/^["']?\$\(\s*/,""))||/\bgrep\b[^;|]*\s-[a-zA-Z]*v|\[\[?\s*-z\b|\btest\s+-z\b|-eq\s*0\b|-lt\s*1\b|==?\s*0\b|(^|\s)!\s/.test(r))return!1;let a=/^case ([\s\S]*) in ([\s\S]*)$/.exec(r);return a?a[2].split("|").every(i=>vi(i,n)):vi(r,n)&&!/\\\||\s-e\s.*\s-e\s/.test(r)})}function Gi(e,n,t){let r=e.replace(/^["']|["']$/g,"").split(/(?<!\\)\|/);return r.length>8||r.some(o=>o.trim()==="")?!1:r.every(o=>Yb(o,n)||Rl(o,ju(n),t,Pu(n)))}function Yb(e,n){let t=e.replace(/^["']|["']$/g,"");if(/(^|[^\\])\|/.test(t))return!1;let s=/^[^|()?*+[\]{}\\^$]*/.exec(t.replace(/\\\./g,"."))[0];return vi(s,n)&&/\/scratchpad\//.test(`${s}/`)&&/\/scratchpad\b/.test(s)}function vi(e,n){let t=e.toLowerCase(),s=n.sessionId?.toLowerCase()??null;return s?t.includes(s)||/^[0-9a-f]{8}/.test(s)&&new RegExp(`(^|[^0-9a-f])${s.slice(0,8)}([^0-9a-f]|$)`).test(t):Gb.test(t)}function Jb(e,n){let t=/^\$\(\s*pgrep\s+((?:-[a-zA-Z]+\s+)*)("[^"]*"|'[^']*'|\S+)\s*\)$/.exec(e.trim());if(!t||/[uUgGPtv]/.test(t[1]??""))return!1;let s=/f/.test(t[1]??"");return Gi(t[2],n,s)||Tm([t[2]],{full:s,exact:/x/.test(t[1]??""),fold:/i/.test(t[1]??"")},n)}function Xb(e,n){let t=[];for(let i=e;i&&t.length<8;i=i.pipeFrom)t.push(i);if(t.length===1&&e.name==="pgrep"){let i=e.argv.slice(1).filter(c=>c.startsWith("-")),l=e.argv.slice(1).filter(c=>!c.startsWith("-"));if(l.length===1&&!i.some(c=>/[uUgGPtv]/.test(c)||c==="--inverse")&&Gi(l[0],n,i.some(c=>c.includes("f"))))return[]}let s=t.map(i=>i.name),r=t.find(i=>i.name==="lsof");if(r){if(r.argv.some(l=>l==="-sTCP:LISTEN"||l.includes("TCP:LISTEN")))return[];let i=t.length===1&&!Dt(r)&&!Dt(e)?Du(r.argv.slice(1),n):null;return i==="own"?[]:[w("claude.bash.process.kill_by_name","kills by port without checking LISTEN, so clients die too",{target:r.argv.slice(1).join(" "),is_local:!0,housekeeping:i==="some"})]}if(s.some(i=>i==="pgrep"||i==="pidof"||i==="ps"))return[w("claude.bash.process.kill_by_name","kills processes found by name",{target:t.map(i=>i.name).reverse().join(" | "),is_local:!0})];if(s.includes("docker"))return[w("claude.bash.process.kill_by_name","kills containers listed by docker",{target:"docker ps",is_local:!0})];let o=t[t.length-1],a=["cat","head","tail","sort","uniq","tr","cut"].includes(o.name)?o.argv.slice(1).find(i=>!i.startsWith("-")&&!/^\d+$/.test(i))??o.stdinFile:["awk","sed","jq","grep"].includes(o.name)?Jr(o)[0]??o.stdinFile:null;return a?Fr(a,o,n):(o.name==="echo"||o.name==="printf")&&o.argv.slice(1).some(i=>/^\d+$/.test(i))?[w("claude.bash.process.kill_by_name","kills a hard-coded PID this command did not start",{target:o.argv.slice(1).join(" "),is_local:!0})]:[]}var Qb=ae({aws:new Set(["--profile","--region","--output","--endpoint-url","--query","--color","--ca-bundle","--cli-read-timeout","--cli-connect-timeout"]),kubectl:new Set(["--context","--namespace","-n","--kubeconfig","--cluster","--user","-s","--server","--token","--as","--as-group","--request-timeout","-l","--selector","-o","--output","-f","--filename","-v"]),helm:new Set(["--kube-context","--namespace","-n","--kubeconfig","--repo","--version","-f","--values","--set","-o","--output"]),fly:new Set(["-a","--app","-c","--config","-r","--region","-o","--org"]),flyctl:new Set(["-a","--app","-c","--config","-r","--region","-o","--org"]),railway:new Set(["-s","--service","-e","--environment","-p","--project"]),ngrok:new Set(["--config","--authtoken","--log","--log-format","--log-level","--region","--api-key","--url","--domain"]),cloudflared:new Set(["--config","--loglevel","--logfile","--metrics","--origincert","--credentials-file","--protocol","--edge-ip-version","--region","--hostname","--url"]),sui:new Set(["--client.env","--client.config","--gas-budget","--gas","--gas-price"]),bq:new Set(["--location","--project_id","--dataset_id","--format","--api","--job_id","--destination_table","--parameter","--label","--maximum_bytes_billed","-n","--max_rows"]),eas:new Set(["--branch","--channel","--message","-m","--platform","-p","--profile","-e","--id","--group","--runtime-version","--percent"]),hardhat:new Set(["--network","--config"]),truffle:new Set(["--network","--config"]),brownie:new Set(["--network"]),solana:new Set(["--url","-u","--keypair","-k","--fee-payer","--commitment","--with-compute-unit-price","--program-id","--upgrade-authority","--buffer"]),"spl-token":new Set(["--url","-u","--fee-payer","--owner","--program-id"]),cast:new Set(["--rpc-url","-r","--private-key","--from","-f","--value","--gas-limit","--gas-price","--chain","--keystore","--account","--nonce"]),forge:new Set(["--rpc-url","-r","--fork-url","-f","--private-key","--sender","--chain","--etherscan-api-key","--verifier","--sig","-s","--account","--keystore","--constructor-args"]),fastlane:new Set(["--env"]),claude:new Set(["--transport","-t","--scope","-s","-e","--env","-H","--header","--model","--permission-mode","--allowedTools","--allowed-tools","--disallowedTools","--disallowed-tools","--output-format","--append-system-prompt","--add-dir","--mcp-config","--settings","--resume","-r"]),vercel:new Set(["--token","-t","--scope","-S","--cwd","-A","--local-config","--team","-T","--target","-e","--env","-b","--build-env","-m","--meta","--regions","--archive"]),gcloud:new Set(["--project","--account","--configuration","--zone","--region","--format","--impersonate-service-account"]),az:new Set(["--subscription","--output","-o","--query"]),doctl:new Set(["--context","-t","--access-token","-o","--output"]),heroku:new Set(["-a","--app","-r","--remote"]),wrangler:new Set(["-c","--config","-e","--env"]),supabase:new Set(["--project-ref","--workdir","--profile"]),modal:new Set(["-e","--env"]),docker:new Set(["-H","--host","--context","-c","--config","--log-level"]),terraform:new Set([]),pulumi:new Set(["-s","--stack","-C","--cwd"]),stripe:new Set(["--api-key","--project-name","-p"])}),_=e=>{let n=Qb[he(e[0]??"")]??new Set,t=[];for(let s=1;s<e.length;s++){let r=e[s];if(r.startsWith("-")){n.has(r)&&s++;continue}t.push(r)}return t},ce=(...e)=>n=>e.every((t,s)=>_(n)[s]===t),I=(e,...n)=>e.some(t=>n.includes(t)||n.some(s=>t.startsWith(`${s}=`))),ew=new Set(["--dry-run","--force","--yes","-y","--atomic","--wait","--wait-for-jobs","--all","--debug","--verbose","-v","--quiet","-q","--json","--allow-dirty","--no-verify","--locked","--frozen","--offline","--install","--create-namespace","--reuse-values","--reset-values","--cleanup-on-fail","--recursive","-R","--prune","--server-side","--keep-history","--no-hooks","--skip-crds","--devel","--dependency-update","--provenance","--ignore-scripts","--workspaces","--include-workspace-root","--linked","--local","--include-all","--include-roles","--include-seed"]);function nn(e,n,t=["true"]){let s=i=>i.replace(/^--/,"").replace(/[A-Z]/g,l=>`-${l.toLowerCase()}`).replace(/_/g,"-"),r=n.map(s),o=i=>r.some(l=>l===i||l.replace(/-/g,"")===i.replace(/-/g,"")||i.length>=2&&l.startsWith(i)),a=null;for(let i=0;i<e.length;i++){let l=e[i];if(l==="--")break;if(!l.startsWith("--"))continue;let[c,...u]=l.slice(2).split("="),p=c.startsWith("no-")||/^no[A-Z]/.test(c),d=s(p?c.replace(/^no-?/,"").replace(/^./,b=>b.toLowerCase()):c);if(!o(d))continue;let f=n.includes(`--${c}`),h=e[i-1]??"",g=/^--?[a-zA-Z][\w-]*$/.test(h)&&!ew.has(h);p?a="false":u.length?a=f?u.join("="):u.join("=")==="true"?null:"false":!f||g?a=a??null:a=e[i+1]==="false"?"false":"true"}return a!==null&&t.includes(a)}var Te=e=>!nn(e,["--dry-run","--dryrun","--plan","--preview"]),bd=ae({railway:[{match:e=>["up","redeploy","deploy","down"].includes(_(e)[0]??""),action:"claude.bash.deploy",why:"railway deploys or removes a service"},{match:e=>["variables","variable","vars"].includes(_(e)[0]??"")&&(I(e,"--set")||["set","delete","remove"].includes(_(e)[1]??"")),action:"claude.bash.deploy",why:"railway changes production variables"},{match:e=>_(e)[0]==="domain",action:"claude.bash.deploy",why:"railway domain can create a public domain for a live service"},{match:e=>["service","environment","volume","project"].includes(_(e)[0]??"")&&["delete","remove","rm"].includes(_(e)[1]??""),action:"claude.bash.deploy",why:"railway deletes infrastructure"},{match:e=>_(e)[0]==="add",action:"claude.bash.deploy",why:"railway add creates a service"}],vercel:[{match:e=>["remove","rm"].includes(_(e)[0]??""),action:"claude.bash.deploy",why:"vercel removes a deployment"},{match:e=>_(e)[0]==="rollback",action:"claude.bash.deploy",why:"vercel rolls production back to an earlier deployment"},{match:e=>I(e,"--prod","--production")||_(e)[0]==="promote",action:"claude.bash.deploy",why:"vercel deploys to production"},{match:e=>_(e)[0]==="env"&&["add","rm","remove"].includes(_(e)[1]??"")||_(e)[0]==="alias"&&_(e)[1]==="set"||_(e)[0]==="domains"&&["add","rm","remove"].includes(_(e)[1]??""),action:"claude.bash.deploy",why:"vercel changes production settings"},{match:e=>P(e,"--target")!==null&&(_(e).length===0||_(e)[0]==="deploy"||/^[./~]/.test(_(e)[0])),action:"claude.bash.deploy",why:"vercel deploys to the environment --target names"}],wrangler:[{match:e=>["deploy","publish"].includes(_(e)[0]??"")&&!nn(e,["--dry-run"])||_(e)[0]==="rollback"||ce("pages","deploy")(e)||ce("versions","deploy")(e)||_(e)[0]==="secret"&&["put","delete"].includes(_(e)[1]??""),action:"claude.bash.deploy",why:"wrangler deploys to Cloudflare"}],fly:[{match:e=>ce("ssh","console")(e)&&/\b(printenv|env|set|export\s+-p|cat\s+\S*\.env)\b/.test(P(e,"-C","--command")??""),action:"claude.bash.secrets.print",why:"fly ssh console prints a live app's environment"},{match:e=>["deploy","scale","destroy"].includes(_(e)[0]??"")||["secrets","apps","machine","machines","volumes","postgres"].includes(_(e)[0]??"")&&["set","unset","destroy","delete","remove","stop","create"].includes(_(e)[1]??""),action:"claude.bash.deploy",why:"fly changes a live app"}],netlify:[{match:e=>_(e)[0]==="deploy"&&I(e,"--prod"),action:"claude.bash.deploy",why:"netlify deploys to production"}],firebase:[{match:e=>_(e)[0]==="deploy"||/^hosting:channel:deploy/.test(_(e)[0]??""),action:"claude.bash.deploy",why:"firebase deploys"},{match:e=>/^functions:delete/.test(_(e)[0]??""),action:"claude.bash.deploy",why:"firebase deletes live functions"},{match:e=>/^hosting:disable/.test(_(e)[0]??""),action:"claude.bash.deploy",why:"firebase takes the hosting site offline"},{match:e=>_(e)[0]==="appdistribution:distribute",action:"claude.bash.deploy",why:"firebase sends a build to testers"}],fastlane:[{match:Iv,action:"claude.bash.deploy",why:"fastlane uploads or releases an app"}],eas:[{match:Fv,action:"claude.bash.deploy",why:"eas sends an app or an over-the-air update to users"}],expo:[{match:e=>_(e)[0]==="publish",action:"claude.bash.deploy",why:"expo publish sends an over-the-air update to users"}],xcrun:[{match:e=>_(e)[0]==="altool"&&I(e,"--upload-app","--upload-package")||_(e)[0]==="iTMSTransporter"&&P(e,"-m")==="upload",action:"claude.bash.deploy",why:"uploads an app to App Store Connect"}],altool:[{match:e=>I(e,"--upload-app","--upload-package"),action:"claude.bash.deploy",why:"altool uploads an app to App Store Connect"}],appcenter:[{match:e=>_(e)[0]==="codepush"&&/^(release|release-react|release-cordova|release-electron|promote|patch|rollback)$/.test(_(e)[1]??"")&&ui(e)||ce("distribute","release")(e),action:"claude.bash.deploy",why:"appcenter releases an app update to users"}],"code-push":[{match:e=>/^(release|release-react|release-cordova|release-electron|promote|patch|rollback)$/.test(_(e)[0]??"")&&ui(e),action:"claude.bash.deploy",why:"code-push releases an app update to users"}],"code-push-standalone":[{match:e=>/^(release|release-react|release-cordova|release-electron|promote|patch|rollback)$/.test(_(e)[0]??"")&&ui(e),action:"claude.bash.deploy",why:"code-push releases an app update to users"}],shorebird:[{match:e=>_(e)[0]==="patch"&&!/^(staging)$/i.test(P(e,"--track")??"")||ce("patches","promote")(e),action:"claude.bash.deploy",why:"shorebird sends a patch to the app's users"}],capgo:[{match:e=>ce("bundle","upload")(e)&&!mf.test(P(e,"--channel","-c")??""),action:"claude.bash.deploy",why:"capgo sends an over-the-air update to users"}],butler:[{match:e=>_(e)[0]==="push"&&Te(e),action:"claude.bash.deploy",why:"butler pushes a build to itch.io"}],steamcmd:[{match:e=>e.some(n=>/^\+run_app_build(_http)?$|^\+set_?live/i.test(n)),action:"claude.bash.deploy",why:"steamcmd uploads a build to Steam"}],msstore:[{match:e=>_(e)[0]==="publish",action:"claude.bash.deploy",why:"msstore publishes to the Microsoft Store"}],"web-ext":[{match:e=>_(e)[0]==="sign"&&P(e,"--channel")==="listed",action:"claude.bash.deploy",why:"web-ext submits a listed add-on to addons.mozilla.org"}],"chrome-webstore-upload":[{match:e=>!["help"].includes(_(e)[0]??""),action:"claude.bash.deploy",why:"uploads an extension to the Chrome Web Store"}],gradlew:[{match:mu,action:"claude.bash.deploy",why:"gradle publishes an app to Google Play"},{match:yu,action:"claude.bash.publish",why:"gradle publishes artifacts to a package repository"}],gradle:[{match:mu,action:"claude.bash.deploy",why:"gradle publishes an app to Google Play"},{match:yu,action:"claude.bash.publish",why:"gradle publishes artifacts to a package repository"}],heroku:[{match:e=>/^apps:destroy$/.test(_(e)[0]??""),action:"claude.bash.deploy",why:"heroku deletes the app"},{match:e=>/^(config:set|config:unset|releases:rollback|ps:scale|ps:restart|ps:stop|maintenance:on|run)$/.test(_(e)[0]??""),action:"claude.bash.deploy",why:"heroku changes a live app"},{match:e=>/^pg:reset$/.test(_(e)[0]??""),action:"claude.bash.db.destructive",why:"heroku pg:reset wipes the database"}],kubectl:[{match:e=>_(e)[0]==="delete"&&!nn(e,["--dry-run"],["true","client","server"]),action:"claude.bash.deploy",why:"kubectl deletes from a cluster"},{match:e=>(["apply","create","delete","replace","patch","scale","set","edit","label","annotate","drain","cordon","uncordon","taint","expose","autoscale"].includes(_(e)[0]??"")||_(e)[0]==="run"&&!dd(e)||_(e)[0]==="rollout"&&["restart","undo","pause","resume"].includes(_(e)[1]??""))&&!nn(e,["--dry-run"],["true","client","server"]),action:"claude.bash.deploy",why:"kubectl changes a cluster"}],helm:[{match:e=>["uninstall","delete"].includes(_(e)[0]??"")&&!nn(e,["--dry-run"],["true","client","server"]),action:"claude.bash.deploy",why:"helm removes a release from a cluster"},{match:e=>["install","upgrade","rollback"].includes(_(e)[0]??"")&&!nn(e,["--dry-run"],["true","client","server"]),action:"claude.bash.deploy",why:"helm changes a cluster"}],terraform:[{match:e=>_(e)[0]==="import"||_(e)[0]==="state"&&["rm","mv","push","replace-provider"].includes(_(e)[1]??"")||["taint","untaint","force-unlock"].includes(_(e)[0]??""),action:"claude.bash.deploy",why:"terraform changes the shared state that every later apply works from"},{match:e=>_(e)[0]==="destroy"||_(e)[0]==="apply"&&I(e,"-destroy","--destroy"),action:"claude.bash.deploy",why:"terraform destroy deletes real infrastructure"},{match:e=>_(e)[0]==="apply",action:"claude.bash.deploy",why:"terraform changes real infrastructure"}],tofu:[{match:e=>_(e)[0]==="destroy"||_(e)[0]==="apply"&&I(e,"-destroy","--destroy"),action:"claude.bash.deploy",why:"tofu destroy deletes real infrastructure"},{match:e=>["apply","import","taint"].includes(_(e)[0]??""),action:"claude.bash.deploy",why:"tofu changes real infrastructure"}],pulumi:[{match:e=>_(e)[0]==="destroy",action:"claude.bash.deploy",why:"pulumi destroy deletes real infrastructure"},{match:e=>["up","update","cancel"].includes(_(e)[0]??""),action:"claude.bash.deploy",why:"pulumi changes real infrastructure"}],cdk:[{match:e=>_(e)[0]==="destroy",action:"claude.bash.deploy",why:"cdk destroy deletes real infrastructure"},{match:e=>_(e)[0]==="deploy",action:"claude.bash.deploy",why:"cdk changes real infrastructure"}],serverless:[{match:e=>_(e)[0]==="remove",action:"claude.bash.deploy",why:"serverless remove deletes the deployed service"},{match:e=>_(e)[0]==="deploy",action:"claude.bash.deploy",why:"serverless deploys"}],sls:[{match:e=>_(e)[0]==="remove",action:"claude.bash.deploy",why:"serverless remove deletes the deployed service"},{match:e=>_(e)[0]==="deploy",action:"claude.bash.deploy",why:"serverless deploys"}],modal:[{match:e=>_(e)[0]==="deploy"||["app","secret"].includes(_(e)[0]??"")&&["stop","create","delete"].includes(_(e)[1]??""),action:"claude.bash.deploy",why:"modal deploys or changes a live app"},{match:e=>["run","shell","launch"].includes(_(e)[0]??""),action:"claude.bash.spend",why:"modal starts a paid cloud run"},{match:e=>_(e)[0]==="volume"&&["rm","delete"].includes(_(e)[1]??""),action:"claude.bash.db.destructive",why:"modal deletes stored data"}],supabase:[{match:e=>ce("db","push")(e)&&!I(e,"--local")&&!wd(e)&&!nn(e,["--dry-run"])||ce("functions","deploy")(e)||ce("secrets","set")(e)||ce("functions","delete")(e),action:"claude.bash.deploy",why:"supabase changes a live project"},{match:e=>ce("db","reset")(e)&&I(e,"--linked","--db-url"),action:"claude.bash.db.destructive",why:"supabase db reset wipes a linked database"}],prisma:[{match:e=>ce("migrate","reset")(e)||ce("db","push")(e)&&I(e,"--accept-data-loss","--force-reset"),action:"claude.bash.db.destructive",why:"prisma wipes or drops database data"},{match:e=>ce("migrate","deploy")(e),action:"claude.bash.deploy",why:"prisma migrate deploy changes the target database"}],"drizzle-kit":[{match:e=>_(e)[0]==="push"||_(e)[0]==="drop",action:"claude.bash.db.destructive",why:"drizzle-kit push can drop columns and tables to match the schema"}],docker:[{match:e=>(_(e)[0]==="push"||_(e)[0]==="image"&&_(e)[1]==="push"||_(e)[0]==="buildx"&&I(e,"--push"))&&!bw(e),action:"claude.bash.publish",why:"docker push publishes an image"},{match:e=>["stop","kill","rm","restart"].includes(_(e)[0]??"")&&e.some(n=>S(n)&&/docker\s+ps\b/.test($(n))),action:"claude.bash.process.kill_by_name",why:"docker stops every container, other sessions' too"},{match:e=>ce("system","prune")(e)&&I(e,"--volumes")||_(e)[0]==="volume"&&(_(e)[1]==="prune"||_(e)[1]==="rm"&&!iw(_(e).slice(2)))||ce("compose","down")(e)&&I(e,"-v","--volumes"),action:"claude.bash.fs.delete_recursive",why:"docker deletes volumes, and the data in them"},{match:e=>ce("system","prune")(e)&&e.some(n=>/^-\w*f/.test(n)||n==="--force"),action:"claude.bash.fs.delete_recursive",why:"docker system prune deletes stopped containers and unused images"}],cargo:[{match:e=>(_(e)[0]==="publish"||_(e)[0]==="yank")&&Te(e),action:"claude.bash.publish",why:"cargo publishes a crate"}],podman:[{match:e=>_(e)[0]==="push"||_(e)[0]==="image"&&_(e)[1]==="push"||_(e)[0]==="manifest"&&_(e)[1]==="push",action:"claude.bash.publish",why:"podman push publishes an image"}],buildah:[{match:e=>_(e)[0]==="push",action:"claude.bash.publish",why:"buildah push publishes an image"}],nerdctl:[{match:e=>_(e)[0]==="push",action:"claude.bash.publish",why:"nerdctl push publishes an image"}],glab:[{match:e=>_(e)[0]==="mr"&&_(e)[1]==="merge",action:"claude.bash.git.push_main",why:"glab mr merge merges into the default branch (a deploy)"},{match:e=>_(e)[0]==="release"&&_(e)[1]==="create",action:"claude.bash.publish",why:"glab release create publishes a release"}],twilio:[{match:e=>/:(buy|purchase)(:|$)/.test(_(e)[0]??"")||/^api:core:incoming-phone-numbers:create$/.test(_(e)[0]??""),action:"claude.bash.spend",why:"twilio buys a phone number"},{match:e=>/^api:[\w-]+:(messages|calls|conversations|notifications|verify[\w-]*):create$|^api:[\w-]+:[\w-]+:(messages|calls):create$/.test(_(e)[0]??""),action:"claude.bash.external_write",why:"twilio sends a message or places a call"}],twine:[{match:e=>_(e)[0]==="upload",action:"claude.bash.publish",why:"twine uploads a package"}],gem:[{match:e=>["push","yank"].includes(_(e)[0]??""),action:"claude.bash.publish",why:"gem publishes a package"}],poetry:[{match:e=>_(e)[0]==="publish"&&Te(e),action:"claude.bash.publish",why:"poetry publishes a package"}],vsce:[{match:e=>["publish","unpublish"].includes(_(e)[0]??""),action:"claude.bash.publish",why:"vsce publishes an extension"}],ovsx:[{match:e=>_(e)[0]==="publish",action:"claude.bash.publish",why:"ovsx publishes an extension"}],changeset:[{match:e=>_(e)[0]==="publish",action:"claude.bash.publish",why:"changeset publishes packages"}],lerna:[{match:e=>_(e)[0]==="publish",action:"claude.bash.publish",why:"lerna publishes packages"}],jsr:[{match:e=>_(e)[0]==="publish"&&Te(e),action:"claude.bash.publish",why:"jsr publishes a package"}],sky:[{match:e=>["launch","exec","jobs"].includes(_(e)[0]??""),action:"claude.bash.spend",why:"sky starts paid cloud machines"}],gcloud:[{match:e=>/\b(instances|clusters|tpus)\b/.test(_(e).join(" "))&&_(e).includes("create"),action:"claude.bash.spend",why:"gcloud starts paid machines"},{match:e=>_(e).includes("deploy")||_(e).includes("delete")&&!_(e).includes("describe"),action:"claude.bash.deploy",why:"gcloud changes cloud resources"},{match:e=>_(e).some(n=>/^(add|remove|set)-iam-policy(-binding)?$/.test(n)),action:"claude.bash.deploy",why:"gcloud changes who can reach cloud resources"},{match:e=>_(e)[0]==="auth"&&/^print-(access|identity)-token$/.test(_(e)[1]??"")||_(e)[0]==="secrets"&&_(e)[1]==="versions"&&_(e)[2]==="access",action:"claude.bash.secrets.print",why:"gcloud prints a credential"}],az:[{match:e=>ce("vm","create")(e),action:"claude.bash.spend",why:"az starts a paid machine"},{match:e=>_(e).some(n=>["delete","deploy","create","update","set"].includes(n))&&!ce("account","set")(e),action:"claude.bash.deploy",why:"az changes cloud resources"},{match:e=>ce("account","get-access-token")(e),action:"claude.bash.secrets.print",why:"az prints an access token"}],doctl:[{match:e=>_(e).includes("create")||_(e).includes("delete"),action:"claude.bash.deploy",why:"doctl changes cloud resources"}],stripe:[{match:e=>["post","delete"].includes(_(e)[0]??"")||_(e).some(n=>["create","update","delete","cancel","refund","capture","pay","void"].includes(n)),action:"claude.bash.external_write",why:"stripe changes live payment data"}],mail:[{match:()=>!0,action:"claude.bash.external_write",why:"sends an email"}],uv:[{match:e=>_(e)[0]==="publish"&&Te(e),action:"claude.bash.publish",why:"uv publishes a package"}],mvn:[{match:e=>_(e).some(n=>n==="deploy"||n==="release:perform"||n==="deploy:deploy-file"),action:"claude.bash.publish",why:"mvn deploy uploads artifacts to a package repository"}],mvnw:[{match:e=>_(e).some(n=>n==="deploy"||n==="release:perform"),action:"claude.bash.publish",why:"mvn deploy uploads artifacts to a package repository"}],argocd:[{match:e=>_(e)[0]==="app"&&["sync","rollback","delete","set","patch","terminate-op"].includes(_(e)[1]??"")&&Te(e),action:"claude.bash.deploy",why:"argocd changes what a cluster runs"}],"ansible-playbook":[{match:e=>!I(e,"--check","-C","--syntax-check","--list-hosts","--list-tasks","--list-tags")&&!/^(?:localhost|127\.0\.0\.1),?$/.test(P(e,"-i","--inventory")??""),action:"claude.bash.deploy",why:"ansible-playbook changes the machines in its inventory"}],pm2:[{match:e=>["restart","reload","stop","delete","kill"].includes(_(e)[0]??"")&&(_(e)[0]==="kill"||_(e)[1]==="all"),action:"claude.bash.process.kill_by_name",why:"pm2 stops or restarts every process it manages"}],sendmail:[{match:()=>!0,action:"claude.bash.external_write",why:"sends an email"}],mailx:[{match:()=>!0,action:"claude.bash.external_write",why:"sends an email"}],mutt:[{match:e=>I(e,"-s","-a","-c","-b","-H","-i")||_(e).some(n=>n.includes("@")),action:"claude.bash.external_write",why:"sends an email"}],msmtp:[{match:e=>!I(e,"--help","--version","--serverinfo","-S","-P","--pretend","--rmqs"),action:"claude.bash.external_write",why:"sends an email"}],swaks:[{match:e=>!I(e,"--help","-h","--version"),action:"claude.bash.external_write",why:"sends an email"}]});function wd(e){let n=e.findIndex(r=>r==="--db-url"||r==="--database-url"),t=n>=0?e[n+1]:e.find(r=>r.startsWith("--db-url=")||r.startsWith("--database-url="))?.split("=").slice(1).join("=");if(!t||S(t))return!1;let s=me(t);return s!==null&&qe(s)}var tw=new Set(["--exclude","--include","--cache-control","--acl","--content-type","--content-encoding","--content-disposition","--content-language","--expires","--sse","--sse-kms-key-id","--sse-c","--sse-c-key","--storage-class","--metadata","--metadata-directive","--grants","--website-redirect","--profile","--region","--endpoint-url","--expected-size","--source-region","--request-payer","--output","--query","--page-size","--color","--ca-bundle","--cli-read-timeout","--cli-connect-timeout"]);function $i(e){let n=e.findIndex((t,s)=>s>0&&["cp","sync","mv"].includes(t)&&e[s-1]==="s3");return n<0?[]:ke(e,n+1,tw)}var nw=/^(run-instances|request-spot-instances|create-training-job|create-cluster|create-db-instance|create-endpoint|purchase-[\w-]+|create-capacity-reservation)$/,sw=/^(delete-|terminate-|remove-|deregister-|revoke-|detach-|put-|update-|create-|deploy|attach-|modify-|stop-|reboot-|start-|replace-|disable-|enable-|change-|authorize-|associate-|disassociate-|set-|add-|apply-|import-|restore-|rotate-|schedule-|cancel-|purge-|batch-delete-|batch-write-|reset-|admin-|initiate-|promote-|failover-|reject-|accept-)/,rw=/^(s3|s3api|s3control|kms|dynamodb|rds|backup|secretsmanager|ssm|ecr|ecr-public|sqs|kinesis|firehose|glacier|efs|fsx|elasticache|memorydb|redshift|redshift-serverless|docdb|neptune|opensearch|es|timestream-write|keyspaces|qldb|lightsail|athena|glue|logs|cloudtrail|codecommit|cognito-idp)$/,ow=/^(get-secret-value|get-session-token|assume-role|get-federation-token|get-parameter|get-parameters)$/;function Rr(e){let n=e.argv,t=e.name,s=[],r=mw(e);if(r.length>0)return r;let o=uw(e);if(o.length>0)return o;if(t==="aws"){let[l="",c=""]=_(n),u=c.split("-").some(p=>["delete","deletion","purge","terminate","drop","destroy","wipe","truncate"].includes(p))||/^(disable-key|schedule-key-deletion|remove-objects?)$/.test(c);if(l==="s3"&&["rm","rb"].includes(c))s.push(w("claude.bash.db.destructive",`aws s3 ${c} deletes stored data`,{target:_(n)[2]??null,is_local:!1}));else if(rw.test(l)&&u&&Te(n))s.push(w("claude.bash.db.destructive",`aws ${l} ${c} deletes stored data`,{target:`${l} ${c}`,is_local:!1}));else if(l==="configure"&&c==="export-credentials")s.push(...fe(e)?[w("claude.bash.secrets.print","aws configure export-credentials prints AWS credentials",{target:"configure export-credentials",is_local:!0})]:[]);else if(/^authorize-security-group-ingress$|^modify-security-group-rules$/.test(c)&&n.some(p=>/(^|[=\s"'])(0\.0\.0\.0\/0|::\/0)\b/.test(p)))s.push(w("claude.bash.net.expose",`aws ${l} ${c} opens a port to the whole internet`,{target:`${l} ${c}`,is_local:!1}));else if(l==="s3"&&["cp","sync","mv"].includes(c)&&($i(n).slice(-1)[0]??"").startsWith("s3://")&&$i(n).length>=2)s.push(w("claude.bash.deploy",`aws s3 ${c} writes to a bucket`,{target:_(n).slice(-1)[0]??null,is_local:!1}));else if(l==="configure"&&c==="get"&&/secret|key/i.test(_(n)[2]??""))s.push(...fe(e)?[w("claude.bash.secrets.print","prints an AWS credential",{target:_(n)[2]??null,is_local:!0})]:[]);else if(ow.test(c)&&(c!=="get-parameter"&&c!=="get-parameters"||I(n,"--with-decryption")))s.push(...fe(e)?[w("claude.bash.secrets.print",`aws ${l} ${c} prints a secret`,{target:`${l} ${c}`,is_local:!0})]:[]);else if(l==="athena"&&c==="start-query-execution"){let p=Oe(P(n,"--query-string")??""),d=Ee.exec(p)??Ss.exec(p);d&&s.push(w("claude.bash.db.destructive",`aws athena runs destructive SQL (${d[1].replace(/\s+/g," ").toUpperCase()})`,{target:"athena",host:"athena",is_local:!1}))}else if(["redshift-data","rds-data"].includes(l)&&/execute-statement$/.test(c)){let p=Oe([P(n,"--sql")??"",...n.filter((d,f)=>n[f-1]==="--sqls")].join(`
|
|
49
|
+
`));Ee.test(p)&&s.push(w("claude.bash.db.destructive",`aws ${l} runs destructive SQL (${(Ee.exec(p)?.[1]??"").replace(/\s+/g," ").toUpperCase()})`,{target:`${l} ${c}`,host:l,is_local:!1}))}else nw.test(c)?s.push(w("claude.bash.spend",`aws ${l} ${c} starts paid resources`,{target:`${l} ${c}`,is_local:!1})):["ses","sesv2","sns","sqs"].includes(l)&&/^(send|publish)/.test(c)?s.push(w("claude.bash.external_write",`aws ${l} ${c} sends a message`,{target:`${l} ${c}`,is_local:!1})):sw.test(c)&&Te(n)&&s.push(w("claude.bash.deploy",`aws ${l} ${c} changes cloud resources`,{target:`${l} ${c}`,is_local:!1}));return s}if(["npm","pnpm","yarn","bun"].includes(t))return Sd(e);if(["nx","turbo","mise","lerna","run-s","run-p","npm-run-all"].includes(t))return ww(e);if(["make","just","task","mise"].includes(t)){let l=_(n).find(c=>!c.includes("="));return l&&/^(deploy|release|publish|ship)([-:_].*)?$/.test(l)&&!xd.test(l)&&Te(n)&&!I(n,"-n","--just-print","--recon")?[w("claude.bash.deploy",`${t} ${l} runs a deploy or release target`,{target:l,is_local:!1})]:[]}let a=yw(e);if(a.length>0)return a;let i=gw(e);if(i.length>0)return i;if(t==="python"||t==="python3"){let l=n.indexOf("-m");if(l>0&&n[l+1]==="twine"&&n[l+2]==="upload")return[w("claude.bash.publish","twine uploads a package",{is_local:!1})];if(n.includes("manage.py")&&["flush","reset_db","sqlflush"].some(u=>n.includes(u)))return[w("claude.bash.db.destructive","manage.py wipes the database",{is_local:null})];let c=n.indexOf("migrate");if(n.includes("manage.py")&&c>0){let u=n.slice(c+1).filter(p=>!p.startsWith("-"));if(u[1]==="zero")return[w("claude.bash.db.destructive","manage.py migrate APP zero drops the app's tables",{target:u[0]??null,is_local:null})]}return[]}if(t==="alembic"&&_(n).includes("downgrade")&&!I(n,"--sql")||t==="flask"&&ce("db","downgrade")(n)&&!I(n,"--sql"))return[w("claude.bash.db.destructive",`${t} downgrades the database schema (drops what the migrations made)`,{target:_(n).slice(-1)[0]??null,is_local:null})];if(t==="rails"||t==="rake"||t==="bin/rails"){let l=(/(?:^|\s)(?:RAILS_ENV|RACK_ENV)=["']?(\w+)/.exec(e.text)?.[1]??P(n,"-e","--environment")??"").toLowerCase();return/^(test|development|dev)$/.test(l)?[]:n.some(c=>/^db:(drop|reset|schema:load|migrate:reset|purge|truncate_all)$/.test(c))?[w("claude.bash.db.destructive","rails wipes or rebuilds the database",{is_local:null})]:/^prod(uction)?$/.test(l)&&n.some(c=>/^db:(migrate|rollback|seed|setup)(:|$)/.test(c))?[w("claude.bash.deploy","rails changes the production database",{target:n.find(c=>c.startsWith("db:"))??null,is_local:!1})]:[]}for(let l of bd[t==="flyctl"?"fly":t]??[])if(l.match(n)){if(l.action==="claude.bash.secrets.print"&&!fe(e))continue;s.push(w(l.action,l.why,{target:_(n).slice(0,3).join(" ")||t,is_local:!1,host:t}));break}return t==="railway"&&["variables","variable","vars"].includes(_(n)[0]??"")&&s.length===0&&fe(e)&&s.push(w("claude.bash.secrets.print","railway variables prints live production secrets",{target:"railway variables",is_local:!0,host:"railway"})),t==="heroku"&&/^config(:get)?$/.test(_(n)[0]??"")&&s.length===0&&fe(e)&&s.push(w("claude.bash.secrets.print","heroku config prints live secrets",{target:"heroku config",is_local:!0,host:"heroku"})),s.length===0&&s.push(...cw(e),...lw(e)),s.length===0&&s.push(...pw(e),...hw(e)),s}function iw(e){return e.length>0&&e.every(n=>$(n).replace(/[${}"']/g,"").toLowerCase().split(/[-_.:]+/).some(t=>/^(cache|caches|test|tests|testing|tmp|temp|ci|fixture|fixtures|scratch)$/.test(t)))}var kd=/^(delete|deletion|destroy|drop|purge|wipe|nuke|truncate|erase|rm|rb|remove|terminate|flush|flushall|flushdb|reset)$/i,aw=e=>e.split(/[-:_.]/).some(n=>kd.test(n)),Gc=/^(buckets?|blobs?|objects?|storage|tables?|datasets?|databases?|dbs?|collections?|documents?|docs|indexe?s|indices|topics?|queues?|streams?|keys?|kms|keyrings?|secrets?|backups?|snapshots?|volumes?|disks?|branch(es)?|firestore|datastore|bigtable|spanner|redis|memcache|memorystore|filestore|keyspaces?|schemas?|kv|keyvalue|file-?systems?|repositor(y|ies)|images?|vaults?|caches?|data|records?|rows?|partitions?|shards?|replicas?|buckets?|containers?)$/i,Zr=new Set(["gsutil","bq","pscale","turso","neonctl","neon","upstash","xata","atlas","mongocli","snowsql","kafka-topics","kafka-topics.sh","kafka-configs","cqlsh","clickhouse-client","influx","cockroach","surreal","supabase","firebase","fauna","convex","rclone","restic","b2","mc","s3cmd","azcopy","cbq","couchbase-cli","arangosh","typesense","meilisearch","algolia","pinecone","weaviate","qdrant","chroma","elasticdump","curator","litestream","turso-cli","d1","pgbackrest","barman","wal-g"]),Hn=new Set(["gcloud","az","doctl","linode-cli","hcloud","oci","ibmcloud","scw","vultr-cli","exo","aliyun","tccli","cf","render","koyeb","northflank","porter","qovery","okteto","nomad","consul","vault","eksctl","kops","flux","databricks","confluent","ccloud","heroku","fly","flyctl","railway","vercel","netlify","wrangler","glab","dokku","caprover","kamal","coolify","sst","amplify","copilot","crane","oras"]),vd=new Set(["config","configure","auth","login","logout","components","alias","aliases","profile","profiles","context","contexts","completion","init","cache","plugin","plugins","extension","extensions","help","version"]);function lw(e){let n=e.name,t=Zr.has(n);if(!t&&!Hn.has(n))return[];let s=e.argv;if(!Te(s)||I(s,"--what-if","--validate-only","--check","--simulate","--no-execute"))return[];let r=_(s).slice(0,6);if(r.length>0&&vd.has(r[0]))return[];if(n==="rclone"&&ke(s.map(h=>$(h)),1,Ku).slice(1).every(h=>!Ye(h)))return[];let o=r.findIndex(aw),a=s.find(h=>/^--?(delete|drop|purge|wipe|truncate|destroy|flush|remove)(=|$)/.test(h));if(o<0&&!a)return[];if(o>0&&r.slice(0,o).some(h=>/^(list|ls|describe|get|show|info|logs?|cat|view|inspect|read|search|query)$/i.test(h)))return[];let i=r.slice(0,6),l=t||i.some(h=>Gc.test(h)||h.split(/[-:_.]/).some(g=>Gc.test(g))),c=o>=0?r[o]:a.split("=")[0],u=`${n} ${o>=0?r.slice(0,o+1).join(" "):c}`.trim(),p=o>=0?r.slice(o+1).find(h=>!h.includes("="))??null:r[0]??null,d=o>=0&&r[o].split(/[-:_.]/).every(h=>!kd.test(h)||/^reset$/i.test(h));return!l&&o>=0&&r.slice(0,o+1).some(h=>h.split(/[-:_.]/).some(g=>/^(options?|configs?|settings?|labels?|tags?|annotations?|env|vars?|variables?|aliases?|metadata)$/i.test(g)))?[w("claude.bash.deploy",`${u} changes a live service's settings`,{target:p,is_local:!1,host:n})]:[l?w("claude.bash.db.destructive",`${u} ${d?"resets":"deletes"} stored data`,{target:p,is_local:!1,host:n}):w("claude.bash.deploy",`${u} ${d?"resets a cloud resource":"deletes cloud resources"}`,{target:p,is_local:!1,host:n})]}function cw(e){let n=e.argv,t=s=>!!s&&!S(s)&&an(s.replace(/:\d+$/,""));if(e.name==="pg_restore"){if(I(n,"-l","--list","-f","--file"))return[];let s=n.some(l=>l==="--clean"||/^-[A-Za-z]+$/.test(l)&&l.includes("c")),r=P(n,"-d","--dbname");if(r===null)return[];let o=P(n,"-h","--host")??(/^postgres(ql)?:\/\//i.test(r)?me(r):null),a=Nd(e,"");if(a===null&&(t(o)||o===null&&!S(r)&&!/^postgres(ql)?:\/\//i.test(r)))return[];let i=a??(o!==null&&!S(o)?Fn(o):null);return[w("claude.bash.db.destructive",s?`pg_restore --clean drops the database's objects before it restores${i?` (${i})`:""}`:`pg_restore writes a dump into ${i??"a database the command does not name"}`,{target:i??$(r),is_local:!1,catastrophic:s&&i!==null})]}if(e.name==="mongorestore"||e.name==="mongoimport"){if(!I(n,"--drop"))return[];let s=P(n,"--uri","--host","-h"),r=s?/^mongodb(\+srv)?:\/\//.test(s)?me(s):s:"localhost";return t(r)?[]:[w("claude.bash.db.destructive",`${e.name} --drop drops ${e.name==="mongoimport"?"the collection before it imports":"each collection before it restores"}`,{target:S(r??"")?"a database the command does not name":r,is_local:!1})]}return[]}function uw(e){if(!Hn.has(e.name)&&!Zr.has(e.name)&&!["aws","kubectl"].includes(e.name))return[];let n=e.argv,t=_(n);if(!Te(n)||t.some(o=>/^(list|ls|describe|get|show|view|what-if)$/.test(o)))return[];let s=`${e.name} ${t.slice(0,3).join(" ")}`.trim();if(n.some(o=>/(^|[=:,\s"'])all(Authenticated)?Users\b/.test(o))&&!t.some(o=>/^remove-/.test(o))&&!(e.name==="gsutil"&&I(n,"-d")))return[w("claude.bash.net.expose",`${s} makes a cloud resource readable by anyone on the internet`,{target:t.slice(0,4).join(" ")||e.name,host:e.name,is_local:!1})];let r=P(n,"--public-access","--allow-blob-public-access");return r!==null&&/^(blob|container|true)$/i.test(r)?[w("claude.bash.net.expose",`${s} opens a storage container to anonymous reads`,{target:t.slice(0,4).join(" ")||e.name,host:e.name,is_local:!1})]:e.name!=="aws"&&t.some(o=>/^(create|update|add|authorize|allow|set)/.test(o))&&n.some(o=>/(^|[=\s"',])(0\.0\.0\.0\/0|::\/0)\b/.test(o))?[w("claude.bash.net.expose",`${s} admits the whole internet (0.0.0.0/0)`,{target:t.slice(0,4).join(" ")||e.name,host:e.name,is_local:!1})]:[]}function dw(e,n){let t=e.argv,s=_(t),r=O.basename(e.name)==="docker-compose"?s:s[0]==="compose"?s.slice(1):null;if(!(r?r.some(c=>/^(up|deploy|start|restart|run|create)$/.test(c)):/^(run|start|restart|create)$/.test(s[0]??"")||s[0]==="service"&&/^(create|update|scale|rollback)$/.test(s[1]??"")))return[];let a=t.indexOf(s[0]??"\0"),l=[...t.slice(0,a<0?t.length:a).flatMap((c,u,p)=>/^(-H|--host|--context|-c)$/.test(p[u-1]??"")?[c]:/^--(host|context)=/.test(c)?[c.slice(c.indexOf("=")+1)]:[]),...[...n.matchAll(/\bDOCKER_(?:HOST|CONTEXT)=["']?([^\s"';&|)]+)/g)].map(c=>c[1])].find(c=>!Xo.test(c));return l?[w("claude.bash.deploy",`${O.basename(e.name)} ${s.slice(0,2).join(" ")} runs on another machine's docker (${l})`,{target:l,is_local:!1,host:"docker"})]:[]}var fw=/^(deploy|deploys|deployment|deployments|promote|promotion|release|releases|rollout|rollback)$/i;function pw(e){let n=e.argv,t=_(n).slice(0,6);if(e.name==="docker"||e.name==="podman"){if(t[0]==="stack"&&t[1]==="deploy")return[w("claude.bash.deploy",`${e.name} stack deploy rolls out a swarm stack`,{target:t[2]??null,is_local:!1})];if(t[0]==="compose"&&(t.includes("up")||t.includes("deploy"))){let i=[P(n,"-f","--file")??"",P(n,"-p","--project-name")??"",Ws(e)];if(i.some(l=>Ns.test(O.basename(l).toLowerCase().replace(/\.(ya?ml)$/,""))||/(^|[._-])prod(uction)?([._-]|$)/i.test(O.basename(l))))return[w("claude.bash.deploy",`${e.name} compose starts the production stack (${O.basename(i.find(l=>l)??"")})`,{target:i.find(l=>l)??null,is_local:!1})]}return[]}if(!Hn.has(e.name)&&!Zr.has(e.name))return[];if(!Te(n)||I(n,"--what-if","--validate-only","--check","--simulate","--preview"))return[];if(t.length>0&&vd.has(t[0]))return[];let s=t.findIndex(i=>/^(run|exec|ssh|shell|console|connect|--)$/.test(i)),r=(s<0?t:t.slice(0,s)).filter(i=>!/[/.]/.test(i)||/^[\w-]+:[\w:-]+$/.test(i)),o=r.findIndex(i=>i.split(/[-:_.]/).some(l=>fw.test(l)));if(o<0)return[];if(r.slice(0,o+1).some(i=>i.split(/[-:_.]/).some(l=>/^(tokens?|keys?|credentials?)$/i.test(l))))return[];if(t.some(i=>/^(list|ls|describe|get|show|info|logs?|status|history|view|inspect|what-if|validate|diff|plan|wait|cancel|close)$/i.test(i)))return[];if(/^(deploy|release)-(branch|key|keys|hook|hooks|setting|settings|config|target|env)$/i.test(r[o])&&r.slice(0,o).some(i=>/(^|:)(set|unset|config|configure)$/.test(i)))return[w("claude.bash.deploy",`${e.name} ${r.slice(0,o+1).join(" ")} changes a deploy setting`,{target:r.slice(o+1).find(i=>!i.includes("="))??null,host:e.name,is_local:!1})];if(/(deploys|deployments|releases)$/i.test(r[o])&&r[o+1]===void 0)return[];let a=/(deploys|deployments?|deploy-requests?|releases)$/i.test(r[o])&&r[o+1]!==void 0?o+2:o+1;return[w("claude.bash.deploy",`${e.name} ${r.slice(0,a).join(" ")} starts a deploy`,{target:r.slice(a).find(i=>!i.includes("="))??null,host:e.name,is_local:!1})]}function hw(e){let n=e.argv;return["np","release-it","semantic-release"].includes(e.name)?!Te(n)||I(n,"--preview","--dry-run","-d","--no-ci","--help","-h")||_(n)[0]==="init"?[]:[w("claude.bash.publish",`${e.name} publishes a release`,{target:_(n)[0]??null,is_local:!1})]:[]}function gw(e){let n=e.argv;return(e.name==="python"||e.name==="python3")&&n.includes("manage.py")&&n.includes("dumpdata")&&Ns.test(Ws(e))?[w("claude.bash.data.export","manage.py dumpdata copies the production database onto this machine",{target:"dumpdata",is_local:!1})]:e.name==="firebase"&&_(n)[0]==="auth:export"?[w("claude.bash.data.export","firebase auth:export copies every user account onto this machine",{target:_(n)[1]??null,host:"firebase",is_local:!1})]:e.name==="prisma"&&_(n)[0]==="db"&&_(n)[1]==="execute"&&(Ns.test(Ws(e))||/(?:^|\s)[A-Z_]*DATABASE_URL=["']?\$\{?[A-Z_]*PROD/i.test(e.text)||/prod/i.test(P(n,"--url")??""))?[w("claude.bash.deploy","prisma db execute runs SQL against the production database",{target:P(n,"--file")??null,is_local:!1})]:[]}function mw(e){let n=e.argv,t=_(n),s=(()=>{switch(e.name){case"gpg":case"gpg2":return n.some(o=>/^--export-secret-(sub)?keys$/.test(o))?"gpg prints a private key":null;case"security":return t[0]==="dump-keychain"?n.some(o=>/^-[a-z]*d/.test(o))?"security dumps the keychain with its secrets":null:/^find-(generic|internet)-password$/.test(t[0]??"")&&n.some(o=>/^-[a-z]*[wg]/.test(o))?"security prints a saved password":null;case"kubectl":case"oc":return t[0]==="config"&&t[1]==="view"&&I(n,"--raw","--flatten")?`${e.name} config view --raw prints the cluster credentials`:null;case"heroku":return t[0]==="auth:token"?"heroku auth:token prints an API token":null;case"stripe":return t[0]==="config"&&I(n,"--list")?"stripe config --list prints the API keys":null;case"az":return t[0]==="ad"&&t[1]==="sp"&&t[2]==="create-for-rbac"?"az ad sp create-for-rbac creates a service principal and prints its password":t[0]==="account"&&t[1]==="get-access-token"?"az account get-access-token prints a token":null;case"aws":return t[0]==="ecr"&&t[1]==="get-login-password"?"aws ecr get-login-password prints a registry password":t[0]==="iam"&&t[1]==="create-access-key"?"aws iam create-access-key creates a key and prints its secret":t[0]==="sts"&&/^(get-session-token|assume-role)$/.test(t[1]??"")?`aws sts ${t[1]} prints temporary credentials`:null;case"claude":return t[0]==="setup-token"?"claude setup-token prints a long-lived Claude token":null;case"glab":return t[0]==="auth"&&t[1]==="status"&&I(n,"-t","--show-token")?"glab auth status --show-token prints the GitLab token":null;case"firebase":return t[0]==="login:ci"?"firebase login:ci prints a CI token":null;case"neonctl":case"neon":return/^(connection-string|cs)$/.test(t[0]??"")?`${e.name} ${t[0]} prints a connection string with its password`:null;case"php":case"artisan":{let o=e.name==="artisan"?0:n.slice(1).findIndex(l=>/(^|\/)artisan$/.test(l))+1;if(e.name==="php"&&o<=0)return null;let[a="",i=""]=n.slice(o+1).filter(l=>!l.startsWith("-"));return a==="config:show"&&/^(app|database|mail|services|cache|queue|broadcasting|filesystems|session|logging)(\.|$)/.test(i)?`artisan config:show ${i} prints settings with their secrets`:null}default:return t.includes("diffsettings")&&(n.some(o=>/(^|\/)manage\.py$/.test(o))||O.basename(e.name)==="django-admin")?"manage.py diffsettings prints SECRET_KEY and the database password":t[0]==="auth"&&/^(token|print-token|show-token)$/.test(t[1]??"")?`${e.name} auth ${t[1]} prints a token`:t.slice(0,4).some(o=>/^print-(access|identity|id)-token$/.test(o))?`${e.name} prints an access token`:t[0]==="token"&&/^(create|new|generate)$/.test(t[1]??"")?`${e.name} token ${t[1]} makes a token and prints it`:null}})(),r=e.pipeTo;return r&&$d(r)?[]:s!==null&&fe(e)?[w("claude.bash.secrets.print",s,{target:t.slice(0,3).join(" ")||e.name,is_local:!0,host:e.name})]:[]}function $d(e){let n=_(e.argv);return["pbcopy","xclip","xsel","wl-copy","clip.exe","clip"].includes(e.name)?!0:["xargs","echo","printf","cat","tee"].includes(O.basename(e.name))||e.argv.some(s=>/^(-o|--output)(=|$)|^--dry-run(=|$)/.test(s))?!1:e.argv.includes("--password-stdin")&&n.includes("login")||["kubectl","oc"].includes(e.name)&&e.argv.some(s=>s==="--from-file=/dev/stdin")||(e.name==="gpg"||e.name==="gpg2")&&I(e.argv,"--import")?!0:["gh","glab"].includes(e.name)?(n[0]==="secret"||n[0]==="variable")&&n[1]==="set":e.name==="wrangler"?n[0]==="secret"&&(n[1]==="put"||n[1]==="bulk"):e.name==="fly"||e.name==="flyctl"?n[0]==="secrets"&&(n[1]==="set"||n[1]==="import"):e.name==="vercel"?n[0]==="env"&&n[1]==="add":!1}function Ws(e){return(/(?:^|\s)(?:NODE_ENV|APP_ENV|RAILS_ENV|RACK_ENV|MIX_ENV|FLASK_ENV|DJANGO_ENV|ENVIRONMENT|STAGE)=["']?([\w.-]+)/.exec(e.text)?.[1]??P(e.argv,"--env","--environment","--settings")??"").toLowerCase()}var Ns=/(^|[._-])(prod|production|live)($|[._-])/;function yw(e){let n=e.argv,t=_(n),s=Ns.test(Ws(e)),r=a=>[w("claude.bash.db.destructive",a,{target:t.join(" ")||e.name,is_local:!1})],o=a=>s?r(`${a} in production`):[w("claude.bash.db.destructive",`${a}, with no server shown`,{target:t.join(" ")||e.name,is_local:null})];switch(e.name){case"sequelize":case"sequelize-cli":return t[0]==="db:drop"?o("sequelize db:drop drops the database"):s&&/^db:(drop|migrate:undo(:all)?|seed:undo(:all)?)$/.test(t[0]??"")?r(`sequelize ${t[0]} drops data in production`):[];case"knex":return s&&/^migrate:(rollback|down)$/.test(t[0]??"")?r(`knex ${t[0]} runs migrations backwards in production`):[];case"typeorm":case"typeorm-ts-node-commonjs":case"typeorm-ts-node-esm":return t[0]==="schema:drop"?o("typeorm schema:drop drops every table"):t[0]==="schema:sync"?o("typeorm schema:sync drops what the entities no longer name"):s&&/^(schema:drop|migration:revert)$/.test(t[0]??"")?r(`typeorm ${t[0]} drops data in production`):[];case"mix":return/^ecto\.(drop|reset)$/.test(t[0]??"")?o(`mix ${t[0]} drops the database`):s&&/^ecto\.(drop|reset|rollback)$/.test(t[0]??"")?r(`mix ${t[0]} drops data in production`):[];case"flyway":return t.includes("clean")?r("flyway clean drops every object in the schema"):[];case"liquibase":return t.some(a=>/^drop-?all$/i.test(a))?r("liquibase dropAll drops every object in the database"):[];case"php":case"artisan":{let a=e.name==="artisan"?0:n.slice(1).findIndex(l=>/(^|\/)artisan$/.test(l))+1;if(a<0||e.name==="php"&&a===0)return[];let i=n.slice(a+1).find(l=>!l.startsWith("-"))??"";return i==="db:seed"?s||I(n,"--force")?r(`artisan db:seed writes seed data into the database${s?" in production":" (--force: even in production)"}`):[]:/^(db:wipe|migrate:(fresh|reset|refresh|rollback))$/.test(i)?s||I(n,"--force")?r(`artisan ${i} drops the database's tables${s?" in production":" (--force: even in production)"}`):i==="migrate:rollback"?[]:o(`artisan ${i} drops every table`):[]}default:return[]}}function bw(e){let n=_(e).filter(t=>t.includes("/")||t.includes(":")).filter(t=>!["push","image","buildx","build"].includes(t));return n.length>0&&n.every(t=>/^(localhost|127\.0\.0\.1|\[::1\]|host\.docker\.internal)(:\d+)?\//.test(t))}var xd=/^(deploy|release|publish|ship)[-:_](notes|changelog|log|check|verify|lint|dry(-?run)?|plan|diff|status|info|list|test|smoke)$|^build[-:_]release$/;function _d(e){let n=new Set(["--filter","-F","--workspace","-w","--cwd","-C","--dir","--prefix","--scope","--filter-prod"]),t=[];for(let s=1;s<e.length;s++){let r=e[s];if(n.has(r)&&!(r==="-w"&&e[0]!=="npm")){s++;continue}if(r==="--")break;r.startsWith("-")||t.push(r)}return t[0]==="workspace"&&t.length>=3?[t[2],...t.slice(3)]:t[0]==="workspaces"&&t[1]==="foreach"?t.slice(2):t}function Sd(e){let n=_d(e.argv),t=n[0]??"",s=P(e.argv,"--registry");if(["publish","unpublish","deprecate"].includes(t)&&s!==null&&qe($(s)))return[];if(["publish","unpublish","deprecate"].includes(t)&&Te(e.argv))return[w("claude.bash.publish",`${e.name} ${t} changes a published package`,{target:n[1]??null,is_local:!1})];if(t==="dist-tag"&&["add","rm"].includes(n[1]??""))return[w("claude.bash.publish",`${e.name} dist-tag moves a published tag`,{target:n.slice(2).join(" "),is_local:!1})];if(t==="owner"&&["add","rm"].includes(n[1]??""))return[w("claude.bash.external_write",`${e.name} owner changes who can publish`,{is_local:!1})];if(O.basename(e.name)==="pnpm"&&t==="deploy")return[];let r=t==="run"||t==="run-script"?n[1]:e.name!=="npm"&&!Zi.has(t)?t:void 0;return r?Cd(r,e.argv):[]}function Cd(e,n){let t=!/^(check|verify|test|lint|validate|dry|preview|plan|diff|smoke|generate|prepare)([-:_]|$)/.test(e),s=xd.test(e),r=n.indexOf("--"),o=r>=0&&!Te(n.slice(r+1));return s||o?[]:/^(deploy|release|publish|ship)([-:_].*)?$/.test(e)||t&&/[-:_](deploy|release|publish)$/.test(e)?[w(/publish/.test(e)?"claude.bash.publish":"claude.bash.deploy",`the ${e} script deploys or releases`,{target:e,is_local:!1})]:t&&/^(promote|rollout|rollback)([-:_].*)?$|[-:_](promote|rollout|rollback)$/.test(e)?[w("claude.bash.deploy",`the ${e} script changes what is live`,{target:e,is_local:!1})]:/^db[-:_]?(push|reset|drop|wipe|nuke|truncate)\b|^(migrate|migration)[-:_]?(reset|fresh|drop)\b|[-:_](reset|drop|wipe)[-:_]?db$/.test(e)||/(^|[-:_])(db|database|schema|prisma|drizzle|clickhouse|postgres|mysql|mongo)[-:_](reset|drop|wipe|nuke|truncate|rollback|fresh)\b/.test(e)||/(^|[-:_])(migrate|migration|migrations)[-:_](deploy|prod|production|rollback|down|undo)\b/.test(e)?[w("claude.bash.db.destructive",`the ${e} script can drop, reset or change database data`,{target:e,is_local:null})]:[]}function ww(e){let n=O.basename(e.name),t=e.argv.slice(1).map(a=>$(a)),s=t.filter(a=>!a.startsWith("-")),r=(...a)=>t.flatMap((i,l)=>a.includes(i)?[t[l+1]??""]:a.some(c=>i.startsWith(`${c}=`))?[i.slice(i.indexOf("=")+1)]:[]).flatMap(i=>i.split(",")),o=[];if(n==="nx"){if(s[0]==="release"&&!t.includes("--dry-run")&&!t.includes("-d"))return[w("claude.bash.publish","nx release versions and publishes packages",{target:"nx release",is_local:!1})];o=s[0]==="run"?[(s[1]??"").split(":")[1]??""]:["run-many","affected"].includes(s[0]??"")?r("-t","--target","--targets"):s[0]?[s[0].includes(":")?s[0].split(":")[1]:s[0]]:[]}else if(n==="turbo"||n==="mise")o=s[0]==="run"?s.slice(1):n==="turbo"?s:[];else if(n==="lerna"){if(s[0]==="publish"&&!t.includes("--dry-run"))return[w("claude.bash.publish","lerna publish publishes packages",{target:"lerna publish",is_local:!1})];o=s[0]==="run"?s.slice(1,2):[]}else["run-s","run-p","npm-run-all"].includes(n)&&(o=s);for(let a of o.filter(Boolean)){let i=Cd(a,e.argv);if(i.length>0)return i.map(l=>({...l,why:`${l.why} (through ${n})`}))}return[]}var kw=new Set(["anvil","anvil-claude","hardhat","truffle","ape","forge","cast","anchor","prisma","drizzle-kit","supabase","wrangler","eas","expo","firebase","netlify","vercel","serverless","sls","cdk","dbt","ngrok","lt","untun","cloudflared","claude","codex","gemini","smithery","capgo","shorebird","web-ext","chrome-webstore-upload","changeset","lerna","vsce","ovsx","code-push","appcenter"]),Zi=new Set(["install","i","add","remove","rm","uninstall","update","up","upgrade","test","t","build","exec","dlx","x","create","init","link","unlink","list","ls","why","outdated","audit","config","cache","info","view","pack","run","start","dev","lint","format","typecheck","version","help","login","logout","whoami","ci","prune","dedupe","store","setup","workspaces","workspace"]),Ee=/\b(drop\s+(table|database|schema|keyspace|view|materialized\s+view|index|user|role|column|type|function|trigger|sequence|extension|owned|policy)\b|truncate\b|delete\s+from\b|alter\s+table\s+\S+\s+(drop|delete)\b|update\s+\S+\s+set\b(?![\s\S]*\bwhere\b))/i,vw=/\.(dropDatabase|drop|deleteMany|remove)\s*\(/;function Zc(e,n){let t=e.slice(n).search(/[\n\r]/);return t<0?e.length:n+t}function Oe(e,n="postgres"){if(/\b(execute|exec|sp_executesql|do)\b/i.test(e))return e;let t=n!=="postgres",s=n==="mysql"||n==="bigquery",r="";for(let o=0;o<e.length;o++){let a=e[o],i=e[o+1];if(a==="-"&&i==="-"&&(n!=="mysql"||o+2>=e.length||/\s/.test(e[o+2])))o=Zc(e,o)-1;else if(a==="#"&&(n==="mysql"||n==="bigquery")||a==="/"&&i==="/"&&n==="snowflake")o=Zc(e,o)-1;else if(a==="/"&&i==="*"){let l=e.indexOf("*/",o+2);n==="mysql"&&e[o+2]==="!"?r+=` ${e.slice(o+3,l<0?e.length:l)} `:r+=" ",o=l<0?e.length:l+1}else if(a==='"'&&!s||a==="`"&&(n==="mysql"||n==="bigquery")){let l=o+1;for(;l<e.length;l++)if(e[l]===a&&e[l+1]===a)l++;else if(e[l]===a)break;if(l>=e.length)return e;r+=a+a,o=l}else if(a==="$"&&(n==="postgres"||n==="snowflake")&&!/[\w$]/.test(e[o-1]??"")&&/^\$([A-Za-z_]\w*)?\$/.test(e.slice(o,o+64))){let l=/^\$([A-Za-z_]\w*)?\$/.exec(e.slice(o,o+64))[0],c=e.indexOf(l,o+l.length);if(c<0)return e;r+="''",o=c+l.length-1}else if(a==="'"||a==='"'&&s){let l=t||a==="'"&&/(^|[^\w])[eE]$/.test(r),c=o+1;for(;c<e.length;c++)if(l&&e[c]==="\\")c++;else if(e[c]===a&&e[c+1]===a)c++;else if(e[c]===a)break;if(c>=e.length)return e;r+=a+a,o=c}else r+=a}return r}function Pt(e){if(/(?<![\w-])ssh(?![\w-])[^\n;&|]{0,200}\s-[A-Za-z]*L\s*\S/.exec(e))return"ssh -L";let t=/\b(DOCKER_(?:HOST|CONTEXT)=\S+|(?:docker|podman)\b[^\n;&|]{0,100}\s(?:-H|--host|--context)[\s=]\S+|cloudflared\s+access\s+(?:tcp|rdp|ssh)|fly(?:ctl)?\s+proxy|(?:kubectl|oc)\b[^\n;&|]{0,200}\bport-forward|cloud[-_]sql[-_]proxy|cloud_sql_proxy|aws\s+ssm\s+start-session\b[^\n;&|]{0,200}PortForward|tsh\s+proxy\s+db|start-iap-tunnel|railway\s+connect)/i.exec(e);return t?t[1].replace(/\s+/g," ").slice(0,40):null}var $w=/\b(create\s+or\s+replace\s+(table|schema|database)|insert\s+overwrite|delete\s+(?!from\b)[\w.`"-]+\s+where)\b/i,Ss={exec(e){let n=$w.exec(e);return n?[n[0],n[1]]:/\bmerge\b/i.test(e)&&/\bthen\s+delete\b/i.test(e)?["MERGE \u2026 THEN DELETE","MERGE \u2026 THEN DELETE"]:null},test(e){return this.exec(e)!==null}};function Ki(e,n){let t=Ad.has(e.name)?Rd(e):null,s=t!==null?{...e,stdin:t}:e;s!==e&&Mr.has(e)&&Mr.add(s);let r=s.argv,o=s.name,a=(...f)=>P(r,...f),i=s.pipeFrom&&["echo","printf","cat"].includes(s.pipeFrom.name)?s.pipeFrom.argv.slice(1).join(" ")+(s.pipeFrom.stdin??""):"",l="",c=null,u=null,p=!0;switch(o){case"psql":case"pgcli":{l=[...r.flatMap((g,b)=>g==="-c"||g==="--command"?[r[b+1]??""]:g.startsWith("--command=")?[g.slice(10)]:[]),s.stdin??"",i].join(`
|
|
50
|
+
`),c=a("-h","--host");let f=a("-d","--dbname")??Od(r)[0]??null,h=f!==null&&/^\s*[a-z_]+\s*=/i.test($(f))&&!/\b(host|hostaddr|service)\s*=/i.test($(f));f!==null&&!h&&(S(f)?p=c!==null&&!S(c)&&an(c):(/^postgres(ql)?:\/\//i.test(f)||/\bhost=/.test(f))&&(u=/\bhost=([^\s]+)/.exec(f)?.[1]??me(f)));break}case"sqlite3":case"sqlite":{let f=r.slice(1).find(k=>!k.startsWith("-")),h=[r.slice(1).filter(k=>!k.startsWith("-"))[1]??"",s.stdin??"",i].join(`
|
|
51
|
+
`);if(!f||!Ee.test(h)||f===":memory:"||/\/scratchpad(\/|$)|^\/(private\/)?(tmp|var\/folders)\//.test(f))return[];let g=te(f,s.cwd,le(n)),b=g.why===rs?"own":Im(g.path,n);return b==="own"?[]:[w("claude.bash.fs.delete_recursive",`destroys data in a real database file (${O.basename($(f))})`,{target:$(f),is_local:!0,housekeeping:b==="dev"})]}case"mysql":case"mariadb":l=[a("-e","--execute")??"",s.stdin??"",i].join(`
|
|
45
52
|
`),c=a("-h","--host");break;case"clickhouse-client":case"clickhouse":l=[a("-q","--query")??"",s.stdin??"",i].join(`
|
|
46
|
-
`),c=a("-h","--host");break;case"cockroach":{l=a("-e","--execute")??"",c=a("--host");let
|
|
47
|
-
`),c=r.slice(1).find((
|
|
48
|
-
`),c="turso";break}case"prisma":{let
|
|
49
|
-
`);let h=a("--url");h!==null&&!S(h)?u=
|
|
50
|
-
`),c="planetscale";break}case"trino":case"presto":l=a("--execute")??s.stdin??"",c=a("--server"),c!==null&&(c=
|
|
51
|
-
`),h=r.find(
|
|
53
|
+
`),c=a("-h","--host");break;case"cockroach":{l=a("-e","--execute")??"",c=a("--host");let f=a("--url");f!==null&&(S(f)?p=!1:u=me(f));break}case"cqlsh":l=[a("-e","--execute")??"",s.stdin??"",i].join(`
|
|
54
|
+
`),c=r.slice(1).find((f,h)=>!f.startsWith("-")&&!/^(-e|--execute|-u|--username|-p|--password|-k|--keyspace|-f|--file|--cqlversion|--request-timeout|--connect-timeout|--cqlshrc)$/.test(r[h]??""))??null;break;case"turso":{let f=_(r);if(f[0]!=="db"||f[1]!=="shell")return[];l=[f.slice(3).join(" "),s.stdin??"",i].join(`
|
|
55
|
+
`),c="turso";break}case"prisma":{let f=_(r);if(f[0]!=="db"||f[1]!=="execute"||!I(r,"--stdin"))return[];l=[s.stdin??"",i].join(`
|
|
56
|
+
`);let h=a("--url");h!==null&&!S(h)?u=me(h):p=!1;break}case"pscale":{if(!["shell","sql"].includes(_(r)[0]??""))return[];l=[a("--query","--execute","-e")??"",s.stdin??"",i].join(`
|
|
57
|
+
`),c="planetscale";break}case"trino":case"presto":l=a("--execute")??s.stdin??"",c=a("--server"),c!==null&&(c=me(c)??c);break;case"sqlcmd":l=a("-Q","-q")??s.stdin??"",c=(a("-S")??"").replace(/^tcp:/i,"").split(/[,\\]/)[0]||null,c!==null&&/^(\.|\(local\)|localhost)$/i.test(c)&&(c="localhost"),c===null&&(p=!1);break;case"beeline":l=a("-e")??s.stdin??"",c=/\/\/([^:/;]+)/.exec(a("-u")??"")?.[1]??null,c===null&&(p=!1);break;case"impala-shell":l=a("-q","--query")??"",c=(a("-i","--impalad")??"").replace(/:\d+$/,"")||null,c===null&&(p=!1);break;case"spark-sql":l=a("-e")??"",c="spark";break;case"mongosh":case"mongo":{let f=[a("--eval")??"",s.stdin??""].join(`
|
|
58
|
+
`),h=r.find(b=>/^mongodb(\+srv)?:\/\//i.test(b));h&&(u=me(h)),c=a("--host");let g=r.slice(1).find((b,k)=>!b.startsWith("-")&&!/^--?(eval|file|f|host|port|username|u|password|p|authenticationDatabase)$/.test(r[k]??""));return g!==void 0&&S(g)&&(p=!1),vw.test(f)?Wt(s,c??u,p,`mongo ${/dropDatabase/.test(f)?"drops a database":/\.drop\s*\(/.test(f)?"drops a collection":"deletes documents"}`,Pt(n.lineText),f):[]}case"redis-cli":{let f=r.slice(1).map(g=>g.toLowerCase());if(!f.includes("flushall")&&!f.includes("flushdb"))return[];let h=a("-u");return Wt(s,a("-h")??(h?me(h):null),p,`redis ${f.includes("flushall")?"FLUSHALL wipes every database":"FLUSHDB wipes a database"}`,Pt(n.lineText))}case"dropdb":case"dropuser":return Wt(s,a("-h","--host"),p,`${o} deletes a database`,Pt(n.lineText));case"mysqladmin":return r.includes("drop")?Wt(s,a("-h","--host"),p,"mysqladmin drops a database",Pt(n.lineText)):[];case"bq":{let f=_(r),h=E=>[w("claude.bash.db.destructive",E,{target:f.slice(1).join(" ")||"bigquery",host:"bigquery",is_local:!1})];if(f[0]==="rm")return h("bq rm deletes a BigQuery table or dataset");if(f[0]==="load"&&I(r,"--replace"))return h("bq load --replace overwrites a BigQuery table");if(f[0]==="cp"&&I(r,"-f","--force"))return h("bq cp -f overwrites a BigQuery table");let g=a("--expiration","--default_table_expiration","--default_partition_expiration");if(f[0]==="update"&&g!==null&&g!=="0")return h("bq update sets BigQuery data to expire (be deleted)");if(f[0]!=="query"||I(r,"--dry_run"))return[];if(I(r,"--replace"))return h("bq query --replace overwrites its destination table");let b=Oe([r.slice(r.indexOf("query")+1).join(`
|
|
52
59
|
`),s.stdin??"",i].join(`
|
|
53
|
-
`),"bigquery")
|
|
54
|
-
`),"snowflake"),g=
|
|
55
|
-
`));return/^(md|motherduck):/i.test(
|
|
56
|
-
`).replace(/\\(.)/g,"$1"));for(let r of e.matchAll(new RegExp(`(?:^|[?&])${s}=([^&]*)`,"gi")))try{
|
|
57
|
-
`).replace(/\\t/g," "):
|
|
58
|
-
`),j=[.../^(\s*\w+=("[^"]*"|'[^']*'|[^\s;&|]*))*/.exec(e.text)[0].matchAll(/(?:^|\s)(\w+)=("[^"]*"|'[^']*'|\S*)/g)].filter(z=>/(HOST|URL|URI|DSN|ADDR|SERVER|ENDPOINT)/i.test(z[1])||vl.test(z[2].replace(/^["']/,""))).map(z=>z[2].replace(/^["']|["']$/g,"")),C=P(s,"--host","-host","--hostname","--server","-server","--server_address","--vtctld_server","--url","-url","--uri","--dsn","--connection","--connection-string","--conn","--database-url","--db-url","--endpoint","--addr","--address","-h")??(n==="curl"||n==="wget"?s.find((z,B)=>B>0&&!z.startsWith("-")&&!Js.has(s[B-1])&&(un(k(z))||S(z))):s.slice(1).find(z=>vl.test(k(z).replace(/^--?[\w-]+=/,""))))?.replace(/^--?[\w-]+=/,"")??j[0]??null,A=C===null?null:k(C),U=A!==null&&/^[^:[\]]+:\d+$/.test(A),I=A===null?u&&!T(s,"--local")?`${n}'s server`:null:/^[a-z][\w+.-]*:\/\//i.test(A)?$l(A):S(C)?C:U?A.replace(/:\d+$/,""):A,D=I===null?s.slice(1).map(z=>k(z).replace(/^--?[\w-]+=/,"")).find(z=>Dm.test(z)):void 0;return D!==void 0?[m("claude.bash.db.destructive",`${n} runs destructive SQL (${on(x)}) on a database file on this machine (${R.basename(D)})`,{target:D,is_local:!0})]:bt(e,I,!0,`${n} runs destructive SQL (${on(x)})`,Sl(t.lineText),x)}for(let x of h){let b=Mm(x);if(b===null)continue;let j=/\b(?:postgres(?:ql)?|mysql|mariadb|clickhouse|mssql|sqlserver|cockroachdb|redshift|snowflake)(?:\+\w+)?:\/\/[^\s'"`]+/i.exec(x)?.[0],C=j!==void 0?$l(j):/\bhost(?:name)?['"]?\s*[:=]\s*(['"`])([^'"`\s]+)\1/i.exec(x)?.[2]??null,A=/(?:process\.env\.|process\.env\[\s*['"]|environ(?:\.get)?\s*[([]\s*['"]|getenv\(\s*['"]|env\.get\(\s*['"])(\w*(?:HOST|URL|URI|DSN|CONN|SERVER)\w*)/i.exec(x)?.[1];if(!(C===null&&A===void 0&&(j===void 0&&/sqlite|duckdb|:memory:/i.test(x))))return bt(e,C??(A!==void 0?`$${A}`:null),!0,`${n} runs destructive SQL (${b}) through a database driver`,Sl(t.lineText),x)}return[]}function Bm(e){let t=ue(e[0]??"");if(t!=="heroku"&&t!=="netlify"&&t!=="vercel")return null;let n=/^(local|dev):(run|exec)$/.test(e[1]??"")?2:e[1]==="env"&&e[2]==="run"?3:-1;if(n<0)return null;let s=e.slice(e[n]==="--"?n+1:n);return s.length>0&&!s[0].startsWith("-")?s:null}function Gc(e){let t=new Set(["-c","--command","-f","--file","-h","--host","-p","--port","-U","--username","-d","--dbname","-v","--set","--variable","-o","--output","-L","--log-file","-P","--pset","-T","-F","-R"]),n=[];for(let s=1;s<e.length;s++){let r=e[s];t.has(r)?s++:r.startsWith("-")||n.push(r)}return n}function Ut(e){return e.startsWith("/")||Re(e)}function bt(e,t,n,s,r=null,o=""){let a=Yc(e),i=(e.remote===null||e.remote.startsWith("container:"))&&a===null,l=n&&!e.productionEnv&&i&&r===null&&(t===null||Ut(t))&&!(t!==null&&S(t)),c=Xc(e,o),u=t?fn(t):a??e.remote;if(c!==null)return[m("claude.bash.db.destructive",`${s}: ${c} is named for production`,{target:c,host:u,is_local:!1,catastrophic:!0})];if(l)return t!==null||e.remote!==null||Zm.has(e.name)||Qs.has(e)?[]:[m("claude.bash.db.destructive",`${s}, with no server shown`,{target:"no server shown",is_local:null,catastrophic:!1})];let f=r!==null&&(t===null||Ut(t))?`a database forwarded here (${r})`:t?fn(t):e.productionEnv?"production (railway run)":a!==null?`${a} (${e.remote?.replace(/^container:/,"container ")??"a container"})`:e.remote??"a database the command does not name";return[m("claude.bash.db.destructive",`${s} on ${f}`,{target:f,host:u,is_local:!1,catastrophic:!0})]}function Kc(e){return e.remote===null?null:e.remote.startsWith("container:")?Yc(e):e.remote==="kubernetes"?"a cluster's pod":e.remote}var Cl=/^(reload|restart|stop|start|enable|disable|daemon-reload|mask|kill|try-restart|reload-or-restart|graceful|delete|down|up|rm|update)$/;function Vm(e){let t=Kc(e);if(t===null)return[];let n=v(e.argv).map(i=>k(i)),s=R.basename(e.name),r=i=>[m("claude.bash.deploy",`${i} on ${t}`,{target:t,host:t,is_local:!1})];if(["rm","unlink","rmdir","shred","truncate"].includes(s)&&n.length>0)return r(`${s} deletes files`);if((s==="systemctl"||s==="service")&&n.some(i=>Cl.test(i)))return r(`${s} ${n.find(i=>Cl.test(i))} changes a service`);if(["docker","podman","docker-compose"].includes(s)){let i=n[0]==="compose"?1:0,l=n[i]==="exec"?void 0:n.slice(i,4).find(c=>/^(down|up|stop|rm|restart|kill|start|run|rmi|prune)$/.test(c));if(l)return r(`${s}${n[0]==="compose"?" compose":""} ${l} changes containers`)}let o=/^(\.{0,2}\/|~\/)|\.(sh|bash|py|rb)$/.test(e.argv[0]??"")||["bash","sh","zsh"].includes(s)&&/\.(sh|bash)$/.test(n[0]??""),a=n.find(i=>/^(remove|delete|destroy|uninstall|purge|drop|teardown|down)$/i.test(i));return o&&a?r(`runs ${R.basename(k(e.argv[0]??s))} ${a}`):[]}var Qs=new WeakSet,Zm=new Set(["redis-cli","mongosh","mongo"]);function Yc(e){if(e.remote===null||!e.remote.startsWith("container:"))return null;for(let t=e.parent;t;t=t.parent)if(t.remote!==null&&!t.remote.startsWith("container:"))return t.remote;return null}function or(e){let t=e.split(/[^A-Za-z0-9]+|(?<=[a-z0-9])(?=[A-Z])/);return t.some((n,s)=>/^(prod|prd|production|live)\d*$/i.test(n)&&!/^(non|pre|not|no|un)$/i.test(t[s-1]??""))}function Gm(e){let t=[];for(let n=e;n;n=n.parent){let s=P(["",...n.wrapperArgs],"--config","--env","--environment","--stage","--profile");s!==null&&t.push(s)}return t}function Jc(e){return[.../^(\s*\w+=("[^"]*"|'[^']*'|[^\s;&|]*))*/.exec(e.text)[0].matchAll(/(?:^|\s)(\w+)=("[^"]*"|'[^']*'|\S*)/g)].filter(n=>!/pass|pwd|secret|token|key|auth/i.test(n[1])).flatMap(n=>[n[1],n[2]])}function Xc(e,t){let n=e.argv.map(r=>k(r));return[...Gm(e),...n.filter((r,o)=>o>0&&!/\s/.test(r)&&!/^-([UupPfoceqWaL]|-(user(name)?|pass(word)?|port|file|output|command|execute|eval|query|sql|log-file))$/.test(n[o-1])&&!/^(--?(user|pass|port|file|output)|-[UupP].)/.test(r)).map(r=>r.replace(/^--?[\w-]+=/,"")),...n.flatMap(r=>[...r.matchAll(/\b(?:dbname|host)=([^\s'"]+)/g)].map(o=>o[1])),...[...k(t).matchAll(/(?:\\c(?:onnect)?\s+|\b(?:drop\s+(?:database|schema|keyspace)\s+(?:if\s+exists\s+)?|use\s+|(?:table|from|into|update)\s+(?:if\s+exists\s+)?(?=[`"']?[\w$]+[`"']?\.)))[`"']?([\w$-]+)/gi)].map(r=>r[1]),...Jc(e)].map(r=>r.replace(/(:\/\/)[^@/\s]+@/,"$1").replace(/\?.*$/,"")).find(r=>r.length<=200&&or(r))?.slice(0,80)??null}var Qc=new Set(["firebase","xata","fauna","aws","gsutil","azd","upctl","yc","openstack","terraform","tofu","terragrunt","pulumi","cdk","cdktf","serverless","sls","ticloud","neon","neonctl","upstash","supabase","pscale","turso","atlas","mongocli","modal","bq","snow","snowsql","juju","rclone","s3cmd","mc","b2","argocd","velero","rancher","zeet","scaleway","civo"]),Km=/^(delete|deletion|destroy|remove|rm|rb|uninstall|terminate|purge|teardown|deprovision|decommission|drop|wipe|nuke|erase|tombstone|truncate|flushall|flushdb)$/,Ym=/^(env|envs|vars?|variables?|configs?|settings?|labels?|tags?|annotations?|alias(es)?|metadata|options?|domains?)$/,Jm=/^(clusters?|serverless|instances?|buckets?|regions?|stores?|replicas?|shards?|partitions?|brokers?|namespaces?|volumes?|stacks?|deployments?|tombstone|vpcs?)$/,eu=/^(kind-|k3d-|minikube$|docker-desktop$|rancher-desktop$|orbstack$|colima)/,Xm=/\.aws\/credentials|\.azure\/|gcloud\/.*(credential|token)|application_default_credentials|service[-_]?account[^/]*\.json|-sa(-key)?\.json$|\.kube\/config|kubeconfig|\.oci\/|oci_api_key|doctl\/|credentials\.tfrc|\.s3cfg|\.boto$|\.vault-token/i,Qm=/^\/(var\/lib\/(mysql|postgresql|pgsql|mongodb|redis|cassandra|clickhouse|elasticsearch|influxdb|etcd|mariadb)|(usr\/local|opt\/homebrew)\/var\/(postgres|mysql|mongodb))/;function ey(e){if(eu.test(k(P(e.argv,"--context","--kube-context")??"")))return!1;let t=v(e.argv);if(e.name==="helm"||t[0]!=="delete"||T(e.argv,"-f","--filename","-k","--kustomize"))return!0;let n=t[1]??"";return!(n.includes("/")?t.slice(1).map(s=>s.split("/")[0]):n.split(",")).every(s=>/^(po|pods?|jobs?|events?|ev|rs|replicasets?|leases?)$/i.test(s))}function ty(e,t){if(e.catastrophic!==void 0||e.housekeeping)return e;let n=e.action,s=t.name,r=t.argv.map(d=>k(d)),o=v(r).slice(0,6).flatMap(d=>d.toLowerCase().split(/[-_:]/)),a=d=>o.some(h=>d.test(h)),i=(a(Km)||r.includes("-destroy")||r.includes("--destroy"))&&!a(Ym),l=["kubectl","oc","helm"].includes(s),c=l||Qc.has(s)||yn.has(s),u=n==="claude.bash.db.destructive",f=u||n==="claude.bash.deploy"?(l?i&&ey(t):c?(i||u&&!/\bresets\b/.test(e.why))&&!T(t.argv,"--local"):i&&e.is_local===!1&&/read by its words/.test(e.why)&&a(Jm)&&!r.some(d=>eu.test(d)))||u&&(t.productionEnv||Yn.test(Kn(t))||Jc(t).some(or))||s==="heroku"&&r[1]==="run"&&/\b(db:(drop|reset|purge|schema:load)|flush|migrate:(fresh|reset|refresh)|ecto\.(drop|reset)|dropdb)\b/.test(r.join(" ")):n==="claude.bash.fs.delete_recursive"?r.some(d=>Qm.test(d)):n==="claude.bash.secrets.print"&&(c||[e.target??"",...r,t.stdinFile??""].some(d=>Xm.test(k(d)))),p=c&&n!=="claude.bash.fs.delete_recursive"&&a(/^(credentials?|keys?|passwords?|tokens?|rbac)$/)&&a(/^(reset|create|rotate|new|regenerate|renew|for)$/)&&ae(t);return f||p?{...e,catastrophic:!0}:e}var ny=/(^|\/)(\.env(\.(?![\w.-]*\b(example|sample|template|tpl|tmpl|dist|defaults|schema)\b)[\w.-]+)?|\.envrc|[^/]*\.pem|[^/]*\.key|[^/]*\.p12|[^/]*\.pfx|[^/]*\.keystore|[^/]*\.jks|id_(rsa|dsa|ecdsa|ed25519)|\.npmrc|\.pypirc|\.netrc|\.git-credentials|credentials(\.json)?|[^/]*[-_.]credentials\.json|[^/]*service[-_]account[^/]*\.json|(key|keystore)\.properties|[\w-]*deploy[-_]key(\.pem)?|[^/]*serviceaccountkey[^/]*\.json|[^/]*\.p8|[^/]*keypair[^/]*\.json|\.config\/solana\/id\.json|\.dockercfg|kubeconfig(-[\w.-]+)?(\.(ya?ml|json|conf))?|[\w-]+[-_]kubeconfig(\.(ya?ml|json))?|\.pgpass|\.my\.cnf|credentials\.tfrc\.json|rclone\.conf|\.s3cfg|\.vault-token|\.dev\.vars|[^/]*firebase-admin[^/]*\.json|secrets?\.(ya?ml|json|toml)|terraform\.tfvars|authorized_keys|\.anvil\/workspace-keys\.json)$/i,sy=/(^|\/)\.(aws|kube|docker|ssh|gnupg|config\/gh)\/(credentials|config(\.json)?|hosts\.yml|id_[a-z0-9_]+|[^/]*\.pem)$/i,ry=/(^|\/)\.ssh\/config$/;function ko(e){return ye(e)&&!ry.test(k(e))}var oy=/(^|\/)\.ssh\/(?!known_hosts|authorized_keys|config$|environment$|rc$)[^/]+(?<!\.pub)$/;function ye(e){let t=k(e);return ny.test(t)||sy.test(t)||oy.test(t)||iy.test(t)&&!/\/memory(\/|$)/.test(t)}var iy=/(^|\/)\.claude\/projects(\/[^/]+)?\/?$|(^|\/)\.claude\/projects\/[^/]+\/[^/]+\.jsonl$|(^|\/)\.claude\/projects\/[^/]+\/[^/]+\/subagents\/[^/]+\.jsonl$/,dn=/(SECRET|TOKEN|PASSW(OR)?D|PASSPHRASE|API_?KEY|PRIVATE_?KEY|ACCESS_?KEY|CREDENTIAL|AUTH|DSN|DATABASE_UR[IL]|DB_URL|REDIS_UR[IL]|POSTGRES(QL)?_UR[IL]|PG_?URL|MONGO(DB)?_UR[IL]|AMQP_URL|RABBITMQ_URL|CONNECTION_STRING|WEBHOOK_URL|CLIENT_SECRET|SIGNING|_PAT$|^PAT_|COOKIE|SESSION_KEY)/i,tu=/^(PWD|OLDPWD|PATH|HOME|USER|SHELL|TERM|LANG|TMPDIR|LOGNAME|EDITOR|PAGER|HOSTNAME)$/;function ae(e){if(e.captured||e.redirects.some(r=>(r.op===">"||r.op===">>"||r.op==="&>"||r.op===">|"||r.op==="1>")&&(r.fd===null||r.fd===1)&&r.target&&!["/dev/stdout","/dev/tty","/dev/stderr"].includes(r.target)))return!1;let t=!1,n=e.pipeTo,s=!1;for(let r=e.pipeTo;r;r=r.pipeTo)if(n=r,r.name==="tee"&&(s=!0),r.name==="tee"&&r.argv.slice(1).some(o=>/^\/dev\/(stderr|tty|fd\/[12])$/.test(k(o))))return!0;if(n&&!s&&zc(n))return!1;for(let r=e.pipeTo;r;r=r.pipeTo)if(["grep","rg","egrep"].includes(r.name)&&ly(r.argv.slice(1))&&(t=!0),ay(r)&&t||nu(r)||r.redirects.some(o=>(o.op===">"||o.op===">>")&&(o.fd===null||o.fd===1)&&o.target&&o.target!=="/dev/stdout"))return!1;return e.parent?ae(e.parent):!0}function ay(e){return e.name==="sed"&&/\[\^[^\]]*@[^\]]*\][*+]@/.test(e.argv.slice(1).join(" "))}function ly(e){let t=e.find(s=>!s.startsWith("-"));if(!t)return!1;let n=t.replace(/[\^$()\\]/g,"").split("|").map(s=>s.trim().replace(/=$/,"")).filter(Boolean);return n.length>0&&n.every(s=>/^[A-Za-z0-9_]+$/.test(s)&&(/(URL|URI|DSN|POSTGRES|PG_?URL|REDIS|MONGO|DATABASE)/i.test(s)||/^[A-Za-z][A-Za-z0-9]*(_[A-Za-z0-9]+)+$/.test(s)&&!dn.test(s)))}function nu(e){let t=e.argv.slice(1),n=t.join(" ");switch(e.name){case"wc":case"sha256sum":case"shasum":case"md5":case"diff":case"cmp":return t.some(s=>s==="-q"||s==="--brief"||s==="--quiet");case"md5sum":case"pbcopy":case"xclip":case"true":return!0;case"grep":case"rg":case"egrep":return t.some(s=>/^-[a-zA-Z]*[clLq]/.test(s)||s==="--count"||s==="--quiet"||s==="--files-with-matches")||cy(t)||uy(t);case"cut":return/-d\s*=?\s*'?=/.test(n.replace(/\s+/g," "))&&/-f\s*1\b|-f1\b/.test(n);case"awk":return/\{\s*print\s+\$1\s*\}/.test(n)&&/-F\s*'?=|-F=/.test(n);case"sed":return/\bs([/|#,])=\.[*+]\$?\1[^\\&]*\1/.test(n);case"jq":return/\bkeys\b|\blength\b|\bhas\(/.test(n);case"node":case"python":case"python3":case"ruby":return/\bkeys\b|Object\.keys|\.keys\(\)|length/.test(n+(e.stdin??""));case"head":return t.includes("-c")&&t[t.indexOf("-c")+1]==="0";default:return!1}}function cy(e){let t=e.find(s=>!s.startsWith("-"));if(!t)return!1;let n=t.replace(/[\^$()\\]/g,"").split("|").map(s=>s.trim().replace(/=$/,"")).filter(Boolean);return n.length>0&&n.every(s=>/^[A-Za-z][A-Za-z0-9]*(_[A-Za-z0-9]+)+$/.test(s)&&!dn.test(s))}function uy(e){if(!e.some(s=>/^-[a-zA-Z]*o[a-zA-Z]*$/.test(s)||s==="--only-matching"))return!1;let t=e.find(s=>!s.startsWith("-")),n=t?.endsWith("=")?t.slice(0,-1):t;return n!==void 0&&!/\.|\\S|\[\^|=|\\w\*/.test(n)}var er=new Set(["cat","head","tail","less","more","bat","nl","tac","strings","grep","rg","egrep","sed","awk","cut","sort","uniq","xxd","od","base64","jq","yq","column","pr","paste","fold","rev","fmt","expand","unexpand","iconv","tr","tee","diff","hexdump","hd","comm"]);function dy(e,t){let n=t.secretCopies,s=e.argv,r=e.name,o=s.slice(1);if(r==="printenv"||(r==="env"||r==="set"||r==="export"||r==="declare")&&o.every(f=>f.startsWith("-")&&f!=="-c"))return r==="printenv"&&o.filter(f=>!f.startsWith("-")).length>0&&!o.some(f=>!f.startsWith("-")&&dn.test(f))?[]:(r==="export"||r==="declare")&&!o.some(f=>f==="-p"||f==="-x"||o.length===0)?[]:r==="set"&&o.length>0?[]:!ae(e)||yy(e)==="no-secret"?[]:[m("claude.bash.secrets.print",`${r} prints the environment, secrets included`,{target:r,is_local:!0})];let a=f=>ko(f)||n.has(X(f,e.cwd,se(t)).path),l=(r==="xargs"?s.find((f,p)=>s[p-1]==="-a"||s[p-1]==="--arg-file")??s.find(f=>f.startsWith("--arg-file="))?.slice(11)??s.find(f=>/^-a./.test(f))?.slice(2):void 0)??e.stdinFile;if((r==="exec"||r==="xargs")&&l&&a(l))return[m("claude.bash.secrets.print",`${r==="exec"?"feeds a secrets file to the commands after it":"passes a secrets file to a command"} (${R.basename(k(l))})`,{target:k(l),is_local:!0})];if(r==="git"&&s.includes("--no-index")&&s.slice(1).some(f=>!f.startsWith("-")&&a(f))&&ae(e)){let f=s.slice(1).find(p=>!p.startsWith("-")&&a(p));return[m("claude.bash.secrets.print",`prints a secrets file (${R.basename(k(f))})`,{target:k(f),is_local:!0})]}let c=r==="dd"?s.find(f=>f.startsWith("if="))?.slice(3):void 0,u=s.find(f=>f.startsWith("of="))?.slice(3);if(c&&a(c)&&(u===void 0?ae(e):["/dev/stdout","/dev/stderr","/dev/tty","/dev/fd/1","/dev/fd/2"].includes(u)))return[m("claude.bash.secrets.print",`prints a secrets file (${R.basename(k(c))})`,{target:k(c),is_local:!0})];if(er.has(r)){let f=["-","/dev/stdin","/dev/fd/0"],p=r==="tr"||r==="tee"?[]:qt(e).filter(j=>!f.includes(j)),d=r==="tr"||r==="tee"||e.argv.slice(1).some(j=>f.includes(j))||qt(e).length===0,h=e.stdinFile!==null&&d?[...p,e.stdinFile]:p,g=["sed","gsed"].includes(r)&&e.argv.slice(1).some(j=>/^(-i\S*|--in-place(=.*)?|-[A-Za-z]*i)$/.test(k(j)))||/^g?awk$/.test(r)&&/(^| )(-i ?|--include[= ])inplace\b/.test(e.argv.map(k).join(" ")),y=h.filter(j=>(g?ye(j):ko(j))||n.has(X(j,e.cwd,se(t)).path)),$=r==="tee"&&qt(e).some(j=>["/dev/stderr","/dev/tty","/dev/fd/2","/dev/stdout"].includes(j)),E=["sed","gsed"].includes(r)&&e.argv.slice(1).some(j=>/^(-i\S*|--in-place(=.*)?|-[A-Za-z]*i)$/.test(k(j))),x=j=>X(j,e.cwd,se(t)).path||k(j);if(y.length&&E)return y.slice(0,8).map(j=>m("claude.file.write_secret",`edits a secrets file in place (${R.basename(k(j))})`,{target:x(j),is_local:!0}));if(y.length&&(ae(e)||$)&&!nu({...e,pipeTo:null}))return y.slice(0,8).map(j=>m("claude.bash.secrets.print",`prints a secrets file (${R.basename(k(j))})`,{target:x(j),is_local:!0}));let b=e.stdinExpands&&ae(e)?Al(e.stdin??"",e,t):null;return b?[m("claude.bash.secrets.print",`prints a secret through $(\u2026) (${R.basename(b)})`,{target:b,is_local:!0})]:[]}if(r==="security"&&/^find-(generic|internet)-password$/.test(o[0]??"")&&o.some(f=>f==="-w"||f==="-g"||/^-[a-z]*[wg]$/.test(f)))return ae(e)?[m("claude.bash.secrets.print","prints a keychain password",{target:"keychain",is_local:!0})]:[];if(r==="kubectl"&&["get","describe"].includes(v(s)[0]??"")&&/^secrets?$/.test(v(s)[1]??"")&&s.some((f,p)=>/^-o(yaml|json|jsonpath|go-template)|^--output/.test(f)||["yaml","json"].includes(f)||/^(jsonpath|go-template|custom-columns)=/.test(f)||s[p-1]==="-o"&&/^(yaml|json|jsonpath|go-template)/.test(f)))return ae(e)?[m("claude.bash.secrets.print","kubectl prints a secret",{target:"kubectl secret",is_local:!1})]:[];if(r==="op"&&(o[0]==="read"||o[0]==="item"&&o.includes("--reveal"))||r==="vault"&&(o[0]==="read"||o[0]==="kv"&&o[1]==="get")||r==="doppler"&&o[0]==="secrets"&&(o.length===1||["get","download"].includes(o[1]??"")||(o[1]??"").startsWith("-"))||r==="infisical"&&(o[0]==="secrets"&&(o.length===1||o[1]==="get"||o[1].startsWith("-"))||o[0]==="export"&&!s.some(f=>f.startsWith("--output-file")))||r==="az"&&v(s)[0]==="keyvault"&&v(s)[1]==="secret"&&v(s)[2]==="show"||r==="dotenv"&&["list","get"].includes(pe(s,1,new Set(["-f","--file","-e","-c","-v","-p"]))[0]??""))return ae(e)?[m("claude.bash.secrets.print",`${r} prints a secret`,{target:r,is_local:!0})]:[];if((r==="echo"||r==="printf"||r==="print"||e.stdinKind==="here-string"&&er.has(r))&&ae(e)){let f=[...s.slice(1),e.stdinKind==="here-string"?e.stdin??"":""].map(p=>Al(p,e,t)).find(p=>p!==null);if(f)return[m("claude.bash.secrets.print",`prints a secret through $(\u2026) (${R.basename(f)})`,{target:f,is_local:!0})]}if(r==="echo"||r==="printf"||r==="print"){let f=su(e.text);for(let p of f.matchAll(/\$(?:\{(#?)([A-Za-z_][A-Za-z0-9_]*)([^}]*)\}|([A-Za-z_][A-Za-z0-9_]*))/g)){let d=p[2]??p[4],h=p[3]??"";if(!(p[1]==="#"||/^:?\+/.test(h)||/^:\s*0?\s*:\s*[1-8]$/.test(h))&&dn.test(d.replace(/AUTHOR(?!IZ)/gi,""))&&!tu.test(d)&&ae(e))return[m("claude.bash.secrets.print",`echoes a secret variable (${d})`,{target:d,is_local:!0})]}}return[]}function fy(e){let t=[];for(let n=0;n<e.length;n++)if(e[n]==="`"){let s=e.indexOf("`",n+1);if(s<0)break;t.push(e.slice(n+1,s)),n=s}else if(e[n]==="$"&&e[n+1]==="("){let s=0,r=n+1;for(;r<e.length;r++)if(e[r]==="(")s++;else if(e[r]===")"&&--s===0)break;t.push(e.slice(n+2,r)),n=r}return t}function Al(e,t,n){if(!e.includes("$(")&&!e.includes("`"))return null;for(let s of fy(e)){let r=s.trim(),o=/^<\s*["']?([^"'\s]+)["']?$/.exec(r);if(o){if(ye(o[1]))return o[1];continue}for(let a of Jn(r,t.cwd,n).commands){let i=Gn(a,n).find(l=>l.action==="claude.bash.secrets.print"&&!l.why.startsWith("echoes a secret variable"));if(i)return i.target??a.name}}return null}function qt(e){let t=e.argv.slice(1),n=t.filter((o,a)=>!o.startsWith("-")&&!["-e","-f","--regexp","--file","-m","-A","-B","-C","--max-count"].includes(t[a-1]??"")),s=t.some(o=>o==="-e"||o==="--regexp"||o.startsWith("--regexp=")||o==="-f"||o==="--file");return["grep","rg","egrep","sed","awk","jq","yq"].includes(e.name)&&!(e.name!=="sed"&&e.name!=="awk"&&e.name!=="jq"&&e.name!=="yq"&&s)&&!(e.name==="sed"&&s)?n.slice(1):n}var py=/(^|\/)(public|static|www|htdocs|wwwroot|public_html)(\/|$)/;function hy(e,t){if(["cp","mv","install","rsync","ditto"].includes(e.name)){let n=e.argv.slice(1).filter(o=>!o.startsWith("-")),s=n.at(-1),r=n.slice(0,-1).find(o=>ye(o));if(s!==void 0&&r!==void 0&&!S(s)&&py.test(M(s,e.cwd,t.ctx))&&He(s,e,t).kind!=="disposable")return[m("claude.bash.secrets.expose",`copies a secrets file (${R.basename(k(r))}) into a folder a web server serves (${k(s)})`,{target:k(s),is_local:!0})]}if(["echo","printf","print"].includes(e.name)){let n=e.redirects.find(s=>[">",">>",">|","1>","&>"].includes(s.op)&&(s.fd===null||s.fd===1)&&s.target)?.target;if(n&&!n.startsWith("/dev/")&&!S(n)&&!ye(n)&&!ot.test(n)){let s=[...su(e.text).matchAll(/\$(?:\{([A-Za-z_][A-Za-z0-9_]*)\}|([A-Za-z_][A-Za-z0-9_]*))/g)].map(r=>r[1]??r[2]).find(r=>dn.test(r)&&!tu.test(r));if(s!==void 0&&He(n,e,t).kind!=="disposable")return[m("claude.bash.secrets.expose",`writes the value of ${s} into ${R.basename(k(n))}`,{target:k(n),is_local:!0})]}}return[]}var gy=/\.(pem|key|crt|cer|der|p12|pfx|jks|keystore|p8)$/i;function my(e,t){let n=t.replace(/(?<!\/)\/+$/,""),s=e.startsWith(`${n}/`)?e.slice(n.length+1):null;return s!==null?/^\.(ssh|aws|kube|gnupg|docker|azure|oci|helm|minikube|config\/(gcloud|gh|helm|doctl))(\/|$)/.test(s):/^\/(etc|usr|System|Library|private\/etc|opt\/homebrew\/etc|var\/lib)(\/|$)/.test(e)||!e.startsWith("/")}function su(e){let t="",n=!1;for(let s=0;s<e.length;s++){let r=e[s];if(r==="\\"&&!n)t+=e.slice(s,s+2),s++;else if(r==='"')n=!n,t+=r;else if(r==="'"&&!n){let o=e.indexOf("'",s+1),a=o===-1?e.length:o;t+=" ".repeat(a-s+1),s=a}else t+=r}return t}function yy(e){let t=e.pipeTo;if(!t||!["grep","rg","egrep"].includes(t.name))return"none";let n=t.argv.slice(1).find(s=>!s.startsWith("-"))??"";return dn.test(n)||n===""?"secret":"no-secret"}function El(e,t){let n=[];for(let u of e.redirects)[">",">>","&>",">|","1>"].includes(u.op)&&u.target&&n.push(u.target);e.name==="tee"&&n.push(...e.argv.slice(1).filter(u=>!u.startsWith("-")));let s=e.argv.slice(1).flatMap(u=>u==="--no-clobber"||/^--update=none(-fail)?$/.test(u)?["n"]:u==="--force"?["f"]:u==="--interactive"?["i"]:/^-[A-Za-z]+$/.test(u)?[...u.slice(1)].filter(f=>"nfi".includes(f)):[]).pop(),r=(e.name==="cp"||e.name==="mv")&&s==="n";(e.name==="cp"||e.name==="mv"||e.name==="install")&&e.argv.length>=3&&!r&&n.push(e.argv[e.argv.length-1]);let o=u=>{let f=R.basename(k(u)).toLowerCase();return/\.(pem|crt|cer)$/.test(f)&&/(^|[-_.])(ca|cacert|cert|certs|certificate|certificates|chain|fullchain|bundle|root|intermediate|public|pub)([-_.]|$)/.test(f)&&!/key|priv|secret|p12|pfx|keystore|jks|id_/.test(f)},a=u=>{let f=X(u,e.cwd,se(t)).path,p=t.projectRoot&&!S(t.projectRoot)?t.projectRoot.replace(/(?<!\/)\/+$/,""):null,d=t.ctx.home.replace(/(?<!\/)\/+$/,"");return p!==null&&p!==""&&p!=="/"&&p!==d&&!d.startsWith(`${p}/`)&&f.startsWith(`${p}/`)},i=n.find(u=>ye(u)&&!u.startsWith("/dev/")&&!(o(u)&&a(u)));if(!i)return[];if(He(i,e,t).kind==="disposable")return[];let c=R.basename(k(i));return gy.test(c)&&e.remote===null&&!my(X(i,e.cwd,se(t)).path,t.ctx.home)?[]:[m("claude.file.write_secret",`writes ${/\.(pem|crt|cer|der|p12|pfx|key)$/i.test(c)?"a key or certificate file":"a secrets file"} (${c})`,{target:k(i),is_local:!0})]}function Bs(e,t){let n=e.findIndex((s,r)=>r>0&&new RegExp(`^-[A-Za-z]*${t}$`).test(s));return n>0?e[n+1]??null:null}function fn(e){let t=k(e).replace(/^["']|["']$/g,"");return/^[a-z][a-z0-9+.-]*:\/\//i.test(t)||/^[\w.-]+\.[a-z]{2,}\//i.test(t)?de(t)??t.replace(/\/.*/,""):t.replace(/(:\/\/)[^@/\s]+@/g,"$1***@")}function P(e,...t){for(let n=1;n<e.length;n++){let s=e[n];for(let r of t){if(s===r&&e[n+1]!==void 0)return e[n+1];if(r.startsWith("--")&&s.startsWith(`${r}=`))return s.slice(r.length+1);if(!r.startsWith("--")&&r.length===2&&s.startsWith(r)&&s.length>2)return s.slice(2)}}return null}function Le(e,t=!1){let n=k(e).replace(/(?<!\/)\/+$/,""),s=R.basename(n);return/\.(enc|sops|encrypted|gpg|age|asc)(\.[\w-]+)?$|\.enc\.|\.sops\./i.test(s)||/^(package(-lock)?\.json|tsconfig[\w.-]*\.json|readme[\w.-]*|license[\w.-]*|changelog[\w.-]*|\.gitkeep|\.keep|\.gitignore)$/i.test(s)||t&&/^\.(npmrc|envrc)$/.test(s)||/(^|\/)templates\//.test(n)&&/^secrets?\.ya?ml$/.test(s)||s==="debug.keystore"||/\.(pem|crt)$/i.test(s)&&/(bundle|chain|cacert|ca-cert|^ca[-_.]|root|intermediate|cert|public|pub)/i.test(s)&&!/key|priv/i.test(s)?!1:/^[^/]+\.env$/.test(s)&&!/^(example|sample|template|tpl)\.env$/i.test(s)?!0:ye(n)||ye(n.replace(/\*+$/,""))||/(^|\/)\.(ssh|aws|gnupg|kube|docker|config\/gh)$|(^|\/)(secrets?|credentials)$/i.test(n)||/(^|\/)(secrets?|credentials)\//i.test(n)&&(!/\./.test(s)||/\.(json|ya?ml|env|toml|ini|txt|pem|key|p12|pfx|crt|cer|properties|conf|cfg|xml|plist|csv|jks|keystore)$/i.test(s))}var by=/^\/\.claude(\/settings(\.local)?\.json|\/hooks(\/.*)?|\/plugins(\/.*)?)?$|^\/\.claude\.json$|^\/\.mcp\.json$|^\/\.anvil(\/claude(\/.*)?|\/rules\.(?:json|md)|\/workspace-keys\.json|\/telemetry-notice)?$/i,wy=/(^|\/)managed-(settings|mcp)\.json$/i,ky=/(^|\/)library\/launch(agents|daemons)(\/|$)|^\/etc\/systemd\/|(^|\/)\.config\/systemd\/user(\/|$)|^\/(usr\/)?lib\/systemd\/system(\/|$)|^\/etc\/cron(\.(d|hourly|daily|weekly|monthly)(\/|$)|tab$)|^\/(private\/)?(var\/spool\/cron|usr\/lib\/cron\/tabs)(\/|$)/;function Bo(e,t,n=[],s=!0){return Vo(e,t,n,s).place}function Vo(e,t,n=[],s=!0){let r=so(e,t,n,s);if(r==="agent")return{place:r,at:e};let o=u=>{for(let[f,p]of Object.entries(t.controlLinks??{})){if(S(u)||!(u===f||u.startsWith(`${f}/`)))continue;let d=p+u.slice(f.length);if(so(d,t,n,s)==="agent")return d}return null},a=o(e);if(a!==null)return{place:"agent",at:a};if(!t.onDisk)return{place:r,at:e};let i=ks(e,t.onDisk,!0),l=i!==null?o(i):null;if(l!==null)return{place:"agent",at:l};let c=i===null?null:so(i,t,n,s);return i!==null&&(c==="agent"||r===null)?{place:c,at:i}:{place:r,at:e}}var vy=/^\/projects\/[^/]+\/(?:[^/]+\.jsonl|[^/]+\/subagents\/.+\.jsonl)$/i,$y=/^\/projects(?:\/[^/]+(?:\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}(?:\/subagents)?)?)?\/?$/i,Zo=e=>[`${e.home.replace(/(?<!\/)\/+$/,"")}/.claude`,...e.claudeConfigDir&&!S(e.claudeConfigDir)?[e.claudeConfigDir.replace(/(?<!\/)\/+$/,"")]:[]];function St(e,t,n=!0){let s=e.toLowerCase();return!s.includes("/projects")||S(e)||/\/memory(\/|$)/i.test(e)?!1:Zo(t).some(r=>(s===`${r.toLowerCase()}/projects`||s.startsWith(`${r.toLowerCase()}/projects/`))&&(vy.test(e.slice(r.length))||n&&$y.test(e.slice(r.length))))}function ir(e,t,n){if(!/[*?[]/.test(e)||S(e)||!e.toLowerCase().includes("/projects"))return!1;let s="3f2a9c1e-5d4b-4a7e-9b1c-2e8f6a0d7c35",r=(i,l)=>{if(!/[*?[]/.test(i))return i.toLowerCase()===l.toLowerCase()||l!=="projects"&&l!=="subagents"&&(l.endsWith(".jsonl")?/\.jsonl$/i.test(i):l===s?/^[0-9a-f]{8}-/i.test(i):i.toLowerCase()!=="memory");let c=/^[^*?[]*/.exec(i)[0];return[l,c+l.slice(c.length)].some(u=>Go(i).test(u))},o=[["projects","-Users-dev-app",`${s}.jsonl`],["projects","-Users-dev-app",s,"subagents","agent-a1b2c3.jsonl"],["projects","-Users-dev-app",s,"subagents","workflows","w","journal.jsonl"]],a=n?[...o,["projects","-Users-dev-app"],["projects","-Users-dev-app",s],["projects","-Users-dev-app",s,"subagents"]]:o;return Zo(t).some(i=>{if(!e.toLowerCase().startsWith(`${i.toLowerCase()}/`))return!1;let l=e.slice(i.length+1).replace(/(?<!\/)\/+$/,"").split("/");return a.some(c=>c.length===l.length&&l.every((u,f)=>r(u,c[f])))})}function ar(e,t,n=null){if(!S(e))return!1;let s=e.indexOf(ie),r=s>0?e.slice(0,s).replace(/(?<!\/)\/+$/,"").toLowerCase():"";if(r&&!Zo(t).some(u=>`${u.toLowerCase()}/projects`.startsWith(r)||r.startsWith(`${u.toLowerCase()}/projects`)))return!1;let o=k(e);if(n!==null&&!S(n)&&/\.jsonl|\b(ls|find)\b|\*/.test(o)&&St(n.replace(/(?<!\/)\/+$/,""),t))return!/\/memory(\/|$)/i.test(o);if(!o.toLowerCase().includes("/projects"))return!1;let a=t.home.replace(/(?<!\/)\/+$/,""),i=t.claudeConfigDir&&!S(t.claudeConfigDir)?t.claudeConfigDir.replace(/(?<!\/)\/+$/,""):null,l=u=>u.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),c=new RegExp(`(?:(?:~|\\$\\{?HOME\\}?|${l(a)})["']?/\\.claude${i?`|${l(i)}["']?`:""})/projects(?:/[^\\s'"|;&)<>]*)?`,"gi");for(let u of o.matchAll(c)){let f=o.slice(u.index);if(!(/\/memory\//i.test(f)&&!/(^|\/)\.\.(\/|$)/.test(f)))return!0}return!1}function xy(e,t){return e.name==="find"||e.name==="gfind"?iu(e,t)!==null:e.argv.slice(1).some(n=>{if(n.startsWith("-"))return!1;let s=k(M(n,e.cwd,t.ctx));return ar(n,t.ctx,e.cwd)||St(s,t.ctx)||ir(s,t.ctx,!0)})}function _y(e){return`writes Claude Code's record of a session (${R.basename(e)||e})`}var Sy=["3f2a9c1e-5d4b-4a7e-9b1c-2e8f6a0d7c35.jsonl","3f2a9c1e-5d4b-4a7e-9b1c-2e8f6a0d7c35","agent-a1b2c3.jsonl","journal.jsonl","subagents","workflows","-Users-dev-app","projects"];function Cy(e,t){let n=e.argv.slice(1),s=n.findIndex(l=>/^-(exec|execdir|ok|okdir)$/.test(l)),r=n.findIndex((l,c)=>c>s&&(l===";"||l==="+")),o=s<0?[]:n.slice(s+1,r<0?void 0:r),a=n.find((l,c)=>/^-(fprint0?|fprintf|fls)$/.test(n[c-1]??"")&&St(k(M(l,e.cwd,t.ctx)),t.ctx,!1));if(a!==void 0)return k(M(a,e.cwd,t.ctx));let i=n.includes("-delete");return!i&&!(o.length>0&&ou(o,o.at(-1)==="{}"))||(i||/^(rm|unlink)$/.test(ue(o[0]??"")))&&ru(n,i?n.indexOf("-delete"):s)?null:iu(e,t)}function ru(e,t){let n=e.findIndex((s,r)=>e[r-1]==="-mtime"&&/^\+([7-9]|[1-9]\d+)$/.test(s)||e[r-1]==="-mmin"&&/^\+\d+$/.test(s)&&Number(s.slice(1))>=10080);return n>0&&n<t&&!["!","-not"].includes(e[n-2]??"")&&!e.some(s=>["-o","-or","(",")",","].includes(s))}function ou(e,t){let n=ue(e[0]??""),s=e.slice(1);if(/^(rm|unlink|shred|srm|trash|truncate|tee|dd|touch|chmod|chown|chflags|xattr|setfacl|g?mv|ed|ex|sponge)$/.test(n))return!0;if(/^(g?sed|perl)$/.test(n))return s.some(o=>/^-[a-zA-Z]*i/.test(o)||o.startsWith("--in-place"));if(/^g?awk$/.test(n))return s.some((o,a)=>o==="inplace"&&s[a-1]==="-i");if(/^(g?cp|install|rsync|ln|ditto)$/.test(n))return t&&!s.some(o=>o==="-t"||o.startsWith("--target-directory"));let r=/^(ba|z|da|k)?sh$/.test(n)?s.indexOf("-c"):-1;return r>=0&&/[>]|\b(rm|truncate|tee|g?mv|dd|touch|sed\s+-[a-zA-Z]*i|perl\s+-[a-zA-Z]*i)\b/.test(s[r+1]??"")}function iu(e,t){let n=e.argv.slice(1),s=[],r=0;for(;r<n.length&&/^-[HLPEXdsx]$/.test(n[r]);)r++;for(;r<n.length&&!/^[-(!]/.test(n[r]);r++)s.push(n[r]);s.length===0&&s.push(".");let o=n.flatMap((f,p)=>p>0&&["-name","-iname"].includes(n[p-1])?[{f,i:n[p-1]==="-iname"}]:[]),a=o.length===0||o.some(({f,i:p})=>Sy.some(d=>Go(p?f.toLowerCase():f).test(p?d.toLowerCase():d))),i=n.flatMap((f,p)=>p>0&&["-path","-ipath","-wholename","-iwholename"].includes(n[p-1])?[f]:[]);if(!a||i.length>0&&i.every(f=>/memory/i.test(f)))return null;let l=t.ctx.home.replace(/(?<!\/)\/+$/,"").toLowerCase(),c=t.ctx.claudeConfigDir&&!S(t.ctx.claudeConfigDir)?t.ctx.claudeConfigDir.replace(/(?<!\/)\/+$/,"").toLowerCase():null,u=[`${l}/.claude/projects`,...c?[`${c}/projects`]:[]];for(let f of s){if(S(f)&&!f.startsWith("/"))continue;let p=M(f,e.cwd,t.ctx).replace(/(?<!\/)\/+$/,"");if(S(p))continue;let d=p.toLowerCase();if(u.some(h=>d===h||h.startsWith(`${d}/`)||d==="/"||d.startsWith(`${h}/`)&&!/\/memory(\/|$)/.test(d)))return k(p)}return null}function so(e,t,n,s=!0){let r=k(e);if(s&&(St(r,t,s===!0)||ir(r,t,s===!0)))return"agent";let o=n.filter(f=>f!==null&&f!==""&&!S(f)),a=r.toLowerCase();if((o.length>1?[...new Set(o)].map(f=>a.startsWith(`${f.toLowerCase()}/`)?r.slice(f.length):null).filter(f=>f!==null):[r.replace(/^.*(?=\/\.claude(\/|\.json$|$)|\/\.mcp\.json$|\/\.anvil(\/|$))/,"")]).some(f=>by.test(f))||wy.test(r))return"agent";let l=t.claudeConfigDir?.replace(/(?<!\/)\/+$/,"").toLowerCase();if(l&&(a===l||a===`${l}/settings.json`||a===`${l}/settings.local.json`||a===`${l}/.claude.json`||a===`${l}/hooks`||a.startsWith(`${l}/hooks/`)||a===`${l}/plugins`||a.startsWith(`${l}/plugins/`)))return"agent";let c=R.dirname(r);if(Do(c)||X(c,null,{home:t.home,tmpdir:t.tmpdir,projectRoot:null}).kind==="disposable")return null;if(ky.test(r.toLowerCase()))return"jobs";let u=t.home;return[`${u}/.gitconfig`,`${u}/.config/git/config`,"/etc/gitconfig"].some(f=>f.toLowerCase()===a)?"gitconfig":null}function Ay(e,t){let n=[],s=a=>{a&&a!=="-"&&!a.startsWith("/dev/")&&n.push(M(Ie(a,e,t),e.cwd,t.ctx))};for(let a of e.redirects)a.target&&a.op.includes(">")&&!(a.op.endsWith("&")&&/^(\d+|-)$/.test(a.target))&&s(a.target);let r=e.argv.slice(1),o=r.filter(a=>!a.startsWith("-"));switch(e.name){case"tee":case"sponge":case"truncate":case"rm":case"unlink":case"trash":case"srm":case"shred":case"mkfifo":o.forEach(s);break;case"mknod":o[0]&&s(o[0]);break;case"touch":for(let a=0;a<r.length;a++)/^(-[tdrA]|--(date|reference|time))$/.test(r[a])?a++:r[a].startsWith("-")||s(r[a]);break;case"cp":case"mv":case"install":case"ln":case"ditto":case"gcp":case"gmv":{let a=P(e.argv,"-t","--target-directory"),i=a!==null?o.filter(c=>c!==a):o.slice(0,-1),l=a??(o.length>=2?o[o.length-1]:e.name==="ln"&&o.length===1?".":null);if(l!==null){s(l);for(let c of i)s(R.join(l,R.basename(k(c))))}e.name==="ln"&&i.forEach(s),(e.name==="mv"||e.name==="gmv")&&i.forEach(s);break}case"sed":case"gsed":case"perl":case"ruby":case"yq":{if(!r.some(c=>c==="--in-place"||c.startsWith("--in-place=")||c==="--inplace"||/^-[A-Za-z]*i/.test(c)&&!c.startsWith("--")))break;let i=[],l=!1;for(let c=0;c<r.length;c++){let u=r[c];["-e","--expression","-f","--file"].includes(u)||(e.name==="perl"||e.name==="ruby")&&/^-[A-Za-z]*e$/.test(u)?(l=!0,c++):u.startsWith("-")||i.push(u)}(l?i:i.slice(1)).forEach(s);break}case"dd":s(r.find(a=>a.startsWith("of="))?.slice(3));break;case"chmod":case"chown":case"chgrp":case"chflags":if(e.name==="chmod"){let a=r.filter(i=>!/^-[RHLPfhvcECNiI]+$/.test(i)&&!i.startsWith("--"));(r.some(i=>i.startsWith("--reference"))?a:a.slice(1)).forEach(s)}else(r.some(a=>a.startsWith("--reference"))?o:o.slice(1)).forEach(s);break;case"curl":s(P(e.argv,"-o","--output")??Bs(e.argv,"o"));break;case"scp":{let a=new Set(["-P","-i","-F","-o","-c","-l","-S","-J","-D","-X"]),i=r.filter((c,u)=>!c.startsWith("-")&&!a.has(r[u-1]??"")),l=i.length>=2?i[i.length-1]:null;l!==null&&!/^[^/]*:/.test(l)&&s(l);break}case"wget":s(P(e.argv,"-O","--output-document")??Bs(e.argv,"O")??P(e.argv,"-P","--directory-prefix"));break;case"rsync":{let a=pe(e.argv,1,Ko),i=a.length>=2?a[a.length-1]:null;if(i!==null&&!Te(i)){s(i);for(let l of a.slice(0,-1))s(R.join(i,R.basename(k(l).replace(/(?<!\/)\/+$/,""))))}break}case"tar":case"gtar":case"bsdtar":case"unzip":{let a=e.name==="unzip"?P(e.argv,"-d"):P(e.argv,"-C","--directory");(e.name==="unzip"?!r.some(l=>/^-[A-Za-z]*[ltpZ]/.test(l)):r.some(l=>/^-?[A-Za-z]*x/.test(l)||l==="--extract"||l==="--get"))&&s(a??".");break}case"7z":case"7za":case"7zr":case"7zz":["x","e"].includes(o[0]??"")&&s(r.find(a=>a.startsWith("-o"))?.slice(2)||".");break;case"sort":s(P(e.argv,"-o","--output")??Bs(e.argv,"o"));break;case"base64":s(P(e.argv,"-o","--output"));break;case"openssl":s(P(e.argv,"-out"));break;case"awk":case"gawk":case"mawk":case"nawk":{let a=Mr(e.argv)??"";if(r.some((i,l)=>i==="-i"&&r[l+1]==="inplace"||i==="-iinplace"||i==="--include=inplace")){let i=pe(e.argv,1,new Set(["-i","--include","-F","-v","-f","-e","-l"]));(a&&i[0]===a?i.slice(1):i).forEach(s)}for(let i of a.matchAll(/\b(?:print|printf)\b(?:"(?:\\.|[^"\\])*"|[^;}|"])*?>{1,2}\s*"((?:\\.|[^"\\])+)"/g))s(i[1]);break}case"ed":case"red":case"ex":case"vi":case"vim":case"nvim":case"emacs":{if(r.some(i=>i==="-R"||i==="-M"||i==="--read-only")||e.name==="emacs"&&!r.some(i=>i==="--batch"||i==="-batch"||i==="--script"))break;let a=e.name==="ed"||e.name==="red"?new Set(["-p"]):new Set(["-c","--cmd","-S","-u","-U","-i","-T","-w","-W","-t","-q","--eval","-l","--load","-f","--funcall","--script"]);pe(e.argv,1,a).filter(i=>!i.startsWith("+")).forEach(s);break}case"patch":s(pe(e.argv,1,new Set(["-i","--input","-p","-d","-o","--output","-r","-B","-z","-V","-F"]))[0]);break;case"plutil":r.some(a=>/^-(replace|insert|remove|convert)$/.test(a))&&s(o[o.length-1]);break;case"git":{let a=_t(e);if(a&&a.sub==="clone"&&s(pe(["git",...a.args],1,new Set(["-b","--branch","-o","--origin","--depth","-c","--config","--reference","--template","-j","--jobs","--filter"]))[1]),a&&["checkout","restore"].includes(a.sub)){let i=a.args.indexOf("--");(a.sub==="restore"&&a.args.some(u=>u==="--staged"||u==="-S")&&!a.args.some(u=>u==="--worktree"||u==="-W")?[]:i>=0?a.args.slice(i+1):a.sub==="restore"?a.args.filter(u=>!u.startsWith("-")):[]).forEach(s)}break}default:break}return n}var au=/permissionMode:\s*['"]?bypassPermissions\b|allowed-tools:[^\n]*\bBash(\(\*\))?(?![\w(])|allowed-tools:[ \t]*\n(?:[ \t]*-[^\n]*\n)*?[ \t]*-[ \t]*['"]?Bash(\(\*\))?['"]?[ \t]*(?:\n|$)/;function Rl(e){if(!e||typeof e!="object")return"";let t=e,n=Array.isArray(t.edits)?t.edits.map(s=>s&&typeof s=="object"&&typeof s.new_string=="string"?s.new_string:""):[];return[t.content,t.new_string,...n].filter(s=>typeof s=="string").join(`
|
|
59
|
-
`)
|
|
60
|
-
`))}var Ty=/\b(CLAUDE_CONFIG_DIR|ANVIL_CLAUDE_SYNC|CLAUDE_CODE_SIMPLE|CLAUDE_CODE_SAFE_MODE|ANVIL_WORKSPACE_KEYS_PATH)\b|\balias\s+['"]?claude=|\bclaude\s*\(\s*\)|\bfunction\s+claude\b/;function vo(e){let t=e.pipeFrom,n=e.stdin??(["echo","printf","sed"].includes(e.name)?e.argv.slice(1).join(`
|
|
61
|
-
`)
|
|
62
|
-
`)
|
|
63
|
-
`)
|
|
60
|
+
`),"bigquery"),k=Ee.exec(b)??Ss.exec(b);return k?h(`bq query runs destructive SQL (${k[1].replace(/\s+/g," ").toUpperCase()})`):[]}case"snowsql":case"snow":{let f=_(r);if(o==="snow"&&(f[0]==="object"&&f[1]==="drop"||f[0]==="stage"&&["remove","rm"].includes(f[1]??"")))return[w("claude.bash.db.destructive",`snow ${f[0]} ${f[1]} deletes Snowflake data`,{target:f.slice(2).join(" ")||"snowflake",host:"snowflake",is_local:!1})];if(o==="snow"&&f[0]!=="sql")return[];let h=Oe([a("-q","--query")??"",s.stdin??"",i].join(`
|
|
61
|
+
`),"snowflake"),g=Ee.exec(h)??Ss.exec(h);return g?[w("claude.bash.db.destructive",`${o} runs destructive SQL (${g[1].replace(/\s+/g," ").toUpperCase()}) on Snowflake`,{target:"snowflake",host:"snowflake",is_local:!1})]:[]}case"databricks":{let f=_(r);if(f[0]==="api"){let h=f[2]??"",g=a("--json")??"",b=(()=>{try{let E=JSON.parse(g);return typeof E=="object"&&E!==null&&typeof E.statement=="string"?E.statement:g}catch{return g}})(),k=Oe(b,"bigquery");return f[1]==="post"&&/sql\/statements/.test(h)&&(Ee.test(k)||Ss.test(k))||f[1]==="delete"&&/unity-catalog\/(tables|schemas|catalogs|volumes)|\/dbfs\//.test(h)?[w("claude.bash.db.destructive",`databricks api ${f[1]} destroys stored data`,{target:h,host:"databricks",is_local:!1})]:[]}return f[0]==="fs"&&f[1]==="rm"||["tables","schemas","catalogs","volumes","registered-models"].includes(f[0]??"")&&f[1]==="delete"?[w("claude.bash.db.destructive",`databricks ${f[0]} ${f[1]} deletes stored data`,{target:f.slice(2).join(" ")||"databricks",host:"databricks",is_local:!1})]:[]}case"duckdb":{let f=r.slice(1).find(g=>!g.startsWith("-"))??"",h=Oe([a("-c")??"",s.stdin??"",i].join(`
|
|
62
|
+
`));return/^(md|motherduck):/i.test(f)&&Ee.test(h)?[w("claude.bash.db.destructive",`duckdb runs destructive SQL (${Ee.exec(h)[1].replace(/\s+/g," ").toUpperCase()}) on MotherDuck`,{target:f,host:"motherduck",is_local:!1})]:[]}case"dbt":{let f=_(r);if(!["run","build","seed"].includes(f[0]??"")||!I(r,"--full-refresh"))return[];let h=a("--target","-t");return h===null||!S(h)&&/^(dev|development|local|ci|test|testing|staging|stage|sandbox|qa|preview)([-_][\w-]+)?$/i.test(h)?[]:[w("claude.bash.db.destructive",`dbt ${f[0]} --full-refresh rebuilds tables on ${h?$(h):"the default target"}`,{target:h??"dbt",host:"dbt",is_local:!1})]}case"wrangler":return _(r)[0]==="d1"&&_(r)[1]==="execute"&&I(r,"--remote")&&Ee.test(a("--command")??"")?[w("claude.bash.db.destructive","wrangler runs destructive SQL on a remote D1 database",{is_local:!1,host:"cloudflare"})]:[];default:return[]}let d=Oe(l,["mysql","mariadb","clickhouse-client","clickhouse"].includes(o)?"mysql":["spark-sql","beeline","impala-shell"].includes(o)?"bigquery":"postgres");if(!Ee.test(d)){let f=s.pipeFrom,h=s.stdinFile??(f&&/^(cat|[bx]?zcat|gunzip|gzip|pv|zstdcat)$/.test(f.name)?f.argv.slice(1).find(k=>!k.startsWith("-"))??null:null),g=[...o==="psql"||o==="pgcli"?r.flatMap((k,E)=>k==="-f"||k==="--file"?[r[E+1]??""]:k.startsWith("--file=")?[k.slice(7)]:[]):[],...h!==null&&["psql","mysql","mariadb"].includes(o)?[h]:[]].filter(k=>k!=="-"&&k!=="");if(g.length===0)return[];let b=O.basename($(g[0]));return Wt(s,c??u,p,`runs the SQL in ${b}`,Pt(n.lineText),d).filter(k=>k.target!=="no server shown").map(k=>({...k,catastrophic:!1}))}return Wt(s,c??u,p,`runs destructive SQL (${(Ee.exec(d)?.[1]??"").replace(/\s+/g," ").toUpperCase()})`,Pt(n.lineText),l)}var $r='[\\w.$"`[\\]{}-]+',xw=new RegExp(`^(drop\\s+(?:database|table|schema)\\s+(?:if\\s+exists\\s+)?${$r}(?:\\s*,\\s*${$r})*(?:\\s+(?:cascade|restrict|purge|sync|on\\s+cluster\\s+\\S+))*$|truncate\\s+(?:table\\s+)?(?:if\\s+exists\\s+)?(?:only\\s+)?${$r}(?:\\s*,\\s*${$r})*\\s*(?:(?:restart|continue)\\s+identity\\s*)?(?:cascade|restrict)?(?:\\s+on\\s+cluster\\s+\\S+)?(?:\\s+settings\\s[\\s\\S]*)?$|delete\\s+from\\b(?![\\s\\S]*\\bwhere\\b))`,"i"),_w=/^(select|insert|update|delete|drop|truncate|create|alter|with|begin|commit|rollback|savepoint|release|set|use|grant|revoke|vacuum|analyze|show|explain|copy|merge|replace|upsert|start|end|pragma|attach|detach|optimize|rename|comment|call|declare|describe|system|kill|lock|unlock|refresh|do|exec|execute|prepare|values|reindex|checkpoint|discard|reset|abort|load)\b/i,Sw=/^\s*(drop\s+(?:database|table|schema)|truncate)(?:\s+table)?(?:\s+if\s+exists)?\s*(?:\$\{|\{|%s|\?|$)/i,Kc=/^--?(sql|query|execute|command|statement|stmt|c|e|q|Q)$/,Cw=new Set(["echo","printf","cat","tee","grep","egrep","fgrep","rg","ag","ack","sed","gsed","awk","gawk","mawk","nawk","jq","yq","sort","head","tail","less","more","wc","cut","tr","diff","patch","touch","truncate","git","gh","glab","hg","svn","bash","sh","zsh","dash","ksh","fish","eval","exec","source","ssh","xargs","docker","podman","kubectl","oc","tmux","screen","watch","claude","codex","gemini","aider","llm","sgpt","ollama","amp","cursor-agent","droid","qwen","copilot","crush","opencode","goose","mods","aichat","tgpt","howdoi","fzf","gum","say","logger","osascript","notify-send","vim","nvim","vi","nano","emacs","code","cursor","subl","open","pbcopy","xclip","wl-copy","test","[","export","read","cd","mkdir","umask","cp","mv","dd","install","sponge","split","base64","gzip","gunzip","bzip2","xz","zstd","md5","md5sum","sha1sum","sha256sum","sha512sum","shasum","mail","mailx","sendmail","scp","rsync","tar","zip","sqlfluff","sql-formatter","pg_format","sqlformat","squawk","prettier","mysqldump","pg_dump","pg_dumpall"]),Aw=new Set(["vtctlclient","vtctldclient","vtctl","spanner-cli","bteq"]),Ew=/^(sql|psql|mysql|query|execute|statement|connect)$/,Ad=new Set(["psql","pgcli","sqlite3","sqlite","mysql","mariadb","clickhouse-client","clickhouse","cockroach","cqlsh","turso","prisma","pscale","trino","presto","sqlcmd","beeline","impala-shell","spark-sql","mongosh","mongo","redis-cli","dropdb","dropuser","mysqladmin","bq","snowsql","snow","databricks","duckdb","dbt","wrangler"]),Rw=/(?:require\(\s*|from\s+|import\s+(?:[\w.]+\s*,\s*)*)['"]?(?:pg|postgres|mysql2?|mssql|oracledb|psycopg2?|asyncpg|pymysql|MySQLdb|mysql\.connector|sqlalchemy|clickhouse[_-](?:connect|driver)|@clickhouse\/client|snowflake[.-](?:connector|sdk)|@neondatabase\/serverless|@planetscale\/database|@vercel\/postgres|@prisma\/client|knex|sequelize|kysely|pyodbc|pymssql)\b/,Yc=/^(?!(?:sqlite\d?|duckdb|file):)[a-z][\w+.-]*:\/\/[^/\s]/i;function Jc(e){let n=/^[a-z][\w+.-]*:\/\/(?:[^@/?#]*@)?([^/?#]*)/i.exec(e)?.[1];return n===void 0?me(e):n===""||/^%2f/i.test(n)||/[?&]host=(\/|%2f)/i.test(e)?null:me(e)}var Ow=/^(?:(?:sqlite\d?|duckdb|file):|[^:\s]*\.(?:db|sqlite3?|duckdb)$)/i,jw=/^(cp|sync|mv|put|upload|add|set|create|write|import|rcat|push)$/;function On(e){if(!e)return null;let n=e.toLowerCase();if(!n.includes("drop")&&!n.includes("truncate")&&!n.includes("delete"))return null;let t=$(e).replace(/^[ \t]*(?:[.\\][^\n]*|go)[ \t]*$/gim,";"),s=Oe(t).split(";").map(o=>o.replace(/^(?:\s|--[^\n]*|\/\*[\s\S]*?\*\/)+/,"").trim()).filter(Boolean);if(s.length===0||!_w.test(s[0]))return null;let r=s.map(o=>xw.exec(o)?.[1]).find(o=>o!==void 0);return r===void 0?null:/^delete/i.test(r)?"DELETE FROM with no WHERE":r.split(/\s+/).slice(0,/^drop/i.test(r)?2:1).join(" ").toUpperCase()}function Pw(e){let n=[];for(let t=0;t<e.length;t++){let s=e[t];if(s!=='"'&&s!=="'"&&s!=="`")continue;let r=t+1;for(;r<e.length&&e[r]!==s;)r+=e[r]==="\\"?2:1;if(r>=e.length)break;n.push(e.slice(t+1,r)),t=r}return n}function Ww(e){for(let n of Pw(e)){let t=On(n)??Sw.exec(n)?.[1]?.split(/\s+/).slice(0,2).join(" ").toUpperCase();if(t)return t}return null}function Nw(e,n){let t=[],s=n?"(?:query|sql|stmt|statement)":"(?:sql|stmt|statement)";for(let r of e.matchAll(new RegExp(`"${s}"\\s*:\\s*"((?:\\\\.|[^"\\\\])*)"`,"gi")))t.push(r[1].replace(/\\n/g,`
|
|
63
|
+
`).replace(/\\(.)/g,"$1"));for(let r of e.matchAll(new RegExp(`(?:^|[?&])${s}=([^&]*)`,"gi")))try{t.push(decodeURIComponent(r[1].replace(/\+/g," ")))}catch{}return t}function Lw(e){let n=null,t=!1,s=!1;for(let r=1;r<e.length;r++){let o=e[r];if(o==="-X"||o==="--request"||o==="--method")n=(e[r+1]??"").toUpperCase();else if(o.startsWith("--request=")||o.startsWith("--method="))n=o.slice(o.indexOf("=")+1).toUpperCase();else if(o[0]==="-"&&o[1]!=="-"&&o.includes("X")){let a=/^-[a-zA-Z]*X([A-Za-z]+)$/.exec(o)?.[1];a!==void 0?n=a.toUpperCase():/^-[a-zA-Z]*X$/.test(o)&&(n=(e[r+1]??"").toUpperCase())}(o==="-G"||o==="--get")&&(s=!0),(on.includes(o)||/^--(data[\w-]*|json|form[\w-]*|upload-file|post-data|post-file|body-data|body-file)(=|$)/.test(o)||/^-d./.test(o))&&(t=!0)}return n!==null&&n!==""?n!=="GET"&&n!=="HEAD":t&&!s}function Ed(e){if(e.stdin!==null)return e.stdin;let n=e.pipeFrom;return n===null?null:n.name==="echo"?n.argv.slice(1).filter((t,s,r)=>!(/^-[neE]+$/.test(t)&&r.slice(0,s).every(o=>/^-[neE]+$/.test(o)))).join(" "):n.name==="printf"?n.argv.slice(1).join(" ").replace(/\\n/g,`
|
|
64
|
+
`).replace(/\\t/g," "):n.name==="cat"?n.stdin:null}function Rd(e){if(e.stdin!==null||e.pipeFrom!==null)return null;for(let n=e;n.parent!==null&&(n.via==="remote"||n.via==="shell-string");n=n.parent){let t=Ed(n.parent);if(t!==null)return t}return null}var Xc=new WeakMap;function Qc(e,n){let t=e.lineCommands??[],s=Xc.get(t);if(!s){s=new Map;for(let r of t)r.parent!==null&&s.set(r.parent.argv,(s.get(r.parent.argv)??0)+1);Xc.set(t,s)}return s.get(n)??0}var xr=null;function eu(e){return(xr===null||xr.text!==e)&&(xr={text:e,at:Pt(e)}),xr.at}function Tw(e,n){let t=e.name,s=e.argv;if(Cw.has(t)||Ad.has(t)||e.functionCall)return[];let r=Rd(e),o=e.pipeFrom,a=`${s.join(" ")} ${e.stdin??""} ${r??""} ${o?o.argv.join(" "):""} ${o?.stdin??""}`.toLowerCase();if(!a.includes("drop")&&!a.includes("truncate")&&!a.includes("delete"))return[];if(Qc(n,s)>0)return[];if(s.some(y=>/^--?(dry[-_]?run|plan|preview|validate|explain|what-?if|check)(=(true|1|yes))?$/i.test($(y))))return[];let i=_(s),l=["heroku","fly","flyctl"].includes(t)||Hn.has(t)||Ld.has(t),c=i.slice(0,4).flatMap(y=>y.toLowerCase().split(/[-_:]/));if(l&&(c.some(y=>jw.test(y))||!c.some(y=>Ew.test(y))))return[];let u=l||Aw.has(t),p=t==="curl"||t==="wget";if(p&&!Lw(s))return[];let d=p&&s.some(y=>/^(?:[a-z]+:\/\/)?[^/?#\s]*\/(?:[^?#\s]*\/)?(sql|query|queries|statements?|pipeline|execute|_sql)(\/|\?|$)/i.test($(y))),f=[],h=[],g=[],b=oa[t]!==void 0?Ls(e):null,k=b!==null,E=(y,m=!1)=>{if(y){if(!k&&On(y)!==null)f.push(y);else if(!m&&Rw.test(y))h.push(y);else if(p)for(let R of Nw($(y),d))On(R)!==null&&f.push(R)}};if(k)E(b);else{for(let y=1;y<s.length;y++){let m=$(s[y]),R=/^(--?[\w-]+)=([\s\S]+)$/.exec(m),v=C=>t==="curl"&&on.includes(C);(Kc.test(m)||v(m))&&!/^--?[A-Za-z]/.test($(s[y+1]??"-x"))?E(s[++y]):R?(Kc.test(R[1])||v(R[1])||/^--(post|body)-data$/.test(R[1]))&&E(R[2]):!m.startsWith("-")&&(y===1||!/^-/.test($(s[y-1]))||s[y-1]==="--"||(t==="curl"||t==="wget")&&!Ir.has(s[y-1]))&&(g.push(s[y]),(/\s/.test(m)||(t==="curl"||t==="wget")&&m.includes("="))&&E(s[y],!0))}E(Ed(e)??(r!==null&&e.parent!==null&&Qc(n,e.parent.argv)===1?r:null))}if(f.length>0){let y=f.join(`;
|
|
65
|
+
`),R=[.../^(\s*\w+=("[^"]*"|'[^']*'|[^\s;&|]*))*/.exec(e.text)[0].matchAll(/(?:^|\s)(\w+)=("[^"]*"|'[^']*'|\S*)/g)].filter(V=>/(HOST|URL|URI|DSN|ADDR|SERVER|ENDPOINT)/i.test(V[1])||Yc.test(V[2].replace(/^["']/,""))).map(V=>V[2].replace(/^["']|["']$/g,"")),v=P(s,"--host","-host","--hostname","--server","-server","--server_address","--vtctld_server","--url","-url","--uri","--dsn","--connection","--connection-string","--conn","--database-url","--db-url","--endpoint","--addr","--address","-h")??(t==="curl"||t==="wget"?s.find((V,F)=>F>0&&!V.startsWith("-")&&!Ir.has(s[F-1])&&(Tn($(V))||S(V))):s.slice(1).find(V=>Yc.test($(V).replace(/^--?[\w-]+=/,""))))?.replace(/^--?[\w-]+=/,"")??R[0]??null,C=v===null?null:$(v),N=C!==null&&/^[^:[\]]+:\d+$/.test(C),q=C===null?u&&!I(s,"--local")?`${t}'s server`:null:/^[a-z][\w+.-]*:\/\//i.test(C)?Jc(C):S(v)?v:N?C.replace(/:\d+$/,""):C,B=q===null?s.slice(1).map(V=>$(V).replace(/^--?[\w-]+=/,"")).find(V=>Ow.test(V)):void 0;return B!==void 0?[w("claude.bash.db.destructive",`${t} runs destructive SQL (${On(y)}) on a database file on this machine (${O.basename(B)})`,{target:B,is_local:!0})]:Wt(e,q,!0,`${t} runs destructive SQL (${On(y)})`,eu(n.lineText),y)}for(let y of h){let m=Ww(y);if(m===null)continue;let R=/\b(?:postgres(?:ql)?|mysql|mariadb|clickhouse|mssql|sqlserver|cockroachdb|redshift|snowflake)(?:\+\w+)?:\/\/[^\s'"`]+/i.exec(y)?.[0],v=R!==void 0?Jc(R):/\bhost(?:name)?['"]?\s*[:=]\s*(['"`])([^'"`\s]+)\1/i.exec(y)?.[2]??null,C=/(?:process\.env\.|process\.env\[\s*['"]|environ(?:\.get)?\s*[([]\s*['"]|getenv\(\s*['"]|env\.get\(\s*['"])(\w*(?:HOST|URL|URI|DSN|CONN|SERVER)\w*)/i.exec(y)?.[1];if(!(v===null&&C===void 0&&(R===void 0&&/sqlite|duckdb|:memory:/i.test(y))))return Wt(e,v??(C!==void 0?`$${C}`:null),!0,`${t} runs destructive SQL (${m}) through a database driver`,eu(n.lineText),y)}return[]}function Dw(e){let n=he(e[0]??"");if(n!=="heroku"&&n!=="netlify"&&n!=="vercel")return null;let t=/^(local|dev):(run|exec)$/.test(e[1]??"")?2:e[1]==="env"&&e[2]==="run"?3:-1;if(t<0)return null;let s=e.slice(e[t]==="--"?t+1:t);return s.length>0&&!s[0].startsWith("-")?s:null}function Od(e){let n=new Set(["-c","--command","-f","--file","-h","--host","-p","--port","-U","--username","-d","--dbname","-v","--set","--variable","-o","--output","-L","--log-file","-P","--pset","-T","-F","-R"]),t=[];for(let s=1;s<e.length;s++){let r=e[s];n.has(r)?s++:r.startsWith("-")||t.push(r)}return t}function an(e){return e.startsWith("/")||qe(e)}function Wt(e,n,t,s,r=null,o=""){let a=Pd(e),i=(e.remote===null||e.remote.startsWith("container:"))&&a===null,l=t&&!e.productionEnv&&i&&r===null&&(n===null||an(n))&&!(n!==null&&S(n)),c=Nd(e,o),u=n?Fn(n):a??e.remote;if(c!==null)return[w("claude.bash.db.destructive",`${s}: ${c} is named for production`,{target:c,host:u,is_local:!1,catastrophic:!0})];if(l)return n!==null||e.remote!==null||Fw.has(e.name)||Mr.has(e)?[]:[w("claude.bash.db.destructive",`${s}, with no server shown`,{target:"no server shown",is_local:null,catastrophic:!1})];let p=r!==null&&(n===null||an(n))?`a database forwarded here (${r})`:n?Fn(n):e.productionEnv?"production (railway run)":a!==null?`${a} (${e.remote?.replace(/^container:/,"container ")??"a container"})`:e.remote??"a database the command does not name";return[w("claude.bash.db.destructive",`${s} on ${p}`,{target:p,host:u,is_local:!1,catastrophic:!0})]}function jd(e){return e.remote===null?null:e.remote.startsWith("container:")?Pd(e):e.remote==="kubernetes"?"a cluster's pod":e.remote}var tu=/^(reload|restart|stop|start|enable|disable|daemon-reload|mask|kill|try-restart|reload-or-restart|graceful|delete|down|up|rm|update)$/;function Iw(e){let n=jd(e);if(n===null)return[];let t=_(e.argv).map(i=>$(i)),s=O.basename(e.name),r=i=>[w("claude.bash.deploy",`${i} on ${n}`,{target:n,host:n,is_local:!1})];if(["rm","unlink","rmdir","shred","truncate"].includes(s)&&t.length>0)return r(`${s} deletes files`);if((s==="systemctl"||s==="service")&&t.some(i=>tu.test(i)))return r(`${s} ${t.find(i=>tu.test(i))} changes a service`);if(["docker","podman","docker-compose"].includes(s)){let i=t[0]==="compose"?1:0,l=t[i]==="exec"?void 0:t.slice(i,4).find(c=>/^(down|up|stop|rm|restart|kill|start|run|rmi|prune)$/.test(c));if(l)return r(`${s}${t[0]==="compose"?" compose":""} ${l} changes containers`)}let o=/^(\.{0,2}\/|~\/)|\.(sh|bash|py|rb)$/.test(e.argv[0]??"")||["bash","sh","zsh"].includes(s)&&/\.(sh|bash)$/.test(t[0]??""),a=t.find(i=>/^(remove|delete|destroy|uninstall|purge|drop|teardown|down)$/i.test(i));return o&&a?r(`runs ${O.basename($(e.argv[0]??s))} ${a}`):[]}var Mr=new WeakSet,Fw=new Set(["redis-cli","mongosh","mongo"]);function Pd(e){if(e.remote===null||!e.remote.startsWith("container:"))return null;for(let n=e.parent;n;n=n.parent)if(n.remote!==null&&!n.remote.startsWith("container:"))return n.remote;return null}function Kr(e){let n=e.split(/[^A-Za-z0-9]+|(?<=[a-z0-9])(?=[A-Z])/);return n.some((t,s)=>/^(prod|prd|production|live)\d*$/i.test(t)&&!/^(non|pre|not|no|un)$/i.test(n[s-1]??""))}function Mw(e){let n=[];for(let t=e;t;t=t.parent){let s=P(["",...t.wrapperArgs],"--config","--env","--environment","--stage","--profile");s!==null&&n.push(s)}return n}function Wd(e){return[.../^(\s*\w+=("[^"]*"|'[^']*'|[^\s;&|]*))*/.exec(e.text)[0].matchAll(/(?:^|\s)(\w+)=("[^"]*"|'[^']*'|\S*)/g)].filter(t=>!/pass|pwd|secret|token|key|auth/i.test(t[1])).flatMap(t=>[t[1],t[2]])}function Nd(e,n){let t=e.argv.map(r=>$(r));return[...Mw(e),...t.filter((r,o)=>o>0&&!/\s/.test(r)&&!/^-([UupPfoceqWaL]|-(user(name)?|pass(word)?|port|file|output|command|execute|eval|query|sql|log-file))$/.test(t[o-1])&&!/^(--?(user|pass|port|file|output)|-[UupP].)/.test(r)).map(r=>r.replace(/^--?[\w-]+=/,"")),...t.flatMap(r=>[...r.matchAll(/\b(?:dbname|host)=([^\s'"]+)/g)].map(o=>o[1])),...[...$(n).matchAll(/(?:\\c(?:onnect)?\s+|\b(?:drop\s+(?:database|schema|keyspace)\s+(?:if\s+exists\s+)?|use\s+|(?:table|from|into|update)\s+(?:if\s+exists\s+)?(?=[`"']?[\w$]+[`"']?\.)))[`"']?([\w$-]+)/gi)].map(r=>r[1]),...Wd(e)].map(r=>r.replace(/(:\/\/)[^@/\s]+@/,"$1").replace(/\?.*$/,"")).find(r=>r.length<=200&&Kr(r))?.slice(0,80)??null}var Ld=new Set(["firebase","xata","fauna","aws","gsutil","azd","upctl","yc","openstack","terraform","tofu","terragrunt","pulumi","cdk","cdktf","serverless","sls","ticloud","neon","neonctl","upstash","supabase","pscale","turso","atlas","mongocli","modal","bq","snow","snowsql","juju","rclone","s3cmd","mc","b2","argocd","velero","rancher","zeet","scaleway","civo"]),zw=/^(delete|deletion|destroy|remove|rm|rb|uninstall|terminate|purge|teardown|deprovision|decommission|drop|wipe|nuke|erase|tombstone|truncate|flushall|flushdb)$/,Uw=/^(env|envs|vars?|variables?|configs?|settings?|labels?|tags?|annotations?|alias(es)?|metadata|options?|domains?)$/,qw=/^(clusters?|serverless|instances?|buckets?|regions?|stores?|replicas?|shards?|partitions?|brokers?|namespaces?|volumes?|stacks?|deployments?|tombstone|vpcs?)$/,Hw=/\.aws\/credentials|\.azure\/|gcloud\/.*(credential|token)|application_default_credentials|service[-_]?account[^/]*\.json|-sa(-key)?\.json$|\.kube\/config|kubeconfig|\.oci\/|oci_api_key|doctl\/|credentials\.tfrc|\.s3cfg|\.boto$|\.vault-token/i,Bw=/^\/(var\/lib\/(mysql|postgresql|pgsql|mongodb|redis|cassandra|clickhouse|elasticsearch|influxdb|etcd|mariadb)|(usr\/local|opt\/homebrew)\/var\/(postgres|mysql|mongodb))/;function Vw(e){if(ms.test($(P(e.argv,"--context","--kube-context")??"")))return!1;let n=_(e.argv);if(e.name==="helm"||n[0]!=="delete"||I(e.argv,"-f","--filename","-k","--kustomize"))return!0;let t=n[1]??"";return!(t.includes("/")?n.slice(1).map(s=>s.split("/")[0]):t.split(",")).every(s=>/^(po|pods?|jobs?|events?|ev|rs|replicasets?|leases?)$/i.test(s))}function Gw(e,n){if(e.catastrophic!==void 0||e.housekeeping)return e;let t=e.action,s=n.name,r=n.argv.map(f=>$(f)),o=_(r).slice(0,6).flatMap(f=>f.toLowerCase().split(/[-_:]/)),a=f=>o.some(h=>f.test(h)),i=(a(zw)||r.includes("-destroy")||r.includes("--destroy"))&&!a(Uw),l=["kubectl","oc","helm"].includes(s),c=l||Ld.has(s)||Hn.has(s),u=t==="claude.bash.db.destructive",p=u||t==="claude.bash.deploy"?(l?i&&Vw(n):c?(i||u&&!/\bresets\b/.test(e.why))&&!I(n.argv,"--local"):i&&e.is_local===!1&&/read by its words/.test(e.why)&&a(qw)&&!r.some(f=>ms.test(f)))||u&&(n.productionEnv||Ns.test(Ws(n))||Wd(n).some(Kr))||s==="heroku"&&r[1]==="run"&&/\b(db:(drop|reset|purge|schema:load)|flush|migrate:(fresh|reset|refresh)|ecto\.(drop|reset)|dropdb)\b/.test(r.join(" ")):t==="claude.bash.fs.delete_recursive"?r.some(f=>Bw.test(f)):t==="claude.bash.secrets.print"&&(c||[e.target??"",...r,n.stdinFile??""].some(f=>Hw.test($(f)))),d=c&&t!=="claude.bash.fs.delete_recursive"&&a(/^(credentials?|keys?|passwords?|tokens?|rbac)$/)&&a(/^(reset|create|rotate|new|regenerate|renew|for)$/)&&fe(n);return p||d?{...e,catastrophic:!0}:e}var Td=/(^|\/)(\.env(\.(?![\w.-]*\b(example|sample|template|tpl|tmpl|dist|defaults|schema)\b)[\w.-]+)?|\.envrc|[^/]*\.pem|[^/]*\.key|[^/]*\.p12|[^/]*\.pfx|[^/]*\.keystore|[^/]*\.jks|id_(rsa|dsa|ecdsa|ed25519)|\.npmrc|\.pypirc|\.netrc|\.git-credentials|credentials(\.json)?|[^/]*[-_.]credentials\.json|[^/]*service[-_]account[^/]*\.json|(key|keystore)\.properties|[\w-]*deploy[-_]key(\.pem)?|[^/]*serviceaccountkey[^/]*\.json|[^/]*\.p8|[^/]*keypair[^/]*\.json|\.config\/solana\/id\.json|\.dockercfg|kubeconfig(-[\w.-]+)?(\.(ya?ml|json|conf))?|[\w-]+[-_]kubeconfig(\.(ya?ml|json))?|\.pgpass|\.my\.cnf|credentials\.tfrc\.json|rclone\.conf|\.s3cfg|\.vault-token|\.dev\.vars|[^/]*firebase-admin[^/]*\.json|secrets?\.(ya?ml|json|toml)|terraform\.tfvars|authorized_keys|\.anvil\/workspace-keys\.json)$/i,Zw=/(^|\/)\.(aws|kube|docker|ssh|gnupg|config\/gh)\/(credentials|config(\.json)?|hosts\.yml|id_[a-z0-9_]+|[^/]*\.pem)$/i,Kw=/(^|\/)\.ssh\/config$/;function Je(e){let n=$(e);return Re(n)&&!Kw.test(n)&&!/(^|\/)authorized_keys$/.test(n)&&!Dd(n)}function Dd(e){let n=O.basename($(e)).toLowerCase();return/\.(pem|crt|cer)$/.test(n)&&/(^|[-_.])(ca|cacert|cert|certs|certificate|certificates|chain|fullchain|bundle|root|intermediate|public|pub)([-_.]|$)/.test(n)&&!/key|priv|secret|p12|pfx|keystore|jks|id_/.test(n)}var Yw=/(^|\/)\.ssh\/(?!known_hosts|authorized_keys|config$|environment$|rc$)[^/]+(?<!\.pub)$/;function Re(e){let n=$(e);return Td.test(n)||Zw.test(n)||Yw.test(n)||Id.test(n)&&!/\/memory(\/|$)/.test(n)}var Id=/(^|\/)\.claude\/projects(\/[^/]+)?\/?$|(^|\/)\.claude\/projects\/[^/]+\/[^/]+\.jsonl$|(^|\/)\.claude\/projects\/[^/]+\/[^/]+\/subagents\/[^/]+\.jsonl$/,Dn=/(SECRET|TOKEN|PASSW(OR)?D|PASSPHRASE|API_?KEY|PRIVATE_?KEY|ACCESS_?KEY|CREDENTIAL|AUTH|DSN|DATABASE_UR[IL]|DB_URL|REDIS_UR[IL]|POSTGRES(QL)?_UR[IL]|PG_?URL|MONGO(DB)?_UR[IL]|AMQP_URL|RABBITMQ_URL|CONNECTION_STRING|WEBHOOK_URL|CLIENT_SECRET|SIGNING|_PAT$|^PAT_|COOKIE|SESSION_KEY)/i,Fd=/^(PWD|OLDPWD|PATH|HOME|USER|SHELL|TERM|LANG|TMPDIR|LOGNAME|EDITOR|PAGER|HOSTNAME)$/;function fe(e){if(e.captured||e.redirects.some(r=>(r.op===">"||r.op===">>"||r.op==="&>"||r.op===">|"||r.op==="1>")&&(r.fd===null||r.fd===1)&&r.target&&!["/dev/stdout","/dev/tty","/dev/stderr"].includes(r.target)))return!1;let n=!1,t=e.pipeTo,s=!1;for(let r=e.pipeTo;r;r=r.pipeTo)if(t=r,r.name==="tee"&&(s=!0),r.name==="tee"&&r.argv.slice(1).some(o=>/^\/dev\/(stderr|tty|fd\/[12])$/.test($(o))))return!0;if(t&&!s&&$d(t))return!1;for(let r=e.pipeTo;r;r=r.pipeTo)if(["grep","rg","egrep"].includes(r.name)&&Xw(r.argv.slice(1))&&(n=!0),Jw(r)&&n||zd(r)||r.redirects.some(o=>(o.op===">"||o.op===">>")&&(o.fd===null||o.fd===1)&&o.target&&o.target!=="/dev/stdout"))return!1;return e.parent?fe(e.parent):!0}function Jw(e){return e.name==="sed"&&/\[\^[^\]]*@[^\]]*\][*+]@/.test(e.argv.slice(1).join(" "))}function Xw(e){let n=e.find(s=>!s.startsWith("-"));if(!n)return!1;let t=n.replace(/[\^$()\\]/g,"").split("|").map(s=>s.trim().replace(/=$/,"")).filter(Boolean);return t.length>0&&t.every(s=>/^[A-Za-z0-9_]+$/.test(s)&&(/(URL|URI|DSN|POSTGRES|PG_?URL|REDIS|MONGO|DATABASE)/i.test(s)||/^[A-Za-z][A-Za-z0-9]*(_[A-Za-z0-9]+)+$/.test(s)&&!Dn.test(s)))}var Nt=e=>[e,{...e,action:"claude.file.read_secret"}];function Ve(e){let n=$(e);return Id.test(n)||/(^|\/)(\.npmrc|\.aws\/config)$/.test(n)?null:Os}function Yi(e){let n=e.indexOf("/.");return e.startsWith("/")&&!e.includes(J)&&(n<0||n===e.lastIndexOf("/"))&&!Td.test(e.slice(e.lastIndexOf("/")+1))?!1:Je(e)&&Ve(e)!==null}function oi(e){return typeof e=="object"&&e!==null&&e.output_mode==="content"}function Md(e){let n=typeof e=="object"&&e!==null?e.glob:null;if(typeof n!="string")return[];if(n.length>200)return null;let t=[];for(let s of n.split(/\s+/)){let r=0,o=0;for(let a=0;a<=s.length;a++){let i=s[a];i==="{"?r++:i==="}"?r=Math.max(0,r-1):(i===void 0||i===","&&r===0)&&(a>o&&t.push(s.slice(o,a)),o=a+1)}}return t}function Qw(e,n){let t=n?re(n):".";for(let s of Md(e)??[]){if(s.startsWith("!"))continue;let r=(s.split("/").pop()??"").replace(/[*?]|\{[^}]*\}|\[[^\]]*\]/g,"");if(r&&Je(r))return`${t}/${r}`;for(let o of It(s)){let a=o.split("/").pop()??"";if(!S(a)&&In(t,a,!1)==="only")return`${t}/${a}`}}return null}function ek(e,n,t,s){let r=e,o=r.pattern;if(typeof o!="string")return null;let a=Md(e),i=(a??[]).flatMap(v=>It(v)).map(v=>v.replace(/^(!?)(?:\*\*\/)+/,"$1")),l=i.filter(v=>!v.startsWith("!")),c=i.filter(v=>v.startsWith("!")).map(v=>v.slice(1)),u=typeof r.type=="string"?r.type:null,p=a===null?[]:l.length>0?l.map(v=>v.split("/").filter(Boolean).pop()??v):u?(Vd[u]??`*.${u}`).split(" "):[];if(p.length>0&&p.every(v=>In(".",v,!1)==="none"))return null;let d=c.filter(v=>!v.includes("/")),f=c.flatMap(v=>v.includes("/")?/^[^/]+\/$/.test(v)?[v.slice(0,-1)]:[]:[v]),h={h:!0,...a!==null&&l.length===0?{g:!0}:{},...p.length>0?{in:p}:{},...d.length>0?{ex:d}:{},...f.length>0?{xd:f}:{},...r.multiline===!0?{}:{t:{d:"R",p:[o],...r["-i"]===!0?{i:!0}:{}}}},g=re(s.home),b=t!==null?re(t):null,k=v=>b!==null&&v.startsWith(`${b}/`)?v.slice(b.length+1):v===g||v.startsWith(`${g}/`)?`~${v.slice(g.length)}`:v,E=(v,C,N=Os)=>({action:"claude.file.read_secret",service:N,target:v,branch:null,host:null,is_local:!0,why:C});if(n===null||S(n))return E(n??".","searches a folder Anvil can't place, secrets files included");let y=sn(n,{ctx:s},h);if("wide"in y)return E(y.wide,`searches every file in ${k(y.wide)}, secrets files included`);if(!("root"in y))return null;let m=je({ctx:s},{kind:"reach",cwd:y.root,arg:JSON.stringify(y.q)});if(m===""||m===Zt||m===void 0&&!s.wantProbes)return null;let R=typeof m=="string"&&m!==Gt?O.join(y.root,m):null;return R!==null?E(R,`reads a secrets file (${k(R)})`,Ve(R)):E(y.root,m===Gt?`reads more files than Anvil can check for secrets files in time (${k(y.root)})`:`reads files Anvil can't check for secrets files (${k(y.root)})`)}function tk(e,n){let t=Xe(e);if(!t)return null;let s=t.args.some(a=>a==="-p"||a==="-u"||a==="--patch"),r=t.args.some(a=>/^--(stat|shortstat|numstat|dirstat|name-only|name-status|summary|no-patch|raw)\b/.test(a)||a==="-s");if(!(t.sub==="blame"||t.sub==="annotate"?!0:t.sub==="cat-file"?t.args.some(a=>a==="-p"||a==="blob"):t.sub==="show"||t.sub==="diff"?s||!r:t.sub==="log"||t.sub==="whatchanged"?s:!1))return null;for(let a of t.args){if(a.startsWith("-"))continue;let i=/^(?:[^:/][^:]*|:\d)?:(?!\/)(.+)$/.exec(a)?.[1]??a;if(n(i))return i}return null}var nk=["grep egrep fgrep ggrep:efmABCdD:regexp file max-count after-context before-context context devices directories binary-files label include exclude exclude-dir exclude-from","rg:efmABCgtTEjMrd:regexp file max-count after-context before-context context glob iglob type type-not type-add encoding threads max-columns replace max-depth pre pre-glob sort sortr max-filesize ignore-file engine color colors path-separator context-separator","sed gsed:efl:expression file line-length","awk gawk mawk nawk:FfveEilW:field-separator assign file source include load exec","cut gcut:dfcb:delimiter fields characters bytes output-delimiter","head ghead:nc:lines bytes","tail gtail:ncbs:lines bytes sleep-interval pid","sort gsort:ktoTS:key field-separator output temporary-directory buffer-size parallel batch-size files0-from compress-program random-source","uniq guniq:fsw:skip-fields skip-chars check-chars","jq gojq jaq:fL:from-file indent *arg *argjson *slurpfile *rawfile","yq:oIpsf:output-format indent input-format expression from-file front-matter *arg *argjson","bat batcat:lHrm:language highlight-line line-range map-syntax style theme tabs wrap terminal-width pager color decorations paging file-name italic-text diff-context","less more:bhjkoOpPtTxyz#:","nl gnl:bdfhilnsvw:","tac gtac:s:separator","strings:nte:bytes radix encoding","xxd:cglson:","od god:AjNtS:address-radix skip-bytes read-bytes format strings","hexdump hd:efns:","base64 gbase64:bwio:wrap break input output","column:cso:","pr:hlwoN:","paste:d:delimiters","fold:w:width","fmt:wpgdlt:","expand unexpand:t:tabs","iconv:fto:from-code to-code output","cat gcat::","diff gdiff:CUIxXFLDWS:label exclude exclude-from ignore-matching-lines ifdef width starting-file show-function-line"],Yr=new Map;for(let e of nk){let[n,t,s]=e.split(":"),r=s.split(" ").filter(Boolean),o={short:t,long:new Set(r.map(a=>a.replace(/^\*/,""))),two:new Set(r.filter(a=>a.startsWith("*")).map(a=>a.slice(1)))};for(let a of n.split(" "))Yr.set(a,o)}var Bn=new Set(["grep","egrep","fgrep","ggrep","rg"]),xi=["-","/dev/stdin","/dev/fd/0"],nu=["-","/dev/stdout","/dev/tty","/dev/stderr","/dev/fd/1","/dev/fd/2"];function Vn(e){let n=Yr.get(e.name),t=new Map,s=(h,g="")=>{(t.get(h)??t.set(h,[]).get(h)).push(g)},r=[],o=e.argv;for(let h=1;h<o.length;h++){let g=o[h];if(g==="--"){r.push(...o.slice(h+1));break}if(g.startsWith("--")){let b=g.indexOf("="),k=g.slice(2,b<0?void 0:b);b>=0?s(k,g.slice(b+1)):n?.two.has(k)?s(k,`${o[++h]??""} ${o[++h]??""}`):s(k,n?.long.has(k)?o[++h]??"":"")}else if(g.length>1&&g.startsWith("-"))for(let b=1;b<g.length;b++){if(n?.short.includes(g[b])){s(g[b],b+1<g.length?g.slice(b+1):o[++h]??"");break}s(g[b])}else r.push(g)}let a=(...h)=>h.some(g=>t.has(g)),i=(...h)=>h.flatMap(g=>t.get(g)??[]),l=e.name,c=()=>r.splice(0,1),u=[];Bn.has(l)?u=a("f","file")?null:a("e","regexp")?i("e","regexp"):l==="rg"&&a("files","type-list")?[]:c():/^g?sed$/.test(l)?u=a("f","file")?null:a("e","expression")?i("e","expression"):c():/^[gmn]?awk$/.test(l)?(u=a("f","file","E","exec")?null:a("e","source")?i("e","source"):c(),r=r.filter(h=>!/^[A-Za-z_]\w*=/.test(h))):/^(go|ja)?jq$|^yq$/.test(l)&&(l==="yq"&&["eval","e","eval-all","ea"].includes(r[0]??"")&&r.shift(),u=l!=="yq"&&a("f")||a("from-file")?null:a("expression")?i("expression"):l==="yq"&&r.length===1&&Je(r[0])?[]:c(),a("args","jsonargs")&&(r=[])),/^g?base64$/.test(l)&&r.push(...i("i","input"));let p=/^g?sort$|^iconv$|^g?base64$/.test(l)?i("o","output"):[],d=/^g?uniq$/.test(l),f=p.some(h=>!nu.includes(h))||d&&r.length>1&&!nu.includes(r[1]);return{opts:t,files:d?r.slice(0,1):r,program:u,toFile:f}}function Jr(e){return[...Vn(e).files]}var sk=new Set(["wc","md5","md5sum","shasum","sha1sum","sha224sum","sha256sum","sha384sum","sha512sum","b2sum","cksum","sum"]),rk=/^(?:\.(?:[A-Za-z_]\w*(?:\.[A-Za-z_]\w*)*)?\s*\|\s*)?(?:keys(?:_unsorted)?(?:\[\])?|length|has\("[^"\\]*"\)|if\s+has\("[^"\\]*"\)\s+then\s+"[^"\\]*"\s+else\s+"[^"\\]*"\s+end)(?:\s*\|\s*length)?$/,ok=/^(?:BEGIN\s*\{\s*FS\s*=\s*"="\s*;?\s*\}\s*)?(?:!?\/(?:[^/\\\n]|\\.)*\/|NF|\$1)?\s*\{\s*print\s+\$1\s*;?\s*\}$/,ik=/^s([/|#,:@])=\.[*+]\$?\1[^\\&\n]*\1[gp]*$/;function zd(e){let n=e.name;if(sk.has(n))return!(n==="md5"&&e.argv.includes("-p"));if(["pbcopy","xclip","wl-copy","true"].includes(n))return!0;if(n==="diff"||n==="cmp")return e.argv.slice(1).some(o=>["-q","--brief","--quiet",...n==="cmp"?["-s","--silent"]:[]].includes(o));if(!Yr.has(n))return!1;let t=Vn(e),s=(...o)=>{let a=o.flatMap(i=>t.opts.get(i)??[]);return a.length===1?a[0]:null},r=t.program?.length===1?t.program[0].trim():null;return Bn.has(n)?ak(n,t):/^g?head$/.test(n)?s("c","bytes")==="0":/^g?cut$/.test(n)?s("d","delimiter")==="="&&s("f","fields")==="1"&&!["c","b","characters","bytes","complement"].some(o=>t.opts.has(o)):/^[gmn]?awk$/.test(n)?r!==null&&ok.test(r)&&(/^BEGIN/.test(r)||s("F","field-separator")==="="||(t.opts.get("v")??[]).includes("FS==")):/^g?sed$/.test(n)?r!==null&&ik.test(r):/^(go|ja)?jq$|^yq$/.test(n)&&r!==null&&rk.test(r)}function ak(e,n){let t=(...a)=>a.some(i=>n.opts.has(i)),s=e==="rg";if(t("c","count","count-matches","l","files-with-matches","files-without-match","q","quiet")||(s?t("files"):t("L","silent")))return!0;let r=n.program;if(r===null||r.length===0||t("v","invert-match","A","B","C","after-context","before-context","context",...s?["r","replace"]:["z","null-data"])||[...n.opts.keys()].some(a=>/^\d$/.test(a)))return!1;let o=Ud(e,n);return t("o","only-matching")?r.every(a=>lk(a)||qd(a,o)!==null):r.every(uk)}function Ud(e,n){let t=(...s)=>s.some(r=>n.opts.has(r));return t("F","fixed-strings")||e==="fgrep"?"F":t("P","perl-regexp","pcre2")?"P":e==="rg"?"R":t("E","extended-regexp")||e==="egrep"?"E":"B"}function lk(e){if(!e.startsWith("^"))return!1;let n=e.slice(1).replace(/^\(export(?: |\\s|\[ \])[+*]?\)\??|^export /,"");if(/^\[\^=\](?:[*+]|\\\+)=?$/.test(n))return!0;let t=n.replace(/\\?=$/,""),s=/^(\\?)\((.*)\1\)$/.exec(t),r=s?s[2].split(s[1]?"\\|":"|"):[t];return r.length<=32&&r.every(ck)}function ck(e){let n=e;for(let t=0;;t++){if(n==="")return t>0;let s=/^(?:\[(?:[A-Z]-[A-Z]|[a-z]-[a-z]|[0-9]-[0-9]|\[:(?:upper|lower|alpha|alnum|digit):\]|[A-Za-z0-9_])+\]|\\w|[A-Za-z0-9_]+)(?:[*+?]|\\[+?]|\\?\{\d*,?\d*\\?\})?/.exec(n);if(!s||t>=8)return!1;n=n.slice(s[0].length)}}function uk(e){let n=e.replace(/[\^$()\\]/g,"").split("|").map(t=>t.trim().replace(/=$/,"")).filter(Boolean);return n.length>0&&n.every(t=>/^[A-Za-z][A-Za-z0-9]*(_[A-Za-z0-9]+)+$/.test(t)&&!Dn.test(t)&&!dk.test(t))}var dk=/(^|_)(KEYS?|PASS|PWD|PW|PIN|SALT|SEED|MNEMONIC|SIG|SIGNATURE|SK|CERT|PEM|CREDS?)(_|$)|KEY$/i;function qd(e,n){if(n==="F")return e.split(`
|
|
66
|
+
`).every(Boolean)?e.split(`
|
|
67
|
+
`):null;let t=[],s="";for(let r=0;r<=e.length;r++){let o=e[r];if(o===void 0||(n==="B"?o==="\\"&&e[r+1]==="|":o==="|")){if(s==="")return null;t.push(s),s="",o==="\\"&&r++}else if(o==="\\"){let a=e[++r];if(a===void 0||!/[.[\]*^$\\/{}()+?|-]/.test(a)||n==="B"&&/[(){}+?]/.test(a))return null;s+=a}else{if((n==="B"?".[*^$":".[*^$(){}+?").includes(o))return null;s+=o}}return t}function fk(e,n,t){if(e.length>200)return null;let s="",r=0,o=!1;for(let a=0;a<e.length;a++){let i=e[a],l=i==="\\";if(l&&(i=e[++a]??""),i==="")return null;let c=n==="B"?l?"(){}|+?".includes(i):".[*^$".includes(i):!l&&".[*^$(){}|+?".includes(i);if(c&&n==="B"&&i==="^"&&!(s===""||s.endsWith("(?:")||s.endsWith("|"))&&(c=!1),c&&n==="B"&&i==="$"&&!(a===e.length-1||/^\\[)|]/.test(e.slice(a+1,a+3)))&&(c=!1),c)if(i==="["){let u=a+1;for(e[u]==="^"&&u++,e[u]==="]"&&u++;u<e.length&&e[u]!=="]";)u++;let p=e.slice(a+1,u);if(u>=e.length||p.includes("[")||p.includes("\\")&&(n==="B"||n==="E"))return null;s+=`[${p.replace(/^(\^?)\]/,"$1\\]")}]`,a=u,o=!0}else if(i==="*"||i==="+"||i==="?"){if(!o){if(n!=="B"||i!=="*")return null;s+="\\*",o=!0;continue}if(s.endsWith(")"))return null;s+=i,o=!1}else if(i==="(")r++,s+="(?:",o=!1;else if(i===")"){if(r--===0)return null;s+=")",o=!0}else if(i==="|"||i==="^"||i==="$"||i===".")s+=i,o=i===".";else return null;else{if(l&&/[wWsSbB]/.test(i))s+=`\\${i}`;else if(l&&n!=="B"&&n!=="E"&&/[dD]/.test(i))s+=`\\${i}`;else{if(l&&!/[.[\]*^$\\/{}()+?|-]/.test(i))return null;s+=i.replace(/[\\^$.*+?()[\]{}|/-]/g,"\\$&")}o=!(l&&/[bB]/.test(i))}}if(r!==0)return null;try{return new RegExp(s,t?"mi":"m")}catch{return null}}function Hd(e,n){if(e.v)return!0;let t=e.p.map(s=>qd(s,e.d));if(t.every(s=>s!==null)){let s=e.i?n.toLowerCase():n;return t.flat().some(r=>s.includes(e.i?r.toLowerCase():r))}return e.d==="F"||n.length>64*1024?!0:e.p.some(s=>fk(s,e.d,e.i===!0)?.test(n)??!0)}function pk(e,n){if(!Bn.has(e)||n.program===null)return;let t=(...r)=>r.some(o=>n.opts.has(o)),s=t("i","ignore-case","y")||e==="rg"&&t("S","smart-case");return{d:Ud(e,n),p:[...n.program],...s?{i:!0}:{},...t("v","invert-match")?{v:!0}:{}}}var hk=[".env",".env.local",".env.production",".envrc",".dev.vars","credentials","credentials.json","app-credentials.json","service-account.json","serviceAccountKey.json","firebase-admin.json","keypair.json","secrets.yaml","secret.yml","secrets.json","secrets.toml","terraform.tfvars","id_rsa","id_ed25519","server.key","private.pem","key.p12","cert.pfx","release.keystore","release.jks","AuthKey.p8",".netrc",".pypirc",".pgpass",".git-credentials","kubeconfig",".dockercfg","rclone.conf",".s3cfg",".vault-token","key.properties","deploy_key",".my.cnf"],gk=["README.md","index.ts","app.js","main.py","package.json","config.yaml","settings.toml","notes.txt","data.csv","Makefile","main","a",".gitignore",".prettierrc",".editorconfig"];function In(e,n,t){let s=o=>(!t||!o.startsWith(".")||n.startsWith("."))&&eo(n,o);return hk.some(o=>s(o)&&Je(`${e}/${o}`))?gk.some(o=>s(o)&&!Je(`${e}/${o}`))?"some":["","x"].map(o=>n.replace(/\*+|\?|\[[^\]]*\]/g,o)).filter(o=>o&&s(o)).some(o=>Je(`${e}/${o}`))?"only":"some":"none"}function mk(e,n,t){let s=e.name,r=pk(s,n),o=Bn.has(s)&&(s==="rg"||["r","R","recursive","dereference-recursive"].some(d=>n.opts.has(d))||[...n.opts.get("d")??[],...n.opts.get("directories")??[]].includes("recurse")),a=[],i=n.files.filter(d=>!xi.includes(d));if(o){let d=Bd(s,n,r),f=s==="rg"&&(e.pipeFrom!==null||e.stdinFile!==null||e.stdinKind!==null);if(d!==null)for(let h of i.length>0?i:f?[]:["."])a.push(...Cs(h,e,t,d))}else for(let d of i)a.push(...Cs(d,e,t,null,r));let l=e.parent&&e.via==="find-exec"&&e.parent.name==="find"?e.parent:e.parent&&e.via==="xargs"?Gd(e.parent.pipeFrom):null;l&&a.push(...Kd(l,t,r)??[]);let c=[],u=t.ctx.home,p=d=>e.cwd&&!S(e.cwd)&&d.startsWith(`${re(e.cwd)}/`)?d.slice(re(e.cwd).length+1):d===u||d.startsWith(`${u}/`)?`~${d.slice(u.length)}`:d;for(let d of a.slice(0,8))if("path"in d)c.push(...Nt(w("claude.bash.secrets.print",`prints a secrets file (${p(d.path)})`,{target:d.path,is_local:!0,service:Ve(d.path)})));else if("wide"in d)c.push(w("claude.bash.secrets.print",S(d.wide)?`searches a folder Anvil can't place, secrets files included (${$(d.wide)})`:`searches every file in ${p(d.wide)}, secrets files included`,{target:$(d.wide),is_local:!0,service:Os}));else{let f=je(t,{kind:"reach",cwd:d.root,arg:JSON.stringify(d.q)});if(f===""||f===void 0&&!t.ctx.wantProbes||f===Zt&&yk(e,t))continue;let h=typeof f=="string"&&f!==Gt&&f!==Zt?O.join(d.root,f):null,g=h!==null?`prints a secrets file (${p(h)})`:f===Gt?`reads more files than Anvil can check for secrets files in time (${p(d.root)})`:f===Zt?`reads a folder that isn't there yet, which Anvil can't check for secrets files (${p(d.root)})`:`reads files Anvil can't check for secrets files (${p(d.root)})`,b=w("claude.bash.secrets.print",g,{target:h??d.root,is_local:!0,service:h!==null?Ve(h):Os});c.push(...h!==null?Nt(b):[b])}return c}function yk(e,n){let t=n.lineCommands??[],s=t.indexOf(e);if(s<0||e.cwdFallbacks.length>0&&(e.cwd===null||S(e.cwd)||je(n,{kind:"reach",cwd:re(e.cwd),arg:bk})!==""))return!1;let r=new Set;for(let o=e;o;o=o.parent)for(let a=o;a;a=a.pipeFrom)r.add(a);return t.slice(0,s).every(o=>r.has(o)||vk(o))}var bk=JSON.stringify({d:0,in:[]}),wk=new Set(["cd","pushd","popd","pwd","ls","tree","cat","head","tail","grep","egrep","fgrep","rg","wc","sort","uniq","cut","tr","sed","gsed","awk","gawk","echo","printf","test","[","true","false","find","xargs","mkdir","touch","stat","file","du","df","which","type","command","jq","date","sleep","basename","dirname","realpath","readlink","diff","cmp","comm","nl","column","env","printenv","whoami","uname","id","hostname","md5","md5sum","shasum","sha256sum","cksum","git"]),kk=new Set(["status","log","diff","show","ls-files","ls-tree","rev-parse","rev-list","grep","blame","branch","describe","shortlog","remote","fetch","cat-file","merge-base","tag","reflog","for-each-ref","show-ref","check-ignore","config","whatchanged","name-rev","count-objects","version"]);function vk(e){if(!wk.has(e.name)||e.redirects.some(t=>[">",">>",">|","&>","&>>"].includes(t.op)&&t.target!==null&&!t.target.startsWith("/dev/")))return!1;let n=e.argv.slice(1);if(e.name==="find")return!n.some(t=>/^-(exec|execdir|ok|okdir|delete|fprint0?|fprintf|fls)$/.test(t));if(e.name==="git"){let t=Xe(e);return t!==null&&kk.has(t.sub)&&!t.args.some(s=>s.startsWith("--output"))}if(/^g?sed$|^g?awk$/.test(e.name)){let t=Vn(e);return t.program!==null&&!["i","I","in-place"].some(s=>t.opts.has(s))&&!t.program.some(s=>(e.name.endsWith("sed")?/(^|[^A-Za-z])[wW]/:/[>|]|system|getline/).test(s))}return e.name==="sort"?!n.some(t=>/^-[A-Za-z]*o|^--output/.test(t)):e.name==="uniq"?n.filter(t=>!t.startsWith("-")).length<=1:!0}function Bd(e,n,t){let s=(...h)=>h.flatMap(g=>n.opts.get(g)??[]),r=e==="rg",o=s("u","unrestricted").length,a=r?s("g","glob","iglob"):[],i=a.filter(h=>!h.startsWith("!")),l=r?[...i.map(h=>h.split("/").filter(Boolean).pop()??h),...s("t","type").flatMap(h=>(Vd[h]??`*.${h}`).split(" "))]:s("include"),c=a.filter(h=>h.startsWith("!")).map(h=>h.slice(1)),u=r?c.filter(h=>!h.includes("/")):s("exclude"),p=r?c.flatMap(h=>h.includes("/")?/^[^/]+\/$/.test(h)?[h.slice(0,-1)]:[]:[h]):s("exclude-dir");if(l.length>0&&l.every(h=>In(".",h,!1)==="none"))return null;let d=r?Number(s("d","max-depth","maxdepth").at(-1)??NaN):NaN,f=i.length>0;return{...Number.isInteger(d)&&d>0?{d:d-1}:{},...!r||f||o>=2||n.opts.has("hidden")||n.opts.has(".")?{h:!0}:{},...r&&!f&&o===0&&!["no-ignore","no-ignore-vcs"].some(h=>n.opts.has(h))?{g:!0}:{},...(r?["L","follow"]:["R","dereference-recursive"]).some(h=>n.opts.has(h))?{l:!0}:{},...l.length>0?{in:l}:{},...u.length>0?{ex:u}:{},...p.length>0?{xd:p}:{},...t?{t}:{}}}var Vd={json:"*.json",yaml:"*.yaml *.yml",toml:"*.toml",config:"*.cfg *.conf *.config *.ini",tf:"*.tf *.tf.json *.auto.tfvars *.auto.tfvars.json terraform.tfvars terraform.tfvars.json",env:".env .env.* *.env"};function Cs(e,n,t,s,r,o=!1){if(S(e)){let i=Yd($(e));return i.length===0?s?[{wide:e}]:[]:i.flatMap(l=>{let c=cn(l,n.cwd,t).commands.filter(u=>u.via==="top"&&u.pipeTo===null).at(-1);return(c&&Kd(Gd(c),t,s?.t??r))??[]})}let a=[];for(let i of It(e)){if(S(i))continue;let l=M(i,n.cwd,t.ctx);if(S(l)||!l.startsWith("/")){s&&a.push({wide:l});continue}let c=l.split("/"),u=c.findIndex(b=>/[*?[]/.test(b));if(u<0){Je(l)?(o||i!==e||s)&&a.push({path:l}):s&&a.push(sn(l,t,s));continue}let p=c.slice(0,u).join("/")||"/",d=c.slice(u),f=d.at(-1),h=In(d.length>1?`${p}/x`:p,f,!0),g=f.startsWith(".")?{h:!0}:{};h==="only"?a.push({path:l}):h==="some"&&a.push(sn(p,t,s?{...s,...g}:{d:d.length-1,in:[f],...g,...r?{t:r}:{}}))}return a}function sn(e,n,t){let s=re(n.ctx.home),r=re(e);return r==="/"||r===s||s.startsWith(`${r}/`)||r.startsWith(`${s}/Library/`)||r===`${s}/Library`?{wide:r}:{root:r,q:t}}function Gd(e){let n=e;for(;n&&["head","tail","sort","uniq","tac","shuf","tr","cut","sed","awk","grep","egrep","rg"].includes(n.name)&&!(Bn.has(n.name)&&Zd(n))&&n.pipeFrom;)n=n.pipeFrom;return n}function Zd(e){let n=Vn(e);return["l","files-with-matches","L","files-without-match","files"].some(t=>n.opts.has(t))}function Kd(e,n,t){if(!e)return null;let s=e.argv,r=e.cwd;if(e.name==="find"){let o=1,a=!1;for(;/^-[HLP]$/.test(s[o]??"");o++)a=s[o]==="-L";let i=s.findIndex((k,E)=>E>=o&&/^[-(!]/.test(k)),l=s.slice(o,i<0?void 0:i),c=i<0?[]:s.slice(i),u=[],p=[],d=c.some((k,E)=>(k==="!"||k==="-not")&&c[E+1]==="("),f=[[]];for(let k of c)["-o","-or",","].includes(k)?f.push([]):f.at(-1).push(k);for(let k of f){let E=!1;for(let y=0;y<k.length;y++){if(!["-name","-iname"].includes(k[y]))continue;let m=k[y+1]??"";k[y-1]==="!"||k[y-1]==="-not"?f.length===1&&!S(m)&&p.push(m):S(m)?d=!0:(u.push(m),E=!0)}E||(d=!0)}let h=NaN;for(let k=0;k<c.length;k++)c[k]==="-maxdepth"&&(h=Number(c[k+1]));let g=u.find(k=>In(".",k,!1)==="only");if(g!==void 0)return[{path:O.join(M(l[0]??".",r,n.ctx),g)}];if(!d&&u.every(k=>In(".",k,!1)==="none"))return[];let b={h:!0,...a?{l:!0}:{},...d?{}:{in:u},...p.length>0?{ex:p}:{},...Number.isInteger(h)&&h>0?{d:h-1}:{},...t?{t}:{}};return(l.length>0?l:["."]).map(k=>S(k)?{wide:k}:sn(M(k,r,n.ctx),n,b))}if(e.name==="ls"){let o=s.slice(1).filter(c=>!c.startsWith("-")),a=s.some(c=>/^-[A-Za-z]*[aA]/.test(c)),i=s.some(c=>/^-[A-Za-z]*R/.test(c)),l={...i?{}:{d:0},...a?{h:!0}:{},...t?{t}:{}};return o.length===0?[sn(M(".",r,n.ctx),n,l)]:o.flatMap(c=>Cs(c,e,n,i||!/[*?[]/.test(c)?l:null,t,!0))}if(e.name==="echo"||e.name==="printf")return s.slice(e.name==="printf"?2:1).filter(o=>!o.startsWith("-")).flatMap(o=>Cs(o,e,n,null,t,!0));if(Bn.has(e.name)&&Zd(e)){let o=Vn(e),a=Bd(e.name,o,t);return a===null?[]:(o.files.length>0?o.files:["."]).flatMap(i=>Cs(i,e,n,a))}if(e.name==="fd"||e.name==="fdfind"){let o=s.slice(1).filter((l,c)=>!l.startsWith("-")&&!/^-(e|g|t|E|d|x|X|-extension|-type|-exclude|-max-depth)$/.test(s[c]??"")),a=s.flatMap((l,c)=>["-e","--extension"].includes(s[c-1]??"")?[`*.${l}`]:[]),i={...s.some(l=>/^-[A-Za-z]*H|^--hidden$|^-[A-Za-z]*u/.test(l))?{h:!0}:{},...s.some(l=>/^-[A-Za-z]*[Iu]|^--no-ignore/.test(l))?{}:{g:!0},...a.length>0?{in:a}:{},...t?{t}:{}};return(o.length>1?o.slice(1):["."]).map(l=>sn(M(l,r,n.ctx),n,i))}return e.name==="git"&&Xe(e)?.sub==="ls-files"?[sn(M(".",r,n.ctx),n,{h:!0,...t?{t}:{}})]:null}var $k=new Set(["type","get-content","gc"]),zr=new Set(["cat","head","tail","less","more","bat","nl","tac","strings","grep","rg","egrep","sed","awk","cut","sort","uniq","xxd","od","base64","jq","yq","column","pr","paste","fold","rev","fmt","expand","unexpand","iconv","tr","tee","diff","hexdump","hd","comm",...Yr.keys()]);function xk(e,n){let t=n.secretCopies,s=e.argv,r=e.name,o=s.slice(1);if(r==="printenv"||(r==="env"||r==="set"||r==="export"||r==="declare")&&o.every(d=>d.startsWith("-")&&d!=="-c"))return r==="printenv"&&o.filter(d=>!d.startsWith("-")).length>0&&!o.some(d=>!d.startsWith("-")&&Dn.test(d))?[]:(r==="export"||r==="declare")&&!o.some(d=>d==="-p"||d==="-x"||o.length===0)?[]:r==="set"&&o.length>0?[]:!fe(e)||Ek(e)==="no-secret"?[]:[w("claude.bash.secrets.print",`${r} prints the environment, secrets included`,{target:r,is_local:!0})];let a=d=>Je(d)||t.has(te(d,e.cwd,le(n)).path),l=(r==="xargs"?s.find((d,f)=>s[f-1]==="-a"||s[f-1]==="--arg-file")??s.find(d=>d.startsWith("--arg-file="))?.slice(11)??s.find(d=>/^-a./.test(d))?.slice(2):void 0)??e.stdinFile;if((r==="exec"||r==="xargs")&&l&&a(l))return Nt(w("claude.bash.secrets.print",`${r==="exec"?"feeds a secrets file to the commands after it":"passes a secrets file to a command"} (${O.basename($(l))})`,{target:$(l),is_local:!0,service:Ve($(l))}));if(r==="git"&&s.includes("--no-index")&&s.slice(1).some(d=>!d.startsWith("-")&&a(d))&&fe(e)){let d=s.slice(1).find(f=>!f.startsWith("-")&&a(f));return Nt(w("claude.bash.secrets.print",`prints a secrets file (${O.basename($(d))})`,{target:$(d),is_local:!0,service:Ve($(d))}))}let c=r==="git"?tk(e,a):null;if(c&&fe(e))return Nt(w("claude.bash.secrets.print",`prints a secrets file (${O.basename($(c))})`,{target:$(c),is_local:!0,service:Ve($(c))}));let u=r==="dd"?s.find(d=>d.startsWith("if="))?.slice(3):void 0,p=s.find(d=>d.startsWith("of="))?.slice(3);if(u&&a(u)&&(p===void 0?fe(e):["/dev/stdout","/dev/stderr","/dev/tty","/dev/fd/1","/dev/fd/2"].includes(p)))return Nt(w("claude.bash.secrets.print",`prints a secrets file (${O.basename($(u))})`,{target:$(u),is_local:!0,service:Ve($(u))}));if(zr.has(r)||Z()&&$k.has(r.toLowerCase())){let d=Vn(e),f=r==="tr"||r==="tee"?[]:d.files,h=f.filter(N=>!xi.includes(N)),g=r==="tr"||r==="tee"||f.some(N=>xi.includes(N))||f.length===0,b=e.stdinFile!==null&&g?[...h,e.stdinFile]:h,k=["sed","gsed"].includes(r)&&e.argv.slice(1).some(N=>/^(-i\S*|--in-place(=.*)?|-[A-Za-z]*i)$/.test($(N)))||/^g?awk$/.test(r)&&/(^| )(-i ?|--include[= ])inplace\b/.test(e.argv.map($).join(" ")),E=b.filter(N=>(k?Re(N):Je(N))||t.has(te(N,e.cwd,le(n)).path)),y=r==="tee"&&d.files.some(N=>["/dev/stderr","/dev/tty","/dev/fd/2","/dev/stdout"].includes(N)),m=N=>te(N,e.cwd,le(n)).path||$(N);if(E.length&&k)return E.slice(0,8).map(N=>w("claude.file.write_secret",`edits a secrets file in place (${O.basename($(N))})`,{target:m(N),is_local:!0}));let R=(fe(e)||y)&&!d.toFile&&!zd({...e,pipeTo:null});if(E.length&&R)return E.slice(0,8).flatMap(N=>Nt(w("claude.bash.secrets.print",`prints a secrets file (${O.basename($(N))})`,{target:m(N),is_local:!0,service:Ve(m(N))})));let v=R&&!k?mk(e,d,n):[];if(v.length>0)return v;let C=e.stdinExpands&&fe(e)?su(e.stdin??"",e,n):null;return C?Nt(w("claude.bash.secrets.print",`prints a secret through $(\u2026) (${O.basename(C)})`,{target:C,is_local:!0,service:Ve(C)})):[]}if(r==="security"&&/^find-(generic|internet)-password$/.test(o[0]??"")&&o.some(d=>d==="-w"||d==="-g"||/^-[a-z]*[wg]$/.test(d)))return fe(e)?[w("claude.bash.secrets.print","prints a keychain password",{target:"keychain",is_local:!0})]:[];if(r==="kubectl"&&["get","describe"].includes(_(s)[0]??"")&&/^secrets?$/.test(_(s)[1]??"")&&s.some((d,f)=>/^-o(yaml|json|jsonpath|go-template)|^--output/.test(d)||["yaml","json"].includes(d)||/^(jsonpath|go-template|custom-columns)=/.test(d)||s[f-1]==="-o"&&/^(yaml|json|jsonpath|go-template)/.test(d)))return fe(e)?[w("claude.bash.secrets.print","kubectl prints a secret",{target:"kubectl secret",is_local:!1})]:[];if(r==="op"&&(o[0]==="read"||o[0]==="item"&&o.includes("--reveal"))||r==="vault"&&(o[0]==="read"||o[0]==="kv"&&o[1]==="get")||r==="doppler"&&o[0]==="secrets"&&(o.length===1||["get","download"].includes(o[1]??"")||(o[1]??"").startsWith("-"))||r==="infisical"&&(o[0]==="secrets"&&(o.length===1||o[1]==="get"||o[1].startsWith("-"))||o[0]==="export"&&!s.some(d=>d.startsWith("--output-file")))||r==="az"&&_(s)[0]==="keyvault"&&_(s)[1]==="secret"&&_(s)[2]==="show"||r==="dotenv"&&["list","get"].includes(ke(s,1,new Set(["-f","--file","-e","-c","-v","-p"]))[0]??""))return fe(e)?[w("claude.bash.secrets.print",`${r} prints a secret`,{target:r,is_local:!0})]:[];if((r==="echo"||r==="printf"||r==="print"||e.stdinKind==="here-string"&&zr.has(r))&&fe(e)){let d=[...s.slice(1),e.stdinKind==="here-string"?e.stdin??"":""].map(f=>su(f,e,n)).find(f=>f!==null);if(d)return[w("claude.bash.secrets.print",`prints a secret through $(\u2026) (${O.basename(d)})`,{target:d,is_local:!0,service:Ve(d)})]}if(r==="echo"||r==="printf"||r==="print"){let d=Jd(e.text);for(let f of d.matchAll(/\$(?:\{(#?)([A-Za-z_][A-Za-z0-9_]*)([^}]*)\}|([A-Za-z_][A-Za-z0-9_]*))/g)){let h=f[2]??f[4],g=f[3]??"";if(!(f[1]==="#"||/^:?\+/.test(g)||/^:\s*0?\s*:\s*[1-8]$/.test(g))&&Dn.test(h.replace(/AUTHOR(?!IZ)/gi,""))&&!Fd.test(h)&&fe(e))return[w("claude.bash.secrets.print",`echoes a secret variable (${h})`,{target:h,is_local:!0})]}}return[]}function Yd(e){let n=[];for(let t=0;t<e.length;t++)if(e[t]==="`"){let s=e.indexOf("`",t+1);if(s<0)break;n.push(e.slice(t+1,s)),t=s}else if(e[t]==="$"&&e[t+1]==="("){let s=0,r=t+1;for(;r<e.length;r++)if(e[r]==="(")s++;else if(e[r]===")"&&--s===0)break;n.push(e.slice(t+2,r)),t=r}return n}function su(e,n,t){if(!e.includes("$(")&&!e.includes("`"))return null;for(let s of Yd(e)){let r=s.trim(),o=/^<\s*["']?([^"'\s]+)["']?$/.exec(r);if(o){if(Re(o[1]))return o[1];continue}for(let a of cn(r,n.cwd,t).commands){let i=Ps(a,t).find(l=>l.action==="claude.bash.secrets.print"&&!l.why.startsWith("echoes a secret variable"));if(i)return i.target??a.name}}return null}var _k=/(^|\/)(public|static|www|htdocs|wwwroot|public_html)(\/|$)/;function Sk(e,n){let t=e.argv.slice(1).filter(r=>!r.startsWith("-")),s=(["cp","install","rsync","ditto"].includes(e.name)?t.slice(0,-1):e.name==="cat"&&e.redirects.some(r=>(r.op===">"||r.op===">>")&&r.target&&!r.target.startsWith("/dev/"))?t:[]).filter(r=>Je(r)).slice(0,8).map(r=>({...w("claude.file.read_secret",`copies a secrets file (${O.basename($(r))})`,{target:te(r,e.cwd,le(n)).path||$(r),is_local:!0}),copy:!0}));if(["cp","mv","install","rsync","ditto"].includes(e.name)){let r=t.at(-1),o=t.slice(0,-1).find(a=>Re(a));if(r!==void 0&&o!==void 0&&!S(r)&&_k.test(M(r,e.cwd,n.ctx))&&rt(r,e,n).kind!=="disposable")return[w("claude.bash.secrets.expose",`copies a secrets file (${O.basename($(o))}) into a folder a web server serves (${$(r)})`,{target:$(r),is_local:!0}),...s]}if(["echo","printf","print"].includes(e.name)){let r=e.redirects.find(o=>[">",">>",">|","1>","&>"].includes(o.op)&&(o.fd===null||o.fd===1)&&o.target)?.target;if(r&&!r.startsWith("/dev/")&&!S(r)&&!Re(r)&&!$t.test(r)){let o=[...Jd(e.text).matchAll(/\$(?:\{([A-Za-z_][A-Za-z0-9_]*)\}|([A-Za-z_][A-Za-z0-9_]*))/g)].map(a=>a[1]??a[2]).find(a=>Dn.test(a)&&!Fd.test(a));if(o!==void 0&&rt(r,e,n).kind!=="disposable")return[w("claude.bash.secrets.expose",`writes the value of ${o} into ${O.basename($(r))}`,{target:$(r),is_local:!0})]}}return s}var Ck=/\.(pem|key|crt|cer|der|p12|pfx|jks|keystore|p8)$/i;function Ak(e,n){let t=n.replace(/(?<!\/)\/+$/,""),s=e.startsWith(`${t}/`)?e.slice(t.length+1):null;return s!==null?/^\.(ssh|aws|kube|gnupg|docker|azure|oci|helm|minikube|config\/(gcloud|gh|helm|doctl))(\/|$)/.test(s):/^\/(etc|usr|System|Library|private\/etc|opt\/homebrew\/etc|var\/lib)(\/|$)/.test(e)||!e.startsWith("/")}function Jd(e){let n="",t=!1;for(let s=0;s<e.length;s++){let r=e[s];if(r==="\\"&&!t)n+=e.slice(s,s+2),s++;else if(r==='"')t=!t,n+=r;else if(r==="'"&&!t){let o=e.indexOf("'",s+1),a=o===-1?e.length:o;n+=" ".repeat(a-s+1),s=a}else n+=r}return n}function Ek(e){let n=e.pipeTo;if(!n||!["grep","rg","egrep"].includes(n.name))return"none";let t=n.argv.slice(1).find(s=>!s.startsWith("-"))??"";return Dn.test(t)||t===""?"secret":"no-secret"}function ru(e,n){let t=[];for(let u of e.redirects)[">",">>","&>",">|","1>"].includes(u.op)&&u.target&&t.push(u.target);e.name==="tee"&&t.push(...e.argv.slice(1).filter(u=>!u.startsWith("-")));let s=e.argv.slice(1).flatMap(u=>u==="--no-clobber"||/^--update=none(-fail)?$/.test(u)?["n"]:u==="--force"?["f"]:u==="--interactive"?["i"]:/^-[A-Za-z]+$/.test(u)?[...u.slice(1)].filter(p=>"nfi".includes(p)):[]).pop(),r=(e.name==="cp"||e.name==="mv")&&s==="n";(e.name==="cp"||e.name==="mv"||e.name==="install")&&e.argv.length>=3&&!r&&t.push(e.argv[e.argv.length-1]);let o=Dd,a=u=>{let p=te(u,e.cwd,le(n)).path,d=n.projectRoot&&!S(n.projectRoot)?n.projectRoot.replace(/(?<!\/)\/+$/,""):null,f=n.ctx.home.replace(/(?<!\/)\/+$/,"");return d!==null&&d!==""&&d!=="/"&&d!==f&&!f.startsWith(`${d}/`)&&p.startsWith(`${d}/`)},i=t.find(u=>Re(u)&&!u.startsWith("/dev/")&&!(o(u)&&a(u)));if(!i)return[];if(rt(i,e,n).kind==="disposable")return[];let c=O.basename($(i));return Ck.test(c)&&e.remote===null&&!Ak(te(i,e.cwd,le(n)).path,n.ctx.home)?[]:[w("claude.file.write_secret",`writes ${/\.(pem|crt|cer|der|p12|pfx|key)$/i.test(c)?"a key or certificate file":"a secrets file"} (${c})`,{target:$(i),is_local:!0})]}function Or(e,n){let t=e.findIndex((s,r)=>r>0&&new RegExp(`^-[A-Za-z]*${n}$`).test(s));return t>0?e[t+1]??null:null}function Fn(e){let n=$(e).replace(/^["']|["']$/g,"");return/^[a-z][a-z0-9+.-]*:\/\//i.test(n)||/^[\w.-]+\.[a-z]{2,}\//i.test(n)?me(n)??n.replace(/\/.*/,""):n.replace(/(:\/\/)[^@/\s]+@/g,"$1***@")}function P(e,...n){for(let t=1;t<e.length;t++){let s=e[t];for(let r of n){if(s===r&&e[t+1]!==void 0)return e[t+1];if(r.startsWith("--")&&s.startsWith(`${r}=`))return s.slice(r.length+1);if(!r.startsWith("--")&&r.length===2&&s.startsWith(r)&&s.length>2)return s.slice(2)}}return null}function Ze(e,n=!1){let t=$(e).replace(/(?<!\/)\/+$/,""),s=O.basename(t);return/\.(enc|sops|encrypted|gpg|age|asc)(\.[\w-]+)?$|\.enc\.|\.sops\./i.test(s)||/^(package(-lock)?\.json|tsconfig[\w.-]*\.json|readme[\w.-]*|license[\w.-]*|changelog[\w.-]*|\.gitkeep|\.keep|\.gitignore)$/i.test(s)||n&&/^\.(npmrc|envrc)$/.test(s)||/(^|\/)templates\//.test(t)&&/^secrets?\.ya?ml$/.test(s)||s==="debug.keystore"||/\.(pem|crt)$/i.test(s)&&/(bundle|chain|cacert|ca-cert|^ca[-_.]|root|intermediate|cert|public|pub)/i.test(s)&&!/key|priv/i.test(s)?!1:/^[^/]+\.env$/.test(s)&&!/^(example|sample|template|tpl)\.env$/i.test(s)?!0:Re(t)||Re(t.replace(/\*+$/,""))||/(^|\/)\.(ssh|aws|gnupg|kube|docker|config\/gh)$|(^|\/)(secrets?|credentials)$/i.test(t)||/(^|\/)(secrets?|credentials)\//i.test(t)&&(!/\./.test(s)||/\.(json|ya?ml|env|toml|ini|txt|pem|key|p12|pfx|crt|cer|properties|conf|cfg|xml|plist|csv|jks|keystore)$/i.test(s))}var Rk=/^\/\.claude(\/settings(\.local)?\.json|\/hooks(\/.*)?|\/plugins(\/.*)?)?$|^\/\.claude\.json$|^\/\.mcp\.json$|^\/\.anvil(\/claude(\/.*)?|\/rules\.(?:json|md)|\/workspace-keys\.json|\/telemetry-notice)?$/i,Ok=/(^|\/)managed-(settings|mcp)\.json$/i,jk=/(^|\/)library\/launch(agents|daemons)(\/|$)|^\/etc\/systemd\/|(^|\/)\.config\/systemd\/user(\/|$)|^\/(usr\/)?lib\/systemd\/system(\/|$)|^\/etc\/cron(\.(d|hourly|daily|weekly|monthly)(\/|$)|tab$)|^\/(private\/)?(var\/spool\/cron|usr\/lib\/cron\/tabs)(\/|$)/;function Ji(e,n,t=[],s=!0){return Xi(e,n,t,s).place}function Xi(e,n,t=[],s=!0){let r=ii(e,n,t,s);if(r==="agent")return{place:r,at:e};let o=u=>{for(let[p,d]of Object.entries(n.controlLinks??{})){if(S(u)||!(u===p||u.startsWith(`${p}/`)))continue;let f=d+u.slice(p.length);if(ii(f,n,t,s)==="agent")return f}return null},a=o(e);if(a!==null)return{place:"agent",at:a};if(!n.onDisk)return{place:r,at:e};let i=os(e,n.onDisk,!0),l=i!==null?o(i):null;if(l!==null)return{place:"agent",at:l};let c=i===null?null:ii(i,n,t,s);return i!==null&&(c==="agent"||r===null)?{place:c,at:i}:{place:r,at:e}}var Pk=/^\/projects\/[^/]+\/(?:[^/]+\.jsonl|[^/]+\/subagents\/.+\.jsonl)$/i,Wk=/^\/projects(?:\/[^/]+(?:\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}(?:\/subagents)?)?)?\/?$/i,Qi=e=>[`${e.home.replace(/(?<!\/)\/+$/,"")}/.claude`,...e.claudeConfigDir&&!S(e.claudeConfigDir)?[e.claudeConfigDir.replace(/(?<!\/)\/+$/,"")]:[]];function Mt(e,n,t=!0){let s=e.toLowerCase();return!s.includes("/projects")||S(e)||/\/memory(\/|$)/i.test(e)?!1:Qi(n).some(r=>(s===`${r.toLowerCase()}/projects`||s.startsWith(`${r.toLowerCase()}/projects/`))&&(Pk.test(e.slice(r.length))||t&&Wk.test(e.slice(r.length))))}function Xr(e,n,t){if(!/[*?[]/.test(e)||S(e)||!e.toLowerCase().includes("/projects"))return!1;let s="3f2a9c1e-5d4b-4a7e-9b1c-2e8f6a0d7c35",r=(i,l)=>{if(!/[*?[]/.test(i))return i.toLowerCase()===l.toLowerCase()||l!=="projects"&&l!=="subagents"&&(l.endsWith(".jsonl")?/\.jsonl$/i.test(i):l===s?/^[0-9a-f]{8}-/i.test(i):i.toLowerCase()!=="memory");let c=/^[^*?[]*/.exec(i)[0];return[l,c+l.slice(c.length)].some(u=>na(i).test(u))},o=[["projects","-Users-dev-app",`${s}.jsonl`],["projects","-Users-dev-app",s,"subagents","agent-a1b2c3.jsonl"],["projects","-Users-dev-app",s,"subagents","workflows","w","journal.jsonl"]],a=t?[...o,["projects","-Users-dev-app"],["projects","-Users-dev-app",s],["projects","-Users-dev-app",s,"subagents"]]:o;return Qi(n).some(i=>{if(!e.toLowerCase().startsWith(`${i.toLowerCase()}/`))return!1;let l=e.slice(i.length+1).replace(/(?<!\/)\/+$/,"").split("/");return a.some(c=>c.length===l.length&&l.every((u,p)=>r(u,c[p])))})}function Qr(e,n,t=null){if(!S(e))return!1;let s=e.indexOf(J),r=s>0?e.slice(0,s).replace(/(?<!\/)\/+$/,"").toLowerCase():"";if(r&&!Qi(n).some(u=>`${u.toLowerCase()}/projects`.startsWith(r)||r.startsWith(`${u.toLowerCase()}/projects`)))return!1;let o=$(e);if(t!==null&&!S(t)&&/\.jsonl|\b(ls|find)\b|\*/.test(o)&&Mt(t.replace(/(?<!\/)\/+$/,""),n))return!/\/memory(\/|$)/i.test(o);if(!o.toLowerCase().includes("/projects"))return!1;let a=n.home.replace(/(?<!\/)\/+$/,""),i=n.claudeConfigDir&&!S(n.claudeConfigDir)?n.claudeConfigDir.replace(/(?<!\/)\/+$/,""):null,l=u=>u.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),c=new RegExp(`(?:(?:~|\\$\\{?HOME\\}?|${l(a)})["']?/\\.claude${i?`|${l(i)}["']?`:""})/projects(?:/[^\\s'"|;&)<>]*)?`,"gi");for(let u of o.matchAll(c)){let p=o.slice(u.index);if(!(/\/memory\//i.test(p)&&!/(^|\/)\.\.(\/|$)/.test(p)))return!0}return!1}function Nk(e,n){return e.name==="find"||e.name==="gfind"?ef(e,n)!==null:e.argv.slice(1).some(t=>{if(t.startsWith("-"))return!1;let s=$(M(t,e.cwd,n.ctx));return Qr(t,n.ctx,e.cwd)||Mt(s,n.ctx)||Xr(s,n.ctx,!0)})}function Lk(e){return`writes Claude Code's record of a session (${O.basename(e)||e})`}var Tk=["3f2a9c1e-5d4b-4a7e-9b1c-2e8f6a0d7c35.jsonl","3f2a9c1e-5d4b-4a7e-9b1c-2e8f6a0d7c35","agent-a1b2c3.jsonl","journal.jsonl","subagents","workflows","-Users-dev-app","projects"];function Dk(e,n){let t=e.argv.slice(1),s=t.findIndex(l=>/^-(exec|execdir|ok|okdir)$/.test(l)),r=t.findIndex((l,c)=>c>s&&(l===";"||l==="+")),o=s<0?[]:t.slice(s+1,r<0?void 0:r),a=t.find((l,c)=>/^-(fprint0?|fprintf|fls)$/.test(t[c-1]??"")&&Mt($(M(l,e.cwd,n.ctx)),n.ctx,!1));if(a!==void 0)return $(M(a,e.cwd,n.ctx));let i=t.includes("-delete");return!i&&!(o.length>0&&Qd(o,o.at(-1)==="{}"))||(i||/^(rm|unlink)$/.test(he(o[0]??"")))&&Xd(t,i?t.indexOf("-delete"):s)?null:ef(e,n)}function Xd(e,n){let t=e.findIndex((s,r)=>e[r-1]==="-mtime"&&/^\+([7-9]|[1-9]\d+)$/.test(s)||e[r-1]==="-mmin"&&/^\+\d+$/.test(s)&&Number(s.slice(1))>=10080);return t>0&&t<n&&!["!","-not"].includes(e[t-2]??"")&&!e.some(s=>["-o","-or","(",")",","].includes(s))}function Qd(e,n){let t=he(e[0]??""),s=e.slice(1);if(/^(rm|unlink|shred|srm|trash|truncate|tee|dd|touch|chmod|chown|chflags|xattr|setfacl|g?mv|ed|ex|sponge)$/.test(t))return!0;if(/^(g?sed|perl)$/.test(t))return s.some(o=>/^-[a-zA-Z]*i/.test(o)||o.startsWith("--in-place"));if(/^g?awk$/.test(t))return s.some((o,a)=>o==="inplace"&&s[a-1]==="-i");if(/^(g?cp|install|rsync|ln|ditto)$/.test(t))return n&&!s.some(o=>o==="-t"||o.startsWith("--target-directory"));let r=/^(ba|z|da|k)?sh$/.test(t)?s.indexOf("-c"):-1;return r>=0&&/[>]|\b(rm|truncate|tee|g?mv|dd|touch|sed\s+-[a-zA-Z]*i|perl\s+-[a-zA-Z]*i)\b/.test(s[r+1]??"")}function ef(e,n){let t=e.argv.slice(1),s=[],r=0;for(;r<t.length&&/^-[HLPEXdsx]$/.test(t[r]);)r++;for(;r<t.length&&!/^[-(!]/.test(t[r]);r++)s.push(t[r]);s.length===0&&s.push(".");let o=t.flatMap((p,d)=>d>0&&["-name","-iname"].includes(t[d-1])?[{f:p,i:t[d-1]==="-iname"}]:[]),a=o.length===0||o.some(({f:p,i:d})=>Tk.some(f=>na(d?p.toLowerCase():p).test(d?f.toLowerCase():f))),i=t.flatMap((p,d)=>d>0&&["-path","-ipath","-wholename","-iwholename"].includes(t[d-1])?[p]:[]);if(!a||i.length>0&&i.every(p=>/memory/i.test(p)))return null;let l=n.ctx.home.replace(/(?<!\/)\/+$/,"").toLowerCase(),c=n.ctx.claudeConfigDir&&!S(n.ctx.claudeConfigDir)?n.ctx.claudeConfigDir.replace(/(?<!\/)\/+$/,"").toLowerCase():null,u=[`${l}/.claude/projects`,...c?[`${c}/projects`]:[]];for(let p of s){if(S(p)&&!p.startsWith("/"))continue;let d=M(p,e.cwd,n.ctx).replace(/(?<!\/)\/+$/,"");if(S(d))continue;let f=d.toLowerCase();if(u.some(h=>f===h||h.startsWith(`${f}/`)||f==="/"||f.startsWith(`${h}/`)&&!/\/memory(\/|$)/.test(f)))return $(d)}return null}function ii(e,n,t,s=!0){let r=$(e);if(s&&(Mt(r,n,s===!0)||Xr(r,n,s===!0)))return"agent";let o=t.filter(p=>p!==null&&p!==""&&!S(p)),a=r.toLowerCase();if((o.length>1?[...new Set(o)].map(p=>a.startsWith(`${p.toLowerCase()}/`)?r.slice(p.length):null).filter(p=>p!==null):[r.replace(/^.*(?=\/\.claude(\/|\.json$|$)|\/\.mcp\.json$|\/\.anvil(\/|$))/,"")]).some(p=>Rk.test(p))||Ok.test(r))return"agent";let l=n.claudeConfigDir?.replace(/(?<!\/)\/+$/,"").toLowerCase();if(l&&(a===l||a===`${l}/settings.json`||a===`${l}/settings.local.json`||a===`${l}/.claude.json`||a===`${l}/hooks`||a.startsWith(`${l}/hooks/`)||a===`${l}/plugins`||a.startsWith(`${l}/plugins/`)))return"agent";let c=O.dirname(r);if(qi(c)||te(c,null,{home:n.home,tmpdir:n.tmpdir,projectRoot:null}).kind==="disposable")return null;if(jk.test(r.toLowerCase()))return"jobs";let u=n.home;return[`${u}/.gitconfig`,`${u}/.config/git/config`,"/etc/gitconfig"].some(p=>p.toLowerCase()===a)?"gitconfig":null}function tf(e,n,t,s){let r=[],o=(c,u)=>{if(!c||c==="-"||c.startsWith("/dev/"))return;let p=M(De(c,e,n),e.cwd,n.ctx);return r.push(p),typeof u=="string"&&t?.set(p,u==="d"?ta(c):u),p},a=(c,u,p)=>{let d=o(c,u);d!==void 0&&p!==void 0&&s?.set(d,p)};for(let c of e.redirects)c.target&&c.op.includes(">")&&!(c.op.endsWith("&")&&/^(\d+|-)$/.test(c.target))&&o(c.target,"w");let i=e.argv.slice(1),l=i.filter(c=>!c.startsWith("-"));switch(e.name){case"tee":case"sponge":case"truncate":case"rm":case"unlink":case"trash":case"srm":case"shred":case"mkfifo":l.forEach(c=>o(c,e.name==="mkfifo"?null:["tee","sponge","truncate"].includes(e.name)?"w":"d"));break;case"mknod":l[0]&&o(l[0]);break;case"touch":for(let c=0;c<i.length;c++)/^(-[tdrA]|--(date|reference|time))$/.test(i[c])?c++:i[c].startsWith("-")||o(i[c]);break;case"cp":case"mv":case"install":case"ln":case"ditto":case"gcp":case"gmv":{let c=P(e.argv,"-t","--target-directory"),u=c!==null?l.filter(d=>d!==c):l.slice(0,-1),p=c??(l.length>=2?l[l.length-1]:e.name==="ln"&&l.length===1?".":null);if(p!==null){a(p,"w",u.length===1?u[0]:void 0);for(let d of u)a(O.join(p,O.basename($(d))),"w",d)}e.name==="ln"&&u.forEach(d=>o(d)),(e.name==="mv"||e.name==="gmv")&&u.forEach(d=>o(d,"m"));break}case"sed":case"gsed":case"perl":case"ruby":case"yq":{if(!i.some(d=>d==="--in-place"||d.startsWith("--in-place=")||d==="--inplace"||/^-[A-Za-z]*i/.test(d)&&!d.startsWith("--")))break;let u=[],p=!1;for(let d=0;d<i.length;d++){let f=i[d];["-e","--expression","-f","--file"].includes(f)||(e.name==="perl"||e.name==="ruby")&&/^-[A-Za-z]*e$/.test(f)?(p=!0,d++):/^(?:sed|gsed)$/.test(e.name)&&f==="-i"&&(i[d+1]===""||!p&&/^\.[\w.-]*$/.test(i[d+1]??""))?d++:f.startsWith("-")||u.push(f)}(p?u:u.slice(1)).forEach(d=>o(d,"w"));break}case"dd":o(i.find(c=>c.startsWith("of="))?.slice(3),"w");break;case"chmod":case"chown":case"chgrp":case"chflags":if(e.name==="chmod"){let c=i.filter(u=>!/^-[RHLPfhvcECNiI]+$/.test(u)&&!u.startsWith("--"));(i.some(u=>u.startsWith("--reference"))?c:c.slice(1)).forEach(o)}else(i.some(c=>c.startsWith("--reference"))?l:l.slice(1)).forEach(o);break;case"curl":o(P(e.argv,"-o","--output")??Or(e.argv,"o"));break;case"scp":{let c=new Set(["-P","-i","-F","-o","-c","-l","-S","-J","-D","-X"]),u=i.filter((d,f)=>!d.startsWith("-")&&!c.has(i[f-1]??"")),p=u.length>=2?u[u.length-1]:null;p!==null&&!/^[^/]*:/.test(p)&&o(p);break}case"wget":o(P(e.argv,"-O","--output-document")??Or(e.argv,"O")??P(e.argv,"-P","--directory-prefix"));break;case"rsync":{let c=ke(e.argv,1,sa),u=c.length>=2?c[c.length-1]:null;if(u!==null&&!Ye(u)){a(u,e.argv.some(p=>/^--del(?:ete(?:-[\w-]+)?)?$/.test(p))?"f":"w",c.length===2?c[0]:void 0);for(let p of c.slice(0,-1))a(O.join(u,O.basename($(p).replace(/(?<!\/)\/+$/,""))),"w",p)}break}case"tar":case"gtar":case"bsdtar":case"unzip":{let c=e.name==="unzip"?P(e.argv,"-d"):P(e.argv,"-C","--directory");(e.name==="unzip"?!i.some(p=>/^-[A-Za-z]*[ltpZ]/.test(p)):i.some(p=>/^-?[A-Za-z]*x/.test(p)||p==="--extract"||p==="--get"))&&o(c??".");break}case"7z":case"7za":case"7zr":case"7zz":["x","e"].includes(l[0]??"")&&o(i.find(c=>c.startsWith("-o"))?.slice(2)||".");break;case"sort":o(P(e.argv,"-o","--output")??Or(e.argv,"o"));break;case"base64":o(P(e.argv,"-o","--output"));break;case"openssl":o(P(e.argv,"-out"));break;case"awk":case"gawk":case"mawk":case"nawk":{let c=Wo(e.argv)??"";if(i.some((u,p)=>u==="-i"&&i[p+1]==="inplace"||u==="-iinplace"||u==="--include=inplace")){let u=ke(e.argv,1,new Set(["-i","--include","-F","-v","-f","-e","-l"]));(c&&u[0]===c?u.slice(1):u).forEach(p=>o(p,"w"))}for(let u of c.matchAll(/\b(?:print|printf)\b(?:"(?:\\.|[^"\\])*"|[^;}|"])*?>{1,2}\s*"((?:\\.|[^"\\])+)"/g))o(u[1]);break}case"ed":case"red":case"ex":case"vi":case"vim":case"nvim":case"emacs":{if(i.some(u=>u==="-R"||u==="-M"||u==="--read-only")||e.name==="emacs"&&!i.some(u=>u==="--batch"||u==="-batch"||u==="--script"))break;let c=e.name==="ed"||e.name==="red"?new Set(["-p"]):new Set(["-c","--cmd","-S","-u","-U","-i","-T","-w","-W","-t","-q","--eval","-l","--load","-f","--funcall","--script"]);ke(e.argv,1,c).filter(u=>!u.startsWith("+")).forEach(o);break}case"patch":o(ke(e.argv,1,new Set(["-i","--input","-p","-d","-o","--output","-r","-B","-z","-V","-F"]))[0]);break;case"plutil":i.some(c=>/^-(replace|insert|remove|convert)$/.test(c))&&o(l[l.length-1]);break;case"git":{let c=Xe(e);if(c&&c.sub==="clone"&&o(ke(["git",...c.args],1,new Set(["-b","--branch","-o","--origin","--depth","-c","--config","--reference","--template","-j","--jobs","--filter"]))[1]),c&&["checkout","restore"].includes(c.sub)){let u=c.args.indexOf("--");(c.sub==="restore"&&c.args.some(f=>f==="--staged"||f==="-S")&&!c.args.some(f=>f==="--worktree"||f==="-W")?[]:u>=0?c.args.slice(u+1):c.sub==="restore"?c.args.filter(f=>!f.startsWith("-")):[]).forEach(o)}break}default:break}return r}var nf=/permissionMode:\s*['"]?bypassPermissions\b|allowed-tools:[^\n]*\bBash(\(\*\))?(?![\w(])|allowed-tools:[ \t]*\n(?:[ \t]*-[^\n]*\n)*?[ \t]*-[ \t]*['"]?Bash(\(\*\))?['"]?[ \t]*(?:\n|$)/;function ou(e){if(!e||typeof e!="object")return"";let n=e,t=Array.isArray(n.edits)?n.edits.map(s=>s&&typeof s=="object"&&typeof s.new_string=="string"?s.new_string:""):[];return[n.content,n.new_string,...t].filter(s=>typeof s=="string").join(`
|
|
68
|
+
`)}function Ik(e,n){for(let[t,s]of Object.entries(n.controlLinks??{}))if(e===t||e.startsWith(`${t}/`))return s+e.slice(t.length);return e}function sf(e,n){if(/(^|\/)\.claude\/(agents|commands|skills)\//i.test(e))return!0;let t=n.claudeConfigDir?.replace(/(?<!\/)\/+$/,"");return!!t&&e.startsWith(`${t}/`)&&/^(agents|commands|skills)\//i.test(e.slice(t.length+1))}function iu(e,n){if(S(e))return!1;let t=e.replace(/(?<!\/)\/+$/,""),s=n.home.replace(/(?<!\/)\/+$/,""),r=n.claudeConfigDir?.replace(/(?<!\/)\/+$/,"");return[`${s}/.claude`,`${s}/.anvil`,...r?[r]:[],...Object.keys(n.controlLinks??{})].some(a=>t===""||a.startsWith(`${t}/`))}var Fk=/(^|\/)\.(zshrc|zshenv|zprofile|zlogin|bashrc|bash_profile|bash_login|bash_aliases|bash_functions|zsh_aliases|aliases|profile|envrc|zshrc\.local|bashrc\.local)$|(^|\/)\.(bashrc|zshrc)\.d\/.+$|(^|\/)\.oh-my-zsh\/custom\/.+\.zsh$|(^|\/)\.zsh\/.+\.zsh$|(^|\/)\.config\/fish\/(config\.fish|conf\.d\/.+\.fish|functions\/.+\.fish)$/,Mk=/(^|\/)[Dd]ocuments\/(?:[Ww]indows)?[Pp]ower[Ss]hell\/[^/]*[Pp]rofile\.ps1$/,$t={test:e=>Fk.test(e)||Z()&&Mk.test(e)};function zk(e,n){let t=$(e),s=n.ctx.home.replace(/(?<!\/)\/+$/,"");if(S(e)||!t.startsWith(`${s}/`)||!$t.test(t)||/(^|\/)\.envrc$/.test(t))return!1;let r=n.projectRoot;return r&&!S(r)&&r!==s&&t.startsWith(`${r}/`)?!1:te(O.dirname(t),null,{home:n.ctx.home,tmpdir:n.ctx.tmpdir,projectRoot:null}).kind!=="disposable"}function Uk(e,n,t){let s=$(e);if(n.remote!==null||S(e)||Dt(n)||!/^\/usr\/local\/./.test(s))return!1;let r=je(t,{kind:"owner",arg:s});return typeof r=="string"&&/^\d+$/.test(r)&&r!=="0"}var qk=/^\/(etc|usr|bin|sbin|lib|lib32|lib64|libexec|boot|System|Library|root|private\/etc)(\/|$)/;function Hk(e){let n=$(e);return!S(e)&&qk.test(n)&&!/^\/(etc|private\/etc)$|^\/usr$/.test(n)}function Bk(e,n){let t=$(e);if(S(e))return!1;let s=n.ctx.home.replace(/(?<!\/)\/+$/,"");return/^\/(private\/)?etc\/(profile|bashrc|bash\.bashrc|zshrc|zshenv|zprofile|zlogin|environment)$|^\/(private\/)?etc\/profile\.d\//.test(t)?!0:$t.test(t)&&/^\/(root|home\/[^/]+|Users\/[^/]+)\//.test(t)&&!t.startsWith(`${s}/`)&&!/(^|\/)\.envrc$/.test(t)}function Mn(e){return Vk.test(e.replace(/\\[ntr]/g,`
|
|
69
|
+
`))}var Vk=/\b(CLAUDE_CONFIG_DIR|ANVIL_CLAUDE_SYNC|CLAUDE_CODE_SIMPLE|CLAUDE_CODE_SAFE_MODE|ANVIL_WORKSPACE_KEYS_PATH)\b|\balias\s+['"]?claude=|\bclaude\s*\(\s*\)|\bfunction\s+claude\b/;function _i(e){let n=e.pipeFrom,t=e.stdin??(["echo","printf","sed"].includes(e.name)?e.argv.slice(1).join(`
|
|
70
|
+
`):n&&["echo","printf","cat"].includes(n.name)?n.stdin??n.argv.slice(1).join(`
|
|
71
|
+
`):null),s=(e.groupWriters??[]).map(r=>_i(r)??"").filter(Boolean).join(`
|
|
72
|
+
`);return t??(s!==""?s:null)}function Gk(e){let n=e.argv.slice(1),t=n.filter(r=>!r.startsWith("-")),s=r=>S(r)||r==="."||/\/\.?$/.test(r)||/[*?[]/.test(r);switch(e.name){case"cp":case"gcp":{if(!n.some(i=>i==="--recursive"||i==="--archive"||/^-[A-Za-z]*[rRa]/.test(i)&&!i.startsWith("--")))return[];let r=P(e.argv,"-t","--target-directory"),o=r!==null?t.filter(i=>i!==r):t.slice(0,-1),a=r??(t.length>=2?t[t.length-1]:null);return a!==null&&o.some(s)?[a]:[]}case"ditto":return t.length>=2?[t[t.length-1]]:[];case"rsync":{let r=ke(e.argv,1,sa),o=r.length>=2?r[r.length-1]:null;return o!==null&&!Ye(o)&&r.slice(0,-1).some(s)?[o]:[]}case"7z":case"7za":case"7zr":case"7zz":return["x","e"].includes(t[0]??"")?[n.find(r=>r.startsWith("-o"))?.slice(2)||"."]:[];default:{if(e.name==="unar")return[P(e.argv,"-o","-output-directory")??"."];if(e.name==="jar")return/^-?[a-z]*x/.test(n[0]??"")||n.includes("--extract")?[P(e.argv,"-C","--dir")??"."]:[];if(e.name==="cpio"||e.name==="bsdcpio")return n.some(i=>i==="--extract"||/^-[A-Za-z]*i/.test(i))?[P(e.argv,"-D","--directory")??"."]:[];if(e.name==="pax")return n.some(i=>/^-[A-Za-z]*r/.test(i))?["."]:[];if(!/^python(\d+(\.\d+)?)?$/.test(e.name))return[];let r=n.indexOf("-m");if(r<0||!["zipfile","tarfile"].includes(n[r+1]??""))return[];let o=n.slice(r+2),a=o.findIndex(i=>i==="-e"||i==="--extract");return a<0?[]:[o.slice(a+1).filter(i=>!i.startsWith("-"))[1]??"."]}}}var ai=`${J}a link loop${ee}`,Zk=/^\/(?:\.(?:npm|cargo\/(?:registry|git)|m2\/repository|bun\/install\/cache|[^/]+\/(?:cache|caches))|go\/pkg\/mod|Library\/Developer\/Xcode\/DerivedData)(?:\/|$)/,Kk=/\/(dist|build|out|coverage|target|venv|test-results|playwright-report|storybook-static|htmlcov|[^./][^/]*\.lock)(?=\/|$)/gi,Yk=/^\/(?:projects|plans)(?:\/|$)/i,Jk=/\bmktemp\b|tmpdir\(\)|gettempdir\(\)|\$\{?(?:TMPDIR|TEMP|TMP)\b|%TE?MP%|\bgetconf\s+DARWIN_USER_TEMP_DIR\b/i;function ea(e,n,t,s,r,o=!1,a=null){if(!s||!s.startsWith("/")||S(s))return null;let i=li(os(e,t.onDisk,r)??e,e,n,t,s,a);if(/^[we]$/.test(n))return i;let l=o||n==="D"||n==="F",c=[.../[*?[]/.test(l?e:O.dirname(e))?No(l?`${e}/`:e,t.onDisk,"glob").map(u=>li(u,e,o?"F":n,t,s)):[],...o?No(e,t.onDisk,"deep").map(u=>li(u,e,"F",t,s)):[]];return[i,...c].find(u=>u?.service)??i??c.find(u=>u!==null)??null}function li(e,n,t,s,r,o=null){if(/^\/dev\/(?:null|stdout|stderr|tty|fd\/\d+)$/.test(e)||ts(e))return null;let a=e.startsWith("/")?e.indexOf(J):0,i=a<0?e:e.slice(0,Math.max(0,e.lastIndexOf("/",a-1))),l=C=>process.platform==="linux"&&!Z()?C:C.toLowerCase(),c=l(i),u=re(s.home),p=l(re(r)),d=p!=="/"&&l(u)!==p&&!l(u).startsWith(`${p}/`),f=(C,N)=>{let q=l(re(C));return q!=="/"&&(N&&c===q||c.startsWith(`${q}/`))},h=s.session?.roots??[];if(i!==""&&(d&&f(r,!0)||h.some(C=>f(C,!1))))return null;let g=i!==""&&h.some(C=>l(re(C))===c);if(a===0&&Jk.test(e)&&!e.startsWith(ai)&&!/\/\.\.(?:\/|$)/.test(e)||/\/\.[^/]*\.lock(?:\/|$)/i.test(i)||te(e.replace(Kk,"/$1"),null,{home:s.home,tmpdir:s.tmpdir,projectRoot:null,made:s.session?.made??null}).kind==="disposable")return null;let b=typeof s.claudeConfigDir=="string"&&!S(s.claudeConfigDir)?re(s.claudeConfigDir):`${u}/.claude`;if(i.startsWith(`${u}/`)&&Zk.test(i.slice(u.length))||i.startsWith(`${b}/`)&&Yk.test(i.slice(b.length)))return null;let k=$(e.startsWith(ai)?n:e),E=k===u?"~":k.startsWith(`${u}/`)?`~${k.slice(u.length)}`:gn(k),y=e.startsWith(ai),m=i!==""&&(!/^[we]$/.test(t)||/(?:^|\/)\.git(?:\/|$)/.test(i))||y||o!==null&&i==="",R=t==="m"?"move":t==="w"?"write to":t==="e"?"edit":t==="f"||t==="F"?"delete files under":"delete",v=i===""?o!==null&&!y?`Anvil can't tell where ${o} is`:"can't tell if it's in your project":g?"one of your project's folders, whole":"outside your project";return w("claude.file.outside_project",`would ${R} ${E} (${v})`,{target:k,service:m?mm:null,is_local:!0,op:t==="m"?"move":/^[we]$/.test(t)?"write":"delete",lands:i===""?"unknown":g?"whole":"outside"})}var Si=(e,n)=>n.endsWith("/")||e.argv.slice(1).some(t=>t==="-L"||t==="-H"||t==="-follow"),rf=(e,n)=>e.argv.slice(1).some(t=>t==="-L"||t==="-follow")||of(e,n);function of(e,n){for(let t=e.parent;t;t=t.parent)if(/^(?:powershell|pwsh|cmd)(?:\.exe)?$/i.test(t.name))return!0;return n.ctx.powershell===!0}var au=ae({grep:/^-[viwxFEsh]+$/,head:/^-n?\d*$|^\d+$/,tail:/^-n?\+?\d*$|^\+?\d+$/,sort:/^-[rnufVbdR]+$/,uniq:/^-[udi]+$/});function Xk(e){let n=e.name.replace(/^[ef](?=grep$)/,""),t=e.argv.slice(1);return au[n]!==void 0&&t.every((s,r)=>au[n].test(s)||n==="grep"&&r===t.length-1&&!s.startsWith("-"))}function lu(e,n,t){let s=e;for(;s!==null&&Xk(s);)s=s.pipeFrom;if(s===null)return null;let r=s;if(r.name==="find"||r.name==="gfind"){let l=Vr(r);return l.disposableFilter?[]:l.roots.map(c=>[M(c,n.cwd,t.ctx),Si(r,c)?"F":"f",rf(r,t)])}if(r.name!=="ls"&&r.name!=="gls")return null;let o=r.argv.slice(1),a=o.filter(l=>!l.startsWith("-")),i=!o.some(l=>/^-[a-zA-Z0-9]*d|^--directory$/.test(l))&&(a.length===0||a.some(l=>!/[*?[]/.test(l)));return[...a.map(l=>[M(l,n.cwd,t.ctx),ta(l),!1]),...i?[[M(".",n.cwd,t.ctx),"f",!1]]:[]]}function ta(e){let n=e.replace(new RegExp(`${J}[^${ee}]*${ee}`,"g"),"");return e.endsWith("/")?"D":/[*?[]/.test(n.slice(n.lastIndexOf("/")+1))?"G":"d"}var Qk=/(?:^|[\s;&|({`])(?:source|\.|eval)\s|\b(?:export|declare|typeset|local|readonly)\s+(?:-\S+\s+)*["']?[$`]/;function ev(e,n,t){if(!S(e))return e;let s=t.ctx.powershell===!0||n.via==="shell-string"||n.via==="stdin-script"?{}:t.ctx.session?.env??{},r=re(t.ctx.home);return e.replace(new RegExp(`${J}([^${ee}]*)${ee}`,"g"),(o,a)=>{let i=/^~([A-Za-z_][\w.-]*|\+)$/.exec(a)?.[1];if(i==="+")return n.cwd!==null&&n.cwd.startsWith("/")&&!S(n.cwd)?n.cwd:o;if(i!==void 0)return i==="root"&&!Z()?process.platform==="darwin"?"/var/root":"/root":`${O.dirname(r)}/${i}`;let l=/^\$(?:([A-Za-z_]\w*)|\{([A-Za-z_]\w*)(?::?\?[^}]*)?\})$/.exec(a),c=l?.[1]??l?.[2],u=c===void 0?void 0:Z()?Object.keys(s).find(f=>f.toLowerCase()===c.toLowerCase()):Object.hasOwn(s,c)?c:void 0,p=u!==void 0?s[u]:void 0,d=()=>Qk.test(t.lineText)||new RegExp(`(?<![\\w$\\{])${c}(?!\\w)`,Z()?"i":"").test(t.lineText);return p!==void 0&&p.startsWith("/")&&!S(p)&&!d()?re(p):o})}function tv(e){let n=e.indexOf(J),t=n<0?"":$(e.slice(n,e.indexOf(ee,n)+1));return t.length>48?`${t.slice(0,24)}\u2026${t.slice(-20)}`:t}function Ur(e,n){let t=[],s=uv(e,n).find(y=>ff(y,n));if(s!==void 0){let y=$(s),m=n.ctx.home.replace(/(?<!\/)\/+$/,""),R=y===m?"~":y.startsWith(`${m}/`)?`~${y.slice(m.length)}`:y;return[w("claude.agent.controls",`links to a folder that holds Anvil's or Claude Code's settings (${R})`,{target:y,is_local:!0})]}for(let y of Gk(e)){if(S(y)&&!y.startsWith("/"))continue;let m=M(y,e.cwd,n.ctx),R=Mt($(m),n.ctx);if(!iu(m,n.ctx)&&!R)continue;let v=n.ctx.home.replace(/(?<!\/)\/+$/,""),C=$(m).length;for(;C>1&&$(m)[C-1]==="/";)C--;let N=$(m).slice(0,C),q=N===v?"~":N.startsWith(`${v}/`)?`~${N.slice(v.length)}`:N;return[w("claude.agent.controls",`${e.name} writes what it copies or unpacks into a folder that holds ${R?"Claude Code's records of sessions":"Anvil's or Claude Code's settings"} (${q})`,{target:N,is_local:!0})]}let r=lv(e);e.via==="xargs"&&!As.has(e.name)&&Nn(n,`${J}(paths ${e.name} reads from xargs)${ee}`,e.cwd),(e.name==="git"?Xe(e)?.sub==="apply"&&!e.argv.some(y=>/^--(?:check|stat|numstat|summary)$/.test(y)):e.name==="patch"&&!e.argv.some(y=>y==="--dry-run"||y==="-C"||y==="--check"))&&Nn(n,`${J}(paths the patch names)${ee}`,e.cwd);let a=["rm","trash","srm","shred","mv","gmv"].includes(e.name),i=a||/^((g|bsd)?tar|unzip|7z[arz]?|unar|jar|(bsd)?cpio|pax)$/.test(e.name)||"files",l=e.via==="xargs"?e.parent?.pipeFrom??e.pipeFrom:null,c=l!==null&&/^(rm|unlink)$/.test(e.name)&&/^g?find$/.test(l.name)&&Xd(l.argv.slice(1),l.argv.length);l&&!c&&Qd(e.argv,!e.argv.includes("{}")||e.argv.at(-1)==="{}")&&Nk(l,n)&&t.push(w("claude.agent.controls",`${e.name} changes Claude Code's records of sessions (a listing of its projects folder, through xargs)`,{target:$(l.argv.slice(1).join(" ")).slice(0,200),is_local:!0}));let u=r.argv.slice(1),p=["mv","gmv"].includes(e.name)?P(r.argv,"-t","--target-directory")??u.filter(y=>!y.startsWith("-")).at(-1)??null:null,d=new Set(p!==null&&!S(p)?[M(p,e.cwd,n.ctx),M(p,e.cwd,n.ctx).replace(/(?<!\/)\/+$/,"")]:[]),f=new Map,h=[],g=(y,m,R=!1)=>{if(e.via==="find-exec"&&/^(?:rm|unlink|shred|rmdir)$/.test(e.name)&&/(?:^|\/)\{\}$/.test(y)&&e.argv.includes("{}"))return;let v=y.indexOf(ee),C=y[1]==="`";if(m&&/^[dDGm]$/.test(m)&&y[0]===J&&(C||y.startsWith("$(",1))&&y[v-1]===(C?"`":")")){let z=cn(y.slice(C?2:3,v-1),e.cwd,n).commands.filter(ue=>ue.via==="top"),G=z.length>0?lu(z[z.length-1],e,n):null,ve=y.slice(v+1);if(G){for(let[ue,Se,xe]of G)g(ve?`${ue}/${J}\u2026${ee}${ve}`:ue,ve?m:Se,xe);return}}let N=ev(S(y)&&!y.startsWith("/")&&!y.startsWith(J)&&e.cwd!==null&&e.cwd.startsWith("/")&&!S(e.cwd)?O.join(e.cwd,y):y,e,n),q=e.name==="find"||e.name==="gfind"||e.argv.slice(1).some(z=>/^-[a-zA-Z]*[rR]/.test(z)||z==="--recursive"),B=e.cwd!==null&&S(e.cwd)&&!e.cwd.startsWith("/")&&!N.startsWith("/")&&(N.startsWith(e.cwd)||!S(N)),F=m!==void 0&&(B?/^[GfF]$/.test(m)||q&&/^[dD]$/.test(m):q&&m==="G")?tv(B?e.cwd:N):"",U=F!==""?F:null,X=m&&e.remote===null?ea(N,m,n.ctx,n.projectRoot,/^[wDFG]$/.test(m),R,U):null;X&&h.push(X)},b=y=>e.name==="rm"&&/^[DG]$/.test(y??"")&&of(e,n)&&e.argv.slice(1).some(m=>/^-[a-zA-Z]*r/i.test(m)||m==="--recursive");for(let y of tf(r,n,f)){Nn(n,y,e.cwd);let m=f.get(y),R=m!==void 0&&(!/^[we]$/.test(m)||/(?:^|\/)\.git(?:\/|$)/.test(y));if(R&&g(y,m,b(m)),Qr(y,n.ctx,e.cwd)){t.push(w("claude.agent.controls","writes Claude Code's record of a session (a file a listing of its projects folder names)",{target:$(y).slice(0,200),is_local:!0}));continue}if(a&&!d.has(y)&&iu(y,n.ctx)){t.push(w("claude.agent.controls",`${e.name} takes a folder that holds the agent's controls (${$(y)})`,{target:$(y),is_local:!0}));continue}let v=df(y,n.ctx,[n.ctx.home,n.projectRoot,n.base],i).find(B=>B!==y);if(v!==void 0){t.push(w("claude.agent.controls",jr($(v),n.ctx),{target:$(v),is_local:!0}));continue}if($t.test(y)&&Mn(_i(e)??"")){t.push(w("claude.agent.controls",`changes how every later Claude Code session starts (${O.basename($(y))})`,{target:$(y),is_local:!0}));continue}if(Rm.test(y)&&!vt(y,n)){t.push(w("claude.bash.git.discard",`rewrites git's own records (${$(y).split("/.git/").pop()})`,{target:$(y),is_local:!0}));continue}if(sf(y,n.ctx)){let B=_i(e);if(B!==null&&nf.test(B)){t.push(w("claude.agent.controls",`gives a subagent, command or skill its own bypass or unrestricted shell (${O.basename($(y))})`,{target:$(y),is_local:!0}));continue}}let{place:C,at:N}=Xi(y,n.ctx,[n.ctx.home,n.projectRoot,n.base],i),q=$(N);if(C===null&&zk(y,n)){t.push(w("claude.bash.persistence",`changes a shell startup file (${O.basename($(y))}), which runs in every new shell`,{target:$(y),is_local:e.remote===null,host:e.remote}));continue}if(C===null&&Bk(y,n)){t.push(w("claude.bash.persistence",`changes a shell startup file outside your own home (${$(y)}), which runs in other users' shells`,{target:$(y),is_local:e.remote===null,host:e.remote}));continue}if(C===null&&Hk(y)&&!Uk(y,e,n)){let B=["rm","trash","srm","shred","unlink"].includes(e.name);t.push(w(B?"claude.bash.fs.delete_recursive":"claude.bash.privilege",`${B?"deletes":"changes"} a system file (${$(y)})`,{target:$(y),is_local:e.remote===null,host:e.remote}));continue}C==="agent"?t.push(w("claude.agent.controls",jr(q,n.ctx),{target:q,is_local:!0})):C==="jobs"?t.push(w("claude.bash.persistence",`installs or changes a background job (${q})`,{target:q,is_local:e.remote===null,host:e.remote})):C==="gitconfig"?t.push(w("claude.bash.persistence",`rewrites the global git config (${q})`,{target:q,is_local:!0})):R||g(y,m,b(m))}let k=/^(?:rm|unlink|rmdir|trash|srm|shred)$/;if(e.name==="rmdir")for(let y of r.argv.slice(1).filter(m=>!m.startsWith("-")))g(M(De(y,e,n),e.cwd,n.ctx),"d");if(e.via==="xargs"&&e.pipeFrom&&k.test(e.name)){let y=lu(e.pipeFrom,e,n);if(y)for(let[m,R,v]of y)g(m,R,v);else for(let m of Ui(e.pipeFrom,n))S(m)||g(M(m,e.pipeFrom.cwd,n.ctx),ta(m))}if(e.name==="find"||e.name==="gfind"){let y=Vr(e);if(y.deletes&&!y.disposableFilter)for(let m of y.roots)g(M(m,e.cwd,n.ctx),y.narrowed!==null?Si(e,m)?"F":"f":Si(e,m)?"D":"d",rf(e,n))}if(!t.some(y=>y.action==="claude.agent.controls")&&!As.has(e.name)&&Mn(`${e.argv.join(`
|
|
64
73
|
`)}
|
|
65
|
-
${e.stdin??""}`)){let
|
|
66
|
-
`);if(
|
|
67
|
-
`)}return null}function uu(e){return e===null?[]:[...e.slice(0,262144).matchAll(/^(?:---|\+\+\+)\s+(\S+)/gm)].map(t=>t[1]).filter(t=>t!=="/dev/null").flatMap(t=>/^[ab]\//.test(t)?[t,t.slice(2)]:[t])}function qy(e,t){let n=[],s=0;for(;s<t.length&&t[s].startsWith("-");s++){let i=t[s];if(i==="-C"||i==="--work-tree"||i==="--git-dir")n.push(t[++s]??"");else if(i==="-c"){let l=t[++s]??"";/^core\.worktree=/i.test(l)&&n.push(l.slice(l.indexOf("=")+1))}else(i.startsWith("--work-tree=")||i.startsWith("--git-dir="))&&n.push(i.slice(i.indexOf("=")+1))}for(let i of e.text.matchAll(/\bGIT_(?:WORK_TREE|DIR)=("[^"]*"|'[^']*'|[^\s;&|]+)/g))n.push(i[1].replace(/^["']|["']$/g,""));let r=t[s]??"",o=t.slice(s+1);if(r==="stash"&&["list","show"].includes(o[0]??"")||r==="worktree"&&(o[0]??"")==="list"||r==="apply"&&o.some(i=>["--check","--stat","--numstat","--summary"].includes(i)))return null;if(r==="apply"||r==="am")return{names:[...n,...o,...uu(cu(e))],cwd:!0};let a=r==="restore"&&o.some(i=>i==="--staged"||i==="-S")&&!o.some(i=>i==="--worktree"||i==="-W")||r==="reset"&&!o.some(i=>i==="--hard"||i==="--merge"||i==="--keep")||r==="rm"&&o.includes("--cached");return zy.has(r)||a?null:{names:[...n,...n.length===0&&e.cwd!==null?[e.cwd]:[],...o],cwd:!0}}function Hy(e){let t=n=>{if(/[\s"']/.test(n))return!1;let s=n.indexOf("{"),r=s<0?-1:n.indexOf(",",s+1);return r>s&&n.lastIndexOf("}")>r};return e.argv.slice(1).some(t)?{...e,argv:[e.argv[0],...e.argv.slice(1).flatMap(n=>t(n)?du(n):[n])].slice(0,256)}:e}function du(e){if(!e.includes("{"))return[e];let t=[],n=[e];for(let s=0;n.length>0&&t.length<64&&s<256;s++){let r=n.shift(),o=r.indexOf("{"),a=-1,i=[];for(let c=o,u=0;o>=0&&c<r.length;c++)if(r[c]==="{")u++;else if(r[c]==="}"&&--u===0){a=c;break}else r[c]===","&&u===1&&i.push(c);if(o<0||a<0||i.length===0){t.push(r);continue}let l=[o,...i,a];for(let c=0;c+1<l.length;c++)n.push(r.slice(0,o)+r.slice(l[c]+1,l[c+1])+r.slice(a+1))}return t.length>0?t:[e]}function Go(e){let t=/^[*?[]/.test(e)?"(?!\\.)":"";for(let n=0;n<e.length;n++){let s=e[n];if(s==="*")t+="[^/]*";else if(s==="?")t+="[^/]";else if(s==="["){let r=e.indexOf("]",n+2);r<0?t+="\\[":(t+=`[${e.slice(n+1,r).replace(/^!/,"^").replace(/\\/g,"\\\\")}]`,n=r)}else t+=s.replace(/[.+^${}()|\\]/g,"\\$&")}try{return new RegExp(`^${t}$`)}catch{return new RegExp(`^${e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}$`)}}function fu(e,t){let n=[...new Set(t.filter(o=>typeof o=="string"&&o.startsWith("/")&&!S(o)).map(o=>o.replace(/(?<!\/)\/+$/,"")))],s=e.claudeConfigDir&&!S(e.claudeConfigDir)?e.claudeConfigDir.replace(/(?<!\/)\/+$/,""):null,r=e.home.replace(/(?<!\/)\/+$/,"");return{files:[...n.flatMap(o=>[`${o}/.claude/settings.json`,`${o}/.claude/settings.local.json`,`${o}/.claude.json`,`${o}/.mcp.json`,`${o}/.claude`]),`${r}/.anvil`,`${r}/.anvil/rules.json`,`${r}/.anvil/rules.md`,`${r}/.anvil/workspace-keys.json`,`${r}/.anvil/telemetry-notice`,...s?[s,`${s}/settings.json`,`${s}/settings.local.json`,`${s}/.claude.json`]:[]],folders:[...n.flatMap(o=>[`${o}/.claude/hooks`,`${o}/.claude/plugins`]),`${r}/.anvil/claude`,...s?[`${s}/hooks`,`${s}/plugins`]:[]]}}function pu(e,t,n,s=!0){let r=[];for(let o of du(e)){if(!/[*?[]/.test(o)||s&&St(k(o),t,s===!0)){Bo(o,t,n,s)==="agent"&&r.push(o);continue}if(s&&ir(k(o),t,s===!0)){r.push(o);continue}let a=o.split("/"),i=a.map(Go),l=(f,p)=>{let d=f.split("/");return(p?a.length>d.length:a.length===d.length)&&d.every((h,g)=>i[g].test(h))},c=fu(t,n),u=c.files.find(f=>l(f,!1))??c.folders.find(f=>l(f,!1)||l(f,!0));u!==void 0&&r.push(u)}return r}function By(e,t){let n=[t.ctx.home,t.projectRoot,t.base],s=e.cwd!==null&&!S(e.cwd)?e.cwd.replace(/(?<!\/)\/+$/,""):null,r=s!==null&&fu(t.ctx,n).folders.some(c=>s===c||s.startsWith(`${c}/`)),o=c=>{if(c.startsWith("-")&&!c.includes("=")&&!/[~/]/.test(c))return null;let u=c.startsWith("-")?c.includes("=")?c.slice(c.indexOf("=")+1):c.slice(Math.max(0,c.search(/[~/]/))):c,f=/^(\/|~|\.\.?\/)/.test(u)||!/\s/.test(u)&&(/^\.[\w-]/.test(u)||u.includes("/")||/^[\w.-]+$/.test(u));return!u||S(u)&&!u.startsWith("/")||!f?null:pu(M(u,e.cwd,t.ctx),t.ctx,n,!1)[0]??null};for(let c of e.wrapperArgs){let u=o(c);if(u!==null)return u}let a=Uy(e,t.ctx.claudeConfigDir&&!S(t.ctx.claudeConfigDir)?t.ctx.claudeConfigDir.replace(/(?<!\/)\/+$/,""):null);if(a===null)return null;let i=t.ctx.home.replace(/(?<!\/)\/+$/,"");if(e.name==="git"&&Fy.has(_t(e)?.sub??""))for(let c of a.names){if(S(c))continue;let u=M(c,e.cwd,t.ctx).replace(/(?<!\/)\/+$/,"");if(u===i)return`${i}/.claude`;let f=Object.entries(t.ctx.controlLinks??{}).find(([p])=>p.startsWith(`${u}/`));if(f)return f[1]}let l=Ag(e);for(let c of a.names){let u=l.has(c)?Ft(t,()=>o(c)):o(c);if(u!==null)return u}return a.cwd&&r?s:null}function Vy(e,t){let n=e.argv.slice(1),s=n.some(f=>f==="--symbolic"||/^-[a-zA-Z]*s/.test(f));if(e.name==="ln"?!s:!(["cp","gcp"].includes(e.name)&&n.some(f=>f==="--symbolic-link"||f==="--link"||/^-[a-zA-Z]*[sl]/.test(f))))return[];let r=new Set(["-t","--target-directory","-S","--suffix"]),o=n.filter((f,p)=>!f.startsWith("-")&&!r.has(n[p-1]??"")),a=P(e.argv,"-t","--target-directory"),i=a!==null||o.length===1?o:o.slice(0,-1),l=a??(o.length>=2?o[o.length-1]:"."),c=e.name==="ln"&&!S(l)?M(l,e.cwd,t.ctx):null,u=c===null?[e.cwd]:a!==null||o.length<2?[c]:[R.dirname(c),c];return i.filter(f=>!S(f)).flatMap(f=>(f.startsWith("/")||f.startsWith("~")?[e.cwd]:u).map(p=>M(f,p,t.ctx)))}var Zy=["/Library/Application Support/ClaudeCode","/etc/claude-code","/c/program files/claudecode"];function hu(e,t){if(Bo(e,t.ctx,[t.ctx.home,t.projectRoot,t.base])==="agent")return!0;let n=k(e).replace(/(?<!\/)\/+$/,"").toLowerCase();return[t.ctx.home,t.ctx.claudeConfigDir??null,...Zy].filter(r=>typeof r=="string"&&r.startsWith("/")&&!S(r)).map(r=>r.replace(/(?<!\/)\/+$/,"").toLowerCase()).some(r=>r===n||r.startsWith(`${n}/`)||n==="")}function Vs(e,t=null){return t&&(St(k(e),t)||ir(k(e),t,!0))?_y(e):/(^|\/)\.anvil(\/|$)/.test(e)?`changes Anvil's checks on this agent (${R.basename(e)})`:`changes Claude Code's own permissions, hooks or MCP servers (${R.basename(e)})`}function Vn(e,t,n=[]){let s=[...n].reverse().find(i=>typeof i=="string"&&i.startsWith("/")&&!S(i))??null,r=e.startsWith("/")||e.startsWith("~")?M(e,null,t):s!==null?M(e,s,t):e,{place:o,at:a}=Vo(r,t,[t.home,...n]);return o==="agent"?{action:"claude.agent.controls",service:null,target:a,branch:null,host:null,is_local:!0,why:Vs(a,t)}:o==="jobs"?{action:"claude.bash.persistence",service:null,target:a,branch:null,host:null,is_local:!0,why:`installs or changes a background job (${a})`}:o==="gitconfig"?{action:"claude.bash.persistence",service:null,target:a,branch:null,host:null,is_local:!0,why:`rewrites the global git config (${a})`}:null}var Gy=new Set(["-m","--message","-F","--file","-C","--reuse-message","-c","--reedit-message","--author","--date","--fixup","--squash","--cleanup","-t","--template","--trailer","--pathspec-from-file"]);function Ky(e,t){if(e.name!=="git")return[];let n=_t(e);if(!n||!["add","stage","commit"].includes(n.sub))return[];let s=n.sub==="commit";if(n.args.includes("--dry-run")||!s&&n.args.some(c=>/^-[A-Za-z]*n[A-Za-z]*$/.test(c)))return[];let r=e.via==="find-exec"&&e.parent?.name==="find"?So(e.parent)[0]??null:null,o=[],a=!1;for(let c=0;c<n.args.length;c++){let u=n.args[c];!a&&u==="--"?a=!0:!a&&u.startsWith("-")?(s&&(Gy.has(u)||/^-[A-Za-z]*[mFCct]$/.test(u))||!s&&(u==="--chmod"||u==="--pathspec-from-file"))&&c++:o.push(u==="{}"&&r!==null?r:u)}e.via==="xargs"&&o.push(...vu(e));let i=o.filter(c=>!/^:(!|\^|\([^)]*exclude[^)]*\))/.test(c)).map(c=>c.replace(/^:(\([^)]*\)|\/)?/,"")).flatMap(qn).sort((c,u)=>Number(/key|priv/i.test(u))-Number(/key|priv/i.test(c))).find(c=>Le(c,!0)||t.secretCopies.has(X(c,e.cwd,se(t)).path));if(!i)return[];let l=zt(e,n,t);return l!==null&&kt(l,t)?[]:[m("claude.bash.secrets.expose",`git ${n.sub} ${s?"commits":"stages"} a secrets file (${R.basename(k(i))})`,{target:k(i),is_local:!0})]}function Te(e){return/^(scp|sftp|rsync):\/\//.test(e)||/^[^\s/:=]+:/.test(e)&&!/^[A-Za-z]:\\/.test(e)&&!/^[a-z]+:\/\//i.test(e)}function Zn(e){let t=/^(?:[a-z]+:\/\/)?(?:[^@/:]+@)?(\[[^\]]+\]|[^:/]+)/i.exec(e);return t?t[1]:e}function pe(e,t,n){let s=[];for(let r=t;r<e.length;r++){let o=e[r];if(o==="--"){s.push(...e.slice(r+1));break}o.startsWith("-")&&o!=="-"?n.has(o)&&r++:s.push(o)}return s}var Yy=new Set(["-i","-P","-o","-F","-c","-l","-S","-J","-D","-X"]),Ko=new Set(["-e","--rsh","-f","--filter","--exclude","--include","--files-from","--exclude-from","--include-from","--port","--password-file","-B","--block-size","--bwlimit","--log-file","--partial-dir","-T","--temp-dir","--chmod","--chown","--backup-dir","--suffix","--compare-dest","--link-dest","--copy-dest","--max-size","--min-size","--timeout","-M","--remote-option","--rsync-path"]),Jy=new Set(["-o","-h","-u"]),Xy=new Set(["-B","-b","-c","-D","-E","-e","-F","-I","-i","-J","-L","-l","-m","-O","-o","-p","-Q","-R","-S","-W","-w"]),Qy=new Set(["-B","-b","-c","-D","-F","-i","-J","-l","-o","-P","-R","-S","-s","-X"]),eb=new Set(["-w","-p","-s","-i","-q","-x","-X","-O","-I","-V","-T","-e","-c","-W","-M","-m","-g","-G"]);function tb(e){let t=e.pipeFrom;if(!t)return null;if(er.has(t.name)||["tar","gtar","zip","gzip"].includes(t.name)){let n=(["tar","gtar","zip","gzip"].includes(t.name)?t.argv.slice(1).filter(s=>!s.startsWith("-")):qt(t)).find(s=>Le(s));if(n)return n}return t.stdinFile!==null&&Le(t.stdinFile)?t.stdinFile:null}function nb(e,t){let n=e.argv,s=e.name,r=(c,u)=>[m("claude.bash.secrets.expose",`${s} sends a secrets file (${R.basename(k(c))}) to ${u}`,{target:k(c),host:u,is_local:!1})],o=vu(e),a=(c,u)=>{let f=c.flatMap(h=>h==="{}"&&o.length>0?o:qn(h));if(f.length<2)return[];let p=f[f.length-1],d=f.slice(0,-1).find(h=>Le(h)||t.secretCopies.has(X(h,e.cwd,se(t)).path));return d&&u(p)&&!Re(Zn(p))?r(d,Zn(k(p))):[]},i=e.redirects.find(c=>c.target!==null&&/^\/dev\/(tcp|udp)\/[^/]+\/\d+/.test(c.target)&&[">",">>",">|"].includes(c.op)),l=i?i.target.split("/")[3]:null;if(l!==null&&!Re(l)&&er.has(s)){let c=qt(e).find(u=>Le(u))??(e.stdinFile!==null&&Le(e.stdinFile)?e.stdinFile:null);if(c)return r(c,l)}switch(s){case"scp":return a(pe(n,1,Yy),Te);case"rsync":return a(pe(n,1,Ko),Te);case"rclone":{let c=pe(n,1,new Set(["--config","--exclude","--include","--filter","--transfers","--checkers","--log-file","--bwlimit","--max-age","--min-age","--max-size","--min-size"]));return["copy","copyto","sync","move","moveto","bisync"].includes(c[0]??"")?a(c.slice(1,3),Te):[]}case"gsutil":{let c=pe(n,1,Jy);return["cp","mv","rsync"].includes(c[0]??"")?a(c.slice(1),u=>u.startsWith("gs://")):[]}case"gcloud":{let c=v(n);return c[0]==="compute"&&c[1]==="scp"?a(pe(n,n.indexOf("scp")+1,new Set(["--zone","--project","--ssh-key-file","--scp-flag","--tunnel-through-iap"])),Te):c[0]==="compute"&&c[1]==="ssh"&&e.stdinFile!==null&&Le(e.stdinFile)?r(e.stdinFile,c[2]??"a VM"):c[0]==="storage"&&["cp","mv","rsync"].includes(c[1]??"")?a(c.slice(2),u=>u.startsWith("gs://")):[]}case"az":{let c=v(n);if(c[0]!=="storage")return[];let u=P(n,"-f","--file","-s","--source");return u&&Le(u)&&["blob","file","copy","fs"].includes(c[1]??"")?r(u,"Azure storage"):[]}case"aws":{let c=v(n);return c[0]==="s3"&&["cp","mv","sync"].includes(c[1]??"")?a(wo(n),u=>u.startsWith("s3://")):[]}case"s3cmd":return["put","sync","cp","mv"].includes(v(n)[0]??"")?a(v(n).slice(1),c=>c.startsWith("s3://")):[];case"azcopy":return["copy","cp","sync"].includes(v(n)[0]??"")?a(v(n).slice(1,3),c=>/^https:\/\/[^/]+\.(blob|dfs|file)\.core\.windows\.net\//.test(c)):[];case"mc":return["cp","mv","mirror"].includes(v(n)[0]??"")?a(v(n).slice(1),c=>!/^[./~]/.test(c)&&c.includes("/")):[];case"croc":case"wormhole":case"ffsend":{let c=v(n),u=["send","upload","u"].includes(c[0]??"")?c.slice(1).find(f=>Le(f)):void 0;return u?r(u,`a ${s} relay`):[]}case"kubectl":{let c=v(n);return c[0]==="cp"?a(c.slice(1),u=>/^([^\s/:]+\/)?[^\s/:]+:/.test(u)):[]}case"nc":case"ncat":case"netcat":case"socat":case"telnet":case"ssh":case"sftp":{let c=e.stdinFile!==null&&Le(e.stdinFile)?e.stdinFile:tb(e);s==="socat"&&(c??=n.slice(1).map(h=>/^(FILE|OPEN|GOPEN|READ):([^,]+)/i.exec(h)?.[2]).find(h=>h!==void 0&&Le(h))??null);let u=(e.stdin??"")+(e.pipeFrom&&["echo","printf"].includes(e.pipeFrom.name)?`
|
|
74
|
+
${e.stdin??""}`)){let y=e.argv.slice(1).filter(m=>!/\s/.test(m)&&!m.startsWith("-")).map(m=>M(m,e.cwd,n.ctx)).find(m=>!S(m)&&$t.test(m));y!==void 0&&t.push(w("claude.agent.controls",`changes how every later Claude Code session starts (${O.basename(y)})`,{target:$(y),is_local:!0}))}if(t.length===0&&(e.name==="find"||e.name==="gfind")){let y=Dk(r,n);y!==null&&t.push(w("claude.agent.controls",`${e.name} deletes or changes Claude Code's records of sessions (${y})`,{target:y,is_local:!0}))}if(t.length===0){let y=cv(r,n);y!==null&&t.push(w("claude.agent.controls",jr($(y),n.ctx),{target:$(y),is_local:!0}))}let E=h.find(y=>y.service&&y.op!=="write")??h.find(y=>y.service)??h.find(y=>y.op!=="write")??h[0];return E&&t.push(E),t.filter((y,m)=>t.findIndex(R=>R.action===y.action)===m)}var As=new Set(["mkdir","cat","bat","less","more","head","tail","ls","stat","file","wc","grep","egrep","fgrep","rg","ag","diff","cmp","md5","md5sum","shasum","sha1sum","sha256sum","cksum","jq","du","readlink","realpath","test","[","echo","printf","basename","dirname","od","hexdump","strings","nl","cut","column","cd","pushd","popd","type","which","command","pwd","view","tree","fd","fdfind","shellcheck","open","xdg-open","code","code-insiders","cursor","subl","ccusage"]),nv=new Set(["tee","sponge","truncate","rm","unlink","trash","srm","shred","mkfifo","mknod","touch","cp","gcp","mv","gmv","install","ln","ditto","perl","ruby","yq","dd","awk","gawk","mawk","nawk","base64","openssl","plutil","rsync","scp","sort","chflags","chgrp","chmod","chown"]),sv=new Set(["checkout","switch","restore","reset","stash","pull","merge","rebase","cherry-pick","revert","am","apply","read-tree","checkout-index","clean"]),rv=new Set(["push","reflog","config","ls-remote","add","commit","status","diff","log","show","blame","ls-files","grep","rev-parse","describe","shortlog","cat-file","ls-tree","check-ignore","fetch","remote","branch","tag","update-index"]),ov=new Set(["node","python","python3","bash","sh","zsh","dash","ksh","ruby","perl","deno","bun","php","tsx","ts-node","source","."]),cu=/\bfileinput\.(input|FileInput)\s*\([^)]*inplace\s*=\s*(True|1)|\bunlink\s*\(?\s*['"$]|\bopen\s*\([^)]{0,300}(,\s*|mode\s*=\s*)['"]([wax]|rb?\+)|\.open\s*\(\s*(mode\s*=\s*)?['"]([wax]|rb?\+)|\.write_(text|bytes)\s*\(|\bshutil\.(copy\w*|move|rmtree)\s*\(|\bos\.(rename|replace|remove|unlink|truncate)\s*\(|\.(unlink|rename|touch|rm|rmdir)\s*\(|\b(writeFileSync|writeFile|appendFileSync|appendFile|createWriteStream|copyFileSync|copyFile|cpSync|renameSync|unlinkSync|rmSync|truncateSync)\s*\(|\bFile\.(write|delete|rename)\b|\bFile\.open\s*\([^)]*['"][wa]|\bIO\.write\b|\bFileUtils\.|\bopen\s*\(?\s*(my\s+)?[$\w]+\s*,\s*['"]?\s*(>|\+<)|\bDeno\.(writeTextFile|writeFile|remove|rename)|\bBun\.write\b/;function iv(e,n=null){let t=e.argv.slice(1),s=(...a)=>t.some(i=>a.includes(i)),r=t.filter(a=>!a.startsWith("-"));if(e.name==="fd"||e.name==="fdfind"){let a=t.findIndex(u=>["-x","--exec","-X","--exec-batch"].includes(u));if(a<0)return null;let i=he(t[a+1]??""),l=t[a+2]??"";return i==="node"&&(l==="--check"||l==="-c")||["bash","sh","zsh"].includes(i)&&l==="-n"||As.has(i)?null:{names:t.slice(0,a),cwd:!0}}if(e.name==="tree"&&t.some(a=>a.startsWith("-o")))return{names:[P(e.argv,"-o")??""].filter(Boolean),cwd:!1};if(As.has(e.name)||e.name==="rmdir"||e.name==="inspector"&&/@modelcontextprotocol\/inspector/.test(e.argv[0]??"")||["bash","sh","zsh","dash","ksh"].includes(e.name)&&t[0]==="-n"||e.name==="node"&&s("--check","-c")||e.name==="tsc"&&s("--noEmit")||e.name==="eslint"&&!t.some(a=>a.startsWith("--fix"))||e.name==="ruff"&&t[0]==="check"&&!s("--fix")||["mypy","flake8","pylint","pyright","pytest","vitest","jest","mocha"].includes(e.name)||e.name==="black"&&s("--check")||/^python(3(\.\d+)?)?$/.test(e.name)&&t[0]==="-m"&&["py_compile","compileall","pytest","mypy","unittest"].includes(t[1]??"")||e.name==="prettier"&&s("--check","-c","--list-different","-l")&&!s("--write","-w")||e.name==="xxd"&&!t.some(a=>/^-(r|revert)$/.test(a))||e.name==="xattr"&&!t.some(a=>/^-[a-z]*[wdcr]/.test(a)))return null;if(/^python(3(\.\d+)?)?$/.test(e.name)&&t[0]==="-m"&&t[1]==="json.tool")return{names:t.slice(2).filter((i,l,c)=>!i.startsWith("-")&&c[l-1]!=="--indent").slice(1),cwd:!1};if(e.name==="git")return av(e,t);if(e.name==="find"){let a=t.findIndex(d=>/^-(exec|execdir|ok|okdir)$/.test(d)),i=he(t[a+1]??""),l=t[a+2]??"",c=i==="node"&&(l==="--check"||l==="-c")||["bash","sh","zsh"].includes(i)&&l==="-n",u=t.some(d=>/^-(delete|fprint0?|fprintf|fls)$/.test(d))||a>=0&&!c&&!As.has(he(t[a+1]??"")),p=t.filter((d,f)=>f>0&&["-name","-iname"].includes(t[f-1]));return u&&p.length>0&&p.every(d=>/\.(jsonl|log|tmp)$/i.test(d))?null:u?{names:t,cwd:!0}:null}let o=Ls(e);if(o!==null){let a=t.filter(g=>g!==o),i=e.cwd!==null&&(/\/\.anvil(\/|$)|\/\.claude(\/|$)/.test(e.cwd)||n!==null&&e.cwd.startsWith(n)),l=ra(o.slice(0,65536)),c=/homedir\(|expanduser|Path\.home\(|process\.env\.HOME|environ[^\n]{0,12}HOME|ENV\[['"]HOME/.test(l),u=[...l.matchAll(/(?:[(,=[]|\b(?:unlink|rmtree|rename|truncate|open)\s)\s*(['"`])([^'"`\n]*(?:\.anvil|\.claude|\.mcp\.json)[^'"`\n]*)\1/g)].flatMap(g=>{let b=g.index+g[0].length,k=/^(?:\s*[,/]\s*(['"])([^'"\n]+)\1)+/.exec(l.slice(b,b+512))?.[0]??"",E=[g[2],...[...k.matchAll(/(['"])([^'"\n]+)\1/g)].map(m=>m[2])].join("/").replace(/\/{2,}/g,"/");if(/^(\/|~\/)/.test(E))return[E];if(/^\$\{?HOME\}?\//.test(E))return[E.replace(/^\$\{?HOME\}?/,"~")];if(/^\$ENV\{['"]?HOME['"]?\}\//.test(E))return[E.replace(/^\$ENV\{['"]?HOME['"]?\}/,"~")];let y=E.replace(/^\$\{[^}]*\}\/?/,"");return c&&/^\.(anvil|claude|mcp\.json)(\/|\.json|$)/.test(y)?[`~/${y}`]:[]}),p={n:0},d=yf(l,{hit:!1},p),h=d.length>0&&p.n===0&&d.every(g=>!S(g.path)&&!/\.anvil|\.claude|\.mcp\.json|LaunchAgents|LaunchDaemons|\.gitconfig/.test(g.path))?[]:u;return(i||h.length>0||a.some(g=>/\.claude|\.anvil|\.mcp\.json|managed-/.test(g)))&&cu.test(l)?{names:[...a,...h],cwd:!0}:null}if(ov.has(e.name)){let a=t.indexOf("-");if(a>=0)return e.stdin!==null&&!cu.test(e.stdin.slice(0,65536))?null:{names:t.slice(a+1),cwd:!1};let i=t.indexOf("-m");if(i>=0)return{names:t.slice(i+2),cwd:!1};let l=t.findIndex(c=>!c.startsWith("-"));return l<0?null:{names:t.slice(l+1).filter(c=>!/(^|\/)\.(claude|anvil)\/?$/.test(c)),cwd:!1}}if(e.name==="uniq")return{names:r.slice(1,2),cwd:!1};if(e.name==="zip")return{names:r.slice(0,1),cwd:!1};if(["tar","bsdtar","gtar"].includes(e.name)){let a=t[0]&&!t[0].startsWith("--")?t[0].replace(/^-/,""):"";if(/t/.test(a)||s("--list"))return null;if(/x/.test(a)||s("--extract","--get"))return{names:t,cwd:!0};let i=P(e.argv,"-f","--file")??(/f/.test(a)?t[1]??null:null);return{names:i?[i]:[],cwd:!1}}if(/^7z[arz]?$/.test(e.name)){if(["l","t","i","h"].includes(t[0]??""))return null;if(["x","e"].includes(t[0]??"")){let a=t.filter(i=>i.startsWith("-o")).map(i=>i.slice(2));return{names:a,cwd:a.length===0}}return{names:r.slice(1,2),cwd:!1}}if(e.name==="unzip"){if(t.some(i=>/^-[a-zA-Z]*[ltvZp]/.test(i)))return null;let a=P(e.argv,"-d");return{names:a?[a]:[],cwd:a===null}}if(e.name==="patch"){let a=P(e.argv,"-d","--directory"),i=lf(af(e));return{names:[P(e.argv,"-o","--output")??"",...i,...a?i.map(l=>`${a.replace(/(?<!\/)\/+$/,"")}/${l}`):[]].filter(Boolean),cwd:!0}}return["sed","gsed","vim","vi","nvim","ex","ed","red","emacs"].includes(e.name)?["vim","vi","nvim"].includes(e.name)&&s("-R")?null:{names:t.flatMap(a=>[...a.matchAll(/(?:^|[\s;:|{}\/!%,$\d])(?:w|W|wq|x|write|sav|saveas)!?\s*(?:>>\s*)?([~\/.][^\s;|}]*)/g)].map(i=>i[1])),cwd:!1}:e.name==="curl"?{names:t,cwd:t.some(a=>/^-[a-zA-Z]*[OJ]|^--(remote-name|remote-header-name|output-dir)/.test(a))}:e.name==="wget"?{names:t,cwd:!t.some((a,i)=>(a==="-O"||a==="--output-document")&&t[i+1]==="-"||/^-[a-zA-Z]*O-$/.test(a))}:nv.has(e.name)?{names:[],cwd:!1}:{names:t,cwd:!0}}function af(e){if(e.stdin!==null)return e.stdin;let n=e.pipeFrom;if(!n)return null;if(["cat","echo","printf"].includes(n.name))return n.stdin??n.argv.slice(1).join(`
|
|
75
|
+
`);if(n.name==="git"&&n.argv[1]==="diff"){let t=n.argv.indexOf("--");return t<0?null:n.argv.slice(t+1).map(s=>`+++ ${s}`).join(`
|
|
76
|
+
`)}return null}function lf(e){return e===null?[]:[...e.slice(0,262144).matchAll(/^(?:---|\+\+\+)\s+(\S+)/gm)].map(n=>n[1]).filter(n=>n!=="/dev/null").flatMap(n=>/^[ab]\//.test(n)?[n,n.slice(2)]:[n])}function av(e,n){let t=[],s=0;for(;s<n.length&&n[s].startsWith("-");s++){let i=n[s];if(i==="-C"||i==="--work-tree"||i==="--git-dir")t.push(n[++s]??"");else if(i==="-c"){let l=n[++s]??"";/^core\.worktree=/i.test(l)&&t.push(l.slice(l.indexOf("=")+1))}else(i.startsWith("--work-tree=")||i.startsWith("--git-dir="))&&t.push(i.slice(i.indexOf("=")+1))}for(let i of e.text.matchAll(/\bGIT_(?:WORK_TREE|DIR)=("[^"]*"|'[^']*'|[^\s;&|]+)/g))t.push(i[1].replace(/^["']|["']$/g,""));let r=n[s]??"",o=n.slice(s+1);if(r==="stash"&&["list","show"].includes(o[0]??"")||r==="worktree"&&(o[0]??"")==="list"||r==="apply"&&o.some(i=>["--check","--stat","--numstat","--summary"].includes(i)))return null;if(r==="apply"||r==="am")return{names:[...t,...o,...lf(af(e))],cwd:!0};let a=r==="restore"&&o.some(i=>i==="--staged"||i==="-S")&&!o.some(i=>i==="--worktree"||i==="-W")||r==="reset"&&!o.some(i=>i==="--hard"||i==="--merge"||i==="--keep")||r==="rm"&&o.includes("--cached");return rv.has(r)||a?null:{names:[...t,...t.length===0&&e.cwd!==null?[e.cwd]:[],...o],cwd:!0}}function lv(e){let n=t=>{if(/[\s"']/.test(t))return!1;let s=t.indexOf("{"),r=s<0?-1:t.indexOf(",",s+1);return r>s&&t.lastIndexOf("}")>r};return e.argv.slice(1).some(n)?{...e,argv:[e.argv[0],...e.argv.slice(1).flatMap(t=>n(t)?cf(t):[t])].slice(0,256)}:e}function cf(e){if(!e.includes("{"))return[e];let n=[],t=[e];for(let s=0;t.length>0&&n.length<64&&s<256;s++){let r=t.shift(),o=r.indexOf("{"),a=-1,i=[];for(let c=o,u=0;o>=0&&c<r.length;c++)if(r[c]==="{")u++;else if(r[c]==="}"&&--u===0){a=c;break}else r[c]===","&&u===1&&i.push(c);if(o<0||a<0||i.length===0){n.push(r);continue}let l=[o,...i,a];for(let c=0;c+1<l.length;c++)t.push(r.slice(0,o)+r.slice(l[c]+1,l[c+1])+r.slice(a+1))}return n.length>0?n:[e]}function na(e){let n=/^[*?[]/.test(e)?"(?!\\.)":"";for(let t=0;t<e.length;t++){let s=e[t];if(s==="*")n+="[^/]*";else if(s==="?")n+="[^/]";else if(s==="["){let r=e.indexOf("]",t+2);r<0?n+="\\[":(n+=`[${e.slice(t+1,r).replace(/^!/,"^").replace(/\\/g,"\\\\")}]`,t=r)}else n+=s.replace(/[.+^${}()|\\]/g,"\\$&")}try{return new RegExp(`^${n}$`)}catch{return new RegExp(`^${e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}$`)}}function uf(e,n){let t=[...new Set(n.filter(o=>typeof o=="string"&&o.startsWith("/")&&!S(o)).map(o=>o.replace(/(?<!\/)\/+$/,"")))],s=e.claudeConfigDir&&!S(e.claudeConfigDir)?e.claudeConfigDir.replace(/(?<!\/)\/+$/,""):null,r=e.home.replace(/(?<!\/)\/+$/,"");return{files:[...t.flatMap(o=>[`${o}/.claude/settings.json`,`${o}/.claude/settings.local.json`,`${o}/.claude.json`,`${o}/.mcp.json`,`${o}/.claude`]),`${r}/.anvil`,`${r}/.anvil/rules.json`,`${r}/.anvil/rules.md`,`${r}/.anvil/workspace-keys.json`,`${r}/.anvil/telemetry-notice`,...s?[s,`${s}/settings.json`,`${s}/settings.local.json`,`${s}/.claude.json`]:[]],folders:[...t.flatMap(o=>[`${o}/.claude/hooks`,`${o}/.claude/plugins`]),`${r}/.anvil/claude`,...s?[`${s}/hooks`,`${s}/plugins`]:[]]}}function df(e,n,t,s=!0){let r=[];for(let o of cf(e)){if(!/[*?[]/.test(o)||s&&Mt($(o),n,s===!0)){Ji(o,n,t,s)==="agent"&&r.push(o);continue}if(s&&Xr($(o),n,s===!0)){r.push(o);continue}let a=o.split("/"),i=a.map(na),l=(p,d)=>{let f=p.split("/");return(d?a.length>f.length:a.length===f.length)&&f.every((h,g)=>i[g].test(h))},c=uf(n,t),u=c.files.find(p=>l(p,!1))??c.folders.find(p=>l(p,!1)||l(p,!0));u!==void 0&&r.push(u)}return r}function cv(e,n){let t=[n.ctx.home,n.projectRoot,n.base],s=e.cwd!==null&&!S(e.cwd)?e.cwd.replace(/(?<!\/)\/+$/,""):null,r=s!==null&&uf(n.ctx,t).folders.some(c=>s===c||s.startsWith(`${c}/`)),o=c=>{if(c.startsWith("-")&&!c.includes("=")&&!/[~/]/.test(c))return null;let u=c.startsWith("-")?c.includes("=")?c.slice(c.indexOf("=")+1):c.slice(Math.max(0,c.search(/[~/]/))):c,p=/^(\/|~|\.\.?\/)/.test(u)||!/\s/.test(u)&&(/^\.[\w-]/.test(u)||u.includes("/")||/^[\w.-]+$/.test(u));return!u||S(u)&&!u.startsWith("/")||!p?null:df(M(u,e.cwd,n.ctx),n.ctx,t,!1)[0]??null};for(let c of e.wrapperArgs){let u=o(c);if(u!==null)return u}let a=iv(e,n.ctx.claudeConfigDir&&!S(n.ctx.claudeConfigDir)?n.ctx.claudeConfigDir.replace(/(?<!\/)\/+$/,""):null);if(a===null)return null;let i=n.ctx.home.replace(/(?<!\/)\/+$/,"");if(e.name==="git"&&sv.has(Xe(e)?.sub??""))for(let c of a.names){if(S(c))continue;let u=M(c,e.cwd,n.ctx).replace(/(?<!\/)\/+$/,"");if(u===i)return`${i}/.claude`;let p=Object.entries(n.ctx.controlLinks??{}).find(([d])=>d.startsWith(`${u}/`));if(p)return p[1]}let l=yb(e);for(let c of a.names){let u=l.has(c)?rn(n,()=>o(c)):o(c);if(u!==null)return u}return a.cwd&&r?s:null}function uv(e,n){let t=e.argv.slice(1),s=t.some(p=>p==="--symbolic"||/^-[a-zA-Z]*s/.test(p));if(e.name==="ln"?!s:!(["cp","gcp"].includes(e.name)&&t.some(p=>p==="--symbolic-link"||p==="--link"||/^-[a-zA-Z]*[sl]/.test(p))))return[];let r=new Set(["-t","--target-directory","-S","--suffix"]),o=t.filter((p,d)=>!p.startsWith("-")&&!r.has(t[d-1]??"")),a=P(e.argv,"-t","--target-directory"),i=a!==null||o.length===1?o:o.slice(0,-1),l=a??(o.length>=2?o[o.length-1]:"."),c=e.name==="ln"&&!S(l)?M(l,e.cwd,n.ctx):null,u=c===null?[e.cwd]:a!==null||o.length<2?[c]:[O.dirname(c),c];return i.filter(p=>!S(p)).flatMap(p=>(p.startsWith("/")||p.startsWith("~")?[e.cwd]:u).map(d=>M(p,d,n.ctx)))}var dv=["/Library/Application Support/ClaudeCode","/etc/claude-code","/c/program files/claudecode"];function ff(e,n){if(Ji(e,n.ctx,[n.ctx.home,n.projectRoot,n.base])==="agent")return!0;let t=$(e).replace(/(?<!\/)\/+$/,"").toLowerCase();return[n.ctx.home,n.ctx.claudeConfigDir??null,...dv].filter(r=>typeof r=="string"&&r.startsWith("/")&&!S(r)).map(r=>r.replace(/(?<!\/)\/+$/,"").toLowerCase()).some(r=>r===t||r.startsWith(`${t}/`)||t==="")}function jr(e,n=null){return n&&(Mt($(e),n)||Xr($(e),n,!0))?Lk(e):/(^|\/)\.anvil(\/|$)/.test(e)?`changes Anvil's checks on this agent (${O.basename(e)})`:`changes Claude Code's own permissions, hooks or MCP servers (${O.basename(e)})`}function Es(e,n,t=[]){let s=[...t].reverse().find(i=>typeof i=="string"&&i.startsWith("/")&&!S(i))??null,r=e.startsWith("/")||e.startsWith("~")?M(e,null,n):s!==null?M(e,s,n):e,{place:o,at:a}=Xi(r,n,[n.home,...t]);return o==="agent"?{action:"claude.agent.controls",service:null,target:a,branch:null,host:null,is_local:!0,why:jr(a,n)}:o==="jobs"?{action:"claude.bash.persistence",service:null,target:a,branch:null,host:null,is_local:!0,why:`installs or changes a background job (${a})`}:o==="gitconfig"?{action:"claude.bash.persistence",service:null,target:a,branch:null,host:null,is_local:!0,why:`rewrites the global git config (${a})`}:null}var fv=new Set(["-m","--message","-F","--file","-C","--reuse-message","-c","--reedit-message","--author","--date","--fixup","--squash","--cleanup","-t","--template","--trailer","--pathspec-from-file"]);function pv(e,n){if(e.name!=="git")return[];let t=Xe(e);if(!t||!["add","stage","commit"].includes(t.sub))return[];let s=t.sub==="commit";if(t.args.includes("--dry-run")||!s&&t.args.some(c=>/^-[A-Za-z]*n[A-Za-z]*$/.test(c)))return[];let r=e.via==="find-exec"&&e.parent?.name==="find"?Ri(e.parent)[0]??null:null,o=[],a=!1;for(let c=0;c<t.args.length;c++){let u=t.args[c];!a&&u==="--"?a=!0:!a&&u.startsWith("-")?(s&&(fv.has(u)||/^-[A-Za-z]*[mFCct]$/.test(u))||!s&&(u==="--chmod"||u==="--pathspec-from-file"))&&c++:o.push(u==="{}"&&r!==null?r:u)}e.via==="xargs"&&o.push(...wf(e));let i=o.filter(c=>!/^:(!|\^|\([^)]*exclude[^)]*\))/.test(c)).map(c=>c.replace(/^:(\([^)]*\)|\/)?/,"")).flatMap(It).sort((c,u)=>Number(/key|priv/i.test(u))-Number(/key|priv/i.test(c))).find(c=>Ze(c,!0)||n.secretCopies.has(te(c,e.cwd,le(n)).path));if(!i)return[];let l=Ln(e,t,n);return l!==null&&vt(l,n)?[]:[w("claude.bash.secrets.expose",`git ${t.sub} ${s?"commits":"stages"} a secrets file (${O.basename($(i))})`,{target:$(i),is_local:!0})]}function Ye(e){return/^(scp|sftp|rsync):\/\//.test(e)||/^[^\s/:=]+:/.test(e)&&!/^[A-Za-z]:\\/.test(e)&&!/^[a-z]+:\/\//i.test(e)}function Rs(e){let n=/^(?:[a-z]+:\/\/)?(?:[^@/:]+@)?(\[[^\]]+\]|[^:/]+)/i.exec(e);return n?n[1]:e}function ke(e,n,t){let s=[];for(let r=n;r<e.length;r++){let o=e[r];if(o==="--"){s.push(...e.slice(r+1));break}o.startsWith("-")&&o!=="-"?t.has(o)&&r++:s.push(o)}return s}var hv=new Set(["-i","-P","-o","-F","-c","-l","-S","-J","-D","-X"]),sa=new Set(["-e","--rsh","-f","--filter","--exclude","--include","--files-from","--exclude-from","--include-from","--port","--password-file","-B","--block-size","--bwlimit","--log-file","--partial-dir","-T","--temp-dir","--chmod","--chown","--backup-dir","--suffix","--compare-dest","--link-dest","--copy-dest","--max-size","--min-size","--timeout","-M","--remote-option","--rsync-path"]),gv=new Set(["-o","-h","-u"]),mv=new Set(["-B","-b","-c","-D","-E","-e","-F","-I","-i","-J","-L","-l","-m","-O","-o","-p","-Q","-R","-S","-W","-w"]),yv=new Set(["-B","-b","-c","-D","-F","-i","-J","-l","-o","-P","-R","-S","-s","-X"]),bv=new Set(["-w","-p","-s","-i","-q","-x","-X","-O","-I","-V","-T","-e","-c","-W","-M","-m","-g","-G"]);function wv(e){let n=e.pipeFrom;if(!n)return null;if(zr.has(n.name)||["tar","gtar","zip","gzip"].includes(n.name)){let t=(["tar","gtar","zip","gzip"].includes(n.name)?n.argv.slice(1).filter(s=>!s.startsWith("-")):Jr(n)).find(s=>Ze(s));if(t)return t}return n.stdinFile!==null&&Ze(n.stdinFile)?n.stdinFile:null}function kv(e,n){let t=e.argv,s=e.name,r=(c,u)=>[w("claude.bash.secrets.expose",`${s} sends a secrets file (${O.basename($(c))}) to ${u}`,{target:$(c),host:u,is_local:!1})],o=wf(e),a=(c,u)=>{let p=c.flatMap(h=>h==="{}"&&o.length>0?o:It(h));if(p.length<2)return[];let d=p[p.length-1],f=p.slice(0,-1).find(h=>Ze(h)||n.secretCopies.has(te(h,e.cwd,le(n)).path));return f&&u(d)&&!qe(Rs(d))?r(f,Rs($(d))):[]},i=e.redirects.find(c=>c.target!==null&&/^\/dev\/(tcp|udp)\/[^/]+\/\d+/.test(c.target)&&[">",">>",">|"].includes(c.op)),l=i?i.target.split("/")[3]:null;if(l!==null&&!qe(l)&&zr.has(s)){let c=Jr(e).find(u=>Ze(u))??(e.stdinFile!==null&&Ze(e.stdinFile)?e.stdinFile:null);if(c)return r(c,l)}switch(s){case"scp":return a(ke(t,1,hv),Ye);case"rsync":return a(ke(t,1,sa),Ye);case"rclone":{let c=ke(t,1,new Set(["--config","--exclude","--include","--filter","--transfers","--checkers","--log-file","--bwlimit","--max-age","--min-age","--max-size","--min-size"]));return["copy","copyto","sync","move","moveto","bisync"].includes(c[0]??"")?a(c.slice(1,3),Ye):[]}case"gsutil":{let c=ke(t,1,gv);return["cp","mv","rsync"].includes(c[0]??"")?a(c.slice(1),u=>u.startsWith("gs://")):[]}case"gcloud":{let c=_(t);return c[0]==="compute"&&c[1]==="scp"?a(ke(t,t.indexOf("scp")+1,new Set(["--zone","--project","--ssh-key-file","--scp-flag","--tunnel-through-iap"])),Ye):c[0]==="compute"&&c[1]==="ssh"&&e.stdinFile!==null&&Ze(e.stdinFile)?r(e.stdinFile,c[2]??"a VM"):c[0]==="storage"&&["cp","mv","rsync"].includes(c[1]??"")?a(c.slice(2),u=>u.startsWith("gs://")):[]}case"az":{let c=_(t);if(c[0]!=="storage")return[];let u=P(t,"-f","--file","-s","--source");return u&&Ze(u)&&["blob","file","copy","fs"].includes(c[1]??"")?r(u,"Azure storage"):[]}case"aws":{let c=_(t);return c[0]==="s3"&&["cp","mv","sync"].includes(c[1]??"")?a($i(t),u=>u.startsWith("s3://")):[]}case"s3cmd":return["put","sync","cp","mv"].includes(_(t)[0]??"")?a(_(t).slice(1),c=>c.startsWith("s3://")):[];case"azcopy":return["copy","cp","sync"].includes(_(t)[0]??"")?a(_(t).slice(1,3),c=>/^https:\/\/[^/]+\.(blob|dfs|file)\.core\.windows\.net\//.test(c)):[];case"mc":return["cp","mv","mirror"].includes(_(t)[0]??"")?a(_(t).slice(1),c=>!/^[./~]/.test(c)&&c.includes("/")):[];case"croc":case"wormhole":case"ffsend":{let c=_(t),u=["send","upload","u"].includes(c[0]??"")?c.slice(1).find(p=>Ze(p)):void 0;return u?r(u,`a ${s} relay`):[]}case"kubectl":{let c=_(t);return c[0]==="cp"?a(c.slice(1),u=>/^([^\s/:]+\/)?[^\s/:]+:/.test(u)):[]}case"nc":case"ncat":case"netcat":case"socat":case"telnet":case"ssh":case"sftp":{let c=e.stdinFile!==null&&Ze(e.stdinFile)?e.stdinFile:wv(e);s==="socat"&&(c??=t.slice(1).map(h=>/^(FILE|OPEN|GOPEN|READ):([^,]+)/i.exec(h)?.[2]).find(h=>h!==void 0&&Ze(h))??null);let u=(e.stdin??"")+(e.pipeFrom&&["echo","printf"].includes(e.pipeFrom.name)?`
|
|
68
77
|
${e.pipeFrom.argv.slice(1).join(" ").replace(/\\n/g,`
|
|
69
|
-
`)}`:"");if(s==="sftp"&&(c??=[...u.matchAll(/(?:^|\n|;)\s*put\s+(?:-\w+\s+)*(\S+)/g)].map(h=>h[1]).find(h=>
|
|
70
|
-
`),
|
|
71
|
-
`):"";return u[0]==="query"&&Fn(ke(f,"bigquery"))&&ht(e)?[m("claude.bash.data.export","bq query copies table rows onto this machine",{target:"bigquery",host:"bigquery",is_local:!1})]:[]}case"gsutil":case"gcloud":{if(re("compute","ssh")(n)&&/\b(pg_dump|pg_dumpall|mysqldump|mongodump|mongoexport)\b/.test(P(n,"--command")??"")&&ht(e))return[m("claude.bash.data.export","dumps a database on a VM and streams it onto this machine",{target:"gcloud compute ssh",host:"gcloud",is_local:!1})];let u=v(n),f=s==="gsutil"?u.slice(1):u[0]==="storage"?u.slice(2):[],p=s==="gsutil"?u[0]:u[1];return["cp","rsync"].includes(p??"")&&f.length>=2&&f[0].startsWith("gs://")&&!f[f.length-1].startsWith("gs://")&&/\bbq\s+extract\b/.test(t.lineText)?[m("claude.bash.data.export","downloads a table the line exported from BigQuery",{target:f[0],host:"bigquery",is_local:!1})]:[]}case"wrangler":return v(n)[0]==="d1"&&v(n)[1]==="export"&&T(n,"--remote")&&!T(n,"--no-data")?[m("claude.bash.data.export","wrangler d1 export copies a remote D1 database onto this machine",{target:"d1",host:"cloudflare",is_local:!1})]:[];case"pscale":return re("database","dump")(n)?[m("claude.bash.data.export","pscale database dump copies a PlanetScale database onto this machine",{target:"planetscale",host:"planetscale",is_local:!1})]:[];case"turso":return re("db","shell")(n)&&n.some(u=>u===".dump")?[m("claude.bash.data.export","turso db shell .dump copies a Turso database onto this machine",{target:"turso",host:"turso",is_local:!1})]:[];case"aws":return re("dynamodb","scan")(n)&&ht(e)?[m("claude.bash.data.export","aws dynamodb scan copies a table onto this machine",{target:"dynamodb",host:"dynamodb",is_local:!1})]:[];case"curl":case"wget":return/\bheroku\s+pg:backups:url\b/.test(t.lineText)?[m("claude.bash.data.export","downloads a Heroku production backup onto this machine",{target:"heroku",host:"heroku",is_local:!1})]:[];case"fly":case"flyctl":{let u=P(n,"-C","--command")??"";return re("ssh","console")(n)&&/\b(pg_dump|pg_dumpall|mysqldump|mongodump|mongoexport)\b/.test(u)?[m("claude.bash.data.export","dumps a Fly database and streams it onto this machine",{target:"fly",host:"fly",is_local:!1})]:[]}case"heroku":return/^pg:(pull|backups:download)$/.test(v(n)[0]??"")?[m("claude.bash.data.export",`heroku ${v(n)[0]} copies a production database onto this machine`,{target:"heroku",host:"heroku",is_local:!1})]:[];case"supabase":return re("db","dump")(n)&&T(n,"--data-only")&&!T(n,"--local")&&!Ic(n)?[m("claude.bash.data.export","supabase db dump copies a linked database's data onto this machine",{target:"supabase",host:"supabase",is_local:!1})]:[];default:return[]}let a=e.remote===null||e.remote.startsWith("container:"),i=yt(t.lineText),l=r===null||!S(r)&&Ut(r);if(o&&!e.productionEnv&&a&&l&&i===null)return[];let c=i!==null&&l?`a database forwarded here (${i})`:r?fn(r):e.productionEnv?"production (railway run)":e.remote??"a database the command does not name";return[m("claude.bash.data.export",`${s} copies the data of ${c} onto this machine`,{target:c,host:r?fn(r):e.remote,is_local:!1})]}var ib=/^((https?|wss?):\/\/)?(localhost|127\.0\.0\.1|0\.0\.0\.0|\[::1\]|anvil|hardhat|ganache)\b|^(localhost|hardhat|anvil|ganache|localnet|local|development|l)$/i,Nl=/sepolia|holesky|hoodi|goerli|rinkeby|ropsten|kovan|testnet|devnet|localnet|amoy|mumbai|fuji|chapel|alfajores|chiado|moonbase|baobab|calibration|shasta|nile|bepolia|hekla|garnet|cardona|fork|^d$|^t$/i,Ll=/0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80|0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d/i;function Ue(e){if(e===null)return!1;let t=k(e).replace(/^["']|["']$/g,""),n=/^([a-z][a-z0-9+.-]*:\/\/)?([^/?#\s]+)([^?#\s]*)/i.exec(t);if(n&&(n[1]||n[3])){let s=n[2].replace(/:\d+$/,"").replace(/^[^@]*@/,"").toLowerCase();return/^(localhost|127\.0\.0\.1|0\.0\.0\.0|\[::1\]|anvil|hardhat|ganache|host\.docker\.internal)$/.test(s)?!0:Nl.test(`${s}${n[3]}`)}return ib.test(t)||Nl.test(t)}function Tl(e,t){let n=e.argv,s=v(n),r=i=>i===null?null:fn(i),o=(i,l)=>[m("claude.bash.crypto.transaction",`${i} on ${r(l)??"a network the command does not name"}`,{target:`${e.name} ${s[0]??""}`.trim(),host:r(l),is_local:!1})],a=()=>P(n,"--rpc-url","-r","--fork-url",...e.name==="forge"?["-f"]:[])??/(?:^|[\s;&|(])(?:export\s+)?ETH_RPC_URL=["']?([^\s"';&|)]+)/.exec(t.lineText)?.[1]??null;switch(e.name){case"cast":{if(!(["send","s","publish"].includes(s[0]??"")||s[0]==="rpc"&&/^(eth_sendRawTransaction|eth_sendTransaction|personal_sendTransaction)$/.test(s[1]??"")))return[];let l=a();return Ue(l)||l===null&&Ll.test(n.join(" "))?[]:o(`cast ${s[0]} sends a transaction`,l)}case"forge":{if(!(s[0]==="script"&&T(n,"--broadcast","--resume")||s[0]==="create"))return[];let l=a();return Ue(l)||l===null&&Ll.test(n.join(" "))?[]:o(`forge ${s[0]} ${s[0]==="create"?"deploys a contract":"broadcasts transactions"}`,l)}case"solana":case"spl-token":{if(!(e.name==="solana"?["transfer","deploy","pay","delegate-stake","deactivate-stake","withdraw-stake","create-stake-account","split-stake","merge-stake","withdraw-from-vote-account","close-vote-account"].includes(s[0]??"")||s[0]==="program"&&["deploy","close","set-upgrade-authority","extend","write-buffer","upgrade"].includes(s[1]??""):["transfer","mint","burn","close","authorize","approve","create-token","create-account","wrap","unwrap","freeze","thaw"].includes(s[0]??"")))return[];let l=P(n,"--url","-u")??/\bsolana\s+config\s+set\s+(?:--url|-u)\s+(\S+)/.exec(t.lineText)?.[1]??null,c={m:"mainnet-beta",d:"devnet",t:"testnet",l:"localhost"};return Ue(l)?[]:o(`${e.name} ${s[0]} sends a transaction`,l===null?null:c[l]??l)}case"anchor":{if(!["deploy","upgrade","migrate"].includes(s[0]??""))return[];let i=P(n,"--provider.cluster");return Ue(i)?[]:o(`anchor ${s[0]} deploys a program`,i)}case"bitcoin-cli":case"lncli":{let i=pe(n,1,new Set(["--network","--rpcserver","--macaroonpath","--tlscertpath","--lnddir","--chain","--profile"]))[0]??"";if(!(e.name==="bitcoin-cli"?["sendtoaddress","sendmany","send","sendall","sendrawtransaction","bumpfee"].includes(i):["sendpayment","payinvoice","sendcoins","sendmany","openchannel","closechannel","closeallchannels","sendtoroute"].includes(i)))return[];let c=n.find(f=>/^-(regtest|testnet|testnet4|signet)$|^--?(chain|network)=/.test(f))??(P(n,"--network","--chain")!==null?`--network=${P(n,"--network","--chain")}`:null);return c!==null&&/regtest|testnet|signet|(chain|network)=(test|regtest|signet|simnet)/i.test(c)?[]:o(`${e.name} ${i} sends a payment`,c===null?"mainnet":c)}case"near":{let i=["deploy","send","send-near","call","delete","delete-account","stake","contract","tokens","transaction"].includes(s[0]??""),l=n.some(c=>/mainnet/i.test(c)||/\.near$/.test(c))||/\bNEAR_ENV=mainnet\b/.test(t.lineText);return i&&l?o(`near ${s[0]} sends a transaction`,"mainnet"):[]}case"starkli":{if(!["invoke","deploy","declare","transfer"].includes(s[0]??"")&&!(s[0]==="account"&&s[1]==="deploy"))return[];let i=P(n,"--network","--rpc");return Ue(i)?[]:o(`starkli ${s[0]} sends a transaction`,i)}case"stellar":case"soroban":{if(!(s[0]==="contract"&&["invoke","deploy","install","upload","extend","restore"].includes(s[1]??"")||s[0]==="tx"&&["send","new"].includes(s[1]??"")))return[];let l=P(n,"--network","--rpc-url");return l!==null&&/^(testnet|futurenet|local|standalone)$/i.test(l)?[]:Ue(l)?[]:o(`${e.name} ${s[0]} ${s[1]} sends a transaction`,l)}case"cardano-cli":return n.includes("submit")?n.some(i=>i==="--testnet-magic"||i.startsWith("--testnet-magic="))?[]:o("cardano-cli submits a transaction",n.includes("--mainnet")?"mainnet":null):[];case"sui":{if(!(s[0]==="client"&&["publish","upgrade","transfer","transfer-sui","pay","pay-sui","pay-all-sui","call","split-coin","merge-coin","ptb"].includes(s[1]??"")))return[];let l=P(n,"--client.env")??/\bsui\s+client\s+switch\s+--env\s+(\S+)/.exec(t.lineText)?.[1]??null;return Ue(l)?[]:o(`sui client ${s[1]} sends a transaction`,l)}case"aptos":{if(!(s[0]==="move"&&["publish","run","deploy-object","upgrade-object","create-object-and-publish-package","run-script"].includes(s[1]??"")||s[0]==="account"&&["transfer"].includes(s[1]??"")))return[];let l=P(n,"--profile","--url")??null;return Ue(l)?[]:o(`aptos ${s[0]} ${s[1]} sends a transaction`,l)}case"ape":{if(s[0]!=="run")return[];let i=P(n,"--network");return i===null||Ue(i)?[]:o(`ape run ${s[1]??""} sends transactions`,i)}case"hardhat":case"truffle":case"brownie":{let i=s[0]==="ignition"?s[1]??"":s[0]??"";if(!(["run","deploy","migrate"].includes(i)||/deploy|mint|transfer|send|upgrade|migrat|withdraw|airdrop|burn|propose|execute/i.test(i)))return[];let c=P(n,"--network")??(e.name==="hardhat"?/(?:^|[\s;&|(])(?:export\s+)?HARDHAT_NETWORK=["']?([^\s"';&|)]+)/.exec(t.lineText)?.[1]??null:null);return c===null||Ue(c)?[]:o(`${e.name} ${i} sends transactions`,c)}default:{if(/^[a-z]+d$/.test(e.name)&&s[0]==="tx"&&!T(n,"--generate-only","--dry-run")){let i=P(n,"--chain-id"),l=P(n,"--node");return i!==null&&/test|devnet|local/i.test(i)||l!==null&&Ue(l)?[]:o(`${e.name} tx ${s[1]??""} broadcasts a transaction`,i??l)}return[]}}}var gt=(e,...t)=>e.some(n=>t.some(s=>new RegExp(`^(?:/{1,2}|-)${s}(?::.*)?$`,"i").test(n))),ro=(e,...t)=>{for(let n=0;n<e.length;n++)for(let s of t){let r=new RegExp(`^(?:/{1,2}|-)${s}(?::(.*))?$`,"i").exec(e[n]);if(r)return r[1]??e[n+1]??null}return null},Il=/[\\/](?:Run|RunOnce|RunServices|RunServicesOnce)\b|[\\/]Winlogon\b|[\\/]Services[\\/]|[\\/]Image File Execution Options[\\/]|[\\/]Explorer[\\/]Shell Folders|[\\/]Policies[\\/]Explorer[\\/]Run|^(?:Registry::)?HK(?:CU|EY_CURRENT_USER):?[\\/]Environment\b|[\\/]Session Manager[\\/]Environment\b|[\\/]Command Processor\b/i,ab=new Set(["format","format-volume","clear-disk","initialize-disk","remove-partition","clear-recyclebin","diskpart","vssadmin","wmic","wbadmin","wsl","bcdedit","reg","set-itemproperty","new-itemproperty","remove-itemproperty","remove-item","sc","new-service","remove-service","set-service","stop-service","register-scheduledtask","set-scheduledtask","unregister-scheduledtask","new-scheduledtask","set-executionpolicy","set-mppreference","add-mppreference","netsh","set-netfirewallprofile","new-netfirewallrule","disable-netfirewallrule","remove-netfirewallrule","takeown","icacls","taskkill","runas","gsudo","mountvol","robocopy","setx","forfiles"]);function lb(e,t){let n=e.argv.slice(1),s=n.join(" "),r={is_local:e.remote===null,host:e.remote},o=(a,i,l={})=>[m(a,i,{target:e.argv.slice(0,4).join(" "),...r,...l})];switch(e.name){case"format":case"format-volume":case"clear-disk":case"initialize-disk":case"remove-partition":return n.length>0||e.name!=="format"?o("claude.bash.fs.delete_recursive",`formats or wipes a drive (${e.name})`,{service:"fs.device"}):[];case"diskpart":return o("claude.bash.fs.delete_recursive","changes disks and partitions (diskpart)",{service:"fs.device"});case"clear-recyclebin":return o("claude.bash.fs.delete_recursive","empties the Recycle Bin, deleting what is in it for good",{target:"the Recycle Bin"});case"vssadmin":return/\b(delete|resize)\s+shadow/i.test(s)?o("claude.bash.fs.delete_recursive","deletes Windows' restore points (shadow copies)",{service:"fs.system"}):[];case"wmic":return/\bshadowcopy\b.*\bdelete\b/i.test(s)?o("claude.bash.fs.delete_recursive","deletes Windows' restore points (shadow copies)",{service:"fs.system"}):[];case"wbadmin":return/\bdelete\b/i.test(s)?o("claude.bash.fs.delete_recursive","deletes Windows' backups (wbadmin)",{service:"fs.system"}):[];case"wsl":return gt(n,"unregister")||n.includes("--unregister")?o("claude.bash.fs.delete_recursive","unregisters a Linux distribution, deleting its whole disk (wsl --unregister)",{service:"fs.root"}):[];case"bcdedit":return n.length===0||gt(n,"enum","v")?[]:o("claude.bash.privilege","changes how Windows starts (bcdedit)");case"reg":{let a=(n[0]??"").toLowerCase();if(["query","compare","export"].includes(a))return[];let i=n[1]??"";return Il.test(i)?o("claude.bash.persistence",`changes what Windows starts at sign-in or boot (reg ${a} ${i})`):/^HK(LM|EY_LOCAL_MACHINE)/i.test(i)?o("claude.bash.privilege",`changes Windows' machine-wide settings (reg ${a})`):[]}case"set-itemproperty":case"new-itemproperty":case"remove-itemproperty":case"remove-item":{let a=ro(n,"path","literalpath")??n.find(i=>!i.startsWith("-"))??"";return/^(HK(CU|LM|CR|U|CC)|HKEY_|Registry::)/i.test(a)?Il.test(a)?o("claude.bash.persistence",`changes what Windows starts at sign-in or boot (${a})`):/^(HKLM|HKEY_LOCAL_MACHINE)/i.test(a)?o("claude.bash.privilege","changes Windows' machine-wide settings (the registry)"):[]:[]}case"sc":{let a=(n[0]??"").toLowerCase();return["create","config","delete","failure","sidtype","privs"].includes(a)?o("claude.bash.persistence",`changes a Windows service (sc ${a})`):a==="stop"?o("claude.bash.process.kill_by_name",`stops a Windows service (sc stop ${n[1]??""})`):[]}case"new-service":case"remove-service":return o("claude.bash.persistence",`changes a Windows service (${e.name})`);case"set-service":return gt(n,"startuptype")?o("claude.bash.persistence","changes when a Windows service starts"):[];case"stop-service":return o("claude.bash.process.kill_by_name",`stops a Windows service (${n.find(a=>!a.startsWith("-"))??""})`);case"register-scheduledtask":case"set-scheduledtask":case"unregister-scheduledtask":case"new-scheduledtask":return o("claude.bash.persistence",`changes Windows scheduled tasks (${e.name})`);case"set-executionpolicy":return o("claude.bash.privilege","changes which PowerShell scripts may run (Set-ExecutionPolicy)");case"set-mppreference":case"add-mppreference":return/-(Disable\w+|Exclusion\w+)/i.test(s)?o("claude.bash.privilege","turns off or narrows Microsoft Defender's checks"):[];case"netsh":return/firewall\b.*\b(state\s+off|disable|delete|add\s+rule|set\s+rule)/i.test(s)||/\bportproxy\b.*\badd\b/i.test(s)?o("claude.bash.net.expose","changes the Windows firewall or forwards a port (netsh)"):[];case"set-netfirewallprofile":case"new-netfirewallrule":case"disable-netfirewallrule":case"remove-netfirewallrule":return o("claude.bash.net.expose",`changes the Windows firewall (${e.name})`);case"takeown":return o("claude.bash.privilege",`takes ownership of files (takeown${gt(n,"r")?" /r":""})`);case"icacls":return gt(n,"grant","reset","setowner","inheritance","remove","deny")?o("claude.bash.privilege","changes who may read or change files (icacls)"):[];case"taskkill":{let a=ro(n,"im");if(a)return o("claude.bash.process.kill_by_name",`kills every ${a} process (taskkill /im)`,{target:a});let i=ro(n,"fi");return i?/^\s*imagename\s+eq\s+\S+\s*$/i.test(i)?o("claude.bash.process.kill_by_name",`kills every process its filter names (taskkill /fi "${i}")`,{target:i}):o("claude.bash.process.kill_by_name",`kills every process its filter matches (taskkill /fi "${i}")`,{target:i,service:"proc.all"}):[]}case"robocopy":{if(!gt(n,"mir","purge"))return[];let a=`robocopy ${gt(n,"mir")?"/mir":"/purge"}`,i=n.filter(l=>!/^\/{1,2}[A-Za-z]+(?::.*)?$/.test(l));return i.length<2?o("claude.bash.fs.delete_recursive",`${a} deletes from a folder the line does not show`):/^[A-Za-z]:(?![\\/])/.test(i[1])?o("claude.bash.fs.delete_recursive",`${a} deletes from ${i[1]}, a folder under a drive's current folder`):$c({...e,name:"rsync",argv:["rsync","-a","--delete",i[0],i[1]]},t).map(l=>({...l,why:l.why.replace(/^rsync --delete/,a)}))}case"setx":return n.length>0?o("claude.bash.persistence",`sets an environment variable every later program starts with (setx ${n.find(a=>!a.startsWith("/"))??""})`):[];case"runas":case"gsudo":return o("claude.bash.privilege",`runs a command as another user or as an administrator (${e.name})`);case"mountvol":return gt(n,"d","p")?o("claude.bash.fs.delete_recursive","removes a drive from Windows (mountvol)",{service:"fs.device"}):[];default:return[]}}function cb(e){let t=e.argv,n=s=>[m("claude.bash.persistence",s,{target:t.slice(0,3).join(" "),is_local:e.remote===null,host:e.remote})];switch(e.name){case"crontab":{let s=t.slice(1).filter(r=>/^-[A-Za-z]+$/.test(r));return s.some(r=>r.includes("r"))?n("crontab -r deletes every scheduled job"):s.some(r=>/[lTV]/.test(r))?[]:s.some(r=>r.includes("e"))?n("crontab -e changes scheduled jobs"):n("crontab replaces every scheduled job")}case"launchctl":{let s=t.slice(1).find(r=>!r.startsWith("-"))??"";return["load","bootstrap","enable","submit"].includes(s)?n(`launchctl ${s} installs a background job`):[]}case"systemctl":{let s=t.slice(1).find(r=>!r.startsWith("-"))??"";return["enable","link","mask","preset","preset-all","set-default","edit","add-wants","add-requires"].includes(s)?n(`systemctl ${s} changes what starts at boot`):[]}case"pm2":return v(t)[0]==="startup"?n("pm2 startup makes processes start at boot"):[];case"brew":return v(t)[0]==="services"&&["start","restart"].includes(v(t)[1]??"")?n(`brew services ${v(t)[1]} registers a job that starts at login`):[];case"osascript":return/\bmake\s+(new\s+)?login\s+item\b/i.test(t.join(" "))?n("osascript adds a login item"):[];case"powershell":case"powershell.exe":case"pwsh":case"pwsh.exe":{let s=P(t,"-Command","-c","-command")??"",r=o=>new RegExp(`(^|[;|{(\\n&]\\s*)(${o})`,"i").test(s.trim());return r("Register-ScheduledTask|Set-ScheduledTask|Unregister-ScheduledTask|New-Service|schtasks(\\.exe)?\\s+\\/(create|change|delete)")||r("Set-Service\\b[^;|\\n]*-StartupType\\s+Automatic")?n("PowerShell changes scheduled tasks or services"):[]}case"schtasks":case"schtasks.exe":return t.some(s=>(V()?/^\/{1,2}(create|change|delete)$/i:/^\/(create|change|delete)$/i).test(s))?n("schtasks changes Windows scheduled tasks"):[];case"at":case"batch":return T(t,"-l","-r","-d","-c")?[]:e.name==="batch"||t.slice(1).some(s=>!s.startsWith("-"))?n(`${e.name} schedules a command to run later`):[];default:return[]}}var ub=/^(core\.(hookspath|sshcommand|fsmonitor|askpass|gitproxy)|credential\..+|url\..+\.(insteadof|pushinsteadof)|https?\..*\.?(sslcainfo|sslcapath|proxy|extraheader|sslcert|sslkey)|include\.path|includeif\..+\.path|init\.templatedir|filter\..+\.(clean|smudge|process)|diff\..+\.textconv|merge\..+\.driver|gpg\.(program|ssh\.program|x509\.program|openpgp\.program))$/i;function db(e,t){if(e.name!=="git")return[];let n=_t(e);if(!n||n.sub!=="config")return[];let s=[...n.args],r="set",o=s[0]??"";["set","unset","get","list","edit","rename-section","remove-section"].includes(o)&&(s.shift(),r=o==="get"||o==="list"?"read":o==="edit"?"edit":o==="set"?"set":"unset");let a=!1,i=[];for(let d=0;d<s.length;d++){let h=s[d];if(h==="--global"||h==="--system")a=!0;else if(h==="-f"||h==="--file"||h.startsWith("--file=")){let g=h.startsWith("--file=")?h.slice(7):s[++d]??"";Bo(M(g,e.cwd,t.ctx),t.ctx,[t.ctx.home])==="gitconfig"&&(a=!0)}else h==="--unset"||h==="--unset-all"||h==="--remove-section"||h==="--rename-section"?r="unset":/^(--get|--get-all|--get-regexp|--get-urlmatch|--get-color|--get-colorbool|-l|--list)$/.test(h)?r="read":h==="-e"||h==="--edit"?r="edit":["--type","--default","--comment","--value","-t"].includes(h)?d++:h.startsWith("-")||i.push(h)}if(!a||r==="read")return[];let l=/^\s*(?:\w+=\S*\s+)*(?:HOME|GIT_CONFIG_GLOBAL|XDG_CONFIG_HOME)=["']?([^\s"']+)/.exec(e.text)?.[1]??/(?:^|[;&|\n(]\s*)(?:export\s+)?(?:HOME|GIT_CONFIG_GLOBAL|XDG_CONFIG_HOME)=["']?([^\s"';&|)]+)["']?\s*(?=$|[;&\n|])/.exec(t.lineText.slice(0,Math.max(0,t.lineText.indexOf(e.text))))?.[1];if(l!==void 0&&kt(M(l,e.cwd,t.ctx),t))return[];let c=(i[0]??"").replace(/(:\/\/)[^@/\s]+@/g,"$1***@"),u=d=>[m("claude.bash.persistence",d,{target:c||"git config --global",is_local:!0})];if(r==="edit")return u("git config --global --edit rewrites the global git config");let f=(i[0]??"").toLowerCase(),p=i[1]??"";return r==="unset"?f==="core.hookspath"?u("turns off the git hooks every repository on this machine runs"):[]:i.length<2?[]:/^https?\..*sslverify$/.test(f)?/^(false|0|no|off)$/i.test(p)?u("turns off TLS certificate checks for every repository on this machine"):[]:/^alias\./.test(f)?p.startsWith("!")?u(`adds a git alias that runs a shell command (${i[0]})`):[]:f==="core.fsmonitor"?/^(true|false|0|1|yes|no|on|off)$/i.test(p)?[]:u(`sets ${c} to run a program for every repository`):/^protocol\..*allow$/.test(f)?/^always$/i.test(p)?u(`allows a git transport that can run commands (${c})`):[]:f==="diff.external"?/^(difft|difftastic|delta|diff-so-fancy|icdiff|meld|opendiff|kdiff3|code|ksdiff)(\s|$)/.test(R.basename(p))?[]:u(`sets ${c} to run a program on every diff`):/^(core\.(pager|editor)|sequence\.editor|interactive\.difffilter|pager\.\w+)$/.test(f)?/[;&`>]|\$\(|\b(curl|wget|nc|ncat|base64)\b|\b(sh|bash|zsh|python3?|node|perl|ruby)\s+-[ce]\b/.test(p)?u(`sets ${c} to run a shell command for every repository`):[]:ub.test(f)?u(`sets ${c} for every repository on this machine`):[]}function fb(e){let t=Xn(e);if(t===null)return[];let n=Yo(t.slice(0,65536));if(!zo(n)||!Fo.test(n))return[];let s=/\.delete\s*\(|method\s*[:=]\s*['"]DELETE|request\s*\(\s*['"]DELETE/i.test(n)?"DELETE":/\.(post|put|patch)\s*\(|method\s*[:=]\s*['"](POST|PUT|PATCH)|request\s*\(\s*['"](POST|PUT|PATCH)|Request\([^)]*data\s*=|-X\s*POST/i.test(n)?"POST":null,r=s!==null?Oc(n,s,n):null;return r!==null?[m("claude.agent.controls",`changes your Anvil workspace's modes through its API (${r})`,{target:r,is_local:!1})]:[]}function mu(e,t,n){let s=t.lineText.slice(0,Math.max(0,t.lineText.indexOf(e.text))),r=n.join("|"),o=new RegExp(`^\\s*(?:\\w+=\\S*\\s+)*(?:${r})=["']?([^\\s"']+)`).exec(e.text)?.[1],a=[...s.matchAll(new RegExp(`(?:^|[;&|\\n(]\\s*)(?:export\\s+)?(?:${r})=["']?([^\\s"';&|)]+)`,"g"))].map(u=>u[1]),i=o??a[a.length-1];if(!i)return null;let l=i.replace(/^\$\{?([A-Za-z_]\w*)\}?/,(u,f)=>{let p=new RegExp(`(?:^|[;&|\\n(]\\s*)(?:export\\s+)?${f}=(?:"?\\$\\(mktemp\\b[^)]*\\)"?|["']?([^\\s"';&|)]+))`).exec(s);return p?p[1]??`${t.ctx.tmpdir.replace(/(?<!\/)\/+$/,"")}/mktemp`:u});if(S(l)||l.includes("$"))return null;let c=X(l,e.cwd,se(t));return c.kind==="disposable"&&c.why!==On?c.path:null}var pb=new Set(["node","nodejs","bun","deno","tsx","ts-node","sh","bash","zsh","dash","ksh","source",".","python","python3","perl","ruby"]),hb=/(?:\.anvil\/claude\/bin\/|useanvil\S*\/|\/anvil\/bin\/)claude-(?:hook|hook-core|sync|meter)\.(?:[cm]?js|sh)\b/;function gb(e,t){let n=e.argv,s=v(n),r=i=>[m("claude.agent.controls",i,{target:`${e.name} ${s[0]??""}`.trim(),is_local:!0})],o=n.findIndex((i,l)=>n[l+1]==="claude"&&/\$\(|`/.test(k(i))&&/(^|[^\w.-])anvil($|[^\w.-])/.test(k(i)));if(o>=0){let i=Ln(v(["anvil",...n.slice(o+1)]));if(i)return r(i)}let a=n.findIndex(i=>/\$\(|`/.test(k(i))&&/(^|[^\w.-])anvil-claude($|[^\w.-])/.test(k(i)));if(a>=0){let i=Ss(v(["anvil-claude",...n.slice(a+1)]),n.slice(a+1));if(i)return r(i)}if(pb.has(e.name)){let i=n.findIndex((l,c)=>c>0&&hb.test(/^[/~$]/.test(k(l))?k(l):`${e.cwd??""}/${k(l)}`));if(i>0&&!(/claude-sync\.js$/.test(k(n[i]))&&n.length===i+2&&n[i+1]==="--status"))return r("runs Anvil's own hook by hand: what it records would be made up")}switch(e.name){case"claude":{if((s[0]==="plugin"||s[0]==="plugins")&&["list","ls","validate"].includes(s[1]??"")&&!(s[1]==="list"&&s[2]==="marketplace")||s[0]==="mcp"&&["list","get"].includes(s[1]??"")||s[0]==="config"&&["get","list"].includes(s[1]??"")||s.length===0&&T(n,"--version","-v"))return[];let i=(s[0]==="plugin"||s[0]==="plugins")&&["install","i","enable","disable","uninstall","remove","rm","marketplace"].includes(s[1]??"")||s[0]==="mcp"&&["add","add-json","add-from-claude-desktop","remove"].includes(s[1]??"")||s[0]==="config"&&["set","add","remove"].includes(s[1]??""),l=n.some(($,E)=>["-s","--scope"].includes(n[E-1]??"")&&/^(project|local)$/.test($)||/^(--scope=|-s)(project|local)$/.test($));if(i&&!l&&mu(e,t,["HOME","CLAUDE_CONFIG_DIR"]))return[];if(s[0]==="mcp"&&["add","add-json","add-from-claude-desktop"].includes(s[1]??""))return r(`claude mcp ${s[1]} gives Claude Code a new MCP server`);if(s[0]==="config"&&["set","add"].includes(s[1]??""))return r("claude config changes Claude Code's settings");if(s[0]==="import")return r("claude import brings another agent's MCP servers and settings into Claude Code");if((s[0]==="plugin"||s[0]==="plugins")&&(["install","i","enable"].includes(s[1]??"")||s[1]==="marketplace"&&s[2]==="add"))return r(`claude plugin ${s.slice(1,3).join(" ")} gives Claude Code new hooks, tools or MCP servers`);if((s[0]==="plugin"||s[0]==="plugins")&&(["disable","uninstall","remove","rm"].includes(s[1]??"")||s[1]==="marketplace"&&["remove","rm"].includes(s[2]??"")))return r(`claude plugin ${s.slice(1,3).join(" ")} turns off hooks Claude Code was running`);if(T(n,"--dangerously-skip-permissions","--allow-dangerously-skip-permissions")||P(n,"--permission-mode")==="bypassPermissions")return r("runs Claude Code with its permission checks off");let c=P(n,"--setting-sources"),u=c?.split(",").map($=>$.trim())??[];if(c!==null&&!(u.includes("user")&&u.includes("local")))return r("runs Claude Code without your user or local settings, where Anvil's hook is");let p=`${/^\s*((?:(?:env\s+(?:-\S+\s+)*)?[A-Za-z_][A-Za-z0-9_]*=(?:'[^']*'|"[^"]*"|\S*)\s+)+)/.exec(e.text)?.[1]??""} ${e.text.slice(0,Math.max(0,e.text.search(/(^|[\s/])claude(\s|$)/)))}`,d=t.lineText.slice(0,65536);if(/(^|\s)(CLAUDE_CONFIG_DIR|HOME)=/.test(p)||/(^|[\s;&|(])(export|declare\s+-x)\s+(CLAUDE_CONFIG_DIR|HOME)=/.test(d)||/(^|[\s;&|(])CLAUDE_CONFIG_DIR=/.test(d))return r("runs Claude Code with its settings folder moved, away from Anvil's hook");if(/(^|\s)(ANVIL_API_KEY|ANVIL_API_BASE_URL|ANVIL_WORKSPACE_KEYS_PATH)=/.test(p)||/(^|[\s;&|(])export\s+(ANVIL_API_KEY|ANVIL_API_BASE_URL|ANVIL_WORKSPACE_KEYS_PATH)=/.test(d))return r("runs Claude Code under another account's key, whose modes its sync would take");if(/(^|[\s;&|(])unset\s+(-v\s+)?CLAUDE_CONFIG_DIR\b|\benv\s+(?:-\S+\s+)*-u\s*CLAUDE_CONFIG_DIR\b/.test(d))return r("runs Claude Code without the settings folder this session uses, where Anvil's hook is");if(T(n,"--bare","--safe-mode")||/(^|\s)(CLAUDE_CODE_SIMPLE|CLAUDE_CODE_SAFE_MODE)=/.test(p)||/(^|[\s;&|(])(export\s+|declare\s+-x\s+)?(CLAUDE_CODE_SIMPLE|CLAUDE_CODE_SAFE_MODE)=/.test(d))return r("runs Claude Code with hooks and plugins skipped, Anvil's among them");let h=P(n,"--settings");if(h!==null&&/bypassPermissions|dangerously|"Bash(\(\*\))?"|disableAllHooks|"hooks"\s*:/.test(h))return r("runs Claude Code with settings that turn its permission checks off");let g=[];for(let $=1;$<n.length;$++)if(n[$]==="--allowedTools"||n[$]==="--allowed-tools"||/^--allowed-?[tT]ools=/.test(n[$])){n[$].includes("=")&&g.push(n[$].slice(n[$].indexOf("=")+1));for(let E=$+1;E<n.length&&!n[E].startsWith("-");E++)g.push(n[E])}if(g.some($=>/(^|[\s,'"])Bash(\(\*\))?($|[\s,'"])/.test($)))return r("runs Claude Code with every shell command allowed");let y=P(n,"--mcp-config");return y!==null&&!/^\s*\{\s*("mcpServers"\s*:\s*\{\s*\}\s*)?\}\s*$/.test(y)?r("runs Claude Code with MCP servers from a config file"):h!==null&&!h.trim().startsWith("{")?r("runs Claude Code with settings from a file the command does not show"):[]}case"fish":case"set":return/\bset\s+-[a-zA-Z]*U[a-zA-Z]*\s+(CLAUDE_CONFIG_DIR|CLAUDE_CODE_SIMPLE|CLAUDE_CODE_SAFE_MODE|ANVIL_CLAUDE_SYNC|ANVIL_WORKSPACE_KEYS_PATH)\b/.test(e.name==="set"?`set ${n.slice(1).join(" ")}`:n.slice(1).join(" "))?r("a fish universal variable changes how every later Claude Code session starts"):[];case"launchctl":{let i=["CLAUDE_CONFIG_DIR","CLAUDE_CODE_SIMPLE","CLAUDE_CODE_SAFE_MODE","ANVIL_CLAUDE_SYNC","ANVIL_WORKSPACE_KEYS_PATH"];return s[0]==="setenv"&&i.includes(s[1]??"")?r(`launchctl setenv ${s[1]} changes how every later Claude Code session starts`):[]}case"anvil":{let i=Ln(s);if(i)return r(i);let l=/^\s*((?:[A-Za-z_][A-Za-z0-9_]*=\S*\s+)+)/.exec(e.text)?.[1]??"";return s[0]==="claude"&&(/(^|\s)(ANVIL_API_KEY|ANVIL_API_BASE_URL|ANVIL_WORKSPACE_KEYS_PATH)=/.test(l)||/(^|[\s;&|(])export\s+(ANVIL_API_KEY|ANVIL_API_BASE_URL|ANVIL_WORKSPACE_KEYS_PATH)=/.test(t.lineText.slice(0,65536)))?r("runs anvil claude under another account's key, whose modes it would take"):e.via==="xargs"&&s[0]==="claude"&&s.length===1?r("anvil claude with its subcommand read from input"):[]}case"anvil-claude":{if(e.via==="xargs"&&s.length===0)return r("anvil-claude with its subcommand read from input");let i=Ss(s,n.slice(1));return i?r(i):[]}case"node":case"bun":case"deno":case"tsx":case"ts-node":{let i=n.findIndex((f,p)=>p>0&&!f.startsWith("-")),l=i>0?k(n[i]):"",c=/@useanvil\/claude-code\/|(?:^|\/)anvil-claude$/i.test(l),u=i>0&&(c||/(?:^|\/)(?:@useanvil\/sdk|anvil)(?:\/|\.[cm]?[jt]s$|$)|useanvil/i.test(l))?c?Ss(v([e.name,...n.slice(i+1)]),n.slice(i+1)):Ln(v([e.name,...n.slice(i+1)])):null;return u?r(u):[]}case"code":case"code-insiders":return T(n,"--add-mcp")?r(`${e.name} --add-mcp gives an AI agent a new MCP server`):[];case"codex":return s[0]==="mcp"&&s[1]==="add"?r("codex mcp add gives Codex a new MCP server"):T(n,"--dangerously-bypass-approvals-and-sandbox","--yolo")||P(n,"-s","--sandbox")==="danger-full-access"||n.some((i,l)=>(n[l-1]==="-c"||n[l-1]==="--config")&&/^sandbox_mode\s*=\s*["']?danger-full-access/.test(i))?r("runs Codex with its sandbox and approvals off"):[];case"gemini":return s[0]==="mcp"&&s[1]==="add"?r("gemini mcp add gives Gemini CLI a new MCP server"):T(n,"--yolo","-y")||P(n,"--approval-mode")==="yolo"?r("runs Gemini CLI approving every action"):[];case"cursor-agent":return T(n,"--force","-f")?r("runs Cursor Agent without asking before commands"):[];case"aider":return T(n,"--yes-always")?r("runs aider confirming every action"):[];case"amp":return T(n,"--dangerously-allow-all")?r("runs Amp with every action allowed"):[];case"droid":return T(n,"--skip-permissions-unsafe")?r("runs Droid with its permission checks off"):[];case"q":return s[0]==="chat"&&T(n,"--trust-all-tools")?r("runs Amazon Q trusting every tool"):[];case"qwen":case"crush":return T(n,"--yolo","-y")?r(`runs ${e.name} approving every action`):[];case"fastmcp":return s[0]==="install"?r("fastmcp install adds an MCP server to an AI agent"):[];case"copilot":return T(n,"--yolo","--allow-all-tools")?r("runs Copilot CLI approving every tool"):[];case"smithery":return s[0]==="install"||s[0]==="mcp"&&s[1]==="add"?r("installs an MCP server into an AI agent"):[];case"install-mcp":return s.length>0?r("installs an MCP server into an AI agent"):[];case"mcp-get":return s[0]==="install"?r("installs an MCP server into an AI agent"):[];default:return[]}}var mb=new Set(["deliver","pilot","supply","upload_to_app_store","upload_to_testflight","upload_to_play_store","appstore","testflight","app_store_connect","upload_to_play_store_internal_app_sharing"]),yb=new Set(["init","download_metadata","download_screenshots","list","builds","export","help"]),bb=/(^|_)(release|beta|deploy|production|prod|store|publish|submit|upload|ship|distribute|promote|appstore|testflight|playstore|alpha|internal|rollout)(_|$)/i,wb=/(^|_)(build|test|tests|lint|screenshots?|certs|certificates|match|setup|bump|version|changelog|notes|metadata|precheck|dry_?run|check|verify|dsyms?|symbols|crashlytics|sentry|bugsnag)(_|$)/i;function kb(e){if(e.some((s,r)=>/^(--)?(validate|verify)_only(:|=)?(true)?$/i.test(s)&&(/true$/i.test(s)||/^true$/i.test(e[r+1]??""))))return!1;let t=v(e);["ios","android","mac"].includes(t[0]??"")&&(t=t.slice(1)),t[0]==="run"&&(t=t.slice(1));let n=t[0]??"";return n==="match"&&t[1]==="nuke"||n==="match_nuke"?!0:mb.has(n)?!yb.has(t[1]??""):/(^|_)(dsyms?|symbols|crashlytics|sentry|bugsnag|metadata|screenshots?)(_|$)/i.test(n)?!1:/(^|_)(upload|deploy|submit|distribute|publish|ship|promote|testflight|appstore|playstore|rollout)(_|$)/i.test(n)||/(^|_)and_(release|beta|production|prod|store)(_|$)/i.test(n)?!0:bb.test(n)&&!wb.test(n)}function oo(e){return e.slice(1).some(t=>/^prod(uction)?$/i.test(k(t))||/^--(deployment-?name|deploymentName|destDeploymentName|target-deployment)=prod/i.test(t))}function yu(e){return T(e,"-m","--dry-run")?[]:e.slice(1).filter(t=>!t.startsWith("-")&&!t.includes("=")).map(t=>t.slice(t.lastIndexOf(":")+1))}function Dl(e){return yu(e).some(t=>/^publish\w*(Bundles?|Apks?|Listing)$|^promote\w*Artifact$/.test(t))}function Fl(e){return yu(e).some(t=>/^publish(AllPublicationsTo\w+Repository|\w+PublicationTo\w+Repository|ToSonatype|ToMavenCentral|AndReleaseToMavenCentral)?$/.test(t))}var bu=/^(preview|previews|staging|stage|dev|develop|development|test|testing|qa|internal|canary|pr-[\w.-]+|feat(ure)?[/-][\w./-]+)$/i;function vb(e){let t=v(e),[n="",s=""]=(t[0]??"").split(":");if(n==="submit"||n==="build"&&s==="submit")return!0;if(n==="build"&&!s)return T(e,"--auto-submit","--auto-submit-with-profile");if(n==="update"&&!s){let r=P(e,"--branch","--channel");return!(r!==null&&!S(r)&&bu.test(r))}return n==="update"?["republish","rollback","roll-back-to-embedded","edit","revert-update-rollout"].includes(s):n==="channel"?["edit","rollout"].includes(s||(t[1]??"")):n==="deploy"?T(e,"--prod","--production"):!1}function xo(e,t){let n=e.trim();if(/^[A-Za-z_$][\w$.]*$/.test(n)){let s=new RegExp(`(?:^|[^\\w$.])${n.replace(/[.$]/g,r=>`\\${r}`)}\\s*(?::\\s*[\\w.]+\\s*)?=(?!=)\\s*([^\\n;]+)`).exec(t);s&&(n=s[1])}return n=n.replace(/\b(require|__import__|import)\s*\(\s*(['"`])[^'"`]*\2\s*\)/g,"$1()"),[...n.matchAll(/(['"`])((?:\\.|(?!\1)[^\\])*)\1/g)].map(s=>s[2]).join("/").replace(/\/{2,}/g,"/")}function _o(e,t,n){let s=e.indexOf("(",t);if(s<0)return[];let r=e.slice(s,s+4e3),o=lr(r,0);return o<0&&s+4e3<e.length&&(n.hit=!0),o>0?gn(r.slice(1,o)):[]}function zl(e,t){let n=t,s=Math.max(0,t-400);for(;;){for(;n>s&&/\s/.test(e[n-1]);)n--;if(e[n-1]===")"){let a=0,i=null,l=n-1;for(;l>=s;l--){let c=e[l];if(i){c===i&&e[l-1]!=="\\"&&(i=null);continue}if(c==='"'||c==="'"||c==="`")i=c;else if(c===")")a++;else if(c==="("&&--a===0)break}if(l<s)return null;n=l}let o=n;for(;o>s&&/[\w$]/.test(e[o-1]);)o--;if(o===n&&e[n]!=="(")return null;if(n=o,e[n-1]==="."&&n-1>s){n--;continue}break}let r=e.slice(n,t).trim();return r===""?null:r}var $b=/^\s*[rRbB]?['"][rwxabt+U]{1,4}['"]\s*$/,Ml=/['"][^'"]*[wax+]|\bO_(?:WRONLY|RDWR|CREAT|TRUNC|APPEND)\b/,xb=/\b(exec|eval|compile|execfile|run_path|run_module|system|popen|spawn|spawnSync|execSync|execFileSync|Function|vm\.run\w*|subprocess\.\w+|os\.exec\w*)\s*\(/;function Yo(e){return!/'''|"""|`[^`]*\n/.test(e)||xb.test(e)?e:e.replace(/('''|""")([\s\S]*?)\1|`((?:\\.|[^`\\])*\n(?:\\.|[^`\\])*)`/g,t=>{let n=t.startsWith("'''")||t.startsWith('"""')?3:1;return t.slice(0,n)+t.slice(n,t.length-n).replace(/[^\n]/g," ")+t.slice(t.length-n)})}function wu(e,t,n){let s=[],r=Yo(e),o=(i,l=!0)=>{let c=xo(i,e);c!==""?s.push({path:c,content:l,expr:i}):n&&(n.n++,n.exprs?.push(i))},a=i=>_o(e,i,t);for(let i of Ge([...r.matchAll(/\b(?:f?open|openSync|File\.new)\s*\(/g)],t)){let l=a(i.index),c=(l.find(u=>/^\s*mode\s*=/.test(u))??"").replace(/^\s*mode\s*=/,"");if(e[i.index-1]==="."&&($b.test(l[0]??"")||/^\s*mode\s*=/.test(l[0]??""))){let u=Ml.test(c||l[0])?zl(e,i.index-1):null;u&&o(u);continue}Ml.test(l[1]??c)&&o(l[0]??"")}for(let i of Ge([...r.matchAll(/\.(write_text|write_bytes|unlink|chmod|rename|replace|touch)\s*\(/g)],t)){let l=zl(e,i.index);l&&o(l,i[1]==="write_text"||i[1]==="write_bytes"),i[1]==="rename"?o(a(i.index)[0]??""):i[1]==="replace"&&l&&_b(l,e)&&o(_o(e,i.index,{hit:!1})[0]??"")}for(let i of Ge([...r.matchAll(/\b(writeFileSync|writeFile|appendFileSync|appendFile|createWriteStream|truncateSync|truncate|outputFileSync|outputFile|outputJsonSync|outputJson|writeJsonSync|writeJson|file_put_contents|Deno\.writeTextFileSync|Deno\.writeTextFile|Deno\.writeFileSync|Deno\.writeFile|Bun\.write|(?:File|IO)\.(?:write|binwrite))\s*\(/g)],t))o(a(i.index)[0]??"");for(let i of Ge([...r.matchAll(/\b(rmSync|unlinkSync|unlink|chmodSync|chmod|Deno\.remove|os\.remove|os\.unlink|os\.chmod|shutil\.rmtree|rmtree|rimraf(?:\.sync)?|fse?\.removeSync|fse?\.remove|(?:File|IO)\.(?:delete|unlink)|FileUtils\.(?:rm|rm_f|rm_rf|remove_dir|touch))\s*\(/g)],t))o(a(i.index)[0]??"",!1);for(let i of Ge([...r.matchAll(/\bfileinput\.(?:input|FileInput)\s*\(/g)],t)){let l=a(i.index);if(!l.some(f=>/^\s*inplace\s*=\s*(?:True|1)\s*$/.test(f)))continue;let c=(l.find(f=>/^\s*files\s*=/.test(f))??l.find(f=>!/^\s*\w+\s*=/.test(f))??"").replace(/^\s*files\s*=\s*/,"").trim(),u=/^[[(]([\s\S]*)[\])]$/.exec(c);for(let f of u?gn(u[1]):[c])o(f.trim())}for(let i of Ge([...r.matchAll(/\bopen\s*\(?\s*(?:my\s+)?(?:\$\w+|[A-Z]\w*)\s*,\s*['"](?:\+?>{1,2}|\+<)['"]\s*,\s*([^;)]+)/g)],t))o(i[1].trim());for(let i of Ge([...r.matchAll(/\bopen\s*\(?\s*(?:my\s+)?(?:\$\w+|[A-Z]\w*)\s*,\s*(['"])\s*(?:\+?>{1,2}|\+<)\s*([^'"]+)\1/g)],t))o(`"${i[2].trim()}"`);for(let i of Ge([...r.matchAll(/\b(copyFileSync|copyFile|renameSync|rename|cpSync|(?<=\.)cp|(?:fse?|fsExtra)\.(?:copySync|copy|moveSync|move)|shutil\.copy\w*|shutil\.move|os\.replace|os\.rename|FileUtils\.(?:cp|mv|ln_s|ln_sf|cp_r)|File\.rename)\s*\(/g)],t)){let l=a(i.index);o(l[1]??""),/rename|move|replace/.test(i[1])&&o(l[0]??"",!1)}return s}function _b(e,t){if(/\b(?:pathlib\.)?Path\s*\(|\.with_(?:name|suffix|stem)\s*\(/.test(e))return!0;let n=/^[A-Za-z_]\w*$/.exec(e.trim())?.[0];return n!==void 0&&new RegExp(`(?:^|[^\\w.])${n}\\s*=\\s*(?:pathlib\\.)?Path\\s*\\(`).test(t)}var Sb=/(?:\b(?:os\.symlink|os\.link|fs\.symlinkSync|fs\.symlink|fs\.linkSync|fs\.link|symlinkSync|linkSync|File\.symlink|File\.link|FileUtils\.ln_sf|FileUtils\.ln_s|FileUtils\.ln|Deno\.symlinkSync|Deno\.symlink|symlink)|\.(?:symlink_to|hardlink_to))\s*\(/g,Ul=/\.claude(\/settings(\.local)?\.json|\/hooks(\/.*)?)?\/?$|\.claude\.json$|\.mcp\.json$|\.anvil\/(claude(\/.*)?|rules\.json)$|Library\/Launch(Agents|Daemons)\/|\.gitconfig$|\.claude\/projects(\/[^/]+(\/.+\.jsonl)?)?\/?$/,Cb=/(?:^|[;\n])[ \t]*(?:from\s+google\.cloud\s+import\s+bigquery\b|import\s+google\.cloud\.bigquery\b|import\s+snowflake\b|from\s+snowflake\b|import\s+redshift_connector\b|from\s+databricks\b[\w.]*\s+import\b|(?:const|let|var|import)\b[^\n;]{0,80}(?:require\(\s*|from\s+)['"](?:@google-cloud\/bigquery|snowflake-sdk|@databricks\/sql)['"])/;function Ab(e,t){let n=Xn(e);if(n===null)return[];let s=[],r={n:0,exprs:[]},o=wu(n,t.cut,r),a=Kb(e,n,r.exprs,t);a!==null&&s.push(m("claude.agent.controls",`${e.name} writes the file the line hands it: Claude Code's record of a session (${S(a)?"a file a listing of its projects folder names":R.basename(k(a))})`,{target:k(a).slice(0,200),is_local:!0}));for(let i of o){if(!i.content||!ye(i.path))continue;let l=Ht(i.expr,n,e,0,t.ctx.home,t.cut);if(!(l===null||l.startsWith("/dev/")||!ye(l))&&He(l,e,t).kind!=="disposable"){s.push(m("claude.file.write_secret",`writes a secrets file (${R.basename(k(l))}) (from ${e.name})`,{target:k(l),is_local:!0}));break}}for(let{path:i}of o){let l=k(i);if(S(i)&&ar(i,t.ctx,e.cwd)){s.push(m("claude.agent.controls",`writes Claude Code's record of a session (a file a listing of its projects folder names) (from ${e.name})`,{target:l.slice(0,200),is_local:!0}));continue}if(!Ul.test(l)){let y=l.startsWith("/")?l:M(l,e.cwd,t.ctx);if(cn(t,S(i)?M(i,e.cwd,t.ctx):y),ot.test(y)&&pn(n)){s.push(m("claude.agent.controls",`changes how every later Claude Code session starts (${R.basename(y)}) (from ${e.name})`,{target:k(y),is_local:!0}));continue}let $=S(y)?null:Vn(y,t.ctx,[t.projectRoot,t.base]);if($){s.push({...$,why:`${$.why} (from ${e.name})`});continue}let E=Ie(y,e,t),x=E!==y?E:ks(y,t.ctx.onDisk,!0);if(x===null||!Ul.test(x))continue;let b=Vn(x,t.ctx,[t.projectRoot,t.base]);if(b){s.push({...b,why:`${b.why} (from ${e.name})`});continue}continue}let c=l.replace(/^(\$ENV\{['"]?HOME['"]?\}|ENV\[['"]HOME['"]\]|\$?\{[^}]*\}|HOME|~|USERPROFILE|homedir\(\))\/?/,""),u=/\b(HOME|homedir|expanduser|USERPROFILE)\b|Path\.home\b/.test(n),f=/^\/(\.claude|\.mcp\.json|\.gitconfig|\.anvil\/|Library\/)/.test(l),p=l!==c||/^(\.claude\.json|\.gitconfig|Library\/)/.test(c)||(f||/^\.(claude|anvil)\//.test(c))&&u,d=p?mu(e,t,["HOME"])??t.ctx.home:t.ctx.home,h=l.startsWith("/")&&!(f&&u)?l:p?`${d}/${c.replace(/^\/+/,"")}`:M(c,e.cwd,t.ctx);cn(t,h);let g=Vn(Ie(h,e,t),t.ctx,[t.projectRoot,t.base]);if(g){s.push({...g,why:`${g.why} (from ${e.name})`});continue}}for(let i of Ge([...n.matchAll(Sb)],t.cut)){let l=_o(n,i.index,t.cut)[0];if(l===void 0)continue;let c=Ht(l,n,e,0,t.ctx.home,t.cut)??xo(l,n);if(!c||S(c)||c.startsWith(hn))continue;let u=M(c,e.cwd,t.ctx);if(!hu(u,t))continue;let f=t.ctx.home.replace(/(?<!\/)\/+$/,""),p=u===f?"~":u.startsWith(`${f}/`)?`~${u.slice(f.length)}`:u;s.push(m("claude.agent.controls",`links to a folder that holds Anvil's or Claude Code's settings (${p}) (from ${e.name})`,{target:u,is_local:!0}));break}if(/\bread_sql(_query|_table)?\s*\(/.test(n)&&/\.to_(csv|parquet|json|excel|feather|pickle|orc|hdf)\s*\(/.test(n)&&!/localhost|127\.0\.0\.1|sqlite/i.test(n)&&s.push(m("claude.bash.data.export",`copies query rows from a database into a file (from ${e.name})`,{target:e.name,host:null,is_local:!1})),/\.to_gbq\s*\([^)]{0,500}if_exists\s*=\s*['"]replace/.test(n)&&s.push(m("claude.bash.db.destructive",`replaces a BigQuery table (from ${e.name})`,{target:e.name,host:"bigquery",is_local:!1})),(/\bfrom\s+pyngrok\s+import\b|\bimport\s+pyngrok\b/.test(n)&&/\bngrok\.connect\s*\(/.test(n)||/require\(\s*['"](localtunnel|ngrok|@ngrok\/ngrok)['"]\s*\)|\bngrok\.(forward|connect)\s*\(/.test(n))&&s.push(m("claude.bash.net.expose",`opens a local port to the internet (from ${e.name})`,{target:e.name,host:null,is_local:!1})),Cb.test(n)){let i=(()=>{if(/\.(delete_table|delete_dataset|delete_model|delete_routine)\s*\(|\.(table|dataset)\([^)]*\)\.delete\s*\(/.test(n))return"deletes warehouse data";for(let l of Ge([...n.matchAll(/\.(query|execute|execute_string|executemany|sql|run_query)\s*\(/g)],t.cut)){let c=n.indexOf("(",l.index),u=n.slice(c,c+4e3),f=lr(u,0);f<0&&c+4e3<n.length&&(t.cut.hit=!0);let p=f>0?gn(u.slice(1,f))[0]??"":"",d=/^\s*[A-Za-z_$][\w$]*\s*$/.test(p)&&xo(p,n)||p,h=be.exec(d)??Hn.exec(d);if(h)return`runs destructive SQL (${h[1].replace(/\s+/g," ").toUpperCase()})`}return null})();i&&s.push(m("claude.bash.db.destructive",`${i} through a warehouse client (from ${e.name})`,{target:e.name,host:/bigquery/i.test(n)?"bigquery":/snowflake/i.test(n)?"snowflake":/databricks/i.test(n)?"databricks":"redshift",is_local:!1}))}return s}function Eb(e,t){let n=e.argv,s=[],r=null;if(e.name==="tmux"&&["new","new-session","new-window","neww","split-window","splitw","respawn-pane"].includes(n[1]??"")){let a=ql(n,2,Rb);if(a.length>1&&(a.some(S)||/\s/.test(a[0])))return qe("tmux");s=[a.length>1?Is(a):a.join(" ")],r="tmux"}else if(e.name==="tmux"&&["send-keys","send"].includes(n[1]??""))s=[pe(n,2,new Set(["-t","-N"])).filter(a=>!/^(Enter|C-m|KPEnter)$/.test(a)).join(" ")];else if(e.name==="screen"){let a=1;for(;a<n.length&&n[a].startsWith("-");)a+=/^-[A-Za-z]*[ScpTXh]$/.test(n[a])||n[a]==="-Logfile"?2:1;let i=n.slice(1,a).some(l=>/^-[A-Za-z]*X$/.test(l));if(!i&&n.slice(a).some(S))return qe("screen");s=[i?n.slice(a).join(" "):Is(n.slice(a))],r="screen"}else if(e.name==="concurrently")s=pe(n,1,new Set(["-n","--names","-c","--prefix-colors","-p","--prefix","-s","--success","--restart-tries"]));else if(e.name==="kitty"&&n[1]==="@"&&n[2]==="launch"||e.name==="wezterm"&&n[1]==="cli"&&n[2]==="spawn"||e.name==="zellij"&&(n[1]==="run"||n[1]==="r")||e.name==="systemd-run"){let a=e.name==="systemd-run"?1:e.name==="zellij"?2:3,i=ql(n,a,Ob[e.name]??new Set);if(i.length===0)return[];if(i.some(S)||/\s/.test(i[0]))return qe(e.name);s=[Is(i)],r=e.name}else if(e.name==="launchctl"){let a=n.slice(1).find(i=>!i.startsWith("-"))??"";if(a==="submit"){let i=n.indexOf("--");if(i<0||n.slice(i+1).some(S))return qe("launchctl submit");s=[Is(n.slice(i+1))],r="launchctl submit"}else if(a==="load"||a==="bootstrap")return qe(`launchctl ${a}`)}else if(e.name==="crontab"||e.name==="at"||e.name==="batch"){let a=n.slice(1).filter(c=>/^-[A-Za-z]+$/.test(c));if(e.name==="crontab"&&a.some(c=>/[lTVre]/.test(c)))return[];if(e.name!=="crontab"&&a.some(c=>/[lrdcq]/.test(c)))return[];let i=e.name==="crontab"?n.slice(1).filter(c=>!c.startsWith("-")||c==="-").filter(c=>c!=="-"):[],l=i.length===1?Tb(i[0],e,t):i.length===0&&!n.includes("-f")?Hl(e)??(e.name==="crontab"?Ib(e,t):null):null;if(l===null)return qe(e.name);s=e.name==="crontab"?Db(l):l.split(`
|
|
72
|
-
`),r=e.name}else if(e.name==="osascript"){let a=
|
|
73
|
-
`):
|
|
74
|
-
`).replace(/\\t/g," "):null:
|
|
75
|
-
`)}function
|
|
78
|
+
`)}`:"");if(s==="sftp"&&(c??=[...u.matchAll(/(?:^|\n|;)\s*put\s+(?:-\w+\s+)*(\S+)/g)].map(h=>h[1]).find(h=>Ze(h))??null),c===null)return[];let p=ke(t,1,s==="ssh"?mv:s==="sftp"?yv:bv),d=s==="socat"?t.slice(1).map(h=>/^(?:TCP|TCP4|TCP6|SSL|OPENSSL|UDP)[^:]*:([^:,]+)/i.exec(h)?.[1]).find(h=>h!==void 0)??null:p[0]?Rs(p[0]):null;return["nc","ncat","netcat"].includes(s)&&t.slice(1).some(h=>/^-[A-Za-z]*l/.test(h))?d!==null&&qe(d)?[]:r(c,"anyone who connects"):d===null||qe(d)?[]:r(c,$(d))}default:return[]}}var vv="BbcDEeFIiJLlmOoPpQRSWw";function uu(e){let n=!1;for(let t=1;t<e.length;t++){let s=e[t];if(s==="--")return!1;if(!s.startsWith("-")){if(n)return!1;n=!0;continue}if(!s.startsWith("--"))for(let r=1;r<s.length;r++){let o=s[r];if(o==="R")return!0;if(o==="o"){let a=r+1<s.length?s.slice(r+1):e[t+1]??"";if(/^RemoteForward\b/i.test(a))return!0}if(vv.includes(o)){r===s.length-1&&t++;break}}}return!1}function Ci(e){let n=e.argv,t=_(n),s=r=>[w("claude.bash.net.expose",r,{target:`${e.name} ${t[0]??""}`.trim(),is_local:!1})];switch(e.name){case"ngrok":return["http","tcp","tls","start","tunnel"].includes(t[0]??"")||t[0]==="service"&&["install","start"].includes(t[1]??"")?s(`ngrok ${t[0]} opens a local port to the internet`):[];case"cloudflared":return t[0]==="access"?[]:I(n,"--url","--hello-world")||t[0]==="tunnel"&&(t.includes("run")||t.includes("route"))||t[0]==="service"&&t[1]==="install"?s("cloudflared opens a tunnel from the internet to this machine"):[];case"lt":return I(n,"--port","-p")?s("localtunnel opens a local port to the internet"):[];case"tailscale":return t[0]==="funnel"&&!["status","reset"].includes(t[1]??"")&&!t.includes("off")?s("tailscale funnel opens a local port to the internet"):[];case"ssh":case"autossh":return e.name==="ssh"&&n.slice(1).some(r=>/^-[a-zA-Z]*G[a-zA-Z]*$/.test(r))?[]:uu(e.name==="autossh"?n.filter((r,o)=>!(r==="-M"||n[o-1]==="-M"||/^-M\d/.test(r))):n)?s(`${e.name} -R opens a port on another machine that reaches this one`):[];case"gcloud":{let r=n.indexOf("--");return t[0]==="compute"&&t[1]==="ssh"&&r>0&&uu(["ssh",...n.slice(r+1),"host"])?s("gcloud compute ssh -R opens a port on a VM that reaches this machine"):[]}case"frpc":return["verify","status","reload","stop"].includes(t[0]??"")||I(n,"-v","--version")?[]:s("frpc exposes local services through an frp server");case"bore":return t[0]==="local"?s("bore opens a local port to the internet"):[];case"zrok":return t[0]==="share"&&t[1]==="public"?s("zrok shares a local port publicly"):[];case"loclx":case"localxpose":return t[0]==="tunnel"?s("localxpose opens a local port to the internet"):[];case"devtunnel":return t[0]==="host"&&I(n,"--allow-anonymous","-a")?s("devtunnel host lets anyone reach a local port"):[];case"ddev":case"valet":case"herd":return t[0]==="share"?s(`${e.name} share serves this project at a public URL`):[];case"tmole":case"tunnelmole":return t.length>0?s(`${e.name} opens a local port to the internet`):[];case"untun":return t[0]==="tunnel"?s("untun opens a local port to the internet"):[];case"expo":return t[0]==="start"&&I(n,"--tunnel")?s("expo start --tunnel serves the dev server at a public URL"):[];case"code":case"code-insiders":return t[0]==="tunnel"&&!["status","kill","unregister","prune","rename","user","help"].includes(t[1]??"")?s(`${e.name} tunnel opens this machine to remote access over the internet`):[];case"docker":case"podman":{let r=pf(n);if(!r)return[];let o=/(^|\/)(cloudflared|ngrok)(:[^/]*)?$/.exec(r.image)?.[2];return o?Ci({...e,name:o,argv:[o,...r.args]}):[]}default:return[]}}var $v=new Set(["-e","--env","--env-file","-v","--volume","-p","--publish","--name","--network","--net","-w","--workdir","-u","--user","--entrypoint","--mount","-l","--label","--label-file","--restart","-m","--memory","--memory-swap","--cpus","--cpu-shares","-c","--platform","--pull","--add-host","--dns","-h","--hostname","--device","--cap-add","--cap-drop","--gpus","--log-driver","--log-opt","--ulimit","--shm-size","--tmpfs","--ipc","--pid","--security-opt","--stop-signal","-a","--attach","--cidfile","--expose","--link","--runtime","--userns","--volumes-from","--group-add","--health-cmd"]);function pf(e){let n=1;if((e[n]==="container"||e[n]==="compose")&&n++,e[n]!=="run")return null;let t=null;for(n++;n<e.length;n++){let s=e[n];if(s.startsWith("--entrypoint")&&(t=s.includes("=")?s.slice(s.indexOf("=")+1):e[n+1]??null),!s.startsWith("-"))return{image:$(s),args:t?[t,...e.slice(n+1)]:e.slice(n+1)};($v.has(s)||s==="--entrypoint")&&n++}return null}function ws(e){if(/^\s*(explain|describe|desc|show)\b/i.test(e)||/\bfrom\s+(information_schema|pg_catalog|sys|mysql)\./i.test(e))return!1;let n=e.search(/\bfrom\b/i);if(!/\bselect\b/i.test(e)||n<0)return!1;let t=e.slice(0,n);if(/\bselect\s+(count|sum|avg|min|max)\s*\(/i.test(t)&&!t.includes(","))return!1;let s=/\blimit\s+(\d+)/i.exec(e);return!(s&&Number(s[1])<=1e3)}function Ot(e){for(let n=e;n;n=n.pipeTo)if(n.redirects.some(t=>[">",">>",">|","&>","&>>"].includes(t.op)&&(t.fd===null||t.fd===1)&&t.target!==null&&!t.target.startsWith("/dev/"))||n!==e&&n.name==="tee"&&n.argv.slice(1).some(t=>!t.startsWith("-")))return!0;return!1}var xv=new Set(["-f","--file","-F","--format","-j","--jobs","-n","--schema","-N","--exclude-schema","-t","--table","-T","--exclude-table","-Z","--compress","-E","--encoding","-h","--host","-p","--port","-U","--username","-d","--dbname","--role","-S","--superuser","--exclude-table-data","--lock-wait-timeout","--section","--snapshot","-l","--database"]);function du(e,n){let t=e.argv,s=e.name,r=null,o=!0;switch(s){case"pg_dump":case"pg_dumpall":case"pg_basebackup":{if(I(t,"--schema-only")||t.some(p=>/^-[A-Za-z]+$/.test(p)&&/^[^fFjnNtTZEhpUdSlD]*s/.test(p.slice(1))))return[];r=P(t,"-h","--host")??/(?:^|[\s;&|(])(?:export\s+)?PGHOST=["']?([^\s"';&|)]+)/.exec(n.lineText)?.[1]??null;let u=P(t,"-d","--dbname")??ke(t,1,xv)[0]??null;u!==null&&(S(u)?o=r!==null&&!S(r)&&an(r):/^postgres(ql)?:\/\//i.test(u)?r=/^postgres(?:ql)?:\/\/(?:[^@/]*@)?([^/:?#]*)/i.exec(u)?.[1]||/[?&]host=([^&]+)/.exec(u)?.[1]||r:/\bhost=/.test(u)&&(r=/\bhost=([^\s]+)/.exec(u)?.[1]??r));break}case"psql":case"pgcli":{let u=e.pipeFrom&&["echo","printf","cat"].includes(e.pipeFrom.name)?e.pipeFrom.argv.slice(1).join(" ")+(e.pipeFrom.stdin??""):"",p=[P(t,"-c","--command")??"",e.stdin??"",u].join(`
|
|
79
|
+
`),d=ws(Oe(p))&&(Ot(e)||P(t,"-o","--output")!==null);if(!/\\copy\s+(\([\s\S]{0,4000}?\)|\S+)\s+to\b/i.test(p)&&!/\bcopy\s+(\([\s\S]{0,4000}?\)|\S+)\s+to\s+stdout\b/i.test(p)&&!d)return[];r=P(t,"-h","--host");let f=P(t,"-d","--dbname")??Od(t)[0]??null;f!==null&&(S(f)?o=r!==null&&!S(r)&&an(r):(/^postgres(ql)?:\/\//i.test(f)||/\bhost=/.test(f))&&(r=/\bhost=([^\s]+)/.exec(f)?.[1]??me(f)??r));break}case"mysqldump":case"mariadb-dump":case"mysqlpump":case"mydumper":if(I(t,"--no-data","-d"))return[];r=P(t,"-h","--host");break;case"mysql":case"mariadb":case"clickhouse-client":case"clickhouse":{let u=P(t,"-e","--execute","-q","--query")??e.stdin??"";if(!ws(Oe(u,"mysql"))||!(Ot(e)||/\binto\s+outfile\b/i.test(u)))return[];r=P(t,"-h","--host");break}case"mongosh":case"mongo":{let u=P(t,"--eval")??e.stdin??"";if(!/\.(find|aggregate)\s*\(/.test(u)||!Ot(e))return[];let p=t.slice(1).find(d=>/^mongodb(\+srv)?:\/\//i.test($(d))||S(d)&&!d.startsWith("-"))??null;r=P(t,"--host")??(p&&!S(p)?me(p):null),p!==null&&S(p)&&(o=!1);break}case"sqlcmd":{let u=P(t,"-Q","-q")??e.stdin??"";if(!ws(Oe(u))||!(P(t,"-o")!==null||Ot(e)))return[];r=(P(t,"-S")??"").replace(/^tcp:/i,"").split(/[,\\]/)[0]||null,r!==null&&/^(\.|\(local\)|localhost)$/i.test(r)&&(r="localhost"),r===null&&(o=!1);break}case"bcp":{if(!["out","queryout"].includes(t[2]??""))return[];r=P(t,"-S"),r!==null&&/^(\.|\(local\)|localhost)(\\|,|$)/i.test(r)&&(r="localhost"),r===null&&(o=!1);break}case"mongodump":case"mongoexport":{let u=P(t,"--uri")??t.find(p=>/^mongodb(\+srv)?:\/\//i.test($(p)))??null;r=P(t,"--host","-h")??(u&&!S(u)?me(u):null),u!==null&&S(u)&&(o=!1);break}case"redis-cli":{if(!I(t,"--rdb"))return[];let u=P(t,"-u");r=P(t,"-h")??(u?S(u)?u:me(u):null),u!==null&&S(u)&&(o=!1);break}case"snowsql":case"snow":{let u=_(t);if(s==="snow"&&u[0]!=="sql")return[];let p=P(t,"-q","--query")??e.stdin??"";return ws(Oe(p,"snowflake"))&&(Ot(e)||t.some(d=>/^output_file=/i.test(d)))?[w("claude.bash.data.export",`${s} copies query rows from Snowflake onto this machine`,{target:"snowflake",host:"snowflake",is_local:!1})]:[]}case"bq":{let u=_(t),p=u[0]==="query"?[u.slice(1).join(" "),e.stdin??""].join(`
|
|
80
|
+
`):"";return u[0]==="query"&&ws(Oe(p,"bigquery"))&&Ot(e)?[w("claude.bash.data.export","bq query copies table rows onto this machine",{target:"bigquery",host:"bigquery",is_local:!1})]:[]}case"gsutil":case"gcloud":{if(ce("compute","ssh")(t)&&/\b(pg_dump|pg_dumpall|mysqldump|mongodump|mongoexport)\b/.test(P(t,"--command")??"")&&Ot(e))return[w("claude.bash.data.export","dumps a database on a VM and streams it onto this machine",{target:"gcloud compute ssh",host:"gcloud",is_local:!1})];let u=_(t),p=s==="gsutil"?u.slice(1):u[0]==="storage"?u.slice(2):[],d=s==="gsutil"?u[0]:u[1];return["cp","rsync"].includes(d??"")&&p.length>=2&&p[0].startsWith("gs://")&&!p[p.length-1].startsWith("gs://")&&/\bbq\s+extract\b/.test(n.lineText)?[w("claude.bash.data.export","downloads a table the line exported from BigQuery",{target:p[0],host:"bigquery",is_local:!1})]:[]}case"wrangler":return _(t)[0]==="d1"&&_(t)[1]==="export"&&I(t,"--remote")&&!I(t,"--no-data")?[w("claude.bash.data.export","wrangler d1 export copies a remote D1 database onto this machine",{target:"d1",host:"cloudflare",is_local:!1})]:[];case"pscale":return ce("database","dump")(t)?[w("claude.bash.data.export","pscale database dump copies a PlanetScale database onto this machine",{target:"planetscale",host:"planetscale",is_local:!1})]:[];case"turso":return ce("db","shell")(t)&&t.some(u=>u===".dump")?[w("claude.bash.data.export","turso db shell .dump copies a Turso database onto this machine",{target:"turso",host:"turso",is_local:!1})]:[];case"aws":return ce("dynamodb","scan")(t)&&Ot(e)?[w("claude.bash.data.export","aws dynamodb scan copies a table onto this machine",{target:"dynamodb",host:"dynamodb",is_local:!1})]:[];case"curl":case"wget":return/\bheroku\s+pg:backups:url\b/.test(n.lineText)?[w("claude.bash.data.export","downloads a Heroku production backup onto this machine",{target:"heroku",host:"heroku",is_local:!1})]:[];case"fly":case"flyctl":{let u=P(t,"-C","--command")??"";return ce("ssh","console")(t)&&/\b(pg_dump|pg_dumpall|mysqldump|mongodump|mongoexport)\b/.test(u)?[w("claude.bash.data.export","dumps a Fly database and streams it onto this machine",{target:"fly",host:"fly",is_local:!1})]:[]}case"heroku":return/^pg:(pull|backups:download)$/.test(_(t)[0]??"")?[w("claude.bash.data.export",`heroku ${_(t)[0]} copies a production database onto this machine`,{target:"heroku",host:"heroku",is_local:!1})]:[];case"supabase":return ce("db","dump")(t)&&I(t,"--data-only")&&!I(t,"--local")&&!wd(t)?[w("claude.bash.data.export","supabase db dump copies a linked database's data onto this machine",{target:"supabase",host:"supabase",is_local:!1})]:[];default:return[]}let a=e.remote===null||e.remote.startsWith("container:"),i=Pt(n.lineText),l=r===null||!S(r)&&an(r);if(o&&!e.productionEnv&&a&&l&&i===null)return[];let c=i!==null&&l?`a database forwarded here (${i})`:r?Fn(r):e.productionEnv?"production (railway run)":e.remote??"a database the command does not name";return[w("claude.bash.data.export",`${s} copies the data of ${c} onto this machine`,{target:c,host:r?Fn(r):e.remote,is_local:!1})]}var _v=/^((https?|wss?):\/\/)?(localhost|127\.0\.0\.1|0\.0\.0\.0|\[::1\]|anvil|hardhat|ganache)\b|^(localhost|hardhat|anvil|ganache|localnet|local|development|l)$/i,fu=/sepolia|holesky|hoodi|goerli|rinkeby|ropsten|kovan|testnet|devnet|localnet|amoy|mumbai|fuji|chapel|alfajores|chiado|moonbase|baobab|calibration|shasta|nile|bepolia|hekla|garnet|cardona|fork|^d$|^t$/i,pu=/0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80|0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d/i;function nt(e){if(e===null)return!1;let n=$(e).replace(/^["']|["']$/g,""),t=/^([a-z][a-z0-9+.-]*:\/\/)?([^/?#\s]+)([^?#\s]*)/i.exec(n);if(t&&(t[1]||t[3])){let s=t[2].replace(/:\d+$/,"").replace(/^[^@]*@/,"").toLowerCase();return/^(localhost|127\.0\.0\.1|0\.0\.0\.0|\[::1\]|anvil|hardhat|ganache|host\.docker\.internal)$/.test(s)?!0:fu.test(`${s}${t[3]}`)}return _v.test(n)||fu.test(n)}function hu(e,n){let t=e.argv,s=_(t),r=i=>i===null?null:Fn(i),o=(i,l)=>[w("claude.bash.crypto.transaction",`${i} on ${r(l)??"a network the command does not name"}`,{target:`${e.name} ${s[0]??""}`.trim(),host:r(l),is_local:!1})],a=()=>P(t,"--rpc-url","-r","--fork-url",...e.name==="forge"?["-f"]:[])??/(?:^|[\s;&|(])(?:export\s+)?ETH_RPC_URL=["']?([^\s"';&|)]+)/.exec(n.lineText)?.[1]??null;switch(e.name){case"cast":{if(!(["send","s","publish"].includes(s[0]??"")||s[0]==="rpc"&&/^(eth_sendRawTransaction|eth_sendTransaction|personal_sendTransaction)$/.test(s[1]??"")))return[];let l=a();return nt(l)||l===null&&pu.test(t.join(" "))?[]:o(`cast ${s[0]} sends a transaction`,l)}case"forge":{if(!(s[0]==="script"&&I(t,"--broadcast","--resume")||s[0]==="create"))return[];let l=a();return nt(l)||l===null&&pu.test(t.join(" "))?[]:o(`forge ${s[0]} ${s[0]==="create"?"deploys a contract":"broadcasts transactions"}`,l)}case"solana":case"spl-token":{if(!(e.name==="solana"?["transfer","deploy","pay","delegate-stake","deactivate-stake","withdraw-stake","create-stake-account","split-stake","merge-stake","withdraw-from-vote-account","close-vote-account"].includes(s[0]??"")||s[0]==="program"&&["deploy","close","set-upgrade-authority","extend","write-buffer","upgrade"].includes(s[1]??""):["transfer","mint","burn","close","authorize","approve","create-token","create-account","wrap","unwrap","freeze","thaw"].includes(s[0]??"")))return[];let l=P(t,"--url","-u")??/\bsolana\s+config\s+set\s+(?:--url|-u)\s+(\S+)/.exec(n.lineText)?.[1]??null,c={m:"mainnet-beta",d:"devnet",t:"testnet",l:"localhost"};return nt(l)?[]:o(`${e.name} ${s[0]} sends a transaction`,l===null?null:c[l]??l)}case"anchor":{if(!["deploy","upgrade","migrate"].includes(s[0]??""))return[];let i=P(t,"--provider.cluster");return nt(i)?[]:o(`anchor ${s[0]} deploys a program`,i)}case"bitcoin-cli":case"lncli":{let i=ke(t,1,new Set(["--network","--rpcserver","--macaroonpath","--tlscertpath","--lnddir","--chain","--profile"]))[0]??"";if(!(e.name==="bitcoin-cli"?["sendtoaddress","sendmany","send","sendall","sendrawtransaction","bumpfee"].includes(i):["sendpayment","payinvoice","sendcoins","sendmany","openchannel","closechannel","closeallchannels","sendtoroute"].includes(i)))return[];let c=t.find(p=>/^-(regtest|testnet|testnet4|signet)$|^--?(chain|network)=/.test(p))??(P(t,"--network","--chain")!==null?`--network=${P(t,"--network","--chain")}`:null);return c!==null&&/regtest|testnet|signet|(chain|network)=(test|regtest|signet|simnet)/i.test(c)?[]:o(`${e.name} ${i} sends a payment`,c===null?"mainnet":c)}case"near":{let i=["deploy","send","send-near","call","delete","delete-account","stake","contract","tokens","transaction"].includes(s[0]??""),l=t.some(c=>/mainnet/i.test(c)||/\.near$/.test(c))||/\bNEAR_ENV=mainnet\b/.test(n.lineText);return i&&l?o(`near ${s[0]} sends a transaction`,"mainnet"):[]}case"starkli":{if(!["invoke","deploy","declare","transfer"].includes(s[0]??"")&&!(s[0]==="account"&&s[1]==="deploy"))return[];let i=P(t,"--network","--rpc");return nt(i)?[]:o(`starkli ${s[0]} sends a transaction`,i)}case"stellar":case"soroban":{if(!(s[0]==="contract"&&["invoke","deploy","install","upload","extend","restore"].includes(s[1]??"")||s[0]==="tx"&&["send","new"].includes(s[1]??"")))return[];let l=P(t,"--network","--rpc-url");return l!==null&&/^(testnet|futurenet|local|standalone)$/i.test(l)?[]:nt(l)?[]:o(`${e.name} ${s[0]} ${s[1]} sends a transaction`,l)}case"cardano-cli":return t.includes("submit")?t.some(i=>i==="--testnet-magic"||i.startsWith("--testnet-magic="))?[]:o("cardano-cli submits a transaction",t.includes("--mainnet")?"mainnet":null):[];case"sui":{if(!(s[0]==="client"&&["publish","upgrade","transfer","transfer-sui","pay","pay-sui","pay-all-sui","call","split-coin","merge-coin","ptb"].includes(s[1]??"")))return[];let l=P(t,"--client.env")??/\bsui\s+client\s+switch\s+--env\s+(\S+)/.exec(n.lineText)?.[1]??null;return nt(l)?[]:o(`sui client ${s[1]} sends a transaction`,l)}case"aptos":{if(!(s[0]==="move"&&["publish","run","deploy-object","upgrade-object","create-object-and-publish-package","run-script"].includes(s[1]??"")||s[0]==="account"&&["transfer"].includes(s[1]??"")))return[];let l=P(t,"--profile","--url")??null;return nt(l)?[]:o(`aptos ${s[0]} ${s[1]} sends a transaction`,l)}case"ape":{if(s[0]!=="run")return[];let i=P(t,"--network");return i===null||nt(i)?[]:o(`ape run ${s[1]??""} sends transactions`,i)}case"hardhat":case"truffle":case"brownie":{let i=s[0]==="ignition"?s[1]??"":s[0]??"";if(!(["run","deploy","migrate"].includes(i)||/deploy|mint|transfer|send|upgrade|migrat|withdraw|airdrop|burn|propose|execute/i.test(i)))return[];let c=P(t,"--network")??(e.name==="hardhat"?/(?:^|[\s;&|(])(?:export\s+)?HARDHAT_NETWORK=["']?([^\s"';&|)]+)/.exec(n.lineText)?.[1]??null:null);return c===null||nt(c)?[]:o(`${e.name} ${i} sends transactions`,c)}default:{if(/^[a-z]+d$/.test(e.name)&&s[0]==="tx"&&!I(t,"--generate-only","--dry-run")){let i=P(t,"--chain-id"),l=P(t,"--node");return i!==null&&/test|devnet|local/i.test(i)||l!==null&&nt(l)?[]:o(`${e.name} tx ${s[1]??""} broadcasts a transaction`,i??l)}return[]}}}var jt=(e,...n)=>e.some(t=>n.some(s=>new RegExp(`^(?:/{1,2}|-)${s}(?::.*)?$`,"i").test(t))),ci=(e,...n)=>{for(let t=0;t<e.length;t++)for(let s of n){let r=new RegExp(`^(?:/{1,2}|-)${s}(?::(.*))?$`,"i").exec(e[t]);if(r)return r[1]??e[t+1]??null}return null},gu=/[\\/](?:Run|RunOnce|RunServices|RunServicesOnce)\b|[\\/]Winlogon\b|[\\/]Services[\\/]|[\\/]Image File Execution Options[\\/]|[\\/]Explorer[\\/]Shell Folders|[\\/]Policies[\\/]Explorer[\\/]Run|^(?:Registry::)?HK(?:CU|EY_CURRENT_USER):?[\\/]Environment\b|[\\/]Session Manager[\\/]Environment\b|[\\/]Command Processor\b/i,Sv=new Set(["format","format-volume","clear-disk","initialize-disk","remove-partition","clear-recyclebin","diskpart","vssadmin","wmic","wbadmin","wsl","bcdedit","reg","set-itemproperty","new-itemproperty","remove-itemproperty","remove-item","sc","new-service","remove-service","set-service","stop-service","register-scheduledtask","set-scheduledtask","unregister-scheduledtask","new-scheduledtask","set-executionpolicy","set-mppreference","add-mppreference","netsh","set-netfirewallprofile","new-netfirewallrule","disable-netfirewallrule","remove-netfirewallrule","takeown","icacls","taskkill","runas","gsudo","mountvol","robocopy","setx","forfiles"]);function Cv(e,n){let t=e.argv.slice(1),s=t.join(" "),r={is_local:e.remote===null,host:e.remote},o=(a,i,l={})=>[w(a,i,{target:e.argv.slice(0,4).join(" "),...r,...l})];switch(e.name){case"format":case"format-volume":case"clear-disk":case"initialize-disk":case"remove-partition":return t.length>0||e.name!=="format"?o("claude.bash.fs.delete_recursive",`formats or wipes a drive (${e.name})`,{service:"fs.device"}):[];case"diskpart":return o("claude.bash.fs.delete_recursive","changes disks and partitions (diskpart)",{service:"fs.device"});case"clear-recyclebin":return o("claude.bash.fs.delete_recursive","empties the Recycle Bin, deleting what is in it for good",{target:"the Recycle Bin"});case"vssadmin":return/\b(delete|resize)\s+shadow/i.test(s)?o("claude.bash.fs.delete_recursive","deletes Windows' restore points (shadow copies)",{service:"fs.system"}):[];case"wmic":return/\bshadowcopy\b.*\bdelete\b/i.test(s)?o("claude.bash.fs.delete_recursive","deletes Windows' restore points (shadow copies)",{service:"fs.system"}):[];case"wbadmin":return/\bdelete\b/i.test(s)?o("claude.bash.fs.delete_recursive","deletes Windows' backups (wbadmin)",{service:"fs.system"}):[];case"wsl":return jt(t,"unregister")||t.includes("--unregister")?o("claude.bash.fs.delete_recursive","unregisters a Linux distribution, deleting its whole disk (wsl --unregister)",{service:"fs.root"}):[];case"bcdedit":return t.length===0||jt(t,"enum","v")?[]:o("claude.bash.privilege","changes how Windows starts (bcdedit)");case"reg":{let a=(t[0]??"").toLowerCase();if(["query","compare","export"].includes(a))return[];let i=t[1]??"";return gu.test(i)?o("claude.bash.persistence",`changes what Windows starts at sign-in or boot (reg ${a} ${i})`):/^HK(LM|EY_LOCAL_MACHINE)/i.test(i)?o("claude.bash.privilege",`changes Windows' machine-wide settings (reg ${a})`):[]}case"set-itemproperty":case"new-itemproperty":case"remove-itemproperty":case"remove-item":{let a=ci(t,"path","literalpath")??t.find(i=>!i.startsWith("-"))??"";return/^(HK(CU|LM|CR|U|CC)|HKEY_|Registry::)/i.test(a)?gu.test(a)?o("claude.bash.persistence",`changes what Windows starts at sign-in or boot (${a})`):/^(HKLM|HKEY_LOCAL_MACHINE)/i.test(a)?o("claude.bash.privilege","changes Windows' machine-wide settings (the registry)"):[]:[]}case"sc":{let a=(t[0]??"").toLowerCase();return["create","config","delete","failure","sidtype","privs"].includes(a)?o("claude.bash.persistence",`changes a Windows service (sc ${a})`):a==="stop"?o("claude.bash.process.kill_by_name",`stops a Windows service (sc stop ${t[1]??""})`):[]}case"new-service":case"remove-service":return o("claude.bash.persistence",`changes a Windows service (${e.name})`);case"set-service":return jt(t,"startuptype")?o("claude.bash.persistence","changes when a Windows service starts"):[];case"stop-service":return o("claude.bash.process.kill_by_name",`stops a Windows service (${t.find(a=>!a.startsWith("-"))??""})`);case"register-scheduledtask":case"set-scheduledtask":case"unregister-scheduledtask":case"new-scheduledtask":return o("claude.bash.persistence",`changes Windows scheduled tasks (${e.name})`);case"set-executionpolicy":return o("claude.bash.privilege","changes which PowerShell scripts may run (Set-ExecutionPolicy)");case"set-mppreference":case"add-mppreference":return/-(Disable\w+|Exclusion\w+)/i.test(s)?o("claude.bash.privilege","turns off or narrows Microsoft Defender's checks"):[];case"netsh":return/firewall\b.*\b(state\s+off|disable|delete|add\s+rule|set\s+rule)/i.test(s)||/\bportproxy\b.*\badd\b/i.test(s)?o("claude.bash.net.expose","changes the Windows firewall or forwards a port (netsh)"):[];case"set-netfirewallprofile":case"new-netfirewallrule":case"disable-netfirewallrule":case"remove-netfirewallrule":return o("claude.bash.net.expose",`changes the Windows firewall (${e.name})`);case"takeown":return o("claude.bash.privilege",`takes ownership of files (takeown${jt(t,"r")?" /r":""})`);case"icacls":return jt(t,"grant","reset","setowner","inheritance","remove","deny")?o("claude.bash.privilege","changes who may read or change files (icacls)"):[];case"taskkill":{let a=ci(t,"im");if(a)return o("claude.bash.process.kill_by_name",`kills every ${a} process (taskkill /im)`,{target:a});let i=ci(t,"fi");return i?/^\s*imagename\s+eq\s+\S+\s*$/i.test(i)?o("claude.bash.process.kill_by_name",`kills every process its filter names (taskkill /fi "${i}")`,{target:i}):o("claude.bash.process.kill_by_name",`kills every process its filter matches (taskkill /fi "${i}")`,{target:i,service:"proc.all"}):[]}case"robocopy":{if(!jt(t,"mir","purge"))return[];let a=`robocopy ${jt(t,"mir")?"/mir":"/purge"}`,i=t.filter(l=>!/^\/{1,2}[A-Za-z]+(?::.*)?$/.test(l));return i.length<2?o("claude.bash.fs.delete_recursive",`${a} deletes from a folder the line does not show`):/^[A-Za-z]:(?![\\/])/.test(i[1])?o("claude.bash.fs.delete_recursive",`${a} deletes from ${i[1]}, a folder under a drive's current folder`):rd({...e,name:"rsync",argv:["rsync","-a","--delete",i[0],i[1]]},n).map(l=>({...l,why:l.why.replace(/^rsync --delete/,a)}))}case"setx":return t.length>0?o("claude.bash.persistence",`sets an environment variable every later program starts with (setx ${t.find(a=>!a.startsWith("/"))??""})`):[];case"runas":case"gsudo":return o("claude.bash.privilege",`runs a command as another user or as an administrator (${e.name})`);case"mountvol":return jt(t,"d","p")?o("claude.bash.fs.delete_recursive","removes a drive from Windows (mountvol)",{service:"fs.device"}):[];default:return[]}}function Av(e){let n=e.argv,t=s=>[w("claude.bash.persistence",s,{target:n.slice(0,3).join(" "),is_local:e.remote===null,host:e.remote})];switch(e.name){case"crontab":{let s=n.slice(1).filter(r=>/^-[A-Za-z]+$/.test(r));return s.some(r=>r.includes("r"))?t("crontab -r deletes every scheduled job"):s.some(r=>/[lTV]/.test(r))?[]:s.some(r=>r.includes("e"))?t("crontab -e changes scheduled jobs"):t("crontab replaces every scheduled job")}case"launchctl":{let s=n.slice(1).find(r=>!r.startsWith("-"))??"";return["load","bootstrap","enable","submit"].includes(s)?t(`launchctl ${s} installs a background job`):[]}case"systemctl":{let s=n.slice(1).find(r=>!r.startsWith("-"))??"";return["enable","link","mask","preset","preset-all","set-default","edit","add-wants","add-requires"].includes(s)?t(`systemctl ${s} changes what starts at boot`):[]}case"pm2":return _(n)[0]==="startup"?t("pm2 startup makes processes start at boot"):[];case"brew":return _(n)[0]==="services"&&["start","restart"].includes(_(n)[1]??"")?t(`brew services ${_(n)[1]} registers a job that starts at login`):[];case"osascript":return/\bmake\s+(new\s+)?login\s+item\b/i.test(n.join(" "))?t("osascript adds a login item"):[];case"powershell":case"powershell.exe":case"pwsh":case"pwsh.exe":{let s=P(n,"-Command","-c","-command")??"",r=o=>new RegExp(`(^|[;|{(\\n&]\\s*)(${o})`,"i").test(s.trim());return r("Register-ScheduledTask|Set-ScheduledTask|Unregister-ScheduledTask|New-Service|schtasks(\\.exe)?\\s+\\/(create|change|delete)")||r("Set-Service\\b[^;|\\n]*-StartupType\\s+Automatic")?t("PowerShell changes scheduled tasks or services"):[]}case"schtasks":case"schtasks.exe":return n.some(s=>(Z()?/^\/{1,2}(create|change|delete)$/i:/^\/(create|change|delete)$/i).test(s))?t("schtasks changes Windows scheduled tasks"):[];case"at":case"batch":return I(n,"-l","-r","-d","-c")?[]:e.name==="batch"||n.slice(1).some(s=>!s.startsWith("-"))?t(`${e.name} schedules a command to run later`):[];default:return[]}}var Ev=/^(core\.(hookspath|sshcommand|fsmonitor|askpass|gitproxy)|credential\..+|url\..+\.(insteadof|pushinsteadof)|https?\..*\.?(sslcainfo|sslcapath|proxy|extraheader|sslcert|sslkey)|include\.path|includeif\..+\.path|init\.templatedir|filter\..+\.(clean|smudge|process)|diff\..+\.textconv|merge\..+\.driver|gpg\.(program|ssh\.program|x509\.program|openpgp\.program))$/i;function Rv(e,n){if(e.name!=="git")return[];let t=Xe(e);if(!t||t.sub!=="config")return[];let s=[...t.args],r="set",o=s[0]??"";["set","unset","get","list","edit","rename-section","remove-section"].includes(o)&&(s.shift(),r=o==="get"||o==="list"?"read":o==="edit"?"edit":o==="set"?"set":"unset");let a=!1,i=[];for(let f=0;f<s.length;f++){let h=s[f];if(h==="--global"||h==="--system")a=!0;else if(h==="-f"||h==="--file"||h.startsWith("--file=")){let g=h.startsWith("--file=")?h.slice(7):s[++f]??"";Ji(M(g,e.cwd,n.ctx),n.ctx,[n.ctx.home])==="gitconfig"&&(a=!0)}else h==="--unset"||h==="--unset-all"||h==="--remove-section"||h==="--rename-section"?r="unset":/^(--get|--get-all|--get-regexp|--get-urlmatch|--get-color|--get-colorbool|-l|--list)$/.test(h)?r="read":h==="-e"||h==="--edit"?r="edit":["--type","--default","--comment","--value","-t"].includes(h)?f++:h.startsWith("-")||i.push(h)}if(!a||r==="read")return[];let l=/^\s*(?:\w+=\S*\s+)*(?:HOME|GIT_CONFIG_GLOBAL|XDG_CONFIG_HOME)=["']?([^\s"']+)/.exec(e.text)?.[1]??/(?:^|[;&|\n(]\s*)(?:export\s+)?(?:HOME|GIT_CONFIG_GLOBAL|XDG_CONFIG_HOME)=["']?([^\s"';&|)]+)["']?\s*(?=$|[;&\n|])/.exec(n.lineText.slice(0,Math.max(0,n.lineText.indexOf(e.text))))?.[1];if(l!==void 0&&vt(M(l,e.cwd,n.ctx),n))return[];let c=(i[0]??"").replace(/(:\/\/)[^@/\s]+@/g,"$1***@"),u=f=>[w("claude.bash.persistence",f,{target:c||"git config --global",is_local:!0})];if(r==="edit")return u("git config --global --edit rewrites the global git config");let p=(i[0]??"").toLowerCase(),d=i[1]??"";return r==="unset"?p==="core.hookspath"?u("turns off the git hooks every repository on this machine runs"):[]:i.length<2?[]:/^https?\..*sslverify$/.test(p)?/^(false|0|no|off)$/i.test(d)?u("turns off TLS certificate checks for every repository on this machine"):[]:/^alias\./.test(p)?d.startsWith("!")?u(`adds a git alias that runs a shell command (${i[0]})`):[]:p==="core.fsmonitor"?/^(true|false|0|1|yes|no|on|off)$/i.test(d)?[]:u(`sets ${c} to run a program for every repository`):/^protocol\..*allow$/.test(p)?/^always$/i.test(d)?u(`allows a git transport that can run commands (${c})`):[]:p==="diff.external"?/^(difft|difftastic|delta|diff-so-fancy|icdiff|meld|opendiff|kdiff3|code|ksdiff)(\s|$)/.test(O.basename(d))?[]:u(`sets ${c} to run a program on every diff`):/^(core\.(pager|editor)|sequence\.editor|interactive\.difffilter|pager\.\w+)$/.test(p)?/[;&`>]|\$\(|\b(curl|wget|nc|ncat|base64)\b|\b(sh|bash|zsh|python3?|node|perl|ruby)\s+-[ce]\b/.test(d)?u(`sets ${c} to run a shell command for every repository`):[]:Ev.test(p)?u(`sets ${c} for every repository on this machine`):[]}function Ov(e){let n=Ls(e);if(n===null)return[];let t=ra(n.slice(0,65536));if(!Vi(t)||!Bi.test(t))return[];let s=/\.delete\s*\(|method\s*[:=]\s*['"]DELETE|request\s*\(\s*['"]DELETE/i.test(t)?"DELETE":/\.(post|put|patch)\s*\(|method\s*[:=]\s*['"](POST|PUT|PATCH)|request\s*\(\s*['"](POST|PUT|PATCH)|Request\([^)]*data\s*=|-X\s*POST/i.test(t)?"POST":null,r=s!==null?fd(t,s,t):null;return r!==null?[w("claude.agent.controls",`changes your Anvil workspace's modes through its API (${r})`,{target:r,is_local:!1})]:[]}function hf(e,n,t){let s=n.lineText.slice(0,Math.max(0,n.lineText.indexOf(e.text))),r=t.join("|"),o=new RegExp(`^\\s*(?:\\w+=\\S*\\s+)*(?:${r})=["']?([^\\s"']+)`).exec(e.text)?.[1],a=[...s.matchAll(new RegExp(`(?:^|[;&|\\n(]\\s*)(?:export\\s+)?(?:${r})=["']?([^\\s"';&|)]+)`,"g"))].map(u=>u[1]),i=o??a[a.length-1];if(!i)return null;let l=i.replace(/^\$\{?([A-Za-z_]\w*)\}?/,(u,p)=>{let d=new RegExp(`(?:^|[;&|\\n(]\\s*)(?:export\\s+)?${p}=(?:"?\\$\\(mktemp\\b[^)]*\\)"?|["']?([^\\s"';&|)]+))`).exec(s);return d?d[1]??`${n.ctx.tmpdir.replace(/(?<!\/)\/+$/,"")}/mktemp`:u});if(S(l)||l.includes("$"))return null;let c=te(l,e.cwd,le(n));return c.kind==="disposable"&&c.why!==rs?c.path:null}var jv=new Set(["node","nodejs","bun","deno","tsx","ts-node","sh","bash","zsh","dash","ksh","source",".","python","python3","perl","ruby"]),Pv=/(?:\.anvil\/claude\/bin\/|useanvil\S*\/|\/anvil\/bin\/)claude-(?:hook|hook-core|sync|meter)\.(?:[cm]?js|sh)\b/;function Wv(e,n){let t=e.argv,s=_(t),r=i=>[w("claude.agent.controls",i,{target:`${e.name} ${s[0]??""}`.trim(),is_local:!0})],o=t.findIndex((i,l)=>t[l+1]==="claude"&&/\$\(|`/.test($(i))&&/(^|[^\w.-])anvil($|[^\w.-])/.test($(i)));if(o>=0){let i=us(_(["anvil",...t.slice(o+1)]));if(i)return r(i)}let a=t.findIndex(i=>/\$\(|`/.test($(i))&&/(^|[^\w.-])anvil-claude($|[^\w.-])/.test($(i)));if(a>=0){let i=lr(_(["anvil-claude",...t.slice(a+1)]),t.slice(a+1));if(i)return r(i)}if(jv.has(e.name)){let i=t.findIndex((l,c)=>c>0&&Pv.test(/^[/~$]/.test($(l))?$(l):`${e.cwd??""}/${$(l)}`));if(i>0&&!(/claude-sync\.js$/.test($(t[i]))&&t.length===i+2&&t[i+1]==="--status"))return r("runs Anvil's own hook by hand: what it records would be made up")}switch(e.name){case"claude":{if((s[0]==="plugin"||s[0]==="plugins")&&["list","ls","validate"].includes(s[1]??"")&&!(s[1]==="list"&&s[2]==="marketplace")||s[0]==="mcp"&&["list","get"].includes(s[1]??"")||s[0]==="config"&&["get","list"].includes(s[1]??"")||s.length===0&&I(t,"--version","-v"))return[];let i=(s[0]==="plugin"||s[0]==="plugins")&&["install","i","enable","disable","uninstall","remove","rm","marketplace"].includes(s[1]??"")||s[0]==="mcp"&&["add","add-json","add-from-claude-desktop","remove"].includes(s[1]??"")||s[0]==="config"&&["set","add","remove"].includes(s[1]??""),l=t.some((k,E)=>["-s","--scope"].includes(t[E-1]??"")&&/^(project|local)$/.test(k)||/^(--scope=|-s)(project|local)$/.test(k));if(i&&!l&&hf(e,n,["HOME","CLAUDE_CONFIG_DIR"]))return[];if(s[0]==="mcp"&&["add","add-json","add-from-claude-desktop"].includes(s[1]??""))return r(`claude mcp ${s[1]} gives Claude Code a new MCP server`);if(s[0]==="config"&&["set","add"].includes(s[1]??""))return r("claude config changes Claude Code's settings");if(s[0]==="import")return r("claude import brings another agent's MCP servers and settings into Claude Code");if((s[0]==="plugin"||s[0]==="plugins")&&(["install","i","enable"].includes(s[1]??"")||s[1]==="marketplace"&&s[2]==="add"))return r(`claude plugin ${s.slice(1,3).join(" ")} gives Claude Code new hooks, tools or MCP servers`);if((s[0]==="plugin"||s[0]==="plugins")&&(["disable","uninstall","remove","rm"].includes(s[1]??"")||s[1]==="marketplace"&&["remove","rm"].includes(s[2]??"")))return r(`claude plugin ${s.slice(1,3).join(" ")} turns off hooks Claude Code was running`);if(I(t,"--dangerously-skip-permissions","--allow-dangerously-skip-permissions")||P(t,"--permission-mode")==="bypassPermissions")return r("runs Claude Code with its permission checks off");let c=P(t,"--setting-sources"),u=c?.split(",").map(k=>k.trim())??[];if(c!==null&&!(u.includes("user")&&u.includes("local")))return r("runs Claude Code without your user or local settings, where Anvil's hook is");let d=`${/^\s*((?:(?:env\s+(?:-\S+\s+)*)?[A-Za-z_][A-Za-z0-9_]*=(?:'[^']*'|"[^"]*"|\S*)\s+)+)/.exec(e.text)?.[1]??""} ${e.text.slice(0,Math.max(0,e.text.search(/(^|[\s/])claude(\s|$)/)))}`,f=n.lineText.slice(0,65536);if(/(^|\s)(CLAUDE_CONFIG_DIR|HOME)=/.test(d)||/(^|[\s;&|(])(export|declare\s+-x)\s+(CLAUDE_CONFIG_DIR|HOME)=/.test(f)||/(^|[\s;&|(])CLAUDE_CONFIG_DIR=/.test(f))return r("runs Claude Code with its settings folder moved, away from Anvil's hook");if(/(^|\s)(ANVIL_API_KEY|ANVIL_API_BASE_URL|ANVIL_WORKSPACE_KEYS_PATH)=/.test(d)||/(^|[\s;&|(])export\s+(ANVIL_API_KEY|ANVIL_API_BASE_URL|ANVIL_WORKSPACE_KEYS_PATH)=/.test(f))return r("runs Claude Code under another account's key, whose modes its sync would take");if(/(^|[\s;&|(])unset\s+(-v\s+)?CLAUDE_CONFIG_DIR\b|\benv\s+(?:-\S+\s+)*-u\s*CLAUDE_CONFIG_DIR\b/.test(f))return r("runs Claude Code without the settings folder this session uses, where Anvil's hook is");if(I(t,"--bare","--safe-mode")||/(^|\s)(CLAUDE_CODE_SIMPLE|CLAUDE_CODE_SAFE_MODE)=/.test(d)||/(^|[\s;&|(])(export\s+|declare\s+-x\s+)?(CLAUDE_CODE_SIMPLE|CLAUDE_CODE_SAFE_MODE)=/.test(f))return r("runs Claude Code with hooks and plugins skipped, Anvil's among them");let h=P(t,"--settings");if(h!==null&&/bypassPermissions|dangerously|"Bash(\(\*\))?"|disableAllHooks|"hooks"\s*:/.test(h))return r("runs Claude Code with settings that turn its permission checks off");let g=[];for(let k=1;k<t.length;k++)if(t[k]==="--allowedTools"||t[k]==="--allowed-tools"||/^--allowed-?[tT]ools=/.test(t[k])){t[k].includes("=")&&g.push(t[k].slice(t[k].indexOf("=")+1));for(let E=k+1;E<t.length&&!t[E].startsWith("-");E++)g.push(t[E])}if(g.some(k=>/(^|[\s,'"])Bash(\(\*\))?($|[\s,'"])/.test(k)))return r("runs Claude Code with every shell command allowed");let b=P(t,"--mcp-config");return b!==null&&!/^\s*\{\s*("mcpServers"\s*:\s*\{\s*\}\s*)?\}\s*$/.test(b)?r("runs Claude Code with MCP servers from a config file"):h!==null&&!h.trim().startsWith("{")?r("runs Claude Code with settings from a file the command does not show"):[]}case"fish":case"set":return/\bset\s+-[a-zA-Z]*U[a-zA-Z]*\s+(CLAUDE_CONFIG_DIR|CLAUDE_CODE_SIMPLE|CLAUDE_CODE_SAFE_MODE|ANVIL_CLAUDE_SYNC|ANVIL_WORKSPACE_KEYS_PATH)\b/.test(e.name==="set"?`set ${t.slice(1).join(" ")}`:t.slice(1).join(" "))?r("a fish universal variable changes how every later Claude Code session starts"):[];case"launchctl":{let i=["CLAUDE_CONFIG_DIR","CLAUDE_CODE_SIMPLE","CLAUDE_CODE_SAFE_MODE","ANVIL_CLAUDE_SYNC","ANVIL_WORKSPACE_KEYS_PATH"];return s[0]==="setenv"&&i.includes(s[1]??"")?r(`launchctl setenv ${s[1]} changes how every later Claude Code session starts`):[]}case"anvil":{let i=us(s);if(i)return r(i);let l=/^\s*((?:[A-Za-z_][A-Za-z0-9_]*=\S*\s+)+)/.exec(e.text)?.[1]??"";return s[0]==="claude"&&(/(^|\s)(ANVIL_API_KEY|ANVIL_API_BASE_URL|ANVIL_WORKSPACE_KEYS_PATH)=/.test(l)||/(^|[\s;&|(])export\s+(ANVIL_API_KEY|ANVIL_API_BASE_URL|ANVIL_WORKSPACE_KEYS_PATH)=/.test(n.lineText.slice(0,65536)))?r("runs anvil claude under another account's key, whose modes it would take"):e.via==="xargs"&&s[0]==="claude"&&s.length===1?r("anvil claude with its subcommand read from input"):[]}case"anvil-claude":{if(e.via==="xargs"&&s.length===0)return r("anvil-claude with its subcommand read from input");let i=lr(s,t.slice(1));return i?r(i):[]}case"node":case"bun":case"deno":case"tsx":case"ts-node":{let i=t.findIndex((p,d)=>d>0&&!p.startsWith("-")),l=i>0?$(t[i]):"",c=/@useanvil\/claude-code\/|(?:^|\/)anvil-claude$/i.test(l),u=i>0&&(c||/(?:^|\/)(?:@useanvil\/sdk|anvil)(?:\/|\.[cm]?[jt]s$|$)|useanvil/i.test(l))?c?lr(_([e.name,...t.slice(i+1)]),t.slice(i+1)):us(_([e.name,...t.slice(i+1)])):null;return u?r(u):[]}case"code":case"code-insiders":return I(t,"--add-mcp")?r(`${e.name} --add-mcp gives an AI agent a new MCP server`):[];case"codex":return s[0]==="mcp"&&s[1]==="add"?r("codex mcp add gives Codex a new MCP server"):I(t,"--dangerously-bypass-approvals-and-sandbox","--yolo")||P(t,"-s","--sandbox")==="danger-full-access"||t.some((i,l)=>(t[l-1]==="-c"||t[l-1]==="--config")&&/^sandbox_mode\s*=\s*["']?danger-full-access/.test(i))?r("runs Codex with its sandbox and approvals off"):[];case"gemini":return s[0]==="mcp"&&s[1]==="add"?r("gemini mcp add gives Gemini CLI a new MCP server"):I(t,"--yolo","-y")||P(t,"--approval-mode")==="yolo"?r("runs Gemini CLI approving every action"):[];case"cursor-agent":return I(t,"--force","-f")?r("runs Cursor Agent without asking before commands"):[];case"aider":return I(t,"--yes-always")?r("runs aider confirming every action"):[];case"amp":return I(t,"--dangerously-allow-all")?r("runs Amp with every action allowed"):[];case"droid":return I(t,"--skip-permissions-unsafe")?r("runs Droid with its permission checks off"):[];case"q":return s[0]==="chat"&&I(t,"--trust-all-tools")?r("runs Amazon Q trusting every tool"):[];case"qwen":case"crush":return I(t,"--yolo","-y")?r(`runs ${e.name} approving every action`):[];case"fastmcp":return s[0]==="install"?r("fastmcp install adds an MCP server to an AI agent"):[];case"copilot":return I(t,"--yolo","--allow-all-tools")?r("runs Copilot CLI approving every tool"):[];case"smithery":return s[0]==="install"||s[0]==="mcp"&&s[1]==="add"?r("installs an MCP server into an AI agent"):[];case"install-mcp":return s.length>0?r("installs an MCP server into an AI agent"):[];case"mcp-get":return s[0]==="install"?r("installs an MCP server into an AI agent"):[];default:return[]}}var Nv=new Set(["deliver","pilot","supply","upload_to_app_store","upload_to_testflight","upload_to_play_store","appstore","testflight","app_store_connect","upload_to_play_store_internal_app_sharing"]),Lv=new Set(["init","download_metadata","download_screenshots","list","builds","export","help"]),Tv=/(^|_)(release|beta|deploy|production|prod|store|publish|submit|upload|ship|distribute|promote|appstore|testflight|playstore|alpha|internal|rollout)(_|$)/i,Dv=/(^|_)(build|test|tests|lint|screenshots?|certs|certificates|match|setup|bump|version|changelog|notes|metadata|precheck|dry_?run|check|verify|dsyms?|symbols|crashlytics|sentry|bugsnag)(_|$)/i;function Iv(e){if(e.some((s,r)=>/^(--)?(validate|verify)_only(:|=)?(true)?$/i.test(s)&&(/true$/i.test(s)||/^true$/i.test(e[r+1]??""))))return!1;let n=_(e);["ios","android","mac"].includes(n[0]??"")&&(n=n.slice(1)),n[0]==="run"&&(n=n.slice(1));let t=n[0]??"";return t==="match"&&n[1]==="nuke"||t==="match_nuke"?!0:Nv.has(t)?!Lv.has(n[1]??""):/(^|_)(dsyms?|symbols|crashlytics|sentry|bugsnag|metadata|screenshots?)(_|$)/i.test(t)?!1:/(^|_)(upload|deploy|submit|distribute|publish|ship|promote|testflight|appstore|playstore|rollout)(_|$)/i.test(t)||/(^|_)and_(release|beta|production|prod|store)(_|$)/i.test(t)?!0:Tv.test(t)&&!Dv.test(t)}function ui(e){return e.slice(1).some(n=>/^prod(uction)?$/i.test($(n))||/^--(deployment-?name|deploymentName|destDeploymentName|target-deployment)=prod/i.test(n))}function gf(e){return I(e,"-m","--dry-run")?[]:e.slice(1).filter(n=>!n.startsWith("-")&&!n.includes("=")).map(n=>n.slice(n.lastIndexOf(":")+1))}function mu(e){return gf(e).some(n=>/^publish\w*(Bundles?|Apks?|Listing)$|^promote\w*Artifact$/.test(n))}function yu(e){return gf(e).some(n=>/^publish(AllPublicationsTo\w+Repository|\w+PublicationTo\w+Repository|ToSonatype|ToMavenCentral|AndReleaseToMavenCentral)?$/.test(n))}var mf=/^(preview|previews|staging|stage|dev|develop|development|test|testing|qa|internal|canary|pr-[\w.-]+|feat(ure)?[/-][\w./-]+)$/i;function Fv(e){let n=_(e),[t="",s=""]=(n[0]??"").split(":");if(t==="submit"||t==="build"&&s==="submit")return!0;if(t==="build"&&!s)return I(e,"--auto-submit","--auto-submit-with-profile");if(t==="update"&&!s){let r=P(e,"--branch","--channel");return!(r!==null&&!S(r)&&mf.test(r))}return t==="update"?["republish","rollback","roll-back-to-embedded","edit","revert-update-rollout"].includes(s):t==="channel"?["edit","rollout"].includes(s||(n[1]??"")):t==="deploy"?I(e,"--prod","--production"):!1}function Ai(e,n){let t=e.trim();if(/^[A-Za-z_$][\w$.]*$/.test(t)){let s=new RegExp(`(?:^|[^\\w$.])${t.replace(/[.$]/g,r=>`\\${r}`)}\\s*(?::\\s*[\\w.]+\\s*)?=(?!=)\\s*([^\\n;]+)`).exec(n);s&&(t=s[1])}return t=t.replace(/\b(require|__import__|import)\s*\(\s*(['"`])[^'"`]*\2\s*\)/g,"$1()"),[...t.matchAll(/(['"`])((?:\\.|(?!\1)[^\\])*)\1/g)].map(s=>s[2]).join("/").replace(/\/{2,}/g,"/")}function Ei(e,n,t){let s=e.indexOf("(",n);if(s<0)return[];let r=e.slice(s,s+4e3),o=to(r,0);return o<0&&s+4e3<e.length&&(t.hit=!0),o>0?Un(r.slice(1,o)):[]}function bu(e,n){let t=n,s=Math.max(0,n-400);for(;;){for(;t>s&&/\s/.test(e[t-1]);)t--;if(e[t-1]===")"){let a=0,i=null,l=t-1;for(;l>=s;l--){let c=e[l];if(i){c===i&&e[l-1]!=="\\"&&(i=null);continue}if(c==='"'||c==="'"||c==="`")i=c;else if(c===")")a++;else if(c==="("&&--a===0)break}if(l<s)return null;t=l}let o=t;for(;o>s&&/[\w$]/.test(e[o-1]);)o--;if(o===t&&e[t]!=="(")return null;if(t=o,e[t-1]==="."&&t-1>s){t--;continue}break}let r=e.slice(t,n).trim();return r===""?null:r}var Mv=/^\s*[rRbB]?['"][rwxabt+U]{1,4}['"]\s*$/,wu=/['"][^'"]*[wax+]|\bO_(?:WRONLY|RDWR|CREAT|TRUNC|APPEND)\b/,zv=/\b(exec|eval|compile|execfile|run_path|run_module|system|popen|spawn|spawnSync|execSync|execFileSync|Function|vm\.run\w*|subprocess\.\w+|os\.exec\w*)\s*\(/;function ra(e){return!/'''|"""|`[^`]*\n/.test(e)||zv.test(e)?e:e.replace(/('''|""")([\s\S]*?)\1|`((?:\\.|[^`\\])*\n(?:\\.|[^`\\])*)`/g,n=>{let t=n.startsWith("'''")||n.startsWith('"""')?3:1;return n.slice(0,t)+n.slice(t,n.length-t).replace(/[^\n]/g," ")+n.slice(n.length-t)})}function yf(e,n,t){let s=[],r=ra(e),o=(i,l=!0)=>{let c=Ai(i,e);c!==""?s.push({path:c,content:l,expr:i}):t&&(t.n++,t.exprs?.push(i))},a=i=>Ei(e,i,n);for(let i of ft([...r.matchAll(/\b(?:f?open|openSync|File\.new)\s*\(/g)],n)){let l=a(i.index),c=(l.find(u=>/^\s*mode\s*=/.test(u))??"").replace(/^\s*mode\s*=/,"");if(e[i.index-1]==="."&&(Mv.test(l[0]??"")||/^\s*mode\s*=/.test(l[0]??""))){let u=wu.test(c||l[0])?bu(e,i.index-1):null;u&&o(u);continue}wu.test(l[1]??c)&&o(l[0]??"")}for(let i of ft([...r.matchAll(/\.(write_text|write_bytes|unlink|chmod|rename|replace|touch)\s*\(/g)],n)){let l=bu(e,i.index);l&&o(l,i[1]==="write_text"||i[1]==="write_bytes"),i[1]==="rename"?o(a(i.index)[0]??""):i[1]==="replace"&&l&&Uv(l,e)&&o(Ei(e,i.index,{hit:!1})[0]??"")}for(let i of ft([...r.matchAll(/\b(writeFileSync|writeFile|appendFileSync|appendFile|createWriteStream|truncateSync|truncate|outputFileSync|outputFile|outputJsonSync|outputJson|writeJsonSync|writeJson|file_put_contents|Deno\.writeTextFileSync|Deno\.writeTextFile|Deno\.writeFileSync|Deno\.writeFile|Bun\.write|(?:File|IO)\.(?:write|binwrite))\s*\(/g)],n))o(a(i.index)[0]??"");for(let i of ft([...r.matchAll(/\b(rmSync|unlinkSync|unlink|chmodSync|chmod|Deno\.remove|os\.remove|os\.unlink|os\.chmod|shutil\.rmtree|rmtree|rimraf(?:\.sync)?|fse?\.removeSync|fse?\.remove|(?:File|IO)\.(?:delete|unlink)|FileUtils\.(?:rm|rm_f|rm_rf|remove_dir|touch))\s*\(/g)],n))o(a(i.index)[0]??"",!1);for(let i of ft([...r.matchAll(/\bfileinput\.(?:input|FileInput)\s*\(/g)],n)){let l=a(i.index);if(!l.some(p=>/^\s*inplace\s*=\s*(?:True|1)\s*$/.test(p)))continue;let c=(l.find(p=>/^\s*files\s*=/.test(p))??l.find(p=>!/^\s*\w+\s*=/.test(p))??"").replace(/^\s*files\s*=\s*/,"").trim(),u=/^[[(]([\s\S]*)[\])]$/.exec(c);for(let p of u?Un(u[1]):[c])o(p.trim())}for(let i of ft([...r.matchAll(/\bopen\s*\(?\s*(?:my\s+)?(?:\$\w+|[A-Z]\w*)\s*,\s*['"](?:\+?>{1,2}|\+<)['"]\s*,\s*([^;)]+)/g)],n))o(i[1].trim());for(let i of ft([...r.matchAll(/\bopen\s*\(?\s*(?:my\s+)?(?:\$\w+|[A-Z]\w*)\s*,\s*(['"])\s*(?:\+?>{1,2}|\+<)\s*([^'"]+)\1/g)],n))o(`"${i[2].trim()}"`);for(let i of ft([...r.matchAll(/\b(copyFileSync|copyFile|renameSync|rename|cpSync|(?<=\.)cp|(?:fse?|fsExtra)\.(?:copySync|copy|moveSync|move)|shutil\.copy\w*|shutil\.move|os\.replace|os\.rename|FileUtils\.(?:cp|mv|ln_s|ln_sf|cp_r)|File\.rename)\s*\(/g)],n)){let l=a(i.index);o(l[1]??""),/rename|move|replace/.test(i[1])&&o(l[0]??"",!1)}return s}function Uv(e,n){if(/\b(?:pathlib\.)?Path\s*\(|\.with_(?:name|suffix|stem)\s*\(/.test(e))return!0;let t=/^[A-Za-z_]\w*$/.exec(e.trim())?.[0];return t!==void 0&&new RegExp(`(?:^|[^\\w.])${t}\\s*=\\s*(?:pathlib\\.)?Path\\s*\\(`).test(n)}var qv=/(?:\b(?:os\.symlink|os\.link|fs\.symlinkSync|fs\.symlink|fs\.linkSync|fs\.link|symlinkSync|linkSync|File\.symlink|File\.link|FileUtils\.ln_sf|FileUtils\.ln_s|FileUtils\.ln|Deno\.symlinkSync|Deno\.symlink|symlink)|\.(?:symlink_to|hardlink_to))\s*\(/g,ku=/\.claude(\/settings(\.local)?\.json|\/hooks(\/.*)?)?\/?$|\.claude\.json$|\.mcp\.json$|\.anvil\/(claude(\/.*)?|rules\.json)$|Library\/Launch(Agents|Daemons)\/|\.gitconfig$|\.claude\/projects(\/[^/]+(\/.+\.jsonl)?)?\/?$/,Hv=/(?:^|[;\n])[ \t]*(?:from\s+google\.cloud\s+import\s+bigquery\b|import\s+google\.cloud\.bigquery\b|import\s+snowflake\b|from\s+snowflake\b|import\s+redshift_connector\b|from\s+databricks\b[\w.]*\s+import\b|(?:const|let|var|import)\b[^\n;]{0,80}(?:require\(\s*|from\s+)['"](?:@google-cloud\/bigquery|snowflake-sdk|@databricks\/sql)['"])/;function Bv(e,n){let t=Ls(e);if(t===null)return[];let s=[],r={n:0,exprs:[]},o=yf(t,n.cut,r),a=f$(e,t,r.exprs,n);a!==null&&s.push(w("claude.agent.controls",`${e.name} writes the file the line hands it: Claude Code's record of a session (${S(a)?"a file a listing of its projects folder names":O.basename($(a))})`,{target:$(a).slice(0,200),is_local:!0}));for(let i of o){if(!i.content||!Re(i.path))continue;let l=ln(i.expr,t,e,0,n.ctx.home,n.cut);if(!(l===null||l.startsWith("/dev/")||!Re(l))&&rt(l,e,n).kind!=="disposable"){s.push(w("claude.file.write_secret",`writes a secrets file (${O.basename($(l))}) (from ${e.name})`,{target:$(l),is_local:!0}));break}}for(let{path:i}of o){let l=$(i);if(S(i)&&Qr(i,n.ctx,e.cwd)){s.push(w("claude.agent.controls",`writes Claude Code's record of a session (a file a listing of its projects folder names) (from ${e.name})`,{target:l.slice(0,200),is_local:!0}));continue}if(!ku.test(l)){let b=l.startsWith("/")?l:M(l,e.cwd,n.ctx);if(Nn(n,S(i)?M(i,e.cwd,n.ctx):b),$t.test(b)&&Mn(t)){s.push(w("claude.agent.controls",`changes how every later Claude Code session starts (${O.basename(b)}) (from ${e.name})`,{target:$(b),is_local:!0}));continue}let k=S(b)?null:Es(b,n.ctx,[n.projectRoot,n.base]);if(k){s.push({...k,why:`${k.why} (from ${e.name})`});continue}let E=De(b,e,n),y=E!==b?E:os(b,n.ctx.onDisk,!0);if(y===null||!ku.test(y))continue;let m=Es(y,n.ctx,[n.projectRoot,n.base]);if(m){s.push({...m,why:`${m.why} (from ${e.name})`});continue}continue}let c=l.replace(/^(\$ENV\{['"]?HOME['"]?\}|ENV\[['"]HOME['"]\]|\$?\{[^}]*\}|HOME|~|USERPROFILE|homedir\(\))\/?/,""),u=/\b(HOME|homedir|expanduser|USERPROFILE)\b|Path\.home\b/.test(t),p=/^\/(\.claude|\.mcp\.json|\.gitconfig|\.anvil\/|Library\/)/.test(l),d=l!==c||/^(\.claude\.json|\.gitconfig|Library\/)/.test(c)||(p||/^\.(claude|anvil)\//.test(c))&&u,f=d?hf(e,n,["HOME"])??n.ctx.home:n.ctx.home,h=l.startsWith("/")&&!(p&&u)?l:d?`${f}/${c.replace(/^\/+/,"")}`:M(c,e.cwd,n.ctx);Nn(n,h);let g=Es(De(h,e,n),n.ctx,[n.projectRoot,n.base]);if(g){s.push({...g,why:`${g.why} (from ${e.name})`});continue}}for(let i of ft([...t.matchAll(qv)],n.cut)){let l=Ei(t,i.index,n.cut)[0];if(l===void 0)continue;let c=ln(l,t,e,0,n.ctx.home,n.cut)??Ai(l,t);if(!c||S(c)||c.startsWith(zn))continue;let u=M(c,e.cwd,n.ctx);if(!ff(u,n))continue;let p=n.ctx.home.replace(/(?<!\/)\/+$/,""),d=u===p?"~":u.startsWith(`${p}/`)?`~${u.slice(p.length)}`:u;s.push(w("claude.agent.controls",`links to a folder that holds Anvil's or Claude Code's settings (${d}) (from ${e.name})`,{target:u,is_local:!0}));break}if(/\bread_sql(_query|_table)?\s*\(/.test(t)&&/\.to_(csv|parquet|json|excel|feather|pickle|orc|hdf)\s*\(/.test(t)&&!/localhost|127\.0\.0\.1|sqlite/i.test(t)&&s.push(w("claude.bash.data.export",`copies query rows from a database into a file (from ${e.name})`,{target:e.name,host:null,is_local:!1})),/\.to_gbq\s*\([^)]{0,500}if_exists\s*=\s*['"]replace/.test(t)&&s.push(w("claude.bash.db.destructive",`replaces a BigQuery table (from ${e.name})`,{target:e.name,host:"bigquery",is_local:!1})),(/\bfrom\s+pyngrok\s+import\b|\bimport\s+pyngrok\b/.test(t)&&/\bngrok\.connect\s*\(/.test(t)||/require\(\s*['"](localtunnel|ngrok|@ngrok\/ngrok)['"]\s*\)|\bngrok\.(forward|connect)\s*\(/.test(t))&&s.push(w("claude.bash.net.expose",`opens a local port to the internet (from ${e.name})`,{target:e.name,host:null,is_local:!1})),Hv.test(t)){let i=(()=>{if(/\.(delete_table|delete_dataset|delete_model|delete_routine)\s*\(|\.(table|dataset)\([^)]*\)\.delete\s*\(/.test(t))return"deletes warehouse data";for(let l of ft([...t.matchAll(/\.(query|execute|execute_string|executemany|sql|run_query)\s*\(/g)],n.cut)){let c=t.indexOf("(",l.index),u=t.slice(c,c+4e3),p=to(u,0);p<0&&c+4e3<t.length&&(n.cut.hit=!0);let d=p>0?Un(u.slice(1,p))[0]??"":"",f=/^\s*[A-Za-z_$][\w$]*\s*$/.test(d)&&Ai(d,t)||d,h=Ee.exec(f)??Ss.exec(f);if(h)return`runs destructive SQL (${h[1].replace(/\s+/g," ").toUpperCase()})`}return null})();i&&s.push(w("claude.bash.db.destructive",`${i} through a warehouse client (from ${e.name})`,{target:e.name,host:/bigquery/i.test(t)?"bigquery":/snowflake/i.test(t)?"snowflake":/databricks/i.test(t)?"databricks":"redshift",is_local:!1}))}return s}function Vv(e,n){let t=e.argv,s=[],r=null;if(e.name==="tmux"&&["new","new-session","new-window","neww","split-window","splitw","respawn-pane"].includes(t[1]??"")){let a=vu(t,2,Gv);if(a.length>1&&(a.some(S)||/\s/.test(a[0])))return st("tmux");s=[a.length>1?_r(a):a.join(" ")],r="tmux"}else if(e.name==="tmux"&&["send-keys","send"].includes(t[1]??""))s=[ke(t,2,new Set(["-t","-N"])).filter(a=>!/^(Enter|C-m|KPEnter)$/.test(a)).join(" ")];else if(e.name==="screen"){let a=1;for(;a<t.length&&t[a].startsWith("-");)a+=/^-[A-Za-z]*[ScpTXh]$/.test(t[a])||t[a]==="-Logfile"?2:1;let i=t.slice(1,a).some(l=>/^-[A-Za-z]*X$/.test(l));if(!i&&t.slice(a).some(S))return st("screen");s=[i?t.slice(a).join(" "):_r(t.slice(a))],r="screen"}else if(e.name==="concurrently")s=ke(t,1,new Set(["-n","--names","-c","--prefix-colors","-p","--prefix","-s","--success","--restart-tries"]));else if(e.name==="kitty"&&t[1]==="@"&&t[2]==="launch"||e.name==="wezterm"&&t[1]==="cli"&&t[2]==="spawn"||e.name==="zellij"&&(t[1]==="run"||t[1]==="r")||e.name==="systemd-run"){let a=e.name==="systemd-run"?1:e.name==="zellij"?2:3,i=vu(t,a,Zv[e.name]??new Set);if(i.length===0)return[];if(i.some(S)||/\s/.test(i[0]))return st(e.name);s=[_r(i)],r=e.name}else if(e.name==="launchctl"){let a=t.slice(1).find(i=>!i.startsWith("-"))??"";if(a==="submit"){let i=t.indexOf("--");if(i<0||t.slice(i+1).some(S))return st("launchctl submit");s=[_r(t.slice(i+1))],r="launchctl submit"}else if(a==="load"||a==="bootstrap")return st(`launchctl ${a}`)}else if(e.name==="crontab"||e.name==="at"||e.name==="batch"){let a=t.slice(1).filter(c=>/^-[A-Za-z]+$/.test(c));if(e.name==="crontab"&&a.some(c=>/[lTVre]/.test(c)))return[];if(e.name!=="crontab"&&a.some(c=>/[lrdcq]/.test(c)))return[];let i=e.name==="crontab"?t.slice(1).filter(c=>!c.startsWith("-")||c==="-").filter(c=>c!=="-"):[],l=i.length===1?e$(i[0],e,n):i.length===0&&!t.includes("-f")?$u(e)??(e.name==="crontab"?t$(e,n):null):null;if(l===null)return st(e.name);s=e.name==="crontab"?n$(l):l.split(`
|
|
81
|
+
`),r=e.name}else if(e.name==="osascript"){let a=t.includes("-e")?t.filter((u,p)=>t[p-1]==="-e").join(`
|
|
82
|
+
`):t.length===1||t.length===2&&t[1]==="-"?$u(e):null;if(a===null)return st("osascript");let i=P(t,"-l");if(i!==null&&!/^applescript$/i.test(i)&&/terminal|iterm|doShellScript|doScript|\bwrite\s*\(|System\s*Events|keystroke/i.test(a))return st("osascript");let l=[...a.matchAll(/\b(?:do\s+(?:shell\s+)?script|write\s+text)\b/gi)].length,c=[...a.matchAll(/\b(?:do\s+(?:shell\s+)?script|write\s+text)\s+"((?:\\.|[^"\\])*)"(?!\s*&)/gi)].map(u=>u[1].replace(/\\(.)/g,"$1"));if(l>c.length)return st("osascript");s=c,r="osascript"}else if(e.name==="open"){let a=P(t,"-a")??P(t,"-b")??"",i=ke(t,1,new Set(["-a","-b","--env","--stdin","--stdout","--stderr","-u"]));if(i.some(l=>/\.(command|tool|terminal|sh|bash|zsh|workflow|scpt|applescript)$/i.test(l))||/terminal|iterm|warp|ghostty|kitty|alacritty|wezterm|hyper/i.test(a)&&i.some(l=>/\.[A-Za-z0-9]+$/.test(O.basename(l))))return st("open")}let o=[];for(let a of s.filter(i=>i.trim()!=="")){if(r!==null&&!Kv(a,e,n,!0)){o.push(...st(r));continue}let i=Ou({tool:"Bash",command:a,target:null,cwd:e.cwd,git_branch:n.branch,project_dir:n.projectRoot},n);o.push(...zu(i,r!==null&&r!=="tmux"&&r!=="screen"?`(run by ${r}, outside this session)`:`(in ${e.name})`))}return o}function vu(e,n,t){for(let s=n;s<e.length;s++){let r=e[s];if(r==="--")return e.slice(s+1);if(r.startsWith("-")&&r!=="-"){!r.includes("=")&&t.has(r)&&s++;continue}return e.slice(s)}return[]}var Gv=new Set(["-s","-n","-t","-c","-x","-y","-F","-e","-l","-f","-p"]),Zv=ae({"systemd-run":new Set(["-u","--unit","-p","--property","--description","--slice","--uid","--gid","--nice","--working-directory","-E","--setenv","-M","--machine","-H","--host","--on-active","--on-boot","--on-startup","--on-unit-active","--on-unit-inactive","--on-calendar","--timer-property","--path-property","--socket-property","--service-type","-C","--capsule"]),kitty:new Set(["--type","--title","--tab-title","--cwd","--env","--var","--location","--next-to","--os-window-title","--os-window-name","--os-window-class","--os-window-state","--logo","--logo-position","--logo-alpha","--color","--spacing","--marker","--watcher","-w","--source-window","--stdin-source","--match","-m","--bias","--add-to-session","--window-type","--remote-control-password"]),wezterm:new Set(["--pane-id","--domain-name","--window-id","--workspace","--cwd"]),zellij:new Set(["--name","-n","--cwd","--direction","-d","--width","--height","-x","-y"])});function _r(e){return e.map(Oi).join(" ")}function st(e){return[w("claude.agent.controls",`hands a command to ${e}, which runs it outside this session, and Anvil cannot read that command here`,{target:e,is_local:!0})]}function Kv(e,n,t,s=!1){return bf(e,n.cwd,t.ctx,t.projectRoot,t.cut,s)}var Yv=new Set(["install","i","ci","add","remove","rm","uninstall","un","ls","list","view","info","outdated","audit","why","config","help","login","whoami","init","link","pack","prune","dedupe","cache","version"]),Jv=new Set(["make","gmake","just","task","rake","invoke","mise","turbo","nx","gulp","grunt","npx","bunx","pnpx","dlx"]),Xv=new Set(["sh","bash","zsh","dash","ksh","fish","node","nodejs","python","python3","ruby","perl","php","deno","tsx","ts-node","bun"]);function Qv(e){let n=O.basename(e.name),t=e.argv.slice(1).filter(s=>!s.startsWith("-"));return["npm","pnpm","yarn","bun"].includes(n)?t.length>0&&!Yv.has(t[0]):Jv.has(n)?!0:Xv.has(n)?!e.argv.slice(1).some(s=>/^(-c|-e|-p|--eval|--print|-m)$/.test(s))&&t.length>0:(e.argv[0]??"").includes("/")&&!/^\/(usr\/)?(s?bin)\/|^\/opt\/homebrew\/bin\/|^\/usr\/local\/bin\//.test(e.argv[0])}function bf(e,n,t,s,r,o=!1){let a=At(e,{home:t.home,tmpdir:t.tmpdir,cwd:n,projectDir:s,claudeConfigDir:t.claudeConfigDir??null,...ji(t)});return a.status==="limited"&&(r.hit=!0),a.commands.length>0&&a.commands.every(i=>!S(i.name)&&!S(i.argv[0]??"")&&i.unreadableCode===null&&!["eval","source",".","exec"].includes(i.name)&&!(o&&Qv(i)))}function $u(e){if(e.stdin!==null)return e.stdinExpands&&/\$|`/.test(e.stdin)?null:e.stdin;let n=e.pipeFrom;if(!n||n.pipeFrom!==null||n.name!=="echo"&&n.name!=="printf")return null;let t=n.argv.slice(1).filter(s=>!/^-[neE]+$/.test(s));return t.length===0||t.some(s=>S(s))?null:n.name==="printf"?t.length===1&&!/%/.test(t[0])?t[0].replace(/\\n/g,`
|
|
83
|
+
`).replace(/\\t/g," "):null:t.join(" ").replace(/\\n/g,`
|
|
84
|
+
`)}function e$(e,n,t){if(S(e))return null;let s=M(e,n.cwd,{home:t.ctx.home}),r=t.ctx.session?.scripts?.[s];return r!==void 0?r:(t.ctx.wantScripts?.add(s),null)}function t$(e,n){if(e.pipeFrom!==null||e.stdin!==null)return null;let t=cn(n.lineText,n.base,n).commands.filter(r=>!(r.name==="crontab"&&r.text===e.text)),s=[];for(let r of t)if(!(r.name==="crontab"&&r.argv.slice(1).every(o=>/^-[A-Za-z]*l[A-Za-z]*$/.test(o)||/^2?>/.test(o)))&&!(["cat","grep","sort","uniq","true","cd"].includes(r.name)&&r.argv.slice(1).every(o=>!S(o)))){if((r.name==="echo"||r.name==="printf")&&r.argv.length>1&&r.argv.slice(1).every(o=>!S(o))){let o=r.argv.slice(1).filter(a=>!/^-[neE]+$/.test(a));if(r.name==="printf"&&(o.length!==1||/%/.test(o[0])))return null;s.push(o.join(" ").replace(/\\n/g,`
|
|
76
85
|
`));continue}return null}return s.length>0?s.join(`
|
|
77
|
-
`):null}function
|
|
78
|
-
`).map(
|
|
79
|
-
`,s),i=a===-1?e.length:a;
|
|
80
|
-
`)break;i++}n.fill(1,s+a.length,Math.max(s+a.length,Math.min(i,e.length)-a.length)),s=Math.max(i,s+1);continue}s++}return r=>n[r]!==1}var Jo=oe({python:["-c"],python3:["-c"],node:["-e","--eval","-p","--print"],tsx:["-e","--eval","-p","--print"],"ts-node":["-e","--eval","-p","--print"],perl:["-e","-E"],ruby:["-e"],deno:["eval"],bun:["-e","--eval"],php:["-r"]}),Xo=/^(os\.homedir\(\)|require\(['"](node:)?os['"]\)\.homedir\(\)|process\.env\.HOME\b|process\.env\[['"]HOME['"]\]|Path\.home\(\)|os\.path\.expanduser\(\s*['"]~['"]\s*\)|os\.environ\[['"]HOME['"]\]|os\.environ\.get\(\s*['"]HOME['"]\s*\)|os\.getenv\(\s*['"]HOME['"]\s*\)|Deno\.env\.get\(['"]HOME['"]\)|Dir\.home|ENV\[['"]HOME['"]\]|\$ENV\{['"]?HOME['"]?\}|glob\(\s*['"]~['"]\s*\))/;function Gb(e,t,n){let s=[],r=a=>{let i=a.trim(),l=/^(['"`])((?:\\.|(?!\1)[^\\])*)\1$/.exec(i);if(l)return Co(l[2].replace(/\\(.)/g,"$1"));if(Xo.test(i))return"~";let c=/^(?:process\.env\.(\w+)|process\.env\[['"](\w+)['"]\]|os\.environ\[['"](\w+)['"]\]|os\.environ\.get\(\s*['"](\w+)['"]|os\.getenv\(\s*['"](\w+)['"]|ENV\[['"](\w+)['"]\]|Deno\.env\.get\(['"](\w+)['"]\))/.exec(i);if(c)return`"$${c.slice(1).find(Boolean)}"`;let u=/^[A-Za-z_$][\w$.]*$/.test(i)||/^(?:pathlib\.)?Path\(|^os\.path\.join\(|^path\.join\(/.test(i)?n(i):null;return u!==null?Co(u):'"$(unknown)"'},o=a=>{let i=[],l=null;for(let f=a.length-1;f>=0;f--){let p=a[f];p===")"||p==="]"||p==="}"?l="close":p==="("||p==="["||p==="{"?l="open":p===","&&l!=="close"&&i.push(f)}let c=[],u=a.length;for(let f of i)c.unshift(a.slice(f+1,u)),u=f;return c.unshift(a.slice(0,u)),c.map(f=>f.trim()).filter(Boolean)};for(let a of e.matchAll(/\b(?:subprocess\.(?:run|call|check_call|check_output|Popen)|Bun\.spawn(?:Sync)?|os\.spawnvp?e?)\s*\(\s*(?:os\.P_\w+\s*,\s*)?(?:\{\s*cmd\s*:\s*)?\[([^\]]*)\]/g)){let i=o(a[1]);t(a.index??0)&&/^(['"`])/.test(i[0]??"")&&s.push(i.map(r).join(" "))}for(let a of e.matchAll(/\b(?:spawn|spawnSync|execFile|execFileSync|execa|execaSync|execaNode)\s*\(\s*((['"`])(?:\\.|(?!\2)[^\\])*\2)\s*,\s*\[([^\]]*)\]/g))t(a.index??0)&&s.push([r(a[1]),...o(a[3]).map(r)].join(" "));for(let a of e.matchAll(/\bDeno\.Command\s*\(\s*((['"`])(?:\\.|(?!\2)[^\\])*\2)\s*,\s*\{\s*args\s*:\s*\[([^\]]*)\]/g))t(a.index??0)&&s.push([r(a[1]),...o(a[3]).map(r)].join(" "));return s}function Co(e){return/^[\w./=:@%+,~-]+$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}function Kb(e,t,n,s){let r=Jo[e.name],o=r?e.argv.findIndex((f,p)=>p>0&&r.includes(f)):-1;if(o<0||n.length===0)return null;let a=e.argv.slice(o+2),i=f=>ar(f,s.ctx,e.cwd)||!S(f)&&St(k(M(f,e.cwd,s.ctx)),s.ctx,!1),l=f=>{let p=f.trim(),d=/^[A-Za-z_$][\w$]*$/.test(p)?new RegExp(`(?:^|[^\\w$.])${p.replace(/\$/g,"\\$")}\\s*=(?!=)\\s*([^\\n;]+)`).exec(t)?.[1]??p:p,h=/\b(?:process|sys)\.argv\[(\d+)\]/.exec(d);if(h)return Number(h[1])-1;let g=/(?:\$|\b)ARGV\[(\d+)\]/.exec(d);return g?Number(g[1]):null},c=n.map(l);return(c.every(f=>f!==null)?c.map(f=>a[f]).filter(f=>f!==void 0):a).find(i)??null}function Xn(e){let t=Jo[e.name];if(!t)return null;let n=null;for(let r=1;r<e.argv.length;r++){let o=e.argv[r];if(t.includes(o)||/^-[A-Za-z]{2,}$/.test(o)&&t.some(a=>/^-[A-Za-z]$/.test(a)&&o.endsWith(a.slice(1)))){n=e.argv[r+1]??null;break}}let s=e.argv.length===1||e.argv.slice(1).every(r=>r==="-"||r.startsWith("-"));return n===null&&e.scriptText!==null&&(n=e.scriptText),n===null&&e.stdin!==null&&s&&(n=e.stdin),n===null&&s&&e.pipeFrom&&(e.pipeFrom.name==="echo"||e.pipeFrom.name==="printf")&&(n=e.pipeFrom.argv.slice(1).join(" ")),n}function Yb(e,t){let n=Xn(e);if(n===null)return[];let s=Zb(n,e.name.startsWith("python")?"python":["node","deno","bun"].includes(e.name)?"js":"other"),r=[],o=[],a=/\b(?:os\.system|os\.popen|subprocess\.(?:run|call|check_call|check_output|Popen)|execSync|execFileSync|spawnSync|exec|system|`)\s*\(\s*(?:\[\s*)?(['"`])((?:\\.|(?!\1)[^\\])*)\1/g;for(let u of n.matchAll(a))s(u.index??0)&&o.push(u[2].replace(/\\(.)/g,"$1"));o.push(...Gb(n,s,u=>{let f=Ht(u,n,e,0,t.ctx.home,t.cut);return f===null?null:f.startsWith(hn)?R.join(t.ctx.tmpdir,"code-temp"):S(f)?null:f}));for(let u of n.matchAll(/(?:\bBun\.\$|(?<![\w$.])\$)(?:\.\w+\([^)]*\))*\s*`((?:\\.|[^`\\])*)`/g))s(u.index??0)&&o.push(u[1].replace(/\$\{[^}]*\}/g,'"$(unknown)"'));let i=/\b(execSync|execFileSync|spawnSync|check_output|getoutput|getstatusoutput|popen)\b|capture_output\s*=\s*True|stdout\s*=\s*subprocess\.PIPE|stdio\s*:\s*['"]pipe/.test(n);for(let u of o){let f=Xl({tool:"Bash",command:u,target:null,cwd:e.cwd,git_branch:t.branch},t),p=lc(f,`(run from ${e.name})`).filter(d=>!(d.action==="claude.bash.secrets.print"&&i)&&!(d.action==="claude.bash.privilege"&&/cannot read/.test(f.why)));r.push(...p)}let l=/(?:\b(?:shutil\.rmtree|rmtree|remove_tree|rimraf(?:\.sync)?|fse?\.removeSync|fse?\.remove|Deno\.remove|FileUtils\.rm_rf|FileUtils\.remove_dir)|(?:\bfs|\bpromises|\))\.(?:rmSync|rm|rmdirSync))\s*\(\s*(?:(['"`])((?:\\.|(?!\1)[^\\])*)\1|([A-Za-z_$][\w.{}$]*))/g;for(let u of n.matchAll(l)){if(!s(u.index??0))continue;let f=u[2],p=u[0];if(!(/rmtree|remove_tree|rimraf|remove|rm_rf|remove_dir/.test(p)||/recursive\s*:\s*true/.test(n.slice(u.index??0,(u.index??0)+200))))continue;let h=n.slice((u.index??0)+u[0].length-(u[3]?.length??0),(u.index??0)+u[0].length+40),g=Xo.test(h),y=(u.index??0)+u[0].indexOf("("),$=lr(n,y),E=$>y?gn(n.slice(y+1,$))[0]??u[3]??"?":u[3]??"?",x=f!==void 0&&E.trim().length===f.length+2?X(Ie(f,e,t),e.cwd,se(t)):g&&E.trim()===(u[3]??"").trim()?X(t.ctx.home,null,se(t)):Jb(n,E,e,t);r.push({...xt([x],e),why:`${xt([x],e).why} (from ${e.name})`})}let c=/\b(?:requests|httpx|axios)\.(post|put|patch|delete)\s*\(\s*(?:(['"`])([^'"`]*)\2|f(['"])([^'"]*)\4|([A-Za-z_$][\w.$]*(?:\[['"]\w+['"]\])?))|\bfetch\s*\(\s*(?:(['"`])([^'"`]*)\7|([A-Za-z_$][\w.$]*))\s*,\s*\{[^}]*method\s*:\s*['"`](POST|PUT|PATCH|DELETE)/gi;for(let u of n.matchAll(c)){if(!s(u.index??0))continue;let f=(u[1]??u[10]??"POST").toUpperCase(),p=u[3]??u[5]??u[8],d=u[6]??u[9],h=p??(d?Qb(n,d):null),g=h===null?null:h.replace(/:\$?\{[^}]*\}/,":1").replace(/\$?\{[^}]*\}/g,"x");g!==null&&/^https?:\/\//i.test(g)?Re(g)||r.push(m("claude.bash.external_write",`${f} to ${de(g)} (from ${e.name})`,{target:g,host:de(g),is_local:!1})):g===null&&d&&!/https?:\/\/(localhost|127\.0\.0\.1|\[::1\])\b/i.test(n)&&r.push(m("claude.bash.external_write",`${f} to a URL held in ${d} (from ${e.name})`,{target:d,host:null,is_local:null}))}return r}function Jb(e,t,n,s){let r={kind:"normal",path:t,token:null,why:`a path held in ${t}`},o=Ht(t,e,n,0,s.ctx.home,s.cut);if(o===null)return r;if(o.startsWith(hn))return{kind:"disposable",path:t,token:null,why:`a temp folder the code made (${t})`};let a=X(Ie(o,n,s),n.cwd,se(s));return a.kind==="normal"&&S(o)?r:a}var hn="temp",Xb=/^(tempfile\.(mkdtemp|TemporaryDirectory|gettempdir)\b|(?:await\s+)?(?:fs\.|fsp\.|promises\.)?mkdtemp(Sync)?\s*\(|os\.tmpdir\(\)|Dir\.mktmpdir|Deno\.makeTempDir|path\.join\(\s*os\.tmpdir\(\)|tmpdir\(\))/;function Ht(e,t,n,s,r,o){if(s>4)return null;let a=e.trim().replace(/\.(resolve|absolute|expanduser)\(\)/g,"").replace(/^await\s+/,"");if(Xb.test(a))return hn;let i=Xo.exec(a);if(i)return Fs(r,a.slice(i[0].length).trim()?`/${io(a.slice(i[0].length).replace(/^\s*[+/]\s*/,""))}`:"");let l=null,c="",u=p=>{let d=p.exec(a);return d&&(c=a.slice(d[0].length)),d},f;if(f=u(/^f?(['"`])((?:\\.|(?!\1)[^\\])*)\1/)){let p=/^\$?\{([A-Za-z_$][\w$.]*)\}(.*)$/s.exec(f[2]);l=p?Fs(Ht(p[1],t,n,s+1,r,o),p[2].replace(/\$?\{[^}]*\}/g,"x")):f[2].replace(/\$?\{[^}]*\}/g,"x")}else if(f=u(/^(?:sys\.argv|process\.argv)\[(\d+)\]/)){let p=n.argv.findIndex((h,g)=>g>0&&!h.startsWith("-")),d=Number(f[1]);l=n.argv[p+(a.startsWith("process")?d-1:d)]??null}else if(f=u(/^(?:Path\(\s*__file__\s*\)\.parent|os\.path\.dirname\(\s*(?:os\.path\.abspath\(\s*)?__file__\s*\)?\s*\)|__dirname|path\.dirname\(\s*fileURLToPath\(\s*import\.meta\.url\s*\)\s*\))/))l=n.scriptPath?R.dirname(n.scriptPath):null;else if(f=u(/^(?:pathlib\.)?(?:Path|PurePath|PosixPath|str|String|os\.path\.(?:join|abspath|realpath|normpath)|path\.(?:join|resolve|normalize)|join|resolve)\s*\(/)){let p=lr(a,f[0].length-1);if(p<0)return null;let d=gn(a.slice(f[0].length,p));c=a.slice(p+1),l=Ht(d[0]??"",t,n,s+1,r,o);for(let h of d.slice(1))l=Fs(l,`/${io(h)}`)}else if(f=u(/^(?:self\.|this\.)?([A-Za-z_$][\w$]*)/)){let p=new RegExp(`(?:^|[^\\w$.])${f[1].replace(/\$/g,"\\$")}\\s*(?::\\s*[\\w.\\[\\] ]+\\s*)?=(?!=)\\s*([^\\n;]+)`).exec(t);if(!p||gn(p[1]).length>1)return null;l=Ht(p[1],t,n,s+1,r,o)}if(l===null)return null;for(let p=0;c.trim();p++){if(p>=12){o&&(o.hit=!0);break}let d=c.trimStart(),h=/^(\/|\+)\s*(f?(['"`])(?:\\.|(?!\3)[^\\])*\3|[\w.$]+(?:\([^)]*\))?)/.exec(d);if(h){let g=io(h[2]);if(l=Fs(l,h[1]==="/"?`/${g}`:g),l===null)return null;c=d.slice(h[0].length);continue}if(d.startsWith(".parent")){if(l===null)return null;l=l.startsWith(hn)?l:R.dirname(l),c=d.slice(7);continue}break}return l}function Fs(e,t){return e===null?null:e.startsWith(hn)?e:t.startsWith("/")?`${e.replace(/\/$/,"")}${t}`:`${e}${t}`}function io(e){let t=/^f?(['"`])((?:\\.|(?!\1)[^\\])*)\1$/.exec(e.trim());return t?t[2].replace(/\$?\{[^}]*\}/g,"x"):"x"}function lr(e,t){let n=0,s=null;for(let r=t;r<e.length;r++){let o=e[r];if(s){o==="\\"?r++:o===s&&(s=null);continue}if(o==='"'||o==="'"||o==="`")s=o;else if(o==="(")n++;else if(o===")"&&--n===0)return r}return-1}function gn(e){let t=[],n=0,s=null,r=0;for(let o=0;o<e.length;o++){let a=e[o];if(s){a==="\\"?o++:a===s&&(s=null);continue}a==='"'||a==="'"||a==="`"?s=a:"([{".includes(a)?n++:")]}".includes(a)?n--:a===","&&n===0&&(t.push(e.slice(r,o).trim()),r=o+1)}return t.push(e.slice(r).trim()),t.filter(o=>o!=="")}function Qb(e,t){let n=t.replace(/^(self|this)\./,"");if(!/^[A-Za-z_$][\w$]*$/.test(n))return null;let s=new RegExp(`(?:^|[^\\w$.])${n.replace(/\$/g,"\\$")}\\s*(?::\\s*\\w+\\s*)?=\\s*f?(['"\`])([^'"\`]*)\\1`).exec(e);return s?s[2]:null}var Qo=new Set(["node","python","python3","ruby","deno","bun","tsx","ts-node","go","php","perl","sh","bash"]),Zl=new Set(["--apply","--write","--commit","--execute","--fix","--force","--yes","--confirm","--no-dry-run","--live","--migrate","--delete","--purge","--reset","--prune"]);function ew(e){if(!e.productionEnv||e.via==="substitution"||!Qo.has(e.name))return[];let t=e.argv.slice(2).find(s=>Zl.has(s)||Zl.has(s.split("=")[0]??""));if(!t)return[];let n=e.argv.slice(1).find(s=>!s.startsWith("-"))??e.name;return[m("claude.bash.db.destructive",`runs ${R.basename(k(n))} with production credentials and ${t}`,{target:k(n),is_local:!1,host:"production"})]}var _u=/^(deploy|release|publish|ship|rollout|promote)$/i,tw=/(^|[-_.])(deploy|release|publish|rollout|promote)([-_.]|$)/i,nw=/(^|[-_.])(tags?[-_.](and[-_.])?push|push[-_.]tags?)([-_.]|$)/i,sw=/(^|[-_.])(test|tests|spec|check|verify|lint|notes|changelog|build|docs|plan|diff|status|dry|preview|local|mock|fake|stub|prepare)([-_.]|$)/i,rw=/^(detect|find|get|next|determine|should|is|has|needs|parse|extract|wait|print|show|list|read|info)[-_.]/i,ao=e=>sw.test(e)||rw.test(e),lo=/\.(sh|bash|zsh|py|rb|js|mjs|cjs|ts|mts|cts|pl)$/,ow=/^(\.{1,2}\/)?[\w.-]+\/[\w./-]*[\w-]$/,co=e=>ow.test(e)&&!/\.[A-Za-z0-9]{1,5}$/.test(R.basename(e))&&!/(^|\/)node_modules\//.test(e)&&!["gradlew","mvnw","gradle","mvn"].includes(R.basename(e))&&!Zs(R.basename(e))&&!wc.has(R.basename(e))&&!yn.has(R.basename(e))&&!rr.has(R.basename(e)),iw=/(^|[-_.])(drop|purge|nuke|wipe|reset|truncate)[-_.]?(db|dbs|database|databases|data|tables?|schema)([-_.]|$)|(^|[-_.])(db|database)[-_.]?(drop|purge|nuke|wipe|reset|truncate)([-_.]|$)/i,aw=new Set(["py_compile","compileall","pyflakes","pylint","flake8","mypy","black","ruff"]);function Su(e,t){let n=R.basename(e);if(["sh","bash","zsh","dash","ksh"].includes(n))return t.some(r=>/^-[a-zA-Z]*n[a-zA-Z]*$/.test(r));if(n==="node"||n==="nodejs")return t.some(r=>r==="--check"||r==="-c");let s=/^python[\d.]*$/.test(n)?t.indexOf("-m"):-1;return s>=0&&aw.has(t[s+1]??"")}function lw(e,t){if(e.via==="substitution")return[];let n=e.argv.map(d=>k(d)),s=d=>lo.test(d)||co(d),r=n[0]?.includes("/")&&s(n[0])?0:(e.name==="source"||e.name===".")&&(lo.test(n[1]??"")||(n[1]??"").includes("/")&&co(n[1]))?1:Qo.has(e.name)?n.findIndex((d,h)=>h>0&&!d.startsWith("-")&&(lo.test(d)||d.includes("/")&&co(d))):-1;if(r<0||r>0&&Su(e.name,n.slice(1,r)))return[];let o=n[r],a=X(o,e.cwd,se(t)).path;if(a&&t.lineMade.includes(a)&&yc(o,t,bc(e,o)))return[];let i=R.basename(o).replace(/\.[^.]+$/,""),l=n.slice(r+1),c=l.filter(d=>!d.startsWith("-")),u=["run","exec","task"].includes(c[0]??"")?c[1]:c[0];if(iw.test(i)&&!ao(i)&&!l.some(d=>/^--?(dry-?run|plan|help)$/i.test(d)))return[m("claude.bash.db.destructive",`runs ${R.basename(o)}, a script that drops or resets data`,{target:o,is_local:null})];let f=(tw.test(i)||nw.test(i))&&!ao(i),p=u!==void 0&&_u.test(u)&&!ao(i);return!f&&!p||l.some(d=>/^--?(dry-?run|plan|check|preview|diff|help|version|what-?if)$/i.test(d))?[]:[m("claude.bash.deploy",`runs ${R.basename(o)}${p?` ${u}`:""}, a script that deploys or releases`,{target:o,is_local:!1})]}var Cu=/\.(db|sqlite|sqlite3|db3|log|csv|tsv|parquet|ndjson|jsonl|bak|dump)$/i;function Gl(e){let t=e.name==="printf"&&(e.argv[1]??"")===""&&e.argv.length<=2||e.name==="echo"&&e.argv.slice(1).every(n=>n===""||/^-[neE]+$/.test(n));return e.name===":"||e.name==="true"||t||e.name==="cat"&&e.argv[1]==="/dev/null"&&e.argv.length===2}function Kl(e,t){let n=[];e.name==="truncate"&&e.argv.some((o,a)=>(o==="-s"||o==="--size")&&/^0+$/.test(e.argv[a+1]??"")||/^--size=0+$/.test(o)||o==="-s0")&&n.push(...e.argv.slice(1).filter((o,a,i)=>!o.startsWith("-")&&i[a-1]!=="-s"&&i[a-1]!=="--size")),e.name==="cp"&&e.argv[1]==="/dev/null"&&e.argv[2]&&n.push(e.argv[2]);let s=e.groupWriters!==null&&!e.groupWriters.every(Gl);if(Gl(e))for(let o of e.redirects)(o.op===">"||o.op===">|")&&o.target&&!(s&&/\.log$/i.test(k(o.target)))&&n.push(o.target);e.redirects.forEach((o,a)=>{(o.op===">"||o.op===">|")&&(o.fd===null||o.fd===1)&&o.target&&e.redirects.slice(a+1).some(i=>i.fd===1||i.fd===null&&[">",">>",">|",">&"].includes(i.op))&&n.push(o.target)});let r=n.map(o=>({t:o,v:He(o,e,t)})).find(({t:o,v:a})=>Cu.test(k(o))&&a.kind!=="disposable");return r?[m("claude.bash.fs.delete_recursive",`empties a data file (${R.basename(k(r.t))})`,{target:r.v.path,is_local:!0})]:[]}import{createHash as Gw}from"crypto";import{readFileSync as Kw}from"fs";import{join as wn}from"path";import{spawnSync as t_}from"child_process";import{createHash as Ww}from"crypto";import{chmodSync as r_,existsSync as o_,lstatSync as Nw,mkdirSync as i_,readdirSync as a_,readFileSync as l_,readlinkSync as Lw,realpathSync as Mu,rmdirSync as c_,statSync as si,unlinkSync as u_,writeFileSync as d_}from"fs";import{dirname as Tw,isAbsolute as p_,join as h_,relative as g_,resolve as Iw}from"path";var at={on:"\u25CF",watching:"\u25CB",held:"\u25A0",ok:"\u2713",blocked:"\u2715",problem:"\u25B2",next:"\u203A"};function cw(e){if(!e){let l=c=>c;return{on:!1,bold:l,dim:l,blue:l,grey:l,amber:l,mark:l,field:l}}let t=e==="truecolor",n=l=>c=>`\x1B[${l}m${c}\x1B[0m`,s=n(t?"38;2;76;139;255":"38;5;69"),r=n(t?"38;2;130;134;150":"90"),o=n(t?"38;2;245;165;36":"38;5;214"),a=n(t?"38;2;34;197;94":"32"),i={[at.on]:s,[at.blocked]:s,[at.held]:s,[at.next]:s,[at.watching]:r,[at.problem]:o,[at.ok]:a};return{on:!0,bold:n("1"),dim:n("2"),blue:s,grey:r,amber:o,mark:l=>(i[l]??(c=>c))(l),field:l=>`\x1B[${t?"48;2;24;2;166;38;2;255;255;255":"48;5;19;97"}m${dw(l)}\x1B[0m`}}var P$=cw(!1),uw=/\u001b\[[0-9;]*m|\u001b\][^\u0007]*\u0007/g;function dw(e){return e.replace(uw,"")}var Au="claude.agent.controls";var Eu=[{id:"protect",name:"Protect what can't come back",verdict:"block",short:"wiping your home folder or the project, and force-pushing main",context:"blocks deleting the user's home folder, the disk, a system folder, the project or its .git, force-pushing main or deleting it on the remote, and killing every process",slugs:{protected:"deleting your home folder, the disk, a system folder, the project or its .git; force-pushing main or deleting it on the remote; killing every process"}},{id:"keep-anvil-on",name:"Keep Anvil on",verdict:"hold",short:"changes to Anvil",context:"holds any change to Anvil or to Claude Code's permissions, hooks and settings",slugs:{"agent-controls":"any change to Anvil, or to Claude Code's permissions, hooks and settings"}},{id:"stop-loops",name:"Stop runaway loops",verdict:"hold",short:"delete bursts and repeats",context:"holds more than 20 recursive deletes in a minute and the same app change twice in 10 minutes",slugs:{"delete-burst":"more than 20 recursive deletes in a minute",repeat:"the same app (MCP) change twice in 10 minutes"}},{id:"stop-helper-bursts",name:"Stop runaway helpers",verdict:"hold",short:"helper bursts",context:"holds more than 20 helper agent launches in 10 minutes in one session",slugs:{"helper-burst":"more than 20 helper launches in 10 minutes"}},{id:"keep-keys-in",name:"Keep keys in",verdict:"hold",short:"use of your account keys",context:"holds reading or writing the user's account key files (such as ~/.ssh/id_* and ~/.aws/credentials) and committing or sending a secrets file",slugs:{credentials:"reading or writing your account key files (~/.ssh/id_*, ~/.aws/credentials, ~/.npmrc \u2026)","secrets-expose":"committing or sending a secrets file"}},{id:"hold-unchecked",name:"Hold what it can't check",verdict:"hold",short:"actions it can't check",context:"holds a call it could not read in full or check in time",slugs:{"could-not-check":"a command too long or nested too deep to read, or one its classifier failed on","too-long-to-check":"a call it could not check in time (1 second a pass, 3 in all)"}}],fw="home and project wipes and force-pushes to main",D$=`always blocking ${fw}`,F$=new Map(Eu.map(e=>[e.id,e]));var pw=new Set(Eu.flatMap(e=>Object.keys(e.slugs)));var Ru=new Set([Au,"claude.bash.secrets.expose"]);var Ou=oe({"claude.bash.fs.delete_recursive":{slug:"delete",text:"recursive delete"},"claude.bash.fs.delete_disposable":{slug:"delete-temp",text:"delete of temp or build files"},"claude.bash.git.force_push":{slug:"force-push",text:"force-push"},"claude.bash.git.push_main":{slug:"push-main",text:"push or merge to main"},"claude.bash.git.discard":{slug:"discard",text:"discard uncommitted work"},"claude.bash.db.destructive":{slug:"db-destroy",text:"destroy database data"},"claude.bash.deploy":{slug:"deploy",text:"deploy"},"claude.bash.publish":{slug:"publish",text:"publish a package or release"},"claude.bash.secrets.print":{slug:"secrets-print",text:"print secrets"},"claude.bash.privilege":{slug:"sudo",text:"run as root, or run code it cannot read"},"claude.bash.process.kill_by_name":{slug:"kill",text:"kill processes by name or port"},"claude.bash.external_write":{slug:"external-write",text:"write to an external API"},"claude.bash.spend":{slug:"spend",text:"start paid compute"},"claude.bash.secrets.expose":{slug:"secrets-expose",text:"commit or send a secrets file"},"claude.bash.net.expose":{slug:"net-expose",text:"open this machine to the internet"},"claude.bash.data.export":{slug:"data-export",text:"copy a remote database here"},"claude.bash.crypto.transaction":{slug:"crypto",text:"send a transaction on a real chain"},"claude.bash.persistence":{slug:"persistence",text:"install background jobs or global git hooks"},"claude.agent.controls":{slug:"agent-controls",text:"change its own permissions, hooks or rules"},"claude.agent.helper":{slug:"helper-agent",text:"launch a helper agent"},"claude.file.write_secret":{slug:"secret-file-write",text:"write a secrets file"},"claude.file.read_secret":{slug:"secret-file-read",text:"read a secrets file"},"claude.mcp.side_effect":{slug:"mcp-write",text:"MCP tool that changes something"},"claude.mcp.call":{slug:"mcp-read",text:"MCP tool call"},"claude.bash.unclassified":{slug:"other",text:"command"},"claude.tool.other":{slug:"tool",text:"tool call"}});function ju(e){return Ou[e]?.text??e}var Pu="\u{1F539}",cr=e=>`${Pu} ${e} ${Pu}`,hw=oe({"claude.bash.git.push_main":"pushes to main","claude.agent.controls":"its own settings","claude.bash.git.force_push":"force-pushes","claude.bash.fs.delete_recursive":"deletes","claude.bash.git.discard":"thrown-away work","claude.bash.db.destructive":"database wipes","claude.bash.deploy":"deploys","claude.bash.publish":"releases","claude.bash.secrets.print":"printed secrets","claude.bash.spend":"paid compute","claude.bash.external_write":"outside writes","claude.mcp.side_effect":"app changes"}),gw=e=>hw[e]??ju(e),mw=gw;function yw(e,t){let n=[...[...e].sort((s,r)=>+(s==="claude.agent.controls")-+(r==="claude.agent.controls")).map(mw),...t?[t]:[]];return n.length<=2?n.join(" and "):`${n[0]}, ${n[1]} and ${n.length-2} more`}var Wu=e=>`
|
|
81
|
-
${
|
|
82
|
-
${
|
|
83
|
-
`);i=l<0?"":i.slice(l+1)}return i}finally{Lu(n)}}function zu(e,t,n=384){let s=`${e}.${process.pid}.${Date.now().toString(36)}.tmp`;jw(s,t,{mode:n}),ni(s,e)}function ni(e,t){for(let n=0;;n++)try{Rw(e,t);return}catch(s){let r=s.code;if(process.platform!=="win32"||n>=12||r!=="EPERM"&&r!=="EACCES"&&r!=="EBUSY")throw s;Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,20+n*10)}}function Qn(e){if(Ke(e)!==!0)return null;try{return JSON.parse(Ew(e,"utf8"))}catch{return null}}var F0=256*1024,z0=1024*1024;var Dw="/.anvil/claude/bin/claude-hook.js",Fw=/[\\/]\.anvil[\\/]claude[\\/]bin[\\/]claude-hook\.js/i;var bn=class extends Error{constructor(t){super(t),this.name="SettingsRefused"}};function Uu(e){return`// anvil-claude-hook ${Ww("sha256").update(e).digest("hex").slice(0,16)}`}function ri(e,t){let n=e.startsWith("\uFEFF")?e.slice(1):e;if(n.trim()==="")return{};let s;try{s=JSON.parse(n)}catch(r){throw new bn(`${t} is not valid JSON (${r instanceof Error?r.message:String(r)}). Anvil changed nothing; fix the file and run this again.`)}if(!s||typeof s!="object"||Array.isArray(s))throw new bn(`${t} is not a JSON object. Anvil changed nothing.`);return s}function zw(e){if(!e||typeof e!="object")return null;let{command:t,args:n}=e;return typeof t!="string"?null:Array.isArray(n)?[t,...n.filter(s=>typeof s=="string")].join(" "):t}var Mw=e=>{let t=zw(e);return t!==null&&(t.includes(Dw)||Fw.test(t))};function Uw(e){return lt(e,64*1024*1024)}function qw(e){try{if(!Nw(e).isSymbolicLink())return e}catch{return e}try{return Mu(e)}catch(t){let n=t.code;throw n==="ENOENT"?new bn(`${e} is a link to ${Hw(e)}, which does not exist. Anvil changed nothing; create that file or remove the link, and run this again.`):new bn(`${e} is a link Anvil cannot follow (${n??String(t)}). Anvil changed nothing.`)}}function Hw(e){let t=Tw(e);try{t=Mu(t)}catch{}return Iw(t,Lw(e))}function qu(e){try{let t=qw(e),n=si(t);if(!n.isFile()||n.size>4*1024*1024)return!1;let s=Uw(t);if(s===null)return!1;let r=ri(s.toString("utf8"),e).hooks?.PreToolUse;return Array.isArray(r)&&r.some(o=>{let a=o&&typeof o=="object"?o:null,i=a?.matcher;return(i===void 0||i===""||i==="*")&&Array.isArray(a?.hooks)&&a.hooks.some(l=>Mw(l)&&Zw(l))})}catch{return!1}}function Bw(e){let t=e.trim().match(/'(?:[^']|'\\'')*'|[^\s']+/g),n=o=>o.startsWith("'")?o.slice(1,-1).replace(/'\\''/g,"'"):o,s=t?t.findIndex(o=>o==="/bin/sh"||o==="sh"):-1,r=t&&s>=0&&(t[s+3]==="PreToolUse"||t[s+3]==="SessionStart")?1:0;if(t&&s>=0&&t[s+3+r]==="||"){let o=s>0&&s%5===0;for(let a=0;o&&a<s;a+=5)o=t[a]==="["&&(t[a+1]==="-s"||t[a+1]==="-f")&&t[a+3]==="]"&&t[a+4]==="&&"&&n(t[a+2])===n(t[s+1]);if(s===0||o)return[n(t[s+1]),n(t[s+2])]}return!t||t.length!==2?null:[n(t[0]),n(t[1])]}function Vw(e){if(!e||typeof e!="object")return null;let{command:t,args:n}=e;if(typeof t!="string")return null;if(Array.isArray(n)){let s=n.find(r=>typeof r=="string"&&/[\\/]\.anvil[\\/]claude[\\/]bin[\\/]claude-hook\.js$/i.test(r));return s?[t,s]:null}return Bw(t)}function Zw(e){let t=Vw(e);if(!t)return!1;try{return si(t[0]).isFile()&&si(t[1]).isFile()}catch{return!1}}var Yw=["claude-hook-core.js","claude-sync.js","claude-hook.js","claude-meter.js","claude-helpers.js","claude-conditions.js"],Jw=process.platform==="darwin"?"/Library/Application Support/ClaudeCode/managed-settings.json":process.platform==="win32"?`${process.env.ProgramFiles||"C:\\Program Files"}\\ClaudeCode\\managed-settings.json`:"/etc/claude-code/managed-settings.json";function Xw(e,t=Jw){let n=[],s=l=>l.startsWith(`${e.home}/`)?`~${l.slice(e.home.length)}`:l;for(let l of[t,...e.files])try{Ke(l,4*1024*1024)===!0&&ri(Kw(l,"utf8"),l).disableAllHooks===!0&&n.push(`hooks are off for new sessions ("disableAllHooks") in
|
|
86
|
+
`):null}function n$(e){return e.split(`
|
|
87
|
+
`).map(n=>n.trim()).filter(n=>n!==""&&!n.startsWith("#")&&!/^[A-Za-z_][A-Za-z0-9_]*\s*=/.test(n)).map(n=>n.startsWith("@")?n.replace(/^@\S+\s+/,""):n.split(/\s+/).slice(5).join(" "))}var xu=new WeakMap;function Ri(e){let n=xu.get(e);return n||(n=[P(e.argv,"-name","-iname","-path","-ipath")].filter(t=>t!==null),xu.set(e,n)),n}function wf(e){let n=e.parent;if(!n)return[];if(e.via==="find-exec"&&n.name==="find")return Ri(n);if(e.via==="xargs"&&n.pipeFrom){let t=n.pipeFrom;if(t.name==="find")return Ri(t);if(["echo","printf","ls"].includes(t.name))return t.argv.slice(1).filter(s=>!s.startsWith("-"))}return[]}var kf="reads Anvil's seal key, which signs its rules: with it, a rule changed out of sight would pass as Anvil's own",s$=/\.anvil\/claude\/seal\.key(?![\w.-])/,r$=new Set(["cat","tac","nl","head","tail","less","more","bat","batcat","grep","egrep","fgrep","rg","ag","ack","base64","base32","xxd","od","hexdump","strings","tar","gtar","bsdtar","zip","7z","7za","gzip","bzip2","xz","zstd","cp","gcp","rsync","scp","sftp","ditto","pax","cpio","openssl","sed","gsed","awk","gawk","diff","cmp","curl","nc","ncat","dd","rclone","aws","gsutil","azcopy"]);function vf(e,n,t){let s=O.join(n,".anvil"),r=O.join(s,"claude"),o=e;for(let a=!0;a;){for(a=!1;o.length>1&&o.endsWith("/");)o=o.slice(0,-1),a=!0;o.endsWith("/.")&&(o=o.slice(0,-2),a=!0)}return o===`${r}/seal.key`||O.dirname(o)===r&&/[*?[]/.test(O.basename(o))&&eo(O.basename(o),"seal.key")?!0:t?o===s||o===r?!0:O.dirname(o)===s&&/[*?[]/.test(O.basename(o)):!1}function eo(e,n){let t=(i,l)=>{if(e[i]==="?")return[!0,i+1];if(e[i]==="["){let c=e.indexOf("]",i+2);if(c>i){let u=e.slice(i+1,c),p=u[0]==="!"||u[0]==="^";p&&(u=u.slice(1));let d=!1;for(let f=0;f<u.length;f++)u[f+1]==="-"&&f+2<u.length?(l>=u[f]&&l<=u[f+2]&&(d=!0),f+=2):u[f]===l&&(d=!0);return[d!==p,c+1]}}return[e[i]===l,i+1]},s=0,r=0,o=-1,a=0;for(;r<n.length;){if(e[s]==="*"){o=s++,a=r;continue}if(s<e.length){let[i,l]=t(s,n[r]);if(i){s=l,r++;continue}}if(o<0)return!1;s=o+1,r=++a}for(;e[s]==="*";)s++;return s===e.length}function o$(e,n){let t=[w("claude.agent.controls",kf,{target:"~/.anvil/claude/seal.key",is_local:!0})];if([e.text,...e.argv.map($),e.scriptText??"",e.stdin??""].some(a=>s$.test(a)))return t;let s=n.ctx.home,r=r$.has(e.name)||e.name==="find"&&(e.argv.some(a=>/^-(exec|execdir|ok|okdir)$/.test(a))||e.pipeTo!==null),o=e.cwd??n.base;for(let a=1;a<e.argv.length;a++){let i=e.argv[a];if(S(i))continue;if(["tar","gtar","bsdtar"].includes(e.name)&&(i==="-C"||i==="--directory"||i.startsWith("--directory="))){let c=i.startsWith("--directory=")?i.slice(12):e.argv[++a];c!==void 0&&!S(c)&&(o=M(c,o,n.ctx));continue}if(i.startsWith("-")&&!i.includes("@")&&!i.includes("/"))continue;let l=i.replace(/^(?:-[\w-]*=)?[\w-]*=@?|^@/,"");if(!(l===""||!l.includes("/")&&!l.includes(".")&&!/[*?[]/.test(l))&&!(o===null&&!/^[/~]/.test(l))&&vf(M(l,o,n.ctx),s,r))return t}return[]}function i$(e,n){let t=["docker","podman","docker-compose"].includes(e.name)?pf(e.name==="docker-compose"?["docker","compose",...e.argv.slice(1)]:e.argv):null;if(t&&t.args.length>0&&!/(^|\/)(cloudflared|ngrok)(:[^/]*)?$/.test(t.image)){let s=["sh","bash","ash","zsh","/bin/sh","/bin/bash"].includes(t.args[0])&&t.args[1]==="-c"?t.args[2]??null:t.args.length===1&&/\s/.test(t.args[0])?t.args[0]:null,r=s!==null?cn(s,null,n,null).commands:[{...e,name:he(t.args[0]),argv:t.args}];return[...Ur(e,n),...r.flatMap(o=>[...du(o,n),...hu(o,n),...Ki(o,n),...Ci(o)])]}return[...Vv(e,n),...Bv(e,n),...rn(n,()=>pv(e,n)),...rn(n,()=>kv(e,n)),...Ci(e),...du(e,n),...hu(e,n),...Av(e),...Rv(e,n),...Wv(e,n),...Ov(e),...Ur(e,n),...o$(e,n)]}var _u=new Set(["sudo","doas","pkexec","run0"]),a$=new Set(["-n","-v","-k","-K","-l","--validate","--reset-timestamp","--remove-timestamp","--list","--non-interactive","-nv","-vn","-nl","-ln"]),Sr=new Set(["sh","bash","zsh","dash","ksh","fish","python","python3","node","perl","ruby","php","deno","bun"]),qr=new Set(["curl","wget","fetch","http","https","xh","aria2c"]),$s=new Set(["sh","bash","zsh","dash","ksh","fish","ash","mksh","yash"]);function l$(e,n){let t=[],s=e.wrappers.find(o=>_u.has(o));if(s){let o=(e.argv[0]==="true"||e.argv[0]===":")&&e.argv.length===1,a=c=>c.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),i=new RegExp(`\\b${a(s)}\\b[^;&|\\n]*?\\s-u\\s*([\\w.-]+)[^;&|\\n]*?\\b${a(O.basename(e.name))}\\b`).exec(n.lineText)?.[1],l=i&&!["root","0","#0"].includes(i)?`as the user ${i}`:"as root";!o&&jd(e)===null&&t.push(w("claude.bash.privilege",`runs ${e.name} ${l} (${s})`,{target:e.argv.slice(0,3).join(" "),is_local:e.remote===null,host:e.remote}))}else _u.has(e.name)&&e.argv.slice(1).some(o=>!a$.has(o))&&t.push(w("claude.bash.privilege",`runs ${e.name}`,{target:e.argv.join(" "),is_local:!0}));e.name==="osascript"&&/with\s+administrator\s+privileges/i.test(e.argv.join(" "))&&t.push(w("claude.bash.privilege","osascript runs a shell command as an administrator",{target:"osascript",is_local:!0})),e.name==="su"&&t.push(w("claude.bash.privilege","switches to another user (su)",{target:e.argv.join(" "),is_local:!0})),e.unreadableCode&&t.push(w("claude.bash.privilege",`runs code it cannot read (${e.unreadableCode})`,{target:e.unreadableCode,is_local:null}));let r=$s.has(e.name)?wn(e.argv).stdin||["/dev/stdin","/dev/fd/0","-"].includes(wn(e.argv).script??""):!e.argv.slice(1).some(o=>!o.startsWith("-")&&o!=="-"&&o!=="-s");if(Sr.has(e.name)&&e.pipeFrom&&qr.has(e.pipeFrom.name)&&r){let o=e.pipeFrom.argv.find(a=>Tn(a))??null;(!o||!qe(o))&&t.push(w("claude.bash.privilege",`pipes a download into ${e.name}`,{target:o,host:o?me(o):null,is_local:!1}))}if(Sr.has(e.name)||e.name==="source"||e.name==="."||e.argv[0]?.startsWith("./")||e.argv[0]?.startsWith("/")){let o=e.argv.slice(1).some(i=>["-","-m","--eval","--print"].includes(i)||/^-[a-zA-Z]*[cep]$/.test(i)),a=$s.has(e.name)?wn(e.argv).script:e.name==="source"||e.name==="."?e.argv[1]:Sr.has(e.name)?o?void 0:e.argv.slice(1).find(i=>!i.startsWith("-")):e.argv[0];a&&!S(a)&&n.downloads.has(te(a,e.cwd,le(n)).path)&&t.push(w("claude.bash.privilege",`runs a script it downloaded (${O.basename(a)})`,{target:a,is_local:!1}))}if($s.has(e.name)&&e.stdinKind==="here-string"&&/\$\(\s*(curl|wget)\b|`\s*(curl|wget)\b/.test($(e.stdin??""))&&t.push(w("claude.bash.privilege",`runs a downloaded script with ${e.name}`,{target:$(e.stdin??"").slice(0,120),is_local:!1})),e.name==="xargs"&&e.pipeFrom&&qr.has(e.pipeFrom.name)){let o=e.argv.findIndex((i,l)=>l>0&&$s.has(he(i))),a=e.pipeFrom.argv.find(i=>Tn(i))??null;o>0&&wn(e.argv.slice(o)).command===null&&(!a||!qe(a))&&t.push(w("claude.bash.privilege","pipes a download into a shell through xargs",{target:a,host:a?me(a):null,is_local:!1}))}if(Sr.has(e.name)||e.name==="eval"||e.name==="source"||e.name==="."){let a=c$(e).find(i=>S(i)&&/\$\(\s*(curl|wget)\b|`\s*(curl|wget)\b|<\(\s*(curl|wget)\b/.test($(i)));a&&t.push(w("claude.bash.privilege",`runs a downloaded script with ${e.name}`,{target:$(a).slice(0,120),is_local:!1}))}if(e.name==="chmod"){let o=e.argv.slice(1),a=o.some(d=>d==="-R"||d==="--recursive"||/^-[a-zA-Z]*R/.test(d)),i=o.find(d=>!d.startsWith("-"))??"",l=/^0?777$|^a\+rwx$|^ugo\+rwx$|^o\+w|^a\+w|^\+w$/.test(i),c=/^[ugoa]*\+s$|^[2467]\d{3}$/.test(i),u=o.filter((d,f)=>!d.startsWith("-")&&f>o.indexOf(i)),p=u.some(d=>rt(d,e,n).kind==="catastrophic");(l&&(a||p)||c)&&t.push(w("claude.bash.privilege",`chmod ${i}${a?" -R":""} opens up permissions`,{target:u.join(" "),is_local:!0}))}return(e.name==="spctl"&&e.argv.includes("--master-disable")||e.name==="csrutil"&&e.argv.includes("disable"))&&t.push(w("claude.bash.privilege",`${e.name} turns off a system protection`,{target:e.argv.join(" "),is_local:!0})),t}function c$(e){let n=e.argv.slice(1);if(e.name==="eval"||e.name==="source"||e.name===".")return n;let t=new Set(["-c","-e","-E","--eval","-p","--print","-r"]);for(let s=0;s<n.length;s++){let r=n[s];if(t.has(r)||/^-[a-zA-Z]*c$/.test(r))return n[s+1]!==void 0?[n[s+1]]:[];if(!r.startsWith("-"))return[r]}return[]}function u$(e,n){let t=new Uint8Array(e.length),s=0;for(;s<e.length;){let r=e[s];if(n!=="js"&&r==="#"||n!=="python"&&r==="/"&&e[s+1]==="/"){let a=e.indexOf(`
|
|
88
|
+
`,s),i=a===-1?e.length:a;t.fill(1,s,i),s=i;continue}if(n!=="python"&&r==="/"&&e[s+1]==="*"){let a=e.indexOf("*/",s+2),i=a===-1?e.length:a+2;t.fill(1,s,i),s=i;continue}if(r==='"'||r==="'"||n==="js"&&r==="`"){let a=n==="python"&&e.startsWith(r.repeat(3),s)?r.repeat(3):r,i=s+a.length;for(;i<e.length;){if(e[i]==="\\"){i+=2;continue}if(e.startsWith(a,i)){i+=a.length;break}if(a.length===1&&a!=="`"&&e[i]===`
|
|
89
|
+
`)break;i++}t.fill(1,s+a.length,Math.max(s+a.length,Math.min(i,e.length)-a.length)),s=Math.max(i,s+1);continue}s++}return r=>t[r]!==1}var oa=ae({python:["-c"],python3:["-c"],node:["-e","--eval","-p","--print"],tsx:["-e","--eval","-p","--print"],"ts-node":["-e","--eval","-p","--print"],perl:["-e","-E"],ruby:["-e"],deno:["eval"],bun:["-e","--eval"],php:["-r"]}),ia=/^(os\.homedir\(\)|require\(['"](node:)?os['"]\)\.homedir\(\)|process\.env\.HOME\b|process\.env\[['"]HOME['"]\]|Path\.home\(\)|os\.path\.expanduser\(\s*['"]~['"]\s*\)|os\.environ\[['"]HOME['"]\]|os\.environ\.get\(\s*['"]HOME['"]\s*\)|os\.getenv\(\s*['"]HOME['"]\s*\)|Deno\.env\.get\(['"]HOME['"]\)|Dir\.home|ENV\[['"]HOME['"]\]|\$ENV\{['"]?HOME['"]?\}|glob\(\s*['"]~['"]\s*\))/;function d$(e,n,t){let s=[],r=a=>{let i=a.trim(),l=/^(['"`])((?:\\.|(?!\1)[^\\])*)\1$/.exec(i);if(l)return Oi(l[2].replace(/\\(.)/g,"$1"));if(ia.test(i))return"~";let c=/^(?:process\.env\.(\w+)|process\.env\[['"](\w+)['"]\]|os\.environ\[['"](\w+)['"]\]|os\.environ\.get\(\s*['"](\w+)['"]|os\.getenv\(\s*['"](\w+)['"]|ENV\[['"](\w+)['"]\]|Deno\.env\.get\(['"](\w+)['"]\))/.exec(i);if(c)return`"$${c.slice(1).find(Boolean)}"`;let u=/^[A-Za-z_$][\w$.]*$/.test(i)||/^(?:pathlib\.)?Path\(|^os\.path\.join\(|^path\.join\(/.test(i)?t(i):null;return u!==null?Oi(u):'"$(unknown)"'},o=a=>{let i=[],l=null;for(let p=a.length-1;p>=0;p--){let d=a[p];d===")"||d==="]"||d==="}"?l="close":d==="("||d==="["||d==="{"?l="open":d===","&&l!=="close"&&i.push(p)}let c=[],u=a.length;for(let p of i)c.unshift(a.slice(p+1,u)),u=p;return c.unshift(a.slice(0,u)),c.map(p=>p.trim()).filter(Boolean)};for(let a of e.matchAll(/\b(?:subprocess\.(?:run|call|check_call|check_output|Popen)|Bun\.spawn(?:Sync)?|os\.spawnvp?e?)\s*\(\s*(?:os\.P_\w+\s*,\s*)?(?:\{\s*cmd\s*:\s*)?\[([^\]]*)\]/g)){let i=o(a[1]);n(a.index??0)&&/^(['"`])/.test(i[0]??"")&&s.push(i.map(r).join(" "))}for(let a of e.matchAll(/\b(?:spawn|spawnSync|execFile|execFileSync|execa|execaSync|execaNode)\s*\(\s*((['"`])(?:\\.|(?!\2)[^\\])*\2)\s*,\s*\[([^\]]*)\]/g))n(a.index??0)&&s.push([r(a[1]),...o(a[3]).map(r)].join(" "));for(let a of e.matchAll(/\bDeno\.Command\s*\(\s*((['"`])(?:\\.|(?!\2)[^\\])*\2)\s*,\s*\{\s*args\s*:\s*\[([^\]]*)\]/g))n(a.index??0)&&s.push([r(a[1]),...o(a[3]).map(r)].join(" "));return s}function Oi(e){return/^[\w./=:@%+,~-]+$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}function f$(e,n,t,s){let r=oa[e.name],o=r?e.argv.findIndex((p,d)=>d>0&&r.includes(p)):-1;if(o<0||t.length===0)return null;let a=e.argv.slice(o+2),i=p=>Qr(p,s.ctx,e.cwd)||!S(p)&&Mt($(M(p,e.cwd,s.ctx)),s.ctx,!1),l=p=>{let d=p.trim(),f=/^[A-Za-z_$][\w$]*$/.test(d)?new RegExp(`(?:^|[^\\w$.])${d.replace(/\$/g,"\\$")}\\s*=(?!=)\\s*([^\\n;]+)`).exec(n)?.[1]??d:d,h=/\b(?:process|sys)\.argv\[(\d+)\]/.exec(f);if(h)return Number(h[1])-1;let g=/(?:\$|\b)ARGV\[(\d+)\]/.exec(f);return g?Number(g[1]):null},c=t.map(l);return(c.every(p=>p!==null)?c.map(p=>a[p]).filter(p=>p!==void 0):a).find(i)??null}function Ls(e){let n=oa[e.name];if(!n)return null;let t=null;for(let r=1;r<e.argv.length;r++){let o=e.argv[r];if(n.includes(o)||/^-[A-Za-z]{2,}$/.test(o)&&n.some(a=>/^-[A-Za-z]$/.test(a)&&o.endsWith(a.slice(1)))){t=e.argv[r+1]??null;break}}let s=e.argv.length===1||e.argv.slice(1).every(r=>r==="-"||r.startsWith("-"));return t===null&&e.scriptText!==null&&(t=e.scriptText),t===null&&e.stdin!==null&&s&&(t=e.stdin),t===null&&s&&e.pipeFrom&&(e.pipeFrom.name==="echo"||e.pipeFrom.name==="printf")&&(t=e.pipeFrom.argv.slice(1).join(" ")),t}function p$(e,n){let t=Ls(e);if(t===null)return[];let s=u$(t,e.name.startsWith("python")?"python":["node","deno","bun"].includes(e.name)?"js":"other"),r=[],o=[],a=/\b(?:os\.system|os\.popen|subprocess\.(?:run|call|check_call|check_output|Popen)|execSync|execFileSync|spawnSync|exec|system|`)\s*\(\s*(?:\[\s*)?(['"`])((?:\\.|(?!\1)[^\\])*)\1/g;for(let u of t.matchAll(a))s(u.index??0)&&o.push(u[2].replace(/\\(.)/g,"$1"));o.push(...d$(t,s,u=>{let p=ln(u,t,e,0,n.ctx.home,n.cut);return p===null?null:p.startsWith(zn)?O.join(n.ctx.tmpdir,"code-temp"):S(p)?null:p}));for(let u of t.matchAll(/(?:\bBun\.\$|(?<![\w$.])\$)(?:\.\w+\([^)]*\))*\s*`((?:\\.|[^`\\])*)`/g))s(u.index??0)&&o.push(u[1].replace(/\$\{[^}]*\}/g,'"$(unknown)"'));let i=/\b(execSync|execFileSync|spawnSync|check_output|getoutput|getstatusoutput|popen)\b|capture_output\s*=\s*True|stdout\s*=\s*subprocess\.PIPE|stdio\s*:\s*['"]pipe/.test(t);for(let u of o){let p=Ou({tool:"Bash",command:u,target:null,cwd:e.cwd,git_branch:n.branch},n),d=zu(p,`(run from ${e.name})`).filter(f=>!(f.action==="claude.bash.secrets.print"&&i)&&!(f.action==="claude.bash.privilege"&&/cannot read/.test(p.why)));r.push(...d)}let l=/(?:\b(?:shutil\.rmtree|rmtree|remove_tree|rimraf(?:\.sync)?|fse?\.removeSync|fse?\.remove|Deno\.remove|FileUtils\.rm_rf|FileUtils\.remove_dir)|(?:\bfs|\bpromises|\))\.(?:rmSync|rm|rmdirSync))\s*\(\s*(?:(['"`])((?:\\.|(?!\1)[^\\])*)\1|([A-Za-z_$][\w.{}$]*))/g;for(let u of t.matchAll(l)){if(!s(u.index??0))continue;let p=u[2],d=u[0];if(!(/rmtree|remove_tree|rimraf|remove|rm_rf|remove_dir/.test(d)||/recursive\s*:\s*true/.test(t.slice(u.index??0,(u.index??0)+200))))continue;let h=t.slice((u.index??0)+u[0].length-(u[3]?.length??0),(u.index??0)+u[0].length+40),g=ia.test(h),b=(u.index??0)+u[0].indexOf("("),k=to(t,b),E=k>b?Un(t.slice(b+1,k))[0]??u[3]??"?":u[3]??"?",y=p!==void 0&&E.trim().length===p.length+2?te(De(p,e,n),e.cwd,le(n)):g&&E.trim()===(u[3]??"").trim()?te(n.ctx.home,null,le(n)):h$(t,E,e,n);if(r.push({...Ft([y],e),why:`${Ft([y],e).why} (from ${e.name})`}),p!==void 0&&E.trim().length===p.length+2&&e.remote===null){let m=ea(M(De(p,e,n),e.cwd,n.ctx),"d",n.ctx,n.projectRoot,!1);m&&r.push(m)}}let c=/\b(?:requests|httpx|axios)\.(post|put|patch|delete)\s*\(\s*(?:(['"`])([^'"`]*)\2|f(['"])([^'"]*)\4|([A-Za-z_$][\w.$]*(?:\[['"]\w+['"]\])?))|\bfetch\s*\(\s*(?:(['"`])([^'"`]*)\7|([A-Za-z_$][\w.$]*))\s*,\s*\{[^}]*method\s*:\s*['"`](POST|PUT|PATCH|DELETE)/gi;for(let u of t.matchAll(c)){if(!s(u.index??0))continue;let p=(u[1]??u[10]??"POST").toUpperCase(),d=u[3]??u[5]??u[8],f=u[6]??u[9],h=d??(f?m$(t,f):null),g=h===null?null:h.replace(/:\$?\{[^}]*\}/,":1").replace(/\$?\{[^}]*\}/g,"x");g!==null&&/^https?:\/\//i.test(g)?qe(g)||r.push(w("claude.bash.external_write",`${p} to ${me(g)} (from ${e.name})`,{target:g,host:me(g),is_local:!1})):g===null&&f&&!/https?:\/\/(localhost|127\.0\.0\.1|\[::1\])\b/i.test(t)&&r.push(w("claude.bash.external_write",`${p} to a URL held in ${f} (from ${e.name})`,{target:f,host:null,is_local:null}))}return r}function h$(e,n,t,s){let r={kind:"normal",path:n,token:null,why:`a path held in ${n}`},o=ln(n,e,t,0,s.ctx.home,s.cut);if(o===null)return r;if(o.startsWith(zn))return{kind:"disposable",path:n,token:null,why:`a temp folder the code made (${n})`};let a=te(De(o,t,s),t.cwd,le(s));return a.kind==="normal"&&S(o)?r:a}var zn="temp",g$=/^(tempfile\.(mkdtemp|TemporaryDirectory|gettempdir)\b|(?:await\s+)?(?:fs\.|fsp\.|promises\.)?mkdtemp(Sync)?\s*\(|os\.tmpdir\(\)|Dir\.mktmpdir|Deno\.makeTempDir|path\.join\(\s*os\.tmpdir\(\)|tmpdir\(\))/;function ln(e,n,t,s,r,o){if(s>4)return null;let a=e.trim().replace(/\.(resolve|absolute|expanduser)\(\)/g,"").replace(/^await\s+/,"");if(g$.test(a))return zn;let i=ia.exec(a);if(i)return Cr(r,a.slice(i[0].length).trim()?`/${di(a.slice(i[0].length).replace(/^\s*[+/]\s*/,""))}`:"");let l=null,c="",u=d=>{let f=d.exec(a);return f&&(c=a.slice(f[0].length)),f},p;if(p=u(/^f?(['"`])((?:\\.|(?!\1)[^\\])*)\1/)){let d=/^\$?\{([A-Za-z_$][\w$.]*)\}(.*)$/s.exec(p[2]);l=d?Cr(ln(d[1],n,t,s+1,r,o),d[2].replace(/\$?\{[^}]*\}/g,"x")):p[2].replace(/\$?\{[^}]*\}/g,"x")}else if(p=u(/^(?:sys\.argv|process\.argv)\[(\d+)\]/)){let d=t.argv.findIndex((h,g)=>g>0&&!h.startsWith("-")),f=Number(p[1]);l=t.argv[d+(a.startsWith("process")?f-1:f)]??null}else if(p=u(/^(?:Path\(\s*__file__\s*\)\.parent|os\.path\.dirname\(\s*(?:os\.path\.abspath\(\s*)?__file__\s*\)?\s*\)|__dirname|path\.dirname\(\s*fileURLToPath\(\s*import\.meta\.url\s*\)\s*\))/))l=t.scriptPath?O.dirname(t.scriptPath):null;else if(p=u(/^(?:pathlib\.)?(?:Path|PurePath|PosixPath|str|String|os\.path\.(?:join|abspath|realpath|normpath)|path\.(?:join|resolve|normalize)|join|resolve)\s*\(/)){let d=to(a,p[0].length-1);if(d<0)return null;let f=Un(a.slice(p[0].length,d));c=a.slice(d+1),l=ln(f[0]??"",n,t,s+1,r,o);for(let h of f.slice(1))l=Cr(l,`/${di(h)}`)}else if(p=u(/^(?:self\.|this\.)?([A-Za-z_$][\w$]*)/)){let d=new RegExp(`(?:^|[^\\w$.])${p[1].replace(/\$/g,"\\$")}\\s*(?::\\s*[\\w.\\[\\] ]+\\s*)?=(?!=)\\s*([^\\n;]+)`).exec(n);if(!d||Un(d[1]).length>1)return null;l=ln(d[1],n,t,s+1,r,o)}if(l===null)return null;for(let d=0;c.trim();d++){if(d>=12){o&&(o.hit=!0);break}let f=c.trimStart(),h=/^(\/|\+)\s*(f?(['"`])(?:\\.|(?!\3)[^\\])*\3|[\w.$]+(?:\([^)]*\))?)/.exec(f);if(h){let g=di(h[2]);if(l=Cr(l,h[1]==="/"?`/${g}`:g),l===null)return null;c=f.slice(h[0].length);continue}if(f.startsWith(".parent")){if(l===null)return null;l=l.startsWith(zn)?l:O.dirname(l),c=f.slice(7);continue}break}return l}function Cr(e,n){return e===null?null:e.startsWith(zn)?e:n.startsWith("/")?`${e.replace(/\/$/,"")}${n}`:`${e}${n}`}function di(e){let n=/^f?(['"`])((?:\\.|(?!\1)[^\\])*)\1$/.exec(e.trim());return n?n[2].replace(/\$?\{[^}]*\}/g,"x"):"x"}function to(e,n){let t=0,s=null;for(let r=n;r<e.length;r++){let o=e[r];if(s){o==="\\"?r++:o===s&&(s=null);continue}if(o==='"'||o==="'"||o==="`")s=o;else if(o==="(")t++;else if(o===")"&&--t===0)return r}return-1}function Un(e){let n=[],t=0,s=null,r=0;for(let o=0;o<e.length;o++){let a=e[o];if(s){a==="\\"?o++:a===s&&(s=null);continue}a==='"'||a==="'"||a==="`"?s=a:"([{".includes(a)?t++:")]}".includes(a)?t--:a===","&&t===0&&(n.push(e.slice(r,o).trim()),r=o+1)}return n.push(e.slice(r).trim()),n.filter(o=>o!=="")}function m$(e,n){let t=n.replace(/^(self|this)\./,"");if(!/^[A-Za-z_$][\w$]*$/.test(t))return null;let s=new RegExp(`(?:^|[^\\w$.])${t.replace(/\$/g,"\\$")}\\s*(?::\\s*\\w+\\s*)?=\\s*f?(['"\`])([^'"\`]*)\\1`).exec(e);return s?s[2]:null}var aa=new Set(["node","python","python3","ruby","deno","bun","tsx","ts-node","go","php","perl","sh","bash"]),Su=new Set(["--apply","--write","--commit","--execute","--fix","--force","--yes","--confirm","--no-dry-run","--live","--migrate","--delete","--purge","--reset","--prune"]);function y$(e){if(!e.productionEnv||e.via==="substitution"||!aa.has(e.name))return[];let n=e.argv.slice(2).find(s=>Su.has(s)||Su.has(s.split("=")[0]??""));if(!n)return[];let t=e.argv.slice(1).find(s=>!s.startsWith("-"))??e.name;return[w("claude.bash.db.destructive",`runs ${O.basename($(t))} with production credentials and ${n}`,{target:$(t),is_local:!1,host:"production"})]}var $f=/^(deploy|release|publish|ship|rollout|promote)$/i,b$=/(^|[-_.])(deploy|release|publish|rollout|promote)([-_.]|$)/i,w$=/(^|[-_.])(tags?[-_.](and[-_.])?push|push[-_.]tags?)([-_.]|$)/i,k$=/(^|[-_.])(test|tests|spec|check|verify|lint|notes|changelog|build|docs|plan|diff|status|dry|preview|local|mock|fake|stub|prepare)([-_.]|$)/i,v$=/^(detect|find|get|next|determine|should|is|has|needs|parse|extract|wait|print|show|list|read|info)[-_.]/i,fi=e=>k$.test(e)||v$.test(e),pi=/\.(sh|bash|zsh|py|rb|js|mjs|cjs|ts|mts|cts|pl)$/,$$=/^(\.{1,2}\/)?[\w.-]+\/[\w./-]*[\w-]$/,hi=e=>$$.test(e)&&!/\.[A-Za-z0-9]{1,5}$/.test(O.basename(e))&&!/(^|\/)node_modules\//.test(e)&&!["gradlew","mvnw","gradle","mvn"].includes(O.basename(e))&&!Pr(O.basename(e))&&!td.has(O.basename(e))&&!Hn.has(O.basename(e))&&!Zr.has(O.basename(e)),x$=/(^|[-_.])(drop|purge|nuke|wipe|reset|truncate)[-_.]?(db|dbs|database|databases|data|tables?|schema)([-_.]|$)|(^|[-_.])(db|database)[-_.]?(drop|purge|nuke|wipe|reset|truncate)([-_.]|$)/i,_$=new Set(["py_compile","compileall","pyflakes","pylint","flake8","mypy","black","ruff"]);function xf(e,n){let t=O.basename(e);if(["sh","bash","zsh","dash","ksh"].includes(t))return n.some(r=>/^-[a-zA-Z]*n[a-zA-Z]*$/.test(r));if(t==="node"||t==="nodejs")return n.some(r=>r==="--check"||r==="-c");let s=/^python[\d.]*$/.test(t)?n.indexOf("-m"):-1;return s>=0&&_$.has(n[s+1]??"")}function S$(e,n){if(e.via==="substitution")return[];let t=e.argv.map(f=>$(f)),s=f=>pi.test(f)||hi(f),r=t[0]?.includes("/")&&s(t[0])?0:(e.name==="source"||e.name===".")&&(pi.test(t[1]??"")||(t[1]??"").includes("/")&&hi(t[1]))?1:aa.has(e.name)?t.findIndex((f,h)=>h>0&&!f.startsWith("-")&&(pi.test(f)||f.includes("/")&&hi(f))):-1;if(r<0||r>0&&xf(e.name,t.slice(1,r)))return[];let o=t[r],a=te(o,e.cwd,le(n)).path;if(a&&n.lineMade.includes(a)&&Qu(o,n,ed(e,o)))return[];let i=O.basename(o).replace(/\.[^.]+$/,""),l=t.slice(r+1),c=l.filter(f=>!f.startsWith("-")),u=["run","exec","task"].includes(c[0]??"")?c[1]:c[0];if(x$.test(i)&&!fi(i)&&!l.some(f=>/^--?(dry-?run|plan|help)$/i.test(f)))return[w("claude.bash.db.destructive",`runs ${O.basename(o)}, a script that drops or resets data`,{target:o,is_local:null})];let p=(b$.test(i)||w$.test(i))&&!fi(i),d=u!==void 0&&$f.test(u)&&!fi(i);return!p&&!d||l.some(f=>/^--?(dry-?run|plan|check|preview|diff|help|version|what-?if)$/i.test(f))?[]:[w("claude.bash.deploy",`runs ${O.basename(o)}${d?` ${u}`:""}, a script that deploys or releases`,{target:o,is_local:!1})]}var _f=/\.(db|sqlite|sqlite3|db3|log|csv|tsv|parquet|ndjson|jsonl|bak|dump)$/i;function Cu(e){let n=e.name==="printf"&&(e.argv[1]??"")===""&&e.argv.length<=2||e.name==="echo"&&e.argv.slice(1).every(t=>t===""||/^-[neE]+$/.test(t));return e.name===":"||e.name==="true"||n||e.name==="cat"&&e.argv[1]==="/dev/null"&&e.argv.length===2}function Au(e,n){let t=[];e.name==="truncate"&&e.argv.some((o,a)=>(o==="-s"||o==="--size")&&/^0+$/.test(e.argv[a+1]??"")||/^--size=0+$/.test(o)||o==="-s0")&&t.push(...e.argv.slice(1).filter((o,a,i)=>!o.startsWith("-")&&i[a-1]!=="-s"&&i[a-1]!=="--size")),e.name==="cp"&&e.argv[1]==="/dev/null"&&e.argv[2]&&t.push(e.argv[2]);let s=e.groupWriters!==null&&!e.groupWriters.every(Cu);if(Cu(e))for(let o of e.redirects)(o.op===">"||o.op===">|")&&o.target&&!(s&&/\.log$/i.test($(o.target)))&&t.push(o.target);e.redirects.forEach((o,a)=>{(o.op===">"||o.op===">|")&&(o.fd===null||o.fd===1)&&o.target&&e.redirects.slice(a+1).some(i=>i.fd===1||i.fd===null&&[">",">>",">|",">&"].includes(i.op))&&t.push(o.target)});let r=t.map(o=>({t:o,v:rt(o,e,n)})).find(({t:o,v:a})=>_f.test($(o))&&a.kind!=="disposable");return r?[w("claude.bash.fs.delete_recursive",`empties a data file (${O.basename($(r.t))})`,{target:r.v.path,is_local:!0})]:[]}import{createHash as mx}from"crypto";import{readFileSync as yx}from"fs";import{join as Zn}from"path";import{spawnSync as GC}from"child_process";import{createHash as tx}from"crypto";import{chmodSync as YC,existsSync as JC,lstatSync as nx,mkdirSync as XC,readdirSync as QC,readFileSync as eA,readlinkSync as sx,realpathSync as Tf,rmdirSync as tA,statSync as ca,unlinkSync as nA,writeFileSync as sA}from"fs";import{dirname as rx,isAbsolute as oA,join as iA,relative as aA,resolve as ox}from"path";var xt={on:"\u25CF",watching:"\u25CB",held:"\u25A0",ok:"\u2713",blocked:"\u2715",problem:"\u25B2",next:"\u203A"};function C$(e){if(!e){let l=c=>c;return{on:!1,bold:l,dim:l,blue:l,grey:l,amber:l,mark:l,field:l}}let n=e==="truecolor",t=l=>c=>`\x1B[${l}m${c}\x1B[0m`,s=t(n?"38;2;76;139;255":"38;5;69"),r=t(n?"38;2;130;134;150":"90"),o=t(n?"38;2;245;165;36":"38;5;214"),a=t(n?"38;2;34;197;94":"32"),i={[xt.on]:s,[xt.blocked]:s,[xt.held]:s,[xt.next]:s,[xt.watching]:r,[xt.problem]:o,[xt.ok]:a};return{on:!0,bold:t("1"),dim:t("2"),blue:s,grey:r,amber:o,mark:l=>(i[l]??(c=>c))(l),field:l=>`\x1B[${n?"48;2;24;2;166;38;2;255;255;255":"48;5;19;97"}m${E$(l)}\x1B[0m`}}var wS=C$(!1),A$=/\u001b\[[0-9;]*m|\u001b\][^\u0007]*\u0007/g;function E$(e){return e.replace(A$,"")}var Sf="claude.agent.controls";var Cf=[{id:"protect",verdict:"block",short:"wiping your home folder or the project",slugs:["protected"]},{id:"protect-main",verdict:"block",short:"force-pushing main",slugs:["protected"]},{id:"protect-processes",verdict:"block",short:"killing every process",slugs:["protected"]},{id:"keep-work",verdict:"hold",short:"throwing away uncommitted work",slugs:["uncommitted"]},{id:"stay-in-project",verdict:"hold",short:"deletes outside your project",slugs:["outside-folder"]},{id:"stay-out-of-prod",verdict:"hold",short:"changes aimed at production",slugs:["prod-changes"]},{id:"keep-anvil-on",verdict:"hold",short:"changes to Anvil",slugs:["agent-controls"]},{id:"stop-loops",verdict:"hold",short:"delete bursts and repeats",slugs:["delete-burst","repeat"]},{id:"stop-helper-bursts",verdict:"hold",short:"helper bursts",slugs:["helper-burst"]},{id:"keep-keys-in",verdict:"hold",short:"use of your account keys",slugs:["credentials","secrets-expose"]},{id:"keep-env-out",verdict:"hold",short:"showing secrets files in the chat",slugs:["env-in-chat"]},{id:"hold-unchecked",verdict:"hold",short:"actions it can't check",slugs:["could-not-check","too-long-to-check"]}],R$="home and project wipes and force-pushes to main",SS=`always blocking ${R$}`,CS=new Map(Cf.map(e=>[e.id,e]));var O$=new Set(Cf.flatMap(e=>e.slugs));var Af=new Set([Sf,"claude.bash.secrets.expose"]);var Ef=ae({"claude.bash.fs.delete_recursive":{slug:"delete",text:"recursive delete"},"claude.bash.fs.delete_disposable":{slug:"delete-temp",text:"delete of temp or build files"},"claude.bash.git.force_push":{slug:"force-push",text:"force-push"},"claude.bash.git.push_main":{slug:"push-main",text:"push or merge to main"},"claude.bash.git.discard":{slug:"discard",text:"throw away git work"},"claude.bash.db.destructive":{slug:"db-destroy",text:"destroy database data"},"claude.bash.deploy":{slug:"deploy",text:"deploy"},"claude.bash.publish":{slug:"publish",text:"publish a package or release"},"claude.bash.secrets.print":{slug:"secrets-print",text:"print secrets"},"claude.bash.privilege":{slug:"sudo",text:"run as root, or run code it cannot read"},"claude.bash.process.kill_by_name":{slug:"kill",text:"kill processes by name or port"},"claude.bash.external_write":{slug:"external-write",text:"write to an external API"},"claude.bash.spend":{slug:"spend",text:"start paid compute"},"claude.bash.secrets.expose":{slug:"secrets-expose",text:"commit or send a secrets file"},"claude.bash.net.expose":{slug:"net-expose",text:"open this machine to the internet"},"claude.bash.data.export":{slug:"data-export",text:"copy a remote database here"},"claude.bash.crypto.transaction":{slug:"crypto",text:"send a transaction on a real chain"},"claude.bash.persistence":{slug:"persistence",text:"install background jobs or global git hooks"},"claude.bash.deps.add":{slug:"new-dependency",text:"add a new dependency"},"claude.bash.prod.target":{slug:"production",text:"use a production account"},"claude.agent.controls":{slug:"agent-controls",text:"change its own permissions, hooks or rules"},"claude.agent.helper":{slug:"helper-agent",text:"launch a helper agent"},"claude.file.write_secret":{slug:"secret-file-write",text:"write a secrets file"},"claude.file.read_secret":{slug:"secret-file-read",text:"read a secrets file"},"claude.file.outside_project":{slug:"outside-project",text:"change files outside the project"},"claude.mcp.side_effect":{slug:"mcp-write",text:"MCP tool that changes something"},"claude.mcp.call":{slug:"mcp-read",text:"MCP tool call"},"claude.bash.unclassified":{slug:"other",text:"command"},"claude.tool.other":{slug:"tool",text:"tool call"}});function Rf(e){return Ef[e]?.text??e}var Of="\u{1F539}",jf=e=>`${Of} ${e} ${Of}`,j$=ae({"claude.bash.git.push_main":"pushes to main","claude.agent.controls":"its own settings","claude.bash.git.force_push":"force-pushes","claude.bash.fs.delete_recursive":"deletes","claude.bash.git.discard":"thrown-away work","claude.bash.db.destructive":"database wipes","claude.bash.deploy":"deploys","claude.bash.publish":"releases","claude.bash.secrets.print":"printed secrets","claude.bash.spend":"paid compute","claude.bash.external_write":"outside writes","claude.mcp.side_effect":"app changes"}),P$=e=>j$[e]??Rf(e),W$=P$;function N$(e,n){let t=[...[...e].sort((s,r)=>+(s==="claude.agent.controls")-+(r==="claude.agent.controls")).map(W$),...n?[n]:[]];return t.length<=2?t.join(" and "):`${t[0]}, ${t[1]} and ${t.length-2} more`}var Pf=e=>`
|
|
90
|
+
${xt.next} ${e}`;var L$=72;function la(e,n){let t=`To ${e}, run in a terminal: ${n}`;return t.length+5<=L$?Pf(t):`${Pf(`To ${e}, run in a terminal:`)}
|
|
91
|
+
${n}`}function T$(e,n,t,s,r=null,o=D$){if(t.length>0){let c=M$(t[0],s);return`${jf("Anvil on")} but ${c.said}${t.length>1?` (and ${t.length-1} more)`:""}${c.fix??la("see details",`${Be(s)} report`)}`}let a=la("add your own rules",`${Be(s)} rules edit`),i=`${jf("Anvil is on")} ${o}`;if(e.length>=n)return`${i} \xB7 holding every risky action for your OK${a}`;let l=e.filter(c=>!Af.has(c));return`${l.length>0||r?`${i} \xB7 holding ${N$(l,r)} for your OK`:i}${a}`}var D$="blocking unsafe actions automatically";var I$={protect:"blocks deleting the user's home folder, the disk, a system folder, the project or its .git","protect-main":"blocks force-pushing main or deleting it on the remote","protect-processes":"blocks killing every process or stopping the machine","keep-work":"holds throwing away uncommitted work (git reset --hard, discarding every change, git clean -f, dropping a stash)","stay-in-project":`holds deleting or moving files outside the project, its git worktrees and the folders the user added (temp folders and caches run); where it can't tell the folder, it holds a recursive or wildcard delete after a cd it can't follow (cd "$OUT" && rm -rf *) and a recursive wildcard delete under a variable (rm -rf "$OUT"/*); a delete of one path a variable names runs (rm -rf "$VAR")`,"stay-out-of-prod":"holds changes aimed at production (a production account, profile, context, env file, host or token)","keep-anvil-on":"holds any change to Anvil or to Claude Code's permissions, hooks and settings","stop-loops":"holds more than 20 recursive deletes in a minute and the same app change twice in 10 minutes","stop-helper-bursts":"holds more than 20 helper agent launches in 10 minutes in one session","keep-keys-in":"holds reading or writing the user's account key files (such as ~/.ssh/id_* and ~/.aws/credentials) and committing or sending a secrets file","keep-env-out":"holds showing a project's secrets file in the chat (a .env, a private key or credentials.json read, printed, or reached by a search or a list of files; using it, its names alone, a count or a hash run)","hold-unchecked":"holds a call it could not read in full or check in time"};function F$(e,n,t,s=null){return["Anvil (anvilcontrol.ai) checks every tool call in this session before it runs.",...e.length>0?[`From the first call, it ${e.map(r=>I$[r]).join("; it ")}.`]:[],...n.length>0?[`It also stops these when they come up: ${n.join("; ")}.`]:[],...s?[s]:[],...n.length===0?["It watches everything else: it records what it would have stopped, and lets it run."]:[],`When Anvil holds a call, nothing in that command runs until the user allows it, in Claude Code's prompt, in Anvil's pop-up (on a Mac), or with a one-time allow command they are shown. Tell the user what was held; once they allow it, run the same command again. \`${Be(t)} report\` shows what Anvil did; changing Anvil is the user's to do, in their own terminal, so do not run other \`${Be(t)}\` commands, edit ~/.anvil, or look for another way around a hold.`].join(" ")}function M$(e,n){let t=e.lastIndexOf(` run ${Be(n)} on`),s=t>0?e[t-1]:"";if(t<=0||s!==":"&&s!==";")return{said:e,fix:null};let r=e.slice(t+` run ${Be(n)} on`.length);return r!==""&&!/^ to [a-z][a-z ]*$/.test(r)?{said:e,fix:null}:{said:e.slice(0,t-1),fix:la("fix it",`${Be(n)} on`)}}import{createHash as bC}from"crypto";import{appendFileSync as kC,closeSync as G$,constants as Lf,fstatSync as Z$,mkdirSync as vC,openSync as K$,readdirSync as $C,readFileSync as Y$,readSync as J$,renameSync as xC,statSync as X$,unlinkSync as _C,writeFileSync as SC}from"fs";import{homedir as AC}from"os";import{dirname as RC,join as _t}from"path";var Wf,z$;function U$(){return z$??=import(new URL("claude-conditions.js",import.meta.url).href).then(e=>{Wf=typeof e.matchCondition=="function"&&typeof e.capMoved=="function"?e:void 0},()=>{})}async function Nf(e){return await U$(),Wf?.answerDeps?.(e)??null}import{createHash as JS}from"crypto";import{existsSync as QS,readdirSync as e1,statSync as t1}from"fs";import{dirname as s1,isAbsolute as r1,join as o1,posix as i1,resolve as a1}from"path";import{domainToASCII as m1}from"url";var _1="Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" ");import{existsSync as M1,readdirSync as z1,realpathSync as U1}from"fs";import{basename as H1,dirname as B1,join as V1}from"path";function no(e){return{dir:e,bin:_t(e,"bin"),compiled:_t(e,"compiled.json"),modes:_t(e,"modes.json"),decisions:_t(e,"decisions.jsonl"),install:_t(e,"install.json"),state:_t(e,"state"),approvals:_t(e,"approvals"),counts:_t(e,"counts"),backups:_t(e,"backups")}}function St(e,n=8*1024*1024){try{let t=X$(e);return t.isFile()&&t.size<=n}catch(t){return t.code==="ENOENT"?null:!1}}function ot(e,n=8*1024*1024){let t;try{t=K$(e,Lf.O_RDONLY|Lf.O_NONBLOCK)}catch(s){if(s.code==="ENOENT"||s.code==="ENOTDIR")return null;throw s}try{let s=Z$(t);if(!s.isFile())throw new Error(`${e} is not a regular file`);if(s.size>n)throw new Error(`${e} is over ${n} bytes`);let r=Buffer.alloc(s.size),o=0;for(;o<s.size;){let a=J$(t,r,o,s.size-o,o);if(a===0)break;o+=a}return r.subarray(0,o)}finally{G$(t)}}function Ts(e){if(St(e)!==!0)return null;try{return JSON.parse(Y$(e,"utf8"))}catch{return null}}var jC=256*1024,PC=1024*1024;var ix="/.anvil/claude/bin/claude-hook.js",ax=/[\\/]\.anvil[\\/]claude[\\/]bin[\\/]claude-hook\.js/i;var Gn=class extends Error{constructor(n){super(n),this.name="SettingsRefused"}};function Df(e){return`// anvil-claude-hook ${tx("sha256").update(e).digest("hex").slice(0,16)}`}function ua(e,n){let t=e.startsWith("\uFEFF")?e.slice(1):e;if(t.trim()==="")return{};let s;try{s=JSON.parse(t)}catch(r){throw new Gn(`${n} is not valid JSON (${r instanceof Error?r.message:String(r)}). Anvil changed nothing; fix the file and run this again.`)}if(!s||typeof s!="object"||Array.isArray(s))throw new Gn(`${n} is not a JSON object. Anvil changed nothing.`);return s}function lx(e){if(!e||typeof e!="object")return null;let{command:n,args:t}=e;return typeof n!="string"?null:Array.isArray(t)?[n,...t.filter(s=>typeof s=="string")].join(" "):n}var cx=e=>{let n=lx(e);return n!==null&&(n.includes(ix)||ax.test(n))};function ux(e){return ot(e,64*1024*1024)}function dx(e){try{if(!nx(e).isSymbolicLink())return e}catch{return e}try{return Tf(e)}catch(n){let t=n.code;throw t==="ENOENT"?new Gn(`${e} is a link to ${fx(e)}, which does not exist. Anvil changed nothing; create that file or remove the link, and run this again.`):new Gn(`${e} is a link Anvil cannot follow (${t??String(n)}). Anvil changed nothing.`)}}function fx(e){let n=rx(e);try{n=Tf(n)}catch{}return ox(n,sx(e))}function If(e){try{let n=dx(e),t=ca(n);if(!t.isFile()||t.size>4*1024*1024)return!1;let s=ux(n);if(s===null)return!1;let r=ua(s.toString("utf8"),e).hooks?.PreToolUse;return Array.isArray(r)&&r.some(o=>{let a=o&&typeof o=="object"?o:null,i=a?.matcher;return(i===void 0||i===""||i==="*")&&Array.isArray(a?.hooks)&&a.hooks.some(l=>cx(l)&&gx(l))})}catch{return!1}}function px(e){let n=e.trim().match(/'(?:[^']|'\\'')*'|[^\s']+/g),t=o=>o.startsWith("'")?o.slice(1,-1).replace(/'\\''/g,"'"):o,s=n?n.findIndex(o=>o==="/bin/sh"||o==="sh"):-1,r=n&&s>=0&&(n[s+3]==="PreToolUse"||n[s+3]==="SessionStart")?/^\d{2,3}$/.test(n[s+4]??"")?2:1:0;if(n&&s>=0&&n[s+3+r]==="||"){let o=s>0&&s%5===0;for(let a=0;o&&a<s;a+=5)o=n[a]==="["&&(n[a+1]==="-s"||n[a+1]==="-f")&&n[a+3]==="]"&&n[a+4]==="&&"&&t(n[a+2])===t(n[s+1]);if(s===0||o)return[t(n[s+1]),t(n[s+2])]}return!n||n.length!==2?null:[t(n[0]),t(n[1])]}function hx(e){if(!e||typeof e!="object")return null;let{command:n,args:t}=e;if(typeof n!="string")return null;if(Array.isArray(t)){let s=t.find(r=>typeof r=="string"&&/[\\/]\.anvil[\\/]claude[\\/]bin[\\/]claude-hook\.js$/i.test(r));return s?[n,s]:null}return px(n)}function gx(e){let n=hx(e);if(!n)return!1;try{return ca(n[0]).isFile()&&ca(n[1]).isFile()}catch{return!1}}var bx=["claude-hook-core.js","claude-sync.js","claude-hook.js","claude-meter.js","claude-helpers.js","claude-conditions.js","claude-approve.js",...process.platform==="darwin"?["Anvil"]:[]],wx=process.platform==="darwin"?"/Library/Application Support/ClaudeCode/managed-settings.json":process.platform==="win32"?`${process.env.ProgramFiles||"C:\\Program Files"}\\ClaudeCode\\managed-settings.json`:"/etc/claude-code/managed-settings.json";function kx(e,n=wx){let t=[],s=l=>l.startsWith(`${e.home}/`)?`~${l.slice(e.home.length)}`:l;for(let l of[n,...e.files])try{St(l,4*1024*1024)===!0&&ua(yx(l,"utf8"),l).disableAllHooks===!0&&t.push(`hooks are off for new sessions ("disableAllHooks") in
|
|
84
92
|
${(s(l).match(/.{1,63}(?:\/|$)|.{64}/g)??[l]).join(`
|
|
85
|
-
`)}`)}catch{}e.files.some(l=>
|
|
86
|
-
`,1)[0]}catch{}let a=
|
|
87
|
-
`)
|
|
88
|
-
|
|
89
|
-
end run`,e,t,n],{detached:!0,stdio:"ignore"}).unref()}function kk(e,t=wk){try{let n=e.env;if((e.platform??process.platform)!=="darwin"||!n.CLAUDE_CODE_ENTRYPOINT||n.CI||n.VITEST||n.ANVIL_NO_NOTIFY||!e.transcript||!yk(e.transcript).isFile())return;let s=Zu(e.anvilDir,"state");ti(s);let r=Zu(s,`notice-${(e.session??"none").replace(/[^\w-]/g,"_").slice(0,80)}`),o=Number(Fu(r,64).trim());if(Number.isFinite(o)&&e.now-o<bk)return;zu(r,String(e.now)),t(`${cr("Anvil")} needs your OK`,`Held: ${e.why}`,`Allow once: run ${Se(e.cli)} allow in a terminal.`)}catch{}}import{createHash as _S,randomBytes as SS}from"crypto";import{readdirSync as Ak,renameSync as AS,unlinkSync as Ek}from"fs";import{join as Xu}from"path";import{createHmac as vk,randomBytes as eS,timingSafeEqual as $k}from"crypto";import{closeSync as nS,existsSync as sS,fsyncSync as rS,linkSync as oS,mkdirSync as iS,openSync as aS,readdirSync as lS,readFileSync as Gu,unlinkSync as cS,writeSync as uS}from"fs";import{basename as fS,dirname as pS,join as xk}from"path";var es="_seal";function _k(e){return xk(e.dir,"seal.key")}function Ku(e){let t=_k(e);if(Ke(t,1024)!==!0)return null;try{let n=Gu(t,"utf8").trim();return/^[0-9a-f]{64}$/.test(n)?Buffer.from(n,"hex"):null}catch{return null}}function ai(e,t=0){if(t>64)throw new Error("nested too deep to seal");return Array.isArray(e)?`[${e.map(n=>ai(n===void 0?null:n,t+1)).join(",")}]`:e&&typeof e=="object"?`{${Object.keys(e).filter(s=>!(t===0&&s===es)&&e[s]!==void 0).sort().map(s=>`${JSON.stringify(s)}:${ai(e[s],t+1)}`).join(",")}}`:JSON.stringify(e??null)}function Sk(e,t){return vk("sha256",e).update(ai(t)).digest("hex")}function ii(e){if(!(es in e))return e;let t={...e};return delete t[es],t}function Ck(e,t){let n=t[es];if(typeof n!="string"||!/^[0-9a-f]{64}$/.test(n))return!1;let s;try{s=Sk(e,t)}catch{return!1}return $k(Buffer.from(n,"hex"),Buffer.from(s,"hex"))}function Yu(e,t,n=8*1024*1024){let s=Ke(e,n);if(s===null)return{status:"missing"};if(s===!1)return{status:"unreadable"};let r;try{r=JSON.parse(Gu(e,"utf8"))}catch{return{status:"unreadable"}}return!r||typeof r!="object"||Array.isArray(r)?{status:"unreadable"}:t?es in r?Ck(t,r)?{status:"ok",value:ii(r)}:{status:"changed",value:ii(r)}:{status:"unsealed",value:r}:{status:"unkeyed",value:ii(r)}}var jS=600*1e3,PS=1440*60*1e3;function Ju(e){return Xu(e.state,"pending")}function Rk(e,t,n,s,r,o,a){let i=0;for(let{hold:l,file:c}of Pk(e,t,o))if(!(c===a||(l.session??null)!==(n??null)||(l.project??null)!==(s??null)||l.stops.length===0)&&l.stops.every(u=>r.some(f=>jk(f,u))))try{Ek(c),i++}catch{}return i}function Ok(e){let t=ur(e.anvilDir);Rk(t,Ku(t),e.session,e.project,e.stops,e.now)}function jk(e,t){return e.kind===t.kind&&(e.target??null)===(t.target??null)}function Pk(e,t,n){let s=[];try{s=Ak(Ju(e)).filter(o=>o.endsWith(".json")).slice(0,2e3)}catch{return[]}let r=[];for(let o of s){let a=Xu(Ju(e),o),i=Yu(a,t,64*1024);i.status!=="ok"||i.value.v!==2||!Array.isArray(i.value.stops)||!(Date.parse(i.value.expires_at)>=n)||r.push({hold:i.value,file:a})}return r.sort((o,a)=>Date.parse(a.hold.created_at)-Date.parse(o.hold.created_at))}function ci(){return{touched:{full:new Set,parent:new Set},read:new Set,written:new Set,unknown:new Set}}function td(e){return{full:[...e.touched?.full??[]],parent:[...e.touched?.parent??[]],read:[...e.read??[]],written:[...e.written??[]],unknown:[...e.unknown??[]]}}function Nk(e){if(!e||typeof e!="object")return null;let t=e;for(let n of["file_path","notebook_path","path"])if(typeof t[n]=="string")return t[n];return null}var Lk=/(?:^|[^\w.-])(?:git|gh|patch|tar|bsdtar|gtar|unzip)(?![\w.-])/,Tk=/^(add|annotate|archive|bisect|blame|branch|bundle|cat-file|check-[\w-]+|clean|clone|commit|config|count-objects|describe|diff(-\w+)?|fetch|filter-branch|for-each-ref|format-patch|fsck|gc|grep|hash-object|help|init|log|ls-\w+|maintenance|merge-\w+|mk\w+|mv|name-rev|notes|prune|push|range-diff|reflog|remote|repack|replace|rerere|rev-\w+|rm|shortlog|show(-\w+)?|sparse-checkout|status|submodule|symbolic-ref|tag|update-[\w-]+|var|verify-\w+|version|whatchanged|worktree|\w+-tree)$/,Ik=/^(?!-)[^\0-\x20:?*[\\\x7f]+$/,li=/^(?:\.\/?|\*|:\/|:\(top\))$/;function Qu(e){let t=e.toLowerCase().split("/");return t[t.length-1]===".mcp.json"||t.some(n=>n===".claude"||n===".anvil")}var vn=e=>typeof e=="string"&&e.startsWith("/")&&!S(e),ve=e=>({what:e,ask:null,base:null,shown:null}),hr=(e,t)=>{let n=e.replace(/[\u0000-\u0008\u000b-\u001f\u007f]/g,"");return n.length>t?`${n.slice(0,t-3)}\u2026`:n};function ns(e,t,n){if(e===""||S(e)||!e.startsWith("/")&&!e.startsWith("~")&&!vn(t))return null;let s=M(e,t,{home:n});return vn(s)?s:null}function me(e,t,n,s,r=[]){return!vn(s)||S(n)||!Ik.test(n)||r.some(o=>S(o)||!/^(?!-)[^\0-\x1f]+$/.test(o))?ve(e):{what:e,ask:{probe:{kind:"changes",arg:[`${t} ${n}`,...r].join(" "),cwd:s}},base:s,shown:null}}function di(e,t,n,s,r,o,a,i={}){let l=ns(n,s,a),c=r===null?vn(o)?o:null:ns(r,o,a);return l===null||c===null||/[\u0000-\u001f]/.test(l)?ve(e):{what:e,ask:{probe:{kind:"changes",arg:`${t} ${l}`,cwd:null}},base:c,shown:r===null?null:k(r),...i}}function nd(e){if(e.stdinKind)return;if(e.stdinFile)return e.stdinFile;let t=e.pipeFrom;if(!t)return;let n=t.argv.slice(1).filter(s=>!s.startsWith("-"));return t.name==="cat"&&n.length===1?n[0]:null}function De(e,t,n=[]){let s=[],r=new Map,o=!1;for(let a=0;a<e.length;a++){let i=e[a];if(o)s.push(i);else if(i==="--")o=!0;else if(i.startsWith("--")){let l=i.indexOf("=");r.set(l>0?i.slice(0,l):i,l>0?i.slice(l+1):n.includes(i)?e[++a]??"":"")}else if(i.startsWith("-")&&i.length>1)for(let l=1;l<i.length;l++){let c=i[l];if(t.includes(c)){r.set(`-${c}`,l+1<i.length?i.slice(l+1):e[++a]??"");break}r.set(`-${c}`,"")}else s.push(i)}return{pos:s,opt:r,dashdash:o}}var Fe=(e,t)=>t.some(n=>e.opt.has(n)),ts=e=>e==="-"?"@{-1}":e;function ui(e,t,n,s,r,o,a,i){if(!/^\d{1,2}$/.test(s))return[ve(t)];let l=`p${Number(s)}`,c=(u,f)=>di(`${t} ${Et.basename(k(u))}`,l,u,f,o,a,i);return(n.length>0?n:["-"]).flatMap(u=>{if(u!=="-")return[c(u,r)];let f=nd(e);return f===void 0?[]:f===null?[ve(t)]:[c(f,a)]})}function sd(e,t,n,s){let r=e.argv,o=t,a=/\bGIT_(?:DIR|WORK_TREE|INDEX_FILE|COMMON_DIR)=/.test(e.text),i=1;for(;i<r.length;i++){let p=r[i];if(p==="-C")o=ns(r[++i]??"",o,n);else if(p==="-c"||p==="--namespace"||p==="--config-env")i++;else if(p==="--git-dir"||p==="--work-tree")a=!0,i++;else if(/^--(git-dir|work-tree)=/.test(p))a=!0;else if(!p.startsWith("-"))break}let l=r[i]??"",c=r.slice(i+1);if(c.includes("--help")||c.includes("-h"))return[];let u=(...p)=>["git",l,...p].map(k).join(" "),f=(()=>{switch(l){case"checkout":{let d=De(c,"bB",["--orphan","--conflict","--pathspec-from-file"]);if(d.pos.some($=>li.test($)))return[d.pos.length>1&&!li.test(d.pos[0])?me(u(...d.pos),"wt",d.pos[0],o):me(u(...d.pos),"wi","HEAD",o)];if(Fe(d,["-p","--patch","--pathspec-from-file"]))return[];let h=c.indexOf("--"),g=h>=0?c.slice(h+1):d.pos.slice(1);if(g.length>0&&(h<0||d.pos.length>g.length))return[me(u(...d.pos),"wt",d.pos[0],o,g)];if(d.dashdash)return[];let y=Fe(d,["-b","-B","--orphan"])||d.pos.length===1?d.pos[0]:void 0;return Fe(d,["-f","--force"])?[me(u("-f",...d.pos),"wt",y??"HEAD",o)]:y===void 0?[]:[me(u(y),"co",ts(y),o)]}case"switch":{let d=De(c,"cC",["--create","--force-create","--orphan","--conflict"]);if(d.opt.has("--orphan"))return[ve(u("--orphan"))];let h=d.pos[0];return Fe(d,["-f","--force","--discard-changes"])?[me(u("-f",...d.pos),"wt",h??"HEAD",o)]:h===void 0?[]:[me(u(h),"co",ts(h),o)]}case"restore":{let d=De(c,"s",["--source","--pathspec-from-file","--conflict"]);if(d.pos.length===0||Fe(d,["-S","--staged"])&&!Fe(d,["-W","--worktree"]))return[];let h=d.opt.get("-s")??d.opt.get("--source"),g=d.pos.some(y=>li.test(y))?[]:[...d.pos];return[h?me(u(...d.pos),"wt",h,o,g):me(u(...d.pos),"wi","HEAD",o,g)]}case"reset":{let d=De(c,"",["--pathspec-from-file"]),h=["--hard","--keep","--merge"].find(y=>d.opt.has(y)),g=d.pos[0]??"HEAD";return h===void 0||d.dashdash||d.pos.length>1?[]:[me(u(h,...d.pos),"wt",g,o)]}case"merge":{let d=De(c,"mFsX",["--message","--file","--strategy","--strategy-option","--into-name","--cleanup"]);return Fe(d,["--abort","--continue","--quit"])?[]:d.pos.length>0?d.pos.map(h=>me(u(h),"merge",ts(h),o)):[me(u(),"merge","@{u}",o)]}case"rebase":{let d=De(c,"sXxC",["--onto","--exec","--strategy","--strategy-option","--empty","--whitespace"]);if(Fe(d,["--continue","--abort","--skip","--quit","--edit-todo","--show-current-patch"]))return[];let h=d.pos[0]??(d.opt.has("--root")?void 0:"@{u}"),g=d.pos[1]!==void 0?[me(u(...d.pos),"co",d.pos[1],o)]:[];for(let y of[d.opt.get("--onto"),h])y&&g.push(me(u(...d.pos),"co",ts(y),o));return g}case"pull":{let d=De(c,"sXjo",["--strategy","--strategy-option","--depth","--deepen","--shallow-since","--shallow-exclude","--jobs","--upload-pack","--server-option","--negotiation-tip"]),[h,...g]=d.pos;return(h!==void 0&&g.length>0?g.map($=>`${h}/${$.replace(/^\+/,"").split(":")[0].replace(/^refs\/heads\//,"")}`):["@{u}"]).map($=>me(u(...d.pos),"pull",$,o))}case"cherry-pick":case"revert":{let d=De(c,"mX",["--mainline","--strategy","--strategy-option","--cleanup"]);return Fe(d,["--continue","--abort","--skip","--quit"])?[]:d.opt.has("--stdin")?[ve(u("--stdin"))]:d.pos.map(h=>h.includes("..")||h.startsWith("^")?ve(u(h)):me(u(h),"pick",ts(h),o))}case"stash":{let[d="",...h]=c;if(d!=="pop"&&d!=="apply"&&d!=="branch")return[];let g=De(h,""),y=d==="branch"?g.pos[1]:g.pos[0],$=y===void 0?"stash@{0}":/^\d+$/.test(y)?`stash@{${y}}`:y,E=u(d,...g.pos);return d==="branch"?[me(E,"stash",$,o),me(E,"co",`${$}^1`,o)]:[me(E,"stash",$,o)]}case"apply":{let d=De(c,"pC",["--directory","--include","--exclude","--whitespace","--build-fake-ancestor"]);return Fe(d,["--check","--stat","--numstat","--summary"])&&!d.opt.has("--apply")||d.opt.has("--cached")&&!d.opt.has("--index")?[]:ui(e,"git apply",d.pos,d.opt.get("-p")??"1",o,d.opt.get("--directory")??null,o,n)}case"am":{let d=De(c,"pC",["--directory","--include","--exclude","--whitespace","--patch-format","--resolvemsg","--quoted-cr","--empty"]);return Fe(d,["--continue","--skip","--abort","--quit","--resolved","-r","--show-current-patch","--retry"])?[]:ui(e,"git am",d.pos,d.opt.get("-p")??"1",o,d.opt.get("--directory")??null,o,n)}}if(!s||!/^[a-z][\w-]*$/.test(l)||Tk.test(l))return[];let p=s(l,o);return p===void 0||p===At?[]:p===null||/^\s*!|['"\\]/.test(p)?[ve(u())]:sd({...e,argv:["git",...p.trim().split(/\s+/),...c]},o,n)})();return a?f.map(p=>ve(p.what)):f}function Dk(e,t,n){let s=De(e.argv.slice(1),"BDFgiopVxYzdr",["--prefix","--ifdef","--fuzz","--get","--input","--output","--strip","--reject-file","--version-control","--debug","--basename-prefix","--suffix","--directory","--quoting-style","--reject-format","--read-only"]);if(Fe(s,["--dry-run","--check","-C"]))return[];let r=s.opt.get("-d")??s.opt.get("--directory")??null,o=r===null?vn(t)?t:null:ns(r,t,n),[a,i]=s.pos,c=s.opt.get("-o")??s.opt.get("--output")??a;if(c!==void 0){if(c==="-")return[];let f=ns(c,o,n);return[f===null?ve("patch"):{what:`patch ${Et.basename(k(c))}`,ask:{files:[f]},base:null,shown:null}]}let u=s.opt.get("-i")??s.opt.get("--input")??i;return ui(e,"patch",u===void 0?[]:[u],s.opt.get("-p")??s.opt.get("--strip")??"0",o,r,t,n)}function Fk(e,t,n){let s=e.argv.slice(1),r,o=null,a="";for(let l=0;l<s.length;l++){let c=s[l];if(!c.startsWith("-")||c.length===1){r??=c;continue}for(let u=1;u<c.length;u++){let f=c[u];if(f==="d"||f==="P"){let p=u+1<c.length?c.slice(u+1):s[++l]??"";f==="d"&&(o=p);break}if(f==="x"){for(;l+1<s.length&&!s[l+1].startsWith("-");)l++;break}a+=f}}if(r===void 0||/[lvtZpcz]/.test(a))return[];if(/[*?[]/.test(k(r)))return[ve(`unzip ${k(r)}`)];let i=`unzip ${Et.basename(k(r))}`;return(/\.zip$/i.test(r)?[r]:[r,`${r}.zip`]).map(l=>di(i,"zip",l,t,o,t,n,{flat:a.includes("j")}))}var zk=["fCTXbgNKVIHFL","fCTXbsI"],Mk=new Set(["--file","--directory","--exclude","--files-from","--exclude-from","--transform","--xform","--use-compress-program","--owner","--group","--mode","--mtime","--newer","--newer-mtime","--format","--strip-components","--to-command","--suffix","--occurrence","--sort","--include","--options","--uid","--gid","--passphrase"]);function Uk(e,t,n){let s=e.argv.slice(1),r=[];for(let o of zk){let a={extract:!1,toStdout:!1,renames:!1,file:void 0,dest:null},i=(u,f)=>{u==="x"||u==="--extract"||u==="--get"?a.extract=!0:u==="O"||u==="--to-stdout"||u==="--to-command"?a.toStdout=!0:u==="f"||u==="--file"?a.file=f:u==="C"||u==="--directory"?a.dest=f:(u==="s"&&o.includes("s")||u==="--transform"||u==="--xform")&&(a.renames=!0)},l=0;if(s[0]&&/^[A-Za-z]+$/.test(s[0])){l=1;for(let u of s[0])i(u,o.includes(u)?s[l++]??"":"")}for(;l<s.length;l++){let u=s[l];if(u==="--")break;if(u.startsWith("--")){let f=u.indexOf("="),p=f>0?u.slice(0,f):u;i(p,f>0?u.slice(f+1):Mk.has(p)?s[++l]??"":"")}else if(u.startsWith("-")&&u.length>1)for(let f=1;f<u.length;f++){let p=u[f];if(o.includes(p)){i(p,f+1<u.length?u.slice(f+1):s[++l]??"");break}i(p,"")}}if(!a.extract||a.toStdout)continue;if(a.renames){r.push(ve("tar -x"));continue}let c=a.file===void 0||a.file==="-"?nd(e):a.file;c!==void 0&&r.push(c===null?ve("tar -x"):di(`tar -xf ${Et.basename(k(c))}`,"tar",c,t,a.dest,t,n))}return r}function qk(e,t,n,s){switch(e.name){case"git":return sd(e,t,n,s);case"gh":return/^(pr (checkout|co)|co)\b/.test(e.argv.slice(1,3).join(" "))?[ve("gh pr checkout")]:[];case"patch":return Dk(e,t,n);case"unzip":return Fk(e,t,n);case"tar":case"bsdtar":case"gtar":return Uk(e,t,n)}return[]}function Hk(e,t){for(let n of t){let s=n.replace(/\\/g,"/");if(s===""||s.endsWith("/"))continue;let r=e.flat?Et.basename(s):s,a=[...r.startsWith("/")?[r]:[],e.base?Et.join(e.base,r):Et.normalize(r)].find(Qu);if(a===void 0)continue;let i=e.shown?Et.join(e.shown,r):r,l=hr(Qu(i)?i:a,200);return{why:hr(`${e.what} brings in a change to ${l}`,300),target:l,sure:!0}}return null}function Bk(e,t,n){let s=_e(t.home),r=typeof t.cwd=="string"&&t.cwd.startsWith("/")?_e(t.cwd):t.cwd,o=typeof t.project_dir=="string"&&t.project_dir.startsWith("/")?_e(t.project_dir):t.project_dir,a=t.session_facts??null,i=dt(e,{home:s,tmpdir:_e(t.tmpdir),cwd:r,projectDir:o,claudeConfigDir:t.claude_config_dir??null,knownFiles:a?.scripts??null,unreadableFiles:a?.unreadableScripts??null}),l=a?.probed,c=[],u=new Set,f=new Set(i.commands.flatMap(d=>d.name==="git"?d.argv.flatMap(h=>/^alias\.(.+)$/.exec(h)?.[1]??[]):[])),p=(d,h)=>{if(!vn(h))return null;let g={kind:"changes",arg:`al ${d}`,cwd:h},y=Wn(g);if(!l||!(y in l))return void n.set(y,g);let $=l[y];return typeof $=="string"&&$!==fr?$:null};return i.commands.forEach((d,h)=>{if(d.via==="remote"||d.functionCall)return;let g=i.commands.slice(0,h).some($=>!["cd","pushd","export","set","true",":"].includes($.name)),y=d.name==="git"&&d.argv[1]==="stash"&&/^(pop|apply)$/.test(d.argv[2]??"")&&d.argv.length===3&&i.commands.slice(0,h).some($=>$.name==="git"&&$.argv[1]==="stash"&&!/^(pop|apply|drop|list|show|clear|branch)$/.test($.argv[2]??""));for(let $ of[...new Set([d.cwd,...d.cwdFallbacks])]){let E=d.name==="git"&&f.has(d.argv[1]??"")?[ve(`git ${k(d.argv[1])}`)]:qk(d,$,s,p);for(let x of d.via==="xargs"?E.map(b=>ve(b.what)):E){let b,j=!1;if(x.ask===null)b=null;else if("files"in x.ask)b=x.ask.files;else{let A=Wn(x.ask.probe);if(!l||!(A in l)){n.set(A,x.ask.probe);continue}let U=l[A];if(U===At&&(!g||y))continue;j=U===fr,b=typeof U=="string"&&!j&&U!==At?U.split(/[\0\n]/):null}let C=b===null?{why:hr(j?`couldn't check in time which files ${x.what} would change`:`can't tell which files ${x.what} would change`,300),target:hr(x.what,200),sure:!1}:Hk(x,b);C&&!u.has(C.why)&&(u.add(C.why),c.push(C))}}}),c.sort((d,h)=>Number(h.sure)-Number(d.sure))}function Vk(e,t){let{housekeeping:n,findings:s,...r}=e,o=e.action!=="claude.bash.unclassified"&&e.action!=="claude.tool.other",a=t[0],i=[...new Set([...o?[e.action]:[],...e.also])].filter($=>$!=="claude.agent.controls"),{environment:l,environment_said:c,repo_dir:u,repo_remote:f,repo_via:p,...d}=e.attributes,h={...l!==void 0?{environment:l,environment_said:c??null}:{},...p!==void 0?{repo_dir:u??null,repo_remote:f??null,repo_via:p}:{}},g=e.findings??(o?[{action:e.action,service:e.service,target:e.attributes.target,why:e.why,...h}]:[]),y=[...t.map($=>({action:"claude.agent.controls",service:null,target:$.target,why:$.why})),...g].slice(0,16);return{...r,action:"claude.agent.controls",service:null,attributes:{...d,target:a.target,branch:null,host:null,is_local:!0},why:a.why,also:i,...y.length>1?{findings:y}:{}}}function Zk(e){let t=a=>typeof a=="string"&&a!==""?Ne(a):a??null,n=e.control_links?Object.fromEntries(Object.entries(e.control_links).map(([a,i])=>[Ne(a),Ne(i)])):e.control_links,s=e.session_facts?.repoRemotes,r=e.tool_input&&typeof e.tool_input=="object"?e.tool_input:null,o=r?["file_path","notebook_path"].find(a=>typeof r[a]=="string"):void 0;return{...e,...r&&o?{tool_input:{...r,[o]:We(r[o])??r[o]}}:{},cwd:t(e.cwd),project_dir:t(e.project_dir),home:Ne(e.home),tmpdir:Ne(e.tmpdir),...e.claude_config_dir!==void 0?{claude_config_dir:t(e.claude_config_dir)}:{},...e.project_controls?{project_controls:e.project_controls.map(a=>({...a,path:Ne(a.path)}))}:{},...n!==void 0?{control_links:n}:{},...e.session_facts&&s?{session_facts:{...e.session_facts,repoRemotes:Object.fromEntries(Object.entries(s).map(([a,i])=>[Ne(a),i]))}}:{}}}function Gk(e){let t=e.tool_input&&typeof e.tool_input=="object"?e.tool_input:null;if(e.tool_name!=="PowerShell"||typeof t?.command!="string")return e;let n=Vt(t.command,{cwd:e.cwd!==null?Je(e.cwd):null});return n.kind==="shell"?{...e,tool_name:"Bash",tool_input:{...t,command:n.text}}:e}function Kk(e){let t=Gk(V()?Zk(e):e),n=t.tool_input&&typeof t.tool_input=="object"?t.tool_input:{},s=(t.tool_name==="Bash"||t.tool_name==="PowerShell")&&typeof n.command=="string"?n.command:null,r=t.on_disk==="collect"?ci():t.on_disk?{real:t.on_disk,...ci()}:null,o=t.tool_name==="Bash"?new Set:null,a=t.tool_name==="Bash"?new Map:null,i=mn({tool:t.tool_name,command:s,target:t.tool_name==="Bash"?null:Nk(n),args:t.tool_input,cwd:t.cwd,git_branch:t.git_branch,project_dir:t.project_dir,session_id:t.session_id},{home:t.home,tmpdir:t.tmpdir,claudeConfigDir:t.claude_config_dir??null,onDisk:r,projectControls:t.project_controls??null,controlLinks:t.control_links??null,session:t.session_facts??null,wantScripts:o,wantProbes:a}),l=new Map,c=$=>Lk.test($.replace(/['"\\]/g,"")),u=s!==null&&i.action!=="claude.agent.controls"&&(c(s)||Object.values(t.session_facts?.scripts??{}).some(c))?Bk(s,t,l):[];u.length>0&&l.clear();let f=u.length>0?Vk(i,u):i,p=r?.touched?{...f,touched:td(r)}:f,d=o&&o.size>0?{...p,scriptsWanted:[...o].slice(0,8)}:p,h=[...l.values(),...a?.values()??[]],g=h.length>0?{...d,probesWanted:h.slice(0,12)}:d;if(!t.want_makings)return g;let y={paths:[],launched:[]};try{y=ka(t.tool_name,t.tool_input,t.cwd,{home:t.home,tmpdir:t.tmpdir,projectDir:t.project_dir})}catch{}return{...g,makings:y}}var Yk=1e3,Jk=new Wk.Script("globalThis.__anvilReplayClassify()");function Xk(e,t){let n=globalThis;n.__anvilReplayClassify=e;try{return Jk.runInThisContext({timeout:t})}catch(s){if(s.code==="ERR_SCRIPT_EXECUTION_TIMEOUT")return"timeout";throw s}finally{delete n.__anvilReplayClassify}}function Qk(e,t){return e.map(n=>{try{let s=ci(),r=Xk(()=>Jl(n.command_judge!==void 0?{...n,command_local:n.command_judge}:n,{...t,...n.session_facts?{session:n.session_facts}:{},onDisk:s}),Yk);if(r==="timeout")return{action:"claude.bash.unclassified",also:[],service:null,attributes:{target:null,branch:null,host:null,is_local:null,args_hash:null},parse:"limited",why:"too long to check in time"};let o=r,a=n.command_judge_cut===!0?"limited":o.parse,i=[s.touched?.full,s.touched?.parent,s.read,s.written,s.unknown].some(l=>(l?.size??0)>0);return{action:o.action,also:o.also,service:o.service,attributes:o.attributes,parse:a,why:o.why,...o.findings?{findings:o.findings}:{},...o.catastrophic?{catastrophic:!0}:{},...i?{touched:td(s)}:{}}}catch{return{action:"claude.bash.unclassified",also:[],service:null,attributes:{target:null,branch:null,host:null,is_local:null,args_hash:null},parse:"limited",why:"the classifier failed on it"}}})}if(!ed&&pr&&kn&&kn.anvilReplayPool===!0){let e=pr,t=kn.ctx;e.on("message",n=>{try{e.postMessage({id:n.id,ok:!0,results:Qk(n.calls,t)})}catch(s){e.postMessage({id:n.id,ok:!1,error:s instanceof Error?s.message:String(s)})}})}if(!ed&&pr&&kn&&kn.anvilClaudeHook===!0){let e=pr;try{e.postMessage({ok:!0,classification:Kk(kn.request)})}catch(t){e.postMessage({ok:!1,error:t instanceof Error?t.message:String(t)})}}export{Yk as REPLAY_CALL_LIMIT_MS,gk as answerChanges,Qk as classifyLogged,Kk as classifyRequest,kk as heldNotice,Ok as mootHolds,sk as sessionChores,vw as sessionContext,ww as sessionLine,Xw as startProblems};
|
|
93
|
+
`)}`)}catch{}e.files.some(l=>If(l))||t.push(`no settings file this session reads puts Anvil's check in front of tool calls, so they are not checked: run ${Be(e.cli)} on`);let r=Ts(Zn(e.anvilDir,"install.json")),o;try{o=ot(Zn(e.anvilDir,"bin","claude-hook.js"),4*1024*1024)?.toString().split(`
|
|
94
|
+
`,1)[0]}catch{}let a=Ts(Zn(e.anvilDir,"bin","files.json")),i=a?.v===1&&a.source&&typeof a.source=="object"?a.source:null;for(let l of Array.isArray(r?.package_dirs)?r.package_dirs:[])try{let c=typeof l=="string"?ot(Zn(l,"dist","claude-hook.js"),4194304):null,u=Ts(Zn(l,"package.json"))?.version,p=typeof u=="string"&&typeof r?.hook_version=="string"&&u.localeCompare(r.hook_version,void 0,{numeric:!0})<0,d=h=>{let g=ot(Zn(l,"dist",h),67108864);return g?mx("sha256").update(g).digest("hex"):void 0},f=i?bx.some(h=>d(h)!==i[h]):!!o&&Df(c?.toString()??"")!==o;if(c&&!p&&f){t.push(`its hook is older than the ${typeof u=="string"?`${u} `:""}update: run ${Be(e.cli)} on`);break}}catch{}return t}import{createHash as vx}from"crypto";import{readdirSync as $x,readFileSync as Ff,renameSync as xx,statSync as so,unlinkSync as _x}from"fs";import{join as zt}from"path";function Sx(e,n){Cx(no(e),n)}var un=1440*60*1e3;function Cx(e,n){let t=(s,r)=>{let o=[];try{o=$x(s)}catch{return}for(let a of o.slice(0,5e3))try{let i=so(zt(s,a));r(a,i.mtimeMs)||_x(zt(s,a))}catch{}};t(e.state,(s,r)=>!(s.startsWith("note-")||s.startsWith("notice-")||s.startsWith("problem-")||s.startsWith("helpers-said-"))||n-r<un),t(zt(e.state,"covered"),(s,r)=>n-r<un),t(zt(e.state,"pending"),(s,r)=>n-r<un),t(zt(e.state,"sessions"),(s,r)=>n-r<7*un),t(e.approvals,(s,r)=>n-r<un),t(e.counts,(s,r)=>n-r<60*un);try{if(St(e.decisions,Number.MAX_SAFE_INTEGER)===!0){let s=so(e.decisions).size;s>5*1024*1024&&(s>Ax||Rx(e,n))&&xx(e.decisions,`${e.decisions}.1`)}}catch{}}var Ax=64*1024*1024,Ex=14*un;function Rx(e,n=Date.now()){if(St(`${e.decisions}.1`,Number.MAX_SAFE_INTEGER)===null)return!0;let t=null;try{t=JSON.parse(Ff(zt(e.state,"sync-active.json"),"utf8"))}catch{return!0}if(typeof t?.id!="string")return!0;let s=i=>{try{return n-so(i).mtimeMs>Ex}catch{return!0}},r=zt(e.state,"sync",`${vx("sha256").update(t.id).digest("hex").slice(0,16)}.json`),o=null;try{o=JSON.parse(Ff(r,"utf8"))}catch{return s(zt(e.state,"sync-active.json"))}let a=null;try{a=so(e.decisions).ino}catch{a=null}return a!==null&&o?.ino===a?!0:s(r)}import{createHash as rE,randomBytes as oE}from"crypto";import{readdirSync as Tx,renameSync as aE,unlinkSync as Dx}from"fs";import{join as Hf}from"path";import{createHmac as Ox,randomBytes as WA,timingSafeEqual as jx}from"crypto";import{closeSync as LA,existsSync as TA,fsyncSync as DA,linkSync as IA,mkdirSync as FA,openSync as MA,readdirSync as zA,readFileSync as Mf,unlinkSync as UA,writeSync as qA}from"fs";import{basename as BA,dirname as VA,join as Px}from"path";var Ds="_seal";function Wx(e){return Px(e.dir,"seal.key")}function zf(e){let n=Wx(e);if(St(n,1024)!==!0)return null;try{let t=Mf(n,"utf8").trim();return/^[0-9a-f]{64}$/.test(t)?Buffer.from(t,"hex"):null}catch{return null}}function fa(e,n=0){if(n>64)throw new Error("nested too deep to seal");return Array.isArray(e)?`[${e.map(t=>fa(t===void 0?null:t,n+1)).join(",")}]`:e&&typeof e=="object"?`{${Object.keys(e).filter(s=>!(n===0&&s===Ds)&&e[s]!==void 0).sort().map(s=>`${JSON.stringify(s)}:${fa(e[s],n+1)}`).join(",")}}`:JSON.stringify(e??null)}function Nx(e,n){return Ox("sha256",e).update(fa(n)).digest("hex")}function da(e){if(!(Ds in e))return e;let n={...e};return delete n[Ds],n}function Lx(e,n){let t=n[Ds];if(typeof t!="string"||!/^[0-9a-f]{64}$/.test(t))return!1;let s;try{s=Nx(e,n)}catch{return!1}return jx(Buffer.from(t,"hex"),Buffer.from(s,"hex"))}function Uf(e,n,t=8*1024*1024){let s=St(e,t);if(s===null)return{status:"missing"};if(s===!1)return{status:"unreadable"};let r;try{r=JSON.parse(Mf(e,"utf8"))}catch{return{status:"unreadable"}}return!r||typeof r!="object"||Array.isArray(r)?{status:"unreadable"}:n?Ds in r?Lx(n,r)?{status:"ok",value:da(r)}:{status:"changed",value:da(r)}:{status:"unsealed",value:r}:{status:"unkeyed",value:da(r)}}var dE=600*1e3,fE=1440*60*1e3;function qf(e){return Hf(e.state,"pending")}function Ix(e,n,t,s,r,o,a){let i=0;for(let{hold:l,file:c}of zx(e,n,o))if(!(c===a||(l.session??null)!==(t??null)||(l.project??null)!==(s??null)||l.stops.length===0)&&l.stops.every(u=>r.some(p=>Mx(p,u))))try{Dx(c),i++}catch{}return i}function Fx(e){let n=no(e.anvilDir);Ix(n,zf(n),e.session,e.project,e.stops,e.now)}function Mx(e,n){return e.kind===n.kind&&(e.target??null)===(n.target??null)}function zx(e,n,t){let s=[];try{s=Tx(qf(e)).filter(o=>o.endsWith(".json")).slice(0,2e3)}catch{return[]}let r=[];for(let o of s){let a=Hf(qf(e),o),i=Uf(a,n,64*1024);i.status!=="ok"||i.value.v!==2||!Array.isArray(i.value.stops)||!(Date.parse(i.value.expires_at)>=t)||r.push({hold:i.value,file:a})}return r.sort((o,a)=>Date.parse(a.hold.created_at)-Date.parse(o.hold.created_at))}import{spawnSync as Bx}from"child_process";import{closeSync as Vx,constants as Yf,existsSync as Gx,fstatSync as Zx,openSync as Kx,readSync as Yx,statSync as Jx}from"fs";import{basename as Xx,join as Qx,resolve as e0}from"path";var Bf=["-c","core.fsmonitor=false","-c","core.hooksPath=/dev/null"];function Vf(e){let n=[];for(let t of e.split("\0")){let[s="",r="true"]=t.split(`
|
|
95
|
+
`);if(s==="submodule.recurse"){if(!/^(false|no|off|0)$/i.test(r))return null}else if(s!==""){let o=s.slice(7,s.lastIndexOf("."));if(!/^[\w.-]+$/.test(o))return null;n.push("-c",`filter.${o}.clean=`,"-c",`filter.${o}.process=`,"-c",`filter.${o}.required=false`)}}return n}import{lstatSync as Ux,readdirSync as qx}from"fs";import{join as Gf}from"path";var Is=e=>/[*?[\]{}]/.test(e);function Zf(e,n){let[t,s]=[[...e],[...n]],[r,o,a,i]=[0,0,-1,0];for(;r<t.length;)if(s[o]==="*")[a,i]=[o++,r];else if(o<s.length&&(s[o]==="?"||s[o]===t[r]))r++,o++;else{if(a<0)return!1;[o,r]=[a+1,++i]}for(;s[o]==="*";)o++;return o===s.length}var Hx=4096;function Kf(e,n,t=0,s=()=>{},r=o=>qx(o)){let o=[e.slice(0,t)||"/"],a=e.slice(t);if(a.includes("**"))return null;for(let l of a.split("/").filter(Boolean)){let c=0;for(let d of l)if(d==="{")c++;else if(d==="}"&&--c<0)return null;if(c!==0)return null;let u=l.replace(/[[{].*[\]}]/,"*");if(!/[*?]/.test(u)){o=o.map(d=>Gf(d,l));continue}let p=[];for(let d of o){s();let f;try{f=r(d)}catch(h){if(!/^(ENOENT|ENOTDIR)$/.test(h.code??""))return null;continue}for(let h of l.startsWith(".")?[...f,".",".."]:f)if(s(),(Zf(h,u)||Zf(h.normalize("NFC"),u.normalize("NFC")))&&p.push(Gf(d,h)),p.length>Hx)return null}o=p}let i=new Set;for(let l of new Set([e,...o])){s();try{Ux(l,{throwIfNoEntry:!1})&&i.add(l)}catch(c){if(!/^(ENOENT|ENOTDIR|ENAMETOOLONG)$/.test(c.code??""))return null}}return i.size>n?null:[...i]}var Xf=4*1024*1024,t0=1e3,ro=class extends Error{};function Qf(e,n=Xf){try{let t=ot(e,n);return t===null?"missing":t.toString("utf8")}catch{return null}}function ep(e,n,t,s=400){let r=Bx(e,n,{cwd:t?Fe(t):void 0,encoding:"utf8",timeout:s,stdio:["ignore","pipe","ignore"],env:{...process.env,GIT_OPTIONAL_LOCKS:"0"},windowsHide:!0});if(r.error||r.signal)throw r;return r.status===0&&typeof r.stdout=="string"?r.stdout:null}var oo="not in time",dn="not there",Jf=["--",...[".claude",".claude/**",".anvil",".anvil/**",".mcp.json"].map(e=>`:(top,glob,icase)**/${e}`)];function n0(e,n){let t=[];for(let s of e.matchAll(/^(?:\+\+\+|---|\*\*\*|Index:|rename to|copy to) ([^\t\n]+)/gm)){let r=s[1].replace(/^"|"$/g,"").trim();r!=="/dev/null"&&t.push(r.split("/").slice(n).join("/"))}for(let s of e.matchAll(/^diff --git a\/(\S+) b\/(\S+)/gm))t.push(s[1],s[2]);return t.join(`
|
|
96
|
+
`)}var pa=128*1024;function s0(e){let n=-1;try{n=Kx(e,Yf.O_RDONLY|Yf.O_NONBLOCK);let t=Zx(n);if(!t.isFile()||t.size>pa)return!0;let s=Buffer.alloc(pa),r=s.subarray(0,Yx(n,s,0,pa,0)),o=r.toString("latin1");for(let a=0;a+512<=r.length;a+=512){let i=256,l=256;for(let u=a;u<a+512;u++)(u-a<148||u-a>155)&&(i+=r[u],l+=r[u]<<24>>24);let c=parseInt(o.slice(a+148,a+156),8);if(c===i||c===l)return!0}return/^(\x1f[\x8b\x9d]|BZh|\(\xb5\/\xfd|\x04"M\x18|LZIP|[\s\S]{2}-l[hz][\s\S]-|!<arch>\n|WARC\/|#mtree)/.test(o)||o.startsWith("CD001",32769)||/^begin(-base64)? [0-7]/m.test(o)?!0:!o.startsWith("\0\x07")&&(r.includes(0)||o.includes("="))}catch{return!0}finally{n>=0&&Vx(n)}}function r0(e,n,t){let s=performance.now()+t0,r=()=>{let l=s-performance.now();if(l<=0)throw new ro;return Math.ceil(l)},o=Is(n.slice(t))?Kf(n,1e3,t,r):[n];if(o===null)return null;let a=[],i=Xf;for(let l of o){let c=Jx(l,{throwIfNoEntry:!1});if(!c)continue;let u=null;if(c.isFile())if(e==="zip"||e==="tar")u=ep(e==="zip"?"unzip":"tar",[e==="zip"?"-Z1":"-tf",l],null,Math.min(400,r()));else{r();let p=Qf(l,i);if(p==="missing")continue;i-=p?.length??0,u=p===null?null:n0(p,Number(e.slice(1)))}if(u!==null)a.push(u);else if(o.length===1||!Xx(l).startsWith(".")||!c.isDirectory()&&(e[0]==="p"||s0(l)))return null}return a.length>0?a.join(`
|
|
97
|
+
`):dn}function tp(e){if(e.kind!=="changes")return null;let n=e.arg??"";try{let t=/^(?:(co|wt|wi|merge|pull|pick|stash|al)\t((?!-)[^\0-\x20:?*[\\\x7f]+)((?:\t(?!-)[^\0-\x1f]+)*)|(zip|tar|p\d\d?)\t(\/[^\0-\x1f]*)(?:\t(\d{1,5}))?)$/.exec(n);if(!t)return null;if(t[4]){let u=Fe(t[5]);return r0(t[4],u,u===t[5]?Number(t[6]??0):0)}let s=t[1],r=t[2],o=(...u)=>ep("git",[...Bf,...u],e.cwd);if(s==="al")return o("config","--get",`alias.${r}`)?.trim()??dn;let a=(o("rev-parse","--verify","--quiet",`${r}^0`)||(s==="co"?o("for-each-ref","--count=1","--format=%(objectname)",`refs/remotes/*/${r}`):""))?.trim();if(!a)return s==="pull"?null:s==="co"&&Gx(e0(Fe(e.cwd??"/"),r))?"":dn;let i=["--name-only","-z","--no-renames","--no-ext-diff","--no-relative"];if(s==="stash")return o("stash","show","-u",...i,r);if(s==="pick")return o("diff-tree","-r","-m","--root","--no-commit-id",...i,a,...Jf);let l=[];if(s[0]==="w"){let u=o("rev-parse","--show-toplevel")?.trim()??"";if([".gitattributes",".claude/.gitattributes"].some(d=>{let f=Qf(Qx(u,d));return f===null||f!=="missing"&&/filter\s*=/.test(f)}))return null;let p=Vf(o("config","-z","--get-regexp","^filter\\.")??"");if(p===null)return null;l=p}let c=t[3]?["--",...t[3].slice(1).split(" ").map(u=>`:(literal)${u}`)]:Jf;return o(...l,"diff",...i,"--ignore-submodules=dirty",...s==="wi"?[]:[s==="wt"?a:`HEAD..${s==="co"?"":"."}${a}`],...c)}catch(t){if(t instanceof ro||t.signal||t.error?.code==="ETIMEDOUT")return oo}return null}import{spawnSync as sp}from"child_process";import{readdirSync as o0,statSync as rp}from"fs";import{homedir as i0}from"os";var a0=250,l0=4e4,c0=5e3,op=["-c","core.ignorecase=false"],u0=1024*1024,d0=new Set([".git","node_modules","bower_components",".pnpm-store",".venv","venv","site-packages","__pycache__",".Trash","Containers","Group Containers","Mobile Documents","CloudStorage"]);function ip(e,n={}){try{let t=e.cwd??"",s=JSON.parse(e.arg??"");if(!t.startsWith("/")||typeof s!="object"||s===null)return null;let r=Date.now()+a0,o=(u,p)=>(u??[]).some(d=>typeof d=="string"&&eo(d,p)),a=u=>(!s.in||o(s.in,u))&&!o(s.ex,u),i=[],l=!1,c;try{c=rp(Fe(t)).isDirectory()}catch(u){let p=u.code;return p==="ENOENT"||p==="ENOTDIR"?Zt:null}if(c){let u=i0(),p=[["",0]],d=new Set,f=0,h;for(let g=0;g<p.length&&!l;g++){let[b,k]=p[g];if(h&&b&&np(b,h))continue;let E=b?`${t}/${b}`:t,y=[];try{y=o0(Fe(E),{withFileTypes:!0})}catch{}for(let m of y){if(++f>(n.names??l0)||Date.now()>r){l=!0;break}if(s.g&&h===void 0&&f>(n.pruneAfter??c0)&&(h=g0(t,r),h&&b&&np(b,h)))break;if(!s.h&&m.name.startsWith("."))continue;let R=b?`${b}/${m.name}`:m.name,v=m.isSymbolicLink()?s.l?f0(`${E}/${m.name}`,d):null:m.isDirectory()?"dir":m.isFile()?"file":null;v==="dir"?k<(s.d??1/0)&&!d0.has(m.name)&&!m.name.endsWith(".photoslibrary")&&!(m.name==="Library"&&Fe(E)===u)&&!o(s.xd,m.name)&&p.push([R,k+1]):v==="file"&&Yi(`${t}/${R}`)&&a(m.name)&&(i.length<32?i.push(R):l=!0)}}}else{let u=t.slice(t.lastIndexOf("/")+1);Yi(t)&&a(u)&&i.push(".")}for(let u of s.g?h0(t,i):i)if(p0(u==="."?t:`${t}/${u}`,s))return u;return l?Gt:""}catch{return null}}function f0(e,n){try{let t=rp(Fe(e));return t.isFile()?"file":!t.isDirectory()||n.has(`${t.dev}:${t.ino}`)?null:(n.add(`${t.dev}:${t.ino}`),"dir")}catch{return null}}function p0(e,n){if(!n.t)return!0;try{let t=ot(Fe(e),u0);return t===null?!1:t[0]===255&&t[1]===254||t[0]===254&&t[1]===255?!0:Hd(n.t,t.toString("utf8",t[0]===239&&t[1]===187&&t[2]===191?3:0))}catch{return!0}}function h0(e,n){if(n.length===0)return[];let t=sp("git",[...op,"-c","core.fsmonitor=false","-c","core.hooksPath=/dev/null","check-ignore","--no-index","--stdin","-z"],{cwd:Fe(e),input:[".",...n].join("\0"),encoding:"utf8",timeout:400,stdio:["pipe","pipe","ignore"],env:{...process.env,GIT_OPTIONAL_LOCKS:"0"},windowsHide:!0});if(t.error||t.signal||t.status!==0&&t.status!==1||typeof t.stdout!="string")return[...n];let s=new Set(t.stdout.split("\0"));return s.has(".")?[...n]:n.filter(r=>!s.has(r))}function g0(e,n){let t=n-Date.now();if(t<20)return null;let s=sp("git",[...op,"-c","core.fsmonitor=false","-c","core.hooksPath=/dev/null","ls-files","--others","--ignored","--exclude-standard","--directory","-z"],{cwd:Fe(e),encoding:"utf8",timeout:t,maxBuffer:16*1024*1024,stdio:["ignore","pipe","ignore"],env:{...process.env,GIT_OPTIONAL_LOCKS:"0"},windowsHide:!0});return s.error||s.signal||s.status!==0||typeof s.stdout!="string"?null:new Set(s.stdout.split("\0").filter(r=>r.endsWith("/")).map(r=>r.slice(0,-1)))}function np(e,n){for(let t=e.indexOf("/");t>=0;t=e.indexOf("/",t+1))if(n.has(e.slice(0,t)))return!0;return n.has(e)}function ga(){return{touched:{full:new Set,parent:new Set,glob:new Set,deep:new Set},read:new Set,written:new Set,unknown:new Set}}function cp(e){let{glob:n,deep:t}=e.touched??{};return{full:[...e.touched?.full??[]],parent:[...e.touched?.parent??[]],...n?.size?{glob:[...n]}:{},...t?.size?{deep:[...t]}:{},read:[...e.read??[]],written:[...e.written??[]],unknown:[...e.unknown??[]]}}function y0(e){if(!e||typeof e!="object")return null;let n=e;for(let t of["file_path","notebook_path","path"])if(typeof n[t]=="string")return n[t];return null}var b0=/(?:^|[^\w.-])(?:git|gh|patch|tar|bsdtar|gtar|unzip)(?![\w.-])/,w0=/^(add|annotate|archive|bisect|blame|branch|bundle|cat-file|check-[\w-]+|clean|clone|commit|config|count-objects|describe|diff(-\w+)?|fetch|filter-branch|for-each-ref|format-patch|fsck|gc|grep|hash-object|help|init|log|ls-\w+|maintenance|merge-\w+|mk\w+|mv|name-rev|notes|prune|push|range-diff|reflog|remote|repack|replace|rerere|rev-\w+|rm|shortlog|show(-\w+)?|sparse-checkout|status|submodule|symbolic-ref|tag|update-[\w-]+|var|verify-\w+|version|whatchanged|worktree|\w+-tree)$/,k0=/^(?!-)[^\0-\x20:?*[\\\x7f]+$/,ha=/^(?:\.\/?|\*|:\/|:\(top\))$/;function ap(e){let n=e.toLowerCase().split("/");return n[n.length-1]===".mcp.json"||n.some(t=>t===".claude"||t===".anvil")}var fn=e=>typeof e=="string"&&e.startsWith("/")&&!S(e),Pe=e=>({what:e,ask:null,base:null,shown:null}),Ms=(e,n)=>{let t=e.replace(/[\u0000-\u0008\u000b-\u001f\u007f]/g,"");return t.length>n?`${t.slice(0,n-3)}\u2026`:t};function zs(e,n,t){if(e===""||S(e)||!e.startsWith("/")&&!e.startsWith("~")&&!fn(n))return null;let s=M(e,n,{home:t});return fn(s)?s:null}function _e(e,n,t,s,r=[]){return!fn(s)||S(t)||!k0.test(t)||r.some(o=>S(o)||!/^(?!-)[^\0-\x1f]+$/.test(o))?Pe(e):{what:e,ask:{probe:{kind:"changes",arg:[`${n} ${t}`,...r].join(" "),cwd:s}},base:s,shown:null}}function ya(e,n,t,s,r,o,a,i={}){let l=zs(t,s,a),c=r===null?fn(o)?o:null:zs(r,o,a);if(l===null||c===null||/[\u0000-\u001f]/.test(l))return Pe(e);let u=Is(l)&&fn(s)&&s!=="/"&&l.startsWith(`${s}/`)&&!t.startsWith("/")?` ${s.length}`:"";return{what:e,ask:{probe:{kind:"changes",arg:`${n} ${l}${u}`,cwd:null}},base:c,shown:r===null?null:$(r),...i}}function up(e){if(e.stdinKind)return;if(e.stdinFile)return e.stdinFile;let n=e.pipeFrom;if(!n)return;let t=n.argv.slice(1).filter(s=>!s.startsWith("-"));return n.name==="cat"&&t.length===1?t[0]:null}function Qe(e,n,t=[]){let s=[],r=new Map,o=!1;for(let a=0;a<e.length;a++){let i=e[a];if(o)s.push(i);else if(i==="--")o=!0;else if(i.startsWith("--")){let l=i.indexOf("=");r.set(l>0?i.slice(0,l):i,l>0?i.slice(l+1):t.includes(i)?e[++a]??"":"")}else if(i.startsWith("-")&&i.length>1)for(let l=1;l<i.length;l++){let c=i[l];if(n.includes(c)){r.set(`-${c}`,l+1<i.length?i.slice(l+1):e[++a]??"");break}r.set(`-${c}`,"")}else s.push(i)}return{pos:s,opt:r,dashdash:o}}var et=(e,n)=>n.some(t=>e.opt.has(t)),Fs=e=>e==="-"?"@{-1}":e;function ma(e,n,t,s,r,o,a,i){if(!/^\d{1,2}$/.test(s))return[Pe(n)];let l=`p${Number(s)}`,c=(u,p)=>ya(`${n} ${Ut.basename($(u))}`,l,u,p,o,a,i);return(t.length>0?t:["-"]).flatMap(u=>{if(u!=="-")return[c(u,r)];let p=up(e);return p===void 0?[]:p===null?[Pe(n)]:[c(p,a)]})}function dp(e,n,t,s){let r=e.argv,o=n,a=/\bGIT_(?:DIR|WORK_TREE|INDEX_FILE|COMMON_DIR)=/.test(e.text),i=1;for(;i<r.length;i++){let d=r[i];if(d==="-C")o=zs(r[++i]??"",o,t);else if(d==="-c"||d==="--namespace"||d==="--config-env")i++;else if(d==="--git-dir"||d==="--work-tree")a=!0,i++;else if(/^--(git-dir|work-tree)=/.test(d))a=!0;else if(!d.startsWith("-"))break}let l=r[i]??"",c=r.slice(i+1);if(c.includes("--help")||c.includes("-h"))return[];let u=(...d)=>["git",l,...d].map($).join(" "),p=(()=>{switch(l){case"checkout":{let f=Qe(c,"bB",["--orphan","--conflict","--pathspec-from-file"]);if(f.pos.some(k=>ha.test(k)))return[f.pos.length>1&&!ha.test(f.pos[0])?_e(u(...f.pos),"wt",f.pos[0],o):_e(u(...f.pos),"wi","HEAD",o)];if(et(f,["-p","--patch","--pathspec-from-file"]))return[];let h=c.indexOf("--"),g=h>=0?c.slice(h+1):f.pos.slice(1);if(g.length>0&&(h<0||f.pos.length>g.length))return[_e(u(...f.pos),"wt",f.pos[0],o,g)];if(f.dashdash)return[];let b=et(f,["-b","-B","--orphan"])||f.pos.length===1?f.pos[0]:void 0;return et(f,["-f","--force"])?[_e(u("-f",...f.pos),"wt",b??"HEAD",o)]:b===void 0?[]:[_e(u(b),"co",Fs(b),o)]}case"switch":{let f=Qe(c,"cC",["--create","--force-create","--orphan","--conflict"]);if(f.opt.has("--orphan"))return[Pe(u("--orphan"))];let h=f.pos[0];return et(f,["-f","--force","--discard-changes"])?[_e(u("-f",...f.pos),"wt",h??"HEAD",o)]:h===void 0?[]:[_e(u(h),"co",Fs(h),o)]}case"restore":{let f=Qe(c,"s",["--source","--pathspec-from-file","--conflict"]);if(f.pos.length===0||et(f,["-S","--staged"])&&!et(f,["-W","--worktree"]))return[];let h=f.opt.get("-s")??f.opt.get("--source"),g=f.pos.some(b=>ha.test(b))?[]:[...f.pos];return[h?_e(u(...f.pos),"wt",h,o,g):_e(u(...f.pos),"wi","HEAD",o,g)]}case"reset":{let f=Qe(c,"",["--pathspec-from-file"]),h=["--hard","--keep","--merge"].find(b=>f.opt.has(b)),g=f.pos[0]??"HEAD";return h===void 0||f.dashdash||f.pos.length>1?[]:[_e(u(h,...f.pos),"wt",g,o)]}case"merge":{let f=Qe(c,"mFsX",["--message","--file","--strategy","--strategy-option","--into-name","--cleanup"]);return et(f,["--abort","--continue","--quit"])?[]:f.pos.length>0?f.pos.map(h=>_e(u(h),"merge",Fs(h),o)):[_e(u(),"merge","@{u}",o)]}case"rebase":{let f=Qe(c,"sXxC",["--onto","--exec","--strategy","--strategy-option","--empty","--whitespace"]);if(et(f,["--continue","--abort","--skip","--quit","--edit-todo","--show-current-patch"]))return[];let h=f.pos[0]??(f.opt.has("--root")?void 0:"@{u}"),g=f.pos[1]!==void 0?[_e(u(...f.pos),"co",f.pos[1],o)]:[];for(let b of[f.opt.get("--onto"),h])b&&g.push(_e(u(...f.pos),"co",Fs(b),o));return g}case"pull":{let f=Qe(c,"sXjo",["--strategy","--strategy-option","--depth","--deepen","--shallow-since","--shallow-exclude","--jobs","--upload-pack","--server-option","--negotiation-tip"]),[h,...g]=f.pos;return(h!==void 0&&g.length>0?g.map(k=>`${h}/${k.replace(/^\+/,"").split(":")[0].replace(/^refs\/heads\//,"")}`):["@{u}"]).map(k=>_e(u(...f.pos),"pull",k,o))}case"cherry-pick":case"revert":{let f=Qe(c,"mX",["--mainline","--strategy","--strategy-option","--cleanup"]);return et(f,["--continue","--abort","--skip","--quit"])?[]:f.opt.has("--stdin")?[Pe(u("--stdin"))]:f.pos.map(h=>h.includes("..")||h.startsWith("^")?Pe(u(h)):_e(u(h),"pick",Fs(h),o))}case"stash":{let[f="",...h]=c;if(f!=="pop"&&f!=="apply"&&f!=="branch")return[];let g=Qe(h,""),b=f==="branch"?g.pos[1]:g.pos[0],k=b===void 0?"stash@{0}":/^\d+$/.test(b)?`stash@{${b}}`:b,E=u(f,...g.pos);return f==="branch"?[_e(E,"stash",k,o),_e(E,"co",`${k}^1`,o)]:[_e(E,"stash",k,o)]}case"apply":{let f=Qe(c,"pC",["--directory","--include","--exclude","--whitespace","--build-fake-ancestor"]);return et(f,["--check","--stat","--numstat","--summary"])&&!f.opt.has("--apply")||f.opt.has("--cached")&&!f.opt.has("--index")?[]:ma(e,"git apply",f.pos,f.opt.get("-p")??"1",o,f.opt.get("--directory")??null,o,t)}case"am":{let f=Qe(c,"pC",["--directory","--include","--exclude","--whitespace","--patch-format","--resolvemsg","--quoted-cr","--empty"]);return et(f,["--continue","--skip","--abort","--quit","--resolved","-r","--show-current-patch","--retry"])?[]:ma(e,"git am",f.pos,f.opt.get("-p")??"1",o,f.opt.get("--directory")??null,o,t)}}if(!s||!/^[a-z][\w-]*$/.test(l)||w0.test(l))return[];let d=s(l,o);return d===void 0||d===dn?[]:d===null||/^\s*!|['"\\]/.test(d)?[Pe(u())]:dp({...e,argv:["git",...d.trim().split(/\s+/),...c]},o,t)})();return a?p.map(d=>Pe(d.what)):p}function v0(e,n,t){let s=Qe(e.argv.slice(1),"BDFgiopVxYzdr",["--prefix","--ifdef","--fuzz","--get","--input","--output","--strip","--reject-file","--version-control","--debug","--basename-prefix","--suffix","--directory","--quoting-style","--reject-format","--read-only"]);if(et(s,["--dry-run","--check","-C"]))return[];let r=s.opt.get("-d")??s.opt.get("--directory")??null,o=r===null?fn(n)?n:null:zs(r,n,t),[a,i]=s.pos,c=s.opt.get("-o")??s.opt.get("--output")??a;if(c!==void 0){if(c==="-")return[];let p=zs(c,o,t);return[p===null?Pe("patch"):{what:`patch ${Ut.basename($(c))}`,ask:{files:[p]},base:null,shown:null}]}let u=s.opt.get("-i")??s.opt.get("--input")??i;return ma(e,"patch",u===void 0?[]:[u],s.opt.get("-p")??s.opt.get("--strip")??"0",o,r,n,t)}function $0(e,n,t){let s=e.argv.slice(1),r,o=null,a="";for(let l=0;l<s.length;l++){let c=s[l];if(!c.startsWith("-")||c.length===1){r??=c;continue}for(let u=1;u<c.length;u++){let p=c[u];if(p==="d"||p==="P"){let d=u+1<c.length?c.slice(u+1):s[++l]??"";p==="d"&&(o=d);break}if(p==="x"){for(;l+1<s.length&&!s[l+1].startsWith("-");)l++;break}a+=p}}if(r===void 0||/[lvtZpcz]/.test(a))return[];if(/[*?[]/.test($(r)))return[Pe(`unzip ${$(r)}`)];let i=`unzip ${Ut.basename($(r))}`;return(/\.zip$/i.test(r)?[r]:[r,`${r}.zip`]).map(l=>ya(i,"zip",l,n,o,n,t,{flat:a.includes("j")}))}var x0=["fCTXbgNKVIHFL","fCTXbsI"],_0=new Set(["--file","--directory","--exclude","--files-from","--exclude-from","--transform","--xform","--use-compress-program","--owner","--group","--mode","--mtime","--newer","--newer-mtime","--format","--strip-components","--to-command","--suffix","--occurrence","--sort","--include","--options","--uid","--gid","--passphrase"]);function S0(e,n,t){let s=e.argv.slice(1),r=[];for(let o of x0){let a={extract:!1,toStdout:!1,renames:!1,file:void 0,dest:null},i=(u,p)=>{u==="x"||u==="--extract"||u==="--get"?a.extract=!0:u==="O"||u==="--to-stdout"||u==="--to-command"?a.toStdout=!0:u==="f"||u==="--file"?a.file=p:u==="C"||u==="--directory"?a.dest=p:(u==="s"&&o.includes("s")||u==="--transform"||u==="--xform")&&(a.renames=!0)},l=0;if(s[0]&&/^[A-Za-z]+$/.test(s[0])){l=1;for(let u of s[0])i(u,o.includes(u)?s[l++]??"":"")}for(;l<s.length;l++){let u=s[l];if(u==="--")break;if(u.startsWith("--")){let p=u.indexOf("="),d=p>0?u.slice(0,p):u;i(d,p>0?u.slice(p+1):_0.has(d)?s[++l]??"":"")}else if(u.startsWith("-")&&u.length>1)for(let p=1;p<u.length;p++){let d=u[p];if(o.includes(d)){i(d,p+1<u.length?u.slice(p+1):s[++l]??"");break}i(d,"")}}if(!a.extract||a.toStdout)continue;if(a.renames){r.push(Pe("tar -x"));continue}let c=a.file===void 0||a.file==="-"?up(e):a.file;c!==void 0&&r.push(c===null?Pe("tar -x"):ya(`tar -xf ${Ut.basename($(c))}`,"tar",c,n,a.dest,n,t))}return r}function C0(e,n,t,s){switch(e.name){case"git":return dp(e,n,t,s);case"gh":return/^(pr (checkout|co)|co)\b/.test(e.argv.slice(1,3).join(" "))?[Pe("gh pr checkout")]:[];case"patch":return v0(e,n,t);case"unzip":return $0(e,n,t);case"tar":case"bsdtar":case"gtar":return S0(e,n,t)}return[]}function A0(e,n){let t=new Set;for(let i of n){let l=i.replace(/\\/g,"/");if(l===""||l.endsWith("/"))continue;let c=e.flat?Ut.basename(l):l,p=[...c.startsWith("/")?[c]:[],e.base?Ut.join(e.base,c):Ut.normalize(c)].find(ap);if(p===void 0)continue;let d=e.shown?Ut.join(e.shown,c):c;t.add(ap(d)?d:p)}if(t.size===0)return null;let s=Ms([...t][0],200),[r,...o]=[...t].map(i=>Ms(i,1e3)).map(i=>i.length>120?`\u2026${i.slice(-119)}`:i),a=o.length>2?`${o.splice(2).length} more`:o.pop();return{why:`${Ms(e.what,200)} brings in a change to ${[r,...o].join(", ")}${a?` and ${a}`:""}`,target:s,sure:!0}}function E0(e,n,t,s){let[,r,o]=/^(?:zip|tar|p\d\d?)\t([^\t]*)(?:\t(\d+))?$/.exec(e)??[];return r!==void 0&&(n&&Is(r.slice(Number(o??0)))||s&&r.includes("(")||/<\d*-\d*>/.test(t))}function R0(e,n,t){let s=re(n.home),r=typeof n.cwd=="string"&&n.cwd.startsWith("/")?re(n.cwd):n.cwd,o=typeof n.project_dir=="string"&&n.project_dir.startsWith("/")?re(n.project_dir):n.project_dir,a=n.session_facts??null,i=At(e,{home:s,tmpdir:re(n.tmpdir),cwd:r,projectDir:o,claudeConfigDir:n.claude_config_dir??null,knownFiles:a?.scripts??null,unreadableFiles:a?.unreadableScripts??null}),l=a?.probed,c=[],u=new Set,p=new Set(i.commands.flatMap(f=>f.name==="git"?f.argv.flatMap(h=>/^alias\.(.+)$/.exec(h)?.[1]??[]):[])),d=(f,h)=>{if(!fn(h))return null;let g={kind:"changes",arg:`al ${f}`,cwd:h},b=ls(g);if(!l||!(b in l))return void t.set(b,g);let k=l[b];return typeof k=="string"&&k!==oo?k:null};return i.commands.forEach((f,h)=>{if(f.via==="remote"||f.functionCall)return;let g=i.commands.slice(0,h).some(k=>!["cd","pushd","export","set","true",":"].includes(k.name)),b=f.name==="git"&&f.argv[1]==="stash"&&/^(pop|apply)$/.test(f.argv[2]??"")&&f.argv.length===3&&i.commands.slice(0,h).some(k=>k.name==="git"&&k.argv[1]==="stash"&&!/^(pop|apply|drop|list|show|clear|branch)$/.test(k.argv[2]??""));for(let k of[...new Set([f.cwd,...f.cwdFallbacks])]){let E=f.name==="git"&&p.has(f.argv[1]??"")?[Pe(`git ${$(f.argv[1])}`)]:C0(f,k,s,d);for(let y of f.via==="xargs"?E.map(m=>Pe(m.what)):E){let m,R=!1;if(y.ask===null)m=null;else if("files"in y.ask)m=y.ask.files;else if(E0(y.ask.probe.arg??"",g,e,i.status!=="complete"))m=null;else{let C=ls(y.ask.probe);if(!l||!(C in l)){t.set(C,y.ask.probe);continue}let N=l[C];if(N===dn&&(!g||b))continue;R=N===oo,m=typeof N=="string"&&!R&&N!==dn?N.split(/[\0\n]/):null}let v=m===null?{why:Ms(R?`couldn't check in time which files ${y.what} would change`:`can't tell which files ${y.what} would change`,300),target:Ms(y.what,200),sure:!1}:A0(y,m);v&&!u.has(v.why)&&(u.add(v.why),c.push(v))}}}),c.sort((f,h)=>Number(h.sure)-Number(f.sure))}function O0(e,n){let{housekeeping:t,findings:s,prod:r,copy:o,...a}=e,i=e.action!=="claude.bash.unclassified"&&e.action!=="claude.tool.other",l=n[0],c=[...new Set([...i?[e.action]:[],...e.also])].filter(y=>y!=="claude.agent.controls"),{environment:u,environment_said:p,repo_dir:d,repo_remote:f,repo_via:h,...g}=e.attributes,b={...u!==void 0?{environment:u,environment_said:p??null}:{},...h!==void 0?{repo_dir:d??null,repo_remote:f??null,repo_via:h}:{},...r?{prod:r}:{}},k=e.findings??(i?[{action:e.action,service:e.service,target:e.attributes.target,why:e.why,...b,...o?{copy:o}:{}}]:[]),E=[...n.map(y=>({action:"claude.agent.controls",service:null,target:y.target,why:y.why})),...k].slice(0,16);return{...a,action:"claude.agent.controls",service:null,attributes:{...g,target:l.target,branch:null,host:null,is_local:!0},why:l.why,also:c,...E.length>1?{findings:E}:{}}}function j0(e){let n=a=>typeof a=="string"&&a!==""?Ie(a):a??null,t=e.control_links?Object.fromEntries(Object.entries(e.control_links).map(([a,i])=>[Ie(a),Ie(i)])):e.control_links,s=e.session_facts?.repoRemotes,r=e.tool_input&&typeof e.tool_input=="object"?e.tool_input:null,o=r?["file_path","notebook_path"].find(a=>typeof r[a]=="string"):void 0;return{...e,...r&&o?{tool_input:{...r,[o]:Ge(r[o])??r[o]}}:{},cwd:n(e.cwd),project_dir:n(e.project_dir),home:Ie(e.home),tmpdir:Ie(e.tmpdir),...e.claude_config_dir!==void 0?{claude_config_dir:n(e.claude_config_dir)}:{},...e.project_controls?{project_controls:e.project_controls.map(a=>({...a,path:Ie(a.path)}))}:{},...t!==void 0?{control_links:t}:{},...e.session_facts&&(s||e.session_facts.roots||e.session_facts.env)?{session_facts:{...e.session_facts,...s?{repoRemotes:Object.fromEntries(Object.entries(s).map(([a,i])=>[Ie(a),i]))}:{},...e.session_facts.roots?{roots:e.session_facts.roots.map(Ie)}:{},...e.session_facts.env?{env:Object.fromEntries(Object.entries(e.session_facts.env).map(([a,i])=>[a,Ie(i)]))}:{}}}:{}}}function P0(e){let n=e.tool_input&&typeof e.tool_input=="object"?e.tool_input:null;if(e.tool_name!=="PowerShell"||typeof n?.command!="string")return e;let t=pn(n.command,{cwd:e.cwd!==null?pt(e.cwd):null});return t.kind==="shell"?{...e,tool_name:"Bash",tool_input:{...n,command:t.text}}:e}var W0=new Set(["Write","Edit","MultiEdit"]);function N0(e){let n=Z()?j0(e):e,t=P0(n),s=t.tool_input&&typeof t.tool_input=="object"?t.tool_input:{},r=(t.tool_name==="Bash"||t.tool_name==="PowerShell")&&typeof s.command=="string"?s.command:null,o=t.on_disk==="collect"?ga():t.on_disk?{real:t.on_disk,...ga()}:null,a=t.tool_name==="Bash"?new Set:null,i=t.tool_name==="Bash"||t.tool_name==="Grep"||W0.has(t.tool_name)?new Map:null,l=qn({tool:t.tool_name,command:r,target:t.tool_name==="Bash"?null:y0(s),args:t.tool_input,cwd:t.cwd,git_branch:t.git_branch,project_dir:t.project_dir,session_id:t.session_id},{home:t.home,tmpdir:t.tmpdir,claudeConfigDir:t.claude_config_dir??null,onDisk:o,projectControls:t.project_controls??null,controlLinks:t.control_links??null,session:t.session_facts??null,wantScripts:a,wantProbes:i,production:t.production??null,...t!==n?{powershell:!0}:{}}),c=new Map,u=E=>b0.test(E.replace(/['"\\]/g,"")),p=r!==null&&l.action!=="claude.agent.controls"&&(u(r)||Object.values(t.session_facts?.scripts??{}).some(u))?R0(r,t,c):[];p.length>0&&c.clear();let d=p.length>0?O0(l,p):l,f=o?.touched?{...d,touched:cp(o)}:d,h=a&&a.size>0?{...f,scriptsWanted:[...a].slice(0,8)}:f,g=[...c.values(),...i?.values()??[]],b=g.length>0?{...h,probesWanted:g.slice(0,12)}:h;if(!t.want_makings)return b;let k={paths:[],launched:[]};try{k=El(t.tool_name,t.tool_input,t.cwd,{home:t.home,tmpdir:t.tmpdir,projectDir:t.project_dir})}catch{}return{...b,makings:k}}var HE=e=>e.kind==="deps"?Nf(e):e.kind==="reach"?ip(e):tp(e),L0=1e3,T0=new m0.Script("globalThis.__anvilReplayClassify()");function D0(e,n){let t=globalThis;t.__anvilReplayClassify=e;try{return T0.runInThisContext({timeout:n})}catch(s){if(s.code==="ERR_SCRIPT_EXECUTION_TIMEOUT")return"timeout";throw s}finally{delete t.__anvilReplayClassify}}function I0(e,n){return e.map(t=>{try{let s=ga(),r=D0(()=>Ru(t.command_judge!==void 0?{...t,command_local:t.command_judge}:t,{...n,...t.session_facts?{session:t.session_facts}:{},onDisk:s}),L0);if(r==="timeout")return{action:"claude.bash.unclassified",also:[],service:null,attributes:{target:null,branch:null,host:null,is_local:null,args_hash:null},parse:"limited",why:"too long to check in time"};let o=r,a=t.command_judge_cut===!0?"limited":o.parse,i=[s.touched?.full,s.touched?.parent,s.read,s.written,s.unknown].some(l=>(l?.size??0)>0);return{action:o.action,also:o.also,service:o.service,attributes:o.attributes,parse:a,why:o.why,...o.findings?{findings:o.findings}:{},...o.catastrophic?{catastrophic:!0}:{},...o.prod?{prod:o.prod}:{},...o.copy?{copy:!0}:{},...i?{touched:cp(s)}:{}}}catch{return{action:"claude.bash.unclassified",also:[],service:null,attributes:{target:null,branch:null,host:null,is_local:null,args_hash:null},parse:"limited",why:"the classifier failed on it"}}})}if(!lp&&io&&Kn&&Kn.anvilReplayPool===!0){let e=io,n=Kn.ctx;e.on("message",t=>{try{e.postMessage({id:t.id,ok:!0,results:I0(t.calls,n)})}catch(s){e.postMessage({id:t.id,ok:!1,error:s instanceof Error?s.message:String(s)})}})}if(!lp&&io&&Kn&&Kn.anvilClaudeHook===!0){let e=io;try{e.postMessage({ok:!0,classification:N0(Kn.request)})}catch(n){e.postMessage({ok:!1,error:n instanceof Error?n.message:String(n)})}}export{L0 as REPLAY_CALL_LIMIT_MS,HE as answerChanges,I0 as classifyLogged,N0 as classifyRequest,Fx as mootHolds,Sx as sessionChores,F$ as sessionContext,T$ as sessionLine,kx as startProblems};
|