/** * command-meta — 给 commander Command 实例附加 adapter-facing 元数据。 * * 用 WeakMap 而不是在 Command 上加属性,避免污染 commander 类型 + 自动 GC。 * 此文件**不感知具体适配器**;它只是约定一组字段,由 adapter 决定如何用。 * * 当前消费者:`src/commands/_schema.ts` 把 meta 写进输出, * `openclaw-clawclaw` 适配器读 meta 决定: * · requiresConfirm → 自动给工具加 `confirm:boolean` 必填参数 * · longRunning + timeoutMs → 拉长 spawn timeout * · sensitive → 在工具 description 加 ⚠️ 警示 */ import type { Command } from 'commander'; export interface CommandMeta { /** Adapter should add a mandatory `confirm: true` parameter before invocation. */ requiresConfirm?: boolean; /** Adapter should expect this command to block; pair with `timeoutMs`. */ longRunning?: boolean; /** Semantic flag: writes credentials / consumes quotas / etc. */ sensitive?: boolean; /** Adapter should use this timeout (ms) for spawn instead of default. */ timeoutMs?: number; } const META = new WeakMap(); export function setMeta(cmd: Command, meta: CommandMeta): Command { const existing = META.get(cmd) ?? {}; META.set(cmd, { ...existing, ...meta }); return cmd; } export function getMeta(cmd: Command): CommandMeta | undefined { return META.get(cmd); }