/** * src/core/sandbox-scanner.ts — GDScript 执行前安全防线(沙箱扫描 + autoload 检测/修复) * * W5 遗留批5(2026-09-20):从 src/gdscript-executor.ts 的 Sandbox scanner 段原样搬出 * (纯搬家零行为变化;gdscript-executor 保留 re-export 兼容存量消费方,新代码请直连本模块)。 * 涵盖:危险 API 模式扫描(scanGdscriptSandbox 三阶段)、字面量剥离(stripLiterals)、 * autoload 名称解析/孤儿 bridge 行修复/注入用法检测(detectAutoloadUsage)。 * * ⚠️ KNOWN LIMITATIONS — This scanner is a safety net against accidental misuse, * NOT a security boundary. GDScript is Turing-complete; regex cannot exhaustively * block indirect/reflection bypasses. For multi-user / untrusted input use * container/VM isolation + GODOT_MCP_ALLOW_UNSAFE=false. */ /** 转义正则元字符。用于 autoload 名称匹配。 */ export declare function escapeRegExp(str: string): string; /** @internal 测试用:重置缓存 */ export declare function _resetAutoloadCache(): void; /** * 从 project.godot 解析 autoload 单例名列表。 * 全面 try-catch:任何错误返回空数组。 */ export declare function parseAutoloadNames(projectPath: string): string[]; /** * 纯函数:project.godot 内容含 orphan bridge autoload 行时返回移除后的新内容,否则 null。 * (逻辑/IO 分离:纯字符串可稳定单测。注意键大小写——真实键为 MCPBridge(大写, * bridge-client.ts AUTOLOAD_KEY),首版实现与测试双双手误小写 McpBridge,错打正着 * 掩盖至审查 I-2 修正;键名常量必须 grep 写入方核对,不能信记忆/注释。) */ export declare function removeOrphanBridgeLines(content: string): string | null; /** * P2-4 (2026-09-11): orphan autoload 修复——project.godot 残留 McpBridge autoload 条目但 * 脚本本体已删(手删/卸载残留)时,每次 headless 操作都会因 autoload 加载失败而崩 * (来源 Erodenn bridge-manager.ts repairOrphaned 的前置自愈)。IO 壳:读→纯函数判定→原子写。 * 返回 true = 本次修复了(调用方 warn 留痕)。幂等:无 orphan 返回 false 零写入。 * 行为断言走纯函数 removeOrphanBridgeLines(本壳 IO 含 tmpdir 写盘,冒烟级覆盖)。 */ export declare function repairOrphanedBridgeAutoload(projectPath: string): boolean; /** * 检测代码中是否引用了 autoload 单例。 * A-2 (advisory): 改用 stripLiterals 骨架扫描(剥注释/字符串),消除原词边界匹配的误触发。 */ export declare function detectAutoloadUsage(code: string, autoloadNames: string[]): string[]; export declare function stripLiterals(code: string): string; /** @internal 测试用:重置 extra patterns 缓存 */ export declare function _resetExtraDangerousPatternsCache(): void; /** * 从环境变量 GODOT_MCP_EXTRA_DANGEROUS_PATTERNS 加载用户自定义危险正则。 * 格式:JSON 数组 [{"pattern": <正则源码>, "label": <人类可读标签>}, ...] * * memoized:以 raw 字符串为键,相同 env 不重复解析(风格同 _autoloadCache)。 * 坏正则/坏 JSON 降级:跳过该条或整体忽略,记录 warn,绝不抛异常。 */ export declare function loadExtraDangerousPatterns(): Array<{ pattern: RegExp; label: string; }>; export declare function scanGdscriptSandbox(code: string, opts?: { skipPhase3?: boolean; }): string[];