jackwener/OpenCLI · error · ArgumentError

--approve-kinds must contain only terminal, delete, keep, or

Error message

--approve-kinds must contain only terminal, delete, keep, or all

What it means

normalizeApprovalKinds parses the --approve-kinds option and accepts only 'terminal', 'delete', 'keep', or 'all'. The library throws this ArgumentError immediately when any list item falls outside that whitelist, before any automation runs, so bad CLI input fails fast.

Source

Thrown at clis/trae-cn/utils.js:81

  if (!Number.isInteger(interval) || interval < 1 || interval > 300) {
    throw new ArgumentError('--interval must be an integer between 1 and 300 seconds');
  }
  return interval;
}

export function normalizeApprovalKinds(value, fallback = TRAE_CN_APPROVAL_DEFAULT_KINDS.join(',')) {
  const raw = value === undefined || value === null || value === '' ? fallback : value;
  const parts = Array.isArray(raw) ? raw : String(raw).split(',');
  const expanded = [];
  for (const part of parts) {
    const item = String(part || '').trim().toLowerCase();
    if (!item) continue;
    if (item === 'all') {
      expanded.push('terminal', 'delete', 'keep');
      continue;
    }
    if (!['terminal', 'delete', 'keep'].includes(item)) {
      throw new ArgumentError('--approve-kinds must contain only terminal, delete, keep, or all');
    }
    expanded.push(item);
  }
  const unique = Array.from(new Set(expanded));
  if (unique.length === 0) {
    throw new ArgumentError('--approve-kinds must contain at least one approval kind');
  }
  return unique;
}

export function normalizeApprovalLimit(value, fallback = 1) {
  const limit = value === undefined || value === null ? fallback : Number(value);
  if (!Number.isInteger(limit) || limit < 1 || limit > 20) {
    throw new ArgumentError('--limit must be an integer between 1 and 20');
  }
  return limit;
}

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Replace the invalid kind with one of terminal, delete, keep
  2. Use 'all' to approve every supported kind at once
  3. Check the exact spelling, kinds are lowercase and singular

Example fix

// before
--approve-kinds terminal,exec
// after
--approve-kinds terminal,delete,keep
Defensive patterns

Strategy: validation

Validate before calling

const KINDS = ['terminal','delete','keep'];
const items = approveKinds.split(',').map(s => s.trim()).filter(Boolean);
const valid = items.every(i => i === 'all' || KINDS.includes(i));
if (!valid) throw new Error(`--approve-kinds must be one of ${[...KINDS,'all'].join(', ')}`);

Type guard

const isApprovalKind = (v) => ['terminal','delete','keep','all'].includes(v);

Try / catch

try { kinds = normalizeApprovalKinds(raw); } catch (e) { if (e instanceof ArgumentError) { console.error(e.message + ' (use: terminal, delete, keep, all)'); process.exitCode = 2; } else throw e; }

Prevention

When it happens

Trigger: Calling kinds/approvalKinds with --approve-kinds containing a misspelled or unsupported kind, e.g. 'termnal', 'bash', 'file-edit', or 'terminal,delete,exec'.

Common situations: Users copying --approve-kinds flags from a different tool's docs (e.g. Trae international vs Trae CN variants), or guessing kind names instead of using 'all'.

Understand the failure class

Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 libraries.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/6fb30b50d5bf49fe. Report an issue: GitHub.