@cotal-ai/cli 0.174.2 → 0.174.4
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 +62 -25
- package/dist/command.js.map +1 -1
- package/dist/commands/agents.d.ts +7 -1
- package/dist/commands/agents.d.ts.map +1 -1
- package/dist/commands/agents.js +38 -17
- package/dist/commands/agents.js.map +1 -1
- package/dist/commands/backup.js +11 -3
- package/dist/commands/backup.js.map +1 -1
- package/dist/commands/channel-members.d.ts.map +1 -1
- package/dist/commands/channel-members.js +9 -7
- package/dist/commands/channel-members.js.map +1 -1
- package/dist/commands/channels.d.ts.map +1 -1
- package/dist/commands/channels.js +16 -7
- package/dist/commands/channels.js.map +1 -1
- package/dist/commands/chat.js +1 -1
- package/dist/commands/chat.js.map +1 -1
- package/dist/commands/clean.d.ts.map +1 -1
- package/dist/commands/clean.js +12 -3
- package/dist/commands/clean.js.map +1 -1
- package/dist/commands/config.d.ts.map +1 -1
- package/dist/commands/config.js +8 -1
- package/dist/commands/config.js.map +1 -1
- package/dist/commands/console.d.ts +3 -4
- package/dist/commands/console.d.ts.map +1 -1
- package/dist/commands/console.js +12 -15
- package/dist/commands/console.js.map +1 -1
- package/dist/commands/describe.d.ts.map +1 -1
- package/dist/commands/describe.js +11 -1
- package/dist/commands/describe.js.map +1 -1
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +21 -9
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/down-preserve.d.ts.map +1 -1
- package/dist/commands/down-preserve.js +2 -1
- package/dist/commands/down-preserve.js.map +1 -1
- package/dist/commands/down.d.ts.map +1 -1
- package/dist/commands/down.js +2 -1
- package/dist/commands/down.js.map +1 -1
- package/dist/commands/endpoint-authoring.d.ts.map +1 -1
- package/dist/commands/endpoint-authoring.js +20 -19
- package/dist/commands/endpoint-authoring.js.map +1 -1
- package/dist/commands/endpoint.d.ts.map +1 -1
- package/dist/commands/endpoint.js +7 -2
- package/dist/commands/endpoint.js.map +1 -1
- package/dist/commands/endpoints.d.ts.map +1 -1
- package/dist/commands/endpoints.js +12 -5
- package/dist/commands/endpoints.js.map +1 -1
- package/dist/commands/ext.d.ts +2 -6
- package/dist/commands/ext.d.ts.map +1 -1
- package/dist/commands/ext.js +19 -25
- package/dist/commands/ext.js.map +1 -1
- package/dist/commands/history-clear.d.ts.map +1 -1
- package/dist/commands/history-clear.js +5 -2
- package/dist/commands/history-clear.js.map +1 -1
- package/dist/commands/history.d.ts.map +1 -1
- package/dist/commands/history.js +21 -10
- package/dist/commands/history.js.map +1 -1
- package/dist/commands/join.d.ts.map +1 -1
- package/dist/commands/join.js +37 -21
- package/dist/commands/join.js.map +1 -1
- package/dist/commands/meshes-add.d.ts.map +1 -1
- package/dist/commands/meshes-add.js +3 -2
- package/dist/commands/meshes-add.js.map +1 -1
- package/dist/commands/meshes.d.ts.map +1 -1
- package/dist/commands/meshes.js +17 -4
- package/dist/commands/meshes.js.map +1 -1
- package/dist/commands/mint.d.ts.map +1 -1
- package/dist/commands/mint.js +5 -2
- package/dist/commands/mint.js.map +1 -1
- package/dist/commands/models.d.ts.map +1 -1
- package/dist/commands/models.js +9 -3
- package/dist/commands/models.js.map +1 -1
- package/dist/commands/persona-remote.d.ts.map +1 -1
- package/dist/commands/persona-remote.js +8 -4
- package/dist/commands/persona-remote.js.map +1 -1
- package/dist/commands/persona.d.ts.map +1 -1
- package/dist/commands/persona.js +40 -27
- package/dist/commands/persona.js.map +1 -1
- package/dist/commands/personas.js +4 -8
- package/dist/commands/personas.js.map +1 -1
- package/dist/commands/revoke-credential.d.ts.map +1 -1
- package/dist/commands/revoke-credential.js +5 -2
- package/dist/commands/revoke-credential.js.map +1 -1
- package/dist/commands/send.d.ts.map +1 -1
- package/dist/commands/send.js +1 -8
- package/dist/commands/send.js.map +1 -1
- package/dist/commands/service-actions.d.ts.map +1 -1
- package/dist/commands/service-actions.js +14 -6
- 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 +4 -2
- package/dist/commands/service-registry.js.map +1 -1
- package/dist/commands/setup.d.ts.map +1 -1
- package/dist/commands/setup.js +21 -8
- package/dist/commands/setup.js.map +1 -1
- package/dist/commands/space-delete.d.ts.map +1 -1
- package/dist/commands/space-delete.js +17 -10
- package/dist/commands/space-delete.js.map +1 -1
- package/dist/commands/space-registration.d.ts.map +1 -1
- package/dist/commands/space-registration.js +11 -9
- package/dist/commands/space-registration.js.map +1 -1
- package/dist/commands/space.d.ts.map +1 -1
- package/dist/commands/space.js +39 -9
- package/dist/commands/space.js.map +1 -1
- package/dist/commands/spawn-flags.d.ts +5 -7
- package/dist/commands/spawn-flags.d.ts.map +1 -1
- package/dist/commands/spawn-flags.js +42 -6
- package/dist/commands/spawn-flags.js.map +1 -1
- package/dist/commands/spawn-managed-launch.js +2 -2
- package/dist/commands/spawn-managed-launch.js.map +1 -1
- package/dist/commands/spawn-preview.d.ts.map +1 -1
- package/dist/commands/spawn-preview.js +5 -3
- package/dist/commands/spawn-preview.js.map +1 -1
- package/dist/commands/spawn.d.ts.map +1 -1
- package/dist/commands/spawn.js +9 -2
- package/dist/commands/spawn.js.map +1 -1
- package/dist/commands/stack-up.d.ts.map +1 -1
- package/dist/commands/stack-up.js +47 -19
- package/dist/commands/stack-up.js.map +1 -1
- package/dist/commands/status-health.d.ts +139 -0
- package/dist/commands/status-health.d.ts.map +1 -0
- package/dist/commands/status-health.js +651 -0
- package/dist/commands/status-health.js.map +1 -0
- package/dist/commands/status-meshes.d.ts +26 -0
- package/dist/commands/status-meshes.d.ts.map +1 -0
- package/dist/commands/status-meshes.js +468 -0
- package/dist/commands/status-meshes.js.map +1 -0
- package/dist/commands/status-render.d.ts +30 -0
- package/dist/commands/status-render.d.ts.map +1 -0
- package/dist/commands/status-render.js +782 -0
- package/dist/commands/status-render.js.map +1 -0
- package/dist/commands/status.d.ts +2 -16
- package/dist/commands/status.d.ts.map +1 -1
- package/dist/commands/status.js +21 -1878
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/topology.d.ts.map +1 -1
- package/dist/commands/topology.js +4 -0
- package/dist/commands/topology.js.map +1 -1
- package/dist/commands/up-host.d.ts +19 -0
- package/dist/commands/up-host.d.ts.map +1 -0
- package/dist/commands/up-host.js +105 -0
- package/dist/commands/up-host.js.map +1 -0
- package/dist/commands/up-stores.d.ts +42 -0
- package/dist/commands/up-stores.d.ts.map +1 -0
- package/dist/commands/up-stores.js +242 -0
- package/dist/commands/up-stores.js.map +1 -0
- package/dist/commands/up-target.d.ts +2 -0
- package/dist/commands/up-target.d.ts.map +1 -1
- package/dist/commands/up-target.js +9 -0
- package/dist/commands/up-target.js.map +1 -1
- package/dist/commands/up-transport.d.ts +2 -0
- package/dist/commands/up-transport.d.ts.map +1 -1
- package/dist/commands/up-transport.js +6 -1
- package/dist/commands/up-transport.js.map +1 -1
- package/dist/commands/up.d.ts.map +1 -1
- package/dist/commands/up.js +62 -407
- package/dist/commands/up.js.map +1 -1
- package/dist/commands/update-caches.d.ts +1 -2
- package/dist/commands/update-caches.d.ts.map +1 -1
- package/dist/commands/update-caches.js +21 -8
- package/dist/commands/update-caches.js.map +1 -1
- package/dist/commands/update-process.d.ts.map +1 -1
- package/dist/commands/update-process.js +10 -5
- package/dist/commands/update-process.js.map +1 -1
- package/dist/commands/update.js +2 -2
- package/dist/commands/update.js.map +1 -1
- package/dist/commands/use.js +2 -2
- package/dist/commands/use.js.map +1 -1
- package/dist/commands/watch.d.ts +8 -0
- package/dist/commands/watch.d.ts.map +1 -1
- package/dist/commands/watch.js +10 -4
- package/dist/commands/watch.js.map +1 -1
- package/dist/commands/who.js +3 -3
- package/dist/commands/who.js.map +1 -1
- package/dist/console/app.js +5 -5
- package/dist/console/app.js.map +1 -1
- package/dist/console/commands.d.ts +1 -1
- package/dist/console/commands.d.ts.map +1 -1
- package/dist/console/commands.js +1 -1
- package/dist/console/commands.js.map +1 -1
- package/dist/console/ui/Feed.d.ts +2 -2
- package/dist/console/ui/Feed.d.ts.map +1 -1
- package/dist/console/ui/Feed.js +2 -2
- package/dist/console/ui/Feed.js.map +1 -1
- package/dist/console/ui/StatusBar.d.ts +1 -1
- package/dist/console/ui/StatusBar.d.ts.map +1 -1
- package/dist/console/ui/StatusBar.js +1 -1
- package/dist/console/ui/StatusBar.js.map +1 -1
- package/dist/console/ui/Tabs.d.ts +2 -2
- package/dist/console/ui/Tabs.d.ts.map +1 -1
- package/dist/console/ui/Tabs.js +4 -4
- package/dist/console/ui/Tabs.js.map +1 -1
- package/dist/help.d.ts +1 -1
- package/dist/help.d.ts.map +1 -1
- package/dist/help.js +3 -1
- package/dist/help.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/backup-artifact.d.ts.map +1 -1
- package/dist/lib/backup-artifact.js +19 -7
- package/dist/lib/backup-artifact.js.map +1 -1
- package/dist/lib/broker-service.d.ts +8 -0
- package/dist/lib/broker-service.d.ts.map +1 -1
- package/dist/lib/broker-service.js +18 -2
- package/dist/lib/broker-service.js.map +1 -1
- package/dist/lib/choose-target.d.ts +1 -1
- package/dist/lib/choose-target.d.ts.map +1 -1
- package/dist/lib/choose-target.js +11 -5
- package/dist/lib/choose-target.js.map +1 -1
- package/dist/lib/completion-install.d.ts.map +1 -1
- package/dist/lib/completion-install.js +12 -10
- package/dist/lib/completion-install.js.map +1 -1
- package/dist/lib/control.d.ts +8 -2
- package/dist/lib/control.d.ts.map +1 -1
- package/dist/lib/control.js +11 -4
- package/dist/lib/control.js.map +1 -1
- package/dist/lib/endpoint-selection.d.ts.map +1 -1
- package/dist/lib/endpoint-selection.js +2 -5
- package/dist/lib/endpoint-selection.js.map +1 -1
- package/dist/lib/foreground-hold.d.ts.map +1 -1
- package/dist/lib/foreground-hold.js +2 -1
- package/dist/lib/foreground-hold.js.map +1 -1
- package/dist/lib/manager-choice.d.ts +2 -1
- package/dist/lib/manager-choice.d.ts.map +1 -1
- package/dist/lib/manager-choice.js +2 -2
- package/dist/lib/manager-choice.js.map +1 -1
- package/dist/lib/manifest/index.d.ts +1 -1
- package/dist/lib/manifest/index.d.ts.map +1 -1
- package/dist/lib/manifest/index.js +2 -2
- package/dist/lib/manifest/index.js.map +1 -1
- package/dist/lib/manifest/resolve.d.ts +1 -1
- package/dist/lib/manifest/resolve.d.ts.map +1 -1
- package/dist/lib/manifest/resolve.js +4 -4
- package/dist/lib/manifest/resolve.js.map +1 -1
- package/dist/lib/npm-invocation.d.ts +6 -0
- package/dist/lib/npm-invocation.d.ts.map +1 -0
- package/dist/lib/npm-invocation.js +18 -0
- package/dist/lib/npm-invocation.js.map +1 -0
- package/dist/lib/persona-files.d.ts +3 -2
- package/dist/lib/persona-files.d.ts.map +1 -1
- package/dist/lib/persona-files.js +14 -7
- package/dist/lib/persona-files.js.map +1 -1
- package/dist/lib/personas.d.ts +1 -2
- package/dist/lib/personas.d.ts.map +1 -1
- package/dist/lib/personas.js +12 -3
- package/dist/lib/personas.js.map +1 -1
- package/dist/lib/private-directory.d.ts +3 -3
- package/dist/lib/private-directory.d.ts.map +1 -1
- package/dist/lib/private-directory.js +17 -7
- package/dist/lib/private-directory.js.map +1 -1
- package/dist/lib/service-preset-target.d.ts.map +1 -1
- package/dist/lib/service-preset-target.js +4 -3
- package/dist/lib/service-preset-target.js.map +1 -1
- package/dist/lib/service-presets.d.ts +1 -1
- package/dist/lib/service-presets.d.ts.map +1 -1
- package/dist/lib/service-presets.js +19 -4
- package/dist/lib/service-presets.js.map +1 -1
- package/dist/lib/stack-journal.d.ts.map +1 -1
- package/dist/lib/stack-journal.js +7 -4
- package/dist/lib/stack-journal.js.map +1 -1
- package/dist/lib/stdout-owner.d.ts +4 -4
- package/dist/lib/stdout-owner.d.ts.map +1 -1
- package/dist/lib/stdout-owner.js +12 -10
- package/dist/lib/stdout-owner.js.map +1 -1
- package/dist/lib/update-recovery-state.d.ts +1 -1
- package/dist/lib/update-recovery-state.d.ts.map +1 -1
- package/dist/lib/update-recovery-state.js +18 -9
- package/dist/lib/update-recovery-state.js.map +1 -1
- package/dist/telemetry.d.ts.map +1 -1
- package/dist/telemetry.js +5 -3
- package/dist/telemetry.js.map +1 -1
- package/package.json +4 -4
package/dist/commands/up.js
CHANGED
|
@@ -4,14 +4,13 @@ import {} from "node:child_process";
|
|
|
4
4
|
import { openBrokerLog, prepareForegroundBrokerLog } from "../lib/broker-log.js";
|
|
5
5
|
import { spawnBroker } from "../lib/broker-spawn.js";
|
|
6
6
|
import { randomUUID } from "node:crypto";
|
|
7
|
-
import { createConnection,
|
|
7
|
+
import { createConnection, isIP } from "node:net";
|
|
8
8
|
import { homedir, hostname } from "node:os";
|
|
9
9
|
import { accessSync, constants, mkdirSync, readFileSync, existsSync, statSync, closeSync, lstatSync, realpathSync, readdirSync, rmdirSync, } from "node:fs";
|
|
10
10
|
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, credsProblem, mintCreds, mintLifecycleUid, DEV_OWNER, mintConnectionEvictorCreds, mintMembershipObserverCreds, newIdentity,
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import { assertManagerName, processStopped, readManagerName, readManagerSeatCap, recordManagerName, parseSeatCapFlag, seatCapText, CommandFailure, codeSpan, commandFailureReport, failureEnvelope, writeEnvelope, isCommandFailure, protectedLocalDirectory, jsonFlag, plainFlag, renderReport, assertSingleSpaceBroker, assertUserAuthInfo, authDir, brokerAddressForDisplay, 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, brokerAccountResolver, removePidPair, writePidPair, verifyIdentityPin, processesNaming, isLoopbackHost, connectUserControlOrThrow, userViewAuth, recordOperationSpace, 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";
|
|
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, credsProblem, mintCreds, mintLifecycleUid, DEV_OWNER, mintConnectionEvictorCreds, mintMembershipObserverCreds, newIdentity, reconcileSpaceMemoryBuckets, standaloneConnectOpts, requireBrokerFloor, parseServerVersion, presenceBucket, LEASE_TTL_MS, EpEnvelopeError, mkSecretDir, writeSecretFile, } from "@cotal-ai/core";
|
|
12
|
+
import { jetstreamManager, StorageType } from "@nats-io/jetstream";
|
|
13
|
+
import { assertManagerName, processStopped, readManagerName, readManagerSeatCap, DEFAULT_SEAT_CAP, recordManagerName, parseSeatCapFlag, seatCapText, CommandFailure, codeSpan, commandFailureReport, failureEnvelope, writeEnvelope, isCommandFailure, protectedLocalDirectory, jsonFlag, plainFlag, renderReport, assertSingleSpaceBroker, assertUserAuthInfo, authDir, brokerAddressForDisplay, 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, brokerAccountResolver, removePidPair, writePidPair, verifyIdentityPin, processesNaming, isLoopbackHost, connectUserControlOrThrow, userViewAuth, recordOperationSpace, 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";
|
|
15
14
|
import { FlagValueRefusal } from "../lib/flag-value-refusal.js";
|
|
16
15
|
import { ensureAuthService, resolveAuthProvider, stopAuthService } from "../lib/auth-proc.js";
|
|
17
16
|
import { resolveSpace } from "../lib/status.js";
|
|
@@ -43,7 +42,7 @@ import { failManifest, refuseManifestSpaceMismatch } from "./topology.js";
|
|
|
43
42
|
import { liveMeshProcesses } from "./clean.js";
|
|
44
43
|
import { checkSpaceFlagValue, checkSpaceName } from "./meshes-add.js";
|
|
45
44
|
import { checkLocalSpace } from "./space-registration.js";
|
|
46
|
-
import { checkNewUpSpace, preparedUpRoot } from "./up-target.js";
|
|
45
|
+
import { checkNewUpSpace, checkPublicExchangePort, preparedUpRoot } from "./up-target.js";
|
|
47
46
|
import { cleanedManifestStart, interruptedStartBroker, namedOpenConfig, retainedOpenSpace } from "../lib/legacy-start.js";
|
|
48
47
|
import { bindReaches, canonicalServer, controllerStackApplies, recheckExistingStore, requestedStackMode, refuseForegroundStackHolder, requestsTls, stackUp, stackUpForegroundNotice, stackUpInterrupted, keptOnUp, selectedOnUp, unparsableDaemonCredsNotice, } from "./stack-up.js";
|
|
49
48
|
import { exitInterrupted, handOverStartupNotice, noticeOnInterrupt, releaseStartupNotice } from "../lib/interrupt-notice.js";
|
|
@@ -68,12 +67,14 @@ import { metadataPositionals } from "../lib/command-path.js";
|
|
|
68
67
|
import { bindPreparedRestoreListener, isManagerCommitResult, isManagerFinalizeResult, isManagerCommittedRestore, markPreparedRestoreActive, markPreparedRestoreDegraded, heldRestoreAttempt, heldClaim, movedFolderRefusal, prepareRestore, restoreArtifactPath, restoreLaunch, preservedSourceState, recordPreparedRestoreManagerCommit, rehydratePreparedRestore, journaledMaxFileStore, journaledRestoredStreams, leftOutNotes, rearmUnboundRestore, replacePreparedDeadRestoreListener, restoreComposition, restoreInterruptNotice, restoreNextStep, restoreOnlyCopy, } from "../lib/restore.js";
|
|
69
68
|
import { attemptProcessesGone } from "../lib/isolated-broker.js";
|
|
70
69
|
import { assertEndpointUnreachable } from "../lib/endpoint-cut.js";
|
|
71
|
-
import {
|
|
70
|
+
import { brokerAddressConflict } from "../lib/broker-service.js";
|
|
72
71
|
import { freePort, freshStackServer, retryStackAddress, serverWithFreePort } from "../lib/up-broker-address.js";
|
|
73
72
|
import { askManager } from "@cotal-ai/workspace/control";
|
|
74
73
|
import { cliControl } from "../lib/control.js";
|
|
75
74
|
import { pendingRestores, pendingOrdinaryResumes } from "./up-pending.js";
|
|
76
|
-
import { parseMaxFileStore, parseAuthTimeout, parseMaxPayload, parseAccountResolver, authTimeoutArgs, loadChannelsFile, refuseRunningElsewhere, refuseRecordsElsewhere, resolveTransport, assertTlsIntentServed, assertTlsAddressServed, commitTransportPolicy, tlsAddress, announceTransport, liveListenerRequiresTls, assertServesDialHost, adoptedTlsRequired, refuseUnnamedLastStore, reopenLastStore, refuseMissingNamedStore, checkStartStore, } from "./up-transport.js";
|
|
75
|
+
import { parseMaxFileStore, parseAuthTimeout, parseMaxPayload, assertManagerPayload, parseAccountResolver, authTimeoutArgs, loadChannelsFile, refuseRunningElsewhere, refuseRecordsElsewhere, resolveTransport, assertTlsIntentServed, assertTlsAddressServed, commitTransportPolicy, tlsAddress, announceTransport, liveListenerRequiresTls, assertServesDialHost, adoptedTlsRequired, refuseUnnamedLastStore, reopenLastStore, refuseMissingNamedStore, checkStartStore, } from "./up-transport.js";
|
|
76
|
+
import { WILDCARD_HOSTS, reconcileHostAndServer, assertFreshTeamBindAvailable } from "./up-host.js";
|
|
77
|
+
import { registeredAddressHolder, refuseRegisteredAddress, membershipConversionRefusal, fileMembershipStore, postStart, recreateMemoryBuckets, recreateAdoptedMemoryBuckets, recreateDeletedStreams, } from "./up-stores.js";
|
|
77
78
|
const restoreSinks = new Map();
|
|
78
79
|
/** Run the guarded `up --restore` startup and return its result instead of printing it. The
|
|
79
80
|
* restore inputs and fences are exactly `up --restore`'s; this adds no route, flag or authority. */
|
|
@@ -110,12 +111,12 @@ export const upFlags = [
|
|
|
110
111
|
{ name: "open", type: "boolean", description: "unauthenticated dev mesh (no JWT/ACLs)" },
|
|
111
112
|
{ name: "user-auth", type: "boolean", description: "per-USER auth: login + bearer through the space's auth service" },
|
|
112
113
|
{ name: "idp", type: "string", value: "<url>", description: "with --user-auth: the IdP auth base URL to pin (first enable)" },
|
|
113
|
-
{ name: "exchange-public-port", type: "string", value: "<n>", description: "
|
|
114
|
-
{ name: "exchange-public-url", type: "string", value: "<https://…>", description: "with --exchange-public-port:
|
|
115
|
-
{ name: "exchange-trusted-proxy", type: "boolean", description: "with --exchange-public-port: attribute peers by the last X-Forwarded-For hop (
|
|
116
|
-
{ name: "advertised-server", type: "string", value: "<url>", description: "with --exchange-public-port:
|
|
114
|
+
{ name: "exchange-public-port", type: "string", value: "<n>", description: "legacy user-auth startup only: public loopback port (0 to 65535) for an HTTPS reverse proxy" },
|
|
115
|
+
{ name: "exchange-public-url", type: "string", value: "<https://…>", description: "legacy user-auth startup only, with --exchange-public-port: advertise the reverse proxy's HTTPS URL" },
|
|
116
|
+
{ name: "exchange-trusted-proxy", type: "boolean", description: "legacy user-auth startup only, with --exchange-public-port: attribute peers by the last X-Forwarded-For hop (default: socket address)" },
|
|
117
|
+
{ name: "advertised-server", type: "string", value: "<url>", description: "legacy user-auth startup only, with --exchange-public-port: broker address to advertise (default: --server)" },
|
|
117
118
|
{ name: "service-endpoints", type: "boolean", description: "with --user-auth: the auth service also hosts service endpoints (the registration door and the owner-decision host route)" },
|
|
118
|
-
{ name: "agent-provisioning-url", type: "string", value: "<https://…>", description: "with --exchange-public-port:
|
|
119
|
+
{ name: "agent-provisioning-url", type: "string", value: "<https://…>", description: "legacy user-auth startup only, with --exchange-public-port: agent-provisioning endpoint to advertise" },
|
|
119
120
|
{ name: "rotate-sys", type: "boolean", description: "renew the expired/expiring $SYS creds by rotating the system account (agents, data and creds survive; needs a stopped mesh)" },
|
|
120
121
|
{ name: "recreate-membership-store", type: "boolean", description: "replace a stopped space's legacy File-backed derived membership feed with the current Memory-backed store" },
|
|
121
122
|
{ name: "recreate-issued-stores", type: "string", value: "<backup-dir>", description: "back up this space's issued-authority stores created before 0.111.0 into a new <backup-dir>, delete them and create them again (needs a stopped stack and every other issuer of the space stopped)" },
|
|
@@ -175,6 +176,8 @@ export function validateUpArguments(args) {
|
|
|
175
176
|
publicExchangeArgs(args.values, false);
|
|
176
177
|
serviceEndpointsArgs(args.values, false);
|
|
177
178
|
}
|
|
179
|
+
else if (typeof args.values["exchange-public-port"] === "string")
|
|
180
|
+
checkPublicExchangePort(args.values["exchange-public-port"]);
|
|
178
181
|
if (args.values.idp !== undefined && args.values["user-auth"] !== true && !args.values.file)
|
|
179
182
|
throw new CommandFailure("refused", "USAGE_INVALID", '--idp is for user-auth spaces; pair it with --user-auth, or set broker.auth: "user" in a manifest', { remedy: "use --user-auth --idp <auth base URL>, without --open" });
|
|
180
183
|
if (args.values.restore !== undefined && args.values["no-manager"] === true)
|
|
@@ -255,11 +258,8 @@ export function validateUpArguments(args) {
|
|
|
255
258
|
// anything starts and a broker that comes up without its auth plane.
|
|
256
259
|
if (args.values["service-endpoints"] === true && requestedPayload < SERVICE_CALLER_PAYLOAD_FLOOR)
|
|
257
260
|
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` });
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
// start does not publish them, so it keeps the positive-integer check alone.
|
|
261
|
-
if (args.values["no-manager"] !== true && requestedPayload < MANAGER_START_PAYLOAD_FLOOR)
|
|
262
|
-
throw new CommandFailure("refused", "USAGE_INVALID", `--max-payload ${requestedPayload} is below ${MANAGER_START_PAYLOAD_FLOOR} bytes, the least the space's manager starts on: it publishes its contract artifacts, one message each, and the largest is bounded at ${CONTRACT_ARTIFACT_MAX_BYTES} bytes with ${MANAGER_START_PAYLOAD_FLOOR - CONTRACT_ARTIFACT_MAX_BYTES} more for the publish; nothing was started`, { remedy: `pass --max-payload ${MANAGER_START_PAYLOAD_FLOOR} or more, or pass --no-manager to start the broker without a manager` });
|
|
261
|
+
if (args.values["no-manager"] !== true)
|
|
262
|
+
assertManagerPayload(requestedPayload);
|
|
263
263
|
}
|
|
264
264
|
// The account resolver belongs to the auth-mode broker configuration as well: the open broker has
|
|
265
265
|
// no operator and so no accounts to resolve, and a manifest or a restore starts the broker its own
|
|
@@ -277,6 +277,8 @@ export function validateUpArguments(args) {
|
|
|
277
277
|
throw new CommandFailure("refused", "USAGE_INVALID", `--restore-only takes registry (got ${JSON.stringify(restoreOnly)})`);
|
|
278
278
|
if (!args.values.restore && (restoreOnly !== undefined || args.values["accept-missing-source"] === true))
|
|
279
279
|
throw new CommandFailure("refused", "USAGE_INVALID", "--restore-only and --accept-missing-source require --restore <dir>");
|
|
280
|
+
if (args.values.file !== undefined && args.values["accept-stale-checkpoint"] === true)
|
|
281
|
+
throw new FlagValueRefusal("--accept-stale-checkpoint cannot be combined with --file/-f: a manifest starts a fresh mesh, not a preserved stack", "drop --accept-stale-checkpoint for a fresh start, or omit --file/-f to resume a preserved stack");
|
|
280
282
|
if (args.values.restore && (args.values.file !== undefined || args.values.channels !== undefined))
|
|
281
283
|
throw new CommandFailure("refused", "USAGE_INVALID", "--restore cannot be combined with --file/-f or --channels");
|
|
282
284
|
if (args.values.restore && args.values["rotate-sys"] === true)
|
|
@@ -334,7 +336,7 @@ function assertUpRootWritable(root) {
|
|
|
334
336
|
const code = error.code;
|
|
335
337
|
if (code !== "EACCES" && code !== "EPERM" && code !== "EROFS")
|
|
336
338
|
throw error;
|
|
337
|
-
throw new CommandFailure("refused", "PERMISSION_DENIED", `${path}
|
|
339
|
+
throw new CommandFailure("refused", "PERMISSION_DENIED", `${path} does not grant this account both write and search access (${code}); nothing was started or written`, { target: { root, path }, remedy: `make it writable and searchable by you, for example with chmod u+wx ${shellWord(path)}` });
|
|
338
340
|
}
|
|
339
341
|
}
|
|
340
342
|
/** The broker exits when it cannot write its store, naming the cause only in its own log. The store
|
|
@@ -1369,7 +1371,7 @@ async function runUp(args, invokedFrom, inheritedLock, onAdopt, freshTeamBoot =
|
|
|
1369
1371
|
// address never reaches the later pin in startMeshDetached, so the catch used to discard it.
|
|
1370
1372
|
let prepared;
|
|
1371
1373
|
try {
|
|
1372
|
-
prepared = loadManifest(resolve(values.file));
|
|
1374
|
+
prepared = loadManifest(resolve(values.file), logFile);
|
|
1373
1375
|
}
|
|
1374
1376
|
catch {
|
|
1375
1377
|
// Manifest errors are reported by the -f path with the same load; do not double-print.
|
|
@@ -1398,7 +1400,7 @@ async function runUp(args, invokedFrom, inheritedLock, onAdopt, freshTeamBoot =
|
|
|
1398
1400
|
const managerSeatCap = parseSeatCapFlag("--seat-cap", values["seat-cap"]);
|
|
1399
1401
|
if (managerSeatCap !== undefined) {
|
|
1400
1402
|
const capped = { root: cotalRoot(), space: values.space ?? folderSpace() };
|
|
1401
|
-
if (readManagerSeatCap(capped) !== managerSeatCap && managerRecordState(capped.space, capped.root).state === "alive")
|
|
1403
|
+
if ((readManagerSeatCap(capped) ?? DEFAULT_SEAT_CAP) !== managerSeatCap && managerRecordState(capped.space, capped.root).state === "alive")
|
|
1402
1404
|
throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", `a manager already runs for space ${capped.space}, and it keeps the seat cap it started with`, { target: { root: capped.root, space: capped.space }, remedy: `stop it with \`cotal down\`, then run \`cotal up --seat-cap ${seatCapText(managerSeatCap)}\`` });
|
|
1403
1405
|
}
|
|
1404
1406
|
// THE TRANSPORT IS DECIDED HERE, ABOVE EVERY BRANCH, AND THIS POSITION IS THE FIX.
|
|
@@ -1533,7 +1535,7 @@ async function runUp(args, invokedFrom, inheritedLock, onAdopt, freshTeamBoot =
|
|
|
1533
1535
|
// Structured and plain manifest refusals report file errors before checking startup support.
|
|
1534
1536
|
if (values.json || values.plain) {
|
|
1535
1537
|
try {
|
|
1536
|
-
loadManifest(path);
|
|
1538
|
+
loadManifest(path, logFile);
|
|
1537
1539
|
}
|
|
1538
1540
|
catch (e) {
|
|
1539
1541
|
throw manifestFileRefusal(e, path);
|
|
@@ -2113,6 +2115,9 @@ async function runUp(args, invokedFrom, inheritedLock, onAdopt, freshTeamBoot =
|
|
|
2113
2115
|
process.exit(1);
|
|
2114
2116
|
}
|
|
2115
2117
|
}
|
|
2118
|
+
const openMaxPayload = values.open ? maxPayload ?? readBrokerPolicy(cotalRoot())?.maxPayload : undefined;
|
|
2119
|
+
if (!noManager)
|
|
2120
|
+
assertManagerPayload(openMaxPayload);
|
|
2116
2121
|
if (stoppedStart)
|
|
2117
2122
|
console.log(c.dim(stoppedStart));
|
|
2118
2123
|
if (!resumeAttempt) {
|
|
@@ -2167,7 +2172,7 @@ async function runUp(args, invokedFrom, inheritedLock, onAdopt, freshTeamBoot =
|
|
|
2167
2172
|
logfileSizeLimit,
|
|
2168
2173
|
logfileMaxNum,
|
|
2169
2174
|
authTimeout,
|
|
2170
|
-
maxPayload,
|
|
2175
|
+
maxPayload: openMaxPayload ?? maxPayload,
|
|
2171
2176
|
accountResolver,
|
|
2172
2177
|
space: values.space,
|
|
2173
2178
|
open: values.open,
|
|
@@ -2257,7 +2262,7 @@ async function runUp(args, invokedFrom, inheritedLock, onAdopt, freshTeamBoot =
|
|
|
2257
2262
|
// the server, and the hostname is what the certificate has to match).
|
|
2258
2263
|
assertServesDialHost(transport, new URL(server).hostname);
|
|
2259
2264
|
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, logFile, logfileSizeLimit, logfileMaxNum }) : undefined;
|
|
2260
|
-
const brokerMaxPayload = brokerSetup?.maxPayload ??
|
|
2265
|
+
const brokerMaxPayload = brokerSetup?.maxPayload ?? openMaxPayload;
|
|
2261
2266
|
const port = Number(new URL(server).port) || 4222;
|
|
2262
2267
|
// Both modes go through a RENDERER, never bare CLI flags. Open mode used to start from
|
|
2263
2268
|
// `-js -sd … -p … -a …`, which never called a renderer at all — so the required transport union
|
|
@@ -3500,7 +3505,7 @@ function manifestFileRefusal(e, path) {
|
|
|
3500
3505
|
async function upManifest(file, opts) {
|
|
3501
3506
|
let prepared;
|
|
3502
3507
|
try {
|
|
3503
|
-
prepared = loadManifest(resolve(file));
|
|
3508
|
+
prepared = loadManifest(resolve(file), opts.logFile);
|
|
3504
3509
|
}
|
|
3505
3510
|
catch (e) {
|
|
3506
3511
|
if (opts.freshTeamBoot)
|
|
@@ -3589,9 +3594,7 @@ async function upManifest(file, opts) {
|
|
|
3589
3594
|
assertFreshTeamBootOwnership(cotalRoot(), m.space, open ? "open" : userAuth ? "user" : "auth");
|
|
3590
3595
|
await assertFreshTeamBindAvailable(server, host, m.space);
|
|
3591
3596
|
}
|
|
3592
|
-
// A manifest
|
|
3593
|
-
// against a manifest declaring agents asks for a boot that cannot deliver its own plan. Refused
|
|
3594
|
-
// before the dry-run print and before anything boots.
|
|
3597
|
+
// A manifest needs its manager to boot declared agents.
|
|
3595
3598
|
if (opts.noManager && eff.agents.length)
|
|
3596
3599
|
throw new FlagValueRefusal(`--no-manager cannot launch this manifest: it declares ${eff.agents.length} agent(s), and a manifest's agents are booted by its manager (which --no-manager omits)`, "drop --no-manager, or use a broker-only manifest with no agents");
|
|
3597
3600
|
const effectiveNoManager = Boolean(opts.noManager);
|
|
@@ -3610,9 +3613,10 @@ async function upManifest(file, opts) {
|
|
|
3610
3613
|
if (userAuth)
|
|
3611
3614
|
await preflightUserStack(cotalRoot(), m.space, userAuth.idpUrl);
|
|
3612
3615
|
checkStartStore(opts.storeDir, m.space);
|
|
3613
|
-
// Preview and apply
|
|
3616
|
+
// Preview and apply only probe a runtime when starting a manager.
|
|
3614
3617
|
try {
|
|
3615
|
-
|
|
3618
|
+
if (!effectiveNoManager)
|
|
3619
|
+
await preflightRuntime(runtime);
|
|
3616
3620
|
}
|
|
3617
3621
|
catch (error) {
|
|
3618
3622
|
throw new CommandFailure("refused", "DEPENDENCY_UNAVAILABLE", `the requested runtime did not pass preflight; ${opts.freshTeamBoot ? "no fresh boot intent or broker was started" : "no broker was started"}`, { target: { space: m.space, runtime }, remedy: error instanceof Error ? error.message : "inspect the selected runtime provider" });
|
|
@@ -4027,30 +4031,27 @@ async function serveReadyListener(l) {
|
|
|
4027
4031
|
// an authoritative registry entry (marker-without-registry is a refused start, not a guess),
|
|
4028
4032
|
// so the record must exist by the time it boots. A manager/delivery failure after this leaves
|
|
4029
4033
|
// a recorded-but-degraded mesh — the documented, healable posture.
|
|
4030
|
-
//
|
|
4031
|
-
// --preserve-state` then a bare `up`) carries the operator's `--host` only in the registry, and
|
|
4032
|
-
// the record below is written whole, so reading it afterwards would find the field this very call
|
|
4033
|
-
// had just erased.
|
|
4034
|
+
// Read the prior host and session limit before replacing the registry entry on resume.
|
|
4034
4035
|
const attachHost = attachHostFor(space, l.host);
|
|
4035
4036
|
const maxSessions = maxSessionsFor(space, l.maxSessions);
|
|
4036
|
-
|
|
4037
|
-
|
|
4038
|
-
|
|
4039
|
-
|
|
4040
|
-
|
|
4041
|
-
|
|
4042
|
-
|
|
4043
|
-
|
|
4044
|
-
|
|
4045
|
-
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
|
|
4052
|
-
|
|
4053
|
-
}
|
|
4037
|
+
try {
|
|
4038
|
+
recordOurMesh({
|
|
4039
|
+
space, server, root: cotalRoot(),
|
|
4040
|
+
mode: setup?.prepared ? "user" : setup ? "auth" : "open",
|
|
4041
|
+
// Record the transport decision even for plaintext. Omit the host unless the operator chose one.
|
|
4042
|
+
tlsRequired: transport.kind === "tls-required",
|
|
4043
|
+
...(svc.userAuth ? { userAuth: svc.userAuth } : {}),
|
|
4044
|
+
...(attachHost ? { attachHost } : {}),
|
|
4045
|
+
...(maxSessions !== undefined ? { maxSessions } : {}),
|
|
4046
|
+
...(l.maxFileStore !== undefined ? { maxFileStore: l.maxFileStore } : {}),
|
|
4047
|
+
storeDir: l.storeDir,
|
|
4048
|
+
ts: new Date().toISOString(),
|
|
4049
|
+
}, "started", l.quietBoot);
|
|
4050
|
+
}
|
|
4051
|
+
catch (e) {
|
|
4052
|
+
await stopFailedListener(child);
|
|
4053
|
+
throw e;
|
|
4054
|
+
}
|
|
4054
4055
|
// Commit the policy only for a listener that is up and recorded (S5), and before the control
|
|
4055
4056
|
// plane (S9). startDeliveryWithBroker is HANDED the transport decision, so it does not depend on
|
|
4056
4057
|
// the file at all.
|
|
@@ -4215,15 +4216,11 @@ opts) {
|
|
|
4215
4216
|
* the controller stack refuses it. nats-server would exit on its bind with only a log line, and the
|
|
4216
4217
|
* readiness probe would wait on that program instead. `command` is the start the remedy reruns. */
|
|
4217
4218
|
async function assertBrokerAddressFree(server, command, bindHost) {
|
|
4218
|
-
const
|
|
4219
|
-
if (
|
|
4219
|
+
const conflict = await brokerAddressConflict(server, command, bindHost);
|
|
4220
|
+
if (!conflict)
|
|
4220
4221
|
return;
|
|
4221
|
-
|
|
4222
|
-
|
|
4223
|
-
const { says, frees } = await addressHolder("the broker address", host, port);
|
|
4224
|
-
throw new CommandFailure("refused", "CONFLICT", `${says} (bind failed: address already in use); no broker was launched`, {
|
|
4225
|
-
target: { root: cotalRoot(), server, bindError: bindError.code },
|
|
4226
|
-
remedy: `start it at another address with ${codeSpan(`${command} --server ${address.protocol}//${address.hostname}:<port>`)}, or ${frees} and run ${codeSpan(command)} again`,
|
|
4222
|
+
throw new CommandFailure("refused", "CONFLICT", `${conflict.message} (bind failed: address already in use); no broker was launched`, {
|
|
4223
|
+
target: { root: cotalRoot(), server, bindError: "EADDRINUSE" }, remedy: conflict.remedy,
|
|
4227
4224
|
});
|
|
4228
4225
|
}
|
|
4229
4226
|
/** THE FLIP: a start without `--user-auth` must never boot a broker over a root whose space has
|
|
@@ -4272,14 +4269,14 @@ function ensureRootForSpace(space) {
|
|
|
4272
4269
|
remedy: gone ? `forget it with \`cotal space forget ${space}\`, then start it here` : `start it in its folder with \`cotal up --root ${shellWord(prepared.root)} --space ${space}\`, or \`cotal space forget ${space}\` to start it here`,
|
|
4273
4270
|
});
|
|
4274
4271
|
}
|
|
4275
|
-
//
|
|
4276
|
-
//
|
|
4272
|
+
// Auth material, a locally started registration, or a preparation names what this root hosts.
|
|
4273
|
+
// A remote registration uses the root as a connection folder, not as a stack root.
|
|
4277
4274
|
const hosted = listSpaceAccounts(authDir(root));
|
|
4278
4275
|
if (hosted.includes(space))
|
|
4279
4276
|
return;
|
|
4280
4277
|
const existing = hosted.length
|
|
4281
4278
|
? hosted
|
|
4282
|
-
: [
|
|
4279
|
+
: [localMeshesForRoot(root)[0]?.space ?? preparedSpaceAt(root)?.space].filter((s) => !!s);
|
|
4283
4280
|
if (existing.length === 0 || existing.includes(space))
|
|
4284
4281
|
return;
|
|
4285
4282
|
const names = existing.map((s) => `"${s}"`).join(", ");
|
|
@@ -4339,14 +4336,6 @@ function assertSelectionNotMoved(root, space) {
|
|
|
4339
4336
|
remedy: `if this is that folder moved, forget it with \`cotal space forget ${current}\`, then prepare it here with \`cotal space create ${current}\` and run \`cotal up\`; to start "${space}" here, pass --space ${space}`,
|
|
4340
4337
|
});
|
|
4341
4338
|
}
|
|
4342
|
-
function realpathSafe(p) {
|
|
4343
|
-
try {
|
|
4344
|
-
return realpathSync(p);
|
|
4345
|
-
}
|
|
4346
|
-
catch {
|
|
4347
|
-
return p;
|
|
4348
|
-
}
|
|
4349
|
-
}
|
|
4350
4339
|
/** The remedy for a hand-registered (`origin === "manual"`) space `claimSpace` refuses to touch.
|
|
4351
4340
|
* Branches on whether the REGISTERED server is loopback, the one authority for that being
|
|
4352
4341
|
* `isLoopbackHost` (`@cotal-ai/workspace`) — never a second opinion here.
|
|
@@ -4666,338 +4655,6 @@ function belowPresenceSafeBroker(version) {
|
|
|
4666
4655
|
return p.minor < 14;
|
|
4667
4656
|
return p.patch < 5;
|
|
4668
4657
|
}
|
|
4669
|
-
/** Wildcard binds mean "every interface", so they are NOT an address a client can be told to dial:
|
|
4670
|
-
* the probe/registry URL stays whatever it already is (loopback by default), which the wildcard
|
|
4671
|
-
* bind necessarily covers. */
|
|
4672
|
-
const WILDCARD_HOSTS = new Set(["0.0.0.0", "::", "[::]"]);
|
|
4673
|
-
/** Establish that a bind-host value IS a host, BEFORE anything brackets it, and return the
|
|
4674
|
-
* bracketed literal a URL can hold (#1697).
|
|
4675
|
-
*
|
|
4676
|
-
* `--host` is the bind address; its sibling `--server` takes a URL, the registry stores and prints
|
|
4677
|
-
* URLs, and every message in this area shows one — so an operator plausibly types the URL here
|
|
4678
|
-
* (the manifest's `broker.host` carries the same ambiguity against `broker.servers`). Unrejected,
|
|
4679
|
-
* the IPv6 bracketing wrapped it into `nats://[nats://127.0.0.1:4222]:4222`, which is not a URL at
|
|
4680
|
-
* all. Nothing checked the derived string: the first code to look at it compared it with the
|
|
4681
|
-
* space's registry record, failed for a reason unrelated to what was typed, and showed the
|
|
4682
|
-
* operator the "registered by hand" refusal whose remedy de-registers a live mesh. Refused by name
|
|
4683
|
-
* here instead — pointing at the URL-carrying sibling — and a value that still cannot serve as a
|
|
4684
|
-
* URL host (a `host:port` spelling, say) is refused rather than reaching that comparison as a
|
|
4685
|
-
* silently wrong server string. Never rewritten: a value this flag cannot use is an error, not a
|
|
4686
|
-
* URL to derive from. */
|
|
4687
|
-
function assertBindableHost(host, source, urlSource) {
|
|
4688
|
-
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(host)) {
|
|
4689
|
-
console.error(c.red(`✗ ${source} ${host} looks like a URL - it takes a bind host only (an IP or hostname, no scheme); pass the broker URL with ${urlSource} instead`));
|
|
4690
|
-
process.exit(1);
|
|
4691
|
-
}
|
|
4692
|
-
const literal = host.includes(":") && !host.startsWith("[") ? `[${host}]` : host;
|
|
4693
|
-
try {
|
|
4694
|
-
// ONE parse, both consumers served from it: `literal` builds the derived URL (a URL host needs
|
|
4695
|
-
// the brackets), `hostname` compares against the explicit server's (the URL API strips them).
|
|
4696
|
-
return { literal, hostname: new URL(`nats://${literal}:1`).hostname };
|
|
4697
|
-
}
|
|
4698
|
-
catch {
|
|
4699
|
-
console.error(c.red(`✗ ${source} ${host} is not a valid bind host - an IP or hostname only, with no port; the port comes from ${urlSource} (or its default), never from the bind host`));
|
|
4700
|
-
process.exit(1);
|
|
4701
|
-
}
|
|
4702
|
-
}
|
|
4703
|
-
/**
|
|
4704
|
-
* Reconcile the bind address (`--host`, manifest `broker.host`) with the broker URL the readiness
|
|
4705
|
-
* probe, the mesh registry, and every later client use.
|
|
4706
|
-
*
|
|
4707
|
-
* They must name the same address. Left independent, `--host <non-loopback>` bound correctly and was
|
|
4708
|
-
* then probed at the loopback default: the probe found nothing, timed out, and the caller SIGTERM'd
|
|
4709
|
-
* a broker that had started perfectly, so `--host` alone could never succeed. With no explicit URL,
|
|
4710
|
-
* derive one from the host (keeping the implicit URL's port); with both, refuse a contradicting pair rather
|
|
4711
|
-
* than starting a broker that nothing can reach.
|
|
4712
|
-
*/
|
|
4713
|
-
function reconcileHostAndServer(host, explicitServer, source = "--host", urlSource = "--server", implicitServer = DEFAULT_SERVER) {
|
|
4714
|
-
const url = new URL(explicitServer ?? implicitServer);
|
|
4715
|
-
if (WILDCARD_HOSTS.has(host))
|
|
4716
|
-
return explicitServer ?? implicitServer;
|
|
4717
|
-
const { literal, hostname } = assertBindableHost(host, source, urlSource);
|
|
4718
|
-
if (!explicitServer)
|
|
4719
|
-
return `nats://${literal}:${url.port || "4222"}`;
|
|
4720
|
-
// NO parse on this path: `assertBindableHost` just parsed the identical literal above, so the
|
|
4721
|
-
// mismatch check compares two parsed hostnames and can only ever print its diagnostic and exit 1
|
|
4722
|
-
// — the "never throw a raw Invalid URL" requirement (#1697) holds by construction, not by a
|
|
4723
|
-
// second guard that no input could reach.
|
|
4724
|
-
if (url.hostname !== hostname) {
|
|
4725
|
-
console.error(c.red(`✗ ${source} ${host} and ${urlSource} ${explicitServer} name different addresses - the broker would bind ${host} but be probed at ${url.hostname}. Pass one, or make them agree.`));
|
|
4726
|
-
process.exit(1);
|
|
4727
|
-
}
|
|
4728
|
-
return explicitServer;
|
|
4729
|
-
}
|
|
4730
|
-
/** Bind the manifest's exact listener address before any team-boot write. Releasing this
|
|
4731
|
-
* socket is not a reservation: the real broker still owns the final bind verdict. */
|
|
4732
|
-
async function assertFreshTeamBindAvailable(server, host, space) {
|
|
4733
|
-
const url = new URL(server), port = Number(url.port || "4222");
|
|
4734
|
-
const displayServer = brokerAddressForDisplay(server) ?? "not displayable";
|
|
4735
|
-
if (!Number.isSafeInteger(port) || port < 1 || port > 65535)
|
|
4736
|
-
throw new CommandFailure("refused", "USAGE_INVALID", "the fresh team broker needs a concrete TCP port before it can check its bind address", { target: { space } });
|
|
4737
|
-
await new Promise((resolve, reject) => {
|
|
4738
|
-
const socket = createServer(), controller = new AbortController();
|
|
4739
|
-
socket.unref();
|
|
4740
|
-
let settled = false;
|
|
4741
|
-
const finish = (error) => {
|
|
4742
|
-
if (settled)
|
|
4743
|
-
return;
|
|
4744
|
-
settled = true;
|
|
4745
|
-
clearTimeout(timer);
|
|
4746
|
-
if (error)
|
|
4747
|
-
reject(error);
|
|
4748
|
-
else
|
|
4749
|
-
resolve();
|
|
4750
|
-
};
|
|
4751
|
-
const timer = setTimeout(() => {
|
|
4752
|
-
controller.abort();
|
|
4753
|
-
finish(new CommandFailure("refused", "TARGET_UNAVAILABLE", "the local broker bind inspection did not complete within its deadline; no absence or startup eligibility was inferred", { target: { space, server: displayServer } }));
|
|
4754
|
-
}, 1500);
|
|
4755
|
-
socket.once("error", () => finish(new CommandFailure("refused", "TARGET_UNAVAILABLE", "the selected broker address cannot be bound as a new local listener; no existing or remote broker was adopted", { target: { space, server: displayServer }, remedy: "inspect this local bind address and any process already listening there" })));
|
|
4756
|
-
try {
|
|
4757
|
-
socket.listen({ port, host, signal: controller.signal }, () => {
|
|
4758
|
-
if (settled)
|
|
4759
|
-
return;
|
|
4760
|
-
socket.close((error) => finish(error ? new CommandFailure("failed", "OPERATION_FAILED", "the temporary bind inspection did not confirm closure; no broker was started", { target: { space, server: displayServer } }) : undefined));
|
|
4761
|
-
});
|
|
4762
|
-
}
|
|
4763
|
-
catch {
|
|
4764
|
-
controller.abort();
|
|
4765
|
-
finish(new CommandFailure("refused", "TARGET_UNAVAILABLE", "the selected broker bind address was rejected before startup; no other listener was chosen", { target: { space, server: displayServer } }));
|
|
4766
|
-
}
|
|
4767
|
-
});
|
|
4768
|
-
}
|
|
4769
|
-
function registeredAddressHolder(server, space) {
|
|
4770
|
-
const key = brokerAddressKey(server);
|
|
4771
|
-
if (key === undefined)
|
|
4772
|
-
return undefined;
|
|
4773
|
-
const root = canonicalRoot(cotalRoot());
|
|
4774
|
-
return loadMeshes().find((m) => m.space !== space && canonicalRoot(m.root) !== root && brokerAddressKey(m.server) === key);
|
|
4775
|
-
}
|
|
4776
|
-
/** Refuse an address that a space registered for another folder keeps while its broker is stopped,
|
|
4777
|
-
* as an occupied one is refused. Starting there would leave two registrations naming one broker:
|
|
4778
|
-
* whichever stack runs answers for both, and the other one's `down` and reads reach it. Every
|
|
4779
|
-
* start that names its own address asks this, a manifest's `broker.servers` included, and
|
|
4780
|
-
* `elsewhere` names the way to move the one being started. A space this start takes the name of is
|
|
4781
|
-
* left to the name rules. */
|
|
4782
|
-
function refuseRegisteredAddress(server, space, elsewhere) {
|
|
4783
|
-
const held = registeredAddressHolder(server, space);
|
|
4784
|
-
if (!held)
|
|
4785
|
-
return;
|
|
4786
|
-
throw new CommandFailure("refused", "CONFLICT", `${server} is the broker address of "${held.space}", registered for ${held.root} and stopped; nothing was started`, {
|
|
4787
|
-
target: { root: cotalRoot(), server, space, heldSpace: held.space, heldBy: held.root },
|
|
4788
|
-
remedy: `${elsewhere}, or free that one with \`cotal space forget ${held.space}\``,
|
|
4789
|
-
});
|
|
4790
|
-
}
|
|
4791
|
-
function membershipConversionRefusal(space, remedy = "stop the stack with `cotal down --yes`, then run `cotal up --recreate-membership-store`") {
|
|
4792
|
-
return new CommandFailure("refused", "LIFECYCLE_BLOCKED", `space ${space} has a legacy File-backed membership store; it was not changed while its broker or membership services may be in use`, {
|
|
4793
|
-
target: { space }, remedy,
|
|
4794
|
-
});
|
|
4795
|
-
}
|
|
4796
|
-
async function fileMembershipStore(server, space, creds, stockOnly = false) {
|
|
4797
|
-
const nc = await dialerFor(server)({ servers: server, ...standaloneConnectOpts({ creds, tls: false }) });
|
|
4798
|
-
try {
|
|
4799
|
-
requireBrokerFloor(nc);
|
|
4800
|
-
const { config } = await (await jetstreamManager(nc)).streams.info(`KV_${membershipStoreDefinition(space).bucket}`);
|
|
4801
|
-
if (config.storage !== StorageType.File)
|
|
4802
|
-
return false;
|
|
4803
|
-
if (stockOnly && (![-1, LEGACY_MEMBERSHIP_MAX_BYTES].includes(config.max_bytes) || config.max_msgs_per_subject !== 1 || ![-1, MEMBERSHIP_MAX_VALUE_SIZE].includes(config.max_msg_size)))
|
|
4804
|
-
throw membershipConversionRefusal(space);
|
|
4805
|
-
return true;
|
|
4806
|
-
}
|
|
4807
|
-
catch (error) {
|
|
4808
|
-
if (isJetStreamMissing(error, JetStreamApiCodes.StreamNotFound))
|
|
4809
|
-
return false;
|
|
4810
|
-
throw error;
|
|
4811
|
-
}
|
|
4812
|
-
finally {
|
|
4813
|
-
await drainAndClose(nc);
|
|
4814
|
-
}
|
|
4815
|
-
}
|
|
4816
|
-
/** Create or verify space infrastructure before any services start on this broker.
|
|
4817
|
-
* Only a fresh owned local boot may automatically replace its derived legacy membership feed. */
|
|
4818
|
-
async function postStart(server, space, setup, seedFile, recreateIssuedStores, recreateMembershipStore, freshOwnedLocalBroker = false) {
|
|
4819
|
-
if (recreateIssuedStores !== undefined)
|
|
4820
|
-
await recreateIssuedStoresBeforeSetup(server, space, setup !== undefined, recreateIssuedStores);
|
|
4821
|
-
const legacyMembership = await fileMembershipStore(server, space, setup?.creds, recreateMembershipStore !== true);
|
|
4822
|
-
if (legacyMembership) {
|
|
4823
|
-
const running = serviceInstances(space).filter((row) => row.record.value.definition !== STACK_DEFINITION.broker).some((row) => !["gone", "previous-boot", "foreign-pid"].includes(observeServiceProcess(row.record.value)));
|
|
4824
|
-
if ((!freshOwnedLocalBroker && !recreateMembershipStore) || running)
|
|
4825
|
-
throw membershipConversionRefusal(space);
|
|
4826
|
-
}
|
|
4827
|
-
const convertMembership = legacyMembership && (freshOwnedLocalBroker || recreateMembershipStore === true);
|
|
4828
|
-
let recreateCreds;
|
|
4829
|
-
if (convertMembership && setup !== undefined) {
|
|
4830
|
-
const auth = await getSpaceAuth(workspaceSecretStore(cotalRoot()), space);
|
|
4831
|
-
if (!auth)
|
|
4832
|
-
throw new Error(`space "${space}" has no trust material under ${authDir(cotalRoot())}; its membership store was not touched`);
|
|
4833
|
-
recreateCreds = await mintCreds(auth, newIdentity(), "membership-store-recreate");
|
|
4834
|
-
}
|
|
4835
|
-
try {
|
|
4836
|
-
await setupSpaceStreams({
|
|
4837
|
-
servers: server,
|
|
4838
|
-
space,
|
|
4839
|
-
creds: setup?.creds,
|
|
4840
|
-
...(convertMembership ? { recreateFileMembership: { creds: recreateCreds } } : {}),
|
|
4841
|
-
});
|
|
4842
|
-
}
|
|
4843
|
-
catch (error) {
|
|
4844
|
-
// Nothing of the stack runs yet, and the caller stops this broker again, so this is a refusal.
|
|
4845
|
-
if (error instanceof IssuedStoreBeforeRetentionError)
|
|
4846
|
-
throw new CommandFailure("refused", "CONFLICT", error.message, { target: { space, store: error.bucket }, remedy: `stop every other issuer and resolver of space ${space}, then add --recreate-issued-stores <backup-dir> to the \`cotal up\` that starts it` });
|
|
4847
|
-
throw error;
|
|
4848
|
-
}
|
|
4849
|
-
if (convertMembership)
|
|
4850
|
-
console.error(`Converted ${membershipStoreDefinition(space).bucket} from File to Memory; broker-sourced membership rebuilds on startup.`);
|
|
4851
|
-
try {
|
|
4852
|
-
if (seedFile) {
|
|
4853
|
-
await seedChannelRegistry({ servers: server, space, creds: setup?.creds, file: seedFile });
|
|
4854
|
-
}
|
|
4855
|
-
// SPEC §4: `defaults.deliveryClass` MUST be written at space creation so the effective default is
|
|
4856
|
-
// discoverable on the wire, never inferred from the `?? "durable"` resolution fallback. Auth mode
|
|
4857
|
-
// (`setup` present ⇒ the delivery daemon is up) is local/self-hosted ⇒ `durable`; open mode has no
|
|
4858
|
-
// daemon and is live-only ⇒ `live`. Runs after the seed so an explicit `channels.json` default wins.
|
|
4859
|
-
// A key that does not decode is not replaced by either write.
|
|
4860
|
-
await ensureDefaultDeliveryClass({
|
|
4861
|
-
servers: server,
|
|
4862
|
-
space,
|
|
4863
|
-
creds: setup?.creds,
|
|
4864
|
-
deliveryClass: setup ? "durable" : "live",
|
|
4865
|
-
});
|
|
4866
|
-
}
|
|
4867
|
-
catch (error) {
|
|
4868
|
-
if (!(error instanceof UndecodableRegistryEntry))
|
|
4869
|
-
throw error;
|
|
4870
|
-
throw new CommandFailure("refused", "CONFLICT", error.message, { target: { space }, remedy: "read the key and replace the value; the bytes were left as they are" });
|
|
4871
|
-
}
|
|
4872
|
-
}
|
|
4873
|
-
/** `--recreate-issued-stores`: on the broker this boot just started, before any issuer or resolver
|
|
4874
|
-
* of the space runs, back up and delete the space's issued-authority stores created before bounded
|
|
4875
|
-
* retention, so the stream setup that follows creates them in the current shape. It runs the core
|
|
4876
|
-
* step an embedder runs, on a one-shot `issued-store-recreate` credential minted from the root's
|
|
4877
|
-
* trust; an open space uses its bare connection, as stream setup does. */
|
|
4878
|
-
async function recreateIssuedStoresBeforeSetup(server, space, authenticated, backupDir) {
|
|
4879
|
-
let creds;
|
|
4880
|
-
let inboxPrefix = "_INBOX";
|
|
4881
|
-
if (authenticated) {
|
|
4882
|
-
const auth = await getSpaceAuth(workspaceSecretStore(cotalRoot()), space);
|
|
4883
|
-
if (!auth)
|
|
4884
|
-
throw new Error(`space "${space}" has no trust material under ${authDir(cotalRoot())}; its issued-authority stores were not touched`);
|
|
4885
|
-
const identity = newIdentity();
|
|
4886
|
-
creds = await mintCreds(auth, identity, "issued-store-recreate");
|
|
4887
|
-
inboxPrefix = `_INBOX_${identity.id}`;
|
|
4888
|
-
}
|
|
4889
|
-
const nc = await dialerFor(server)({ servers: server, ...standaloneConnectOpts({ creds, tls: false }), inboxPrefix });
|
|
4890
|
-
let removed;
|
|
4891
|
-
try {
|
|
4892
|
-
removed = await removeIssuedStoresBeforeRetention(nc, { space, backupDir, inboxPrefix });
|
|
4893
|
-
}
|
|
4894
|
-
catch (error) {
|
|
4895
|
-
if (error instanceof IssuedStoreRecreateRefusal)
|
|
4896
|
-
throw new CommandFailure("refused", error.reason === "nothing-to-recreate" ? "CONFLICT" : "USAGE_INVALID", error.message, { target: { space, backupDir }, remedy: error.reason === "nothing-to-recreate" ? "start the space without --recreate-issued-stores" : "name a directory that does not exist yet, inside one that does" });
|
|
4897
|
-
throw error;
|
|
4898
|
-
}
|
|
4899
|
-
finally {
|
|
4900
|
-
await drainAndClose(nc);
|
|
4901
|
-
}
|
|
4902
|
-
for (const store of removed)
|
|
4903
|
-
console.log(`→ backed up ${store.stream} (${store.messages} messages) to ${store.backup}, then deleted it`);
|
|
4904
|
-
console.log(c.dim("• the issued-authority stores are created again in the current shape; every generation issued before the upgrade is refused from now on"));
|
|
4905
|
-
}
|
|
4906
|
-
/** A resume or restore skips `postStart` because the preserved store already holds every canonical
|
|
4907
|
-
* stream. A memory-backed bucket is the exception: the broker stop that preserved the store emptied
|
|
4908
|
-
* it, stream and all (#1356 made presence memory-backed). Recreate those, and only those, from the
|
|
4909
|
-
* same `ttlBuckets` list `setupSpaceStreams` creates them from, before any daemon opens them.
|
|
4910
|
-
* Only an ordinary resume that just started this listener may opt into replacing a File feed. */
|
|
4911
|
-
async function recreateMemoryBuckets(server, space, setup, ownedResume) {
|
|
4912
|
-
const legacy = await fileMembershipStore(server, space, setup?.creds);
|
|
4913
|
-
if (legacy) {
|
|
4914
|
-
if (!ownedResume?.convertMembership)
|
|
4915
|
-
throw membershipConversionRefusal(space, ownedResume && "retry this preserved resume with `cotal up --recreate-membership-store`");
|
|
4916
|
-
const running = serviceInstances(space).filter((row) => row.record.value.definition !== STACK_DEFINITION.broker).some((row) => !["gone", "previous-boot", "foreign-pid"].includes(observeServiceProcess(row.record.value)));
|
|
4917
|
-
if (running)
|
|
4918
|
-
throw membershipConversionRefusal(space, "stop the remaining membership services, then retry the preserved resume with `cotal up --recreate-membership-store`");
|
|
4919
|
-
try {
|
|
4920
|
-
const auth = setup && await getSpaceAuth(workspaceSecretStore(cotalRoot()), space);
|
|
4921
|
-
if (setup && !auth)
|
|
4922
|
-
throw new Error(`space "${space}" has no trust material under ${authDir(cotalRoot())}`);
|
|
4923
|
-
await recreateMembershipStore({
|
|
4924
|
-
servers: server, space, provisionerCreds: setup?.creds,
|
|
4925
|
-
recreateCreds: auth ? await mintCreds(auth, newIdentity(), "membership-store-recreate") : undefined,
|
|
4926
|
-
});
|
|
4927
|
-
}
|
|
4928
|
-
catch (error) {
|
|
4929
|
-
throw new CommandFailure("failed", "OPERATION_FAILED", `could not convert the preserved membership store: ${error.message}`, {
|
|
4930
|
-
target: { space }, remedy: "fix the reported cause, then retry this preserved resume with `cotal up --recreate-membership-store`",
|
|
4931
|
-
});
|
|
4932
|
-
}
|
|
4933
|
-
console.error(`Converted ${membershipStoreDefinition(space).bucket} from File to Memory; broker-sourced membership rebuilds on startup.`);
|
|
4934
|
-
}
|
|
4935
|
-
const nc = await dialerFor(server)({ servers: server, ...standaloneConnectOpts({ creds: setup?.creds, tls: false }) });
|
|
4936
|
-
try {
|
|
4937
|
-
requireBrokerFloor(nc);
|
|
4938
|
-
const kvm = new Kvm(nc);
|
|
4939
|
-
for (const [bucket, ttl, storage] of ttlBuckets(space))
|
|
4940
|
-
if (storage === StorageType.Memory)
|
|
4941
|
-
await kvm.create(bucket, { ttl, storage });
|
|
4942
|
-
if (!legacy) {
|
|
4943
|
-
const membership = membershipStoreDefinition(space);
|
|
4944
|
-
await kvm.create(membership.bucket, membership.createOptions);
|
|
4945
|
-
}
|
|
4946
|
-
}
|
|
4947
|
-
finally {
|
|
4948
|
-
await drainAndClose(nc);
|
|
4949
|
-
}
|
|
4950
|
-
}
|
|
4951
|
-
/** An adopted listener may have been bound by an `up` that stopped before {@link recreateMemoryBuckets},
|
|
4952
|
-
* so the memory buckets the daemons open can be missing on it. An existing bucket is left as it is. */
|
|
4953
|
-
async function recreateAdoptedMemoryBuckets(root, space, server, mode) {
|
|
4954
|
-
if (mode === "open")
|
|
4955
|
-
return recreateMemoryBuckets(server, space);
|
|
4956
|
-
const auth = await getSpaceAuth(workspaceSecretStore(root), space);
|
|
4957
|
-
if (!auth)
|
|
4958
|
-
throw new Error(`space "${space}" has no trust material under ${authDir(root)}; cannot recreate its memory buckets on the adopted listener`);
|
|
4959
|
-
await recreateMemoryBuckets(server, space, { creds: await mintCreds(auth, newIdentity(), "provisioner") });
|
|
4960
|
-
}
|
|
4961
|
-
/** `cotal space delete` removes a space's streams from a broker that keeps running. When a stack
|
|
4962
|
-
* reuses that broker and every canonical stream of the space is gone, create them again, empty, as
|
|
4963
|
-
* a broker start does, and return true. A broker that still holds any of them is left as it is. */
|
|
4964
|
-
async function recreateDeletedStreams(opts) {
|
|
4965
|
-
let setup;
|
|
4966
|
-
if (opts.mode !== "open") {
|
|
4967
|
-
const auth = await getSpaceAuth(workspaceSecretStore(opts.root), opts.space);
|
|
4968
|
-
if (!auth)
|
|
4969
|
-
throw new Error(`space "${opts.space}" has no trust material under ${authDir(opts.root)}; cannot read its streams on the running broker`);
|
|
4970
|
-
setup = { creds: await mintCreds(auth, newIdentity(), "provisioner") };
|
|
4971
|
-
}
|
|
4972
|
-
if (await fileMembershipStore(opts.server, opts.space, setup?.creds))
|
|
4973
|
-
throw membershipConversionRefusal(opts.space);
|
|
4974
|
-
if (opts.mode === "user")
|
|
4975
|
-
return false; // User-auth running stacks retain their existing stream lifecycle.
|
|
4976
|
-
const nc = await dialerFor(opts.server)({ servers: opts.server, ...standaloneConnectOpts({ creds: setup?.creds, tls: false }) });
|
|
4977
|
-
let held = false;
|
|
4978
|
-
try {
|
|
4979
|
-
requireBrokerFloor(nc);
|
|
4980
|
-
const jsm = await jetstreamManager(nc);
|
|
4981
|
-
for (const name of spaceDeletionStreams(opts.space)) {
|
|
4982
|
-
try {
|
|
4983
|
-
await jsm.streams.info(name);
|
|
4984
|
-
held = true;
|
|
4985
|
-
break;
|
|
4986
|
-
}
|
|
4987
|
-
catch (error) {
|
|
4988
|
-
if (!isJetStreamMissing(error, JetStreamApiCodes.StreamNotFound))
|
|
4989
|
-
throw error;
|
|
4990
|
-
}
|
|
4991
|
-
}
|
|
4992
|
-
}
|
|
4993
|
-
finally {
|
|
4994
|
-
await drainAndClose(nc);
|
|
4995
|
-
}
|
|
4996
|
-
if (held)
|
|
4997
|
-
return false;
|
|
4998
|
-
await postStart(opts.server, opts.space, setup, opts.seed ?? loadChannelsFile(opts.channels));
|
|
4999
|
-
return true;
|
|
5000
|
-
}
|
|
5001
4658
|
/**
|
|
5002
4659
|
* Render and write the config for an OPEN (no-auth) broker, returning its path. It names `space`,
|
|
5003
4660
|
* because an open root holds no account that would ({@link namedOpenConfig}).
|
|
@@ -5192,10 +4849,8 @@ requested = {}) {
|
|
|
5192
4849
|
const recorded = readBrokerPolicy(cotalRoot());
|
|
5193
4850
|
const authTimeout = requested.authTimeout ?? recorded?.authTimeout;
|
|
5194
4851
|
const maxPayload = requested.maxPayload ?? recorded?.maxPayload;
|
|
5195
|
-
|
|
5196
|
-
|
|
5197
|
-
if (requested.manager === true && maxPayload !== undefined && maxPayload < MANAGER_START_PAYLOAD_FLOOR)
|
|
5198
|
-
throw new CommandFailure("refused", "USAGE_INVALID", `--max-payload ${maxPayload} is below ${MANAGER_START_PAYLOAD_FLOOR} bytes, the least the space's manager starts on: it publishes its contract artifacts, one message each, and the largest is bounded at ${CONTRACT_ARTIFACT_MAX_BYTES} bytes with ${MANAGER_START_PAYLOAD_FLOOR - CONTRACT_ARTIFACT_MAX_BYTES} more for the publish; nothing was started`, { remedy: `pass --max-payload ${MANAGER_START_PAYLOAD_FLOOR} or more, or pass --no-manager to start the broker without a manager` });
|
|
4852
|
+
if (requested.manager === true)
|
|
4853
|
+
assertManagerPayload(maxPayload);
|
|
5199
4854
|
const resolverChoice = requested.accountResolver ?? recorded?.accountResolver ?? "memory";
|
|
5200
4855
|
const accountResolver = brokerAccountResolver(cotalRoot(), resolverChoice === "full" ? "full" : undefined);
|
|
5201
4856
|
// Owner-private like the auth dir: nats-server writes each pushed claim here.
|