@cotal-ai/cli 0.168.0 → 0.169.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/command.d.ts.map +1 -1
- package/dist/command.js +6 -2
- package/dist/command.js.map +1 -1
- package/dist/commands/agents.d.ts.map +1 -1
- package/dist/commands/agents.js +48 -18
- package/dist/commands/agents.js.map +1 -1
- package/dist/commands/app-identity.d.ts.map +1 -1
- package/dist/commands/app-identity.js +14 -5
- package/dist/commands/app-identity.js.map +1 -1
- package/dist/commands/channels.js +2 -2
- package/dist/commands/channels.js.map +1 -1
- package/dist/commands/clean.d.ts.map +1 -1
- package/dist/commands/clean.js +30 -5
- package/dist/commands/clean.js.map +1 -1
- package/dist/commands/config.d.ts +1 -0
- package/dist/commands/config.d.ts.map +1 -1
- package/dist/commands/config.js +15 -7
- package/dist/commands/config.js.map +1 -1
- package/dist/commands/describe.js +4 -4
- package/dist/commands/describe.js.map +1 -1
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +30 -13
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/down.d.ts.map +1 -1
- package/dist/commands/down.js +16 -6
- package/dist/commands/down.js.map +1 -1
- package/dist/commands/endpoint.d.ts +1 -1
- package/dist/commands/endpoint.d.ts.map +1 -1
- package/dist/commands/endpoint.js +3 -4
- package/dist/commands/endpoint.js.map +1 -1
- package/dist/commands/ext.d.ts +1 -0
- package/dist/commands/ext.d.ts.map +1 -1
- package/dist/commands/ext.js +24 -0
- package/dist/commands/ext.js.map +1 -1
- package/dist/commands/help.d.ts.map +1 -1
- package/dist/commands/help.js +5 -0
- package/dist/commands/help.js.map +1 -1
- package/dist/commands/history-clear.js +2 -2
- package/dist/commands/history-clear.js.map +1 -1
- package/dist/commands/history.d.ts +1 -1
- package/dist/commands/history.d.ts.map +1 -1
- package/dist/commands/history.js +21 -10
- package/dist/commands/history.js.map +1 -1
- package/dist/commands/join.d.ts.map +1 -1
- package/dist/commands/join.js +104 -23
- package/dist/commands/join.js.map +1 -1
- package/dist/commands/manager-service.d.ts.map +1 -1
- package/dist/commands/manager-service.js +7 -14
- package/dist/commands/manager-service.js.map +1 -1
- package/dist/commands/meshes-add.d.ts.map +1 -1
- package/dist/commands/meshes-add.js +6 -0
- package/dist/commands/meshes-add.js.map +1 -1
- package/dist/commands/meshes.d.ts.map +1 -1
- package/dist/commands/meshes.js +17 -2
- package/dist/commands/meshes.js.map +1 -1
- package/dist/commands/mint.d.ts.map +1 -1
- package/dist/commands/mint.js +4 -2
- package/dist/commands/mint.js.map +1 -1
- package/dist/commands/models.d.ts +1 -0
- package/dist/commands/models.d.ts.map +1 -1
- package/dist/commands/models.js +11 -3
- package/dist/commands/models.js.map +1 -1
- package/dist/commands/persona.d.ts +1 -0
- package/dist/commands/persona.d.ts.map +1 -1
- package/dist/commands/persona.js +13 -2
- package/dist/commands/persona.js.map +1 -1
- package/dist/commands/send.d.ts.map +1 -1
- package/dist/commands/send.js +47 -20
- package/dist/commands/send.js.map +1 -1
- package/dist/commands/service-actions.d.ts.map +1 -1
- package/dist/commands/service-actions.js +9 -7
- 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 +20 -11
- package/dist/commands/service-registry.js.map +1 -1
- package/dist/commands/setup.d.ts +4 -4
- package/dist/commands/setup.d.ts.map +1 -1
- package/dist/commands/setup.js +18 -15
- package/dist/commands/setup.js.map +1 -1
- package/dist/commands/space-registration.d.ts.map +1 -1
- package/dist/commands/space-registration.js +37 -12
- package/dist/commands/space-registration.js.map +1 -1
- package/dist/commands/space.d.ts +1 -0
- package/dist/commands/space.d.ts.map +1 -1
- package/dist/commands/space.js +13 -2
- package/dist/commands/space.js.map +1 -1
- package/dist/commands/spawn-preview.d.ts.map +1 -1
- package/dist/commands/spawn-preview.js +11 -4
- package/dist/commands/spawn-preview.js.map +1 -1
- package/dist/commands/spawn.d.ts.map +1 -1
- package/dist/commands/spawn.js +103 -44
- package/dist/commands/spawn.js.map +1 -1
- package/dist/commands/stack-gone.d.ts +10 -0
- package/dist/commands/stack-gone.d.ts.map +1 -1
- package/dist/commands/stack-gone.js +169 -7
- package/dist/commands/stack-gone.js.map +1 -1
- package/dist/commands/stack-lost-records.js +1 -1
- package/dist/commands/stack-lost-records.js.map +1 -1
- package/dist/commands/stack-up.d.ts.map +1 -1
- package/dist/commands/stack-up.js +13 -6
- package/dist/commands/stack-up.js.map +1 -1
- package/dist/commands/status.d.ts +2 -2
- package/dist/commands/status.d.ts.map +1 -1
- package/dist/commands/status.js +142 -43
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/sync.d.ts +1 -0
- package/dist/commands/sync.d.ts.map +1 -1
- package/dist/commands/sync.js +8 -1
- package/dist/commands/sync.js.map +1 -1
- package/dist/commands/up.d.ts.map +1 -1
- package/dist/commands/up.js +32 -8
- package/dist/commands/up.js.map +1 -1
- package/dist/commands/update.d.ts +3 -1
- package/dist/commands/update.d.ts.map +1 -1
- package/dist/commands/update.js +107 -22
- package/dist/commands/update.js.map +1 -1
- package/dist/commands/use.d.ts +1 -0
- package/dist/commands/use.d.ts.map +1 -1
- package/dist/commands/use.js +6 -0
- package/dist/commands/use.js.map +1 -1
- package/dist/commands/whoami.js +3 -3
- package/dist/commands/whoami.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -7
- package/dist/index.js.map +1 -1
- package/dist/lib/completion-install.d.ts.map +1 -1
- package/dist/lib/completion-install.js +6 -3
- package/dist/lib/completion-install.js.map +1 -1
- package/dist/lib/confirmation-required.d.ts +14 -0
- package/dist/lib/confirmation-required.d.ts.map +1 -1
- package/dist/lib/confirmation-required.js +13 -0
- package/dist/lib/confirmation-required.js.map +1 -1
- package/dist/lib/connect.d.ts +2 -2
- package/dist/lib/connect.d.ts.map +1 -1
- package/dist/lib/connect.js +6 -4
- package/dist/lib/connect.js.map +1 -1
- package/dist/lib/control.d.ts +8 -0
- package/dist/lib/control.d.ts.map +1 -1
- package/dist/lib/control.js +23 -1
- package/dist/lib/control.js.map +1 -1
- package/dist/lib/controller-restore.d.ts.map +1 -1
- package/dist/lib/controller-restore.js +5 -1
- package/dist/lib/controller-restore.js.map +1 -1
- package/dist/lib/credential-exports.d.ts +1 -0
- package/dist/lib/credential-exports.d.ts.map +1 -1
- package/dist/lib/credential-exports.js +3 -3
- package/dist/lib/credential-exports.js.map +1 -1
- package/dist/lib/delivery-proc.d.ts +2 -0
- package/dist/lib/delivery-proc.d.ts.map +1 -1
- package/dist/lib/delivery-proc.js +12 -2
- package/dist/lib/delivery-proc.js.map +1 -1
- package/dist/lib/local-process-stop.d.ts.map +1 -1
- package/dist/lib/local-process-stop.js +49 -18
- package/dist/lib/local-process-stop.js.map +1 -1
- package/dist/lib/persona-files.d.ts.map +1 -1
- package/dist/lib/persona-files.js +10 -20
- package/dist/lib/persona-files.js.map +1 -1
- package/dist/lib/restore.js +1 -1
- package/dist/lib/restore.js.map +1 -1
- package/dist/lib/self-exec.d.ts +4 -2
- package/dist/lib/self-exec.d.ts.map +1 -1
- package/dist/lib/self-exec.js +12 -6
- package/dist/lib/self-exec.js.map +1 -1
- package/dist/lib/service-preset-target.d.ts.map +1 -1
- package/dist/lib/service-preset-target.js +15 -5
- 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 +38 -18
- package/dist/lib/service-presets.js.map +1 -1
- package/dist/lib/service-process.d.ts +10 -0
- package/dist/lib/service-process.d.ts.map +1 -1
- package/dist/lib/service-process.js +108 -3
- package/dist/lib/service-process.js.map +1 -1
- package/dist/lib/stack-journal.d.ts +8 -6
- package/dist/lib/stack-journal.d.ts.map +1 -1
- package/dist/lib/stack-journal.js +60 -18
- package/dist/lib/stack-journal.js.map +1 -1
- package/dist/lib/store-dir.d.ts +2 -2
- package/dist/lib/store-dir.d.ts.map +1 -1
- package/dist/lib/store-dir.js +12 -3
- package/dist/lib/store-dir.js.map +1 -1
- package/dist/lib/update-snapshot.d.ts.map +1 -1
- package/dist/lib/update-snapshot.js +4 -3
- package/dist/lib/update-snapshot.js.map +1 -1
- package/package.json +4 -4
package/dist/commands/status.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { accessSync, constants, existsSync, lstatSync } from "node:fs";
|
|
1
|
+
import { accessSync, constants, existsSync, lstatSync, statSync } from "node:fs";
|
|
2
2
|
import { drainAndClose } from "@cotal-ai/core";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { CotalEndpoint, agentFilePath, dialerFor, EpEnvelopeError, formatAge, isReachable, isStreamNotFound, mintCreds, mintLifecycleUid, resolveService, realDirNoSymlink, invokeRepairingSplit, standaloneConnectOpts, newIdentity, idFromCreds, principalKey, DEV_OWNER, unansweredRequest, resolveAuthProvider, personaDir, } from "@cotal-ai/core";
|
|
6
|
-
import { stoppedLoopbackListener, accountInventory, authDir, isCommandFailure, readMaintenanceJournal, recordsElsewhereError, recordsElsewhereText, restoreRolledBackRuns, targetErrorSpace, brokerAddressForDisplay, brokerCheck, canonicalRoot, CLI_USER_ACTOR, codeSpan, CommandFailure, deliveryCredsKey, DELIVERY_PIDFILE, extensionsDir, findCotalRoot, folderSpaceOverSelection, meshesForRoot, resolveReadsLiveness, stoppedStack, unsettledStackOperation, withdrawOperationNote, hasUserAuthState, homeCotalDir, installationWriter, cachedPreferences, loadLaunchPersonaFile, resolvePreference, isMeshRegistryError, isWorkspaceTargetError, jsonFlag, loadManagerInstanceIdentity, loadSoleSpaceAuth, localProcessPath, localProcessVisible, MANAGER_PIDFILE, oneLine,
|
|
6
|
+
import { stoppedLoopbackListener, stackRunsUnderOtherHome, accountInventory, authDir, isCommandFailure, readMaintenanceJournal, recordsElsewhereError, recordsElsewhereText, restoreRolledBackRuns, targetErrorSpace, brokerAddressForDisplay, brokerCheck, canonicalRoot, CLI_USER_ACTOR, codeSpan, CommandFailure, deliveryCredsKey, DELIVERY_PIDFILE, extensionsDir, findCotalRoot, folderSpaceOverSelection, meshesForRoot, resolveReadsLiveness, stoppedStack, unsettledStackOperation, withdrawOperationNote, hasUserAuthState, homeCotalDir, installationWriter, cachedPreferences, loadLaunchPersonaFile, resolvePreference, isMeshRegistryError, isWorkspaceTargetError, jsonFlag, loadManagerInstanceIdentity, loadSoleSpaceAuth, localProcessPath, localProcessVisible, MANAGER_PIDFILE, NATS_PIDFILE, oneLine, spaceKey, PREFERENCE_KEYS, plainFlag, preflightTarget, presentationOf, principalFromBearer, verifyIdentityPin, probeWebReadiness, readCurrent, readMeshRegistry, readPidfile, preparedRecordSkipped, readPreparedSpaces, stackJournalPath, readRenewalRecord, recordOperationSpace, renderWorkspaceError, resolveMeshTarget, serverFlag, spaceFlag, userAuthStateDir, WEB_PIDFILE, workspaceSecretStore, displayWidth, terminalWidth, wrapWords, writeResult, workspaceErrorParts, preferencesPath, preferencesFolderWarning, cotalDirLink, movedProject, spaceStreamsAbsent, spaceStreamsExpected, resolveControlTarget, } from "@cotal-ai/workspace";
|
|
7
7
|
import { localProcessSurface } from "../ext-loader.js";
|
|
8
8
|
import { cliVersion, cliProvenance, readExtensionVersions } from "../lib/version.js";
|
|
9
9
|
import { agentSkillsSkew } from "../lib/agent-skills.js";
|
|
10
|
-
import { managerHasDeliveryMarker } from "../lib/manager-proc.js";
|
|
10
|
+
import { managerHasDeliveryMarker, managerLogPath } from "../lib/manager-proc.js";
|
|
11
|
+
import { MANAGER_OMITTED } from "../lib/delivery-proc.js";
|
|
11
12
|
import { signedInSpace } from "../lib/conversation-identity.js";
|
|
12
13
|
import { connectorHarnesses, connectorStatusRows, machineStatus, recordedWebUrl, resolveRuntimeSpace, webBoundAddress, webInstalled, webSessionSource } from "../lib/status.js";
|
|
13
14
|
import { deliveryResponderFromLease, deliveryResponderState, deliveryRowSuffix, RESPONDER_STALE_TEXT, RESPONDER_UNBOUND_CONSEQUENCE } from "../lib/delivery-responder.js";
|
|
@@ -22,7 +23,7 @@ import { c } from "../ui.js";
|
|
|
22
23
|
import { preparedCatalogDiagnostics } from "./sync.js";
|
|
23
24
|
import { agentStatus } from "./agents.js";
|
|
24
25
|
import { invalidEnvironmentValues } from "./config.js";
|
|
25
|
-
import { cliControl, onInstance } from "../lib/control.js";
|
|
26
|
+
import { cliControl, onInstance, onRerun } from "../lib/control.js";
|
|
26
27
|
import { serviceDefinitionProjection, serviceDefinitionStore } from "../lib/service-definitions.js";
|
|
27
28
|
import { instanceProjection, serviceInstances } from "../lib/service-instances.js";
|
|
28
29
|
import { readinessAddressSurvivors } from "../lib/service-process.js";
|
|
@@ -51,11 +52,11 @@ export const statusFlags = [
|
|
|
51
52
|
spaceFlag,
|
|
52
53
|
serverFlag,
|
|
53
54
|
{ name: "on", type: "string", value: "<manager-instance>", description: "named agent: inspect one manager instance" },
|
|
54
|
-
{ name: "creds", type: "string", value: "<file>", description: "
|
|
55
|
+
{ name: "creds", type: "string", value: "<file>", description: "explicit credential file (unsupported for status)" },
|
|
55
56
|
{ name: "all", type: "boolean", description: "check every recorded mesh, not only the selected one, and report every row in full" },
|
|
56
57
|
{ name: "wide", type: "boolean", description: "report every row in full: each known agent application, each extension, and the spaces under their broker addresses" },
|
|
57
58
|
{ name: "verbose", short: "v", type: "boolean", description: "include installation paths, local records and detailed diagnostics" },
|
|
58
|
-
{ name: "components", type: "boolean", description: "probe manager, delivery, web, and registered broker component health (exit: 0 serving, or the optional dashboard not installed or not started; 1 absent; 2 present but not serving; 3 probe refused)" },
|
|
59
|
+
{ name: "components", type: "boolean", description: "probe manager, delivery, web, and registered broker component health (exit: 0 serving, an intentionally omitted manager, or the optional dashboard not installed or not started; 1 absent; 2 present but not serving; 3 probe refused)" },
|
|
59
60
|
jsonFlag,
|
|
60
61
|
plainFlag,
|
|
61
62
|
];
|
|
@@ -120,14 +121,24 @@ function displayStatusBroker(server, space, gaps) {
|
|
|
120
121
|
}
|
|
121
122
|
/** Named-agent and infrastructure inputs choose different reads. */
|
|
122
123
|
export function validateStatusArguments(args) {
|
|
124
|
+
presentationOf(args.values);
|
|
123
125
|
if (args.positionals.length > 1 || args.positionals.length && !args.positionals[0]?.trim())
|
|
124
126
|
throw new CommandFailure("refused", "USAGE_INVALID", "status takes at most one agent name");
|
|
125
|
-
if (args.positionals.length && (args.values.all || args.values.components))
|
|
126
|
-
throw new CommandFailure("refused", "USAGE_INVALID", "a named agent status takes no --all or --
|
|
127
|
+
if (args.positionals.length && (args.values.all || args.values.components || args.values.wide || args.values.verbose))
|
|
128
|
+
throw new CommandFailure("refused", "USAGE_INVALID", "a named agent status takes no --all, --components, --wide or --verbose");
|
|
127
129
|
if (typeof args.values.on === "string")
|
|
128
|
-
onInstance(args.values.on, "cotal status");
|
|
129
|
-
if (!args.positionals.length &&
|
|
130
|
-
throw new CommandFailure("refused", "USAGE_INVALID", "--on
|
|
130
|
+
onInstance(args.values.on, onRerun("cotal status", args.values, args.positionals));
|
|
131
|
+
if (!args.positionals.length && args.values.on !== undefined)
|
|
132
|
+
throw new CommandFailure("refused", "USAGE_INVALID", "--on selects a named agent read, not infrastructure status");
|
|
133
|
+
if (!args.positionals.length && args.values.creds !== undefined) {
|
|
134
|
+
const space = typeof args.values.space === "string" && args.values.space.trim() ? args.values.space : undefined;
|
|
135
|
+
if (space !== undefined)
|
|
136
|
+
recordOperationSpace(space);
|
|
137
|
+
throw new CommandFailure("refused", "UNSUPPORTED", "status does not accept --creds: infrastructure status reads local and registered meshes, and named agent status mints its own control caller", {
|
|
138
|
+
...(space !== undefined ? { target: { space } } : {}),
|
|
139
|
+
remedy: "run `cotal status` or `cotal status <agent>` without --creds",
|
|
140
|
+
});
|
|
141
|
+
}
|
|
131
142
|
}
|
|
132
143
|
/** `cotal status` — detailed, read-only diagnostics for the local machine + selected mesh. */
|
|
133
144
|
export async function status(args) {
|
|
@@ -230,7 +241,7 @@ export async function status(args) {
|
|
|
230
241
|
...(parts ? { partial: { message: `status could not read ${parts === 1 ? "one part" : `${parts} parts`} of what it reports; the warnings name ${parts === 1 ? "it" : "each"}` } } : {}),
|
|
231
242
|
}, (result) => statusView(result, Boolean(values.verbose), Boolean(values.all) || Boolean(values.wide)));
|
|
232
243
|
if (values.components)
|
|
233
|
-
await printComponentHealth(
|
|
244
|
+
await printComponentHealth(selected);
|
|
234
245
|
}
|
|
235
246
|
/** Why this account cannot list or search `root`, or undefined when it can. */
|
|
236
247
|
function folderReadProblem(root) {
|
|
@@ -551,7 +562,12 @@ async function readResponderAxis(selected, preflight) {
|
|
|
551
562
|
// A daemon killed before it could release shard 0 leaves its ready row, which names this
|
|
552
563
|
// folder's credential, until the bucket TTL removes it. When this folder's delivery pidfile
|
|
553
564
|
// names a process that is gone, that row is the dead daemon's, the same rule `up` waits on.
|
|
554
|
-
|
|
565
|
+
const deadLocal = processRecord(DELIVERY_PIDFILE, { root: target.root, space: target.space }).kind === "dead";
|
|
566
|
+
const journal = readStackJournal(target.root)?.journal;
|
|
567
|
+
const member = journal?.space === target.space ? journal.members.find((row) => row.role === "delivery") : undefined;
|
|
568
|
+
const instance = member?.instanceId && serviceInstances(target.space, STACK_DEFINITION.delivery).find((row) => row.name === member.instanceId);
|
|
569
|
+
const deadInstance = instance && ["gone", "foreign-pid", "previous-boot"].includes(instanceProjection(instance).observedProcess);
|
|
570
|
+
return { state: state === "bound" && holder !== undefined && (deadLocal || deadInstance) ? "stale" : state, leased };
|
|
555
571
|
}
|
|
556
572
|
finally {
|
|
557
573
|
await ep.stop().catch(() => { });
|
|
@@ -692,6 +708,11 @@ async function readFolder(root, selected, values, responder, gaps, hints) {
|
|
|
692
708
|
const brokerIndex = processes.findIndex((row) => row.name === "nats");
|
|
693
709
|
if (brokerIndex !== -1)
|
|
694
710
|
processes[brokerIndex] = brokerProcess(processes[brokerIndex], controllerStack ? journal : undefined, gaps);
|
|
711
|
+
const managerIndex = !controllerStack && (nats?.liveness === "alive" || nats?.liveness === "dead")
|
|
712
|
+
? processes.findIndex((row) => row.name === "manager" && row.state === "stopped" && row.pid === null)
|
|
713
|
+
: -1;
|
|
714
|
+
if (managerIndex !== -1 && legacyManagerStopped(root, space))
|
|
715
|
+
processes[managerIndex] = { ...processes[managerIndex], detail: "stopped" };
|
|
695
716
|
const noManager = journal !== undefined && controllerStack && stackStartedWithoutManager(journal);
|
|
696
717
|
// An operation cut off with no recorded outcome can keep up and down from settling it; status names
|
|
697
718
|
// why and the way out their refusal names. A refusal of another kind is left to them.
|
|
@@ -855,6 +876,8 @@ function brokerProcess(legacy, journal, gaps) {
|
|
|
855
876
|
const row = { ...legacy, source: journal ? "owned-service" : "legacy-pidfile", legacyPidfile: { state, pid, detail }, ownedService: null };
|
|
856
877
|
if (!journal)
|
|
857
878
|
return row;
|
|
879
|
+
if (stackRunsUnderOtherHome(journal.root, journal) && journal.recovery?.home !== homeCotalDir())
|
|
880
|
+
return { ...row, state: "unknown", pid: null, detail: `stack member records belong to ${journal.recovery?.home ?? "another Cotal home"}` };
|
|
858
881
|
try {
|
|
859
882
|
const instances = serviceInstances(journal.space, STACK_DEFINITION.broker);
|
|
860
883
|
if (instances.length === 0) {
|
|
@@ -940,6 +963,28 @@ function localManagerInstanceId(root, space) {
|
|
|
940
963
|
return undefined;
|
|
941
964
|
}
|
|
942
965
|
}
|
|
966
|
+
/** Whether the legacy stack whose broker pidfile is in `root` started a manager that has since
|
|
967
|
+
* exited and removed its pidfile (as SIGTERM does), rather than running with `--no-manager`. */
|
|
968
|
+
function legacyManagerStopped(root, space) {
|
|
969
|
+
const id = localManagerInstanceId(root, space);
|
|
970
|
+
if (id === undefined)
|
|
971
|
+
return false;
|
|
972
|
+
let brokerMtime;
|
|
973
|
+
try {
|
|
974
|
+
brokerMtime = statSync(join(root, ".cotal", NATS_PIDFILE), { bigint: true }).mtimeNs;
|
|
975
|
+
}
|
|
976
|
+
catch {
|
|
977
|
+
return false;
|
|
978
|
+
}
|
|
979
|
+
for (const path of [managerLogPath(space, root), join(root, ".cotal", `manager-execution.${spaceKey(space)}.${id}.json`)]) {
|
|
980
|
+
try {
|
|
981
|
+
if (statSync(path, { bigint: true }).mtimeNs >= brokerMtime)
|
|
982
|
+
return true;
|
|
983
|
+
}
|
|
984
|
+
catch { /* absent or unreadable candidate */ }
|
|
985
|
+
}
|
|
986
|
+
return false;
|
|
987
|
+
}
|
|
943
988
|
/** User-mode manager status goes through the same control call `cotal spawn` uses. `instanceId`
|
|
944
989
|
* pins that call to this machine's manager. Without it, the exchange may select another live
|
|
945
990
|
* manager of the same owner. */
|
|
@@ -1060,7 +1105,7 @@ async function readMeshes(cwd, selected, all, gaps, offline, preflight) {
|
|
|
1060
1105
|
return "reachable";
|
|
1061
1106
|
if (preflight.kind === "slow-link" || preflight.kind === "broker-stopped" || preflight.kind === "unreachable")
|
|
1062
1107
|
return preflight.kind;
|
|
1063
|
-
return preflight.kind === "tls-trust" || preflight.kind === "tls-unsupported" ? "unreachable" : "reachable";
|
|
1108
|
+
return preflight.kind === "tls-trust" || preflight.kind === "tls-unsupported" || preflight.kind === "auth-unsupported" || preflight.kind === "jetstream-unsupported" || preflight.kind === "non-nats-listener" ? "unreachable" : "reachable";
|
|
1064
1109
|
}
|
|
1065
1110
|
return brokerCheck(m.server, m.tlsRequired);
|
|
1066
1111
|
};
|
|
@@ -1311,6 +1356,10 @@ async function readSelected(selected, responder, folder, gaps, hints, preflight)
|
|
|
1311
1356
|
const { message, remedy } = workspaceErrorParts({ kind: "preflight", failure: "unreachable", target, pruned: !offline && preflight.prune });
|
|
1312
1357
|
hints.push(remedy === undefined ? message : `${message}; ${remedy}`);
|
|
1313
1358
|
}
|
|
1359
|
+
if (preflight.kind === "non-nats-listener" || preflight.kind === "auth-unsupported" || preflight.kind === "jetstream-unsupported") {
|
|
1360
|
+
const { message, remedy } = workspaceErrorParts({ kind: "preflight", failure: preflight.kind, target, pruned: false });
|
|
1361
|
+
hints.push(remedy === undefined ? message : `${message}; ${remedy}`);
|
|
1362
|
+
}
|
|
1314
1363
|
return { ...base, connection: preflight.kind, ...(preflight.pid === undefined ? {} : { brokerPid: preflight.pid }), staleRecord: preflight.prune && !offline, snapshot: { state: "skipped", reason: "broker not connected" } };
|
|
1315
1364
|
}
|
|
1316
1365
|
// The mesh-level statement of the same axis (#1576). The folder section says what this machine's
|
|
@@ -1741,6 +1790,9 @@ function connectionCell(s) {
|
|
|
1741
1790
|
"broker-stopped": `broker process ${s.brokerPid} is stopped`,
|
|
1742
1791
|
"tls-trust": "TLS could not be verified",
|
|
1743
1792
|
"tls-unsupported": "listener does not offer required TLS",
|
|
1793
|
+
"auth-unsupported": "listener does not enforce Cotal authentication",
|
|
1794
|
+
"jetstream-unsupported": "listener does not offer JetStream",
|
|
1795
|
+
"non-nats-listener": "non-NATS listener holds the broker address",
|
|
1744
1796
|
"stale-auth": "credentials need renewal",
|
|
1745
1797
|
"auth-required": "authentication required",
|
|
1746
1798
|
"open-wants-auth": "authentication required",
|
|
@@ -1898,7 +1950,7 @@ function selectedOverview(r) {
|
|
|
1898
1950
|
columns: [{ key: "name", label: "Service" }, { key: "state", label: "State" }],
|
|
1899
1951
|
rows: r.folder.processes.map((item) => ({
|
|
1900
1952
|
name: item.name === "nats" ? "Broker" : item.name === "manager" ? "Manager" : item.name === "delivery" ? "Delivery" : item.name === "web" ? "Web" : item.name,
|
|
1901
|
-
state: item.state === "running" || item.state === "not-serving" || item.state === "unreadable" ? processCell(item) : stateCell(item.pid === null ? "not started" : item.detail ?? "stopped", "hint"),
|
|
1953
|
+
state: item.state === "running" || item.state === "not-serving" || item.state === "unreadable" ? processCell(item) : stateCell(item.pid === null && item.detail !== "stopped" ? "not started" : item.detail ?? "stopped", "hint"),
|
|
1902
1954
|
})),
|
|
1903
1955
|
});
|
|
1904
1956
|
}
|
|
@@ -1948,7 +2000,7 @@ function nextActions(r) {
|
|
|
1948
2000
|
const cmd = displayCmd();
|
|
1949
2001
|
const items = [];
|
|
1950
2002
|
const extra = [];
|
|
1951
|
-
const noApplication = !r.machine.
|
|
2003
|
+
const noApplication = !setUpApplications(r.machine).length;
|
|
1952
2004
|
if (!r.selected.resolved && !r.meshes.items.length && !r.meshes.unreadable.length) {
|
|
1953
2005
|
items.push({ command: `${cmd} login`, description: "Sign in to Cotal Cloud" });
|
|
1954
2006
|
}
|
|
@@ -1978,7 +2030,7 @@ function nextActions(r) {
|
|
|
1978
2030
|
// own records. One whose last operation a member keeps unsettled is named the way out that
|
|
1979
2031
|
// `up` and `down` name instead. A stack started with --no-manager leaves its manager out by choice,
|
|
1980
2032
|
// so a manager record an earlier up left is not a stopped member, and the restart keeps the flag.
|
|
1981
|
-
const memberGone = r.services?.instances?.some((row) => row.definition.startsWith("stack-") &&
|
|
2033
|
+
const memberGone = r.services?.instances?.some((row) => row.definition.startsWith("stack-") && ["gone", "foreign-pid", "previous-boot"].includes(row.observedProcess) && !(r.folder.noManager && row.definition === STACK_DEFINITION.manager)) === true;
|
|
1982
2034
|
// A connection to a `--server` address other than the recorded one does not say whether the stack
|
|
1983
2035
|
// answers; the hint `readSelected` adds names that address. A user-auth space is probed on its own path.
|
|
1984
2036
|
const dialed = r.selected.resolved ? r.selected : undefined;
|
|
@@ -1993,7 +2045,7 @@ function nextActions(r) {
|
|
|
1993
2045
|
// refresh restarts no manager, and an open or user-auth broker needs its mode flag again.
|
|
1994
2046
|
const local = r.selected.resolved && r.selected.mode === "auth" && !r.folder.controllerStack && r.folder.root === r.selected.root && r.folder.processSpace === r.selected.space
|
|
1995
2047
|
&& !["manual", "catalog"].includes(r.meshes.items.find((m) => m.space === r.selected.space)?.origin ?? "up");
|
|
1996
|
-
const exited = local ? (r.folder.processes ?? []).filter((row) => (row.name === "nats" || row.name === "manager") && row.state === "stopped" && row.pid !== null).map((row) => row.name) : [];
|
|
2048
|
+
const exited = local ? (r.folder.processes ?? []).filter((row) => (row.name === "nats" || row.name === "manager") && row.state === "stopped" && (row.pid !== null || row.detail === "stopped")).map((row) => row.name) : [];
|
|
1997
2049
|
if (r.selected.resolved && r.selected.connection === "broker-stopped")
|
|
1998
2050
|
items.unshift({ command: `kill -CONT ${r.selected.brokerPid}`, description: "Resume the stopped broker process so it answers again" });
|
|
1999
2051
|
else if (block && blocked) {
|
|
@@ -2035,6 +2087,11 @@ function nextActions(r) {
|
|
|
2035
2087
|
const notes = [...(broker ? ["up reopens the recorded store"] : []), ...(manager ? ["pass --runtime again if the manager ran on one"] : [])];
|
|
2036
2088
|
items.unshift({ command: `${cmd} up`, description: `Restart this folder's ${broker && manager ? "broker and manager" : broker ? "broker" : "manager"}, which exited; ${notes.join("; ")}` });
|
|
2037
2089
|
}
|
|
2090
|
+
else if (local && r.selected.resolved && r.selected.connection === "unreachable" && (r.folder.processes ?? []).every((row) => row.state === "stopped")) {
|
|
2091
|
+
// A clean down leaves every member stopped with no pidfile. Spawn and ps need the stack, so the
|
|
2092
|
+
// bare `up` that starts it again on its recorded address and store comes first.
|
|
2093
|
+
items.unshift({ command: `${cmd} up`, description: "Start this folder's stopped stack again; pass --runtime again if the manager ran on one" });
|
|
2094
|
+
}
|
|
2038
2095
|
// A stack whose folder was deleted stops only from this machine's records.
|
|
2039
2096
|
if (r.selected.resolved && r.selected.rootGone)
|
|
2040
2097
|
items.unshift({ command: `${cmd} down --space ${r.selected.space} --yes`, description: "Stop the stack whose folder is gone and free its name" });
|
|
@@ -2184,21 +2241,17 @@ function componentExit(components) {
|
|
|
2184
2241
|
return Math.max(...components.map((component) => COMPONENT_EXIT[component.verdict]));
|
|
2185
2242
|
}
|
|
2186
2243
|
function processRecord(template, context) {
|
|
2187
|
-
let raw;
|
|
2188
2244
|
try {
|
|
2189
|
-
|
|
2245
|
+
const path = localProcessPath(template, context);
|
|
2246
|
+
const state = pidfileState(path);
|
|
2247
|
+
if (state.pid === undefined)
|
|
2248
|
+
return state.liveness === "dead" ? { kind: "absent" } : { kind: "unattributable", raw: readPidfile(path) ?? "" };
|
|
2249
|
+
return { kind: state.liveness === "alive" ? "live" : state.liveness === "dead" ? "dead" : "unknown", pid: state.pid };
|
|
2190
2250
|
}
|
|
2191
2251
|
catch (e) {
|
|
2192
2252
|
// An ambiguous record or any failed read refuses this component's row, never the whole pass.
|
|
2193
2253
|
return { kind: "unreadable", error: e.message };
|
|
2194
2254
|
}
|
|
2195
|
-
if (!raw)
|
|
2196
|
-
return { kind: "absent" };
|
|
2197
|
-
const pid = parsePid(raw);
|
|
2198
|
-
if (pid === undefined)
|
|
2199
|
-
return { kind: "unattributable", raw };
|
|
2200
|
-
const liveness = probeLiveness(pid);
|
|
2201
|
-
return liveness === "alive" ? { kind: "live", pid } : liveness === "dead" ? { kind: "dead", pid } : { kind: "unknown", pid };
|
|
2202
2255
|
}
|
|
2203
2256
|
function pidFacts(record) {
|
|
2204
2257
|
if (record.kind === "live" || record.kind === "dead" || record.kind === "unknown")
|
|
@@ -2350,7 +2403,7 @@ async function managerServiceHealth(target, auth) {
|
|
|
2350
2403
|
await drainAndClose(nc);
|
|
2351
2404
|
}
|
|
2352
2405
|
}
|
|
2353
|
-
async function managerHealth(target, context, credential) {
|
|
2406
|
+
async function managerHealth(target, context, credential, broker) {
|
|
2354
2407
|
const record = processRecord(MANAGER_PIDFILE, context);
|
|
2355
2408
|
const facts = pidFacts(record);
|
|
2356
2409
|
// A corrupt or kernel-unreadable LOCAL record is neither evidence that the manager is absent nor
|
|
@@ -2446,10 +2499,26 @@ async function managerHealth(target, context, credential) {
|
|
|
2446
2499
|
// lease still identifies an extant component; any other failed probe remains a refusal.
|
|
2447
2500
|
const noService = managerNoService(e);
|
|
2448
2501
|
facts.push(noService ? "serve no answer" : `serve probe refused: ${e.message}`);
|
|
2502
|
+
if (broker.verdict === "absent" && processVerdict(record) === "absent")
|
|
2503
|
+
return { name: "manager", verdict: "absent", facts };
|
|
2449
2504
|
if (!noService)
|
|
2450
2505
|
return { name: "manager", verdict: "refused", facts };
|
|
2451
2506
|
const liveRecord = record.kind === "live";
|
|
2452
2507
|
const hasLease = facts.some((fact) => fact.startsWith("lease holder "));
|
|
2508
|
+
if (!liveRecord && !hasLease) {
|
|
2509
|
+
try {
|
|
2510
|
+
const journal = readStackJournal(context.root)?.journal;
|
|
2511
|
+
const pin = verifyIdentityPin(localProcessPath(MANAGER_OMITTED, context));
|
|
2512
|
+
const brokerRecord = processRecord(NATS_PIDFILE, context);
|
|
2513
|
+
const omitted = journal?.space === context.space ? stackStartedWithoutManager(journal)
|
|
2514
|
+
: pin.kind === "match" && brokerRecord.kind === "live" && pin.record.pid === brokerRecord.pid;
|
|
2515
|
+
if (omitted)
|
|
2516
|
+
return { name: "manager", verdict: "not-started", facts: [...facts, "started with --no-manager"] };
|
|
2517
|
+
}
|
|
2518
|
+
catch (error) {
|
|
2519
|
+
return { name: "manager", verdict: "refused", facts: [...facts, `startup intent unreadable: ${error.message}`] };
|
|
2520
|
+
}
|
|
2521
|
+
}
|
|
2453
2522
|
return { name: "manager", verdict: liveRecord || (record.kind !== "dead" && hasLease) ? "not-serving" : "absent", facts };
|
|
2454
2523
|
}
|
|
2455
2524
|
finally {
|
|
@@ -2549,6 +2618,14 @@ async function webHealth(context) {
|
|
|
2549
2618
|
const facts = pidFacts(record);
|
|
2550
2619
|
const stopped = processVerdict(record);
|
|
2551
2620
|
if (record.kind === "absent") {
|
|
2621
|
+
try {
|
|
2622
|
+
const unsettled = serviceInstances(context.space, "web").map(instanceProjection).find((row) => row.recordedState !== "stopped" && ["gone", "foreign-pid", "previous-boot"].includes(row.observedProcess));
|
|
2623
|
+
if (unsettled)
|
|
2624
|
+
return { name: "web", verdict: "absent", facts: [`service instance ${unsettled.instanceId}`, `recorded ${unsettled.recordedState}`, unsettled.observedProcess] };
|
|
2625
|
+
}
|
|
2626
|
+
catch (e) {
|
|
2627
|
+
return { name: "web", verdict: "refused", facts: [`service instance records unreadable: ${e.message}`] };
|
|
2628
|
+
}
|
|
2552
2629
|
// An installation that cannot be read keeps the absent verdict rather than a clean zero.
|
|
2553
2630
|
let installed;
|
|
2554
2631
|
try {
|
|
@@ -2614,6 +2691,29 @@ async function brokerHealth(target) {
|
|
|
2614
2691
|
if (address === undefined)
|
|
2615
2692
|
return { name: "broker", verdict: "refused", facts: ["registered address unavailable", "invalid broker address"] };
|
|
2616
2693
|
try {
|
|
2694
|
+
const context = { root: target.root, space: target.space };
|
|
2695
|
+
const journal = readStackJournal(target.root)?.journal;
|
|
2696
|
+
if (journal?.space === target.space && journal.server === target.server) {
|
|
2697
|
+
const member = journal.members.find((row) => row.role === "broker");
|
|
2698
|
+
const instance = serviceInstances(target.space, STACK_DEFINITION.broker).find((row) => row.name === member?.instanceId);
|
|
2699
|
+
const observed = instance && instanceProjection(instance).observedProcess;
|
|
2700
|
+
if (!instance || observed && ["gone", "foreign-pid", "previous-boot"].includes(observed))
|
|
2701
|
+
return { name: "broker", verdict: "absent", facts: [`registered ${address}`, observed ?? "no local instance"] };
|
|
2702
|
+
if (observed !== "running")
|
|
2703
|
+
return { name: "broker", verdict: "refused", facts: [`registered ${address}`, `local process ${observed}`] };
|
|
2704
|
+
}
|
|
2705
|
+
else if (target.origin === "up" && target.mode !== "user" && (target.recordedServer === undefined || target.recordedServer === target.server)) {
|
|
2706
|
+
const record = processRecord(NATS_PIDFILE, context);
|
|
2707
|
+
const verdict = processVerdict(record);
|
|
2708
|
+
if (verdict)
|
|
2709
|
+
return { name: "broker", verdict, facts: [`registered ${address}`, ...pidFacts(record), ...(record.kind === "dead" ? ["stale pidfile"] : [])] };
|
|
2710
|
+
}
|
|
2711
|
+
if (target.mode !== "user") {
|
|
2712
|
+
const preflight = await preflightTarget(target);
|
|
2713
|
+
if (!preflight.ok)
|
|
2714
|
+
return { name: "broker", verdict: "not-serving", facts: [`registered ${address}`, workspaceErrorParts({ kind: "preflight", failure: preflight.kind, target, pruned: false }).message] };
|
|
2715
|
+
return { name: "broker", verdict: "serving", facts: [`registered ${address}`, "reachable"] };
|
|
2716
|
+
}
|
|
2617
2717
|
const reachable = await isReachable(target.server, target.tlsRequired ? { tls: true } : {});
|
|
2618
2718
|
return reachable
|
|
2619
2719
|
? { name: "broker", verdict: "serving", facts: [`registered ${address}`, "reachable"] }
|
|
@@ -2623,36 +2723,35 @@ async function brokerHealth(target) {
|
|
|
2623
2723
|
return { name: "broker", verdict: "refused", facts: [`registered ${address}`, `probe refused: ${e.message}`] };
|
|
2624
2724
|
}
|
|
2625
2725
|
}
|
|
2626
|
-
async function printComponentHealth(
|
|
2726
|
+
async function printComponentHealth(selected) {
|
|
2627
2727
|
section("Component Health");
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
target = resolveMeshTarget(cwd, { server: values.server, space: values.space });
|
|
2631
|
-
}
|
|
2632
|
-
catch (e) {
|
|
2728
|
+
if (!selected.ok) {
|
|
2729
|
+
const e = selected.error;
|
|
2633
2730
|
if (isWorkspaceTargetError(e)) {
|
|
2634
|
-
|
|
2731
|
+
const verdict = e.code === "not-started" ? "absent" : "refused";
|
|
2732
|
+
printComponent({ name: "target", verdict, facts: [e.code, renderWorkspaceError({ kind: "target", error: e }).replace(/^✗ /, "")] });
|
|
2733
|
+
process.exitCode = COMPONENT_EXIT[verdict];
|
|
2734
|
+
return;
|
|
2735
|
+
}
|
|
2736
|
+
if (e instanceof UnregisteredRoot) {
|
|
2737
|
+
printComponent({ name: "target", verdict: "refused", facts: ["unregistered-root", `no space is registered or prepared here for ${e.root}`] });
|
|
2635
2738
|
process.exitCode = COMPONENT_EXIT.refused;
|
|
2636
2739
|
return;
|
|
2637
2740
|
}
|
|
2638
2741
|
throw e;
|
|
2639
2742
|
}
|
|
2640
|
-
|
|
2641
|
-
if (target.source === "local-space") {
|
|
2642
|
-
printComponent({ name: "target", verdict: "refused", facts: ["unregistered-root", `no space is registered or prepared here for ${target.root}`] });
|
|
2643
|
-
process.exitCode = COMPONENT_EXIT.refused;
|
|
2644
|
-
return;
|
|
2645
|
-
}
|
|
2743
|
+
const target = selected.target;
|
|
2646
2744
|
const context = { root: target.root, space: target.space, userAuth: target.mode === "user" };
|
|
2647
2745
|
// ONE credential read for the whole pass (user mode resolves the signed-in login once; the
|
|
2648
2746
|
// static shape is just the target's own auth material), shared by the manager and delivery
|
|
2649
2747
|
// probes so the two rows cannot disagree about whose credential they probed with.
|
|
2650
2748
|
const credential = await componentCredential(target);
|
|
2749
|
+
const broker = await brokerHealth(target);
|
|
2651
2750
|
const components = await Promise.all([
|
|
2652
|
-
managerHealth(target, context, credential),
|
|
2751
|
+
managerHealth(target, context, credential, broker),
|
|
2653
2752
|
deliveryHealth(target, context, credential),
|
|
2654
2753
|
webHealth(context),
|
|
2655
|
-
|
|
2754
|
+
broker,
|
|
2656
2755
|
]);
|
|
2657
2756
|
for (const component of components)
|
|
2658
2757
|
printComponent(component);
|