@cotal-ai/cli 0.194.0 → 0.196.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.
@@ -0,0 +1,31 @@
1
+ import { type Command, type FlagSpec, type Subcommand } from "@cotal-ai/core";
2
+ /** Whether the invoked mode declares a structured output, so it reports every outcome by the 0 to 5
3
+ * table: the subcommand `first` selects, else the command's bare form. */
4
+ export declare function structured(cmd: Command, first: string | undefined): boolean;
5
+ /** Whether `args` ask `cmd` for JSON before any `--`: `--json`, `-j`, or `-j` in a short option group
6
+ * before any value-taking option. The mode is the first positional after skipping declared values. */
7
+ export declare function asksForJson(cmd: Command, args: readonly string[]): boolean;
8
+ /** The refusal for a named or short option typed with a typographic dash pasted from
9
+ * typeset text, as `\u2013\u2013json`, naming it with hyphens; undefined when `word` is no such option. */
10
+ export declare function typographicOption(word: string, names: ReadonlySet<string>, flags?: readonly FlagSpec[]): {
11
+ message: string;
12
+ spelling: string;
13
+ flagName: string | undefined;
14
+ remedy: string | undefined;
15
+ } | undefined;
16
+ export declare function typographicOptions(cmd: Command, flagNames?: readonly string[]): (word: string) => {
17
+ message: string;
18
+ spelling: string;
19
+ flagName: string | undefined;
20
+ remedy: string | undefined;
21
+ } | undefined;
22
+ /** Identify seed before recovery, even when a typographic maintenance flag precedes it. */
23
+ export declare function extSeedSubcommand(cmd: Command, words: readonly string[]): Subcommand | undefined;
24
+ /** An option the parser would misread without an error: a short option written `-c=value`, which
25
+ * takes `=value` as its value, or a declared option typed with a typographic dash pasted from typeset
26
+ * text, which is read as a positional. */
27
+ export declare function misspelledOption(cmd: Command, rest: readonly string[], flagNames: readonly string[] | undefined): {
28
+ message: string;
29
+ remedy?: string;
30
+ } | undefined;
31
+ //# sourceMappingURL=command-options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-options.d.ts","sourceRoot":"","sources":["../src/command-options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAO9F;2EAC2E;AAC3E,wBAAgB,UAAU,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAG3E;AAED;uGACuG;AACvG,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAe1E;AAED;4GAC4G;AAC5G,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,EAAE,KAAK,GAAE,SAAS,QAAQ,EAAO;;;;;cAY1G;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,OAAO,EAAE,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,IAGpE,MAAM,MAAM;;;;;cACrB;AAED,2FAA2F;AAC3F,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,UAAU,GAAG,SAAS,CAQhG;AAED;;2CAE2C;AAC3C,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,MAAM,EAAE,EAAE,SAAS,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CA0ClK"}
@@ -0,0 +1,119 @@
1
+ import { findSubcommand } from "@cotal-ai/core";
2
+ import { GLOBAL_FLAGS, windowsShellWord } from "@cotal-ai/workspace";
3
+ import { HISTORY_LIMIT_FLAGS } from "./commands/history-limit.js";
4
+ import { metadataPositionals } from "./lib/command-path.js";
5
+ import { shellWord } from "./lib/endpoint-errors.js";
6
+ import { TYPOGRAPHIC_OPTION } from "./lib/leading-flags.js";
7
+ /** Whether the invoked mode declares a structured output, so it reports every outcome by the 0 to 5
8
+ * table: the subcommand `first` selects, else the command's bare form. */
9
+ export function structured(cmd, first) {
10
+ const sub = findSubcommand(cmd, first);
11
+ return ((sub ? sub.outputs : cmd.outputs) ?? []).some((mode) => mode === "json" || mode === "ndjson");
12
+ }
13
+ /** Whether `args` ask `cmd` for JSON before any `--`: `--json`, `-j`, or `-j` in a short option group
14
+ * before any value-taking option. The mode is the first positional after skipping declared values. */
15
+ export function asksForJson(cmd, args) {
16
+ if (!structured(cmd, metadataPositionals(cmd, args).positionals[0]?.value))
17
+ return false;
18
+ const shorts = new Map(cmd.flags?.flatMap((flag) => flag.short ? [[flag.short, flag.type]] : []));
19
+ const end = args.indexOf("--");
20
+ return (end === -1 ? args : args.slice(0, end)).some((word) => {
21
+ if (word === "--json" || word === "-j")
22
+ return true;
23
+ if (!/^-[^-]/.test(word))
24
+ return false;
25
+ let json = false;
26
+ for (const ch of word.slice(1)) {
27
+ const type = shorts.get(ch);
28
+ if (type === undefined || type === "string")
29
+ break;
30
+ if (ch === "j")
31
+ json = true;
32
+ }
33
+ return json;
34
+ });
35
+ }
36
+ /** The refusal for a named or short option typed with a typographic dash pasted from
37
+ * typeset text, as `\u2013\u2013json`, naming it with hyphens; undefined when `word` is no such option. */
38
+ export function typographicOption(word, names, flags = []) {
39
+ const typed = TYPOGRAPHIC_OPTION.exec(word);
40
+ if (!typed)
41
+ return undefined;
42
+ const [, name, value] = typed;
43
+ const long = names.has(name);
44
+ const flag = flags.find((flag) => long ? flag.name === name : flag.short === name);
45
+ if (!long && !flag)
46
+ return undefined;
47
+ const option = `${long ? "--" : "-"}${name}`;
48
+ const spelling = value === undefined ? option : `${option}=${value}`;
49
+ const message = `${word} starts with a typographic dash, so it is not an option`;
50
+ const correction = value === undefined ? option : flag?.type === "string" ? `--${flag.name}=${shellWord(value)}` : undefined;
51
+ return { message, spelling, flagName: flag?.name, remedy: correction && `type the option with hyphens: ${correction}` };
52
+ }
53
+ export function typographicOptions(cmd, flagNames) {
54
+ const names = new Set([...(flagNames ?? (cmd.flags ?? []).map((flag) => flag.name)), ...GLOBAL_FLAGS, "help"]);
55
+ const flags = [...(cmd.flags ?? []), { name: "help", short: "h", type: "boolean" }];
56
+ return (word) => typographicOption(word, names, flags);
57
+ }
58
+ /** Identify seed before recovery, even when a typographic maintenance flag precedes it. */
59
+ export function extSeedSubcommand(cmd, words) {
60
+ if (cmd.name !== "ext")
61
+ return undefined;
62
+ const seed = findSubcommand(cmd, "seed");
63
+ if (!seed)
64
+ return undefined;
65
+ const end = words.indexOf("--");
66
+ const names = new Set(seed.flagNames);
67
+ const scope = words.filter((word, index) => (end !== -1 && index >= end) || !typographicOption(word, names));
68
+ return metadataPositionals(cmd, scope).positionals[0]?.value === "seed" ? seed : undefined;
69
+ }
70
+ /** An option the parser would misread without an error: a short option written `-c=value`, which
71
+ * takes `=value` as its value, or a declared option typed with a typographic dash pasted from typeset
72
+ * text, which is read as a positional. */
73
+ export function misspelledOption(cmd, rest, flagNames) {
74
+ const recognize = typographicOptions(cmd, flagNames);
75
+ const positionals = new Set(metadataPositionals(cmd, rest).positionals.map(({ index }) => index));
76
+ for (const [index, word] of rest.entries()) {
77
+ if (word === "--")
78
+ return undefined;
79
+ const previous = rest[index - 1];
80
+ if (previous !== undefined && cmd.flags?.some((flag) => flag.type === "string" && (previous === `--${flag.name}` || previous === `-${flag.short}`)))
81
+ continue;
82
+ const short = /^-([^-=])=(.*)$/su.exec(word);
83
+ const flag = short && cmd.flags?.find((item) => item.short === short[1] && item.type === "string");
84
+ if (short && flag) {
85
+ const value = short[2];
86
+ const windows = process.platform === "win32";
87
+ const common = windows ? windowsShellWord(value) : undefined;
88
+ const quoted = windows ? common ?? `'${value.replaceAll("'", "''")}'` : shellWord(value);
89
+ const long = `--${flag.name}=${quoted}`;
90
+ const correction = value.startsWith("-") ? long : `-${short[1]} ${quoted} or ${long}`;
91
+ return { message: `${word} gives -${short[1]} the value "=${value}"`, remedy: `write ${correction}${windows && common === undefined ? " in PowerShell" : ""}` };
92
+ }
93
+ const typed = positionals.has(index) ? recognize(word) : undefined;
94
+ if (typed?.flagName && typed.flagName !== "help" && (cmd.name === "ext" || cmd.name === "endpoint" || cmd.name === "history" || cmd.name === "service")) {
95
+ const { positionals: modes } = metadataPositionals(cmd, rest, { optionSpelling: (arg) => recognize(arg)?.spelling });
96
+ const sub = findSubcommand(cmd, modes[0]?.value);
97
+ const nested = cmd.name === "endpoint" && sub ? findSubcommand(sub, modes[1]?.value) : undefined;
98
+ const selected = nested ?? sub;
99
+ const accepted = selected ? selected.flagNames : cmd.flagNames;
100
+ if (cmd.name === "history" && sub?.name === "clear" && HISTORY_LIMIT_FLAGS.some((name) => name === typed.flagName))
101
+ return { message: typed.message, remedy: `omit --${typed.flagName} from \`history clear\` and keep the other arguments. Use it with \`history limit\` to change retention` };
102
+ if (accepted && !accepted.includes(typed.flagName)) {
103
+ if (cmd.name === "ext" || (cmd.name === "endpoint" && sub?.name === "check"))
104
+ return { message: typed.message, remedy: `omit this option; \`cotal ${cmd.name}${sub ? ` ${sub.name}` : ""}\` does not take --${typed.flagName}` };
105
+ // Dropping a target or read limit can change the operation. Point to scoped help instead.
106
+ if ((cmd.name === "endpoint" && (sub || !modes.length)) || (cmd.name === "history" && sub) || (cmd.name === "service" && sub?.name === "status")) {
107
+ const path = [cmd.name, sub?.hidden ? undefined : sub?.name, nested?.name].filter(Boolean).join(" ");
108
+ return { message: typed.message, remedy: `see the options for this operation with \`cotal help ${path}\`` };
109
+ }
110
+ }
111
+ }
112
+ if (typed && typed.flagName === "plain" && asksForJson(cmd, rest))
113
+ return { message: typed.message, remedy: "omit the mistyped plain option" };
114
+ if (typed)
115
+ return typed;
116
+ }
117
+ return undefined;
118
+ }
119
+ //# sourceMappingURL=command-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-options.js","sourceRoot":"","sources":["../src/command-options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAgD,MAAM,gBAAgB,CAAC;AAC9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ources":["../src/command.ts"],"names":[],"mappings":"AAIA,OAAO,EAA6E,KAAK,OAAO,EAAkC,KAAK,QAAQ,EAAmB,MAAM,gBAAgB,CAAC;AA2EzL,OAAO,EAAqB,KAAK,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAiXlF,2DAA2D;AAC3D,MAAM,WAAW,aAAa;IAC5B;;;oCAGgC;IAChC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;gCAE4B;IAC5B,aAAa,CAAC,EAAE,aAAa,CAAC;CAC/B;AAoWD,+FAA+F;AAC/F,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,CAUtE;AAoKD;;;;;;;;;;GAUG;AACH,wBAAgB,MAAM,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,IAAI,GAAE,aAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAGlG"}
package/dist/command.js CHANGED
@@ -3,7 +3,8 @@ import { homedir } from "node:os";
3
3
  import { isAbsolute, join, parse, resolve } from "node:path";
4
4
  import { parseArgs } from "node:util";
5
5
  import { commandDeclarationProblems, findCommand, findSubcommand, parseCommandArgs } from "@cotal-ai/core";
6
- import { CommandFailure, commandFailureReport, cachedPreferences, withProjectTrustMigration, BlockedExtensionsDirectoryError, CorruptExtensionsManifestError, cotalDirProblem, cotalHomeProblem, findCotalRoot, disableColor, disableInput, envelopeLine, exitCode, extensionsDir, failureEnvelope, GLOBAL_FLAGS, globalConfigDirProblem, globalFlagDeclarationProblems, hasMeshTargetFlags, inOperationSpace, isCommandFailure, checkServer, isConnectRefusal, isMeshRegistryError, isSeededCommand, isWorkspaceTargetError, jsonFlag, localeIsUtf8, loadExtensionsManifest, operationWarnings, outputDeclarationProblems, oneLine, paintFor, plainFlag, preferencesFolderWarning, recordOperationWarning, renderReport, renderWorkspaceError, runOperation, workspaceErrorParts, spaceRootTarget, targetErrorCode, targetErrorSpace, terminalWidth, userCotalDir, windowsShellWord, staleStoreHint, UnreadableConnectorSelection, } from "@cotal-ai/workspace";
6
+ import { CommandFailure, commandFailureReport, cachedPreferences, withProjectTrustMigration, BlockedExtensionsDirectoryError, CorruptExtensionsManifestError, cotalDirProblem, cotalHomeProblem, findCotalRoot, disableColor, disableInput, envelopeLine, exitCode, extensionsDir, failureEnvelope, globalConfigDirProblem, globalFlagDeclarationProblems, hasMeshTargetFlags, inOperationSpace, isCommandFailure, checkServer, isConnectRefusal, isMeshRegistryError, isSeededCommand, isWorkspaceTargetError, jsonFlag, localeIsUtf8, loadExtensionsManifest, operationWarnings, outputDeclarationProblems, oneLine, paintFor, plainFlag, preferencesFolderWarning, recordOperationWarning, renderReport, renderWorkspaceError, runOperation, workspaceErrorParts, spaceRootTarget, targetErrorCode, targetErrorSpace, terminalWidth, userCotalDir, staleStoreHint, UnreadableConnectorSelection, } from "@cotal-ai/workspace";
7
+ import { structured, asksForJson, typographicOption, typographicOptions, extSeedSubcommand, misspelledOption } from "./command-options.js";
7
8
  import { c, stderrLine } from "./ui.js";
8
9
  import { debugFlag } from "./lib/debug-flag.js";
9
10
  import { commandSurface, isExtensionStub, materializeExtension, materializeExtensionCommand, overlayExtensions, setCommandSurface, setInstalledExtensionsEnabled, } from "./ext-loader.js";
@@ -30,7 +31,7 @@ import { npmProjectDirectory, preserveUpdatePath } from "./lib/npm-invocation.js
30
31
  import { reportLostOutput, writeWholeSync } from "./lib/stdout-owner.js";
31
32
  import { shellWord } from "./lib/endpoint-errors.js";
32
33
  import { crossFolderRemedy, displayProjectTrustFailure, displayRemedy, hasMovedStackRemedy } from "./lib/self-exec.js";
33
- import { asksForHelp, GLOBAL_FLAG_WORDS, leadingInvocation, OUTPUT_FLAG_WORDS, TYPOGRAPHIC_OPTION } from "./lib/leading-flags.js";
34
+ import { asksForHelp, GLOBAL_FLAG_WORDS, leadingInvocation, OUTPUT_FLAG_WORDS } from "./lib/leading-flags.js";
34
35
  import { takeManagedHandoffCustody } from "./managed-handoff.js";
35
36
  import { nearestWords, LEADING_FLAGS, unknownCommandMessage, unknownSubcommandMessage } from "./lib/nearest-word.js";
36
37
  import { UnusableFile } from "./lib/unusable-file.js";
@@ -109,35 +110,6 @@ async function repeatedGlobalFlag(word, cmd, words, warnings = [], textWords) {
109
110
  routeCollisionWarnings(warnings, found, rest, false);
110
111
  return usageExit(refusal.message, found, json, options.includes("--plain"), refusal.remedy, rest);
111
112
  }
112
- /** Whether the invoked mode declares a structured output, so it reports every outcome by the 0 to 5
113
- * table: the subcommand `first` selects, else the command's bare form. */
114
- function structured(cmd, first) {
115
- const sub = findSubcommand(cmd, first);
116
- return ((sub ? sub.outputs : cmd.outputs) ?? []).some((mode) => mode === "json" || mode === "ndjson");
117
- }
118
- /** Whether `args` ask `cmd` for JSON before any `--`: `--json`, `-j`, or `-j` in a short option group
119
- * before any value-taking option. The mode is the first positional after skipping declared values. */
120
- function asksForJson(cmd, args) {
121
- if (!structured(cmd, metadataPositionals(cmd, args).positionals[0]?.value))
122
- return false;
123
- const shorts = new Map(cmd.flags?.flatMap((flag) => flag.short ? [[flag.short, flag.type]] : []));
124
- const end = args.indexOf("--");
125
- return (end === -1 ? args : args.slice(0, end)).some((word) => {
126
- if (word === "--json" || word === "-j")
127
- return true;
128
- if (!/^-[^-]/.test(word))
129
- return false;
130
- let json = false;
131
- for (const ch of word.slice(1)) {
132
- const type = shorts.get(ch);
133
- if (type === undefined || type === "string")
134
- break;
135
- if (ch === "j")
136
- json = true;
137
- }
138
- return json;
139
- });
140
- }
141
113
  function collisionWarning(warnings) {
142
114
  return (message) => { warnings.push({ code: "EXTENSION_COMMAND_COLLISION", target: null, message: message.slice(2) }); };
143
115
  }
@@ -549,89 +521,6 @@ function usageExit(message, cmd, json = false, plain = false, remedy, words = []
549
521
  usageRefusal(new CommandFailure("refused", "USAGE_INVALID", message, remedy === undefined ? undefined : { remedy }), plain, cmd, words);
550
522
  process.exit(1);
551
523
  }
552
- /** The refusal for a named or short option typed with a typographic dash pasted from
553
- * typeset text, as `\u2013\u2013json`, naming it with hyphens; undefined when `word` is no such option. */
554
- function typographicOption(word, names, flags = []) {
555
- const typed = TYPOGRAPHIC_OPTION.exec(word);
556
- if (!typed)
557
- return undefined;
558
- const [, name, value] = typed;
559
- const long = names.has(name);
560
- const flag = flags.find((flag) => long ? flag.name === name : flag.short === name);
561
- if (!long && !flag)
562
- return undefined;
563
- const option = `${long ? "--" : "-"}${name}`;
564
- const spelling = value === undefined ? option : `${option}=${value}`;
565
- const message = `${word} starts with a typographic dash, so it is not an option`;
566
- const correction = value === undefined ? option : flag?.type === "string" ? `--${flag.name}=${shellWord(value)}` : undefined;
567
- return { message, spelling, flagName: flag?.name, remedy: correction && `type the option with hyphens: ${correction}` };
568
- }
569
- function typographicOptions(cmd, flagNames) {
570
- const names = new Set([...(flagNames ?? (cmd.flags ?? []).map((flag) => flag.name)), ...GLOBAL_FLAGS, "help"]);
571
- const flags = [...(cmd.flags ?? []), { name: "help", short: "h", type: "boolean" }];
572
- return (word) => typographicOption(word, names, flags);
573
- }
574
- /** Identify seed before recovery, even when a typographic maintenance flag precedes it. */
575
- function extSeedSubcommand(cmd, words) {
576
- if (cmd.name !== "ext")
577
- return undefined;
578
- const seed = findSubcommand(cmd, "seed");
579
- if (!seed)
580
- return undefined;
581
- const end = words.indexOf("--");
582
- const names = new Set(seed.flagNames);
583
- const scope = words.filter((word, index) => (end !== -1 && index >= end) || !typographicOption(word, names));
584
- return metadataPositionals(cmd, scope).positionals[0]?.value === "seed" ? seed : undefined;
585
- }
586
- /** An option the parser would misread without an error: a short option written `-c=value`, which
587
- * takes `=value` as its value, or a declared option typed with a typographic dash pasted from typeset
588
- * text, which is read as a positional. */
589
- function misspelledOption(cmd, rest, flagNames) {
590
- const recognize = typographicOptions(cmd, flagNames);
591
- const positionals = new Set(metadataPositionals(cmd, rest).positionals.map(({ index }) => index));
592
- for (const [index, word] of rest.entries()) {
593
- if (word === "--")
594
- return undefined;
595
- const previous = rest[index - 1];
596
- if (previous !== undefined && cmd.flags?.some((flag) => flag.type === "string" && (previous === `--${flag.name}` || previous === `-${flag.short}`)))
597
- continue;
598
- const short = /^-([^-=])=(.*)$/su.exec(word);
599
- const flag = short && cmd.flags?.find((item) => item.short === short[1] && item.type === "string");
600
- if (short && flag) {
601
- const value = short[2];
602
- const windows = process.platform === "win32";
603
- const common = windows ? windowsShellWord(value) : undefined;
604
- const quoted = windows ? common ?? `'${value.replaceAll("'", "''")}'` : shellWord(value);
605
- const long = `--${flag.name}=${quoted}`;
606
- const correction = value.startsWith("-") ? long : `-${short[1]} ${quoted} or ${long}`;
607
- return { message: `${word} gives -${short[1]} the value "=${value}"`, remedy: `write ${correction}${windows && common === undefined ? " in PowerShell" : ""}` };
608
- }
609
- const typed = positionals.has(index) ? recognize(word) : undefined;
610
- if (typed?.flagName && typed.flagName !== "help" && (cmd.name === "ext" || cmd.name === "endpoint" || cmd.name === "history" || cmd.name === "service")) {
611
- const { positionals: modes } = metadataPositionals(cmd, rest, { optionSpelling: (arg) => recognize(arg)?.spelling });
612
- const sub = findSubcommand(cmd, modes[0]?.value);
613
- const nested = cmd.name === "endpoint" && sub ? findSubcommand(sub, modes[1]?.value) : undefined;
614
- const selected = nested ?? sub;
615
- const accepted = selected ? selected.flagNames : cmd.flagNames;
616
- if (cmd.name === "history" && sub?.name === "clear" && HISTORY_LIMIT_FLAGS.some((name) => name === typed.flagName))
617
- return { message: typed.message, remedy: `omit --${typed.flagName} from \`history clear\` and keep the other arguments. Use it with \`history limit\` to change retention` };
618
- if (accepted && !accepted.includes(typed.flagName)) {
619
- if (cmd.name === "ext" || (cmd.name === "endpoint" && sub?.name === "check"))
620
- return { message: typed.message, remedy: `omit this option; \`cotal ${cmd.name}${sub ? ` ${sub.name}` : ""}\` does not take --${typed.flagName}` };
621
- // Dropping a target or read limit can change the operation. Point to scoped help instead.
622
- if ((cmd.name === "endpoint" && (sub || !modes.length)) || (cmd.name === "history" && sub) || (cmd.name === "service" && sub?.name === "status")) {
623
- const path = [cmd.name, sub?.hidden ? undefined : sub?.name, nested?.name].filter(Boolean).join(" ");
624
- return { message: typed.message, remedy: `see the options for this operation with \`cotal help ${path}\`` };
625
- }
626
- }
627
- }
628
- if (typed && typed.flagName === "plain" && asksForJson(cmd, rest))
629
- return { message: typed.message, remedy: "omit the mistyped plain option" };
630
- if (typed)
631
- return typed;
632
- }
633
- return undefined;
634
- }
635
524
  /** Strip standalone globals, but keep any global where a string option needs its value. */
636
525
  function stripGlobalFlags(cmd, words) {
637
526
  if (takesWordsRaw(cmd))
@@ -1328,7 +1217,10 @@ async function dispatchCli(registry, argv, opts, scope) {
1328
1217
  if (repeated)
1329
1218
  return repeatedGlobalFlag(repeated, cmd, ownWords(cmd), warnings);
1330
1219
  routeCollisionWarnings(warnings, cmd, ownWords(cmd), wantsHelp);
1331
- ({ cmd, rest } = await serviceSurface(cmd, ownWords(cmd)));
1220
+ const refreshed = await serviceSurface(cmd, ownWords(cmd));
1221
+ ({ cmd, rest } = refreshed);
1222
+ if (!parsed && cmd && !isExtensionStub(cmd))
1223
+ parsed = parseOrExit(cmd, rest, refreshed.noMoreOperands);
1332
1224
  arm();
1333
1225
  }
1334
1226
  }