@cotal-ai/cli 0.175.2 → 0.176.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.
- package/dist/chat/chat-view.d.ts.map +1 -1
- package/dist/chat/chat-view.js +8 -2
- package/dist/chat/chat-view.js.map +1 -1
- package/dist/chat/controller.d.ts +1 -1
- package/dist/chat/controller.d.ts.map +1 -1
- package/dist/chat/controller.js +8 -5
- package/dist/chat/controller.js.map +1 -1
- package/dist/chat/plain.d.ts.map +1 -1
- package/dist/chat/plain.js +7 -3
- package/dist/chat/plain.js.map +1 -1
- package/dist/chat/stdio-io.d.ts.map +1 -1
- package/dist/chat/stdio-io.js +10 -4
- package/dist/chat/stdio-io.js.map +1 -1
- package/dist/command.d.ts.map +1 -1
- package/dist/command.js +119 -52
- package/dist/command.js.map +1 -1
- package/dist/commands/agents.d.ts.map +1 -1
- package/dist/commands/agents.js +71 -24
- package/dist/commands/agents.js.map +1 -1
- package/dist/commands/backup-restore.js +1 -1
- package/dist/commands/backup-restore.js.map +1 -1
- package/dist/commands/backup.d.ts.map +1 -1
- package/dist/commands/backup.js +5 -1
- package/dist/commands/backup.js.map +1 -1
- package/dist/commands/channel-members.d.ts.map +1 -1
- package/dist/commands/channel-members.js +3 -2
- package/dist/commands/channel-members.js.map +1 -1
- package/dist/commands/channels.d.ts.map +1 -1
- package/dist/commands/channels.js +7 -5
- package/dist/commands/channels.js.map +1 -1
- package/dist/commands/clean.d.ts.map +1 -1
- package/dist/commands/clean.js +58 -8
- package/dist/commands/clean.js.map +1 -1
- package/dist/commands/config.js +1 -1
- package/dist/commands/config.js.map +1 -1
- package/dist/commands/describe.d.ts.map +1 -1
- package/dist/commands/describe.js +12 -9
- package/dist/commands/describe.js.map +1 -1
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +37 -7
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/down-preserve.d.ts.map +1 -1
- package/dist/commands/down-preserve.js +14 -2
- package/dist/commands/down-preserve.js.map +1 -1
- package/dist/commands/down.d.ts.map +1 -1
- package/dist/commands/down.js +13 -3
- package/dist/commands/down.js.map +1 -1
- package/dist/commands/endpoint-authoring.d.ts.map +1 -1
- package/dist/commands/endpoint-authoring.js +6 -3
- package/dist/commands/endpoint-authoring.js.map +1 -1
- package/dist/commands/endpoint.d.ts.map +1 -1
- package/dist/commands/endpoint.js +9 -4
- package/dist/commands/endpoint.js.map +1 -1
- package/dist/commands/ext.js +4 -4
- package/dist/commands/ext.js.map +1 -1
- package/dist/commands/help.js +2 -2
- package/dist/commands/help.js.map +1 -1
- package/dist/commands/history.d.ts +1 -9
- package/dist/commands/history.d.ts.map +1 -1
- package/dist/commands/history.js +6 -16
- package/dist/commands/history.js.map +1 -1
- package/dist/commands/join.js +14 -5
- package/dist/commands/join.js.map +1 -1
- package/dist/commands/manager-service.d.ts.map +1 -1
- package/dist/commands/manager-service.js +9 -1
- package/dist/commands/manager-service.js.map +1 -1
- package/dist/commands/meshes.js +1 -1
- package/dist/commands/meshes.js.map +1 -1
- package/dist/commands/persona.d.ts.map +1 -1
- package/dist/commands/persona.js +25 -16
- package/dist/commands/persona.js.map +1 -1
- package/dist/commands/personas.js +3 -2
- package/dist/commands/personas.js.map +1 -1
- package/dist/commands/reset-space-apply.d.ts.map +1 -1
- package/dist/commands/reset-space-apply.js +4 -2
- package/dist/commands/reset-space-apply.js.map +1 -1
- package/dist/commands/reset-store-apply.d.ts.map +1 -1
- package/dist/commands/reset-store-apply.js +14 -6
- package/dist/commands/reset-store-apply.js.map +1 -1
- package/dist/commands/runtimes.d.ts +2 -2
- package/dist/commands/runtimes.d.ts.map +1 -1
- package/dist/commands/runtimes.js +27 -10
- package/dist/commands/runtimes.js.map +1 -1
- package/dist/commands/send.d.ts.map +1 -1
- package/dist/commands/send.js +2 -1
- package/dist/commands/send.js.map +1 -1
- package/dist/commands/service-actions.d.ts.map +1 -1
- package/dist/commands/service-actions.js +4 -3
- package/dist/commands/service-actions.js.map +1 -1
- package/dist/commands/service-registry.d.ts.map +1 -1
- package/dist/commands/service-registry.js +17 -9
- package/dist/commands/service-registry.js.map +1 -1
- package/dist/commands/setup.d.ts +5 -0
- package/dist/commands/setup.d.ts.map +1 -1
- package/dist/commands/setup.js +85 -3
- package/dist/commands/setup.js.map +1 -1
- package/dist/commands/space-delete.d.ts.map +1 -1
- package/dist/commands/space-delete.js +4 -2
- package/dist/commands/space-delete.js.map +1 -1
- package/dist/commands/space-registration.d.ts +1 -1
- package/dist/commands/space-registration.d.ts.map +1 -1
- package/dist/commands/space-registration.js +22 -6
- package/dist/commands/space-registration.js.map +1 -1
- package/dist/commands/space.d.ts.map +1 -1
- package/dist/commands/space.js +27 -10
- package/dist/commands/space.js.map +1 -1
- package/dist/commands/spawn-managed-launch.js +1 -1
- package/dist/commands/spawn-managed-launch.js.map +1 -1
- package/dist/commands/spawn-preview.d.ts.map +1 -1
- package/dist/commands/spawn-preview.js +23 -6
- package/dist/commands/spawn-preview.js.map +1 -1
- package/dist/commands/spawn.d.ts.map +1 -1
- package/dist/commands/spawn.js +19 -4
- package/dist/commands/spawn.js.map +1 -1
- package/dist/commands/stack-down.d.ts +1 -1
- package/dist/commands/stack-down.d.ts.map +1 -1
- package/dist/commands/stack-down.js +14 -6
- package/dist/commands/stack-down.js.map +1 -1
- package/dist/commands/stack-up.d.ts +1 -0
- package/dist/commands/stack-up.d.ts.map +1 -1
- package/dist/commands/stack-up.js +6 -4
- package/dist/commands/stack-up.js.map +1 -1
- package/dist/commands/status-health.d.ts +1 -1
- package/dist/commands/status-health.d.ts.map +1 -1
- package/dist/commands/status-health.js +46 -41
- package/dist/commands/status-health.js.map +1 -1
- package/dist/commands/status-meshes.d.ts +2 -0
- package/dist/commands/status-meshes.d.ts.map +1 -1
- package/dist/commands/status-meshes.js +13 -1
- package/dist/commands/status-meshes.js.map +1 -1
- package/dist/commands/status-model.d.ts +2 -0
- package/dist/commands/status-model.d.ts.map +1 -1
- package/dist/commands/status-model.js.map +1 -1
- package/dist/commands/status-render.d.ts.map +1 -1
- package/dist/commands/status-render.js +6 -3
- package/dist/commands/status-render.js.map +1 -1
- package/dist/commands/status.d.ts.map +1 -1
- package/dist/commands/status.js +9 -8
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/team-agent-remove.d.ts.map +1 -1
- package/dist/commands/team-agent-remove.js +4 -3
- package/dist/commands/team-agent-remove.js.map +1 -1
- package/dist/commands/team-boot-controller.js +1 -1
- package/dist/commands/team-boot-controller.js.map +1 -1
- package/dist/commands/team-channel-remove.d.ts.map +1 -1
- package/dist/commands/team-channel-remove.js +4 -3
- package/dist/commands/team-channel-remove.js.map +1 -1
- package/dist/commands/team-deploy-apply.js +5 -9
- package/dist/commands/team-deploy-apply.js.map +1 -1
- package/dist/commands/team-mixed-remove.d.ts.map +1 -1
- package/dist/commands/team-mixed-remove.js +4 -3
- package/dist/commands/team-mixed-remove.js.map +1 -1
- package/dist/commands/team.js +10 -5
- package/dist/commands/team.js.map +1 -1
- package/dist/commands/up-args.d.ts +1 -1
- package/dist/commands/up-args.d.ts.map +1 -1
- package/dist/commands/up-args.js +28 -13
- package/dist/commands/up-args.js.map +1 -1
- package/dist/commands/up-detach.d.ts +3 -0
- package/dist/commands/up-detach.d.ts.map +1 -1
- package/dist/commands/up-detach.js +3 -1
- package/dist/commands/up-detach.js.map +1 -1
- package/dist/commands/up-manifest.d.ts.map +1 -1
- package/dist/commands/up-manifest.js +5 -3
- package/dist/commands/up-manifest.js.map +1 -1
- package/dist/commands/up-resume.d.ts +59 -0
- package/dist/commands/up-resume.d.ts.map +1 -0
- package/dist/commands/up-resume.js +764 -0
- package/dist/commands/up-resume.js.map +1 -0
- package/dist/commands/up-target.d.ts +2 -0
- package/dist/commands/up-target.d.ts.map +1 -1
- package/dist/commands/up-target.js +10 -0
- package/dist/commands/up-target.js.map +1 -1
- package/dist/commands/up.d.ts.map +1 -1
- package/dist/commands/up.js +27 -773
- package/dist/commands/up.js.map +1 -1
- package/dist/commands/update-process.js +7 -6
- package/dist/commands/update-process.js.map +1 -1
- package/dist/commands/update-release.d.ts +6 -1
- package/dist/commands/update-release.d.ts.map +1 -1
- package/dist/commands/update-release.js +19 -5
- package/dist/commands/update-release.js.map +1 -1
- package/dist/commands/update.d.ts +3 -0
- package/dist/commands/update.d.ts.map +1 -1
- package/dist/commands/update.js +93 -69
- package/dist/commands/update.js.map +1 -1
- package/dist/commands/use.d.ts.map +1 -1
- package/dist/commands/use.js +8 -3
- package/dist/commands/use.js.map +1 -1
- package/dist/ext-loader.d.ts +10 -0
- package/dist/ext-loader.d.ts.map +1 -1
- package/dist/ext-loader.js +19 -0
- package/dist/ext-loader.js.map +1 -1
- package/dist/help.d.ts.map +1 -1
- package/dist/help.js +13 -4
- package/dist/help.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/choose-target.d.ts +1 -1
- package/dist/lib/choose-target.d.ts.map +1 -1
- package/dist/lib/choose-target.js +9 -5
- package/dist/lib/choose-target.js.map +1 -1
- package/dist/lib/completion-install.d.ts.map +1 -1
- package/dist/lib/completion-install.js +9 -4
- package/dist/lib/completion-install.js.map +1 -1
- package/dist/lib/confirmation-required.d.ts +7 -1
- package/dist/lib/confirmation-required.d.ts.map +1 -1
- package/dist/lib/confirmation-required.js +10 -3
- package/dist/lib/confirmation-required.js.map +1 -1
- package/dist/lib/delivery-proc.d.ts +1 -0
- package/dist/lib/delivery-proc.d.ts.map +1 -1
- package/dist/lib/endpoint-errors.d.ts +1 -0
- package/dist/lib/endpoint-errors.d.ts.map +1 -1
- package/dist/lib/endpoint-errors.js +9 -1
- package/dist/lib/endpoint-errors.js.map +1 -1
- package/dist/lib/endpoint-scatter.d.ts +1 -1
- package/dist/lib/endpoint-scatter.d.ts.map +1 -1
- package/dist/lib/endpoint-scatter.js +12 -2
- package/dist/lib/endpoint-scatter.js.map +1 -1
- package/dist/lib/endpoint-selection.js +1 -1
- package/dist/lib/endpoint-selection.js.map +1 -1
- package/dist/lib/follow-setup-failure.d.ts +23 -0
- package/dist/lib/follow-setup-failure.d.ts.map +1 -0
- package/dist/lib/follow-setup-failure.js +23 -0
- package/dist/lib/follow-setup-failure.js.map +1 -0
- package/dist/lib/manager-proc.d.ts +1 -0
- package/dist/lib/manager-proc.d.ts.map +1 -1
- package/dist/lib/manager-proc.js +7 -4
- package/dist/lib/manager-proc.js.map +1 -1
- package/dist/lib/npm-invocation.d.ts +2 -1
- package/dist/lib/npm-invocation.d.ts.map +1 -1
- package/dist/lib/npm-invocation.js +81 -11
- package/dist/lib/npm-invocation.js.map +1 -1
- package/dist/lib/persona-files.d.ts +11 -1
- package/dist/lib/persona-files.d.ts.map +1 -1
- package/dist/lib/persona-files.js +35 -11
- package/dist/lib/persona-files.js.map +1 -1
- package/dist/lib/personas.d.ts +1 -0
- package/dist/lib/personas.d.ts.map +1 -1
- package/dist/lib/personas.js +4 -1
- package/dist/lib/personas.js.map +1 -1
- package/dist/lib/self-exec.d.ts +1 -0
- package/dist/lib/self-exec.d.ts.map +1 -1
- package/dist/lib/self-exec.js +4 -1
- package/dist/lib/self-exec.js.map +1 -1
- package/dist/lib/service-preset-target.d.ts.map +1 -1
- package/dist/lib/service-preset-target.js +13 -2
- package/dist/lib/service-preset-target.js.map +1 -1
- package/dist/lib/service-start-options.d.ts +2 -0
- package/dist/lib/service-start-options.d.ts.map +1 -0
- package/dist/lib/service-start-options.js +4 -0
- package/dist/lib/service-start-options.js.map +1 -0
- package/dist/lib/spawn-defaults.d.ts +2 -0
- package/dist/lib/spawn-defaults.d.ts.map +1 -1
- package/dist/lib/spawn-defaults.js +10 -1
- package/dist/lib/spawn-defaults.js.map +1 -1
- package/dist/lib/stack-journal.js +2 -2
- package/dist/lib/stack-journal.js.map +1 -1
- package/dist/lib/status.d.ts +3 -0
- package/dist/lib/status.d.ts.map +1 -1
- package/dist/lib/status.js +17 -1
- package/dist/lib/status.js.map +1 -1
- package/dist/lib/store-dir.d.ts +1 -1
- package/dist/lib/store-dir.d.ts.map +1 -1
- package/dist/lib/store-dir.js +5 -2
- package/dist/lib/store-dir.js.map +1 -1
- package/dist/lib/team-deploy-inspection.d.ts +43 -37
- package/dist/lib/team-deploy-inspection.d.ts.map +1 -1
- package/dist/lib/team-deploy-inspection.js +53 -7
- package/dist/lib/team-deploy-inspection.js.map +1 -1
- package/dist/lib/up-manager-name.d.ts +4 -0
- package/dist/lib/up-manager-name.d.ts.map +1 -0
- package/dist/lib/up-manager-name.js +25 -0
- package/dist/lib/up-manager-name.js.map +1 -0
- package/dist/seed/reconcile.js +1 -1
- package/dist/seed/reconcile.js.map +1 -1
- package/dist/telemetry.d.ts +2 -3
- package/dist/telemetry.d.ts.map +1 -1
- package/dist/telemetry.js +26 -13
- package/dist/telemetry.js.map +1 -1
- package/package.json +5 -4
package/dist/command.js
CHANGED
|
@@ -3,7 +3,7 @@ import { homedir } from "node:os";
|
|
|
3
3
|
import { delimiter, 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, cotalDirProblem, cotalHomeProblem, findCotalRoot, disableColor, disableInput, envelopeLine, exitCode, failureEnvelope, GLOBAL_FLAGS, globalConfigDirProblem, globalFlagDeclarationProblems, hasMeshTargetFlags, inOperationSpace, isCommandFailure, checkServer, isConnectRefusal, isMeshRegistryError, isSeededCommand, isWorkspaceTargetError, localeIsUtf8, operationWarnings, outputDeclarationProblems, oneLine, paintFor, preferencesFolderWarning, recordOperationWarning, renderReport, renderWorkspaceError, runOperation, workspaceErrorParts, spaceRootTarget, targetErrorCode, targetErrorSpace, terminalWidth, userCotalDir, staleStoreHint, UnreadableConnectorSelection, } from "@cotal-ai/workspace";
|
|
6
|
+
import { CommandFailure, commandFailureReport, cachedPreferences, cotalDirProblem, cotalHomeProblem, findCotalRoot, disableColor, disableInput, envelopeLine, exitCode, failureEnvelope, GLOBAL_FLAGS, globalConfigDirProblem, globalFlagDeclarationProblems, hasMeshTargetFlags, inOperationSpace, isCommandFailure, checkServer, isConnectRefusal, isMeshRegistryError, isSeededCommand, isWorkspaceTargetError, jsonFlag, localeIsUtf8, operationWarnings, outputDeclarationProblems, oneLine, paintFor, preferencesFolderWarning, recordOperationWarning, renderReport, renderWorkspaceError, runOperation, workspaceErrorParts, spaceRootTarget, targetErrorCode, targetErrorSpace, terminalWidth, userCotalDir, staleStoreHint, UnreadableConnectorSelection, } from "@cotal-ai/workspace";
|
|
7
7
|
import { c, stderrLine } from "./ui.js";
|
|
8
8
|
import { debugFlag } from "./lib/debug-flag.js";
|
|
9
9
|
import { isExtensionStub, materializeExtension, materializeExtensionCommand, overlayExtensions, setCommandSurface, setInstalledExtensionsEnabled, } from "./ext-loader.js";
|
|
@@ -12,7 +12,7 @@ import { SeedChildFailure, deferredSeedRefusal, reconcileSeededConnectors, seedD
|
|
|
12
12
|
import { deferSeedToLaunch } from "./seed/launch.js";
|
|
13
13
|
import { isAuthenticSeedChild } from "./seed/lock.js";
|
|
14
14
|
import { printHelpPath, printEntry } from "./help.js";
|
|
15
|
-
import { historySetupFailureRecords } from "./
|
|
15
|
+
import { historySetupFailureRecords, membershipSetupFailureRecords } from "./lib/follow-setup-failure.js";
|
|
16
16
|
import { watchSetupFailureRecords } from "./commands/watch.js";
|
|
17
17
|
import { HISTORY_LIMIT_FLAGS } from "./commands/history-limit.js";
|
|
18
18
|
import { CatalogPreparationError, prepareCatalogCommand } from "./commands/sync.js";
|
|
@@ -24,7 +24,7 @@ import { FlagValueRefusal } from "./lib/flag-value-refusal.js";
|
|
|
24
24
|
import { workingFolderRemoved } from "./lib/paths.js";
|
|
25
25
|
import { reportLostOutput, writeAllSync } from "./lib/stdout-owner.js";
|
|
26
26
|
import { shellWord } from "./lib/endpoint-errors.js";
|
|
27
|
-
import { displayRemedy } from "./lib/self-exec.js";
|
|
27
|
+
import { displayRemedy, hasMovedStackRemedy } from "./lib/self-exec.js";
|
|
28
28
|
import { GLOBAL_FLAG_WORDS, OUTPUT_FLAG_WORDS } from "./lib/leading-flags.js";
|
|
29
29
|
import { takeManagedHandoffCustody } from "./managed-handoff.js";
|
|
30
30
|
import { nearestWords, LEADING_FLAGS, unknownCommandMessage, unknownSubcommandMessage } from "./lib/nearest-word.js";
|
|
@@ -53,20 +53,20 @@ function takeGlobalFlag(word) {
|
|
|
53
53
|
return false;
|
|
54
54
|
return true;
|
|
55
55
|
}
|
|
56
|
-
/**
|
|
57
|
-
function
|
|
58
|
-
const end = words.indexOf("--");
|
|
56
|
+
/** Collect globals before `--`; the parser still needs their original positions. */
|
|
57
|
+
function collectGlobalFlags(words, leading) {
|
|
59
58
|
const flags = new Set();
|
|
60
59
|
let repeated;
|
|
61
|
-
|
|
60
|
+
for (const word of words) {
|
|
61
|
+
if (word === "--")
|
|
62
|
+
break;
|
|
62
63
|
if (!GLOBAL_FLAG_WORDS.has(word))
|
|
63
|
-
|
|
64
|
+
continue;
|
|
64
65
|
if (leading.has(word) || flags.has(word))
|
|
65
66
|
repeated ??= word;
|
|
66
67
|
flags.add(word);
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
return { rest: end === -1 ? head : [...head, ...words.slice(end)], flags, repeated };
|
|
68
|
+
}
|
|
69
|
+
return { flags, repeated };
|
|
70
70
|
}
|
|
71
71
|
/** Whether `cmd` takes its words raw: it declares so, or it is an internal command, whose words are
|
|
72
72
|
* another command line. Such a command parses no flags of its own. */
|
|
@@ -78,11 +78,20 @@ async function repeatedGlobalFlag(word, cmd, words, warnings = []) {
|
|
|
78
78
|
const { cmd: found, rest } = await serviceSurface(takesWordsRaw(cmd) ? undefined : cmd, words, true);
|
|
79
79
|
const end = rest.indexOf("--");
|
|
80
80
|
const options = end === -1 ? rest : rest.slice(0, end);
|
|
81
|
+
// A global word in a string option's value slot cannot supply that value.
|
|
82
|
+
const tokens = found && parseArgs({ args: options, options: parserOptions(found), strict: false, allowPositionals: true, tokens: true }).tokens;
|
|
83
|
+
const missing = tokens?.find((token) => token.kind === "option" && token.inlineValue === false && token.value === word);
|
|
84
|
+
const flag = missing?.kind === "option" ? found?.flags?.find(({ name }) => name === missing.name) : undefined;
|
|
85
|
+
const refusal = flag && missing
|
|
86
|
+
? !flag.multiple && tokens?.some((token) => token.kind === "option" && token.name === flag.name && token.index < missing.index)
|
|
87
|
+
? { message: `--${flag.name} cannot be repeated`, remedy: `use --${flag.name} once` }
|
|
88
|
+
: missingValue(flag)
|
|
89
|
+
: { message: `Option '${word}' cannot be repeated` };
|
|
81
90
|
const json = found !== undefined && asksForJson(found, rest);
|
|
82
91
|
if (!json)
|
|
83
92
|
for (const warning of warnings)
|
|
84
93
|
console.error(c.red(`! ${warning.message}`));
|
|
85
|
-
return runOperation({ warnings }, () => usageExit(
|
|
94
|
+
return runOperation({ warnings }, () => usageExit(refusal.message, found, json, options.includes("--plain"), refusal.remedy, rest));
|
|
86
95
|
}
|
|
87
96
|
/** Whether the invoked mode declares a structured output, so it reports every outcome by the 0 to 5
|
|
88
97
|
* table: the subcommand `first` selects, else the command's bare form. */
|
|
@@ -105,9 +114,7 @@ function asksForJson(cmd, args) {
|
|
|
105
114
|
let json = false;
|
|
106
115
|
for (const ch of word.slice(1)) {
|
|
107
116
|
const type = shorts.get(ch);
|
|
108
|
-
if (type === undefined)
|
|
109
|
-
return false;
|
|
110
|
-
if (type === "string")
|
|
117
|
+
if (type === undefined || type === "string")
|
|
111
118
|
break;
|
|
112
119
|
if (ch === "j")
|
|
113
120
|
json = true;
|
|
@@ -153,10 +160,17 @@ function failureExit(cmd, failure, json, plain = false, scope, words = [], valid
|
|
|
153
160
|
// Mint receipts identify the operation, not the auth namespace used by account reports.
|
|
154
161
|
const command = cmd.name === "auth" && findSubcommand(cmd, metadataPositionals(cmd, words).positionals[0]?.value)?.name === "mint"
|
|
155
162
|
? "auth mint" : cmd.name;
|
|
156
|
-
const
|
|
163
|
+
const follow = validationArgs?.values.follow === true && validationArgs.values.plain !== true && !plain;
|
|
164
|
+
const historyFollow = cmd.name === "history" && follow
|
|
157
165
|
&& !findSubcommand(cmd, validationArgs.positionals[0]);
|
|
166
|
+
const membershipFollow = cmd.name === "channel" && follow && validationArgs.positionals[0] === "members";
|
|
167
|
+
const space = validationArgs?.values.space;
|
|
158
168
|
const records = historyFollow ? historySetupFailureRecords(validationArgs, failure)
|
|
159
|
-
:
|
|
169
|
+
: membershipFollow ? membershipSetupFailureRecords({
|
|
170
|
+
space: typeof space === "string" && space.trim() ? space : null,
|
|
171
|
+
channel: validationArgs.positionals[1]?.replace(/^#/, "") ?? null,
|
|
172
|
+
}, failure)
|
|
173
|
+
: cmd.name === "watch" && validationArgs && !plain ? watchSetupFailureRecords(validationArgs, failure) : undefined;
|
|
160
174
|
const lines = records ? records.map((record) => `${JSON.stringify(record)}\n`).join("") : envelopeLine(failureEnvelope(command, failure, warnings, scope));
|
|
161
175
|
writeAllSync(1, Buffer.from(lines));
|
|
162
176
|
}
|
|
@@ -377,13 +391,31 @@ function usageRefusal(failure, plain, cmd, words = []) {
|
|
|
377
391
|
console.error("");
|
|
378
392
|
paintFor(process.stderr, () => printHelpPath(cmd, helpPath(cmd, words).path, (line) => console.error(line), terminalWidth(process.stderr)));
|
|
379
393
|
}
|
|
394
|
+
/** Recover the requested stream output and target for a refusal, without running the command. */
|
|
395
|
+
function streamRefusalArgs(cmd, words) {
|
|
396
|
+
if (cmd.name !== "history" && cmd.name !== "channel" && cmd.name !== "watch")
|
|
397
|
+
return undefined;
|
|
398
|
+
const options = Object.fromEntries((cmd.flags ?? []).map(({ name, type, short }) => [name, { type, ...(short ? { short } : {}) }]));
|
|
399
|
+
const args = [...words];
|
|
400
|
+
for (;;) {
|
|
401
|
+
const { values, positionals, tokens } = parseArgs({ args, options, strict: false, allowPositionals: true, tokens: true });
|
|
402
|
+
// The loose parser consumes an option-looking word after a missing value. Leave that word
|
|
403
|
+
// available as an option (or the separator), as it is in the usage diagnostic.
|
|
404
|
+
const missing = tokens.find((token) => token.kind === "option" && token.inlineValue === false
|
|
405
|
+
&& token.value?.startsWith("-") && token.value !== "-"
|
|
406
|
+
&& !(args[token.index] === token.rawName && /^-\d/.test(token.value)));
|
|
407
|
+
if (!missing)
|
|
408
|
+
return values.json === true && (cmd.name === "watch" || values.follow === true)
|
|
409
|
+
? { values: values, positionals, raw: words } : undefined;
|
|
410
|
+
args.splice(missing.index + 1, 0, "");
|
|
411
|
+
}
|
|
412
|
+
}
|
|
380
413
|
/** A usage error, written by {@link usageRefusal} with the help of the command or subcommand `words`
|
|
381
414
|
* name when there is one, and with `remedy` under the message when the parser can name one. Exit 1. */
|
|
382
415
|
function usageExit(message, cmd, json = false, plain = false, remedy, words = []) {
|
|
383
|
-
// A JSON caller gets
|
|
384
|
-
// the remedy names stays out of it.
|
|
416
|
+
// A JSON caller gets only its receipt or stream records, without help text on stdout.
|
|
385
417
|
if (cmd && json)
|
|
386
|
-
failureExit(cmd, new CommandFailure("refused", "USAGE_INVALID", message, { remedy: remedy ?? `run \`cotal help ${cmd.name}\`` }), true, false, undefined, words);
|
|
418
|
+
failureExit(cmd, new CommandFailure("refused", "USAGE_INVALID", message, { remedy: remedy ?? `run \`cotal help ${cmd.name}\`` }), true, false, undefined, words, streamRefusalArgs(cmd, words));
|
|
387
419
|
recordTelemetryFailure("refused", "USAGE_INVALID", message);
|
|
388
420
|
// The help goes to stderr with the reason, so a refused run leaves stdout empty and a script that
|
|
389
421
|
// sources or parses it gets nothing.
|
|
@@ -448,25 +480,46 @@ function misspelledOption(cmd, rest, flagNames) {
|
|
|
448
480
|
}
|
|
449
481
|
return undefined;
|
|
450
482
|
}
|
|
483
|
+
function parserOptions(cmd) {
|
|
484
|
+
return Object.fromEntries((cmd.flags ?? []).map(({ name, type, short }) => [name, { type, ...(short ? { short } : {}) }]));
|
|
485
|
+
}
|
|
486
|
+
/** Strip standalone globals, but keep any global where a string option needs its value. */
|
|
487
|
+
function stripGlobalFlags(cmd, words) {
|
|
488
|
+
if (takesWordsRaw(cmd))
|
|
489
|
+
return words;
|
|
490
|
+
const end = words.indexOf("--");
|
|
491
|
+
const head = end === -1 ? words : words.slice(0, end);
|
|
492
|
+
if (!head.some((word) => GLOBAL_FLAG_WORDS.has(word)))
|
|
493
|
+
return words;
|
|
494
|
+
const { tokens } = parseArgs({ args: head, options: parserOptions(cmd), strict: false, allowPositionals: true, tokens: true });
|
|
495
|
+
const globals = new Set(tokens.filter((token) => token.kind === "option" && GLOBAL_FLAG_WORDS.has(head[token.index])).map((token) => token.index));
|
|
496
|
+
return words.filter((_, index) => !globals.has(index));
|
|
497
|
+
}
|
|
498
|
+
function missingValue(flag, beforeSeparator = false) {
|
|
499
|
+
return { message: `--${flag.name} needs a value`, remedy: `write --${flag.name} ${flag.value ?? "<value>"}${beforeSeparator ? " before --" : ""}` };
|
|
500
|
+
}
|
|
451
501
|
/** A parse error as a refusal. A mistyped option names its spelling. A word that starts with `-`
|
|
452
|
-
* goes after `--` only where the command
|
|
502
|
+
* goes after `--` only where the command has room for an operand and there is no spelling suggestion.
|
|
453
503
|
* An option value that starts with `-` is written `--name=value`, and an option given with no value,
|
|
454
504
|
* last, before `--`, or before another of the command's options, is named with its placeholder. */
|
|
455
|
-
function parseRefusal(error, cmd, rest, flagNames, takesOperands) {
|
|
505
|
+
function parseRefusal(error, cmd, rest, flagNames, takesOperands, operandsFull) {
|
|
456
506
|
if (error.code === "ERR_PARSE_ARGS_UNKNOWN_OPTION") {
|
|
457
507
|
const reason = error.message.replace(/'\. To specify a positional argument starting with a '-', place it at the end of the command after '--', as in '-- "(?:[^"\\]|\\.)*"$/u, "'");
|
|
458
508
|
const option = /^Unknown option '(--.+)'$/su.exec(reason)?.[1];
|
|
459
509
|
const nearest = option ? nearestWords(option, [...(flagNames ?? (cmd.flags ?? []).map((flag) => flag.name)).map((name) => `--${name}`), "--no-color", "--no-input", "--help"]) : [];
|
|
460
510
|
const spellings = nearest.join(" or ");
|
|
511
|
+
const flag = cmd.flags?.find((item) => `--${item.name}` === spellings);
|
|
512
|
+
if (flag?.type === "boolean" && !flag.multiple && parseArgs({ args: [...rest], options: parserOptions(cmd), strict: false, allowPositionals: true }).values[flag.name] === true)
|
|
513
|
+
return { message: reason, remedy: `drop the unknown option; --${flag.name} is already set` };
|
|
461
514
|
const message = spellings ? `${reason} - did you mean ${spellings}?` : reason;
|
|
462
515
|
const remedy = cmd.name === "completion" ? "drop the unknown option"
|
|
463
|
-
: !takesOperands ? undefined : spellings ? `use ${spellings}`
|
|
516
|
+
: !takesOperands ? undefined : spellings ? `use ${spellings}`
|
|
517
|
+
: operandsFull ? "drop the unknown option" : "to pass a word that starts with \"-\", put -- before it";
|
|
464
518
|
return { message, remedy };
|
|
465
519
|
}
|
|
466
520
|
if (error.code === "ERR_PARSE_ARGS_UNEXPECTED_POSITIONAL") {
|
|
467
521
|
return { message: error.message.replace(/\. This command does not take positional arguments\.?$/u, "") };
|
|
468
522
|
}
|
|
469
|
-
const missingValue = (flag, beforeSeparator = false) => ({ message: `--${flag.name} needs a value`, remedy: `write --${flag.name} ${flag.value ?? "<value>"}${beforeSeparator ? " before --" : ""}` });
|
|
470
523
|
const bare = /^Option '(?:-[^,']+, )?--([^ ']+) <value>' argument missing/.exec(error.message)?.[1];
|
|
471
524
|
const last = bare === undefined ? undefined : cmd.flags?.find((item) => item.name === bare);
|
|
472
525
|
if (error.code === "ERR_PARSE_ARGS_INVALID_OPTION_VALUE" && last)
|
|
@@ -474,7 +527,7 @@ function parseRefusal(error, cmd, rest, flagNames, takesOperands) {
|
|
|
474
527
|
const long = /use '--([^=']+)=-XYZ'/.exec(error.message)?.[1];
|
|
475
528
|
const flag = long === undefined ? undefined : cmd.flags?.find((item) => item.name === long);
|
|
476
529
|
if (error.code === "ERR_PARSE_ARGS_INVALID_OPTION_VALUE" && flag) {
|
|
477
|
-
const options =
|
|
530
|
+
const options = parserOptions(cmd);
|
|
478
531
|
const { tokens } = parseArgs({ args: [...rest], options, strict: false, allowPositionals: true, tokens: true });
|
|
479
532
|
let seen = false;
|
|
480
533
|
for (const token of tokens) {
|
|
@@ -488,6 +541,8 @@ function parseRefusal(error, cmd, rest, flagNames, takesOperands) {
|
|
|
488
541
|
return { message: `--${flag.name} cannot be repeated`, remedy: `use --${flag.name} once` };
|
|
489
542
|
if (value === "--")
|
|
490
543
|
return missingValue(flag, true);
|
|
544
|
+
if (GLOBAL_FLAG_WORDS.has(value))
|
|
545
|
+
return missingValue(flag);
|
|
491
546
|
const next = parseArgs({ args: [value], options, strict: false, allowPositionals: true, tokens: true });
|
|
492
547
|
if (next.tokens.every((item) => item.kind === "option" && Object.hasOwn(options, item.name)))
|
|
493
548
|
return missingValue(flag);
|
|
@@ -500,6 +555,7 @@ function parseRefusal(error, cmd, rest, flagNames, takesOperands) {
|
|
|
500
555
|
}
|
|
501
556
|
/** `rest` parsed against `cmd`'s declared flags, positionals and subcommands, or a usage exit. */
|
|
502
557
|
function parseOrExit(cmd, rest) {
|
|
558
|
+
rest = stripGlobalFlags(cmd, rest);
|
|
503
559
|
const seed = extSeedSubcommand(cmd, rest);
|
|
504
560
|
const json = !seed && asksForJson(cmd, rest);
|
|
505
561
|
const plain = !seed && rest.includes("--plain");
|
|
@@ -524,15 +580,14 @@ function parseOrExit(cmd, rest) {
|
|
|
524
580
|
}
|
|
525
581
|
const takesOperands = !seed && cmd.positionals !== undefined &&
|
|
526
582
|
(!cmd.subcommands?.length || cmd.name === "history" || (first !== undefined && findSubcommand(cmd, first) !== undefined));
|
|
527
|
-
const
|
|
583
|
+
const operandsFull = cmd.name === "config" && selected.name === "get" && positionals.length >= 2;
|
|
584
|
+
const refusal = parseRefusal(e, cmd, rest, seed?.flagNames ?? selected.flagNames, takesOperands, operandsFull);
|
|
528
585
|
usageExit(refusal.message, cmd, json, plain, refusal.remedy, rest);
|
|
529
586
|
}
|
|
530
587
|
throw e;
|
|
531
588
|
}
|
|
532
589
|
const first = parsed.positionals[0];
|
|
533
|
-
|
|
534
|
-
if (cmd.subcommands?.length && first !== undefined && cmd.name !== "history" && !findSubcommand(cmd, first))
|
|
535
|
-
usageExit(unknownSubcommandMessage(cmd.name, cmd, first), cmd, json, plain);
|
|
590
|
+
const canonical = canonicalSubcommand(cmd, parsed, json, plain);
|
|
536
591
|
// Target resolution reads an empty space as no space and falls back to the selected one, so a script
|
|
537
592
|
// whose variable is unset would act on whichever space is selected.
|
|
538
593
|
const spaceFlag = cmd.flags?.find((flag) => flag.name === "space");
|
|
@@ -546,7 +601,6 @@ function parseOrExit(cmd, rest) {
|
|
|
546
601
|
// `--json` implies `--no-input`: a script reading one document cannot answer a prompt.
|
|
547
602
|
if (structured(cmd, first) && parsed.values.json === true)
|
|
548
603
|
disableInput();
|
|
549
|
-
const canonical = canonicalSubcommand(cmd, parsed);
|
|
550
604
|
refuseRemovedFolder(cmd, canonical, rest);
|
|
551
605
|
try {
|
|
552
606
|
cmd.validate?.(canonical);
|
|
@@ -603,21 +657,26 @@ function refuseRemovedFolder(cmd, parsed, rest) {
|
|
|
603
657
|
return;
|
|
604
658
|
failureExit(cmd, new CommandFailure("refused", "USAGE_INVALID", "this folder no longer exists", { remedy: "cd to an existing folder and run the command again", selfContained: true }), structured(cmd, parsed.positionals[0]) && parsed.values.json === true, parsed.values.plain === true, undefined, rest);
|
|
605
659
|
}
|
|
606
|
-
/**
|
|
607
|
-
|
|
608
|
-
function canonicalSubcommand(cmd, parsed) {
|
|
660
|
+
/** Resolve subcommand aliases and refuse a word that names no subcommand before checking operands. */
|
|
661
|
+
function canonicalSubcommand(cmd, parsed, json, plain) {
|
|
609
662
|
const positionals = [...parsed.positionals];
|
|
610
663
|
let surface = cmd;
|
|
611
664
|
let changed = false;
|
|
612
|
-
for (let index = 0; index < positionals.length; index++) {
|
|
613
|
-
const
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
665
|
+
for (let index = 0; index < positionals.length && surface.subcommands?.length; index++) {
|
|
666
|
+
const word = positionals[index];
|
|
667
|
+
const sub = findSubcommand(surface, word);
|
|
668
|
+
if (!sub) {
|
|
669
|
+
// History also accepts a channel as its first positional.
|
|
670
|
+
if (index === 0 && cmd.name === "history")
|
|
671
|
+
break;
|
|
672
|
+
const message = unknownSubcommandMessage([cmd.name, ...positionals.slice(0, index)].join(" "), surface, word);
|
|
673
|
+
if (index === 0)
|
|
674
|
+
usageExit(message, cmd, json, plain);
|
|
675
|
+
failureExit(cmd, new CommandFailure("refused", "USAGE_INVALID", message), json, plain, undefined, parsed.raw);
|
|
676
|
+
}
|
|
677
|
+
changed ||= sub.name !== word;
|
|
617
678
|
positionals[index] = sub.name;
|
|
618
679
|
surface = sub;
|
|
619
|
-
if (!sub.subcommands?.length)
|
|
620
|
-
break;
|
|
621
680
|
}
|
|
622
681
|
return changed ? { ...parsed, positionals } : parsed;
|
|
623
682
|
}
|
|
@@ -664,7 +723,7 @@ async function serviceSurface(found, words, forRefusal = false) {
|
|
|
664
723
|
if (forRefusal || asksForHelp(words))
|
|
665
724
|
return { cmd: found, rest: words };
|
|
666
725
|
const failure = isCommandFailure(error) ? error : new CommandFailure("refused", "SCHEMA_INVALID", "service preset metadata could not be read; no provider was imported or installed");
|
|
667
|
-
return failureExit(found, failure, asksForJson(found, words), words.includes("--plain"));
|
|
726
|
+
return failureExit(found, failure, asksForJson(found, words), words.includes("--plain"), undefined, words);
|
|
668
727
|
}
|
|
669
728
|
}
|
|
670
729
|
/**
|
|
@@ -706,13 +765,12 @@ export async function runCli(registry, argv, opts = {}) {
|
|
|
706
765
|
: original === "--help" || original === "-h" ? "help" : original;
|
|
707
766
|
const words = [...output, ...argv.slice(lead + 1)];
|
|
708
767
|
const builtin = findCommand(registry.all("command"), word);
|
|
709
|
-
const globals =
|
|
768
|
+
const globals = collectGlobalFlags(words, leadingGlobals);
|
|
710
769
|
const ownWords = (cmd) => {
|
|
711
|
-
if (takesWordsRaw(cmd))
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
return [...globals.rest];
|
|
770
|
+
if (!takesWordsRaw(cmd))
|
|
771
|
+
for (const option of globals.flags)
|
|
772
|
+
takeGlobalFlag(option);
|
|
773
|
+
return [...words];
|
|
716
774
|
};
|
|
717
775
|
const duplicate = (cmd) => repeatedLeading ?? (takesWordsRaw(cmd) ? undefined : globals.repeated);
|
|
718
776
|
if (repeatedLeading && (word === undefined || takesWordsRaw(builtin)))
|
|
@@ -863,7 +921,9 @@ export async function runCli(registry, argv, opts = {}) {
|
|
|
863
921
|
const awaitingSeed = !cmd && opts.extensions === true && isSeededCommand(word) && !wantsHelp && !skipsSeed(word, rest[0], rest);
|
|
864
922
|
// A leading flag typed with a typographic dash is read as the command word, so it is refused as the
|
|
865
923
|
// same word after the command word is.
|
|
866
|
-
const typed = cmd || awaitingSeed ? undefined : typographicOption(word, new Set(LEADING_FLAGS.map((flag) => flag.slice(2)))
|
|
924
|
+
const typed = cmd || awaitingSeed ? undefined : typographicOption(word, new Set(LEADING_FLAGS.map((flag) => flag.slice(2))), [
|
|
925
|
+
jsonFlag, { name: "help", short: "h", type: "boolean" }, { name: "version", short: "V", type: "boolean" },
|
|
926
|
+
]);
|
|
867
927
|
if (typed)
|
|
868
928
|
usageExit(typed.message, undefined, false, false, typed.remedy);
|
|
869
929
|
if (!cmd && !awaitingSeed)
|
|
@@ -964,7 +1024,7 @@ export async function runCli(registry, argv, opts = {}) {
|
|
|
964
1024
|
// uses its selected home, not the invoking project's records.
|
|
965
1025
|
const dirProblem = cmd.name === "version" || cmd.name === "daemon" || workingFolderRemoved() ? undefined : cotalDirProblem(typeof parsed.values.root === "string" ? resolve(parsed.values.root) : findCotalRoot());
|
|
966
1026
|
if (dirProblem)
|
|
967
|
-
failureExit(cmd, new CommandFailure("refused", "CONFLICT", `${dirProblem}; the command did not run`, { remedy: "rename or move that file, then run the command again" }), structured(cmd, parsed.positionals[0]) && parsed.values.json === true, parsed.values.plain === true, undefined, rest);
|
|
1027
|
+
failureExit(cmd, new CommandFailure("refused", "CONFLICT", `${dirProblem}; the command did not run`, { remedy: "rename or move that file, then run the command again" }), structured(cmd, parsed.positionals[0]) && parsed.values.json === true, parsed.values.plain === true, undefined, rest, parsed);
|
|
968
1028
|
if (!["version", "docs", "status", "daemon"].includes(cmd.name)) {
|
|
969
1029
|
try {
|
|
970
1030
|
cachedPreferences();
|
|
@@ -990,8 +1050,13 @@ export async function runCli(registry, argv, opts = {}) {
|
|
|
990
1050
|
// them says so, with the change that protects their folder.
|
|
991
1051
|
if (!cmd.name.startsWith("__") && !["help", "completion", "version", "docs"].includes(cmd.name)) {
|
|
992
1052
|
const folder = preferencesFolderWarning();
|
|
1053
|
+
// Under --json the warning lives in the envelope only: an immediate echo would put it on
|
|
1054
|
+
// stderr as well, so a JSON refusal would break the "envelope on stdout, nothing on
|
|
1055
|
+
// stderr" contract (docs/UPGRADING.md, "JSON refusals after 0.100.2"). Human mode still
|
|
1056
|
+
// prints it at once, as before.
|
|
1057
|
+
const jsonOutput = structured(cmd, parsed.positionals[0]) && parsed.values.json === true;
|
|
993
1058
|
if (folder)
|
|
994
|
-
recordOperationWarning(folder.warning);
|
|
1059
|
+
recordOperationWarning(folder.warning, { echo: !jsonOutput });
|
|
995
1060
|
}
|
|
996
1061
|
if (cmd.prepare)
|
|
997
1062
|
await cmd.prepare(parsed);
|
|
@@ -1036,8 +1101,10 @@ export async function runCli(registry, argv, opts = {}) {
|
|
|
1036
1101
|
// not resolve or connect to is refused before any request, under the refusal's own code; a
|
|
1037
1102
|
// failure it did not classify is unknown: it may have had effects that cannot be attributed.
|
|
1038
1103
|
if (structured(cmd, mode)) {
|
|
1039
|
-
const
|
|
1040
|
-
const
|
|
1104
|
+
const targetError = isConnectRefusal(e) ? e.cause : e;
|
|
1105
|
+
const spaceRemedy = spaceChoiceRemedy(targetError, cmd.name, parsed, rest);
|
|
1106
|
+
const renderRemedy = spaceRemedy !== undefined ? () => spaceRemedy
|
|
1107
|
+
: hasMovedStackRemedy(targetError) || ["status", "ps", "space", "whoami"].includes(cmd.name) ? displayRemedy : undefined;
|
|
1041
1108
|
if (isConnectRefusal(e)) {
|
|
1042
1109
|
const failure = e.failure(renderRemedy), cause = e.cause;
|
|
1043
1110
|
if (isWorkspaceTargetError(cause) && cause.code === "not-started" && cause.details.stopped && !cause.details.unsettled && cause.details.root && cause.details.space) {
|