@cotal-ai/cli 0.174.3 → 0.174.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/command.d.ts.map +1 -1
- package/dist/command.js +8 -5
- package/dist/command.js.map +1 -1
- package/dist/commands/agents.d.ts.map +1 -1
- package/dist/commands/agents.js +17 -10
- package/dist/commands/agents.js.map +1 -1
- package/dist/commands/channel-members.d.ts.map +1 -1
- package/dist/commands/channel-members.js +9 -7
- package/dist/commands/channel-members.js.map +1 -1
- package/dist/commands/channels.d.ts.map +1 -1
- package/dist/commands/channels.js +16 -7
- package/dist/commands/channels.js.map +1 -1
- package/dist/commands/chat.js +1 -1
- package/dist/commands/chat.js.map +1 -1
- package/dist/commands/clean.d.ts.map +1 -1
- package/dist/commands/clean.js +5 -3
- package/dist/commands/clean.js.map +1 -1
- package/dist/commands/config.d.ts.map +1 -1
- package/dist/commands/config.js +8 -1
- package/dist/commands/config.js.map +1 -1
- package/dist/commands/describe.d.ts.map +1 -1
- package/dist/commands/describe.js +11 -1
- package/dist/commands/describe.js.map +1 -1
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +21 -9
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/down-preserve.d.ts.map +1 -1
- package/dist/commands/down-preserve.js +2 -1
- package/dist/commands/down-preserve.js.map +1 -1
- package/dist/commands/endpoint-authoring.d.ts.map +1 -1
- package/dist/commands/endpoint-authoring.js +20 -19
- package/dist/commands/endpoint-authoring.js.map +1 -1
- package/dist/commands/endpoint.d.ts.map +1 -1
- package/dist/commands/endpoint.js +7 -2
- package/dist/commands/endpoint.js.map +1 -1
- package/dist/commands/endpoints.d.ts.map +1 -1
- package/dist/commands/endpoints.js +12 -5
- package/dist/commands/endpoints.js.map +1 -1
- package/dist/commands/ext.d.ts +2 -6
- package/dist/commands/ext.d.ts.map +1 -1
- package/dist/commands/ext.js +19 -25
- package/dist/commands/ext.js.map +1 -1
- package/dist/commands/history-clear.d.ts.map +1 -1
- package/dist/commands/history-clear.js +5 -2
- package/dist/commands/history-clear.js.map +1 -1
- package/dist/commands/join.d.ts.map +1 -1
- package/dist/commands/join.js +23 -20
- package/dist/commands/join.js.map +1 -1
- package/dist/commands/meshes-add.d.ts.map +1 -1
- package/dist/commands/meshes-add.js +3 -2
- package/dist/commands/meshes-add.js.map +1 -1
- package/dist/commands/meshes.d.ts.map +1 -1
- package/dist/commands/meshes.js +17 -4
- package/dist/commands/meshes.js.map +1 -1
- package/dist/commands/persona-remote.d.ts.map +1 -1
- package/dist/commands/persona-remote.js +8 -4
- package/dist/commands/persona-remote.js.map +1 -1
- package/dist/commands/persona.d.ts.map +1 -1
- package/dist/commands/persona.js +38 -29
- package/dist/commands/persona.js.map +1 -1
- package/dist/commands/personas.js +1 -5
- package/dist/commands/personas.js.map +1 -1
- package/dist/commands/revoke-credential.d.ts.map +1 -1
- package/dist/commands/revoke-credential.js +5 -2
- package/dist/commands/revoke-credential.js.map +1 -1
- package/dist/commands/service-registry.js +1 -1
- package/dist/commands/service-registry.js.map +1 -1
- package/dist/commands/setup.d.ts.map +1 -1
- package/dist/commands/setup.js +2 -2
- package/dist/commands/setup.js.map +1 -1
- package/dist/commands/space-delete.d.ts.map +1 -1
- package/dist/commands/space-delete.js +17 -10
- package/dist/commands/space-delete.js.map +1 -1
- package/dist/commands/space-registration.d.ts.map +1 -1
- package/dist/commands/space-registration.js +11 -9
- package/dist/commands/space-registration.js.map +1 -1
- package/dist/commands/space.d.ts.map +1 -1
- package/dist/commands/space.js +39 -9
- package/dist/commands/space.js.map +1 -1
- package/dist/commands/spawn-flags.d.ts +5 -7
- package/dist/commands/spawn-flags.d.ts.map +1 -1
- package/dist/commands/spawn-flags.js +42 -6
- package/dist/commands/spawn-flags.js.map +1 -1
- package/dist/commands/spawn-preview.d.ts.map +1 -1
- package/dist/commands/spawn-preview.js +5 -3
- package/dist/commands/spawn-preview.js.map +1 -1
- package/dist/commands/spawn.d.ts.map +1 -1
- package/dist/commands/spawn.js +9 -2
- package/dist/commands/spawn.js.map +1 -1
- package/dist/commands/stack-up.d.ts.map +1 -1
- package/dist/commands/stack-up.js +12 -6
- package/dist/commands/stack-up.js.map +1 -1
- package/dist/commands/status-health.d.ts +139 -0
- package/dist/commands/status-health.d.ts.map +1 -0
- package/dist/commands/status-health.js +651 -0
- package/dist/commands/status-health.js.map +1 -0
- package/dist/commands/status-meshes.d.ts +26 -0
- package/dist/commands/status-meshes.d.ts.map +1 -0
- package/dist/commands/status-meshes.js +468 -0
- package/dist/commands/status-meshes.js.map +1 -0
- package/dist/commands/status-render.d.ts +30 -0
- package/dist/commands/status-render.d.ts.map +1 -0
- package/dist/commands/status-render.js +782 -0
- package/dist/commands/status-render.js.map +1 -0
- package/dist/commands/status.d.ts +2 -16
- package/dist/commands/status.d.ts.map +1 -1
- package/dist/commands/status.js +20 -1877
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/topology.d.ts.map +1 -1
- package/dist/commands/topology.js +4 -0
- package/dist/commands/topology.js.map +1 -1
- package/dist/commands/up-host.d.ts +19 -0
- package/dist/commands/up-host.d.ts.map +1 -0
- package/dist/commands/up-host.js +105 -0
- package/dist/commands/up-host.js.map +1 -0
- package/dist/commands/up-stores.d.ts +42 -0
- package/dist/commands/up-stores.d.ts.map +1 -0
- package/dist/commands/up-stores.js +242 -0
- package/dist/commands/up-stores.js.map +1 -0
- package/dist/commands/up-target.d.ts +2 -0
- package/dist/commands/up-target.d.ts.map +1 -1
- package/dist/commands/up-target.js +9 -0
- package/dist/commands/up-target.js.map +1 -1
- package/dist/commands/up.d.ts.map +1 -1
- package/dist/commands/up.js +27 -363
- package/dist/commands/up.js.map +1 -1
- package/dist/commands/update-process.d.ts.map +1 -1
- package/dist/commands/update-process.js +3 -15
- package/dist/commands/update-process.js.map +1 -1
- package/dist/commands/update.js +1 -1
- package/dist/commands/update.js.map +1 -1
- package/dist/commands/use.js +2 -2
- package/dist/commands/use.js.map +1 -1
- package/dist/console/app.js +5 -5
- package/dist/console/app.js.map +1 -1
- package/dist/console/commands.d.ts +1 -1
- package/dist/console/commands.d.ts.map +1 -1
- package/dist/console/commands.js +1 -1
- package/dist/console/commands.js.map +1 -1
- package/dist/console/ui/Feed.d.ts +2 -2
- package/dist/console/ui/Feed.d.ts.map +1 -1
- package/dist/console/ui/Feed.js +2 -2
- package/dist/console/ui/Feed.js.map +1 -1
- package/dist/console/ui/StatusBar.d.ts +1 -1
- package/dist/console/ui/StatusBar.d.ts.map +1 -1
- package/dist/console/ui/StatusBar.js +1 -1
- package/dist/console/ui/StatusBar.js.map +1 -1
- package/dist/console/ui/Tabs.d.ts +2 -2
- package/dist/console/ui/Tabs.d.ts.map +1 -1
- package/dist/console/ui/Tabs.js +4 -4
- package/dist/console/ui/Tabs.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/backup-artifact.d.ts.map +1 -1
- package/dist/lib/backup-artifact.js +19 -7
- package/dist/lib/backup-artifact.js.map +1 -1
- package/dist/lib/choose-target.d.ts +1 -1
- package/dist/lib/choose-target.d.ts.map +1 -1
- package/dist/lib/choose-target.js +7 -4
- package/dist/lib/choose-target.js.map +1 -1
- package/dist/lib/completion-install.js +7 -8
- package/dist/lib/completion-install.js.map +1 -1
- package/dist/lib/control.d.ts +8 -2
- package/dist/lib/control.d.ts.map +1 -1
- package/dist/lib/control.js +11 -4
- package/dist/lib/control.js.map +1 -1
- package/dist/lib/manager-choice.d.ts +2 -1
- package/dist/lib/manager-choice.d.ts.map +1 -1
- package/dist/lib/manager-choice.js +2 -2
- package/dist/lib/manager-choice.js.map +1 -1
- package/dist/lib/manifest/index.d.ts +1 -1
- package/dist/lib/manifest/index.d.ts.map +1 -1
- package/dist/lib/manifest/index.js +2 -2
- package/dist/lib/manifest/index.js.map +1 -1
- package/dist/lib/manifest/resolve.d.ts +1 -1
- package/dist/lib/manifest/resolve.d.ts.map +1 -1
- package/dist/lib/manifest/resolve.js +4 -4
- package/dist/lib/manifest/resolve.js.map +1 -1
- package/dist/lib/npm-invocation.d.ts +6 -0
- package/dist/lib/npm-invocation.d.ts.map +1 -0
- package/dist/lib/npm-invocation.js +18 -0
- package/dist/lib/npm-invocation.js.map +1 -0
- package/dist/lib/persona-files.d.ts +1 -0
- package/dist/lib/persona-files.d.ts.map +1 -1
- package/dist/lib/persona-files.js +6 -2
- package/dist/lib/persona-files.js.map +1 -1
- package/dist/lib/personas.d.ts +1 -2
- package/dist/lib/personas.d.ts.map +1 -1
- package/dist/lib/personas.js +12 -3
- package/dist/lib/personas.js.map +1 -1
- package/dist/lib/private-directory.d.ts +3 -3
- package/dist/lib/private-directory.d.ts.map +1 -1
- package/dist/lib/private-directory.js +17 -7
- package/dist/lib/private-directory.js.map +1 -1
- package/dist/lib/service-presets.d.ts.map +1 -1
- package/dist/lib/service-presets.js +10 -5
- package/dist/lib/service-presets.js.map +1 -1
- package/dist/lib/stack-journal.d.ts.map +1 -1
- package/dist/lib/stack-journal.js +7 -4
- package/dist/lib/stack-journal.js.map +1 -1
- package/dist/telemetry.d.ts.map +1 -1
- package/dist/telemetry.js +3 -2
- package/dist/telemetry.js.map +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,782 @@
|
|
|
1
|
+
import { homedir } from "node:os";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { formatAge } from "@cotal-ai/core";
|
|
4
|
+
import { brokerUrlKey, canonicalRoot, CLI_USER_ACTOR, codeSpan, CommandFailure, homeCotalDir, OFFICIAL_CONNECTORS, spaceStreamsAbsent, } from "@cotal-ai/workspace";
|
|
5
|
+
import { storeWriteRepair } from "../lib/broker-store-health.js";
|
|
6
|
+
import { displayCmd } from "../lib/self-exec.js";
|
|
7
|
+
import { shellWord } from "../lib/endpoint-errors.js";
|
|
8
|
+
import { onRerun } from "../lib/control.js";
|
|
9
|
+
import { rolledBackNotes } from "../lib/restore.js";
|
|
10
|
+
import { STACK_DEFINITION } from "../lib/stack-journal.js";
|
|
11
|
+
import { homeHoldsStack } from "../lib/paths.js";
|
|
12
|
+
import { channelSeedRestartBlock } from "../lib/channel-seed.js";
|
|
13
|
+
import { rootStoreProblem } from "../lib/store-dir.js";
|
|
14
|
+
import { natsServerLabel } from "../lib/nats-bin.js";
|
|
15
|
+
import { readCursor } from "../seed/lock.js";
|
|
16
|
+
import { responderText } from "./status-delivery.js";
|
|
17
|
+
import {} from "./status-model.js";
|
|
18
|
+
// ---- the report ------------------------------------------------------------------------------
|
|
19
|
+
const cell = (text, tone) => (tone ? { text, tone } : text);
|
|
20
|
+
function personaText(p) {
|
|
21
|
+
if (p.default === "unreadable")
|
|
22
|
+
return `unreadable: ${p.error}`;
|
|
23
|
+
const parts = [p.default === "valid" ? "default" : p.default === "invalid" ? "invalid default" : "no default"];
|
|
24
|
+
if (p.demo)
|
|
25
|
+
parts.push(`demo team ${p.demo}/3`);
|
|
26
|
+
return parts.join(" · ");
|
|
27
|
+
}
|
|
28
|
+
function personaTone(p) {
|
|
29
|
+
return p.default === "valid" ? "ok" : p.default === "invalid" || p.default === "unreadable" ? "failed" : "hint";
|
|
30
|
+
}
|
|
31
|
+
/** A catalog's summary and root. Green only for a `default` that loads, and never for a catalog
|
|
32
|
+
* `dim` marks as not the one spawn launches from. */
|
|
33
|
+
function personaCell(p, dim = false) {
|
|
34
|
+
const tone = dim ? "hint" : personaTone(p);
|
|
35
|
+
return cell(`${personaText(p)} · ${p.root}`, tone);
|
|
36
|
+
}
|
|
37
|
+
function processCell(p) {
|
|
38
|
+
const detail = p.detail ? ` · ${p.detail}` : "";
|
|
39
|
+
if (p.state === "unreadable" || p.state === "unknown")
|
|
40
|
+
return cell(p.detail ?? "process state unknown", "failed");
|
|
41
|
+
if (p.state === "not-serving")
|
|
42
|
+
return cell(`not serving (pid ${p.pid})${detail}`, "failed");
|
|
43
|
+
if (p.state === "running")
|
|
44
|
+
return cell(`running (pid ${p.pid})${detail}`, /NOT BOUND|unreadable/.test(detail) ? "failed" : "ok");
|
|
45
|
+
return cell(p.pid ? `${p.detail ?? "stopped"} (${p.pid})` : (p.detail ?? "down"), "hint");
|
|
46
|
+
}
|
|
47
|
+
function skillsCell(s) {
|
|
48
|
+
const remedy = `${displayCmd()} setup --skills`;
|
|
49
|
+
if (s.state === "unreadable")
|
|
50
|
+
return cell(`bundle error: ${s.error}`, "failed");
|
|
51
|
+
if (s.state === "current")
|
|
52
|
+
return cell(`current (${s.total})`, "ok");
|
|
53
|
+
if (s.state === "not-installed")
|
|
54
|
+
return cell(`not installed · ${remedy}`, "hint");
|
|
55
|
+
return cell(`${s.retired ? `${s.behind} to reconcile (${s.retired} retired)` : `${s.behind}/${s.total} out of date`} · ${remedy}`, "waiting");
|
|
56
|
+
}
|
|
57
|
+
/** The nats-server a broker start would run, or why it refuses the one it found. */
|
|
58
|
+
function brokerExecutable(m) {
|
|
59
|
+
if (m.natsProblem)
|
|
60
|
+
return m.natsProblem;
|
|
61
|
+
return natsServerLabel({ ...m.natsServer, source: m.nats === "path" ? "path" : "bundled" });
|
|
62
|
+
}
|
|
63
|
+
function machineSection(m) {
|
|
64
|
+
const tone = { ok: "ok", warn: "waiting", error: "failed", off: "hint" };
|
|
65
|
+
const rows = [
|
|
66
|
+
["cotal-ai", cell(`v${m.version} (${m.install.kind === "source" ? "source checkout" : m.install.kind}: ${m.install.root}${m.install.note ? ` · ${m.install.note}` : ""})`, "ok")],
|
|
67
|
+
["NATS", m.nats === "missing" ? cell("missing", "failed") : cell(brokerExecutable(m), m.natsProblem ? "failed" : "ok")],
|
|
68
|
+
...m.integrations.map((r) => [r.name, cell(r.text, tone[r.state])]),
|
|
69
|
+
];
|
|
70
|
+
if (m.connectors === null)
|
|
71
|
+
rows.push(["Connectors", cell("unreadable - see the warning below", "failed")]);
|
|
72
|
+
else if (!m.connectors.length)
|
|
73
|
+
rows.push(["Connectors", cell(`none installed · \`${displayCmd()} setup\``, "hint")]);
|
|
74
|
+
for (const h of m.connectors ?? [])
|
|
75
|
+
rows.push([h.name, h.missing.length ? cell(`${h.missing.join(", ")} not on PATH`, "hint") : cell(h.requires.length ? `${h.requires.join(", ")} on PATH` : "in-process", "ok")]);
|
|
76
|
+
rows.push(["Skills (.agents)", skillsCell(m.skills)]);
|
|
77
|
+
rows.push(["Web extension", m.web.installed === null ? cell(m.web.installedError ?? "unreadable", "failed") : m.web.installed ? cell("installed", "ok") : cell("not installed", "hint")]);
|
|
78
|
+
// An install state that could not be read reads `down`, since only a known absence is `not installed`.
|
|
79
|
+
rows.push(["Web process", m.web.url ? cell(m.web.url, "ok") : m.web.urlError ? cell(m.web.urlError, "failed") : cell(m.web.installed === false ? "not installed" : "down", "hint")]);
|
|
80
|
+
return { title: "Machine", blocks: [{ kind: "fields", rows }] };
|
|
81
|
+
}
|
|
82
|
+
function extensionsSection(e) {
|
|
83
|
+
const rows = [["root", e.root]];
|
|
84
|
+
if (e.items === null)
|
|
85
|
+
rows.push(["installed", cell("manifest unreadable - see the warning below", "failed")]);
|
|
86
|
+
else if (!e.items.length)
|
|
87
|
+
rows.push(["installed", cell("none", "hint")]);
|
|
88
|
+
for (const x of e.items ?? [])
|
|
89
|
+
rows.push([x.label, cell(`v${x.version}${x.package === x.label ? "" : ` · ${x.package}`}`, "ok")]);
|
|
90
|
+
return { title: "Extensions", blocks: [{ kind: "fields", rows }] };
|
|
91
|
+
}
|
|
92
|
+
function folderSection(f, selected) {
|
|
93
|
+
const rows = [["root", f.root]];
|
|
94
|
+
const cwd = canonicalRoot(process.cwd());
|
|
95
|
+
if (cwd !== canonicalRoot(f.root) && (canonicalRoot(f.root) === canonicalRoot(homedir()) || canonicalRoot(join(f.root, ".cotal")) === canonicalRoot(homeCotalDir())))
|
|
96
|
+
rows.push(["root selection", homeHoldsStack(f.root)
|
|
97
|
+
? cell("inherited the machine's home .cotal, which holds a stack; commands here reach that stack until up here makes this folder its own project root", "hint")
|
|
98
|
+
: cell("inherited the machine's home .cotal; up here makes this folder its own project root", "hint")]);
|
|
99
|
+
const auth = f.auth;
|
|
100
|
+
if (auth.state === "unreadable")
|
|
101
|
+
rows.push(["auth", cell(auth.error ?? "unreadable", "failed")]);
|
|
102
|
+
else if (auth.state === "spaces")
|
|
103
|
+
rows.push(["auth", cell(`${auth.spaces.length} spaces · ${auth.spaces.join(", ")}`, "ok")]);
|
|
104
|
+
else if (auth.state === "space")
|
|
105
|
+
rows.push(["auth", cell(`space ${auth.spaces[0]}${auth.userAuth ? " · user-auth" : ""}`, "ok")]);
|
|
106
|
+
else
|
|
107
|
+
rows.push(["auth", cell("none (open/local only)", "hint")]);
|
|
108
|
+
if (f.launches === null) {
|
|
109
|
+
rows.push(["personas", personaCell(f.personas)]);
|
|
110
|
+
rows.push(["spawn root", cell("unresolved - see Selected Mesh below; until it resolves, no persona here is launchable", "waiting")]);
|
|
111
|
+
}
|
|
112
|
+
else if (f.launches)
|
|
113
|
+
rows.push(["personas", personaCell(f.personas)]);
|
|
114
|
+
else {
|
|
115
|
+
// The divergence. The folder's catalog is real and worth reporting, but it is NOT the spawn
|
|
116
|
+
// catalog, so its `default` must not be green: green here is the false capability claim.
|
|
117
|
+
rows.push(["personas", personaCell(f.personas, true)]);
|
|
118
|
+
if (selected.resolved) {
|
|
119
|
+
rows.push(["spawn root", cell(`differs · ${selected.personas.root}`, "waiting")]);
|
|
120
|
+
rows.push(["→ launches", cell(`${personaText(selected.personas)} · space ${selected.space} · via ${selected.source}`, personaTone(selected.personas))]);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (auth.state === "spaces")
|
|
124
|
+
rows.push(["processes", cell("not reported per space on a multi-space root", "hint")]);
|
|
125
|
+
for (const p of f.processes ?? [])
|
|
126
|
+
rows.push([p.name, processCell(p)]);
|
|
127
|
+
if (f.storedState)
|
|
128
|
+
rows.push(["stored state", cell("JetStream store persists across down/up", "hint")]);
|
|
129
|
+
return { title: "This Folder", blocks: [{ kind: "fields", rows }] };
|
|
130
|
+
}
|
|
131
|
+
function meshesSections(m) {
|
|
132
|
+
const check = { reachable: cell("reachable", "ok"), unreachable: cell("down", "failed"), "slow-link": cell("not answering", "failed"), "broker-stopped": cell("broker process is stopped", "failed"), "not-checked": cell("not checked", "hint") };
|
|
133
|
+
const blocks = [];
|
|
134
|
+
if (!m.items.length && !m.unreadable.length)
|
|
135
|
+
blocks.push({ kind: "lines", lines: [cell("none", "hint")] });
|
|
136
|
+
else
|
|
137
|
+
blocks.push({
|
|
138
|
+
kind: "table",
|
|
139
|
+
columns: [
|
|
140
|
+
{ key: "space", label: "SPACE" },
|
|
141
|
+
{ key: "check", label: "CHECK" },
|
|
142
|
+
{ key: "mode", label: "MODE" },
|
|
143
|
+
{ key: "server", label: "SERVER" },
|
|
144
|
+
{ key: "root", label: "ROOT" },
|
|
145
|
+
{ key: "note", label: "NOTE" },
|
|
146
|
+
],
|
|
147
|
+
rows: m.items.map((x) => ({
|
|
148
|
+
space: x.current ? cell(`* ${x.space}`, "selected") : ` ${x.space}`,
|
|
149
|
+
check: check[x.check],
|
|
150
|
+
mode: x.mode,
|
|
151
|
+
server: x.server ?? cell("unavailable", "failed"),
|
|
152
|
+
root: x.root,
|
|
153
|
+
// A `down` record means two different things, and the repair differs: a mesh this machine
|
|
154
|
+
// started can be re-`up`ed here, one registered by hand runs somewhere this machine doesn't
|
|
155
|
+
// control (and, unlike the others, its record is never swept away for it).
|
|
156
|
+
note: [
|
|
157
|
+
x.origin === "manual" ? "registered" : x.origin === "catalog" ? "discovered" : "",
|
|
158
|
+
x.tlsRequired ? "tls-required" : "",
|
|
159
|
+
x.eventsRequired ? "events: required" : "",
|
|
160
|
+
x.catalog ? `${x.catalog.name ? `${x.catalog.name} ` : ""}catalog ${x.catalog.error ? `stale since ${x.catalog.fetchedAt ?? "unknown"}: ${x.catalog.error}` : `snapshot ${x.catalog.fetchedAt ?? "unknown"}`}` : "",
|
|
161
|
+
].filter(Boolean).join(" "),
|
|
162
|
+
})),
|
|
163
|
+
});
|
|
164
|
+
if (!m.currentRecorded)
|
|
165
|
+
blocks.push({ kind: "lines", lines: [cell(`note: current mesh "${m.current}" is ${m.currentStopped ? "stopped" : m.currentPrepared ? "prepared, not started" : "not recorded"}`, "hint")] });
|
|
166
|
+
if (m.unreadable.length)
|
|
167
|
+
blocks.push({ kind: "lines", lines: m.unreadable.map((u) => cell(`unreadable: ${u.error}`, "failed")) });
|
|
168
|
+
const sections = [{ title: "Recorded Meshes", blocks }];
|
|
169
|
+
if (m.catalogs.length)
|
|
170
|
+
sections.push({ title: "Space Catalog Accounts", blocks: [{ kind: "lines", lines: m.catalogs.map((r) => `${r.idp} ${r.state}${r.error ? `: ${r.error}` : ""}`) }] });
|
|
171
|
+
return sections;
|
|
172
|
+
}
|
|
173
|
+
/** The pid of the selected space's running stack delivery member, from its owned service record. */
|
|
174
|
+
function stackDeliveryPid(r) {
|
|
175
|
+
return r.services?.instances?.find((item) => item.definition === STACK_DEFINITION.delivery && item.observedProcess === "running")?.pid ?? undefined;
|
|
176
|
+
}
|
|
177
|
+
function selectedSection(s, folder, deliveryPid, storeFull = false) {
|
|
178
|
+
if (!s.resolved)
|
|
179
|
+
return { title: "Selected Mesh", blocks: [{ kind: "fields", rows: [["target", cell(s.code, "failed")]] }] };
|
|
180
|
+
const rows = [
|
|
181
|
+
["space", s.space],
|
|
182
|
+
["server", s.server ?? cell("unavailable", "failed")],
|
|
183
|
+
["mode", s.mode],
|
|
184
|
+
];
|
|
185
|
+
if (s.eventsRequired)
|
|
186
|
+
rows.push(["events", "required"]);
|
|
187
|
+
if (s.tlsRequired)
|
|
188
|
+
rows.push(["transport", "tls-required"]);
|
|
189
|
+
if (s.idp)
|
|
190
|
+
rows.push(["idp", s.idp]);
|
|
191
|
+
rows.push(["source", s.source], ["root", s.root], ["personas", personaCell(s.personas)]);
|
|
192
|
+
if (s.mode === "user") {
|
|
193
|
+
rows.push(["connection", s.connection === "reachable" ? cell("reachable", "ok") : cell("unreachable", "failed")]);
|
|
194
|
+
const l = s.login;
|
|
195
|
+
if (!l)
|
|
196
|
+
rows.push(["login", cell("unreadable - see the warning below", "failed")]);
|
|
197
|
+
if (l && !l.subject)
|
|
198
|
+
rows.push(["login", cell(`not signed in - ${codeSpan(`${displayCmd()} login --idp ${l.idp}`)}`, "waiting")]);
|
|
199
|
+
if (l?.subject) {
|
|
200
|
+
rows.push(["login", cell(`${l.subject} · session until ${l.expiresAt}`, "ok")]);
|
|
201
|
+
if (l.actor === "not-granted")
|
|
202
|
+
rows.push(["actor", cell(`"${CLI_USER_ACTOR}" not granted - ${codeSpan(`${displayCmd()} actor grant ${CLI_USER_ACTOR} --sub ${l.subject} --full`)}`, "waiting")]);
|
|
203
|
+
else if (l.actor === "granted" && l.grant)
|
|
204
|
+
rows.push([
|
|
205
|
+
"actor",
|
|
206
|
+
cell(`"${CLI_USER_ACTOR}" granted${l.grant.label ? ` (${l.grant.label})` : ""} - read [${l.grant.read.join(", ")}], post [${l.grant.post.join(", ")}]${l.grant.scope.length ? `, scope [${l.grant.scope.join(", ")}]` : ""}`, "ok"),
|
|
207
|
+
]);
|
|
208
|
+
else
|
|
209
|
+
rows.push(["actor", cell("grant not checkable on this machine (no local ledger)", "hint")]);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
rows.push(["connection", s.connection === "ok" ? cell("ok", "ok") : cell(`${s.connection}${s.staleRecord ? " (stale registry entry)" : ""}`, "failed")]);
|
|
214
|
+
const responder = responderText(s.deliveryResponder, s.mode, Boolean(servedStack(folder, s) && folder.stackBlock), deliveryPid, storeFull);
|
|
215
|
+
if (responder)
|
|
216
|
+
rows.push(["delivery responder", cell(responder.text, responder.tone)]);
|
|
217
|
+
}
|
|
218
|
+
if (s.snapshot.state === "unavailable" || (s.mode === "user" && s.snapshot.state === "skipped"))
|
|
219
|
+
rows.push(["live snapshot", cell(`${s.snapshot.state === "unavailable" ? "unavailable" : "not read"} (${s.snapshot.reason})`, s.snapshot.state === "unavailable" ? "failed" : "hint")]);
|
|
220
|
+
if (s.channels)
|
|
221
|
+
rows.push(["channels", s.channels.length ? s.channels.map((ch) => `${ch.channel}(${ch.messages})`).join(", ") : "none"]);
|
|
222
|
+
if (s.membershipFeed)
|
|
223
|
+
rows.push(["membership feed", s.membershipFeed.asOf ? cell(`${s.membershipFeed.entries} entries · updated ${formatAge(Math.max(0, Date.now() - Date.parse(s.membershipFeed.asOf)))} ago`, "ok") : cell("no heartbeat", "hint")]);
|
|
224
|
+
return { title: "Selected Mesh", blocks: [{ kind: "fields", rows }] };
|
|
225
|
+
}
|
|
226
|
+
function stateCell(text, tone) {
|
|
227
|
+
return { text, tone, mark: tone === "hint" ? "○" : "●" };
|
|
228
|
+
}
|
|
229
|
+
/** The agent applications this machine has set up: those whose required executables are all on PATH,
|
|
230
|
+
* and the ones that run in this process. The rest are what `cotal setup` adds. */
|
|
231
|
+
function setUpApplications(m) {
|
|
232
|
+
return (m.connectors ?? []).filter((connector) => !connector.missing.length).map((connector) => connector.name);
|
|
233
|
+
}
|
|
234
|
+
/** The applications line: the names that are set up, and how many more `cotal setup` would add. */
|
|
235
|
+
function applicationsCell(m, interactive) {
|
|
236
|
+
if (m.connectors === null)
|
|
237
|
+
return stateCell("could not be read", "failed");
|
|
238
|
+
const setUp = setUpApplications(m), others = m.connectors.length - setUp.length;
|
|
239
|
+
if (!interactive)
|
|
240
|
+
return setUp.length ? stateCell(`${setUp.join(", ")}${others ? ` · ${others} not set up` : ""}`, "ok") : stateCell("not set up", "hint");
|
|
241
|
+
if (!setUp.length)
|
|
242
|
+
return stateCell(`not set up · \`${displayCmd()} setup\` adds one`, "hint");
|
|
243
|
+
return stateCell(`${setUp.join(", ")}${others ? ` · ${others} more with \`${displayCmd()} setup\`` : ""}`, "ok");
|
|
244
|
+
}
|
|
245
|
+
/** The extensions line: one count at the version they share, naming only those that differ from it.
|
|
246
|
+
* The versions are the manifest pins, so a differing one is a skew an upgrade did not carry. */
|
|
247
|
+
function extensionsCell(e) {
|
|
248
|
+
if (e.items === null)
|
|
249
|
+
return stateCell("manifest could not be read", "failed");
|
|
250
|
+
if (!e.items.length)
|
|
251
|
+
return undefined;
|
|
252
|
+
const counts = new Map();
|
|
253
|
+
for (const item of e.items)
|
|
254
|
+
counts.set(item.version, (counts.get(item.version) ?? 0) + 1);
|
|
255
|
+
const shared = [...counts].sort((a, b) => b[1] - a[1])[0][0];
|
|
256
|
+
const odd = e.items.filter((item) => item.version !== shared);
|
|
257
|
+
const text = `${e.items.length} extension${e.items.length === 1 ? "" : "s"} at ${shared}`;
|
|
258
|
+
return odd.length ? stateCell(`${text} · ${odd.map((item) => `${item.label} v${item.version}`).join(" · ")}`, "waiting") : text;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* What this machine has set up, and what needs attention.
|
|
262
|
+
*
|
|
263
|
+
* A row in its good state says nothing a reader acts on, and a piece of an application this machine
|
|
264
|
+
* does not have is what `cotal setup` adds, which the applications line already counts. So an
|
|
265
|
+
* application's own rows (the Claude plugin, Desktop and skills) appear only for an application that
|
|
266
|
+
* IS set up, and only when they are not current; the broker executable appears when it is missing or
|
|
267
|
+
* refused and local broker records make it relevant; the dashboard, which is optional, appears
|
|
268
|
+
* when its record cannot be read. `--all` and
|
|
269
|
+
* `--wide` print every row, and `--verbose` adds the installation paths ({@link machineSection}).
|
|
270
|
+
*
|
|
271
|
+
* It used to print one row per known connector whether or not it was set up, every extension label
|
|
272
|
+
* with the same version spelled out on each, and the broker executable's full bundled path on a
|
|
273
|
+
* healthy machine: a block of text whose signal a reader had to hunt for.
|
|
274
|
+
*/
|
|
275
|
+
function machineOverview(r, wide, interactive, seed) {
|
|
276
|
+
const m = r.machine;
|
|
277
|
+
const tones = { ok: "ok", warn: "waiting", error: "failed", off: "hint" };
|
|
278
|
+
const setUp = setUpApplications(m);
|
|
279
|
+
// An application's rows carry its name: "Claude plugin" and "claude setup" are both claude's.
|
|
280
|
+
const ownedBySetUp = (label) => setUp.some((name) => label.toLowerCase().includes(name.toLowerCase()));
|
|
281
|
+
const rows = wide
|
|
282
|
+
? m.integrations.map((item) => [item.name, stateCell(item.text, tones[item.state])])
|
|
283
|
+
: m.integrations.filter((item) => item.state !== "ok" && ownedBySetUp(item.name)).map((item) => [item.name, stateCell(item.text, tones[item.state])]);
|
|
284
|
+
rows.unshift(["Agent applications", applicationsCell(m, interactive)]);
|
|
285
|
+
if (wide)
|
|
286
|
+
for (const connector of m.connectors ?? []) {
|
|
287
|
+
if (m.integrations.some((item) => item.name.toLowerCase().includes(connector.name.toLowerCase())))
|
|
288
|
+
continue;
|
|
289
|
+
rows.push([connector.name, stateCell(connector.missing.length ? `${connector.missing.join(", ")} not on PATH` : connector.requires.length ? "available on PATH" : "in-process", connector.missing.length ? "waiting" : "ok")]);
|
|
290
|
+
}
|
|
291
|
+
// A remote registration uses the broker elsewhere. Keep executable readiness in the full
|
|
292
|
+
// diagnostics, without making a hosted client repair a binary it does not need to run.
|
|
293
|
+
const localBroker = r.meshes.hasPrepared || r.meshes.currentPrepared || r.meshes.unreadable.length > 0 ||
|
|
294
|
+
r.meshes.items.some((entry) => entry.origin !== "manual" && entry.origin !== "catalog") ||
|
|
295
|
+
r.folder.controllerStack || r.folder.storedState || r.folder.auth.state !== "none" ||
|
|
296
|
+
(r.folder.stackJournal !== undefined && r.folder.stackJournal !== "absent") ||
|
|
297
|
+
r.folder.processes?.some((row) => row.name === "nats" && (row.pid !== null || row.state === "unreadable")) ||
|
|
298
|
+
(!r.selected.resolved && (r.selected.code === "not-started" || r.selected.code === "unregistered-root" || r.selected.code === "unreadable-auth"));
|
|
299
|
+
if (wide || (localBroker && (m.nats === "missing" || m.natsProblem)))
|
|
300
|
+
rows.push(["Broker executable", stateCell(m.nats === "missing" ? "not installed" : brokerExecutable(m), m.nats === "missing" ? "waiting" : m.natsProblem ? "failed" : "ok")]);
|
|
301
|
+
if (wide || (m.skills.state !== "current" && setUp.length))
|
|
302
|
+
rows.push(["Agent skills", skillsCell(m.skills)]);
|
|
303
|
+
if (wide || m.web.installed === null)
|
|
304
|
+
rows.push(["Dashboard", stateCell(m.web.installed === null ? "installation could not be read" : m.web.installed ? "installed" : "not installed · optional", m.web.installed === null ? "failed" : m.web.installed ? "ok" : "hint")]);
|
|
305
|
+
const extensions = wide
|
|
306
|
+
? r.extensions.items === null ? stateCell("manifest could not be read", "failed") : r.extensions.items.length ? r.extensions.items.map((item) => `${item.label} v${item.version}`).join(" · ") : undefined
|
|
307
|
+
: extensionsCell(r.extensions);
|
|
308
|
+
if (extensions !== undefined)
|
|
309
|
+
rows.push(["Extensions", extensions]);
|
|
310
|
+
if (seed)
|
|
311
|
+
rows.push(["Connector setup", stateCell(`incomplete · ${seed.package} failed during ${seed.phase}`, "failed")]);
|
|
312
|
+
return {
|
|
313
|
+
title: "This machine",
|
|
314
|
+
blocks: [
|
|
315
|
+
{ kind: "lines", lines: [`cotal ${m.version} · Node ${m.node} · ${m.platform}`] },
|
|
316
|
+
{ kind: "fields", rows },
|
|
317
|
+
],
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
function connectionCell(s) {
|
|
321
|
+
if (s.connection === "ok" || s.connection === "reachable")
|
|
322
|
+
return stateCell("reachable", "ok");
|
|
323
|
+
const states = {
|
|
324
|
+
"root-gone": "project folder was moved or deleted",
|
|
325
|
+
unreachable: "unreachable",
|
|
326
|
+
"slow-link": "not answering",
|
|
327
|
+
"broker-stopped": `broker process ${s.brokerPid} is stopped`,
|
|
328
|
+
"tls-trust": "TLS could not be verified",
|
|
329
|
+
"tls-unsupported": "listener does not offer required TLS",
|
|
330
|
+
"auth-unsupported": "listener does not enforce Cotal authentication",
|
|
331
|
+
"jetstream-unsupported": "listener does not offer JetStream",
|
|
332
|
+
"non-nats-listener": "non-NATS listener holds the broker address",
|
|
333
|
+
"stale-auth": "credentials need renewal",
|
|
334
|
+
"auth-required": "authentication required",
|
|
335
|
+
"open-wants-auth": "authentication required",
|
|
336
|
+
"registry-open-now-auth": "authentication required",
|
|
337
|
+
"creds-rejected": "credentials rejected",
|
|
338
|
+
"registry-creds-rejected": "credentials rejected",
|
|
339
|
+
"address-held": "address held by another space",
|
|
340
|
+
};
|
|
341
|
+
return stateCell(`${states[s.connection] ?? s.connection.replaceAll("-", " ")}${s.staleRecord ? " · saved registration needs attention" : ""}`, "failed");
|
|
342
|
+
}
|
|
343
|
+
/** Show recorded mode, TLS, and catalog problems. `cotal space show <name>` names the address. */
|
|
344
|
+
function signsInText(entry, wide) {
|
|
345
|
+
return [
|
|
346
|
+
`${entry.mode === "user" ? "user sign-in" : entry.mode === "auth" ? "static auth" : "open"}${entry.modeChecked ? "" : ", not checked"}`,
|
|
347
|
+
...(wide ? [entry.origin === "catalog" ? "saved catalog entry" : entry.origin === "manual" ? "registered endpoint" : "local registration"] : []),
|
|
348
|
+
entry.tlsRequired ? "TLS required" : "",
|
|
349
|
+
entry.catalog?.error ? "catalog refresh failed" : "",
|
|
350
|
+
].filter(Boolean).join(" · ");
|
|
351
|
+
}
|
|
352
|
+
/** The connection state of one row: the selected space's own dialed state when this row is the
|
|
353
|
+
* address it dialed, else the row's own check. A row that was not dialed carries no state, and the
|
|
354
|
+
* note under the table says so once instead of repeating it on every row. */
|
|
355
|
+
function spaceStateCell(r, entry) {
|
|
356
|
+
const selected = r.selected.resolved && entry.space === r.selected.space;
|
|
357
|
+
// The selected connection describes this row only when it dialed the row's address; under
|
|
358
|
+
// `--all` with a `--server` that names another, the row shows its own address's check.
|
|
359
|
+
if (selected && r.selected.resolved && entry.check !== "not-checked" && r.selected.server !== null && entry.server !== null &&
|
|
360
|
+
brokerUrlKey(r.selected.server) === brokerUrlKey(entry.server))
|
|
361
|
+
return connectionCell(r.selected);
|
|
362
|
+
if (entry.check === "not-checked")
|
|
363
|
+
return "";
|
|
364
|
+
return stateCell(entry.check === "slow-link" ? "not answering" : entry.check === "broker-stopped" ? "broker process is stopped" : entry.check, entry.check === "reachable" ? "ok" : "failed");
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* The spaces this machine knows: the selected one first with its connection state, then one line
|
|
368
|
+
* each for the others.
|
|
369
|
+
*
|
|
370
|
+
* Only the selected space is dialed, so the others carry no state and ONE note says so, rather than
|
|
371
|
+
* `not checked` repeated on every row; `--all` dials each and fills the column. The broker address
|
|
372
|
+
* is not a group title: it groups spaces by an address a reader does not act on here, and `cotal
|
|
373
|
+
* space show <name>` names it. `--all` and `--wide` keep the grouped report.
|
|
374
|
+
*/
|
|
375
|
+
function spacesOverview(r, wide, seedFailed) {
|
|
376
|
+
const blocks = [];
|
|
377
|
+
// The space this report is for: the target it resolved or the space it is about, else the selection
|
|
378
|
+
// it could not resolve.
|
|
379
|
+
const reported = r.selected.space ?? r.meshes.current;
|
|
380
|
+
const row = (entry) => ({
|
|
381
|
+
space: entry.space === reported ? cell(`→ ${entry.space}`, "selected") : entry.space,
|
|
382
|
+
state: spaceStateCell(r, entry),
|
|
383
|
+
detail: cell(signsInText(entry, wide), "hint"),
|
|
384
|
+
});
|
|
385
|
+
const columns = [{ key: "space", label: "Space" }, { key: "state", label: "Connection" }, { key: "detail", label: "Signs in" }];
|
|
386
|
+
if (!r.meshes.items.length && !r.meshes.unreadable.length)
|
|
387
|
+
blocks.push({ kind: "lines", lines: [cell("No spaces registered", "hint"), ...(seedFailed ? [] : [cell(`Sign in to Cotal Cloud with \`${displayCmd()} login\`.`, "hint")])] });
|
|
388
|
+
else if (wide) {
|
|
389
|
+
const groups = new Map();
|
|
390
|
+
for (const entry of r.meshes.items) {
|
|
391
|
+
const key = entry.server ?? `unavailable:${entry.space}`;
|
|
392
|
+
const group = groups.get(key);
|
|
393
|
+
if (group)
|
|
394
|
+
group.push(entry);
|
|
395
|
+
else
|
|
396
|
+
groups.set(key, [entry]);
|
|
397
|
+
}
|
|
398
|
+
for (const entries of groups.values()) {
|
|
399
|
+
blocks.push({ kind: "lines", lines: [cell(entries[0].server ?? "Broker address unavailable", "title")] });
|
|
400
|
+
blocks.push({ kind: "table", header: false, columns, rows: entries.map(row) });
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
else {
|
|
404
|
+
// The space this report is for first, then the rest by name: the one a command here targets is
|
|
405
|
+
// the one a reader looks for.
|
|
406
|
+
const ordered = [...r.meshes.items].sort((a, b) => Number(b.space === reported) - Number(a.space === reported) || a.space.localeCompare(b.space));
|
|
407
|
+
blocks.push({ kind: "table", header: false, columns, rows: ordered.map(row) });
|
|
408
|
+
if (r.meshes.items.some((entry) => entry.check === "not-checked"))
|
|
409
|
+
blocks.push({ kind: "lines", lines: [cell(`Unselected spaces are not dialed · \`${displayCmd()} status --all\` dials each`, "hint")] });
|
|
410
|
+
}
|
|
411
|
+
for (const unreadable of r.meshes.unreadable)
|
|
412
|
+
blocks.push({ kind: "lines", lines: [stateCell(`Registration could not be read: ${unreadable.error}`, "failed")] });
|
|
413
|
+
// One line per account, named by the account whose catalog failed rather than by its token URL.
|
|
414
|
+
for (const account of r.meshes.catalogs)
|
|
415
|
+
if (account.error)
|
|
416
|
+
blocks.push({ kind: "lines", lines: [stateCell(`Space catalog for ${account.account ?? account.idp} could not be refreshed: ${account.error}`, "failed")] });
|
|
417
|
+
if (!r.meshes.currentRecorded)
|
|
418
|
+
blocks.push({ kind: "lines", lines: [cell(`Selected space '${r.meshes.current}' is ${r.meshes.currentStopped ? "stopped" : r.meshes.currentPrepared ? "prepared, not started" : "not recorded"}${folderTargeted(r) ? "; it applies outside this folder" : ""}`, "waiting")] });
|
|
419
|
+
return { title: "Spaces", blocks };
|
|
420
|
+
}
|
|
421
|
+
/** The unresolved selections that mean nothing runs or is selected here, rather than a failure. */
|
|
422
|
+
const NOTHING_SELECTED = new Set(["no-meshes", "not-started", "unregistered-root"]);
|
|
423
|
+
/** Whether this report is for this folder's space, which a command without `--space` targets here
|
|
424
|
+
* instead of the selection. */
|
|
425
|
+
function folderTargeted(r) {
|
|
426
|
+
return typeof r.meshes.folder === "string" && r.meshes.folder === r.selected.space;
|
|
427
|
+
}
|
|
428
|
+
function selectedOverview(r) {
|
|
429
|
+
const s = r.selected;
|
|
430
|
+
const title = !s.resolved && s.recordedRoot !== undefined ? "This folder" : folderTargeted(r) ? "This folder's space" : "Selected space";
|
|
431
|
+
// Nothing running or selected is a state to start from, so it does not carry the mark of a live connection.
|
|
432
|
+
if (!s.resolved)
|
|
433
|
+
return { title, blocks: [
|
|
434
|
+
{ kind: "lines", lines: [stateCell(s.message, NOTHING_SELECTED.has(s.code) ? "hint" : "failed")] },
|
|
435
|
+
...(servedStack(r.folder, s) ? stackLines(r.folder) : []),
|
|
436
|
+
] };
|
|
437
|
+
// A broker named with `--server` is reported even when nothing on this machine is registered.
|
|
438
|
+
if (s.source !== "flag-server" && !r.meshes.items.length && !r.meshes.currentPrepared && r.folder.auth.state === "none" && !r.folder.processes?.some((item) => item.pid !== null))
|
|
439
|
+
return undefined;
|
|
440
|
+
const responder = responderText(s.deliveryResponder, s.mode, Boolean(servedStack(r.folder, s) && r.folder.stackBlock), stackDeliveryPid(r), r.store?.state === "full");
|
|
441
|
+
const rows = [
|
|
442
|
+
["Broker", s.server ?? stateCell("address unavailable", "failed")],
|
|
443
|
+
["Connection", connectionCell(s)],
|
|
444
|
+
...(s.spaceStreams.state === "absent" ? [["Space streams", stateCell(s.spaceStreams.stack === "running" ? "not on the broker · the space was deleted under its running stack" : "not on the broker · a space delete removed them", "failed")]] : []),
|
|
445
|
+
...(responder ? [["Delivery responder", stateCell(responder.text, responder.tone)]] : []),
|
|
446
|
+
...(r.store?.state === "write-failed" ? [["Store", stateCell(`write failed at ${r.store.at}: ${r.store.cause}${r.store.path ? ` · ${r.store.path}` : ""}`, "failed")]] : []),
|
|
447
|
+
...(r.store?.state === "full" ? [["Store", stateCell(`full · ${r.store.used} bytes stored, over its --max-file-store cap of ${r.store.cap} · ${r.store.path}`, "failed")]] : []),
|
|
448
|
+
...(r.store?.state === "damaged" ? [["Store", stateCell(`damage logged at ${r.store.at}: ${r.store.warning}`, "failed")]] : []),
|
|
449
|
+
...(r.stackManager ? [["Manager", r.stackManager.endpoint === "answered" ? stateCell("answering", "ok") : r.stackManager.endpoint === "not-answering" ? stateCell(`not answering · stack-manager pid ${r.stackManager.pid}`, "failed") : stateCell("endpoint not checked", "hint")]] : []),
|
|
450
|
+
["Access", s.mode === "user" ? "user sign-in" : s.mode === "auth" ? "static auth" : "open"],
|
|
451
|
+
["Project", s.rootGone ? stateCell(`${s.root} · folder is gone`, "failed") : s.root],
|
|
452
|
+
["Default agent", r.machine.defaults ? `${r.machine.defaults.harness ?? "application unresolved"} · persona ${r.machine.defaults.persona ?? "not set"}` : stateCell("saved defaults could not be read", "failed")],
|
|
453
|
+
["Persona catalog", s.personas.default === "valid" ? "default available" : stateCell(s.personas.default === "invalid" ? "default is invalid" : s.personas.default === "unreadable" ? "could not be read" : "no default persona", s.personas.default === "invalid" || s.personas.default === "unreadable" ? "failed" : "hint")],
|
|
454
|
+
];
|
|
455
|
+
if (s.tlsRequired)
|
|
456
|
+
rows.push(["Transport", "TLS required"]);
|
|
457
|
+
if (s.eventsRequired)
|
|
458
|
+
rows.push(["Events", "required"]);
|
|
459
|
+
if (s.mode === "user") {
|
|
460
|
+
if (!s.login)
|
|
461
|
+
rows.push(["Account", stateCell("could not be read", "failed")]);
|
|
462
|
+
else if (!s.login.subject)
|
|
463
|
+
rows.push(["Account", stateCell("not signed in", "waiting")]);
|
|
464
|
+
else {
|
|
465
|
+
rows.push(["Account", `${s.login.subject} · session until ${s.login.expiresAt}`]);
|
|
466
|
+
rows.push(["Grant", stateCell(s.login.actor === "granted" ? "granted" : s.login.actor === "not-granted" ? "not granted" : "not checkable on this machine", s.login.actor === "granted" ? "ok" : s.login.actor === "not-granted" ? "waiting" : "hint")]);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
if (s.snapshot.state === "unavailable")
|
|
470
|
+
rows.push(["Live details", stateCell(`unavailable · ${s.snapshot.reason}`, "waiting")]);
|
|
471
|
+
if (servedStack(r.folder, s) && r.folder.noManager && !r.stackManager) {
|
|
472
|
+
const service = r.folder.managerService;
|
|
473
|
+
const outside = r.outsideStackManager;
|
|
474
|
+
rows.push(["Manager", service
|
|
475
|
+
? stateCell(`the ${service.definition} service · instance ${service.instanceId} · outside this stack, which was started with --no-manager`, "ok")
|
|
476
|
+
: outside?.endpoint === "answered"
|
|
477
|
+
? stateCell(`answering${outside.instanceId ? ` · instance ${outside.instanceId}` : ""} · outside this stack, which was started with --no-manager`, "ok")
|
|
478
|
+
: stateCell(`${outside?.endpoint === "not-answering" ? "no manager answered" : "endpoint not checked"} · this stack was started with --no-manager`, "hint")]);
|
|
479
|
+
}
|
|
480
|
+
const blocks = [{ kind: "fields", rows }];
|
|
481
|
+
if (r.folder.root === s.root && r.folder.processSpace === s.space && r.folder.controllerStack) {
|
|
482
|
+
blocks.push({ kind: "lines", lines: [cell("Controller stack · its members are the stack-* rows under Owned services", "hint")] }, ...stackLines(r.folder));
|
|
483
|
+
}
|
|
484
|
+
else if (r.folder.root === s.root && r.folder.stackJournal === "unreadable") {
|
|
485
|
+
blocks.push({ kind: "lines", lines: [cell("Stack journal unreadable · no stack membership or stopped state was inferred; see Owned services and the journal warning", "failed")] });
|
|
486
|
+
}
|
|
487
|
+
else if (r.folder.root === s.root && r.folder.processSpace === s.space && r.folder.processes) {
|
|
488
|
+
blocks.push({ kind: "lines", lines: [cell("Legacy local process records", "label")] });
|
|
489
|
+
blocks.push({
|
|
490
|
+
kind: "table", header: false,
|
|
491
|
+
columns: [{ key: "name", label: "Service" }, { key: "state", label: "State" }],
|
|
492
|
+
rows: r.folder.processes.map((item) => ({
|
|
493
|
+
name: item.name === "nats" ? "Broker" : item.name === "manager" ? "Manager" : item.name === "delivery" ? "Delivery" : item.name === "web" ? "Web" : item.name,
|
|
494
|
+
state: item.state !== "stopped" ? processCell(item) : stateCell(item.pid === null && item.detail !== "stopped" ? "not started" : item.detail ?? "stopped", "hint"),
|
|
495
|
+
})),
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
else
|
|
499
|
+
blocks.push({ kind: "lines", lines: [cell("Legacy process records not checked here · the selected space has a different or unresolved local process scope", "hint")] });
|
|
500
|
+
if (r.folder.launches === false)
|
|
501
|
+
blocks.push({ kind: "lines", lines: [cell(`This folder's personas are not used by the selected space. Spawn uses ${s.personas.root}.`, "waiting")] });
|
|
502
|
+
return { title: `${title} → ${s.space}`, blocks };
|
|
503
|
+
}
|
|
504
|
+
/** The selected space and its root when this folder's controller stack serves it: a resolved one, or
|
|
505
|
+
* a prepared one that is not started, as an `up` cut off before it registered the space leaves it. */
|
|
506
|
+
export function servedStack(folder, s) {
|
|
507
|
+
if (s.space === undefined || s.root === undefined)
|
|
508
|
+
return undefined;
|
|
509
|
+
return folder.controllerStack && folder.root === s.root && folder.processSpace === s.space ? { space: s.space, root: s.root } : undefined;
|
|
510
|
+
}
|
|
511
|
+
/** This folder's own controller stack when it does not serve the selected space. The note under the
|
|
512
|
+
* heading sends to status when its last operation has no recorded outcome, so status names it. */
|
|
513
|
+
export function folderStack(folder, s) {
|
|
514
|
+
return folder.controllerStack && folder.processSpace !== null && !servedStack(folder, s) ? { space: folder.processSpace, root: folder.root } : undefined;
|
|
515
|
+
}
|
|
516
|
+
/** The lines that name this folder's stack operation cut off with no recorded outcome: one that keeps
|
|
517
|
+
* `up` and `down` from settling it, or one that left the stack part way. */
|
|
518
|
+
function stackLines(folder) {
|
|
519
|
+
const blocks = [];
|
|
520
|
+
if (folder.stackBlock)
|
|
521
|
+
blocks.push({ kind: "lines", lines: [stateCell(`Stack blocked · ${folder.stackBlock.reason}`, "waiting")] });
|
|
522
|
+
const part = folder.stackUnfinished;
|
|
523
|
+
if (part)
|
|
524
|
+
blocks.push({ kind: "lines", lines: [stateCell(part.kind === "up"
|
|
525
|
+
? part.running.length ? `Half started · the last up ended before ${roleList(part.stopped)} started; ${roleList(part.running)} ${part.running.length === 1 ? "runs" : "run"}` : "Start interrupted · the last up ended before any member started"
|
|
526
|
+
: part.stopped.length ? `Half stopped · the last down ended with ${roleList(part.running)} still running; ${roleList(part.stopped)} ${part.stopped.length === 1 ? "is" : "are"} stopped` : "Stop interrupted · the last down ended before any member stopped", "waiting")] });
|
|
527
|
+
return blocks;
|
|
528
|
+
}
|
|
529
|
+
/** Stack members as a status line names them: `broker`, `delivery and manager`. */
|
|
530
|
+
function roleList(roles) {
|
|
531
|
+
return roles.length > 1 ? `${roles.slice(0, -1).join(", ")} and ${roles.at(-1)}` : roles[0] ?? "";
|
|
532
|
+
}
|
|
533
|
+
/** Pre-commit backup claims and ready cuts with a missing source block ordinary startup. */
|
|
534
|
+
export function backupRecovery(maintenance, sourceMissing = false) {
|
|
535
|
+
return maintenance && (maintenance.state === "claimed" || maintenance.state === "restore-ready" || sourceMissing) ? maintenance.next : null;
|
|
536
|
+
}
|
|
537
|
+
function nextActions(r, seedFailed, interactive, recovery, preparedHarness, stoppedForeignListener = false) {
|
|
538
|
+
if (seedFailed)
|
|
539
|
+
return {
|
|
540
|
+
title: "Next",
|
|
541
|
+
blocks: [{ kind: "lines", lines: r.hints.flatMap(hint => hint.split("\n").map(line => cell(line, "hint"))) }],
|
|
542
|
+
};
|
|
543
|
+
if (recovery)
|
|
544
|
+
return { title: "Next", blocks: [...new Set([recovery, ...r.hints])].map((hint) => ({ kind: "lines", lines: [cell(hint, "hint")] })) };
|
|
545
|
+
const cmd = displayCmd();
|
|
546
|
+
const items = [];
|
|
547
|
+
const extra = [];
|
|
548
|
+
let restartBlock;
|
|
549
|
+
const noApplication = !setUpApplications(r.machine).length;
|
|
550
|
+
if (!r.selected.resolved && !r.meshes.items.length && !r.meshes.unreadable.length) {
|
|
551
|
+
items.push({ command: `${cmd} login`, description: "Sign in to Cotal Cloud" });
|
|
552
|
+
}
|
|
553
|
+
if (noApplication) {
|
|
554
|
+
const s = r.selected;
|
|
555
|
+
const connector = r.machine.connectors?.find((row) => row.name === preparedHarness);
|
|
556
|
+
if (interactive)
|
|
557
|
+
items.push({ command: `${cmd} setup`, description: !s.resolved && s.code !== "not-started" ? "Set up an agent application and a space" : "Set up an agent application" });
|
|
558
|
+
else if (connector && !s.resolved && s.code === "not-started" && s.root && s.space && !s.recordedRoot) {
|
|
559
|
+
const guide = Object.hasOwn(OFFICIAL_CONNECTORS, connector.name) ? `connect-${connector.name}` : "connectors";
|
|
560
|
+
extra.push(`Install ${connector.missing.join(", ")} on PATH first. See https://docs.cotal.ai/docs/${guide}/.`);
|
|
561
|
+
items.push({ command: `${cmd} setup --destination local --harness ${shellWord(connector.name)} --project ${shellWord(s.root)} --space ${shellWord(s.space)} --configure-only --no-input`, description: "" });
|
|
562
|
+
}
|
|
563
|
+
else
|
|
564
|
+
items.push({ command: `${cmd} setup --help`, description: "See setup flags for scripts. Bare setup needs a terminal." });
|
|
565
|
+
}
|
|
566
|
+
if (r.selected.resolved) {
|
|
567
|
+
const s = r.selected;
|
|
568
|
+
const reachable = s.connection === "ok" || s.connection === "reachable";
|
|
569
|
+
const scope = { space: s.source === "flag-server" ? undefined : s.space, server: s.source === "flag-server" || s.source === "flag-space-override" ? s.server : undefined };
|
|
570
|
+
if (!noApplication) {
|
|
571
|
+
if (s.personas.default !== "missing" && s.personas.default !== "valid")
|
|
572
|
+
items.push({ command: onRerun(`${cmd} persona show default`, scope), description: "See what is wrong with the default persona" });
|
|
573
|
+
else if (reachable && s.deliveryResponder !== "unbound" && s.deliveryResponder !== "stale")
|
|
574
|
+
items.push({ command: onRerun(`${cmd} spawn`, scope), description: s.personas.default === "missing" ? "Open your default agent; creates the shipped default persona" : "Open your default agent" });
|
|
575
|
+
}
|
|
576
|
+
if (reachable)
|
|
577
|
+
items.push({ command: onRerun(`${cmd} who`, scope), description: "See the live roster" });
|
|
578
|
+
if (r.stackManager?.endpoint === "answered" || r.outsideStackManager?.endpoint === "answered")
|
|
579
|
+
items.push({ command: onRerun(`${cmd} ps`, scope), description: "List managed agents" });
|
|
580
|
+
}
|
|
581
|
+
if (r.selected.resolved || !noApplication) {
|
|
582
|
+
items.push({ command: `${cmd} space`, description: "List the spaces on this machine" });
|
|
583
|
+
const unchecked = r.meshes.items.some(m => m.check === "not-checked");
|
|
584
|
+
if (!r.selected.resolved || r.selected.source !== "registry" || unchecked)
|
|
585
|
+
items.push({ command: `${cmd} use <name>`, description: "Select the default space" });
|
|
586
|
+
if (r.meshes.items.length > 1 && unchecked)
|
|
587
|
+
items.push({ command: `${cmd} status --all`, description: "Check every registered space" });
|
|
588
|
+
}
|
|
589
|
+
// A stopped broker is resumed, not restarted. A local controller stack that does not answer,
|
|
590
|
+
// or one with a member whose process is gone, otherwise restarts its stopped members from its
|
|
591
|
+
// own records. One whose last operation a member keeps unsettled is named the way out that
|
|
592
|
+
// `up` and `down` name instead. A stack started with --no-manager leaves its manager out by choice,
|
|
593
|
+
// so a manager record an earlier up left is not a stopped member, and the restart keeps the flag.
|
|
594
|
+
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;
|
|
595
|
+
// A connection to a `--server` address other than the recorded one does not say whether the stack
|
|
596
|
+
// answers; the hint `readSelected` adds names that address. A user-auth space is probed on its own path.
|
|
597
|
+
const dialed = r.selected.resolved ? r.selected : undefined;
|
|
598
|
+
const recordedServer = r.meshes.items.find((m) => m.space === dialed?.space)?.server;
|
|
599
|
+
const elsewhere = dialed !== undefined && dialed.mode !== "user" && (dialed.source === "flag-server" || dialed.source === "flag-space-override")
|
|
600
|
+
&& (recordedServer == null || dialed.server === null ? recordedServer !== dialed.server : brokerUrlKey(recordedServer) !== brokerUrlKey(dialed.server));
|
|
601
|
+
const stack = servedStack(r.folder, r.selected), own = stack !== undefined;
|
|
602
|
+
const seedBlocksRestart = r.selected.channelSeedBlocksRestart;
|
|
603
|
+
// This folder's own stack is blocked the same way under another selection, and its block leads too.
|
|
604
|
+
const blocked = stack ?? folderStack(r.folder, r.selected);
|
|
605
|
+
const block = blocked ? r.folder.stackBlock : undefined;
|
|
606
|
+
const origin = r.meshes.items.find((m) => m.space === dialed?.space)?.origin;
|
|
607
|
+
const legacy = dialed && !r.folder.controllerStack && r.folder.root === dialed.root && r.folder.processSpace === dialed.space;
|
|
608
|
+
const local = legacy && dialed.mode === "auth" && !["manual", "catalog"].includes(origin ?? "up");
|
|
609
|
+
const exited = legacy ? (r.folder.processes ?? []).filter((row) => (row.name === "nats" || row.name === "manager") && row.state === "stopped" && (row.pid !== null || row.detail === "stopped")).map((row) => row.name) : [];
|
|
610
|
+
const storeBlocked = !elsewhere && r.selected.resolved && r.selected.connection === "unreachable" && rootStoreProblem(r.selected.root) !== undefined;
|
|
611
|
+
if (r.selected.resolved && r.selected.connection === "broker-stopped")
|
|
612
|
+
items.unshift({ command: `kill -CONT ${r.selected.brokerPid}`, description: "Resume the stopped broker process so it answers again" });
|
|
613
|
+
else if (stoppedForeignListener) { /* The address remedy in hints takes precedence over a restart. */ }
|
|
614
|
+
else if (block && blocked) {
|
|
615
|
+
const inspect = { command: `${cmd} service status ${block.definition} --instance ${block.instanceId} --space ${shellWord(blocked.space)}`, description: block.route.kind === "inspect" ? "Inspect the member that keeps up and down from settling" : "Inspect that member" };
|
|
616
|
+
items.unshift(...(block.route.kind === "abandon" ? [{ command: `${cmd} down --abandon-stop ${block.route.requestId} --yes`, description: `Abandon the unconfirmed stop of ${block.definition}; up and down refuse until then` }, inspect] : [inspect]));
|
|
617
|
+
}
|
|
618
|
+
else if (stack && r.folder.stackUnfinished) {
|
|
619
|
+
const part = r.folder.stackUnfinished;
|
|
620
|
+
const restart = `${cmd} up --root ${shellWord(stack.root)}${part.noManager ? " --no-manager" : ""}`;
|
|
621
|
+
// An up that ended before it registered the space cannot be finished: the next up reuses the
|
|
622
|
+
// running broker, and delivery does not start for a space that is not registered.
|
|
623
|
+
items.unshift(...(part.kind === "up"
|
|
624
|
+
? r.selected.resolved || !part.running.length
|
|
625
|
+
? seedBlocksRestart ? [] : [{ command: restart, description: `Finish starting the stack: the last up ended before ${roleList(part.stopped)} started` }]
|
|
626
|
+
: [{ command: `${cmd} down --yes`, description: `Stop what the last up started: it ended before it registered the space, so up cannot finish it` }, { command: restart, description: "Then start the stack again" }]
|
|
627
|
+
: [{ command: `${cmd} down --yes`, description: `Finish stopping the stack: the last down ended with ${roleList(part.running)} still running` },
|
|
628
|
+
...(part.stopped.length && !seedBlocksRestart ? [{ command: `${cmd} up --root ${shellWord(stack.root)}`, description: "Or restart this stack's stopped members from its recorded inputs" }] : [])]));
|
|
629
|
+
}
|
|
630
|
+
else if (r.selected.resolved && r.selected.spaceStreams.state === "absent") {
|
|
631
|
+
// Up creates the streams again only while the stack's other members are stopped.
|
|
632
|
+
const stack = r.selected.spaceStreams.stack;
|
|
633
|
+
if (own && stack === "running")
|
|
634
|
+
items.unshift({ command: `${cmd} down --yes`, description: "Stop the stack its space was deleted under" }, { command: `${cmd} up`, description: "Then start it again; up creates the space's streams, empty" });
|
|
635
|
+
else if (own)
|
|
636
|
+
items.unshift({ command: `${cmd} up --root ${shellWord(r.selected.root)}`, description: stack === "stopped" ? "Create the space's streams again, empty, and restart the stack's stopped members" : `Create the space's streams again, empty; while the stack runs, stop it first with \`${cmd} down --yes\`` });
|
|
637
|
+
else {
|
|
638
|
+
const absent = spaceStreamsAbsent(r.selected.space, r.selected.spaceStreams.root ?? undefined, stack ?? undefined);
|
|
639
|
+
extra.push(`${absent.message}; ${absent.remedy}`);
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
else if (!storeBlocked && !seedBlocksRestart && own && r.selected.resolved && r.store?.state !== "full" && (memberGone || !elsewhere && r.selected.connection !== "ok" && r.selected.connection !== "reachable")) {
|
|
643
|
+
// `up` neither adopts nor replaces a service outside the stack that runs one of this root's
|
|
644
|
+
// records, so each is stopped first, with the stop `up` names.
|
|
645
|
+
const held = r.folder.heldServices ?? [], space = r.selected.space;
|
|
646
|
+
items.unshift(...held.map((row) => ({ command: `${cmd} svc stop ${row.definition} --instance ${row.instanceId} --space ${shellWord(space)} --yes`, description: `Stop the ${row.definition} service, which runs this root's ${row.record} (pid ${row.pid}) outside the stack` })), { command: `${cmd} up --root ${shellWord(r.selected.root)}${r.folder.noManager ? " --no-manager" : ""}`, description: held.length ? "Then restart this stack's stopped members from its recorded inputs" : "Restart this stack's stopped members from its recorded inputs" });
|
|
647
|
+
}
|
|
648
|
+
else if (!elsewhere && legacy && dialed.mode === "open" && dialed.connection === "ok" && origin === "up" && exited.includes("manager") && r.folder.processes?.some((row) => row.name === "nats" && row.state === "running")) {
|
|
649
|
+
restartBlock = channelSeedRestartBlock(dialed.root);
|
|
650
|
+
if (!restartBlock)
|
|
651
|
+
items.unshift({ command: `${cmd} up`, description: "Restart this folder's manager without stopping the broker" });
|
|
652
|
+
}
|
|
653
|
+
else if (!storeBlocked && !seedBlocksRestart && local && exited.length) {
|
|
654
|
+
const broker = exited.includes("nats"), manager = exited.includes("manager");
|
|
655
|
+
const notes = [...(broker ? ["up reopens the recorded store"] : []), ...(manager ? ["pass --runtime again if the manager ran on one"] : [])];
|
|
656
|
+
items.unshift({ command: `${cmd} up`, description: `Restart this folder's ${broker && manager ? "broker and manager" : broker ? "broker" : "manager"}, which exited; ${notes.join("; ")}` });
|
|
657
|
+
}
|
|
658
|
+
else if (!storeBlocked && !seedBlocksRestart && local && r.selected.resolved && r.selected.connection === "unreachable" && (r.folder.processes ?? []).every((row) => row.state === "stopped")) {
|
|
659
|
+
// A clean down leaves every member stopped with no pidfile. Spawn and ps need the stack, so the
|
|
660
|
+
// bare `up` that starts it again on its recorded address and store comes first.
|
|
661
|
+
items.unshift({ command: `${cmd} up`, description: "Start this folder's stopped stack again; pass --runtime again if the manager ran on one" });
|
|
662
|
+
}
|
|
663
|
+
else if (!seedBlocksRestart && !elsewhere && local && r.selected.resolved && r.selected.connection === "ok" && r.store?.state !== "full" && r.store?.state !== "write-failed"
|
|
664
|
+
&& (r.selected.deliveryResponder === "unbound" || r.selected.deliveryResponder === "stale")
|
|
665
|
+
&& r.folder.processes?.some((row) => row.name === "delivery" && row.state === "stopped")) {
|
|
666
|
+
items.unshift({ command: `${cmd} up`, description: "Restore the delivery responder" });
|
|
667
|
+
}
|
|
668
|
+
// A stack whose folder was deleted stops only from this machine's records.
|
|
669
|
+
if (r.selected.resolved && r.selected.rootGone)
|
|
670
|
+
items.unshift({ command: `${cmd} down --space ${shellWord(r.selected.space)} --yes`, description: "Stop the stack whose folder is gone and free its name" });
|
|
671
|
+
if (r.selected.resolved && r.selected.mode === "user" && r.selected.login && !r.selected.login.subject)
|
|
672
|
+
items.unshift({ command: `${cmd} login --idp ${r.selected.login.idp}`, description: "Sign in to the selected space" });
|
|
673
|
+
// A delivery member that runs with no lease is not replaced by `up`; `down` kills one that does not exit.
|
|
674
|
+
const deliveryPid = stackDeliveryPid(r);
|
|
675
|
+
if (r.selected.resolved && r.selected.deliveryResponder === "unbound" && deliveryPid !== undefined)
|
|
676
|
+
items.unshift({ command: `${cmd} service status stack-delivery${own ? "" : ` --space ${shellWord(r.selected.space)}`}`, description: `Read the delivery member's record: pid ${deliveryPid} is alive but holds no lease, so it is starting or not responding` }, { command: own ? `${cmd} down --yes` : `${cmd} down --space ${shellWord(r.selected.space)} --yes`, description: "If it stays that way, stop the stack; down kills a member that does not exit on SIGTERM" }, { command: own ? `${cmd} up` : `${cmd} up --root ${shellWord(r.selected.root)}`, description: "Then start the stack again" });
|
|
677
|
+
// A manager that does not answer cannot report its stop impact, so no stop route reaches it.
|
|
678
|
+
if (r.stackManager?.endpoint === "not-answering")
|
|
679
|
+
items.unshift({ command: `kill -KILL ${r.stackManager.pid}`, description: `The stack manager does not answer, so \`${cmd} down\` cannot stop it. If it stays that way, end its process; \`${cmd} down --yes\` then records it stopped` });
|
|
680
|
+
// The broker keeps a store write error until it restarts, so messages sent meanwhile may be lost.
|
|
681
|
+
if (r.store?.state === "write-failed") {
|
|
682
|
+
const repair = storeWriteRepair(r.store, r.selected.resolved ? r.selected.root : undefined, r.selected.space ?? "");
|
|
683
|
+
const first = `First ${repair}`;
|
|
684
|
+
// A broker without JetStream cannot record the manager's stop, and it stops only after the manager.
|
|
685
|
+
if (r.store.jetStreamDisabled && r.stackManager && r.selected.resolved)
|
|
686
|
+
items.unshift({ command: `kill -TERM ${r.stackManager.pid}`, description: "The broker disabled JetStream after the write failure and serves none until it restarts, which needs the manager stopped first. On this host, end the manager; it stops its agents by its default policy" }, { command: own ? `${cmd} down --yes` : `${cmd} down --space ${shellWord(r.selected.space)} --yes`, description: "Then stop the other members" }, { command: own ? `${cmd} up` : `${cmd} up --root ${shellWord(r.selected.root)}`, description: `${first}; then up starts the broker again with the history it kept` });
|
|
687
|
+
else
|
|
688
|
+
items.unshift({ command: `${cmd} down`, description: `${first}; then \`${cmd} up\` starts the broker again with the history it kept` });
|
|
689
|
+
}
|
|
690
|
+
// The broker refuses every write while the store is over its cap, so sends store nothing, and a
|
|
691
|
+
// stopped member starts again only once there is room. A larger cap makes that room and keeps the
|
|
692
|
+
// history, but needs the broker restarted, so the manager's own process is ended first where it
|
|
693
|
+
// runs, as a full store refuses its stop. This is the route up names. A history purge is not named:
|
|
694
|
+
// it frees only the channel history's bytes, which may leave the store over its cap.
|
|
695
|
+
if (r.store?.state === "full" && r.selected.resolved) {
|
|
696
|
+
const { root } = r.selected;
|
|
697
|
+
const manager = r.stackManager;
|
|
698
|
+
items.unshift(...(manager ? [{ command: `kill -TERM ${manager.pid}`, description: "End the manager on this host, as a full store refuses its stop; it stops its agents by its default policy" }] : []),
|
|
699
|
+
// `down` stops only the stack of the folder it runs in.
|
|
700
|
+
{ command: `${cmd} down --yes`, description: `${manager ? "Then stop the other members" : "Stop the stack"}${own ? "" : `; run it in ${root}`}` }, { command: own ? `${cmd} up --max-file-store <bytes>` : `${cmd} up --root ${shellWord(root)} --max-file-store <bytes>`, description: "Then start it again with a larger cap; the store keeps the history" });
|
|
701
|
+
}
|
|
702
|
+
// The broker keeps serving a store it found damage in, from what it can still read there.
|
|
703
|
+
if (r.store?.state === "damaged" && r.selected.resolved && r.services?.instances?.some((row) => row.definition === STACK_DEFINITION.broker))
|
|
704
|
+
items.unshift({ command: `${cmd} service logs stack-broker${own ? "" : ` --space ${shellWord(r.selected.space)}`}`, description: "Read what the broker logged about the damage it found in its store; history holds only what it could still read" });
|
|
705
|
+
const first = restartBlock ? [{ kind: "lines", lines: [cell(`Restart blocked: ${restartBlock.message}. ${restartBlock.remedy}`, "hint")] }] : [];
|
|
706
|
+
return { title: "Next", blocks: [...first, { kind: "commands", items }, ...[...extra, ...r.hints].map((hint) => ({ kind: "lines", lines: [cell(hint, "hint")] }))] };
|
|
707
|
+
}
|
|
708
|
+
function ownedServicesOverview(services) {
|
|
709
|
+
if (!services || services.state === "not-checked")
|
|
710
|
+
return undefined;
|
|
711
|
+
const blocks = [];
|
|
712
|
+
if (services.definitions === null)
|
|
713
|
+
blocks.push({ kind: "lines", lines: [stateCell("Saved service definitions unavailable", "waiting")] });
|
|
714
|
+
if (services.instances === null)
|
|
715
|
+
blocks.push({ kind: "lines", lines: [stateCell("Owned service instances unavailable; no stopped state inferred", "waiting")] });
|
|
716
|
+
if (services.instances?.length)
|
|
717
|
+
blocks.push({ kind: "table", columns: [{ key: "service", label: "Service" }, { key: "instance", label: "Full instance" }, { key: "host", label: "Execution host" }, { key: "process", label: "Process observation" }, { key: "readiness", label: "Recorded readiness" }, { key: "supervisor", label: "Supervisor record" }], rows: services.instances.slice(0, 100).map((row) => ({
|
|
718
|
+
service: row.definition, instance: row.instanceId, host: row.executionHost,
|
|
719
|
+
process: stateCell(row.observedProcess.replaceAll("-", " "), row.observedProcess === "running" ? "ok" : row.observedProcess === "unreadable" || row.observedProcess === "unresolved-launch" || row.observedProcess === "foreign-host" ? "waiting" : "hint"),
|
|
720
|
+
readiness: cell(`${row.startInterrupted ? "start interrupted" : row.readinessObservation.replaceAll("-", " ")} · ${row.readinessAsOf}`, "hint"),
|
|
721
|
+
supervisor: row.supervisorRecord.mechanism === "none-recorded" ? "not assigned here" : `${row.supervisorRecord.mechanism} · ${row.supervisorRecord.fileObservation}; OS state not checked`,
|
|
722
|
+
})) });
|
|
723
|
+
if (services.instances && services.instances.length > 100)
|
|
724
|
+
blocks.push({ kind: "lines", lines: [cell(`${services.instances.length - 100} instance rows omitted; --json retains the complete readable inventory.`, "hint")] });
|
|
725
|
+
const instantiated = new Set(services.instances?.map((row) => row.definition));
|
|
726
|
+
const saved = services.instances === null ? [] : services.definitions?.filter((row) => !instantiated.has(row.name)) ?? [];
|
|
727
|
+
if (saved.length)
|
|
728
|
+
blocks.push({ kind: "table", columns: [{ key: "service", label: "Saved service" }, { key: "type", label: "Launch type" }, { key: "observation", label: "Instance records" }], rows: saved.slice(0, 100).map((row) => ({ service: row.name, type: row.launch.type === "adapter" ? row.launch.adapter : "process", observation: "no owned instance recorded" })) });
|
|
729
|
+
if (saved.length > 100)
|
|
730
|
+
blocks.push({ kind: "lines", lines: [cell(`${saved.length - 100} saved definitions omitted; --json retains the complete readable inventory.`, "hint")] });
|
|
731
|
+
if (services.definitions?.length === 0 && services.instances?.length === 0)
|
|
732
|
+
blocks.push({ kind: "lines", lines: [cell("No saved definitions or owned instance records in this selected space.", "hint")] });
|
|
733
|
+
blocks.push({ kind: "lines", lines: [cell(`Local records and process observations as of ${services.observedAt}; non-atomic. Recorded readiness is historical, not a fresh endpoint response. No OS unit query, service control, adoption or remote process ownership is implied.`, "hint")] });
|
|
734
|
+
// The space is known here, and a sole instance names its service and full ID as well.
|
|
735
|
+
const sole = services.instances?.length === 1 ? services.instances[0] : undefined;
|
|
736
|
+
if (services.space !== null && (services.instances?.length || services.definitions?.length)) {
|
|
737
|
+
const inspect = `${displayCmd()} svc status ${sole ? `${sole.definition} --instance ${sole.instanceId}` : "<service> --instance <full-id>"} --space ${shellWord(services.space)}`;
|
|
738
|
+
blocks.push({ kind: "commands", items: [{ command: inspect, description: "Inspect one exact owned instance and its recorded supervisor" }, { command: `${displayCmd()} svc`, description: "Read the full saved-service inventory" }] });
|
|
739
|
+
}
|
|
740
|
+
return { title: `Owned services → ${services.space}`, blocks };
|
|
741
|
+
}
|
|
742
|
+
function bootAttemptOverview(snapshot) {
|
|
743
|
+
if (!snapshot)
|
|
744
|
+
return undefined;
|
|
745
|
+
const elsewhere = [...snapshot.elsewhere.slice(0, 100).map((row) => `Launch summary ${row.deploymentId} was recorded at ${row.root}. This folder was moved or copied since, so it reports only that earlier boot and blocks nothing here.`), ...(snapshot.elsewhere.length > 100 ? ["Additional summaries are in JSON."] : [])];
|
|
746
|
+
if (!snapshot.unsettled.length && !snapshot.additive.length && !snapshot.unreadable.length)
|
|
747
|
+
return elsewhere.length ? { title: "Deployment attempts", blocks: [{ kind: "fields", rows: [["Folder root", snapshot.root]] }, { kind: "lines", lines: elsewhere }] } : undefined;
|
|
748
|
+
return { title: "Deployment attempts", blocks: [
|
|
749
|
+
{ kind: "fields", rows: [["Folder root", snapshot.root], ["Local read", snapshot.state], ["Unsettled fresh", String(snapshot.unsettled.length)], ["Additive attempts", String(snapshot.additive.length)], ["Unreadable records", String(snapshot.unreadable.length)]] },
|
|
750
|
+
snapshot.unsettled.length ? { kind: "table", columns: [{ key: "id", label: "Fresh boot" }, { key: "space", label: "Space" }, { key: "broker", label: "Recorded broker" }], rows: snapshot.unsettled.slice(0, 100).map((row) => ({ id: row.deploymentId, space: row.space, broker: row.server })) } : { kind: "lines", lines: ["No readable unsettled fresh attempt in this folder."] },
|
|
751
|
+
snapshot.additive.length ? { kind: "table", columns: [{ key: "id", label: "Additive intent" }, { key: "space", label: "Space" }, { key: "state", label: "Recorded state" }], rows: snapshot.additive.slice(0, 100).map((row) => ({ id: row.deploymentId, space: row.space, state: row.recordedState })) } : { kind: "lines", lines: ["No readable additive attempt in this folder."] },
|
|
752
|
+
...(elsewhere.length ? [{ kind: "lines", lines: elsewhere }] : []),
|
|
753
|
+
{ kind: "lines", lines: [...snapshot.unreadable.slice(0, 100).map((path) => `Unreadable record: ${path}`), ...(snapshot.unsettled.length > 100 || snapshot.additive.length > 100 || snapshot.unreadable.length > 100 ? ["Additional records are in JSON."] : []), "A fresh intent may have started a broker; an additive intent may have changed its resources. No retry or stop authority follows from this read."] },
|
|
754
|
+
{ kind: "commands", items: [{ command: `${displayCmd()} team show <deployment-id>`, description: "Inspect the original attempt from its recorded root" }] },
|
|
755
|
+
] };
|
|
756
|
+
}
|
|
757
|
+
function maintenanceOverview(maintenance) {
|
|
758
|
+
if (!maintenance)
|
|
759
|
+
return undefined;
|
|
760
|
+
return { title: "Maintenance", blocks: [
|
|
761
|
+
{ kind: "fields", rows: [["Folder root", maintenance.root], ["Space", maintenance.space ?? "not read"], ["State", maintenance.state], ["Attempt", maintenance.attemptId ?? "not read"]] },
|
|
762
|
+
...(maintenance.next ? [{ kind: "lines", lines: [maintenance.next] }] : []),
|
|
763
|
+
...(maintenance.rolledBackRuns?.length ? [{ kind: "lines", lines: rolledBackNotes({ runs: maintenance.rolledBackRuns, more: maintenance.rolledBackRunsMore ?? 0 }) }] : []),
|
|
764
|
+
] };
|
|
765
|
+
}
|
|
766
|
+
/** The approved screen hierarchy; record-level diagnostics are opt-in. `wide` reports every row in
|
|
767
|
+
* full, as `--all` and `--wide` ask. */
|
|
768
|
+
export function statusView(r, verbose = false, wide = false, { interactive = false, preparedHarness, seed, recovery = backupRecovery(r.maintenance), stoppedForeignListener = false } = {}) {
|
|
769
|
+
const selected = selectedOverview(r);
|
|
770
|
+
// This folder's own stack under another selection, with the lines it has when it is selected.
|
|
771
|
+
const held = folderStack(r.folder, r.selected), heldLines = held ? stackLines(r.folder) : [];
|
|
772
|
+
const heldSection = held && heldLines.length ? { title: `This folder's space → ${held.space}`, blocks: heldLines } : undefined;
|
|
773
|
+
const owned = ownedServicesOverview(r.services);
|
|
774
|
+
const attempts = bootAttemptOverview(r.bootAttempts);
|
|
775
|
+
const maintenance = maintenanceOverview(r.maintenance);
|
|
776
|
+
const sections = [machineOverview(r, wide, interactive, seed), spacesOverview(r, wide, Boolean(seed)), ...(selected ? [selected] : []), ...(heldSection ? [heldSection] : []), ...(maintenance ? [maintenance] : []), ...(attempts ? [attempts] : []), ...(owned ? [owned] : [])];
|
|
777
|
+
if (verbose)
|
|
778
|
+
sections.push(machineSection(r.machine), extensionsSection(r.extensions), folderSection(r.folder, r.selected), ...meshesSections(r.meshes), selectedSection(r.selected, r.folder, stackDeliveryPid(r), r.store?.state === "full"));
|
|
779
|
+
sections.push(nextActions(r, Boolean(seed), interactive, recovery, preparedHarness, stoppedForeignListener));
|
|
780
|
+
return { sections };
|
|
781
|
+
}
|
|
782
|
+
//# sourceMappingURL=status-render.js.map
|