@hallohuman/hightea 0.1.15 → 0.1.30

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.
@@ -0,0 +1,465 @@
1
+ // ../client/src/index.ts
2
+ var sourceOf = (kind, id) => ({ kind, id });
3
+ var sameSource = (a, b) => a !== undefined && b !== undefined && a.kind === b.kind && a.id === b.id;
4
+ var sourceText = (source) => `${source.kind}:${source.id}`;
5
+ function requirePerson(caller, operation) {
6
+ if (caller.kind === "agent") {
7
+ throw new Error(`${operation}: a person must grant this; agent ${caller.id} cannot`);
8
+ }
9
+ }
10
+ var SOURCE_FIELD = "source";
11
+ var AGENT_SOURCE_KEY = "x-hh/source";
12
+ var neutralFields = ["command", "cwd", "env", "schedule", "restart", "depends_on", "health"];
13
+ var fieldsOf = (service) => ({
14
+ command: service.command,
15
+ cwd: service.cwd,
16
+ env: service.env,
17
+ schedule: service.schedule,
18
+ restart: service.restart,
19
+ depends_on: service.depends_on,
20
+ health: service.health
21
+ });
22
+ var canonical = (value) => {
23
+ if (value === undefined)
24
+ return "undefined";
25
+ if (Array.isArray(value))
26
+ return `[${value.map(canonical).join(",")}]`;
27
+ if (value !== null && typeof value === "object") {
28
+ const keys = Object.keys(value).sort();
29
+ return `{${keys.map((k) => `${JSON.stringify(k)}:${canonical(value[k])}`).join(",")}}`;
30
+ }
31
+ return JSON.stringify(value);
32
+ };
33
+ var changedFields = (before, after) => {
34
+ const a = fieldsOf(before);
35
+ const b = fieldsOf(after);
36
+ return neutralFields.filter((field) => canonical(a[field]) !== canonical(b[field]));
37
+ };
38
+ var SERVICES_CHANNEL = "x-hh-services://";
39
+ var operate = (host, operationId, rest) => host.call("x-ahpd/invokeOperation", { channel: SERVICES_CHANNEL, operationId, ...rest });
40
+ var listOf = async (host) => {
41
+ const answer = await host.call("subscribe", { channel: SERVICES_CHANNEL });
42
+ await host.call("unsubscribe", { channel: SERVICES_CHANNEL });
43
+ const state = answer?.snapshot?.state;
44
+ if (typeof state?.error === "string")
45
+ throw new Error(`the machine's services could not be read: ${state.error}`);
46
+ if (state === undefined || !Array.isArray(state.rows))
47
+ throw new Error("the services channel answered no rows");
48
+ const rows = state.rows;
49
+ return {
50
+ services: rows.flatMap((row) => row.record === undefined ? [] : [withState(row.record, row.state)]),
51
+ readOnly: rows.flatMap((row) => row.readOnly === undefined ? [] : [{ name: row.name, reason: row.readOnly }]),
52
+ capabilities: state.capabilities,
53
+ ifVersion: state.ifVersion,
54
+ ...typeof state.file === "string" ? { file: state.file } : {}
55
+ };
56
+ };
57
+ var withState = (record, state) => {
58
+ if (!isRecord(state) || typeof state.status !== "string")
59
+ return record;
60
+ return { ...record, state: { status: state.status, ...typeof state.why === "string" ? { why: state.why } : {} } };
61
+ };
62
+ var DEPLOYS_CHANNEL = "x-hh-deploys://";
63
+ async function deployService(host, call) {
64
+ if (typeof call?.service !== "string" || call.service.trim() === "")
65
+ throw new Error("deployService: service is a non-empty name");
66
+ if (typeof call?.version !== "string" || call.version.trim() === "")
67
+ throw new Error("deployService: version is a branch, a tag or a commit sha");
68
+ const answer = await host.call("x-ahpd/invokeOperation", {
69
+ channel: DEPLOYS_CHANNEL,
70
+ operationId: "deploy",
71
+ target: { id: call.service },
72
+ input: { service: call.service, version: call.version }
73
+ });
74
+ if (!isRecord(answer))
75
+ throw new Error(`the deploys channel answered no record: ${JSON.stringify(answer)}`);
76
+ if (answer["ok"] === true) {
77
+ const service = answer["service"];
78
+ const sha = answer["sha"];
79
+ const deployId = answer["deployId"];
80
+ if (typeof service !== "string" || typeof sha !== "string" || typeof deployId !== "string" || answer["state"] !== "started") {
81
+ throw new Error(`the deploys channel answered a start without service, sha, deployId and state: ${JSON.stringify(answer)}`);
82
+ }
83
+ return { ok: true, service, sha, deployId, state: "started" };
84
+ }
85
+ const code = answer["code"];
86
+ const message = answer["message"];
87
+ if (answer["ok"] === false && typeof code === "string" && code !== "" && typeof message === "string") {
88
+ return { ok: false, code, message };
89
+ }
90
+ throw new Error(`the deploys channel answered neither a start nor a named refusal: ${JSON.stringify(answer)}`);
91
+ }
92
+ var runOf = (value) => {
93
+ if (!isRecord(value))
94
+ return;
95
+ const service = value["service"];
96
+ const deployId = value["deployId"];
97
+ const state = value["state"];
98
+ if (typeof service !== "string" || typeof deployId !== "string" || typeof state !== "string")
99
+ return;
100
+ const step = value["step"];
101
+ const from = value["from"];
102
+ const to = value["to"];
103
+ const at = value["at"];
104
+ const last = value["last"];
105
+ const reason = isRecord(last) && typeof last["reason"] === "string" ? last["reason"] : undefined;
106
+ const exit = isRecord(last) && (last["exit"] === null || typeof last["exit"] === "number") ? last["exit"] : undefined;
107
+ return {
108
+ service,
109
+ deployId,
110
+ state,
111
+ ...typeof step === "string" ? { step } : {},
112
+ ...from === null || typeof from === "string" ? { from } : {},
113
+ ...typeof to === "string" ? { to } : {},
114
+ ...typeof at === "string" ? { at } : {},
115
+ ...reason === undefined ? {} : { reason },
116
+ ...exit === undefined ? {} : { exit }
117
+ };
118
+ };
119
+ async function deploys(host) {
120
+ const answer = await host.call("subscribe", { channel: DEPLOYS_CHANNEL });
121
+ await host.call("unsubscribe", { channel: DEPLOYS_CHANNEL });
122
+ const state = answer?.snapshot?.state;
123
+ if (state === undefined)
124
+ throw new Error("the deploys channel answered no state");
125
+ const runs = Array.isArray(state["runs"]) ? state["runs"].flatMap((row) => {
126
+ const run = runOf(row);
127
+ return run === undefined ? [] : [run];
128
+ }) : [];
129
+ const machine = typeof state["machine"] === "string" ? state["machine"] : "";
130
+ const error = typeof state["error"] === "string" ? state["error"] : undefined;
131
+ return { machine, runs, ...error === undefined ? {} : { error } };
132
+ }
133
+ async function preview(plan, host, options) {
134
+ const plannedHosts = hostsOf(plan);
135
+ const services = plan.services === undefined ? undefined : await previewServices(plan.services, host, options);
136
+ return {
137
+ ...services ?? { create: [], change: [], unchanged: [], readOnly: [], remove: [], keep: [], unmanaged: [] },
138
+ ...plan.agents === undefined ? {} : { agents: await previewAgents(plan.agents, host, options) },
139
+ ...plannedHosts.length === 0 ? {} : { hosts: await previewHosts(plannedHosts, options) }
140
+ };
141
+ }
142
+ async function previewServices(plannedServices, host, options) {
143
+ const current = await listOf(host);
144
+ const fields = current.capabilities?.fields ?? [];
145
+ if (!fields.includes(SOURCE_FIELD)) {
146
+ throw new Error(`this machine's services driver records no "${SOURCE_FIELD}" (its fields are ${fields.join(", ")}); it cannot say which client wrote an entry, so nothing is written`);
147
+ }
148
+ const byName = new Map(current.services.map((service) => [service.name, service]));
149
+ const readOnly = new Map(current.readOnly.map((entry) => [entry.name, entry.reason]));
150
+ const create = [];
151
+ const change = [];
152
+ const unchanged = [];
153
+ const planned = new Set;
154
+ for (const service of plannedServices) {
155
+ planned.add(service.name);
156
+ const before = byName.get(service.name);
157
+ if (readOnly.has(service.name)) {
158
+ throw new Error(`${service.name} is read-only on this machine: ${readOnly.get(service.name) ?? ""}`);
159
+ }
160
+ if (before === undefined) {
161
+ create.push(service);
162
+ } else {
163
+ const changed = changedFields(before, service);
164
+ if (changed.length === 0)
165
+ unchanged.push(service.name);
166
+ else
167
+ change.push({ name: service.name, before, after: service, changed });
168
+ }
169
+ }
170
+ const candidates = options.prune === true ? current.services.filter((service) => sameSource(service.source, options.source) && !planned.has(service.name)) : [];
171
+ if (candidates.length > 0 && options.removal === undefined) {
172
+ const named = candidates.map((service) => `${service.name} (${service.state?.status ?? "state unknown"})`).join(", ");
173
+ throw new Error(`prune would remove ${named}: pass stop (stop each program, then remove the entry) or keep (leave it running here and clear its source)`);
174
+ }
175
+ const remove = options.removal === "stop" ? candidates : [];
176
+ const keep = options.removal === "keep" ? candidates : [];
177
+ const unmanaged = options.prune === true ? current.services.filter((service) => !sameSource(service.source, options.source) && !planned.has(service.name)) : [];
178
+ return { ifVersion: current.ifVersion, create, change, unchanged, readOnly: current.readOnly, remove, keep, unmanaged };
179
+ }
180
+ function hostsOf(plan) {
181
+ const entries = plan.hosts;
182
+ if (entries === undefined)
183
+ return [];
184
+ if (!Array.isArray(entries))
185
+ throw new Error("the plan's hosts is not a list: a host entry is {name, agents}");
186
+ const named = new Set;
187
+ return entries.map((entry, index) => {
188
+ if (!isRecord(entry))
189
+ throw new Error(`host entry ${index + 1} is not an object: a host entry is {name, agents}`);
190
+ const name = entry.name;
191
+ if (typeof name !== "string" || name.trim().length === 0) {
192
+ throw new Error(`host entry ${index + 1} names no machine: every host entry needs a non-empty "name"`);
193
+ }
194
+ const unknown = Object.keys(entry).filter((key) => key !== "name" && key !== "agents");
195
+ if (unknown.length > 0)
196
+ throw new Error(`host entry ${name}: unknown ${unknown.length === 1 ? "field" : "fields"} ${unknown.join(", ")} (a host entry is {name, agents})`);
197
+ if (named.has(name))
198
+ throw new Error(`${name} is named twice in one plan`);
199
+ named.add(name);
200
+ const agents = entry.agents;
201
+ if (agents !== undefined && (!Array.isArray(agents) || !agents.every((id) => typeof id === "string" && id.length > 0 && id.length <= 256))) {
202
+ throw new Error(`host entry ${name}: agents must be a list of agent member ids`);
203
+ }
204
+ return agents === undefined ? { name } : { name, agents };
205
+ });
206
+ }
207
+ function hostJoinFor(entries, options) {
208
+ const workspace = options.hostJoin;
209
+ if (workspace !== undefined)
210
+ return workspace;
211
+ const named = entries.map((entry) => `host:${entry.name}`).join(", ");
212
+ throw new Error(`host entries need a workspace to mint their join links and this apply has none: ${named}. ` + "Nothing is sent and no host is created from a plan: run it with the workspace's origin and slug, signed in as a person, or take the hosts out of the plan.");
213
+ }
214
+ async function previewHosts(entries, options) {
215
+ requirePerson(options.source.kind === "agent" ? { kind: "agent", id: options.source.id } : { kind: "person", id: options.source.id }, "host-join");
216
+ hostJoinFor(entries, options);
217
+ const pending = entries.map((entry) => ({ name: entry.name, agents: [...entry.agents ?? []] }));
218
+ if (options.prune !== true)
219
+ return { pending };
220
+ return { pending, pruneNote: "host links are not pruned; each unconsumed link expires on its own, and its expiry is printed when it is minted" };
221
+ }
222
+ var AGENTS_CHANNEL = "x-ahpd-agents://";
223
+ var AGENT_FIELDS = ["engine", "owner", "name", "description", "tags", "model"];
224
+ var isRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
225
+ var sourceInConfig = (id, config) => {
226
+ const raw = config[AGENT_SOURCE_KEY];
227
+ if (raw === undefined)
228
+ return;
229
+ if (!isRecord(raw))
230
+ throw new Error(`${id}: config.${AGENT_SOURCE_KEY} is not a source ({kind, id})`);
231
+ const kind = raw.kind;
232
+ const sourceId = raw.id;
233
+ if (kind !== "file" && kind !== "program" && kind !== "agent" && kind !== "ci") {
234
+ throw new Error(`${id}: config.${AGENT_SOURCE_KEY}.kind is not one of file, program, agent, ci`);
235
+ }
236
+ if (typeof sourceId !== "string" || sourceId === "")
237
+ throw new Error(`${id}: config.${AGENT_SOURCE_KEY}.id is empty`);
238
+ return { kind, id: sourceId };
239
+ };
240
+ var agentOf = (entry) => {
241
+ if (!isRecord(entry))
242
+ throw new Error("the agents channel answered an entry that is not an object");
243
+ const held = isRecord(entry.record) ? entry.record : entry;
244
+ const id = entry.id;
245
+ if (typeof id !== "string" || id === "")
246
+ throw new Error("the agents channel answered a record that names no id");
247
+ const revision = typeof held.revision === "number" && Number.isInteger(held.revision) && held.revision >= 0 ? held.revision : undefined;
248
+ const config = isRecord(held.config) ? held.config : {};
249
+ const source = sourceInConfig(id, config);
250
+ return { id, ...revision === undefined ? {} : { revision }, record: held, ...source === undefined ? {} : { source } };
251
+ };
252
+ async function listAgents(host) {
253
+ const answer = await host.call("subscribe", { channel: AGENTS_CHANNEL });
254
+ await host.call("unsubscribe", { channel: AGENTS_CHANNEL });
255
+ const state = answer?.snapshot?.state;
256
+ const records = isRecord(state) ? state.records : undefined;
257
+ if (!Array.isArray(records))
258
+ throw new Error("the agents channel answered no records");
259
+ return records.map(agentOf);
260
+ }
261
+ var agentFieldsOf = (agent) => ({
262
+ engine: agent.engine,
263
+ owner: agent.owner,
264
+ name: agent.name,
265
+ ...agent.description === undefined ? {} : { description: agent.description },
266
+ ...agent.tags === undefined ? {} : { tags: agent.tags },
267
+ ...agent.model === undefined ? {} : { model: agent.model }
268
+ });
269
+ var withoutSource = (config) => Object.fromEntries(Object.entries(config).filter(([key]) => key !== AGENT_SOURCE_KEY));
270
+ var changedAgentFields = (before, after) => {
271
+ const fields = agentFieldsOf(after);
272
+ const changed = AGENT_FIELDS.filter((field) => canonical(before.record[field]) !== canonical(fields[field]));
273
+ const config = isRecord(before.record.config) ? before.record.config : {};
274
+ if (canonical(withoutSource(config)) !== canonical(withoutSource(after.config ?? {})))
275
+ changed.push("config");
276
+ return changed;
277
+ };
278
+ async function previewAgents(plan, host, options) {
279
+ const current = await listAgents(host);
280
+ const byId = new Map(current.map((agent) => [agent.id, agent]));
281
+ const create = [];
282
+ const change = [];
283
+ const unchanged = [];
284
+ const planned = new Set;
285
+ for (const agent of plan) {
286
+ if (planned.has(agent.id))
287
+ throw new Error(`${agent.id} is named twice in one plan`);
288
+ planned.add(agent.id);
289
+ const before = byId.get(agent.id);
290
+ if (before === undefined) {
291
+ create.push(agent);
292
+ } else {
293
+ const changed = changedAgentFields(before, agent);
294
+ if (changed.length === 0)
295
+ unchanged.push(agent.id);
296
+ else if (before.revision === undefined)
297
+ throw new Error(`${agent.id} has no revision on this machine; it cannot be edited from here`);
298
+ else
299
+ change.push({ id: agent.id, before, after: agent, changed });
300
+ }
301
+ }
302
+ const remove = options.prune === true ? current.filter((agent) => sameSource(agent.source, options.source) && !planned.has(agent.id)) : [];
303
+ for (const agent of remove) {
304
+ if (agent.revision === undefined)
305
+ throw new Error(`${agent.id} has no revision on this machine; it cannot be removed from here`);
306
+ }
307
+ return { create, change, unchanged, remove };
308
+ }
309
+ async function applyPreview(shown, host, workspace) {
310
+ let ifVersion = shown.ifVersion ?? "";
311
+ const written = [];
312
+ const hostLinks = [];
313
+ for (const entry of shown.hosts?.pending ?? []) {
314
+ if (workspace === undefined) {
315
+ throw new Error(`host ${entry.name}: host links need a workspace to mint them and this apply has none; nothing was minted`);
316
+ }
317
+ let link;
318
+ try {
319
+ link = await workspace.mintHostJoin(entry.agents);
320
+ } catch (error) {
321
+ throw new Error(`host ${entry.name} was not minted: ${error.message}`);
322
+ }
323
+ hostLinks.push({ name: entry.name, link });
324
+ }
325
+ for (const service of shown.create) {
326
+ const answer = await operate(host, "put", { input: { service, ifVersion: "absent" } });
327
+ ifVersion = answer.ifVersion ?? ifVersion;
328
+ written.push(service.name);
329
+ }
330
+ for (const entry of shown.change) {
331
+ const answer = await operate(host, "put", { input: { service: entry.after, ifVersion } });
332
+ ifVersion = answer.ifVersion ?? ifVersion;
333
+ written.push(entry.name);
334
+ }
335
+ const kept = [];
336
+ for (const entry of shown.keep ?? []) {
337
+ const answer = await operate(host, "put", { input: { service: { name: entry.name, source: null }, ifVersion } });
338
+ ifVersion = answer.ifVersion ?? ifVersion;
339
+ kept.push(entry.name);
340
+ }
341
+ const removed = [];
342
+ for (const entry of shown.remove ?? []) {
343
+ if (entry.state?.status.toLowerCase() === "running") {
344
+ await operate(host, "stop", { target: { id: entry.name }, input: {} });
345
+ }
346
+ const answer = await operate(host, "remove", { target: { id: entry.name }, input: { ifVersion } });
347
+ ifVersion = answer.ifVersion ?? ifVersion;
348
+ removed.push(entry.name);
349
+ }
350
+ if (shown.agents !== undefined) {
351
+ for (const agent of shown.agents.create) {
352
+ await putAgent(host, agent, 0);
353
+ written.push(`agent:${agent.id}`);
354
+ }
355
+ for (const entry of shown.agents.change) {
356
+ if (entry.before.revision === undefined)
357
+ throw new Error(`${entry.id} has no revision on this machine; it cannot be edited from here`);
358
+ await putAgent(host, entry.after, entry.before.revision);
359
+ written.push(`agent:${entry.id}`);
360
+ }
361
+ for (const entry of shown.agents.remove) {
362
+ if (entry.revision === undefined)
363
+ throw new Error(`${entry.id} has no revision on this machine; it cannot be removed from here`);
364
+ await removeAgent(host, entry.id, entry.revision);
365
+ removed.push(`agent:${entry.id}`);
366
+ }
367
+ }
368
+ const hostNote = shown.hosts?.pruneNote === undefined ? undefined : hostLinks.length === 0 ? "host links are not pruned; this apply minted none, so nothing of its own is outstanding" : `host links are not pruned; unconsumed ones expire at ${hostLinks.map((entry) => entry.link.expiresAt).sort()[0]}`;
369
+ return {
370
+ preview: shown,
371
+ written,
372
+ removed,
373
+ kept,
374
+ ...shown.hosts === undefined ? {} : { hostLinks },
375
+ ...hostNote === undefined ? {} : { hostNote }
376
+ };
377
+ }
378
+ var putAgent = (host, agent, ifRevision) => host.call("x-ahpd/agents/put", {
379
+ id: agent.id,
380
+ ...agentFieldsOf(agent),
381
+ config: { ...agent.config, [AGENT_SOURCE_KEY]: agent.source },
382
+ ifRevision
383
+ });
384
+ var removeAgent = (host, id, ifRevision) => host.call("x-ahpd/agents/remove", { id, ifRevision });
385
+ function describe(preview) {
386
+ const lines = [];
387
+ for (const service of preview.create)
388
+ lines.push(`+ ${service.name}`);
389
+ for (const change of preview.change)
390
+ lines.push(`~ ${change.name} (${change.changed.join(", ")})`);
391
+ for (const service of preview.remove ?? []) {
392
+ const running = service.state?.status.toLowerCase() === "running";
393
+ lines.push(`- ${service.name} (${running ? "stop, then remove" : "remove"}; source ${sourceText(service.source)})`);
394
+ }
395
+ for (const service of preview.keep ?? [])
396
+ lines.push(`= ${service.name} (kept: left running here, source cleared)`);
397
+ for (const service of preview.unmanaged ?? []) {
398
+ const why = service.source === undefined ? "no source" : `source ${sourceText(service.source)}`;
399
+ lines.push(`? ${service.name} (not managed by this apply: ${why})`);
400
+ }
401
+ for (const name of preview.unchanged)
402
+ lines.push(`= ${name}`);
403
+ for (const entry of preview.readOnly)
404
+ lines.push(`! ${entry.name} read-only: ${entry.reason}`);
405
+ if (preview.hosts !== undefined) {
406
+ for (const entry of preview.hosts.pending) {
407
+ const agents = entry.agents.length === 0 ? "no agents" : `agents ${entry.agents.join(",")}`;
408
+ lines.push(`+ host:${entry.name} (pending link: the machine must join; ${agents})`);
409
+ }
410
+ if (preview.hosts.pruneNote !== undefined)
411
+ lines.push(`note: ${preview.hosts.pruneNote}`);
412
+ }
413
+ if (preview.agents !== undefined) {
414
+ for (const agent of preview.agents.create)
415
+ lines.push(`+ agent:${agent.id}`);
416
+ for (const change of preview.agents.change)
417
+ lines.push(`~ agent:${change.id} (${change.changed.join(", ")})`);
418
+ for (const agent of preview.agents.remove) {
419
+ lines.push(`- agent:${agent.id} (source ${agent.source === undefined ? "unknown" : sourceText(agent.source)})`);
420
+ }
421
+ for (const id of preview.agents.unchanged)
422
+ lines.push(`= agent:${id}`);
423
+ }
424
+ return lines;
425
+ }
426
+
427
+ // ../client/src/ahp.ts
428
+ import WebSocket from "ws";
429
+ async function connectAhp(url, options) {
430
+ const endpoint = options.token === undefined ? url : `${url}${url.includes("?") ? "&" : "?"}tkn=${encodeURIComponent(options.token)}`;
431
+ const ws = new WebSocket(endpoint);
432
+ const waiting = new Map;
433
+ let closed;
434
+ let nextId = 0;
435
+ ws.on("message", (data) => {
436
+ const frame = JSON.parse(String(data));
437
+ if (frame.id !== undefined && frame.method === undefined)
438
+ waiting.get(frame.id)?.(frame);
439
+ });
440
+ ws.on("close", (code, reason) => {
441
+ closed = `${String(code)} ${reason.toString()}`;
442
+ for (const resolve of waiting.values())
443
+ resolve({ error: { code: 0, message: `closed: ${closed}` } });
444
+ });
445
+ await new Promise((resolve, reject) => {
446
+ ws.once("open", () => resolve());
447
+ ws.once("error", (error) => reject(error));
448
+ });
449
+ const call = (method, params) => new Promise((resolve, reject) => {
450
+ if (closed !== undefined)
451
+ return reject(new Error(`the machine's connection closed: ${closed}`));
452
+ const id = ++nextId;
453
+ waiting.set(id, (frame) => {
454
+ if (frame.error !== undefined)
455
+ reject(new Error(frame.error.message));
456
+ else
457
+ resolve(frame.result);
458
+ });
459
+ ws.send(JSON.stringify({ jsonrpc: "2.0", id, method, params }));
460
+ });
461
+ await call("initialize", { channel: "ahp-root://", protocolVersions: ["1.1.0"], clientId: options.clientId });
462
+ return { call, close: () => ws.close() };
463
+ }
464
+
465
+ export { sourceOf, deployService, deploys, preview, applyPreview, describe, connectAhp };
@@ -0,0 +1,16 @@
1
+ import {
2
+ agentAppsOnPath2,
3
+ installLineOf2,
4
+ describedApp2,
5
+ appInstalled2,
6
+ isShippedApp2,
7
+ noAgentAppsLine2
8
+ } from "./chunk-dvnzt54t.js";
9
+ export {
10
+ agentAppsOnPath2 as agentAppsOnPath,
11
+ appInstalled2 as appInstalled,
12
+ describedApp2 as describedApp,
13
+ installLineOf2 as installLineOf,
14
+ isShippedApp2 as isShippedApp,
15
+ noAgentAppsLine2 as noAgentAppsLine
16
+ };
@@ -6,7 +6,7 @@ import {
6
6
 
7
7
  // src/host.ts
8
8
  var USAGE = `hightea host list --origin https://your-deployment --workspace SLUG [--session-file FILE] [--json]
9
- ` + "hightea host remove --origin https://your-deployment --workspace SLUG --host HOST [--session-file FILE] [--json]";
9
+ ` + "hightea host remove --origin https://your-deployment --workspace SLUG --host HOST [--remove-agents] [--session-file FILE] [--json]";
10
10
  async function hostRemove(target, io = ownerIo()) {
11
11
  if (target.workspace.trim().length === 0 || target.host.trim().length === 0) {
12
12
  io.err(`HOST_REMOVE_INPUT: --workspace and --host are required.
@@ -14,9 +14,10 @@ ${USAGE}`);
14
14
  return 1;
15
15
  }
16
16
  const hostId = target.host.trim();
17
+ const query = target.removeAgents === true ? "?removeAgents=1" : "";
17
18
  const sent = await sendOwner(target, io, {
18
19
  method: "DELETE",
19
- path: `/hosts/${encodeURIComponent(hostId)}`,
20
+ path: `/hosts/${encodeURIComponent(hostId)}${query}`,
20
21
  what: "remove",
21
22
  label: "HOST_REMOVE"
22
23
  });
@@ -36,14 +37,16 @@ ${USAGE}`);
36
37
  return 0;
37
38
  }
38
39
  io.out(`removed host ${name}: revoked, ${ended} ${ended === 1 ? "delivery" : "deliveries"} ended`);
39
- io.out("Its agents have no host until they join again with a new join code.");
40
+ const kept = Array.isArray(sent.answer.agentsKeptUnrouted) ? sent.answer.agentsKeptUnrouted.length : 0;
41
+ io.out(kept === 0 ? "Its agents have no host until they join again with a new join code." : `Its ${kept === 1 ? "agent is" : `${String(kept)} agents are`} still a member, now with no computer; a new join code routes ${kept === 1 ? "it" : "them"} again. (--remove-agents deletes them with the computer.)`);
40
42
  return 0;
41
43
  }
42
44
  function hostLine(host) {
43
45
  const field = (name) => host[name] === null || host[name] === undefined ? "none" : String(host[name]);
44
46
  const agents = Array.isArray(host.agentMemberIds) && host.agentMemberIds.length > 0 ? host.agentMemberIds.join(",") : "none";
45
47
  const state = field("status") === "revoked" ? `revoked ${field("revokedAt")}` : `last seen ${field("lastSeenAt")}`;
46
- return `${field("hostId")} ${field("status")} ${host.connected === true ? "connected" : "not connected"} ` + `plugin ${field("pluginVersion")} agents ${agents} owner ${field("ownerAccountId")} ${state}`;
48
+ const note = typeof host.initializeNote === "string" ? ` ${host.initializeNote}` : "";
49
+ return `${field("hostId")} ${field("status")} ${host.connected === true ? "connected" : "not connected"} ` + `plugin ${field("pluginVersion")} agents ${agents} owner ${field("ownerAccountId")} ${state}${note}`;
47
50
  }
48
51
  async function hostList(target, io = ownerIo()) {
49
52
  if (target.workspace.trim().length === 0) {
@@ -70,6 +73,14 @@ ${USAGE}`);
70
73
  if (hosts.some((host) => host.status === "active")) {
71
74
  io.out("A host you no longer use: `hightea host remove --workspace " + target.workspace.trim() + " --host <id>`.");
72
75
  }
76
+ const carrier = sent.answer.wakeCarrier;
77
+ if (typeof carrier?.active !== "number" || typeof carrier.unsigned !== "number") {
78
+ io.err("WAKE_CARRIER_UNKNOWN: this workspace answered no wakeCarrier census (active, unsigned), so whether any host " + "still gets a wake bearer is unknown. The workspace build and this CLI disagree; the list above is not evidence " + "that the old wake path is unused.");
79
+ } else if (carrier.unsigned === 0) {
80
+ io.out(`every active host advertises signed envelopes: the wake-bearer path can be deleted`);
81
+ } else {
82
+ io.out(`${carrier.unsigned} of ${carrier.active} active hosts lack signed envelopes and still get a wake bearer; ` + `the path can be deleted when this reads 0`);
83
+ }
73
84
  return 0;
74
85
  }
75
86
  export {