@hasna/hooks 0.12.16 → 0.12.17
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 +1 -1
- package/bin/index.js +1 -1
- package/bin/native-safety-worker.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/lib/codex-safety-check.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -391,7 +391,7 @@ Codex is installed through npm, pass the platform package's native binary rather
|
|
|
391
391
|
than its JavaScript launcher. Executable ownership, permissions, ancestry and
|
|
392
392
|
bytes are checked. Supported protocol versions are 0.153.0, 0.154.0,
|
|
393
393
|
0.154.0-alpha.6.1, 0.155.0, 0.155.1, 0.156.1, 0.157.0, 0.157.1, 0.158.0, 0.159.0, 0.159.2,
|
|
394
|
-
0.159.3, 0.160.0 and 0.
|
|
394
|
+
0.159.3, 0.160.0, 0.160.1, 0.161.0, 0.162.0 and 0.162.1;
|
|
395
395
|
other versions refuse pending compatibility validation. Updating Codex can
|
|
396
396
|
therefore require a compatible Hooks release before native safety verification
|
|
397
397
|
and trust provisioning succeed. Keep existing hook definitions and trust intact
|
package/bin/index.js
CHANGED
|
@@ -39282,7 +39282,7 @@ var init_codex_safety_check = __esm(() => {
|
|
|
39282
39282
|
init_native_child_env();
|
|
39283
39283
|
init_native_safety2();
|
|
39284
39284
|
init_native_readiness();
|
|
39285
|
-
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"];
|
|
39285
|
+
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"];
|
|
39286
39286
|
versions = new Set(SUPPORTED_CODEX_SAFETY_VERSIONS);
|
|
39287
39287
|
CodexSafetyError = class CodexSafetyError extends Error {
|
|
39288
39288
|
code;
|
|
@@ -24,4 +24,4 @@ var{defineProperty:H0,getOwnPropertyNames:V3,getOwnPropertyDescriptor:G3}=Object
|
|
|
24
24
|
`).replace(/%s/g,()=>H[K++]?.value??"")+(K<H.length?" "+H.slice(K).map((B)=>B.value).join(" "):"")}if(Y==="cat"){let X=Z.indexOf("<<");if(X<0)return null;let H=WZ(Z,X),K=Z.indexOf(`
|
|
25
25
|
`,X);if(!H||K<0)return null;let B=sZ(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 h0(Z,J,$){for(let z of g0(Z).bodies){let Y=u0(z);if(Y===null)continue;let Q=o(Y,J+1,$.debug);if(Q.refused)return Q}return I}function o(Z,J=0,$=!1){if(typeof Z!=="string"||!Z.trim())return I;if(J>G6)return eZ.test(Z)?T("unclassifiable"):I;let{segments:z,trustworthy:Y}=d0(Z);if(!Y)return eZ.test(Z)?T("unclassifiable"):I;let Q=$,X=(H)=>o(H,J+1,Q);for(let H of j6(Z)){if(H.runsBody){let K=X(H.body);if(K.refused)return K}if(!H.quoted){let K=g0(H.body,"heredoc");if(!K.complete&&eZ.test(H.body))return T("unclassifiable");for(let B of K.bodies){let M=X(B);if(M.refused)return M}}}for(let H=0;H<z.length;H++){let K=z[H];for(let N of K.words){let R=g0(N.text);if(!R.complete&&eZ.test(N.text))return T("unclassifiable");for(let w of R.bodies){let g=X(w);if(g.refused)return g}}let B=h(K),M=K.words.map((N,R)=>({word:jZ(N.text),redirect:K.redirects.has(R)})),V=M.slice(0,B<0?M.length:B).map((N)=>N.word),G=B>=0?BZ(M[B].word.value):"";if(B<0||["export","declare","typeset","readonly","local"].includes(G)){if(Q=$3([...V,...M.slice(B+1).map((N)=>N.word)],Q),B<0)continue}let U=$3(V,Q),j=M.slice(B+1).filter((N)=>!N.redirect).map((N)=>N.word),F=M.slice(B+1).filter((N)=>N.redirect).map((N)=>N.word),E=M[B].word,k=BZ(E.value),m={depth:J,appendsArgs:!1,debug:U};if(B>0&&M[B-1].word.value==="function"){let N=j.filter((w)=>!["{","()","(",")"].includes(w.value)),R=m0(N,m);if(R.refused)return R;continue}if(H>0&&Y3(K.sepBefore)&&l0(k,j)){let N=z[H-1],R=U6(Z,N),w=R===null?null:u0(R);if(w!==null){let g=o(w,J+1,U);if(g.refused)return g}}let d=z[H+1];if(d&&/<\(\s*$/.test(d.sepBefore)&&(J0.has(k)||k==="source"||k===".")){let N=d.words[0].start-d.sepBefore.length+d.sepBefore.lastIndexOf("("),R=KZ(Z,N),w=R<0?null:u0(Z.slice(N+1,R-1));if(w!==null){let g=o(w,J+1,U);if(g.refused)return g}}let C=Q3(k,E,j,F,K.words.slice(0,B+1),m);if(C.refused)return C}return I}function U6(Z,J){let $=J.words[0],z=J.words[J.words.length-1];return $&&z?Z.slice($.start,z.end):null}function W6(Z){let J=BZ(Z.value);return/[$`]/.test(J)||J===""?void 0:J}function Q3(Z,J,$,z,Y,Q){let X=Q.depth,H=(K)=>o(K,X+1,Q.debug);if(J.opaque){let K=W6(J);if(K===void 0){let B=$.find((V)=>!V.value.startsWith("-")),M=Z0($,Q);if(!M.refused)return I;return M.rule!=="unclassifiable"||B!==void 0&&!B.opaque&&u5.has(B.value)?M:I}Z=K}if(Z==="gh")return Z0($,Q);if(J0.has(Z)){let K=s0($);if(K){let B=H(K.value);if(B.refused||!K.opaque)return B;return h0(K.raw,X,Q)}for(let B of z){let M=H(B.value);if(M.refused)return M;if(B.opaque){let V=h0(B.raw,X,Q);if(V.refused)return V}}return I}if(X6.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):w0($,Q)}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=h0(M.raw,X,Q);if(V.refused)return V}return I}if(Z==="env")return H(RZ([...Y.map((K)=>jZ(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(M6.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):I}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(B6.has(M))K++}return m0($.slice(K),{depth:X,appendsArgs:!B,debug:Q.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=m0($.slice(K+1,B),Q);if(M.refused)return M;K=B}return I}if(K6.has(Z))return w0($,Q);if(H6.get(Z)?.includes($[0]?.value??""))return w0($.slice(1),Q);return I}function m0(Z,J){if(Z.length===0)return I;let $=BZ(Z[0].value);if($==="gh")return Z0(Z.slice(1),J);if(J0.has($)){let z=s0(Z.slice(1));return z?o(z.value,J.depth+1,J.debug):I}return Q3($,Z[0],Z.slice(1),[],[],J)}function w0(Z,J){let $=Z.findIndex((z)=>!z.opaque&&BZ(z.value)==="gh"&&(z.value==="gh"||z.value.includes("/")));return $>=0?Z0(Z.slice($+1),J):I}function s0(Z){for(let J=0;J<Z.length;J++){let $=Z[J].value;if($==="--")return;if(!$.startsWith("-")&&!$.startsWith("+"))return;if($==="-c"||/^-[A-Za-z]+$/.test($)&&$.includes("c"))return Z.slice(J+1).find((z)=>!z.value.startsWith("-")||z.value==="-");if(/^[-+][A-Za-z]*[oO]$/.test($))J++}return}function j6(Z){let J=[],$=0;for(;;){let z=Z.indexOf("<<",$);if(z<0)break;if($=z+2,Z[z+2]==="<"||z>0&&Z[z-1]==="<"){$=z+3;continue}let Y=WZ(Z,z);if(!Y)continue;let Q=Z.lastIndexOf(`
|
|
26
26
|
`,z)+1,X=Z.indexOf(`
|
|
27
|
-
`,z);if(X<0)continue;let H=sZ(Z,X,[Y]),K=H<0?Z.slice(X+1):Z.slice(X+1,H),B=H<0?K:K.slice(0,Math.max(0,K.lastIndexOf(Y.delimiter))).replace(/\n$/,""),M=Z.slice(Q,z)+" HEREDOC_OPERATOR "+Z.slice(Y.end,X);J.push({body:B,runsBody:N6(M),quoted:Y.quoted})}return J}function N6(Z){let{segments:J}=d0(Z),$=J.findIndex((H)=>H.words.some((K)=>K.text==="HEREDOC_OPERATOR"));if($<0)return!1;let z=(H)=>{let K=h(H);if(K<0)return{verb:"",args:[]};let B=H.words.slice(K+1).filter((M)=>M.text!=="HEREDOC_OPERATOR").map((M)=>jZ(M.text));return{verb:BZ(jZ(H.words[K].text).value),args:B}},{verb:Y,args:Q}=z(J[$]);if(Y==="ssh"||l0(Y,Q))return!0;if((Y==="source"||Y===".")&&["/dev/stdin","/dev/fd/0","/proc/self/fd/0"].includes(Q[0]?.value??""))return!0;let X=J[$+1];if(Y==="cat"&&X&&Y3(X.sepBefore)){let H=z(X);return H.verb==="ssh"||l0(H.verb,H.args)}return!1}var F6=/(?:^|[^A-Za-z0-9_.-])gh(?:$|[^A-Za-z0-9_.-])/;function X3(){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:p0}}}var _6=new Set(["Bash","Monitor"]);function K3(Z){if(Z?.hook_event_name!=="PreToolUse"||!_6.has(Z.tool_name??""))return{continue:!0};let J=GZ(Z);if(!J.trim())return{continue:!0};try{return o(J).refused?X3():{continue:!0}}catch{return F6.test(J)?X3():{continue:!0}}}function T6(Z){if(Z!=="trash-guard"&&Z!=="workspace-repos-guard")throw Error("Invalid safety capability")}function H3(Z,J){T6(Z);let $=Z,z=JSON.parse(J);if(!z||Array.isArray(z)||z.hook_event_name!=="PreToolUse"||typeof z.tool_name!=="string"||!z.tool_input||typeof z.tool_input!=="object"||Array.isArray(z.tool_input)||typeof z.cwd!=="string"||!n0.isAbsolute(z.cwd))throw Error("Invalid safety input");if(z.tool_name==="Bash"&&typeof z.tool_input.command!=="string")throw Error("Invalid shell input");if(z.tool_name==="Monitor"&&z.tool_input.command!==void 0&&typeof z.tool_input.command!=="string")throw Error("Invalid monitor input");let Y=z.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 Q=Y===void 0?void 0:{runtime:process.execPath,home:z0.homedir(),path:process.env.PATH,agent:Y.agent};if(Q&&(!n0.isAbsolute(Q.runtime)||!Q.path))throw Error("Invalid bound execution context");if(["apply_patch","ApplyPatch","functions.apply_patch"].includes(z.tool_name)){if(z.tool_input.command!==void 0&&z.tool_input.patch!==void 0&&z.tool_input.command!==z.tool_input.patch)throw Error("Conflicting patch aliases");let F=z.tool_input.command??z.tool_input.patch;if(typeof F!=="string")throw Error("Invalid patch input");z.tool_input={...z.tool_input,command:F,patch:F}}let X=z.tool_name==="Monitor",H=z.tool_name==="Bash"||X&&typeof z.tool_input.command==="string",K=X&&H?{...z,tool_name:"Bash"}:z,B=(F)=>({hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:F}}),M=c2(K).output,V=K3(K),G=H&&bZ(K.tool_input.command,{home:z0.homedir(),cwd:z.cwd}).handoffHits.length>0,U=$==="trash-guard"&&(!X||H)?P2(K,{home:z0.homedir(),cwd:z.cwd,findTrash:hZ,inspectTrash:qZ,execution:Q}):{continue:!0};if(X&&U.hookSpecificOutput?.permissionDecision==="allow")U=B("[trash-guard] A deletion inside a Monitor command is refused; run it with the Bash tool, where it is redirected into trash.");let j=M.decision==="block"?B(M.reason):V.hookSpecificOutput?V:G?B("[workspace-repos-guard] Deletion under a protected repository checkout is refused."):U;return JSON.stringify({verdict:"continue"in j?null:j})}var I6=2,C6="0.12.
|
|
27
|
+
`,z);if(X<0)continue;let H=sZ(Z,X,[Y]),K=H<0?Z.slice(X+1):Z.slice(X+1,H),B=H<0?K:K.slice(0,Math.max(0,K.lastIndexOf(Y.delimiter))).replace(/\n$/,""),M=Z.slice(Q,z)+" HEREDOC_OPERATOR "+Z.slice(Y.end,X);J.push({body:B,runsBody:N6(M),quoted:Y.quoted})}return J}function N6(Z){let{segments:J}=d0(Z),$=J.findIndex((H)=>H.words.some((K)=>K.text==="HEREDOC_OPERATOR"));if($<0)return!1;let z=(H)=>{let K=h(H);if(K<0)return{verb:"",args:[]};let B=H.words.slice(K+1).filter((M)=>M.text!=="HEREDOC_OPERATOR").map((M)=>jZ(M.text));return{verb:BZ(jZ(H.words[K].text).value),args:B}},{verb:Y,args:Q}=z(J[$]);if(Y==="ssh"||l0(Y,Q))return!0;if((Y==="source"||Y===".")&&["/dev/stdin","/dev/fd/0","/proc/self/fd/0"].includes(Q[0]?.value??""))return!0;let X=J[$+1];if(Y==="cat"&&X&&Y3(X.sepBefore)){let H=z(X);return H.verb==="ssh"||l0(H.verb,H.args)}return!1}var F6=/(?:^|[^A-Za-z0-9_.-])gh(?:$|[^A-Za-z0-9_.-])/;function X3(){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:p0}}}var _6=new Set(["Bash","Monitor"]);function K3(Z){if(Z?.hook_event_name!=="PreToolUse"||!_6.has(Z.tool_name??""))return{continue:!0};let J=GZ(Z);if(!J.trim())return{continue:!0};try{return o(J).refused?X3():{continue:!0}}catch{return F6.test(J)?X3():{continue:!0}}}function T6(Z){if(Z!=="trash-guard"&&Z!=="workspace-repos-guard")throw Error("Invalid safety capability")}function H3(Z,J){T6(Z);let $=Z,z=JSON.parse(J);if(!z||Array.isArray(z)||z.hook_event_name!=="PreToolUse"||typeof z.tool_name!=="string"||!z.tool_input||typeof z.tool_input!=="object"||Array.isArray(z.tool_input)||typeof z.cwd!=="string"||!n0.isAbsolute(z.cwd))throw Error("Invalid safety input");if(z.tool_name==="Bash"&&typeof z.tool_input.command!=="string")throw Error("Invalid shell input");if(z.tool_name==="Monitor"&&z.tool_input.command!==void 0&&typeof z.tool_input.command!=="string")throw Error("Invalid monitor input");let Y=z.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 Q=Y===void 0?void 0:{runtime:process.execPath,home:z0.homedir(),path:process.env.PATH,agent:Y.agent};if(Q&&(!n0.isAbsolute(Q.runtime)||!Q.path))throw Error("Invalid bound execution context");if(["apply_patch","ApplyPatch","functions.apply_patch"].includes(z.tool_name)){if(z.tool_input.command!==void 0&&z.tool_input.patch!==void 0&&z.tool_input.command!==z.tool_input.patch)throw Error("Conflicting patch aliases");let F=z.tool_input.command??z.tool_input.patch;if(typeof F!=="string")throw Error("Invalid patch input");z.tool_input={...z.tool_input,command:F,patch:F}}let X=z.tool_name==="Monitor",H=z.tool_name==="Bash"||X&&typeof z.tool_input.command==="string",K=X&&H?{...z,tool_name:"Bash"}:z,B=(F)=>({hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:F}}),M=c2(K).output,V=K3(K),G=H&&bZ(K.tool_input.command,{home:z0.homedir(),cwd:z.cwd}).handoffHits.length>0,U=$==="trash-guard"&&(!X||H)?P2(K,{home:z0.homedir(),cwd:z.cwd,findTrash:hZ,inspectTrash:qZ,execution:Q}):{continue:!0};if(X&&U.hookSpecificOutput?.permissionDecision==="allow")U=B("[trash-guard] A deletion inside a Monitor command is refused; run it with the Bash tool, where it is redirected into trash.");let j=M.decision==="block"?B(M.reason):V.hookSpecificOutput?V:G?B("[workspace-repos-guard] Deletion under a protected repository checkout is refused."):U;return JSON.stringify({verdict:"continue"in j?null:j})}var I6=2,C6="0.12.17";function D6(Z,J){return H3(Z,J)}
|
package/dist/index.js
CHANGED
|
@@ -46440,7 +46440,7 @@ async function verifyNativeSafetyCommand(command, home = homedir8(), guard = "tr
|
|
|
46440
46440
|
}
|
|
46441
46441
|
|
|
46442
46442
|
// src/lib/codex-safety-check.ts
|
|
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"];
|
|
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
46445
|
|
|
46446
46446
|
class CodexSafetyError extends Error {
|
|
@@ -2,7 +2,7 @@ import { type NativeSafetyName } from "./native-safety.js";
|
|
|
2
2
|
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
|
-
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"];
|
|
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
6
|
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
7
|
export declare class CodexSafetyError extends Error {
|
|
8
8
|
readonly code: CodexSafetyCode;
|
package/package.json
CHANGED