sim 2.2.22-preview.264.1 → 2.2.22-preview.265.1

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/index.js CHANGED
@@ -21354,6 +21354,25 @@ async function localFile(path, override) {
21354
21354
  }
21355
21355
 
21356
21356
  // src/runtime/request.ts
21357
+ function jsonKind(value) {
21358
+ if (Array.isArray(value))
21359
+ return "a JSON array";
21360
+ if (value === null)
21361
+ return "null";
21362
+ return typeof value === "object" ? "a JSON object" : `a JSON ${typeof value}`;
21363
+ }
21364
+ function bodyVariantShapeError(variant, parsed, variants) {
21365
+ const flag = `--${variant.name}`;
21366
+ const example = variant.kind === "array" ? `'[{"column":"value"}]'` : `'{"column":"value"}'`;
21367
+ const base = `${flag} must be a JSON ${variant.kind}, e.g. ${flag} ${example}; got ${jsonKind(parsed)}.`;
21368
+ if (variant.kind === "array" && parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
21369
+ if (Array.isArray(parsed[variant.property])) {
21370
+ return `${base} Pass the array under its "${variant.property}" key itself, not the object wrapping it.`;
21371
+ }
21372
+ }
21373
+ const other = variants.find((candidate) => candidate !== variant && candidate.kind === (Array.isArray(parsed) ? "array" : "object"));
21374
+ return other && parsed && typeof parsed === "object" ? `${base} For that shape use --${other.name}.` : base;
21375
+ }
21357
21376
  var PROFILE_INJECTED_FIELD = "workspaceId";
21358
21377
  function isProfileWorkspacePath(commandSpec, param) {
21359
21378
  return commandSpec.profileWorkspacePath === true && param === PROFILE_INJECTED_FIELD;
@@ -21726,7 +21745,7 @@ async function buildRequest(operation, positional, flags, workspaceId) {
21726
21745
  throw new SimApiError(`--${variant.name} is required`, 0);
21727
21746
  const parsed = await coerce(raw, { kind: variant.kind }, { json: true }, variant.name);
21728
21747
  if (variant.kind === "object" && (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) || variant.kind === "array" && !Array.isArray(parsed)) {
21729
- throw new SimApiError(`--${variant.name} must be a JSON ${variant.kind}`, 0);
21748
+ throw new SimApiError(bodyVariantShapeError(variant, parsed, commandSpec.bodyVariants), 0);
21730
21749
  }
21731
21750
  return boundedRequest({
21732
21751
  params,
@@ -22374,35 +22393,78 @@ var UNKNOWN_OPTION_TOKEN = /^error: unknown option '(.+?)'/;
22374
22393
  function looksLikeAnId(token) {
22375
22394
  return token.length > 2 && !token.startsWith("--") && /^-[A-Za-z0-9_-]*[A-Z0-9][A-Za-z0-9_-]*$/.test(token);
22376
22395
  }
22396
+ var MISSING_OPTION_ERROR = /^error: required option '(.+?)' not specified/;
22397
+ var EXCESS_ARGUMENTS_ERROR = /^error: too many arguments/;
22398
+ function longFlagSyntax(option) {
22399
+ return option.flags.replace(/^-[A-Za-z], /, "");
22400
+ }
22401
+ function usageExample(command) {
22402
+ const parts = [commandPath2(command), argumentSyntax(command)];
22403
+ for (const option of command.options)
22404
+ if (option.mandatory)
22405
+ parts.push(longFlagSyntax(option));
22406
+ return parts.filter(Boolean).join(" ");
22407
+ }
22408
+ function optionList(command) {
22409
+ const flags = command.options.filter((option) => !option.hidden).map((option) => option.flags);
22410
+ return flags.length > 0 ? `Options for ${commandPath2(command)}: ${flags.join(", ")}` : `${commandPath2(command)} takes no options.`;
22411
+ }
22412
+ function extraOperands(command) {
22413
+ const declared = command.registeredArguments.length;
22414
+ if (command.registeredArguments.some((argument) => argument.variadic))
22415
+ return [];
22416
+ return command.args.filter((arg) => !arg.startsWith("-")).slice(declared);
22417
+ }
22418
+ function siblingsDeclaring(command, flag) {
22419
+ const siblings = command.parent?.commands ?? [];
22420
+ return siblings.filter((sibling) => sibling !== command && !sibling._hidden && sibling.options.some((option) => !option.hidden && (option.long === flag || option.short === flag))).map((sibling) => ` ${commandPath2(sibling)} — ${sibling.description().split(`
22421
+ `, 1)[0]}`);
22422
+ }
22423
+ function parseErrorGuidance(command, message) {
22424
+ if (message.startsWith("error: missing required argument ")) {
22425
+ return [`Example: ${usageExample(command)}`];
22426
+ }
22427
+ const missingOption = MISSING_OPTION_ERROR.exec(message)?.[1];
22428
+ if (missingOption) {
22429
+ const extra = extraOperands(command);
22430
+ const flag = missingOption.split(" ", 1)[0];
22431
+ const moved = extra.length === 1 ? [`"${extra[0]}" was passed as a positional; pass it as ${flag} "${extra[0]}".`] : [];
22432
+ return [...moved, `Example: ${usageExample(command)}`];
22433
+ }
22434
+ if (EXCESS_ARGUMENTS_ERROR.test(message)) {
22435
+ return [`Example: ${usageExample(command)}`, optionList(command)];
22436
+ }
22437
+ const token = UNKNOWN_OPTION_TOKEN.exec(message)?.[1];
22438
+ if (!token)
22439
+ return [];
22440
+ if (looksLikeAnId(token) && command.registeredArguments.length > 0) {
22441
+ return [`Example: ${commandPath2(command)} -- ${token}`];
22442
+ }
22443
+ const flag = token.split("=", 1)[0];
22444
+ const owners = siblingsDeclaring(command, flag);
22445
+ return [
22446
+ optionList(command),
22447
+ ...owners.length > 0 ? [`${flag} is an option of:`, ...owners] : []
22448
+ ];
22449
+ }
22377
22450
  function addParseErrorGuidance(command) {
22378
- const outputError = command.configureOutput().outputError;
22379
- if (!outputError)
22380
- throw new Error("Commander output formatter is not configured");
22381
- command.configureOutput({
22382
- outputError: (message, write) => {
22383
- outputError(message, write);
22384
- if (message.startsWith("error: missing required argument ")) {
22385
- const syntax = argumentSyntax(command);
22386
- const example = syntax ? `${commandPath2(command)} ${syntax}` : commandPath2(command);
22387
- write(`Example: ${example}
22388
- `);
22389
- return;
22390
- }
22391
- const token = UNKNOWN_OPTION_TOKEN.exec(message)?.[1];
22392
- if (!token)
22393
- return;
22394
- if (looksLikeAnId(token) && command.registeredArguments.length > 0) {
22395
- write(`Example: ${commandPath2(command)} -- ${token}
22396
- `);
22397
- return;
22398
- }
22399
- const flags = command.options.filter((option) => !option.hidden).map((option) => option.flags);
22400
- write(flags.length > 0 ? `Options for ${commandPath2(command)}: ${flags.join(", ")}
22401
- ` : `${commandPath2(command)} takes no options.
22402
- `);
22403
- }
22404
- });
22405
- return command;
22451
+ const error = command.error.bind(command);
22452
+ command.error = (message, options) => {
22453
+ const guidance = parseErrorGuidance(command, message);
22454
+ return error(guidance.length > 0 ? `${message}
22455
+ ${guidance.join(`
22456
+ `)}` : message, options);
22457
+ };
22458
+ }
22459
+ function addParseErrorGuidanceToTree(program) {
22460
+ const walk = (command) => {
22461
+ const parsesOwnArguments = command.commands.length === 0 || Boolean(command._actionHandler);
22462
+ if (parsesOwnArguments || !command.parent)
22463
+ addParseErrorGuidance(command);
22464
+ for (const child of command.commands)
22465
+ walk(child);
22466
+ };
22467
+ walk(program);
22406
22468
  }
22407
22469
  function assertNoReservedFlags(command, operation) {
22408
22470
  for (const option of command.options) {
@@ -22538,7 +22600,7 @@ function configureOperation(command, operation, spec) {
22538
22600
  return command;
22539
22601
  }
22540
22602
  function buildLeaf(operation, spec, leafName) {
22541
- return addParseErrorGuidance(configureOperation(new Command(leafName), operation, spec));
22603
+ return configureOperation(new Command(leafName), operation, spec);
22542
22604
  }
22543
22605
  function addRenamedCommand(groups, operation, spec, from, to) {
22544
22606
  const segments = from.split(" ");
@@ -26386,6 +26448,7 @@ function buildProgram(options = {}) {
26386
26448
  program.addHelpText("after", options.helpText ?? HELP_EPILOGUE);
26387
26449
  program.addHelpText("beforeAll", ({ command }) => detectCodingAgent(env) !== undefined && command.commands.length > 0 ? AGENT_DISCOVERY_NOTE : "");
26388
26450
  refuseHelpAfterUnknownCommand(program);
26451
+ addParseErrorGuidanceToTree(program);
26389
26452
  assertNoReservedProgramFlags(program);
26390
26453
  return program;
26391
26454
  }
@@ -11,6 +11,13 @@ import type { OperationSpec } from './types';
11
11
  * caller has to name the operation it actually calls, so the two cannot drift.
12
12
  */
13
13
  export declare function describeOperation(operationSpec: OperationSpec, described: string): string;
14
+ /**
15
+ * Attaches {@link addParseErrorGuidance} to every command that parses its own
16
+ * arguments, generated or attached by hand (`files upload`, `secrets set`), so
17
+ * a hand-written command does not answer a guessed flag with a bare error.
18
+ * Pure dispatchers below the root are left to commander's unknown-command handling.
19
+ */
20
+ export declare function addParseErrorGuidanceToTree(program: Command): void;
14
21
  /**
15
22
  * Sweeps the assembled program for a flag the root already owns.
16
23
  *
package/dist/runtime.js CHANGED
@@ -21403,6 +21403,25 @@ async function localFile(path, override) {
21403
21403
  }
21404
21404
 
21405
21405
  // src/runtime/request.ts
21406
+ function jsonKind(value) {
21407
+ if (Array.isArray(value))
21408
+ return "a JSON array";
21409
+ if (value === null)
21410
+ return "null";
21411
+ return typeof value === "object" ? "a JSON object" : `a JSON ${typeof value}`;
21412
+ }
21413
+ function bodyVariantShapeError(variant, parsed, variants) {
21414
+ const flag = `--${variant.name}`;
21415
+ const example = variant.kind === "array" ? `'[{"column":"value"}]'` : `'{"column":"value"}'`;
21416
+ const base = `${flag} must be a JSON ${variant.kind}, e.g. ${flag} ${example}; got ${jsonKind(parsed)}.`;
21417
+ if (variant.kind === "array" && parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
21418
+ if (Array.isArray(parsed[variant.property])) {
21419
+ return `${base} Pass the array under its "${variant.property}" key itself, not the object wrapping it.`;
21420
+ }
21421
+ }
21422
+ const other = variants.find((candidate) => candidate !== variant && candidate.kind === (Array.isArray(parsed) ? "array" : "object"));
21423
+ return other && parsed && typeof parsed === "object" ? `${base} For that shape use --${other.name}.` : base;
21424
+ }
21406
21425
  var PROFILE_INJECTED_FIELD = "workspaceId";
21407
21426
  function isProfileWorkspacePath(commandSpec, param) {
21408
21427
  return commandSpec.profileWorkspacePath === true && param === PROFILE_INJECTED_FIELD;
@@ -21775,7 +21794,7 @@ async function buildRequest(operation, positional, flags, workspaceId) {
21775
21794
  throw new SimApiError(`--${variant.name} is required`, 0);
21776
21795
  const parsed = await coerce(raw, { kind: variant.kind }, { json: true }, variant.name);
21777
21796
  if (variant.kind === "object" && (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) || variant.kind === "array" && !Array.isArray(parsed)) {
21778
- throw new SimApiError(`--${variant.name} must be a JSON ${variant.kind}`, 0);
21797
+ throw new SimApiError(bodyVariantShapeError(variant, parsed, commandSpec.bodyVariants), 0);
21779
21798
  }
21780
21799
  return boundedRequest({
21781
21800
  params,
@@ -22423,35 +22442,78 @@ var UNKNOWN_OPTION_TOKEN = /^error: unknown option '(.+?)'/;
22423
22442
  function looksLikeAnId(token) {
22424
22443
  return token.length > 2 && !token.startsWith("--") && /^-[A-Za-z0-9_-]*[A-Z0-9][A-Za-z0-9_-]*$/.test(token);
22425
22444
  }
22445
+ var MISSING_OPTION_ERROR = /^error: required option '(.+?)' not specified/;
22446
+ var EXCESS_ARGUMENTS_ERROR = /^error: too many arguments/;
22447
+ function longFlagSyntax(option) {
22448
+ return option.flags.replace(/^-[A-Za-z], /, "");
22449
+ }
22450
+ function usageExample(command) {
22451
+ const parts = [commandPath2(command), argumentSyntax(command)];
22452
+ for (const option of command.options)
22453
+ if (option.mandatory)
22454
+ parts.push(longFlagSyntax(option));
22455
+ return parts.filter(Boolean).join(" ");
22456
+ }
22457
+ function optionList(command) {
22458
+ const flags = command.options.filter((option) => !option.hidden).map((option) => option.flags);
22459
+ return flags.length > 0 ? `Options for ${commandPath2(command)}: ${flags.join(", ")}` : `${commandPath2(command)} takes no options.`;
22460
+ }
22461
+ function extraOperands(command) {
22462
+ const declared = command.registeredArguments.length;
22463
+ if (command.registeredArguments.some((argument) => argument.variadic))
22464
+ return [];
22465
+ return command.args.filter((arg) => !arg.startsWith("-")).slice(declared);
22466
+ }
22467
+ function siblingsDeclaring(command, flag) {
22468
+ const siblings = command.parent?.commands ?? [];
22469
+ return siblings.filter((sibling) => sibling !== command && !sibling._hidden && sibling.options.some((option) => !option.hidden && (option.long === flag || option.short === flag))).map((sibling) => ` ${commandPath2(sibling)} — ${sibling.description().split(`
22470
+ `, 1)[0]}`);
22471
+ }
22472
+ function parseErrorGuidance(command, message) {
22473
+ if (message.startsWith("error: missing required argument ")) {
22474
+ return [`Example: ${usageExample(command)}`];
22475
+ }
22476
+ const missingOption = MISSING_OPTION_ERROR.exec(message)?.[1];
22477
+ if (missingOption) {
22478
+ const extra = extraOperands(command);
22479
+ const flag = missingOption.split(" ", 1)[0];
22480
+ const moved = extra.length === 1 ? [`"${extra[0]}" was passed as a positional; pass it as ${flag} "${extra[0]}".`] : [];
22481
+ return [...moved, `Example: ${usageExample(command)}`];
22482
+ }
22483
+ if (EXCESS_ARGUMENTS_ERROR.test(message)) {
22484
+ return [`Example: ${usageExample(command)}`, optionList(command)];
22485
+ }
22486
+ const token = UNKNOWN_OPTION_TOKEN.exec(message)?.[1];
22487
+ if (!token)
22488
+ return [];
22489
+ if (looksLikeAnId(token) && command.registeredArguments.length > 0) {
22490
+ return [`Example: ${commandPath2(command)} -- ${token}`];
22491
+ }
22492
+ const flag = token.split("=", 1)[0];
22493
+ const owners = siblingsDeclaring(command, flag);
22494
+ return [
22495
+ optionList(command),
22496
+ ...owners.length > 0 ? [`${flag} is an option of:`, ...owners] : []
22497
+ ];
22498
+ }
22426
22499
  function addParseErrorGuidance(command) {
22427
- const outputError = command.configureOutput().outputError;
22428
- if (!outputError)
22429
- throw new Error("Commander output formatter is not configured");
22430
- command.configureOutput({
22431
- outputError: (message, write) => {
22432
- outputError(message, write);
22433
- if (message.startsWith("error: missing required argument ")) {
22434
- const syntax = argumentSyntax(command);
22435
- const example = syntax ? `${commandPath2(command)} ${syntax}` : commandPath2(command);
22436
- write(`Example: ${example}
22437
- `);
22438
- return;
22439
- }
22440
- const token = UNKNOWN_OPTION_TOKEN.exec(message)?.[1];
22441
- if (!token)
22442
- return;
22443
- if (looksLikeAnId(token) && command.registeredArguments.length > 0) {
22444
- write(`Example: ${commandPath2(command)} -- ${token}
22445
- `);
22446
- return;
22447
- }
22448
- const flags = command.options.filter((option) => !option.hidden).map((option) => option.flags);
22449
- write(flags.length > 0 ? `Options for ${commandPath2(command)}: ${flags.join(", ")}
22450
- ` : `${commandPath2(command)} takes no options.
22451
- `);
22452
- }
22453
- });
22454
- return command;
22500
+ const error = command.error.bind(command);
22501
+ command.error = (message, options) => {
22502
+ const guidance = parseErrorGuidance(command, message);
22503
+ return error(guidance.length > 0 ? `${message}
22504
+ ${guidance.join(`
22505
+ `)}` : message, options);
22506
+ };
22507
+ }
22508
+ function addParseErrorGuidanceToTree(program) {
22509
+ const walk = (command) => {
22510
+ const parsesOwnArguments = command.commands.length === 0 || Boolean(command._actionHandler);
22511
+ if (parsesOwnArguments || !command.parent)
22512
+ addParseErrorGuidance(command);
22513
+ for (const child of command.commands)
22514
+ walk(child);
22515
+ };
22516
+ walk(program);
22455
22517
  }
22456
22518
  function assertNoReservedFlags(command, operation) {
22457
22519
  for (const option of command.options) {
@@ -22587,7 +22649,7 @@ function configureOperation(command, operation, spec) {
22587
22649
  return command;
22588
22650
  }
22589
22651
  function buildLeaf(operation, spec, leafName) {
22590
- return addParseErrorGuidance(configureOperation(new Command(leafName), operation, spec));
22652
+ return configureOperation(new Command(leafName), operation, spec);
22591
22653
  }
22592
22654
  function addRenamedCommand(groups, operation, spec, from, to) {
22593
22655
  const segments = from.split(" ");
@@ -26435,6 +26497,7 @@ function buildProgram(options = {}) {
26435
26497
  program.addHelpText("after", options.helpText ?? HELP_EPILOGUE);
26436
26498
  program.addHelpText("beforeAll", ({ command }) => detectCodingAgent(env) !== undefined && command.commands.length > 0 ? AGENT_DISCOVERY_NOTE : "");
26437
26499
  refuseHelpAfterUnknownCommand(program);
26500
+ addParseErrorGuidanceToTree(program);
26438
26501
  assertNoReservedProgramFlags(program);
26439
26502
  return program;
26440
26503
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sim",
3
- "version": "2.2.22-preview.264.1",
3
+ "version": "2.2.22-preview.265.1",
4
4
  "description": "Sim CLI - talk to the Sim API from your terminal",
5
5
  "type": "module",
6
6
  "imports": {