@cotal-ai/cli 0.176.6 → 0.178.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 (259) hide show
  1. package/dist/command.d.ts.map +1 -1
  2. package/dist/command.js +138 -59
  3. package/dist/command.js.map +1 -1
  4. package/dist/commands/agents.d.ts.map +1 -1
  5. package/dist/commands/agents.js +9 -6
  6. package/dist/commands/agents.js.map +1 -1
  7. package/dist/commands/backup-maintenance.js +4 -4
  8. package/dist/commands/backup-maintenance.js.map +1 -1
  9. package/dist/commands/backup-restore.js +5 -5
  10. package/dist/commands/backup-restore.js.map +1 -1
  11. package/dist/commands/backup.d.ts.map +1 -1
  12. package/dist/commands/backup.js +11 -6
  13. package/dist/commands/backup.js.map +1 -1
  14. package/dist/commands/channel-members.js +1 -1
  15. package/dist/commands/channels.js +1 -1
  16. package/dist/commands/channels.js.map +1 -1
  17. package/dist/commands/describe.d.ts.map +1 -1
  18. package/dist/commands/describe.js +25 -8
  19. package/dist/commands/describe.js.map +1 -1
  20. package/dist/commands/doctor.d.ts.map +1 -1
  21. package/dist/commands/doctor.js +16 -3
  22. package/dist/commands/doctor.js.map +1 -1
  23. package/dist/commands/down-preserve.d.ts.map +1 -1
  24. package/dist/commands/down-preserve.js +2 -2
  25. package/dist/commands/down-preserve.js.map +1 -1
  26. package/dist/commands/down.d.ts.map +1 -1
  27. package/dist/commands/down.js +14 -17
  28. package/dist/commands/down.js.map +1 -1
  29. package/dist/commands/endpoint-authoring.d.ts.map +1 -1
  30. package/dist/commands/endpoint-authoring.js +10 -5
  31. package/dist/commands/endpoint-authoring.js.map +1 -1
  32. package/dist/commands/ext.js +10 -2
  33. package/dist/commands/ext.js.map +1 -1
  34. package/dist/commands/help.d.ts.map +1 -1
  35. package/dist/commands/help.js +18 -3
  36. package/dist/commands/help.js.map +1 -1
  37. package/dist/commands/history.d.ts.map +1 -1
  38. package/dist/commands/history.js +4 -2
  39. package/dist/commands/history.js.map +1 -1
  40. package/dist/commands/join.js +6 -7
  41. package/dist/commands/join.js.map +1 -1
  42. package/dist/commands/mint.d.ts.map +1 -1
  43. package/dist/commands/mint.js +7 -5
  44. package/dist/commands/mint.js.map +1 -1
  45. package/dist/commands/persona.d.ts.map +1 -1
  46. package/dist/commands/persona.js +15 -8
  47. package/dist/commands/persona.js.map +1 -1
  48. package/dist/commands/reset-space-apply.d.ts.map +1 -1
  49. package/dist/commands/reset-space-apply.js +2 -1
  50. package/dist/commands/reset-space-apply.js.map +1 -1
  51. package/dist/commands/reset-store-apply.d.ts +1 -1
  52. package/dist/commands/reset-store-apply.d.ts.map +1 -1
  53. package/dist/commands/reset-store-apply.js +10 -4
  54. package/dist/commands/reset-store-apply.js.map +1 -1
  55. package/dist/commands/reset.d.ts.map +1 -1
  56. package/dist/commands/reset.js +2 -1
  57. package/dist/commands/reset.js.map +1 -1
  58. package/dist/commands/send.js +5 -4
  59. package/dist/commands/send.js.map +1 -1
  60. package/dist/commands/service-actions.d.ts.map +1 -1
  61. package/dist/commands/service-actions.js +17 -8
  62. package/dist/commands/service-actions.js.map +1 -1
  63. package/dist/commands/service-registry.d.ts.map +1 -1
  64. package/dist/commands/service-registry.js +16 -11
  65. package/dist/commands/service-registry.js.map +1 -1
  66. package/dist/commands/service-set-stop.d.ts.map +1 -1
  67. package/dist/commands/service-set-stop.js +3 -2
  68. package/dist/commands/service-set-stop.js.map +1 -1
  69. package/dist/commands/setup.d.ts +1 -1
  70. package/dist/commands/setup.d.ts.map +1 -1
  71. package/dist/commands/setup.js +7 -1
  72. package/dist/commands/setup.js.map +1 -1
  73. package/dist/commands/space-delete.d.ts.map +1 -1
  74. package/dist/commands/space-delete.js +10 -3
  75. package/dist/commands/space-delete.js.map +1 -1
  76. package/dist/commands/space-registration.d.ts.map +1 -1
  77. package/dist/commands/space-registration.js +33 -16
  78. package/dist/commands/space-registration.js.map +1 -1
  79. package/dist/commands/space.d.ts +1 -1
  80. package/dist/commands/space.d.ts.map +1 -1
  81. package/dist/commands/space.js +36 -13
  82. package/dist/commands/space.js.map +1 -1
  83. package/dist/commands/spawn-flags.d.ts +1 -0
  84. package/dist/commands/spawn-flags.d.ts.map +1 -1
  85. package/dist/commands/spawn-flags.js +4 -0
  86. package/dist/commands/spawn-flags.js.map +1 -1
  87. package/dist/commands/spawn-managed-launch.d.ts +1 -1
  88. package/dist/commands/spawn-managed-launch.d.ts.map +1 -1
  89. package/dist/commands/spawn-managed-launch.js +7 -4
  90. package/dist/commands/spawn-managed-launch.js.map +1 -1
  91. package/dist/commands/spawn-preview.d.ts.map +1 -1
  92. package/dist/commands/spawn-preview.js +8 -4
  93. package/dist/commands/spawn-preview.js.map +1 -1
  94. package/dist/commands/spawn.d.ts.map +1 -1
  95. package/dist/commands/spawn.js +4 -2
  96. package/dist/commands/spawn.js.map +1 -1
  97. package/dist/commands/stack-down.d.ts.map +1 -1
  98. package/dist/commands/stack-down.js +3 -1
  99. package/dist/commands/stack-down.js.map +1 -1
  100. package/dist/commands/stack-gone.d.ts +2 -0
  101. package/dist/commands/stack-gone.d.ts.map +1 -1
  102. package/dist/commands/stack-gone.js +36 -15
  103. package/dist/commands/stack-gone.js.map +1 -1
  104. package/dist/commands/stack-up.d.ts +1 -1
  105. package/dist/commands/stack-up.d.ts.map +1 -1
  106. package/dist/commands/stack-up.js +38 -5
  107. package/dist/commands/stack-up.js.map +1 -1
  108. package/dist/commands/status-legacy.d.ts +3 -3
  109. package/dist/commands/status-legacy.d.ts.map +1 -1
  110. package/dist/commands/status-legacy.js +5 -3
  111. package/dist/commands/status-legacy.js.map +1 -1
  112. package/dist/commands/status-meshes.d.ts +5 -3
  113. package/dist/commands/status-meshes.d.ts.map +1 -1
  114. package/dist/commands/status-meshes.js +35 -9
  115. package/dist/commands/status-meshes.js.map +1 -1
  116. package/dist/commands/status-render.d.ts +2 -1
  117. package/dist/commands/status-render.d.ts.map +1 -1
  118. package/dist/commands/status-render.js +13 -10
  119. package/dist/commands/status-render.js.map +1 -1
  120. package/dist/commands/status.d.ts.map +1 -1
  121. package/dist/commands/status.js +41 -38
  122. package/dist/commands/status.js.map +1 -1
  123. package/dist/commands/sync.d.ts.map +1 -1
  124. package/dist/commands/sync.js +4 -2
  125. package/dist/commands/sync.js.map +1 -1
  126. package/dist/commands/team-channel-remove.d.ts +2 -0
  127. package/dist/commands/team-channel-remove.d.ts.map +1 -1
  128. package/dist/commands/team-channel-remove.js +16 -12
  129. package/dist/commands/team-channel-remove.js.map +1 -1
  130. package/dist/commands/team-mixed-remove.js +3 -3
  131. package/dist/commands/team-mixed-remove.js.map +1 -1
  132. package/dist/commands/team.d.ts.map +1 -1
  133. package/dist/commands/team.js +2 -15
  134. package/dist/commands/team.js.map +1 -1
  135. package/dist/commands/up-args.d.ts.map +1 -1
  136. package/dist/commands/up-args.js +23 -29
  137. package/dist/commands/up-args.js.map +1 -1
  138. package/dist/commands/up-detach.d.ts.map +1 -1
  139. package/dist/commands/up-detach.js +7 -5
  140. package/dist/commands/up-detach.js.map +1 -1
  141. package/dist/commands/up-resume.d.ts +1 -1
  142. package/dist/commands/up-resume.d.ts.map +1 -1
  143. package/dist/commands/up-resume.js +19 -15
  144. package/dist/commands/up-resume.js.map +1 -1
  145. package/dist/commands/up-target.d.ts.map +1 -1
  146. package/dist/commands/up-target.js +33 -2
  147. package/dist/commands/up-target.js.map +1 -1
  148. package/dist/commands/up.js +2 -2
  149. package/dist/commands/up.js.map +1 -1
  150. package/dist/commands/update-continuity.d.ts.map +1 -1
  151. package/dist/commands/update-continuity.js +4 -3
  152. package/dist/commands/update-continuity.js.map +1 -1
  153. package/dist/commands/update-process.d.ts.map +1 -1
  154. package/dist/commands/update-process.js +4 -1
  155. package/dist/commands/update-process.js.map +1 -1
  156. package/dist/commands/update-release.d.ts.map +1 -1
  157. package/dist/commands/update-release.js +56 -26
  158. package/dist/commands/update-release.js.map +1 -1
  159. package/dist/commands/update.d.ts +2 -2
  160. package/dist/commands/update.d.ts.map +1 -1
  161. package/dist/commands/update.js +9 -9
  162. package/dist/commands/update.js.map +1 -1
  163. package/dist/commands/use.d.ts.map +1 -1
  164. package/dist/commands/use.js +12 -9
  165. package/dist/commands/use.js.map +1 -1
  166. package/dist/commands/watch.d.ts +0 -8
  167. package/dist/commands/watch.d.ts.map +1 -1
  168. package/dist/commands/watch.js +2 -9
  169. package/dist/commands/watch.js.map +1 -1
  170. package/dist/console/ui/SpacePicker.d.ts.map +1 -1
  171. package/dist/console/ui/SpacePicker.js +2 -1
  172. package/dist/console/ui/SpacePicker.js.map +1 -1
  173. package/dist/help.d.ts +3 -2
  174. package/dist/help.d.ts.map +1 -1
  175. package/dist/help.js +6 -6
  176. package/dist/help.js.map +1 -1
  177. package/dist/lib/agent-skills.d.ts.map +1 -1
  178. package/dist/lib/agent-skills.js +11 -6
  179. package/dist/lib/agent-skills.js.map +1 -1
  180. package/dist/lib/choose-target.d.ts.map +1 -1
  181. package/dist/lib/choose-target.js +6 -3
  182. package/dist/lib/choose-target.js.map +1 -1
  183. package/dist/lib/confirmation-required.d.ts +2 -2
  184. package/dist/lib/confirmation-required.d.ts.map +1 -1
  185. package/dist/lib/confirmation-required.js +2 -2
  186. package/dist/lib/confirmation-required.js.map +1 -1
  187. package/dist/lib/endpoint-errors.d.ts +3 -0
  188. package/dist/lib/endpoint-errors.d.ts.map +1 -1
  189. package/dist/lib/endpoint-errors.js +4 -1
  190. package/dist/lib/endpoint-errors.js.map +1 -1
  191. package/dist/lib/isolated-broker.d.ts +2 -0
  192. package/dist/lib/isolated-broker.d.ts.map +1 -1
  193. package/dist/lib/isolated-broker.js +5 -1
  194. package/dist/lib/isolated-broker.js.map +1 -1
  195. package/dist/lib/leading-flags.d.ts +1 -1
  196. package/dist/lib/leading-flags.d.ts.map +1 -1
  197. package/dist/lib/leading-flags.js +9 -4
  198. package/dist/lib/leading-flags.js.map +1 -1
  199. package/dist/lib/manager-choice.d.ts +4 -0
  200. package/dist/lib/manager-choice.d.ts.map +1 -1
  201. package/dist/lib/manager-choice.js +6 -2
  202. package/dist/lib/manager-choice.js.map +1 -1
  203. package/dist/lib/manifest/index.d.ts +7 -0
  204. package/dist/lib/manifest/index.d.ts.map +1 -1
  205. package/dist/lib/manifest/index.js +16 -0
  206. package/dist/lib/manifest/index.js.map +1 -1
  207. package/dist/lib/manifest/resolve.d.ts.map +1 -1
  208. package/dist/lib/manifest/resolve.js +10 -3
  209. package/dist/lib/manifest/resolve.js.map +1 -1
  210. package/dist/lib/npm-invocation.d.ts +10 -0
  211. package/dist/lib/npm-invocation.d.ts.map +1 -1
  212. package/dist/lib/npm-invocation.js +81 -7
  213. package/dist/lib/npm-invocation.js.map +1 -1
  214. package/dist/lib/paths.d.ts +8 -0
  215. package/dist/lib/paths.d.ts.map +1 -1
  216. package/dist/lib/paths.js +28 -1
  217. package/dist/lib/paths.js.map +1 -1
  218. package/dist/lib/persona-files.d.ts +4 -0
  219. package/dist/lib/persona-files.d.ts.map +1 -1
  220. package/dist/lib/persona-files.js +24 -7
  221. package/dist/lib/persona-files.js.map +1 -1
  222. package/dist/lib/restore.d.ts +13 -13
  223. package/dist/lib/restore.d.ts.map +1 -1
  224. package/dist/lib/restore.js +32 -26
  225. package/dist/lib/restore.js.map +1 -1
  226. package/dist/lib/rolled-back-runs.d.ts +12 -6
  227. package/dist/lib/rolled-back-runs.d.ts.map +1 -1
  228. package/dist/lib/rolled-back-runs.js +109 -7
  229. package/dist/lib/rolled-back-runs.js.map +1 -1
  230. package/dist/lib/service-preset-target.d.ts.map +1 -1
  231. package/dist/lib/service-preset-target.js +10 -4
  232. package/dist/lib/service-preset-target.js.map +1 -1
  233. package/dist/lib/service-presets.d.ts +5 -0
  234. package/dist/lib/service-presets.d.ts.map +1 -1
  235. package/dist/lib/service-presets.js +17 -1
  236. package/dist/lib/service-presets.js.map +1 -1
  237. package/dist/lib/service-process.d.ts +5 -1
  238. package/dist/lib/service-process.d.ts.map +1 -1
  239. package/dist/lib/service-process.js +7 -3
  240. package/dist/lib/service-process.js.map +1 -1
  241. package/dist/lib/stack-journal.d.ts.map +1 -1
  242. package/dist/lib/stack-journal.js +15 -11
  243. package/dist/lib/stack-journal.js.map +1 -1
  244. package/dist/lib/{follow-setup-failure.d.ts → stream-setup-failure.d.ts} +11 -3
  245. package/dist/lib/stream-setup-failure.d.ts.map +1 -0
  246. package/dist/lib/stream-setup-failure.js +41 -0
  247. package/dist/lib/stream-setup-failure.js.map +1 -0
  248. package/dist/seed/reconcile.d.ts +1 -1
  249. package/dist/seed/reconcile.d.ts.map +1 -1
  250. package/dist/seed/reconcile.js +6 -6
  251. package/dist/seed/reconcile.js.map +1 -1
  252. package/dist/seed/verify.d.ts +2 -2
  253. package/dist/seed/verify.d.ts.map +1 -1
  254. package/dist/seed/verify.js +6 -3
  255. package/dist/seed/verify.js.map +1 -1
  256. package/package.json +4 -4
  257. package/dist/lib/follow-setup-failure.d.ts.map +0 -1
  258. package/dist/lib/follow-setup-failure.js +0 -23
  259. package/dist/lib/follow-setup-failure.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../src/command.ts"],"names":[],"mappings":"AAIA,OAAO,EAA6E,KAAK,OAAO,EAAkC,KAAK,QAAQ,EAAmB,MAAM,gBAAgB,CAAC;AAiEzL,OAAO,EAAqB,KAAK,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAqUlF,2DAA2D;AAC3D,MAAM,WAAW,aAAa;IAC5B;;;oCAGgC;IAChC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;gCAE4B;IAC5B,aAAa,CAAC,EAAE,aAAa,CAAC;CAC/B;AAsPD,+FAA+F;AAC/F,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,CAUtE;AAwHD;;;;;;;;;;GAUG;AACH,wBAAsB,MAAM,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,IAAI,GAAE,aAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAmVxG"}
1
+ {"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../src/command.ts"],"names":[],"mappings":"AAIA,OAAO,EAA6E,KAAK,OAAO,EAAkC,KAAK,QAAQ,EAAmB,MAAM,gBAAgB,CAAC;AAkEzL,OAAO,EAAqB,KAAK,aAAa,EAAE,MAAM,2BAA2B,CAAC;AA4VlF,2DAA2D;AAC3D,MAAM,WAAW,aAAa;IAC5B;;;oCAGgC;IAChC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;gCAE4B;IAC5B,aAAa,CAAC,EAAE,aAAa,CAAC;CAC/B;AA+QD,+FAA+F;AAC/F,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,CAUtE;AAyID;;;;;;;;;;GAUG;AACH,wBAAgB,MAAM,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,IAAI,GAAE,aAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAGlG"}
package/dist/command.js CHANGED
@@ -3,17 +3,16 @@ 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, 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";
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, staleStoreHint, UnreadableConnectorSelection, } from "@cotal-ai/workspace";
7
7
  import { c, stderrLine } from "./ui.js";
8
8
  import { debugFlag } from "./lib/debug-flag.js";
9
- import { isExtensionStub, materializeExtension, materializeExtensionCommand, overlayExtensions, setCommandSurface, setInstalledExtensionsEnabled, } from "./ext-loader.js";
9
+ import { commandSurface, isExtensionStub, materializeExtension, materializeExtensionCommand, overlayExtensions, setCommandSurface, setInstalledExtensionsEnabled, } from "./ext-loader.js";
10
10
  import { recoverExtensionPromotion } from "./lib/extension-stage.js";
11
11
  import { SeedChildFailure, deferredSeedRefusal, reconcileSeededConnectors, seedDowngradeRefusal } from "./seed/reconcile.js";
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, membershipSetupFailureRecords } from "./lib/follow-setup-failure.js";
16
- import { watchSetupFailureRecords } from "./commands/watch.js";
15
+ import { historySetupFailureRecords, membershipSetupFailureRecords, watchSetupFailureRecords } from "./lib/stream-setup-failure.js";
17
16
  import { HISTORY_LIMIT_FLAGS } from "./commands/history-limit.js";
18
17
  import { CatalogPreparationError, prepareCatalogCommand } from "./commands/sync.js";
19
18
  import { keepStartupNotice } from "./lib/interrupt-notice.js";
@@ -22,7 +21,7 @@ import { chooseMeshTarget, spaceChoiceRemedy } from "./lib/choose-target.js";
22
21
  import { registryFailure } from "./lib/registry-errors.js";
23
22
  import { FlagValueRefusal } from "./lib/flag-value-refusal.js";
24
23
  import { workingFolderRemoved } from "./lib/paths.js";
25
- import { preserveUpdatePath } from "./lib/npm-invocation.js";
24
+ import { npmProjectDirectory, preserveUpdatePath } from "./lib/npm-invocation.js";
26
25
  import { reportLostOutput, writeAllSync } from "./lib/stdout-owner.js";
27
26
  import { shellWord } from "./lib/endpoint-errors.js";
28
27
  import { displayRemedy, hasMovedStackRemedy } from "./lib/self-exec.js";
@@ -132,6 +131,31 @@ function asksForJson(cmd, args) {
132
131
  return json;
133
132
  });
134
133
  }
134
+ function collisionWarning(warnings) {
135
+ return (message) => { warnings.push({ code: "EXTENSION_COMMAND_COLLISION", target: null, message: message.slice(2) }); };
136
+ }
137
+ /** Built-in finite JSON receipts carry collision warnings. Other output keeps them on stderr. */
138
+ function routeCollisionWarnings(warnings, cmd, words, wantsHelp) {
139
+ if (!warnings.length)
140
+ return;
141
+ let finiteJson = false;
142
+ if (cmd && !wantsHelp && !isExtensionStub(cmd) && !takesWordsRaw(cmd) && asksForJson(cmd, words)) {
143
+ const sub = findSubcommand(cmd, metadataPositionals(cmd, words).positionals[0]?.value);
144
+ const outputs = sub ? sub.outputs : cmd.outputs;
145
+ if (outputs?.includes("json")) {
146
+ const values = !outputs.includes("ndjson") ? undefined
147
+ : cmd.name === "history" || cmd.name === "channel" ? streamRefusalArgs(cmd, words)?.values
148
+ : parseArgs({ args: words, options: parserOptions(cmd), strict: false, allowPositionals: true }).values;
149
+ finiteJson = values?.follow !== true && values?.wait !== true;
150
+ }
151
+ }
152
+ for (const warning of warnings) {
153
+ if (finiteJson)
154
+ recordOperationWarning(warning, { echo: false });
155
+ else
156
+ console.error(c.red(`! ${warning.message}`));
157
+ }
158
+ }
135
159
  /** Under COTAL_DEBUG, print the failure's stack and the stack of each error that caused it. */
136
160
  function debugStacks(failure) {
137
161
  if (!debugFlag("COTAL_DEBUG"))
@@ -179,10 +203,9 @@ function failureExit(cmd, failure, json, plain = false, scope, words = [], valid
179
203
  const historyFollow = cmd.name === "history" && follow
180
204
  && !findSubcommand(cmd, validationArgs.positionals[0]);
181
205
  const membershipFollow = cmd.name === "channel" && follow && validationArgs.positionals[0] === "members";
182
- const space = validationArgs?.values.space;
183
206
  const records = historyFollow ? historySetupFailureRecords(validationArgs, failure)
184
207
  : membershipFollow ? membershipSetupFailureRecords({
185
- space: typeof space === "string" && space.trim() ? space : null,
208
+ space: validationArgs.values.space,
186
209
  channel: validationArgs.positionals[1]?.replace(/^#/, "") ?? null,
187
210
  }, failure)
188
211
  : cmd.name === "watch" && validationArgs && !plain ? watchSetupFailureRecords(validationArgs, failure) : undefined;
@@ -404,7 +427,7 @@ function usageRefusal(failure, plain, cmd, words = []) {
404
427
  return;
405
428
  if (report)
406
429
  console.error("");
407
- paintFor(process.stderr, () => printHelpPath(cmd, helpPath(cmd, words).path, (line) => console.error(line), terminalWidth(process.stderr)));
430
+ paintFor(process.stderr, () => printHelpPath(cmd, helpPath(cmd, words).path, (line) => console.error(line), terminalWidth(process.stderr), plain ? "plain" : "rich"));
408
431
  }
409
432
  /** Recover the requested stream output and target for a refusal, without running the command. */
410
433
  function streamRefusalArgs(cmd, words) {
@@ -412,6 +435,7 @@ function streamRefusalArgs(cmd, words) {
412
435
  return undefined;
413
436
  const options = Object.fromEntries((cmd.flags ?? []).map(({ name, type, short }) => [name, { type, ...(short ? { short } : {}) }]));
414
437
  const args = [...words];
438
+ let missingSpace = false;
415
439
  for (;;) {
416
440
  const { values, positionals, tokens } = parseArgs({ args, options, strict: false, allowPositionals: true, tokens: true });
417
441
  // The loose parser consumes an option-looking word after a missing value. Leave that word
@@ -419,10 +443,21 @@ function streamRefusalArgs(cmd, words) {
419
443
  const missing = tokens.find((token) => token.kind === "option" && token.inlineValue === false
420
444
  && token.value?.startsWith("-") && token.value !== "-"
421
445
  && !(args[token.index] === token.rawName && /^-\d/.test(token.value)));
422
- // The caller already detected a valid JSON switch. Watch needs no separate stream selector.
423
- if (!missing)
424
- return cmd.name === "watch" || (values.json === true && values.follow === true)
425
- ? { values: values, positionals, raw: words } : undefined;
446
+ if (missing?.kind !== "option") {
447
+ // A later --space cannot supply the value for a missing or blank occurrence.
448
+ if (missingSpace || tokens.some((token) => token.kind === "option" && token.name === "space" && !token.value?.trim())) {
449
+ delete values.space;
450
+ }
451
+ // The caller detected JSON. A malformed repeat cannot mask a bare follow switch.
452
+ if (cmd.name !== "watch") {
453
+ if (!tokens.some((token) => token.kind === "option" && token.name === "follow" && token.value === undefined))
454
+ return undefined;
455
+ values.follow = true;
456
+ }
457
+ return { values: values, positionals, raw: words };
458
+ }
459
+ if (missing.name === "space")
460
+ missingSpace = true;
426
461
  args.splice(missing.index + 1, 0, "");
427
462
  }
428
463
  }
@@ -494,12 +529,12 @@ function misspelledOption(cmd, rest, flagNames) {
494
529
  return { message: `${word} gives -${short[1]} the value "=${value}"`, remedy: `write ${correction}` };
495
530
  }
496
531
  const typed = positionals.has(index) ? recognize(word) : undefined;
497
- if (typed && cmd.name === "ext" && typed.flagName && typed.flagName !== "help") {
532
+ if (typed && (cmd.name === "ext" || cmd.name === "endpoint") && typed.flagName && typed.flagName !== "help") {
498
533
  const first = metadataPositionals(cmd, rest, { optionSpelling: (arg) => recognize(arg)?.spelling }).positionals[0]?.value;
499
534
  const sub = findSubcommand(cmd, first);
500
535
  const accepted = sub ? sub.flagNames : cmd.flagNames;
501
- if (accepted && !accepted.includes(typed.flagName))
502
- return { message: typed.message, remedy: `omit this option; \`cotal ext${sub ? ` ${sub.name}` : ""}\` does not take --${typed.flagName}` };
536
+ if ((cmd.name === "ext" || sub?.name === "check") && accepted && !accepted.includes(typed.flagName))
537
+ return { message: typed.message, remedy: `omit this option; \`cotal ${cmd.name}${sub ? ` ${sub.name}` : ""}\` does not take --${typed.flagName}` };
503
538
  }
504
539
  if (typed)
505
540
  return typed;
@@ -526,6 +561,9 @@ function missingValue(cmd, words, flag, beforeSeparator = false) {
526
561
  return { message: `\`run check\` does not take --${flag.name}`, remedy: `run the check without --${flag.name}` };
527
562
  return { message: `--${flag.name} needs a value`, remedy: `write --${flag.name} ${flag.value ?? "<value>"}${beforeSeparator ? " before --" : ""}` };
528
563
  }
564
+ function globalFlagValueRefusal(flag) {
565
+ return { message: `${flag} takes no value`, remedy: `omit ${flag} or pass it without a value` };
566
+ }
529
567
  /** A parse error as a refusal. A mistyped option names its spelling. A word that starts with `-`
530
568
  * goes after `--` only where the command has room for an operand and there is no spelling suggestion.
531
569
  * An option value that starts with `-` is written `--name=value`, and an option given with no value,
@@ -534,6 +572,13 @@ function parseRefusal(error, cmd, rest, flagNames, takesOperands, operandsFull)
534
572
  if (error.code === "ERR_PARSE_ARGS_UNKNOWN_OPTION") {
535
573
  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, "'");
536
574
  const option = /^Unknown option '(--.+)'$/su.exec(reason)?.[1];
575
+ if (option && GLOBAL_FLAG_WORDS.has(option) && !takesWordsRaw(cmd))
576
+ return globalFlagValueRefusal(option);
577
+ if (cmd.name === "help" && option === "--preset") {
578
+ const [service, verb] = metadataPositionals(cmd, rest).positionals;
579
+ if (findCommand(commandSurface(), service?.value)?.name === "service" && verb?.value === "add")
580
+ return { message: reason, remedy: displayRemedy("to see the preset options, use `cotal service add <name> --preset <preset> --help`") };
581
+ }
537
582
  const nearest = option ? nearestWords(option, [...(flagNames ?? (cmd.flags ?? []).map((flag) => flag.name)).map((name) => `--${name}`), "--no-color", "--no-input", "--help"]) : [];
538
583
  const spellings = nearest.join(" or ");
539
584
  const flag = cmd.flags?.find((item) => `--${item.name}` === spellings);
@@ -584,11 +629,12 @@ function parseRefusal(error, cmd, rest, flagNames, takesOperands, operandsFull)
584
629
  return { message: error.message };
585
630
  }
586
631
  /** `rest` parsed against `cmd`'s declared flags, positionals and subcommands, or a usage exit. */
587
- function parseOrExit(cmd, rest) {
632
+ function parseOrExit(cmd, rest, noMoreOperands = false) {
588
633
  rest = stripGlobalFlags(cmd, rest);
589
634
  const seed = extSeedSubcommand(cmd, rest);
590
635
  const json = !seed && asksForJson(cmd, rest);
591
- const plain = !seed && rest.includes("--plain");
636
+ const end = rest.indexOf("--");
637
+ const plain = !seed && (end === -1 ? rest : rest.slice(0, end)).includes("--plain");
592
638
  const flagNames = seed?.flagNames ?? (cmd.name === "spawn" ? cmd.flagNames : undefined);
593
639
  const misspelled = cmd.rawArgs ? undefined : misspelledOption(cmd, rest, flagNames);
594
640
  if (misspelled)
@@ -610,8 +656,11 @@ function parseOrExit(cmd, rest) {
610
656
  }
611
657
  const takesOperands = !seed && cmd.positionals !== undefined &&
612
658
  (!cmd.subcommands?.length || cmd.name === "history" || (first !== undefined && findSubcommand(cmd, first) !== undefined));
613
- const operandsFull = (cmd.name === "config" && selected.name === "get" && positionals.length >= 2)
659
+ const operandsFull = noMoreOperands || (cmd.name === "config" && ((selected.name === "set" && positionals.length >= 3)
660
+ || ((selected.name === "get" || selected.name === "unset") && positionals.length >= 2)))
661
+ || (cmd.name === "ext" && selected.name === "root")
614
662
  || (cmd.name === "space" && selected.name === "add" && positionals.length >= 2)
663
+ || (cmd.name === "service" && selected !== cmd && (selected.name === "list" || positionals.length >= 2))
615
664
  || (cmd.name === "team" && ["check", "boot", "deploy"].includes(selected.name) && positionals.length >= 2)
616
665
  || (cmd.name === "endpoint" && ((selected.name === "check" && positionals.length >= 2)
617
666
  || (first === "work" && selected.name === "lease" && positionals.length >= 4)));
@@ -633,7 +682,8 @@ function parseOrExit(cmd, rest) {
633
682
  // `--json` implies `--no-input`: a script reading one document cannot answer a prompt.
634
683
  if (structured(cmd, first) && parsed.values.json === true)
635
684
  disableInput();
636
- refuseRemovedFolder(cmd, canonical, rest);
685
+ if (cmd.name !== "update")
686
+ refuseRemovedFolder(cmd, canonical, rest);
637
687
  try {
638
688
  cmd.validate?.(canonical);
639
689
  }
@@ -701,22 +751,22 @@ const FOLDERLESS = new Set(["help", "version", "completion", "docs", "telemetry"
701
751
  * Node caches the first read that succeeds. One read refuses that case before the command's own
702
752
  * checks, such as `up`'s, or any effect, unless the command never reads the folder. */
703
753
  function refuseRemovedFolder(cmd, parsed, rest) {
704
- if (cmd.name === "update") {
705
- // Global maintenance must not inherit an unrelated disposable working folder. Keep the
706
- // project's root when one exists and preserve relative credentials and tool paths.
707
- const removed = workingFolderRemoved();
708
- const root = removed ? undefined : findCotalRoot();
709
- if (typeof parsed.values.creds === "string" && !isAbsolute(parsed.values.creds) && !removed)
710
- parsed.values.creds = resolve(parsed.values.creds);
711
- if (!removed)
712
- preserveUpdatePath();
713
- process.chdir(root && existsSync(join(root, ".cotal")) ? root : parse(homedir()).root);
714
- return;
715
- }
716
754
  if (cmd.name.startsWith("__") || FOLDERLESS.has(cmd.name) || !workingFolderRemoved())
717
755
  return;
718
756
  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, parsed);
719
757
  }
758
+ function prepareUpdateFolder(parsed) {
759
+ // Track the caller's tool selection without keeping a disposable working directory for maintenance.
760
+ const caller = workingFolderRemoved() ? undefined : process.cwd();
761
+ const root = caller === undefined ? undefined : findCotalRoot(caller);
762
+ if (caller !== undefined) {
763
+ if (typeof parsed.values.creds === "string" && !isAbsolute(parsed.values.creds))
764
+ parsed.values.creds = resolve(caller, parsed.values.creds);
765
+ preserveUpdatePath();
766
+ }
767
+ process.chdir(root && existsSync(join(root, ".cotal")) ? root : parse(homedir()).root);
768
+ return caller;
769
+ }
720
770
  /** Resolve subcommand aliases and refuse a word that names no subcommand before checking operands. */
721
771
  function canonicalSubcommand(cmd, parsed, json, plain) {
722
772
  const positionals = [...parsed.positionals];
@@ -768,7 +818,7 @@ function printHelpFor(cmd, rest) {
768
818
  paintFor(process.stdout, () => printHelpPath(cmd, unknown === undefined ? path : [...path, unknown]));
769
819
  }
770
820
  /** A service invocation takes its preset's flags, and `manager <verb>` is `service <verb> manager`.
771
- * Preset details can enrich a duplicate refusal but cannot replace it. */
821
+ * Preset details can enrich a global flag refusal but cannot replace it. */
772
822
  async function serviceSurface(found, words, forRefusal = false) {
773
823
  if (found?.name !== "service" && found?.name !== "manager")
774
824
  return { cmd: found, rest: words };
@@ -777,7 +827,7 @@ async function serviceSurface(found, words, forRefusal = false) {
777
827
  if (found.name === "service")
778
828
  return { cmd: servicePresetCommand(found, words), rest: words };
779
829
  const lifecycle = managerServiceCommand(found, words, forRefusal);
780
- return lifecycle ? { cmd: lifecycle.cmd, rest: lifecycle.argv } : { cmd: found, rest: words };
830
+ return lifecycle ? { cmd: lifecycle.cmd, rest: lifecycle.argv, noMoreOperands: true } : { cmd: found, rest: words };
781
831
  }
782
832
  catch (error) {
783
833
  if (forRefusal || asksForHelp(words))
@@ -786,6 +836,21 @@ async function serviceSurface(found, words, forRefusal = false) {
786
836
  return failureExit(found, failure, asksForJson(found, words), words.includes("--plain"), undefined, words);
787
837
  }
788
838
  }
839
+ /** Recover the command and output mode for a malformed leading global without dispatching it. */
840
+ async function unknownInvocationExit(commands, word, args, output, beforeSeparator) {
841
+ const equals = word.indexOf("=");
842
+ const flag = equals === -1 ? undefined : word.slice(0, equals);
843
+ if (!beforeSeparator || !flag || !GLOBAL_FLAG_WORDS.has(flag))
844
+ usageExit(unknownCommandMessage(commands, word));
845
+ const retry = leadingInvocation(args, true);
846
+ const found = findCommand(commands, retry.word);
847
+ const words = [...output, ...retry.leading.filter((item) => OUTPUT_FLAG_WORDS.has(item)), ...retry.args];
848
+ const { cmd, rest } = await serviceSurface(takesWordsRaw(found) ? undefined : found, words, true);
849
+ const end = rest.indexOf("--");
850
+ const plain = (end === -1 ? rest : rest.slice(0, end)).includes("--plain");
851
+ const { message, remedy } = globalFlagValueRefusal(flag);
852
+ return usageExit(message, cmd, cmd !== undefined && asksForJson(cmd, rest), plain, remedy, rest);
853
+ }
789
854
  /**
790
855
  * Dispatch `argv` against the commands self-registered in a {@link Registry}. The single entry point
791
856
  * a composition root calls — no hardcoded command list.
@@ -797,7 +862,11 @@ async function serviceSurface(found, words, forRefusal = false) {
797
862
  * launches nothing. An extension command's flags are parsed after the seed, because its live specs
798
863
  * come from importing a package the seed keeps current.
799
864
  */
800
- export async function runCli(registry, argv, opts = {}) {
865
+ export function runCli(registry, argv, opts = {}) {
866
+ const scope = {};
867
+ return runOperation(scope, () => dispatchCli(registry, argv, opts, scope));
868
+ }
869
+ async function dispatchCli(registry, argv, opts, scope) {
801
870
  const startedAt = Date.now();
802
871
  const { leading, original, word, args } = leadingInvocation(argv);
803
872
  const { output, leadingGlobals, repeatedLeading } = prepareLeadingFlags(leading);
@@ -853,8 +922,17 @@ export async function runCli(registry, argv, opts = {}) {
853
922
  // The built-in updater repairs its connector paths before opening any promotion journal.
854
923
  const selfUpdate = builtin?.name === "update" && words.includes("--self") && !wantsHelp
855
924
  && parseOrExit(builtin, ownWords(builtin)).values.self === true;
856
- // The removed start command only gives migration advice and needs no extension inventory.
857
- let useExtensionOverlay = opts.extensions && !updateCheck && !selfUpdate && builtin?.name !== "start";
925
+ const preference = builtin?.name === "update" && !wantsHelp && (words.includes("--auto") || words.includes("--notify"))
926
+ ? parseOrExit(builtin, ownWords(builtin)).values : undefined;
927
+ const extMode = builtin?.name === "ext" ? metadataPositionals(builtin, words).positionals[0]?.value : undefined;
928
+ // Root only resolves a path. The JSON list classifies inventory errors in its handler.
929
+ const extDiagnostics = builtin?.name === "ext" && !wantsHelp
930
+ && (extMode === "root" || ((extMode === undefined || extMode === "list") && asksForJson(builtin, words)));
931
+ const readMode = builtin && !wantsHelp && (builtin.name === "config" || builtin.name === "completion")
932
+ ? metadataPositionals(builtin, words).positionals[0]?.value : undefined;
933
+ const configRead = builtin?.name === "config" && !wantsHelp && (readMode === undefined || readMode === "get");
934
+ const completionStatus = builtin?.name === "completion" && !wantsHelp && readMode === undefined;
935
+ let useExtensionOverlay = opts.extensions && !updateCheck && !selfUpdate && !preference?.auto && !preference?.notify && builtin?.name !== "start";
858
936
  function skipUnreadableConnectorOverlay(error) {
859
937
  if (!(error instanceof UnreadableConnectorSelection) || !builtin || !["version", "status", "down"].includes(builtin.name))
860
938
  return false;
@@ -894,17 +972,14 @@ export async function runCli(registry, argv, opts = {}) {
894
972
  }
895
973
  }
896
974
  }
897
- function collisionWarning(warnings) {
898
- return (message) => { warnings.push({ code: "EXTENSION_COMMAND_COLLISION", target: null, message: message.slice(2) }); };
899
- }
900
975
  const pendingWarnings = [];
901
976
  const surface = (warnings) => {
902
977
  let commands;
903
978
  try {
904
- commands = useExtensionOverlay && !versionJson && !configFolder ? overlayExtensions(registry, warnings && collisionWarning(warnings)) : registry.all("command");
979
+ commands = useExtensionOverlay && !versionJson && !extDiagnostics && !configFolder ? overlayExtensions(registry, collisionWarning(warnings)) : registry.all("command");
905
980
  }
906
981
  catch (e) {
907
- if (skipUnreadableConnectorOverlay(e))
982
+ if (((configRead || completionStatus) && e instanceof CorruptExtensionsManifestError) || skipUnreadableConnectorOverlay(e))
908
983
  commands = registry.all("command");
909
984
  else {
910
985
  if (repeatedLeading)
@@ -927,17 +1002,17 @@ export async function runCli(registry, argv, opts = {}) {
927
1002
  setCommandSurface(commands); // the completion dispatcher reads the SAME surface help renders
928
1003
  return commands;
929
1004
  };
930
- let commands = surface(duplicate(undefined) ? pendingWarnings : undefined);
931
- if (word === undefined)
932
- return paintFor(process.stdout, () => printEntry(commands));
1005
+ let commands = surface(pendingWarnings);
933
1006
  let cmd = findCommand(commands, word);
934
1007
  let rest = ownWords(cmd);
935
1008
  const repeated = duplicate(cmd);
936
1009
  if (repeated)
937
1010
  return repeatedGlobalFlag(repeated, cmd, rest, pendingWarnings);
938
- for (const warning of pendingWarnings)
939
- console.error(c.red(`! ${warning.message}`));
940
- ({ cmd, rest } = await serviceSurface(cmd, rest));
1011
+ routeCollisionWarnings(pendingWarnings, cmd, rest, wantsHelp);
1012
+ if (word === undefined)
1013
+ return paintFor(process.stdout, () => printEntry(commands));
1014
+ const scoped = await serviceSurface(cmd, rest);
1015
+ ({ cmd, rest } = scoped);
941
1016
  // The usage telemetry hook is armed as soon as the command is known, so a usage refusal below
942
1017
  // counts too, and before anything runs, so the one-time notice precedes the command's output.
943
1018
  const arm = () => {
@@ -965,14 +1040,14 @@ export async function runCli(registry, argv, opts = {}) {
965
1040
  if (typed)
966
1041
  usageExit(typed.message, undefined, false, false, typed.remedy);
967
1042
  if (!cmd && !awaitingSeed)
968
- usageExit(unknownCommandMessage(commands, word));
1043
+ return unknownInvocationExit(commands, word, args, output, argv[leading.length] !== "--");
969
1044
  // `cotal <cmd> --help` / `-h` → that command's help, never run it. This intercept also covers
970
1045
  // rawArgs commands and extension STUBS (cached specs are exactly the display surface) — only
971
1046
  // `__`-internal ones are exempt, because __complete's argv is ANOTHER command's half-typed
972
1047
  // line, where `--help` is a word being completed, not a request.
973
1048
  if (cmd && !cmd.name.startsWith("__") && wantsHelp)
974
1049
  return printHelpFor(cmd, rest);
975
- let parsed = cmd && !isExtensionStub(cmd) ? parseOrExit(cmd, rest) : undefined;
1050
+ let parsed = cmd && !isExtensionStub(cmd) ? parseOrExit(cmd, rest, scoped.noMoreOperands) : undefined;
976
1051
  // ---- Effects: only a validated invocation reaches this line. ----
977
1052
  // A config folder that is a file fails every read and write of the preferences, the config file and
978
1053
  // the extensions, so a command that could use them stops here, before the seed would write there.
@@ -1016,15 +1091,16 @@ export async function runCli(registry, argv, opts = {}) {
1016
1091
  }
1017
1092
  if (!deferred) {
1018
1093
  const warnings = [];
1019
- commands = surface(duplicate(undefined) ? warnings : undefined);
1094
+ commands = surface(warnings);
1020
1095
  cmd = findCommand(commands, word);
1021
- if (!cmd)
1096
+ if (!cmd) {
1097
+ routeCollisionWarnings(warnings, cmd, rest, wantsHelp);
1022
1098
  usageExit(unknownCommandMessage(commands, word));
1099
+ }
1023
1100
  const repeated = duplicate(cmd);
1024
1101
  if (repeated)
1025
1102
  return repeatedGlobalFlag(repeated, cmd, ownWords(cmd), warnings);
1026
- for (const warning of warnings)
1027
- console.error(c.red(`! ${warning.message}`));
1103
+ routeCollisionWarnings(warnings, cmd, ownWords(cmd), wantsHelp);
1028
1104
  ({ cmd, rest } = await serviceSurface(cmd, ownWords(cmd)));
1029
1105
  arm();
1030
1106
  }
@@ -1043,6 +1119,7 @@ export async function runCli(registry, argv, opts = {}) {
1043
1119
  }
1044
1120
  if (!cmd || !parsed)
1045
1121
  throw new Error("internal error: dispatch reached its effects without a parsed command");
1122
+ const updateDirectory = cmd.name === "update" ? prepareUpdateFolder(parsed) : undefined;
1046
1123
  // A preferences file that does not validate stops every command that could act on a default, as a
1047
1124
  // broken config file does, so nothing runs on a default the person did not mean. Help, shell
1048
1125
  // completion, version, docs and machine-daemon operations need no preference defaults, and status
@@ -1056,7 +1133,7 @@ export async function runCli(registry, argv, opts = {}) {
1056
1133
  failureExit(cmd, 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()}` }), structured(cmd, parsed.positionals[0]) && parsed.values.json === true, parsed.values.plain === true, undefined, rest, parsed);
1057
1134
  const homeProblem = cotalHomeProblem();
1058
1135
  if (homeProblem)
1059
- failureExit(cmd, new CommandFailure("refused", "SCHEMA_INVALID", `${homeProblem}; the command did not run`, { remedy: `point COTAL_HOME at a directory, or unset it to use ${userCotalDir()}` }), structured(cmd, parsed.positionals[0]) && parsed.values.json === true, parsed.values.plain === true, undefined, rest);
1136
+ failureExit(cmd, new CommandFailure("refused", "SCHEMA_INVALID", `${homeProblem}; the command did not run`, { remedy: `point COTAL_HOME at a directory, or unset it to use ${userCotalDir()}` }), structured(cmd, parsed.positionals[0]) && parsed.values.json === true, parsed.values.plain === true, undefined, rest, parsed);
1060
1137
  // A `.cotal` that is a file in the folder the command uses, such as someone's notes, holds no
1061
1138
  // records, and every reader would otherwise report a different wrong cause. The machine daemon
1062
1139
  // uses its selected home, not the invoking project's records.
@@ -1074,10 +1151,10 @@ export async function runCli(registry, argv, opts = {}) {
1074
1151
  }
1075
1152
  }
1076
1153
  }
1077
- // A failure raised after the command recorded the space it resolved is reported in that space. A
1078
- // completion writes its warnings, as its errors, only under COTAL_COMPLETE_DEBUG.
1079
- const scope = cmd.name === "__complete" && !debugFlag("COTAL_COMPLETE_DEBUG") ? { quiet: true } : {};
1080
- const execute = async () => {
1154
+ // Keep failures in the resolved space and completion warnings behind COTAL_COMPLETE_DEBUG.
1155
+ if (cmd.name === "__complete" && !debugFlag("COTAL_COMPLETE_DEBUG"))
1156
+ scope.quiet = true;
1157
+ const execute = async () => npmProjectDirectory.run(updateDirectory, async () => {
1081
1158
  if (opts.extensions && cmd.requiredExtensions) {
1082
1159
  for (const ref of cmd.requiredExtensions(parsed))
1083
1160
  await materializeExtension(ref);
@@ -1100,7 +1177,7 @@ export async function runCli(registry, argv, opts = {}) {
1100
1177
  await cmd.prepare(parsed);
1101
1178
  await cmd.run(parsed);
1102
1179
  });
1103
- };
1180
+ });
1104
1181
  if (opts.startupNotice && cmd.keepsStartupNotice)
1105
1182
  keepStartupNotice(opts.startupNotice);
1106
1183
  else
@@ -1123,6 +1200,8 @@ export async function runCli(registry, argv, opts = {}) {
1123
1200
  recordTelemetryError(e);
1124
1201
  const mode = parsed.positionals[0];
1125
1202
  const json = structured(cmd, mode) && parsed.values.json === true;
1203
+ if (configRead && e instanceof CorruptExtensionsManifestError)
1204
+ failureExit(cmd, new CommandFailure("refused", "SCHEMA_INVALID", e.diagnosis, { remedy: e.remedy, cause: e }), json, parsed.values.plain === true, scope, rest);
1126
1205
  // A usage error a command raises from its own checks prints the command's help, not a stack trace.
1127
1206
  if (isArgError(e))
1128
1207
  usageExit(e.message.split(".")[0], cmd, json, parsed.values.plain === true, undefined, rest);