Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/docs/content/docs/cli/chat-deployments.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ sim chat-deployments list [options]

| Option | Required | Description |
| --- | --- | --- |
| `--workflow-id <value>` | No | Restrict to deployments of one workflow. |
| `--workflow <value>` | 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 <value>` | No | Field used to sort the result. Defaults to "createdAt". Accepted values: `identifier`, `createdAt`, `updatedAt`. |
Expand Down
8 changes: 4 additions & 4 deletions apps/docs/content/docs/cli/reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ sim chat-deployments list [options]

| Option | Required | Description |
| --- | --- | --- |
| `--workflow-id <value>` | No | Restrict to deployments of one workflow. |
| `--workflow <value>` | 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 <value>` | No | Field used to sort the result. Defaults to "createdAt". Accepted values: `identifier`, `createdAt`, `updatedAt`. |
Expand Down Expand Up @@ -6072,7 +6072,7 @@ sim tables groups update <tableId> [options]
| Option | Required | Description |
| --- | --- | --- |
| `--group-id <value>` | Yes | Workflow group to update. |
| `--workflow-id <value>` | No | Replacement backing workflow identifier. |
| `--workflow <value>` | No | Replacement backing workflow identifier. |
| `--name <value>` | No | Replacement workflow-group display name. |
| `--dependencies <json\|@file>` | No | Replacement input dependencies. (JSON, or @path / @- to read a file or stdin). |
| `--outputs <json\|@file>` | No | Replacement producer outputs. (JSON, or @path / @- to read a file or stdin). |
Expand Down Expand Up @@ -7555,7 +7555,7 @@ sim workflow-mcp-servers tools create <serverId> [options]

| Option | Required | Description |
| --- | --- | --- |
| `--workflow-id <value>` | Yes | Workflow to expose as an MCP tool. It must already be deployed. |
| `--workflow <value>` | Yes | Workflow to expose as an MCP tool. It must already be deployed. |
| `--tool-name <value>` | No | Name MCP clients call. Normalized to the MCP tool-name grammar, and derived from the workflow name when omitted. |
| `--tool-description <value>` | No | Description shown to MCP clients. Derived from the workflow name when omitted. |
| `--parameter-descriptions <json\|@file>` | No | Per-field description overrides applied to the schema generated from the deployed workflow inputs, as [&#123;"name":"email","description":"Customer email address"&#125;]. A name matching no input field is ignored (JSON, or @path / @- to read a file or stdin). |
Expand Down Expand Up @@ -8596,7 +8596,7 @@ sim workflows source catalog [options]

| Option | Required | Description |
| --- | --- | --- |
| `--workflow-id <value>` | 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 <value>` | 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 <dir>` | No | Source directory whose workspace and workflow to read. Defaults to `.`. |
| `--json` | No | Print machine-readable JSON (same as --output json). |

Expand Down
2 changes: 1 addition & 1 deletion apps/docs/content/docs/cli/tables.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ sim tables groups update <tableId> [options]
| Option | Required | Description |
| --- | --- | --- |
| `--group-id <value>` | Yes | Workflow group to update. |
| `--workflow-id <value>` | No | Replacement backing workflow identifier. |
| `--workflow <value>` | No | Replacement backing workflow identifier. |
| `--name <value>` | No | Replacement workflow-group display name. |
| `--dependencies <json\|@file>` | No | Replacement input dependencies. (JSON, or @path / @- to read a file or stdin). |
| `--outputs <json\|@file>` | No | Replacement producer outputs. (JSON, or @path / @- to read a file or stdin). |
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/content/docs/cli/workflow-mcp-servers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ sim workflow-mcp-servers tools create <serverId> [options]

| Option | Required | Description |
| --- | --- | --- |
| `--workflow-id <value>` | Yes | Workflow to expose as an MCP tool. It must already be deployed. |
| `--workflow <value>` | Yes | Workflow to expose as an MCP tool. It must already be deployed. |
| `--tool-name <value>` | No | Name MCP clients call. Normalized to the MCP tool-name grammar, and derived from the workflow name when omitted. |
| `--tool-description <value>` | No | Description shown to MCP clients. Derived from the workflow name when omitted. |
| `--parameter-descriptions <json\|@file>` | No | Per-field description overrides applied to the schema generated from the deployed workflow inputs, as [&#123;"name":"email","description":"Customer email address"&#125;]. A name matching no input field is ignored (JSON, or @path / @- to read a file or stdin). |
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/content/docs/cli/workflows.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1508,7 +1508,7 @@ sim workflows source catalog [options]

| Option | Required | Description |
| --- | --- | --- |
| `--workflow-id <value>` | 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 <value>` | 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 <dir>` | No | Source directory whose workspace and workflow to read. Defaults to `.`. |
| `--json` | No | Print machine-readable JSON (same as --output json). |

Expand Down
13 changes: 9 additions & 4 deletions packages/sim-cli/src/commands/protocol/workflow-source-reads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async function actInDirectory(command: Command): Promise<string> {
* Teaches the generated `workflows source resources` and `catalog` leaves the `--dir <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 {
Expand All @@ -64,12 +64,17 @@ export function attachWorkflowSourceReads(source: Command): void {
const connectCatalog = callsOperations(catalog, ['getSourceCatalog', 'listWorkflows'])
catalog.action(async (_options: unknown, command: Command): Promise<void> => {
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),
Comment thread
waleedlatif1 marked this conversation as resolved.
Resolved
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)
})
Expand Down
14 changes: 14 additions & 0 deletions packages/sim-cli/src/contract/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -668,6 +680,7 @@ export const CLI_CONTRACT: CliContract = {
},
deployWorkflowMcpTool: {
flags: {
workflowId: WORKFLOW_FLAG,
parameterDescriptions: { json: true, describe: MCP_PARAMETER_DESCRIPTIONS_HELP },
},
},
Expand Down Expand Up @@ -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`',
},
Expand Down
60 changes: 48 additions & 12 deletions packages/sim-cli/src/runtime/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,28 +145,54 @@ 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<Command, readonly string[]>()

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 <id> --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}`
}

/**
* The value a caller typed as a positional where the one missing required flag
* was wanted (`files rename <id> new.pdf`, `knowledge search <kbId>`), 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 <id> -- --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
Expand Down Expand Up @@ -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
Expand All @@ -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': {
Expand Down Expand Up @@ -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)
Expand Down
19 changes: 11 additions & 8 deletions packages/sim-cli/src/runtime/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -396,7 +397,7 @@ function assertSelectorIsUsable(operation: V2OperationName, flags: Record<string

/**
* Moves a value supplied under a flag's former name or hidden alias onto its
* documented one.
* documented one, and warns about a former name.
*
* Done here rather than in `buildRequest` because this is where the parsed
* flags are assembled and still keyed by what the caller typed; by the time the
Expand All @@ -414,17 +415,19 @@ function foldOtherSpellings(
): void {
for (const [field, flag] of Object.entries(commandSpec.flags ?? {})) {
const current = flagNameFor(operation, field)
// A value flag's other spelling was copied onto it as it was parsed (`copyOntoCurrentSpelling`),
// and an action may since have rewritten the copy (a workflow name resolved to its id).
const copied = host.getOptionValueSource(camel(current)) === OTHER_SPELLING_SOURCE
let taken = flags[camel(current)] !== undefined && !copied
for (const { name, renamed } of otherSpellings(flag)) {
const supplied = flags[camel(name)]
if (supplied === undefined) continue
if (flags[camel(current)] !== undefined) {
throw new SimApiError(
`--${name} is ${renamed ? 'the former name' : 'another spelling'} of --${current}; pass one, not both`,
0
)
if (taken) {
throw new SimApiError(bothSpellingsRefusal(name, renamed, current), 0)
}
if (renamed) warnRenamedFlag(host, name, current)
flags[camel(current)] = supplied
if (!copied) flags[camel(current)] = supplied
taken = true
}
}
}
Expand Down
Loading
Loading