@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,549 @@
|
|
|
1
|
+
import { mkdirSync } from "node:fs";
|
|
2
|
+
import { join, resolve } from "node:path";
|
|
3
|
+
import { isReachable, DEFAULT_SERVER } from "@cotal-ai/core";
|
|
4
|
+
import { CommandFailure, isCommandFailure, brokerAddressForDisplay, canonicalRoot, getCurrent, loadMeshes, oneLine, writeResult, workspaceSecretStore } from "@cotal-ai/workspace";
|
|
5
|
+
import { FlagValueRefusal } from "../lib/flag-value-refusal.js";
|
|
6
|
+
import { resolveAuthProvider } from "../lib/auth-proc.js";
|
|
7
|
+
import { c, stderrLine } from "../ui.js";
|
|
8
|
+
import { cotalPath, cotalRoot } from "../lib/paths.js";
|
|
9
|
+
import { displayCmd } from "../lib/self-exec.js";
|
|
10
|
+
import { shellWord } from "../lib/endpoint-errors.js";
|
|
11
|
+
import { clearManagerArtifacts, managerLogDisplayPath, stopManager } from "../lib/manager-proc.js";
|
|
12
|
+
import { ManifestError, formatIssue, loadManifest } from "../lib/manifest/index.js";
|
|
13
|
+
import { UnusableFile } from "../lib/unusable-file.js";
|
|
14
|
+
import { buildLaunchSpec, genRunId, manifestToChannels, preflightConnectors, writeLaunchSpec } from "../lib/manifest/apply.js";
|
|
15
|
+
import { writeFreshTeamAttempt, writeFreshTeamSummary } from "../lib/team-fresh.js";
|
|
16
|
+
import { renderUpPlan, renderInherited, renderWarnings } from "../lib/manifest/render.js";
|
|
17
|
+
import { idpUrlProblem, serverUrlProblems } from "../lib/manifest/resolve.js";
|
|
18
|
+
import { failManifest, refuseManifestSpaceMismatch } from "./topology.js";
|
|
19
|
+
import {} from "./stack-up.js";
|
|
20
|
+
import { preflightUserStack } from "./stack-user-auth.js";
|
|
21
|
+
import { preflightRuntime } from "../ext-loader.js";
|
|
22
|
+
import { resolveTransport, assertTlsIntentServed, commitTransportPolicy, tlsAddress, announceTransport, assertServesDialHost, refuseUnnamedLastStore, refuseMissingNamedStore, checkStartStore, } from "./up-transport.js";
|
|
23
|
+
import { reconcileHostAndServer, assertFreshTeamBindAvailable } from "./up-host.js";
|
|
24
|
+
import { refuseRegisteredAddress, postStart, recreateDeletedStreams } from "./up-stores.js";
|
|
25
|
+
import { authSetup } from "./up-broker-auth.js";
|
|
26
|
+
import { bindListRefusal, assertFreshTeamBootOwnership } from "./up-args.js";
|
|
27
|
+
import { prepareBrokerStart, startMeshDetached, assertBrokerAddressFree, recordOurMesh } from "./up-detach.js";
|
|
28
|
+
/** The fresh boot's read-only preparation, shared by the controller team boot. It runs the same
|
|
29
|
+
* manifest load, override, mode agreement, ownership, bind, runtime, reachability and connector
|
|
30
|
+
* refusals as the retained `upManifest` fresh path, in the same order, and writes nothing. */
|
|
31
|
+
export async function prepareFreshTeamBoot(file, opts) {
|
|
32
|
+
const flags = { ...opts, dryRun: false, freshTeamBoot: true };
|
|
33
|
+
let prepared;
|
|
34
|
+
try {
|
|
35
|
+
prepared = loadManifest(resolve(file));
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
throw new CommandFailure("refused", "SCHEMA_INVALID", "the fresh boot manifest changed or could not be resolved before startup; no broker was started", { target: { path: resolve(file), space: opts.space } });
|
|
39
|
+
}
|
|
40
|
+
if (opts.space !== prepared.manifest.space)
|
|
41
|
+
throw new CommandFailure("refused", "CONFLICT", "the fresh boot manifest no longer names the selected space; no broker was started", { target: { selectedSpace: opts.space, declaredSpace: prepared.manifest.space } });
|
|
42
|
+
const declared = prepared.manifest.broker?.auth;
|
|
43
|
+
if (opts.open && declared === "user")
|
|
44
|
+
throw new CommandFailure("refused", "CONFLICT", "--open contradicts this manifest's user-auth mode; no trust or broker was changed", { target: { space: opts.space } });
|
|
45
|
+
if (opts.userAuth && declared !== "user")
|
|
46
|
+
throw new CommandFailure("refused", "CONFLICT", "--user-auth contradicts this manifest's declared auth mode; no trust or broker was changed", { target: { space: opts.space } });
|
|
47
|
+
if (opts.idp && declared !== "user")
|
|
48
|
+
throw new CommandFailure("refused", "CONFLICT", "--idp needs this manifest's user-auth mode; no trust or broker was changed", { target: { space: opts.space } });
|
|
49
|
+
const idpProblem = opts.idp === undefined ? undefined : idpUrlProblem(opts.idp, "--idp");
|
|
50
|
+
if (idpProblem)
|
|
51
|
+
throw new CommandFailure("refused", "SCHEMA_INVALID", idpProblem, { target: { space: opts.space } });
|
|
52
|
+
const serverProblems = opts.server === undefined ? [] : serverUrlProblems(opts.server, "--server");
|
|
53
|
+
if (serverProblems.length)
|
|
54
|
+
throw new CommandFailure("refused", "SCHEMA_INVALID", serverProblems.join("; "), { target: { space: opts.space } });
|
|
55
|
+
const list = bindListRefusal("team boot", file, opts.space, opts.server, prepared.manifest.broker?.servers);
|
|
56
|
+
if (list)
|
|
57
|
+
throw list;
|
|
58
|
+
const { prepared: eff, hostSource, serverSource } = applyUpOverrides(prepared, flags);
|
|
59
|
+
const m = eff.manifest;
|
|
60
|
+
const host = m.broker?.host ?? "127.0.0.1";
|
|
61
|
+
const server = m.broker?.host ? reconcileHostAndServer(m.broker.host, m.broker?.servers, hostSource, serverSource) : (m.broker?.servers ?? DEFAULT_SERVER);
|
|
62
|
+
const open = m.broker?.auth === false;
|
|
63
|
+
const mode = open ? "open" : m.broker?.auth === "user" ? "user" : "auth";
|
|
64
|
+
const runtime = m.runtime ?? "pty";
|
|
65
|
+
if (open && (m.defaults?.deliveryClass === "durable" || m.channels.some((channel) => channel.deliveryClass === "durable")))
|
|
66
|
+
throw new CommandFailure("refused", "UNSUPPORTED", "this open manifest explicitly requests durable channel delivery, but the open broker has no delivery daemon; no channel metadata or broker was written", { target: { space: m.space }, remedy: "use static/user authentication for durable delivery, or declare live delivery for an open mesh" });
|
|
67
|
+
const other = loadMeshes().filter((row) => row.space !== m.space && row.server === server);
|
|
68
|
+
if (other.length)
|
|
69
|
+
throw new CommandFailure("refused", "CONFLICT", "another local registration names this exact broker address; fresh team boot did not create a listener over its recorded target", { target: { space: m.space, server: brokerAddressForDisplay(server) ?? "not displayable", otherSpaces: other.map((row) => row.space) } });
|
|
70
|
+
assertFreshTeamBootOwnership(cotalRoot(), m.space, mode);
|
|
71
|
+
await assertFreshTeamBindAvailable(server, host, m.space);
|
|
72
|
+
try {
|
|
73
|
+
await preflightRuntime(runtime);
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
throw new CommandFailure("refused", "DEPENDENCY_UNAVAILABLE", "the requested runtime did not pass preflight; no fresh boot intent or broker was started", { target: { space: m.space, runtime }, remedy: error instanceof Error ? error.message : "inspect the selected runtime provider" });
|
|
77
|
+
}
|
|
78
|
+
if (await isReachable(server))
|
|
79
|
+
throw new CommandFailure("refused", "CONFLICT", "the selected address already has a broker; fresh boot did not adopt it or start a competing listener", { target: { space: m.space, server: brokerAddressForDisplay(server) ?? "not displayable" } });
|
|
80
|
+
const conn = await preflightConnectors(prepared);
|
|
81
|
+
if (conn)
|
|
82
|
+
throw new CommandFailure("refused", "DEPENDENCY_UNAVAILABLE", "connector preflight failed before the fresh boot intent; no native effect was requested", { target: { space: m.space }, remedy: conn });
|
|
83
|
+
return { root: canonicalRoot(cotalRoot()), space: m.space, server, host: m.broker?.host, mode, idp: m.broker?.idp, runtime, manifestPath: resolve(file), prepared: eff, transport: assertServesDialHost(opts.transport, new URL(server).hostname), maxSessions: opts.maxSessions, logFile: m.broker?.logFile, logfileSizeLimit: m.broker?.logfileSizeLimit, logfileMaxNum: m.broker?.logfileMaxNum };
|
|
84
|
+
}
|
|
85
|
+
/** A stack's auth mode in words, and the manifest's `broker.auth` value that declares it. */
|
|
86
|
+
const RESUME_MODE = { open: { words: "open", field: "false" }, auth: { words: "static auth", field: "static" }, user: { words: "user auth", field: "user" } };
|
|
87
|
+
/** A team boot that resumes one exact stopped controller stack whose manager was never attempted.
|
|
88
|
+
* The same manifest load, agreement, durable-on-open, runtime, reachability and connector refusals
|
|
89
|
+
* as {@link prepareFreshTeamBoot}, without the fresh zero-instance ownership gate: that gate is
|
|
90
|
+
* replaced by the stopped-stack eligibility the caller binds under its lock. The manifest may not
|
|
91
|
+
* move the recorded broker: its server must equal the recorded one, and a declared bind host must
|
|
92
|
+
* equal the recorded host. Writes nothing. */
|
|
93
|
+
export async function prepareResumeTeamBoot(file, opts) {
|
|
94
|
+
let prepared;
|
|
95
|
+
try {
|
|
96
|
+
prepared = loadManifest(resolve(file));
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
throw new CommandFailure("refused", "SCHEMA_INVALID", "the team manifest changed or could not be resolved before startup; nothing was resumed", { target: { path: resolve(file), space: opts.space } });
|
|
100
|
+
}
|
|
101
|
+
if (opts.space !== prepared.manifest.space)
|
|
102
|
+
throw new CommandFailure("refused", "CONFLICT", "the team manifest no longer names the selected space; nothing was resumed", { target: { selectedSpace: opts.space, declaredSpace: prepared.manifest.space } });
|
|
103
|
+
const { prepared: eff, hostSource, serverSource } = applyUpOverrides(prepared, { transport: opts.transport, dryRun: false, freshTeamBoot: true });
|
|
104
|
+
const m = eff.manifest;
|
|
105
|
+
const server = m.broker?.host ? reconcileHostAndServer(m.broker.host, m.broker?.servers, hostSource, serverSource) : (m.broker?.servers ?? DEFAULT_SERVER);
|
|
106
|
+
const open = m.broker?.auth === false;
|
|
107
|
+
const mode = open ? "open" : m.broker?.auth === "user" ? "user" : "auth";
|
|
108
|
+
const runtime = m.runtime ?? "pty";
|
|
109
|
+
// Each setting the manifest moves, with both values and the manifest change that keeps the recorded one.
|
|
110
|
+
const shown = (address) => brokerAddressForDisplay(address) ?? "not displayable";
|
|
111
|
+
const moved = [
|
|
112
|
+
...(server !== opts.recorded.server ? [{ name: "broker address", recorded: shown(opts.recorded.server), declared: shown(server), keep: `set \`broker.servers\` to ${shown(opts.recorded.server)}` }] : []),
|
|
113
|
+
...(m.broker?.host !== undefined && m.broker.host !== opts.recorded.host ? [{ name: "bind host", recorded: opts.recorded.host ?? "none", declared: m.broker.host, keep: opts.recorded.host ? `set \`broker.host\` to ${opts.recorded.host}` : "remove `broker.host`" }] : []),
|
|
114
|
+
...(mode !== opts.recorded.mode ? [{ name: "auth mode", recorded: RESUME_MODE[opts.recorded.mode].words, declared: RESUME_MODE[mode].words, keep: `set \`broker.auth\` to \`${RESUME_MODE[opts.recorded.mode].field}\`` }] : []),
|
|
115
|
+
];
|
|
116
|
+
if (moved.length) {
|
|
117
|
+
const named = moved.map((row) => `${row.name} (recorded ${row.recorded}, declared ${row.declared})`);
|
|
118
|
+
throw new CommandFailure("refused", "CONFLICT", `the manifest differs from the recorded stopped stack in its ${named.length > 1 ? `${named.slice(0, -1).join(", ")} and ${named.at(-1)}` : named[0]}; nothing was resumed`, {
|
|
119
|
+
target: { space: m.space, recorded: { ...opts.recorded, server: shown(opts.recorded.server) }, declared: { server: shown(server), host: m.broker?.host ?? null, mode } },
|
|
120
|
+
remedy: `${moved.map((row) => row.keep).join(" and ")} in the manifest to resume this stack, or boot the manifest as a new space in another folder prepared with \`cotal space create <space>\``,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
if (open && (m.defaults?.deliveryClass === "durable" || m.channels.some((channel) => channel.deliveryClass === "durable")))
|
|
124
|
+
throw new CommandFailure("refused", "UNSUPPORTED", "this open manifest explicitly requests durable channel delivery, but the open broker has no delivery daemon; nothing was resumed", { target: { space: m.space } });
|
|
125
|
+
const other = loadMeshes().filter((row) => row.space !== m.space && row.server === server);
|
|
126
|
+
if (other.length)
|
|
127
|
+
throw new CommandFailure("refused", "CONFLICT", "another local registration names this exact broker address; the stopped stack was not resumed over it", { target: { space: m.space, otherSpaces: other.map((row) => row.space) } });
|
|
128
|
+
try {
|
|
129
|
+
await preflightRuntime(runtime);
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
throw new CommandFailure("refused", "DEPENDENCY_UNAVAILABLE", "the requested runtime did not pass preflight; nothing was resumed", { target: { space: m.space, runtime }, remedy: error instanceof Error ? error.message : "inspect the selected runtime provider" });
|
|
133
|
+
}
|
|
134
|
+
if (await isReachable(server))
|
|
135
|
+
throw new CommandFailure("refused", "CONFLICT", "the recorded broker address already answers; the stopped stack was not resumed over it", { target: { space: m.space, server: brokerAddressForDisplay(server) ?? "not displayable" } });
|
|
136
|
+
const conn = await preflightConnectors(prepared);
|
|
137
|
+
if (conn)
|
|
138
|
+
throw new CommandFailure("refused", "DEPENDENCY_UNAVAILABLE", "connector preflight failed; nothing was resumed", { target: { space: m.space }, remedy: conn });
|
|
139
|
+
return { root: canonicalRoot(cotalRoot()), space: m.space, server, host: opts.recorded.host, mode, idp: m.broker?.idp, runtime, manifestPath: resolve(file), prepared: eff, transport: assertServesDialHost(opts.transport, new URL(server).hostname), maxSessions: undefined, logFile: m.broker?.logFile, logfileSizeLimit: m.broker?.logfileSizeLimit, logfileMaxNum: m.broker?.logfileMaxNum };
|
|
140
|
+
}
|
|
141
|
+
/** The recorded broker transport of a prepared root, decided without persisting anything: a team
|
|
142
|
+
* boot names no TLS flags, so it inherits the root's recorded policy exactly as a bare `up` does. */
|
|
143
|
+
export function recordedBrokerTransport(root) {
|
|
144
|
+
return resolveTransport({}, undefined, root, { persist: false, quiet: true });
|
|
145
|
+
}
|
|
146
|
+
/** Recheck, under the fresh boot's own lock, the ownership and bind refusals that a concurrent
|
|
147
|
+
* writer could have invalidated after {@link prepareFreshTeamBoot}. */
|
|
148
|
+
export async function recheckFreshTeamBoot(plan, own) {
|
|
149
|
+
assertFreshTeamBootOwnership(plan.root, plan.space, plan.mode, own ? { deploymentId: own.deploymentId, server: plan.server, manifestPath: plan.manifestPath } : undefined);
|
|
150
|
+
await assertFreshTeamBindAvailable(plan.server, plan.host ?? "127.0.0.1", plan.space);
|
|
151
|
+
}
|
|
152
|
+
/** The native callbacks a controller stack start uses, shared by `cotal up` and a controller team
|
|
153
|
+
* boot so both prepare, seed and record through the same native path. */
|
|
154
|
+
export function controllerStackNative() {
|
|
155
|
+
return {
|
|
156
|
+
prepareBroker: async (opts) => {
|
|
157
|
+
const prepared = await prepareBrokerStart({ transport: opts.transport, server: opts.server, space: opts.space, ...(opts.open ? { open: true } : {}), ...(opts.userAuth ? { userAuth: opts.userAuth } : {}), ...(opts.host ? { host: opts.host } : {}), ...(opts.wsPort !== undefined ? { wsPort: opts.wsPort } : {}), ...(opts.storeDir ? { storeDir: opts.storeDir } : {}), ...(opts.existingStore ? { existingStore: opts.existingStore } : {}), ...(opts.maxFileStore !== undefined ? { maxFileStore: opts.maxFileStore } : {}), ...(opts.logFile !== undefined ? { logFile: opts.logFile } : {}), ...(opts.logfileSizeLimit !== undefined ? { logfileSizeLimit: opts.logfileSizeLimit } : {}), ...(opts.logfileMaxNum !== undefined ? { logfileMaxNum: opts.logfileMaxNum } : {}), ...(opts.authTimeout !== undefined ? { authTimeout: opts.authTimeout } : {}), ...(opts.maxPayload !== undefined ? { maxPayload: opts.maxPayload } : {}), ...(opts.accountResolver !== undefined ? { accountResolver: opts.accountResolver } : {}), ...(opts.noManager ? { noManager: true } : {}), ...(opts.seed !== undefined ? { seed: opts.seed } : opts.channels ? { channels: opts.channels } : {}), quietBoot: true });
|
|
158
|
+
return { root: prepared.root, server: prepared.server, space: prepared.space, storeDir: prepared.storeDir, transport: prepared.transport, ...(prepared.setup ? { setup: { mintProvisioner: prepared.setup.mintProvisioner, wsPort: prepared.setup.wsPort, moveWebsocketPort: prepared.setup.moveWebsocketPort } } : {}), ...(prepared.setup?.prepared && prepared.setup.stateDir ? { user: { prepared: prepared.setup.prepared, stateDir: prepared.setup.stateDir } } : {}), confPath: prepared.confPath, bin: prepared.bin, source: prepared.source, version: prepared.version, seedFile: prepared.seedFile, ...(prepared.setup?.authTimeout !== undefined ? { authTimeout: prepared.setup.authTimeout } : {}), ...(prepared.maxPayload !== undefined ? { maxPayload: prepared.maxPayload } : {}), ...(prepared.setup?.accountResolver !== undefined ? { accountResolver: prepared.setup.accountResolver } : {}) };
|
|
159
|
+
},
|
|
160
|
+
initializeStreams: async (server, space, setup, seedFile, recreateIssuedStores, recreateMembershipStore) => postStart(server, space, setup && { creds: await setup.mintProvisioner() }, seedFile, recreateIssuedStores, recreateMembershipStore, true),
|
|
161
|
+
recreateDeletedStreams: ({ seed, ...opts }) => recreateDeletedStreams({ ...opts, ...(seed !== undefined ? { seed: seed } : {}) }),
|
|
162
|
+
recordMesh: (entry) => recordOurMesh({ ...entry, ts: new Date().toISOString() }, "started", true),
|
|
163
|
+
commitTransport: (root, chosen, limits) => commitTransportPolicy(root, chosen, true, undefined, limits),
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
/** The structured refusal for a manifest `up -f` cannot use: the located problems of one that does
|
|
167
|
+
* not validate, or the read failure of one that cannot be read. Both exit 1, as the text path does. */
|
|
168
|
+
export function manifestFileRefusal(e, path) {
|
|
169
|
+
if (e instanceof ManifestError) {
|
|
170
|
+
// One line per problem: a parse error's code frame stays out of the sentence.
|
|
171
|
+
const issues = e.issues.map((issue) => ({ ...issue, message: issue.message.split("\n")[0].replace(/(at line \d+, column \d+):$/, "$1") }));
|
|
172
|
+
return new CommandFailure("refused", "SCHEMA_INVALID", `the manifest does not validate, so nothing was started: ${issues.map((issue) => formatIssue(e.file, issue)).join("; ")}`, { target: { path, issues }, remedy: "fix each named problem and run the command again" });
|
|
173
|
+
}
|
|
174
|
+
// A refusal that already names the problem, such as a directory given as the manifest, keeps its
|
|
175
|
+
// own sentence and remedy, as the text path prints them.
|
|
176
|
+
if (e instanceof CommandFailure)
|
|
177
|
+
return e;
|
|
178
|
+
const code = e?.code;
|
|
179
|
+
return new UnusableFile(code === "ENOENT" ? `manifest file not found: ${path}` : `the manifest ${path} could not be read (${code ?? e.message})`, { file: path });
|
|
180
|
+
}
|
|
181
|
+
/** `cotal up -f cotal.yaml` — bring up a FRESH mesh from a manifest (broker + channels + booted
|
|
182
|
+
* agents). `up -f` is a broker-CREATION command: `broker.servers` is the bind address for the NEW
|
|
183
|
+
* local broker, never a connect target. A broker already reachable there (local OR remote) means
|
|
184
|
+
* fresh boot refusal; an unbindable/remote address makes the broker fail to start (no silent
|
|
185
|
+
* local fallback). It owns the whole space, so `cotal down` tears it down without an additive
|
|
186
|
+
* ownership ledger. */
|
|
187
|
+
export async function upManifest(file, opts) {
|
|
188
|
+
let prepared;
|
|
189
|
+
try {
|
|
190
|
+
prepared = loadManifest(resolve(file), opts.logFile);
|
|
191
|
+
}
|
|
192
|
+
catch (e) {
|
|
193
|
+
if (opts.freshTeamBoot)
|
|
194
|
+
throw new CommandFailure("refused", "SCHEMA_INVALID", "the fresh boot manifest changed or could not be resolved before startup; no broker was started", { target: { path: resolve(file), space: opts.space } });
|
|
195
|
+
failManifest(e);
|
|
196
|
+
}
|
|
197
|
+
if (opts.freshTeamBoot && opts.space !== prepared.manifest.space)
|
|
198
|
+
throw new CommandFailure("refused", "CONFLICT", "the fresh boot manifest no longer names the selected space; no broker was started", { target: { selectedSpace: opts.space, declaredSpace: prepared.manifest.space } });
|
|
199
|
+
refuseManifestSpaceMismatch(prepared, opts.space);
|
|
200
|
+
// The auth-mode sources (flags vs manifest) must AGREE — any mismatch names both sources and the
|
|
201
|
+
// exact correction in one sentence (a no-fallback identity decision, never a bare enum error).
|
|
202
|
+
const declared = prepared.manifest.broker?.auth;
|
|
203
|
+
const declaredStr = declared === undefined ? '"static" (the unset default)' : JSON.stringify(declared);
|
|
204
|
+
if (opts.open && declared === "user") {
|
|
205
|
+
if (opts.freshTeamBoot)
|
|
206
|
+
throw new CommandFailure("refused", "CONFLICT", "--open contradicts this manifest's user-auth mode; no trust or broker was changed", { target: { space: prepared.manifest.space } });
|
|
207
|
+
console.error(c.red('✗ --open contradicts this manifest\'s broker.auth: "user" - a user-auth space cannot run unauthenticated. Drop --open, or change the manifest.'));
|
|
208
|
+
process.exit(1);
|
|
209
|
+
}
|
|
210
|
+
if (opts.userAuth && declared !== "user") {
|
|
211
|
+
if (opts.freshTeamBoot)
|
|
212
|
+
throw new CommandFailure("refused", "CONFLICT", "--user-auth contradicts this manifest's declared auth mode; no trust or broker was changed", { target: { space: prepared.manifest.space } });
|
|
213
|
+
stderrLine("✗ ", `--user-auth requires manifest broker.auth: "user" (this manifest's broker.auth is ${declaredStr}). Either set broker.auth: "user" in the manifest, or drop --user-auth.`, c.red);
|
|
214
|
+
process.exit(1);
|
|
215
|
+
}
|
|
216
|
+
if (opts.idp && declared !== "user") {
|
|
217
|
+
if (opts.freshTeamBoot)
|
|
218
|
+
throw new CommandFailure("refused", "CONFLICT", "--idp needs this manifest's user-auth mode; no trust or broker was changed", { target: { space: prepared.manifest.space } });
|
|
219
|
+
stderrLine("✗ ", `--idp is for user-auth spaces (this manifest's broker.auth is ${declaredStr}) - set broker.auth: "user" in the manifest, or drop --idp.`, c.red);
|
|
220
|
+
process.exit(1);
|
|
221
|
+
}
|
|
222
|
+
const idpProblem = opts.idp === undefined ? undefined : idpUrlProblem(opts.idp, "--idp");
|
|
223
|
+
if (idpProblem) {
|
|
224
|
+
if (opts.freshTeamBoot)
|
|
225
|
+
throw new CommandFailure("refused", "SCHEMA_INVALID", idpProblem, { target: { space: prepared.manifest.space } });
|
|
226
|
+
stderrLine("✗ ", `${idpProblem}`, c.red);
|
|
227
|
+
process.exit(1);
|
|
228
|
+
}
|
|
229
|
+
const serverProblems = opts.server === undefined ? [] : serverUrlProblems(opts.server, "--server");
|
|
230
|
+
if (serverProblems.length) {
|
|
231
|
+
if (opts.freshTeamBoot)
|
|
232
|
+
throw new CommandFailure("refused", "SCHEMA_INVALID", serverProblems.join("; "), { target: { space: prepared.manifest.space } });
|
|
233
|
+
for (const problem of serverProblems)
|
|
234
|
+
stderrLine("✗ ", `${problem}`, c.red);
|
|
235
|
+
process.exit(1);
|
|
236
|
+
}
|
|
237
|
+
// Each entry of a list is checked above; the start still needs one address, before any parse of it.
|
|
238
|
+
const list = bindListRefusal(opts.freshTeamBoot ? "team boot" : "up -f", file, prepared.manifest.space, opts.server, prepared.manifest.broker?.servers);
|
|
239
|
+
if (list)
|
|
240
|
+
throw list;
|
|
241
|
+
// Apply CLI overrides to one effective manifest (flag > manifest > default) so render + seed +
|
|
242
|
+
// broker + launch all agree on the same values.
|
|
243
|
+
const { prepared: eff, hostSource, serverSource } = applyUpOverrides(prepared, opts);
|
|
244
|
+
const m = eff.manifest;
|
|
245
|
+
if (m.broker?.logFile === undefined && (opts.logfileSizeLimit !== undefined || opts.logfileMaxNum !== undefined))
|
|
246
|
+
throw new CommandFailure("refused", "USAGE_INVALID", "--logfile-size-limit and --logfile-max-num require --log-file or broker.logFile in the manifest", { remedy: "pass --log-file <path>, set broker.logFile in the manifest, or omit the rotation flags" });
|
|
247
|
+
const host = m.broker?.host ?? "127.0.0.1";
|
|
248
|
+
// Same bind-vs-probe reconciliation as the flag path: a manifest that sets `broker.host` without
|
|
249
|
+
// an explicit `broker.servers` would otherwise bind one address and be probed at another.
|
|
250
|
+
const server = m.broker?.host ? reconcileHostAndServer(m.broker.host, m.broker?.servers, hostSource, serverSource) : (m.broker?.servers ?? DEFAULT_SERVER);
|
|
251
|
+
assertTlsIntentServed(server, opts.transport, opts.server !== undefined ? "--server" : "the manifest's broker.servers");
|
|
252
|
+
// A --tls-cert broker serves TLS only, so its address says tls://, as a bare up requires of --server.
|
|
253
|
+
if (opts.transport.kind === "tls-required" && server.split(",").some((url) => /^nats:\/\//i.test(url.trim())))
|
|
254
|
+
throw new CommandFailure("refused", "USAGE_INVALID", `--tls-cert serves the broker over TLS, so ${opts.server !== undefined ? "--server" : "the manifest's broker.servers"} must be a tls:// address; nothing was started or written`, {
|
|
255
|
+
target: { space: m.space, server: brokerAddressForDisplay(server) ?? "not displayable" },
|
|
256
|
+
remedy: opts.server !== undefined ? `pass --server ${tlsAddress(server)}` : `set broker.servers to ${tlsAddress(server)} in ${file}`,
|
|
257
|
+
});
|
|
258
|
+
const open = m.broker?.auth === false; // default is auth
|
|
259
|
+
const userAuth = m.broker?.auth === "user" ? { idpUrl: m.broker.idp } : undefined;
|
|
260
|
+
const runtime = m.runtime ?? "pty";
|
|
261
|
+
if (open && (m.defaults?.deliveryClass === "durable" || m.channels.some((channel) => channel.deliveryClass === "durable")))
|
|
262
|
+
throw new CommandFailure("refused", "UNSUPPORTED", "this open manifest explicitly requests durable channel delivery, but the open broker has no delivery daemon; no channel metadata or broker was written", { target: { space: m.space, defaultDurable: m.defaults?.deliveryClass === "durable", channels: m.channels.filter((channel) => channel.deliveryClass === "durable").map((channel) => channel.name) }, remedy: "use static/user authentication for durable delivery, or declare live delivery for an open mesh" });
|
|
263
|
+
// The address this manifest names is held by the same rule as a `--server` on the flag path: a
|
|
264
|
+
// stopped space keeps its registered address, and a second stack started there answers for both
|
|
265
|
+
// registrations. A fresh team boot has its own refusal below, so this is the ordinary `up -f`.
|
|
266
|
+
if (!opts.freshTeamBoot)
|
|
267
|
+
refuseRegisteredAddress(server, m.space, opts.dryRun
|
|
268
|
+
? "choose another address for --server and repeat the same --dry-run"
|
|
269
|
+
: opts.server !== undefined ? "choose another address for --server and repeat the original command" : `point broker.servers in ${file} at another address`);
|
|
270
|
+
if (opts.freshTeamBoot) {
|
|
271
|
+
const other = loadMeshes().filter((row) => row.space !== m.space && row.server === server);
|
|
272
|
+
if (other.length)
|
|
273
|
+
throw new CommandFailure("refused", "CONFLICT", "another local registration names this exact broker address; fresh team boot did not create a listener over its recorded target", { target: { space: m.space, server: brokerAddressForDisplay(server) ?? "not displayable", otherSpaces: other.map((row) => row.space) }, remedy: "inspect both registrations and their native brokers; exact-address conflicts block creation, while no conflict does not prove exclusivity" });
|
|
274
|
+
}
|
|
275
|
+
if (opts.freshTeamBoot) {
|
|
276
|
+
assertFreshTeamBootOwnership(cotalRoot(), m.space, open ? "open" : userAuth ? "user" : "auth");
|
|
277
|
+
await assertFreshTeamBindAvailable(server, host, m.space);
|
|
278
|
+
}
|
|
279
|
+
// A manifest needs its manager to boot declared agents.
|
|
280
|
+
if (opts.noManager && eff.agents.length)
|
|
281
|
+
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");
|
|
282
|
+
const effectiveNoManager = Boolean(opts.noManager);
|
|
283
|
+
// The open-mesh refusal must be RE-STATED here, not only against the CLI `--open` flag: on this
|
|
284
|
+
// path openness comes from the MANIFEST (`broker.auth: false`), which the flag-level guard cannot
|
|
285
|
+
// see. Without it, `cotal up -f open.yaml --rotate-sys` boots an open broker, exits 0 and rotates
|
|
286
|
+
// nothing: a rotation ask answered with silent success, the exact failure class this change
|
|
287
|
+
// exists to remove. Before the dry-run print and before anything boots.
|
|
288
|
+
if (opts.rotateSys && open)
|
|
289
|
+
throw new FlagValueRefusal("--rotate-sys is for auth meshes: this manifest sets broker.auth: false (open), so there is no system account or $SYS credentials to rotate, and nothing was started", "drop --rotate-sys for this open manifest");
|
|
290
|
+
// Before the dry-run print and before connector preflight or any write, as the refusals above.
|
|
291
|
+
if (!opts.storeDir)
|
|
292
|
+
refuseUnnamedLastStore(cotalPath("nats"));
|
|
293
|
+
else
|
|
294
|
+
refuseMissingNamedStore(resolve(opts.storeDir));
|
|
295
|
+
if (userAuth)
|
|
296
|
+
await preflightUserStack(cotalRoot(), m.space, userAuth.idpUrl);
|
|
297
|
+
checkStartStore(opts.storeDir, m.space);
|
|
298
|
+
// Preview and apply only probe a runtime when starting a manager.
|
|
299
|
+
try {
|
|
300
|
+
if (!effectiveNoManager)
|
|
301
|
+
await preflightRuntime(runtime);
|
|
302
|
+
}
|
|
303
|
+
catch (error) {
|
|
304
|
+
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" });
|
|
305
|
+
}
|
|
306
|
+
if (opts.dryRun) {
|
|
307
|
+
// Dial-host SAN must refuse here too (S6). The real route runs assertServesDialHost after
|
|
308
|
+
// the plan is computed; dry-run used to return before that check and green-lit a launch
|
|
309
|
+
// the applying command refuses. Validate against the effective server; still no writes.
|
|
310
|
+
// Announce only AFTER the dial-host check so a wrong-SAN dry-run does not print TLS: serving.
|
|
311
|
+
assertServesDialHost(opts.transport, new URL(server).hostname);
|
|
312
|
+
// Connector preflight on the dry-run path too (#315): the real route refuses a manifest at
|
|
313
|
+
// preflightConnectors before anything boots; a dry run that plans a launch the applying
|
|
314
|
+
// command refuses is the same green-lit-a-refusal failure class.
|
|
315
|
+
const dryConn = await preflightConnectors(prepared);
|
|
316
|
+
if (dryConn) {
|
|
317
|
+
stderrLine("✗ ", `connector preflight failed: ${dryConn}`, c.red);
|
|
318
|
+
process.exit(1);
|
|
319
|
+
}
|
|
320
|
+
if (opts.transport.kind === "tls-required")
|
|
321
|
+
announceTransport(opts.transport);
|
|
322
|
+
console.log(renderUpPlan(eff, server));
|
|
323
|
+
// The omission is part of the plan (#1417): a dry run that lists a manager the real boot
|
|
324
|
+
// will not start is the exact "green-lit a launch the applying command refuses" failure.
|
|
325
|
+
if (effectiveNoManager)
|
|
326
|
+
console.log(c.dim(" no manager will start on this host (--no-manager): broker, channels and, in auth mode, the delivery daemon come up, and no agents launch from here"));
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
// up -f never adopts a running broker. The old spawn -f route is no longer a manifest deploy.
|
|
330
|
+
if (await isReachable(server)) {
|
|
331
|
+
if (opts.freshTeamBoot)
|
|
332
|
+
throw new CommandFailure("refused", "CONFLICT", "the selected address already has a broker; fresh boot did not adopt it or start a competing listener", { target: { space: m.space, server: brokerAddressForDisplay(server) ?? "not displayable" }, remedy: "inspect the existing broker and selected local records, or use another prepared address" });
|
|
333
|
+
// This folder's own mesh for the manifest's space is named as running, as a bare `up` names it,
|
|
334
|
+
// with the routes that change it instead of the advice for a foreign broker.
|
|
335
|
+
if (loadMeshes().some((row) => row.server === server && row.root === cotalRoot() && row.space === m.space)) {
|
|
336
|
+
stderrLine("✗ ", `mesh "${m.space}" is already running at ${brokerAddressForDisplay(server) ?? "its address"} from this folder - \`up -f\` boots a fresh mesh and does not apply a manifest to a running one; stop it with \`cotal down\`, then retry your original command`, c.red);
|
|
337
|
+
process.exit(1);
|
|
338
|
+
}
|
|
339
|
+
stderrLine("✗ ", `${brokerAddressForDisplay(server) ?? "selected address"} already has a broker - a fresh boot will not adopt it. Stop the owned stack or select another address; team deploy supports only all-new channel cards, not agent apply.`, c.red);
|
|
340
|
+
process.exit(1);
|
|
341
|
+
}
|
|
342
|
+
await assertBrokerAddressFree(server, `${displayCmd()} up -f ${shellWord(file)}`, host);
|
|
343
|
+
// Connectors + their required binaries must exist before any mutation (no fallback).
|
|
344
|
+
const conn = await preflightConnectors(prepared);
|
|
345
|
+
if (conn) {
|
|
346
|
+
if (opts.freshTeamBoot)
|
|
347
|
+
throw new CommandFailure("refused", "DEPENDENCY_UNAVAILABLE", "connector preflight failed before the fresh boot intent; no native effect was requested", { target: { space: m.space }, remedy: conn });
|
|
348
|
+
stderrLine("✗ ", `connector preflight failed: ${conn}`, c.red);
|
|
349
|
+
process.exit(1);
|
|
350
|
+
}
|
|
351
|
+
if (opts.freshTeamBoot) {
|
|
352
|
+
assertFreshTeamBootOwnership(cotalRoot(), m.space, open ? "open" : userAuth ? "user" : "auth");
|
|
353
|
+
await assertFreshTeamBindAvailable(server, host, m.space);
|
|
354
|
+
}
|
|
355
|
+
const deploymentId = genRunId();
|
|
356
|
+
if (opts.freshTeamBoot) {
|
|
357
|
+
try {
|
|
358
|
+
writeFreshTeamAttempt(cotalRoot(), { schemaVersion: 1, kind: "fresh-team-attempt", deploymentId, space: m.space, root: cotalRoot(), server, authMode: open ? "open" : userAuth ? "user" : "auth", manifestPath: resolve(file), createdAt: new Date().toISOString() });
|
|
359
|
+
}
|
|
360
|
+
catch {
|
|
361
|
+
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "fresh boot intent creation or its durability did not confirm; no trust preparation, launch spec or listener was requested", { target: { space: m.space, deploymentId, root: cotalRoot(), intentPath: join(cotalRoot(), ".cotal", `team-boot-attempt-${deploymentId}.json`) }, remedy: "inspect the exact intent path before deciding whether any further boot can be attempted" });
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
// USER-AUTH manifest: the agents run under the LOGGED-IN operator's owner, and the launch spec
|
|
365
|
+
// (consumed by the manager at boot) must carry it — so resolve it NOW. On a fresh mesh the
|
|
366
|
+
// derivation material doesn't exist yet; ensure it just-in-time (authSetup + prepareServer are
|
|
367
|
+
// idempotent ensure-* — the same contract the refresh-heal path already rides). Not logged in /
|
|
368
|
+
// no provider = the exact recovery sentence, before anything boots.
|
|
369
|
+
let owner;
|
|
370
|
+
if (userAuth) {
|
|
371
|
+
try {
|
|
372
|
+
mkdirSync(cotalPath("nats"), { recursive: true, mode: 0o700 });
|
|
373
|
+
// NO `rotateSys` here on purpose: this is an owner-derivation pre-resolve that runs BEFORE the
|
|
374
|
+
// real boot, and the boot below carries the flag. Rotating in both would burn two generations
|
|
375
|
+
// per `up -f --rotate-sys` and retire the account the first pass just minted creds against.
|
|
376
|
+
const setup = await authSetup(cotalPath("nats"), server, m.space, host, userAuth, assertServesDialHost(opts.transport, new URL(server).hostname), false, undefined, opts.freshTeamBoot);
|
|
377
|
+
owner = await resolveAuthProvider().ownerForLogin({ store: workspaceSecretStore(cotalRoot()), dir: setup.stateDir, space: m.space });
|
|
378
|
+
}
|
|
379
|
+
catch (e) {
|
|
380
|
+
if (opts.freshTeamBoot)
|
|
381
|
+
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the fresh user-auth owner preparation did not confirm; trust or provider state may have changed, but no launch spec or listener was requested", { target: { space: m.space, deploymentId, root: cotalRoot() }, remedy: "inspect the retained boot intent, trust state and login before deciding another action; do not repeat an uncertain preparation" });
|
|
382
|
+
stderrLine("✗ ", `${e.message}`, c.red);
|
|
383
|
+
process.exit(1);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
// The resolved launch spec is written FIRST so the ONE control-plane manager that comes up with
|
|
387
|
+
// the broker (inside startMeshDetached) carries it. Exactly one manager serves a space (the
|
|
388
|
+
// singleton lease): a second `supervise` started here for the launch would race the plain one for
|
|
389
|
+
// the lease — the loser refuses, so either the agents never boot or the incumbent is orphaned
|
|
390
|
+
// behind an overwritten pid file. The manager materializes each transient persona and mints creds
|
|
391
|
+
// from the resolved policy — never re-reading a file for authority.
|
|
392
|
+
if (opts.freshTeamBoot) {
|
|
393
|
+
assertFreshTeamBootOwnership(cotalRoot(), m.space, open ? "open" : userAuth ? "user" : "auth", { deploymentId, server, manifestPath: resolve(file) });
|
|
394
|
+
try {
|
|
395
|
+
await assertFreshTeamBindAvailable(server, host, m.space);
|
|
396
|
+
}
|
|
397
|
+
catch {
|
|
398
|
+
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the fresh boot's bind address was not confirmed after owner preparation; no launch spec or listener was requested, but its retained intent and any prepared trust were not discarded", { target: { space: m.space, deploymentId, server: brokerAddressForDisplay(server) ?? "not displayable" }, remedy: "inspect the exact retained intent, trust state and address before deciding another boot; this bind probe does not reserve the listener" });
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
let specPath;
|
|
402
|
+
try {
|
|
403
|
+
specPath = writeLaunchSpec(cotalRoot(), buildLaunchSpec(eff, deploymentId, owner));
|
|
404
|
+
}
|
|
405
|
+
catch (error) {
|
|
406
|
+
if (opts.freshTeamBoot)
|
|
407
|
+
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the fresh boot intent was recorded, but launch-spec creation did not confirm its outcome; no broker launch was attempted and the intent remains for inspection", { target: { space: m.space, deploymentId, root: cotalRoot() }, remedy: "inspect the original intent and launch-spec path before another boot; no effect was retried" });
|
|
408
|
+
throw error;
|
|
409
|
+
}
|
|
410
|
+
// Ordinary up can reconcile a leftover manager. Fresh team boot must not signal one: its
|
|
411
|
+
// stricter prewrite gate required no manager record at all, and a later contender wins
|
|
412
|
+
// neither stop authority nor permission to replace it.
|
|
413
|
+
if (!opts.freshTeamBoot) {
|
|
414
|
+
await stopManager(m.space);
|
|
415
|
+
clearManagerArtifacts(m.space);
|
|
416
|
+
}
|
|
417
|
+
let pid;
|
|
418
|
+
let controlPlane = false;
|
|
419
|
+
let authService = true;
|
|
420
|
+
let deliveryResponderBound = null;
|
|
421
|
+
try {
|
|
422
|
+
// `m.broker?.host`, not the defaulted `host`: same reason as the flag path — only a host the
|
|
423
|
+
// manifest actually declared is an exposure decision worth persisting.
|
|
424
|
+
({ pid, controlPlane, authService, deliveryResponderBound } = await startMeshDetached({ transport: opts.transport, server, space: m.space, open, userAuth, rotateSys: opts.rotateSys, host: m.broker?.host, logFile: m.broker?.logFile, logfileSizeLimit: m.broker?.logfileSizeLimit, logfileMaxNum: m.broker?.logfileMaxNum, seed: manifestToChannels(eff), runtime, launch: specPath, maxSessions: opts.maxSessions, noManager: effectiveNoManager, quietBoot: opts.freshTeamBoot, ...(opts.storeDir ? { storeDir: opts.storeDir } : {}) }));
|
|
425
|
+
}
|
|
426
|
+
catch (e) {
|
|
427
|
+
if (opts.freshTeamBoot)
|
|
428
|
+
throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the fresh broker startup did not confirm completion after its launch spec was written; the listener or control plane may have changed state and the boot was not retried", { target: { space: m.space, deploymentId, launchSpec: specPath }, changed: [{ kind: "launch-spec-written", path: specPath }], remedy: "inspect this exact run and the recorded local listener, manager and auth state before another boot" });
|
|
429
|
+
// A classified failure, such as a certificate this client refuses, keeps its code and next step.
|
|
430
|
+
if (isCommandFailure(e))
|
|
431
|
+
throw e;
|
|
432
|
+
stderrLine("✗ ", `${e.message}`, c.red);
|
|
433
|
+
process.exit(1);
|
|
434
|
+
}
|
|
435
|
+
// Transport committed inside startMeshDetached before delivery (S5+S9).
|
|
436
|
+
let summaryRecorded = false;
|
|
437
|
+
try {
|
|
438
|
+
writeFreshTeamSummary(cotalRoot(), {
|
|
439
|
+
schemaVersion: 1, kind: "fresh-team-summary", deploymentId, space: m.space,
|
|
440
|
+
root: cotalRoot(), server, authMode: open ? "open" : userAuth ? "user" : "auth", brokerPid: pid, manifestPath: resolve(file),
|
|
441
|
+
requestedAgents: eff.agents.map((agent) => agent.name),
|
|
442
|
+
declaredChannels: m.channels.map((channel) => channel.name),
|
|
443
|
+
recordedAt: new Date().toISOString(), managerRequested: !effectiveNoManager,
|
|
444
|
+
controlPlaneReturned: controlPlane, authServiceReturned: authService, deliveryResponderBound,
|
|
445
|
+
agentReadiness: "not-checked",
|
|
446
|
+
});
|
|
447
|
+
summaryRecorded = true;
|
|
448
|
+
}
|
|
449
|
+
catch {
|
|
450
|
+
console.error(c.yellow(`! the native fresh boot returned but its local team summary could not be recorded (run ${deploymentId}); do not repeat the boot just to recreate the summary`));
|
|
451
|
+
}
|
|
452
|
+
if (opts.freshTeamBoot) {
|
|
453
|
+
if (!authService || !controlPlane || !summaryRecorded || (!open && deliveryResponderBound !== true))
|
|
454
|
+
throw new CommandFailure("partial", "OPERATION_PARTIAL", "the fresh broker started, but its control plane, auth service, delivery responder or local deployment summary did not confirm readiness; the same boot was not retried", { target: { space: m.space, deploymentId, brokerPid: pid, launchSpec: specPath }, changed: [{ kind: "broker-started", pid, server: brokerAddressForDisplay(server) ?? "not displayable" }, { kind: "launch-spec-written", path: specPath }, ...(summaryRecorded ? [{ kind: "fresh-summary-recorded", deploymentId }] : [])], remedy: "inspect this exact run, the local broker and manager, and any retained summary before deciding another action" });
|
|
455
|
+
const inheritedAccess = eff.agents.flatMap((agent) => {
|
|
456
|
+
const access = agent.inherited;
|
|
457
|
+
return access.capabilities.length || access.subscribe.length || access.allowSubscribe.length || access.allowPublish.length
|
|
458
|
+
? [{ agent: agent.name, persona: agent.persona ?? null, capabilities: access.capabilities, subscribe: access.subscribe, allowSubscribe: access.allowSubscribe, allowPublish: access.allowPublish }]
|
|
459
|
+
: [];
|
|
460
|
+
});
|
|
461
|
+
let currentSelection = null;
|
|
462
|
+
let selectionChecked = false;
|
|
463
|
+
try {
|
|
464
|
+
currentSelection = getCurrent() ?? null;
|
|
465
|
+
selectionChecked = true;
|
|
466
|
+
}
|
|
467
|
+
catch { /* The returned broker receipt remains usable without a current-default read. */ }
|
|
468
|
+
const result = { kind: "fresh-team-boot", space: m.space, root: cotalRoot(), deploymentId, server: brokerAddressForDisplay(server) ?? "not displayable", brokerPid: pid, manifestPath: resolve(file), runtime, currentSelection, selectionChecked,
|
|
469
|
+
mode: open ? "open" : userAuth ? "user-auth" : "static-auth", controlPlaneReturned: controlPlane, authServiceReturned: authService, deliveryResponderBound, summaryRecorded,
|
|
470
|
+
requestedAgents: eff.agents.map((agent) => ({ name: agent.name, application: agent.agentType, role: agent.role ?? null })),
|
|
471
|
+
declaredChannels: m.channels.map((channel) => ({ name: channel.name, deliveryClass: channel.deliveryClass ?? null, replay: channel.replay ?? null, replayWindow: channel.replayWindow ?? null })), inheritedAccess, agentReadiness: "not-checked" };
|
|
472
|
+
writeResult(opts.presentation ?? "rich", { command: "team boot", target: { space: m.space, root: cotalRoot(), deploymentId }, result, completeness: "partial", warnings: [...eff.warnings.map((warning) => ({ code: "MANIFEST_WARNING", target: { agent: warning.agent }, message: warning.message })), ...(!selectionChecked ? [{ code: "CURRENT_SELECTION_UNAVAILABLE", target: { space: m.space }, message: "The current default space could not be read after boot; no default was inferred." }] : [])] }, (data) => ({ sections: [
|
|
473
|
+
{ title: "Fresh team broker returned", blocks: [{ kind: "fields", rows: [["Space", data.space], ["Deployment", data.deploymentId], ["Root", data.root], ["Broker", data.server], ["Broker PID", String(data.brokerPid)], ["Manifest", data.manifestPath], ["Auth mode", data.mode], ["Runtime request", data.runtime], ["Current default", data.selectionChecked ? data.currentSelection ?? "none selected" : "not checked"], ["Control-plane ensure", "returned"], ["Delivery responder", data.deliveryResponderBound === null ? "not required" : "bound when boot returned"], ["Membership material", "not checked by this receipt"], ["Auth service", data.mode === "user-auth" ? "returned at boot" : "not required"], ["Launch summary", "recorded"], ["Agent readiness", "not checked"]] }, { kind: "lines", lines: ["The manager was requested as part of boot; this receipt does not establish agent joins, current broker health or whole-stack stop authority."] }] },
|
|
474
|
+
{ title: "Requested topology", blocks: [data.requestedAgents.length ? { kind: "table", columns: [{ key: "name", label: "Agent" }, { key: "application", label: "Application" }, { key: "role", label: "Role" }], rows: data.requestedAgents.slice(0, 100).map((agent) => ({ ...agent, role: agent.role ?? "none" })) } : { kind: "lines", lines: ["No agents requested."] }, data.declaredChannels.length ? { kind: "table", columns: [{ key: "name", label: "Channel" }, { key: "delivery", label: "Declared delivery" }, { key: "replay", label: "Declared replay" }, { key: "window", label: "Declared window" }], rows: data.declaredChannels.slice(0, 100).map((channel) => ({ name: `#${channel.name}`, delivery: channel.deliveryClass ?? "not declared", replay: channel.replay === null ? "not declared" : channel.replay ? "on" : "off", window: channel.replayWindow ?? "not declared" })) } : { kind: "lines", lines: ["No channels declared."] }, ...((data.requestedAgents.length > 100 || data.declaredChannels.length > 100) ? [{ kind: "lines", lines: ["Showing at most 100 declared agents and channels; the saved summary retains all names."] }] : [])] },
|
|
475
|
+
...(data.inheritedAccess.length ? [{ title: "Persona-inherited access", blocks: [{ kind: "table", columns: [{ key: "agent", label: "Agent" }, { key: "persona", label: "Persona" }, { key: "scope", label: "Outside manifest channels" }], rows: data.inheritedAccess.slice(0, 100).map((row) => ({ agent: row.agent, persona: row.persona ?? "none", scope: [row.capabilities.length ? `capabilities ${row.capabilities.join(",")}` : "", row.subscribe.length ? `subscribe ${row.subscribe.join(",")}` : "", row.allowSubscribe.length ? `read ${row.allowSubscribe.join(",")}` : "", row.allowPublish.length ? `post ${row.allowPublish.join(",")}` : ""].filter(Boolean).join(" · ") })) }, { kind: "lines", lines: [...(data.inheritedAccess.length > 100 ? ["Additional inherited scopes are not shown in this terminal view."] : []), "These scopes came from referenced personas and are not limited to channels declared by this manifest."] }] }] : []),
|
|
476
|
+
{ title: "Next", blocks: [{ kind: "commands", items: [{ command: `cotal team show ${data.deploymentId}`, description: "Read this local launch summary" }, { command: `cotal watch --space ${data.space}`, description: "Observe the selected mesh" }, { command: `cotal down --space ${data.space} --dry-run`, description: "Inspect local stop records without stopping the stack" }] }] },
|
|
477
|
+
] }));
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
console.log(c.green(`✓ mesh "${m.space}" up at ${server}`) + c.dim(` (broker pid ${pid})`));
|
|
481
|
+
console.log(c.dim(` seeded ${m.channels.length} channel(s): ${m.channels.map((ch) => "#" + ch.name).join(", ")}`));
|
|
482
|
+
if (summaryRecorded)
|
|
483
|
+
console.log(c.dim(` fresh deployment ${deploymentId} recorded; \`cotal team show ${deploymentId}\` reads its launch summary, not live ownership`));
|
|
484
|
+
// Never claim a launch the control plane can't deliver: the manager carries the launch spec, so a
|
|
485
|
+
// degraded control plane (announced above) means the agents are NOT coming up.
|
|
486
|
+
if (effectiveNoManager) {
|
|
487
|
+
// Truthful summary for the broker-only boot (#1417): nothing was omitted by accident, and the
|
|
488
|
+
// agents this manifest declares (none — a declaring manifest is refused above) launch elsewhere.
|
|
489
|
+
console.log(c.dim(` broker-only (--no-manager): no manager started on this host - run \`cotal supervise --space ${m.space} --server ${server}\` from a manager host to manage agents`));
|
|
490
|
+
}
|
|
491
|
+
else if (controlPlane) {
|
|
492
|
+
// U6: on a user mesh the agents run under the OPERATOR's identity — say whose they are.
|
|
493
|
+
// The manager launches them after this command returns, so nothing here knows whether one joined:
|
|
494
|
+
// no success mark, and name where the outcome shows.
|
|
495
|
+
console.log(` launch pending: the manager (${runtime}) starts ${eff.agents.length} agent(s)${owner ? ` as you (owner ${owner})` : ""} after this returns; up -f does not wait for them to join`);
|
|
496
|
+
console.log(c.dim(` who joined: \`cotal ps --space ${m.space}\` · a failed launch and its reason: ${managerLogDisplayPath(m.space)}`));
|
|
497
|
+
}
|
|
498
|
+
else {
|
|
499
|
+
stderrLine("✗ ", `${eff.agents.length} agent(s) NOT launched - the control plane did not come up (see above)`, c.red);
|
|
500
|
+
}
|
|
501
|
+
// Loud summary: any persona-inherited access an `include` manifest dragged in, plus warnings.
|
|
502
|
+
const inherited = renderInherited(eff);
|
|
503
|
+
if (inherited)
|
|
504
|
+
console.log("\n" + inherited);
|
|
505
|
+
if (eff.warnings.length)
|
|
506
|
+
console.log("\n" + renderWarnings(eff.warnings));
|
|
507
|
+
const downRoute = opts.root ? `from ${oneLine(cotalRoot())}, run \`cotal down\`` : "`cotal down`";
|
|
508
|
+
console.log(c.dim(`\nWatch: \`cotal watch --space ${m.space}\` (terminal) · Dashboard: configure the explicit web service preset separately · Tear down: ${downRoute}`));
|
|
509
|
+
// A declared-user-auth manifest whose auth service never became ready, or a degraded control
|
|
510
|
+
// plane: the mesh is up + recorded, but this launch did not deliver what it declared — exit
|
|
511
|
+
// non-zero so CI/wrappers don't read success (the consequence line printed at the failure above).
|
|
512
|
+
if (!authService || !controlPlane || !summaryRecorded)
|
|
513
|
+
process.exitCode = 1;
|
|
514
|
+
}
|
|
515
|
+
/** Return a copy of the prepared manifest with CLI overrides applied to broker/space/runtime, so the
|
|
516
|
+
* whole launch (render, seed, broker, manager, launch spec) runs against one effective manifest.
|
|
517
|
+
* A flag names itself. A value that came from the file keeps that file's key, and a value neither
|
|
518
|
+
* supplied is named by the flag that would supply it. */
|
|
519
|
+
function applyUpOverrides(prepared, o) {
|
|
520
|
+
const m = prepared.manifest;
|
|
521
|
+
const broker = { ...m.broker };
|
|
522
|
+
if (o.server)
|
|
523
|
+
broker.servers = o.server;
|
|
524
|
+
if (o.host)
|
|
525
|
+
broker.host = o.host;
|
|
526
|
+
if (o.open)
|
|
527
|
+
broker.auth = false;
|
|
528
|
+
if (o.idp)
|
|
529
|
+
broker.idp = o.idp;
|
|
530
|
+
if (o.logFile !== undefined)
|
|
531
|
+
broker.logFile = o.logFile;
|
|
532
|
+
if (o.logfileSizeLimit !== undefined)
|
|
533
|
+
broker.logfileSizeLimit = o.logfileSizeLimit;
|
|
534
|
+
if (o.logfileMaxNum !== undefined)
|
|
535
|
+
broker.logfileMaxNum = o.logfileMaxNum;
|
|
536
|
+
return {
|
|
537
|
+
prepared: {
|
|
538
|
+
...prepared,
|
|
539
|
+
manifest: {
|
|
540
|
+
...m,
|
|
541
|
+
broker: Object.keys(broker).length ? broker : undefined,
|
|
542
|
+
runtime: o.runtime ?? m.runtime,
|
|
543
|
+
},
|
|
544
|
+
},
|
|
545
|
+
hostSource: !o.host && m.broker?.host !== undefined ? "broker.host" : "--host",
|
|
546
|
+
serverSource: !o.server && m.broker?.servers !== undefined ? "broker.servers" : "--server",
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
//# sourceMappingURL=up-manifest.js.map
|