@@ -23,7 +23,10 @@ import { privateFileStoreSync } from "../../infra/private-file-store.js";
2323import { createSubsystemLogger } from "../../logging/subsystem.js" ;
2424import { hasGlobalHooks } from "../../plugins/hook-runner-global.js" ;
2525import { PluginApprovalResolutions } from "../../plugins/types.js" ;
26- import { resolveExpiresAtMsFromDurationMs } from "../../shared/number-coercion.js" ;
26+ import {
27+ asDateTimestampMs ,
28+ resolveExpiresAtMsFromDurationMs ,
29+ } from "../../shared/number-coercion.js" ;
2730import {
2831 cancelDeferredPluginToolApproval ,
2932 hasBeforeToolCallPolicy ,
@@ -1687,11 +1690,16 @@ function consumeNativeHookRelayPermissionBudget(relayId: string, now = Date.now(
16871690}
16881691
16891692function hasNativeHookRelayPermissionAllowAlways ( key : string , now = Date . now ( ) ) : boolean {
1693+ const validNow = asDateTimestampMs ( now ) ;
1694+ if ( validNow === undefined ) {
1695+ return false ;
1696+ }
16901697 const entry = permissionAllowAlwaysApprovals . get ( key ) ;
16911698 if ( ! entry ) {
16921699 return false ;
16931700 }
1694- if ( entry . expiresAtMs <= now ) {
1701+ const expiresAtMs = asDateTimestampMs ( entry . expiresAtMs ) ;
1702+ if ( expiresAtMs === undefined || expiresAtMs <= validNow ) {
16951703 permissionAllowAlwaysApprovals . delete ( key ) ;
16961704 return false ;
16971705 }
@@ -1700,8 +1708,14 @@ function hasNativeHookRelayPermissionAllowAlways(key: string, now = Date.now()):
17001708
17011709function rememberNativeHookRelayPermissionAllowAlways ( key : string , now = Date . now ( ) ) : void {
17021710 pruneNativeHookRelayPermissionAllowAlways ( now ) ;
1711+ const expiresAtMs = resolveExpiresAtMsFromDurationMs ( PERMISSION_ALLOW_ALWAYS_TTL_MS , {
1712+ nowMs : now ,
1713+ } ) ;
1714+ if ( expiresAtMs === undefined ) {
1715+ return ;
1716+ }
17031717 permissionAllowAlwaysApprovals . set ( key , {
1704- expiresAtMs : now + PERMISSION_ALLOW_ALWAYS_TTL_MS ,
1718+ expiresAtMs,
17051719 } ) ;
17061720 while ( permissionAllowAlwaysApprovals . size > MAX_PERMISSION_ALLOW_ALWAYS_ENTRIES ) {
17071721 const oldestKey = permissionAllowAlwaysApprovals . keys ( ) . next ( ) . value ;
@@ -1713,8 +1727,13 @@ function rememberNativeHookRelayPermissionAllowAlways(key: string, now = Date.no
17131727}
17141728
17151729function pruneNativeHookRelayPermissionAllowAlways ( now = Date . now ( ) ) : void {
1730+ const validNow = asDateTimestampMs ( now ) ;
1731+ if ( validNow === undefined ) {
1732+ return ;
1733+ }
17161734 for ( const [ key , entry ] of permissionAllowAlwaysApprovals ) {
1717- if ( entry . expiresAtMs <= now ) {
1735+ const expiresAtMs = asDateTimestampMs ( entry . expiresAtMs ) ;
1736+ if ( expiresAtMs === undefined || expiresAtMs <= validNow ) {
17181737 permissionAllowAlwaysApprovals . delete ( key ) ;
17191738 }
17201739 }
0 commit comments