koala73/worldmonitor · error · Error

Use --plan, --check, or --apply

Error message

Use --plan, --check, or --apply

What it means

runAgentReadiness only accepts one of three CLI modes: --plan, --check, or --apply. It throws immediately when mode is anything else, before resolving the token or contacting Cloudflare. This is the entry-point argument validation for the readiness script.

Solutions

  1. Run the script with exactly one of: --plan, --check, or --apply.
  2. Check for typos or extra arguments after the mode flag.
  3. If calling runAgentReadiness from code, pass the literal flag string (e.g. runAgentReadiness('--check')).

Example fix

// before
node scripts/cloudflare-agent-readiness.mjs --chek
// after
node scripts/cloudflare-agent-readiness.mjs --check
Defensive patterns

Strategy: validation

Validate before calling

const mode = process.argv[2];
if (!['--plan', '--check', '--apply'].includes(mode)) {
  console.error('usage: node scripts/cloudflare-agent-readiness.mjs <--plan|--check|--apply>');
  process.exit(2);
}
runAgentReadiness(mode);

Type guard

function isValidMode(mode) {
  return mode === '--plan' || mode === '--check' || mode === '--apply';
}

Try / catch

try {
  await runAgentReadiness(mode);
} catch (e) {
  if (e.message === 'Use --plan, --check, or --apply') {
    console.error('usage: cloudflare-agent-readiness <--plan|--check|--apply>');
    process.exit(2);
  }
  throw e;
}

Prevention

When it happens

Trigger: Invoking the script with no mode (undefined), a misspelled flag like --plane or -plan, or an extra/unexpected argv value.

Common situations: Typo in the flag when running node scripts/cloudflare-agent-readiness.mjs, calling the exported function programmatically with the wrong argument, or omitting the mode entirely.

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 koala73/worldmonitor@7d06c8633d (2026-09-15). Data as JSON: /api/errors/18418c899a716212. Report an issue: GitHub.

Appendix: source

Thrown at scripts/cloudflare-agent-readiness.mjs:46

      content_type: 'application/json',
      content: JSON.stringify(policy.blockedResponse),
    };
    if (!isDeepStrictEqual(rule.action_parameters?.response, response)) {
      const definition = Object.fromEntries(Object.entries(rule).filter(([key]) =>
        !['id', 'version', 'last_updated'].includes(key)));
      changes.push({
        phase: FIREWALL_PHASE, rulesetId: firewall.id, ruleId: rule.id,
        description, method: 'PATCH',
        body: { ...definition, action_parameters: { ...rule.action_parameters, response } },
      });
    }
  }

  return changes;
}

export async function runAgentReadiness(mode, { env = process.env, fetchImpl } = {}) {
  if (!['--plan', '--check', '--apply'].includes(mode)) throw new Error('Use --plan, --check, or --apply');
  const token = resolveToken(env);
  const zoneId = await resolveZoneId(token, { env, fetchImpl });
  const read = (phase) => cloudflareRequest(`/zones/${zoneId}/rulesets/phases/${phase}/entrypoint`, { token, fetchImpl });
  const firewall = await read(FIREWALL_PHASE);
  const changes = planAgentReadiness(firewall);
  if (mode !== '--apply' || changes.length === 0) return { zone: 'worldmonitor.app', ready: changes.length === 0, changes };

  for (const change of changes) {
    const current = await read(change.phase);
    if (!isDeepStrictEqual(current.rules, firewall.rules)) {
      throw new Error('Cloudflare rules changed after planning. Run --plan again before applying.');
    }
    const updated = await cloudflareRequest(`/zones/${zoneId}/rulesets/${change.rulesetId}/rules/${change.ruleId}`, {
      token, fetchImpl, method: change.method, body: change.body,
    });
    firewall.rules = updated.rules;
  }
  const remaining = planAgentReadiness(await read(FIREWALL_PHASE));

View on GitHub (pinned to 7d06c8633d)