@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.
Files changed (205) hide show
  1. package/dist/command.d.ts.map +1 -1
  2. package/dist/command.js +8 -5
  3. package/dist/command.js.map +1 -1
  4. package/dist/commands/agents.d.ts.map +1 -1
  5. package/dist/commands/agents.js +17 -10
  6. package/dist/commands/agents.js.map +1 -1
  7. package/dist/commands/channel-members.d.ts.map +1 -1
  8. package/dist/commands/channel-members.js +9 -7
  9. package/dist/commands/channel-members.js.map +1 -1
  10. package/dist/commands/channels.d.ts.map +1 -1
  11. package/dist/commands/channels.js +16 -7
  12. package/dist/commands/channels.js.map +1 -1
  13. package/dist/commands/chat.js +1 -1
  14. package/dist/commands/chat.js.map +1 -1
  15. package/dist/commands/clean.d.ts.map +1 -1
  16. package/dist/commands/clean.js +5 -3
  17. package/dist/commands/clean.js.map +1 -1
  18. package/dist/commands/config.d.ts.map +1 -1
  19. package/dist/commands/config.js +8 -1
  20. package/dist/commands/config.js.map +1 -1
  21. package/dist/commands/describe.d.ts.map +1 -1
  22. package/dist/commands/describe.js +11 -1
  23. package/dist/commands/describe.js.map +1 -1
  24. package/dist/commands/doctor.d.ts.map +1 -1
  25. package/dist/commands/doctor.js +21 -9
  26. package/dist/commands/doctor.js.map +1 -1
  27. package/dist/commands/down-preserve.d.ts.map +1 -1
  28. package/dist/commands/down-preserve.js +2 -1
  29. package/dist/commands/down-preserve.js.map +1 -1
  30. package/dist/commands/endpoint-authoring.d.ts.map +1 -1
  31. package/dist/commands/endpoint-authoring.js +20 -19
  32. package/dist/commands/endpoint-authoring.js.map +1 -1
  33. package/dist/commands/endpoint.d.ts.map +1 -1
  34. package/dist/commands/endpoint.js +7 -2
  35. package/dist/commands/endpoint.js.map +1 -1
  36. package/dist/commands/endpoints.d.ts.map +1 -1
  37. package/dist/commands/endpoints.js +12 -5
  38. package/dist/commands/endpoints.js.map +1 -1
  39. package/dist/commands/ext.d.ts +2 -6
  40. package/dist/commands/ext.d.ts.map +1 -1
  41. package/dist/commands/ext.js +19 -25
  42. package/dist/commands/ext.js.map +1 -1
  43. package/dist/commands/history-clear.d.ts.map +1 -1
  44. package/dist/commands/history-clear.js +5 -2
  45. package/dist/commands/history-clear.js.map +1 -1
  46. package/dist/commands/join.d.ts.map +1 -1
  47. package/dist/commands/join.js +23 -20
  48. package/dist/commands/join.js.map +1 -1
  49. package/dist/commands/meshes-add.d.ts.map +1 -1
  50. package/dist/commands/meshes-add.js +3 -2
  51. package/dist/commands/meshes-add.js.map +1 -1
  52. package/dist/commands/meshes.d.ts.map +1 -1
  53. package/dist/commands/meshes.js +17 -4
  54. package/dist/commands/meshes.js.map +1 -1
  55. package/dist/commands/persona-remote.d.ts.map +1 -1
  56. package/dist/commands/persona-remote.js +8 -4
  57. package/dist/commands/persona-remote.js.map +1 -1
  58. package/dist/commands/persona.d.ts.map +1 -1
  59. package/dist/commands/persona.js +38 -29
  60. package/dist/commands/persona.js.map +1 -1
  61. package/dist/commands/personas.js +1 -5
  62. package/dist/commands/personas.js.map +1 -1
  63. package/dist/commands/revoke-credential.d.ts.map +1 -1
  64. package/dist/commands/revoke-credential.js +5 -2
  65. package/dist/commands/revoke-credential.js.map +1 -1
  66. package/dist/commands/service-registry.js +1 -1
  67. package/dist/commands/service-registry.js.map +1 -1
  68. package/dist/commands/setup.d.ts.map +1 -1
  69. package/dist/commands/setup.js +2 -2
  70. package/dist/commands/setup.js.map +1 -1
  71. package/dist/commands/space-delete.d.ts.map +1 -1
  72. package/dist/commands/space-delete.js +17 -10
  73. package/dist/commands/space-delete.js.map +1 -1
  74. package/dist/commands/space-registration.d.ts.map +1 -1
  75. package/dist/commands/space-registration.js +11 -9
  76. package/dist/commands/space-registration.js.map +1 -1
  77. package/dist/commands/space.d.ts.map +1 -1
  78. package/dist/commands/space.js +39 -9
  79. package/dist/commands/space.js.map +1 -1
  80. package/dist/commands/spawn-flags.d.ts +5 -7
  81. package/dist/commands/spawn-flags.d.ts.map +1 -1
  82. package/dist/commands/spawn-flags.js +42 -6
  83. package/dist/commands/spawn-flags.js.map +1 -1
  84. package/dist/commands/spawn-preview.d.ts.map +1 -1
  85. package/dist/commands/spawn-preview.js +5 -3
  86. package/dist/commands/spawn-preview.js.map +1 -1
  87. package/dist/commands/spawn.d.ts.map +1 -1
  88. package/dist/commands/spawn.js +9 -2
  89. package/dist/commands/spawn.js.map +1 -1
  90. package/dist/commands/stack-up.d.ts.map +1 -1
  91. package/dist/commands/stack-up.js +12 -6
  92. package/dist/commands/stack-up.js.map +1 -1
  93. package/dist/commands/status-health.d.ts +139 -0
  94. package/dist/commands/status-health.d.ts.map +1 -0
  95. package/dist/commands/status-health.js +651 -0
  96. package/dist/commands/status-health.js.map +1 -0
  97. package/dist/commands/status-meshes.d.ts +26 -0
  98. package/dist/commands/status-meshes.d.ts.map +1 -0
  99. package/dist/commands/status-meshes.js +468 -0
  100. package/dist/commands/status-meshes.js.map +1 -0
  101. package/dist/commands/status-render.d.ts +30 -0
  102. package/dist/commands/status-render.d.ts.map +1 -0
  103. package/dist/commands/status-render.js +782 -0
  104. package/dist/commands/status-render.js.map +1 -0
  105. package/dist/commands/status.d.ts +2 -16
  106. package/dist/commands/status.d.ts.map +1 -1
  107. package/dist/commands/status.js +20 -1877
  108. package/dist/commands/status.js.map +1 -1
  109. package/dist/commands/topology.d.ts.map +1 -1
  110. package/dist/commands/topology.js +4 -0
  111. package/dist/commands/topology.js.map +1 -1
  112. package/dist/commands/up-host.d.ts +19 -0
  113. package/dist/commands/up-host.d.ts.map +1 -0
  114. package/dist/commands/up-host.js +105 -0
  115. package/dist/commands/up-host.js.map +1 -0
  116. package/dist/commands/up-stores.d.ts +42 -0
  117. package/dist/commands/up-stores.d.ts.map +1 -0
  118. package/dist/commands/up-stores.js +242 -0
  119. package/dist/commands/up-stores.js.map +1 -0
  120. package/dist/commands/up-target.d.ts +2 -0
  121. package/dist/commands/up-target.d.ts.map +1 -1
  122. package/dist/commands/up-target.js +9 -0
  123. package/dist/commands/up-target.js.map +1 -1
  124. package/dist/commands/up.d.ts.map +1 -1
  125. package/dist/commands/up.js +27 -363
  126. package/dist/commands/up.js.map +1 -1
  127. package/dist/commands/update-process.d.ts.map +1 -1
  128. package/dist/commands/update-process.js +3 -15
  129. package/dist/commands/update-process.js.map +1 -1
  130. package/dist/commands/update.js +1 -1
  131. package/dist/commands/update.js.map +1 -1
  132. package/dist/commands/use.js +2 -2
  133. package/dist/commands/use.js.map +1 -1
  134. package/dist/console/app.js +5 -5
  135. package/dist/console/app.js.map +1 -1
  136. package/dist/console/commands.d.ts +1 -1
  137. package/dist/console/commands.d.ts.map +1 -1
  138. package/dist/console/commands.js +1 -1
  139. package/dist/console/commands.js.map +1 -1
  140. package/dist/console/ui/Feed.d.ts +2 -2
  141. package/dist/console/ui/Feed.d.ts.map +1 -1
  142. package/dist/console/ui/Feed.js +2 -2
  143. package/dist/console/ui/Feed.js.map +1 -1
  144. package/dist/console/ui/StatusBar.d.ts +1 -1
  145. package/dist/console/ui/StatusBar.d.ts.map +1 -1
  146. package/dist/console/ui/StatusBar.js +1 -1
  147. package/dist/console/ui/StatusBar.js.map +1 -1
  148. package/dist/console/ui/Tabs.d.ts +2 -2
  149. package/dist/console/ui/Tabs.d.ts.map +1 -1
  150. package/dist/console/ui/Tabs.js +4 -4
  151. package/dist/console/ui/Tabs.js.map +1 -1
  152. package/dist/index.d.ts.map +1 -1
  153. package/dist/index.js +6 -1
  154. package/dist/index.js.map +1 -1
  155. package/dist/lib/backup-artifact.d.ts.map +1 -1
  156. package/dist/lib/backup-artifact.js +19 -7
  157. package/dist/lib/backup-artifact.js.map +1 -1
  158. package/dist/lib/choose-target.d.ts +1 -1
  159. package/dist/lib/choose-target.d.ts.map +1 -1
  160. package/dist/lib/choose-target.js +7 -4
  161. package/dist/lib/choose-target.js.map +1 -1
  162. package/dist/lib/completion-install.js +7 -8
  163. package/dist/lib/completion-install.js.map +1 -1
  164. package/dist/lib/control.d.ts +8 -2
  165. package/dist/lib/control.d.ts.map +1 -1
  166. package/dist/lib/control.js +11 -4
  167. package/dist/lib/control.js.map +1 -1
  168. package/dist/lib/manager-choice.d.ts +2 -1
  169. package/dist/lib/manager-choice.d.ts.map +1 -1
  170. package/dist/lib/manager-choice.js +2 -2
  171. package/dist/lib/manager-choice.js.map +1 -1
  172. package/dist/lib/manifest/index.d.ts +1 -1
  173. package/dist/lib/manifest/index.d.ts.map +1 -1
  174. package/dist/lib/manifest/index.js +2 -2
  175. package/dist/lib/manifest/index.js.map +1 -1
  176. package/dist/lib/manifest/resolve.d.ts +1 -1
  177. package/dist/lib/manifest/resolve.d.ts.map +1 -1
  178. package/dist/lib/manifest/resolve.js +4 -4
  179. package/dist/lib/manifest/resolve.js.map +1 -1
  180. package/dist/lib/npm-invocation.d.ts +6 -0
  181. package/dist/lib/npm-invocation.d.ts.map +1 -0
  182. package/dist/lib/npm-invocation.js +18 -0
  183. package/dist/lib/npm-invocation.js.map +1 -0
  184. package/dist/lib/persona-files.d.ts +1 -0
  185. package/dist/lib/persona-files.d.ts.map +1 -1
  186. package/dist/lib/persona-files.js +6 -2
  187. package/dist/lib/persona-files.js.map +1 -1
  188. package/dist/lib/personas.d.ts +1 -2
  189. package/dist/lib/personas.d.ts.map +1 -1
  190. package/dist/lib/personas.js +12 -3
  191. package/dist/lib/personas.js.map +1 -1
  192. package/dist/lib/private-directory.d.ts +3 -3
  193. package/dist/lib/private-directory.d.ts.map +1 -1
  194. package/dist/lib/private-directory.js +17 -7
  195. package/dist/lib/private-directory.js.map +1 -1
  196. package/dist/lib/service-presets.d.ts.map +1 -1
  197. package/dist/lib/service-presets.js +10 -5
  198. package/dist/lib/service-presets.js.map +1 -1
  199. package/dist/lib/stack-journal.d.ts.map +1 -1
  200. package/dist/lib/stack-journal.js +7 -4
  201. package/dist/lib/stack-journal.js.map +1 -1
  202. package/dist/telemetry.d.ts.map +1 -1
  203. package/dist/telemetry.js +3 -2
  204. package/dist/telemetry.js.map +1 -1
  205. package/package.json +4 -4
@@ -0,0 +1,651 @@
1
+ import { lstatSync } from "node:fs";
2
+ import { drainAndClose, CotalEndpoint, dialerFor, EpEnvelopeError, isReachable, isStreamNotFound, mintCreds, mintLifecycleUid, resolveService, invokeRepairingSplit, standaloneConnectOpts, newIdentity, idFromCreds, principalKey, DEV_OWNER, unansweredRequest, resolveAuthProvider, } from "@cotal-ai/core";
3
+ import { join } from "node:path";
4
+ import { hasNonNatsExecutable, stoppedLoopbackListener, isCommandFailure, brokerAddressForDisplay, brokerUrlKey, CLI_USER_ACTOR, credentialFileExposure, CommandFailure, deliveryCredsKey, DELIVERY_PIDFILE, isMeshRegistryError, isWorkspaceTargetError, loadManagerInstanceIdentity, localProcessPath, MANAGER_PIDFILE, NATS_PIDFILE, oneLine, preflightTarget, principalFromBearer, verifyIdentityPin, probeWebReadiness, readPidfile, readRenewalRecord, userAuthStateDir, WEB_PIDFILE, workspaceSecretStore, displayWidth, terminalWidth, wrapWords, workspaceErrorParts, resolveControlTarget, } from "@cotal-ai/workspace";
5
+ import { MANAGER_OMITTED } from "../lib/delivery-proc.js";
6
+ import { webBoundAddress, webInstalled, webSessionSource } from "../lib/status.js";
7
+ import { deliveryResponderFromLease, RESPONDER_UNBOUND_CONSEQUENCE } from "../lib/delivery-responder.js";
8
+ import {} from "../lib/broker-store-health.js";
9
+ import { pidfileState } from "./down.js";
10
+ import { displayRemedy } from "../lib/self-exec.js";
11
+ import { c } from "../ui.js";
12
+ import { cliControl } from "../lib/control.js";
13
+ import { instanceProjection, serviceInstances } from "../lib/service-instances.js";
14
+ import { readStackJournal, STACK_DEFINITION, stackStartedWithoutManager, unusableStackJournal } from "../lib/stack-journal.js";
15
+ import { askManager } from "@cotal-ai/workspace/control";
16
+ import { managerStopImpactFacts } from "./status-stop-impact.js";
17
+ import { UnregisteredRoot } from "./status-model.js";
18
+ /** The lease `holder` the delivery daemon THIS WORKSPACE launched would write, or `undefined` when it
19
+ * cannot be known (#1576, and the reason is #837).
20
+ *
21
+ * THE HOLDER IS A PRINCIPAL DOT-FORM, NOT THE RAW CREDS ID, and getting that wrong is a live-caught
22
+ * mistake rather than a hypothetical: the daemon builds its endpoint with
23
+ * `card.id = idFromCreds(creds)`, and the endpoint then REWRITES `card.id` to
24
+ * `principalKey(owner, actor).key` — `<owner>.<actor>` — which is what lands in the lease. Comparing
25
+ * against the bare id therefore mismatches EVERY healthy daemon, which would turn this check into
26
+ * the mirror of the bug it removes: a permanent false "stale" on a perfectly good mesh. A smoke cell
27
+ * reads the record a real holder wrote and pins the exact shape, so this cannot regress silently.
28
+ *
29
+ * WHY IT MATTERS AT ALL. Without it, a `ready:true` record left by a daemon that has since died
30
+ * reads as health for the rest of the bucket TTL — measured against a real broker, not theorised —
31
+ * and a status command that exists to stop false green would print `responder bound` at a mesh that
32
+ * cannot spawn, retire or join. Core demands a named holder in `waitForDeliveryLease` for exactly
33
+ * this reason.
34
+ *
35
+ * READ-ONLY AND BEST EFFORT. A workspace that never launched a daemon locally (an adopted or remote
36
+ * one) has no creds file, and that is not an error: the caller then does not check the holder, the
37
+ * same concession `waitForDeliveryLease` makes for an adopted daemon. An existing credential that
38
+ * cannot be read privately refuses the check rather than silently disabling holder attribution. */
39
+ export async function expectedDeliveryHolder(target) {
40
+ const key = deliveryCredsKey(target.space, { injected: false, root: target.root });
41
+ const path = join(target.root, ".cotal", key);
42
+ const stat = lstatSync(path, { throwIfNoEntry: false });
43
+ const exposure = stat?.isFile() ? credentialFileExposure(path, stat) : undefined;
44
+ if (exposure)
45
+ throw new CommandFailure("refused", "PERMISSION_DENIED", `${path}: ${exposure.reason}`, { remedy: exposure.remedy, target: { path, space: target.space } });
46
+ const creds = await workspaceSecretStore(target.root).get(key);
47
+ if (!creds)
48
+ return undefined;
49
+ // The daemon declares no owner/actor, so the endpoint falls back to DEV_OWNER for the owner and
50
+ // to the connection id for the actor: `local.<idFromCreds>`. Built through `principalKey` rather
51
+ // than string concatenation so this tracks the one definition of the dot-form.
52
+ return principalKey(DEV_OWNER, idFromCreds(creds)).key;
53
+ }
54
+ /** The instance id this workspace root persisted for `space`. That is the id the manager's
55
+ * own status reports. Absent when this root has never registered a manager. A malformed
56
+ * record is not an id: status must not invent one. */
57
+ export function localManagerInstanceId(root, space) {
58
+ try {
59
+ const id = loadManagerInstanceIdentity(root, space)?.instanceId;
60
+ return typeof id === "string" && id.length > 0 ? id : undefined;
61
+ }
62
+ catch {
63
+ return undefined;
64
+ }
65
+ }
66
+ /** User-mode manager status goes through the same control call `cotal spawn` uses. `instanceId`
67
+ * pins that call to this machine's manager. Without it, the exchange may select another live
68
+ * manager of the same owner. */
69
+ export async function userManagerStatus(target, instanceId) {
70
+ const control = await resolveControlTarget({ space: target.space, server: target.server }, "control-caller-privileged", instanceId, { onRefusal: "throw" });
71
+ const reply = await askManager(cliControl, control.space, control.server, "managerStatus", undefined, control.auth, "owner", 3_000);
72
+ if (reply.ok !== true) {
73
+ const message = "error" in reply && typeof reply.error === "string" ? reply.error : "manager status refused";
74
+ // `unavailable` stays a reachability failure, as the static probe does. Anything else, including
75
+ // a manager that answered and refused, is a precondition. The reply's details stay on the error:
76
+ // a real no-answer carries the unanswered marker, and dropping it would report silence as a refusal.
77
+ const code = reply.code === "unavailable" ? "unavailable" : "failed-precondition";
78
+ throw new EpEnvelopeError(code, message, reply.details);
79
+ }
80
+ if (reply.data === undefined)
81
+ throw new EpEnvelopeError("unavailable", "the manager status reply carried no data");
82
+ return reply.data;
83
+ }
84
+ /** A no-responder service rail or an absent manager registry: the definitive no-service evidence
85
+ * that both the manager row and the manager health check grade on, kept in one place (#3046). */
86
+ export function managerNoService(e) {
87
+ return e instanceof EpEnvelopeError && (unansweredRequest(e) || isStreamNotFound(e.cause));
88
+ }
89
+ function section(name) {
90
+ console.log(`\n${c.bold(name)}`);
91
+ }
92
+ const COMPONENT_EXIT = {
93
+ serving: 0,
94
+ // An optional component that was never installed is not a failed one.
95
+ "not-installed": 0,
96
+ "not-started": 0,
97
+ absent: 1,
98
+ "not-serving": 2,
99
+ refused: 3,
100
+ };
101
+ /** Piped records keep one line per component. Terminal rows that do not fit put their facts below
102
+ * the verdict, wrapping at word boundaries. Escape control characters before layout so a stored
103
+ * reason cannot inject a new component record. */
104
+ function printComponent(component) {
105
+ const heading = ` ${component.name.padEnd(16)} ${component.verdict}`;
106
+ const facts = component.facts.map(oneLine);
107
+ const line = `${heading}${facts.length ? ` · ${facts.join(" · ")}` : ""}`;
108
+ const width = terminalWidth(process.stdout);
109
+ if (displayWidth(line) <= width)
110
+ console.log(line);
111
+ else {
112
+ console.log(heading);
113
+ for (const fact of facts)
114
+ for (const part of wrapWords(fact, width - 4))
115
+ console.log(` ${part}`);
116
+ }
117
+ }
118
+ function componentExit(components) {
119
+ // Refusal outranks every state: an unreadable control surface is not a clean zero even if some
120
+ // other component answered. A process that exists but lacks its serving answer is next, then
121
+ // genuine absence. The order is intentionally one place so a new component cannot accidentally
122
+ // collapse these states by choosing its own exit code.
123
+ return Math.max(...components.map((component) => COMPONENT_EXIT[component.verdict]));
124
+ }
125
+ export function processRecord(template, context) {
126
+ try {
127
+ const path = localProcessPath(template, context);
128
+ const state = pidfileState(path);
129
+ if (state.pid === undefined)
130
+ return state.liveness === "dead" ? { kind: "absent" } : { kind: "unattributable", raw: readPidfile(path) ?? "" };
131
+ return { kind: state.liveness === "alive" ? "live" : state.liveness === "dead" ? "dead" : "unknown", pid: state.pid };
132
+ }
133
+ catch (e) {
134
+ // An ambiguous record or any failed read refuses this component's row, never the whole pass.
135
+ return { kind: "unreadable", error: e.message };
136
+ }
137
+ }
138
+ function pidFacts(record) {
139
+ if (record.kind === "live" || record.kind === "dead" || record.kind === "unknown")
140
+ return [`pid ${record.pid}`];
141
+ if (record.kind === "unreadable")
142
+ return [`pidfile unreadable: ${record.error}`];
143
+ return [];
144
+ }
145
+ function processVerdict(record) {
146
+ if (record.kind === "absent" || record.kind === "dead")
147
+ return "absent";
148
+ if (record.kind === "unattributable" || record.kind === "unknown" || record.kind === "unreadable")
149
+ return "refused";
150
+ return undefined;
151
+ }
152
+ /** The probe credential for the components pass, per target mode. Static/open meshes keep the exact
153
+ * mint they had; a user-mode target gets the signed-in login's bearer, or the one-sentence reason
154
+ * it cannot be had. */
155
+ export async function componentCredential(target) {
156
+ if (target.mode !== "user")
157
+ return { kind: "static", auth: target.auth };
158
+ try {
159
+ const { bearer, sentinelCreds } = await resolveAuthProvider().userCredentials({
160
+ store: workspaceSecretStore(target.root),
161
+ dir: userAuthStateDir(target.root, target.space),
162
+ space: target.space,
163
+ actor: CLI_USER_ACTOR,
164
+ });
165
+ const { owner, actor, lifecycleUid: uid } = principalFromBearer(bearer);
166
+ return { kind: "user", bearer, sentinelCreds, caller: { owner, actor, uid } };
167
+ }
168
+ catch (e) {
169
+ return { kind: "unavailable", reason: e instanceof Error ? e.message : String(e) };
170
+ }
171
+ }
172
+ async function componentEp(target, credential) {
173
+ await requireGreeting(target);
174
+ const id = newIdentity();
175
+ const user = credential.kind === "user";
176
+ // Static/open: ONE lifecycleUid minted and used both in the credential and as the endpoint's own
177
+ // option, matching `staticServiceAuth`. Two different uids here (a fresh mint per site) is what
178
+ // `permissionsFor: ... mint with opts.lifecycleUid` refuses: the lease read is bound to the uid
179
+ // baked into the credential, not the one the endpoint separately declares (#2073).
180
+ const staticUid = !user && credential.auth ? mintLifecycleUid() : undefined;
181
+ const ep = new CotalEndpoint({
182
+ space: target.space,
183
+ servers: target.server,
184
+ tls: target.tlsRequired,
185
+ // User: the signed-in login's bearer + sentinel; no lifecycleUid mint exists on this path (the
186
+ // bearer carries its own lifecycle claim).
187
+ ...(user
188
+ ? { bearer: credential.bearer, sentinelCreds: credential.sentinelCreds }
189
+ : {
190
+ creds: credential.auth && staticUid ? await mintCreds(credential.auth, id, "deployer", { lifecycleUid: staticUid }) : undefined,
191
+ lifecycleUid: staticUid,
192
+ }),
193
+ channels: [],
194
+ consume: false,
195
+ registerPresence: false,
196
+ watchPresence: false,
197
+ watchChannels: false,
198
+ // A bearer-source endpoint derives its id from the principal; only the minted path names one.
199
+ card: user ? { name: "status-components", kind: "endpoint" } : { id: id.id, name: "status-components", kind: "endpoint" },
200
+ });
201
+ ep.on("error", () => { });
202
+ // Same one-shot policy as renderSnapshot: the command grades the awaited service reply itself.
203
+ const ignoreComponentWarning = () => { };
204
+ ep.on("warning", ignoreComponentWarning);
205
+ await ep.start();
206
+ return { ep, close: () => ep.stop().catch(() => { }) };
207
+ }
208
+ /** Refuse before a probe dials a broker that does not greet on a socket this check owns. A broker
209
+ * that takes the connection and never greets, as a stopped one does, leaves the dial's socket open
210
+ * after its timeout, because the client library does not release a connection it never finished,
211
+ * and status could then never exit. */
212
+ async function requireGreeting(target) {
213
+ const stopped = stoppedLoopbackListener(target.server);
214
+ if (stopped !== undefined)
215
+ throw new Error(hasNonNatsExecutable(stopped) ? `stopped process ${stopped} holds the broker address and is not a NATS server` : `the broker at ${brokerAddressForDisplay(target.server) ?? "an invalid broker address"} is served by process ${stopped}, which is stopped`);
216
+ if (!(await isReachable(target.server, { ...(target.tlsRequired ? { tls: true } : {}), timeoutMs: 3_000 })))
217
+ throw new Error(`the broker at ${brokerAddressForDisplay(target.server) ?? "an invalid broker address"} is not answering`);
218
+ }
219
+ /** The static arm's one-shot service instrument, unchanged from before the user-mode fix: a fresh
220
+ * identity, its minted deployer credential, and the caller triple on the SAME identity — a
221
+ * mismatched random actor would turn an authorized manager into a false no-answer. */
222
+ export async function staticServiceAuth(auth) {
223
+ const serviceIdentity = newIdentity();
224
+ const serviceUid = mintLifecycleUid();
225
+ return {
226
+ creds: auth ? await mintCreds(auth, serviceIdentity, "deployer", { lifecycleUid: serviceUid }) : undefined,
227
+ caller: { owner: "local", actor: serviceIdentity.id, uid: serviceUid },
228
+ };
229
+ }
230
+ /** A service registration is the health target itself. Calling its `status` command through a
231
+ * generic endpoint does not work on this base because a passive status endpoint has no v0.4 caller
232
+ * rail; a one-shot standalone caller does. */
233
+ export async function managerServiceHealth(target, auth) {
234
+ await requireGreeting(target);
235
+ const nc = await dialerFor(target.server)({
236
+ servers: target.server,
237
+ ...standaloneConnectOpts("bearer" in auth
238
+ ? { bearer: auth.bearer, sentinelCreds: auth.sentinelCreds, tls: target.tlsRequired }
239
+ : auth.creds
240
+ ? { creds: auth.creds, tls: target.tlsRequired }
241
+ : { tls: target.tlsRequired }),
242
+ maxReconnectAttempts: 0,
243
+ });
244
+ try {
245
+ const service = await resolveService(nc, target.space, "manager", auth.caller, { deadlineMs: 3_000, commands: ["status"] });
246
+ const response = await invokeRepairingSplit(nc, target.space, service, "status", undefined, { deadlineMs: 3_000 });
247
+ if (response.reply.ok !== true)
248
+ throw new EpEnvelopeError(response.reply.error.code === "unavailable" ? "unavailable" : "failed-precondition", response.reply.error.message);
249
+ return response.reply.data;
250
+ }
251
+ finally {
252
+ await drainAndClose(nc);
253
+ }
254
+ }
255
+ async function managerHealth(target, context, credential, broker) {
256
+ const record = processRecord(MANAGER_PIDFILE, context);
257
+ const facts = pidFacts(record);
258
+ // A corrupt or kernel-unreadable LOCAL record is neither evidence that the manager is absent nor
259
+ // permission to replace it with a network answer. Name that failed local control surface first.
260
+ if (processVerdict(record) === "refused") {
261
+ if (record.kind === "unattributable")
262
+ facts.push("unattributable pidfile");
263
+ if (record.kind === "unknown")
264
+ facts.push("pid liveness unestablishable");
265
+ return { name: "manager", verdict: "refused", facts };
266
+ }
267
+ if (record.kind === "dead")
268
+ facts.push("stale pidfile");
269
+ let close;
270
+ try {
271
+ if (credential.kind === "unavailable") {
272
+ // USER MODE without a usable login credential: say what is missing instead of probing bare.
273
+ // A bare probe of an authenticated broker reports an Authorization Violation that describes
274
+ // our own missing credential, not the manager's health. `refused` (not absent): the pass
275
+ // could not read this component's control surface, which is exactly what that verdict means.
276
+ facts.push(`probe needs the signed-in login: ${credential.reason}`);
277
+ return { name: "manager", verdict: "refused", facts };
278
+ }
279
+ const component = await componentEp(target, credential);
280
+ close = component.close;
281
+ // The lease sweep needs manager-bucket STREAM.INFO rows an interactive ledger bearer does not
282
+ // hold (provision.ts grants those to the manager/supervisor credentials only; the agent-view
283
+ // comment in core says exactly this). In user mode the SERVICE probe is the whole verdict, so
284
+ // the row says the lease axis is not checkable rather than reporting a refusal the broker
285
+ // makes about our own credential's shape.
286
+ let lease;
287
+ if (credential.kind === "user") {
288
+ facts.push("lease not checkable as the signed-in login (manager-bucket read is a host credential)");
289
+ }
290
+ else {
291
+ lease = await component.ep.readManagerLease();
292
+ if (lease)
293
+ facts.push(`lease holder ${lease.holder}`, `lease pid ${lease.pid}`);
294
+ else
295
+ facts.push("lease absent");
296
+ }
297
+ // Static/open keeps the one-shot instrument on the same identity as its caller triple.
298
+ // User mode calls manager status through the same control path `cotal spawn` uses.
299
+ // The login bearer does not carry that command for a spawn holder.
300
+ // Pin only while this machine's manager process is live. With no live process, an
301
+ // unpinned answer is this row's own verdict and the facts below name its instance.
302
+ const liveLocal = record.kind === "live";
303
+ const localId = credential.kind === "user" && liveLocal ? localManagerInstanceId(context.root, target.space) : undefined;
304
+ const served = credential.kind === "user"
305
+ ? await userManagerStatus(target, liveLocal ? localId : undefined)
306
+ : await managerServiceHealth(target, await staticServiceAuth(credential.auth));
307
+ // A live local process is serving only when its persisted instance answered. An unknown
308
+ // id, or a different one, cannot be attributed: refused, not not-serving, and the remote
309
+ // runtime stays off this row. The facts name the instance that answered.
310
+ if (credential.kind === "user" && liveLocal && (localId === undefined || served.instanceId !== localId)) {
311
+ const answered = typeof served.instanceId === "string" && served.instanceId.length > 0 ? served.instanceId : undefined;
312
+ facts.push(answered === undefined
313
+ ? "the manager answer named no instance, so it is not this machine's manager"
314
+ : localId === undefined
315
+ ? `answered by manager instance ${answered}; this machine's manager instance is not known`
316
+ : `answered by manager instance ${answered}, not this machine's manager ${localId}`);
317
+ return { name: "manager", verdict: "refused", facts };
318
+ }
319
+ facts.push(`service instance ${served.instanceId ?? "unreported"}`);
320
+ facts.push(`runtime ${served.runtime ?? "unreported"}`);
321
+ facts.push(...managerStopImpactFacts(served.stopImpact));
322
+ const reconcile = served.staticReconciliation;
323
+ if (!reconcile) {
324
+ facts.push("static reconciliation not reported by this manager build");
325
+ }
326
+ else {
327
+ facts.push(`static reconciliation ${String(reconcile.state ?? "unreported")}`);
328
+ if (typeof reconcile.lastSweep?.error === "string")
329
+ facts.push(`static sweep error=${reconcile.lastSweep.error}`);
330
+ for (const failure of reconcile.failures ?? []) {
331
+ const next = typeof failure.nextRetryAt === "string" ? ` nextRetryAt=${failure.nextRetryAt}` : "";
332
+ const remedy = typeof failure.remedy === "string" ? ` remedy=${failure.remedy}` : "";
333
+ facts.push(`static alias=${String(failure.alias ?? "unreported")} phase=${String(failure.phase ?? "unreported")} disposition=${String(failure.disposition ?? "unreported")}${next}${remedy}`);
334
+ }
335
+ }
336
+ facts.push("serve reachable");
337
+ // A manager service without its own liveness lease is a contradicted component surface, not a
338
+ // healthy one. It still reports reachability, but cannot claim the required lease holder. In
339
+ // USER MODE neither local axis is checkable from a participant machine (no pidfile under a
340
+ // discovered root, no manager-bucket read), so the manager's own typed service answer carries
341
+ // the verdict alone — reaching this line means it answered, which is the same single answer
342
+ // `ps` grades a user-mode manager by.
343
+ return { name: "manager", verdict: lease || credential.kind === "user" ? "serving" : "not-serving", facts };
344
+ }
345
+ catch (e) {
346
+ // A no-responder service rail or an absent manager registry is definitive no-service evidence.
347
+ // A dead local PID is absent even while its lease awaits expiry. Without a PID record, the
348
+ // lease still identifies an extant component; any other failed probe remains a refusal.
349
+ const noService = managerNoService(e);
350
+ facts.push(noService ? "serve no answer" : `serve probe refused: ${e.message}`);
351
+ if (broker.verdict === "absent" && processVerdict(record) === "absent")
352
+ return { name: "manager", verdict: "absent", facts };
353
+ if (!noService)
354
+ return { name: "manager", verdict: "refused", facts };
355
+ const liveRecord = record.kind === "live";
356
+ const hasLease = facts.some((fact) => fact.startsWith("lease holder "));
357
+ if (!liveRecord && !hasLease) {
358
+ try {
359
+ const journal = readStackJournal(context.root)?.journal;
360
+ const pin = verifyIdentityPin(localProcessPath(MANAGER_OMITTED, context));
361
+ const brokerRecord = processRecord(NATS_PIDFILE, context);
362
+ const omitted = journal?.space === context.space ? stackStartedWithoutManager(journal)
363
+ : pin.kind === "match" && brokerRecord.kind === "live" && pin.record.pid === brokerRecord.pid;
364
+ if (omitted)
365
+ return { name: "manager", verdict: "not-started", facts: [...facts, "started with --no-manager"] };
366
+ }
367
+ catch (error) {
368
+ return { name: "manager", verdict: "refused", facts: [...facts, `startup intent unreadable: ${error.message}`] };
369
+ }
370
+ }
371
+ return { name: "manager", verdict: liveRecord || (record.kind !== "dead" && hasLease) ? "not-serving" : "absent", facts };
372
+ }
373
+ finally {
374
+ await close?.();
375
+ }
376
+ }
377
+ /** True when a delivery-lease read failed because the lease stream/bucket is absent (#3046). */
378
+ export function deliveryLeaseAbsent(e) {
379
+ return isStreamNotFound(e);
380
+ }
381
+ /** Delivery owns two answers: its ready lease is its liveness/control surface; its latest explicit
382
+ * adoption report is the renewal record it writes through the manager-owned renewal pass. The
383
+ * latter is intentionally not inferred from credential mtime or process output. */
384
+ async function deliveryHealth(target, context, credential, brokerOffline) {
385
+ const record = processRecord(DELIVERY_PIDFILE, context);
386
+ const facts = pidFacts(record);
387
+ const stopped = processVerdict(record);
388
+ // The renewal record is PER-SPACE (#1850): read THIS space's record through the workspace seam
389
+ // (`renewalRecordPath` — the same keyed spelling the pidfiles use), never a hand-composed
390
+ // root-only path: a co-resident space's pass must not color this row.
391
+ let renewal;
392
+ try {
393
+ renewal = readRenewalRecord(context.root, context.space);
394
+ }
395
+ catch (e) {
396
+ facts.push(`renewal record unreadable: ${e.message}`);
397
+ return { name: "delivery", verdict: "refused", facts };
398
+ }
399
+ if (renewal?.adoption === undefined)
400
+ facts.push("renewal adoption not reported");
401
+ else
402
+ facts.push(renewal.adoption.ok ? "renewal adoption accepted" : `renewal adoption refused${renewal.adoption.error ? `: ${renewal.adoption.error}` : ""}`);
403
+ const renewalRefused = renewal?.adoption?.ok === false;
404
+ if (target.mode === "open" && record.kind === "absent" && !renewalRefused) {
405
+ if (brokerOffline)
406
+ return { name: "delivery", verdict: "not-started", facts: ["not used on an open mesh"] };
407
+ if (credential.kind === "unavailable")
408
+ return { name: "delivery", verdict: "refused", facts: [credential.reason] };
409
+ try {
410
+ const component = await componentEp(target, credential);
411
+ try {
412
+ if (!await component.ep.readDeliveryLease(0))
413
+ return { name: "delivery", verdict: "not-started", facts: ["not used on an open mesh"] };
414
+ }
415
+ finally {
416
+ await component.close();
417
+ }
418
+ }
419
+ catch (error) {
420
+ if (deliveryLeaseAbsent(error))
421
+ return { name: "delivery", verdict: "not-started", facts: ["not used on an open mesh"] };
422
+ return { name: "delivery", verdict: "refused", facts: [`lease probe refused: ${error instanceof Error ? error.message : String(error)}`] };
423
+ }
424
+ }
425
+ if (stopped) {
426
+ if (record.kind === "dead")
427
+ facts.push("stale pidfile");
428
+ if (record.kind === "unattributable")
429
+ facts.push("unattributable pidfile");
430
+ if (record.kind === "unknown")
431
+ facts.push("pid liveness unestablishable");
432
+ return { name: "delivery", verdict: renewalRefused ? "refused" : stopped, facts };
433
+ }
434
+ let close;
435
+ try {
436
+ if (credential.kind === "unavailable") {
437
+ // Same user-mode discipline as the manager row: never probe an authenticated broker bare.
438
+ facts.push("lease probe needs the signed-in login");
439
+ facts.push(credential.reason);
440
+ return { name: "delivery", verdict: "refused", facts };
441
+ }
442
+ const component = await componentEp(target, credential);
443
+ close = component.close;
444
+ const lease = await component.ep.readDeliveryLease(0);
445
+ // ONE classifier for both surfaces (#1576). `--components` was already right here and bare
446
+ // status was not, which is exactly how the two came to disagree about a mesh's health; routing
447
+ // both through `deliveryResponderFromLease` means a future change cannot fix one and leave the
448
+ // other green. The facts below stay as specific as they were.
449
+ //
450
+ // THE HOLDER IS PART OF THE QUESTION (#837). This surface already PRINTED `lease holder …` as a
451
+ // fact while grading on `ready` alone, so it displayed the evidence that its own verdict was
452
+ // wrong and did not read it. A ready record belonging to a daemon that is gone keeps this row
453
+ // `serving` for the rest of the bucket TTL.
454
+ const state = deliveryResponderFromLease(lease, await expectedDeliveryHolder(target));
455
+ if (!lease) {
456
+ facts.push("ready lease absent", `responder not bound - ${RESPONDER_UNBOUND_CONSEQUENCE}`);
457
+ return { name: "delivery", verdict: renewalRefused ? "refused" : "not-serving", facts };
458
+ }
459
+ facts.push(`lease holder ${lease.holder}`);
460
+ if (state === "stale") {
461
+ // Name WHOSE record it is against whom we expected, because this is the one verdict an
462
+ // operator cannot derive from the other facts on the line.
463
+ facts.push("ready, but held by a DIFFERENT daemon than this workspace launched (a dead holder's record expires on its own)");
464
+ facts.push(`responder not bound - ${RESPONDER_UNBOUND_CONSEQUENCE}`);
465
+ return { name: "delivery", verdict: renewalRefused ? "refused" : "not-serving", facts };
466
+ }
467
+ facts.push(state === "bound" ? "ready" : "starting (lease not ready)");
468
+ if (state !== "bound")
469
+ facts.push(`responder not bound - ${RESPONDER_UNBOUND_CONSEQUENCE}`);
470
+ return { name: "delivery", verdict: renewalRefused ? "refused" : state === "bound" ? "serving" : "not-serving", facts };
471
+ }
472
+ catch (e) {
473
+ // A live recorded daemon with no delivery lease bucket cannot be serving this build's delivery
474
+ // control surface. A denied/timed-out read is different: it is a refusal and must never read
475
+ // as a clean absence.
476
+ const noLeaseSurface = deliveryLeaseAbsent(e);
477
+ const msg = e instanceof Error ? e.message : String(e);
478
+ facts.push(noLeaseSurface ? "ready lease absent" : `lease probe refused: ${msg}`);
479
+ if (isCommandFailure(e) && e.remedy)
480
+ facts.push(e.remedy);
481
+ return { name: "delivery", verdict: renewalRefused || !noLeaseSurface ? "refused" : "not-serving", facts };
482
+ }
483
+ finally {
484
+ await close?.();
485
+ }
486
+ }
487
+ /** The web dashboard owns the HTTP listener and identifies itself through `/api/meta`, including
488
+ * the serving PID. A raw TCP success is insufficient: another program could own its port. */
489
+ async function webHealth(context) {
490
+ const record = processRecord(WEB_PIDFILE, context);
491
+ const facts = pidFacts(record);
492
+ const stopped = processVerdict(record);
493
+ if (record.kind === "absent") {
494
+ try {
495
+ const unsettled = serviceInstances(context.space, "web").map(instanceProjection).find((row) => row.recordedState !== "stopped" && ["gone", "foreign-pid", "previous-boot"].includes(row.observedProcess));
496
+ if (unsettled)
497
+ return { name: "web", verdict: "absent", facts: [`service instance ${unsettled.instanceId}`, `recorded ${unsettled.recordedState}`, unsettled.observedProcess] };
498
+ }
499
+ catch (e) {
500
+ return { name: "web", verdict: "refused", facts: [`service instance records unreadable: ${e.message}`] };
501
+ }
502
+ // An installation that cannot be read keeps the absent verdict rather than a clean zero.
503
+ let installed;
504
+ try {
505
+ installed = webInstalled();
506
+ }
507
+ catch {
508
+ installed = undefined;
509
+ }
510
+ if (installed === false)
511
+ return { name: "web", verdict: "not-installed", facts: ["optional"] };
512
+ if (installed === true)
513
+ return { name: "web", verdict: "not-started", facts: ["optional"] };
514
+ }
515
+ if (stopped) {
516
+ if (record.kind === "dead")
517
+ facts.push("stale pidfile");
518
+ if (record.kind === "unattributable")
519
+ facts.push("unattributable pidfile");
520
+ if (record.kind === "unknown")
521
+ facts.push("pid liveness unestablishable");
522
+ return { name: "web", verdict: stopped, facts };
523
+ }
524
+ // Probe only the address the dashboard recorded once it was listening, never one guessed from its
525
+ // command line or a default: no argv names the port `--port 0` bound. Without that record the
526
+ // control surface cannot be located, which is a probe refusal rather than a not-serving answer.
527
+ if (record.kind !== "live")
528
+ throw new Error("web component record lost its live pid after classification");
529
+ const pid = record.pid;
530
+ let source;
531
+ try {
532
+ source = webSessionSource(context, pid);
533
+ }
534
+ catch (e) {
535
+ return { name: "web", verdict: "refused", facts: [...facts, `service instance records unreadable: ${e.message}`] };
536
+ }
537
+ if (source.instance !== undefined)
538
+ facts.push(`service instance ${source.instance}`);
539
+ let bound;
540
+ try {
541
+ bound = webBoundAddress(source.path);
542
+ }
543
+ catch (e) {
544
+ return { name: "web", verdict: "refused", facts: [...facts, `${source.label} unreadable: ${e.message}`] };
545
+ }
546
+ if (!bound)
547
+ return { name: "web", verdict: "refused", facts: [...facts, "probe refused (no bound address recorded)"] };
548
+ try {
549
+ // The dashboard refuses an anonymous `/api/meta`; the readiness nonce is the one credential its
550
+ // gate accepts there, so without it a live dashboard could only ever answer 401.
551
+ const { status, meta } = await probeWebReadiness(bound.url, bound.readiness);
552
+ if (meta?.pid === pid)
553
+ return { name: "web", verdict: "serving", facts: [...facts, `host ${bound.host}`, `port ${bound.port}`, "http reachable"] };
554
+ return { name: "web", verdict: "not-serving", facts: [...facts, `host ${bound.host}`, `port ${bound.port}`, meta === undefined ? `HTTP ${status}` : "http identity mismatch"] };
555
+ }
556
+ catch {
557
+ // If the recorded address cannot identify the recorded PID, this component is present but not
558
+ // serving.
559
+ }
560
+ return { name: "web", verdict: "not-serving", facts: [...facts, `host ${bound.host}`, `port ${bound.port}`, "http not answered"] };
561
+ }
562
+ async function brokerHealth(target, store) {
563
+ const address = brokerAddressForDisplay(target.server);
564
+ if (address === undefined)
565
+ return { name: "broker", verdict: "refused", facts: ["registered address unavailable", "invalid broker address"] };
566
+ try {
567
+ const context = { root: target.root, space: target.space };
568
+ const journal = readStackJournal(target.root)?.journal;
569
+ const serverKey = brokerUrlKey(target.server);
570
+ if (journal?.space === target.space && brokerUrlKey(journal.server) === serverKey) {
571
+ const member = journal.members.find((row) => row.role === "broker");
572
+ const instance = serviceInstances(target.space, STACK_DEFINITION.broker).find((row) => row.name === member?.instanceId);
573
+ const observed = instance && instanceProjection(instance).observedProcess;
574
+ if (!instance || observed && ["gone", "foreign-pid", "previous-boot"].includes(observed))
575
+ return { name: "broker", verdict: "absent", facts: [`registered ${address}`, observed ?? "no local instance"] };
576
+ if (observed !== "running")
577
+ return { name: "broker", verdict: "refused", facts: [`registered ${address}`, `local process ${observed}`] };
578
+ }
579
+ else if (target.origin === "up" && target.mode !== "user" && (target.recordedServer === undefined || brokerUrlKey(target.recordedServer) === serverKey)) {
580
+ const record = processRecord(NATS_PIDFILE, context);
581
+ const verdict = processVerdict(record);
582
+ if (verdict)
583
+ return { name: "broker", verdict, facts: [`registered ${address}`, ...pidFacts(record), ...(record.kind === "dead" ? ["stale pidfile"] : [])] };
584
+ }
585
+ const storeFailure = store?.state === "write-failed" ? `store write failed: ${store.cause}`
586
+ : store?.state === "full" ? `store full: ${store.used} bytes exceeds ${store.cap} bytes at ${store.path}` : undefined;
587
+ if (target.mode !== "user") {
588
+ const preflight = await preflightTarget(target);
589
+ if (!preflight.ok)
590
+ return { name: "broker", verdict: "not-serving", facts: [`registered ${address}`, workspaceErrorParts({ kind: "preflight", failure: preflight.kind, target, pruned: false, ...(preflight.pid === undefined ? {} : { pid: preflight.pid }) }).message] };
591
+ return { name: "broker", verdict: storeFailure ? "not-serving" : "serving", facts: [`registered ${address}`, "reachable", ...(storeFailure ? [storeFailure] : [])] };
592
+ }
593
+ const reachable = await isReachable(target.server, target.tlsRequired ? { tls: true } : {});
594
+ if (storeFailure)
595
+ return { name: "broker", verdict: "not-serving", facts: [`registered ${address}`, reachable ? "reachable" : "unreachable", storeFailure] };
596
+ return reachable
597
+ ? { name: "broker", verdict: "serving", facts: [`registered ${address}`, "reachable"] }
598
+ : { name: "broker", verdict: "not-serving", facts: [`registered ${address}`, "unreachable"] };
599
+ }
600
+ catch (e) {
601
+ return { name: "broker", verdict: "refused", facts: [`registered ${address}`, `probe refused: ${e.message}`] };
602
+ }
603
+ }
604
+ export async function printComponentHealth(selected, store, brokerUnreachable) {
605
+ section("Component Health");
606
+ if (!selected.ok) {
607
+ const error = selected.error;
608
+ const e = isWorkspaceTargetError(error) && error.code === "not-started" && error.details.root !== undefined && !error.details.rootMissing
609
+ ? unusableStackJournal(error.details.root) ?? error : error;
610
+ if (isCommandFailure(e) && (e.code === "SCHEMA_INVALID" || e.code === "PERMISSION_DENIED")) {
611
+ printComponent({ name: "target", verdict: "refused", facts: [e.code, e.message, ...(e.remedy ? [e.remedy] : [])] });
612
+ process.exitCode = COMPONENT_EXIT.refused;
613
+ return;
614
+ }
615
+ if (isMeshRegistryError(e)) {
616
+ printComponent({ name: "target", verdict: "refused", facts: ["SCHEMA_INVALID", e.message] });
617
+ process.exitCode = COMPONENT_EXIT.refused;
618
+ return;
619
+ }
620
+ if (isWorkspaceTargetError(e)) {
621
+ const verdict = e.code === "not-started" ? "absent" : "refused";
622
+ const { message, remedy } = workspaceErrorParts({ kind: "target", error: e });
623
+ printComponent({ name: "target", verdict, facts: [e.code, remedy === undefined ? message : `${message} - ${displayRemedy(remedy)}`] });
624
+ process.exitCode = COMPONENT_EXIT[verdict];
625
+ return;
626
+ }
627
+ if (e instanceof UnregisteredRoot) {
628
+ printComponent({ name: "target", verdict: "refused", facts: ["unregistered-root", `no space is registered or prepared here for ${e.root}`] });
629
+ process.exitCode = COMPONENT_EXIT.refused;
630
+ return;
631
+ }
632
+ throw e;
633
+ }
634
+ const target = selected.target;
635
+ const context = { root: target.root, space: target.space, userAuth: target.mode === "user" };
636
+ // ONE credential read for the whole pass (user mode resolves the signed-in login once; the
637
+ // static shape is just the target's own auth material), shared by the manager and delivery
638
+ // probes so the two rows cannot disagree about whose credential they probed with.
639
+ const credential = await componentCredential(target);
640
+ const broker = await brokerHealth(target, store);
641
+ const components = await Promise.all([
642
+ managerHealth(target, context, credential, broker),
643
+ deliveryHealth(target, context, credential, brokerUnreachable && broker.verdict === "absent"),
644
+ webHealth(context),
645
+ broker,
646
+ ]);
647
+ for (const component of components)
648
+ printComponent(component);
649
+ process.exitCode = componentExit(components);
650
+ }
651
+ //# sourceMappingURL=status-health.js.map