diff --git a/apps/docs/content/docs/cli/chat-deployments.mdx b/apps/docs/content/docs/cli/chat-deployments.mdx index e6469503896..f050b7e27a2 100644 --- a/apps/docs/content/docs/cli/chat-deployments.mdx +++ b/apps/docs/content/docs/cli/chat-deployments.mdx @@ -21,7 +21,7 @@ sim chat-deployments list [options] | Option | Required | Description | | --- | --- | --- | -| `--workflow-id ` | No | Restrict to deployments of one workflow. | +| `--workflow ` | No | Restrict to deployments of one workflow. | | `--is-active` | No | Restrict to active or inactive deployments. | | `--no-is-active` | No | Send --is-active as false. | | `--sort-by ` | No | Field used to sort the result. Defaults to "createdAt". Accepted values: `identifier`, `createdAt`, `updatedAt`. | diff --git a/apps/docs/content/docs/cli/reference.mdx b/apps/docs/content/docs/cli/reference.mdx index 8eec52df285..a81f1d86093 100644 --- a/apps/docs/content/docs/cli/reference.mdx +++ b/apps/docs/content/docs/cli/reference.mdx @@ -487,7 +487,7 @@ sim chat-deployments list [options] | Option | Required | Description | | --- | --- | --- | -| `--workflow-id ` | No | Restrict to deployments of one workflow. | +| `--workflow ` | No | Restrict to deployments of one workflow. | | `--is-active` | No | Restrict to active or inactive deployments. | | `--no-is-active` | No | Send --is-active as false. | | `--sort-by ` | No | Field used to sort the result. Defaults to "createdAt". Accepted values: `identifier`, `createdAt`, `updatedAt`. | @@ -6072,7 +6072,7 @@ sim tables groups update [options] | Option | Required | Description | | --- | --- | --- | | `--group-id ` | Yes | Workflow group to update. | -| `--workflow-id ` | No | Replacement backing workflow identifier. | +| `--workflow ` | No | Replacement backing workflow identifier. | | `--name ` | No | Replacement workflow-group display name. | | `--dependencies ` | No | Replacement input dependencies. (JSON, or @path / @- to read a file or stdin). | | `--outputs ` | No | Replacement producer outputs. (JSON, or @path / @- to read a file or stdin). | @@ -7555,7 +7555,7 @@ sim workflow-mcp-servers tools create [options] | Option | Required | Description | | --- | --- | --- | -| `--workflow-id ` | Yes | Workflow to expose as an MCP tool. It must already be deployed. | +| `--workflow ` | Yes | Workflow to expose as an MCP tool. It must already be deployed. | | `--tool-name ` | No | Name MCP clients call. Normalized to the MCP tool-name grammar, and derived from the workflow name when omitted. | | `--tool-description ` | No | Description shown to MCP clients. Derived from the workflow name when omitted. | | `--parameter-descriptions ` | No | Per-field description overrides applied to the schema generated from the deployed workflow inputs, as [{"name":"email","description":"Customer email address"}]. A name matching no input field is ignored (JSON, or @path / @- to read a file or stdin). | @@ -8596,7 +8596,7 @@ sim workflows source catalog [options] | Option | Required | Description | | --- | --- | --- | -| `--workflow-id ` | No | Workflow id, or its exact name: adds every block type already placed in it, the ones the caller could not add marked `addable: false`. | +| `--workflow ` | No | Workflow id, or its exact name: adds every block type already placed in it, the ones the caller could not add marked `addable: false`. | | `--dir ` | No | Source directory whose workspace and workflow to read. Defaults to `.`. | | `--json` | No | Print machine-readable JSON (same as --output json). | diff --git a/apps/docs/content/docs/cli/tables.mdx b/apps/docs/content/docs/cli/tables.mdx index 56b2086b8b9..61733f97bac 100644 --- a/apps/docs/content/docs/cli/tables.mdx +++ b/apps/docs/content/docs/cli/tables.mdx @@ -896,7 +896,7 @@ sim tables groups update [options] | Option | Required | Description | | --- | --- | --- | | `--group-id ` | Yes | Workflow group to update. | -| `--workflow-id ` | No | Replacement backing workflow identifier. | +| `--workflow ` | No | Replacement backing workflow identifier. | | `--name ` | No | Replacement workflow-group display name. | | `--dependencies ` | No | Replacement input dependencies. (JSON, or @path / @- to read a file or stdin). | | `--outputs ` | No | Replacement producer outputs. (JSON, or @path / @- to read a file or stdin). | diff --git a/apps/docs/content/docs/cli/workflow-mcp-servers.mdx b/apps/docs/content/docs/cli/workflow-mcp-servers.mdx index 85d5be6d55d..bcb8599298c 100644 --- a/apps/docs/content/docs/cli/workflow-mcp-servers.mdx +++ b/apps/docs/content/docs/cli/workflow-mcp-servers.mdx @@ -158,7 +158,7 @@ sim workflow-mcp-servers tools create [options] | Option | Required | Description | | --- | --- | --- | -| `--workflow-id ` | Yes | Workflow to expose as an MCP tool. It must already be deployed. | +| `--workflow ` | Yes | Workflow to expose as an MCP tool. It must already be deployed. | | `--tool-name ` | No | Name MCP clients call. Normalized to the MCP tool-name grammar, and derived from the workflow name when omitted. | | `--tool-description ` | No | Description shown to MCP clients. Derived from the workflow name when omitted. | | `--parameter-descriptions ` | No | Per-field description overrides applied to the schema generated from the deployed workflow inputs, as [{"name":"email","description":"Customer email address"}]. A name matching no input field is ignored (JSON, or @path / @- to read a file or stdin). | diff --git a/apps/docs/content/docs/cli/workflows.mdx b/apps/docs/content/docs/cli/workflows.mdx index 812c774d61c..f6a9ab42ae3 100644 --- a/apps/docs/content/docs/cli/workflows.mdx +++ b/apps/docs/content/docs/cli/workflows.mdx @@ -1508,7 +1508,7 @@ sim workflows source catalog [options] | Option | Required | Description | | --- | --- | --- | -| `--workflow-id ` | No | Workflow id, or its exact name: adds every block type already placed in it, the ones the caller could not add marked `addable: false`. | +| `--workflow ` | No | Workflow id, or its exact name: adds every block type already placed in it, the ones the caller could not add marked `addable: false`. | | `--dir ` | No | Source directory whose workspace and workflow to read. Defaults to `.`. | | `--json` | No | Print machine-readable JSON (same as --output json). | diff --git a/packages/sim-cli/src/commands/protocol/workflow-source-reads.ts b/packages/sim-cli/src/commands/protocol/workflow-source-reads.ts index ba4c566c40d..7536cdd7856 100644 --- a/packages/sim-cli/src/commands/protocol/workflow-source-reads.ts +++ b/packages/sim-cli/src/commands/protocol/workflow-source-reads.ts @@ -50,7 +50,7 @@ async function actInDirectory(command: Command): Promise { * Teaches the generated `workflows source resources` and `catalog` leaves the `--dir ` every * other `workflows source` command takes: each reads the workspace the directory names, and * `catalog` also the block types placed in the workflow the directory holds. `catalog - * --workflow-id` takes a workflow's exact name as well as its id, as `get` does. Commander offers + * --workflow` takes a workflow's exact name as well as its id, as `get` does. Commander offers * no way to read the action a leaf holds, so it is captured and delegated to, as `get` does. */ export function attachWorkflowSourceReads(source: Command): void { @@ -64,12 +64,17 @@ export function attachWorkflowSourceReads(source: Command): void { const connectCatalog = callsOperations(catalog, ['getSourceCatalog', 'listWorkflows']) catalog.action(async (_options: unknown, command: Command): Promise => { const dir = await actInDirectory(command) - const workflow: unknown = command.getOptionValue('workflowId') + const workflow: unknown = command.getOptionValue('workflow') if (typeof workflow === 'string') { - command.setOptionValue('workflowId', await resolveWorkflow(connectCatalog().client, workflow)) + // Keeps the source, so `--workflow-id` still warns that it was renamed. + command.setOptionValueWithSource( + 'workflow', + await resolveWorkflow(connectCatalog().client, workflow), + command.getOptionValueSource('workflow') + ) } else { const held = await heldWorkflowId(dir) - if (held !== null) command.setOptionValue('workflowId', held) + if (held !== null) command.setOptionValue('workflow', held) } await readCatalog(command.processedArgs) }) diff --git a/packages/sim-cli/src/contract/commands.ts b/packages/sim-cli/src/contract/commands.ts index 64c6947069d..8cdcdbe3cb9 100644 --- a/packages/sim-cli/src/contract/commands.ts +++ b/packages/sim-cli/src/contract/commands.ts @@ -174,6 +174,12 @@ const KNOWLEDGE_BASE_PATH_ARGUMENT = { knowledgeBaseId: 'knowledgeBaseId' } as c * workspace it already sends. */ const TRANSFER_TOKEN_OMITTED = { 'upload-token': { omit: true } } as const +/** + * A `workflowId` request field, spelled `--workflow` like every other flag naming a workflow. + * Commands that derived `--workflow-id` from the field name shipped that spelling, so it still + * works, with the rename warning. + */ +const WORKFLOW_FLAG = { name: 'workflow', renamedFrom: ['workflow-id'] } as const const WORKFLOW_RUN_SCOPE = { workflowId: { name: 'workflow', @@ -550,6 +556,9 @@ export const CLI_CONTRACT: CliContract = { { header: 'remaining columns', path: 'columns', format: 'count' }, ], }, + updateWorkflowGroup: { + flags: { workflowId: WORKFLOW_FLAG }, + }, // Fields whose type misdescribes their meaning // `z.string()` that the route splits on commas. No generator can infer this. listLogs: { @@ -631,6 +640,9 @@ export const CLI_CONTRACT: CliContract = { command: 'meta status', describe: 'Show API availability and the calling credential’s type and expiry', }, + listChatDeployments: { + flags: { workflowId: WORKFLOW_FLAG }, + }, getWorkflowChatDeployment: { command: 'workflows chat status', describe: 'Show a workflow’s chat deployment', @@ -668,6 +680,7 @@ export const CLI_CONTRACT: CliContract = { }, deployWorkflowMcpTool: { flags: { + workflowId: WORKFLOW_FLAG, parameterDescriptions: { json: true, describe: MCP_PARAMETER_DESCRIPTIONS_HELP }, }, }, @@ -737,6 +750,7 @@ export const CLI_CONTRACT: CliContract = { flags: { 'if-none-match': { omit: true }, workflowId: { + ...WORKFLOW_FLAG, describe: 'Workflow id, or its exact name: adds every block type already placed in it, the ones the caller could not add marked `addable: false`', }, diff --git a/packages/sim-cli/src/runtime/build.ts b/packages/sim-cli/src/runtime/build.ts index 767f5febbc4..8e904d7e2b1 100644 --- a/packages/sim-cli/src/runtime/build.ts +++ b/packages/sim-cli/src/runtime/build.ts @@ -145,13 +145,41 @@ function optionList(command: Command): string { : `${commandPath(command)} takes no options.` } +/** What each guided command's own option parse left unknown, recorded by {@link addParseErrorGuidance}. */ +const UNKNOWN_ARGUMENTS = new WeakMap() + +function isDashLed(arg: string): boolean { + return arg.length > 1 && arg.startsWith('-') +} + /** - * The first unknown option commander saw. Commander files it, and every - * operand after it, at the end of `args`; an operand never opens with a dash - * unless it follows `--`, and then no option is unknown. + * The first unknown option commander saw. Its parse files that option and everything after it as + * unknown, while an operand escaped with `--` (`files rename f_1 -- --name`) stays an operand: + * `args` holds both, so only the parse's own unknown list tells them apart. */ function unknownOptionToken(command: Command): string | undefined { - return command.args.find((arg) => arg.length > 1 && arg.startsWith('-')) + const first = UNKNOWN_ARGUMENTS.get(command)?.[0] + return first !== undefined && isDashLed(first) ? first : undefined +} + +function missingMandatory(command: Command): Option[] { + return command.options.filter( + (option) => option.mandatory && command.getOptionValue(option.attributeName()) === undefined + ) +} + +/** + * An unknown flag typed while a required one is missing, in commander's unknown-option words. + * Commander checks required flags before unknown ones, so its own near-spelling suggestion never + * reaches `runs get --workflow-id`. With one required flag missing, that is the one suggested. + */ +function unknownBesideMissing(command: Command): string | undefined { + const token = unknownOptionToken(command) + if (!token) return undefined + const missing = missingMandatory(command) + const suggestion = + missing.length === 1 && missing[0].long ? ` (Did you mean ${missing[0].long}?)` : '' + return `${token.split('=', 1)[0]} is not an option of ${commandPath(command)}.${suggestion}` } /** @@ -159,14 +187,12 @@ function unknownOptionToken(command: Command): string | undefined { * was wanted (`files rename new.pdf`, `knowledge search `), when * that reading is the only one. An unknown option puts its own value among the * operands, and with two flags missing the value could belong to either, so - * both cases name nothing (as does a dash-led operand escaped with `--`, which - * reads the same as an unknown option here). + * both cases name nothing, as does a dash-led operand escaped with `--`, which + * may be the flag itself (`files rename -- --name`). */ function misplacedFlagValue(command: Command): { option: Option; value: string } | undefined { - const missing = command.options.filter( - (option) => option.mandatory && command.getOptionValue(option.attributeName()) === undefined - ) - if (missing.length !== 1 || unknownOptionToken(command) !== undefined) return undefined + const missing = missingMandatory(command) + if (missing.length !== 1 || command.args.some(isDashLed)) return undefined if (command.registeredArguments.some((argument) => argument.variadic)) return undefined const extra = command.args.slice(command.registeredArguments.length) return extra.length === 1 ? { option: missing[0], value: extra[0] } : undefined @@ -289,7 +315,8 @@ function siblingsDeclaring(command: Command, flag: string): string[] { * * - A missing positional or required flag gets the full command line, and a * value typed as a positional where the flag was wanted is named against - * that flag when nothing else could have put it there. + * that flag when nothing else could have put it there. An unknown flag + * typed beside it is named, with the missing flag suggested. * - Too many positionals get the same command line and the flag list; an option that took * another flag as its value is named, and a JSON operand is moved to the JSON flag it belongs to. * - An unknown option gets the command's own flags, and the sibling commands @@ -305,11 +332,14 @@ function parseErrorGuidance(command: Command, code: string | undefined): string[ return [`Example: ${usageExample(command)}`] case 'commander.missingMandatoryOptionValue': { const misplaced = misplacedFlagValue(command) + const unknown = unknownBesideMissing(command) const moved = misplaced ? [ `"${misplaced.value}" was passed as a positional; pass it as ${misplaced.option.long ?? misplaced.option.short} "${misplaced.value}".`, ] - : [] + : unknown + ? [unknown] + : [] return [...moved, `Example: ${usageExample(command)}`] } case 'commander.excessArguments': { @@ -348,6 +378,12 @@ function parseErrorGuidance(command: Command, code: string | undefined): string[ * one would answer for all of them. */ function addParseErrorGuidance(command: Command): void { + const parseOptions = command.parseOptions.bind(command) + command.parseOptions = (argv) => { + const parsed = parseOptions(argv) + UNKNOWN_ARGUMENTS.set(command, parsed.unknown) + return parsed + } const error = command.error.bind(command) command.error = (message, options) => { const guidance = parseErrorGuidance(command, options?.code) diff --git a/packages/sim-cli/src/runtime/execute.ts b/packages/sim-cli/src/runtime/execute.ts index ed3ecba5f62..8fe180e087f 100644 --- a/packages/sim-cli/src/runtime/execute.ts +++ b/packages/sim-cli/src/runtime/execute.ts @@ -14,10 +14,11 @@ import { assertCursorAdvances, pageProgress, SimApiError, type V2Page } from '.. import { safeOneLine } from '../output/render' import { connect } from './called-operations' import { camel } from './derive' -import { DEFAULT_PAGE_SIZE, defaultListLimit } from './options' +import { DEFAULT_PAGE_SIZE, defaultListLimit, OTHER_SPELLING_SOURCE } from './options' import { renameWarningOptions, warnRenamedFlag } from './renamed' import { type BuiltRequest, + bothSpellingsRefusal, buildRequest, cursorSlot, flagNameFor, @@ -396,7 +397,7 @@ function assertSelectorIsUsable(operation: V2OperationName, flags: Record