@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.
Files changed (282) hide show
  1. package/dist/chat/chat-view.d.ts.map +1 -1
  2. package/dist/chat/chat-view.js +8 -2
  3. package/dist/chat/chat-view.js.map +1 -1
  4. package/dist/chat/controller.d.ts +1 -1
  5. package/dist/chat/controller.d.ts.map +1 -1
  6. package/dist/chat/controller.js +8 -5
  7. package/dist/chat/controller.js.map +1 -1
  8. package/dist/chat/plain.d.ts.map +1 -1
  9. package/dist/chat/plain.js +7 -3
  10. package/dist/chat/plain.js.map +1 -1
  11. package/dist/chat/stdio-io.d.ts.map +1 -1
  12. package/dist/chat/stdio-io.js +10 -4
  13. package/dist/chat/stdio-io.js.map +1 -1
  14. package/dist/command.d.ts.map +1 -1
  15. package/dist/command.js +119 -52
  16. package/dist/command.js.map +1 -1
  17. package/dist/commands/agents.d.ts.map +1 -1
  18. package/dist/commands/agents.js +71 -24
  19. package/dist/commands/agents.js.map +1 -1
  20. package/dist/commands/backup-restore.js +1 -1
  21. package/dist/commands/backup-restore.js.map +1 -1
  22. package/dist/commands/backup.d.ts.map +1 -1
  23. package/dist/commands/backup.js +5 -1
  24. package/dist/commands/backup.js.map +1 -1
  25. package/dist/commands/channel-members.d.ts.map +1 -1
  26. package/dist/commands/channel-members.js +3 -2
  27. package/dist/commands/channel-members.js.map +1 -1
  28. package/dist/commands/channels.d.ts.map +1 -1
  29. package/dist/commands/channels.js +7 -5
  30. package/dist/commands/channels.js.map +1 -1
  31. package/dist/commands/clean.d.ts.map +1 -1
  32. package/dist/commands/clean.js +58 -8
  33. package/dist/commands/clean.js.map +1 -1
  34. package/dist/commands/config.js +1 -1
  35. package/dist/commands/config.js.map +1 -1
  36. package/dist/commands/describe.d.ts.map +1 -1
  37. package/dist/commands/describe.js +12 -9
  38. package/dist/commands/describe.js.map +1 -1
  39. package/dist/commands/doctor.d.ts.map +1 -1
  40. package/dist/commands/doctor.js +37 -7
  41. package/dist/commands/doctor.js.map +1 -1
  42. package/dist/commands/down-preserve.d.ts.map +1 -1
  43. package/dist/commands/down-preserve.js +14 -2
  44. package/dist/commands/down-preserve.js.map +1 -1
  45. package/dist/commands/down.d.ts.map +1 -1
  46. package/dist/commands/down.js +13 -3
  47. package/dist/commands/down.js.map +1 -1
  48. package/dist/commands/endpoint-authoring.d.ts.map +1 -1
  49. package/dist/commands/endpoint-authoring.js +6 -3
  50. package/dist/commands/endpoint-authoring.js.map +1 -1
  51. package/dist/commands/endpoint.d.ts.map +1 -1
  52. package/dist/commands/endpoint.js +9 -4
  53. package/dist/commands/endpoint.js.map +1 -1
  54. package/dist/commands/ext.js +4 -4
  55. package/dist/commands/ext.js.map +1 -1
  56. package/dist/commands/help.js +2 -2
  57. package/dist/commands/help.js.map +1 -1
  58. package/dist/commands/history.d.ts +1 -9
  59. package/dist/commands/history.d.ts.map +1 -1
  60. package/dist/commands/history.js +6 -16
  61. package/dist/commands/history.js.map +1 -1
  62. package/dist/commands/join.js +14 -5
  63. package/dist/commands/join.js.map +1 -1
  64. package/dist/commands/manager-service.d.ts.map +1 -1
  65. package/dist/commands/manager-service.js +9 -1
  66. package/dist/commands/manager-service.js.map +1 -1
  67. package/dist/commands/meshes.js +1 -1
  68. package/dist/commands/meshes.js.map +1 -1
  69. package/dist/commands/persona.d.ts.map +1 -1
  70. package/dist/commands/persona.js +25 -16
  71. package/dist/commands/persona.js.map +1 -1
  72. package/dist/commands/personas.js +3 -2
  73. package/dist/commands/personas.js.map +1 -1
  74. package/dist/commands/reset-space-apply.d.ts.map +1 -1
  75. package/dist/commands/reset-space-apply.js +4 -2
  76. package/dist/commands/reset-space-apply.js.map +1 -1
  77. package/dist/commands/reset-store-apply.d.ts.map +1 -1
  78. package/dist/commands/reset-store-apply.js +14 -6
  79. package/dist/commands/reset-store-apply.js.map +1 -1
  80. package/dist/commands/runtimes.d.ts +2 -2
  81. package/dist/commands/runtimes.d.ts.map +1 -1
  82. package/dist/commands/runtimes.js +27 -10
  83. package/dist/commands/runtimes.js.map +1 -1
  84. package/dist/commands/send.d.ts.map +1 -1
  85. package/dist/commands/send.js +2 -1
  86. package/dist/commands/send.js.map +1 -1
  87. package/dist/commands/service-actions.d.ts.map +1 -1
  88. package/dist/commands/service-actions.js +4 -3
  89. package/dist/commands/service-actions.js.map +1 -1
  90. package/dist/commands/service-registry.d.ts.map +1 -1
  91. package/dist/commands/service-registry.js +17 -9
  92. package/dist/commands/service-registry.js.map +1 -1
  93. package/dist/commands/setup.d.ts +5 -0
  94. package/dist/commands/setup.d.ts.map +1 -1
  95. package/dist/commands/setup.js +85 -3
  96. package/dist/commands/setup.js.map +1 -1
  97. package/dist/commands/space-delete.d.ts.map +1 -1
  98. package/dist/commands/space-delete.js +4 -2
  99. package/dist/commands/space-delete.js.map +1 -1
  100. package/dist/commands/space-registration.d.ts +1 -1
  101. package/dist/commands/space-registration.d.ts.map +1 -1
  102. package/dist/commands/space-registration.js +22 -6
  103. package/dist/commands/space-registration.js.map +1 -1
  104. package/dist/commands/space.d.ts.map +1 -1
  105. package/dist/commands/space.js +27 -10
  106. package/dist/commands/space.js.map +1 -1
  107. package/dist/commands/spawn-managed-launch.js +1 -1
  108. package/dist/commands/spawn-managed-launch.js.map +1 -1
  109. package/dist/commands/spawn-preview.d.ts.map +1 -1
  110. package/dist/commands/spawn-preview.js +23 -6
  111. package/dist/commands/spawn-preview.js.map +1 -1
  112. package/dist/commands/spawn.d.ts.map +1 -1
  113. package/dist/commands/spawn.js +19 -4
  114. package/dist/commands/spawn.js.map +1 -1
  115. package/dist/commands/stack-down.d.ts +1 -1
  116. package/dist/commands/stack-down.d.ts.map +1 -1
  117. package/dist/commands/stack-down.js +14 -6
  118. package/dist/commands/stack-down.js.map +1 -1
  119. package/dist/commands/stack-up.d.ts +1 -0
  120. package/dist/commands/stack-up.d.ts.map +1 -1
  121. package/dist/commands/stack-up.js +6 -4
  122. package/dist/commands/stack-up.js.map +1 -1
  123. package/dist/commands/status-health.d.ts +1 -1
  124. package/dist/commands/status-health.d.ts.map +1 -1
  125. package/dist/commands/status-health.js +46 -41
  126. package/dist/commands/status-health.js.map +1 -1
  127. package/dist/commands/status-meshes.d.ts +2 -0
  128. package/dist/commands/status-meshes.d.ts.map +1 -1
  129. package/dist/commands/status-meshes.js +13 -1
  130. package/dist/commands/status-meshes.js.map +1 -1
  131. package/dist/commands/status-model.d.ts +2 -0
  132. package/dist/commands/status-model.d.ts.map +1 -1
  133. package/dist/commands/status-model.js.map +1 -1
  134. package/dist/commands/status-render.d.ts.map +1 -1
  135. package/dist/commands/status-render.js +6 -3
  136. package/dist/commands/status-render.js.map +1 -1
  137. package/dist/commands/status.d.ts.map +1 -1
  138. package/dist/commands/status.js +9 -8
  139. package/dist/commands/status.js.map +1 -1
  140. package/dist/commands/team-agent-remove.d.ts.map +1 -1
  141. package/dist/commands/team-agent-remove.js +4 -3
  142. package/dist/commands/team-agent-remove.js.map +1 -1
  143. package/dist/commands/team-boot-controller.js +1 -1
  144. package/dist/commands/team-boot-controller.js.map +1 -1
  145. package/dist/commands/team-channel-remove.d.ts.map +1 -1
  146. package/dist/commands/team-channel-remove.js +4 -3
  147. package/dist/commands/team-channel-remove.js.map +1 -1
  148. package/dist/commands/team-deploy-apply.js +5 -9
  149. package/dist/commands/team-deploy-apply.js.map +1 -1
  150. package/dist/commands/team-mixed-remove.d.ts.map +1 -1
  151. package/dist/commands/team-mixed-remove.js +4 -3
  152. package/dist/commands/team-mixed-remove.js.map +1 -1
  153. package/dist/commands/team.js +10 -5
  154. package/dist/commands/team.js.map +1 -1
  155. package/dist/commands/up-args.d.ts +1 -1
  156. package/dist/commands/up-args.d.ts.map +1 -1
  157. package/dist/commands/up-args.js +28 -13
  158. package/dist/commands/up-args.js.map +1 -1
  159. package/dist/commands/up-detach.d.ts +3 -0
  160. package/dist/commands/up-detach.d.ts.map +1 -1
  161. package/dist/commands/up-detach.js +3 -1
  162. package/dist/commands/up-detach.js.map +1 -1
  163. package/dist/commands/up-manifest.d.ts.map +1 -1
  164. package/dist/commands/up-manifest.js +5 -3
  165. package/dist/commands/up-manifest.js.map +1 -1
  166. package/dist/commands/up-resume.d.ts +59 -0
  167. package/dist/commands/up-resume.d.ts.map +1 -0
  168. package/dist/commands/up-resume.js +764 -0
  169. package/dist/commands/up-resume.js.map +1 -0
  170. package/dist/commands/up-target.d.ts +2 -0
  171. package/dist/commands/up-target.d.ts.map +1 -1
  172. package/dist/commands/up-target.js +10 -0
  173. package/dist/commands/up-target.js.map +1 -1
  174. package/dist/commands/up.d.ts.map +1 -1
  175. package/dist/commands/up.js +27 -773
  176. package/dist/commands/up.js.map +1 -1
  177. package/dist/commands/update-process.js +7 -6
  178. package/dist/commands/update-process.js.map +1 -1
  179. package/dist/commands/update-release.d.ts +6 -1
  180. package/dist/commands/update-release.d.ts.map +1 -1
  181. package/dist/commands/update-release.js +19 -5
  182. package/dist/commands/update-release.js.map +1 -1
  183. package/dist/commands/update.d.ts +3 -0
  184. package/dist/commands/update.d.ts.map +1 -1
  185. package/dist/commands/update.js +93 -69
  186. package/dist/commands/update.js.map +1 -1
  187. package/dist/commands/use.d.ts.map +1 -1
  188. package/dist/commands/use.js +8 -3
  189. package/dist/commands/use.js.map +1 -1
  190. package/dist/ext-loader.d.ts +10 -0
  191. package/dist/ext-loader.d.ts.map +1 -1
  192. package/dist/ext-loader.js +19 -0
  193. package/dist/ext-loader.js.map +1 -1
  194. package/dist/help.d.ts.map +1 -1
  195. package/dist/help.js +13 -4
  196. package/dist/help.js.map +1 -1
  197. package/dist/index.d.ts.map +1 -1
  198. package/dist/index.js +3 -2
  199. package/dist/index.js.map +1 -1
  200. package/dist/lib/choose-target.d.ts +1 -1
  201. package/dist/lib/choose-target.d.ts.map +1 -1
  202. package/dist/lib/choose-target.js +9 -5
  203. package/dist/lib/choose-target.js.map +1 -1
  204. package/dist/lib/completion-install.d.ts.map +1 -1
  205. package/dist/lib/completion-install.js +9 -4
  206. package/dist/lib/completion-install.js.map +1 -1
  207. package/dist/lib/confirmation-required.d.ts +7 -1
  208. package/dist/lib/confirmation-required.d.ts.map +1 -1
  209. package/dist/lib/confirmation-required.js +10 -3
  210. package/dist/lib/confirmation-required.js.map +1 -1
  211. package/dist/lib/delivery-proc.d.ts +1 -0
  212. package/dist/lib/delivery-proc.d.ts.map +1 -1
  213. package/dist/lib/endpoint-errors.d.ts +1 -0
  214. package/dist/lib/endpoint-errors.d.ts.map +1 -1
  215. package/dist/lib/endpoint-errors.js +9 -1
  216. package/dist/lib/endpoint-errors.js.map +1 -1
  217. package/dist/lib/endpoint-scatter.d.ts +1 -1
  218. package/dist/lib/endpoint-scatter.d.ts.map +1 -1
  219. package/dist/lib/endpoint-scatter.js +12 -2
  220. package/dist/lib/endpoint-scatter.js.map +1 -1
  221. package/dist/lib/endpoint-selection.js +1 -1
  222. package/dist/lib/endpoint-selection.js.map +1 -1
  223. package/dist/lib/follow-setup-failure.d.ts +23 -0
  224. package/dist/lib/follow-setup-failure.d.ts.map +1 -0
  225. package/dist/lib/follow-setup-failure.js +23 -0
  226. package/dist/lib/follow-setup-failure.js.map +1 -0
  227. package/dist/lib/manager-proc.d.ts +1 -0
  228. package/dist/lib/manager-proc.d.ts.map +1 -1
  229. package/dist/lib/manager-proc.js +7 -4
  230. package/dist/lib/manager-proc.js.map +1 -1
  231. package/dist/lib/npm-invocation.d.ts +2 -1
  232. package/dist/lib/npm-invocation.d.ts.map +1 -1
  233. package/dist/lib/npm-invocation.js +81 -11
  234. package/dist/lib/npm-invocation.js.map +1 -1
  235. package/dist/lib/persona-files.d.ts +11 -1
  236. package/dist/lib/persona-files.d.ts.map +1 -1
  237. package/dist/lib/persona-files.js +35 -11
  238. package/dist/lib/persona-files.js.map +1 -1
  239. package/dist/lib/personas.d.ts +1 -0
  240. package/dist/lib/personas.d.ts.map +1 -1
  241. package/dist/lib/personas.js +4 -1
  242. package/dist/lib/personas.js.map +1 -1
  243. package/dist/lib/self-exec.d.ts +1 -0
  244. package/dist/lib/self-exec.d.ts.map +1 -1
  245. package/dist/lib/self-exec.js +4 -1
  246. package/dist/lib/self-exec.js.map +1 -1
  247. package/dist/lib/service-preset-target.d.ts.map +1 -1
  248. package/dist/lib/service-preset-target.js +13 -2
  249. package/dist/lib/service-preset-target.js.map +1 -1
  250. package/dist/lib/service-start-options.d.ts +2 -0
  251. package/dist/lib/service-start-options.d.ts.map +1 -0
  252. package/dist/lib/service-start-options.js +4 -0
  253. package/dist/lib/service-start-options.js.map +1 -0
  254. package/dist/lib/spawn-defaults.d.ts +2 -0
  255. package/dist/lib/spawn-defaults.d.ts.map +1 -1
  256. package/dist/lib/spawn-defaults.js +10 -1
  257. package/dist/lib/spawn-defaults.js.map +1 -1
  258. package/dist/lib/stack-journal.js +2 -2
  259. package/dist/lib/stack-journal.js.map +1 -1
  260. package/dist/lib/status.d.ts +3 -0
  261. package/dist/lib/status.d.ts.map +1 -1
  262. package/dist/lib/status.js +17 -1
  263. package/dist/lib/status.js.map +1 -1
  264. package/dist/lib/store-dir.d.ts +1 -1
  265. package/dist/lib/store-dir.d.ts.map +1 -1
  266. package/dist/lib/store-dir.js +5 -2
  267. package/dist/lib/store-dir.js.map +1 -1
  268. package/dist/lib/team-deploy-inspection.d.ts +43 -37
  269. package/dist/lib/team-deploy-inspection.d.ts.map +1 -1
  270. package/dist/lib/team-deploy-inspection.js +53 -7
  271. package/dist/lib/team-deploy-inspection.js.map +1 -1
  272. package/dist/lib/up-manager-name.d.ts +4 -0
  273. package/dist/lib/up-manager-name.d.ts.map +1 -0
  274. package/dist/lib/up-manager-name.js +25 -0
  275. package/dist/lib/up-manager-name.js.map +1 -0
  276. package/dist/seed/reconcile.js +1 -1
  277. package/dist/seed/reconcile.js.map +1 -1
  278. package/dist/telemetry.d.ts +2 -3
  279. package/dist/telemetry.d.ts.map +1 -1
  280. package/dist/telemetry.js +26 -13
  281. package/dist/telemetry.js.map +1 -1
  282. 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 "./commands/history.js";
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
- /** Separate globals before `--` without applying them to a command that takes its words raw. */
57
- function splitGlobalFlags(words, leading) {
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
- const head = (end === -1 ? words : words.slice(0, end)).filter((word) => {
60
+ for (const word of words) {
61
+ if (word === "--")
62
+ break;
62
63
  if (!GLOBAL_FLAG_WORDS.has(word))
63
- return true;
64
+ continue;
64
65
  if (leading.has(word) || flags.has(word))
65
66
  repeated ??= word;
66
67
  flags.add(word);
67
- return false;
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(`Option '${word}' cannot be repeated`, found, json, options.includes("--plain"), undefined, rest));
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 historyFollow = cmd.name === "history" && validationArgs?.values.follow === true && !plain
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
- : cmd.name === "watch" && validationArgs && !plain ? watchSetupFailureRecords(validationArgs, failure) : undefined;
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 the refusal as an envelope, so stdout stays one document and the help text
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 takes operands and there is no spelling suggestion.
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}` : "to pass a word that starts with \"-\", put -- before it";
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 = Object.fromEntries((cmd.flags ?? []).map(({ name, type, short }) => [name, { type, ...(short ? { short } : {}) }]));
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 refusal = parseRefusal(e, cmd, rest, seed?.flagNames ?? selected.flagNames, takesOperands);
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
- // History also accepts a root channel positional; only its reserved clear token is a mode.
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
- /** The parsed args with a subcommand alias in the first positional replaced by its name, so `run`
607
- * only ever sees canonical subcommands. */
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 sub = findSubcommand(surface, positionals[index]);
614
- if (!sub)
615
- break;
616
- changed ||= sub.name !== positionals[index];
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 = splitGlobalFlags(words, leadingGlobals);
768
+ const globals = collectGlobalFlags(words, leadingGlobals);
710
769
  const ownWords = (cmd) => {
711
- if (takesWordsRaw(cmd))
712
- return [...words];
713
- for (const option of globals.flags)
714
- takeGlobalFlag(option);
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 spaceRemedy = spaceChoiceRemedy(isConnectRefusal(e) ? e.cause : e, cmd.name, parsed, rest);
1040
- const renderRemedy = spaceRemedy !== undefined ? () => spaceRemedy : ["status", "ps", "space", "whoami"].includes(cmd.name) ? displayRemedy : undefined;
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) {