JuliusBrussee/caveman · warning

usage: encode|decode

Error message

usage: ${invokedCommand("toon")} encode|decode

What it means

Fires when the `toon` CLI command is invoked without a valid subcommand. `toon` is not a standalone action: it shells out to `caveman-engine toon` and requires exactly one of `encode` (JSON to TOON) or `decode` (TOON to JSON). This is a generic argument guard at the command dispatcher: the argv after `toon` is empty or not one of the two accepted subcommands, so the usage line is emitted instead of running the conversion.

Solutions

  1. Pass 'encode' or 'decode' explicitly: `caveman toon encode`
  2. Check the subcommand spelling in the script
  3. Quote/validate the subcommand variable in shell scripts before invoking

Example fix

// before
SUB=convert; caveman toon $SUB < payload
// after
SUB=encode; caveman toon $SUB < payload
Defensive patterns

Strategy: validation

Validate before calling

const sub = rest[0];
if (sub !== 'encode' && sub !== 'decode') throw new Error('toon requires encode|decode');

Prevention

When it happens

Trigger: `caveman toon` with no argument, or with an unrecognized subcommand like `caveman toon convert` or a typo such as `caveman toon encod`.

Common situations: Typos; assuming a 'convert' wrapper subcommand exists; piping without passing a subcommand in a script.

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 JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/73e9c17bb3944688. Report an issue: GitHub.

Appendix: source

Thrown at packages/cli/src/index.ts:13362

    bytes_out: input.length,
    ratio: 0,
    basis: "inferred",
    token_count_basis: "unavailable",
    content_type: contentType || "unknown",
    engine: "missing",
    note: "caveman-engine not installed — 0% compression, input passed through unchanged. Run `caveman setup` to see what's missing and how to install.",
  }));
}

// toonConvert shells out to `caveman-engine toon encode|decode` — the stateless,
// CCR-free JSON⇄TOON converter (single source of truth in the engine, no JS
// parser). It is the manual surface for the same transform the proxy applies at
// the wire boundary; the converted output must not be fed back into the agent
// that wrote the other form, or it would double the tokens it sees.
async function toonConvert(rest: string[]) {
  const sub = rest[0];
  if (sub !== "encode" && sub !== "decode") {
    throw new Error(`usage: ${invokedCommand("toon")} encode|decode`);
  }
  const input = await readStdin();
  const bin = cavemanBin("caveman-engine", "CAVEMAN_ENGINE_BIN");
  let handled = false;
  const child = spawn(bin, ["toon", sub], { stdio: ["pipe", "inherit", "inherit"] });
  emitCommandRunOnce("ok"); // exit handler below hard-exits; never returns to main()
  child.on("error", () => {
    if (handled) return;
    handled = true;
    // encode degrades byte-safe: the input is still valid JSON, just not compacted.
    // decode cannot be faked without the engine — emitting raw TOON as JSON would
    // hand downstream a broken payload, so it fails loudly instead.
    if (sub === "encode") {
      // Not silent: the pass-through must announce itself so 0% can never be
      // mistaken for "TOON didn't help".
      console.error(`${mark("warn")} caveman-engine not found — emitting input JSON unchanged (no TOON encoding); run \`caveman setup\` to see what's missing`);
      process.stdout.write(input);
      process.exit(0);

View on GitHub (pinned to 3ee70a1026)