@cotal-ai/cli 0.182.0 → 0.183.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/command.d.ts.map +1 -1
- package/dist/command.js +347 -179
- package/dist/command.js.map +1 -1
- package/dist/commands/agents.d.ts.map +1 -1
- package/dist/commands/agents.js +70 -14
- package/dist/commands/agents.js.map +1 -1
- package/dist/commands/app-identity.d.ts +1 -0
- package/dist/commands/app-identity.d.ts.map +1 -1
- package/dist/commands/app-identity.js +1 -1
- package/dist/commands/app-identity.js.map +1 -1
- package/dist/commands/backup-maintenance.d.ts.map +1 -1
- package/dist/commands/backup-maintenance.js +9 -7
- package/dist/commands/backup-maintenance.js.map +1 -1
- package/dist/commands/backup.d.ts.map +1 -1
- package/dist/commands/backup.js +51 -23
- package/dist/commands/backup.js.map +1 -1
- package/dist/commands/clean.d.ts.map +1 -1
- package/dist/commands/clean.js +8 -2
- package/dist/commands/clean.js.map +1 -1
- package/dist/commands/down.d.ts.map +1 -1
- package/dist/commands/down.js +12 -3
- package/dist/commands/down.js.map +1 -1
- package/dist/commands/ext.d.ts +4 -2
- package/dist/commands/ext.d.ts.map +1 -1
- package/dist/commands/ext.js +62 -15
- package/dist/commands/ext.js.map +1 -1
- package/dist/commands/help.js +1 -1
- package/dist/commands/help.js.map +1 -1
- package/dist/commands/history.d.ts.map +1 -1
- package/dist/commands/history.js +5 -1
- package/dist/commands/history.js.map +1 -1
- package/dist/commands/join.js +1 -1
- package/dist/commands/join.js.map +1 -1
- package/dist/commands/meshes.d.ts.map +1 -1
- package/dist/commands/meshes.js +2 -1
- package/dist/commands/meshes.js.map +1 -1
- package/dist/commands/mint.js +27 -26
- package/dist/commands/mint.js.map +1 -1
- package/dist/commands/persona.d.ts +2 -2
- package/dist/commands/persona.d.ts.map +1 -1
- package/dist/commands/persona.js +4 -3
- package/dist/commands/persona.js.map +1 -1
- package/dist/commands/send.d.ts.map +1 -1
- package/dist/commands/send.js +9 -7
- package/dist/commands/send.js.map +1 -1
- package/dist/commands/service-registry.d.ts +1 -1
- package/dist/commands/service-registry.js +1 -1
- package/dist/commands/service-registry.js.map +1 -1
- package/dist/commands/setup-current-connectors.d.ts +7 -0
- package/dist/commands/setup-current-connectors.d.ts.map +1 -0
- package/dist/commands/setup-current-connectors.js +31 -0
- package/dist/commands/setup-current-connectors.js.map +1 -0
- package/dist/commands/setup.d.ts +1 -0
- package/dist/commands/setup.d.ts.map +1 -1
- package/dist/commands/setup.js +43 -14
- package/dist/commands/setup.js.map +1 -1
- package/dist/commands/space-registration.d.ts.map +1 -1
- package/dist/commands/space-registration.js +6 -1
- package/dist/commands/space-registration.js.map +1 -1
- package/dist/commands/spawn-flags.d.ts +1 -1
- package/dist/commands/spawn-flags.d.ts.map +1 -1
- package/dist/commands/spawn-flags.js +11 -3
- package/dist/commands/spawn-flags.js.map +1 -1
- package/dist/commands/spawn-managed-launch.d.ts.map +1 -1
- package/dist/commands/spawn-managed-launch.js +3 -2
- 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 +21 -4
- package/dist/commands/spawn-preview.js.map +1 -1
- package/dist/commands/spawn.d.ts +2 -15
- package/dist/commands/spawn.d.ts.map +1 -1
- package/dist/commands/spawn.js +117 -120
- package/dist/commands/spawn.js.map +1 -1
- package/dist/commands/stack-down.d.ts.map +1 -1
- package/dist/commands/stack-down.js +24 -12
- package/dist/commands/stack-down.js.map +1 -1
- package/dist/commands/stack-lost-records.d.ts +12 -0
- package/dist/commands/stack-lost-records.d.ts.map +1 -1
- package/dist/commands/stack-lost-records.js +31 -10
- package/dist/commands/stack-lost-records.js.map +1 -1
- package/dist/commands/stack-up.d.ts +1 -1
- package/dist/commands/stack-up.d.ts.map +1 -1
- package/dist/commands/stack-up.js +22 -10
- package/dist/commands/stack-up.js.map +1 -1
- package/dist/commands/stack-user-auth.d.ts +2 -2
- package/dist/commands/stack-user-auth.d.ts.map +1 -1
- package/dist/commands/stack-user-auth.js +6 -3
- package/dist/commands/stack-user-auth.js.map +1 -1
- package/dist/commands/status-health.d.ts +4 -1
- package/dist/commands/status-health.d.ts.map +1 -1
- package/dist/commands/status-health.js +4 -1
- package/dist/commands/status-health.js.map +1 -1
- package/dist/commands/status-meshes.d.ts +4 -1
- package/dist/commands/status-meshes.d.ts.map +1 -1
- package/dist/commands/status-meshes.js +8 -3
- package/dist/commands/status-meshes.js.map +1 -1
- package/dist/commands/status.d.ts.map +1 -1
- package/dist/commands/status.js +16 -11
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/sync.d.ts.map +1 -1
- package/dist/commands/sync.js +2 -2
- package/dist/commands/sync.js.map +1 -1
- package/dist/commands/team-boot-controller.d.ts.map +1 -1
- package/dist/commands/team-boot-controller.js +2 -1
- package/dist/commands/team-boot-controller.js.map +1 -1
- package/dist/commands/team.js +6 -6
- package/dist/commands/team.js.map +1 -1
- package/dist/commands/topology.d.ts.map +1 -1
- package/dist/commands/topology.js +3 -2
- package/dist/commands/topology.js.map +1 -1
- package/dist/commands/trust.d.ts +27 -0
- package/dist/commands/trust.d.ts.map +1 -0
- package/dist/commands/trust.js +39 -0
- package/dist/commands/trust.js.map +1 -0
- package/dist/commands/up-detach.d.ts.map +1 -1
- package/dist/commands/up-detach.js +5 -1
- package/dist/commands/up-detach.js.map +1 -1
- package/dist/commands/up-foreground-listener.d.ts +20 -0
- package/dist/commands/up-foreground-listener.d.ts.map +1 -0
- package/dist/commands/up-foreground-listener.js +156 -0
- package/dist/commands/up-foreground-listener.js.map +1 -0
- package/dist/commands/up-manifest.d.ts.map +1 -1
- package/dist/commands/up-manifest.js +4 -5
- package/dist/commands/up-manifest.js.map +1 -1
- package/dist/commands/up-project-trust.d.ts +8 -0
- package/dist/commands/up-project-trust.d.ts.map +1 -0
- package/dist/commands/up-project-trust.js +35 -0
- package/dist/commands/up-project-trust.js.map +1 -0
- package/dist/commands/up-resume.d.ts +1 -1
- package/dist/commands/up-resume.d.ts.map +1 -1
- package/dist/commands/up-resume.js +12 -5
- package/dist/commands/up-resume.js.map +1 -1
- package/dist/commands/up.d.ts.map +1 -1
- package/dist/commands/up.js +30 -150
- package/dist/commands/up.js.map +1 -1
- package/dist/commands/update-continuity.d.ts +4 -0
- package/dist/commands/update-continuity.d.ts.map +1 -1
- package/dist/commands/update-continuity.js +54 -1
- package/dist/commands/update-continuity.js.map +1 -1
- package/dist/commands/update-offline.d.ts +4 -0
- package/dist/commands/update-offline.d.ts.map +1 -0
- package/dist/commands/update-offline.js +39 -0
- package/dist/commands/update-offline.js.map +1 -0
- package/dist/commands/update-process.d.ts.map +1 -1
- package/dist/commands/update-process.js +11 -8
- package/dist/commands/update-process.js.map +1 -1
- package/dist/commands/update.d.ts.map +1 -1
- package/dist/commands/update.js +24 -67
- package/dist/commands/update.js.map +1 -1
- package/dist/console/app.d.ts.map +1 -1
- package/dist/console/app.js +2 -1
- package/dist/console/app.js.map +1 -1
- package/dist/console/mesh.d.ts +1 -1
- package/dist/console/mesh.d.ts.map +1 -1
- package/dist/console/mesh.js +1 -1
- package/dist/console/mesh.js.map +1 -1
- package/dist/console/ui/CommandPalette.d.ts +2 -1
- package/dist/console/ui/CommandPalette.d.ts.map +1 -1
- package/dist/console/ui/CommandPalette.js +4 -4
- package/dist/console/ui/CommandPalette.js.map +1 -1
- package/dist/help.d.ts +1 -6
- package/dist/help.d.ts.map +1 -1
- package/dist/help.js +26 -4
- package/dist/help.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -4
- package/dist/index.js.map +1 -1
- package/dist/lib/app-user-identity.d.ts +10 -13
- package/dist/lib/app-user-identity.d.ts.map +1 -1
- package/dist/lib/app-user-identity.js +237 -59
- package/dist/lib/app-user-identity.js.map +1 -1
- package/dist/lib/choose-target.d.ts.map +1 -1
- package/dist/lib/choose-target.js +1 -0
- package/dist/lib/choose-target.js.map +1 -1
- package/dist/lib/command-path.d.ts +6 -0
- package/dist/lib/command-path.d.ts.map +1 -1
- package/dist/lib/command-path.js +3 -0
- package/dist/lib/command-path.js.map +1 -1
- package/dist/lib/completion-scripts.d.ts.map +1 -1
- package/dist/lib/completion-scripts.js +1 -1
- package/dist/lib/completion-scripts.js.map +1 -1
- package/dist/lib/conversation-identity.d.ts +2 -1
- package/dist/lib/conversation-identity.d.ts.map +1 -1
- package/dist/lib/conversation-identity.js +1 -1
- package/dist/lib/conversation-identity.js.map +1 -1
- package/dist/lib/conversation-resume.d.ts +30 -0
- package/dist/lib/conversation-resume.d.ts.map +1 -0
- package/dist/lib/conversation-resume.js +73 -0
- package/dist/lib/conversation-resume.js.map +1 -0
- package/dist/lib/endpoint-errors.d.ts.map +1 -1
- package/dist/lib/endpoint-errors.js +17 -2
- package/dist/lib/endpoint-errors.js.map +1 -1
- package/dist/lib/extension-core-peer.d.ts +2 -0
- package/dist/lib/extension-core-peer.d.ts.map +1 -0
- package/dist/lib/extension-core-peer.js +23 -0
- package/dist/lib/extension-core-peer.js.map +1 -0
- package/dist/lib/extension-stage.d.ts +1 -1
- package/dist/lib/extension-stage.d.ts.map +1 -1
- package/dist/lib/extension-stage.js +20 -8
- package/dist/lib/extension-stage.js.map +1 -1
- package/dist/lib/foreground-hold.d.ts +2 -2
- package/dist/lib/foreground-hold.d.ts.map +1 -1
- package/dist/lib/foreground-hold.js +31 -9
- package/dist/lib/foreground-hold.js.map +1 -1
- package/dist/lib/hermes-windows-host.d.ts +8 -0
- package/dist/lib/hermes-windows-host.d.ts.map +1 -0
- package/dist/lib/hermes-windows-host.js +85 -0
- package/dist/lib/hermes-windows-host.js.map +1 -0
- package/dist/lib/hermes-windows-preload.d.ts +2 -0
- package/dist/lib/hermes-windows-preload.d.ts.map +1 -0
- package/dist/lib/hermes-windows-preload.js +7 -0
- package/dist/lib/hermes-windows-preload.js.map +1 -0
- package/dist/lib/history-command.d.ts +2 -1
- package/dist/lib/history-command.d.ts.map +1 -1
- package/dist/lib/history-command.js +4 -2
- package/dist/lib/history-command.js.map +1 -1
- package/dist/lib/isolated-broker.d.ts.map +1 -1
- package/dist/lib/isolated-broker.js +80 -31
- package/dist/lib/isolated-broker.js.map +1 -1
- package/dist/lib/leading-flags.d.ts +1 -0
- package/dist/lib/leading-flags.d.ts.map +1 -1
- package/dist/lib/leading-flags.js +13 -2
- package/dist/lib/leading-flags.js.map +1 -1
- package/dist/lib/manifest/index.d.ts +1 -1
- package/dist/lib/manifest/index.d.ts.map +1 -1
- package/dist/lib/manifest/index.js +3 -3
- package/dist/lib/manifest/index.js.map +1 -1
- package/dist/lib/manifest/preflight.d.ts +1 -1
- package/dist/lib/manifest/preflight.d.ts.map +1 -1
- package/dist/lib/manifest/preflight.js +14 -4
- package/dist/lib/manifest/preflight.js.map +1 -1
- package/dist/lib/npm-invocation.d.ts +13 -9
- package/dist/lib/npm-invocation.d.ts.map +1 -1
- package/dist/lib/npm-invocation.js +66 -17
- package/dist/lib/npm-invocation.js.map +1 -1
- package/dist/lib/paths.d.ts +1 -1
- package/dist/lib/paths.d.ts.map +1 -1
- package/dist/lib/paths.js +3 -3
- package/dist/lib/paths.js.map +1 -1
- package/dist/lib/persona-files.d.ts.map +1 -1
- package/dist/lib/persona-files.js +17 -1
- package/dist/lib/persona-files.js.map +1 -1
- package/dist/lib/personas.d.ts +3 -4
- package/dist/lib/personas.d.ts.map +1 -1
- package/dist/lib/personas.js +6 -5
- package/dist/lib/personas.js.map +1 -1
- package/dist/lib/restore.d.ts +6 -2
- package/dist/lib/restore.d.ts.map +1 -1
- package/dist/lib/restore.js +29 -15
- package/dist/lib/restore.js.map +1 -1
- package/dist/lib/self-exec.d.ts +4 -2
- package/dist/lib/self-exec.d.ts.map +1 -1
- package/dist/lib/self-exec.js +9 -4
- package/dist/lib/self-exec.js.map +1 -1
- package/dist/lib/service-process.d.ts.map +1 -1
- package/dist/lib/service-process.js +12 -3
- package/dist/lib/service-process.js.map +1 -1
- package/dist/lib/service-start-options.d.ts +1 -0
- package/dist/lib/service-start-options.d.ts.map +1 -1
- package/dist/lib/service-start-options.js +3 -0
- package/dist/lib/service-start-options.js.map +1 -1
- package/dist/lib/stack-journal.d.ts +2 -2
- package/dist/lib/stack-journal.d.ts.map +1 -1
- package/dist/lib/stack-journal.js +22 -8
- package/dist/lib/stack-journal.js.map +1 -1
- package/dist/lib/stdout-owner.d.ts +5 -0
- package/dist/lib/stdout-owner.d.ts.map +1 -1
- package/dist/lib/stdout-owner.js +33 -1
- package/dist/lib/stdout-owner.js.map +1 -1
- package/dist/lib/team-deploy-inspection.js +1 -1
- package/dist/lib/team-deploy-inspection.js.map +1 -1
- package/dist/lib/update-connector-config.d.ts +4 -1
- package/dist/lib/update-connector-config.d.ts.map +1 -1
- package/dist/lib/update-connector-config.js +32 -4
- package/dist/lib/update-connector-config.js.map +1 -1
- package/dist/lib/update-manager-install-linux.d.ts +8 -0
- package/dist/lib/update-manager-install-linux.d.ts.map +1 -0
- package/dist/lib/update-manager-install-linux.js +128 -0
- package/dist/lib/update-manager-install-linux.js.map +1 -0
- package/dist/lib/update-managers.d.ts.map +1 -1
- package/dist/lib/update-managers.js +2 -1
- package/dist/lib/update-managers.js.map +1 -1
- package/dist/lib/update-pending.d.ts +1 -1
- package/dist/lib/update-pending.d.ts.map +1 -1
- package/dist/lib/update-pending.js +1 -1
- package/dist/lib/update-pending.js.map +1 -1
- package/dist/lib/version.js +3 -3
- package/dist/lib/version.js.map +1 -1
- package/dist/seed/reconcile.js +1 -1
- package/dist/seed/reconcile.js.map +1 -1
- package/dist/seed/store.d.ts +3 -7
- package/dist/seed/store.d.ts.map +1 -1
- package/dist/seed/store.js +83 -15
- package/dist/seed/store.js.map +1 -1
- package/dist/seed/verify.d.ts +2 -2
- package/dist/seed/verify.d.ts.map +1 -1
- package/dist/seed/verify.js +8 -4
- package/dist/seed/verify.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 { 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, CorruptExtensionsManifestError, 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, windowsShellWord, staleStoreHint, UnreadableConnectorSelection, } from "@cotal-ai/workspace";
|
|
6
|
+
import { CommandFailure, commandFailureReport, cachedPreferences, withProjectTrustMigration, CorruptExtensionsManifestError, 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, plainFlag, preferencesFolderWarning, recordOperationWarning, renderReport, renderWorkspaceError, runOperation, workspaceErrorParts, spaceRootTarget, targetErrorCode, targetErrorSpace, terminalWidth, userCotalDir, windowsShellWord, 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 { commandSurface, isExtensionStub, materializeExtension, materializeExtensionCommand, overlayExtensions, setCommandSurface, setInstalledExtensionsEnabled, } from "./ext-loader.js";
|
|
@@ -16,16 +16,16 @@ import { historySetupFailureRecords, membershipSetupFailureRecords, watchSetupFa
|
|
|
16
16
|
import { HISTORY_LIMIT_FLAGS } from "./commands/history-limit.js";
|
|
17
17
|
import { CatalogPreparationError, prepareCatalogCommand } from "./commands/sync.js";
|
|
18
18
|
import { keepStartupNotice } from "./lib/interrupt-notice.js";
|
|
19
|
-
import { metadataPositionals } from "./lib/command-path.js";
|
|
19
|
+
import { metadataPositionals, parserOptions } from "./lib/command-path.js";
|
|
20
20
|
import { chooseMeshTarget, spaceChoiceRemedy } from "./lib/choose-target.js";
|
|
21
21
|
import { registryFailure } from "./lib/registry-errors.js";
|
|
22
22
|
import { FlagValueRefusal } from "./lib/flag-value-refusal.js";
|
|
23
23
|
import { workingFolderRemoved } from "./lib/paths.js";
|
|
24
24
|
import { npmProjectDirectory, preserveUpdatePath } from "./lib/npm-invocation.js";
|
|
25
|
-
import { reportLostOutput,
|
|
25
|
+
import { reportLostOutput, writeWholeSync } from "./lib/stdout-owner.js";
|
|
26
26
|
import { shellWord } from "./lib/endpoint-errors.js";
|
|
27
|
-
import { displayRemedy, hasMovedStackRemedy } from "./lib/self-exec.js";
|
|
28
|
-
import { asksForHelp, GLOBAL_FLAG_WORDS, leadingInvocation, OUTPUT_FLAG_WORDS } from "./lib/leading-flags.js";
|
|
27
|
+
import { displayProjectTrustFailure, displayRemedy, hasMovedStackRemedy } from "./lib/self-exec.js";
|
|
28
|
+
import { asksForHelp, GLOBAL_FLAG_WORDS, leadingInvocation, OUTPUT_FLAG_WORDS, TYPOGRAPHIC_OPTION } 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";
|
|
31
31
|
import { UnusableFile } from "./lib/unusable-file.js";
|
|
@@ -98,10 +98,11 @@ async function repeatedGlobalFlag(word, cmd, words, warnings = [], textWords) {
|
|
|
98
98
|
? { message: `--${flag.name} cannot be repeated`, remedy: `use --${flag.name} once` }
|
|
99
99
|
: missingValue(found, rest, flag)
|
|
100
100
|
: { message: `Option '${word}' cannot be repeated` };
|
|
101
|
-
if (
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
101
|
+
if (found && json && isExtensionStub(found)) {
|
|
102
|
+
return runOperation({ warnings }, () => usageExit(refusal.message, found, json, options.includes("--plain"), refusal.remedy, rest));
|
|
103
|
+
}
|
|
104
|
+
routeCollisionWarnings(warnings, found, rest, false);
|
|
105
|
+
return usageExit(refusal.message, found, json, options.includes("--plain"), refusal.remedy, rest);
|
|
105
106
|
}
|
|
106
107
|
/** Whether the invoked mode declares a structured output, so it reports every outcome by the 0 to 5
|
|
107
108
|
* table: the subcommand `first` selects, else the command's bare form. */
|
|
@@ -187,7 +188,12 @@ function failureExit(cmd, failure, json, plain = false, scope, words = [], valid
|
|
|
187
188
|
process.exit(1);
|
|
188
189
|
}
|
|
189
190
|
// Rendered in the run's scope, so the `Mesh:` heading keeps the note on how the run chose its space.
|
|
190
|
-
const report = () =>
|
|
191
|
+
const report = () => {
|
|
192
|
+
const message = displayProjectTrustFailure(failure.message);
|
|
193
|
+
const remedy = failure.remedy === undefined ? undefined : displayProjectTrustFailure(failure.remedy);
|
|
194
|
+
const shown = message === failure.message && remedy === failure.remedy ? failure : new CommandFailure(failure.outcome, failure.code, message, { ...failure, remedy });
|
|
195
|
+
return renderReport(commandFailureReport(shown), plain ? "plain" : "rich", process.stderr);
|
|
196
|
+
};
|
|
191
197
|
const writeReport = () => writeSync(2, `${scope ? runOperation(scope, report) : report()}
|
|
192
198
|
`);
|
|
193
199
|
// Under --json the envelope alone reports the failure. Its text report goes to stderr only when the
|
|
@@ -217,7 +223,7 @@ function failureExit(cmd, failure, json, plain = false, scope, words = [], valid
|
|
|
217
223
|
}, failure)
|
|
218
224
|
: cmd.name === "watch" && validationArgs && !plain ? watchSetupFailureRecords(validationArgs, failure) : undefined;
|
|
219
225
|
const lines = records ? records.map((record) => `${JSON.stringify(record)}\n`).join("") : envelopeLine(failureEnvelope(command, failure, warnings, scope));
|
|
220
|
-
|
|
226
|
+
writeWholeSync(1, Buffer.from(lines));
|
|
221
227
|
}
|
|
222
228
|
catch (error) {
|
|
223
229
|
const writeError = error;
|
|
@@ -299,6 +305,8 @@ function skipsSeed(name, sub, argv, cmd, values) {
|
|
|
299
305
|
return true; // local files or existing native manager routes; neither installs connectors
|
|
300
306
|
if (name === "telemetry")
|
|
301
307
|
return true; // one local settings file; never installs connectors
|
|
308
|
+
if (name === "trust")
|
|
309
|
+
return true; // one local trust record; never installs connectors
|
|
302
310
|
if (["__service-feedback-intake", "__service-delivery", "__service-manager", "__service-auth", "__service-linear", "__service-web", "__service-exec-endpoint"].includes(name))
|
|
303
311
|
return true; // explicit native service child; never repairs the installation
|
|
304
312
|
if (name === "team" && (sub === "deploy" || sub === "remove"))
|
|
@@ -434,7 +442,7 @@ function usageRefusal(failure, plain, cmd, words = []) {
|
|
|
434
442
|
return;
|
|
435
443
|
if (report)
|
|
436
444
|
console.error("");
|
|
437
|
-
paintFor(process.stderr, () => printHelpPath(cmd, helpPath(cmd, words).path, (line) => console.error(line), terminalWidth(process.stderr), plain ? "plain" : "rich"));
|
|
445
|
+
paintFor(process.stderr, () => printHelpPath(cmd, helpPath(cmd, words).path, (line) => console.error(line), terminalWidth(process.stderr), plain ? "plain" : "rich", words));
|
|
438
446
|
}
|
|
439
447
|
/** Recover the requested stream output and target for a refusal, without running the command. */
|
|
440
448
|
function streamRefusalArgs(cmd, words) {
|
|
@@ -468,6 +476,21 @@ function streamRefusalArgs(cmd, words) {
|
|
|
468
476
|
args.splice(missing.index + 1, 0, "");
|
|
469
477
|
}
|
|
470
478
|
}
|
|
479
|
+
/** An unreadable extension surface refuses dispatch, using the known built-in output mode if available. */
|
|
480
|
+
function overlayFailureExit(error, builtin, words, wantsHelp, scope) {
|
|
481
|
+
const denied = isCommandFailure(error) && error.code === "PERMISSION_DENIED" ? error : undefined;
|
|
482
|
+
const corrupt = error instanceof CorruptExtensionsManifestError
|
|
483
|
+
? new CommandFailure("refused", "SCHEMA_INVALID", error.diagnosis, { remedy: error.remedy, cause: error }) : undefined;
|
|
484
|
+
const failure = denied ?? corrupt;
|
|
485
|
+
if (failure && builtin && !wantsHelp && !takesWordsRaw(builtin)) {
|
|
486
|
+
const end = words.indexOf("--");
|
|
487
|
+
const plain = (end === -1 ? words : words.slice(0, end)).includes("--plain");
|
|
488
|
+
if (asksForJson(builtin, words) || plain || denied)
|
|
489
|
+
failureExit(builtin, failure, asksForJson(builtin, words), plain, scope, words, streamRefusalArgs(builtin, words));
|
|
490
|
+
}
|
|
491
|
+
stderrLine("✗ ", error.message, c.red);
|
|
492
|
+
process.exit(1);
|
|
493
|
+
}
|
|
471
494
|
/** A usage error, written by {@link usageRefusal} with the help of the command or subcommand `words`
|
|
472
495
|
* name when there is one, and with `remedy` under the message when the parser can name one. Exit 1. */
|
|
473
496
|
function usageExit(message, cmd, json = false, plain = false, remedy, words = []) {
|
|
@@ -483,7 +506,7 @@ function usageExit(message, cmd, json = false, plain = false, remedy, words = []
|
|
|
483
506
|
/** The refusal for a named or short option typed with a typographic dash pasted from
|
|
484
507
|
* typeset text, as `\u2013\u2013json`, naming it with hyphens; undefined when `word` is no such option. */
|
|
485
508
|
function typographicOption(word, names, flags = []) {
|
|
486
|
-
const typed =
|
|
509
|
+
const typed = TYPOGRAPHIC_OPTION.exec(word);
|
|
487
510
|
if (!typed)
|
|
488
511
|
return undefined;
|
|
489
512
|
const [, name, value] = typed;
|
|
@@ -538,21 +561,22 @@ function misspelledOption(cmd, rest, flagNames) {
|
|
|
538
561
|
return { message: `${word} gives -${short[1]} the value "=${value}"`, remedy: `write ${correction}${windows && common === undefined ? " in PowerShell" : ""}` };
|
|
539
562
|
}
|
|
540
563
|
const typed = positionals.has(index) ? recognize(word) : undefined;
|
|
541
|
-
if (typed && (cmd.name === "ext" || cmd.name === "endpoint") && typed.flagName && typed.flagName !== "help") {
|
|
564
|
+
if (typed && (cmd.name === "ext" || cmd.name === "endpoint" || cmd.name === "history") && typed.flagName && typed.flagName !== "help") {
|
|
542
565
|
const first = metadataPositionals(cmd, rest, { optionSpelling: (arg) => recognize(arg)?.spelling }).positionals[0]?.value;
|
|
543
566
|
const sub = findSubcommand(cmd, first);
|
|
544
567
|
const accepted = sub ? sub.flagNames : cmd.flagNames;
|
|
545
|
-
if (
|
|
568
|
+
if (cmd.name === "history" && sub?.name === "clear" && HISTORY_LIMIT_FLAGS.some((name) => name === typed.flagName))
|
|
569
|
+
return { message: typed.message, remedy: `omit --${typed.flagName} from \`history clear\` and keep the other arguments. Use it with \`history limit\` to change retention` };
|
|
570
|
+
if ((cmd.name === "ext" || (cmd.name === "endpoint" && sub?.name === "check")) && accepted && !accepted.includes(typed.flagName))
|
|
546
571
|
return { message: typed.message, remedy: `omit this option; \`cotal ${cmd.name}${sub ? ` ${sub.name}` : ""}\` does not take --${typed.flagName}` };
|
|
547
572
|
}
|
|
573
|
+
if (typed && typed.flagName === "plain" && asksForJson(cmd, rest))
|
|
574
|
+
return { message: typed.message, remedy: "omit the mistyped plain option" };
|
|
548
575
|
if (typed)
|
|
549
576
|
return typed;
|
|
550
577
|
}
|
|
551
578
|
return undefined;
|
|
552
579
|
}
|
|
553
|
-
function parserOptions(cmd) {
|
|
554
|
-
return Object.fromEntries((cmd.flags ?? []).map(({ name, type, short }) => [name, { type, ...(short ? { short } : {}) }]));
|
|
555
|
-
}
|
|
556
580
|
/** Strip standalone globals, but keep any global where a string option needs its value. */
|
|
557
581
|
function stripGlobalFlags(cmd, words) {
|
|
558
582
|
if (takesWordsRaw(cmd))
|
|
@@ -570,6 +594,8 @@ function missingValue(cmd, words, flag, beforeSeparator = false) {
|
|
|
570
594
|
return { message: `\`run check\` does not take --${flag.name}`, remedy: `run the check without --${flag.name}` };
|
|
571
595
|
if (cmd.name === "endpoint" && flag.name === "file" && helpPath(cmd, words).path[0] === "check")
|
|
572
596
|
return { message: "`endpoint check` does not take --file", remedy: "omit --file and keep the contract path" };
|
|
597
|
+
if (cmd.name === "service" && flag.name === "exec" && helpPath(cmd, words).path[0] === "status")
|
|
598
|
+
return { message: "`service status` does not take --exec", remedy: "omit --exec" };
|
|
573
599
|
if (cmd.name === "history") {
|
|
574
600
|
const sub = helpPath(cmd, words).path[0];
|
|
575
601
|
if (sub === "limit" && flag.name === "server")
|
|
@@ -577,15 +603,142 @@ function missingValue(cmd, words, flag, beforeSeparator = false) {
|
|
|
577
603
|
if (sub === "clear" && HISTORY_LIMIT_FLAGS.some((name) => name === flag.name))
|
|
578
604
|
return { message: `\`history clear\` does not take --${flag.name}`, remedy: `omit --${flag.name} from this command. Use it with \`history limit\` to change retention` };
|
|
579
605
|
}
|
|
606
|
+
if (cmd.name === "persona" && flag.name === "subscribe")
|
|
607
|
+
return { message: "--subscribe needs a value", remedy: `write --subscribe <a,b> or --subscribe= for none${beforeSeparator ? " (before --)" : ""}` };
|
|
580
608
|
return { message: `--${flag.name} needs a value`, remedy: `write --${flag.name} ${flag.value ?? "<value>"}${beforeSeparator ? " before --" : ""}` };
|
|
581
609
|
}
|
|
582
|
-
function switchValueRefusal(flag, cmd, rest = []) {
|
|
610
|
+
function switchValueRefusal(flag, cmd, rest = [], json = false) {
|
|
583
611
|
const first = cmd && metadataPositionals(cmd, rest).positionals[0]?.value;
|
|
584
612
|
const acceptsFlag = GLOBAL_FLAG_WORDS.has(flag) || (cmd && (flag === "--plain"
|
|
585
|
-
? (findSubcommand(cmd, first) ?? cmd).outputs?.includes("plain")
|
|
613
|
+
? !json && (findSubcommand(cmd, first) ?? cmd).outputs?.includes("plain")
|
|
586
614
|
: structured(cmd, first)));
|
|
587
615
|
return { message: `${flag} takes no value`, remedy: `omit ${flag}${acceptsFlag ? " or pass it without a value" : ""}` };
|
|
588
616
|
}
|
|
617
|
+
/** `--help` takes no value. Name the bare switch, not a positional that starts with `-`. */
|
|
618
|
+
function helpSwitchValueRefusal(cmd) {
|
|
619
|
+
return { message: "--help takes no value", remedy: displayRemedy(`run \`cotal ${cmd.name} --help\``) };
|
|
620
|
+
}
|
|
621
|
+
/** Positional word limit for the separator remedy only, counting subcommand words. Commands with
|
|
622
|
+
* variable or unspecified arity keep their own grammar. */
|
|
623
|
+
function operandLimit(cmd, selected, first, rest) {
|
|
624
|
+
const mode = selected.name;
|
|
625
|
+
const values = () => parseArgs({ args: [...rest], options: parserOptions(cmd), strict: false, allowPositionals: true }).values;
|
|
626
|
+
switch (cmd.name) {
|
|
627
|
+
case "app-identity":
|
|
628
|
+
case "chat":
|
|
629
|
+
case "clean":
|
|
630
|
+
case "describe":
|
|
631
|
+
case "docs":
|
|
632
|
+
case "doctor":
|
|
633
|
+
case "feedback":
|
|
634
|
+
case "manager":
|
|
635
|
+
case "pending":
|
|
636
|
+
case "telemetry": return 1;
|
|
637
|
+
case "backup":
|
|
638
|
+
case "invoke":
|
|
639
|
+
case "persona":
|
|
640
|
+
case "reset":
|
|
641
|
+
case "service-endpoint":
|
|
642
|
+
case "space":
|
|
643
|
+
return 2;
|
|
644
|
+
case "config": return mode === "set" ? 3 : 2;
|
|
645
|
+
case "actor": return mode === "list" ? 1 : mode === "label" ? 3 : 2;
|
|
646
|
+
case "auth": return mode === "grants" || mode === "signer" ? 1 : mode === "inspect" ? 3 : 2;
|
|
647
|
+
case "channel": return mode === "defaults" ? 1 : 2;
|
|
648
|
+
case "daemon": return mode === "name" ? 2 : 1;
|
|
649
|
+
case "endpoint":
|
|
650
|
+
if (mode === "list")
|
|
651
|
+
return 1;
|
|
652
|
+
if (mode === "lease" || mode === "commit")
|
|
653
|
+
return 4;
|
|
654
|
+
if (mode === "work")
|
|
655
|
+
return 3;
|
|
656
|
+
return ["deregister", "invoke", "watch", "session"].includes(mode) ? 3 : 2;
|
|
657
|
+
case "ext": return mode === "root" || mode === "list" ? 1 : mode === "add" || mode === "remove" ? 2 : Infinity;
|
|
658
|
+
case "linear": return mode === "account" ? 2 : ["add", "login", "show", "call", "resource", "prompt"].includes(mode) ? 3 : 2;
|
|
659
|
+
case "meshes": return first === "add" ? 2 : Infinity;
|
|
660
|
+
case "personas":
|
|
661
|
+
case "service":
|
|
662
|
+
case "team": return mode === "list" ? 1 : 2;
|
|
663
|
+
case "run":
|
|
664
|
+
if (mode === "list" || mode === "turns")
|
|
665
|
+
return 1;
|
|
666
|
+
if (mode === "answer" || mode === "amend")
|
|
667
|
+
return 3;
|
|
668
|
+
if (mode === "check")
|
|
669
|
+
return values().file === undefined ? 3 : 2;
|
|
670
|
+
if (mode === "start" && values().file !== undefined)
|
|
671
|
+
return 1;
|
|
672
|
+
return 2;
|
|
673
|
+
case "attach": return values().name === undefined ? 1 : 0;
|
|
674
|
+
case "history": return mode === "clear" || mode === "limit" || !values().dms ? 1 : 0;
|
|
675
|
+
case "input": {
|
|
676
|
+
const { name, text } = values();
|
|
677
|
+
return name !== undefined ? 0 : text !== undefined ? 1 : 2;
|
|
678
|
+
}
|
|
679
|
+
case "login": {
|
|
680
|
+
const { cloud, idp, "migrate-from": migrateFrom } = values();
|
|
681
|
+
return cloud || idp !== undefined || migrateFrom !== undefined ? 0 : 1;
|
|
682
|
+
}
|
|
683
|
+
case "send": {
|
|
684
|
+
const { file, stdin } = values();
|
|
685
|
+
return file !== undefined || stdin ? 0 : 1;
|
|
686
|
+
}
|
|
687
|
+
case "spawn": return values().file === undefined ? 1 : 0;
|
|
688
|
+
case "status": {
|
|
689
|
+
const { all, components, wide, verbose } = values();
|
|
690
|
+
return all || components || wide || verbose ? 0 : 1;
|
|
691
|
+
}
|
|
692
|
+
case "stop": {
|
|
693
|
+
const { self, name } = values();
|
|
694
|
+
return self || name !== undefined ? 0 : 1;
|
|
695
|
+
}
|
|
696
|
+
case "topology": return values().file === undefined ? 2 : 1;
|
|
697
|
+
case "update": {
|
|
698
|
+
const { auto, notify } = values();
|
|
699
|
+
return auto || notify ? 1 : 0;
|
|
700
|
+
}
|
|
701
|
+
case "use": return values().clear ? 0 : 1;
|
|
702
|
+
default: return Infinity;
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
/** A persona invocation whose unknown word starts with `-`. Flags stay before `--` and only that
|
|
706
|
+
* word follows it, which is the form the command can parse. Undefined when there is no such word. */
|
|
707
|
+
function personaSeparatorRemedy(cmd, rest) {
|
|
708
|
+
const end = rest.indexOf("--");
|
|
709
|
+
const head = end === -1 ? rest : rest.slice(0, end);
|
|
710
|
+
const flags = [];
|
|
711
|
+
const names = [];
|
|
712
|
+
for (let index = 0; index < head.length; index++) {
|
|
713
|
+
const word = head[index];
|
|
714
|
+
if (word === "--")
|
|
715
|
+
continue;
|
|
716
|
+
const inline = /^--([^=]+)=/.exec(word)?.[1];
|
|
717
|
+
const long = inline ?? (/^--([^=]+)$/.exec(word)?.[1]);
|
|
718
|
+
const letter = /^-([^-])$/.exec(word)?.[1];
|
|
719
|
+
const flag = long !== undefined ? cmd.flags?.find((item) => item.name === long)
|
|
720
|
+
: letter === undefined ? undefined : cmd.flags?.find((item) => item.short === letter);
|
|
721
|
+
if (flag) {
|
|
722
|
+
flags.push(word);
|
|
723
|
+
const next = head[index + 1];
|
|
724
|
+
if (!inline && flag.type === "string" && next !== undefined && !next.startsWith("--") && (next === "-" || /^-\d/.test(next) || !next.startsWith("-"))) {
|
|
725
|
+
flags.push(shellWord(next));
|
|
726
|
+
index++;
|
|
727
|
+
}
|
|
728
|
+
continue;
|
|
729
|
+
}
|
|
730
|
+
names.push(word);
|
|
731
|
+
}
|
|
732
|
+
const dashed = names.find((word) => word.startsWith("-") && word !== "-");
|
|
733
|
+
if (dashed === undefined)
|
|
734
|
+
return undefined;
|
|
735
|
+
const kept = names.filter((word) => word !== dashed);
|
|
736
|
+
const line = `cotal persona ${[...kept, ...flags].join(" ")}`;
|
|
737
|
+
// A catalog name cannot start with `-`, so reprinting one would refuse again.
|
|
738
|
+
if (names[0] === "create" || names[0] === "edit" || names[0] === "remove")
|
|
739
|
+
return `choose a catalog name that starts with a letter, digit or _, then repeat \`${line} <name>\``;
|
|
740
|
+
return `repeat it as \`${line} -- ${shellWord(dashed)}\``;
|
|
741
|
+
}
|
|
589
742
|
/** A parse error as a refusal. A mistyped option names its spelling. A word that starts with `-`
|
|
590
743
|
* goes after `--` only where the command has room for an operand and there is no spelling suggestion.
|
|
591
744
|
* An option value that starts with `-` is written `--name=value`, and an option given with no value,
|
|
@@ -596,6 +749,9 @@ function parseRefusal(error, cmd, rest, flagNames, takesOperands, operandsFull)
|
|
|
596
749
|
const option = /^Unknown option '(--.+)'$/su.exec(reason)?.[1];
|
|
597
750
|
if (option && GLOBAL_FLAG_WORDS.has(option) && !takesWordsRaw(cmd))
|
|
598
751
|
return switchValueRefusal(option);
|
|
752
|
+
// `--help` is a switch, not a command flag, so a value on it is not an unknown option.
|
|
753
|
+
if (option === "--help" && !takesWordsRaw(cmd))
|
|
754
|
+
return helpSwitchValueRefusal(cmd);
|
|
599
755
|
if (cmd.name === "help" && option === "--preset") {
|
|
600
756
|
const [service, verb] = metadataPositionals(cmd, rest).positionals;
|
|
601
757
|
if (findCommand(commandSurface(), service?.value)?.name === "service" && verb?.value === "add")
|
|
@@ -610,9 +766,10 @@ function parseRefusal(error, cmd, rest, flagNames, takesOperands, operandsFull)
|
|
|
610
766
|
return { message: reason, remedy: `drop the unknown option${value}; --${flag.name} is already set` };
|
|
611
767
|
}
|
|
612
768
|
const message = spellings ? `${reason} - did you mean ${spellings}?` : reason;
|
|
613
|
-
const
|
|
769
|
+
const personaSeparator = cmd.name === "persona" && !operandsFull() ? personaSeparatorRemedy(cmd, rest) : undefined;
|
|
770
|
+
const remedy = personaSeparator ?? (cmd.name === "completion" ? "drop the unknown option"
|
|
614
771
|
: !takesOperands ? undefined : spellings ? `use ${spellings}`
|
|
615
|
-
: operandsFull ? "drop the unknown option" : "to pass a word that starts with \"-\", put -- before it";
|
|
772
|
+
: operandsFull() ? "drop the unknown option" : "to pass a word that starts with \"-\", put -- before it");
|
|
616
773
|
return { message, remedy };
|
|
617
774
|
}
|
|
618
775
|
if (error.code === "ERR_PARSE_ARGS_UNEXPECTED_POSITIONAL") {
|
|
@@ -679,17 +836,7 @@ function parseOrExit(cmd, rest, noMoreOperands = false) {
|
|
|
679
836
|
}
|
|
680
837
|
const takesOperands = !seed && cmd.positionals !== undefined &&
|
|
681
838
|
(!cmd.subcommands?.length || cmd.name === "history" || (first !== undefined && findSubcommand(cmd, first) !== undefined));
|
|
682
|
-
const operandsFull = noMoreOperands ||
|
|
683
|
-
|| ((selected.name === "get" || selected.name === "unset") && positionals.length >= 2)))
|
|
684
|
-
|| (cmd.name === "docs" && positionals.length >= 1)
|
|
685
|
-
|| (cmd.name === "ext" && selected.name === "root")
|
|
686
|
-
|| (cmd.name === "history" && selected.name === "limit")
|
|
687
|
-
|| (cmd.name === "space" && selected.name === "add" && positionals.length >= 2)
|
|
688
|
-
|| (cmd.name === "channel" && selected.name === "set" && positionals.length >= 2)
|
|
689
|
-
|| (cmd.name === "service" && selected !== cmd && (selected.name === "list" || positionals.length >= 2))
|
|
690
|
-
|| (cmd.name === "team" && ["check", "boot", "deploy"].includes(selected.name) && positionals.length >= 2)
|
|
691
|
-
|| (cmd.name === "endpoint" && ((selected.name === "check" && positionals.length >= 2)
|
|
692
|
-
|| (first === "work" && selected.name === "lease" && positionals.length >= 4)));
|
|
839
|
+
const operandsFull = () => noMoreOperands || positionals.length >= operandLimit(cmd, selected, first, rest);
|
|
693
840
|
const refusal = parseRefusal(e, cmd, rest, seed?.flagNames ?? selected.flagNames, takesOperands, operandsFull);
|
|
694
841
|
usageExit(refusal.message, cmd, json, plain, refusal.remedy, rest);
|
|
695
842
|
}
|
|
@@ -841,7 +988,7 @@ function helpPath(cmd, rest) {
|
|
|
841
988
|
* does, so a mistyped subcommand never gets its group's help. */
|
|
842
989
|
function printHelpFor(cmd, rest) {
|
|
843
990
|
const { path, unknown } = helpPath(cmd, rest);
|
|
844
|
-
paintFor(process.stdout, () => printHelpPath(cmd, unknown === undefined ? path : [...path, unknown]));
|
|
991
|
+
paintFor(process.stdout, () => printHelpPath(cmd, unknown === undefined ? path : [...path, unknown], undefined, undefined, undefined, rest));
|
|
845
992
|
}
|
|
846
993
|
/** A service invocation takes its preset's flags, and `manager <verb>` is `service <verb> manager`.
|
|
847
994
|
* Preset details can enrich a global flag refusal but cannot replace it. */
|
|
@@ -863,22 +1010,35 @@ async function serviceSurface(found, words, forRefusal = false) {
|
|
|
863
1010
|
}
|
|
864
1011
|
}
|
|
865
1012
|
/** Recover the command and output mode for a malformed leading switch without dispatching it. */
|
|
866
|
-
async function unknownInvocationExit(commands, word, args, output, beforeSeparator,
|
|
1013
|
+
async function unknownInvocationExit(commands, word, args, output, beforeSeparator, warnings) {
|
|
1014
|
+
const typed = typographicOption(word, new Set(LEADING_FLAGS.map((flag) => flag.slice(2))), [
|
|
1015
|
+
jsonFlag, plainFlag, { name: "help", short: "h", type: "boolean" }, { name: "version", short: "V", type: "boolean" },
|
|
1016
|
+
]);
|
|
867
1017
|
const equals = word.indexOf("=");
|
|
868
1018
|
const flag = equals === -1 ? word : word.slice(0, equals);
|
|
869
1019
|
const malformedSwitch = equals !== -1 && (GLOBAL_FLAG_WORDS.has(flag) || OUTPUT_FLAG_WORDS.has(flag));
|
|
1020
|
+
const textExit = () => {
|
|
1021
|
+
routeCollisionWarnings(warnings, undefined, [...output, ...args], false);
|
|
1022
|
+
return usageExit(typed?.message ?? unknownCommandMessage(commands, word), undefined, false, false, typed?.remedy);
|
|
1023
|
+
};
|
|
870
1024
|
if (!beforeSeparator || (!typed && !malformedSwitch))
|
|
871
|
-
|
|
1025
|
+
return textExit();
|
|
872
1026
|
const retry = leadingInvocation(args, true);
|
|
873
1027
|
const found = findCommand(commands, retry.word);
|
|
874
1028
|
const words = [...output, ...retry.leading.filter((item) => OUTPUT_FLAG_WORDS.has(item)), ...retry.args];
|
|
875
1029
|
const { cmd, rest } = await serviceSurface(takesWordsRaw(found) ? undefined : found, words, true);
|
|
876
1030
|
const json = cmd !== undefined && asksForJson(cmd, rest);
|
|
1031
|
+
// With JSON chosen, correcting a mistyped `--plain` would ask for both outputs at once, so the
|
|
1032
|
+
// remedy drops the word instead of retyping it.
|
|
1033
|
+
const plainRefusal = typed?.flagName === "plain" && json
|
|
1034
|
+
? { ...typed, remedy: "omit the mistyped plain option" }
|
|
1035
|
+
: typed;
|
|
877
1036
|
if (typed && !json)
|
|
878
|
-
|
|
1037
|
+
return textExit();
|
|
1038
|
+
routeCollisionWarnings(warnings, cmd, rest, false);
|
|
879
1039
|
const end = rest.indexOf("--");
|
|
880
1040
|
const plain = (end === -1 ? rest : rest.slice(0, end)).includes("--plain");
|
|
881
|
-
const refusal =
|
|
1041
|
+
const refusal = plainRefusal ?? switchValueRefusal(flag, cmd, rest, json);
|
|
882
1042
|
return usageExit(refusal.message, cmd, json, plain, refusal.remedy, rest);
|
|
883
1043
|
}
|
|
884
1044
|
function repeatedInvocationExit(repeated, cmd, rest, warnings, commands, tail, output) {
|
|
@@ -906,6 +1066,34 @@ export function runCli(registry, argv, opts = {}) {
|
|
|
906
1066
|
const scope = {};
|
|
907
1067
|
return runOperation(scope, () => dispatchCli(registry, argv, opts, scope));
|
|
908
1068
|
}
|
|
1069
|
+
function checkCommandLocalState(cmd, parsed, rest) {
|
|
1070
|
+
if (cmd.name.startsWith("__") || cmd.name === "help" || cmd.name === "completion")
|
|
1071
|
+
return;
|
|
1072
|
+
const json = structured(cmd, parsed.positionals[0]) && parsed.values.json === true;
|
|
1073
|
+
const refuse = (failure) => failureExit(cmd, failure, json, parsed.values.plain === true, undefined, rest, parsed);
|
|
1074
|
+
// A relative COTAL_HOME would select different records in each working folder.
|
|
1075
|
+
const home = process.env.COTAL_HOME;
|
|
1076
|
+
if (home && !isAbsolute(home))
|
|
1077
|
+
refuse(new CommandFailure("refused", "USAGE_INVALID", `COTAL_HOME ${JSON.stringify(home)} is a relative path, so each folder a command runs in would have its own Cotal home; the command did not run`, { remedy: `set COTAL_HOME to an absolute path, or unset it to use ${userCotalDir()}` }));
|
|
1078
|
+
const homeProblem = cotalHomeProblem();
|
|
1079
|
+
if (homeProblem)
|
|
1080
|
+
refuse(new CommandFailure("refused", "SCHEMA_INVALID", `${homeProblem}; the command did not run`, { remedy: `point COTAL_HOME at a directory, or unset it to use ${userCotalDir()}` }));
|
|
1081
|
+
// The machine daemon uses its selected home, not the invoking project's records.
|
|
1082
|
+
const dirProblem = cmd.name === "version" || cmd.name === "daemon" || workingFolderRemoved() ? undefined : cotalDirProblem(typeof parsed.values.root === "string" ? resolve(parsed.values.root) : findCotalRoot());
|
|
1083
|
+
if (dirProblem)
|
|
1084
|
+
refuse(new CommandFailure("refused", "CONFLICT", `${dirProblem}; the command did not run`, { remedy: "rename or move that file, then run the command again" }));
|
|
1085
|
+
// Commands that act on preferences refuse an invalid file. Status reports it as a warning.
|
|
1086
|
+
if (!["version", "docs", "status", "daemon"].includes(cmd.name)) {
|
|
1087
|
+
try {
|
|
1088
|
+
cachedPreferences();
|
|
1089
|
+
}
|
|
1090
|
+
catch (error) {
|
|
1091
|
+
if (!isCommandFailure(error))
|
|
1092
|
+
throw error;
|
|
1093
|
+
refuse(error);
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
909
1097
|
// Explicit help for the bundled reference needs only the built-in command metadata.
|
|
910
1098
|
function isExplicitDocsHelp(registry, builtin, wantsHelp, words) {
|
|
911
1099
|
return builtin?.name === "help" && !wantsHelp && registry.has("command", "docs")
|
|
@@ -954,46 +1142,19 @@ async function dispatchCli(registry, argv, opts, scope) {
|
|
|
954
1142
|
takeManagedHandoffCustody(process.env, builtin?.name === "spawn");
|
|
955
1143
|
const docsHelp = isExplicitDocsHelp(registry, builtin, wantsHelp, words);
|
|
956
1144
|
setInstalledExtensionsEnabled(Boolean(opts.extensions) && !docsHelp);
|
|
1145
|
+
const pendingWarnings = [];
|
|
957
1146
|
const builtinDuplicate = builtin && duplicate(builtin);
|
|
958
|
-
if (builtinDuplicate)
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
// The built-in check reports an unreadable inventory itself. Do not require that inventory to
|
|
963
|
-
// construct its command surface, or recover an installation as a prelude to this read-only mode.
|
|
964
|
-
const updateCheck = builtin?.name === "update" && words.includes("--check") && !wantsHelp
|
|
965
|
-
&& parseOrExit(builtin, ownWords(builtin)).values.check === true;
|
|
966
|
-
// Version reports inventory failures itself and needs no extension commands.
|
|
967
|
-
const versionRead = builtin?.name === "version" && !wantsHelp;
|
|
968
|
-
// The built-in updater repairs its connector paths before opening any promotion journal.
|
|
969
|
-
const selfUpdate = builtin?.name === "update" && words.includes("--self") && !wantsHelp
|
|
970
|
-
&& parseOrExit(builtin, ownWords(builtin)).values.self === true;
|
|
971
|
-
const preference = builtin?.name === "update" && !wantsHelp && (words.includes("--auto") || words.includes("--notify"))
|
|
972
|
-
? parseOrExit(builtin, ownWords(builtin)).values : undefined;
|
|
973
|
-
const extMode = builtin?.name === "ext" ? metadataPositionals(builtin, words).positionals[0]?.value : undefined;
|
|
974
|
-
// Root only resolves a path. The JSON list classifies inventory errors in its handler.
|
|
975
|
-
const extDiagnostics = builtin?.name === "ext" && !wantsHelp
|
|
976
|
-
&& (extMode === "root" || ((extMode === undefined || extMode === "list") && asksForJson(builtin, words)));
|
|
977
|
-
const readMode = builtin && !wantsHelp && (builtin.name === "config" || builtin.name === "completion")
|
|
978
|
-
? metadataPositionals(builtin, words).positionals[0]?.value : undefined;
|
|
979
|
-
const configRead = builtin?.name === "config" && !wantsHelp && (readMode === undefined || readMode === "get");
|
|
980
|
-
const completionStatus = builtin?.name === "completion" && !wantsHelp && readMode === undefined;
|
|
981
|
-
let useExtensionOverlay = opts.extensions && !docsHelp && !updateCheck && !selfUpdate && !preference?.auto && !preference?.notify && builtin?.name !== "start";
|
|
982
|
-
function skipUnreadableConnectorOverlay(error) {
|
|
983
|
-
if (!(error instanceof UnreadableConnectorSelection) || !builtin || !["version", "status", "down"].includes(builtin.name))
|
|
984
|
-
return false;
|
|
985
|
-
if (builtin.name === "down") {
|
|
986
|
-
const parsed = parseOrExit(builtin, ownWords(builtin));
|
|
987
|
-
if (parsed.positionals.length || parsed.values.file || parsed.values.run || parsed.values["with-agents"] || parsed.values["preserve-state"])
|
|
988
|
-
return false;
|
|
1147
|
+
if (builtinDuplicate) {
|
|
1148
|
+
try {
|
|
1149
|
+
if (opts.extensions && !docsHelp)
|
|
1150
|
+
overlayExtensions(registry, collisionWarning(pendingWarnings));
|
|
989
1151
|
}
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
useExtensionOverlay = false;
|
|
993
|
-
setInstalledExtensionsEnabled(false);
|
|
994
|
-
return true;
|
|
1152
|
+
catch { /* An unreadable manifest does not replace the argument refusal. */ }
|
|
1153
|
+
return repeatedGlobalFlag(builtinDuplicate, builtin, ownWords(builtin), pendingWarnings);
|
|
995
1154
|
}
|
|
996
|
-
|
|
1155
|
+
if (word === "-v")
|
|
1156
|
+
usageExit("-v is not the version flag - run `cotal version` or `cotal -V`");
|
|
1157
|
+
const { configFolder, configRead, surface, useExtensionOverlay, skipUnreadableConnectorOverlay } = prepareDispatchSurface(registry, opts, builtin, words, wantsHelp, docsHelp, repeatedLeading, ownWords, scope);
|
|
997
1158
|
if (useExtensionOverlay) {
|
|
998
1159
|
try {
|
|
999
1160
|
if (builtin?.name === "ext" && await extSeedGate(builtin, ownWords(builtin), configFolder, opts.startupNotice))
|
|
@@ -1018,48 +1179,16 @@ async function dispatchCli(registry, argv, opts, scope) {
|
|
|
1018
1179
|
}
|
|
1019
1180
|
}
|
|
1020
1181
|
}
|
|
1021
|
-
const pendingWarnings = [];
|
|
1022
|
-
const surface = (warnings) => {
|
|
1023
|
-
let commands;
|
|
1024
|
-
try {
|
|
1025
|
-
commands = useExtensionOverlay && !versionRead && !extDiagnostics && !configFolder ? overlayExtensions(registry, collisionWarning(warnings)) : registry.all("command");
|
|
1026
|
-
}
|
|
1027
|
-
catch (e) {
|
|
1028
|
-
const infrastructureStatus = builtin?.name === "status" && !wantsHelp && !words.includes("--components")
|
|
1029
|
-
&& metadataPositionals(builtin, words).positionals.length === 0;
|
|
1030
|
-
if (((configRead || completionStatus || infrastructureStatus) && e instanceof CorruptExtensionsManifestError) || skipUnreadableConnectorOverlay(e)) {
|
|
1031
|
-
// The infrastructure report reads the manifest itself and can name the gap.
|
|
1032
|
-
if (infrastructureStatus)
|
|
1033
|
-
setInstalledExtensionsEnabled(false);
|
|
1034
|
-
commands = registry.all("command");
|
|
1035
|
-
}
|
|
1036
|
-
else {
|
|
1037
|
-
if (repeatedLeading)
|
|
1038
|
-
usageExit(`Option '${repeatedLeading}' cannot be repeated`);
|
|
1039
|
-
// A corrupt extensions manifest must not silently shrink the surface.
|
|
1040
|
-
stderrLine("✗ ", e.message, c.red);
|
|
1041
|
-
process.exit(1);
|
|
1042
|
-
}
|
|
1043
|
-
}
|
|
1044
|
-
for (const cmd of commands) {
|
|
1045
|
-
const problems = [
|
|
1046
|
-
...commandDeclarationProblems(cmd),
|
|
1047
|
-
...outputDeclarationProblems(cmd),
|
|
1048
|
-
...(cmd.subcommands ?? []).flatMap((sub) => outputDeclarationProblems({ name: `${cmd.name} ${sub.name}`, outputs: sub.outputs, flags: cmd.flags })),
|
|
1049
|
-
...globalFlagDeclarationProblems(cmd),
|
|
1050
|
-
];
|
|
1051
|
-
if (problems.length)
|
|
1052
|
-
usageExit(`internal error: ${problems.join("; ")}`);
|
|
1053
|
-
}
|
|
1054
|
-
setCommandSurface(commands); // the completion dispatcher reads the SAME surface help renders
|
|
1055
|
-
return commands;
|
|
1056
|
-
};
|
|
1057
1182
|
let commands = surface(pendingWarnings);
|
|
1058
1183
|
let cmd = findCommand(commands, word);
|
|
1059
1184
|
let rest = ownWords(cmd);
|
|
1060
1185
|
const repeated = duplicate(cmd);
|
|
1061
1186
|
if (repeated)
|
|
1062
1187
|
return repeatedInvocationExit(repeated, cmd, rest, pendingWarnings, commands, argv.slice(leading.length), output);
|
|
1188
|
+
// A seeded command can be absent until the first seed installs it. Help and unknown words do not seed.
|
|
1189
|
+
const awaitingSeed = !cmd && word !== undefined && opts.extensions === true && isSeededCommand(word) && !wantsHelp && !skipsSeed(word, rest[0], rest);
|
|
1190
|
+
if (!cmd && word !== undefined && !awaitingSeed)
|
|
1191
|
+
return unknownInvocationExit(commands, word, args, output, argv[leading.length] !== "--", pendingWarnings);
|
|
1063
1192
|
routeCollisionWarnings(pendingWarnings, cmd, rest, wantsHelp);
|
|
1064
1193
|
if (word === undefined)
|
|
1065
1194
|
return paintFor(process.stdout, () => printEntry(commands));
|
|
@@ -1080,21 +1209,9 @@ async function dispatchCli(registry, argv, opts, scope) {
|
|
|
1080
1209
|
}
|
|
1081
1210
|
};
|
|
1082
1211
|
arm();
|
|
1083
|
-
// A seeded package's command (`web`) can be absent only because the first seed has not installed
|
|
1084
|
-
// it yet, so running it seeds and resolves again. Asking for its help seeds nothing, and any other
|
|
1085
|
-
// unknown word is a usage error.
|
|
1086
|
-
const awaitingSeed = !cmd && opts.extensions === true && isSeededCommand(word) && !wantsHelp && !skipsSeed(word, rest[0], rest);
|
|
1087
|
-
// A leading flag typed with a typographic dash is read as the command word, so it is refused as the
|
|
1088
|
-
// same word after the command word is.
|
|
1089
|
-
const typed = cmd || awaitingSeed ? undefined : typographicOption(word, new Set(LEADING_FLAGS.map((flag) => flag.slice(2))), [
|
|
1090
|
-
jsonFlag, { name: "help", short: "h", type: "boolean" }, { name: "version", short: "V", type: "boolean" },
|
|
1091
|
-
]);
|
|
1092
|
-
if (!cmd && !awaitingSeed)
|
|
1093
|
-
return unknownInvocationExit(commands, word, args, output, argv[leading.length] !== "--", typed);
|
|
1094
1212
|
// `cotal <cmd> --help` / `-h` → that command's help, never run it. This intercept also covers
|
|
1095
|
-
// rawArgs commands and extension
|
|
1096
|
-
//
|
|
1097
|
-
// line, where `--help` is a word being completed, not a request.
|
|
1213
|
+
// rawArgs commands and extension stubs. The `__`-internal ones are exempt: `__complete` receives
|
|
1214
|
+
// another command's half-typed line, where `--help` is a word being completed, not a request.
|
|
1098
1215
|
if (cmd && !cmd.name.startsWith("__") && wantsHelp)
|
|
1099
1216
|
return printHelpFor(cmd, rest);
|
|
1100
1217
|
let parsed = cmd && !isExtensionStub(cmd) ? parseOrExit(cmd, rest, scoped.noMoreOperands) : undefined;
|
|
@@ -1108,36 +1225,15 @@ async function dispatchCli(registry, argv, opts, scope) {
|
|
|
1108
1225
|
// an extension stub resolves against the manifest the seed left.
|
|
1109
1226
|
const controlOnlyManager = parsed?.values.execution === "none" && (cmd?.name === "supervise" || cmd?.name === "__daemon-manager");
|
|
1110
1227
|
if (opts.extensions && !controlOnlyManager && !skipsSeed(cmd?.name ?? word, parsed ? parsed.positionals[0] : rest[0], rest, cmd, parsed?.values)) {
|
|
1111
|
-
// Startup checks seed compatibility here and reconciles at launch. A restore that refuses
|
|
1112
|
-
// before launch leaves the operator-global store as it found it.
|
|
1113
1228
|
const deferred = cmd?.name === "up" || (cmd?.name === "backup" && parsed?.positionals[0] === "restore");
|
|
1114
1229
|
try {
|
|
1115
|
-
if (deferred)
|
|
1116
|
-
|
|
1117
|
-
// recorded manager even when --no-manager is present, so it retains the full seed path.
|
|
1118
|
-
const brokerOnly = parsed?.values["no-manager"] === true && !parsed.values.restore;
|
|
1119
|
-
const refusal = brokerOnly ? seedDowngradeRefusal() : deferredSeedRefusal();
|
|
1120
|
-
if (refusal)
|
|
1121
|
-
throw refusal;
|
|
1122
|
-
if (!brokerOnly)
|
|
1123
|
-
deferSeedToLaunch();
|
|
1124
|
-
}
|
|
1230
|
+
if (deferred)
|
|
1231
|
+
deferStartupSeed(parsed);
|
|
1125
1232
|
else
|
|
1126
1233
|
await reconcileSeededConnectors(cmd?.name === "setup");
|
|
1127
1234
|
}
|
|
1128
1235
|
catch (e) {
|
|
1129
|
-
|
|
1130
|
-
// reports the same outcome and exit status in every presentation.
|
|
1131
|
-
const sub = parsed?.positionals[0] ?? (cmd && metadataPositionals(cmd, rest).positionals[0]?.value);
|
|
1132
|
-
if (cmd && structured(cmd, sub)) {
|
|
1133
|
-
const message = e instanceof Error ? e.message : String(e);
|
|
1134
|
-
const failure = isCommandFailure(e) ? e : new CommandFailure("refused", "DEPENDENCY_UNAVAILABLE", displayRemedy(message), e instanceof SeedChildFailure ? { remedy: displayRemedy("fix that, then run `cotal ext seed --repair`") } : {});
|
|
1135
|
-
const end = rest.indexOf("--");
|
|
1136
|
-
const plain = parsed?.values.plain === true || (!parsed && (end === -1 ? rest : rest.slice(0, end)).includes("--plain"));
|
|
1137
|
-
failureExit(cmd, failure, asksForJson(cmd, rest), plain, undefined, rest);
|
|
1138
|
-
}
|
|
1139
|
-
seedRefusal(e);
|
|
1140
|
-
process.exit(1);
|
|
1236
|
+
dispatchSeedRefusal(e, cmd, parsed, rest);
|
|
1141
1237
|
}
|
|
1142
1238
|
if (!deferred) {
|
|
1143
1239
|
const warnings = [];
|
|
@@ -1156,7 +1252,7 @@ async function dispatchCli(registry, argv, opts, scope) {
|
|
|
1156
1252
|
}
|
|
1157
1253
|
}
|
|
1158
1254
|
// An extension stub materializes before parsing: verify the version pin, import the package
|
|
1159
|
-
// (self-registers), and parse with the
|
|
1255
|
+
// (self-registers), and parse with the live specs. The cache never drives run's input.
|
|
1160
1256
|
if (cmd && isExtensionStub(cmd)) {
|
|
1161
1257
|
try {
|
|
1162
1258
|
cmd = await materializeExtensionCommand(cmd);
|
|
@@ -1169,42 +1265,114 @@ async function dispatchCli(registry, argv, opts, scope) {
|
|
|
1169
1265
|
}
|
|
1170
1266
|
if (!cmd || !parsed)
|
|
1171
1267
|
throw new Error("internal error: dispatch reached its effects without a parsed command");
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
//
|
|
1176
|
-
//
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1268
|
+
return executeDispatchedCommand(cmd, parsed, rest, argv, opts, scope, configRead);
|
|
1269
|
+
}
|
|
1270
|
+
function prepareDispatchSurface(registry, opts, builtin, words, wantsHelp, docsHelp, repeatedLeading, ownWords, scope) {
|
|
1271
|
+
// The built-in check reports an unreadable inventory itself. Do not require that inventory to
|
|
1272
|
+
// construct its command surface, or recover an installation as a prelude to this read-only mode.
|
|
1273
|
+
const updateCheck = builtin?.name === "update" && words.includes("--check") && !wantsHelp
|
|
1274
|
+
&& parseOrExit(builtin, ownWords(builtin)).values.check === true;
|
|
1275
|
+
// Version reports inventory failures itself and needs no extension commands.
|
|
1276
|
+
const versionRead = builtin?.name === "version" && !wantsHelp;
|
|
1277
|
+
// The built-in updater repairs its connector paths before opening any promotion journal.
|
|
1278
|
+
const selfUpdate = builtin?.name === "update" && words.includes("--self") && !wantsHelp
|
|
1279
|
+
&& parseOrExit(builtin, ownWords(builtin)).values.self === true;
|
|
1280
|
+
const preference = builtin?.name === "update" && !wantsHelp && (words.includes("--auto") || words.includes("--notify"))
|
|
1281
|
+
? parseOrExit(builtin, ownWords(builtin)).values : undefined;
|
|
1282
|
+
const extMode = builtin?.name === "ext" ? metadataPositionals(builtin, words).positionals[0]?.value : undefined;
|
|
1283
|
+
// Root only resolves a path. The JSON list classifies inventory errors in its handler.
|
|
1284
|
+
const extDiagnostics = builtin?.name === "ext" && !wantsHelp
|
|
1285
|
+
&& (extMode === "root" || ((extMode === undefined || extMode === "list") && asksForJson(builtin, words)));
|
|
1286
|
+
const readMode = builtin && !wantsHelp && (builtin.name === "config" || builtin.name === "completion")
|
|
1287
|
+
? metadataPositionals(builtin, words).positionals[0]?.value : undefined;
|
|
1288
|
+
const configRead = builtin?.name === "config" && !wantsHelp && (readMode === undefined || readMode === "get");
|
|
1289
|
+
const completionStatus = builtin?.name === "completion" && !wantsHelp && readMode === undefined;
|
|
1290
|
+
let useExtensionOverlay = opts.extensions && !docsHelp && !updateCheck && !selfUpdate && !preference?.auto && !preference?.notify && builtin?.name !== "start";
|
|
1291
|
+
function skipUnreadableConnectorOverlay(error) {
|
|
1292
|
+
if (!(error instanceof UnreadableConnectorSelection) || !builtin || !["version", "status", "down"].includes(builtin.name))
|
|
1293
|
+
return false;
|
|
1294
|
+
if (builtin.name === "down") {
|
|
1295
|
+
const parsed = parseOrExit(builtin, ownWords(builtin));
|
|
1296
|
+
if (parsed.positionals.length || parsed.values.file || parsed.values.run || parsed.values["with-agents"] || parsed.values["preserve-state"])
|
|
1297
|
+
return false;
|
|
1298
|
+
}
|
|
1299
|
+
// These built-ins can report or stop recorded state without loading extension commands.
|
|
1300
|
+
// Status still reports the unreadable inventory from its own readers.
|
|
1301
|
+
useExtensionOverlay = false;
|
|
1302
|
+
setInstalledExtensionsEnabled(false);
|
|
1303
|
+
return true;
|
|
1304
|
+
}
|
|
1305
|
+
const configFolder = globalConfigDirProblem();
|
|
1306
|
+
function surface(warnings) {
|
|
1307
|
+
let commands;
|
|
1308
|
+
try {
|
|
1309
|
+
commands = useExtensionOverlay && !versionRead && !extDiagnostics && !configFolder ? overlayExtensions(registry, collisionWarning(warnings)) : registry.all("command");
|
|
1310
|
+
}
|
|
1311
|
+
catch (e) {
|
|
1312
|
+
const infrastructureStatus = builtin?.name === "status" && !wantsHelp && !words.includes("--components")
|
|
1313
|
+
&& metadataPositionals(builtin, words).positionals.length === 0;
|
|
1314
|
+
if (((configRead || completionStatus || infrastructureStatus) && e instanceof CorruptExtensionsManifestError)
|
|
1315
|
+
|| (infrastructureStatus && isCommandFailure(e) && e.code === "PERMISSION_DENIED") || skipUnreadableConnectorOverlay(e)) {
|
|
1316
|
+
// The infrastructure report reads the manifest itself and can name the gap.
|
|
1317
|
+
if (infrastructureStatus)
|
|
1318
|
+
setInstalledExtensionsEnabled(false);
|
|
1319
|
+
commands = registry.all("command");
|
|
1196
1320
|
}
|
|
1197
|
-
|
|
1198
|
-
if (
|
|
1199
|
-
|
|
1200
|
-
|
|
1321
|
+
else {
|
|
1322
|
+
if (repeatedLeading)
|
|
1323
|
+
usageExit(`Option '${repeatedLeading}' cannot be repeated`);
|
|
1324
|
+
overlayFailureExit(e, builtin, words, wantsHelp, scope);
|
|
1201
1325
|
}
|
|
1202
1326
|
}
|
|
1327
|
+
for (const cmd of commands) {
|
|
1328
|
+
const problems = [
|
|
1329
|
+
...commandDeclarationProblems(cmd),
|
|
1330
|
+
...outputDeclarationProblems(cmd),
|
|
1331
|
+
...(cmd.subcommands ?? []).flatMap((sub) => outputDeclarationProblems({ name: `${cmd.name} ${sub.name}`, outputs: sub.outputs, flags: cmd.flags })),
|
|
1332
|
+
...globalFlagDeclarationProblems(cmd),
|
|
1333
|
+
];
|
|
1334
|
+
if (problems.length)
|
|
1335
|
+
usageExit(`internal error: ${problems.join("; ")}`);
|
|
1336
|
+
}
|
|
1337
|
+
setCommandSurface(commands); // the completion dispatcher reads the SAME surface help renders
|
|
1338
|
+
return commands;
|
|
1203
1339
|
}
|
|
1340
|
+
return { configFolder, configRead, surface, useExtensionOverlay, skipUnreadableConnectorOverlay };
|
|
1341
|
+
}
|
|
1342
|
+
function deferStartupSeed(parsed) {
|
|
1343
|
+
// Startup checks seed compatibility here and reconciles at launch. A restore that refuses
|
|
1344
|
+
// before launch leaves the operator-global store as it found it.
|
|
1345
|
+
// Broker-only startup still checks the store generation. An explicit restore can start its
|
|
1346
|
+
// recorded manager even when `--no-manager` is present, so it retains the full seed path.
|
|
1347
|
+
const brokerOnly = parsed?.values["no-manager"] === true && !parsed.values.restore;
|
|
1348
|
+
const refusal = brokerOnly ? seedDowngradeRefusal() : deferredSeedRefusal();
|
|
1349
|
+
if (refusal)
|
|
1350
|
+
throw refusal;
|
|
1351
|
+
if (!brokerOnly)
|
|
1352
|
+
deferSeedToLaunch();
|
|
1353
|
+
}
|
|
1354
|
+
function dispatchSeedRefusal(e, cmd, parsed, rest) {
|
|
1355
|
+
// The seed runs before the command reaches its own failure path. A structured command still
|
|
1356
|
+
// reports the same outcome and exit status in every presentation.
|
|
1357
|
+
const sub = parsed?.positionals[0] ?? (cmd && metadataPositionals(cmd, rest).positionals[0]?.value);
|
|
1358
|
+
if (cmd && structured(cmd, sub)) {
|
|
1359
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
1360
|
+
const failure = isCommandFailure(e) ? e : new CommandFailure("refused", "DEPENDENCY_UNAVAILABLE", displayRemedy(message), e instanceof SeedChildFailure ? { remedy: displayRemedy("fix that, then run `cotal ext seed --repair`") } : {});
|
|
1361
|
+
const end = rest.indexOf("--");
|
|
1362
|
+
const plain = parsed?.values.plain === true || (!parsed && (end === -1 ? rest : rest.slice(0, end)).includes("--plain"));
|
|
1363
|
+
failureExit(cmd, failure, asksForJson(cmd, rest), plain, undefined, rest);
|
|
1364
|
+
}
|
|
1365
|
+
seedRefusal(e);
|
|
1366
|
+
process.exit(1);
|
|
1367
|
+
}
|
|
1368
|
+
async function executeDispatchedCommand(cmd, parsed, rest, argv, opts, scope, configRead) {
|
|
1369
|
+
const updateDirectory = cmd.name === "update" ? prepareUpdateFolder(parsed) : undefined;
|
|
1370
|
+
checkCommandLocalState(cmd, parsed, rest);
|
|
1204
1371
|
// Keep failures in the resolved space and completion warnings behind COTAL_COMPLETE_DEBUG.
|
|
1205
1372
|
if (cmd.name === "__complete" && !debugFlag("COTAL_COMPLETE_DEBUG"))
|
|
1206
1373
|
scope.quiet = true;
|
|
1207
|
-
const execute =
|
|
1374
|
+
const execute = () => withProjectTrustMigration(parsed.values["dry-run"] !== true && cmd.name !== "update", structured(cmd, parsed.positionals[0]) && parsed.values.json === true, executeCommand);
|
|
1375
|
+
const executeCommand = async () => npmProjectDirectory.run(updateDirectory, async () => {
|
|
1208
1376
|
if (opts.extensions && cmd.requiredExtensions) {
|
|
1209
1377
|
for (const ref of cmd.requiredExtensions(parsed))
|
|
1210
1378
|
await materializeExtension(ref);
|