@koda-sl/baker-cli 0.344.0 → 0.345.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -118,12 +118,14 @@ Use `--output` to change format:
118
118
 
119
119
  | Format | Description | Best for | Available on |
120
120
  |---------|------------------------------------|--------------------|--------------|
121
- | `json` | Structured JSON envelope (default) | AI agents | every command |
122
- | `files` | Tab-separated, one row per result | Piping / shell | every command |
123
- | `md` | Markdown table | Human reading | every command |
121
+ | `json` | Structured JSON envelope (default) | AI agents | every command that prints the envelope |
122
+ | `files` | Tab-separated, one row per result | Piping / shell | commands whose `baker schema` lists `output` |
123
+ | `md` | Markdown table | Human reading | commands whose `baker schema` lists `output` |
124
124
  | `csv` | RFC 4180 comma-separated values | Analysis tools | `baker research …` only |
125
125
  | `jsonl` | One JSON object per line | Streaming/appending | `baker research …` only |
126
126
 
127
+ `--output json` is accepted even by a command that declares no `--output`: the envelope is already what it prints, and on a command whose default is a readable view (`baker tags list`, the `draft` commands) it becomes that command's `--json`. The few commands that print only text — `baker analytics sending-events`, `baker canvas run` and `rerun` — refuse it, as a command without its own `--output` refuses `md` and `files`.
128
+
127
129
  `csv` and `jsonl` are implemented by the research family alone. Asking any other command for them — or for a format that does not exist — falls back to the JSON envelope and says so on stderr, rather than printing nothing and exiting 0.
128
130
 
129
131
  `files` and `md` print rows and nothing else, so any `hints` or data-quality note the envelope carries is written to **stderr** instead. Reading stdout alone still gives you clean, parseable rows.
package/dist/cli.js CHANGED
@@ -67693,6 +67693,7 @@ function commandFor(root, argv) {
67693
67693
  const { command, resolved } = resolveCommand2(root, argv);
67694
67694
  return resolved ? command : null;
67695
67695
  }
67696
+ var OUTPUT_EXPLANATION = "This command has no --output option: `--output json` is accepted by every command that prints the JSON envelope, and md or files only where `baker schema` lists `output`. Drop the option and read the default output. ";
67696
67697
  function unknownFlagEnvelope(unknown, commandPath, suggestion, hasSchema) {
67697
67698
  const list = unknown.join(", ");
67698
67699
  return {
@@ -67702,7 +67703,7 @@ function unknownFlagEnvelope(unknown, commandPath, suggestion, hasSchema) {
67702
67703
  message: `${list} ${unknown.length > 1 ? "are not options" : "is not an option"} of \`baker ${commandPath}\`.`,
67703
67704
  fix: {
67704
67705
  action: hasSchema ? "check_schema" : "check_help",
67705
- explanation: (suggestion ? `Did you mean ${suggestion}? ` : "") + `Run \`${hasSchema ? `baker schema ${commandPath}` : `baker ${commandPath} --help`}\` to see every option this command takes. Do not re-run the same call: until this version an unrecognised option was accepted and ignored, so a command that looked like it had filtered or narrowed the result was in fact answering the unfiltered question.`
67706
+ explanation: (unknown.some((flag) => flag === "--output" || flag.startsWith("--output=")) ? OUTPUT_EXPLANATION : "") + (suggestion ? `Did you mean ${suggestion}? ` : "") + `Run \`${hasSchema ? `baker schema ${commandPath}` : `baker ${commandPath} --help`}\` to see every option this command takes. Do not re-run the same call: until this version an unrecognised option was accepted and ignored, so a command that looked like it had filtered or narrowed the result was in fact answering the unfiltered question.`
67706
67707
  },
67707
67708
  retryable: false
67708
67709
  }
@@ -67741,6 +67742,58 @@ function refuseUnknownFlags(root, argv) {
67741
67742
  process.exit(1);
67742
67743
  }
67743
67744
 
67745
+ // src/output-flag.ts
67746
+ var FLAG = "--output";
67747
+ var ENVELOPE = "json";
67748
+ var PRINTS_NO_ENVELOPE = /* @__PURE__ */ new Set([
67749
+ "analytics sending-events",
67750
+ "canvas run",
67751
+ "canvas rerun",
67752
+ "canvas sync-definition"
67753
+ ]);
67754
+ function declaredArg(command, name) {
67755
+ const args5 = command.args;
67756
+ if (!args5 || typeof args5 !== "object" || !(name in args5)) {
67757
+ return null;
67758
+ }
67759
+ const def = args5[name];
67760
+ return def && typeof def === "object" ? def : {};
67761
+ }
67762
+ function envelopeRequests(argv) {
67763
+ const end = argv.indexOf("--");
67764
+ const limit = end === -1 ? argv.length : end;
67765
+ const found = [];
67766
+ for (let index = 0; index < limit; index++) {
67767
+ const token = argv[index];
67768
+ if (token === `${FLAG}=${ENVELOPE}`) {
67769
+ found.push({ index, length: 1 });
67770
+ } else if (token === FLAG && argv[index + 1] === ENVELOPE && index + 1 < limit) {
67771
+ found.push({ index, length: 2 });
67772
+ index++;
67773
+ }
67774
+ }
67775
+ return found;
67776
+ }
67777
+ function outputFlagForCommand(root, argv) {
67778
+ const requests = envelopeRequests(argv);
67779
+ if (requests.length === 0) {
67780
+ return argv;
67781
+ }
67782
+ const command = commandFor(root, argv);
67783
+ if (!command || declaredArg(command, "output") || PRINTS_NO_ENVELOPE.has(commandPathOf(root, argv))) {
67784
+ return argv;
67785
+ }
67786
+ const jsonSwitch = declaredArg(command, "json")?.type === "boolean";
67787
+ const dropped = new Set(requests.flatMap(({ index, length }) => length === 2 ? [index, index + 1] : [index]));
67788
+ const first = requests[0]?.index;
67789
+ return argv.flatMap((token, index) => {
67790
+ if (!dropped.has(index)) {
67791
+ return [token];
67792
+ }
67793
+ return jsonSwitch && index === first ? ["--json"] : [];
67794
+ });
67795
+ }
67796
+
67744
67797
  // src/version.ts
67745
67798
  import { readFileSync as readFileSync21 } from "fs";
67746
67799
  function packageJsonUrl() {
@@ -67767,7 +67820,7 @@ var main = defineCommand245({
67767
67820
  Auth: Set BAKER_API_KEY (starts with bk_) and BAKER_API_URL environment variables.
67768
67821
  Chat: Set BAKER_CHAT_ID for action and scheduled-action commands that stage changes against a chat.
67769
67822
  Output: All commands return JSON envelopes: { ok: true, data: ... } or { ok: false, error: { code, message } }.
67770
- Formats: Use --output json|files|md to control output format. Default: json. (The research commands additionally accept csv and jsonl.)
67823
+ Formats: --output json works on every command that prints the envelope. --output md|files only where 'baker schema <command>' lists output. (The research commands additionally accept csv and jsonl.)
67771
67824
  Introspection: Run 'baker schema <command>' to inspect argument schemas.`
67772
67825
  },
67773
67826
  subCommands: {
@@ -67805,6 +67858,7 @@ process.argv = [...process.argv.slice(0, 2), ...normalizeCacheFlag(process.argv.
67805
67858
  installStreamTaps();
67806
67859
  logInvocation(process.argv.slice(2));
67807
67860
  installExitRecord();
67861
+ process.argv = [...process.argv.slice(0, 2), ...outputFlagForCommand(main, process.argv.slice(2))];
67808
67862
  refuseUnknownFlags(main, process.argv.slice(2));
67809
67863
  process.argv = [...process.argv.slice(0, 2), ...cacheFlagForParser(process.argv.slice(2))];
67810
67864
  runMain(main);