@cotal-ai/cli 0.172.2 → 0.173.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 (107) hide show
  1. package/dist/command.d.ts.map +1 -1
  2. package/dist/command.js +15 -7
  3. package/dist/command.js.map +1 -1
  4. package/dist/commands/backup.d.ts.map +1 -1
  5. package/dist/commands/backup.js +15 -10
  6. package/dist/commands/backup.js.map +1 -1
  7. package/dist/commands/channels.d.ts.map +1 -1
  8. package/dist/commands/channels.js +8 -2
  9. package/dist/commands/channels.js.map +1 -1
  10. package/dist/commands/clean.d.ts.map +1 -1
  11. package/dist/commands/clean.js +1 -2
  12. package/dist/commands/clean.js.map +1 -1
  13. package/dist/commands/doctor.js +5 -2
  14. package/dist/commands/doctor.js.map +1 -1
  15. package/dist/commands/down-preserve.d.ts +74 -0
  16. package/dist/commands/down-preserve.d.ts.map +1 -0
  17. package/dist/commands/down-preserve.js +626 -0
  18. package/dist/commands/down-preserve.js.map +1 -0
  19. package/dist/commands/down.d.ts +2 -61
  20. package/dist/commands/down.d.ts.map +1 -1
  21. package/dist/commands/down.js +10 -621
  22. package/dist/commands/down.js.map +1 -1
  23. package/dist/commands/meshes-add.d.ts +2 -3
  24. package/dist/commands/meshes-add.d.ts.map +1 -1
  25. package/dist/commands/meshes-add.js +3 -19
  26. package/dist/commands/meshes-add.js.map +1 -1
  27. package/dist/commands/space-registration.d.ts.map +1 -1
  28. package/dist/commands/space-registration.js +8 -8
  29. package/dist/commands/space-registration.js.map +1 -1
  30. package/dist/commands/space.d.ts.map +1 -1
  31. package/dist/commands/space.js +15 -5
  32. package/dist/commands/space.js.map +1 -1
  33. package/dist/commands/spawn-preview.d.ts.map +1 -1
  34. package/dist/commands/spawn-preview.js +5 -5
  35. package/dist/commands/spawn-preview.js.map +1 -1
  36. package/dist/commands/spawn.d.ts.map +1 -1
  37. package/dist/commands/spawn.js +3 -3
  38. package/dist/commands/spawn.js.map +1 -1
  39. package/dist/commands/stack-up.d.ts +3 -1
  40. package/dist/commands/stack-up.d.ts.map +1 -1
  41. package/dist/commands/stack-up.js +37 -10
  42. package/dist/commands/stack-up.js.map +1 -1
  43. package/dist/commands/status-delivery.d.ts +9 -0
  44. package/dist/commands/status-delivery.d.ts.map +1 -0
  45. package/dist/commands/status-delivery.js +19 -0
  46. package/dist/commands/status-delivery.js.map +1 -0
  47. package/dist/commands/status-legacy.d.ts +7 -0
  48. package/dist/commands/status-legacy.d.ts.map +1 -0
  49. package/dist/commands/status-legacy.js +35 -0
  50. package/dist/commands/status-legacy.js.map +1 -0
  51. package/dist/commands/status.d.ts.map +1 -1
  52. package/dist/commands/status.js +29 -65
  53. package/dist/commands/status.js.map +1 -1
  54. package/dist/commands/team-agent-apply.js +11 -11
  55. package/dist/commands/team-agent-apply.js.map +1 -1
  56. package/dist/commands/team-deploy-apply.js +2 -2
  57. package/dist/commands/team-deploy-apply.js.map +1 -1
  58. package/dist/commands/team.js +12 -19
  59. package/dist/commands/team.js.map +1 -1
  60. package/dist/commands/up.d.ts +2 -0
  61. package/dist/commands/up.d.ts.map +1 -1
  62. package/dist/commands/up.js +11 -30
  63. package/dist/commands/up.js.map +1 -1
  64. package/dist/commands/update.js +6 -6
  65. package/dist/commands/update.js.map +1 -1
  66. package/dist/commands/watch.d.ts.map +1 -1
  67. package/dist/commands/watch.js +5 -2
  68. package/dist/commands/watch.js.map +1 -1
  69. package/dist/commands/whoami.d.ts.map +1 -1
  70. package/dist/commands/whoami.js +3 -2
  71. package/dist/commands/whoami.js.map +1 -1
  72. package/dist/help.d.ts +1 -1
  73. package/dist/help.d.ts.map +1 -1
  74. package/dist/help.js +3 -1
  75. package/dist/help.js.map +1 -1
  76. package/dist/index.d.ts.map +1 -1
  77. package/dist/index.js +3 -2
  78. package/dist/index.js.map +1 -1
  79. package/dist/lib/choose-target.d.ts.map +1 -1
  80. package/dist/lib/choose-target.js +12 -9
  81. package/dist/lib/choose-target.js.map +1 -1
  82. package/dist/lib/endpoint-errors.d.ts.map +1 -1
  83. package/dist/lib/endpoint-errors.js +9 -2
  84. package/dist/lib/endpoint-errors.js.map +1 -1
  85. package/dist/lib/persona-files.d.ts.map +1 -1
  86. package/dist/lib/persona-files.js +2 -3
  87. package/dist/lib/persona-files.js.map +1 -1
  88. package/dist/lib/spawn-defaults.d.ts +2 -0
  89. package/dist/lib/spawn-defaults.d.ts.map +1 -1
  90. package/dist/lib/spawn-defaults.js +11 -0
  91. package/dist/lib/spawn-defaults.js.map +1 -1
  92. package/dist/lib/stack-journal.d.ts.map +1 -1
  93. package/dist/lib/stack-journal.js +10 -1
  94. package/dist/lib/stack-journal.js.map +1 -1
  95. package/dist/lib/store-dir.d.ts +3 -1
  96. package/dist/lib/store-dir.d.ts.map +1 -1
  97. package/dist/lib/store-dir.js +20 -4
  98. package/dist/lib/store-dir.js.map +1 -1
  99. package/dist/lib/team-deploy-inspection.d.ts +2 -1
  100. package/dist/lib/team-deploy-inspection.d.ts.map +1 -1
  101. package/dist/lib/team-deploy-inspection.js +6 -1
  102. package/dist/lib/team-deploy-inspection.js.map +1 -1
  103. package/dist/seed/launch.d.ts +1 -1
  104. package/dist/seed/launch.d.ts.map +1 -1
  105. package/dist/seed/launch.js +3 -3
  106. package/dist/seed/launch.js.map +1 -1
  107. package/package.json +4 -4
@@ -45,7 +45,7 @@ import { checkSpaceFlagValue, checkSpaceName } from "./meshes-add.js";
45
45
  import { checkLocalSpace } from "./space-registration.js";
46
46
  import { checkNewUpSpace, preparedUpRoot } from "./up-target.js";
47
47
  import { cleanedManifestStart, interruptedStartBroker, namedOpenConfig, retainedOpenSpace } from "../lib/legacy-start.js";
48
- import { bindReaches, canonicalServer, controllerStackApplies, recheckExistingStore, requestedStackMode, requestsTls, stackUp, stackUpForegroundNotice, stackUpInterrupted, keptOnUp, selectedOnUp, unparsableDaemonCredsNotice, } from "./stack-up.js";
48
+ import { bindReaches, canonicalServer, controllerStackApplies, recheckExistingStore, requestedStackMode, refuseForegroundStackHolder, requestsTls, stackUp, stackUpForegroundNotice, stackUpInterrupted, keptOnUp, selectedOnUp, unparsableDaemonCredsNotice, } from "./stack-up.js";
49
49
  import { handOverStartupNotice, noticeOnInterrupt, releaseStartupNotice } from "../lib/interrupt-notice.js";
50
50
  import { claimForegroundHold, foregroundHolder, releaseForegroundHold } from "../lib/foreground-hold.js";
51
51
  import { settleInterruptedLaunches } from "../lib/service-process.js";
@@ -61,7 +61,7 @@ import { serviceSupervisorStore } from "../lib/service-supervision.js";
61
61
  import { serviceInstallIntents } from "../lib/service-install-intent.js";
62
62
  import { serviceUninstallIntents } from "../lib/service-uninstall-intent.js";
63
63
  import { serviceUnitActionStore } from "../lib/service-unit-action.js";
64
- import { assertStoreDirArgument, configuredStoreDir, lastServedStore, lastServedStores, missingStoreWarning, servedStore, sharedStoreAtStart, sharedStoreWarning, storeWriteProblem, warnForeignStoreEntries } from "../lib/store-dir.js";
64
+ import { assertStoreDirArgument, configuredStoreDir, lastServedStore, lastServedStores, missingStoreWarning, servedStore, sharedStoreAtStart, sharedStoreWarning, startupStoreProblem, warnForeignStoreEntries } from "../lib/store-dir.js";
65
65
  import { extensionNames, preflightRuntime } from "../ext-loader.js";
66
66
  import { completingFlagValue } from "../lib/completion.js";
67
67
  import { metadataPositionals } from "../lib/command-path.js";
@@ -128,8 +128,8 @@ export const upFlags = [
128
128
  { name: "no-manager", type: "boolean", description: "broker-only boot: start the broker and, in auth mode, the delivery daemon, and no local manager (refuses on a mesh whose manager is live)" },
129
129
  { name: "file", type: "string", short: "f", value: "<cotal.yaml>", description: "launch a whole mesh from a manifest" },
130
130
  { name: "dry-run", type: "boolean", description: "with -f: print the plan, mutate nothing" },
131
- { ...jsonFlag, description: "controller-owned stack only: one structured receipt on stdout" },
132
- { ...plainFlag, description: "controller-owned stack only: plain line-oriented receipt" },
131
+ { ...jsonFlag, description: "one structured receipt on stdout (controller-owned stack only, without --foreground)" },
132
+ { ...plainFlag, description: "plain line-oriented receipt (controller-owned stack only, without --foreground)" },
133
133
  ];
134
134
  /** Completion for `cotal up` — `--runtime <TAB>` offers `pty` + installed runtime providers (the same
135
135
  * offline source `spawn` uses; a <TAB> never imports or probes). Run `cotal runtimes` to also see the
@@ -220,7 +220,7 @@ export function validateUpArguments(args) {
220
220
  if (args.values.file !== undefined && args.values.foreground === true)
221
221
  throw new CommandFailure("refused", "UNSUPPORTED", "manifest boot has no native foreground custody path; a detached broker was not substituted for the requested terminal-bound lifetime");
222
222
  if (args.values.foreground === true && (args.values.json === true || args.values.plain === true))
223
- throw new CommandFailure("refused", "USAGE_INVALID", "foreground up keeps native terminal custody and cannot produce a finite JSON or plain receipt");
223
+ throw new CommandFailure("refused", "USAGE_INVALID", "foreground up keeps native terminal custody and cannot produce a finite JSON or plain receipt", { remedy: `omit ${args.values.json ? "--json" : "--plain"} to keep the stack in this terminal, or omit --foreground for a finite receipt from a controller-owned stack` });
224
224
  // Flag values and combinations are usage, so they refuse here, before any effect. The run keeps
225
225
  // its own checks for maintenance re-entries, which do not pass through this validation.
226
226
  parsePositiveIntegerFlag("--max-sessions", args.values["max-sessions"]);
@@ -341,24 +341,7 @@ function assertUpRootWritable(root) {
341
341
  * a start here opens, as `--store-dir` names it, as the stack or legacy records name it, or `.cotal/nats`,
342
342
  * is refused here, by name, when this account cannot write it. */
343
343
  function assertUpStoreWritable(root, storeDir) {
344
- let recorded;
345
- try {
346
- recorded = readStackJournal(root)?.journal.broker?.storeDir;
347
- }
348
- catch {
349
- recorded = undefined;
350
- }
351
- const defaultStore = join(root, ".cotal", "nats");
352
- if (storeDir === undefined && recorded === undefined) {
353
- const local = localMeshesForRoot(root);
354
- recorded = local.length === 1 ? local[0].storeDir : undefined;
355
- if (recorded === undefined && !existsSync(join(defaultStore, "jetstream"))) {
356
- const served = lastServedStores(root, defaultStore);
357
- if (served.length === 1)
358
- recorded = served[0];
359
- }
360
- }
361
- const problem = storeWriteProblem(storeDir !== undefined ? resolve(storeDir) : recorded ?? defaultStore);
344
+ const problem = startupStoreProblem(root, storeDir);
362
345
  if (problem)
363
346
  throw new CommandFailure("refused", "PERMISSION_DENIED", `${problem.message}; nothing was started or written`, { target: { root, path: problem.path }, remedy: problem.remedy });
364
347
  }
@@ -1490,7 +1473,7 @@ async function runUp(args, invokedFrom, inheritedLock, onAdopt, freshTeamBoot =
1490
1473
  // one, it takes that stack's lifetime over and says so before it blocks.
1491
1474
  const holder = values.foreground ? foregroundHolder(meshRoot) : undefined;
1492
1475
  if (holder !== undefined)
1493
- throw new CommandFailure("refused", "CONFLICT", `a foreground \`cotal up\` in process ${holder} already holds this stack's lifetime; this terminal did not take it over and nothing was started`, { target: { root: meshRoot, space: stackSpace, holderPid: holder }, remedy: `use the terminal that runs process ${holder}, where Ctrl-C stops the stack, or stop it with \`cotal down --yes\` from ${meshRoot} and run \`cotal up --foreground\` again` });
1476
+ refuseForegroundStackHolder(meshRoot, stackSpace, holder);
1494
1477
  const takeover = values.foreground === true && STACK_ROLES.some((role) => serviceInstances(stackSpace, STACK_DEFINITION[role]).some((row) => observeServiceProcess(row.record.value) === "running"));
1495
1478
  // A signal ends a detached start where it is, after it records a launch it had not yet pinned to
1496
1479
  // its child, and the notice names what it left running. It is installed before the lock, so no
@@ -3488,7 +3471,7 @@ export async function recheckFreshTeamBoot(plan, own) {
3488
3471
  export function controllerStackNative() {
3489
3472
  return {
3490
3473
  prepareBroker: async (opts) => {
3491
- const prepared = await prepareBrokerStart({ transport: opts.transport, server: opts.server, space: opts.space, ...(opts.open ? { open: true } : {}), ...(opts.userAuth ? { userAuth: opts.userAuth } : {}), ...(opts.host ? { host: opts.host } : {}), ...(opts.storeDir ? { storeDir: opts.storeDir } : {}), ...(opts.existingStore ? { existingStore: opts.existingStore } : {}), ...(opts.maxFileStore !== undefined ? { maxFileStore: opts.maxFileStore } : {}), ...(opts.logFile !== undefined ? { logFile: opts.logFile } : {}), ...(opts.logfileSizeLimit !== undefined ? { logfileSizeLimit: opts.logfileSizeLimit } : {}), ...(opts.logfileMaxNum !== undefined ? { logfileMaxNum: opts.logfileMaxNum } : {}), ...(opts.authTimeout !== undefined ? { authTimeout: opts.authTimeout } : {}), ...(opts.maxPayload !== undefined ? { maxPayload: opts.maxPayload } : {}), ...(opts.accountResolver !== undefined ? { accountResolver: opts.accountResolver } : {}), ...(opts.noManager ? { noManager: true } : {}), ...(opts.seed !== undefined ? { seed: opts.seed } : opts.channels ? { channels: opts.channels } : {}), quietBoot: true });
3474
+ const prepared = await prepareBrokerStart({ transport: opts.transport, server: opts.server, space: opts.space, ...(opts.open ? { open: true } : {}), ...(opts.userAuth ? { userAuth: opts.userAuth } : {}), ...(opts.host ? { host: opts.host } : {}), ...(opts.wsPort !== undefined ? { wsPort: opts.wsPort } : {}), ...(opts.storeDir ? { storeDir: opts.storeDir } : {}), ...(opts.existingStore ? { existingStore: opts.existingStore } : {}), ...(opts.maxFileStore !== undefined ? { maxFileStore: opts.maxFileStore } : {}), ...(opts.logFile !== undefined ? { logFile: opts.logFile } : {}), ...(opts.logfileSizeLimit !== undefined ? { logfileSizeLimit: opts.logfileSizeLimit } : {}), ...(opts.logfileMaxNum !== undefined ? { logfileMaxNum: opts.logfileMaxNum } : {}), ...(opts.authTimeout !== undefined ? { authTimeout: opts.authTimeout } : {}), ...(opts.maxPayload !== undefined ? { maxPayload: opts.maxPayload } : {}), ...(opts.accountResolver !== undefined ? { accountResolver: opts.accountResolver } : {}), ...(opts.noManager ? { noManager: true } : {}), ...(opts.seed !== undefined ? { seed: opts.seed } : opts.channels ? { channels: opts.channels } : {}), quietBoot: true });
3492
3475
  return { root: prepared.root, server: prepared.server, space: prepared.space, storeDir: prepared.storeDir, transport: prepared.transport, ...(prepared.setup ? { setup: { mintProvisioner: prepared.setup.mintProvisioner, wsPort: prepared.setup.wsPort, moveWebsocketPort: prepared.setup.moveWebsocketPort } } : {}), ...(prepared.setup?.prepared && prepared.setup.stateDir ? { user: { prepared: prepared.setup.prepared, stateDir: prepared.setup.stateDir } } : {}), confPath: prepared.confPath, bin: prepared.bin, source: prepared.source, version: prepared.version, seedFile: prepared.seedFile, ...(prepared.setup?.authTimeout !== undefined ? { authTimeout: prepared.setup.authTimeout } : {}), ...(prepared.maxPayload !== undefined ? { maxPayload: prepared.maxPayload } : {}), ...(prepared.setup?.accountResolver !== undefined ? { accountResolver: prepared.setup.accountResolver } : {}) };
3493
3476
  },
3494
3477
  initializeStreams: async (server, space, setup, seedFile, recreateIssuedStores, recreateMembershipStore) => postStart(server, space, setup && { creds: await setup.mintProvisioner() }, seedFile, recreateIssuedStores, recreateMembershipStore, true),
@@ -4153,7 +4136,7 @@ export async function prepareBrokerStart(opts) {
4153
4136
  closeSync(fd);
4154
4137
  }
4155
4138
  }
4156
- const setup = useAuth ? await authSetup(storeDir, server, space, host, opts.userAuth, transport, opts.rotateSys, opts.maxFileStore, opts.quietBoot, { authTimeout: opts.authTimeout, maxPayload: opts.maxPayload, accountResolver: opts.accountResolver, manager: opts.noManager !== true, logFile, logfileSizeLimit: opts.logfileSizeLimit, logfileMaxNum: opts.logfileMaxNum }) : undefined;
4139
+ const setup = useAuth ? await authSetup(storeDir, server, space, host, opts.userAuth, transport, opts.rotateSys, opts.maxFileStore, opts.quietBoot, { authTimeout: opts.authTimeout, maxPayload: opts.maxPayload, accountResolver: opts.accountResolver, manager: opts.noManager !== true, logFile, logfileSizeLimit: opts.logfileSizeLimit, logfileMaxNum: opts.logfileMaxNum, wsPort: opts.wsPort }) : undefined;
4157
4140
  const maxPayload = setup?.maxPayload ?? opts.maxPayload ?? readBrokerPolicy(root)?.maxPayload;
4158
4141
  const port = Number(new URL(server).port) || 4222;
4159
4142
  // Same rule as the foreground path: every route to a listener names its transport (see
@@ -5525,10 +5508,8 @@ requested = {}) {
5525
5508
  }
5526
5509
  }
5527
5510
  const port = Number(new URL(server).port) || 4222;
5528
- // P2 item 6: allocate the broker's loopback WebSocket listener port — the console page becomes a
5529
- // mesh §13.6 session client over it (a NEW same-host attack surface, localhost-bound, no TLS). The
5530
- // manager's establisher builds its wsUrl from this; threaded to `supervise --ws-port`.
5531
- const wsPort = await freePort(host);
5511
+ // A reused controller manager advertises its launch-time WebSocket port.
5512
+ const wsPort = requested.wsPort ?? await freePort(host);
5532
5513
  const confPath = resolve(dir, "server.conf");
5533
5514
  // EVERY tenant of this root, not just the one being booted: `resolver_preload` is a whole-broker
5534
5515
  // map, so a config rendered from one space evicts the rest silently. `auth` leads the list because