@koda-sl/baker-cli 0.343.0-dev.c28f2e0b3 → 0.344.0-dev.1f4f1c4b7

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
@@ -17114,9 +17114,21 @@ function parseCopyList(value, flag) {
17114
17114
  function copyListFlag(value, flag) {
17115
17115
  return parseCopyList(value, flag)?.map((item) => item.text);
17116
17116
  }
17117
+ function refuseDashLedValue(rawArgs, flag) {
17118
+ for (let i = 0; i < rawArgs.length - 1; i++) {
17119
+ if (rawArgs[i] === "--") return;
17120
+ const value = rawArgs[i + 1];
17121
+ if (rawArgs[i] === `--${flag}` && value?.startsWith("-")) {
17122
+ failWriteValidation(
17123
+ `--${flag} is followed by "${value}", which starts with a dash and is read as another flag, not as copy. Join copy that starts with a dash to its flag with =: --${flag}="${value}"`
17124
+ );
17125
+ }
17126
+ }
17127
+ }
17117
17128
  function withRepeatedCopyFlags(args5, rawArgs) {
17118
17129
  const out = { ...args5 };
17119
17130
  for (const flag of AD_COPY_LIST_FLAGS) {
17131
+ refuseDashLedValue(rawArgs ?? [], flag);
17120
17132
  const values = repeatedFlagValues(rawArgs ?? [], flag);
17121
17133
  if (values.length > 1) {
17122
17134
  out[flag] = values;
@@ -67681,6 +67693,7 @@ function commandFor(root, argv) {
67681
67693
  const { command, resolved } = resolveCommand2(root, argv);
67682
67694
  return resolved ? command : null;
67683
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. ";
67684
67697
  function unknownFlagEnvelope(unknown, commandPath, suggestion, hasSchema) {
67685
67698
  const list = unknown.join(", ");
67686
67699
  return {
@@ -67690,7 +67703,7 @@ function unknownFlagEnvelope(unknown, commandPath, suggestion, hasSchema) {
67690
67703
  message: `${list} ${unknown.length > 1 ? "are not options" : "is not an option"} of \`baker ${commandPath}\`.`,
67691
67704
  fix: {
67692
67705
  action: hasSchema ? "check_schema" : "check_help",
67693
- 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.`
67694
67707
  },
67695
67708
  retryable: false
67696
67709
  }
@@ -67729,6 +67742,53 @@ function refuseUnknownFlags(root, argv) {
67729
67742
  process.exit(1);
67730
67743
  }
67731
67744
 
67745
+ // src/output-flag.ts
67746
+ var FLAG = "--output";
67747
+ var ENVELOPE = "json";
67748
+ var PRINTS_NO_ENVELOPE = /* @__PURE__ */ new Set(["analytics sending-events", "canvas run", "canvas rerun", "canvas sync-definition"]);
67749
+ function declaredArg(command, name) {
67750
+ const args5 = command.args;
67751
+ if (!args5 || typeof args5 !== "object" || !(name in args5)) {
67752
+ return null;
67753
+ }
67754
+ const def = args5[name];
67755
+ return def && typeof def === "object" ? def : {};
67756
+ }
67757
+ function envelopeRequests(argv) {
67758
+ const end = argv.indexOf("--");
67759
+ const limit = end === -1 ? argv.length : end;
67760
+ const found = [];
67761
+ for (let index = 0; index < limit; index++) {
67762
+ const token = argv[index];
67763
+ if (token === `${FLAG}=${ENVELOPE}`) {
67764
+ found.push({ index, length: 1 });
67765
+ } else if (token === FLAG && argv[index + 1] === ENVELOPE && index + 1 < limit) {
67766
+ found.push({ index, length: 2 });
67767
+ index++;
67768
+ }
67769
+ }
67770
+ return found;
67771
+ }
67772
+ function outputFlagForCommand(root, argv) {
67773
+ const requests = envelopeRequests(argv);
67774
+ if (requests.length === 0) {
67775
+ return argv;
67776
+ }
67777
+ const command = commandFor(root, argv);
67778
+ if (!command || declaredArg(command, "output") || PRINTS_NO_ENVELOPE.has(commandPathOf(root, argv))) {
67779
+ return argv;
67780
+ }
67781
+ const jsonSwitch = declaredArg(command, "json")?.type === "boolean";
67782
+ const dropped = new Set(requests.flatMap(({ index, length }) => length === 2 ? [index, index + 1] : [index]));
67783
+ const first = requests[0]?.index;
67784
+ return argv.flatMap((token, index) => {
67785
+ if (!dropped.has(index)) {
67786
+ return [token];
67787
+ }
67788
+ return jsonSwitch && index === first ? ["--json"] : [];
67789
+ });
67790
+ }
67791
+
67732
67792
  // src/version.ts
67733
67793
  import { readFileSync as readFileSync21 } from "fs";
67734
67794
  function packageJsonUrl() {
@@ -67755,7 +67815,7 @@ var main = defineCommand245({
67755
67815
  Auth: Set BAKER_API_KEY (starts with bk_) and BAKER_API_URL environment variables.
67756
67816
  Chat: Set BAKER_CHAT_ID for action and scheduled-action commands that stage changes against a chat.
67757
67817
  Output: All commands return JSON envelopes: { ok: true, data: ... } or { ok: false, error: { code, message } }.
67758
- Formats: Use --output json|files|md to control output format. Default: json. (The research commands additionally accept csv and jsonl.)
67818
+ 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.)
67759
67819
  Introspection: Run 'baker schema <command>' to inspect argument schemas.`
67760
67820
  },
67761
67821
  subCommands: {
@@ -67793,6 +67853,7 @@ process.argv = [...process.argv.slice(0, 2), ...normalizeCacheFlag(process.argv.
67793
67853
  installStreamTaps();
67794
67854
  logInvocation(process.argv.slice(2));
67795
67855
  installExitRecord();
67856
+ process.argv = [...process.argv.slice(0, 2), ...outputFlagForCommand(main, process.argv.slice(2))];
67796
67857
  refuseUnknownFlags(main, process.argv.slice(2));
67797
67858
  process.argv = [...process.argv.slice(0, 2), ...cacheFlagForParser(process.argv.slice(2))];
67798
67859
  runMain(main);