@hasna/hooks 0.12.23 → 0.13.1

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:F0,getOwnPropertyNames:O3,getOwnPropertyDescriptor:L3}=Object
34
34
  `).replace(/%s/g,()=>B[K++]?.value??"")+(K<B.length?" "+B.slice(K).map((H)=>H.value).join(" "):"")}if(Y==="cat"){let Q=Z.indexOf("<<");if(Q<0)return null;let B=IZ(Z,Q),K=Z.indexOf(`
35
35
  `,Q);if(!B||K<0)return null;let H=eZ(Z,K,[B]);if(H<0)return null;let M=Z.slice(K+1,H);return M.slice(0,M.lastIndexOf(B.delimiter)).replace(/\n$/,"")}return null}function d0(Z,z,$){for(let J of n0(Z).bodies){let Y=a0(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>v6)return K0.test(Z)?I("unclassifiable"):T;let{segments:J,trustworthy:Y}=$2(Z);if(!Y)return K0.test(Z)?I("unclassifiable"):T;let X=$,Q=(B)=>r(B,z+1,X);for(let B of S6(Z)){if(B.runsBody){let K=Q(B.body);if(K.refused)return K}if(!B.quoted){let K=n0(B.body,"heredoc");if(!K.complete&&K0.test(B.body))return I("unclassifiable");for(let H of K.bodies){let M=Q(H);if(M.refused)return M}}}for(let B=0;B<J.length;B++){let K=J[B];for(let N of K.words){let R=n0(N.text);if(!R.complete&&K0.test(N.text))return I("unclassifiable");for(let m of R.bodies){let p=Q(m);if(p.refused)return p}}let H=u(K),M=K.words.map((N,R)=>({word:TZ(N.text),redirect:K.redirects.has(R)})),V=M.slice(0,H<0?M.length:H).map((N)=>N.word),G=H>=0?VZ(M[H].word.value):"";if(H<0||["export","declare","typeset","readonly","local"].includes(G)){if(X=W3([...V,...M.slice(H+1).map((N)=>N.word)],X),H<0)continue}let U=W3(V,X),j=M.slice(H+1).filter((N)=>!N.redirect).map((N)=>N.word),F=M.slice(H+1).filter((N)=>N.redirect).map((N)=>N.word),y=M[H].word,b=VZ(y.value),k={depth:z,appendsArgs:!1,debug:U};if(H>0&&M[H-1].word.value==="function"){let N=j.filter((m)=>!["{","()","(",")"].includes(m.value)),R=r0(N,k);if(R.refused)return R;continue}if(B>0&&D3(K.sepBefore)&&o0(b,j)){let N=J[B-1],R=b6(Z,N),m=R===null?null:a0(R);if(m!==null){let p=r(m,z+1,U);if(p.refused)return p}}let d=J[B+1];if(d&&/<\(\s*$/.test(d.sepBefore)&&(M0.has(b)||b==="source"||b===".")){let N=d.words[0].start-d.sepBefore.length+d.sepBefore.lastIndexOf("("),R=HZ(Z,N),m=R<0?null:a0(Z.slice(N+1,R-1));if(m!==null){let p=r(m,z+1,U);if(p.refused)return p}}let q=_3(b,y,j,F,K.words.slice(0,H+1),k);if(q.refused)return q}return T}function b6(Z,z){let $=z.words[0],J=z.words[z.words.length-1];return $&&J?Z.slice($.start,J.end):null}function E6(Z){let z=VZ(Z.value);return/[$`]/.test(z)||z===""?void 0:z}function _3(Z,z,$,J,Y,X){let Q=X.depth,B=(K)=>r(K,Q+1,X.debug);if(z.opaque){let K=E6(z);if(K===void 0){let H=$.find((V)=>!V.value.startsWith("-")),M=B0($,X);if(!M.refused)return T;return M.rule!=="unclassifiable"||H!==void 0&&!H.opaque&&X6.has(H.value)?M:T}Z=K}if(Z==="gh")return B0($,X);if(M0.has(Z)){let K=J2($);if(K){let H=B(K.value);if(H.refused||!K.opaque)return H;return d0(K.raw,Q,X)}for(let H of J){let M=B(H.value);if(M.refused)return M;if(H.opaque){let V=d0(H.raw,Q,X);if(V.refused)return V}}return T}if(P6.has(Z)){let K=$.findIndex((M)=>M.value==="-c"||M.value==="--command"||/^-[A-Za-z]*c$/.test(M.value)),H=K>=0?$[K+1]:void 0;return H?B(H.value):s0($,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 H=B(K.map((M)=>M.value).join(" "));if(H.refused)return H;for(let M of K){let V=d0(M.raw,Q,X);if(V.refused)return V}return T}if(Z==="env")return B(gZ([...Y.map((K)=>TZ(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(y6.has(V))K++}let H=$.slice(K+1);if(H[0]?.value==="--")H.shift();let M=H.map((V)=>V.value).join(" ");return M?B(M):T}if(Z==="xargs"){let K=0,H=!1;for(;K<$.length;K++){let M=$[K].value;if(M==="--"){K++;break}if(!M.startsWith("-"))break;if(/^-I|^-i|^--replace/.test(M))H=!0;if(A6.has(M))K++}return r0($.slice(K),{depth:Q,appendsArgs:!H,debug:X.debug})}if(Z==="find"){for(let K=0;K<$.length;K++){if(!["-exec","-execdir","-ok","-okdir"].includes($[K].value))continue;let H=K+1;while(H<$.length&&$[H].value!==";"&&$[H].value!=="+")H++;let M=r0($.slice(K+1,H),X);if(M.refused)return M;K=H}return T}if(O6.has(Z))return s0($,X);if(L6.get(Z)?.includes($[0]?.value??""))return s0($.slice(1),X);return T}function r0(Z,z){if(Z.length===0)return T;let $=VZ(Z[0].value);if($==="gh")return B0(Z.slice(1),z);if(M0.has($)){let J=J2(Z.slice(1));return J?r(J.value,z.depth+1,z.debug):T}return _3($,Z[0],Z.slice(1),[],[],z)}function s0(Z,z){let $=Z.findIndex((J)=>!J.opaque&&VZ(J.value)==="gh"&&(J.value==="gh"||J.value.includes("/")));return $>=0?B0(Z.slice($+1),z):T}function J2(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 S6(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=IZ(Z,J);if(!Y)continue;let X=Z.lastIndexOf(`
36
36
  `,J)+1,Q=Z.indexOf(`
37
- `,J);if(Q<0)continue;let B=eZ(Z,Q,[Y]),K=B<0?Z.slice(Q+1):Z.slice(Q+1,B),H=B<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:H,runsBody:f6(M),quoted:Y.quoted})}return z}function f6(Z){let{segments:z}=$2(Z),$=z.findIndex((B)=>B.words.some((K)=>K.text==="HEREDOC_OPERATOR"));if($<0)return!1;let J=(B)=>{let K=u(B);if(K<0)return{verb:"",args:[]};let H=B.words.slice(K+1).filter((M)=>M.text!=="HEREDOC_OPERATOR").map((M)=>TZ(M.text));return{verb:VZ(TZ(B.words[K].text).value),args:H}},{verb:Y,args:X}=J(z[$]);if(Y==="ssh"||o0(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&&D3(Q.sepBefore)){let B=J(Q);return B.verb==="ssh"||o0(B.verb,B.args)}return!1}var k6=/(?:^|[^A-Za-z0-9_.-])gh(?:$|[^A-Za-z0-9_.-])/;function I3(){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:t0}}}var x6=new Set(["Bash","Monitor"]);function T3(Z){if(Z?.hook_event_name!=="PreToolUse"||!x6.has(Z.tool_name??""))return{continue:!0};let z=WZ(Z);if(!z.trim())return{continue:!0};try{return r(z).refused?I3():{continue:!0}}catch{return k6.test(z)?I3():{continue:!0}}}function h6(Z){if(Z!=="trash-guard"&&Z!=="workspace-repos-guard")throw Error("Invalid safety capability")}function q3(Z,z){h6(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"||!z2.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:V0.homedir(),path:process.env.PATH,agent:Y.agent};if(X&&(!z2.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",B=J.tool_name==="Bash"||Q&&typeof J.tool_input.command==="string",K=Q&&B?{...J,tool_name:"Bash"}:J,H=(b)=>({hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:b}}),M=Y3(K).output,V=T3(K),G=K.tool_input.command,U=()=>_Z(G,{home:V0.homedir(),cwd:J.cwd}).handoffHits.length>0,j=B&&(U()||!!BZ(G,U)),F=$==="trash-guard"&&(!Q||B)?h2(K,{home:V0.homedir(),cwd:J.cwd,findTrash:sZ,inspectTrash:vZ,execution:X}):{continue:!0};if(Q&&F.hookSpecificOutput?.permissionDecision==="allow")F=H("[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"?H(M.reason):V.hookSpecificOutput?V:j?H("[workspace-repos-guard] Deletion under a protected repository checkout is refused."):F;return JSON.stringify({verdict:"continue"in y?null:y})}var w6=2,g6="0.12.23";function l6(Z,z){return q3(Z,z)}
37
+ `,J);if(Q<0)continue;let B=eZ(Z,Q,[Y]),K=B<0?Z.slice(Q+1):Z.slice(Q+1,B),H=B<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:H,runsBody:f6(M),quoted:Y.quoted})}return z}function f6(Z){let{segments:z}=$2(Z),$=z.findIndex((B)=>B.words.some((K)=>K.text==="HEREDOC_OPERATOR"));if($<0)return!1;let J=(B)=>{let K=u(B);if(K<0)return{verb:"",args:[]};let H=B.words.slice(K+1).filter((M)=>M.text!=="HEREDOC_OPERATOR").map((M)=>TZ(M.text));return{verb:VZ(TZ(B.words[K].text).value),args:H}},{verb:Y,args:X}=J(z[$]);if(Y==="ssh"||o0(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&&D3(Q.sepBefore)){let B=J(Q);return B.verb==="ssh"||o0(B.verb,B.args)}return!1}var k6=/(?:^|[^A-Za-z0-9_.-])gh(?:$|[^A-Za-z0-9_.-])/;function I3(){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:t0}}}var x6=new Set(["Bash","Monitor"]);function T3(Z){if(Z?.hook_event_name!=="PreToolUse"||!x6.has(Z.tool_name??""))return{continue:!0};let z=WZ(Z);if(!z.trim())return{continue:!0};try{return r(z).refused?I3():{continue:!0}}catch{return k6.test(z)?I3():{continue:!0}}}function h6(Z){if(Z!=="trash-guard"&&Z!=="workspace-repos-guard")throw Error("Invalid safety capability")}function q3(Z,z){h6(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"||!z2.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:V0.homedir(),path:process.env.PATH,agent:Y.agent};if(X&&(!z2.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",B=J.tool_name==="Bash"||Q&&typeof J.tool_input.command==="string",K=Q&&B?{...J,tool_name:"Bash"}:J,H=(b)=>({hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:b}}),M=Y3(K).output,V=T3(K),G=K.tool_input.command,U=()=>_Z(G,{home:V0.homedir(),cwd:J.cwd}).handoffHits.length>0,j=B&&(U()||!!BZ(G,U)),F=$==="trash-guard"&&(!Q||B)?h2(K,{home:V0.homedir(),cwd:J.cwd,findTrash:sZ,inspectTrash:vZ,execution:X}):{continue:!0};if(Q&&F.hookSpecificOutput?.permissionDecision==="allow")F=H("[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"?H(M.reason):V.hookSpecificOutput?V:j?H("[workspace-repos-guard] Deletion under a protected repository checkout is refused."):F;return JSON.stringify({verdict:"continue"in y?null:y})}var w6=2,g6="0.13.1";function l6(Z,z){return q3(Z,z)}
package/bin/serve.js CHANGED
@@ -4785,6 +4785,8 @@ var manifestSchema = exports_external.object({
4785
4785
  script_kind: exports_external.enum(["inline", "file"]).optional(),
4786
4786
  args: exports_external.array(exports_external.string()).optional(),
4787
4787
  nativeTargetDispatch: exports_external.boolean().optional(),
4788
+ requires_final_message: exports_external.boolean().optional(),
4789
+ requires_block: exports_external.boolean().optional(),
4788
4790
  timeout_ms: exports_external.number().int().positive().optional(),
4789
4791
  env: exports_external.record(exports_external.string(), exports_external.string()).optional()
4790
4792
  });
@@ -5507,6 +5509,8 @@ function resolveHookMeta(name) {
5507
5509
  matcher: "",
5508
5510
  tags: ["custom"],
5509
5511
  nativeTargetDispatch: manifest.nativeTargetDispatch,
5512
+ requiresFinalMessage: manifest.requires_final_message,
5513
+ requiresBlock: manifest.requires_block,
5510
5514
  timeoutSeconds: manifest.timeout_ms === undefined ? undefined : Math.ceil(manifest.timeout_ms / 1000)
5511
5515
  };
5512
5516
  }