@hasna/hooks 0.12.5 → 0.12.7
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/README.md +26 -5
- package/bin/hooks-mcp.js +3160 -1130
- package/bin/index.js +3550 -1482
- package/bin/native-safety-entry.js +25 -20
- package/bin/native-safety-worker.cjs +25 -20
- package/bin/serve.js +2 -2
- package/dist/index.js +3390 -1308
- package/dist/lib/claude-skills-coordination.d.ts +16 -2
- package/dist/lib/installer.d.ts +11 -0
- package/dist/lib/native-child-env.d.ts +56 -0
- package/dist/lib/native-safety-registration.d.ts +8 -3
- package/hooks/hook-trash-guard/README.md +49 -15
- package/hooks/hook-trash-guard/src/hook.ts +741 -125
- package/hooks/hook-workspace-repos-guard/src/hook.ts +274 -79
- package/hooks/shell-words.ts +368 -0
- package/package.json +2 -2
|
@@ -1,20 +1,25 @@
|
|
|
1
|
-
var{defineProperty:
|
|
2
|
-
`)[0]}finally{W.closeSync($)}let z=/^#!(\/[A-Za-z0-9_./-]+)$/.exec(X);if(z&&z[1]!=="/usr/bin/env")return IZ(z[1],!0);if(X!=="#!/usr/bin/env bun"||!IZ("/usr/bin/env",!0))return!1;for(let Q of J.split(":").slice(0,64)){if(!Q2(Q))return!1;let Y=P.resolve(Q,"bun");try{if(!W.statSync(Y).isFile())continue;W.accessSync(Y,W.constants.X_OK)}catch{continue}return IZ(Y,!0)}return!1}function HZ(Z){let J=Z;for(;;){let $=W.lstatSync(J);if(!$.isDirectory()||!GZ($.uid)||($.mode&18)!==0)return!1;let X=P.dirname(J);if(X===J)return!0;J=X}}function BZ(Z=process.env){let J=Z.PATH??"",$=Date.now()+2000,X="missing",z=(Q)=>{if(X==="missing"||X==="unrecognized_package"||Q.startsWith("unsafe_"))X=Q};for(let Q of J.split(":").slice(0,64)){if(!P.isAbsolute(Q)||Date.now()>=$)continue;let Y=P.resolve(Q,"trash");try{let G=W.statSync(Y);if(!G.isFile()||!GZ(G.uid)||(G.mode&73)===0||(G.mode&18)!==0){z("unsafe_executable");continue}let K=W.realpathSync(Y);if(!HZ(P.resolve(Q))||!HZ(P.dirname(K))){z("unsafe_directory");continue}if(!IZ(Y)){z("unsafe_directory");continue}let H=P.resolve(P.dirname(K),"../.."),B=P.join(H,"package.json"),U=W.statSync(B);if(!U.isFile()||!GZ(U.uid)||U.size>16384||(U.mode&18)!==0||W.lstatSync(B).isSymbolicLink()){z("unsafe_manifest");continue}let V=JSON.parse(W.readFileSync(B,"utf8"));if(V.name!=="@hasna/trash"||typeof V.version!=="string"||typeof V.bin?.trash!=="string"||W.realpathSync(P.resolve(H,V.bin.trash))!==K){z("unrecognized_package");continue}try{if(!Y2(K,J)){z("unsafe_interpreter");continue}}catch{z("unsafe_interpreter");continue}let C=$-Date.now();if(C<=0){z("identity_failed");break}let _=U0.spawnSync(Y,["--identity"],{encoding:"utf8",timeout:C,maxBuffer:2048,env:{PATH:J},stdio:["ignore","pipe","pipe"]});if(_.error||_.status!==0||Date.now()>=$){z("identity_failed");continue}let O=JSON.parse(_.stdout);if(O.name==="@hasna/trash"&&O.version===V.version&&O.guardProtocol==="hasna.trash.guard.v1")return{ok:!0,path:Y,version:V.version};z("unsupported_protocol")}catch{}}return{ok:!1,code:X}}function DZ(Z=process.env){let J=BZ(Z);return J.ok?J.path:null}function $Z(Z){let J=Z.tool_input?.command;return typeof J==="string"?J:""}var M0=["/","/bin","/boot","/dev","/etc","/home","/lib","/lib32","/lib64","/libx32","/opt","/proc","/root","/run","/sbin","/srv","/sys","/usr","/var","/Applications","/Library","/System","/Users","/Volumes","/private"];var H2=600000,B2="Delete via trash guard (rm intercepted and made recoverable)",U2=[".hasna/repos/clones","workspace/repos"],V2=[".hasna",".ssh",".aws"],F0={rmdir:"`rmdir` is a delete that trash-guard does not rewrite (it takes rmdir's flags, not rm's). Re-run it as `rm -d -- <path>` for an empty directory, or `rm -r -- <path>` for a non-empty one, and it is redirected into trash.",unlink:"`unlink` is a delete that trash-guard does not rewrite. Re-run it as `rm -- <path>` and it is redirected into trash.",shred:"`shred` destroys content irrecoverably and is never allowed. Re-run it as `rm -- <path>` and it is redirected into trash."},M2=new Set(["sh","bash","zsh","dash","ksh","ash","eval","source",".","su","runuser","env"]),F2={sudo:["-u","--user","-g","--group","-p","--prompt","-C","--chdir","-h","--host","-r","--role","-t","--type","-U","--other-user"],doas:["-u","-C"],env:["-u","--unset","-C","--chdir","-S","--split-string"],nice:["-n","--adjustment"],ionice:["-c","--class","-n","--classdata","-p","--pid"],stdbuf:["-i","-o","-e","--input","--output","--error"],time:["-f","--format","-o","--output"],timeout:["-s","--signal","-k","--kill-after"],nohup:[],setsid:[],command:[],builtin:[],exec:["-a"]},q2={timeout:1},N2=new Set(["busybox","toybox"]),_2=new Set(["!","{","}","then","do","else","elif","if","while","until","for","case","esac","fi","done","select","function"]),j2=new Set(["-C","-c","--git-dir","--work-tree","--namespace","--exec-path","--config-env"]),W2=/(^|[^A-Za-z0-9_.-])(rm|rmdir|unlink|shred)(?![A-Za-z0-9_.-])/;function VZ(Z){return W2.test(A(Z))}function FZ(Z){return Z.map((J)=>J.replace(/^-[iv0]*S|^--split-string=/," ")).join(" ")}var j0=/^[A-Za-z_][A-Za-z0-9_]*=/;function MZ(Z){let J=Z.lastIndexOf("/");return J>=0?Z.slice(J+1):Z}function W0(Z,J){let $=Z.indexOf("'",J+1);return $===-1?-1:$+1}function wZ(Z,J){let $=J+1;while($<Z.length){if(Z[$]==="\\"){$+=2;continue}if(Z[$]==="`")return $+1;$++}return-1}function T0(Z,J){let $=J+1;while($<Z.length){let X=Z[$];if(X==="\\"){$+=2;continue}if(X==='"')return $+1;if(X==="`"){let z=wZ(Z,$);if(z<0)return-1;$=z;continue}if(X==="$"&&Z[$+1]==="("){let z=qZ(Z,$+1);if(z<0)return-1;$=z;continue}$++}return-1}function JZ(Z,J){if(Z[J]!=="<"||Z[J+1]!=="<"||Z[J+2]==="<")return null;let $=J+2,X=Z[$]==="-";if(X)$++;while(Z[$]===" "||Z[$]==="\t")$++;let z="",Q=!1;while($<Z.length&&!/[\s;|&<>()]/.test(Z[$])){let Y=Z[$];if(Y==="'"||Y==='"'){let G=Z.indexOf(Y,$+1);if(G<0)return null;z+=Z.slice($+1,G),Q=!0,$=G+1;continue}if(Y==="\\"){if($+1>=Z.length)return null;z+=Z[$+1],Q=!0,$+=2;continue}z+=Y,$++}return z?{delimiter:z,stripTabs:X,quoted:Q,end:$}:null}function LZ(Z,J,$){let X=J+1;for(let z of $)for(;;){if(X>Z.length)return-1;let Q=Z.indexOf(`
|
|
3
|
-
`,X),
|
|
4
|
-
|
|
5
|
-
`,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
`,Q=X
|
|
9
|
-
`||Z[Q]==="\r";if(z&&Y)return X;$=X+1}return-1}function A(Z){let J="",$=0;while($<Z.length){let X=Z[$];if(X==="\\"){if($+1<Z.length)J+=Z[$+1];$+=2;continue}if(X==="'"){let z=Z.indexOf("'",$+1);if(z===-1){J+=Z.slice($+1);break}J+=Z.slice($+1,z),$=z+1;continue}if(X==='"'){$++;while($<Z.length&&Z[$]!=='"'){if(Z[$]==="\\"&&$+1<Z.length){J+=Z[$+1],$+=2;continue}J+=Z[$],$++}$++;continue}J+=X,$++}return J}function l(Z){let J=0,$=0;while(J<Z.words.length&&$++<32){if(Z.redirects.has(J)){J++;continue}let X=Z.words[J].text,z=A(X);if(j0.test(z)&&!z.startsWith("-")){J++;continue}if(_2.has(z)){J++;continue}let Q=MZ(z);if(Q==="command")for(let G of Z.words.filter((K,H)=>H>J&&!Z.redirects.has(H))){let K=A(G.text);if(K==="--"||!K.startsWith("-"))break;if(/^-[pvV]*[vV][pvV]*$/.test(K))return-1}let Y=F2[Q];if(Y){let G=J;J++;while(J<Z.words.length){if(Z.redirects.has(J)){J++;continue}let H=A(Z.words[J].text);if(!H.startsWith("-")||H==="-")break;if(H==="--"){J++;break}if(Q==="env"&&(/^-[iv0]*S/.test(H)||/^--split-string(?:=|$)/.test(H)))return G;if(J++,Y.includes(H)||Q==="exec"&&/^-[cl]*a$/.test(H)){while(Z.redirects.has(J))J++;J++}}let K=q2[Q]??0;while(K>0&&J<Z.words.length){let H=A(Z.words[J].text);if(H.startsWith("-")&&H!=="-")break;J++,K--}continue}return J}return-1}function C2(Z,J){let $=[],X=!1;for(let z=J+1;z<Z.words.length;z++){if(Z.redirects.has(z))continue;let Q=A(Z.words[z].text);if(!X){if(Q==="--"){X=!0;continue}if(Q.startsWith("-")&&Q!=="-")continue}$.push(Z.words[z])}return $}function I2(Z){return U2.map((J)=>R.join(Z,...J.split("/")))}function D2(Z,J){if(Z==="~"||Z==="$HOME"||Z==="${HOME}")return J;if(Z.startsWith("~/"))return R.join(J,Z.slice(2));if(Z.startsWith("$HOME/"))return R.join(J,Z.slice(6));if(Z.startsWith("${HOME}/"))return R.join(J,Z.slice(8));return Z}function kZ(Z,J,$){let X=A(Z);if(!X)return null;if(X.includes("`"))return null;if(X==="$HOME"||X==="${HOME}"||X==="$HOME/"||X==="${HOME}/")return $;if(X.replace(/\$\{HOME\}/g,"").replace(/\$HOME/g,"").includes("$"))return null;if(/[*?[\]]/.test(X))return null;if(X.startsWith("~")){let G=D2(X,$);if(G===X)return null;X=G}let Y=(R.isAbsolute(X)?R.normalize(X):R.resolve(J,X)).replace(/\/+$/,"");return Y===""?"/":Y}function UZ(Z,J){return Z===J||Z.startsWith(`${J}${R.sep}`)}function L2(Z,J){let $=`${R.join(J,".hasna","scratchpad","scratch")}${R.sep}`;if(!Z.startsWith($))return!1;let[X,z]=Z.slice($.length).split(R.sep);if(!X||!/^[a-z0-9][a-z0-9._-]{0,63}$/.test(X)||X.endsWith(".")||!z)return!1;let Q=z.normalize("NFKC").toLowerCase();return Q!=="meta.json"&&Q!==".lock"}function A2(Z,J){if(Z===J)return`\`${Z}\` is the home directory itself, which is never deleted or trashed. Delete a specific file or directory inside it instead.`;for(let $ of M0){if(Z!==$&&!UZ($,Z))continue;return $==="/"?`\`${Z}\` is the filesystem root, which is never deleted.`:`\`${Z}\` is the system root \`${$}\` (or an ancestor of it), which is never deleted or trashed.`}for(let $ of V2){let X=R.join(J,$);if($===".hasna"&&L2(Z,J))continue;if(!UZ(Z,X)&&!UZ(X,Z))continue;return`\`${Z}\` is the protected \`~/${$}\` path (or contains it), which is never deleted or trashed. Delete a specific file inside it, and only when you are sure.`}return null}function P2(Z,J,$){let X=I2($);if(X.some((z)=>UZ(J,z)))return!0;for(let z of Z){let Q=kZ(z.text,J,$);if(Q&&X.some((Y)=>UZ(Q,Y)))return!0}return!1}function NZ(Z,J){let $={cwd:J.cwd,home:J.home,depth:J.depth??0},X={rmHits:[],handoffHits:[],refusals:[],protectedHits:[],trustworthy:!0},z=r(Z);if(X.trustworthy=z.trustworthy,!z.trustworthy)return X;let Q=$.cwd;for(let Y of z.segments){let G=l(Y);if(G<0)continue;let K=MZ(A(Y.words[G].text));if(K==="cd"){let U=Y.words[G+1];if(U){let V=kZ(U.text,Q,$.home);if(V)Q=V;else Q=$.cwd}continue}let H=F0[K];if(H){X.refusals.push({reason:H});continue}if(K==="rm"){let U=C2(Y,G);if(U.length===0)continue;let V={word:Y.words[G],operands:U};if(P2(V.operands,Q,$.home)){X.handoffHits.push(V);continue}X.rmHits.push(V);for(let C of V.operands){let _=kZ(C.text,Q,$.home);if(!_)continue;let O=A2(_,$.home);if(O){X.protectedHits.push({reason:O});break}}continue}if(N2.has(K)){let U=Y.words.findIndex((C,_)=>_>G&&!A(C.text).startsWith("-")),V=U>=0?MZ(A(Y.words[U].text)):"";if(V==="rm"||V in F0)X.refusals.push({reason:`\`${K} ${V}\` runs the ${K} applet, whose own \`rm\` is not GNU \`rm\` and cannot be rewritten in place. Run the delete as \`rm -- <path>\`, which is redirected into trash.`});continue}if(K==="git"){let U=xZ(Y,G);if(U==="rm"||U==="clean"){if(!(U==="rm"?E2(Y,G):C0(Y,G)))X.refusals.push({reason:U==="rm"?"`git rm` is refused: without `--cached` it deletes the working-tree file, and its semantics are not `rm`'s. Use `rm -- <path>` (intercepted and redirected into trash) to remove the file, or `git rm --cached -- <path>` to unstage it without deleting.":"`git clean` deletes untracked files irrecoverably and is refused. Remove them explicitly with `rm -- <path>` (intercepted and redirected into trash), or preview with `git clean -n`."})}continue}if(K==="find"){let U=Y.words.map((_)=>A(_.text));if(U.indexOf("-delete")>=0){X.refusals.push({reason:"`find -delete` deletes files irrecoverably and is refused. List the paths first (`find … -print`), then remove them explicitly with `rm -- <path>` so the delete is redirected into trash."});continue}let C=U.findIndex((_)=>_==="-exec"||_==="-execdir"||_==="-ok");if(C>=0&&U.slice(C).some((_)=>_==="rm"||_==="rmdir"||_==="unlink"||_==="shred")){X.refusals.push({reason:"`find -exec <delete>` is refused: the delete runs through find, not through `rm`, and cannot be redirected into trash. Remove the paths explicitly with `rm -- <path>`."});continue}continue}if(K==="xargs"&&Y.words.some((U)=>A(U.text)==="rm")){X.refusals.push({reason:"`xargs rm` takes its targets from stdin, so this hook cannot verify what would be deleted. Pipe the paths into an explicit `rm -- <path> …` instead, which is redirected into trash."});continue}let B=K==="env"?FZ(Y.words.map((U)=>A(U.text))):O2(Y);if(M2.has(K)&&VZ(B)){X.refusals.push({reason:`\`${K}\` runs a command string this hook cannot rewrite in place. Run the delete directly as \`rm -- <path>\` (intercepted and redirected into trash), or as a script that uses \`trash guard\` itself.`});continue}}if($.depth<3)for(let Y of z.substitutions){let G=NZ(Y,{cwd:Q,home:$.home,depth:$.depth+1});if(G.rmHits.length>0||G.refusals.length>0||G.handoffHits.length>0||G.protectedHits.length>0){X.refusals.push({reason:"This command runs a delete inside a command substitution `$(…)`, which this hook cannot rewrite. Run the delete as a separate `rm -- <path>` command, which is redirected into trash."});break}}else if(z.substitutions.some((Y)=>VZ(Y)))X.refusals.push({reason:"This command nests a delete inside command substitutions deeper than this hook will follow. Run the delete as a separate `rm -- <path>` command."});return X}function O2(Z){return Z.words.map((J)=>J.text).join(" ")}function xZ(Z,J){let $=J+1;while($<Z.words.length){let X=A(Z.words[$].text);if(!X.startsWith("-"))return X;if($++,j2.has(X))$++}return null}function E2(Z,J){if(Z.words.slice(J+1).map((X)=>A(X.text)).includes("--cached"))return!0;return C0(Z,J)}function C0(Z,J){let $=Z.words.slice(J+1).map((X)=>A(X.text));return $.includes("-n")||$.includes("--dry-run")}function q0(Z){if(/^[A-Za-z0-9_\-./+=:,@%^]+$/.test(Z))return Z;return`'${Z.replace(/'/g,"'\\''")}'`}function R2(Z,J,$,X){let z=X?["/usr/bin/env","-i",`HOME=${X.home}`,`PATH=${X.path}`,`HASNA_TRASH_AGENT=${X.agent}`,X.runtime,"--config=/dev/null","--no-env-file","--no-macros","--no-install",$,"guard"].map(q0).join(" "):`${q0($)} guard`,Q=[...J].sort((G,K)=>K.word.start-G.word.start),Y=Z;for(let G of Q)Y=`${Y.slice(0,G.word.start)}${z}${Y.slice(G.word.end)}`;return Y}function v2(Z,J,$,X,z){if(!J||J===Z)return!1;if($.length===0)return!1;let Q=NZ(J,{cwd:X,home:z});if(!Q.trustworthy)return!1;if(Q.rmHits.length>0||Q.handoffHits.length>0)return!1;return Q.refusals.length===0}function y2(Z,J){let $={};for(let[X,z]of Object.entries(Z??{}))$[X]=z;if($.command=J,typeof $.description!=="string"||$.description.trim()==="")$.description=B2;if(typeof $.timeout!=="number"||!Number.isFinite($.timeout)||$.timeout<=0)$.timeout=H2;if(typeof $.run_in_background!=="boolean")$.run_in_background=!1;if("dangerouslyDisableSandbox"in $&&typeof $.dangerouslyDisableSandbox!=="boolean")delete $.dangerouslyDisableSandbox;return $}function S2(Z,J,$,X,z){if(typeof Z.command!=="string"||Z.command.trim()==="")return!1;if(typeof Z.description!=="string"||Z.description.trim()==="")return!1;if(typeof Z.timeout!=="number"||!Number.isFinite(Z.timeout)||Z.timeout<=0)return!1;if(typeof Z.run_in_background!=="boolean")return!1;if("dangerouslyDisableSandbox"in Z&&typeof Z.dangerouslyDisableSandbox!=="boolean")return!1;return v2(J,Z.command,$,X,z)}function b2(Z){let J=new Set(["export","set","unset","readonly","declare","typeset","local","alias","unalias","read","readarray","mapfile","getopts","trap","enable","function","env","sudo","doas","stdbuf"]);return r(Z).segments.some((X)=>{let z=l(X);if(X.words.slice(0,z<0?X.words.length:z).some((G)=>j0.test(A(G.text))||J.has(MZ(A(G.text)))))return!0;if(z<0)return!1;let Y=X.words[z];return J.has(MZ(A(Y.text)))||/^\s*\(\s*\)\s*\{/.test(Z.slice(Y.end))})}function h(Z){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:Z}}}function f2(Z){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"allow",updatedInput:Z}}}function k2(Z){try{if(Z.inspectTrash){let J=Z.inspectTrash();return J.ok?{path:J.path,error:null}:{path:null,error:`${J.code}: ${V0[J.code]}`}}return{path:Z.findTrash(),error:null}}catch(J){return{path:null,error:J instanceof Error?J.message:String(J)}}}var w2="[trash-guard] No verified @hasna/trash guard was found on PATH. This deletion is refused. Install the current @hasna/trash package with Bun and run its setup; the operating-system trash utility is not a compatible guard.";function I0(Z,J){if(Z.hook_event_name!=="PreToolUse")return{continue:!0};if(["apply_patch","ApplyPatch","functions.apply_patch"].includes(Z.tool_name??"")){let H=Z.tool_input?.command;if(typeof H!=="string")return h("[trash-guard] Unreadable patch input; deletion safety cannot be checked.");if(/^\s*\*\*\* Delete File:/m.test(H))return h("[trash-guard] Delete File would bypass recoverable deletion. First use `trash put -- <path>` or the trash_put MCP tool, then submit any remaining edits without the deletion block.");return{continue:!0}}if(Z.tool_name!=="Bash")return{continue:!0};if(typeof Z.tool_input?.command!=="string")return h("[trash-guard] The Bash tool call carried no readable `command`, so this hook cannot verify what would run. Refusing a call it cannot verify. Re-run the delete explicitly as `rm -- <path>` so it can be redirected into trash.");let X=$Z(Z);if(!X.trim())return{continue:!0};let z=NZ(X,{cwd:J.cwd,home:J.home});if(z.refusals.length>0)return h(`[trash-guard] ${z.refusals[0].reason}`);if(z.protectedHits.length>0)return h(`[trash-guard] ${z.protectedHits[0].reason}`);if(!z.trustworthy)return VZ(X)?h("[trash-guard] This command could not be parsed to the end (unterminated quote, substitution or here-document), so a delete inside it cannot be redirected. Re-run the delete as a plain `rm -- <path>` command."):{continue:!0};if(z.rmHits.length===0){if(z.handoffHits.length>0)return{continue:!0};return{continue:!0}}if(z.handoffHits.length>0)return h("[trash-guard] This command mixes a delete under the protected repo-checkout roots (owned by workspace-repos-guard) with a delete outside them, and a partial rewrite would leave one of them unredirected. Re-run them as separate commands, so each delete is handled by the hook that owns it.");let Q=k2(J);if(Q.error!==null)return h(`[trash-guard] The guard could not resolve the \`trash\` binary (${Q.error}), so this \`rm\` cannot be redirected into a recoverable delete — and an unrecoverable delete is never allowed, so the command is refused rather than run. Fix the environment (PATH, permissions) and re-run the same command.`);if(Q.path===null)return h(w2);let Y=Q.path;if(J.execution&&b2(X))return h("[trash-guard] A deletion combined with shell environment changes cannot use the verified native execution context. Run the deletion as a separate plain rm command.");let G=R2(X,z.rmHits,Y,J.execution),K=y2(Z.tool_input,G);if(J.execution)K.hasna_execution="hasna.hooks.execution.v1";if(!S2(K,X,z.rmHits,J.cwd,J.home))return h("[trash-guard] The rewrite of this command did not verify (the delete could not be redirected cleanly), so the command is refused rather than run unredirected. Re-run the delete as a plain `rm -- <path>` command.");return f2(K)}var y=require("node:fs"),mZ=require("node:os"),T=require("node:path");var x2=new Set(["Write","Edit","MultiEdit","NotebookEdit"]),g2=new Set(["apply_patch","ApplyPatch","functions.apply_patch"]),h2=["hasna","hasnaxyz","hasna-products"],_Z="workspace-repos-guard";function u2(Z){return T.join(Z,".hasna","repos","clones")}function l2(Z){return T.join(Z,"workspace","repos")}function P0(Z){return[u2(Z),l2(Z)]}function m2(Z){return T.join(Z,".hasna","hooks","config","workspace-repos-guard-orgs")}var c2=/^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/;function gZ(Z){let J=process.getuid?.();return J!==void 0&&(Z.uid===0||Z.uid===J)&&(Z.mode&18)===0}function p2(Z){let J=m2(Z),$;try{let z=y.openSync(J,y.constants.O_RDONLY|y.constants.O_NOFOLLOW);try{let Y=y.fstatSync(z);if(!Y.isFile()||!gZ(Y)||Y.size>4096)return null;$=y.readFileSync(z,"utf8")}finally{y.closeSync(z)}let Q=T.normalize(Z);for(let Y=T.dirname(J);Y!==Q;Y=T.dirname(Y)){let G=y.lstatSync(Y);if(!G.isDirectory()||!gZ(G)||Y===T.dirname(Y))return null}if(!gZ(y.statSync(Q)))return null}catch{return null}let X=$.replace(/#[^\n]*/g,"").split(/[\s,]+/).filter(Boolean);return X.length>0&&X.every((z)=>c2.test(z))?new Set(X):null}function d2(Z=process.env,J=mZ.homedir()){let $=Z.WORKSPACE_REPOS_GUARD_ORGS;if(typeof $==="string"&&$.trim())return new Set($.split(",").map((X)=>X.trim()).filter(Boolean));return p2(J)??new Set(h2)}function hZ(Z,J,$,X){if(X==="read")return{blocked:!1};let z=T.relative(J,Z);if(z===""){if(X==="delete")return{blocked:!0,reason:`[${_Z}] delete of the protected repo-checkout root is forbidden: ${J}`};return{blocked:!0,reason:`[${_Z}] writes directly to the protected repo-checkout root are forbidden: ${J}`}}if(z.startsWith(`..${T.sep}`)||z===".."||T.isAbsolute(z))return{blocked:!1};let Q=z.split(T.sep).filter(Boolean);if(X==="delete")return{blocked:!0,reason:`[${_Z}] delete under the protected repo-checkout root (${J}) is forbidden at any depth: ${Z}`};if(Q.length<=1)return{blocked:!0,reason:`[${_Z}] writing would create a top-level entry directly under the protected repo-checkout root (${J}); only GitHub-org folders belong there: ${Z}`};let Y=Q[0];if(!$.has(Y))return{blocked:!0,reason:`[${_Z}] '${Y}' is not an allowed GitHub org under the protected repo-checkout root (${J}); allowed: ${[...$].join(", ")}: ${Z}`};return{blocked:!1}}var O0=/\b(?:-o|--output|-O|--output-document|-out)\b/,i2=/\d*[<>]&\s*(?:\d+|-)(?=$|[\s;&|)])/g,s2=/(?:\d+|&)?(?:>>|>\||>&|<>|>)\s*([^\s;&|<>()\x60]*)/g;function E0(Z){return Z.replace(i2," ")}function a2(Z){let J=[],$=null,X=0,z=0,Q=!1,Y=0;for(let G=0;G<Z.length;G++){let K=Z[G];if($==="'"){if(K==="'")$=null;continue}if(K==="\\"){G++;continue}if(K==="("){X++;continue}if(K===")"){if(--X<0)return[Z];continue}if(K==="$"&&Z[G+1]==="{"){z++,G++;continue}if(K==="}"&&z>0){z--;continue}if(K==="`"){Q=!Q;continue}if($==='"'){if(K==='"')$=null;continue}if(K==="'"||K==='"'){$=K;continue}if(K!=="|"||X>0||z>0||Q||Z[G-1]===">")continue;if(J.push(Z.slice(Y,G)),Z[G+1]==="&")G++;Y=G+1}if($||X!==0||z!==0||Q)return[Z];return J.push(Z.slice(Y)),J}function n2(Z){let J=[],$="",X="",z=null,Q=!1,Y=()=>{if(!Q)return;let G=X.replace(/^"?\$\{?HOME\}?"?(?=\/|$)/,""),K=$.startsWith("~")&&!/^~(?:\/|$)/.test(X);J.push({text:K?`./${$}`:$,opaque:/[$\x60*?[]/.test(G)||/[()]/.test(G)}),$="",X="",Q=!1};for(let G=0;G<Z.length;G++){let K=Z[G];if(z==="'"){if(K==="'")z=null;else $+=K;X+=K;continue}if(K==="\\"&&G+1<Z.length){let H=Z[G+1];$+=z==='"'&&!/[$\x60"\\\n]/.test(H)?K+H:H,X+=K+H,Q=!0,G++;continue}if(z==='"'){if(K==='"')z=null;else $+=K;X+=K;continue}if(/\s/.test(K)){Y();continue}if(Q=!0,X+=K,K==="'"||K==='"')z=K;else $+=K}if(z)X+="$";return Y(),J}function uZ(Z,J,$){let X=Z[J];return X==="--help"||X==="--version"||$&&(X==="-h"||X==="-V")}function r2(Z){let J=Z.trim();if(!J)return"read";let $=r(J);if(!$.trustworthy||$.substitutions.length||/\$\{[^}]*[|;()]|[<>]\(/.test(J))return D0(J);let X=$.segments.map((z)=>{let Q=l(z);if(Q<0)return"read";let Y=z.words.filter((K,H)=>H>=Q&&!z.redirects.has(H)).map((K)=>A(K.text)),G=Y[0].split("/").pop();if(["rm","rmdir","shred"].includes(G??""))return uZ(Y,1,!1)?"read":"delete";if(["unlink","rmtree","del"].includes(G??""))return"delete";if(G==="trash"){let K=1;while(K<Y.length&&Y[K].startsWith("-")){let H=Y[K++];if(["--help","-h","--version","-V","--identity"].includes(H))return"read";if(["--agent","--spool","--files","--info","--config"].includes(H))K++;else if(!["--json","--local"].includes(H))return"delete"}if(K===Y.length||["status","doctor","list","info","get","pending","station","setup","backup","storage","retrieval","backup-storage","backup-inspect","backup-refresh","help"].includes(Y[K]))return"read";if(["restore","restore-capsule"].includes(Y[K]))return"write";if(["put","rm","delete","remove"].includes(Y[K])&&uZ(Y,K+1,!0))return"read";return"delete"}if(G==="git"){let K=xZ(z,Q);if(K==="clean"||K==="rm")return Y[1]===K&&uZ(Y,2,!0)?"read":"delete";return K==="clone"||K==="init"?"write":"read"}if(G==="env"&&VZ(FZ(Y)))return"delete";if(["sh","bash","zsh","dash","ksh","ash","eval","source",".","su","runuser","env","xargs","find","busybox","toybox"].includes(G??""))return D0(Y.join(" "));if(["mkdir","mkfile","touch","mv","cp","ln","tee","install","dd","rsync","scp","truncate"].includes(G??""))return"write";if(G==="curl"||G==="wget")return O0.test(Y.join(" "))?"write":"read";if(G==="sed"&&Y.slice(1).some((K)=>/^-i|^--in-place(?:=|$)/.test(K)))return"write";if(["python","python3","node","bun"].includes(G??"")&&Y.some((K)=>K==="-c"||K==="-e"))return"write";return"read"});return X.includes("delete")?"delete":X.includes("write")?"write":"read"}function D0(Z){let J=Z.trim();if(!J)return"read";if(/(?:^|\s)\\?(?:[^\s;&|<>()]*\/)?(?:rm|rmdir|unlink|shred|trash|rmtree|del)(?:\s|$)/.test(J))return"delete";if(/\bgit\b/.test(J)){if(/\bgit\b[^;&|]*\b(?:clean|rm)\b/.test(J))return"delete";if(/\bgit\b[^;&|]*\b(?:clone|init)\b/.test(J))return"write";return"read"}if(/(?:^|\s)\\?(?:[^\s;&|<>()]*\/)?(?:mkdir|mkfile|touch|mv|cp|ln|tee|install|dd)(?:\s|$)/.test(J))return"write";if(/\b(?:curl|wget)\b/.test(J)){if(O0.test(J))return"write";return"read"}if(/\bsed\b/.test(J)){if(/(?:^|\s)-i\S*(?:\s|$)|--in-place(?:\s|$)/.test(J))return"write"}else if(/\b(?:rsync|scp|truncate)\b/.test(J))return"write";else if(/(?:^|\s)(?:python3?|node|bun)\b[^;&|]*\s+-[ce](?:\s|$)/.test(J))return"write";if(/(?:^|[;&|])\s*echo\b/.test(J)||/>/.test(E0(J)))return"write";return"read"}function WZ(Z,J){let $=Z.trim(),X=$.match(/^(['"])([\s\S]*)\1$/);if(X)$=X[2];if($=$.replace(/^"*\$HOME"*\//,"$HOME/"),$=$.replace(/^"*\$\{HOME\}"*\//,"${HOME}/"),$==="~")return J;if($.startsWith("~/"))return T.join(J,$.slice(2));if($==="$HOME"||$==="${HOME}")return J;if($.startsWith("$HOME/"))return T.join(J,$.slice(6));if($.startsWith("${HOME}/"))return T.join(J,$.slice(8));let z=$.match(new RegExp(`^"*${lZ(J)}"*/`));if(z)return J+"/"+$.slice(z[0].length);return Z}function o2(Z){let J=Z.trim();while(J.startsWith("(")||J.startsWith("{"))J=J.slice(1).trim();while(J.endsWith(")")||J.endsWith("}"))J=J.slice(0,-1).trim();return J}function lZ(Z){return Z.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function L0(Z,J,$){if(Z===void 0)return[$];let X=WZ(Z,$),z=X.match(/^(['"])(.*)\1$/);if(z)X=z[2];if(!X||X==="-"||/[$\x60*?[\]{}~\\'"]/.test(X))return null;return[...new Set(J.map((Q)=>T.resolve(Q,X)))]}var t2=/(?:^|\s)(\.\.?|[^\s"';&|<>()\x60/]+(?:\/[^\s"';&|<>()\x60]*)?)\s*$/;function e2(Z){let J=Z.split(`
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
`))
|
|
14
|
-
`),bodies:z}}var V3="/";function v0(Z,J,$){if(!Z)return[];let X=U3(Z);if(!X)return A0(Z,J,$);return[...A0(X.outer,J,$),...X.bodies.flatMap((z)=>v0(z,J,V3))]}function A0(Z,J,$){if(!Z)return[];let X=P0(J),z=(U)=>X.some((V)=>U===V||U.startsWith(`${V}${T.sep}`)),Q=Z.split(/(\s*&&\s*|\s*\|\|\s*|;\s*|\n+)/),Y=[],G=[$],K=new Set([$]),H=!0,B=[];for(let U=0;U<Q.length;U+=2){let V=U===0?"":Q[U-1].trim();if(V==="||")H=!1;else if(V!=="&&")H=!0;if(V!=="&&"||!H)G=[...K];let C=Q[U],_=(C.match(/^[\s({]*/)?.[0].match(/\(/g)??[]).length,O=(C.match(/[\s)}]*$/)?.[0].match(/\)/g)??[]).length;for(let N=0;N<_;N++)B.push({current:[...G],reachable:new Set(K),certain:H});let M=o2(C),j=M.match(/^cd(?:\s+(?:-[A-Za-z@]+|--))*(?:\s+([^\s;&|<>()\x60]+))?$/),c=j?null:M.match(/(?:^|\s)cd(?:\s+(?:-[A-Za-z]+|--))*\s+([^\s;&|<>()\x60]+)/);if(c){for(let N of L0(c[1],G,J)??[])K.add(N);H=!1,G=[...K]}let p=lZ(J),a=X.map((N)=>lZ(N.slice(J.length+1))).join("|"),L=new RegExp(`(?:~|\\$HOME"*|\\$\\{HOME\\}"*|${p}"*)/(?:${a})`),v=new RegExp(`(${L.source})([^\\s"';&|<>()\`]*|$)`,"g"),k=(N)=>{let u=[],b;v.lastIndex=0;while((b=v.exec(N))!==null)u.push(T.normalize(WZ(b[0],J)).replace(/\/+$/,""));return u},w=a2(M).map((N)=>{let u=[],b=!1,e=E0(N).replace(s2,(QZ,n)=>{if(!n||/[$\x60]/.test(n))b=!0;if(n)u.push(n);return" "}),KZ=r2(e);return{commandPart:e,operands:u,op:b&&KZ==="read"?"write":KZ}}),r0=w.some((N)=>N.op==="delete")?"delete":w.some((N)=>N.op==="write")?"write":"read",G0=G.filter(z);for(let N of w){let u=!1;for(let E of k(N.commandPart))u=!0,Y.push({path:E,op:r0});for(let E of N.operands){let g=k(E);for(let f of g)Y.push({path:f,op:"write"});if(g.length>0)continue;for(let f of G0)Y.push({path:T.normalize(T.resolve(f,WZ(E,J))),op:"write"})}if(u||N.op==="read")continue;let b=n2(N.commandPart),e=1,KZ=(b[0]?.text??"").split("/").pop();if(KZ==="trash"&&["put","rm","delete","remove"].includes(b[1]?.text??""))e=2;if(KZ==="git"){let E=b.findIndex((g,f)=>f>0&&(g.text==="rm"||g.text==="clean"));if(E>0)e=E+1}let QZ=!1,n=b.slice(e).flatMap((E)=>{if(!QZ&&E.text==="--")return QZ=!0,[];if(!QZ&&E.text.startsWith("-"))return[];return QZ=!0,[E.opaque?".":E.text]}),o0=N.op==="delete"||/(?:^|\s)\\?(?:[^\s;&|<>()]*\/)?(?:mkdir|mkfile|touch|tee|truncate|install|mv)(?:\s|$)/.test(N.commandPart)||/(?:^|\s)sed(?:\s|$)/.test(N.commandPart)&&/(?:^|\s)(?:-i\S*|--in-place\S*)(?:\s|$)/.test(N.commandPart),YZ=[];if(o0)for(let E of n.length>0?n:["."])YZ.push({operand:E,op:N.op});else{let E=N.commandPart.match(t2),g=b.at(-1);if(YZ.push({operand:E?E[1]:!g||g.opaque?".":g.text,op:N.op}),/(?:^|\s)(?:cp|ln|install|mv)(?:\s|$)/.test(N.commandPart))b.forEach((f,H0)=>{let ZZ,bZ=f.text.match(/^-[A-Za-z]*?t(.*)$/),CZ=f.text.match(/^(--t[a-z-]*)(?:=(.*))?$/);if(bZ&&!f.text.startsWith("--"))ZZ=bZ[1]?{text:bZ[1],opaque:f.opaque}:b[H0+1];else if(CZ&&"--target-directory".startsWith(CZ[1]))ZZ=CZ[2]!==void 0?{text:CZ[2],opaque:f.opaque}:b[H0+1];if(ZZ)YZ.push({operand:ZZ.opaque||!ZZ.text?".":ZZ.text,op:N.op})});if(/(?:^|\s)(?:python3?|node|bun)\b[^;&|]*\s+-[ce](?:\s|$)/.test(N.commandPart))YZ.push({operand:".",op:N.op})}for(let E of G0)for(let{operand:g,op:f}of YZ)Y.push({path:T.normalize(T.resolve(E,WZ(g,J))),op:f})}if(j){let N=L0(j[1],G,J);if(N){for(let u of N)K.add(u);if(H)G=N}else H=!1}for(let N=0;N<O&&B.length>0;N++)({current:G,reachable:K,certain:H}=B.pop())}return Y}var M3=/^\s*\*\*\*\s+(Add File|Update File|Delete File):\s+(\S+)\s*$/gm;function F3(Z,J){let $=[],X;while((X=M3.exec(Z))!==null){let z=X[1]==="Delete File"?"delete":"write";$.push({path:T.normalize(T.resolve(J,X[2])),op:z})}return $}function y0(Z,J={}){let $=[];if(Z.hook_event_name!=="PreToolUse")return{output:{continue:!0},warnings:$};let X=typeof Z.tool_name==="string"?Z.tool_name:"",z=J.home??mZ.homedir(),Q=P0(z),Y=d2(process.env,z);if(X==="Bash"){let V=$Z(Z);if(!V)return{output:{continue:!0},warnings:$};let C=typeof Z.cwd==="string"&&Z.cwd?Z.cwd:process.cwd(),_=v0(V,z,C);for(let O of _)for(let M of Q){let j=hZ(O.path,M,Y,O.op);if(j.blocked)return{output:{decision:"block",reason:j.reason},warnings:$}}return{output:{continue:!0},warnings:$}}let G=Z.tool_input??{},K=typeof Z.cwd==="string"&&Z.cwd?Z.cwd:process.cwd();if(g2.has(X)){let V=typeof G.patch==="string"?G.patch:"";if(!V)return{output:{continue:!0},warnings:$};let C=F3(V,K);for(let _ of C)for(let O of Q){let M=hZ(_.path,O,Y,_.op);if(M.blocked)return{output:{decision:"block",reason:M.reason},warnings:$}}return{output:{continue:!0},warnings:$}}if(!x2.has(X))return{output:{continue:!0},warnings:$};let H=typeof G.file_path==="string"?G.file_path:typeof G.path==="string"?G.path:typeof G.notebook_path==="string"?G.notebook_path:null;if(!H)return{output:{continue:!0},warnings:$};let B=WZ(H,z),U=T.isAbsolute(B)?T.normalize(B):T.resolve(K,B);for(let V of Q){let C=hZ(U,V,Y,"write");if(C.blocked)return{output:{decision:"block",reason:C.reason},warnings:$}}return{output:{continue:!0},warnings:$}}var q3=new Set(["id","node_id","databaseId","fullDatabaseId","number","state","state_reason","stateReason","status","conclusion","bucket","name","login","sha","oid","abbreviatedOid","ref","headRefName","baseRefName","headRefOid","baseRefOid","head_sha","headSha","head_branch","headBranch","merged","mergeable","mergeable_state","mergeStateStatus","draft","isDraft","locked","isLocked","title","displayTitle","display_title","created_at","updated_at","closed_at","merged_at","started_at","completed_at","submitted_at","pushed_at","published_at","createdAt","updatedAt","closedAt","mergedAt","startedAt","completedAt","submittedAt","pushedAt","publishedAt","tag_name","tagName","total_count","totalCount","count","additions","deletions","changes","changed_files","changedFiles","filename","path","event","workflow","workflowName","workflow_id","workflowDatabaseId","run_id","run_number","run_attempt","attempt","check_suite_id","default_branch","defaultBranch","full_name","fullName","nameWithOwner","private","isPrivate","visibility","archived","isArchived","fork","isFork","isRequired","is_required","required","context","type","__typename","role","permission","size","reviewDecision","author_association","authorAssociation","isCrossRepository","maintainerCanModify","maintainer_can_modify","commentsCount","language","digest","size_in_bytes","run_started_at","date","wait_timer","ahead_by","behind_by","total_commits","expired","current_user_can_approve","environment","html_url"]),N3=new Set(["payload","client_payload","inputs","config","metadata","output","properties","custom_properties","variables"]),k0=new Set(["length","utf8bytelength","not","type","any","all","isempty","empty","test","startswith","endswith","contains","inside","has","in","index","rindex","indices","floor","ceil","round","fabs","sqrt","isinfinite","isnan","isnormal","infinite","nan","true","false","null"]),w0=new Set(["tostring","tojson","ascii_downcase","ascii_upcase","ltrimstr","rtrimstr","trim","ltrim","rtrim","sort","unique","reverse","first","last","min","max","add","flatten","join","split","values","nulls","strings","numbers","booleans","arrays","objects","iterables","scalars","sort_by","group_by","unique_by","min_by","max_by","select","limit","to_entries","from_entries"]),_3=new Set(["test","startswith","endswith","contains","inside","has","in","index","rindex","indices","ltrimstr","rtrimstr","join","split","flatten","limit"]),j3=new Set(["@text","@json","@csv","@tsv","@sh","@base64","@uri","@html"]);class dZ extends Error{}var I=()=>{throw new dZ};function cZ(Z,J){let $=[],X="",z=J+1;while(z<Z.length){let Q=Z[z];if(Q==='"'){if(X)$.push(X);return{end:z+1,parts:$}}if(Q==="\\"){let Y=Z[z+1];if(Y==="("){let G=1,K=z+2;while(K<Z.length&&G>0){let H=Z[K];if(H==='"'){K=cZ(Z,K).end;continue}if(H==="(")G++;else if(H===")")G--;K++}if(G!==0)I();if(X)$.push(X),X="";$.push({src:Z.slice(z+2,K-1)}),z=K;continue}if(Y===void 0)I();X+=Y,z+=2;continue}X+=Q,z++}return I()}function x0(Z){let J=[],$=0,X=["?//","|=","+=","-=","*=","/=","%=","//=","==","!=","<=",">=","//","|",",","+","-","*","/","%","<",">","=","(",")","[","]","{","}",":",";","?"];while($<Z.length){let z=Z[$];if(/\s/.test(z)){$++;continue}if(z==="#")I();if(z==='"'){let K=cZ(Z,$);J.push({t:"str",parts:K.parts}),$=K.end;continue}if(z==="."){if(Z[$+1]===".")I();let K=/^[A-Za-z_][A-Za-z0-9_]*/.exec(Z.slice($+1));if(K){J.push({t:"field",name:K[0]}),$+=1+K[0].length;continue}if(Z[$+1]==='"'){let H=cZ(Z,$+1);if(H.parts.some((B)=>typeof B!=="string"))I();J.push({t:"field",name:H.parts.join("")}),$=H.end;continue}J.push({t:"dot"}),$++;continue}if(z==="$"||z==="@"){let K=/^[@$][A-Za-z_][A-Za-z0-9_]*/.exec(Z.slice($));if(!K||z==="$")I();J.push({t:"fmt",name:K[0]}),$+=K[0].length;continue}let Q=/^[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?/.exec(Z.slice($));if(Q){J.push({t:"num"}),$+=Q[0].length;continue}let Y=/^[A-Za-z_][A-Za-z0-9_]*(?:::[A-Za-z_][A-Za-z0-9_]*)*/.exec(Z.slice($));if(Y){J.push({t:"ident",name:Y[0]}),$+=Y[0].length;continue}let G=X.find((K)=>Z.startsWith(K,$));if(!G)I();J.push({t:"op",v:G}),$+=G.length}return J}var W3=new Set(["if","then","elif","else","end","as","def","reduce","foreach","try","catch","label","import","include","and","or","__loc__","error","input","inputs","debug","stderr","env","halt","halt_error","input_filename","input_line_number","recurse","paths","leaf_paths","getpath","setpath","delpaths","del","path","splits","sub","gsub","capture","match","scan","keys","keys_unsorted","map_values","with_entries","tostream","fromstream","truncate_stream","walk","tonumber","implode","explode","ascii","fromjson"]);class iZ{tokens;at=0;constructor(Z){this.tokens=Z}parse(){if(this.tokens.length===0)I();let Z=this.pipe();if(this.at!==this.tokens.length)I();return Z}peek(){return this.tokens[this.at]}isOp(Z){let J=this.peek();return!!J&&J.t==="op"&&J.v===Z}isIdent(Z){let J=this.peek();return!!J&&J.t==="ident"&&J.name===Z}expectOp(Z){if(!this.isOp(Z))I();this.at++}pipe(){let Z=this.comma();if(this.isIdent("as"))I();if(this.isOp("|"))this.at++,Z={k:"pipe",a:Z,b:this.pipe()};return Z}comma(){let Z=this.alt();while(this.isOp(","))this.at++,Z={k:"comma",a:Z,b:this.alt()};return Z}alt(){let Z=this.or();if(this.isOp("//"))return this.at++,{k:"alt",a:Z,b:this.alt()};return Z}or(){let Z=this.and();while(this.isIdent("or"))this.at++,Z={k:"bool",a:Z,b:this.and()};return Z}and(){let Z=this.cmp();while(this.isIdent("and"))this.at++,Z={k:"bool",a:Z,b:this.cmp()};return Z}cmp(){let Z=this.add();for(let J of["==","!=","<=",">=","<",">"])if(this.isOp(J))return this.at++,{k:"bool",a:Z,b:this.add()};for(let J of["=","|=","+=","-=","*=","/=","%=","//=","?//"])if(this.isOp(J))I();return Z}add(){let Z=this.mul();while(this.isOp("+")||this.isOp("-"))this.at++,Z={k:"arith",a:Z,b:this.mul()};return Z}mul(){let Z=this.unary();while(this.isOp("*")||this.isOp("/")||this.isOp("%"))this.at++,Z={k:"arith",a:Z,b:this.unary()};return Z}unary(){if(this.isOp("-"))return this.at++,{k:"neg",of:this.postfix()};return this.postfix()}objectValue(){let Z=this.unary();if(this.isOp("|"))this.at++,Z={k:"pipe",a:Z,b:this.objectValue()};return Z}postfix(){let Z=this.primary();for(;;){let J=this.peek();if(!J)return Z;if(J.t==="field"){this.at++,Z={k:"field",name:J.name,of:Z};continue}if(J.t==="dot"&&this.tokens[this.at+1]?.t==="op"&&this.tokens[this.at+1].v==="["){this.at++;continue}if(J.t==="op"&&J.v==="?"){this.at++,Z={k:"opt",of:Z};continue}if(J.t==="op"&&J.v==="["){Z=this.bracket(Z);continue}return Z}}bracket(Z){if(this.expectOp("["),this.isOp("]"))return this.at++,{k:"iter",of:Z};if(this.isOp(":")){if(this.at++,!this.isOp("]"))this.pipe();return this.expectOp("]"),{k:"slice",of:Z}}let J=this.pipe();if(this.isOp(":")){if(this.at++,!this.isOp("]"))this.pipe();return this.expectOp("]"),{k:"slice",of:Z}}return this.expectOp("]"),{k:"index",of:Z,key:J}}primary(){let Z=this.peek();if(!Z)return I();switch(this.at++,Z.t){case"dot":return{k:"dot"};case"field":return{k:"field",name:Z.name};case"num":return{k:"lit"};case"str":return this.stringNode(Z.parts);case"fmt":{if(!j3.has(Z.name))I();let J=this.peek();if(J?.t==="str")return this.at++,{k:"fmt",name:Z.name,str:this.stringNode(J.parts)};return{k:"fmt",name:Z.name}}case"ident":{if(W3.has(Z.name))I();if(Z.name==="map"||k0.has(Z.name)||w0.has(Z.name)){let J=[];if(this.isOp("(")){this.at++,J.push(this.pipe());while(this.isOp(";"))this.at++,J.push(this.pipe());this.expectOp(")")}return{k:"call",name:Z.name,args:J}}return I()}case"op":{if(Z.v==="("){let J=this.pipe();return this.expectOp(")"),J}if(Z.v==="["){if(this.isOp("]"))return this.at++,{k:"array"};let J=this.pipe();return this.expectOp("]"),{k:"array",of:J}}if(Z.v==="{")return this.object();return I()}}return I()}stringNode(Z){let J=[];for(let $ of Z){if(typeof $==="string")continue;J.push(new iZ(x0($.src)).parse())}return J.length===0?{k:"str",parts:J,text:Z.join("")}:{k:"str",parts:J}}object(){let Z=[];if(this.isOp("}"))return this.at++,{k:"object",entries:Z};for(;;){let J=this.peek();if(!J)I();this.at++;let $;if(J.t==="ident")$=J.name;else if(J.t==="str"){if(J.parts.some((X)=>typeof X!=="string"))I();$=J.parts.join("")}else I();if(this.isOp(":"))this.at++,Z.push({key:"static",value:this.objectValue()});else Z.push({key:"static",value:{k:"field",name:$}});if(this.isOp(",")){this.at++;continue}return this.expectOp("}"),{k:"object",entries:Z}}}}function sZ(Z){if(typeof Z==="object"&&"union"in Z)return Z.union.every(sZ);return Z==="safe"||typeof Z==="object"&&q3.has(Z.leaf)}var TZ=(...Z)=>Z.every(sZ)?"safe":"tainted";function pZ(...Z){let J=[];for(let $ of Z)if(typeof $==="object"&&"union"in $)J.push(...$.union);else J.push($);return J.length===1?J[0]:{union:J}}function AZ(Z,J){return typeof Z==="object"&&"union"in Z?pZ(...Z.union.map(J)):J(Z)}var PZ=(Z)=>typeof Z==="object"&&("leaf"in Z)&&N3.has(Z.leaf),d=(Z)=>AZ(Z,(J)=>J==="safe"?"safe":J==="tainted"||PZ(J)?"tainted":"unknown");function S0(Z){return Z.k==="lit"||Z.k==="str"&&Z.parts.length===0||Z.k==="call"&&["true","false","null"].includes(Z.name)&&Z.args.length===0}function b0(Z,J,$){return AZ(Z,(X)=>{if(X==="safe"||X==="tainted")return X;if(PZ(X))return"tainted";if(X==="root"&&$.rootScalars.has(J))return"safe";return{leaf:J}})}function D(Z,J,$){switch(Z.k){case"dot":return J;case"field":return b0(Z.of?D(Z.of,J,$):J,Z.name,$);case"iter":return d(D(Z.of,J,$));case"index":{let X=D(Z.of,J,$);if(Z.key.k==="str"&&Z.key.text!==void 0)return b0(X,Z.key.text,$);if(Z.key.k==="lit")return d(X);return D(Z.key,J,$),"tainted"}case"slice":return AZ(D(Z.of,J,$),(X)=>X==="root"?"unknown":PZ(X)?"tainted":X);case"opt":return D(Z.of,J,$);case"lit":return"safe";case"str":return TZ(...Z.parts.map((X)=>D(X,J,$)));case"fmt":return Z.str?D(Z.str,J,$):J;case"array":return Z.of?TZ(D(Z.of,J,$)):"safe";case"object":return TZ(...Z.entries.map((X)=>D(X.value,J,$)));case"pipe":return D(Z.b,D(Z.a,J,$),$);case"comma":return pZ(D(Z.a,J,$),D(Z.b,J,$));case"alt":return pZ(D(Z.a,J,$),D(Z.b,J,$));case"bool":return D(Z.a,J,$),D(Z.b,J,$),"safe";case"arith":return TZ(D(Z.a,J,$),D(Z.b,J,$));case"neg":return D(Z.of,J,$);case"call":return T3(Z,J,$)}}var f0=(Z)=>AZ(Z,(J)=>J==="root"?"unknown":PZ(J)?"tainted":J);function T3(Z,J,$){let{name:X,args:z}=Z;if(_3.has(X)&&X!=="limit"&&!z.every(S0))I();switch(X){case"map":if(z.length!==1)I();return TZ(D(z[0],d(J),$));case"select":if(z.length!==1)I();return D(z[0],J,$),J;case"limit":if(z.length!==2||!S0(z[0]))I();return D(z[1],J,$);case"first":case"last":if(z.length>1)I();return z.length===1?D(z[0],J,$):d(J);case"min":case"max":return d(J);case"sort_by":case"group_by":case"unique_by":if(z.length!==1)I();return D(z[0],d(J),$),f0(J);case"min_by":case"max_by":if(z.length!==1)I();return D(z[0],d(J),$),d(J);case"any":case"all":case"isempty":for(let Q of z)D(Q,"unknown",$);return"safe"}if(k0.has(X))return"safe";if(w0.has(X))return f0(J);return I()}function g0(Z,J={}){if(typeof Z!=="string"||!Z.trim()||Z.length>4096)return!1;try{let $=new iZ(x0(Z)).parse();return sZ(D($,"root",{rootScalars:J.rootScalars??new Set}))}catch($){if($ instanceof dZ)return!1;return!1}}var J0="composite output withheld: signed-link shape; use bounded scalar projections per class disposition 799310",q={refused:!1},F=(Z)=>({refused:!0,rule:Z}),aZ=new Set(["additions","assignees","author","baseRefName","baseRefOid","changedFiles","closed","closedAt","createdAt","deletions","files","fullDatabaseId","headRefName","headRefOid","headRepository","headRepositoryOwner","id","isCrossRepository","isDraft","labels","maintainerCanModify","mergeCommit","mergeStateStatus","mergeable","mergedAt","mergedBy","number","potentialMergeCommit","reactionGroups","reviewDecision","reviewRequests","state","title","updatedAt","url"]),nZ=new Set(["assignees","author","closed","closedAt","createdAt","id","isPinned","labels","number","reactionGroups","state","stateReason","subIssuesSummary","title","updatedAt","url"]),h0=new Set(["apiUrl","author","createdAt","databaseId","id","isDraft","isImmutable","isLatest","isPrerelease","name","publishedAt","tagName","tarballUrl","targetCommitish","uploadUrl","url","zipballUrl"]),u0=new Set(["answerChosenAt","answerChosenBy","answered","author","closed","closedAt","createdAt","id","labels","locked","number","reactionGroups","state","stateReason","title","updatedAt","url"]),C3=new Set(["assignees","author","authorAssociation","closedAt","commentsCount","createdAt","id","isDraft","isLocked","isPullRequest","labels","number","repository","state","title","updatedAt","url"]),I3=new Set(["author","committer","id","parents","repository","sha","url"]),D3=new Set(["bucket","completedAt","event","name","startedAt","state","workflow"]);function c0(Z){let J=[];for(let $=0;$<Z.length;$++){let X=Z[$];if(X==="\\"){$++;continue}if(X==="'"){let z=Z.indexOf("'",$+1);if(z<0)return!1;$=z;continue}if(X==='"'){$++;while($<Z.length&&Z[$]!=='"')$+=Z[$]==="\\"?2:1;continue}if(X==="{"){J.push({list:!1});continue}if(J.length===0)continue;if(X===","||X==="."&&Z[$+1]===".")J[J.length-1].list=!0;else if(X==="}"&&J.pop().list)return!0}return!1}function XZ(Z){let J="",$=!1,X=0,z=(Q)=>Z[Q]==="`"||Z[Q]==="$"&&/[A-Za-z_{(@*#?$!0-9-]/.test(Z[Q+1]??"");while(X<Z.length){let Q=Z[X];if(Q==="\\"){J+=Z[X+1]??"",X+=2;continue}if(Q==="$"&&Z[X+1]==="'"){$=!0,J+=Q,X++;continue}if(Q==="'"){let Y=Z.indexOf("'",X+1);if(Y<0){$=!0,J+=Z.slice(X+1);break}J+=Z.slice(X+1,Y),X=Y+1;continue}if(Q==='"'){X++;while(X<Z.length&&Z[X]!=='"'){if(Z[X]==="\\"&&/[$`"\\\n]/.test(Z[X+1]??"")){J+=Z[X+1],X+=2;continue}if(z(X))$=!0;J+=Z[X],X++}if(X>=Z.length)$=!0;X++;continue}if(z(X)||Q==="*"||Q==="?"||Q==="[")$=!0;J+=Q,X++}if(!$&&Z.includes("{")&&c0(Z))$=!0;return{value:J,opaque:$,raw:Z}}var o=(Z)=>Z.slice(Z.lastIndexOf("/")+1);function tZ(Z,J="word"){let $=[],X=!1;for(let z=0;z<Z.length;z++){let Q=Z[z];if(Q==="\\"){z++;continue}if(J==="word"&&Q==="'"&&!X){let Y=Z.indexOf("'",z+1);if(Y<0)return{bodies:$,complete:!1};z=Y;continue}if(J==="word"&&Q==='"'){X=!X;continue}if(Q==="`"){let Y=z+1;while(Y<Z.length&&Z[Y]!=="`")Y+=Z[Y]==="\\"?2:1;if(Y>=Z.length)return{bodies:$,complete:!1};$.push(Z.slice(z+1,Y)),z=Y;continue}if(Q==="$"&&Z[z+1]==="("){let Y=qZ(Z,z+1);if(Y<0)return{bodies:$,complete:!1};$.push(Z.slice(z+2,Y-1)),z=Y-1}}return{bodies:$,complete:!0}}function zZ(Z,J){let $=new Set(J.values),X={flags:[],positionals:[]},z=(Q,Y)=>({value:Q,opaque:Y.opaque,raw:Y.raw});for(let Q=0;Q<Z.length;Q++){let Y=Z[Q],G=Y.value;if(G==="--"){X.positionals.push(...Z.slice(Q+1));break}if(G.startsWith("--")&&G.length>2){let K=G.indexOf("="),H=K>=0?G.slice(0,K):G;if(K>=0)X.flags.push({name:H,value:z(G.slice(K+1),Y),inline:!0});else if($.has(H)){let B=Z[Q+1];X.flags.push(B?{name:H,value:B}:{name:H,missing:!0}),Q++}else X.flags.push({name:H});continue}if(G.startsWith("-")&&G.length>1){for(let K=1;K<G.length;K++){let H="-"+G[K],B=G.slice(K+1);if(B.startsWith("=")){X.flags.push({name:H,value:z(B.slice(1),Y),inline:!0});break}if(!$.has(H)){X.flags.push({name:H});continue}if(B)X.flags.push({name:H,value:z(B,Y),inline:!0});else{let U=Z[Q+1];X.flags.push(U?{name:H,value:U}:{name:H,missing:!0}),Q++}break}continue}X.positionals.push(Y)}return X}function S(Z,...J){let $=!1;for(let X of Z.flags){if(!J.includes(X.name))continue;if(!X.inline){$=!0;continue}let z=X.value;$=!z.opaque&&["1","t","T","TRUE","true","True"].includes(z.value)}return $}var s=(Z,...J)=>Z.flags.filter(($)=>J.includes($.name)),x=["-R","--repo","-q","--jq","-t","--template","--json"],t={"pr view":{values:x},"issue view":{values:x},"release view":{values:x},"discussion view":{values:[...x,"--after","-L","--limit","--order"]},"pr list":{values:[...x,"--app","-a","--assignee","-A","--author","-B","--base","-H","--head","-l","--label","-L","--limit","-S","--search","-s","--state"]},"issue list":{values:[...x,"--app","-a","--assignee","-A","--author","-l","--label","-L","--limit","--mention","-m","--milestone","-S","--search","-s","--state"]},"discussion list":{values:[...x,"--after","-A","--author","-c","--category","-l","--label","-L","--limit","--order","-S","--search","--sort","-s","--state"]},"release list":{values:[...x,"-L","--limit","-O","--order"]},"pr status":{values:x},"issue status":{values:x},"pr checks":{values:[...x,"-i","--interval"]},"pr diff":{values:["-R","--repo"]},search:{values:[...x,"--app","--assignee","--author","--author-date","--author-email","--author-name","--base","--checks","--closed","--commenter","--committer","--committer-date","--committer-email","--committer-name","--created","--hash","--head","--interactions","--involves","--label","--language","--limit","-L","--match","--mentions","--merged-at","--milestone","--no-assignee","--no-label","--no-milestone","--no-project","--order","--owner","--parent","--project","--reactions","--review","--review-requested","--reviewed-by","--sort","--state","--team-mentions","--tree","--updated","--visibility","--extension","--filename","--size","--forks","--good-first-issue","--help-wanted-issues","--number-topics","--stars","--topic","--followers","--include-forks","--license"]},"project item-list":{values:["--format","-L","--limit","--owner","-q","--jq","-t","--template","--query","--field","--field-id"]},api:{values:["-X","--method","-H","--header","-f","--raw-field","-F","--field","-q","--jq","-t","--template","-p","--preview","--input","--hostname","--cache"]},group:{values:["-R","--repo"]}},L3=new Set(["auth","browse","codespace","cs","gist","org","repo","skill","cache","run","workflow","co","agent-task","alias","attestation","completion","config","copilot","extension","ext","extensions","gpg-key","label","licenses","preview","ruleset","secret","ssh-key","variable","help","version","accessibility","actions","environment","exit-codes","formatting","mintty","reference","telemetry"]),A3=new Set(["pr","issue","release","discussion","search","project","api","status"]),P3=new Set(["create","new","checkout","co","close","comment","edit","lock","merge","ready","reopen","revert","review","unlock","update-branch"]),O3=new Set(["create","new","close","comment","delete","develop","edit","lock","pin","reopen","transfer","unlock","unpin"]),E3=new Set(["create","new","delete","delete-asset","download","edit","upload","verify","verify-asset"]),R3=new Set(["create","new","close","comment","delete","edit","lock","reopen","unlock","answer","unanswer"]);function vZ(Z,J){let $=s(Z,"--json"),X=[],z=!1;for(let Q of $){if(Q.missing){if(J.appendsArgs)z=!0;continue}if(!Q.value)continue;if(Q.value.opaque)z=!0;X.push(...Q.value.value.split(",").map((Y)=>Y.trim()).filter(Boolean))}return{present:$.length>0,opaque:z,fields:X}}function X0(Z,J){if(S(Z,"--verbose")||s(Z,"-t","--template").length>0)return!1;let $=s(Z,"-q","--jq");return $.length>0&&$.every((X)=>X.value!==void 0&&!X.value.opaque&&g0(X.value.value,{rootScalars:J}))}function z0(Z,J,$,X){let z=vZ(Z,$);if(z.opaque)return F("unclassifiable");if(z.fields.every((Q)=>J.has(Q)))return q;if($.debug)return F("debug-traffic");return X0(Z)?q:F(X)}function OZ(Z,J,$,X,z){let Q=zZ(Z,t[J]);if(S(Q,"-h","--help"))return q;if(S(Q,"-w","--web"))return X.debug?F("debug-traffic"):q;if(z&&S(Q,"-c","--comments"))return F("view-comments");if(!vZ(Q,X).present)return F(X.debug?"debug-traffic":"view-human");return z0(Q,$,X,"json-composite")}function i(Z,J,$,X){let z=zZ(Z,t[J]);if(S(z,"-h","--help"))return q;if(X.debug&&(S(z,"-w","--web")||!vZ(z,X).present))return F("debug-traffic");if(S(z,"-w","--web"))return q;return z0(z,$,X,"json-composite")}function v3(Z,J){let $=zZ(Z,t["pr checks"]);if(S($,"-h","--help"))return q;if(J.debug)return F("debug-traffic");if(S($,"-w","--web"))return q;if(!vZ($,J).present)return F("checks-human");return z0($,D3,J,"checks-json")}function y3(Z){let J=new Set(t.group.values);for(let $=0;$<Z.length;$++){let X=Z[$].value;if(X==="--")return{sub:Z[$+1],rest:Z.slice($+2)};if(!X.startsWith("-")||X==="-")return{sub:Z[$],rest:[...Z.slice(0,$),...Z.slice($+1)]};if(J.has(X))$++}return{rest:Z}}function S3(Z,J,$){let{sub:X,rest:z}=y3(J);if(!X)return $.appendsArgs?F("unclassifiable"):q;if(X.opaque)return F("unclassifiable");let Q=X.value;if((Z==="pr"?P3:Z==="issue"?O3:Z==="release"?E3:Z==="discussion"?R3:new Set).has(Q))return $.debug?F("debug-traffic"):q;if($.appendsArgs&&!(Z==="project"&&Q!=="item-list"))return F("unclassifiable");switch(Z){case"pr":if(Q==="view")return OZ(z,"pr view",aZ,$,!0);if(Q==="list"||Q==="ls")return i(z,"pr list",aZ,$);if(Q==="status")return i(z,"pr status",aZ,$);if(Q==="checks")return v3(z,$);if(Q==="diff"){let G=zZ(z,t["pr diff"]);if(S(G,"-h","--help"))return q;if($.debug)return F("debug-traffic");return S(G,"--patch")?F("composite-other"):q}return F("unclassifiable");case"issue":if(Q==="view")return OZ(z,"issue view",nZ,$,!0);if(Q==="list"||Q==="ls")return i(z,"issue list",nZ,$);if(Q==="status")return i(z,"issue status",nZ,$);return F("unclassifiable");case"release":if(Q==="view")return OZ(z,"release view",h0,$,!1);if(Q==="list"||Q==="ls")return i(z,"release list",h0,$);return F("unclassifiable");case"discussion":if(Q==="view")return OZ(z,"discussion view",u0,$,!0);if(Q==="list"||Q==="ls")return i(z,"discussion list",u0,$);return F("unclassifiable");case"search":if(Q==="prs"||Q==="issues")return i(z,"search",C3,$);if(Q==="commits")return i(z,"search",I3,$);if(Q==="code"||Q==="repos")return $.debug?F("debug-traffic"):q;return F("unclassifiable");case"project":{if($.debug)return F("debug-traffic");if(Q!=="item-list")return q;let G=zZ(z,t["project item-list"]);if(S(G,"-h","--help"))return q;let K=s(G,"--format");if(K.some((H)=>!H.value||H.value.opaque))return F("unclassifiable");if(K.every((H)=>H.value.value!=="json"))return q;return X0(G)?q:F("composite-other")}}return F("unclassifiable")}var p0=new Set(["pulls","issues","commits","check-runs","check-suites","statuses","comments","releases","compare","events","discussions","deployments","milestones"]);function b3(Z){let J=Z.value.trim(),$=/^https?:\/\/([^/]+)(\/.*)?$/i.exec(J);if($){let Q=$[1].toLowerCase(),Y=$[2]??"/";if(Q==="api.github.com"||/^api\./.test(Q))J=Y;else if(/^\/api\/v3(?:\/|$)/i.test(Y))J=Y.replace(/^\/api\/v3/i,"");else if(/^\/api\/graphql(?:[/?#]|$)/i.test(Y))J="graphql";else return null}J=J.replace(/[?#].*$/,"");let X=[],z=[];for(let Q of J.split("/")){let Y;try{Y=decodeURIComponent(Q)}catch{return null}for(let G of Y.split("/")){if(G===""||G===".")continue;if(G===".."){X.pop(),z.pop();continue}X.push(G.toLowerCase()),z.push(Z.opaque&&/[$`]/.test(G)||/[*?[]/.test(G)||c0(G))}}return{segments:X,opaque:z}}function f3(Z){let J=b3(Z);if(!J)return{kind:"unclassifiable",segments:[]};let{segments:$,opaque:X}=J,z=(K)=>({kind:K,segments:$});if($.length===1&&$[0]==="graphql")return z("graphql");if($.length===0)return z(Z.opaque?"unclassifiable":"other");if(X[0])return z("unclassifiable");let Q,Y=[];if($[0]==="repos")Q=$.slice(3),Y=X.slice(3);else if($[0]==="repositories")Q=$.slice(2),Y=X.slice(2);if(Q){if(($[0]==="repos"?X.slice(1,3):X.slice(1,2)).some(Boolean)){let H=X.findIndex(Boolean),B=$.findIndex((U,V)=>V>H&&!X[V]&&k3.has(U));return z(B<0?"unclassifiable":l0($.slice(B),X.slice(B)))}return z(l0(Q,Y))}let G=$[0];if(G==="issues")return z("sensitive");if(G==="user"&&$[1]==="issues")return z("sensitive");if(G==="orgs"&&$[2]==="issues")return z("sensitive");if(G==="search")return z($[1]==="issues"||$[1]==="commits"?"sensitive":$[1]!==void 0&&X[1]?"unclassifiable":"other");if(G==="events"||G==="networks")return z("sensitive");if((G==="users"||G==="orgs")&&$.slice(2).some((K)=>K==="events"||K==="received_events"||K==="discussions"))return z("sensitive");if((G==="users"||G==="orgs")&&$[2]==="projectsv2"&&$[4]==="items")return z("sensitive");if(G==="orgs"&&$[2]==="hooks"&&$[4]==="deliveries"&&$[5]!==void 0||G==="app"&&$[1]==="hook"&&$[2]==="deliveries"&&$[3]!==void 0)return z("sensitive");if(G==="teams"&&$.includes("discussions"))return z("sensitive");if(G==="projects"&&$.includes("cards"))return z("sensitive");if(X.some(Boolean))return z($.some((K)=>K==="events"||K==="discussions"||K==="issues")?"sensitive":"unclassifiable");return z("other")}var k3=new Set([...p0,"branches","git","actions","hooks","zipball","tarball"]);function l0(Z,J){let[$,X]=Z;if($===void 0)return"other";if(J[0])return"unclassifiable";if($==="issues"&&/^\d+$/.test(X??"")&&Z[2]==="labels")return"other";if(p0.has($))return"sensitive";if($==="branches"){if(Z.length===1||Z.slice(1).some((z)=>z==="protection")||Z[Z.length-1]==="rename")return"other";return J.slice(1).some(Boolean)?"unclassifiable":"sensitive"}if($==="git")return X===void 0||X==="commits"||X==="tags"?"sensitive":J[1]?"unclassifiable":"other";if($==="actions"){if(X===void 0)return"sensitive";if(J[1])return"unclassifiable";if(X==="runs"||X==="jobs"){if(Z[Z.length-1]==="logs"&&Z.length>=4&&!J.some(Boolean))return"download";return"sensitive"}if(X==="workflows"&&Z[3]==="runs")return"sensitive";if(X==="artifacts"&&Z.length===4)return"download";return"other"}if($==="hooks"&&Z[2]==="deliveries"&&Z[3]!==void 0)return"sensitive";if($==="zipball"||$==="tarball")return"download";return"other"}function w3(Z,J){if(J[0]!=="repos"||J.length<5)return!1;let $=J.slice(3),X=(Q)=>/^\d+$/.test($[Q]??""),z=(...Q)=>$.length===Q.length&&Q.every((Y,G)=>typeof Y==="number"?X(G):$[G]===Y);if(Z==="DELETE")return z("issues","comments",0)||z("pulls","comments",0)||z("comments",0)||z("issues","comments",0,"reactions",0)||z("pulls","comments",0,"reactions",0)||z("issues",0,"reactions",0)||z("issues",0,"labels")||$.length===4&&$[0]==="issues"&&X(1)&&$[2]==="labels"||z("releases",0)||z("releases","assets",0)||z("actions","runs",0)||z("actions","runs",0,"logs")||z("deployments",0)||z("milestones",0)||z("issues",0,"lock");if(Z==="POST")return $.length===4&&$[0]==="actions"&&$[1]==="runs"&&X(2)&&["rerun","rerun-failed-jobs","cancel","force-cancel","approve"].includes($[3])||z("actions","jobs",0,"rerun")||z("issues",0,"labels");if(Z==="PUT")return z("pulls",0,"merge")||z("pulls",0,"update-branch")||z("issues",0,"labels")||z("issues",0,"lock");if(Z==="GET")return z("pulls",0,"merge");return!1}function x3(Z){if(Z[0]!=="repos"||Z.length!==5||!/^\d+$/.test(Z[4]))return;if(Z[3]==="pulls")return new Set(["commits","comments","review_comments"]);if(Z[3]==="issues")return new Set(["comments"]);return}var g3=new Set(["body","bodyText","bodyHTML","bodyUrl","bodyResourcePath","comments","reviews","latestReviews","latestOpinionatedReviews","reviewThreads","url","permalink","summary","text","description","message","messageBody","messageHeadline","commitBody","commitHeadline","annotations","rawDetails","note","diff","readme","payload"]),h3=new Set(["checkRuns","checkRun","checkSuites","checkSuite","contexts","statusCheckRollup","annotations","CheckRun","CheckSuite","StatusContext","CheckAnnotation","latestStatus","status","statuses"]);function u3(Z){let J=[],$=0;while($<Z.length){let X=Z[$];if(/[\s,]/.test(X)){$++;continue}if(X==="#"){let Y=Z.indexOf(`
|
|
15
|
-
|
|
16
|
-
`)
|
|
17
|
-
`).
|
|
18
|
-
|
|
19
|
-
`,X)+1,Y=Z.indexOf(`
|
|
20
|
-
|
|
1
|
+
var{defineProperty:oZ,getOwnPropertyNames:S2,getOwnPropertyDescriptor:b2}=Object,f2=Object.prototype.hasOwnProperty;function k2(Z){return this[Z]}var x2=(Z)=>{var X=(f0??=new WeakMap).get(Z),$;if(X)return X;if(X=oZ({},"__esModule",{value:!0}),Z&&typeof Z==="object"||typeof Z==="function"){for(var J of S2(Z))if(!f2.call(X,J))oZ(X,J,{get:k2.bind(Z,J),enumerable:!($=b2(Z,J))||$.enumerable})}return f0.set(Z,X),X},f0;var w2=(Z)=>Z;function h2(Z,X){this[Z]=w2.bind(null,X)}var g2=(Z,X)=>{for(var $ in X)oZ(Z,$,{get:X[$],enumerable:!0,configurable:!0,set:h2.bind(X,$)})};var W5={};g2(W5,{version:()=>U5,evaluate:()=>j5,abi:()=>V5});module.exports=x2(W5);var sZ=require("node:os"),E0=require("node:path");var S=require("node:path");var y=require("node:path"),F=require("node:fs"),k0=require("node:child_process"),x0={missing:"No verified @hasna/trash guard was found on PATH.",unsafe_executable:"The Trash candidate is not an owned executable file or is writable by group or others.",unsafe_manifest:"The Trash package manifest is not a safe owned regular file.",unsafe_directory:"A Trash PATH or package directory is not owned safely or is writable by group or others.",unsafe_interpreter:"The Trash interpreter is missing, unsupported, or not a safe owned executable on its actual PATH.",unrecognized_package:"The candidate is not the registered @hasna/trash executable.",identity_failed:"The installed Trash identity probe failed or exceeded its deadline.",unsupported_protocol:"The installed Trash version does not expose the required guard protocol."};function _Z(Z){return Z===0||Z===process.getuid?.()}function SZ(Z,X=!1){let $=Z;for(let J=0;J<32;J++){if(!y.isAbsolute($)||$.length>4096||!IZ("/"))return!1;let z=$.split("/"),Y=z.pop();if(!Y||Y==="."||Y==="..")return!1;let Q="/";for(let B of z){if(!B||B===".")continue;if(B===".."){Q=y.dirname(Q);continue}let M=y.join(Q,B),V=F.lstatSync(M);if(X&&M==="/bin"&&V.isSymbolicLink()&&V.uid===0){let G=F.realpathSync(M);if(!IZ(G))return!1;Q=G;continue}if(!V.isDirectory()||!_Z(V.uid)||V.mode&18)return!1;Q=M}let H=y.join(Q,Y),K=F.lstatSync(H);if(!_Z(K.uid))return!1;if(K.isSymbolicLink()){let B=F.readlinkSync(H);$=y.isAbsolute(B)?B:Q+"/"+B;continue}return K.isFile()&&Boolean(K.mode&73)&&!(K.mode&18)}return!1}function u2(Z){if(!y.isAbsolute(Z)||y.resolve(Z)!==(Z.replace(/\/+$/,"")||"/"))return!1;for(let X=y.resolve(Z);;X=y.dirname(X)){try{return F.lstatSync(X),IZ(X)}catch($){if($.code!=="ENOENT")return!1}if(y.dirname(X)===X)return!1}}function l2(Z,X){let $=F.openSync(Z,F.constants.O_RDONLY|F.constants.O_NONBLOCK|F.constants.O_NOFOLLOW),J;try{if(!F.fstatSync($).isFile())return!1;let Y=Buffer.alloc(256),Q=F.readSync($,Y,0,Y.length,0);J=Y.subarray(0,Q).toString("utf8").split(`
|
|
2
|
+
`)[0]}finally{F.closeSync($)}let z=/^#!(\/[A-Za-z0-9_./-]+)$/.exec(J);if(z&&z[1]!=="/usr/bin/env")return SZ(z[1],!0);if(J!=="#!/usr/bin/env bun"||!SZ("/usr/bin/env",!0))return!1;for(let Y of X.split(":").slice(0,64)){if(!u2(Y))return!1;let Q=y.resolve(Y,"bun");try{if(!F.statSync(Q).isFile())continue;F.accessSync(Q,F.constants.X_OK)}catch{continue}return SZ(Q,!0)}return!1}function IZ(Z){let X=Z;for(;;){let $=F.lstatSync(X);if(!$.isDirectory()||!_Z($.uid)||($.mode&18)!==0)return!1;let J=y.dirname(X);if(J===X)return!0;X=J}}function TZ(Z=process.env){let X=Z.PATH??"",$=Date.now()+2000,J="missing",z=(Y)=>{if(J==="missing"||J==="unrecognized_package"||Y.startsWith("unsafe_"))J=Y};for(let Y of X.split(":").slice(0,64)){if(!y.isAbsolute(Y)||Date.now()>=$)continue;let Q=y.resolve(Y,"trash");try{let H=F.statSync(Q);if(!H.isFile()||!_Z(H.uid)||(H.mode&73)===0||(H.mode&18)!==0){z("unsafe_executable");continue}let K=F.realpathSync(Q);if(!IZ(y.resolve(Y))||!IZ(y.dirname(K))){z("unsafe_directory");continue}if(!SZ(Q)){z("unsafe_directory");continue}let B=y.resolve(y.dirname(K),"../.."),M=y.join(B,"package.json"),V=F.statSync(M);if(!V.isFile()||!_Z(V.uid)||V.size>16384||(V.mode&18)!==0||F.lstatSync(M).isSymbolicLink()){z("unsafe_manifest");continue}let G=JSON.parse(F.readFileSync(M,"utf8"));if(G.name!=="@hasna/trash"||typeof G.version!=="string"||typeof G.bin?.trash!=="string"||F.realpathSync(y.resolve(B,G.bin.trash))!==K){z("unrecognized_package");continue}try{if(!l2(K,X)){z("unsafe_interpreter");continue}}catch{z("unsafe_interpreter");continue}let j=$-Date.now();if(j<=0){z("identity_failed");break}let D=k0.spawnSync(Q,["--identity"],{encoding:"utf8",timeout:j,maxBuffer:2048,env:{PATH:X},stdio:["ignore","pipe","pipe"]});if(D.error||D.status!==0||Date.now()>=$){z("identity_failed");continue}let v=JSON.parse(D.stdout);if(v.name==="@hasna/trash"&&v.version===G.version&&v.guardProtocol==="hasna.trash.guard.v1")return{ok:!0,path:Q,version:G.version};z("unsupported_protocol")}catch{}}return{ok:!1,code:J}}function bZ(Z=process.env){let X=TZ(Z);return X.ok?X.path:null}function BZ(Z){let X=Z.tool_input?.command;return typeof X==="string"?X:""}var w0=["/","/bin","/boot","/dev","/etc","/home","/lib","/lib32","/lib64","/libx32","/opt","/proc","/root","/run","/sbin","/srv","/sys","/usr","/var","/Applications","/Library","/System","/Users","/Volumes","/private"];var fZ=/^[A-Za-z_][A-Za-z0-9_]*\+?=/,s=(Z)=>Z.split("/").pop()??"";function kZ(Z){let X=Z.startsWith("~")?Z.slice(1).split("/",1)[0]:"";if(X&&!/['"\\]/.test(X))return!0;let $=null,J=0;for(let z=0;z<Z.length;z++){let Y=Z[z];if($==="'"){if(Y==="'")$=null;continue}if(Y==="\\"){z++;continue}if($==='"'){if(Y==='"')$=null;continue}if(Y==="'"||Y==='"')$=Y;else if(Y==="$"&&Z[z+1]==="{")J++,z++;else if(Y==="}"&&J>0)J--;else if(Y==="{"||Y==="}")return!0}return!1}var rZ=64;function h0(Z,X){let $=0;for(let J=X;J<Z.length;J++)if(Z[J]==="\\")J++;else if(Z[J]==="{")$++;else if(Z[J]==="}"&&--$===0)return J;return Z.length-1}function m2(Z){let X=Z.match(/^([-+]?\d+)\.\.([-+]?\d+)(?:\.\.([-+]?\d+))?$/),$=X?null:Z.match(/^([A-Za-z])\.\.([A-Za-z])(?:\.\.([-+]?\d+))?$/),J=X??$;if(!J)return null;let z=X?Number(J[1]):J[1].charCodeAt(0),Y=X?Number(J[2]):J[2].charCodeAt(0),Q=Math.abs(Number(J[3]??1))||1;if(!Number.isSafeInteger(z)||!Number.isSafeInteger(Y)||!Number.isSafeInteger(Q))return"overflow";if(Math.floor(Math.abs(Y-z)/Q)+1>rZ)return"overflow";let H=X&&(/^[-+]?0\d/.test(J[1])||/^[-+]?0\d/.test(J[2]))?Math.max(J[1].length,J[2].length):0,K=[];for(let B=z;z<=Y?B<=Y:B>=Y;B+=z<=Y?Q:-Q)if(!X)K.push(String.fromCharCode(B));else K.push(B<0?`-${String(-B).padStart(H-1,"0")}`:String(B).padStart(H,"0"));return K}function p2(Z){let X=null,$=0;for(let J=0;J<Z.length;J++){let z=Z[J];if(X==="'"){if(z==="'")X=null;continue}if(z==="\\"){J++;continue}if(X==='"'){if(z==='"')X=null;continue}if(z==="'"||z==='"')X=z;else if(z==="$"&&Z[J+1]==="{")J=h0(Z,J+1);else if(z==="{"){if(++$>rZ)return"overflow";let Y=null,Q=0,H=!0,K=[];for(let B=J;B<Z.length;B++){let M=Z[B];if(Y==="'"){if(M==="'")Y=null;continue}if(M==="\\"){H=!1,B++;continue}if(Y==='"'){if(M==='"')Y=null;continue}if(M==="'"||M==='"')Y=M,H=!1;else if(M==="$"&&Z[B+1]==="{")B=h0(Z,B+1),H=!1;else if(M==="{")Q++;else if(M===","&&Q===1)K.push(B);else if(M==="}"&&--Q===0){if(K.length>0){let G=[J,...K,B];return{open:J,close:B,parts:G.slice(0,-1).map((j,D)=>Z.slice(j+1,G[D+1]))}}let V=H?m2(Z.slice(J+1,B)):null;if(V==="overflow")return V;if(V)return{open:J,close:B,parts:V};break}}}}return null}function zZ(Z){if(Z.length>4096&&Z.includes("{"))return null;let X=p2(Z);if(X===null)return[Z];if(X==="overflow")return null;let $=[];for(let J of X.parts){let z=zZ(Z.slice(0,X.open)+J+Z.slice(X.close+1));if(z===null||$.push(...z)>rZ)return null}return $}var U={arg:"none"},q={arg:"value"},CZ={arg:"optional"},n={arg:"none",effect:"lookup"},C={arg:"none",effect:"refuse"},t={help:C,version:C},c2=/^(?:\d+(?:\.\d*)?|\.\d+)[smhd]?$/,tZ={timeout:{short:{k:q,s:q,v:U},long:{"kill-after":q,signal:q,verbose:U,foreground:U,"preserve-status":U,...t},positionals:[c2]},env:{short:{i:U,"0":U,v:U,u:q,a:q,C,S:C},long:{"ignore-environment":U,null:U,debug:U,unset:q,argv0:q,chdir:C,"split-string":C,"block-signal":CZ,"default-signal":CZ,"ignore-signal":CZ,"list-signal-handling":C,...t},env:!0},nice:{short:{n:q},long:{adjustment:q,...t},numericOption:!0},nohup:{short:{},long:{...t}},command:{short:{p:U,v:n,V:n},long:{}},exec:{short:{c:U,l:U,a:q},long:{}},builtin:{short:{},long:{}},stdbuf:{short:{i:q,o:q,e:q},long:{input:q,output:q,error:q,...t}},time:{short:{p:U,a:U,q:U,v:U,f:q,o:C,V:C},long:{portability:U,append:U,quiet:U,verbose:U,format:q,output:C,...t}},ionice:{short:{c:q,n:q,t:U,p:C,P:C,u:C,h:C,V:C},long:{class:q,classdata:q,ignore:U,pid:C,pgid:C,uid:C,...t}},setsid:{short:{c:U,f:U,w:U,h:C,V:C},long:{ctty:U,fork:U,wait:U,...t}}},d2=new Set(["!","{","}","then","do","else","elif","if","while","until","for","case","esac","fi","done","select","function"]);function i2(Z,X,$){let J=!1,z=(Y)=>{if(!Y||Y.effect==="refuse")return!1;if(Y.effect==="lookup")J=!0;return!0};while($<X.length){let Y=X[$];if(Y.opaque)return null;let Q=Y.text;if(Q==="--"){$++;break}if(Q==="-"&&Z.env){$++;continue}if(!Q.startsWith("-")||Q==="-")break;if(Z.numericOption&&/^-[-+]?\d+$/.test(Q)){$++;continue}if(Q.startsWith("--")){let H=Q.indexOf("="),K=H<0?Q.slice(2):Q.slice(2,H),B=Object.keys(Z.long),M=B.includes(K)?[K]:B.filter((G)=>K&&G.startsWith(K));if(M.length!==1)return null;let V=Z.long[M[0]];if(!z(V))return null;if(V.arg==="none"&&H>=0)return null;if(V.arg==="value"&&H<0){let G=X[++$];if(!G||G.opaque)return null}$++;continue}for(let H=1;H<Q.length;H++){let K=Z.short[Q[H]];if(!z(K))return null;if(K.arg==="value"){if(H===Q.length-1){let B=X[++$];if(!B||B.opaque)return null}break}}$++}if(J)return-1;for(let Y of Z.positionals??[]){let Q=X[$];if(!Q||Q.opaque||!Y.test(Q.text))return null;$++}if(Z.env||Z.assignments){for(;$<X.length&&fZ.test(X[$].text);$++)if(X[$].opaque)return null}return $}function DZ(Z,X=tZ){let $=0;while($<Z.length&&(fZ.test(Z[$].text)||d2.has(Z[$].text)))$++;for(let J=0;J<16;J++){if($>=Z.length)return{index:-1};if(Z[$].opaque)return J===0?{index:$}:null;let z=Object.hasOwn(X,s(Z[$].text))?X[s(Z[$].text)]:void 0;if(!z)return{index:$};let Y=i2(z,Z,$+1);if(Y===null)return null;if(Y<0)return{index:-1};$=Y}return null}var n2=600000,a2="Delete via trash guard (rm intercepted and made recoverable)",o2=[".hasna/repos/clones","workspace/repos"],r2=[".hasna",".ssh",".aws"],eZ={rmdir:"`rmdir` is a delete that trash-guard does not rewrite (it takes rmdir's flags, not rm's). Re-run it as `rm -d -- <path>` for an empty directory, or `rm -r -- <path>` for a non-empty one, and it is redirected into trash.",unlink:"`unlink` is a delete that trash-guard does not rewrite. Re-run it as `rm -- <path>` and it is redirected into trash.",shred:"`shred` destroys content irrecoverably and is never allowed. Re-run it as `rm -- <path>` and it is redirected into trash."},t2=new Set(["sh","bash","zsh","dash","ksh","ash","eval","source",".","su","runuser","env"]),e2={sudo:["-u","--user","-g","--group","-p","--prompt","-C","--chdir","-h","--host","-r","--role","-t","--type","-U","--other-user"],doas:["-u","-C"],env:["-u","--unset","-C","--chdir","-S","--split-string"],nice:["-n","--adjustment"],ionice:["-c","--class","-n","--classdata","-p","--pid"],stdbuf:["-i","-o","-e","--input","--output","--error"],time:["-f","--format","-o","--output"],timeout:["-s","--signal","-k","--kill-after"],nohup:[],setsid:[],command:[],builtin:[],exec:["-a"]},Z3={timeout:1},$3={sudo:{short:{A:U,B:U,b:U,E:U,H:U,i:U,k:U,N:U,n:U,P:U,S:U,s:U,C:q,g:q,p:q,r:q,T:q,t:q,U:q,u:q,e:n,l:n,v:n,D:C,R:C,h:C,K:C,V:C},long:{askpass:U,bell:U,background:U,"close-from":q,chdir:C,"preserve-env":CZ,edit:n,group:q,"set-home":U,help:C,host:C,login:U,"remove-timestamp":C,"reset-timestamp":U,list:n,"no-update":U,"non-interactive":U,"preserve-groups":U,prompt:q,chroot:C,role:q,stdin:U,shell:U,type:q,"command-timeout":q,"other-user":q,user:q,version:C,validate:n},assignments:!0},doas:{short:{n:U,s:U,u:q,C,L:C},long:{}},flock:{short:{s:U,x:U,e:U,n:U,u:U,o:U,F:U,w:q,E:q,h:C,V:C},long:{shared:U,exclusive:U,unlock:U,nonblock:U,nonblocking:U,nb:U,timeout:q,wait:q,"conflict-exit-code":q,close:U,"no-fork":U,fcntl:U,verbose:U,help:C,version:C},positionals:[/^[\s\S]+$/]}},J3={...tZ,...$3},d0=new Set(["-c","--command"]),X3=new Set(["busybox","toybox"]),X0=new Set(["rm","rmdir","unlink","shred"]),z3=new Set(["!","{","}","then","do","else","elif","if","while","until","for","case","esac","fi","done","select","function"]),Y3=new Set(["-C","-c","--git-dir","--work-tree","--namespace","--exec-path","--config-env"]),Q3=/(^|[^A-Za-z0-9_.-])(rm|rmdir|unlink|shred)(?![A-Za-z0-9_.-])/;function a(Z){return Q3.test(R(Z))}function PZ(Z){return Z.map((X)=>X.replace(/^-[iv0]*S|^--split-string=/," ")).join(" ")}var i0=/^[A-Za-z_][A-Za-z0-9_]*=/;function xZ(Z){let X=Z.lastIndexOf("/");return X>=0?Z.slice(X+1):Z}var g0={a:"\x07",b:"\b",e:"\x1B",E:"\x1B",f:"\f",n:`
|
|
3
|
+
`,r:"\r",t:"\t",v:"\v","\\":"\\","'":"'",'"':'"',"?":"?"};function K3(Z,X){let $="",J=X;while(J<Z.length&&Z[J]!=="'"){if(Z[J]!=="\\"||J+1>=Z.length){$+=Z[J++];continue}let z=Z[J+1],Y=Z.slice(J+1),Q;if(Object.hasOwn(g0,z))$+=g0[z],J+=2;else if(Q=Y.match(/^[0-7]{1,3}/))$+=String.fromCharCode(parseInt(Q[0],8)&255),J+=1+Q[0].length;else if((Q=Y.match(/^x([0-9A-Fa-f]{1,2})/))||(Q=Y.match(/^u([0-9A-Fa-f]{1,4})/))||(Q=Y.match(/^U([0-9A-Fa-f]{1,8})/))){let H=parseInt(Q[1],16);$+=H<=1114111?String.fromCodePoint(H):"",J+=1+Q[0].length}else if(z==="c"&&J+2<Z.length)$+=String.fromCharCode(Z.charCodeAt(J+2)&31),J+=3;else $+=`\\${z}`,J+=2}return{text:$,end:Math.min(J+1,Z.length)}}function wZ(Z){let X="",$=0;while($<Z.length){let J=Z[$];if(J==="$"&&Z[$+1]==="'"){let z=K3(Z,$+2);X+=z.text,$=z.end;continue}if(J==="$"&&Z[$+1]==='"'){$++;continue}if(J==="\\"){if($+1<Z.length)X+=Z[$+1];$+=2;continue}if(J==="'"){let z=Z.indexOf("'",$+1);if(z===-1){X+=Z.slice($+1);break}X+=Z.slice($+1,z),$=z+1;continue}if(J==='"'){$++;while($<Z.length&&Z[$]!=='"'){if(Z[$]==="\\"&&$+1<Z.length){X+=Z[$+1],$+=2;continue}X+=Z[$],$++}$++;continue}X+=J,$++}return X}function z0(Z){if(kZ(Z))return!0;let X=null;for(let $=0;$<Z.length;$++){let J=Z[$];if(X==="'"){if(J==="'")X=null;continue}if(J==="\\"){$++;continue}if(J==="`"||J==="$")return!0;if(J==='"'){X=X===null?'"':null;continue}if(X!==null)continue;if(J==="'")X="'";else if(J==="*"||J==="?")return!0;else if(J==="["&&H3(Z,$+1,"]"))return!0}return!1}function H3(Z,X,$){let J=null;for(let z=X;z<Z.length;z++){let Y=Z[z];if(J!=="'"&&Y==="\\")z++;else if(J===null&&Y===$)return!0;else if(Y==="'"&&J!=='"')J=J==="'"?null:"'";else if(Y==='"'&&J!=="'")J=J==='"'?null:'"'}return!1}function B3(Z){if(!z0(Z))return!1;let X=zZ(Z);return X===null||X.some(($)=>wZ($).split(/[^A-Za-z0-9_]+/).some((J)=>X0.has(J)))}function FZ(Z){return xZ(wZ(Z))}var s0={deep:!0};function Y0(Z,X){return Z.replace(/\\([$`\\"])/g,($,J)=>J==='"'&&!X?$:J)}function M3(Z,X,$){let J=[],z=X+1;while(z<$-1){let Y=Z[z];if(Y==="\\"){z+=2;continue}if(Y==="`"){let Q=OZ(Z,z);if(Q<0)return null;J.push(Y0(Z.slice(z+1,Q-1),!0)),z=Q;continue}if(Y==="$"&&Z[z+1]==="("){let Q=YZ(Z,z+1);if(Q<0)return null;J.push(Z.slice(z+2,Q-1)),z=Q;continue}z++}return J}function G3(Z){let X=[],$=0;while($<Z.length){let J=Z[$];if(J==="\\"){$+=2;continue}if(J==="`"){let z=OZ(Z,$);if(z<0)return null;X.push(Y0(Z.slice($+1,z-1),!1)),$=z;continue}if(J==="$"&&Z[$+1]==="("){let z=YZ(Z,$+1);if(z<0)return null;X.push(Z.slice($+2,z-1)),$=z;continue}$++}return X}function u0(Z,X,$,J){let z=X+1;for(let Y of $){let Q=Math.min(z,Z.length);for(;;){if(z>Z.length){z=Z.length+1;break}let K=Z.indexOf(`
|
|
4
|
+
`,z),B=K===-1?Z.length:K,M=Z.slice(z,B).replace(/\r$/,"");if(Y.stripTabs)M=M.replace(/^\t+/,"");if(M===Y.delimiter)break;z=B+1}let H=Z.slice(Q,Math.min(z,Z.length));if(Y.owner.push(H),!Y.quoted){let K=G3(H);if(!K)return-1;J.push(...K)}if(z<=Z.length){let K=Z.indexOf(`
|
|
5
|
+
`,z);z=(K===-1?Z.length:K)+1}}return Math.min(z-1,Z.length)}function n0(Z,X){let $=Z.indexOf("'",X+1);return $===-1?-1:$+1}function OZ(Z,X){let $=X+1;while($<Z.length){if(Z[$]==="\\"){$+=2;continue}if(Z[$]==="`")return $+1;$++}return-1}function a0(Z,X){let $=X+1;while($<Z.length){let J=Z[$];if(J==="\\"){$+=2;continue}if(J==='"')return $+1;if(J==="`"){let z=OZ(Z,$);if(z<0)return-1;$=z;continue}if(J==="$"&&Z[$+1]==="("){let z=YZ(Z,$+1);if(z<0)return-1;$=z;continue}$++}return-1}function GZ(Z,X){if(Z[X]!=="<"||Z[X+1]!=="<"||Z[X+2]==="<")return null;let $=X+2,J=Z[$]==="-";if(J)$++;while(Z[$]===" "||Z[$]==="\t")$++;let z="",Y=!1;while($<Z.length&&!/[\s;|&<>()]/.test(Z[$])){let Q=Z[$];if(Q==="'"||Q==='"'){let H=Z.indexOf(Q,$+1);if(H<0)return null;z+=Z.slice($+1,H),Y=!0,$=H+1;continue}if(Q==="\\"){if($+1>=Z.length)return null;z+=Z[$+1],Y=!0,$+=2;continue}z+=Q,$++}return z?{delimiter:z,stripTabs:J,quoted:Y,end:$}:null}function hZ(Z,X,$){let J=X+1;for(let z of $)for(;;){if(J>Z.length)return-1;let Y=Z.indexOf(`
|
|
6
|
+
`,J),Q=Y===-1?Z.length:Y,H=Z.slice(J,Q);if(H.endsWith("\r"))H=H.slice(0,-1);let K=z.stripTabs?H.length-H.replace(/^\t+/,"").length:0;if(z.stripTabs)H=H.slice(K);if(H===z.delimiter){J=Q+1;break}if(H.startsWith(z.delimiter)&&/^\s*\)/.test(H.slice(z.delimiter.length))){if(z===$[$.length-1])return J+K+z.delimiter.length;return-1}if(Y===-1)return-1;J=Y+1}return J-1}function YZ(Z,X){let $=Z.length,J=Z[X+1]==="(",z=0,Y=X,Q=[];while(Y<$){let H=Z[Y];if(H==="\\"){Y+=2;continue}if(H==="'"){let K=n0(Z,Y);if(K<0)return-1;Y=K;continue}if(H==='"'){let K=a0(Z,Y);if(K<0)return-1;Y=K;continue}if(H==="`"){let K=OZ(Z,Y);if(K<0)return-1;Y=K;continue}if(!J&&H==="<"&&Z[Y+1]==="<"){if(Z[Y+2]==="<"){Y+=3;continue}let K=GZ(Z,Y);if(!K)return-1;Q.push(K),Y=K.end;continue}if(H===`
|
|
7
|
+
`&&Q.length>0){let K=hZ(Z,Y,Q);if(K<0)return-1;Q=[],Y=K;continue}if(!J&&H==="#"&&/[\s;&|(]/.test(Z[Y-1])){let K=Z.indexOf(`
|
|
8
|
+
`,Y);if(K<0)return-1;Y=K;continue}if(H==="(")z++;else if(H===")"){if(z--,z===0)return Q.length>0?-1:Y+1}Y++}return-1}function o(Z,X={}){let $=X.deep===!0,J=[],z=[],Y=[],Q=new Set,H=[],K=[],B=-1,M=!1,V=!0,G=0,j=Z.length,D=(I)=>{if(B>=0){let W=Y.length;if(Y.push({text:Z.slice(B,I),start:B,end:I}),M)Q.add(W);B=-1,M=!1}},v=(I)=>{if(D(I),Y.length>0)J.push($?{words:Y,redirects:Q,heredocs:H}:{words:Y,redirects:Q});if(Y=[],Q=new Set,$)H=[];M=!1},b=(I)=>n0(Z,I),E=(I)=>OZ(Z,I),JZ=(I)=>YZ(Z,I),i=(I)=>a0(Z,I);while(G<j){let I=Z[G];if(I===" "||I==="\t"||I==="\r"){D(G),G++;continue}if(I===`
|
|
9
|
+
`){if(v(G),K.length>0){let W=u0(Z,G,K,z);if(K=[],W<0)V=!1,G=j;else G=W;continue}G++;continue}if(I===";"){v(G),G++;continue}if(I==="&"){v(G),G+=Z[G+1]==="&"?2:1;continue}if(I==="|"){v(G),G+=Z[G+1]==="|"?2:1;continue}if($&&I==="("&&B>=0&&"?*+@!".includes(Z[G-1])){V=!1,G=j;continue}if(I==="("||I===")"){v(G),G++;continue}if(I==="<"&&Z[G+1]==="<"&&Z[G+2]!=="<"){let W=Z.slice(G+2).match(/^-?[ \t]*(['"]?)([A-Za-z_][A-Za-z0-9_]*)\1/);if(!W){V=!1,G=j;continue}if($){let jZ=G+2+W[0].length;if(jZ<j&&!/[\s;&|()<>]/.test(Z[jZ])){V=!1,G=j;continue}D(G),K.push({delimiter:W[2],quoted:W[1]!=="",stripTabs:W[0].startsWith("-"),owner:H}),G=jZ;continue}let A=Z.indexOf(`
|
|
10
|
+
`,G+2+W[0].length);if(A===-1){V=!1,G=j;continue}let w=Z.slice(A+1),f=V3(w,W[2]);if(f===-1){V=!1,G=j;continue}D(G),G=A+1+f+W[2].length;continue}if(I===">"||I==="<"){if(B>=0&&/^\d+$/.test(Z.slice(B,G)))B=-1;if(D(G),M=!0,G++,Z[G]===I||Z[G]==="&"||I===">"&&Z[G]==="|"||I==="<"&&Z[G]===">")G++;continue}if(I==="'"){if(B<0)B=G;let W=b(G);if(W<0)V=!1,G=j;else G=W;continue}if(I==='"'){if(B<0)B=G;let W=i(G),A=W<0||!$?[]:M3(Z,G,W);if(W<0||!A)V=!1,G=j;else z.push(...A),G=W;continue}if(I==="`"){if(B<0)B=G;let W=E(G);if(W<0)V=!1,G=j;else{let A=Z.slice(G+1,W-1);z.push($?Y0(A,!1):A),G=W}continue}if(I==="$"&&Z[G+1]==="("){if(B<0)B=G;let W=JZ(G+1);if(W<0)V=!1,G=j;else z.push(Z.slice(G+2,W-1)),G=W;continue}if(I==="\\"){if(B<0)B=G;if(G+1>=j)V=!1,G=j;else G+=2;continue}if(B<0)B=G;G++}if(v(j),K.length>0&&u0(Z,j,K,z)<0)V=!1;return{segments:J,trustworthy:V,substitutions:z}}function V3(Z,X){let $=0;while($<=Z.length){let J=Z.indexOf(X,$);if(J===-1)return-1;let z=J===0||Z[J-1]===`
|
|
11
|
+
`,Y=J+X.length,Q=Y===Z.length||Z[Y]===`
|
|
12
|
+
`||Z[Y]==="\r";if(z&&Q)return J;$=J+1}return-1}function R(Z){let X="",$=0;while($<Z.length){let J=Z[$];if(J==="\\"){if($+1<Z.length)X+=Z[$+1];$+=2;continue}if(J==="'"){let z=Z.indexOf("'",$+1);if(z===-1){X+=Z.slice($+1);break}X+=Z.slice($+1,z),$=z+1;continue}if(J==='"'){$++;while($<Z.length&&Z[$]!=='"'){if(Z[$]==="\\"&&$+1<Z.length){X+=Z[$+1],$+=2;continue}X+=Z[$],$++}$++;continue}X+=J,$++}return X}function p(Z){let X=0,$=0;while(X<Z.words.length&&$++<32){if(Z.redirects.has(X)){X++;continue}let J=Z.words[X].text,z=R(J);if(i0.test(z)&&!z.startsWith("-")){X++;continue}if(z3.has(z)){X++;continue}let Y=xZ(z);if(Y==="command")for(let H of Z.words.filter((K,B)=>B>X&&!Z.redirects.has(B))){let K=R(H.text);if(K==="--"||!K.startsWith("-"))break;if(/^-[pvV]*[vV][pvV]*$/.test(K))return-1}let Q=e2[Y];if(Q){let H=X;X++;while(X<Z.words.length){if(Z.redirects.has(X)){X++;continue}let B=R(Z.words[X].text);if(!B.startsWith("-")||B==="-")break;if(B==="--"){X++;break}if(Y==="env"&&(/^-[iv0]*S/.test(B)||/^--split-string(?:=|$)/.test(B)))return H;if(X++,Q.includes(B)||Y==="exec"&&/^-[cl]*a$/.test(B)){while(Z.redirects.has(X))X++;X++}}let K=Z3[Y]??0;while(K>0&&X<Z.words.length){let B=R(Z.words[X].text);if(B.startsWith("-")&&B!=="-")break;X++,K--}continue}return X}return-1}function U3(Z,X){let $=[],J=!1;for(let z=X+1;z<Z.words.length;z++){if(Z.redirects.has(z))continue;let Y=R(Z.words[z].text);if(!J){if(Y==="--"){J=!0;continue}if(Y.startsWith("-")&&Y!=="-")continue}$.push(Z.words[z])}return $}function o0(Z){return o2.map((X)=>S.join(Z,...X.split("/")))}function j3(Z,X){if(Z==="~"||Z==="$HOME"||Z==="${HOME}")return X;if(Z.startsWith("~/"))return S.join(X,Z.slice(2));if(Z.startsWith("$HOME/"))return S.join(X,Z.slice(6));if(Z.startsWith("${HOME}/"))return S.join(X,Z.slice(8));return Z}function Z0(Z,X,$){let J=R(Z);if(!J)return null;if(J.includes("`"))return null;if(J==="$HOME"||J==="${HOME}"||J==="$HOME/"||J==="${HOME}/")return $;if(J.replace(/\$\{HOME\}/g,"").replace(/\$HOME/g,"").includes("$"))return null;if(/[*?[\]]/.test(J))return null;if(J.startsWith("~")){let H=j3(J,$);if(H===J)return null;J=H}let Q=(S.isAbsolute(J)?S.normalize(J):S.resolve(X,J)).replace(/\/+$/,"");return Q===""?"/":Q}function MZ(Z,X){return Z===X||Z.startsWith(`${X}${S.sep}`)}function W3(Z,X){let $=`${S.join(X,".hasna","scratchpad","scratch")}${S.sep}`;if(!Z.startsWith($))return!1;let[J,z]=Z.slice($.length).split(S.sep);if(!J||!/^[a-z0-9][a-z0-9._-]{0,63}$/.test(J)||J.endsWith(".")||!z)return!1;let Y=z.normalize("NFKC").toLowerCase();return Y!=="meta.json"&&Y!==".lock"}function q3(Z,X){if(Z===X)return`\`${Z}\` is the home directory itself, which is never deleted or trashed. Delete a specific file or directory inside it instead.`;for(let $ of w0){if(Z!==$&&!MZ($,Z))continue;return $==="/"?`\`${Z}\` is the filesystem root, which is never deleted.`:`\`${Z}\` is the system root \`${$}\` (or an ancestor of it), which is never deleted or trashed.`}for(let $ of r2){let J=S.join(X,$);if($===".hasna"&&W3(Z,X))continue;if(!MZ(Z,J)&&!MZ(J,Z))continue;return`\`${Z}\` is the protected \`~/${$}\` path (or contains it), which is never deleted or trashed. Delete a specific file inside it, and only when you are sure.`}return null}function N3(Z,X,$){let J=o0($);if(J.some((z)=>MZ(X,z)))return!0;return Z.some((z)=>z!==null&&J.some((Y)=>MZ(z,Y)))}var l0=new WeakMap;function _3(Z){let X=l0.get(Z);if(X)return X;let $=Z.words.map((Q)=>wZ(Q.text)),J=$.findIndex((Q)=>Q==="-exec"||Q==="-execdir"||Q==="-ok"||Q==="-okdir"),z=-1;Z.words.forEach((Q,H)=>{if(d0.has(R(Q.text)))z=H});let Y={findDelete:$.includes("-delete"),findExecDelete:J>=0&&$.slice(J).some((Q)=>X0.has(xZ(Q))),namesDelete:$.some((Q)=>X0.has(xZ(Q))),lastFlockCommand:z,textMention:a(O3(Z)),envMention:a(PZ(Z.words.map((Q)=>R(Q.text)))),bodiesMention:a((Z.heredocs??[]).join(`
|
|
13
|
+
`))};return l0.set(Z,Y),Y}var I3=new Set(["sh","bash","zsh","dash","ksh","ash","mksh"]);function T3(Z,X){if(!I3.has(FZ(Z.words[X].text)))return!1;for(let $=X+1;$<Z.words.length;$++){if(Z.redirects.has($))continue;let J=R(Z.words[$].text);if(J==="--")return $+1>=Z.words.length;if(/^-[A-Za-z]*s/.test(J))return!0;if(/^-[A-Za-z]*c/.test(J))return!1;if(J==="-o"||J==="+o"||J==="-O"||J==="+O"){$++;continue}if(!/^[-+]/.test(J)||J==="-")return J==="-"}return!0}var $0=(Z)=>Z.kind==="rm"||Z.kind==="refuse",C3="This command's command word or wrapper arguments cannot be read before it runs (an expansion such as a variable, substitution, brace or glob pattern, an unknown or unsupported option, a working directory or a non-decimal duration), so this hook cannot tell which word runs, and one of its words could run a delete. Run the delete as a plain `rm -- <path>` command, which is redirected into trash.",D3="This delete's brace pattern names more paths than this hook will check. Run the delete on explicit paths with `rm -- <path> …`, which is redirected into trash.",F3="This delete's brace pattern expands to a path under a protected repository checkout. Deletes there are refused; run them through the owning workflow, and write any other delete out as plain paths.",P3="This command's wrapper arguments can be read as running two different deletes, so no single rewrite is safe. Run the delete as a plain `rm -- <path>` command, which is redirected into trash.";function r0(Z){let X=[];Z.words.forEach((z,Y)=>{if(!Z.redirects.has(Y))X.push(Y)});let $=X.map((z)=>{let Y=Z.words[z].text;return{text:wZ(Y),opaque:z0(Y)}}),J=DZ($,J3);if(J===null)return null;return J.index<0?-1:X[J.index]}function J0(Z,X,$,J){let z=FZ(Z.words[X].text);if(z==="cd"){let H=Z.words[X+1];if(!H)return{kind:"none"};return{kind:"cd",cwd:Z0(H.text,$,J.home)??J.cwd}}if(Object.hasOwn(eZ,z))return{kind:"refuse",reason:eZ[z]};if(z==="rm"){let H=U3(Z,X);if(H.length===0)return{kind:"none"};let K={word:Z.words[X],operands:H},B=o0(J.home),M=(j)=>j!==null&&B.some((D)=>MZ(j,D)),V=[],G=[];for(let j of H){let D=Z0(j.text,$,J.home);if(V.push(D),!j.text.includes("{"))continue;let v=zZ(j.text);if(v===null)return{kind:"refuse",reason:D3};for(let b of v){let E=Z0(b,$,J.home);if(E===null)continue;if(M(E)&&!M(D))return{kind:"refuse",reason:F3};G.push(E)}}if(N3(V,$,J.home))return K.cwdOnly=V.every((j)=>j!==null&&!M(j)),{kind:"rm",hit:K,handoff:!0,protectedReason:null};for(let j of[...V,...G]){if(!j)continue;let D=q3(j,J.home);if(D)return{kind:"rm",hit:K,handoff:!1,protectedReason:D}}return{kind:"rm",hit:K,handoff:!1,protectedReason:null}}if(X3.has(z)){let H=Z.words.findIndex((B,M)=>M>X&&!R(B.text).startsWith("-")),K=H>=0?FZ(Z.words[H].text):"";if(K==="rm"||Object.hasOwn(eZ,K))return{kind:"refuse",reason:`\`${z} ${K}\` runs the ${z} applet, whose own \`rm\` is not GNU \`rm\` and cannot be rewritten in place. Run the delete as \`rm -- <path>\`, which is redirected into trash.`};return{kind:"none"}}if(z==="git"){let H=Q0(Z,X);if(H==="rm"||H==="clean"){if(!(H==="rm"?L3(Z,X):t0(Z,X)))return{kind:"refuse",reason:H==="rm"?"`git rm` is refused: without `--cached` it deletes the working-tree file, and its semantics are not `rm`'s. Use `rm -- <path>` (intercepted and redirected into trash) to remove the file, or `git rm --cached -- <path>` to unstage it without deleting.":"`git clean` deletes untracked files irrecoverably and is refused. Remove them explicitly with `rm -- <path>` (intercepted and redirected into trash), or preview with `git clean -n`."}}return{kind:"none"}}let Y=_3(Z);if(z==="find"){if(Y.findDelete)return{kind:"refuse",reason:"`find -delete` deletes files irrecoverably and is refused. List the paths first (`find … -print`), then remove them explicitly with `rm -- <path>` so the delete is redirected into trash."};if(Y.findExecDelete)return{kind:"refuse",reason:"`find -exec <delete>` is refused: the delete runs through find, not through `rm`, and cannot be redirected into trash. Remove the paths explicitly with `rm -- <path>`."};return{kind:"none"}}if(z==="xargs"&&Y.namesDelete)return{kind:"refuse",reason:"`xargs rm` takes its targets from stdin, so this hook cannot verify what would be deleted. Pipe the paths into an explicit `rm -- <path> …` instead, which is redirected into trash."};let Q=z==="flock"?Y.lastFlockCommand>X:d0.has(z);if(t2.has(z)||Q){let H=T3(Z,X)?J.bodiesMention:Y.bodiesMention;if((z==="env"?Y.envMention:Y.textMention)||H)return{kind:"refuse",reason:`\`${Q?"flock":z}\` runs a command string this hook cannot rewrite in place. Run the delete directly as \`rm -- <path>\` (intercepted and redirected into trash), or as a script that uses \`trash guard\` itself.`}}return{kind:"none"}}function LZ(Z,X){let $={rmHits:[],handoffHits:[],refusals:[],protectedHits:[],trustworthy:!0},J=o(Z,s0);$.trustworthy=J.trustworthy;let z={cwd:X.cwd,home:X.home,depth:X.depth??0,bodiesMention:a(J.segments.flatMap((K)=>K.heredocs??[]).join(`
|
|
14
|
+
`))};if(!J.trustworthy)return $;let Y=[],Q=(K,B=$.refusals)=>{if(K.kind==="refuse")B.push({reason:K.reason});else if(K.kind==="rm"&&K.handoff)$.handoffHits.push(K.hit);else if(K.kind==="rm"){if($.rmHits.push(K.hit),K.protectedReason)$.protectedHits.push({reason:K.protectedReason})}},H=z.cwd;for(let K of J.segments){let B=p(K),M=r0(K),V=B<0?{kind:"none"}:J0(K,B,H,z);if(V.kind!=="cd")Q(V);let G=(j)=>j!==null&&j>=0&&z0(K.words[j].text);if(M===null||G(B)||G(M)){if(K.words.some((j,D)=>!K.redirects.has(D)&&($0(J0(K,D,H,z))||B3(j.text))))Y.push({reason:C3})}else if(M>=0&&M!==B){let j=J0(K,M,H,z);if($0(j))if($0(V))Y.push({reason:P3});else Q(j,Y)}if(V.kind==="cd")H=V.cwd}if(z.depth<3)for(let K of J.substitutions){let B=LZ(K,{cwd:H,home:z.home,depth:z.depth+1});if(B.rmHits.length>0||B.refusals.length>0||B.handoffHits.length>0||B.protectedHits.length>0||!B.trustworthy&&a(K)){$.refusals.push({reason:"This command runs a delete inside a command substitution `$(…)`, which this hook cannot rewrite. Run the delete as a separate `rm -- <path>` command, which is redirected into trash."});break}}else if(J.substitutions.some((K)=>a(K)))$.refusals.push({reason:"This command nests a delete inside command substitutions deeper than this hook will follow. Run the delete as a separate `rm -- <path>` command."});return $.refusals.push(...Y),$}function O3(Z){return Z.words.map((X)=>X.text).join(" ")}function Q0(Z,X){let $=X+1;while($<Z.words.length){let J=R(Z.words[$].text);if(!J.startsWith("-"))return J;if($++,Y3.has(J))$++}return null}function L3(Z,X){if(Z.words.slice(X+1).map((J)=>R(J.text)).includes("--cached"))return!0;return t0(Z,X)}function t0(Z,X){let $=Z.words.slice(X+1).map((J)=>R(J.text));return $.includes("-n")||$.includes("--dry-run")}function m0(Z){if(/^[A-Za-z0-9_\-./+=:,@%^]+$/.test(Z))return Z;return`'${Z.replace(/'/g,"'\\''")}'`}function v3(Z,X,$,J){let z=J?["/usr/bin/env","-i",`HOME=${J.home}`,`PATH=${J.path}`,`HASNA_TRASH_AGENT=${J.agent}`,J.runtime,"--config=/dev/null","--no-env-file","--no-macros","--no-install",$,"guard"].map(m0).join(" "):`${m0($)} guard`,Y=[...X].sort((H,K)=>K.word.start-H.word.start),Q=Z;for(let H of Y)Q=`${Q.slice(0,H.word.start)}${z}${Q.slice(H.word.end)}`;return Q}function A3(Z,X,$,J,z){if(!X||X===Z)return!1;if($.length===0)return!1;let Y=LZ(X,{cwd:J,home:z});if(!Y.trustworthy)return!1;if(Y.rmHits.length>0||Y.handoffHits.length>0)return!1;return Y.refusals.length===0}function y3(Z,X){let $={};for(let[J,z]of Object.entries(Z??{}))$[J]=z;if($.command=X,typeof $.description!=="string"||$.description.trim()==="")$.description=a2;if(typeof $.timeout!=="number"||!Number.isFinite($.timeout)||$.timeout<=0)$.timeout=n2;if(typeof $.run_in_background!=="boolean")$.run_in_background=!1;if("dangerouslyDisableSandbox"in $&&typeof $.dangerouslyDisableSandbox!=="boolean")delete $.dangerouslyDisableSandbox;return $}function R3(Z,X,$,J,z){if(typeof Z.command!=="string"||Z.command.trim()==="")return!1;if(typeof Z.description!=="string"||Z.description.trim()==="")return!1;if(typeof Z.timeout!=="number"||!Number.isFinite(Z.timeout)||Z.timeout<=0)return!1;if(typeof Z.run_in_background!=="boolean")return!1;if("dangerouslyDisableSandbox"in Z&&typeof Z.dangerouslyDisableSandbox!=="boolean")return!1;return A3(X,Z.command,$,J,z)}function E3(Z){let X=new Set(["export","set","unset","readonly","declare","typeset","local","alias","unalias","read","readarray","mapfile","getopts","trap","enable","function","env","sudo","doas","stdbuf"]);return o(Z,s0).segments.some((J)=>{let z=r0(J);return[p(J),...z===null?[]:[z]].some((Y)=>{if(J.words.slice(0,Y<0?J.words.length:Y).some((K)=>i0.test(R(K.text))||X.has(FZ(K.text))))return!0;if(Y<0)return!1;let H=J.words[Y];return X.has(FZ(H.text))||/^\s*\(\s*\)\s*\{/.test(Z.slice(H.end))})})}function u(Z){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:Z}}}function S3(Z){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"allow",updatedInput:Z}}}function b3(Z){try{if(Z.inspectTrash){let X=Z.inspectTrash();return X.ok?{path:X.path,error:null}:{path:null,error:`${X.code}: ${x0[X.code]}`}}return{path:Z.findTrash(),error:null}}catch(X){return{path:null,error:X instanceof Error?X.message:String(X)}}}var f3="[trash-guard] No verified @hasna/trash guard was found on PATH. This deletion is refused. Install the current @hasna/trash package with Bun and run its setup; the operating-system trash utility is not a compatible guard.";function e0(Z,X){if(Z.hook_event_name!=="PreToolUse")return{continue:!0};if(["apply_patch","ApplyPatch","functions.apply_patch"].includes(Z.tool_name??"")){let B=Z.tool_input?.command;if(typeof B!=="string")return u("[trash-guard] Unreadable patch input; deletion safety cannot be checked.");if(/^\s*\*\*\* Delete File:/m.test(B))return u("[trash-guard] Delete File would bypass recoverable deletion. First use `trash put -- <path>` or the trash_put MCP tool, then submit any remaining edits without the deletion block.");return{continue:!0}}if(Z.tool_name!=="Bash")return{continue:!0};if(typeof Z.tool_input?.command!=="string")return u("[trash-guard] The Bash tool call carried no readable `command`, so this hook cannot verify what would run. Refusing a call it cannot verify. Re-run the delete explicitly as `rm -- <path>` so it can be redirected into trash.");let J=BZ(Z);if(!J.trim())return{continue:!0};let z=LZ(J,{cwd:X.cwd,home:X.home});if(z.refusals.length>0)return u(`[trash-guard] ${z.refusals[0].reason}`);if(z.protectedHits.length>0)return u(`[trash-guard] ${z.protectedHits[0].reason}`);if(!z.trustworthy)return a(J)?u("[trash-guard] This command could not be parsed to the end (unterminated quote, substitution or here-document), so a delete inside it cannot be redirected. Re-run the delete as a plain `rm -- <path>` command."):{continue:!0};if(z.rmHits.length===0){if(z.handoffHits.some((B)=>B.cwdOnly))return u("[trash-guard] This delete runs from inside a protected repository checkout but names only paths outside it. Run it from outside the checkout (`cd /tmp && rm -- <path>`), where it is redirected into trash.");if(z.handoffHits.length>0)return{continue:!0};return{continue:!0}}if(z.handoffHits.length>0)return u("[trash-guard] This command mixes a delete under the protected repo-checkout roots (owned by workspace-repos-guard) with a delete outside them, and a partial rewrite would leave one of them unredirected. Re-run them as separate commands, so each delete is handled by the hook that owns it.");let Y=b3(X);if(Y.error!==null)return u(`[trash-guard] The guard could not resolve the \`trash\` binary (${Y.error}), so this \`rm\` cannot be redirected into a recoverable delete — and an unrecoverable delete is never allowed, so the command is refused rather than run. Fix the environment (PATH, permissions) and re-run the same command.`);if(Y.path===null)return u(f3);let Q=Y.path;if(X.execution&&E3(J))return u("[trash-guard] A deletion combined with shell environment changes cannot use the verified native execution context. Run the deletion as a separate plain rm command.");let H=v3(J,z.rmHits,Q,X.execution),K=y3(Z.tool_input,H);if(X.execution)K.hasna_execution="hasna.hooks.execution.v1";if(!R3(K,J,z.rmHits,X.cwd,X.home))return u("[trash-guard] The rewrite of this command did not verify (the delete could not be redirected cleanly), so the command is refused rather than run unredirected. Re-run the delete as a plain `rm -- <path>` command.");return S3(K)}var k=require("node:fs"),V0=require("node:os"),P=require("node:path");var k3=new Set(["Write","Edit","MultiEdit","NotebookEdit"]),x3=new Set(["apply_patch","ApplyPatch","functions.apply_patch"]),w3=["hasna","hasnaxyz","hasna-products"],vZ="workspace-repos-guard";function h3(Z){return P.join(Z,".hasna","repos","clones")}function g3(Z){return P.join(Z,"workspace","repos")}function Q2(Z){return[h3(Z),g3(Z)]}function u3(Z){return P.join(Z,".hasna","hooks","config","workspace-repos-guard-orgs")}var l3=/^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/;function K0(Z){let X=process.getuid?.();return X!==void 0&&(Z.uid===0||Z.uid===X)&&(Z.mode&18)===0}function m3(Z){let X=u3(Z),$;try{let z=k.openSync(X,k.constants.O_RDONLY|k.constants.O_NOFOLLOW);try{let Q=k.fstatSync(z);if(!Q.isFile()||!K0(Q)||Q.size>4096)return null;$=k.readFileSync(z,"utf8")}finally{k.closeSync(z)}let Y=P.normalize(Z);for(let Q=P.dirname(X);Q!==Y;Q=P.dirname(Q)){let H=k.lstatSync(Q);if(!H.isDirectory()||!K0(H)||Q===P.dirname(Q))return null}if(!K0(k.statSync(Y)))return null}catch{return null}let J=$.replace(/#[^\n]*/g,"").split(/[\s,]+/).filter(Boolean);return J.length>0&&J.every((z)=>l3.test(z))?new Set(J):null}function p3(Z=process.env,X=V0.homedir()){let $=Z.WORKSPACE_REPOS_GUARD_ORGS;if(typeof $==="string"&&$.trim())return new Set($.split(",").map((J)=>J.trim()).filter(Boolean));return m3(X)??new Set(w3)}function H0(Z,X,$,J){if(J==="read")return{blocked:!1};let z=P.relative(X,Z);if(z===""){if(J==="delete")return{blocked:!0,reason:`[${vZ}] delete of the protected repo-checkout root is forbidden: ${X}`};return{blocked:!0,reason:`[${vZ}] writes directly to the protected repo-checkout root are forbidden: ${X}`}}if(z.startsWith(`..${P.sep}`)||z===".."||P.isAbsolute(z))return{blocked:!1};let Y=z.split(P.sep).filter(Boolean);if(J==="delete")return{blocked:!0,reason:`[${vZ}] delete under the protected repo-checkout root (${X}) is forbidden at any depth: ${Z}`};if(Y.length<=1)return{blocked:!0,reason:`[${vZ}] writing would create a top-level entry directly under the protected repo-checkout root (${X}); only GitHub-org folders belong there: ${Z}`};let Q=Y[0];if(!$.has(Q))return{blocked:!0,reason:`[${vZ}] '${Q}' is not an allowed GitHub org under the protected repo-checkout root (${X}); allowed: ${[...$].join(", ")}: ${Z}`};return{blocked:!1}}var K2=/\b(?:-o|--output|-O|--output-document|-out)\b/,c3=/\d*[<>]&\s*(?:\d+|-)(?=$|[\s;&|)])/g,d3=/(?:\d+|&)?(?:>>|>\||>&|<>|>)\s*([^\s;&|<>()\x60]*)/g;function H2(Z){return Z.replace(c3," ")}function i3(Z){let X=[],$=null,J=0,z=0,Y=!1,Q=0;for(let H=0;H<Z.length;H++){let K=Z[H];if($==="'"){if(K==="'")$=null;continue}if(K==="\\"){H++;continue}if(K==="("){J++;continue}if(K===")"){if(--J<0)return[Z];continue}if(K==="$"&&Z[H+1]==="{"){z++,H++;continue}if(K==="}"&&z>0){z--;continue}if(K==="`"){Y=!Y;continue}if($==='"'){if(K==='"')$=null;continue}if(K==="'"||K==='"'){$=K;continue}if(K!=="|"||J>0||z>0||Y||Z[H-1]===">")continue;if(X.push(Z.slice(Q,H)),Z[H+1]==="&")H++;Q=H+1}if($||J!==0||z!==0||Y)return[Z];return X.push(Z.slice(Q)),X}function s3(Z){let X=[],$="",J="",z=null,Y=!1,Q=()=>{if(!Y)return;let H=J.replace(/^"?\$\{?HOME\}?"?(?=\/|$)/,""),K=$.startsWith("~")&&!/^~(?:\/|$)/.test(J);X.push({text:K?`./${$}`:$,opaque:/[$\x60*?[]/.test(H)||/[()]/.test(H)||kZ(J)}),$="",J="",Y=!1};for(let H=0;H<Z.length;H++){let K=Z[H];if(z==="'"){if(K==="'")z=null;else $+=K;J+=K;continue}if(K==="\\"&&H+1<Z.length){let B=Z[H+1];$+=z==='"'&&!/[$\x60"\\\n]/.test(B)?K+B:B,J+=K+B,Y=!0,H++;continue}if(z==='"'){if(K==='"')z=null;else $+=K;J+=K;continue}if(/\s/.test(K)){Q();continue}if(Y=!0,J+=K,K==="'"||K==='"')z=K;else $+=K}if(z)J+="$";return Q(),X}function B0(Z,X,$){let J=Z[X];return J==="--help"||J==="--version"||$&&(J==="-h"||J==="-V")}var Z2={read:0,write:1,delete:2};function gZ(...Z){return Z.reduce((X,$)=>Z2[$]>Z2[X]?$:X,"read")}var n3=new Set(["status","doctor","list","info","get","pending","station","setup","backup","storage","retrieval","backup-storage","backup-inspect","backup-refresh","help"]),B2=new Set(["put","rm","delete","remove"]),a3=new Set([...B2,"restore","restore-capsule","recover","release","locks","retention","hold","unhold","pin","unpin","retrieve","backup-retrieve"]),o3=new Set(["-delete","-exec","-execdir","-ok","-okdir","-fls","-fprint","-fprint0","-fprintf"]);function r3(Z){let X=null;for(let $=0;$<Z.length;$++){let J=Z[$];if(X==="'"){if(J==="'")X=null;continue}if(J==="\\"){$++;continue}if(J==="$"||J==="`")return!0;if(X==='"'){if(J==='"')X=null;continue}if(J==="'"||J==='"')X=J;else if("*?[{".includes(J))return!0}return X!==null}function t3(Z){let X=Z.trim();if(!X)return"read";let $=o(X);if(!$.trustworthy||$.substitutions.length||/\$\{[^}]*[|;()]|[<>]\(/.test(X))return AZ(X);let J=$.segments.flatMap((z)=>{let Y=$2(z),Q=z.words.filter((B,M)=>!z.redirects.has(M)).map((B)=>B.text),H=Q.map(zZ);if(H.every((B,M)=>B!==null&&B.length===1&&B[0]===Q[M]))return[Y];if(H.some((B)=>B===null))return[Y,AZ(Q.join(" "))];let K=o(H.flatMap((B)=>B??[]).join(" "));return[Y,...K.trustworthy?K.segments.map($2):[AZ(Q.join(" "))]]});return gZ(...J)}function $2(Z){let X=Z.words.map((Y,Q)=>({word:Y,at:Q})).filter(({at:Y})=>!Z.redirects.has(Y)),$=p(Z),J=$<0?"read":J2(Z,$),z=DZ(X.map(({word:Y})=>({text:R(Y.text),opaque:/[$\x60]/.test(Y.text)})));if(z===null)return gZ(J,AZ(X.map(({word:Y})=>R(Y.text)).join(" ")));if(z.index<0||X[z.index].at===$)return J;return gZ(J,J2(Z,X[z.index].at))}function J2(Z,X){let $=Z.words.filter((Y,Q)=>Q>=X&&!Z.redirects.has(Q)),J=$.map((Y)=>R(Y.text)),z=J[0].split("/").pop();if(["rm","rmdir","shred"].includes(z??""))return B0(J,1,!1)?"read":"delete";if(["unlink","rmtree","del"].includes(z??""))return"delete";if(z==="trash"){let Y=1;while(Y<J.length&&J[Y].startsWith("-")){let Q=J[Y++];if(["--help","-h","--version","-V","--identity"].includes(Q))return"read";if(["--agent","--spool","--files","--info","--config"].includes(Q))Y++;else if(!["--json","--local"].includes(Q))return"delete"}if(Y===J.length||n3.has(J[Y]))return"read";if(a3.has(J[Y])&&B0(J,Y+1,!0))return"read";if(["restore","restore-capsule"].includes(J[Y]))return"write";return"delete"}if(z==="git"){let Y=Q0(Z,X);if(Y==="clean"||Y==="rm")return J[1]===Y&&B0(J,2,!0)?"read":"delete";return Y==="clone"||Y==="init"?"write":"read"}if(z==="find"&&!$.some((Y)=>r3(Y.text))&&!J.some((Y)=>o3.has(Y)))return"read";if(z==="env"&&a(PZ(J)))return"delete";if(["sh","bash","zsh","dash","ksh","ash","eval","source",".","su","runuser","env","xargs","find","busybox","toybox"].includes(z??""))return AZ(J.join(" "));if(["mkdir","mkfile","touch","mv","cp","ln","tee","install","dd","rsync","scp","truncate"].includes(z??""))return"write";if(z==="curl"||z==="wget")return K2.test(J.join(" "))?"write":"read";if(z==="sed"&&J.slice(1).some((Y)=>/^-i|^--in-place(?:=|$)/.test(Y)))return"write";if(["python","python3","node","bun"].includes(z??"")&&J.some((Y)=>Y==="-c"||Y==="-e"))return"write";return"read"}function AZ(Z){let X=Z.replace(/[{},]/g," ");return X===Z?M0(Z):gZ(M0(Z),M0(X))}function M0(Z){let X=Z.trim();if(!X)return"read";if(/(?:^|\s)\\?(?:[^\s;&|<>()]*\/)?(?:rm|rmdir|unlink|shred|trash|rmtree|del)(?:\s|$)/.test(X))return"delete";if(/\bgit\b/.test(X)){if(/\bgit\b[^;&|]*\b(?:clean|rm)\b/.test(X))return"delete";if(/\bgit\b[^;&|]*\b(?:clone|init)\b/.test(X))return"write";return"read"}if(/(?:^|\s)\\?(?:[^\s;&|<>()]*\/)?(?:mkdir|mkfile|touch|mv|cp|ln|tee|install|dd)(?:\s|$)/.test(X))return"write";if(/\b(?:curl|wget)\b/.test(X)){if(K2.test(X))return"write";return"read"}if(/\bsed\b/.test(X)){if(/(?:^|\s)-i\S*(?:\s|$)|--in-place(?:\s|$)/.test(X))return"write"}else if(/\b(?:rsync|scp|truncate)\b/.test(X))return"write";else if(/(?:^|\s)(?:python3?|node|bun)\b[^;&|]*\s+-[ce](?:\s|$)/.test(X))return"write";if(/(?:^|[;&|])\s*echo\b/.test(X)||/>/.test(H2(X)))return"write";return"read"}function yZ(Z,X){let $=Z.trim(),J=$.match(/^(['"])([\s\S]*)\1$/);if(J)$=J[2];if($=$.replace(/^"*\$HOME"*\//,"$HOME/"),$=$.replace(/^"*\$\{HOME\}"*\//,"${HOME}/"),$==="~")return X;if($.startsWith("~/"))return P.join(X,$.slice(2));if($==="$HOME"||$==="${HOME}")return X;if($.startsWith("$HOME/"))return P.join(X,$.slice(6));if($.startsWith("${HOME}/"))return P.join(X,$.slice(8));let z=$.match(new RegExp(`^"*${G0(X)}"*/`));if(z)return X+"/"+$.slice(z[0].length);return Z}function e3(Z){let X=Z.trim();while(X.startsWith("(")||/^\{(?:\s|$)/.test(X))X=X.slice(1).trim();while(X.endsWith(")")||/(?:^|\s)\}$/.test(X))X=X.slice(0,-1).trim();return X}function G0(Z){return Z.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function X2(Z,X,$){if(Z===void 0)return[$];let J=yZ(Z,$),z=J.match(/^(['"])(.*)\1$/);if(z)J=z[2];if(!J||J==="-"||/[$\x60*?[\]{}~\\'"]/.test(J))return null;return[...new Set(X.map((Y)=>P.resolve(Y,J)))]}var Z4=/(?:^|\s)(\.\.?|[^\s"';&|<>()\x60/]+(?:\/[^\s"';&|<>()\x60]*)?)\s*$/;function $4(Z,X){let $=DZ(X);if(!$||$.index<=0||X[$.index].opaque)return 0;let J=o(Z);if(!J.trustworthy||J.substitutions.length>0||J.segments.length!==1)return 0;let[z]=J.segments;if(z.redirects.size>0||z.words.length!==X.length)return 0;if(z.words.some((Y,Q)=>R(Y.text)!==X[Q].text))return 0;return p(z)===$.index?$.index:0}function J4(Z,X){let $=0;if(Z==="git")$=X.findIndex((z)=>z.text==="rm"||z.text==="clean")+1;let J=!1;return X.slice($).filter((z)=>{if(!J&&z.text==="--")return J=!0,!1;if(!J&&z.text.startsWith("-")&&!z.opaque)return!1;return J=!0,!0})}var X4=new Set(["--agent","--spool","--files","--info","--config"]),z4=new Set(["--spool","--files","--info","--config"]),Y4=new Set(["--json","--local","--help","-h","--version","--identity"]),z2={"--agent":/^[^-]/,"--retention":/^(?:\d+(?:\.\d+)?|never)$/},Q4=new Set(["--to"]);function K4(Z){let X=[],$=0;for(;$<Z.length&&Z[$].text.startsWith("-");$++){let Y=Z[$];if(Y.opaque)return null;if(X4.has(Y.text)){let Q=Z[++$];if(!Q||Q.opaque)return null;if(z4.has(Y.text))X.push(Q)}else if(!Y4.has(Y.text))return null}let J=Z[$];if(!J||J.opaque||!B2.has(J.text))return null;let z=!1;for($++;$<Z.length;$++){let Y=Z[$];if(z||Y.opaque||Y.text==="-"||!Y.text.startsWith("-")){X.push(Y);continue}if(Y.text==="--"){z=!0;continue}let Q=Y.text.indexOf("="),H=Q<0?Y.text:Y.text.slice(0,Q);if(Q4.has(H)){if(Q>=0)X.push({text:Y.text.slice(Q+1),opaque:!1});else if(Z[$+1]&&!Z[$+1].text.startsWith("-"))X.push(Z[++$]);continue}let K=Z[$+1];if(Q<0&&Object.hasOwn(z2,H)&&K&&!K.opaque&&z2[H].test(K.text))$++}return X}function H4(Z){let X=Z.split(`
|
|
15
|
+
`),$=[],J=[],z=0;while(z<X.length){let Y=z,Q=X[z++].replace(/\r$/,""),H=[];for(let K=0;K<Q.length;K++){let B=Q[K],M=J[J.length-1];if(B==="\\"){K++;continue}if(B==="$"&&Q[K+1]==="("&&Q[K+2]==="("){let V=Q.indexOf("))",K+3);if(V<0)return null;K=V+1;continue}if(B==="$"&&Q[K+1]==="("){J.push(0),K++;continue}if(B==="$"&&Q[K+1]==="[")return null;if(B==="$"&&Q[K+1]==="{"){let V=Q.indexOf("}",K+2);if(V<0||/['"\x60$]|<</.test(Q.slice(K+2,V)))return null;K=V;continue}if(B==="`"){let V=Q.indexOf("`",K+1);if(V<0)return null;K=V;continue}if(M==='"'){if(B==='"')J.pop();continue}if(B==="'"){let V=Q.indexOf("'",K+1);if(V<0)return null;K=V;continue}if(B==='"'){J.push('"');continue}if(B==="#"&&(K===0||/[\s;&|()]/.test(Q[K-1])))break;if(B==="("&&Q[K+1]==="("&&(K===0||/[\s;&|(]/.test(Q[K-1]))){let V=Q.indexOf("))",K+2);if(V<0)return null;K=V+1;continue}if(typeof M==="number"&&(B==="("||B===")")){if(B==="(")J[J.length-1]=M+1;else if(M===0)J.pop();else J[J.length-1]=M-1;continue}if(B==="<"&&Q[K+1]==="<"){if(Q[K+2]==="<"){K+=2;continue}let V=GZ(Q,K);if(!V)return null;H.push({marker:V,from:K}),K=V.end-1}}for(let{marker:K,from:B}of H){let M=z;for(;;){if(z>=X.length)return null;let V=X[z++].replace(/\r$/,"");if(K.stripTabs)V=V.replace(/^\t+/,"");if(V===K.delimiter)break}$.push({line:Y,from:B,to:K.end,start:M,end:z-1,quoted:K.quoted})}}return J.length===0?$:null}var B4=new Set(["sh","bash","zsh","dash","ksh","mksh","ash","fish","csh","tcsh","nu","xonsh","elvish","busybox","toybox","ssh","su","runuser","sudo","doas","pkexec","xargs","parallel","expect","script","at","batch","crontab","watch","flock","chroot","nsenter","unshare","docker","podman","kubectl","lxc","python","pypy","node","nodejs","bun","deno","tsx","ts-node","zx","npx","bunx","pnpx","perl","ruby","irb","php","lua","luajit","osascript","pwsh","powershell","Rscript","R","julia","tclsh","wish","awk","gawk","mawk","nawk","sed","make","gmake","gdb","lldb","sqlite3","psql","mysql","sftp","ftp","lftp","vim","vi","nvim","ex","ed","emacs","chmod"]),M4=new Set([".","source","eval","env","alias","hash"]),G4=new Set(["tee","cp","mv","install","ln"]),V4=new Set(["cat","tac","tee","head","tail","wc","cut","tr","nl","rev","fold","fmt","paste","uniq","grep","egrep","fgrep","jq","diff","cmp","comm","iconv","od","xxd","hexdump","base64","base32","md5sum","sha1sum","sha224sum","sha256sum","sha384sum","sha512sum","b2sum","cksum","echo","printf","true","false",":","test","[","read","cd","pwd","ls","mkdir","touch","stat","sleep","cp","mv","ln","rm","rmdir","unlink","shred","trash","todos","conversations","mementos","knowledge","files","asks"]),U4=new Set(["add","commit","tag","notes","status","diff","log","show","rev-parse","branch","switch","push","fetch","hash-object","apply"]),j4=new Set(["pr","issue","api","release","gist"]);function W4(Z,X){let $=Z[X];if($==="gh")return j4.has(Z[X+1]??"");if($!=="git")return V4.has($);for(let J=X+1;J<Z.length;J++){let z=Z[J];if(z==="-C")J++;else if(z==="--no-pager"||z==="-P")continue;else return!z.startsWith("-")&&U4.has(z)}return!1}function q4(Z,X){for(let $=X+1;$<Z.length;$++){let J=Z[$];if(J==="\\")$++;else if(J==='"')return $;else if(J==="$"&&Z[$+1]==="("){if($=M2(Z,$+1),$<0)return-1}else if(J==="`"){if($=Z.indexOf("`",$+1),$<0)return-1}}return-1}function M2(Z,X){let $=0;for(let J=X;J<Z.length;J++){let z=Z[J];if(z==="\\")J++;else if(z==="'"||z==="`"){if(J=Z.indexOf(z,J+1),J<0)return-1}else if(z==='"'){if(J=q4(Z,J),J<0)return-1}else if(z==="(")$++;else if(z===")"&&--$===0)return J}return-1}function N4(Z){let X=[],$=!1;for(let J=0;J<Z.length;J++){let z=Z[J];if(z==="\\")J++;else if(z==="'"&&!$){let Y=Z.indexOf("'",J+1);if(Y<0)return null;J=Y}else if(z==='"')$=!$;else if(z==="$"&&Z[J+1]==="("){let Y=M2(Z,J+1);if(Y<0)return null;let Q=Z.slice(J+2,Y);if(Z[J+2]==="("){if(/\$\(|\x60/.test(Q))return null}else X.push(Q);J=Y}else if(z==="`"){let Y=Z.indexOf("`",J+1);if(Y<0)return null;X.push(Z.slice(J+1,Y)),J=Y}}return $?null:X}function _4(Z){if(/[<>]\(/.test(Z))return!0;let X=[],$=[Z];for(let z=0;$.length>0;z++){if(z>64)return!0;let Y=$.shift(),Q=o(Y),H=N4(Y);if(!Q.trustworthy||!H)return!0;X.push(...Q.segments),$.push(...new Set([...Q.substitutions,...H]))}let J=new Set;for(let z of X){let Y=z.words.map((K)=>R(K.text));for(let K of z.redirects)J.add(s(Y[K]??""));let Q=p(z);if(Q<0)continue;let H=s(Y[Q]);if(G4.has(H)){for(let K of Y.slice(Q+1))if(!K.startsWith("-"))J.add(s(K))}if(H==="dd"){for(let K of Y)if(K.startsWith("of="))J.add(s(K.slice(3)))}}J.delete("");for(let z of X){for(let B of z.words){let M=s(R(B.text));if(B4.has(M)||/^(?:python|pypy|node|perl|ruby|php|lua)[0-9.]+$/.test(M))return!0}let Y=p(z),Q=z.words.map((B,M)=>({text:R(B.text),at:M})).filter(({at:B})=>!z.redirects.has(B));if(Q.some(({text:B,at:M})=>(Y<0||M<Y)&&fZ.test(B)))return!0;if(Y<0)continue;let H=z.words[Y].text,K=R(H);if(/[$\x60]/.test(H)||K.includes("/")||M4.has(K)||J.has(K))return!0;if(!W4(Q.filter(({at:B})=>B>=Y).map(({text:B})=>B),0))return!0}return!1}function I4(Z){if(!Z.includes("<<"))return null;let X=H4(Z);if(!X||X.length===0)return null;let $=Z.split(`
|
|
16
|
+
`),J=[...$],z=[];for(let Q of X){let H=$.slice(Q.start,Q.end);if(!Q.quoted&&H.some((K)=>/\$\(|\x60/.test(K)))return null;z.push(H.join(`
|
|
17
|
+
`));for(let K=Q.start;K<=Q.end;K++)J[K]=""}let Y=[...J];for(let Q of[...X].reverse()){let H=Y[Q.line];Y[Q.line]=H.slice(0,Q.from)+" ".repeat(Q.to-Q.from)+H.slice(Q.to)}return _4(Y.join(`
|
|
18
|
+
`))?null:{outer:J.join(`
|
|
19
|
+
`),bodies:z}}var T4="/";function G2(Z,X,$){if(!Z)return[];let J=I4(Z);if(!J)return Y2(Z,X,$);return[...Y2(J.outer,X,$),...J.bodies.flatMap((z)=>G2(z,X,T4))]}function Y2(Z,X,$){if(!Z)return[];let J=Q2(X),z=(V)=>J.some((G)=>V===G||V.startsWith(`${G}${P.sep}`)),Y=Z.split(/(\s*&&\s*|\s*\|\|\s*|;\s*|\n+)/),Q=[],H=[$],K=new Set([$]),B=!0,M=[];for(let V=0;V<Y.length;V+=2){let G=V===0?"":Y[V-1].trim();if(G==="||")B=!1;else if(G!=="&&")B=!0;if(G!=="&&"||!B)H=[...K];let j=Y[V],D=(j.match(/^[\s({]*/)?.[0].match(/\(/g)??[]).length,v=(j.match(/[\s)}]*$/)?.[0].match(/\)/g)??[]).length;for(let T=0;T<D;T++)M.push({current:[...H],reachable:new Set(K),certain:B});let b=e3(j),E=b.match(/^cd(?:\s+(?:-[A-Za-z@]+|--))*(?:\s+([^\s;&|<>()\x60]+))?$/),JZ=E?null:b.match(/(?:^|\s)cd(?:\s+(?:-[A-Za-z]+|--))*\s+([^\s;&|<>()\x60]+)/);if(JZ){for(let T of X2(JZ[1],H,X)??[])K.add(T);B=!1,H=[...K]}let i=G0(X),I=J.map((T)=>G0(T.slice(X.length+1))).join("|"),W=new RegExp(`(?:~|\\$HOME"*|\\$\\{HOME\\}"*|${i}"*)/(?:${I})`),A=new RegExp(`(${W.source})([^\\s"';&|<>()\`]*|$)`,"g"),w=(T)=>{let c=[],g;A.lastIndex=0;while((g=A.exec(T))!==null)c.push(P.normalize(yZ(g[0],X)).replace(/\/+$/,""));return c},f=i3(b).map((T)=>{let c=[],g=!1,WZ=H2(T).replace(d3,(nZ,XZ)=>{if(!XZ||/[$\x60]/.test(XZ))g=!0;if(XZ)c.push(XZ);return" "}),qZ=t3(WZ);return{commandPart:WZ,operands:c,op:g&&qZ==="read"?"write":qZ}}),jZ=f.some((T)=>T.op==="delete")?"delete":f.some((T)=>T.op==="write")?"write":"read",S0=H.filter(z);for(let T of f){let c=!1;for(let h of w(T.commandPart))c=!0,Q.push({path:h,op:jZ});for(let h of T.operands){let r=w(h);for(let m of r)Q.push({path:m,op:"write"});if(r.length>0)continue;for(let m of S0)Q.push({path:P.normalize(P.resolve(m,yZ(h,X))),op:"write"})}if(c||T.op==="read")continue;let g=s3(T.commandPart),WZ=$4(T.commandPart,g),qZ=s(g[WZ]?.text??""),nZ=g.slice(WZ+1),XZ=((qZ==="trash"?K4(nZ):null)??J4(qZ,nZ)).map((h)=>h.opaque?".":h.text),E2=T.op==="delete"||/(?:^|\s)\\?(?:[^\s;&|<>()]*\/)?(?:mkdir|mkfile|touch|tee|truncate|install|mv)(?:\s|$)/.test(T.commandPart)||/(?:^|\s)sed(?:\s|$)/.test(T.commandPart)&&/(?:^|\s)(?:-i\S*|--in-place\S*)(?:\s|$)/.test(T.commandPart),NZ=[];if(E2)for(let h of XZ.length>0?XZ:["."])NZ.push({operand:h,op:T.op});else{let h=T.commandPart.match(Z4),r=g.at(-1);if(NZ.push({operand:h?h[1]:!r||r.opaque?".":r.text,op:T.op}),/(?:^|\s)(?:cp|ln|install|mv)(?:\s|$)/.test(T.commandPart))g.forEach((m,b0)=>{let HZ,aZ=m.text.match(/^-[A-Za-z]*?t(.*)$/),EZ=m.text.match(/^(--t[a-z-]*)(?:=(.*))?$/);if(aZ&&!m.text.startsWith("--"))HZ=aZ[1]?{text:aZ[1],opaque:m.opaque}:g[b0+1];else if(EZ&&"--target-directory".startsWith(EZ[1]))HZ=EZ[2]!==void 0?{text:EZ[2],opaque:m.opaque}:g[b0+1];if(HZ)NZ.push({operand:HZ.opaque||!HZ.text?".":HZ.text,op:T.op})});if(/(?:^|\s)(?:python3?|node|bun)\b[^;&|]*\s+-[ce](?:\s|$)/.test(T.commandPart))NZ.push({operand:".",op:T.op})}for(let h of S0)for(let{operand:r,op:m}of NZ)Q.push({path:P.normalize(P.resolve(h,yZ(r,X))),op:m})}if(E){let T=X2(E[1],H,X);if(T){for(let c of T)K.add(c);if(B)H=T}else B=!1}for(let T=0;T<v&&M.length>0;T++)({current:H,reachable:K,certain:B}=M.pop())}return Q}var C4=/^\s*\*\*\*\s+(Add File|Update File|Delete File):\s+(\S+)\s*$/gm;function D4(Z,X){let $=[],J;while((J=C4.exec(Z))!==null){let z=J[1]==="Delete File"?"delete":"write";$.push({path:P.normalize(P.resolve(X,J[2])),op:z})}return $}function V2(Z,X={}){let $=[];if(Z.hook_event_name!=="PreToolUse")return{output:{continue:!0},warnings:$};let J=typeof Z.tool_name==="string"?Z.tool_name:"",z=X.home??V0.homedir(),Y=Q2(z),Q=p3(process.env,z);if(J==="Bash"){let G=BZ(Z);if(!G)return{output:{continue:!0},warnings:$};let j=typeof Z.cwd==="string"&&Z.cwd?Z.cwd:process.cwd(),D=G2(G,z,j);for(let v of D)for(let b of Y){let E=H0(v.path,b,Q,v.op);if(E.blocked)return{output:{decision:"block",reason:E.reason},warnings:$}}return{output:{continue:!0},warnings:$}}let H=Z.tool_input??{},K=typeof Z.cwd==="string"&&Z.cwd?Z.cwd:process.cwd();if(x3.has(J)){let G=typeof H.patch==="string"?H.patch:"";if(!G)return{output:{continue:!0},warnings:$};let j=D4(G,K);for(let D of j)for(let v of Y){let b=H0(D.path,v,Q,D.op);if(b.blocked)return{output:{decision:"block",reason:b.reason},warnings:$}}return{output:{continue:!0},warnings:$}}if(!k3.has(J))return{output:{continue:!0},warnings:$};let B=typeof H.file_path==="string"?H.file_path:typeof H.path==="string"?H.path:typeof H.notebook_path==="string"?H.notebook_path:null;if(!B)return{output:{continue:!0},warnings:$};let M=yZ(B,z),V=P.isAbsolute(M)?P.normalize(M):P.resolve(K,M);for(let G of Y){let j=H0(V,G,Q,"write");if(j.blocked)return{output:{decision:"block",reason:j.reason},warnings:$}}return{output:{continue:!0},warnings:$}}var F4=new Set(["id","node_id","databaseId","fullDatabaseId","number","state","state_reason","stateReason","status","conclusion","bucket","name","login","sha","oid","abbreviatedOid","ref","headRefName","baseRefName","headRefOid","baseRefOid","head_sha","headSha","head_branch","headBranch","merged","mergeable","mergeable_state","mergeStateStatus","draft","isDraft","locked","isLocked","title","displayTitle","display_title","created_at","updated_at","closed_at","merged_at","started_at","completed_at","submitted_at","pushed_at","published_at","createdAt","updatedAt","closedAt","mergedAt","startedAt","completedAt","submittedAt","pushedAt","publishedAt","tag_name","tagName","total_count","totalCount","count","additions","deletions","changes","changed_files","changedFiles","filename","path","event","workflow","workflowName","workflow_id","workflowDatabaseId","run_id","run_number","run_attempt","attempt","check_suite_id","default_branch","defaultBranch","full_name","fullName","nameWithOwner","private","isPrivate","visibility","archived","isArchived","fork","isFork","isRequired","is_required","required","context","type","__typename","role","permission","size","reviewDecision","author_association","authorAssociation","isCrossRepository","maintainerCanModify","maintainer_can_modify","commentsCount","language","digest","size_in_bytes","run_started_at","date","wait_timer","ahead_by","behind_by","total_commits","expired","current_user_can_approve","environment","html_url"]),P4=new Set(["payload","client_payload","inputs","config","metadata","output","properties","custom_properties","variables"]),q2=new Set(["length","utf8bytelength","not","type","any","all","isempty","empty","test","startswith","endswith","contains","inside","has","in","index","rindex","indices","floor","ceil","round","fabs","sqrt","isinfinite","isnan","isnormal","infinite","nan","true","false","null"]),N2=new Set(["tostring","tojson","ascii_downcase","ascii_upcase","ltrimstr","rtrimstr","trim","ltrim","rtrim","sort","unique","reverse","first","last","min","max","add","flatten","join","split","values","nulls","strings","numbers","booleans","arrays","objects","iterables","scalars","sort_by","group_by","unique_by","min_by","max_by","select","limit","to_entries","from_entries"]),O4=new Set(["test","startswith","endswith","contains","inside","has","in","index","rindex","indices","ltrimstr","rtrimstr","join","split","flatten","limit"]),L4=new Set(["@text","@json","@csv","@tsv","@sh","@base64","@uri","@html"]);class W0 extends Error{}var O=()=>{throw new W0};function U0(Z,X){let $=[],J="",z=X+1;while(z<Z.length){let Y=Z[z];if(Y==='"'){if(J)$.push(J);return{end:z+1,parts:$}}if(Y==="\\"){let Q=Z[z+1];if(Q==="("){let H=1,K=z+2;while(K<Z.length&&H>0){let B=Z[K];if(B==='"'){K=U0(Z,K).end;continue}if(B==="(")H++;else if(B===")")H--;K++}if(H!==0)O();if(J)$.push(J),J="";$.push({src:Z.slice(z+2,K-1)}),z=K;continue}if(Q===void 0)O();J+=Q,z+=2;continue}J+=Y,z++}return O()}function _2(Z){let X=[],$=0,J=["?//","|=","+=","-=","*=","/=","%=","//=","==","!=","<=",">=","//","|",",","+","-","*","/","%","<",">","=","(",")","[","]","{","}",":",";","?"];while($<Z.length){let z=Z[$];if(/\s/.test(z)){$++;continue}if(z==="#")O();if(z==='"'){let K=U0(Z,$);X.push({t:"str",parts:K.parts}),$=K.end;continue}if(z==="."){if(Z[$+1]===".")O();let K=/^[A-Za-z_][A-Za-z0-9_]*/.exec(Z.slice($+1));if(K){X.push({t:"field",name:K[0]}),$+=1+K[0].length;continue}if(Z[$+1]==='"'){let B=U0(Z,$+1);if(B.parts.some((M)=>typeof M!=="string"))O();X.push({t:"field",name:B.parts.join("")}),$=B.end;continue}X.push({t:"dot"}),$++;continue}if(z==="$"||z==="@"){let K=/^[@$][A-Za-z_][A-Za-z0-9_]*/.exec(Z.slice($));if(!K||z==="$")O();X.push({t:"fmt",name:K[0]}),$+=K[0].length;continue}let Y=/^[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?/.exec(Z.slice($));if(Y){X.push({t:"num"}),$+=Y[0].length;continue}let Q=/^[A-Za-z_][A-Za-z0-9_]*(?:::[A-Za-z_][A-Za-z0-9_]*)*/.exec(Z.slice($));if(Q){X.push({t:"ident",name:Q[0]}),$+=Q[0].length;continue}let H=J.find((K)=>Z.startsWith(K,$));if(!H)O();X.push({t:"op",v:H}),$+=H.length}return X}var v4=new Set(["if","then","elif","else","end","as","def","reduce","foreach","try","catch","label","import","include","and","or","__loc__","error","input","inputs","debug","stderr","env","halt","halt_error","input_filename","input_line_number","recurse","paths","leaf_paths","getpath","setpath","delpaths","del","path","splits","sub","gsub","capture","match","scan","keys","keys_unsorted","map_values","with_entries","tostream","fromstream","truncate_stream","walk","tonumber","implode","explode","ascii","fromjson"]);class q0{tokens;at=0;constructor(Z){this.tokens=Z}parse(){if(this.tokens.length===0)O();let Z=this.pipe();if(this.at!==this.tokens.length)O();return Z}peek(){return this.tokens[this.at]}isOp(Z){let X=this.peek();return!!X&&X.t==="op"&&X.v===Z}isIdent(Z){let X=this.peek();return!!X&&X.t==="ident"&&X.name===Z}expectOp(Z){if(!this.isOp(Z))O();this.at++}pipe(){let Z=this.comma();if(this.isIdent("as"))O();if(this.isOp("|"))this.at++,Z={k:"pipe",a:Z,b:this.pipe()};return Z}comma(){let Z=this.alt();while(this.isOp(","))this.at++,Z={k:"comma",a:Z,b:this.alt()};return Z}alt(){let Z=this.or();if(this.isOp("//"))return this.at++,{k:"alt",a:Z,b:this.alt()};return Z}or(){let Z=this.and();while(this.isIdent("or"))this.at++,Z={k:"bool",a:Z,b:this.and()};return Z}and(){let Z=this.cmp();while(this.isIdent("and"))this.at++,Z={k:"bool",a:Z,b:this.cmp()};return Z}cmp(){let Z=this.add();for(let X of["==","!=","<=",">=","<",">"])if(this.isOp(X))return this.at++,{k:"bool",a:Z,b:this.add()};for(let X of["=","|=","+=","-=","*=","/=","%=","//=","?//"])if(this.isOp(X))O();return Z}add(){let Z=this.mul();while(this.isOp("+")||this.isOp("-"))this.at++,Z={k:"arith",a:Z,b:this.mul()};return Z}mul(){let Z=this.unary();while(this.isOp("*")||this.isOp("/")||this.isOp("%"))this.at++,Z={k:"arith",a:Z,b:this.unary()};return Z}unary(){if(this.isOp("-"))return this.at++,{k:"neg",of:this.postfix()};return this.postfix()}objectValue(){let Z=this.unary();if(this.isOp("|"))this.at++,Z={k:"pipe",a:Z,b:this.objectValue()};return Z}postfix(){let Z=this.primary();for(;;){let X=this.peek();if(!X)return Z;if(X.t==="field"){this.at++,Z={k:"field",name:X.name,of:Z};continue}if(X.t==="dot"&&this.tokens[this.at+1]?.t==="op"&&this.tokens[this.at+1].v==="["){this.at++;continue}if(X.t==="op"&&X.v==="?"){this.at++,Z={k:"opt",of:Z};continue}if(X.t==="op"&&X.v==="["){Z=this.bracket(Z);continue}return Z}}bracket(Z){if(this.expectOp("["),this.isOp("]"))return this.at++,{k:"iter",of:Z};if(this.isOp(":")){if(this.at++,!this.isOp("]"))this.pipe();return this.expectOp("]"),{k:"slice",of:Z}}let X=this.pipe();if(this.isOp(":")){if(this.at++,!this.isOp("]"))this.pipe();return this.expectOp("]"),{k:"slice",of:Z}}return this.expectOp("]"),{k:"index",of:Z,key:X}}primary(){let Z=this.peek();if(!Z)return O();switch(this.at++,Z.t){case"dot":return{k:"dot"};case"field":return{k:"field",name:Z.name};case"num":return{k:"lit"};case"str":return this.stringNode(Z.parts);case"fmt":{if(!L4.has(Z.name))O();let X=this.peek();if(X?.t==="str")return this.at++,{k:"fmt",name:Z.name,str:this.stringNode(X.parts)};return{k:"fmt",name:Z.name}}case"ident":{if(v4.has(Z.name))O();if(Z.name==="map"||q2.has(Z.name)||N2.has(Z.name)){let X=[];if(this.isOp("(")){this.at++,X.push(this.pipe());while(this.isOp(";"))this.at++,X.push(this.pipe());this.expectOp(")")}return{k:"call",name:Z.name,args:X}}return O()}case"op":{if(Z.v==="("){let X=this.pipe();return this.expectOp(")"),X}if(Z.v==="["){if(this.isOp("]"))return this.at++,{k:"array"};let X=this.pipe();return this.expectOp("]"),{k:"array",of:X}}if(Z.v==="{")return this.object();return O()}}return O()}stringNode(Z){let X=[];for(let $ of Z){if(typeof $==="string")continue;X.push(new q0(_2($.src)).parse())}return X.length===0?{k:"str",parts:X,text:Z.join("")}:{k:"str",parts:X}}object(){let Z=[];if(this.isOp("}"))return this.at++,{k:"object",entries:Z};for(;;){let X=this.peek();if(!X)O();this.at++;let $;if(X.t==="ident")$=X.name;else if(X.t==="str"){if(X.parts.some((J)=>typeof J!=="string"))O();$=X.parts.join("")}else O();if(this.isOp(":"))this.at++,Z.push({key:"static",value:this.objectValue()});else Z.push({key:"static",value:{k:"field",name:$}});if(this.isOp(",")){this.at++;continue}return this.expectOp("}"),{k:"object",entries:Z}}}}function N0(Z){if(typeof Z==="object"&&"union"in Z)return Z.union.every(N0);return Z==="safe"||typeof Z==="object"&&F4.has(Z.leaf)}var RZ=(...Z)=>Z.every(N0)?"safe":"tainted";function j0(...Z){let X=[];for(let $ of Z)if(typeof $==="object"&&"union"in $)X.push(...$.union);else X.push($);return X.length===1?X[0]:{union:X}}function uZ(Z,X){return typeof Z==="object"&&"union"in Z?j0(...Z.union.map(X)):X(Z)}var lZ=(Z)=>typeof Z==="object"&&("leaf"in Z)&&P4.has(Z.leaf),e=(Z)=>uZ(Z,(X)=>X==="safe"?"safe":X==="tainted"||lZ(X)?"tainted":"unknown");function U2(Z){return Z.k==="lit"||Z.k==="str"&&Z.parts.length===0||Z.k==="call"&&["true","false","null"].includes(Z.name)&&Z.args.length===0}function j2(Z,X,$){return uZ(Z,(J)=>{if(J==="safe"||J==="tainted")return J;if(lZ(J))return"tainted";if(J==="root"&&$.rootScalars.has(X))return"safe";return{leaf:X}})}function L(Z,X,$){switch(Z.k){case"dot":return X;case"field":return j2(Z.of?L(Z.of,X,$):X,Z.name,$);case"iter":return e(L(Z.of,X,$));case"index":{let J=L(Z.of,X,$);if(Z.key.k==="str"&&Z.key.text!==void 0)return j2(J,Z.key.text,$);if(Z.key.k==="lit")return e(J);return L(Z.key,X,$),"tainted"}case"slice":return uZ(L(Z.of,X,$),(J)=>J==="root"?"unknown":lZ(J)?"tainted":J);case"opt":return L(Z.of,X,$);case"lit":return"safe";case"str":return RZ(...Z.parts.map((J)=>L(J,X,$)));case"fmt":return Z.str?L(Z.str,X,$):X;case"array":return Z.of?RZ(L(Z.of,X,$)):"safe";case"object":return RZ(...Z.entries.map((J)=>L(J.value,X,$)));case"pipe":return L(Z.b,L(Z.a,X,$),$);case"comma":return j0(L(Z.a,X,$),L(Z.b,X,$));case"alt":return j0(L(Z.a,X,$),L(Z.b,X,$));case"bool":return L(Z.a,X,$),L(Z.b,X,$),"safe";case"arith":return RZ(L(Z.a,X,$),L(Z.b,X,$));case"neg":return L(Z.of,X,$);case"call":return A4(Z,X,$)}}var W2=(Z)=>uZ(Z,(X)=>X==="root"?"unknown":lZ(X)?"tainted":X);function A4(Z,X,$){let{name:J,args:z}=Z;if(O4.has(J)&&J!=="limit"&&!z.every(U2))O();switch(J){case"map":if(z.length!==1)O();return RZ(L(z[0],e(X),$));case"select":if(z.length!==1)O();return L(z[0],X,$),X;case"limit":if(z.length!==2||!U2(z[0]))O();return L(z[1],X,$);case"first":case"last":if(z.length>1)O();return z.length===1?L(z[0],X,$):e(X);case"min":case"max":return e(X);case"sort_by":case"group_by":case"unique_by":if(z.length!==1)O();return L(z[0],e(X),$),W2(X);case"min_by":case"max_by":if(z.length!==1)O();return L(z[0],e(X),$),e(X);case"any":case"all":case"isempty":for(let Y of z)L(Y,"unknown",$);return"safe"}if(q2.has(J))return"safe";if(N2.has(J))return W2(X);return O()}function I2(Z,X={}){if(typeof Z!=="string"||!Z.trim()||Z.length>4096)return!1;try{let $=new q0(_2(Z)).parse();return N0(L($,"root",{rootScalars:X.rootScalars??new Set}))}catch($){if($ instanceof W0)return!1;return!1}}var L0="composite output withheld: signed-link shape; use bounded scalar projections per class disposition 799310",_={refused:!1},N=(Z)=>({refused:!0,rule:Z}),_0=new Set(["additions","assignees","author","baseRefName","baseRefOid","changedFiles","closed","closedAt","createdAt","deletions","files","fullDatabaseId","headRefName","headRefOid","headRepository","headRepositoryOwner","id","isCrossRepository","isDraft","labels","maintainerCanModify","mergeCommit","mergeStateStatus","mergeable","mergedAt","mergedBy","number","potentialMergeCommit","reactionGroups","reviewDecision","reviewRequests","state","title","updatedAt","url"]),I0=new Set(["assignees","author","closed","closedAt","createdAt","id","isPinned","labels","number","reactionGroups","state","stateReason","subIssuesSummary","title","updatedAt","url"]),T2=new Set(["apiUrl","author","createdAt","databaseId","id","isDraft","isImmutable","isLatest","isPrerelease","name","publishedAt","tagName","tarballUrl","targetCommitish","uploadUrl","url","zipballUrl"]),C2=new Set(["answerChosenAt","answerChosenBy","answered","author","closed","closedAt","createdAt","id","labels","locked","number","reactionGroups","state","stateReason","title","updatedAt","url"]),y4=new Set(["assignees","author","authorAssociation","closedAt","commentsCount","createdAt","id","isDraft","isLocked","isPullRequest","labels","number","repository","state","title","updatedAt","url"]),R4=new Set(["author","committer","id","parents","repository","sha","url"]),E4=new Set(["bucket","completedAt","event","name","startedAt","state","workflow"]);function P2(Z){let X=[];for(let $=0;$<Z.length;$++){let J=Z[$];if(J==="\\"){$++;continue}if(J==="'"){let z=Z.indexOf("'",$+1);if(z<0)return!1;$=z;continue}if(J==='"'){$++;while($<Z.length&&Z[$]!=='"')$+=Z[$]==="\\"?2:1;continue}if(J==="{"){X.push({list:!1});continue}if(X.length===0)continue;if(J===","||J==="."&&Z[$+1]===".")X[X.length-1].list=!0;else if(J==="}"&&X.pop().list)return!0}return!1}function VZ(Z){let X="",$=!1,J=0,z=(Y)=>Z[Y]==="`"||Z[Y]==="$"&&/[A-Za-z_{(@*#?$!0-9-]/.test(Z[Y+1]??"");while(J<Z.length){let Y=Z[J];if(Y==="\\"){X+=Z[J+1]??"",J+=2;continue}if(Y==="$"&&Z[J+1]==="'"){$=!0,X+=Y,J++;continue}if(Y==="'"){let Q=Z.indexOf("'",J+1);if(Q<0){$=!0,X+=Z.slice(J+1);break}X+=Z.slice(J+1,Q),J=Q+1;continue}if(Y==='"'){J++;while(J<Z.length&&Z[J]!=='"'){if(Z[J]==="\\"&&/[$`"\\\n]/.test(Z[J+1]??"")){X+=Z[J+1],J+=2;continue}if(z(J))$=!0;X+=Z[J],J++}if(J>=Z.length)$=!0;J++;continue}if(z(J)||Y==="*"||Y==="?"||Y==="[")$=!0;X+=Y,J++}if(!$&&Z.includes("{")&&P2(Z))$=!0;return{value:X,opaque:$,raw:Z}}var QZ=(Z)=>Z.slice(Z.lastIndexOf("/")+1);function D0(Z,X="word"){let $=[],J=!1;for(let z=0;z<Z.length;z++){let Y=Z[z];if(Y==="\\"){z++;continue}if(X==="word"&&Y==="'"&&!J){let Q=Z.indexOf("'",z+1);if(Q<0)return{bodies:$,complete:!1};z=Q;continue}if(X==="word"&&Y==='"'){J=!J;continue}if(Y==="`"){let Q=z+1;while(Q<Z.length&&Z[Q]!=="`")Q+=Z[Q]==="\\"?2:1;if(Q>=Z.length)return{bodies:$,complete:!1};$.push(Z.slice(z+1,Q)),z=Q;continue}if(Y==="$"&&Z[z+1]==="("){let Q=YZ(Z,z+1);if(Q<0)return{bodies:$,complete:!1};$.push(Z.slice(z+2,Q-1)),z=Q-1}}return{bodies:$,complete:!0}}function UZ(Z,X){let $=new Set(X.values),J={flags:[],positionals:[]},z=(Y,Q)=>({value:Y,opaque:Q.opaque,raw:Q.raw});for(let Y=0;Y<Z.length;Y++){let Q=Z[Y],H=Q.value;if(H==="--"){J.positionals.push(...Z.slice(Y+1));break}if(H.startsWith("--")&&H.length>2){let K=H.indexOf("="),B=K>=0?H.slice(0,K):H;if(K>=0)J.flags.push({name:B,value:z(H.slice(K+1),Q),inline:!0});else if($.has(B)){let M=Z[Y+1];J.flags.push(M?{name:B,value:M}:{name:B,missing:!0}),Y++}else J.flags.push({name:B});continue}if(H.startsWith("-")&&H.length>1){for(let K=1;K<H.length;K++){let B="-"+H[K],M=H.slice(K+1);if(M.startsWith("=")){J.flags.push({name:B,value:z(M.slice(1),Q),inline:!0});break}if(!$.has(B)){J.flags.push({name:B});continue}if(M)J.flags.push({name:B,value:z(M,Q),inline:!0});else{let V=Z[Y+1];J.flags.push(V?{name:B,value:V}:{name:B,missing:!0}),Y++}break}continue}J.positionals.push(Q)}return J}function x(Z,...X){let $=!1;for(let J of Z.flags){if(!X.includes(J.name))continue;if(!J.inline){$=!0;continue}let z=J.value;$=!z.opaque&&["1","t","T","TRUE","true","True"].includes(z.value)}return $}var $Z=(Z,...X)=>Z.flags.filter(($)=>X.includes($.name)),l=["-R","--repo","-q","--jq","-t","--template","--json"],KZ={"pr view":{values:l},"issue view":{values:l},"release view":{values:l},"discussion view":{values:[...l,"--after","-L","--limit","--order"]},"pr list":{values:[...l,"--app","-a","--assignee","-A","--author","-B","--base","-H","--head","-l","--label","-L","--limit","-S","--search","-s","--state"]},"issue list":{values:[...l,"--app","-a","--assignee","-A","--author","-l","--label","-L","--limit","--mention","-m","--milestone","-S","--search","-s","--state"]},"discussion list":{values:[...l,"--after","-A","--author","-c","--category","-l","--label","-L","--limit","--order","-S","--search","--sort","-s","--state"]},"release list":{values:[...l,"-L","--limit","-O","--order"]},"pr status":{values:l},"issue status":{values:l},"pr checks":{values:[...l,"-i","--interval"]},"pr diff":{values:["-R","--repo"]},search:{values:[...l,"--app","--assignee","--author","--author-date","--author-email","--author-name","--base","--checks","--closed","--commenter","--committer","--committer-date","--committer-email","--committer-name","--created","--hash","--head","--interactions","--involves","--label","--language","--limit","-L","--match","--mentions","--merged-at","--milestone","--no-assignee","--no-label","--no-milestone","--no-project","--order","--owner","--parent","--project","--reactions","--review","--review-requested","--reviewed-by","--sort","--state","--team-mentions","--tree","--updated","--visibility","--extension","--filename","--size","--forks","--good-first-issue","--help-wanted-issues","--number-topics","--stars","--topic","--followers","--include-forks","--license"]},"project item-list":{values:["--format","-L","--limit","--owner","-q","--jq","-t","--template","--query","--field","--field-id"]},api:{values:["-X","--method","-H","--header","-f","--raw-field","-F","--field","-q","--jq","-t","--template","-p","--preview","--input","--hostname","--cache"]},group:{values:["-R","--repo"]}},S4=new Set(["auth","browse","codespace","cs","gist","org","repo","skill","cache","run","workflow","co","agent-task","alias","attestation","completion","config","copilot","extension","ext","extensions","gpg-key","label","licenses","preview","ruleset","secret","ssh-key","variable","help","version","accessibility","actions","environment","exit-codes","formatting","mintty","reference","telemetry"]),b4=new Set(["pr","issue","release","discussion","search","project","api","status"]),f4=new Set(["create","new","checkout","co","close","comment","edit","lock","merge","ready","reopen","revert","review","unlock","update-branch"]),k4=new Set(["create","new","close","comment","delete","develop","edit","lock","pin","reopen","transfer","unlock","unpin"]),x4=new Set(["create","new","delete","delete-asset","download","edit","upload","verify","verify-asset"]),w4=new Set(["create","new","close","comment","delete","edit","lock","reopen","unlock","answer","unanswer"]);function dZ(Z,X){let $=$Z(Z,"--json"),J=[],z=!1;for(let Y of $){if(Y.missing){if(X.appendsArgs)z=!0;continue}if(!Y.value)continue;if(Y.value.opaque)z=!0;J.push(...Y.value.value.split(",").map((Q)=>Q.trim()).filter(Boolean))}return{present:$.length>0,opaque:z,fields:J}}function v0(Z,X){if(x(Z,"--verbose")||$Z(Z,"-t","--template").length>0)return!1;let $=$Z(Z,"-q","--jq");return $.length>0&&$.every((J)=>J.value!==void 0&&!J.value.opaque&&I2(J.value.value,{rootScalars:X}))}function A0(Z,X,$,J){let z=dZ(Z,$);if(z.opaque)return N("unclassifiable");if(z.fields.every((Y)=>X.has(Y)))return _;if($.debug)return N("debug-traffic");return v0(Z)?_:N(J)}function mZ(Z,X,$,J,z){let Y=UZ(Z,KZ[X]);if(x(Y,"-h","--help"))return _;if(x(Y,"-w","--web"))return J.debug?N("debug-traffic"):_;if(z&&x(Y,"-c","--comments"))return N("view-comments");if(!dZ(Y,J).present)return N(J.debug?"debug-traffic":"view-human");return A0(Y,$,J,"json-composite")}function ZZ(Z,X,$,J){let z=UZ(Z,KZ[X]);if(x(z,"-h","--help"))return _;if(J.debug&&(x(z,"-w","--web")||!dZ(z,J).present))return N("debug-traffic");if(x(z,"-w","--web"))return _;return A0(z,$,J,"json-composite")}function h4(Z,X){let $=UZ(Z,KZ["pr checks"]);if(x($,"-h","--help"))return _;if(X.debug)return N("debug-traffic");if(x($,"-w","--web"))return _;if(!dZ($,X).present)return N("checks-human");return A0($,E4,X,"checks-json")}function g4(Z){let X=new Set(KZ.group.values);for(let $=0;$<Z.length;$++){let J=Z[$].value;if(J==="--")return{sub:Z[$+1],rest:Z.slice($+2)};if(!J.startsWith("-")||J==="-")return{sub:Z[$],rest:[...Z.slice(0,$),...Z.slice($+1)]};if(X.has(J))$++}return{rest:Z}}function u4(Z,X,$){let{sub:J,rest:z}=g4(X);if(!J)return $.appendsArgs?N("unclassifiable"):_;if(J.opaque)return N("unclassifiable");let Y=J.value;if((Z==="pr"?f4:Z==="issue"?k4:Z==="release"?x4:Z==="discussion"?w4:new Set).has(Y))return $.debug?N("debug-traffic"):_;if($.appendsArgs&&!(Z==="project"&&Y!=="item-list"))return N("unclassifiable");switch(Z){case"pr":if(Y==="view")return mZ(z,"pr view",_0,$,!0);if(Y==="list"||Y==="ls")return ZZ(z,"pr list",_0,$);if(Y==="status")return ZZ(z,"pr status",_0,$);if(Y==="checks")return h4(z,$);if(Y==="diff"){let H=UZ(z,KZ["pr diff"]);if(x(H,"-h","--help"))return _;if($.debug)return N("debug-traffic");return x(H,"--patch")?N("composite-other"):_}return N("unclassifiable");case"issue":if(Y==="view")return mZ(z,"issue view",I0,$,!0);if(Y==="list"||Y==="ls")return ZZ(z,"issue list",I0,$);if(Y==="status")return ZZ(z,"issue status",I0,$);return N("unclassifiable");case"release":if(Y==="view")return mZ(z,"release view",T2,$,!1);if(Y==="list"||Y==="ls")return ZZ(z,"release list",T2,$);return N("unclassifiable");case"discussion":if(Y==="view")return mZ(z,"discussion view",C2,$,!0);if(Y==="list"||Y==="ls")return ZZ(z,"discussion list",C2,$);return N("unclassifiable");case"search":if(Y==="prs"||Y==="issues")return ZZ(z,"search",y4,$);if(Y==="commits")return ZZ(z,"search",R4,$);if(Y==="code"||Y==="repos")return $.debug?N("debug-traffic"):_;return N("unclassifiable");case"project":{if($.debug)return N("debug-traffic");if(Y!=="item-list")return _;let H=UZ(z,KZ["project item-list"]);if(x(H,"-h","--help"))return _;let K=$Z(H,"--format");if(K.some((B)=>!B.value||B.value.opaque))return N("unclassifiable");if(K.every((B)=>B.value.value!=="json"))return _;return v0(H)?_:N("composite-other")}}return N("unclassifiable")}var O2=new Set(["pulls","issues","commits","check-runs","check-suites","statuses","comments","releases","compare","events","discussions","deployments","milestones"]);function l4(Z){let X=Z.value.trim(),$=/^https?:\/\/([^/]+)(\/.*)?$/i.exec(X);if($){let Y=$[1].toLowerCase(),Q=$[2]??"/";if(Y==="api.github.com"||/^api\./.test(Y))X=Q;else if(/^\/api\/v3(?:\/|$)/i.test(Q))X=Q.replace(/^\/api\/v3/i,"");else if(/^\/api\/graphql(?:[/?#]|$)/i.test(Q))X="graphql";else return null}X=X.replace(/[?#].*$/,"");let J=[],z=[];for(let Y of X.split("/")){let Q;try{Q=decodeURIComponent(Y)}catch{return null}for(let H of Q.split("/")){if(H===""||H===".")continue;if(H===".."){J.pop(),z.pop();continue}J.push(H.toLowerCase()),z.push(Z.opaque&&/[$`]/.test(H)||/[*?[]/.test(H)||P2(H))}}return{segments:J,opaque:z}}function m4(Z){let X=l4(Z);if(!X)return{kind:"unclassifiable",segments:[]};let{segments:$,opaque:J}=X,z=(K)=>({kind:K,segments:$});if($.length===1&&$[0]==="graphql")return z("graphql");if($.length===0)return z(Z.opaque?"unclassifiable":"other");if(J[0])return z("unclassifiable");let Y,Q=[];if($[0]==="repos")Y=$.slice(3),Q=J.slice(3);else if($[0]==="repositories")Y=$.slice(2),Q=J.slice(2);if(Y){if(($[0]==="repos"?J.slice(1,3):J.slice(1,2)).some(Boolean)){let B=J.findIndex(Boolean),M=$.findIndex((V,G)=>G>B&&!J[G]&&p4.has(V));return z(M<0?"unclassifiable":D2($.slice(M),J.slice(M)))}return z(D2(Y,Q))}let H=$[0];if(H==="issues")return z("sensitive");if(H==="user"&&$[1]==="issues")return z("sensitive");if(H==="orgs"&&$[2]==="issues")return z("sensitive");if(H==="search")return z($[1]==="issues"||$[1]==="commits"?"sensitive":$[1]!==void 0&&J[1]?"unclassifiable":"other");if(H==="events"||H==="networks")return z("sensitive");if((H==="users"||H==="orgs")&&$.slice(2).some((K)=>K==="events"||K==="received_events"||K==="discussions"))return z("sensitive");if((H==="users"||H==="orgs")&&$[2]==="projectsv2"&&$[4]==="items")return z("sensitive");if(H==="orgs"&&$[2]==="hooks"&&$[4]==="deliveries"&&$[5]!==void 0||H==="app"&&$[1]==="hook"&&$[2]==="deliveries"&&$[3]!==void 0)return z("sensitive");if(H==="teams"&&$.includes("discussions"))return z("sensitive");if(H==="projects"&&$.includes("cards"))return z("sensitive");if(J.some(Boolean))return z($.some((K)=>K==="events"||K==="discussions"||K==="issues")?"sensitive":"unclassifiable");return z("other")}var p4=new Set([...O2,"branches","git","actions","hooks","zipball","tarball"]);function D2(Z,X){let[$,J]=Z;if($===void 0)return"other";if(X[0])return"unclassifiable";if($==="issues"&&/^\d+$/.test(J??"")&&Z[2]==="labels")return"other";if(O2.has($))return"sensitive";if($==="branches"){if(Z.length===1||Z.slice(1).some((z)=>z==="protection")||Z[Z.length-1]==="rename")return"other";return X.slice(1).some(Boolean)?"unclassifiable":"sensitive"}if($==="git")return J===void 0||J==="commits"||J==="tags"?"sensitive":X[1]?"unclassifiable":"other";if($==="actions"){if(J===void 0)return"sensitive";if(X[1])return"unclassifiable";if(J==="runs"||J==="jobs"){if(Z[Z.length-1]==="logs"&&Z.length>=4&&!X.some(Boolean))return"download";return"sensitive"}if(J==="workflows"&&Z[3]==="runs")return"sensitive";if(J==="artifacts"&&Z.length===4)return"download";return"other"}if($==="hooks"&&Z[2]==="deliveries"&&Z[3]!==void 0)return"sensitive";if($==="zipball"||$==="tarball")return"download";return"other"}function c4(Z,X){if(X[0]!=="repos"||X.length<5)return!1;let $=X.slice(3),J=(Y)=>/^\d+$/.test($[Y]??""),z=(...Y)=>$.length===Y.length&&Y.every((Q,H)=>typeof Q==="number"?J(H):$[H]===Q);if(Z==="DELETE")return z("issues","comments",0)||z("pulls","comments",0)||z("comments",0)||z("issues","comments",0,"reactions",0)||z("pulls","comments",0,"reactions",0)||z("issues",0,"reactions",0)||z("issues",0,"labels")||$.length===4&&$[0]==="issues"&&J(1)&&$[2]==="labels"||z("releases",0)||z("releases","assets",0)||z("actions","runs",0)||z("actions","runs",0,"logs")||z("deployments",0)||z("milestones",0)||z("issues",0,"lock");if(Z==="POST")return $.length===4&&$[0]==="actions"&&$[1]==="runs"&&J(2)&&["rerun","rerun-failed-jobs","cancel","force-cancel","approve"].includes($[3])||z("actions","jobs",0,"rerun")||z("issues",0,"labels");if(Z==="PUT")return z("pulls",0,"merge")||z("pulls",0,"update-branch")||z("issues",0,"labels")||z("issues",0,"lock");if(Z==="GET")return z("pulls",0,"merge");return!1}function d4(Z){if(Z[0]!=="repos"||Z.length!==5||!/^\d+$/.test(Z[4]))return;if(Z[3]==="pulls")return new Set(["commits","comments","review_comments"]);if(Z[3]==="issues")return new Set(["comments"]);return}var i4=new Set(["body","bodyText","bodyHTML","bodyUrl","bodyResourcePath","comments","reviews","latestReviews","latestOpinionatedReviews","reviewThreads","url","permalink","summary","text","description","message","messageBody","messageHeadline","commitBody","commitHeadline","annotations","rawDetails","note","diff","readme","payload"]),s4=new Set(["checkRuns","checkRun","checkSuites","checkSuite","contexts","statusCheckRollup","annotations","CheckRun","CheckSuite","StatusContext","CheckAnnotation","latestStatus","status","statuses"]);function n4(Z){let X=[],$=0;while($<Z.length){let J=Z[$];if(/[\s,]/.test(J)){$++;continue}if(J==="#"){let Q=Z.indexOf(`
|
|
20
|
+
`,$);$=Q<0?Z.length:Q+1;continue}if(Z.startsWith('"""',$)){let Q=$+3;for(;;){let H=Z.indexOf('"""',Q);if(H<0)return null;if(Z[H-1]==="\\"){Q=H+3;continue}$=H+3;break}continue}if(J==='"'){let Q=$+1;while(Q<Z.length&&Z[Q]!=='"'&&Z[Q]!==`
|
|
21
|
+
`)Q+=Z[Q]==="\\"?2:1;if(Z[Q]!=='"')return null;$=Q+1;continue}let z=/^[_A-Za-z][_0-9A-Za-z]*/.exec(Z.slice($,$+256));if(z){X.push({kind:"name",text:z[0]}),$+=z[0].length;continue}let Y=/^-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?/.exec(Z.slice($,$+64));if(Y){$+=Y[0].length;continue}if(Z.startsWith("...",$)){X.push({kind:"punct",text:"..."}),$+=3;continue}if("{}()[]:!$@=|&".includes(J)){X.push({kind:"punct",text:J}),$++;continue}return null}return X}function a4(Z){let X=n4(Z);if(!X)return!0;let $=[],J="",z=0;for(let Y=0;Y<X.length;Y++){let Q=X[Y];if(Q.kind==="punct"){if(Q.text==="(")z++;else if(Q.text===")"){if(z--,z<0)return!0}else if(z===0&&Q.text==="{")$.push(J),J="";else if(z===0&&Q.text==="}"){if($.pop()===void 0)return!0;J=""}continue}if(z>0)continue;let H=X[Y-1];if(H?.kind==="punct"&&(H.text==="@"||H.text==="$"))continue;if(X[Y+1]?.kind==="punct"&&X[Y+1].text===":")continue;if(Q.text==="on"&&H?.kind==="punct"&&H.text==="...")continue;if(H?.kind==="name"&&H.text==="on"){J=Q.text;continue}if($.length===0){J=Q.text;continue}if(i4.has(Q.text)||/(?:Url|URL|HTML|Html)$/.test(Q.text))return!0;if(Q.text==="title"&&$.some((K)=>s4.has(K)))return!0;J=Q.text}return z!==0||$.length!==0}function o4(Z,X){let $=UZ(Z,KZ.api);if(x($,"-h","--help"))return _;let J=$.positionals[0];if(!J)return X.appendsArgs?N("unclassifiable"):_;let z=m4(J),Y=$Z($,"-X","--method"),Q=Y[Y.length-1],H=$Z($,"-f","--raw-field","-F","--field","--input"),K=Q?Q.value&&!Q.value.opaque?Q.value.value.toUpperCase():"?":H.length>0?"POST":"GET",B=c4(K,z.segments),M=_;if(z.kind==="unclassifiable")M=N("unclassifiable");else if(z.kind==="sensitive"&&!B)M=N("api-rest");else if(z.kind==="graphql")M=r4($);if(X.debug||x($,"--verbose")){if(z.kind==="download"&&!M.refused)M=N("api-rest");if(M.refused)return X.debug?N("debug-traffic"):M;return _}if(X.appendsArgs&&z.kind!=="other"&&z.kind!=="download")return N("unclassifiable");if(!M.refused||x($,"--silent"))return _;if(v0($,d4(z.segments)))return _;return M}function r4(Z){if($Z(Z,"--input").length>0)return N("unclassifiable");let X=$Z(Z,"-f","--raw-field","-F","--field"),$=X.filter((J)=>J.value&&/^query=/.test(J.value.value));if($.length===0||X.some((J)=>!J.value))return N("unclassifiable");for(let J of $){let z=J.value.value.slice(6);if((J.name==="-F"||J.name==="--field")&&z.startsWith("@")||J.value.opaque)return N("unclassifiable");if(a4(z))return N("api-graphql")}return _}function cZ(Z,X){let $=0;while($<Z.length&&Z[$].value.startsWith("-")&&!Z[$].opaque){if(["--help","-h","--version"].includes(Z[$].value))return _;$++}if($>=Z.length)return X.appendsArgs?N("unclassifiable"):_;let J=Z[$],z=Z.slice($+1);if(J.opaque)return N("unclassifiable");switch(J.value){case"pr":case"issue":case"release":case"discussion":case"search":case"project":return u4(J.value,z,X);case"api":return o4(z,X);case"status":return z.length>0&&z.every((Y)=>Y.value==="-h"||Y.value==="--help")?_:N("composite-other");case"help":case"version":return _;case"cs":case"codespace":{let Y=z.findIndex((Q)=>Q.value==="--");if(z.some((Q)=>Q.value==="ssh")&&Y>=0&&Y+1<z.length){let Q=d(z.slice(Y+1).map((H)=>H.value).join(" "),X.depth+1,X.debug);if(Q.refused)return Q}break}}if(!S4.has(J.value))return N("unclassifiable");if(X.debug)return N("debug-traffic");return _}var iZ=new Set(["sh","bash","zsh","dash","ksh","ash","mksh","fish"]),t4=new Set(["su","runuser","script","flock"]),e4=new Set(["secrets","op","unbuffer","caffeinate","chronic","strace","ltrace","firejail","bwrap","nsenter","unshare","chroot","sg","retry","parallel","doppler","aws-vault","dotenv","direnv","faketime","taskset","numactl","cgexec","systemd-run","docker","podman","kubectl","mise","asdf","rtx","devbox","gosu","su-exec","setpriv","pkexec","with-contenv","uv","poetry","pipenv","npx","bunx","pnpm","yarn","nix","nix-shell","infisical","chamber","envchain","dotenvx","teller","vault","chrt","coproc","prlimit","ionice","cpulimit","trickle","proxychains","proxychains4","torsocks","tsocks","catchsegv","valgrind"]),Z5=new Map([["bun",["x","exec"]],["npm",["exec","x"]],["deno",["run"]]]),$5=new Set(["-I","-L","-l","-n","-P","-s","-d","-E","-e","-a","--arg-file","--delimiter","--max-args","--max-lines","--max-procs","--max-chars","--replace","--eof","--process-slot-var"]),J5=new Set(["-b","-c","-D","-E","-e","-F","-I","-i","-J","-L","-l","-m","-O","-o","-p","-Q","-R","-S","-W","-w"]),pZ=/(?:^|[^A-Za-z0-9_.-])gh(?:$|[^A-Za-z0-9_.-])/,X5=/^([A-Za-z_][A-Za-z0-9_]*)=([\s\S]*)$/,z5=6;function F2(Z,X){let $,J;for(let z of Z){let Y=X5.exec(z.value);if(!Y)continue;let Q={...z,value:Y[2]};if(Y[1]==="GH_DEBUG")$=Q;else if(Y[1]==="DEBUG")J=Q}if($)return $.opaque||!["","0","false","no"].includes($.value);if(J&&(J.opaque||["1","true","yes","api"].includes(J.value)))return!0;return X}function y0(Z){let X=o(Z),$=0;return{segments:X.segments.map((z)=>{let Y=z.words[0],Q=Z.slice($,Y.start);return $=z.words[z.words.length-1].end,{words:z.words,redirects:z.redirects,sepBefore:Q}}),trustworthy:X.trustworthy}}var L2=(Z)=>/(?:^|[^|])\|&?$/.test(Z.trim());function F0(Z,X){if(!iZ.has(Z))return!1;if(R0(X))return!1;for(let $=0;$<X.length;$++){let J=X[$].value;if(J==="--")return $+1>=X.length;if(J==="-"||J==="-s")return!0;if(/^[-+][A-Za-z]*[oO]$/.test(J)){$++;continue}if(!J.startsWith("-")&&!J.startsWith("+"))return!1}return!0}function P0(Z){let{segments:X}=y0(Z.trim());if(X.length!==1)return null;let $=X[0],J=p($);if(J<0)return null;let z=QZ(VZ($.words[J].text).value),Y=$.words.slice(J+1).filter((Q,H)=>!$.redirects.has(H+J+1)).map((Q)=>VZ(Q.text));if(z==="echo")return Y.filter((Q,H)=>!(H===0&&/^-[neE]+$/.test(Q.value))).map((Q)=>Q.value).join(" ");if(z==="printf"){let[Q,...H]=Y.filter((B)=>B.value!=="--");if(!Q)return null;let K=0;return Q.value.replace(/\\n/g,`
|
|
22
|
+
`).replace(/%s/g,()=>H[K++]?.value??"")+(K<H.length?" "+H.slice(K).map((B)=>B.value).join(" "):"")}if(z==="cat"){let Q=Z.indexOf("<<");if(Q<0)return null;let H=GZ(Z,Q),K=Z.indexOf(`
|
|
23
|
+
`,Q);if(!H||K<0)return null;let B=hZ(Z,K,[H]);if(B<0)return null;let M=Z.slice(K+1,B);return M.slice(0,M.lastIndexOf(H.delimiter)).replace(/\n$/,"")}return null}function T0(Z,X,$){for(let J of D0(Z).bodies){let z=P0(J);if(z===null)continue;let Y=d(z,X+1,$.debug);if(Y.refused)return Y}return _}function d(Z,X=0,$=!1){if(typeof Z!=="string"||!Z.trim())return _;if(X>z5)return pZ.test(Z)?N("unclassifiable"):_;let{segments:J,trustworthy:z}=y0(Z);if(!z)return pZ.test(Z)?N("unclassifiable"):_;let Y=$,Q=(H)=>d(H,X+1,Y);for(let H of K5(Z)){if(H.runsBody){let K=Q(H.body);if(K.refused)return K}if(!H.quoted){let K=D0(H.body,"heredoc");if(!K.complete&&pZ.test(H.body))return N("unclassifiable");for(let B of K.bodies){let M=Q(B);if(M.refused)return M}}}for(let H=0;H<J.length;H++){let K=J[H];for(let W of K.words){let A=D0(W.text);if(!A.complete&&pZ.test(W.text))return N("unclassifiable");for(let w of A.bodies){let f=Q(w);if(f.refused)return f}}let B=p(K),M=K.words.map((W,A)=>({word:VZ(W.text),redirect:K.redirects.has(A)})),V=M.slice(0,B<0?M.length:B).map((W)=>W.word),G=B>=0?QZ(M[B].word.value):"";if(B<0||["export","declare","typeset","readonly","local"].includes(G)){if(Y=F2([...V,...M.slice(B+1).map((W)=>W.word)],Y),B<0)continue}let j=F2(V,Y),D=M.slice(B+1).filter((W)=>!W.redirect).map((W)=>W.word),v=M.slice(B+1).filter((W)=>W.redirect).map((W)=>W.word),b=M[B].word,E=QZ(b.value),JZ={depth:X,appendsArgs:!1,debug:j};if(B>0&&M[B-1].word.value==="function"){let W=D.filter((w)=>!["{","()","(",")"].includes(w.value)),A=O0(W,JZ);if(A.refused)return A;continue}if(H>0&&L2(K.sepBefore)&&F0(E,D)){let W=J[H-1],A=Y5(Z,W),w=A===null?null:P0(A);if(w!==null){let f=d(w,X+1,j);if(f.refused)return f}}let i=J[H+1];if(i&&/<\(\s*$/.test(i.sepBefore)&&(iZ.has(E)||E==="source"||E===".")){let W=i.words[0].start-i.sepBefore.length+i.sepBefore.lastIndexOf("("),A=YZ(Z,W),w=A<0?null:P0(Z.slice(W+1,A-1));if(w!==null){let f=d(w,X+1,j);if(f.refused)return f}}let I=v2(E,b,D,v,K.words.slice(0,B+1),JZ);if(I.refused)return I}return _}function Y5(Z,X){let $=X.words[0],J=X.words[X.words.length-1];return $&&J?Z.slice($.start,J.end):null}function Q5(Z){let X=QZ(Z.value);return/[$`]/.test(X)||X===""?void 0:X}function v2(Z,X,$,J,z,Y){let Q=Y.depth,H=(K)=>d(K,Q+1,Y.debug);if(X.opaque){let K=Q5(X);if(K===void 0){let B=$.find((V)=>!V.value.startsWith("-")),M=cZ($,Y);if(!M.refused)return _;return M.rule!=="unclassifiable"||B!==void 0&&!B.opaque&&b4.has(B.value)?M:_}Z=K}if(Z==="gh")return cZ($,Y);if(iZ.has(Z)){let K=R0($);if(K){let B=H(K.value);if(B.refused||!K.opaque)return B;return T0(K.raw,Q,Y)}for(let B of J){let M=H(B.value);if(M.refused)return M;if(B.opaque){let V=T0(B.raw,Q,Y);if(V.refused)return V}}return _}if(t4.has(Z)){let K=$.findIndex((M)=>M.value==="-c"||M.value==="--command"||/^-[A-Za-z]*c$/.test(M.value)),B=K>=0?$[K+1]:void 0;return B?H(B.value):C0($,Y)}if(Z==="eval"||Z==="watch"){let K=$;if(Z==="watch"){let M=0;while(M<$.length&&$[M].value.startsWith("-")){if($[M].value==="--"){M++;break}if(["-n","--interval","-q","--equexit"].includes($[M].value))M++;M++}K=$.slice(M)}let B=H(K.map((M)=>M.value).join(" "));if(B.refused)return B;for(let M of K){let V=T0(M.raw,Q,Y);if(V.refused)return V}return _}if(Z==="env")return H(PZ([...z.map((K)=>VZ(K.text).value),...$.map((K)=>K.value)]));if(Z==="ssh"){let K=0;for(;K<$.length;K++){let V=$[K].value;if(!V.startsWith("-"))break;if(J5.has(V))K++}let B=$.slice(K+1);if(B[0]?.value==="--")B.shift();let M=B.map((V)=>V.value).join(" ");return M?H(M):_}if(Z==="xargs"){let K=0,B=!1;for(;K<$.length;K++){let M=$[K].value;if(M==="--"){K++;break}if(!M.startsWith("-"))break;if(/^-I|^-i|^--replace/.test(M))B=!0;if($5.has(M))K++}return O0($.slice(K),{depth:Q,appendsArgs:!B,debug:Y.debug})}if(Z==="find"){for(let K=0;K<$.length;K++){if(!["-exec","-execdir","-ok","-okdir"].includes($[K].value))continue;let B=K+1;while(B<$.length&&$[B].value!==";"&&$[B].value!=="+")B++;let M=O0($.slice(K+1,B),Y);if(M.refused)return M;K=B}return _}if(e4.has(Z))return C0($,Y);if(Z5.get(Z)?.includes($[0]?.value??""))return C0($.slice(1),Y);return _}function O0(Z,X){if(Z.length===0)return _;let $=QZ(Z[0].value);if($==="gh")return cZ(Z.slice(1),X);if(iZ.has($)){let J=R0(Z.slice(1));return J?d(J.value,X.depth+1,X.debug):_}return v2($,Z[0],Z.slice(1),[],[],X)}function C0(Z,X){let $=Z.findIndex((J)=>!J.opaque&&QZ(J.value)==="gh"&&(J.value==="gh"||J.value.includes("/")));return $>=0?cZ(Z.slice($+1),X):_}function R0(Z){for(let X=0;X<Z.length;X++){let $=Z[X].value;if($==="--")return;if(!$.startsWith("-")&&!$.startsWith("+"))return;if($==="-c"||/^-[A-Za-z]+$/.test($)&&$.includes("c"))return Z.slice(X+1).find((J)=>!J.value.startsWith("-")||J.value==="-");if(/^[-+][A-Za-z]*[oO]$/.test($))X++}return}function K5(Z){let X=[],$=0;for(;;){let J=Z.indexOf("<<",$);if(J<0)break;if($=J+2,Z[J+2]==="<"||J>0&&Z[J-1]==="<"){$=J+3;continue}let z=GZ(Z,J);if(!z)continue;let Y=Z.lastIndexOf(`
|
|
24
|
+
`,J)+1,Q=Z.indexOf(`
|
|
25
|
+
`,J);if(Q<0)continue;let H=hZ(Z,Q,[z]),K=H<0?Z.slice(Q+1):Z.slice(Q+1,H),B=H<0?K:K.slice(0,Math.max(0,K.lastIndexOf(z.delimiter))).replace(/\n$/,""),M=Z.slice(Y,J)+" HEREDOC_OPERATOR "+Z.slice(z.end,Q);X.push({body:B,runsBody:H5(M),quoted:z.quoted})}return X}function H5(Z){let{segments:X}=y0(Z),$=X.findIndex((H)=>H.words.some((K)=>K.text==="HEREDOC_OPERATOR"));if($<0)return!1;let J=(H)=>{let K=p(H);if(K<0)return{verb:"",args:[]};let B=H.words.slice(K+1).filter((M)=>M.text!=="HEREDOC_OPERATOR").map((M)=>VZ(M.text));return{verb:QZ(VZ(H.words[K].text).value),args:B}},{verb:z,args:Y}=J(X[$]);if(z==="ssh"||F0(z,Y))return!0;if((z==="source"||z===".")&&["/dev/stdin","/dev/fd/0","/proc/self/fd/0"].includes(Y[0]?.value??""))return!0;let Q=X[$+1];if(z==="cat"&&Q&&L2(Q.sepBefore)){let H=J(Q);return H.verb==="ssh"||F0(H.verb,H.args)}return!1}var B5=/(?:^|[^A-Za-z0-9_.-])gh(?:$|[^A-Za-z0-9_.-])/;function A2(){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:L0}}}var M5=new Set(["Bash","Monitor"]);function y2(Z){if(Z?.hook_event_name!=="PreToolUse"||!M5.has(Z.tool_name??""))return{continue:!0};let X=BZ(Z);if(!X.trim())return{continue:!0};try{return d(X).refused?A2():{continue:!0}}catch{return B5.test(X)?A2():{continue:!0}}}function G5(Z){if(Z!=="trash-guard"&&Z!=="workspace-repos-guard")throw Error("Invalid safety capability")}function R2(Z,X){G5(Z);let $=Z,J=JSON.parse(X);if(!J||Array.isArray(J)||J.hook_event_name!=="PreToolUse"||typeof J.tool_name!=="string"||!J.tool_input||typeof J.tool_input!=="object"||Array.isArray(J.tool_input)||typeof J.cwd!=="string"||!E0.isAbsolute(J.cwd))throw Error("Invalid safety input");if(J.tool_name==="Bash"&&typeof J.tool_input.command!=="string")throw Error("Invalid shell input");if(J.tool_name==="Monitor"&&J.tool_input.command!==void 0&&typeof J.tool_input.command!=="string")throw Error("Invalid monitor input");let z=J.hasna_execution;if(z!==void 0&&(!z||Object.keys(z).sort().join()!=="agent,schema"||z.schema!=="hasna.hooks.execution.v1"||typeof z.agent!=="string"||!/^[A-Za-z0-9][A-Za-z0-9._:@-]{0,127}$/.test(z.agent)))throw Error("Invalid execution capability");let Y=z===void 0?void 0:{runtime:process.execPath,home:sZ.homedir(),path:process.env.PATH,agent:z.agent};if(Y&&(!E0.isAbsolute(Y.runtime)||!Y.path))throw Error("Invalid bound execution context");if(["apply_patch","ApplyPatch","functions.apply_patch"].includes(J.tool_name)){if(J.tool_input.command!==void 0&&J.tool_input.patch!==void 0&&J.tool_input.command!==J.tool_input.patch)throw Error("Conflicting patch aliases");let v=J.tool_input.command??J.tool_input.patch;if(typeof v!=="string")throw Error("Invalid patch input");J.tool_input={...J.tool_input,command:v,patch:v}}let Q=J.tool_name==="Monitor",H=J.tool_name==="Bash"||Q&&typeof J.tool_input.command==="string",K=Q&&H?{...J,tool_name:"Bash"}:J,B=(v)=>({hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:v}}),M=V2(K).output,V=y2(K),G=H&&LZ(K.tool_input.command,{home:sZ.homedir(),cwd:J.cwd}).handoffHits.length>0,j=$==="trash-guard"&&(!Q||H)?e0(K,{home:sZ.homedir(),cwd:J.cwd,findTrash:bZ,inspectTrash:TZ,execution:Y}):{continue:!0};if(Q&&j.hookSpecificOutput?.permissionDecision==="allow")j=B("[trash-guard] A deletion inside a Monitor command is refused; run it with the Bash tool, where it is redirected into trash.");let D=M.decision==="block"?B(M.reason):V.hookSpecificOutput?V:G?B("[workspace-repos-guard] Deletion under a protected repository checkout is refused."):j;return JSON.stringify({verdict:"continue"in D?null:D})}var V5=2,U5="0.12.7";function j5(Z,X){return R2(Z,X)}
|