optionsProblem

tcmts.cli.mcp.optionsProblem · #zz3xapji · term · runs anywhere

What's wrong with a tool call's arguments, if anything: options the tool doesn't have (unknownOptions), each named with the ones it does, and the build that said so (a call written for a newer tcm, or a misspelt option, would otherwise be ignored, and the call do something else: run in another directory, say).

import { unknownOptions } from "#codebase/tcmts/cli/mcp";

export function optionsProblem(
  name: string,
  inputSchema: Record<string, unknown>,
  args: Record<string, unknown>,
  build?: string,
): string | undefined {
  const unknown = unknownOptions(inputSchema, args);
  if (!unknown.length) return undefined;
  const where = (at: string) => (at.includes(".") ? at.slice(0, at.lastIndexOf(".")) : "");
  const known = [...new Set(unknown.map((u) => where(u.at)))].map(
    (w) =>
      `known ${w ? `in ${w} ` : ""}are ${unknown.find((u) => where(u.at) === w)!.known.join(", ")}`,
  );
  const names = unknown.map((u) => `\`${u.at}\``);
  return `${name} has no ${names.length > 1 ? `${names.slice(0, -1).join(", ")} or ${names.at(-1)} options` : `${names[0]} option`} in this build${build ? ` (#${build.slice(0, 8)})` : ""}: ${known.join("; ")}. Nothing was done.`;
}

uses

used by