@cotal-ai/cli 0.175.0 → 0.175.2
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 +27 -20
- package/dist/command.js.map +1 -1
- package/dist/commands/agents.d.ts +1 -1
- package/dist/commands/agents.d.ts.map +1 -1
- package/dist/commands/agents.js +25 -14
- package/dist/commands/agents.js.map +1 -1
- package/dist/commands/backup-read.d.ts.map +1 -1
- package/dist/commands/backup-read.js +15 -11
- package/dist/commands/backup-read.js.map +1 -1
- package/dist/commands/backup.d.ts.map +1 -1
- package/dist/commands/backup.js +8 -2
- package/dist/commands/backup.js.map +1 -1
- package/dist/commands/clean.d.ts.map +1 -1
- package/dist/commands/clean.js +8 -3
- package/dist/commands/clean.js.map +1 -1
- package/dist/commands/config.d.ts.map +1 -1
- package/dist/commands/config.js +3 -3
- package/dist/commands/config.js.map +1 -1
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +3 -1
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/down.d.ts.map +1 -1
- package/dist/commands/down.js +16 -9
- package/dist/commands/down.js.map +1 -1
- package/dist/commands/endpoint-authoring.d.ts.map +1 -1
- package/dist/commands/endpoint-authoring.js +15 -5
- package/dist/commands/endpoint-authoring.js.map +1 -1
- package/dist/commands/endpoint.d.ts.map +1 -1
- package/dist/commands/endpoint.js +2 -0
- package/dist/commands/endpoint.js.map +1 -1
- package/dist/commands/help.js +1 -1
- package/dist/commands/help.js.map +1 -1
- package/dist/commands/history-clear.d.ts.map +1 -1
- package/dist/commands/history-clear.js +14 -3
- package/dist/commands/history-clear.js.map +1 -1
- package/dist/commands/models.d.ts.map +1 -1
- package/dist/commands/models.js +9 -10
- package/dist/commands/models.js.map +1 -1
- package/dist/commands/personas.d.ts.map +1 -1
- package/dist/commands/personas.js +10 -3
- package/dist/commands/personas.js.map +1 -1
- package/dist/commands/removed-start.d.ts +4 -0
- package/dist/commands/removed-start.d.ts.map +1 -0
- package/dist/commands/removed-start.js +68 -0
- package/dist/commands/removed-start.js.map +1 -0
- package/dist/commands/revoke-credential.d.ts.map +1 -1
- package/dist/commands/revoke-credential.js +9 -6
- package/dist/commands/revoke-credential.js.map +1 -1
- package/dist/commands/service-actions.d.ts.map +1 -1
- package/dist/commands/service-actions.js +4 -2
- 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 +21 -3
- package/dist/commands/service-registry.js.map +1 -1
- package/dist/commands/space-delete.d.ts.map +1 -1
- package/dist/commands/space-delete.js +4 -3
- package/dist/commands/space-delete.js.map +1 -1
- package/dist/commands/space-registration.d.ts +2 -0
- package/dist/commands/space-registration.d.ts.map +1 -1
- package/dist/commands/space-registration.js +15 -8
- package/dist/commands/space-registration.js.map +1 -1
- package/dist/commands/space.d.ts +1 -1
- package/dist/commands/space.d.ts.map +1 -1
- package/dist/commands/space.js +7 -4
- package/dist/commands/space.js.map +1 -1
- package/dist/commands/spawn-flags.d.ts +2 -0
- package/dist/commands/spawn-flags.d.ts.map +1 -1
- package/dist/commands/spawn-flags.js +1 -1
- package/dist/commands/spawn-flags.js.map +1 -1
- package/dist/commands/spawn-preview.js +1 -1
- package/dist/commands/spawn-preview.js.map +1 -1
- package/dist/commands/spawn.js +1 -1
- package/dist/commands/spawn.js.map +1 -1
- package/dist/commands/stack-down.d.ts +3 -1
- package/dist/commands/stack-down.d.ts.map +1 -1
- package/dist/commands/stack-down.js +56 -6
- package/dist/commands/stack-down.js.map +1 -1
- package/dist/commands/stack-up.d.ts +9 -9
- package/dist/commands/stack-up.d.ts.map +1 -1
- package/dist/commands/stack-up.js +23 -31
- package/dist/commands/stack-up.js.map +1 -1
- package/dist/commands/status-health.d.ts +2 -2
- package/dist/commands/status-health.d.ts.map +1 -1
- package/dist/commands/status-health.js +19 -2
- package/dist/commands/status-health.js.map +1 -1
- package/dist/commands/status-meshes.js +3 -3
- package/dist/commands/status-meshes.js.map +1 -1
- package/dist/commands/status.js +1 -1
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/team-agent-apply.d.ts.map +1 -1
- package/dist/commands/team-agent-apply.js +5 -4
- package/dist/commands/team-agent-apply.js.map +1 -1
- package/dist/commands/team-deploy-apply.d.ts.map +1 -1
- package/dist/commands/team-deploy-apply.js +9 -3
- package/dist/commands/team-deploy-apply.js.map +1 -1
- package/dist/commands/team.js +2 -2
- package/dist/commands/team.js.map +1 -1
- package/dist/commands/up-args.d.ts +65 -0
- package/dist/commands/up-args.d.ts.map +1 -0
- package/dist/commands/up-args.js +541 -0
- package/dist/commands/up-args.js.map +1 -0
- package/dist/commands/up-detach.d.ts +373 -0
- package/dist/commands/up-detach.d.ts.map +1 -0
- package/dist/commands/up-detach.js +819 -0
- package/dist/commands/up-detach.js.map +1 -0
- package/dist/commands/up-manifest.d.ts +109 -0
- package/dist/commands/up-manifest.d.ts.map +1 -0
- package/dist/commands/up-manifest.js +549 -0
- package/dist/commands/up-manifest.js.map +1 -0
- package/dist/commands/up-stores.d.ts +2 -2
- package/dist/commands/up-stores.d.ts.map +1 -1
- package/dist/commands/up-stores.js +5 -5
- package/dist/commands/up-stores.js.map +1 -1
- package/dist/commands/up.d.ts +7 -245
- package/dist/commands/up.d.ts.map +1 -1
- package/dist/commands/up.js +39 -1882
- package/dist/commands/up.js.map +1 -1
- package/dist/commands/update-release.d.ts +2 -4
- package/dist/commands/update-release.d.ts.map +1 -1
- package/dist/commands/update-release.js +30 -12
- package/dist/commands/update-release.js.map +1 -1
- package/dist/commands/update.d.ts +3 -3
- package/dist/commands/update.d.ts.map +1 -1
- package/dist/commands/update.js +29 -25
- package/dist/commands/update.js.map +1 -1
- package/dist/help.d.ts +1 -1
- package/dist/help.d.ts.map +1 -1
- package/dist/help.js +6 -2
- package/dist/help.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -9
- package/dist/index.js.map +1 -1
- package/dist/lib/backup-artifact.d.ts +2 -2
- package/dist/lib/backup-artifact.d.ts.map +1 -1
- package/dist/lib/backup-artifact.js +39 -14
- package/dist/lib/backup-artifact.js.map +1 -1
- package/dist/lib/broker-service.d.ts +2 -0
- package/dist/lib/broker-service.d.ts.map +1 -1
- package/dist/lib/broker-service.js +13 -0
- package/dist/lib/broker-service.js.map +1 -1
- package/dist/lib/confirmation-required.d.ts.map +1 -1
- package/dist/lib/confirmation-required.js +7 -1
- package/dist/lib/confirmation-required.js.map +1 -1
- package/dist/lib/credential-authority.d.ts.map +1 -1
- package/dist/lib/credential-authority.js +13 -1
- package/dist/lib/credential-authority.js.map +1 -1
- package/dist/lib/foreground-hold.d.ts +2 -1
- package/dist/lib/foreground-hold.d.ts.map +1 -1
- package/dist/lib/foreground-hold.js +25 -7
- package/dist/lib/foreground-hold.js.map +1 -1
- package/dist/lib/nearest-word.d.ts +3 -4
- package/dist/lib/nearest-word.d.ts.map +1 -1
- package/dist/lib/nearest-word.js +9 -5
- package/dist/lib/nearest-word.js.map +1 -1
- package/dist/lib/persona-files.d.ts +1 -1
- package/dist/lib/persona-files.d.ts.map +1 -1
- package/dist/lib/persona-files.js +23 -5
- package/dist/lib/persona-files.js.map +1 -1
- package/dist/lib/service-preset-target.d.ts +3 -2
- package/dist/lib/service-preset-target.d.ts.map +1 -1
- package/dist/lib/service-preset-target.js +8 -3
- package/dist/lib/service-preset-target.js.map +1 -1
- package/dist/lib/service-presets.d.ts.map +1 -1
- package/dist/lib/service-presets.js +17 -9
- package/dist/lib/service-presets.js.map +1 -1
- package/dist/lib/service-process.d.ts +2 -2
- package/dist/lib/service-process.d.ts.map +1 -1
- package/dist/lib/service-process.js +7 -4
- package/dist/lib/service-process.js.map +1 -1
- package/dist/lib/spawn-defaults.d.ts +2 -2
- package/dist/lib/spawn-defaults.d.ts.map +1 -1
- package/dist/lib/spawn-defaults.js +3 -3
- package/dist/lib/spawn-defaults.js.map +1 -1
- package/dist/lib/stack-journal.d.ts +2 -2
- package/dist/lib/stack-journal.d.ts.map +1 -1
- package/dist/lib/stack-journal.js +9 -5
- package/dist/lib/stack-journal.js.map +1 -1
- package/dist/lib/store-dir.js +1 -1
- package/dist/lib/store-dir.js.map +1 -1
- package/dist/lib/team-deploy-inspection.d.ts +3 -1
- package/dist/lib/team-deploy-inspection.d.ts.map +1 -1
- package/dist/lib/team-deploy-inspection.js +23 -2
- package/dist/lib/team-deploy-inspection.js.map +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,541 @@
|
|
|
1
|
+
import { isIP } from "node:net";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { accessSync, constants, existsSync, statSync, readdirSync } from "node:fs";
|
|
4
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
5
|
+
import { SERVICE_AUTHORITY_MAX_BYTES, SERVICE_CALLER_PAYLOAD_FLOOR } from "@cotal-ai/core";
|
|
6
|
+
import { parseSeatCapFlag, CommandFailure, assertSingleSpaceBroker, authDir, soleSpaceOf, listSpaceAccounts, canonicalRoot, rootPathProblem, rootControlProblem, findMesh, findPreparedSpace, homeCotalDir, getCurrent, preparedSpaceAt, localMeshesForRoot, presentationOf, parsePositiveIntegerFlag, meshesForRoot, userAuthSpacesOnDisk, readMaintenanceJournal, rootNamesNoSpace, SPACE_NAME_MAX, spaceNameTooLong, } from "@cotal-ai/workspace";
|
|
7
|
+
import { FlagValueRefusal } from "../lib/flag-value-refusal.js";
|
|
8
|
+
import { resolveSpace } from "../lib/status.js";
|
|
9
|
+
import { cotalRoot, homeHoldsStack, linkedCotalRefusal } from "../lib/paths.js";
|
|
10
|
+
import { shellWord } from "../lib/endpoint-errors.js";
|
|
11
|
+
import { managerRecordState } from "../lib/manager-proc.js";
|
|
12
|
+
import { listLedgerFiles } from "../lib/manifest/ledger.js";
|
|
13
|
+
import { freshTeamAttemptSettled, listFreshTeamAttempts, listFreshTeamSummaries } from "../lib/team-fresh.js";
|
|
14
|
+
import { listAdditiveTeamAttempts, retainedAdditiveTeamAttempts } from "../lib/team-additive-attempt.js";
|
|
15
|
+
import { liveMeshProcesses } from "./clean.js";
|
|
16
|
+
import { checkSpaceFlagValue, checkSpaceName } from "./meshes-add.js";
|
|
17
|
+
import { checkLocalSpace } from "./space-registration.js";
|
|
18
|
+
import { checkPublicExchangePort, preparedUpRoot } from "./up-target.js";
|
|
19
|
+
import { retainedOpenSpace } from "../lib/legacy-start.js";
|
|
20
|
+
import { bindReaches, controllerStackApplies, requestsTls } from "./stack-up.js";
|
|
21
|
+
import { readStackJournal, refuseControllerCut } from "../lib/stack-journal.js";
|
|
22
|
+
import { serviceInstances } from "../lib/service-instances.js";
|
|
23
|
+
import { serviceSupervisorStore } from "../lib/service-supervision.js";
|
|
24
|
+
import { serviceInstallIntents } from "../lib/service-install-intent.js";
|
|
25
|
+
import { serviceUninstallIntents } from "../lib/service-uninstall-intent.js";
|
|
26
|
+
import { serviceUnitActionStore } from "../lib/service-unit-action.js";
|
|
27
|
+
import { assertStoreDirArgument, startupStoreProblem } from "../lib/store-dir.js";
|
|
28
|
+
import { parseMaxFileStore, parseAuthTimeout, parseMaxPayload, assertManagerPayload, parseAccountResolver, tlsAddress } from "./up-transport.js";
|
|
29
|
+
import { WILDCARD_HOSTS } from "./up-host.js";
|
|
30
|
+
/** `--recreate-issued-stores <backup-dir>` names a directory the step creates, so it must not exist
|
|
31
|
+
* and its parent must. Checked before anything starts; the step checks again when it creates it. */
|
|
32
|
+
function assertIssuedBackupDirArgument(raw) {
|
|
33
|
+
const dir = resolve(raw);
|
|
34
|
+
const problem = !raw.trim() ? "is empty" : existsSync(dir) ? `${dir} already exists` : !existsSync(dirname(dir)) ? `${dirname(dir)} does not exist` : undefined;
|
|
35
|
+
if (problem)
|
|
36
|
+
throw new CommandFailure("refused", "USAGE_INVALID", `--recreate-issued-stores names a new backup directory, and ${problem}; nothing was started`, { target: { backupDir: dir }, remedy: "name a directory that does not exist yet, inside one that does" });
|
|
37
|
+
}
|
|
38
|
+
/** Launch intent is checked by the kernel before seed or effect preparation. A recovery
|
|
39
|
+
* re-entry supplies its recorded mode explicitly rather than inheriting the new public default. */
|
|
40
|
+
export function validateUpArguments(args) {
|
|
41
|
+
presentationOf(args.values);
|
|
42
|
+
if (typeof args.values.file === "string" && !args.values.file.trim())
|
|
43
|
+
throw new CommandFailure("refused", "USAGE_INVALID", "--file is empty, so it names no manifest; nothing was started or written", { remedy: "name a manifest with --file <cotal.yaml>, or omit --file to start the folder's stack" });
|
|
44
|
+
if (args.values.restore === "")
|
|
45
|
+
throw new CommandFailure("refused", "USAGE_INVALID", "--restore is empty, so it names no backup folder; nothing was started or written", { remedy: "pass the backup folder as --restore <dir>, or omit --restore to start without restoring", selfContained: true });
|
|
46
|
+
// A `.cotal` that is a link, or leads nowhere, is refused before anything reads through it.
|
|
47
|
+
const linked = args.values.root === undefined ? linkedCotalRefusal("up") : undefined;
|
|
48
|
+
if (linked)
|
|
49
|
+
throw linked;
|
|
50
|
+
if (args.values["user-auth"] === true && args.values.open === true)
|
|
51
|
+
throw new CommandFailure("refused", "USAGE_INVALID", "--user-auth and --open contradict - a user-auth space cannot run unauthenticated", { remedy: "drop --open for user auth, or drop --user-auth for an open space" });
|
|
52
|
+
if (args.values.open === true) {
|
|
53
|
+
publicExchangeArgs(args.values, false);
|
|
54
|
+
serviceEndpointsArgs(args.values, false);
|
|
55
|
+
}
|
|
56
|
+
else if (typeof args.values["exchange-public-port"] === "string")
|
|
57
|
+
checkPublicExchangePort(args.values["exchange-public-port"]);
|
|
58
|
+
if (args.values.idp !== undefined && args.values["user-auth"] !== true && !args.values.file)
|
|
59
|
+
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" });
|
|
60
|
+
if (args.values.restore !== undefined && args.values["no-manager"] === true)
|
|
61
|
+
throw new CommandFailure("refused", "USAGE_INVALID", "--no-manager cannot be combined with --restore: the restore needs a manager to commit its state; nothing was restored", { remedy: "rerun the restore without --no-manager" });
|
|
62
|
+
if (args.values["no-manager"] === true && args.values.runtime !== undefined)
|
|
63
|
+
throw new CommandFailure("refused", "USAGE_INVALID", "--no-manager cannot be combined with --runtime because no manager starts", { remedy: "drop --runtime, or drop --no-manager to select a manager runtime" });
|
|
64
|
+
// Only an omitted --runtime selects the default runtime. An empty one, as an unset variable gives,
|
|
65
|
+
// is a value that names no runtime (#7114).
|
|
66
|
+
if (typeof args.values.runtime === "string" && !args.values.runtime.trim())
|
|
67
|
+
throw new CommandFailure("refused", "USAGE_INVALID", "--runtime is empty, so it names no runtime; nothing was started or written", { remedy: "name a runtime, such as `--runtime pty`, or omit --runtime to use the default" });
|
|
68
|
+
if (args.values["no-manager"] === true && args.values["max-sessions"] !== undefined)
|
|
69
|
+
throw new CommandFailure("refused", "USAGE_INVALID", "--no-manager cannot be combined with --max-sessions because no manager starts", { remedy: "drop --max-sessions, or drop --no-manager to set the manager session ceiling" });
|
|
70
|
+
if (args.values.foreground === true && args.values.detach === true)
|
|
71
|
+
throw new CommandFailure("refused", "USAGE_INVALID", "choose --foreground or --detach, not both");
|
|
72
|
+
// Only a manifest launch has a plan to print; without -f every route would start the stack.
|
|
73
|
+
if (args.values["dry-run"] === true && !args.values.file)
|
|
74
|
+
throw new CommandFailure("refused", "USAGE_INVALID", "--dry-run previews a manifest launch and needs -f <cotal.yaml>; nothing was started or written", { remedy: "pass -f <cotal.yaml> to print that manifest's plan; `cotal status` shows what this folder records" });
|
|
75
|
+
// The stack passes its space to its own children as `--space <name>`, which a leading - breaks.
|
|
76
|
+
const named = typeof args.values.space === "string" ? checkSpaceFlagValue(args.values.space) : undefined;
|
|
77
|
+
if (named && !named.ok)
|
|
78
|
+
throw new CommandFailure("refused", "USAGE_INVALID", `${named.message.replace(/^✗ /, "")}; nothing was started or written`, { remedy: named.remedy });
|
|
79
|
+
// A manifest boot checks its own `--server` override against `broker.servers`.
|
|
80
|
+
const serverProblem = args.values.server !== undefined && !args.values.file ? upServerProblem(String(args.values.server)) : undefined;
|
|
81
|
+
if (serverProblem)
|
|
82
|
+
throw new FlagValueRefusal(`${serverProblem}; nothing was started or written`, `pass the IP address the local broker listens on, for example ${serverExample(String(args.values.server))}`);
|
|
83
|
+
// A --host that is no bind host, or a bind that does not serve --server's address, refuses here,
|
|
84
|
+
// before the controller stack writes its journal or trust.
|
|
85
|
+
const hostProblem = !args.values.file ? upHostProblem(args.values.host, args.values.server) : undefined;
|
|
86
|
+
if (hostProblem)
|
|
87
|
+
throw new CommandFailure("refused", "USAGE_INVALID", `${hostProblem.problem}; nothing was started or written`, { remedy: hostProblem.remedy });
|
|
88
|
+
const spaceTooLong = typeof args.values.space === "string" ? spaceNameTooLong(args.values.space) : undefined;
|
|
89
|
+
if (spaceTooLong)
|
|
90
|
+
throw new CommandFailure("refused", "USAGE_INVALID", `${spaceTooLong}; nothing was started or written`, { remedy: `choose a space name of at most ${SPACE_NAME_MAX} characters` });
|
|
91
|
+
// A prepared or controller-owned root has no route that serves TLS, so any TLS input refuses here,
|
|
92
|
+
// once and naming the route that does, before the checks below send it from one TLS form to another.
|
|
93
|
+
const tlsRoot = typeof args.values.root === "string" ? resolve(args.values.root) : freshFolderRoot(args.values) ?? cotalRoot();
|
|
94
|
+
if (!args.values.file && requestsTls(args.values) && !readMaintenanceJournal(tlsRoot))
|
|
95
|
+
controllerStackApplies(tlsRoot, args.values.space ?? folderSpace(), args.values);
|
|
96
|
+
// A --tls-cert broker serves TLS only, and its address says so, so every client dials tls:// and
|
|
97
|
+
// checks the certificate against the address it names.
|
|
98
|
+
if (!args.values.file && args.values["tls-cert"] !== undefined && typeof args.values.server === "string" && /^nats:\/\//i.test(args.values.server))
|
|
99
|
+
throw new CommandFailure("refused", "USAGE_INVALID", "--tls-cert serves the broker over TLS, so --server must be a tls:// address; nothing was started or written", { remedy: `pass --server ${tlsAddress(args.values.server)}`, selfContained: true });
|
|
100
|
+
if (args.values.file !== undefined && args.values.foreground === true)
|
|
101
|
+
throw new CommandFailure("refused", "UNSUPPORTED", "manifest boot has no native foreground custody path; a detached broker was not substituted for the requested terminal-bound lifetime");
|
|
102
|
+
if (args.values.foreground === true && (args.values.json === true || args.values.plain === true))
|
|
103
|
+
throw new CommandFailure("refused", "USAGE_INVALID", "foreground up keeps native terminal custody and cannot produce a finite JSON or plain receipt", { remedy: `omit ${args.values.json ? "--json" : "--plain"} to keep the stack in this terminal, or omit --foreground for a finite receipt from a controller-owned stack` });
|
|
104
|
+
// Flag values and combinations are usage, so they refuse here, before any effect. The run keeps
|
|
105
|
+
// its own checks for maintenance re-entries, which do not pass through this validation.
|
|
106
|
+
parsePositiveIntegerFlag("--max-sessions", args.values["max-sessions"]);
|
|
107
|
+
parseSeatCapFlag("--seat-cap", args.values["seat-cap"]);
|
|
108
|
+
parseMaxFileStore(args.values["max-file-store"]);
|
|
109
|
+
const logFile = args.values["log-file"];
|
|
110
|
+
if (logFile !== undefined && (!logFile.trim() || /[\u0000-\u001f\u007f]/u.test(logFile)))
|
|
111
|
+
throw new CommandFailure("refused", "USAGE_INVALID", "--log-file must be a non-empty file path without control characters");
|
|
112
|
+
const logfileSizeLimit = parsePositiveIntegerFlag("--logfile-size-limit", args.values["logfile-size-limit"]);
|
|
113
|
+
const logfileMaxNum = parsePositiveIntegerFlag("--logfile-max-num", args.values["logfile-max-num"]);
|
|
114
|
+
// A controller restart can use its saved path. A restore still needs an explicit path.
|
|
115
|
+
if (!args.values.file && logFile === undefined && (logfileSizeLimit !== undefined || logfileMaxNum !== undefined)
|
|
116
|
+
&& (args.values.restore !== undefined || readStackJournal(tlsRoot)?.journal.broker?.logFile === undefined))
|
|
117
|
+
throw new CommandFailure("refused", "USAGE_INVALID", "--logfile-size-limit and --logfile-max-num require --log-file");
|
|
118
|
+
// The timeout belongs to the auth callout, which only a user-auth space has. A manifest or a
|
|
119
|
+
// restore starts the broker its own record describes, so neither takes it.
|
|
120
|
+
if (parseAuthTimeout(args.values["auth-timeout"]) !== undefined) {
|
|
121
|
+
if (args.values.open === true)
|
|
122
|
+
throw new CommandFailure("refused", "USAGE_INVALID", "--auth-timeout sets the auth callout's timeout, and an open space has no auth callout; nothing was started", { remedy: "drop --auth-timeout, or start a user-auth space with --user-auth" });
|
|
123
|
+
if (args.values.file !== undefined || args.values.restore !== undefined)
|
|
124
|
+
throw new CommandFailure("refused", "USAGE_INVALID", `--auth-timeout cannot be combined with ${args.values.file !== undefined ? "--file/-f" : "--restore"}, which starts the broker its own record describes; nothing was started`, { remedy: "start it without --auth-timeout; a recorded timeout is rendered again" });
|
|
125
|
+
}
|
|
126
|
+
// Both broker modes render the payload limit. A manifest or a restore starts the broker its own
|
|
127
|
+
// record describes, so neither takes the flag.
|
|
128
|
+
const requestedPayload = parseMaxPayload(args.values["max-payload"]);
|
|
129
|
+
if (requestedPayload !== undefined) {
|
|
130
|
+
if (args.values.file !== undefined || args.values.restore !== undefined)
|
|
131
|
+
throw new CommandFailure("refused", "USAGE_INVALID", `--max-payload cannot be combined with ${args.values.file !== undefined ? "--file/-f" : "--restore"}, which starts the broker its own record describes; nothing was started`, { remedy: "start it without --max-payload; a recorded limit is rendered again" });
|
|
132
|
+
// A space that admits service endpoints is a space whose auth host asserts the caller payload
|
|
133
|
+
// precondition at startup, and that assertion REFUSES below the floor, so the auth context does
|
|
134
|
+
// not open at all. Refusing the pair here is the difference between a usage error before
|
|
135
|
+
// anything starts and a broker that comes up without its auth plane.
|
|
136
|
+
if (args.values["service-endpoints"] === true && requestedPayload < SERVICE_CALLER_PAYLOAD_FLOOR)
|
|
137
|
+
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` });
|
|
138
|
+
if (args.values["no-manager"] !== true)
|
|
139
|
+
assertManagerPayload(requestedPayload);
|
|
140
|
+
}
|
|
141
|
+
// The account resolver belongs to the auth-mode broker configuration as well: the open broker has
|
|
142
|
+
// no operator and so no accounts to resolve, and a manifest or a restore starts the broker its own
|
|
143
|
+
// record describes.
|
|
144
|
+
if (parseAccountResolver(args.values["account-resolver"]) !== undefined) {
|
|
145
|
+
if (args.values.open === true)
|
|
146
|
+
throw new CommandFailure("refused", "USAGE_INVALID", "--account-resolver sets how the broker resolves space accounts, and the open broker configuration has none; nothing was started", { remedy: "drop --account-resolver, or start an auth space without --open" });
|
|
147
|
+
if (args.values.file !== undefined || args.values.restore !== undefined)
|
|
148
|
+
throw new CommandFailure("refused", "USAGE_INVALID", `--account-resolver cannot be combined with ${args.values.file !== undefined ? "--file/-f" : "--restore"}, which starts the broker its own record describes; nothing was started`, { remedy: "start it without --account-resolver; a recorded resolver is rendered again" });
|
|
149
|
+
}
|
|
150
|
+
if (typeof args.values["store-dir"] === "string")
|
|
151
|
+
assertStoreDirArgument(args.values["store-dir"], typeof args.values.root === "string" ? resolve(args.values.root) : freshFolderRoot(args.values) ?? cotalRoot());
|
|
152
|
+
const restoreOnly = args.values["restore-only"];
|
|
153
|
+
if (restoreOnly !== undefined && restoreOnly !== "registry")
|
|
154
|
+
throw new CommandFailure("refused", "USAGE_INVALID", `--restore-only takes registry (got ${JSON.stringify(restoreOnly)})`);
|
|
155
|
+
if (!args.values.restore && (restoreOnly !== undefined || args.values["accept-missing-source"] === true))
|
|
156
|
+
throw new CommandFailure("refused", "USAGE_INVALID", "--restore-only and --accept-missing-source require --restore <dir>");
|
|
157
|
+
if (args.values.file !== undefined && args.values["accept-stale-checkpoint"] === true)
|
|
158
|
+
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");
|
|
159
|
+
if (args.values.restore && (args.values.file !== undefined || args.values.channels !== undefined))
|
|
160
|
+
throw new CommandFailure("refused", "USAGE_INVALID", "--restore cannot be combined with --file/-f or --channels");
|
|
161
|
+
if (args.values.restore && args.values["rotate-sys"] === true)
|
|
162
|
+
throw new CommandFailure("refused", "USAGE_INVALID", "--restore cannot be combined with --rotate-sys", { remedy: "restore the space and verify it first, then rotate: `cotal down`, then `cotal up --rotate-sys`" });
|
|
163
|
+
if (args.values["recreate-issued-stores"] !== undefined) {
|
|
164
|
+
if (args.values.file !== undefined || args.values.restore !== undefined)
|
|
165
|
+
throw new CommandFailure("refused", "USAGE_INVALID", `--recreate-issued-stores cannot be combined with ${args.values.file !== undefined ? "--file/-f" : "--restore"}; nothing was started`, { remedy: "run `cotal up --space <space> --recreate-issued-stores <backup-dir>` on its own first" });
|
|
166
|
+
assertIssuedBackupDirArgument(String(args.values["recreate-issued-stores"]));
|
|
167
|
+
}
|
|
168
|
+
if (args.values["recreate-membership-store"] === true && (args.values.file !== undefined || args.values.restore !== undefined))
|
|
169
|
+
throw new CommandFailure("refused", "USAGE_INVALID", `--recreate-membership-store cannot be combined with ${args.values.file !== undefined ? "--file/-f" : "--restore"}; nothing was started`, { remedy: "run `cotal up --space <space> --recreate-membership-store` on its own first" });
|
|
170
|
+
if (args.values.root !== undefined)
|
|
171
|
+
preparedUpRoot(String(args.values.root));
|
|
172
|
+
else if (!(args.values.file && args.values["dry-run"] === true)) {
|
|
173
|
+
const inheritedRoot = inheritedMachineHomeRoot();
|
|
174
|
+
if (inheritedRoot) {
|
|
175
|
+
if (!freshFolderRoot(args.values))
|
|
176
|
+
throw new CommandFailure("refused", "CONFLICT", "this folder inherits the machine's home .cotal; up did not start a stack in that home root", { target: { root: process.cwd(), inheritedRoot }, remedy: "prepare this folder with `cotal space create <space> --root .`, then run `cotal up` again from this folder" });
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
const home = machineHomeRoot();
|
|
180
|
+
if (home && !homeHoldsStack(home))
|
|
181
|
+
throw new CommandFailure("refused", "CONFLICT", `${home} is your home folder, whose .cotal holds this machine's own records, so up started no stack there`, { target: { root: home }, remedy: "prepare a project folder with `cotal space create <space> --root <dir>`, then run `cotal up` there, or pass --root <dir> from here" });
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (args.values.restore !== undefined)
|
|
185
|
+
refuseControllerCut(args.values.root !== undefined ? preparedUpRoot(String(args.values.root)) : cotalRoot(), "up --restore");
|
|
186
|
+
if (!(args.values.file && args.values["dry-run"] === true)) {
|
|
187
|
+
const root = args.values.root !== undefined ? preparedUpRoot(String(args.values.root)) : freshFolderRoot(args.values) ?? cotalRoot();
|
|
188
|
+
// A path with a control character or a bidirectional formatting mark is refused before any write.
|
|
189
|
+
const pathProblem = rootPathProblem(root) ?? rootPathProblem(canonicalRoot(root));
|
|
190
|
+
if (pathProblem)
|
|
191
|
+
throw new CommandFailure("refused", "USAGE_INVALID", `${pathProblem}; nothing was started or written`, { target: { root }, remedy: "rename the folder without those characters, then run `cotal up` there" });
|
|
192
|
+
const control = rootControlProblem(root);
|
|
193
|
+
if (control)
|
|
194
|
+
throw new CommandFailure("refused", "CONFLICT", `${control.message}; nothing was started or written`, { target: { root, controlDirectory: control.controlDirectory }, remedy: control.project === undefined
|
|
195
|
+
? "prepare a project folder with `cotal space create <space> --root <dir>`, then run `cotal up` there"
|
|
196
|
+
: `run \`cotal up\` from the project folder ${shellWord(control.project)}` });
|
|
197
|
+
assertUpRootWritable(root);
|
|
198
|
+
// A restore creates its own store. A manifest uses the explicit or default store, not a legacy one.
|
|
199
|
+
if (args.values.restore === undefined)
|
|
200
|
+
assertUpStoreWritable(root, typeof args.values["store-dir"] === "string" ? args.values["store-dir"] : args.values.file === undefined ? undefined : join(root, ".cotal", "nats"));
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
/** Every launch route writes under the root's .cotal first, or makes it when it is missing. A folder
|
|
204
|
+
* this account cannot write is refused here, by name, instead of as the raw error of whichever
|
|
205
|
+
* write came first. */
|
|
206
|
+
function assertUpRootWritable(root) {
|
|
207
|
+
// A `.cotal` that is a file is refused by name before any command runs, so only a directory is tested here.
|
|
208
|
+
const path = statSync(join(root, ".cotal"), { throwIfNoEntry: false })?.isDirectory() ? join(root, ".cotal") : root;
|
|
209
|
+
try {
|
|
210
|
+
accessSync(path, constants.W_OK | constants.X_OK);
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
const code = error.code;
|
|
214
|
+
if (code !== "EACCES" && code !== "EPERM" && code !== "EROFS")
|
|
215
|
+
throw error;
|
|
216
|
+
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)}` });
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
/** The broker exits when it cannot write its store, naming the cause only in its own log. The store
|
|
220
|
+
* a start here opens, as `--store-dir` names it, as the stack or legacy records name it, or `.cotal/nats`,
|
|
221
|
+
* is refused here, by name, when this account cannot write it. */
|
|
222
|
+
function assertUpStoreWritable(root, storeDir) {
|
|
223
|
+
const problem = startupStoreProblem(root, storeDir);
|
|
224
|
+
if (problem)
|
|
225
|
+
throw new CommandFailure("refused", "PERMISSION_DENIED", `${problem.message}; nothing was started or written`, { target: { root, path: problem.path }, remedy: problem.remedy });
|
|
226
|
+
}
|
|
227
|
+
/** Why `--server` cannot be the address a local broker listens on, or undefined when it can. Both
|
|
228
|
+
* launch routes need one nats:// or tls:// URL with an IP address and a TCP port, and without this
|
|
229
|
+
* check a typo reached their first write. The message names at most the host, never the whole
|
|
230
|
+
* value, which may carry a credential. */
|
|
231
|
+
function upServerProblem(server) {
|
|
232
|
+
let url;
|
|
233
|
+
try {
|
|
234
|
+
url = new URL(server);
|
|
235
|
+
}
|
|
236
|
+
catch {
|
|
237
|
+
return "--server is not a URL";
|
|
238
|
+
}
|
|
239
|
+
if (url.protocol !== "nats:" && url.protocol !== "tls:")
|
|
240
|
+
return "--server must be a nats:// or tls:// URL";
|
|
241
|
+
if (url.username || url.password)
|
|
242
|
+
return "--server must not embed credentials";
|
|
243
|
+
if (url.search || url.hash || (url.pathname && url.pathname !== "/") || server.includes(","))
|
|
244
|
+
return "--server must be one broker URL without a path, query or fragment";
|
|
245
|
+
if (!url.hostname)
|
|
246
|
+
return "--server names no host";
|
|
247
|
+
// An explicit address is taken as given, so a missing port is never filled in with the default.
|
|
248
|
+
if (!url.port)
|
|
249
|
+
return "--server names no port";
|
|
250
|
+
if (url.port === "0")
|
|
251
|
+
return "--server needs a TCP port from 1 to 65535";
|
|
252
|
+
if (url.hostname.startsWith("["))
|
|
253
|
+
return IPV6_UNSERVED("--server");
|
|
254
|
+
// The broker reports its listener by IP address, which is how both launch routes find it ready.
|
|
255
|
+
if (!isIP(url.hostname))
|
|
256
|
+
return `--server names the host ${url.hostname}, and up needs the IP address the broker listens on`;
|
|
257
|
+
return undefined;
|
|
258
|
+
}
|
|
259
|
+
/** The `--server` a refusal gives as its example: 127.0.0.1 on the port the user passed, or a
|
|
260
|
+
* placeholder when the value names none. */
|
|
261
|
+
function serverExample(server) {
|
|
262
|
+
let port;
|
|
263
|
+
try {
|
|
264
|
+
port = new URL(server).port || undefined;
|
|
265
|
+
}
|
|
266
|
+
catch {
|
|
267
|
+
port = undefined;
|
|
268
|
+
}
|
|
269
|
+
port ??= /:(\d{1,5})\/?$/.exec(server)?.[1];
|
|
270
|
+
const valid = port !== undefined && Number(port) >= 1 && Number(port) <= 65535;
|
|
271
|
+
return `--server ${/^tls:/i.test(server) ? "tls" : "nats"}://127.0.0.1:${valid ? Number(port) : "<port>"}`;
|
|
272
|
+
}
|
|
273
|
+
/** The refusal of a manifest start whose effective `--server` or `broker.servers` lists more than
|
|
274
|
+
* one URL, or undefined when it names one. The start binds one new local broker to one address, so
|
|
275
|
+
* it does not pick an entry. The manifest still validates with a list, which `topology view` shows.
|
|
276
|
+
* The message counts the entries and never repeats them, as one may carry a credential. */
|
|
277
|
+
export function bindListRefusal(command, file, space, server, servers) {
|
|
278
|
+
const count = (server ?? servers)?.split(",").filter((entry) => entry.trim()).length ?? 0;
|
|
279
|
+
if (count < 2)
|
|
280
|
+
return undefined;
|
|
281
|
+
const source = server !== undefined ? "--server" : "broker.servers";
|
|
282
|
+
return new CommandFailure("refused", "USAGE_INVALID", `${source} lists ${count} broker URLs, and ${command} binds a single broker address; nothing was started or written`, {
|
|
283
|
+
target: { space, path: resolve(file), source, entries: count },
|
|
284
|
+
remedy: server !== undefined ? "pass one --server URL for the new broker to listen on" : `set broker.servers in ${file} to the one URL the new broker listens on`,
|
|
285
|
+
selfContained: true,
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
/** The local stack's own clients cannot reach a broker on an IPv6 address, so neither flag may name one. */
|
|
289
|
+
const IPV6_UNSERVED = (flag) => `${flag} names an IPv6 address, and the local stack's own clients cannot reach a broker there`;
|
|
290
|
+
/** Why `--host` cannot be the local broker's bind address beside `server`, with the step that fixes
|
|
291
|
+
* it, or undefined when it can. A wildcard bind keeps a loopback URL, so it pairs with any address.
|
|
292
|
+
* With no `--host` the broker binds 127.0.0.1, so a `--server` naming another IPv4 address needs one. */
|
|
293
|
+
function upHostProblem(host, server) {
|
|
294
|
+
if (host === undefined) {
|
|
295
|
+
const named = server === undefined ? undefined : new URL(server).hostname;
|
|
296
|
+
return named !== undefined && isIP(named) === 4 && named !== "127.0.0.1" && !WILDCARD_HOSTS.has(named)
|
|
297
|
+
? { problem: `--server ${server} names ${named}, and with no --host the broker binds 127.0.0.1, so it would not listen where its clients connect`, remedy: `pass --host ${named} to bind the broker there` }
|
|
298
|
+
: undefined;
|
|
299
|
+
}
|
|
300
|
+
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(host))
|
|
301
|
+
return { problem: `--host ${host} looks like a URL, and it takes a bind host only (an IP or hostname, no scheme)`, remedy: "pass the broker URL with --server instead" };
|
|
302
|
+
if (WILDCARD_HOSTS.has(host))
|
|
303
|
+
return undefined;
|
|
304
|
+
const bare = host.startsWith("[") && host.endsWith("]") ? host.slice(1, -1) : host;
|
|
305
|
+
if (isIP(bare) === 6)
|
|
306
|
+
return { problem: IPV6_UNSERVED("--host"), remedy: "pass an IPv4 bind address, for example --host 127.0.0.1" };
|
|
307
|
+
let url;
|
|
308
|
+
try {
|
|
309
|
+
url = new URL(`nats://${host}:1`);
|
|
310
|
+
}
|
|
311
|
+
catch {
|
|
312
|
+
url = undefined;
|
|
313
|
+
}
|
|
314
|
+
if (!url || url.port !== "1" || url.pathname || url.search || url.hash || url.username || url.password)
|
|
315
|
+
return { problem: `--host ${host} is not a valid bind host: an IP or hostname only, with no port; the port comes from --server (or its default)`, remedy: "pass the port in --server, for example --server nats://127.0.0.1:4222" };
|
|
316
|
+
if (server !== undefined && !bindReaches(host, server))
|
|
317
|
+
return { problem: `--host ${host} and --server ${server} name different addresses: the broker would bind ${host} but be probed at ${new URL(server).hostname}`, remedy: "pass one of them, or make both name the same address" };
|
|
318
|
+
return undefined;
|
|
319
|
+
}
|
|
320
|
+
/** The invoking folder, when a bare `up` makes it its own project root: the only `.cotal` above it is
|
|
321
|
+
* the machine home's. The folder has no records of its own, so `up` starts it as it starts a folder
|
|
322
|
+
* with no `.cotal` above it. A stack an earlier release started in the home is left as it is and
|
|
323
|
+
* still starts from the home. A manifest or a restore still needs a prepared folder. */
|
|
324
|
+
export function freshFolderRoot(values) {
|
|
325
|
+
if (values.root !== undefined || values.file !== undefined || values.restore !== undefined)
|
|
326
|
+
return undefined;
|
|
327
|
+
return inheritedMachineHomeRoot() !== undefined ? resolve(process.cwd()) : undefined;
|
|
328
|
+
}
|
|
329
|
+
/** The space a bare `up` starts in a new project: the name of the project folder, when no `--space`
|
|
330
|
+
* names one and the folder's records name no space. The name passes the rules `space create`
|
|
331
|
+
* applies, and a name another folder on this machine holds, running, stopped or prepared, refuses
|
|
332
|
+
* rather than being taken over. Each refusal names `--space`, before anything is written. */
|
|
333
|
+
export function folderNamedSpace(values) {
|
|
334
|
+
if (values.space !== undefined || values.root !== undefined || values.file !== undefined || values.restore !== undefined)
|
|
335
|
+
return undefined;
|
|
336
|
+
const root = freshFolderRoot(values) ?? (machineHomeRoot() ? undefined : cotalRoot());
|
|
337
|
+
if (root === undefined || !recordsNameNoSpace(root))
|
|
338
|
+
return undefined;
|
|
339
|
+
const space = basename(resolve(root));
|
|
340
|
+
const named = `up names a new project's space after its folder, and`;
|
|
341
|
+
const checked = checkSpaceName(space);
|
|
342
|
+
const invalid = spaceNameTooLong(space) ?? (checked.ok ? undefined : checked.message.replace(/^✗ /, ""));
|
|
343
|
+
if (invalid)
|
|
344
|
+
throw new CommandFailure("refused", "USAGE_INVALID", `${named} the folder name ${JSON.stringify(space)} cannot be one: ${invalid}; nothing was started or written`, { target: { root }, remedy: "name the space with `cotal up --space <name>`", selfContained: true });
|
|
345
|
+
assertSelectionNotMoved(root, space);
|
|
346
|
+
const held = findMesh(space) ?? findPreparedSpace(space);
|
|
347
|
+
if (held)
|
|
348
|
+
throw new CommandFailure("refused", "CONFLICT", `${named} "${space}" is already ${"server" in held ? `registered at ${held.server}` : "prepared"} for ${held.root}; nothing was started or written`, { target: { root, space, heldBy: held.root }, remedy: "name this folder's space with `cotal up --space <name>`, naming one this machine does not use; `cotal space` lists the names in use" });
|
|
349
|
+
checkLocalSpace(space, root, "--root", false);
|
|
350
|
+
return space;
|
|
351
|
+
}
|
|
352
|
+
/** Whether no record names a space for `root`: this machine prepared and registered none there, and
|
|
353
|
+
* it has no `.cotal`, an empty one, or one with no account, stack journal, runtime record, broker
|
|
354
|
+
* configuration or maintenance attempt. */
|
|
355
|
+
export function recordsNameNoSpace(root) {
|
|
356
|
+
if (preparedSpaceAt(root) || meshesForRoot(root).length)
|
|
357
|
+
return false;
|
|
358
|
+
const control = join(root, ".cotal");
|
|
359
|
+
let entries;
|
|
360
|
+
try {
|
|
361
|
+
entries = readdirSync(control);
|
|
362
|
+
}
|
|
363
|
+
catch (error) {
|
|
364
|
+
return error.code === "ENOENT";
|
|
365
|
+
}
|
|
366
|
+
try {
|
|
367
|
+
if (readMaintenanceJournal(root))
|
|
368
|
+
return false;
|
|
369
|
+
}
|
|
370
|
+
catch {
|
|
371
|
+
return false;
|
|
372
|
+
}
|
|
373
|
+
return entries.length === 0 || rootNamesNoSpace(root);
|
|
374
|
+
}
|
|
375
|
+
export function inheritedMachineHomeRoot() {
|
|
376
|
+
const root = machineHomeRoot();
|
|
377
|
+
return root !== undefined && canonicalRoot(process.cwd()) !== canonicalRoot(root) ? root : undefined;
|
|
378
|
+
}
|
|
379
|
+
/** The root this `up` resolves when it is the machine home, whose `.cotal` holds this machine's own records. */
|
|
380
|
+
function machineHomeRoot() {
|
|
381
|
+
const root = cotalRoot();
|
|
382
|
+
return canonicalRoot(root) === canonicalRoot(homedir()) || canonicalRoot(join(root, ".cotal")) === canonicalRoot(homeCotalDir()) ? root : undefined;
|
|
383
|
+
}
|
|
384
|
+
/** The fresh team entry refuses retained custody before `up -f` can write a launch spec,
|
|
385
|
+
* regenerate trust or stop a leftover manager. Only a recorded local root is eligible. */
|
|
386
|
+
export function assertFreshTeamBootOwnership(root, space, mode, own) {
|
|
387
|
+
const current = findMesh(space), prepared = findPreparedSpace(space);
|
|
388
|
+
if (!current && !prepared)
|
|
389
|
+
throw new CommandFailure("refused", "TARGET_UNAVAILABLE", "fresh team boot needs a prepared local space; no checkout or machine-home root was guessed", { target: { root, space } });
|
|
390
|
+
if (current && (current.origin !== "up" || canonicalRoot(current.root) !== canonicalRoot(root)) || prepared && canonicalRoot(prepared.root) !== canonicalRoot(root))
|
|
391
|
+
throw new CommandFailure("refused", "CONFLICT", "the selected space is externally registered or its prepared root moved; no fresh local boot was started", { target: { root, space } });
|
|
392
|
+
if (current && mode && current.mode !== mode)
|
|
393
|
+
throw new CommandFailure("refused", "CONFLICT", "the requested fresh boot changes the locally recorded authentication mode; no trust was replaced", { target: { root, space, recordedMode: current.mode, requestedMode: mode } });
|
|
394
|
+
assertSingleSpaceBroker(authDir(root), "team boot");
|
|
395
|
+
const accounts = listSpaceAccounts(authDir(root));
|
|
396
|
+
if (mode === "open" && accounts.length)
|
|
397
|
+
throw new CommandFailure("refused", "CONFLICT", "the selected root retains a broker account; an open team boot did not bypass its recorded authorization", { target: { root, space } });
|
|
398
|
+
if (accounts.some((hosted) => hosted !== space))
|
|
399
|
+
throw new CommandFailure("refused", "CONFLICT", "the local broker root retains another space's account; team boot did not reassign that trust", { target: { root, space } });
|
|
400
|
+
const userSpaces = userAuthSpacesOnDisk(authDir(root));
|
|
401
|
+
if (mode === "user" && (userSpaces.some((hosted) => hosted !== space) || (accounts.includes(space) && !userSpaces.includes(space))))
|
|
402
|
+
throw new CommandFailure("refused", "CONFLICT", "the selected root holds another user-auth space or static trust without matching user-auth state; team boot did not convert its identity", { target: { root, space } });
|
|
403
|
+
if (mode && mode !== "user" && userSpaces.length)
|
|
404
|
+
throw new CommandFailure("refused", "CONFLICT", "this root retains user-auth state; a static or open team boot did not re-mode its identity", { target: { root, space } });
|
|
405
|
+
if (localMeshesForRoot(root).some((entry) => entry.space !== space))
|
|
406
|
+
throw new CommandFailure("refused", "CONFLICT", "another locally registered space uses this broker root; fresh team boot did not reuse or replace its stack", { target: { root, space } });
|
|
407
|
+
if (readMaintenanceJournal(root))
|
|
408
|
+
throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "this root retains a recovery or maintenance attempt; team boot cannot substitute an ordinary startup", { target: { root, space } });
|
|
409
|
+
const manager = managerRecordState(space, root);
|
|
410
|
+
if (manager.state !== "absent")
|
|
411
|
+
throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "a manager record remains, including when its process appears dead; team boot will not stop or overwrite it", { target: { root, space, state: manager.state, path: manager.path }, remedy: "inspect the recorded manager and reconcile its own lifecycle before a fresh team boot" });
|
|
412
|
+
const processes = liveMeshProcesses(root, space);
|
|
413
|
+
if (processes.length)
|
|
414
|
+
throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "a local component may still own this stack; team boot did not replace it", { target: { root, space, processes } });
|
|
415
|
+
const instances = serviceInstances(space), supervisors = serviceSupervisorStore(space).list();
|
|
416
|
+
if (instances.length || supervisors.length)
|
|
417
|
+
throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "service-controller instances or supervisor receipts remain for this space; their ownership was not replaced by fresh team boot", { target: { root, space, instances: instances.map((row) => row.name), supervisors: supervisors.map((row) => row.name) }, remedy: "inspect each service instance and its native supervisor before booting the whole stack" });
|
|
418
|
+
const actions = serviceUnitActionStore(space).list();
|
|
419
|
+
if (actions.some((row) => row.name !== row.record.value.instanceId))
|
|
420
|
+
throw new CommandFailure("refused", "SCHEMA_INVALID", "a retained native action filename differs from its full instance ID; no fresh boot ownership was inferred", { target: { root, space } });
|
|
421
|
+
const attempts = [
|
|
422
|
+
...serviceInstallIntents(space).map((row) => ({ kind: "install", instanceId: row.name, attemptId: row.record.value.attemptId })),
|
|
423
|
+
...serviceUninstallIntents(space).map((row) => ({ kind: "uninstall", instanceId: row.name, attemptId: row.record.value.attemptId })),
|
|
424
|
+
...actions.map((row) => ({ kind: "unit-action", instanceId: row.name, attemptId: row.record.value.attemptId })),
|
|
425
|
+
];
|
|
426
|
+
if (attempts.length)
|
|
427
|
+
throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "native service attempts remain for this space; a submitted step may have changed state, so fresh team boot did not replace their custody", { target: { root, space, attempts }, remedy: "inspect and reconcile each retained attempt on its original service instance before fresh boot" });
|
|
428
|
+
let ledgers;
|
|
429
|
+
try {
|
|
430
|
+
ledgers = listLedgerFiles(root, { requireReadable: true });
|
|
431
|
+
}
|
|
432
|
+
catch {
|
|
433
|
+
throw new CommandFailure("refused", "TARGET_UNAVAILABLE", "the root's additive ledger directory could not be inspected; no absence of prior owned resources was inferred", { target: { root, space } });
|
|
434
|
+
}
|
|
435
|
+
if (ledgers.valid.length || ledgers.refused.length)
|
|
436
|
+
throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "additive ownership ledgers or unreadable ledger records remain under this root; fresh team boot did not adopt or erase them", { target: { root, space, deploymentIds: ledgers.valid.map(({ ledger }) => ledger.runId), unreadable: ledgers.refused.map(({ path }) => path) }, remedy: "inspect and finish each additive deployment's own lifecycle before a fresh team boot" });
|
|
437
|
+
let additiveAttempts;
|
|
438
|
+
try {
|
|
439
|
+
additiveAttempts = listAdditiveTeamAttempts(root);
|
|
440
|
+
}
|
|
441
|
+
catch {
|
|
442
|
+
throw new CommandFailure("refused", "TARGET_UNAVAILABLE", "the root's additive attempt inventory could not be read; fresh boot did not assume it was empty", { target: { root, space } });
|
|
443
|
+
}
|
|
444
|
+
if (retainedAdditiveTeamAttempts(additiveAttempts).length || additiveAttempts.refused.length)
|
|
445
|
+
throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "an additive deployment attempt remains under this root; its native outcome was not adopted as whole-stack ownership", { target: { root, space, deploymentIds: retainedAdditiveTeamAttempts(additiveAttempts).map((attempt) => attempt.deploymentId), unreadable: additiveAttempts.refused.map(({ path }) => path) } });
|
|
446
|
+
let bootAttempts, summaries;
|
|
447
|
+
try {
|
|
448
|
+
bootAttempts = listFreshTeamAttempts(root);
|
|
449
|
+
summaries = listFreshTeamSummaries(root);
|
|
450
|
+
}
|
|
451
|
+
catch {
|
|
452
|
+
throw new CommandFailure("refused", "TARGET_UNAVAILABLE", "fresh boot attempt or summary records could not be read; no earlier startup was assumed settled", { target: { root, space } });
|
|
453
|
+
}
|
|
454
|
+
const byId = new Map(summaries.valid.map((summary) => [summary.deploymentId, summary]));
|
|
455
|
+
const ownAttempt = own && bootAttempts.valid.find((attempt) => attempt.deploymentId === own.deploymentId);
|
|
456
|
+
if (own && (!ownAttempt || ownAttempt.space !== space || ownAttempt.root !== root || ownAttempt.server !== own.server || ownAttempt.manifestPath !== own.manifestPath || ownAttempt.authMode !== mode || byId.has(own.deploymentId)))
|
|
457
|
+
throw new CommandFailure("refused", "CONFLICT", "this fresh boot's own intent changed or acquired a summary during preparation; no launch spec was written", { target: { root, space, deploymentId: own.deploymentId } });
|
|
458
|
+
const unsettled = bootAttempts.valid.filter((attempt) => attempt.deploymentId !== own?.deploymentId && !freshTeamAttemptSettled(attempt, byId.get(attempt.deploymentId)));
|
|
459
|
+
if (bootAttempts.refused.length || summaries.refused.length || unsettled.length)
|
|
460
|
+
throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "a prior fresh boot attempt lacks a matching readable summary, or an attempt/summary is unreadable; its outcome was not treated as absent", { target: { root, space, unsettledIds: unsettled.map((attempt) => attempt.deploymentId), unreadable: [...bootAttempts.refused, ...summaries.refused].map(({ path }) => path) }, remedy: "inspect each full boot attempt and its original listener before another fresh start; do not retry an unknown boot" });
|
|
461
|
+
}
|
|
462
|
+
/** Validate + assemble the auth-service daemon's public-exchange argv from `up`'s flags. The three
|
|
463
|
+
* flags travel with --user-auth (an open mesh has no exchange to publish); --exchange-public-url
|
|
464
|
+
* and --exchange-trusted-proxy modify the public listener, so they require its port. Returned as
|
|
465
|
+
* an argv ARRAY — the daemon re-exec never shell-interpolates. */
|
|
466
|
+
export function publicExchangeArgs(v, wantUser) {
|
|
467
|
+
const port = v["exchange-public-port"];
|
|
468
|
+
const url = v["exchange-public-url"];
|
|
469
|
+
const proxy = Boolean(v["exchange-trusted-proxy"]);
|
|
470
|
+
const advertised = v["advertised-server"];
|
|
471
|
+
const provisioning = v["agent-provisioning-url"];
|
|
472
|
+
if (port === undefined && url === undefined && !proxy && advertised === undefined && provisioning === undefined)
|
|
473
|
+
return [];
|
|
474
|
+
const flags = [port !== undefined && "--exchange-public-port", url !== undefined && "--exchange-public-url", proxy && "--exchange-trusted-proxy", advertised !== undefined && "--advertised-server", provisioning !== undefined && "--agent-provisioning-url"].filter(Boolean);
|
|
475
|
+
if (!wantUser)
|
|
476
|
+
throw userAuthFlagsRefusal(flags.join(", "));
|
|
477
|
+
if (port === undefined)
|
|
478
|
+
throw new CommandFailure("refused", "USAGE_INVALID", `${flags.join(", ")} ${flags.length === 1 ? "requires" : "require"} --exchange-public-port. Nothing started.`, { remedy: "add --exchange-public-port with the public listener port, or remove the flags that need it" });
|
|
479
|
+
return [
|
|
480
|
+
"--exchange-public-port", port,
|
|
481
|
+
...(url !== undefined ? ["--exchange-public-url", url] : []),
|
|
482
|
+
...(proxy ? ["--exchange-trusted-proxy"] : []),
|
|
483
|
+
...(advertised !== undefined ? ["--advertised-server", advertised] : []),
|
|
484
|
+
...(provisioning !== undefined ? ["--agent-provisioning-url", provisioning] : []),
|
|
485
|
+
];
|
|
486
|
+
}
|
|
487
|
+
/** The daemon argv for `--service-endpoints`: the auth service hosts the service endpoint door and
|
|
488
|
+
* host route. User-auth only; an open mesh has no owner to decide. */
|
|
489
|
+
export function serviceEndpointsArgs(v, wantUser) {
|
|
490
|
+
if (!v["service-endpoints"])
|
|
491
|
+
return [];
|
|
492
|
+
if (!wantUser)
|
|
493
|
+
throw userAuthFlagsRefusal("--service-endpoints");
|
|
494
|
+
return ["--service-endpoints"];
|
|
495
|
+
}
|
|
496
|
+
function userAuthFlagsRefusal(flags) {
|
|
497
|
+
return new CommandFailure("refused", "USAGE_INVALID", `${flags} can only be used with user auth. Nothing started.`, { remedy: "remove the incompatible flags for an open space, or use them with --user-auth instead of --open" });
|
|
498
|
+
}
|
|
499
|
+
/** The space a `cotal up` that names none runs in this folder. The root's sole account names it
|
|
500
|
+
* first, as {@link resolveSpace} does. An open mesh has no account, and its first start replaces
|
|
501
|
+
* the prepared record with a registration, so the space this root's stack journal or its locally
|
|
502
|
+
* started registration names comes next. Without it a second `up` in the same folder resolved the
|
|
503
|
+
* default space and refused its own mesh. Several names there are refused, never picked. Then the
|
|
504
|
+
* space prepared here. A stopped open root with none prepared names its space in the broker
|
|
505
|
+
* configuration its last start rendered. Then the default.
|
|
506
|
+
*
|
|
507
|
+
* Only `up` asks this. `resolveSpace` also decides whether identity cleanup may attribute a root to
|
|
508
|
+
* a space (`reset-space-plan.ts`) and, through `resolveRuntimeSpace`, which space a legacy `down`
|
|
509
|
+
* removes credentials for; those keep their own answer. */
|
|
510
|
+
export function folderSpace() {
|
|
511
|
+
const root = cotalRoot();
|
|
512
|
+
if (soleSpaceOf(authDir(root)) === undefined) {
|
|
513
|
+
const named = [...new Set([readStackJournal(root)?.journal.space, ...localMeshesForRoot(root).map((m) => m.space)])].filter((s) => s !== undefined);
|
|
514
|
+
if (named.length > 1)
|
|
515
|
+
throw new CommandFailure("refused", "CONFLICT", `this folder's stack and registrations name ${named.length} spaces (${named.map((s) => `"${s}"`).join(", ")}), so up cannot pick one`, {
|
|
516
|
+
target: { root, spaces: named },
|
|
517
|
+
remedy: "name the space to run with `--space`",
|
|
518
|
+
});
|
|
519
|
+
if (named.length === 1)
|
|
520
|
+
return named[0];
|
|
521
|
+
// A stopped open root holds no account, so its broker configuration names its space.
|
|
522
|
+
const deployed = preparedSpaceAt(root) ? undefined : retainedOpenSpace(root);
|
|
523
|
+
if (deployed)
|
|
524
|
+
return deployed;
|
|
525
|
+
}
|
|
526
|
+
return resolveSpace(process.cwd());
|
|
527
|
+
}
|
|
528
|
+
/** A bare `up` in a folder that names no space starts a space it names itself. When the selected
|
|
529
|
+
* space is prepared in a folder that no longer exists, as after that folder was moved, that space is
|
|
530
|
+
* not what was meant, so `up` refuses with the step that prepares the selection here. */
|
|
531
|
+
export function assertSelectionNotMoved(root, space) {
|
|
532
|
+
const current = getCurrent();
|
|
533
|
+
const prepared = current === undefined || current === space ? undefined : findPreparedSpace(current);
|
|
534
|
+
if (!prepared || existsSync(prepared.root))
|
|
535
|
+
return;
|
|
536
|
+
throw new CommandFailure("refused", "TARGET_UNAVAILABLE", `the selected space "${current}" is prepared in ${prepared.root}, which no longer exists, and this folder names no space, so up did not start "${space}" here`, {
|
|
537
|
+
target: { root, space: current, preparedRoot: prepared.root },
|
|
538
|
+
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}`,
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
//# sourceMappingURL=up-args.js.map
|