@hasna/hooks 0.12.19 → 0.12.20

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.
@@ -34,4 +34,4 @@ var{defineProperty:W0,getOwnPropertyNames:C3,getOwnPropertyDescriptor:P3}=Object
34
34
  `).replace(/%s/g,()=>H[K++]?.value??"")+(K<H.length?" "+H.slice(K).map((B)=>B.value).join(" "):"")}if(Y==="cat"){let Q=Z.indexOf("<<");if(Q<0)return null;let H=DZ(Z,Q),K=Z.indexOf(`
35
35
  `,Q);if(!H||K<0)return null;let B=tZ(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 i0(Z,z,$){for(let J of s0(Z).bodies){let Y=o0(J);if(Y===null)continue;let X=r(Y,z+1,$.debug);if(X.refused)return X}return T}function r(Z,z=0,$=!1){if(typeof Z!=="string"||!Z.trim())return T;if(z>P6)return Q0.test(Z)?I("unclassifiable"):T;let{segments:J,trustworthy:Y}=Z2(Z);if(!Y)return Q0.test(Z)?I("unclassifiable"):T;let X=$,Q=(H)=>r(H,z+1,X);for(let H of A6(Z)){if(H.runsBody){let K=Q(H.body);if(K.refused)return K}if(!H.quoted){let K=s0(H.body,"heredoc");if(!K.complete&&Q0.test(H.body))return I("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 F of K.words){let R=s0(F.text);if(!R.complete&&Q0.test(F.text))return I("unclassifiable");for(let m of R.bodies){let p=Q(m);if(p.refused)return p}}let B=l(K),M=K.words.map((F,R)=>({word:IZ(F.text),redirect:K.redirects.has(R)})),V=M.slice(0,B<0?M.length:B).map((F)=>F.word),G=B>=0?VZ(M[B].word.value):"";if(B<0||["export","declare","typeset","readonly","local"].includes(G)){if(X=U3([...V,...M.slice(B+1).map((F)=>F.word)],X),B<0)continue}let U=U3(V,X),j=M.slice(B+1).filter((F)=>!F.redirect).map((F)=>F.word),N=M.slice(B+1).filter((F)=>F.redirect).map((F)=>F.word),y=M[B].word,b=VZ(y.value),k={depth:z,appendsArgs:!1,debug:U};if(B>0&&M[B-1].word.value==="function"){let F=j.filter((m)=>!["{","()","(",")"].includes(m.value)),R=a0(F,k);if(R.refused)return R;continue}if(H>0&&N3(K.sepBefore)&&n0(b,j)){let F=J[H-1],R=O6(Z,F),m=R===null?null:o0(R);if(m!==null){let p=r(m,z+1,U);if(p.refused)return p}}let d=J[H+1];if(d&&/<\(\s*$/.test(d.sepBefore)&&(B0.has(b)||b==="source"||b===".")){let F=d.words[0].start-d.sepBefore.length+d.sepBefore.lastIndexOf("("),R=BZ(Z,F),m=R<0?null:o0(Z.slice(F+1,R-1));if(m!==null){let p=r(m,z+1,U);if(p.refused)return p}}let q=F3(b,y,j,N,K.words.slice(0,B+1),k);if(q.refused)return q}return T}function O6(Z,z){let $=z.words[0],J=z.words[z.words.length-1];return $&&J?Z.slice($.start,J.end):null}function L6(Z){let z=VZ(Z.value);return/[$`]/.test(z)||z===""?void 0:z}function F3(Z,z,$,J,Y,X){let Q=X.depth,H=(K)=>r(K,Q+1,X.debug);if(z.opaque){let K=L6(z);if(K===void 0){let B=$.find((V)=>!V.value.startsWith("-")),M=K0($,X);if(!M.refused)return T;return M.rule!=="unclassifiable"||B!==void 0&&!B.opaque&&e5.has(B.value)?M:T}Z=K}if(Z==="gh")return K0($,X);if(B0.has(Z)){let K=$2($);if(K){let B=H(K.value);if(B.refused||!K.opaque)return B;return i0(K.raw,Q,X)}for(let B of J){let M=H(B.value);if(M.refused)return M;if(B.opaque){let V=i0(B.raw,Q,X);if(V.refused)return V}}return T}if(_6.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):d0($,X)}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=i0(M.raw,Q,X);if(V.refused)return V}return T}if(Z==="env")return H(wZ([...Y.map((K)=>IZ(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(q6.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):T}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(T6.has(M))K++}return a0($.slice(K),{depth:Q,appendsArgs:!B,debug:X.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=a0($.slice(K+1,B),X);if(M.refused)return M;K=B}return T}if(D6.has(Z))return d0($,X);if(I6.get(Z)?.includes($[0]?.value??""))return d0($.slice(1),X);return T}function a0(Z,z){if(Z.length===0)return T;let $=VZ(Z[0].value);if($==="gh")return K0(Z.slice(1),z);if(B0.has($)){let J=$2(Z.slice(1));return J?r(J.value,z.depth+1,z.debug):T}return F3($,Z[0],Z.slice(1),[],[],z)}function d0(Z,z){let $=Z.findIndex((J)=>!J.opaque&&VZ(J.value)==="gh"&&(J.value==="gh"||J.value.includes("/")));return $>=0?K0(Z.slice($+1),z):T}function $2(Z){for(let z=0;z<Z.length;z++){let $=Z[z].value;if($==="--")return;if(!$.startsWith("-")&&!$.startsWith("+"))return;if($==="-c"||/^-[A-Za-z]+$/.test($)&&$.includes("c"))return Z.slice(z+1).find((J)=>!J.value.startsWith("-")||J.value==="-");if(/^[-+][A-Za-z]*[oO]$/.test($))z++}return}function A6(Z){let z=[],$=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 Y=DZ(Z,J);if(!Y)continue;let X=Z.lastIndexOf(`
36
36
  `,J)+1,Q=Z.indexOf(`
37
- `,J);if(Q<0)continue;let H=tZ(Z,Q,[Y]),K=H<0?Z.slice(Q+1):Z.slice(Q+1,H),B=H<0?K:K.slice(0,Math.max(0,K.lastIndexOf(Y.delimiter))).replace(/\n$/,""),M=Z.slice(X,J)+" HEREDOC_OPERATOR "+Z.slice(Y.end,Q);z.push({body:B,runsBody:y6(M),quoted:Y.quoted})}return z}function y6(Z){let{segments:z}=Z2(Z),$=z.findIndex((H)=>H.words.some((K)=>K.text==="HEREDOC_OPERATOR"));if($<0)return!1;let J=(H)=>{let K=l(H);if(K<0)return{verb:"",args:[]};let B=H.words.slice(K+1).filter((M)=>M.text!=="HEREDOC_OPERATOR").map((M)=>IZ(M.text));return{verb:VZ(IZ(H.words[K].text).value),args:B}},{verb:Y,args:X}=J(z[$]);if(Y==="ssh"||n0(Y,X))return!0;if((Y==="source"||Y===".")&&["/dev/stdin","/dev/fd/0","/proc/self/fd/0"].includes(X[0]?.value??""))return!0;let Q=z[$+1];if(Y==="cat"&&Q&&N3(Q.sepBefore)){let H=J(Q);return H.verb==="ssh"||n0(H.verb,H.args)}return!1}var R6=/(?:^|[^A-Za-z0-9_.-])gh(?:$|[^A-Za-z0-9_.-])/;function _3(){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:r0}}}var v6=new Set(["Bash","Monitor"]);function D3(Z){if(Z?.hook_event_name!=="PreToolUse"||!v6.has(Z.tool_name??""))return{continue:!0};let z=WZ(Z);if(!z.trim())return{continue:!0};try{return r(z).refused?_3():{continue:!0}}catch{return R6.test(z)?_3():{continue:!0}}}function b6(Z){if(Z!=="trash-guard"&&Z!=="workspace-repos-guard")throw Error("Invalid safety capability")}function I3(Z,z){b6(Z);let $=Z,J=JSON.parse(z);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"||!J2.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 Y=J.hasna_execution;if(Y!==void 0&&(!Y||Object.keys(Y).sort().join()!=="agent,schema"||Y.schema!=="hasna.hooks.execution.v1"||typeof Y.agent!=="string"||!/^[A-Za-z0-9][A-Za-z0-9._:@-]{0,127}$/.test(Y.agent)))throw Error("Invalid execution capability");let X=Y===void 0?void 0:{runtime:process.execPath,home:M0.homedir(),path:process.env.PATH,agent:Y.agent};if(X&&(!J2.isAbsolute(X.runtime)||!X.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 b=J.tool_input.command??J.tool_input.patch;if(typeof b!=="string")throw Error("Invalid patch input");J.tool_input={...J.tool_input,command:b,patch:b}}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=(b)=>({hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:b}}),M=J3(K).output,V=D3(K),G=K.tool_input.command,U=()=>_Z(G,{home:M0.homedir(),cwd:J.cwd}).handoffHits.length>0,j=H&&(U()||!!HZ(G,U)),N=$==="trash-guard"&&(!Q||H)?k2(K,{home:M0.homedir(),cwd:J.cwd,findTrash:dZ,inspectTrash:RZ,execution:X}):{continue:!0};if(Q&&N.hookSpecificOutput?.permissionDecision==="allow")N=B("[trash-guard] A deletion inside a Monitor command is refused; run it with the Bash tool, where it is redirected into trash.");let y=M.decision==="block"?B(M.reason):V.hookSpecificOutput?V:j?B("[workspace-repos-guard] Deletion under a protected repository checkout is refused."):N;return JSON.stringify({verdict:"continue"in y?null:y})}var E6=2,S6="0.12.19";function f6(Z,z){return I3(Z,z)}
37
+ `,J);if(Q<0)continue;let H=tZ(Z,Q,[Y]),K=H<0?Z.slice(Q+1):Z.slice(Q+1,H),B=H<0?K:K.slice(0,Math.max(0,K.lastIndexOf(Y.delimiter))).replace(/\n$/,""),M=Z.slice(X,J)+" HEREDOC_OPERATOR "+Z.slice(Y.end,Q);z.push({body:B,runsBody:y6(M),quoted:Y.quoted})}return z}function y6(Z){let{segments:z}=Z2(Z),$=z.findIndex((H)=>H.words.some((K)=>K.text==="HEREDOC_OPERATOR"));if($<0)return!1;let J=(H)=>{let K=l(H);if(K<0)return{verb:"",args:[]};let B=H.words.slice(K+1).filter((M)=>M.text!=="HEREDOC_OPERATOR").map((M)=>IZ(M.text));return{verb:VZ(IZ(H.words[K].text).value),args:B}},{verb:Y,args:X}=J(z[$]);if(Y==="ssh"||n0(Y,X))return!0;if((Y==="source"||Y===".")&&["/dev/stdin","/dev/fd/0","/proc/self/fd/0"].includes(X[0]?.value??""))return!0;let Q=z[$+1];if(Y==="cat"&&Q&&N3(Q.sepBefore)){let H=J(Q);return H.verb==="ssh"||n0(H.verb,H.args)}return!1}var R6=/(?:^|[^A-Za-z0-9_.-])gh(?:$|[^A-Za-z0-9_.-])/;function _3(){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:r0}}}var v6=new Set(["Bash","Monitor"]);function D3(Z){if(Z?.hook_event_name!=="PreToolUse"||!v6.has(Z.tool_name??""))return{continue:!0};let z=WZ(Z);if(!z.trim())return{continue:!0};try{return r(z).refused?_3():{continue:!0}}catch{return R6.test(z)?_3():{continue:!0}}}function b6(Z){if(Z!=="trash-guard"&&Z!=="workspace-repos-guard")throw Error("Invalid safety capability")}function I3(Z,z){b6(Z);let $=Z,J=JSON.parse(z);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"||!J2.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 Y=J.hasna_execution;if(Y!==void 0&&(!Y||Object.keys(Y).sort().join()!=="agent,schema"||Y.schema!=="hasna.hooks.execution.v1"||typeof Y.agent!=="string"||!/^[A-Za-z0-9][A-Za-z0-9._:@-]{0,127}$/.test(Y.agent)))throw Error("Invalid execution capability");let X=Y===void 0?void 0:{runtime:process.execPath,home:M0.homedir(),path:process.env.PATH,agent:Y.agent};if(X&&(!J2.isAbsolute(X.runtime)||!X.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 b=J.tool_input.command??J.tool_input.patch;if(typeof b!=="string")throw Error("Invalid patch input");J.tool_input={...J.tool_input,command:b,patch:b}}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=(b)=>({hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:b}}),M=J3(K).output,V=D3(K),G=K.tool_input.command,U=()=>_Z(G,{home:M0.homedir(),cwd:J.cwd}).handoffHits.length>0,j=H&&(U()||!!HZ(G,U)),N=$==="trash-guard"&&(!Q||H)?k2(K,{home:M0.homedir(),cwd:J.cwd,findTrash:dZ,inspectTrash:RZ,execution:X}):{continue:!0};if(Q&&N.hookSpecificOutput?.permissionDecision==="allow")N=B("[trash-guard] A deletion inside a Monitor command is refused; run it with the Bash tool, where it is redirected into trash.");let y=M.decision==="block"?B(M.reason):V.hookSpecificOutput?V:j?B("[workspace-repos-guard] Deletion under a protected repository checkout is refused."):N;return JSON.stringify({verdict:"continue"in y?null:y})}var E6=2,S6="0.12.20";function f6(Z,z){return I3(Z,z)}
package/dist/index.js CHANGED
@@ -46442,6 +46442,7 @@ async function verifyNativeSafetyCommand(command, home = homedir8(), guard = "tr
46442
46442
  // src/lib/codex-safety-check.ts
46443
46443
  var SUPPORTED_CODEX_SAFETY_VERSIONS = ["codex-cli 0.153.0", "codex-cli 0.154.0", "codex-cli 0.154.0-alpha.6.1", "codex-cli 0.155.0", "codex-cli 0.155.1", "codex-cli 0.156.1", "codex-cli 0.157.0", "codex-cli 0.157.1", "codex-cli 0.158.0", "codex-cli 0.159.0", "codex-cli 0.159.2", "codex-cli 0.159.3", "codex-cli 0.160.0", "codex-cli 0.160.1", "codex-cli 0.161.0", "codex-cli 0.162.0", "codex-cli 0.162.1"];
46444
46444
  var versions = new Set(SUPPORTED_CODEX_SAFETY_VERSIONS);
46445
+ var CODEX_EXECUTABLE_MAX_BYTES = 512000000;
46445
46446
 
46446
46447
  class CodexSafetyError extends Error {
46447
46448
  code;
@@ -46483,9 +46484,9 @@ function executable2(command) {
46483
46484
  const fd = openSync15(path, constants15.O_RDONLY | constants15.O_NOFOLLOW | constants15.O_NONBLOCK);
46484
46485
  try {
46485
46486
  const stat2 = fstatSync10(fd);
46486
- need8(stat2.isFile() && [0, process.getuid?.()].includes(stat2.uid) && !(stat2.mode & 18) && !!(stat2.mode & 64) && stat2.size <= 256000000, "native_unsafe_executable");
46487
+ need8(stat2.isFile() && [0, process.getuid?.()].includes(stat2.uid) && !(stat2.mode & 18) && !!(stat2.mode & 64) && stat2.size <= CODEX_EXECUTABLE_MAX_BYTES, "native_unsafe_executable");
46487
46488
  const bytes = readFileSync19(fd);
46488
- need8(bytes.length <= 256000000, "native_unavailable");
46489
+ need8(bytes.length <= CODEX_EXECUTABLE_MAX_BYTES, "native_unavailable");
46489
46490
  need8(nativeHeader(bytes), "native_executable_required");
46490
46491
  return { path, sha256: digest3(bytes) };
46491
46492
  } finally {
@@ -3,6 +3,10 @@ import { verifyNativeSafetyCommand } from "../native-safety.js";
3
3
  /** Exact `codex --version` outputs whose app-server protocol was measured
4
4
  * against the real native binary. Anything else refuses as native_unsupported. */
5
5
  export declare const SUPPORTED_CODEX_SAFETY_VERSIONS: readonly ["codex-cli 0.153.0", "codex-cli 0.154.0", "codex-cli 0.154.0-alpha.6.1", "codex-cli 0.155.0", "codex-cli 0.155.1", "codex-cli 0.156.1", "codex-cli 0.157.0", "codex-cli 0.157.1", "codex-cli 0.158.0", "codex-cli 0.159.0", "codex-cli 0.159.2", "codex-cli 0.159.3", "codex-cli 0.160.0", "codex-cli 0.160.1", "codex-cli 0.161.0", "codex-cli 0.162.0", "codex-cli 0.162.1"];
6
+ /** Hard sanity bound on the native Codex executable, which is read whole into
7
+ * memory for the header check and SHA-256 pin. Not a platform contract: the
8
+ * measured 0.162.1 binaries are 246.6 MB (darwin-arm64) to 294.4 MB (linux-x64). */
9
+ export declare const CODEX_EXECUTABLE_MAX_BYTES = 512000000;
6
10
  export type CodexSafetyCode = "native_unavailable" | "native_unsafe_executable" | "native_executable_required" | "native_unsupported" | "native_failed" | "native_discovery_failed" | "hooks_disabled" | "guard_missing" | "guard_ambiguous" | "guard_definition_invalid" | "guard_disabled" | "guard_untrusted" | "guard_changed" | "guard_failed";
7
11
  export declare class CodexSafetyError extends Error {
8
12
  readonly code: CodexSafetyCode;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hasna/hooks",
3
- "version": "0.12.19",
3
+ "version": "0.12.20",
4
4
  "description": "Open source hooks library for AI coding agents - Install safety, quality, and automation hooks with a single command",
5
5
  "type": "module",
6
6
  "bin": {