buddy-agent-harness 0.20.0 → 0.21.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/dist/cli.mjs CHANGED
@@ -6,6 +6,8 @@ import { fileURLToPath, pathToFileURL } from "node:url";
6
6
  import { homedir, platform } from "node:os";
7
7
  import { readFile, readdir } from "node:fs/promises";
8
8
  import { execFileSync } from "node:child_process";
9
+ //#region ../../node_modules/.pnpm/clibuilder@11.3.0_typescript@7.0.2/node_modules/clibuilder/esm/app/errors.js
10
+ var _a;
9
11
  /**
10
12
  * The exit codes a clibuilder cli uses.
11
13
  *
@@ -31,6 +33,37 @@ const exitCodes = {
31
33
  usage: 2
32
34
  };
33
35
  const cliErrorBrand = Symbol.for("clibuilder.CliError");
36
+ /**
37
+ * Throw this from a command's `run()` to fail the cli.
38
+ *
39
+ * The message and the help lines are printed through the command's `ui`,
40
+ * and the cli exits with `exitCode`. `parse()` resolves to that `exitCode`
41
+ * instead of rejecting, so the failure is reported rather than surfacing
42
+ * as an unhandled rejection with a stack trace.
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * run({ field }) {
47
+ * if (!fields.includes(field)) {
48
+ * throw new CliError(`unknown field "${field}"`, {
49
+ * exitCode: exitCodes.usage,
50
+ * help: `valid fields: ${fields.join(', ')}`
51
+ * })
52
+ * }
53
+ * }
54
+ * ```
55
+ */
56
+ var CliError = class extends Error {
57
+ constructor(message, options) {
58
+ super(message);
59
+ this.name = "CliError";
60
+ this[_a] = true;
61
+ this.exitCode = options?.exitCode ?? exitCodes.error;
62
+ this.help = options?.help === void 0 ? [] : Array.isArray(options.help) ? options.help : [options.help];
63
+ this.cause = options?.cause;
64
+ }
65
+ };
66
+ _a = cliErrorBrand;
34
67
  function isCliError(err) {
35
68
  return !!err && typeof err === "object" && err[cliErrorBrand] === true;
36
69
  }
@@ -9847,7 +9880,7 @@ function getBaseCommand(description, options) {
9847
9880
  * The `--format` option, declared once so every command that reports a collection
9848
9881
  * offers the same three values, the same wording, and the same default.
9849
9882
  */
9850
- const formatOption$1 = {
9883
+ const formatOption$3 = {
9851
9884
  type: optionalType(enumType([
9852
9885
  "toon",
9853
9886
  "text",
@@ -9929,7 +9962,7 @@ const listPluginsCommand = command({
9929
9962
  name: "list",
9930
9963
  alias: ["ls"],
9931
9964
  description: "List installed plugins",
9932
- options: { format: formatOption$1 },
9965
+ options: { format: formatOption$3 },
9933
9966
  context: { findByKeywords },
9934
9967
  async run(args) {
9935
9968
  const plugins = await this.context.findByKeywords(this.keywords, this);
@@ -9971,7 +10004,7 @@ const searchPluginsCommand = command({
9971
10004
  name: "search",
9972
10005
  description: "Search only for available plugins",
9973
10006
  options: {
9974
- format: formatOption$1,
10007
+ format: formatOption$3,
9975
10008
  fields: {
9976
10009
  type: optionalType(stringType()),
9977
10010
  description: "Extra fields to report, comma separated. Only 'keywords' is available"
@@ -14052,18 +14085,18 @@ function createRegistry() {
14052
14085
  */
14053
14086
  function formatLookupError(error, command) {
14054
14087
  switch (error.type) {
14055
- case "invalid-key": return `unknown option ${formatOption(error.key)}`;
14088
+ case "invalid-key": return `unknown option ${formatOption$2(error.key)}`;
14056
14089
  case "missing-argument": return `missing required argument <${error.name}>`;
14057
14090
  case "extra-arguments": return `unexpected argument${error.values.length > 1 ? "s" : ""}: ${error.values.join(", ")}`;
14058
14091
  case "invalid-value": return `invalid value for ${formatKey(error.key, command)}: ${error.message}, received "${error.value}"`;
14059
- case "conflicting-options": return `option ${formatOption(error.key)} cannot be used with option ${formatOption(error.conflictsWith)}`;
14092
+ case "conflicting-options": return `option ${formatOption$2(error.key)} cannot be used with option ${formatOption$2(error.conflictsWith)}`;
14060
14093
  case "expect-single": return `${formatKey(error.key, command)} expects a single value, received: ${toArray(error.value).join(", ")}`;
14061
14094
  }
14062
14095
  }
14063
14096
  function formatKey(key, command) {
14064
- return command.arguments?.some((a) => a.name === key) ? `argument <${key}>` : `option ${formatOption(key)}`;
14097
+ return command.arguments?.some((a) => a.name === key) ? `argument <${key}>` : `option ${formatOption$2(key)}`;
14065
14098
  }
14066
- function formatOption(key) {
14099
+ function formatOption$2(key) {
14067
14100
  return key.length === 1 ? `-${key}` : `--${key}`;
14068
14101
  }
14069
14102
  function toArray(value) {
@@ -15479,6 +15512,80 @@ function cli(options) {
15479
15512
  return builder(context(), options);
15480
15513
  }
15481
15514
  //#endregion
15515
+ //#region ../../node_modules/.pnpm/@clibuilder+axi@0.2.0_clibuilder@11.3.0_typescript@7.0.2_/node_modules/@clibuilder/axi/esm/help.js
15516
+ /** Normalizes {@link Help} to a list, empty when there is nothing to suggest. */
15517
+ function helpLines(help) {
15518
+ if (help === void 0) return [];
15519
+ return typeof help === "string" ? [help] : [...help];
15520
+ }
15521
+ /**
15522
+ * Appends the next-step suggestions to a result under `help`, last so they read after the answer.
15523
+ * Returns the value unchanged when there is nothing to suggest — a self-contained answer carries no
15524
+ * hint.
15525
+ */
15526
+ function withHelp(value, help) {
15527
+ const lines = helpLines(help);
15528
+ if (lines.length === 0) return value;
15529
+ const { help: _, ...rest } = value;
15530
+ return {
15531
+ ...rest,
15532
+ help: lines
15533
+ };
15534
+ }
15535
+ //#endregion
15536
+ //#region ../../node_modules/.pnpm/@clibuilder+axi@0.2.0_clibuilder@11.3.0_typescript@7.0.2_/node_modules/@clibuilder/axi/esm/error.js
15537
+ /**
15538
+ * The error as a value: `error`, `code`, any details, then `help`, flat so it reads the same in
15539
+ * every format — `error: ...` / `code: ...` / `help[1]: ...` in TOON.
15540
+ */
15541
+ function errorOutput(report) {
15542
+ const output = {
15543
+ error: report.message,
15544
+ code: report.code,
15545
+ ...report.details
15546
+ };
15547
+ const help = helpLines(report.help);
15548
+ if (help.length > 0) output.help = help;
15549
+ return output;
15550
+ }
15551
+ //#endregion
15552
+ //#region ../../node_modules/.pnpm/@clibuilder+axi@0.2.0_clibuilder@11.3.0_typescript@7.0.2_/node_modules/@clibuilder/axi/esm/format.js
15553
+ /** Every supported format, the default first. */
15554
+ const formats$1 = [
15555
+ "toon",
15556
+ "json",
15557
+ "text"
15558
+ ];
15559
+ /**
15560
+ * Declares a `--format` option for a command whose default or wording differs from
15561
+ * {@link formatOption} — for example one whose `text` output is a document a person reads.
15562
+ *
15563
+ * @example
15564
+ * ```ts
15565
+ * options: { format: defineFormatOption({ default: 'text' }) }
15566
+ * ```
15567
+ */
15568
+ function defineFormatOption$1(options = {}) {
15569
+ const defaultFormat = options.default ?? "toon";
15570
+ return {
15571
+ type: optionalType(enumType(formats$1)),
15572
+ description: options.description ?? `Output format: ${formats$1.map((f) => f === defaultFormat ? `${f} (default)` : f).join(", ")} — toon for agents, json to pipe, text for humans`,
15573
+ default: defaultFormat
15574
+ };
15575
+ }
15576
+ /**
15577
+ * The `--format` option, declared once so every agent-facing command offers the same three
15578
+ * values, the same wording, and the same default. Spread it into a command's `options`:
15579
+ *
15580
+ * @example
15581
+ * ```ts
15582
+ * options: { format: formatOption }
15583
+ * ```
15584
+ *
15585
+ * An unknown value is a usage error (exit code 2), reported by clibuilder before `run` is called.
15586
+ */
15587
+ const formatOption$1 = defineFormatOption$1();
15588
+ //#endregion
15482
15589
  //#region ../../node_modules/.pnpm/@toon-format+toon@4.1.1/node_modules/@toon-format/toon/dist/index.mjs
15483
15590
  const NULL_LITERAL = "null";
15484
15591
  const DELIMITERS = {
@@ -16027,37 +16134,10 @@ function resolveOptions(options) {
16027
16134
  };
16028
16135
  }
16029
16136
  //#endregion
16030
- //#region src/is-record/is-record.ts
16031
- function isRecord$1(value) {
16137
+ //#region ../../node_modules/.pnpm/@clibuilder+axi@0.2.0_clibuilder@11.3.0_typescript@7.0.2_/node_modules/@clibuilder/axi/esm/text.js
16138
+ function isRecord$3(value) {
16032
16139
  return typeof value === "object" && value !== null && !Array.isArray(value);
16033
16140
  }
16034
- //#endregion
16035
- //#region src/command-output/command-output.ts
16036
- const formats$1 = [
16037
- "toon",
16038
- "json",
16039
- "text"
16040
- ];
16041
- /** Rejects anything but the supported formats so an unknown value never falls back silently. */
16042
- function parseFormat$1(value) {
16043
- if (!formats$1.includes(value)) throw new Error("--format must be toon, json, or text.");
16044
- return value;
16045
- }
16046
- /** The single stdout boundary: internal logic stays on plain objects, encoding happens here. */
16047
- function writeResult$1(value, format) {
16048
- process.stdout.write(`${encodeResult$1(value, format)}\n`);
16049
- }
16050
- /**
16051
- * Writes a document exactly as read, bypassing the encoders — a Markdown body run through TOON or
16052
- * the text renderer comes back as one escaped line. A command writes one or the other, never both.
16053
- */
16054
- function writeDocument$1(content) {
16055
- process.stdout.write(content.endsWith("\n") ? content : `${content}\n`);
16056
- }
16057
- function encodeResult$1(value, format) {
16058
- if (format === "json") return JSON.stringify(value);
16059
- return format === "text" ? renderText$1(value) : encode(value);
16060
- }
16061
16141
  function cell$1(value) {
16062
16142
  return value === void 0 ? "" : String(value);
16063
16143
  }
@@ -16067,12 +16147,15 @@ function table$1(rows) {
16067
16147
  const line = (values) => ` ${values.map((value, index) => value.padEnd(widths[index])).join(" ")}`.trimEnd();
16068
16148
  return [line(columns), ...rows.map((row) => line(columns.map((column) => cell$1(row[column]))))];
16069
16149
  }
16070
- /** Renders for a person, not an agent — TOON stays the default since that's what an agent parses. */
16150
+ /**
16151
+ * Renders a result for a person, not an agent: each key on its own line, a list of records as an
16152
+ * aligned table under its key, a list of values as bullets, and an empty list as `(none)`.
16153
+ */
16071
16154
  function renderText$1(value) {
16072
16155
  const blocks = Object.entries(value).map(([key, item]) => {
16073
- if (!Array.isArray(item)) return [`${key}: ${isRecord$1(item) ? JSON.stringify(item) : String(item)}`];
16156
+ if (!Array.isArray(item)) return [`${key}: ${isRecord$3(item) ? JSON.stringify(item) : String(item)}`];
16074
16157
  if (!item.length) return [`${key}: (none)`];
16075
- const body = item.every(isRecord$1) ? table$1(item) : item.map((entry) => ` - ${String(entry)}`);
16158
+ const body = item.every(isRecord$3) ? table$1(item) : item.map((entry) => ` - ${String(entry)}`);
16076
16159
  return [`${key}:`, ...body];
16077
16160
  });
16078
16161
  return blocks.flatMap((block, index) => {
@@ -16080,15 +16163,77 @@ function renderText$1(value) {
16080
16163
  return previous && (previous.length > 1 || block.length > 1) ? ["", ...block] : block;
16081
16164
  }).join("\n");
16082
16165
  }
16166
+ //#endregion
16167
+ //#region ../../node_modules/.pnpm/@clibuilder+axi@0.2.0_clibuilder@11.3.0_typescript@7.0.2_/node_modules/@clibuilder/axi/esm/output.js
16168
+ /** Encodes a result in the given format, without writing it anywhere. */
16169
+ function encodeResult$1(value, format) {
16170
+ if (format === "json") return JSON.stringify(value);
16171
+ return format === "text" ? renderText$1(value) : encode(value);
16172
+ }
16173
+ /** The single stdout boundary: internal logic stays on plain objects, encoding happens here. */
16174
+ function writeResult$1(value, format, stdout = process.stdout) {
16175
+ stdout.write(`${encodeResult$1(value, format)}\n`);
16176
+ }
16083
16177
  /**
16084
- * AXI §10: collapses the home directory to `~` so a path in a report is portable to another
16085
- * machine.
16178
+ * Writes a document exactly as read, bypassing the encoders — a Markdown body run through TOON or
16179
+ * the text renderer comes back as one escaped line. A command writes one or the other, never both.
16086
16180
  */
16087
- function collapseHome$1(home, path) {
16088
- return home && path.startsWith(home + sep) ? `~${path.slice(home.length)}` : path;
16181
+ function writeDocument$1(content, stdout = process.stdout) {
16182
+ stdout.write(content.endsWith("\n") ? content : `${content}\n`);
16089
16183
  }
16090
- function displayBinPath(home, executable) {
16091
- return executable ? collapseHome$1(home, executable) : "buddy-agent-harness";
16184
+ /** Encodes an error in the given format, without writing it anywhere. */
16185
+ function encodeError(report, format) {
16186
+ return encodeResult$1(errorOutput(report), format);
16187
+ }
16188
+ /**
16189
+ * Writes an error on stdout — the stream the agent reads its answers from — and returns the exit
16190
+ * code the CLI should end with.
16191
+ *
16192
+ * Inside a command, prefer `createOutput(args.format).error(report)`, which hands back a
16193
+ * `CliError` to throw.
16194
+ */
16195
+ function writeError(report, format, stdout = process.stdout) {
16196
+ stdout.write(`${encodeError(report, format)}\n`);
16197
+ return report.exitCode ?? exitCodes.error;
16198
+ }
16199
+ /**
16200
+ * Binds the parsed `--format` to the writers, so a command picks the format once and writes
16201
+ * through it.
16202
+ *
16203
+ * @param format The command's parsed `format` argument. `undefined` falls back to `toon`.
16204
+ *
16205
+ * @example
16206
+ * ```ts
16207
+ * run(args) {
16208
+ * return createOutput(args.format).result({ plugins })
16209
+ * }
16210
+ * ```
16211
+ */
16212
+ function createOutput$1(format, options = {}) {
16213
+ const resolved = format ?? "toon";
16214
+ const stdout = options.stdout ?? process.stdout;
16215
+ return {
16216
+ format: resolved,
16217
+ result(value, options) {
16218
+ const render = options?.[resolved];
16219
+ const help = helpLines(options?.help);
16220
+ if (!render) {
16221
+ writeResult$1(withHelp(value, help), resolved, stdout);
16222
+ return value;
16223
+ }
16224
+ const body = render(value);
16225
+ if (help.length === 0) writeDocument$1(body, stdout);
16226
+ else writeDocument$1(`${body}${body.endsWith("\n") ? "\n" : "\n\n"}${encodeResult$1({ help }, resolved)}`, stdout);
16227
+ return value;
16228
+ },
16229
+ document(content) {
16230
+ writeDocument$1(content, stdout);
16231
+ },
16232
+ error(report) {
16233
+ const exitCode = writeError(report, resolved, stdout);
16234
+ return new CliError(report.message, { exitCode });
16235
+ }
16236
+ };
16092
16237
  }
16093
16238
  //#endregion
16094
16239
  //#region ../../node_modules/.pnpm/yaml@2.9.0/node_modules/yaml/dist/nodes/identity.js
@@ -22695,7 +22840,7 @@ var require_public_api = /* @__PURE__ */ __commonJSMin(((exports) => {
22695
22840
  exports.stringify = stringify;
22696
22841
  }));
22697
22842
  //#endregion
22698
- //#region ../../node_modules/.pnpm/@cyberuni+agent-harness@0.5.0_typescript@7.0.2/node_modules/@cyberuni/agent-harness/dist/reference-where-BAoFiykf.js
22843
+ //#region ../../node_modules/.pnpm/@cyberuni+agent-harness@0.6.0_typescript@7.0.2/node_modules/@cyberuni/agent-harness/dist/reference-where-CFfGZToE.js
22699
22844
  var import_dist = (/* @__PURE__ */ __commonJSMin(((exports) => {
22700
22845
  var composer = require_composer();
22701
22846
  var Document = require_Document();
@@ -23275,7 +23420,7 @@ function stripJsonComments$1(text) {
23275
23420
  }
23276
23421
  return out.replace(/,(\s*[}\]])/g, "$1");
23277
23422
  }
23278
- function isRecord(value) {
23423
+ function isRecord$2(value) {
23279
23424
  return typeof value === "object" && value !== null && !Array.isArray(value);
23280
23425
  }
23281
23426
  /**
@@ -23592,8 +23737,8 @@ async function enabledPlugins(harness, options = {}) {
23592
23737
  /** Read the `enabledPlugins` object of a JSON settings file, keeping boolean values only. */
23593
23738
  function jsonEnabledPlugins(text) {
23594
23739
  const settings = JSON.parse(text);
23595
- const map = isRecord(settings) ? settings.enabledPlugins : void 0;
23596
- if (!isRecord(map)) return {};
23740
+ const map = isRecord$2(settings) ? settings.enabledPlugins : void 0;
23741
+ if (!isRecord$2(map)) return {};
23597
23742
  return Object.fromEntries(Object.entries(map).filter((entry) => typeof entry[1] === "boolean"));
23598
23743
  }
23599
23744
  const pluginTableHeader = /^\[\s*plugins\s*\.\s*(?:"([^"]*)"|'([^']*)'|([A-Za-z0-9_-]+))\s*\]\s*(?:#.*)?$/;
@@ -23813,14 +23958,14 @@ async function readClaudeInstalls(path) {
23813
23958
  const text = await readText(path);
23814
23959
  if (text === void 0) return void 0;
23815
23960
  const record = JSON.parse(text);
23816
- const map = isRecord(record) ? record.plugins : void 0;
23817
- if (!isRecord(map)) return { plugins: [] };
23961
+ const map = isRecord$2(record) ? record.plugins : void 0;
23962
+ if (!isRecord$2(map)) return { plugins: [] };
23818
23963
  const plugins = [];
23819
23964
  for (const [id, entries] of Object.entries(map)) {
23820
23965
  if (!Array.isArray(entries)) continue;
23821
23966
  for (const entry of entries) {
23822
- const installPath = isRecord(entry) ? optionalString(entry.installPath) : void 0;
23823
- if (!isRecord(entry) || installPath === void 0) continue;
23967
+ const installPath = isRecord$2(entry) ? optionalString(entry.installPath) : void 0;
23968
+ if (!isRecord$2(entry) || installPath === void 0) continue;
23824
23969
  const version = optionalString(entry.version);
23825
23970
  const scope = typeof entry.scope === "string" && scopes.includes(entry.scope) ? entry.scope : void 0;
23826
23971
  const projectPath = optionalString(entry.projectPath);
@@ -23841,11 +23986,11 @@ async function readCopilotInstalls(path) {
23841
23986
  const text = await readText(path);
23842
23987
  if (text === void 0) return void 0;
23843
23988
  const config = JSON.parse(stripJsonComments$1(text));
23844
- const entries = isRecord(config) ? config.installedPlugins : void 0;
23989
+ const entries = isRecord$2(config) ? config.installedPlugins : void 0;
23845
23990
  if (!Array.isArray(entries)) return { plugins: [] };
23846
23991
  const plugins = [];
23847
23992
  for (const entry of entries) {
23848
- if (!isRecord(entry)) continue;
23993
+ if (!isRecord$2(entry)) continue;
23849
23994
  const name = optionalString(entry.name);
23850
23995
  const cachePath = optionalString(entry.cache_path);
23851
23996
  if (name === void 0 || cachePath === void 0) continue;
@@ -24186,7 +24331,7 @@ function readJson$2(path) {
24186
24331
  function isRepositoryRoot(dir) {
24187
24332
  if (existsSync(join(dir, ".git")) || existsSync(join(dir, "pnpm-workspace.yaml"))) return true;
24188
24333
  const manifest = readJson$2(join(dir, "package.json"));
24189
- return isRecord(manifest) && manifest["workspaces"] !== void 0;
24334
+ return isRecord$2(manifest) && manifest["workspaces"] !== void 0;
24190
24335
  }
24191
24336
  /**
24192
24337
  * `root` and each folder above it up to the repository root, nearest first. With no repository root
@@ -24242,7 +24387,7 @@ function dependencyLayers(root, skip) {
24242
24387
  const references = join(dir, "references");
24243
24388
  if (!isDirectory$2(references)) continue;
24244
24389
  const manifest = readJson$2(join(dir, "plugin.json"));
24245
- const manifestName = isRecord(manifest) && typeof manifest["name"] === "string" ? manifest["name"] : void 0;
24390
+ const manifestName = isRecord$2(manifest) && typeof manifest["name"] === "string" ? manifest["name"] : void 0;
24246
24391
  const plugins = manifestName && manifestName !== pkg ? [pkg, manifestName] : [pkg];
24247
24392
  layers.push({
24248
24393
  tier: "plugin",
@@ -24317,7 +24462,7 @@ function parseDocument(raw, warn) {
24317
24462
  metadata: {},
24318
24463
  body
24319
24464
  };
24320
- if (isRecord(value)) return {
24465
+ if (isRecord$2(value)) return {
24321
24466
  metadata: value,
24322
24467
  body
24323
24468
  };
@@ -24841,7 +24986,7 @@ function whereReference(name, layers, { root, caller, display = (path) => path }
24841
24986
  return report;
24842
24987
  }
24843
24988
  //#endregion
24844
- //#region ../../node_modules/.pnpm/@cyberuni+agent-harness@0.5.0_typescript@7.0.2/node_modules/@cyberuni/agent-harness/dist/index.js
24989
+ //#region ../../node_modules/.pnpm/@cyberuni+agent-harness@0.6.0_typescript@7.0.2/node_modules/@cyberuni/agent-harness/dist/index.js
24845
24990
  /**
24846
24991
  * The directories a harness reads skills from, as its vendor documents them.
24847
24992
  *
@@ -25336,15 +25481,11 @@ const depPluginsCommand = command({
25336
25481
  description: "Report whether the catalog is current without writing it. For CI and postinstall.",
25337
25482
  type: optionalType(booleanType())
25338
25483
  },
25339
- format: {
25340
- description: "Output format: toon (default), json, or text for a human-readable report.",
25341
- type: optionalType(stringType()),
25342
- default: "toon"
25343
- }
25484
+ format: formatOption$1
25344
25485
  },
25345
25486
  run(args) {
25346
25487
  try {
25347
- const format = parseFormat$1(args.format);
25488
+ const output = createOutput$1(args.format);
25348
25489
  const root = args.root ?? process.cwd();
25349
25490
  const derived = deriveCatalog(root);
25350
25491
  const outcome = args.check ? catalogStatus(root, derived.catalog) === "unchanged" ? "current" : "would-change" : writeCatalog(root, derived.catalog);
@@ -25376,7 +25517,7 @@ const depPluginsCommand = command({
25376
25517
  });
25377
25518
  }
25378
25519
  if (derived.plugins.length) notes.push(COPILOT_LIMITATION);
25379
- writeResult$1({
25520
+ const report = {
25380
25521
  catalog: CATALOG_PATH,
25381
25522
  marketplace: derived.catalog.name,
25382
25523
  outcome,
@@ -25388,7 +25529,8 @@ const depPluginsCommand = command({
25388
25529
  harness: harness.length ? harness : "no supported harness detected on this machine",
25389
25530
  actions: actions.length ? actions : "0 actions — every detected harness matches the catalog",
25390
25531
  ...notes.length ? { notes } : {}
25391
- }, format);
25532
+ };
25533
+ output.result(report);
25392
25534
  return outcome === "would-change" ? exitCodes.error : exitCodes.success;
25393
25535
  } catch (error) {
25394
25536
  process.stderr.write(`error: ${error instanceof Error ? error.message : "Catalog generation failed."}\n`);
@@ -25397,6 +25539,18 @@ const depPluginsCommand = command({
25397
25539
  }
25398
25540
  });
25399
25541
  //#endregion
25542
+ //#region src/command-output/command-output.ts
25543
+ /**
25544
+ * AXI §10: collapses the home directory to `~` so a path in a report is portable to another
25545
+ * machine.
25546
+ */
25547
+ function collapseHome$1(home, path) {
25548
+ return home && path.startsWith(home + sep) ? `~${path.slice(home.length)}` : path;
25549
+ }
25550
+ function displayBinPath(home, executable) {
25551
+ return executable ? collapseHome$1(home, executable) : "buddy-agent-harness";
25552
+ }
25553
+ //#endregion
25400
25554
  //#region src/diagnose-bridges/directory-files.ts
25401
25555
  /** A directory that does not exist reads as empty: `doctor` never creates one to look at it. */
25402
25556
  function filesUnder(directory) {
@@ -26118,6 +26272,11 @@ function diagnoseConfiguration({ root, git, cli }) {
26118
26272
  return findings;
26119
26273
  }
26120
26274
  //#endregion
26275
+ //#region src/is-record/is-record.ts
26276
+ function isRecord$1(value) {
26277
+ return typeof value === "object" && value !== null && !Array.isArray(value);
26278
+ }
26279
+ //#endregion
26121
26280
  //#region src/diagnose-mcp/mcp-model.ts
26122
26281
  /** Every field of the model, in the order a finding reports them. */
26123
26282
  const mcpFields = [
@@ -27783,31 +27942,35 @@ function diagnoseNonstandard({ root, cli }) {
27783
27942
  return findings.sort((left, right) => left.path.localeCompare(right.path));
27784
27943
  }
27785
27944
  //#endregion
27786
- //#region ../../node_modules/.pnpm/@cyberuni+agent-harness@0.5.0_typescript@7.0.2/node_modules/@cyberuni/agent-harness/dist/commands.js
27945
+ //#region ../../node_modules/.pnpm/@clibuilder+axi@0.1.0_clibuilder@11.3.0_typescript@7.0.2_/node_modules/@clibuilder/axi/esm/format.js
27946
+ /** Every supported format, the default first. */
27787
27947
  const formats = [
27788
27948
  "toon",
27789
27949
  "json",
27790
27950
  "text"
27791
27951
  ];
27792
- /** Rejects anything but the supported formats so an unknown value never falls back silently. */
27793
- function parseFormat(value) {
27794
- if (!formats.includes(value)) throw new Error("--format must be toon, json, or text.");
27795
- return value;
27796
- }
27797
- /** The single stdout boundary: internal logic stays on plain objects, encoding happens here. */
27798
- function writeResult(value, format) {
27799
- process.stdout.write(`${encodeResult(value, format)}\n`);
27800
- }
27801
27952
  /**
27802
- * Writes a document exactly as read, bypassing the encoders — a Markdown body run through TOON or
27803
- * the text renderer comes back as one escaped line. A command writes one or the other, never both.
27953
+ * Declares a `--format` option for a command whose default or wording differs from
27954
+ * {@link formatOption} — for example one whose `text` output is a document a person reads.
27955
+ *
27956
+ * @example
27957
+ * ```ts
27958
+ * options: { format: defineFormatOption({ default: 'text' }) }
27959
+ * ```
27804
27960
  */
27805
- function writeDocument(content) {
27806
- process.stdout.write(content.endsWith("\n") ? content : `${content}\n`);
27961
+ function defineFormatOption(options = {}) {
27962
+ const defaultFormat = options.default ?? "toon";
27963
+ return {
27964
+ type: optionalType(enumType(formats)),
27965
+ description: options.description ?? `Output format: ${formats.map((f) => f === defaultFormat ? `${f} (default)` : f).join(", ")} — toon for agents, json to pipe, text for humans`,
27966
+ default: defaultFormat
27967
+ };
27807
27968
  }
27808
- function encodeResult(value, format) {
27809
- if (format === "json") return JSON.stringify(value);
27810
- return format === "text" ? renderText(value) : encode(value);
27969
+ defineFormatOption();
27970
+ //#endregion
27971
+ //#region ../../node_modules/.pnpm/@clibuilder+axi@0.1.0_clibuilder@11.3.0_typescript@7.0.2_/node_modules/@clibuilder/axi/esm/text.js
27972
+ function isRecord(value) {
27973
+ return typeof value === "object" && value !== null && !Array.isArray(value);
27811
27974
  }
27812
27975
  function cell(value) {
27813
27976
  return value === void 0 ? "" : String(value);
@@ -27818,7 +27981,10 @@ function table(rows) {
27818
27981
  const line = (values) => ` ${values.map((value, index) => value.padEnd(widths[index])).join(" ")}`.trimEnd();
27819
27982
  return [line(columns), ...rows.map((row) => line(columns.map((column) => cell(row[column]))))];
27820
27983
  }
27821
- /** Renders for a person, not an agent — TOON stays the default since that's what an agent parses. */
27984
+ /**
27985
+ * Renders a result for a person, not an agent: each key on its own line, a list of records as an
27986
+ * aligned table under its key, a list of values as bullets, and an empty list as `(none)`.
27987
+ */
27822
27988
  function renderText(value) {
27823
27989
  const blocks = Object.entries(value).map(([key, item]) => {
27824
27990
  if (!Array.isArray(item)) return [`${key}: ${isRecord(item) ? JSON.stringify(item) : String(item)}`];
@@ -27831,6 +27997,55 @@ function renderText(value) {
27831
27997
  return previous && (previous.length > 1 || block.length > 1) ? ["", ...block] : block;
27832
27998
  }).join("\n");
27833
27999
  }
28000
+ //#endregion
28001
+ //#region ../../node_modules/.pnpm/@clibuilder+axi@0.1.0_clibuilder@11.3.0_typescript@7.0.2_/node_modules/@clibuilder/axi/esm/output.js
28002
+ /** Encodes a result in the given format, without writing it anywhere. */
28003
+ function encodeResult(value, format) {
28004
+ if (format === "json") return JSON.stringify(value);
28005
+ return format === "text" ? renderText(value) : encode(value);
28006
+ }
28007
+ /** The single stdout boundary: internal logic stays on plain objects, encoding happens here. */
28008
+ function writeResult(value, format, stdout = process.stdout) {
28009
+ stdout.write(`${encodeResult(value, format)}\n`);
28010
+ }
28011
+ /**
28012
+ * Writes a document exactly as read, bypassing the encoders — a Markdown body run through TOON or
28013
+ * the text renderer comes back as one escaped line. A command writes one or the other, never both.
28014
+ */
28015
+ function writeDocument(content, stdout = process.stdout) {
28016
+ stdout.write(content.endsWith("\n") ? content : `${content}\n`);
28017
+ }
28018
+ /**
28019
+ * Binds the parsed `--format` to the writers, so a command picks the format once and writes
28020
+ * through it.
28021
+ *
28022
+ * @param format The command's parsed `format` argument. `undefined` falls back to `toon`.
28023
+ *
28024
+ * @example
28025
+ * ```ts
28026
+ * run(args) {
28027
+ * return createOutput(args.format).result({ plugins })
28028
+ * }
28029
+ * ```
28030
+ */
28031
+ function createOutput(format, options = {}) {
28032
+ const resolved = format ?? "toon";
28033
+ const stdout = options.stdout ?? process.stdout;
28034
+ return {
28035
+ format: resolved,
28036
+ result(value, renderers) {
28037
+ const render = renderers?.[resolved];
28038
+ if (render) writeDocument(render(value), stdout);
28039
+ else writeResult(value, resolved, stdout);
28040
+ return value;
28041
+ },
28042
+ document(content) {
28043
+ writeDocument(content, stdout);
28044
+ }
28045
+ };
28046
+ }
28047
+ //#endregion
28048
+ //#region ../../node_modules/.pnpm/@cyberuni+agent-harness@0.6.0_typescript@7.0.2/node_modules/@cyberuni/agent-harness/dist/commands.js
27834
28049
  /**
27835
28050
  * AXI §10: collapses the home directory to `~` so a path in a report is portable to another
27836
28051
  * machine.
@@ -27937,13 +28152,14 @@ function missReason(entry) {
27937
28152
  const hint = entry.suggestions?.length ? ` Did you mean: ${entry.suggestions.join(", ")}?` : "";
27938
28153
  return `no reference named "${entry.name}" in any tier.${hint}`;
27939
28154
  }
27940
- function writeShowText(entries) {
28155
+ function writeShowText(output, entries) {
27941
28156
  if (entries.length === 1) {
27942
28157
  const [entry] = entries;
27943
- if (entry.content !== void 0) writeDocument(entry.content);
28158
+ if (entry.content !== void 0) output.document(entry.content);
27944
28159
  return;
27945
28160
  }
27946
- writeDocument(entries.map((entry) => entry.content === void 0 ? `<reference name="${entry.name}" status="${entry.status}" />` : `<reference name="${entry.name}" tier="${entry.tier}">\n${entry.content}</reference>`).join("\n\n"));
28161
+ const blocks = entries.map((entry) => entry.content === void 0 ? `<reference name="${entry.name}" status="${entry.status}" />` : `<reference name="${entry.name}" tier="${entry.tier}">\n${entry.content}</reference>`);
28162
+ output.document(blocks.join("\n\n"));
27947
28163
  }
27948
28164
  function writeShowStderr(entries, format) {
27949
28165
  for (const entry of entries) {
@@ -27969,15 +28185,14 @@ function showCommand(layersFor) {
27969
28185
  description: "Report every path checked, the file that matched, the merge mode, and why a layer was dropped.",
27970
28186
  type: optionalType(booleanType())
27971
28187
  },
27972
- format: {
27973
- description: "Output format: text (default) writes the documents themselves; toon and json return an array with metadata.",
27974
- type: optionalType(stringType()),
27975
- default: "text"
27976
- }
28188
+ format: defineFormatOption({
28189
+ default: "text",
28190
+ description: "Output format: text (default) writes the documents themselves; toon and json return an array with metadata."
28191
+ })
27977
28192
  },
27978
28193
  async run(args) {
27979
28194
  try {
27980
- const format = parseFormat(args.format);
28195
+ const output = createOutput(args.format ?? "text");
27981
28196
  const names = args.names.map(parseReferenceName);
27982
28197
  if (!names.length) throw new Error("Name at least one reference.");
27983
28198
  const home = homedir();
@@ -27988,9 +28203,9 @@ function showCommand(layersFor) {
27988
28203
  const suggestions = resolved.status === "missing" ? searchReferences(name.name, layers, { display }).slice(0, 3).map((match) => match.name) : [];
27989
28204
  return showEntry(resolved, home, suggestions, Boolean(args.trace));
27990
28205
  });
27991
- if (format === "text") writeShowText(entries);
27992
- else writeResult(entries, format);
27993
- writeShowStderr(entries, format);
28206
+ if (output.format === "text") writeShowText(output, entries);
28207
+ else output.result(entries);
28208
+ writeShowStderr(entries, output.format);
27994
28209
  return entries.every((entry) => entry.status === "found") ? exitCodes.success : exitCodes.error;
27995
28210
  } catch (error) {
27996
28211
  return fail(error, "Reference lookup failed.");
@@ -27998,11 +28213,7 @@ function showCommand(layersFor) {
27998
28213
  }
27999
28214
  });
28000
28215
  }
28001
- const listFormatOption = {
28002
- description: "Output format: toon (default), json, or text for a human-readable report.",
28003
- type: optionalType(stringType()),
28004
- default: "toon"
28005
- };
28216
+ const listFormatOption = defineFormatOption({ description: "Output format: toon (default), json, or text for a human-readable report." });
28006
28217
  function listCommand(layersFor) {
28007
28218
  return command({
28008
28219
  name: "list",
@@ -28013,7 +28224,7 @@ function listCommand(layersFor) {
28013
28224
  },
28014
28225
  async run(args) {
28015
28226
  try {
28016
- const format = parseFormat(args.format);
28227
+ const output = createOutput(args.format);
28017
28228
  const home = homedir();
28018
28229
  const layers = await layersFor(args, home);
28019
28230
  const { rows, warnings } = listReferences(layers, { display: (path) => collapseHome(home, path) });
@@ -28030,7 +28241,7 @@ function listCommand(layersFor) {
28030
28241
  })) : "0 references — no layer holds one"
28031
28242
  };
28032
28243
  if (warnings.length) report.warnings = warnings;
28033
- writeResult(report, format);
28244
+ output.result(report);
28034
28245
  return exitCodes.success;
28035
28246
  } catch (error) {
28036
28247
  return fail(error, "Reference listing failed.");
@@ -28053,15 +28264,16 @@ function searchCommand(layersFor) {
28053
28264
  },
28054
28265
  async run(args) {
28055
28266
  try {
28056
- const format = parseFormat(args.format);
28267
+ const output = createOutput(args.format);
28057
28268
  const query = args.query.trim();
28058
28269
  if (!query) throw new Error("Search needs a query.");
28059
28270
  const home = homedir();
28060
28271
  const matches = searchReferences(query, await layersFor(args, home), { display: (path) => collapseHome(home, path) });
28061
- writeResult({
28272
+ const report = {
28062
28273
  query,
28063
28274
  references: matches.length ? matches : `0 references match "${query}"`
28064
- }, format);
28275
+ };
28276
+ output.result(report);
28065
28277
  return exitCodes.success;
28066
28278
  } catch (error) {
28067
28279
  return fail(error, "Reference search failed.");
@@ -28088,7 +28300,7 @@ function whereCommand(layersFor) {
28088
28300
  },
28089
28301
  async run(args) {
28090
28302
  try {
28091
- const format = parseFormat(args.format);
28303
+ const output = createOutput(args.format);
28092
28304
  const name = parseReferenceName(args.name);
28093
28305
  const home = homedir();
28094
28306
  const report = whereReference(name, await layersFor(args, home), {
@@ -28096,7 +28308,7 @@ function whereCommand(layersFor) {
28096
28308
  caller: args.caller === void 0 ? void 0 : resolve(args.caller),
28097
28309
  display: (path) => collapseHome(home, path)
28098
28310
  });
28099
- writeResult(report, format);
28311
+ output.result(report);
28100
28312
  if (!report.plugins) return exitCodes.success;
28101
28313
  process.stderr.write(`error: ${missReason({
28102
28314
  name: name.raw,
@@ -28139,15 +28351,14 @@ function createCommand(layersFor) {
28139
28351
  description: "Print the target path and the exact content, and write nothing.",
28140
28352
  type: optionalType(booleanType())
28141
28353
  },
28142
- format: {
28143
- description: "Output format: text (default) writes the path, then the content or the trace; toon and json return an object.",
28144
- type: optionalType(stringType()),
28145
- default: "text"
28146
- }
28354
+ format: defineFormatOption({
28355
+ default: "text",
28356
+ description: "Output format: text (default) writes the path, then the content or the trace; toon and json return an object."
28357
+ })
28147
28358
  },
28148
28359
  async run(args) {
28149
28360
  try {
28150
- const format = parseFormat(args.format);
28361
+ const output = createOutput(args.format ?? "text");
28151
28362
  const name = parseReferenceName(args.name);
28152
28363
  if (name.plugin !== void 0) throw new Error(`an override is written under the bare name, which every tier resolves; ask for "${name.name}".`);
28153
28364
  const scope = parseScope(args.scope);
@@ -28177,11 +28388,11 @@ function createCommand(layersFor) {
28177
28388
  writeFileSync(target, content, { flag: "wx" });
28178
28389
  report.trace = traceOf(resolveReference(name, layers, { display }), home);
28179
28390
  }
28180
- if (format !== "text") writeResult(report, format);
28391
+ if (output.format !== "text") output.result(report);
28181
28392
  else {
28182
28393
  for (const warning of warnings) process.stderr.write(`warning: ${warning}\n`);
28183
- if (report.trace) process.stdout.write(`${report.path}\n\n${renderText({ trace: report.trace })}\n`);
28184
- else writeDocument(`${report.path}\n\n${content}`);
28394
+ if (report.trace) output.document(`${report.path}\n\n${renderText({ trace: report.trace })}`);
28395
+ else output.document(`${report.path}\n\n${content}`);
28185
28396
  }
28186
28397
  return exitCodes.success;
28187
28398
  } catch (error) {
@@ -28228,15 +28439,14 @@ function deleteCommand(layersFor) {
28228
28439
  description: "Print the file that would be deleted and what would answer the name then, and delete nothing.",
28229
28440
  type: optionalType(booleanType())
28230
28441
  },
28231
- format: {
28232
- description: "Output format: text (default) writes the path, what answers next, and the trace; toon and json return an object.",
28233
- type: optionalType(stringType()),
28234
- default: "text"
28235
- }
28442
+ format: defineFormatOption({
28443
+ default: "text",
28444
+ description: "Output format: text (default) writes the path, what answers next, and the trace; toon and json return an object."
28445
+ })
28236
28446
  },
28237
28447
  async run(args) {
28238
28448
  try {
28239
- const format = parseFormat(args.format);
28449
+ const output = createOutput(args.format ?? "text");
28240
28450
  const name = parseReferenceName(args.name);
28241
28451
  if (name.plugin !== void 0) throw new Error(`a project or user copy is held under the bare name; ask for "${name.name}". A plugin's copy is never deleted.`);
28242
28452
  const scope = parseScope(args.scope);
@@ -28270,8 +28480,8 @@ function deleteCommand(layersFor) {
28270
28480
  next: nextOf(after, home),
28271
28481
  trace: traceOf(after, home)
28272
28482
  };
28273
- if (format !== "text") writeResult(report, format);
28274
- else process.stdout.write(`${report.path}\n\n${dryRun ? "would delete" : "deleted"}. ${describeNext(report.name, report.next)}\n\n${renderText({ trace: report.trace })}\n`);
28483
+ if (output.format !== "text") output.result(report);
28484
+ else output.document(`${report.path}\n\n${dryRun ? "would delete" : "deleted"}. ${describeNext(report.name, report.next)}\n\n${renderText({ trace: report.trace })}`);
28275
28485
  return exitCodes.success;
28276
28486
  } catch (error) {
28277
28487
  return fail(error, "Reference deletion failed.");
@@ -29175,15 +29385,11 @@ const doctorCommand = command({
29175
29385
  description: "Comma-separated harnesses to check in addition to Claude Code and Cursor, e.g. codex,gemini-cli.",
29176
29386
  type: optionalType(stringType())
29177
29387
  },
29178
- format: {
29179
- description: "Output format: toon (default), json, or text for a human-readable report.",
29180
- type: optionalType(stringType()),
29181
- default: "toon"
29182
- }
29388
+ format: formatOption$1
29183
29389
  },
29184
29390
  async run(args) {
29185
29391
  try {
29186
- const format = parseFormat$1(args.format);
29392
+ const output = createOutput$1(args.format);
29187
29393
  const harnesses = parseHarnesses(args.harness);
29188
29394
  const root = args.root ?? process.cwd();
29189
29395
  const home = homedir();
@@ -29224,7 +29430,7 @@ const doctorCommand = command({
29224
29430
  path: collapseHome$1(home, path),
29225
29431
  status
29226
29432
  }));
29227
- writeResult$1(buildDoctorReport(displayBinPath(home, process.argv[1]), result, configuration, held), format);
29433
+ output.result(buildDoctorReport(displayBinPath(home, process.argv[1]), result, configuration, held));
29228
29434
  return exitCodes.success;
29229
29435
  } catch (error) {
29230
29436
  process.stderr.write(`error: ${error instanceof Error ? error.message : "Harness diagnosis failed."}\n`);
@@ -29263,20 +29469,16 @@ const governanceCommand = command({
29263
29469
  options: {
29264
29470
  root: rootOption,
29265
29471
  "overrides-only": overridesOnlyOption,
29266
- format: {
29267
- description: "Output format: toon (default), json, or text for a human-readable report.",
29268
- type: optionalType(stringType()),
29269
- default: "toon"
29270
- }
29472
+ format: formatOption$1
29271
29473
  },
29272
29474
  run(args) {
29273
29475
  process.stderr.write(GOVERNANCE_DEPRECATED);
29274
29476
  try {
29275
- const format = parseFormat$1(args.format);
29477
+ const output = createOutput$1(args.format);
29276
29478
  const home = homedir();
29277
29479
  const layers = layersFor(args);
29278
29480
  const entries = listGovernances(layers);
29279
- writeResult$1({
29481
+ const report = {
29280
29482
  layers: layers.map(({ scope, dir }) => ({
29281
29483
  scope,
29282
29484
  path: collapseHome$1(home, dir),
@@ -29287,7 +29489,8 @@ const governanceCommand = command({
29287
29489
  scope,
29288
29490
  path: collapseHome$1(home, path)
29289
29491
  })) : "0 governances — no layer holds one"
29290
- }, format);
29492
+ };
29493
+ output.result(report);
29291
29494
  return exitCodes.success;
29292
29495
  } catch (error) {
29293
29496
  process.stderr.write(`error: ${error instanceof Error ? error.message : "Governance listing failed."}\n`);
@@ -29305,29 +29508,28 @@ const governanceCommand = command({
29305
29508
  options: {
29306
29509
  root: rootOption,
29307
29510
  "overrides-only": overridesOnlyOption,
29308
- format: {
29309
- description: "Output format: text (default) writes the document itself; toon and json wrap it with the layer it came from.",
29310
- type: optionalType(stringType()),
29311
- default: "text"
29312
- }
29511
+ format: defineFormatOption$1({
29512
+ default: "text",
29513
+ description: "Output format: text (default) writes the document itself; toon and json wrap it with the layer it came from."
29514
+ })
29313
29515
  },
29314
29516
  run(args) {
29315
29517
  process.stderr.write(GOVERNANCE_DEPRECATED);
29316
29518
  try {
29317
- const format = parseFormat$1(args.format);
29519
+ const output = createOutput$1(args.format);
29318
29520
  const name = parseGovernanceName(args.name);
29319
29521
  const found = resolveGovernance(name, layersFor(args));
29320
29522
  if (!found) {
29321
29523
  process.stderr.write(args["overrides-only"] ? `error: no override for governance "${name}" in the project, user, or machine-wide layer.\n` : `error: no governance named "${name}" in any layer.\n`);
29322
29524
  return exitCodes.error;
29323
29525
  }
29324
- if (format === "text") writeDocument$1(found.content);
29325
- else writeResult$1({
29526
+ const report = {
29326
29527
  name: found.name,
29327
29528
  scope: found.scope,
29328
29529
  path: collapseHome$1(homedir(), found.path),
29329
29530
  content: found.content
29330
- }, format);
29531
+ };
29532
+ output.result(report, { text: ({ content }) => content });
29331
29533
  return exitCodes.success;
29332
29534
  } catch (error) {
29333
29535
  process.stderr.write(`error: ${error instanceof Error ? error.message : "Governance lookup failed."}\n`);
@@ -29388,22 +29590,18 @@ const initCommand = command({
29388
29590
  description: "Replace conflicting target skill directories. Names the targets to replace, comma-separated (e.g. .claude/skills); given alone it replaces every conflicting target.",
29389
29591
  type: optionalType(stringType())
29390
29592
  },
29391
- format: {
29392
- description: "Output format: toon (default), json, or text for a human-readable report.",
29393
- type: optionalType(stringType()),
29394
- default: "toon"
29395
- }
29593
+ format: formatOption$1
29396
29594
  },
29397
29595
  run(args) {
29398
29596
  try {
29399
- const format = parseFormat$1(args.format);
29597
+ const output = createOutput$1(args.format);
29400
29598
  const harnesses = parseHarnesses(args.harness);
29401
- writeResult$1(initializeHarnesses({
29599
+ output.result(initializeHarnesses({
29402
29600
  root: args.root ?? process.cwd(),
29403
29601
  ...harnesses.length ? { harnesses } : {},
29404
29602
  ...args.copy === void 0 ? {} : { copy: args.copy },
29405
29603
  ...args.force === void 0 ? {} : { force: parseForce(args.force) }
29406
- }), format);
29604
+ }));
29407
29605
  return exitCodes.success;
29408
29606
  } catch (error) {
29409
29607
  process.stderr.write(`error: ${error instanceof Error ? error.message : "Harness initialization failed."}\n`);
@@ -31974,15 +32172,11 @@ const mcpReconcileCommand = command({
31974
32172
  description: "Approve one field by the path a dry run lists for it; repeat for each field. There is no approve-all.",
31975
32173
  type: optionalType(arrayType(stringType()))
31976
32174
  },
31977
- format: {
31978
- description: "Output format: toon (default), json, or text for a human-readable report.",
31979
- type: optionalType(stringType()),
31980
- default: "toon"
31981
- }
32175
+ format: formatOption$1
31982
32176
  },
31983
32177
  run(args) {
31984
32178
  try {
31985
- const format = parseFormat$1(args.format);
32179
+ const output = createOutput$1(args.format);
31986
32180
  const root = args.root ?? process.cwd();
31987
32181
  const accept = args.accept ?? [];
31988
32182
  const plan = reconcileMcp({
@@ -32000,20 +32194,21 @@ const mcpReconcileCommand = command({
32000
32194
  return exitCodes.error;
32001
32195
  }
32002
32196
  if (plan.kind === "absent") {
32003
- writeResult$1({
32197
+ output.result({
32004
32198
  golden: `0 servers — no golden set at ${goldenSetPath}`,
32005
32199
  mode: "nothing to reconcile into",
32006
32200
  fields: "0 fields",
32007
32201
  record: "not written"
32008
- }, format);
32202
+ });
32009
32203
  return exitCodes.success;
32010
32204
  }
32011
- writeResult$1({
32205
+ const report = {
32012
32206
  golden: goldenSetPath,
32013
32207
  mode: plan.written ? "written — only the fields named by --accept" : "dry run — nothing written; re-run with --accept <path> for each approved field",
32014
32208
  fields: plan.rows.length ? plan.rows : "0 fields — no harness holds a change the golden set lacks",
32015
32209
  record: plan.written ? projectionRecordPath : "not written — dry run"
32016
- }, format);
32210
+ };
32211
+ output.result(report);
32017
32212
  return exitCodes.success;
32018
32213
  } catch (error) {
32019
32214
  process.stderr.write(`error: ${error instanceof Error ? error.message : "MCP reconcile failed."}\n`);
@@ -32273,15 +32468,11 @@ const mcpCommand = command({
32273
32468
  description: "Apply the plan and record what was projected. Without it nothing on disk changes.",
32274
32469
  type: optionalType(booleanType())
32275
32470
  },
32276
- format: {
32277
- description: "Output format: toon (default), json, or text for a human-readable report.",
32278
- type: optionalType(stringType()),
32279
- default: "toon"
32280
- }
32471
+ format: formatOption$1
32281
32472
  },
32282
32473
  run(args) {
32283
32474
  try {
32284
- const format = parseFormat$1(args.format);
32475
+ const output = createOutput$1(args.format);
32285
32476
  const root = args.root ?? process.cwd();
32286
32477
  const write = args.write === true;
32287
32478
  const plan = projectMcp({
@@ -32295,21 +32486,22 @@ const mcpCommand = command({
32295
32486
  return exitCodes.error;
32296
32487
  }
32297
32488
  if (plan.kind === "absent") {
32298
- writeResult$1({
32489
+ output.result({
32299
32490
  golden: `0 servers — no golden set at ${goldenSetPath}`,
32300
32491
  mode: "nothing to project",
32301
32492
  actions: "0 changes",
32302
32493
  record: "not written"
32303
- }, format);
32494
+ });
32304
32495
  return exitCodes.success;
32305
32496
  }
32306
- writeResult$1({
32497
+ const report = {
32307
32498
  golden: goldenSetPath,
32308
32499
  mode: write ? "written" : "dry run — nothing written; re-run with --write to apply",
32309
32500
  actions: plan.rows.length ? plan.rows : "0 changes — every enabled harness already carries the golden set",
32310
32501
  ...plan.entries.length ? { entries: plan.entries } : {},
32311
32502
  record: write ? projectionRecordPath : "not written — dry run"
32312
- }, format);
32503
+ };
32504
+ output.result(report);
32313
32505
  return exitCodes.success;
32314
32506
  } catch (error) {
32315
32507
  process.stderr.write(`error: ${error instanceof Error ? error.message : "MCP projection failed."}\n`);