import { t as Runner } from "./repo-DUJFsj72.mjs"; import { Context } from "@deepseek-ai/cordis"; //#region src/types.d.ts /** 文案语言: 默认 en; 'zh' 切中文; 可经 registerLocale 运行时扩展(保留字面量提示的宽字符串) */ type Locale = 'en' | 'zh' | (string & {}); /** wire 目标客户端枚举(dsh/pi 为进程内接入, 无 hook 文件, 仅输出接入引导) */ type ClientId = 'dsh' | 'claude' | 'codex' | 'opencode' | 'antigravity' | 'pi' | 'codebuddy' | 'zcode' | 'cursor'; //#endregion //#region src/i18n.d.ts /** 可插值变量(分支名/角色名等) */ type I18nVars = Record; /** 单一文案条目: (vars) => 最终文本 */ type Entry = (v: I18nVars) => string; /** 一门语言的文案字典: key 集合必须与内置 en 完全一致(registerLocale / 加载期校验) */ type Dict = Record; declare const MESSAGE_KEYS: readonly string[]; /** * 注册一门新语言(运行时扩展点, P2-2): key 集合必须与内置 en 完全一致, 否则抛英文异常。 * 注册后 makeT/resolveLocale 即接受该 locale; 未注册的 locale 一律回退英文。 */ declare function registerLocale(name: string, dict: Dict): void; //#endregion //#region src/pi.d.ts /** Pi 官方 tool_call 事件(只读提取, 与官方 ExtensionAPI 的 ToolCallEvent 对齐) */ interface PiToolCallEvent { toolName: string; input?: { command?: unknown; }; } /** Pi 扩展上下文最小面(官方 ExtensionContext 的 cwd/hasUI 子集) */ interface PiExtensionContext { cwd: string; hasUI?: boolean; } /** tool_call 拦截返回值: { block: true, reason } 即拒绝(官方 tool_call 协议) */ interface PiBlock { block: true; reason: string; } type PiToolCallResult = PiBlock | undefined; type PiToolCallHandler = (event: PiToolCallEvent, ctx: PiExtensionContext) => Promise | PiToolCallResult; interface PiExtensionAPI { on(event: 'tool_call', handler: PiToolCallHandler): void; } /** 命令执行结果(适配器与守卫 CLI 的进程间契约: 借用 claude 编码 exit 2 + stderr) */ interface PiRunResult { code: number; stdout: string; stderr: string; /** 子进程因超时被杀(区别于 spawn 失败): 必须按阻断处理, 不得 fail-open */ timedOut?: boolean; } interface PiExtensionOptions { /** 拦截哪些工具的命令文本(默认 bash / powershell, 与 DSH 插件 toolNames 同口径) */ toolNames?: string[]; /** 守卫 CLI 可执行(默认 GITFLOW_GUARD_BIN 环境变量 → gitflow-guard); 可为 [node, path] 形式 */ bin?: string | string[]; /** 命令执行器(测试注入; 默认真实 execFile) */ run?: (argv: string[], cwd: string) => Promise; } /** * 创建 Pi 扩展入口: 返回函数形态与官方扩展默认导出一致(default export (pi) => void)。 * 监听 tool_call → 提取 bash/powershell 的 command → 守卫 CLI 门禁 → deny 映射为 { block, reason }。 */ declare function createPiExtension(opts?: PiExtensionOptions): (pi: PiExtensionAPI) => void; //#endregion //#region src/wire.d.ts type WireScope = 'project' | 'global'; interface WireClientSpec { client: ClientId; /** 工程级相对路径(相对仓库根) */ projectPath: string; /** 全局绝对路径(写入前须显式确认) */ globalPath: () => string; /** 实验支持: 落位后需真机核验 */ experimental?: boolean; } declare function isWireClient(v: string): v is ClientId; /** 随包 runner 的绝对路径: 本模块开发态位于 /src/, 构建后位于 /lib/ —— 两种布局下 * ../bin/gitflow-guard.mjs 均指向随包 runner(与 OPENCODE_PLUGIN_SOURCE 同一手法)。 */ declare function resolveRunnerPath(): string; type JsonWireClient = 'claude' | 'codex' | 'antigravity' | 'codebuddy' | 'zcode' | 'cursor'; /** 钩子命令形态: node check --platform 。 * 路径统一正斜杠(node 与各家 shell 在 Windows 均接受, 且免 JSON 反斜杠转义), 含空白时加双引号。 * 仅接受常规安装路径(不含 shell 元字符): npm 全局/项目 node_modules 布局的磁盘路径天然满足。 */ declare function guardCommand(runnerPath: string, client: JsonWireClient): string; /** 各客户端的 hook 落位规格(dsh/pi 无 hook 文件, 仅输出接入引导) * opencode: OpenCode 1.18+ 已废弃 hooks.yaml(实机零调用, 见 docs/e2e/TestResult/opencode.md), * 官方扩展点为 plugins 目录 —— wire 把随包插件 opencode/gitflow-guard.ts 复制到插件目录。 */ declare const WIRE_CLIENTS: ReadonlyArray; type WireResult = 'added' | 'migrated' | 'exists' | 'removed' | 'absent'; /** 执行一次 wire 落位/移除/预览; dsh/pi 由上层直接短路, 不进这里。 * 真实写入 JSON 客户端前自检随包 runner 真实存在 —— 杜绝把死指针写进用户配置(静默 MODULE_NOT_FOUND)。 */ declare function applyWire(client: ClientId, path: string, unwire: boolean, dryRun: boolean, deps?: { runnerExists?: (p: string) => boolean; }): Promise; type WiringState = 'current' | 'legacy' | 'absent'; /** 只读探测接线版本状态: current=canonical 条目在位; legacy=存在任意历史形态条目(status 提示重新 wire 迁移); * absent=无本插件条目(或配置不可解析, 决策保守)。 */ declare function wiringState(client: ClientId, path: string): Promise; /** 只读探测: 该客户端是否已接线为当前 canonical 形态(opencode 判插件文件存在; JSON 客户端按命令精确匹配) */ declare function isWired(client: ClientId, path: string): Promise; //#endregion //#region src/index.d.ts declare const name = "gitflow-guard"; interface PluginConfig { /** 拦截哪些工具的命令文本(默认 pwsh / bash) */ toolNames?: string[]; /** 命令执行器(测试注入; 默认真实 git) */ runner?: Runner; } interface EvaluateOptions { repoRoot: string; runner?: Runner; /** GitHub gh 适配器执行器(测试注入; 默认真实 gh) */ ghRunner?: Runner; /** GitLab glab 适配器执行器(测试注入; 默认真实 glab) */ glabRunner?: Runner; /** 当前分支(缺省时内部查询) */ currentBranch?: string | null; /** 覆盖文案 locale(CLI --locale 旗标用, P2-1); 缺省按项目 config.locale 解析 */ locale?: Locale; } interface EvaluateResult { outcome: 'allow' | 'deny' | 'skipped'; reason?: { why: string; next: string; }; segmentCount: number; /** 本次评估使用的文案语言(供 formatDeny/审计一致) */ locale: Locale; } interface AuditEntry { time: number; event: 'deny' | 'ci'; command?: string; role?: string; reason?: string; } /** * 用户级运行时状态根目录(仓库外): macOS/Linux 走 XDG state, Windows 走 %LOCALAPPDATA%。 * GITFLOW_GUARD_STATE_ROOT 显式覆盖所有平台默认值(测试/特殊部署用)。 */ declare function userStateRoot(): string; /** * 仓库运行时状态目录(审计流水等), 键为「仓库名-真实路径哈希」。 * 键由 git 权威解析(rev-parse --git-common-dir): linked worktree 与主仓库共用 * 同一状态目录(≤0.0.13 共享语义), 且天然规避 Windows 8.3 短名/大小写差异; * git 查询不可用时回退 fs realpath。刻意放在仓库外、且在 agent 文件沙箱 * (workspace-write)可写区之外 —— 凡 agent 可写之处的状态都可能被伪造而自我授权。 */ declare function stateDir(repoRoot: string, runner?: Runner): Promise; /** 审计留痕; 失败不阻断门禁 */ declare function appendAudit(repoRoot: string, entry: AuditEntry, runner?: Runner): Promise; /** 解析一条命令: 分类 → git 事实 → 门禁 → allow/deny */ declare function evaluateCommand(command: string, opts: EvaluateOptions): Promise; declare function formatDeny(locale: Locale, why: string, next: string): string; declare function apply(ctx: Context, pluginConfig?: PluginConfig): void; //#endregion export { AuditEntry, type Dict, EvaluateOptions, EvaluateResult, MESSAGE_KEYS, type PiExtensionAPI, type PiExtensionContext, type PiExtensionOptions, type PiToolCallEvent, type PiToolCallResult, PluginConfig, WIRE_CLIENTS, type WireClientSpec, type WireResult, type WireScope, type WiringState, appendAudit, apply, applyWire, createPiExtension, evaluateCommand, formatDeny, guardCommand, isWireClient, isWired, name, registerLocale, resolveRunnerPath, stateDir, userStateRoot, wiringState };