/ utils / permissions / PermissionRule.ts
PermissionRule.ts
 1  import z from 'zod/v4'
 2  // Types extracted to src/types/permissions.ts to break import cycles
 3  import type {
 4    PermissionBehavior,
 5    PermissionRule,
 6    PermissionRuleSource,
 7    PermissionRuleValue,
 8  } from '../../types/permissions.js'
 9  import { lazySchema } from '../lazySchema.js'
10  
11  // Re-export for backwards compatibility
12  export type {
13    PermissionBehavior,
14    PermissionRule,
15    PermissionRuleSource,
16    PermissionRuleValue,
17  }
18  
19  /**
20   * ToolPermissionBehavior is the behavior associated with a permission rule.
21   * 'allow' means the rule allows the tool to run.
22   * 'deny' means the rule denies the tool from running.
23   * 'ask' means the rule forces a prompt to be shown to the user.
24   */
25  export const permissionBehaviorSchema = lazySchema(() =>
26    z.enum(['allow', 'deny', 'ask']),
27  )
28  
29  /**
30   * PermissionRuleValue is the content of a permission rule.
31   * @param toolName - The name of the tool this rule applies to
32   * @param ruleContent - The optional content of the rule.
33   *   Each tool may implement custom handling in `checkPermissions()`
34   */
35  export const permissionRuleValueSchema = lazySchema(() =>
36    z.object({
37      toolName: z.string(),
38      ruleContent: z.string().optional(),
39    }),
40  )