@cotal-ai/cli 0.119.0 → 0.119.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/command.d.ts.map +1 -1
- package/dist/command.js +9 -9
- package/dist/command.js.map +1 -1
- package/dist/commands/agents.d.ts.map +1 -1
- package/dist/commands/agents.js +5 -5
- package/dist/commands/agents.js.map +1 -1
- package/dist/commands/channel-members.d.ts.map +1 -1
- package/dist/commands/channel-members.js +3 -3
- package/dist/commands/channel-members.js.map +1 -1
- package/dist/commands/describe.js +2 -2
- package/dist/commands/describe.js.map +1 -1
- package/dist/commands/down.d.ts.map +1 -1
- package/dist/commands/down.js +3 -3
- package/dist/commands/down.js.map +1 -1
- package/dist/commands/endpoints.js +2 -2
- package/dist/commands/endpoints.js.map +1 -1
- package/dist/commands/help.js +3 -3
- package/dist/commands/help.js.map +1 -1
- package/dist/commands/history.d.ts.map +1 -1
- package/dist/commands/history.js +2 -2
- package/dist/commands/history.js.map +1 -1
- package/dist/commands/meshes.d.ts.map +1 -1
- package/dist/commands/meshes.js +2 -2
- package/dist/commands/meshes.js.map +1 -1
- package/dist/commands/personas.js +1 -1
- package/dist/commands/personas.js.map +1 -1
- package/dist/commands/reset-space-apply.js +2 -2
- package/dist/commands/reset-space-apply.js.map +1 -1
- package/dist/commands/service-actions.d.ts.map +1 -1
- package/dist/commands/service-actions.js +5 -5
- package/dist/commands/service-actions.js.map +1 -1
- package/dist/commands/service-set-stop.js +2 -2
- package/dist/commands/service-set-stop.js.map +1 -1
- package/dist/commands/setup.d.ts.map +1 -1
- package/dist/commands/setup.js +2 -2
- package/dist/commands/setup.js.map +1 -1
- package/dist/commands/space-delete.js +2 -2
- package/dist/commands/space-delete.js.map +1 -1
- package/dist/commands/space.d.ts +1 -1
- package/dist/commands/space.d.ts.map +1 -1
- package/dist/commands/spawn.js +3 -3
- package/dist/commands/spawn.js.map +1 -1
- package/dist/commands/stack-down.js +3 -3
- package/dist/commands/stack-down.js.map +1 -1
- package/dist/commands/stack-gone.js +2 -2
- package/dist/commands/stack-gone.js.map +1 -1
- package/dist/commands/stack-up.d.ts +10 -2
- package/dist/commands/stack-up.d.ts.map +1 -1
- package/dist/commands/stack-up.js +15 -5
- package/dist/commands/stack-up.js.map +1 -1
- package/dist/commands/up.d.ts +3 -0
- package/dist/commands/up.d.ts.map +1 -1
- package/dist/commands/up.js +76 -26
- package/dist/commands/up.js.map +1 -1
- package/dist/commands/update.js +3 -3
- package/dist/commands/update.js.map +1 -1
- package/dist/help.d.ts.map +1 -1
- package/dist/help.js +8 -5
- package/dist/help.js.map +1 -1
- package/dist/lib/interrupt-report.d.ts.map +1 -1
- package/dist/lib/interrupt-report.js +2 -2
- package/dist/lib/interrupt-report.js.map +1 -1
- package/dist/lib/manager-choice.d.ts.map +1 -1
- package/dist/lib/manager-choice.js +3 -3
- package/dist/lib/manager-choice.js.map +1 -1
- package/dist/lib/service-systemd.js +1 -1
- package/dist/lib/service-systemd.js.map +1 -1
- package/dist/ui.js +2 -2
- package/dist/ui.js.map +1 -1
- package/dist/watch-json.js +3 -3
- package/dist/watch-json.js.map +1 -1
- package/package.json +4 -4
package/dist/commands/up.js
CHANGED
|
@@ -5,10 +5,10 @@ import { createConnection, createServer, isIP } from "node:net";
|
|
|
5
5
|
import { homedir, hostname } from "node:os";
|
|
6
6
|
import { accessSync, constants, mkdirSync, readFileSync, existsSync, statSync, closeSync, lstatSync, realpathSync, readdirSync, rmdirSync, unlinkSync, } from "node:fs";
|
|
7
7
|
import { basename, dirname, isAbsolute, join, resolve } from "node:path";
|
|
8
|
-
import { isReachable, dialerFor, DEFAULT_SERVER, DEFAULT_SPACE, createSpaceAuth, serverConfig, openServerConfig, validateTlsMaterial, credsProblem, mintCreds, mintLifecycleUid, DEV_OWNER, mintConnectionEvictorCreds, mintMembershipObserverCreds, newIdentity, setupSpaceStreams, removeIssuedStoresBeforeRetention, IssuedStoreBeforeRetentionError, IssuedStoreRecreateRefusal, reconcileSpaceTtls, ttlBuckets, standaloneConnectOpts, requireBrokerFloor, parseServerVersion, presenceBucket, MEMBERSHIP_MAX_BYTES, spaceDeletionStreams, isJetStreamMissing, seedChannelRegistry, ensureDefaultDeliveryClass, UndecodableRegistryEntry, assertValidChannel, isConcreteChannel, validateChannelConfig, validateChannelDefaults, LEASE_TTL_MS, mkSecretDir, openPrivateAppend, realDirNoSymlink, writeSecretFile, writeSecretFileAtomic, utf16Problem, } from "@cotal-ai/core";
|
|
8
|
+
import { isReachable, dialerFor, DEFAULT_SERVER, DEFAULT_SPACE, SERVICE_AUTHORITY_MAX_BYTES, SERVICE_CALLER_PAYLOAD_FLOOR, createSpaceAuth, serverConfig, openServerConfig, validateTlsMaterial, credsProblem, mintCreds, mintLifecycleUid, DEV_OWNER, mintConnectionEvictorCreds, mintMembershipObserverCreds, newIdentity, setupSpaceStreams, removeIssuedStoresBeforeRetention, IssuedStoreBeforeRetentionError, IssuedStoreRecreateRefusal, reconcileSpaceTtls, ttlBuckets, standaloneConnectOpts, requireBrokerFloor, parseServerVersion, presenceBucket, MEMBERSHIP_MAX_BYTES, spaceDeletionStreams, isJetStreamMissing, seedChannelRegistry, ensureDefaultDeliveryClass, UndecodableRegistryEntry, assertValidChannel, isConcreteChannel, validateChannelConfig, validateChannelDefaults, LEASE_TTL_MS, mkSecretDir, openPrivateAppend, realDirNoSymlink, writeSecretFile, writeSecretFileAtomic, utf16Problem, } from "@cotal-ai/core";
|
|
9
9
|
import { JetStreamApiCodes, jetstreamManager, StorageType } from "@nats-io/jetstream";
|
|
10
10
|
import { Kvm } from "@nats-io/kv";
|
|
11
|
-
import { assertManagerName, readManagerName, readManagerSeatCap, recordManagerName, recordManagerSeatCap, parseSeatCapFlag, seatCapText, assertRecordIdentity, formatRecord, identityRecord, parseRecord, CommandFailure, codeSpan, commandFailureReport, isCommandFailure, protectedLocalDirectory, jsonFlag, plainFlag, renderReport,
|
|
11
|
+
import { assertManagerName, readManagerName, readManagerSeatCap, recordManagerName, recordManagerSeatCap, parseSeatCapFlag, seatCapText, assertRecordIdentity, formatRecord, identityRecord, parseRecord, CommandFailure, codeSpan, commandFailureReport, isCommandFailure, protectedLocalDirectory, jsonFlag, plainFlag, renderReport, assertSingleSpaceBroker, assertUserAuthInfo, authDir, brokerAddressForDisplay, brokerPolicyPath, getSoleSpaceAuth, soleSpaceOf, getSpaceAuth, hasUserAuthState, listSpaceAccounts, preloadSpaceAccounts, putSpaceAuth, brokerAddressKey, canonicalRoot, rootPathProblem, rootControlProblem, clearCurrent, findMesh, findPreparedSpace, homeCotalDir, getCurrent, loadMeshes, preparedSpaceAt, removePreparedSpace, localMeshesForRoot, keepsRegistration, oneLine, presentationOf, writeResult, connectionEvictorCredsKey, membershipConfigPath, membershipObserverCredsKey, membershipRwCredsKey, MEMBERSHIP_CONFIG_KIND, MEMBERSHIP_RW_CREDS_KIND, parsePositiveIntegerFlag, recordMesh, retainedLegacyBroker, meshesForRoot, removeMesh, rotateSystemCreds, setCurrent, staleSystemCreds, SYSTEM_CREDS_FILES, userAuthStateDir, userAuthSpacesOnDisk, workspaceSecretStore, acquireMaintenanceLock, assertStoreIdentity, assessMaintenanceClaim, assessRestoreClaim, beginOrdinaryResume, bindOrdinaryResumeListener, consumeRetiredMaintenance, markOrdinaryResumeActive, markOrdinaryResumeDegraded, replaceDeadOrdinaryResumeListener, localProcessOwnerStatus, readMaintenanceJournal, rootNamesNoSpace, readMaintenanceResumeDocument, seatCheckpointDir, readStoreIdentity, recordOrdinaryResumeManagerCommit, releaseMaintenanceLock, retireOrdinaryResume, settleTokenHandoff, sweepTokenHandoff, writeTokenHandoff, sameStoreIdentity, cutController, readBrokerPolicy, writeBrokerPolicy, removePidPair, writePidPair, isLoopbackHost, connectUserControlOrThrow, userViewAuth, recordOperationSpace, recordsElsewhereError, recordOperationWarning, retainSystemSigningSeed, restoreLeftOut, SPACE_NAME_MAX, spaceNameTooLong, MIN_FILE_STORE, NATS_PIDFILE, exitCode, } from "@cotal-ai/workspace";
|
|
12
12
|
import { FlagValueRefusal } from "../lib/flag-value-refusal.js";
|
|
13
13
|
import { ensureAuthService, resolveAuthProvider, stopAuthService } from "../lib/auth-proc.js";
|
|
14
14
|
import { resolveSpace } from "../lib/status.js";
|
|
@@ -87,6 +87,7 @@ export const upFlags = [
|
|
|
87
87
|
{ name: "store-dir", type: "string", value: "<dir>", description: "JetStream store directory" },
|
|
88
88
|
{ name: "max-file-store", type: "string", value: "<bytes>", description: "JetStream file storage cap in bytes (default: nats-server's dynamic cap). Fixed at broker start and recorded for the next `up`; a legacy root also keeps it across `down --preserve-state`" },
|
|
89
89
|
{ name: "auth-timeout", type: "string", value: "<seconds>", description: "user-auth only: how long the broker waits for the auth callout, 1 to 60 seconds (default: nats-server's 2); the auth service answers inside it. Fixed at broker start and recorded for the next `up`" },
|
|
90
|
+
{ name: "max-payload", type: "string", value: "<bytes>", description: "broker-wide message size limit in bytes (default: nats-server's 1048576). Service endpoint caller grants need at least 2098176. Fixed at broker start and recorded for the next `up`" },
|
|
90
91
|
{ name: "channels", type: "string", value: "<path>", description: "channel-registry seed file (JSON; default .cotal/channels.json)" },
|
|
91
92
|
{ name: "tls-cert", type: "string", value: "<file>", description: "serve the broker over TLS with this certificate (requires --tls-key)" },
|
|
92
93
|
{ name: "tls-key", type: "string", value: "<file>", description: "the private key for --tls-cert" },
|
|
@@ -206,6 +207,22 @@ export function validateUpArguments(args) {
|
|
|
206
207
|
if (args.values.file !== undefined || args.values.restore !== undefined)
|
|
207
208
|
throw new CommandFailure("refused", "USAGE_INVALID", `--auth-timeout cannot be combined with ${args.values.file !== undefined ? "--file/-f" : "--restore"}, which starts the broker its own record describes; nothing was started`, { remedy: "start it without --auth-timeout; a recorded timeout is rendered again" });
|
|
208
209
|
}
|
|
210
|
+
// The payload limit is rendered by the auth-mode broker configuration. The open broker renders a
|
|
211
|
+
// different one that carries no limit, and a manifest or a restore starts the broker its own
|
|
212
|
+
// record describes, so none of the three takes the flag.
|
|
213
|
+
const requestedPayload = parseMaxPayload(args.values["max-payload"]);
|
|
214
|
+
if (requestedPayload !== undefined) {
|
|
215
|
+
if (args.values.open === true)
|
|
216
|
+
throw new CommandFailure("refused", "USAGE_INVALID", "--max-payload sets the broker's message size limit, which the open broker configuration does not render; nothing was started", { remedy: "drop --max-payload, or start an auth space without --open" });
|
|
217
|
+
if (args.values.file !== undefined || args.values.restore !== undefined)
|
|
218
|
+
throw new CommandFailure("refused", "USAGE_INVALID", `--max-payload cannot be combined with ${args.values.file !== undefined ? "--file/-f" : "--restore"}, which starts the broker its own record describes; nothing was started`, { remedy: "start it without --max-payload; a recorded limit is rendered again" });
|
|
219
|
+
// A space that admits service endpoints is a space whose auth host asserts the caller payload
|
|
220
|
+
// precondition at startup, and that assertion REFUSES below the floor, so the auth context does
|
|
221
|
+
// not open at all. Refusing the pair here is the difference between a usage error before
|
|
222
|
+
// anything starts and a broker that comes up without its auth plane.
|
|
223
|
+
if (args.values["service-endpoints"] === true && requestedPayload < SERVICE_CALLER_PAYLOAD_FLOOR)
|
|
224
|
+
throw new CommandFailure("refused", "USAGE_INVALID", `--max-payload ${requestedPayload} is below ${SERVICE_CALLER_PAYLOAD_FLOOR} bytes, the least a space with --service-endpoints starts on: a caller policy row may grow to ${SERVICE_AUTHORITY_MAX_BYTES} bytes and its write needs ${SERVICE_CALLER_PAYLOAD_FLOOR - SERVICE_AUTHORITY_MAX_BYTES} more, so the auth host refuses to open; nothing was started`, { remedy: `pass --max-payload ${SERVICE_CALLER_PAYLOAD_FLOOR} or more, or drop --service-endpoints` });
|
|
225
|
+
}
|
|
209
226
|
if (typeof args.values["store-dir"] === "string")
|
|
210
227
|
assertStoreDirArgument(args.values["store-dir"], typeof args.values.root === "string" ? resolve(args.values.root) : freshFolderRoot(args.values) ?? cotalRoot());
|
|
211
228
|
const restoreOnly = args.values["restore-only"];
|
|
@@ -531,7 +548,7 @@ function assertFreshTeamBootOwnership(root, space, mode, own) {
|
|
|
531
548
|
* failed or unknown stop is reported with its retained members; nothing is force-killed. */
|
|
532
549
|
function stopForegroundStack(root, signal) {
|
|
533
550
|
return stackDown(root, { yes: true }).catch((error) => {
|
|
534
|
-
process.stderr.write(`${renderReport(commandFailureReport(isCommandFailure(error) ? error : new CommandFailure("unknown", "OPERATION_UNKNOWN", "the foreground stack stop did not confirm its outcome; its members were retained")), "rich",
|
|
551
|
+
process.stderr.write(`${renderReport(commandFailureReport(isCommandFailure(error) ? error : new CommandFailure("unknown", "OPERATION_UNKNOWN", "the foreground stack stop did not confirm its outcome; its members were retained")), "rich", process.stderr)}\n`);
|
|
535
552
|
}).finally(() => { process.exitCode = signal === "SIGINT" ? 130 : 143; });
|
|
536
553
|
}
|
|
537
554
|
/** Foreground controller stack: the terminal holds the stack's lifetime until SIGINT or SIGTERM,
|
|
@@ -601,7 +618,7 @@ async function holdStack(root, start) {
|
|
|
601
618
|
process.off("SIGINT", interrupt);
|
|
602
619
|
process.off("SIGTERM", terminate);
|
|
603
620
|
clearInterval(lifetime);
|
|
604
|
-
process.stderr.write(`${renderReport({ sections: [{ title: "Foreground stack released", blocks: [{ kind: "lines", lines: [`Another command completed a ${operation.kind === "down" ? "stop" : "preserve"} of this stack (operation ${operation.id}). This terminal no longer holds it.`] }] }] }, "rich",
|
|
621
|
+
process.stderr.write(`${renderReport({ sections: [{ title: "Foreground stack released", blocks: [{ kind: "lines", lines: [`Another command completed a ${operation.kind === "down" ? "stop" : "preserve"} of this stack (operation ${operation.id}). This terminal no longer holds it.`] }] }] }, "rich", process.stderr)}\n`);
|
|
605
622
|
process.exitCode = 0;
|
|
606
623
|
resolveHold();
|
|
607
624
|
}, 1000);
|
|
@@ -1018,10 +1035,16 @@ async function runUp(args, inheritedLock, onAdopt, freshTeamBoot = false, restor
|
|
|
1018
1035
|
if (requestedMaxFileStore !== undefined && requestedMaxFileStore !== resumeMaxFileStore)
|
|
1019
1036
|
throw preservedOnly("--max-file-store", requestedMaxFileStore, "file store cap", resumeMaxFileStore === undefined ? "no cap" : String(resumeMaxFileStore));
|
|
1020
1037
|
// The resumed broker renders this root's recorded auth callout timeout again.
|
|
1021
|
-
const
|
|
1038
|
+
const recordedPolicy = readBrokerPolicy(root);
|
|
1039
|
+
const recordedTimeout = recordedPolicy?.authTimeout;
|
|
1022
1040
|
const requestedTimeout = parseAuthTimeout(values["auth-timeout"]);
|
|
1023
1041
|
if (requestedTimeout !== undefined && requestedTimeout !== recordedTimeout)
|
|
1024
1042
|
throw preservedOnly("--auth-timeout", requestedTimeout, "auth callout timeout", recordedTimeout === undefined ? "none" : String(recordedTimeout));
|
|
1043
|
+
// So is the payload limit: a resume renders the recorded one.
|
|
1044
|
+
const recordedPayload = recordedPolicy?.maxPayload;
|
|
1045
|
+
const requestedPayload = parseMaxPayload(values["max-payload"]);
|
|
1046
|
+
if (requestedPayload !== undefined && requestedPayload !== recordedPayload)
|
|
1047
|
+
throw preservedOnly("--max-payload", requestedPayload, "payload limit", recordedPayload === undefined ? "none" : String(recordedPayload));
|
|
1025
1048
|
if (values.runtime && runtimes[0] && values.runtime !== runtimes[0])
|
|
1026
1049
|
throw preservedOnly("--runtime", values.runtime, "agent runtime", runtimes[0]);
|
|
1027
1050
|
const resumeRuntime = values.runtime ?? runtimes[0] ?? "pty";
|
|
@@ -1082,6 +1105,9 @@ async function runUp(args, inheritedLock, onAdopt, freshTeamBoot = false, restor
|
|
|
1082
1105
|
const requestedTimeout = parseAuthTimeout(values["auth-timeout"]);
|
|
1083
1106
|
if (requestedTimeout !== undefined && requestedTimeout !== readBrokerPolicy(root)?.authTimeout)
|
|
1084
1107
|
throw new Error(`--auth-timeout ${requestedTimeout} is not this root's recorded auth callout timeout; resume attempt ${attemptId} re-renders the recorded one - omit --auth-timeout`);
|
|
1108
|
+
const requestedPayload = parseMaxPayload(values["max-payload"]);
|
|
1109
|
+
if (requestedPayload !== undefined && requestedPayload !== readBrokerPolicy(root)?.maxPayload)
|
|
1110
|
+
throw new Error(`--max-payload ${requestedPayload} is not this root's recorded payload limit; resume attempt ${attemptId} re-renders the recorded one - omit --max-payload`);
|
|
1085
1111
|
// Recovery re-asserts the source identity rather than trusting the journaled spelling.
|
|
1086
1112
|
assertStoreIdentity(journal.source);
|
|
1087
1113
|
// The bound listener decides re-entry: a live exact listener is ADOPTED, a provably dead
|
|
@@ -1225,6 +1251,7 @@ async function runUp(args, inheritedLock, onAdopt, freshTeamBoot = false, restor
|
|
|
1225
1251
|
const maxSessions = parsePositiveIntegerFlag("--max-sessions", values["max-sessions"]);
|
|
1226
1252
|
const maxFileStore = parseMaxFileStore(values["max-file-store"]);
|
|
1227
1253
|
const authTimeout = parseAuthTimeout(values["auth-timeout"]);
|
|
1254
|
+
const maxPayload = parseMaxPayload(values["max-payload"]);
|
|
1228
1255
|
// The manifest path renders its broker from the manifest, which has no store fields, so the flag
|
|
1229
1256
|
// would be accepted and never rendered. Refuse it rather than drop it.
|
|
1230
1257
|
if (maxFileStore !== undefined && values.file)
|
|
@@ -1374,7 +1401,7 @@ async function runUp(args, inheritedLock, onAdopt, freshTeamBoot = false, restor
|
|
|
1374
1401
|
const stackServer = values.server ?? readStackJournal(meshRoot)?.journal.server ?? localMeshesForRoot(meshRoot).find((m) => m.space === stackSpace)?.server ?? await unrecordedStackServer(meshRoot, stackSpace, values.host);
|
|
1375
1402
|
if (values.foreground && presentation !== "json")
|
|
1376
1403
|
stackUpForegroundNotice(presentation, stackSpace, takeover);
|
|
1377
|
-
await stackUp({ maintenanceLock: stackLock, root: meshRoot, space: stackSpace, server: stackServer, transport, runtime: values.runtime ?? "pty", noManager, ...(stackMode ? { mode: stackMode } : {}), ...(values.idp ? { idp: values.idp } : {}), ...(values.host ? { host: values.host } : {}), ...(values["store-dir"] ? { storeDir: values["store-dir"] } : {}), ...(values["rotate-sys"] ? { rotateSys: true } : {}), ...(values["recreate-issued-stores"] !== undefined ? { recreateIssuedStores: resolve(values["recreate-issued-stores"]) } : {}), ...(maxFileStore !== undefined ? { maxFileStore } : {}), ...(authTimeout !== undefined ? { authTimeout } : {}), ...(maxSessions !== undefined ? { maxSessions } : {}), ...(values.channels ? { channels: values.channels } : {}), ...(values.__invokedRoot ? { invokedRoot: values.__invokedRoot } : {}), foreground: values.foreground === true, presentation }, native);
|
|
1404
|
+
await stackUp({ maintenanceLock: stackLock, root: meshRoot, space: stackSpace, server: stackServer, transport, runtime: values.runtime ?? "pty", noManager, ...(stackMode ? { mode: stackMode } : {}), ...(values.idp ? { idp: values.idp } : {}), ...(values.host ? { host: values.host } : {}), ...(values["store-dir"] ? { storeDir: values["store-dir"] } : {}), ...(values["rotate-sys"] ? { rotateSys: true } : {}), ...(values["recreate-issued-stores"] !== undefined ? { recreateIssuedStores: resolve(values["recreate-issued-stores"]) } : {}), ...(maxFileStore !== undefined ? { maxFileStore } : {}), ...(authTimeout !== undefined ? { authTimeout } : {}), ...(maxPayload !== undefined ? { maxPayload } : {}), ...(maxSessions !== undefined ? { maxSessions } : {}), ...(values.channels ? { channels: values.channels } : {}), ...(values.__invokedRoot ? { invokedRoot: values.__invokedRoot } : {}), foreground: values.foreground === true, presentation }, native);
|
|
1378
1405
|
}
|
|
1379
1406
|
finally {
|
|
1380
1407
|
releaseMaintenanceLock(stackLock);
|
|
@@ -1712,11 +1739,17 @@ async function runUp(args, inheritedLock, onAdopt, freshTeamBoot = false, restor
|
|
|
1712
1739
|
}
|
|
1713
1740
|
// So is the auth callout timeout: the running broker keeps the one it was started with, which
|
|
1714
1741
|
// its broker policy records.
|
|
1715
|
-
const
|
|
1742
|
+
const runningPolicy = readBrokerPolicy(root);
|
|
1743
|
+
const runningTimeout = runningPolicy?.authTimeout;
|
|
1716
1744
|
if (authTimeout !== undefined && authTimeout !== runningTimeout) {
|
|
1717
1745
|
console.error(c.red(`✗ mesh "${held.space}" is already running at ${server} - a running broker can't change --auth-timeout (it is fixed at start); \`cotal down\` it first, then \`cotal up --user-auth --auth-timeout ${authTimeout}\``));
|
|
1718
1746
|
process.exit(1);
|
|
1719
1747
|
}
|
|
1748
|
+
// And so is the payload limit, which the same record carries.
|
|
1749
|
+
if (maxPayload !== undefined && maxPayload !== runningPolicy?.maxPayload) {
|
|
1750
|
+
console.error(c.red(`✗ mesh "${held.space}" is already running at ${server} - a running broker can't change --max-payload (it is fixed at start); \`cotal down\` it first, then \`cotal up --max-payload ${maxPayload}\``));
|
|
1751
|
+
process.exit(1);
|
|
1752
|
+
}
|
|
1720
1753
|
// The store directory is fixed the same way: an explicit --store-dir on a live refresh can
|
|
1721
1754
|
// only be refused when it disagrees with what the running broker actually opened. Absent
|
|
1722
1755
|
// `held.storeDir` (a pre-field record) has nothing to compare against, so it is not checked.
|
|
@@ -1808,7 +1841,7 @@ async function runUp(args, inheritedLock, onAdopt, freshTeamBoot = false, restor
|
|
|
1808
1841
|
// about it, and ends with the steps to take. It used to print this one green line alone, so
|
|
1809
1842
|
// `up` in a running project's subfolder answered without saying which mesh it reached or what
|
|
1810
1843
|
// to do next, while the launch beside it printed both.
|
|
1811
|
-
console.log(`${renderReport({ space: held.space, sections: [] }, "rich",
|
|
1844
|
+
console.log(`${renderReport({ space: held.space, sections: [] }, "rich", process.stdout)}\n`);
|
|
1812
1845
|
console.log(c.green(`✓ mesh "${held.space}" already running at ${server}`));
|
|
1813
1846
|
// USER MODE: re-upping IS the documented recovery for a dead auth service (the provider's
|
|
1814
1847
|
// failure copy says "restart it with `cotal up`"), so a refresh must re-ensure the service —
|
|
@@ -1891,7 +1924,7 @@ async function runUp(args, inheritedLock, onAdopt, freshTeamBoot = false, restor
|
|
|
1891
1924
|
seedPersonaAfterUp(root);
|
|
1892
1925
|
// The same Next a launch ends with: this mesh runs, so the steps are the ones that use and
|
|
1893
1926
|
// stop it. A manager the refresh found or healed is what makes `spawn` one of them.
|
|
1894
|
-
console.log(`\n${renderReport({ sections: [{ title: "Next", blocks: [{ kind: "commands", items: detachedNext({ manager: managerRecordState(held.space).state === "alive", machineHome: canonicalRoot(root) === canonicalRoot(homedir()), ...(values.root ? { root } : {}) }, held.space) }] }] }, "rich",
|
|
1927
|
+
console.log(`\n${renderReport({ sections: [{ title: "Next", blocks: [{ kind: "commands", items: detachedNext({ manager: managerRecordState(held.space).state === "alive", machineHome: canonicalRoot(root) === canonicalRoot(homedir()), ...(values.root ? { root } : {}) }, held.space) }] }] }, "rich", process.stdout)}`);
|
|
1895
1928
|
return;
|
|
1896
1929
|
}
|
|
1897
1930
|
const who = held ? `mesh "${held.space}" (${held.root})` : "a broker not started here";
|
|
@@ -1951,13 +1984,14 @@ async function runUp(args, inheritedLock, onAdopt, freshTeamBoot = false, restor
|
|
|
1951
1984
|
refuseStartOverUserState(Boolean(values.open), wantUser, receiptSpace);
|
|
1952
1985
|
await claimSpace(receiptSpace, server, cotalRoot());
|
|
1953
1986
|
if (!quietRestore)
|
|
1954
|
-
console.log(`${renderReport({ space: receiptSpace, sections: [] }, "rich",
|
|
1987
|
+
console.log(`${renderReport({ space: receiptSpace, sections: [] }, "rich", process.stdout)}\n`);
|
|
1955
1988
|
const { pid, executable, authService, controlPlane, delivery, manager } = await startMeshDetached({
|
|
1956
1989
|
transport,
|
|
1957
1990
|
server,
|
|
1958
1991
|
storeDir: values["store-dir"],
|
|
1959
1992
|
maxFileStore,
|
|
1960
1993
|
authTimeout,
|
|
1994
|
+
maxPayload,
|
|
1961
1995
|
space: values.space,
|
|
1962
1996
|
open: values.open,
|
|
1963
1997
|
userAuth: wantUser ? { idpUrl: values.idp } : undefined,
|
|
@@ -2009,7 +2043,7 @@ async function runUp(args, inheritedLock, onAdopt, freshTeamBoot = false, restor
|
|
|
2009
2043
|
console.log(c.dim(`next: ${restoreNextStep(journal.state, restored.attemptId, restoreLeftOut(journal))}`));
|
|
2010
2044
|
}
|
|
2011
2045
|
if (!quietRestore)
|
|
2012
|
-
console.log(`\n${renderReport({ sections: [{ title: "Next", blocks: [{ kind: "commands", items: detachedNext(detached, receiptSpace) }] }] }, "rich",
|
|
2046
|
+
console.log(`\n${renderReport({ sections: [{ title: "Next", blocks: [{ kind: "commands", items: detachedNext(detached, receiptSpace) }] }] }, "rich", process.stdout)}`);
|
|
2013
2047
|
if (restored)
|
|
2014
2048
|
restoreSinks.get(restored.attemptId)?.({
|
|
2015
2049
|
attemptId: restored.attemptId, space: restored.space, root: restored.root, server: restored.server, mode: restored.mode,
|
|
@@ -2042,7 +2076,7 @@ async function runUp(args, inheritedLock, onAdopt, freshTeamBoot = false, restor
|
|
|
2042
2076
|
// Decided above the branch; the dial host is only settled here (a port collision may have moved
|
|
2043
2077
|
// the server, and the hostname is what the certificate has to match).
|
|
2044
2078
|
assertServesDialHost(transport, new URL(server).hostname);
|
|
2045
|
-
const setup = useAuth ? await authSetup(storeDir, server, space, host, wantUser ? { idpUrl: values.idp } : undefined, transport, values["rotate-sys"], maxFileStore, false, authTimeout) : undefined;
|
|
2079
|
+
const setup = useAuth ? await authSetup(storeDir, server, space, host, wantUser ? { idpUrl: values.idp } : undefined, transport, values["rotate-sys"], maxFileStore, false, { authTimeout, maxPayload }) : undefined;
|
|
2046
2080
|
const port = Number(new URL(server).port) || 4222;
|
|
2047
2081
|
// Both modes go through a RENDERER, never bare CLI flags. Open mode used to start from
|
|
2048
2082
|
// `-js -sd … -p … -a …`, which never called a renderer at all — so the required transport union
|
|
@@ -2576,6 +2610,8 @@ async function resumeControllerStack(lock, root, values, restoreSink) {
|
|
|
2576
2610
|
throw new CommandFailure("refused", "USAGE_INVALID", "a controller resume takes its store and cap from the cut; --store-dir and --max-file-store are refused", { target: { root, space } });
|
|
2577
2611
|
if (values["auth-timeout"] !== undefined)
|
|
2578
2612
|
throw new CommandFailure("refused", "USAGE_INVALID", "a controller resume renders this root's recorded auth callout timeout; --auth-timeout is refused", { target: { root, space }, remedy: "run `cotal up` without --auth-timeout" });
|
|
2613
|
+
if (values["max-payload"] !== undefined)
|
|
2614
|
+
throw new CommandFailure("refused", "USAGE_INVALID", "a controller resume renders this root's recorded payload limit; --max-payload is refused", { target: { root, space }, remedy: "run `cotal up` without --max-payload" });
|
|
2579
2615
|
const runtimes = [...new Set(agents.map((agent) => agent.launch?.runtime).filter((value) => typeof value === "string"))];
|
|
2580
2616
|
if (runtimes.length > 1 || (values.runtime !== undefined && runtimes[0] !== undefined && values.runtime !== runtimes[0]))
|
|
2581
2617
|
throw new CommandFailure("refused", "USAGE_INVALID", "--runtime must equal the preserved inventory's runtime; a controller resume does not change it", { target: { root, space } });
|
|
@@ -3202,13 +3238,13 @@ export async function recheckFreshTeamBoot(plan, own) {
|
|
|
3202
3238
|
export function controllerStackNative() {
|
|
3203
3239
|
return {
|
|
3204
3240
|
prepareBroker: async (opts) => {
|
|
3205
|
-
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.authTimeout !== undefined ? { authTimeout: opts.authTimeout } : {}), ...(opts.seed !== undefined ? { seed: opts.seed } : opts.channels ? { channels: opts.channels } : {}), quietBoot: true });
|
|
3206
|
-
return { root: prepared.root, server: prepared.server, space: prepared.space, storeDir: prepared.storeDir, transport: prepared.transport, ...(prepared.setup ? { setup: { creds: prepared.setup.creds, wsPort: prepared.setup.wsPort } } : {}), ...(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 } : {}) };
|
|
3241
|
+
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.authTimeout !== undefined ? { authTimeout: opts.authTimeout } : {}), ...(opts.maxPayload !== undefined ? { maxPayload: opts.maxPayload } : {}), ...(opts.seed !== undefined ? { seed: opts.seed } : opts.channels ? { channels: opts.channels } : {}), quietBoot: true });
|
|
3242
|
+
return { root: prepared.root, server: prepared.server, space: prepared.space, storeDir: prepared.storeDir, transport: prepared.transport, ...(prepared.setup ? { setup: { creds: prepared.setup.creds, wsPort: prepared.setup.wsPort } } : {}), ...(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.setup?.maxPayload !== undefined ? { maxPayload: prepared.setup.maxPayload } : {}) };
|
|
3207
3243
|
},
|
|
3208
3244
|
initializeStreams: (server, space, setup, seedFile, recreateIssuedStores) => postStart(server, space, setup, seedFile, recreateIssuedStores),
|
|
3209
3245
|
recreateDeletedStreams: ({ seed, ...opts }) => recreateDeletedStreams({ ...opts, ...(seed !== undefined ? { seed: seed } : {}) }),
|
|
3210
3246
|
recordMesh: (entry) => recordOurMesh({ ...entry, ts: new Date().toISOString() }, "started", true),
|
|
3211
|
-
commitTransport: (root, chosen,
|
|
3247
|
+
commitTransport: (root, chosen, limits) => commitTransportPolicy(root, chosen, true, undefined, limits),
|
|
3212
3248
|
};
|
|
3213
3249
|
}
|
|
3214
3250
|
/** The structured refusal for a manifest `up -f` cannot use: the located problems of one that does
|
|
@@ -3755,7 +3791,7 @@ async function serveReadyListener(l) {
|
|
|
3755
3791
|
// Commit the policy only for a listener that is up and recorded (S5), and before the control
|
|
3756
3792
|
// plane (S9). startDeliveryWithBroker is HANDED the transport decision, so it does not depend on
|
|
3757
3793
|
// the file at all.
|
|
3758
|
-
commitTransportPolicy(cotalRoot(), transport, l.quietBoot, server, setup?.authTimeout);
|
|
3794
|
+
commitTransportPolicy(cotalRoot(), transport, l.quietBoot, server, { authTimeout: setup?.authTimeout, maxPayload: setup?.maxPayload });
|
|
3759
3795
|
// The delivery daemon self-gates on `.cotal/auth`, so an open mesh has none. Class-2 credential
|
|
3760
3796
|
// renewal is NOT wired here: the MANAGER is the renewal owner (it is resident in every mesh mode,
|
|
3761
3797
|
// where a foreground `up` process is not).
|
|
@@ -3809,7 +3845,7 @@ export async function prepareBrokerStart(opts) {
|
|
|
3809
3845
|
// effective server is finally known — a manifest may name a different host than the flags did, and
|
|
3810
3846
|
// a certificate that is valid for one is not thereby valid for the other.
|
|
3811
3847
|
const transport = assertServesDialHost(opts.transport, new URL(server).hostname);
|
|
3812
|
-
const setup = useAuth ? await authSetup(storeDir, server, space, host, opts.userAuth, transport, opts.rotateSys, opts.maxFileStore, opts.quietBoot, opts.authTimeout) : undefined;
|
|
3848
|
+
const setup = useAuth ? await authSetup(storeDir, server, space, host, opts.userAuth, transport, opts.rotateSys, opts.maxFileStore, opts.quietBoot, { authTimeout: opts.authTimeout, maxPayload: opts.maxPayload }) : undefined;
|
|
3813
3849
|
const port = Number(new URL(server).port) || 4222;
|
|
3814
3850
|
// Same rule as the foreground path: every route to a listener names its transport (see
|
|
3815
3851
|
// `writeOpenBrokerConf`). Detach must not be the mode where the fence quietly does not apply.
|
|
@@ -4666,6 +4702,15 @@ function parseAuthTimeout(raw) {
|
|
|
4666
4702
|
return seconds;
|
|
4667
4703
|
}
|
|
4668
4704
|
const MAX_AUTH_TIMEOUT_SECONDS = 60;
|
|
4705
|
+
/** `--max-payload`, a positive whole number of bytes. nats-server refuses to start above 64 MiB, so
|
|
4706
|
+
* the refusal names that bound rather than letting the broker exit on its own configuration. */
|
|
4707
|
+
function parseMaxPayload(raw) {
|
|
4708
|
+
const bytes = parsePositiveIntegerFlag("--max-payload", raw);
|
|
4709
|
+
if (bytes !== undefined && bytes > MAX_BROKER_PAYLOAD_BYTES)
|
|
4710
|
+
throw new CommandFailure("refused", "USAGE_INVALID", `--max-payload ${bytes} is over ${MAX_BROKER_PAYLOAD_BYTES} bytes (64 MiB), which nats-server refuses to start on; nothing was started`, { remedy: `pass --max-payload ${MAX_BROKER_PAYLOAD_BYTES} or less` });
|
|
4711
|
+
return bytes;
|
|
4712
|
+
}
|
|
4713
|
+
const MAX_BROKER_PAYLOAD_BYTES = 64 * 1024 * 1024;
|
|
4669
4714
|
/** The auth-service daemon argv that gives the callout the broker's timeout as its deadline. Built
|
|
4670
4715
|
* only from the value the broker configuration rendered, so the two never differ. */
|
|
4671
4716
|
function authTimeoutArgs(seconds) {
|
|
@@ -4886,10 +4931,11 @@ function assertTlsAddressServed(server, transport, root) {
|
|
|
4886
4931
|
}
|
|
4887
4932
|
/** Persist a transport, and the auth callout timeout the broker configuration rendered, after its
|
|
4888
4933
|
* listener starts; a structured boot leaves stdout to its receipt. */
|
|
4889
|
-
function commitTransportPolicy(root, transport, quietBoot = false, server,
|
|
4890
|
-
|
|
4934
|
+
function commitTransportPolicy(root, transport, quietBoot = false, server, limits) {
|
|
4935
|
+
const { authTimeout, maxPayload } = limits ?? {};
|
|
4936
|
+
if (transport.kind !== "tls-required" && authTimeout === undefined && maxPayload === undefined)
|
|
4891
4937
|
return;
|
|
4892
|
-
writeBrokerPolicy(root, { version: 1, transport, ...(authTimeout !== undefined ? { authTimeout } : {}) });
|
|
4938
|
+
writeBrokerPolicy(root, { version: 1, transport, ...(authTimeout !== undefined ? { authTimeout } : {}), ...(maxPayload !== undefined ? { maxPayload } : {}) });
|
|
4893
4939
|
if (!quietBoot)
|
|
4894
4940
|
announceTransport(transport, server);
|
|
4895
4941
|
}
|
|
@@ -5109,9 +5155,11 @@ async function authSetup(storeDir, server, space, host = "127.0.0.1", user,
|
|
|
5109
5155
|
// safe value and the common value are different values — every caller knows its transport, and
|
|
5110
5156
|
// the one that does not is the one that must not compile.
|
|
5111
5157
|
transport, rotateSys = false, maxFileStore, quietBoot = false,
|
|
5112
|
-
// `--auth-timeout`.
|
|
5113
|
-
//
|
|
5114
|
-
|
|
5158
|
+
// `--auth-timeout` and `--max-payload`. Each absent value falls back to the one the root's broker
|
|
5159
|
+
// policy records, so a bare `up` renders what an earlier `up` set. They arrive as one object
|
|
5160
|
+
// rather than two trailing optional numbers: a transposed pair of those renders a wrong
|
|
5161
|
+
// configuration in silence.
|
|
5162
|
+
requested = {}) {
|
|
5115
5163
|
const dir = authDir(cotalRoot()); // the broker config (server.conf) still lands under the FS auth dir
|
|
5116
5164
|
const store = workspaceSecretStore(cotalRoot());
|
|
5117
5165
|
let auth = await getSpaceAuth(store, space).catch((error) => { throw unreadableTrust(error); });
|
|
@@ -5228,13 +5276,15 @@ requestedAuthTimeout) {
|
|
|
5228
5276
|
}
|
|
5229
5277
|
// Owner-private regardless of umask, as `writeOpenBrokerConf` writes the open configuration: the
|
|
5230
5278
|
// broker preset refuses a configuration that other local users can write.
|
|
5231
|
-
const
|
|
5232
|
-
|
|
5279
|
+
const recorded = readBrokerPolicy(cotalRoot());
|
|
5280
|
+
const authTimeout = requested.authTimeout ?? recorded?.authTimeout;
|
|
5281
|
+
const maxPayload = requested.maxPayload ?? recorded?.maxPayload;
|
|
5282
|
+
writeBrokerConfig(confPath, serverConfig(auth, spaces, { transport, port, storeDir: configuredStoreDir(cotalRoot(), storeDir), maxFileStore, authTimeout, maxPayload, host, wsPort, wsHost: host, extraAccounts }));
|
|
5233
5283
|
// Ephemeral setup cred: used only to probe reachability, pre-create the space streams/buckets
|
|
5234
5284
|
// (setupSpaceStreams) and seed the channel registry (seedChannelRegistry) — all within the
|
|
5235
5285
|
// enumerated `provisioner` scope. No broad `manager` residual for the up path.
|
|
5236
5286
|
const creds = await mintCreds(auth, newIdentity(), "provisioner");
|
|
5237
|
-
return { confPath, creds, wsPort, ...(prepared ? { prepared, stateDir } : {}), ...(authTimeout !== undefined ? { authTimeout } : {}) };
|
|
5287
|
+
return { confPath, creds, wsPort, ...(prepared ? { prepared, stateDir } : {}), ...(authTimeout !== undefined ? { authTimeout } : {}), ...(maxPayload !== undefined ? { maxPayload } : {}) };
|
|
5238
5288
|
}
|
|
5239
5289
|
/**
|
|
5240
5290
|
* Refuse the rotation if this root's own bookkeeping still shows a broker running. This is a
|