@cotal-ai/cli 0.169.0 → 0.171.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/command.d.ts.map +1 -1
- package/dist/command.js +24 -8
- package/dist/command.js.map +1 -1
- package/dist/commands/agents.d.ts.map +1 -1
- package/dist/commands/agents.js +40 -18
- package/dist/commands/agents.js.map +1 -1
- package/dist/commands/channels.js +1 -1
- package/dist/commands/channels.js.map +1 -1
- package/dist/commands/clean.d.ts.map +1 -1
- package/dist/commands/clean.js +9 -4
- package/dist/commands/clean.js.map +1 -1
- package/dist/commands/config.d.ts.map +1 -1
- package/dist/commands/config.js +4 -3
- package/dist/commands/config.js.map +1 -1
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +19 -5
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/down.d.ts.map +1 -1
- package/dist/commands/down.js +70 -6
- package/dist/commands/down.js.map +1 -1
- package/dist/commands/ext.d.ts.map +1 -1
- package/dist/commands/ext.js +17 -8
- package/dist/commands/ext.js.map +1 -1
- package/dist/commands/history.d.ts.map +1 -1
- package/dist/commands/history.js +5 -4
- package/dist/commands/history.js.map +1 -1
- package/dist/commands/join.d.ts.map +1 -1
- package/dist/commands/join.js +19 -10
- package/dist/commands/join.js.map +1 -1
- package/dist/commands/manager-service.js +1 -1
- package/dist/commands/manager-service.js.map +1 -1
- package/dist/commands/meshes.d.ts.map +1 -1
- package/dist/commands/meshes.js +2 -7
- package/dist/commands/meshes.js.map +1 -1
- package/dist/commands/mint.d.ts.map +1 -1
- package/dist/commands/mint.js +20 -2
- package/dist/commands/mint.js.map +1 -1
- package/dist/commands/persona.d.ts.map +1 -1
- package/dist/commands/persona.js +6 -15
- package/dist/commands/persona.js.map +1 -1
- package/dist/commands/personas.js +3 -1
- package/dist/commands/personas.js.map +1 -1
- package/dist/commands/service-actions.d.ts.map +1 -1
- package/dist/commands/service-actions.js +19 -5
- package/dist/commands/service-actions.js.map +1 -1
- package/dist/commands/service-registry.d.ts.map +1 -1
- package/dist/commands/service-registry.js +5 -1
- package/dist/commands/service-registry.js.map +1 -1
- package/dist/commands/setup.d.ts.map +1 -1
- package/dist/commands/setup.js +22 -16
- package/dist/commands/setup.js.map +1 -1
- package/dist/commands/space.d.ts.map +1 -1
- package/dist/commands/space.js +36 -16
- package/dist/commands/space.js.map +1 -1
- package/dist/commands/spawn.d.ts.map +1 -1
- package/dist/commands/spawn.js +4 -8
- package/dist/commands/spawn.js.map +1 -1
- package/dist/commands/stack-gone.d.ts.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 +2 -2
- package/dist/commands/stack-up.d.ts.map +1 -1
- package/dist/commands/status.d.ts +2 -0
- package/dist/commands/status.d.ts.map +1 -1
- package/dist/commands/status.js +152 -83
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/team.d.ts.map +1 -1
- package/dist/commands/team.js +4 -1
- package/dist/commands/team.js.map +1 -1
- package/dist/commands/up.d.ts +1 -1
- package/dist/commands/up.d.ts.map +1 -1
- package/dist/commands/up.js +24 -117
- package/dist/commands/up.js.map +1 -1
- package/dist/commands/update.js +10 -3
- package/dist/commands/update.js.map +1 -1
- package/dist/commands/use.d.ts.map +1 -1
- package/dist/commands/use.js +7 -5
- package/dist/commands/use.js.map +1 -1
- package/dist/help.d.ts.map +1 -1
- package/dist/help.js +29 -27
- package/dist/help.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -4
- package/dist/index.js.map +1 -1
- package/dist/lib/channel-seed.d.ts +15 -0
- package/dist/lib/channel-seed.d.ts.map +1 -0
- package/dist/lib/channel-seed.js +121 -0
- package/dist/lib/channel-seed.js.map +1 -0
- package/dist/lib/persona-files.d.ts.map +1 -1
- package/dist/lib/persona-files.js +4 -2
- package/dist/lib/persona-files.js.map +1 -1
- package/dist/lib/reset-space-plan.d.ts +3 -2
- package/dist/lib/reset-space-plan.d.ts.map +1 -1
- package/dist/lib/reset-space-plan.js +9 -7
- package/dist/lib/reset-space-plan.js.map +1 -1
- package/dist/lib/self-exec.d.ts +1 -1
- package/dist/lib/self-exec.d.ts.map +1 -1
- package/dist/lib/self-exec.js +16 -11
- package/dist/lib/self-exec.js.map +1 -1
- package/dist/lib/service-systemd-files.js +2 -2
- package/dist/lib/service-systemd-files.js.map +1 -1
- package/dist/lib/stack-journal.d.ts +4 -0
- package/dist/lib/stack-journal.d.ts.map +1 -1
- package/dist/lib/stack-journal.js +13 -0
- package/dist/lib/stack-journal.js.map +1 -1
- package/dist/lib/store-dir.d.ts +2 -0
- package/dist/lib/store-dir.d.ts.map +1 -1
- package/dist/lib/store-dir.js +16 -0
- package/dist/lib/store-dir.js.map +1 -1
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +15 -5
- package/dist/render.js.map +1 -1
- package/package.json +4 -4
package/dist/commands/up.js
CHANGED
|
@@ -2,13 +2,12 @@ import { noManagerCredentialWarning } from "../lib/daemon-credential-warning.js"
|
|
|
2
2
|
import { drainAndClose } from "@cotal-ai/core";
|
|
3
3
|
import {} from "node:child_process";
|
|
4
4
|
import { spawnBroker } from "../lib/broker-spawn.js";
|
|
5
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
6
5
|
import { randomUUID } from "node:crypto";
|
|
7
6
|
import { createConnection, createServer, isIP } from "node:net";
|
|
8
7
|
import { homedir, hostname } from "node:os";
|
|
9
8
|
import { accessSync, constants, mkdirSync, readFileSync, existsSync, statSync, closeSync, lstatSync, realpathSync, readdirSync, rmdirSync, } from "node:fs";
|
|
10
9
|
import { basename, dirname, isAbsolute, join, resolve } from "node:path";
|
|
11
|
-
import { isReachable, dialerFor, DEFAULT_SERVER, DEFAULT_SPACE, SERVICE_AUTHORITY_MAX_BYTES, SERVICE_CALLER_PAYLOAD_FLOOR, CONTRACT_ARTIFACT_MAX_BYTES, MANAGER_START_PAYLOAD_FLOOR, createSpaceAuth, serverConfig, openServerConfig, validateTlsMaterial, credsProblem, mintCreds, mintLifecycleUid, DEV_OWNER, mintConnectionEvictorCreds, mintMembershipObserverCreds, newIdentity, setupSpaceStreams, removeIssuedStoresBeforeRetention, IssuedStoreBeforeRetentionError, IssuedStoreRecreateRefusal, reconcileSpaceMemoryBuckets, membershipStoreDefinition, LEGACY_MEMBERSHIP_MAX_BYTES, MEMBERSHIP_MAX_VALUE_SIZE, ttlBuckets, standaloneConnectOpts, requireBrokerFloor, parseServerVersion, presenceBucket, spaceDeletionStreams, isJetStreamMissing, seedChannelRegistry, ensureDefaultDeliveryClass, UndecodableRegistryEntry,
|
|
10
|
+
import { isReachable, dialerFor, DEFAULT_SERVER, DEFAULT_SPACE, SERVICE_AUTHORITY_MAX_BYTES, SERVICE_CALLER_PAYLOAD_FLOOR, CONTRACT_ARTIFACT_MAX_BYTES, MANAGER_START_PAYLOAD_FLOOR, createSpaceAuth, serverConfig, openServerConfig, validateTlsMaterial, credsProblem, mintCreds, mintLifecycleUid, DEV_OWNER, mintConnectionEvictorCreds, mintMembershipObserverCreds, newIdentity, setupSpaceStreams, removeIssuedStoresBeforeRetention, IssuedStoreBeforeRetentionError, IssuedStoreRecreateRefusal, reconcileSpaceMemoryBuckets, membershipStoreDefinition, LEGACY_MEMBERSHIP_MAX_BYTES, MEMBERSHIP_MAX_VALUE_SIZE, ttlBuckets, standaloneConnectOpts, requireBrokerFloor, parseServerVersion, presenceBucket, spaceDeletionStreams, isJetStreamMissing, seedChannelRegistry, ensureDefaultDeliveryClass, UndecodableRegistryEntry, LEASE_TTL_MS, EpEnvelopeError, mkSecretDir, openPrivateAppend, writeSecretFile, } from "@cotal-ai/core";
|
|
12
11
|
import { JetStreamApiCodes, jetstreamManager, StorageType } from "@nats-io/jetstream";
|
|
13
12
|
import { Kvm } from "@nats-io/kv";
|
|
14
13
|
import { assertManagerName, readManagerName, readManagerSeatCap, recordManagerName, recordManagerSeatCap, parseSeatCapFlag, seatCapText, CommandFailure, codeSpan, commandFailureReport, failureEnvelope, writeEnvelope, 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, legacyStackOtherHome, stackHomeRemedy, getCurrent, loadMeshes, preparedSpaceAt, removePreparedSpace, localMeshesForRoot, keepsRegistration, oneLine, presentationOf, writeResult, connectionEvictorCredsKey, membershipConfigPath, membershipObserverCredsKey, membershipRwCredsKey, MEMBERSHIP_CONFIG_KIND, MEMBERSHIP_RW_CREDS_KIND, WEB_CREDS_KIND, webCredsKey, parsePositiveIntegerFlag, recordMesh, retainedLegacyBroker, meshesForRoot, removeMesh, rotateSystemCreds, setAdoptedCurrent, staleSystemCreds, SYSTEM_CREDS_FILES, userAuthStateDir, userAuthSpacesOnDisk, workspaceSecretStore, acquireMaintenanceLock, assertStoreIdentity, assessMaintenanceClaim, assessRestoreClaim, beginOrdinaryResume, bindOrdinaryResumeListener, consumeRetiredMaintenance, markOrdinaryResumeActive, markOrdinaryResumeDegraded, replaceDeadOrdinaryResumeListener, localProcessOwnerStatus, readMaintenanceJournal, rootNamesNoSpace, readMaintenanceResumeDocument, readStoreIdentity, recordOrdinaryResumeManagerCommit, releaseMaintenanceLock, retireOrdinaryResume, settleTokenHandoff, sweepTokenHandoff, writeTokenHandoff, sameStoreIdentity, cutController, readBrokerPolicy, writeBrokerPolicy, brokerAccountResolver, removePidPair, writePidPair, verifyIdentityPin, processesNaming, isLoopbackHost, connectUserControlOrThrow, userViewAuth, recordOperationSpace, recordsElsewhereError, recordOperationWarning, retainSystemSigningSeed, restoreLeftOut, SPACE_NAME_MAX, spaceNameTooLong, NATS_PIDFILE, MANAGER_PIDFILE, DELIVERY_PIDFILE, AUTH_PIDFILE, localProcessPath, UNTRUSTED_CERTIFICATE, exitCode, canonicalLocalProcessPath, DELIVERY_LOGFILE, terminalWidth, } from "@cotal-ai/workspace";
|
|
@@ -19,6 +18,7 @@ import { c, hang, stderrLine } from "../ui.js";
|
|
|
19
18
|
import { admitAndRestoreSeatCheckpoints } from "../lib/seat-resume.js";
|
|
20
19
|
import { natsServerLabel, resolveNatsServer, unreadVersion } from "../lib/nats-bin.js";
|
|
21
20
|
import { cotalPath, cotalRoot, homeHoldsStack, linkedCotalRefusal } from "../lib/paths.js";
|
|
21
|
+
import { channelsReads, readChannelsFile, readDefaultChannelsFile } from "../lib/channel-seed.js";
|
|
22
22
|
import { detachedNext, renderDetachedSummary } from "../lib/up-report.js";
|
|
23
23
|
import { seedDefaultPersona } from "../lib/default-persona.js";
|
|
24
24
|
import { seedBeforeLaunch, seedMoveNote } from "../seed/launch.js";
|
|
@@ -51,7 +51,7 @@ import { assertUserStackTransport, preflightUserStack } from "./stack-user-auth.
|
|
|
51
51
|
import { stackDown } from "./stack-down.js";
|
|
52
52
|
import { assertControllerCoupling, assertControllerMembersLive, assertControllerResumeEligible, beginControllerResume, bindControllerBroker, controllerAttemptBrokerInstance, currentControllerAttempt, managerResumeAttempt, relaunchCommittedManager, settleControllerResume, startControllerMember, startControllerMembers, } from "../lib/controller-resume.js";
|
|
53
53
|
import { removeRetiredBrokerInstance } from "../lib/controller-restore.js";
|
|
54
|
-
import { acquireStackOperationLock,
|
|
54
|
+
import { acquireStackOperationLock, knownStackRecoveryHost, admittedStackRestore, readStackJournal, refuseControllerCut, STACK_DEFINITION, STACK_ROLES } from "../lib/stack-journal.js";
|
|
55
55
|
import { observeServiceProcess, serviceInstances } from "../lib/service-instances.js";
|
|
56
56
|
import { serviceDefinitionStore } from "../lib/service-definitions.js";
|
|
57
57
|
import { MissingFlags } from "../lib/missing-flags.js";
|
|
@@ -1629,7 +1629,7 @@ async function runUp(args, inheritedLock, onAdopt, freshTeamBoot = false, restor
|
|
|
1629
1629
|
// that journals, give it `heldLock` and hand it down from here; do not audit by call-site shape.
|
|
1630
1630
|
// The one caller that does NOT pass it is the prepare-failure path above, where the lock has
|
|
1631
1631
|
// genuinely not been taken yet in this frame and the helper is meant to take its own.
|
|
1632
|
-
let startupLock = inheritedLock ?? acquireStackOperationLock(cotalRoot());
|
|
1632
|
+
let startupLock = inheritedLock ?? acquireStackOperationLock(cotalRoot(), values.detach ? undefined : "foreground up");
|
|
1633
1633
|
onAdopt?.(); // from here the release below owns it, inherited or not
|
|
1634
1634
|
const releaseStartupLock = () => {
|
|
1635
1635
|
if (!startupLock)
|
|
@@ -2235,17 +2235,17 @@ async function runUp(args, inheritedLock, onAdopt, freshTeamBoot = false, restor
|
|
|
2235
2235
|
// Decided above the branch; the dial host is only settled here (a port collision may have moved
|
|
2236
2236
|
// the server, and the hostname is what the certificate has to match).
|
|
2237
2237
|
assertServesDialHost(transport, new URL(server).hostname);
|
|
2238
|
-
const
|
|
2239
|
-
const brokerMaxPayload =
|
|
2238
|
+
const brokerSetup = useAuth ? await authSetup(storeDir, server, space, host, wantUser ? { idpUrl: values.idp } : undefined, transport, values["rotate-sys"], maxFileStore, false, { authTimeout, maxPayload, accountResolver, manager: values["no-manager"] !== true }) : undefined;
|
|
2239
|
+
const brokerMaxPayload = brokerSetup?.maxPayload ?? maxPayload ?? readBrokerPolicy(cotalRoot())?.maxPayload;
|
|
2240
2240
|
const port = Number(new URL(server).port) || 4222;
|
|
2241
2241
|
// Both modes go through a RENDERER, never bare CLI flags. Open mode used to start from
|
|
2242
2242
|
// `-js -sd … -p … -a …`, which never called a renderer at all — so the required transport union
|
|
2243
2243
|
// protected the auth path and was silent on the open one, and a cert/key pair passed to an
|
|
2244
2244
|
// open-mode `up` would have been accepted while the listener came up in cleartext.
|
|
2245
|
-
const renderingBinary =
|
|
2245
|
+
const renderingBinary = brokerSetup?.brokerBinary ?? await resolveNatsServer();
|
|
2246
2246
|
if (!renderingBinary.version)
|
|
2247
2247
|
throw unreadVersion(renderingBinary);
|
|
2248
|
-
const confPath =
|
|
2248
|
+
const confPath = brokerSetup ? brokerSetup.confPath : writeOpenBrokerConf(storeDir, space, { brokerVersion: renderingBinary.version, port, host, transport, maxFileStore, maxPayload: brokerMaxPayload });
|
|
2249
2249
|
const natsArgs = [
|
|
2250
2250
|
"-c", confPath,
|
|
2251
2251
|
...(boundListener ? ["--name", boundListener.serverName] : []),
|
|
@@ -2253,6 +2253,7 @@ async function runUp(args, inheritedLock, onAdopt, freshTeamBoot = false, restor
|
|
|
2253
2253
|
const natsServer = renderingBinary;
|
|
2254
2254
|
const bin = natsServer.path;
|
|
2255
2255
|
await seedBeforeLaunch();
|
|
2256
|
+
const setup = brokerSetup && { ...brokerSetup, creds: await brokerSetup.mintProvisioner() };
|
|
2256
2257
|
const starting = `Starting ${natsServerLabel(natsServer)} (JetStream, ${useAuth ? "JWT auth" : "OPEN/no-auth"}) - store: ${storeDir}, bind: ${host}`;
|
|
2257
2258
|
for (const line of hang("", starting, terminalWidth(process.stdout), c.dim))
|
|
2258
2259
|
console.log(line);
|
|
@@ -2265,7 +2266,6 @@ async function runUp(args, inheritedLock, onAdopt, freshTeamBoot = false, restor
|
|
|
2265
2266
|
const child = spawnBroker(bin, natsArgs, { cwd: cotalRoot(), stdio: "inherit", detached: process.platform !== "win32" });
|
|
2266
2267
|
let activationFinished = !resumeAttempt;
|
|
2267
2268
|
await recordSpawnedListener(child, listenerStartedAt, boundListener);
|
|
2268
|
-
releaseStartupLock();
|
|
2269
2269
|
child.on("error", (err) => {
|
|
2270
2270
|
console.error(c.red(`Failed to start nats-server: ${err.message}`));
|
|
2271
2271
|
if (!resumeAttempt)
|
|
@@ -2459,6 +2459,7 @@ async function runUp(args, inheritedLock, onAdopt, freshTeamBoot = false, restor
|
|
|
2459
2459
|
await completeResumeActivation(resumeAttempt, controlPlane !== undefined && authService, !authService ? "normal listener started but the user-auth service is unavailable" : "normal listener started but the control plane is degraded", server, startupLock);
|
|
2460
2460
|
activationFinished = true;
|
|
2461
2461
|
}
|
|
2462
|
+
releaseStartupLock();
|
|
2462
2463
|
await new Promise(() => { });
|
|
2463
2464
|
}
|
|
2464
2465
|
finally {
|
|
@@ -3417,9 +3418,9 @@ export function controllerStackNative() {
|
|
|
3417
3418
|
return {
|
|
3418
3419
|
prepareBroker: async (opts) => {
|
|
3419
3420
|
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 });
|
|
3420
|
-
return { root: prepared.root, server: prepared.server, space: prepared.space, storeDir: prepared.storeDir, transport: prepared.transport, ...(prepared.setup ? { setup: {
|
|
3421
|
+
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 } : {}) };
|
|
3421
3422
|
},
|
|
3422
|
-
initializeStreams: (server, space, setup, seedFile, recreateIssuedStores, recreateMembershipStore) => postStart(server, space, setup, seedFile, recreateIssuedStores, recreateMembershipStore, true),
|
|
3423
|
+
initializeStreams: async (server, space, setup, seedFile, recreateIssuedStores, recreateMembershipStore) => postStart(server, space, setup && { creds: await setup.mintProvisioner() }, seedFile, recreateIssuedStores, recreateMembershipStore, true),
|
|
3423
3424
|
recreateDeletedStreams: ({ seed, ...opts }) => recreateDeletedStreams({ ...opts, ...(seed !== undefined ? { seed: seed } : {}) }),
|
|
3424
3425
|
recordMesh: (entry) => recordOurMesh({ ...entry, ts: new Date().toISOString() }, "started", true),
|
|
3425
3426
|
commitTransport: (root, chosen, limits) => commitTransportPolicy(root, chosen, true, undefined, limits),
|
|
@@ -4116,8 +4117,9 @@ export async function startMeshDetached(
|
|
|
4116
4117
|
// The `= {}` default is gone with the optional transport: an options object that can be omitted
|
|
4117
4118
|
// entirely cannot carry a mandatory decision.
|
|
4118
4119
|
opts) {
|
|
4119
|
-
const { server, space, useAuth, storeDir, seedFile, transport, setup, maxPayload, args, bin, source, version } = await prepareBrokerStart(opts);
|
|
4120
|
+
const { server, space, useAuth, storeDir, seedFile, transport, setup: brokerSetup, maxPayload, args, bin, source, version } = await prepareBrokerStart(opts);
|
|
4120
4121
|
await seedBeforeLaunch();
|
|
4122
|
+
const setup = brokerSetup && { ...brokerSetup, creds: await brokerSetup.mintProvisioner() };
|
|
4121
4123
|
const logPath = cotalPath("nats.log");
|
|
4122
4124
|
const fd = openBrokerLog(logPath);
|
|
4123
4125
|
const listenerStartedAt = new Date().toISOString();
|
|
@@ -4475,8 +4477,9 @@ function recordOurMesh(m, provenance, quietBoot = false) {
|
|
|
4475
4477
|
if (pin.kind === "match")
|
|
4476
4478
|
nativeMembers.push({ role, process: pin.record });
|
|
4477
4479
|
}
|
|
4478
|
-
const
|
|
4479
|
-
|
|
4480
|
+
const nativeHost = nativeMembers.length ? knownStackRecoveryHost() : undefined;
|
|
4481
|
+
const recorded = { ...m, origin, ...(nativeHost !== undefined ? { nativeMembers, nativeHost } : {}) };
|
|
4482
|
+
recordMesh(provenance === "refresh" ? { ...prior, ...recorded, stoppedByDown: undefined } : recorded);
|
|
4480
4483
|
removePreparedSpace(m.space); // started: the registration is its record now
|
|
4481
4484
|
if (!usableCurrent) {
|
|
4482
4485
|
setAdoptedCurrent(m.space);
|
|
@@ -5015,10 +5018,7 @@ function authTimeoutArgs(seconds) {
|
|
|
5015
5018
|
function loadChannelsFile(explicit) {
|
|
5016
5019
|
if (explicit)
|
|
5017
5020
|
return readChannelsFile(resolve(explicit));
|
|
5018
|
-
|
|
5019
|
-
if (!existsSync(path))
|
|
5020
|
-
return undefined;
|
|
5021
|
-
return readChannelsFile(path, false);
|
|
5021
|
+
return readDefaultChannelsFile(cotalRoot());
|
|
5022
5022
|
}
|
|
5023
5023
|
/** Refuse `up --space` of a space this machine started from another folder while its broker answers,
|
|
5024
5024
|
* naming that folder: the stack there is the one to use or stop. */
|
|
@@ -5049,98 +5049,6 @@ async function refuseRecordsElsewhere(root) {
|
|
|
5049
5049
|
remedy: takeover ? `${records.stackRemedy}; or, to run it from this folder, take the name over with \`cotal up --space ${space}\`` : records.stackRemedy,
|
|
5050
5050
|
});
|
|
5051
5051
|
}
|
|
5052
|
-
/** The channels files one `up` has read, by path. It reads its seed when it checks the flags, when it
|
|
5053
|
-
* prepares the broker and when it seeds the registry, and `--channels` may name a pipe or a FIFO,
|
|
5054
|
-
* which a second open finds empty or waits on for a writer that is gone. */
|
|
5055
|
-
const channelsReads = new AsyncLocalStorage();
|
|
5056
|
-
/** Read, parse and check a channels file: `explicit` is a `--channels` path, else the root's default
|
|
5057
|
-
* `.cotal/channels.json`. A `--channels` path that is missing, unreadable or not JSON is a usage
|
|
5058
|
-
* refusal. A default file that is not JSON, and either file whose content the registry would not
|
|
5059
|
-
* take, is a schema refusal. Each names the file. */
|
|
5060
|
-
function readChannelsFile(path, explicit = true) {
|
|
5061
|
-
const read = channelsReads.getStore()?.get(path);
|
|
5062
|
-
if (read)
|
|
5063
|
-
return read;
|
|
5064
|
-
const remedy = explicit ? "fix the file, or omit --channels" : `fix or remove ${path}`;
|
|
5065
|
-
let text;
|
|
5066
|
-
// A default file that is a FIFO or a device would block the read with no writer, so only a regular
|
|
5067
|
-
// default file is opened. An explicit path may name a pipe such as `<(…)`, read once (see `channelsReads`).
|
|
5068
|
-
if (!explicit && statSync(path, { throwIfNoEntry: false })?.isFile() === false)
|
|
5069
|
-
throw new CommandFailure("refused", "USAGE_INVALID", `the channels file ${path} is not a regular file, such as a FIFO; it was not read`, { remedy });
|
|
5070
|
-
try {
|
|
5071
|
-
text = readFileSync(path, "utf8");
|
|
5072
|
-
}
|
|
5073
|
-
catch {
|
|
5074
|
-
throw new CommandFailure("refused", "USAGE_INVALID", `the channels file ${path} is missing or unreadable`, { remedy: explicit ? "name an existing channels file with --channels <path>, or omit --channels" : remedy });
|
|
5075
|
-
}
|
|
5076
|
-
const encoding = utf16Problem(text);
|
|
5077
|
-
if (encoding)
|
|
5078
|
-
throw new CommandFailure("refused", "USAGE_INVALID", `the channels file ${path} cannot be read: ${encoding}`, { remedy: `save ${path} as UTF-8` });
|
|
5079
|
-
let value;
|
|
5080
|
-
// An editor on Windows can begin the file with a UTF-8 byte-order mark, which RFC 8259 lets a
|
|
5081
|
-
// reader ignore.
|
|
5082
|
-
try {
|
|
5083
|
-
value = JSON.parse(text.replace(/^\uFEFF/, ""));
|
|
5084
|
-
}
|
|
5085
|
-
catch (error) {
|
|
5086
|
-
throw new CommandFailure("refused", "USAGE_INVALID", `the channels file ${path} is not valid JSON (${error.message})`, { remedy });
|
|
5087
|
-
}
|
|
5088
|
-
const problem = channelsFileProblem(value);
|
|
5089
|
-
if (problem)
|
|
5090
|
-
throw new CommandFailure("refused", "SCHEMA_INVALID", `the channels file ${path} is invalid: ${problem}`, { remedy });
|
|
5091
|
-
channelsReads.getStore()?.set(path, value);
|
|
5092
|
-
return value;
|
|
5093
|
-
}
|
|
5094
|
-
const CHANNEL_DEFAULT_FIELDS = { replay: true, replayWindow: true, deliveryClass: true };
|
|
5095
|
-
const CHANNEL_FIELDS = { ...CHANNEL_DEFAULT_FIELDS, description: true, instructions: true };
|
|
5096
|
-
/** Why the registry would not take this seed: the shape, an unknown key, a channel name `channel set`
|
|
5097
|
-
* refuses, or a field value the registry's write checks refuse. Undefined when every entry passes. */
|
|
5098
|
-
function channelsFileProblem(value) {
|
|
5099
|
-
const isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
5100
|
-
const fieldsProblem = (where, entry, fields, check) => {
|
|
5101
|
-
if (!isObject(entry))
|
|
5102
|
-
return `${where} must be an object`;
|
|
5103
|
-
for (const [field, fieldValue] of Object.entries(entry)) {
|
|
5104
|
-
if (!Object.hasOwn(fields, field))
|
|
5105
|
-
return `${where} has an unknown key ${JSON.stringify(field)}; it takes ${Object.keys(fields).join(", ")}`;
|
|
5106
|
-
try {
|
|
5107
|
-
check({ [field]: fieldValue });
|
|
5108
|
-
}
|
|
5109
|
-
catch (error) {
|
|
5110
|
-
return `${where} ${field}: ${error.message}`;
|
|
5111
|
-
}
|
|
5112
|
-
}
|
|
5113
|
-
return undefined;
|
|
5114
|
-
};
|
|
5115
|
-
if (!isObject(value))
|
|
5116
|
-
return 'it must be a JSON object with "defaults" and "channels"';
|
|
5117
|
-
for (const key of Object.keys(value))
|
|
5118
|
-
if (key !== "defaults" && key !== "channels")
|
|
5119
|
-
return `unknown key ${JSON.stringify(key)}; the file takes "defaults" and "channels"`;
|
|
5120
|
-
if (value.defaults !== undefined) {
|
|
5121
|
-
const problem = fieldsProblem('"defaults"', value.defaults, CHANNEL_DEFAULT_FIELDS, validateChannelDefaults);
|
|
5122
|
-
if (problem)
|
|
5123
|
-
return problem;
|
|
5124
|
-
}
|
|
5125
|
-
if (value.channels === undefined)
|
|
5126
|
-
return undefined;
|
|
5127
|
-
if (!isObject(value.channels))
|
|
5128
|
-
return '"channels" must be an object of channel names';
|
|
5129
|
-
for (const [name, config] of Object.entries(value.channels)) {
|
|
5130
|
-
try {
|
|
5131
|
-
assertValidChannel(name);
|
|
5132
|
-
}
|
|
5133
|
-
catch (error) {
|
|
5134
|
-
return error.message;
|
|
5135
|
-
}
|
|
5136
|
-
if (!isConcreteChannel(name))
|
|
5137
|
-
return `channel ${JSON.stringify(name)} is a wildcard; name one concrete channel`;
|
|
5138
|
-
const problem = fieldsProblem(`channel ${JSON.stringify(name)}`, config, CHANNEL_FIELDS, validateChannelConfig);
|
|
5139
|
-
if (problem)
|
|
5140
|
-
return problem;
|
|
5141
|
-
}
|
|
5142
|
-
return undefined;
|
|
5143
|
-
}
|
|
5144
5052
|
/**
|
|
5145
5053
|
* Turn the `--tls-cert`/`--tls-key` pair into a validated {@link BrokerTransport}, or `plaintext`
|
|
5146
5054
|
* when neither was given.
|
|
@@ -5451,8 +5359,8 @@ function unreadableTrust(error) {
|
|
|
5451
5359
|
target: { path }, remedy: `make it readable by you again, as chmod 600 ${shellWord(path)} does, then run \`cotal up\` again; it holds the space's keys, so keep it`,
|
|
5452
5360
|
});
|
|
5453
5361
|
}
|
|
5454
|
-
/** Ensure the space's trust material exists
|
|
5455
|
-
* setup
|
|
5362
|
+
/** Ensure the space's trust material exists and render a server config. The caller can mint
|
|
5363
|
+
* the setup credential after connector reconciliation. The account signing key
|
|
5456
5364
|
* in `.cotal/auth` is what `cotal mint` and the manager later use to issue per-agent creds.
|
|
5457
5365
|
*
|
|
5458
5366
|
* USER MODE (`user` set): additionally run the registered auth provider's `prepareServer` over the
|
|
@@ -5616,11 +5524,10 @@ requested = {}) {
|
|
|
5616
5524
|
// takes it first, the broker exits before readiness, and a controller stack start renders this
|
|
5617
5525
|
// configuration again on a newly chosen port.
|
|
5618
5526
|
const moveWebsocketPort = async () => { const moved = await freePort(host); render(moved); return moved; };
|
|
5619
|
-
//
|
|
5620
|
-
//
|
|
5621
|
-
|
|
5622
|
-
|
|
5623
|
-
return { brokerBinary, confPath, creds, wsPort, moveWebsocketPort, ...(prepared ? { prepared, stateDir } : {}), ...(authTimeout !== undefined ? { authTimeout } : {}), ...(maxPayload !== undefined ? { maxPayload } : {}), accountResolver: resolverChoice };
|
|
5527
|
+
// Connector reconciliation can outlast the provisioner's lifetime. Mint only when boot needs it
|
|
5528
|
+
// to probe the listener, create streams and buckets, or seed the channel registry.
|
|
5529
|
+
const mintProvisioner = () => mintCreds(auth, newIdentity(), "provisioner");
|
|
5530
|
+
return { brokerBinary, confPath, mintProvisioner, wsPort, moveWebsocketPort, ...(prepared ? { prepared, stateDir } : {}), ...(authTimeout !== undefined ? { authTimeout } : {}), ...(maxPayload !== undefined ? { maxPayload } : {}), accountResolver: resolverChoice };
|
|
5624
5531
|
}
|
|
5625
5532
|
/**
|
|
5626
5533
|
* Refuse the rotation if this root's own bookkeeping still shows a broker running. This is a
|