import type { SanitizeResult, SecurityRule, SecurityPolicy, CredentialMatch } from './types.js'; export declare class SecurityGuard { private policy; /** 已编译的正则规则缓存(避免每次 sanitize 重复遍历数组) */ private compiledBlacklist; private compiledCustomRewrite; private compiledCustomWarn; /** 删除保护规则(使用 policy.trashDir) */ private deleteProtectionRule; private windowsDeleteProtectionRule; constructor(policy?: Partial); /** 编译规则缓存(policy 变更时调用) */ private invalidateCompiledRules; private getCompiledBlacklist; private getCompiledCustomRewrite; private getCompiledCustomWarn; /** 检查命令安全性 */ sanitize(command: string): SanitizeResult; /** 添加自定义安全规则 */ addRule(rule: SecurityRule): void; /** 移除规则 */ removeRule(name: string): void; /** 更新安全策略 */ setPolicy(policy: Partial): void; /** 获取当前策略 */ getPolicy(): SecurityPolicy; /** * 检查 Shell 命令安全性(便捷方法) * * 结合内置黑名单 + 自定义规则,返回 null 表示安全,否则返回拦截原因。 * 适用于沙箱场景的快速检查,无需完整的 sanitize 流程。 * * @example * const reason = guard.checkShellCommand('sudo rm -rf /'); * if (reason) console.warn('Command blocked:', reason); */ checkShellCommand(command: string): string | null; /** * 扫描并脱敏文本中的敏感信息 * 将检测到的 API Key、Token、密码等替换为 [REDACTED:xxx] * @param text 输入文本(通常是工具结果) * @returns 脱敏后的文本 */ sanitizeCredentials(text: string): string; /** * 扫描文本中的凭证泄露,返回结构化匹配结果(含处置动作)。 * 供需要区分「告警」与「阻断」语义的调用方使用: * - action='block':高危凭证(如 AKIA 访问密钥、OpenAI key),必须脱敏且应审计/阻断; * - action='warn':低风险凭证(如 key=value 上下文中的 secret),仅告警不阻断。 * 注意:本方法只扫描不改写,脱敏请用 `sanitizeCredentials`。 * * @param text 输入文本 * @returns 所有匹配到的凭证(不含已被脱敏的原文,matched 为原样片段) */ scanCredentials(text: string): CredentialMatch[]; private matchRule; } //# sourceMappingURL=guard.d.ts.map