{"record":{"id":"73e9c17bb3944688","repo":"JuliusBrussee/caveman","slug":"usage-invokedcommand-toon-encode-decode","errorCode":null,"errorMessage":"usage: ${invokedCommand(\"toon\")} encode|decode","messagePattern":"usage: (.+?) encode\\|decode","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/cli/src/index.ts","lineNumber":13362,"sourceCode":"    bytes_out: input.length,\n    ratio: 0,\n    basis: \"inferred\",\n    token_count_basis: \"unavailable\",\n    content_type: contentType || \"unknown\",\n    engine: \"missing\",\n    note: \"caveman-engine not installed — 0% compression, input passed through unchanged. Run `caveman setup` to see what's missing and how to install.\",\n  }));\n}\n\n// toonConvert shells out to `caveman-engine toon encode|decode` — the stateless,\n// CCR-free JSON⇄TOON converter (single source of truth in the engine, no JS\n// parser). It is the manual surface for the same transform the proxy applies at\n// the wire boundary; the converted output must not be fed back into the agent\n// that wrote the other form, or it would double the tokens it sees.\nasync function toonConvert(rest: string[]) {\n  const sub = rest[0];\n  if (sub !== \"encode\" && sub !== \"decode\") {\n    throw new Error(`usage: ${invokedCommand(\"toon\")} encode|decode`);\n  }\n  const input = await readStdin();\n  const bin = cavemanBin(\"caveman-engine\", \"CAVEMAN_ENGINE_BIN\");\n  let handled = false;\n  const child = spawn(bin, [\"toon\", sub], { stdio: [\"pipe\", \"inherit\", \"inherit\"] });\n  emitCommandRunOnce(\"ok\"); // exit handler below hard-exits; never returns to main()\n  child.on(\"error\", () => {\n    if (handled) return;\n    handled = true;\n    // encode degrades byte-safe: the input is still valid JSON, just not compacted.\n    // decode cannot be faked without the engine — emitting raw TOON as JSON would\n    // hand downstream a broken payload, so it fails loudly instead.\n    if (sub === \"encode\") {\n      // Not silent: the pass-through must announce itself so 0% can never be\n      // mistaken for \"TOON didn't help\".\n      console.error(`${mark(\"warn\")} caveman-engine not found — emitting input JSON unchanged (no TOON encoding); run \\`caveman setup\\` to see what's missing`);\n      process.stdout.write(input);\n      process.exit(0);","sourceCodeStart":13344,"sourceCodeEnd":13380,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/cli/src/index.ts#L13344-L13380","documentation":"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.","triggerScenarios":"`caveman toon` with no argument, or with an unrecognized subcommand like `caveman toon convert` or a typo such as `caveman toon encod`.","commonSituations":"Typos; assuming a 'convert' wrapper subcommand exists; piping without passing a subcommand in a script.","solutions":["Pass 'encode' or 'decode' explicitly: `caveman toon encode`","Check the subcommand spelling in the script","Quote/validate the subcommand variable in shell scripts before invoking"],"exampleFix":"// before\nSUB=convert; caveman toon $SUB < payload\n// after\nSUB=encode; caveman toon $SUB < payload","handlingStrategy":"validation","validationCode":"const sub = rest[0];\nif (sub !== 'encode' && sub !== 'decode') throw new Error('toon requires encode|decode');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate the subcommand variable in scripts before invoking","Remember the surface is only encode/decode — there is no 'convert' subcommand"],"tags":["cli","usage","toon"],"backgroundTag":"invalid-cli-argument","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}