@hallohuman/hightea 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin.js +30 -4
- package/dist/chunk-9wxqnv9x.js +149 -0
- package/dist/{chunk-e1ze9fw5.js → chunk-mcmsnaer.js} +84 -4
- package/dist/plugin/plugin.json +1 -1
- package/dist/plugin/plugin.mjs +1309 -29
- package/package.json +15 -6
package/dist/bin.js
CHANGED
|
@@ -5,7 +5,7 @@ import { fileURLToPath } from "node:url";
|
|
|
5
5
|
// package.json
|
|
6
6
|
var package_default = {
|
|
7
7
|
name: "@hallohuman/hightea",
|
|
8
|
-
version: "0.1.
|
|
8
|
+
version: "0.1.2",
|
|
9
9
|
description: "The Hightea command line: join this machine to a Hightea workspace as a host.",
|
|
10
10
|
publishConfig: { access: "public" },
|
|
11
11
|
type: "module",
|
|
@@ -30,14 +30,40 @@ async function runCli(argv, options) {
|
|
|
30
30
|
let code = 0;
|
|
31
31
|
const program = new Command("hightea").description("Hightea: join this machine to a Hightea workspace as a host for your own agents.").version(options.version, "-v, --version").exitOverride();
|
|
32
32
|
const host = program.command("host").description("This machine as a host: where your agents run.").exitOverride();
|
|
33
|
-
host.command("join").description("Join this machine to a workspace with a one-use host join code from the workspace owner.").option("--origin <url>", "The deployment, e.g. https://hightea.dev").option("--workspace <slug>", "The workspace slug").option("--code <code>", "The one-use join code").option("--owner-config <file>", "Your owner configuration: agents, provider plugins and their credentials").
|
|
34
|
-
|
|
33
|
+
host.command("join").description("Join this machine to a workspace with a one-use host join code from the workspace owner.").option("--origin <url>", "The deployment, e.g. https://hightea.dev").option("--workspace <slug>", "The workspace slug").option("--code <code>", "The one-use join code").option("--owner-config <file>", "Your owner configuration: agents, provider plugins and their credentials").addHelpText("after", `
|
|
34
|
+
Exit status: 0 registered; 2 pending, rerun the same command; 3 not authorised for that workspace or agent;
|
|
35
|
+
4 an agent is already bound to another host; 1 any other failure.`).exitOverride().action(async (flags) => {
|
|
36
|
+
const { hostJoin } = await import("./chunk-mcmsnaer.js");
|
|
35
37
|
code = await hostJoin({ origin: flags.origin ?? "", workspace: flags.workspace ?? "", code: flags.code ?? "", ownerConfig: flags.ownerConfig ?? "" }, { directory: options.pluginDirectory, version: options.version });
|
|
36
38
|
});
|
|
37
39
|
host.command("status").description("Show every joined host on this machine and whether its plugin bundle is intact. Changes nothing.").option("--json", "Print one JSON document").exitOverride().action(async (flags) => {
|
|
38
|
-
const { hostStatus } = await import("./chunk-
|
|
40
|
+
const { hostStatus } = await import("./chunk-mcmsnaer.js");
|
|
39
41
|
code = await hostStatus({ version: options.version, json: flags.json === true });
|
|
40
42
|
});
|
|
43
|
+
const source = program.command("source").description("A workspace's km sources: bind one to a host, or read its state.").exitOverride();
|
|
44
|
+
source.command("bind").description("Bind a km source to one of the workspace's hosts, as the workspace owner.").option("--origin <url>", "The deployment, e.g. https://hightea.dev").option("--workspace <slug>", "The workspace slug").option("--source <id>", "The source id, e.g. src_km").option("--host <id>", "The host id that serves the source").option("--session-file <file>", "File holding your signed-in ht_session cookie (default: HIGHTEA_SESSION_FILE)").option("--json", "Print one JSON document").addHelpText("after", `
|
|
45
|
+
Exit status: 0 bound; 3 your account is not this workspace's owner; 4 that source is bound to another host;
|
|
46
|
+
1 any other failure.`).exitOverride().action(async (flags) => {
|
|
47
|
+
const { sourceBind } = await import("./chunk-9wxqnv9x.js");
|
|
48
|
+
code = await sourceBind({
|
|
49
|
+
origin: flags.origin ?? "",
|
|
50
|
+
workspace: flags.workspace ?? "",
|
|
51
|
+
source: flags.source ?? "",
|
|
52
|
+
host: flags.host ?? "",
|
|
53
|
+
sessionFile: flags.sessionFile,
|
|
54
|
+
json: flags.json === true
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
source.command("show").description("Read one source's binding, freshness and position; changes nothing.").option("--origin <url>", "The deployment, e.g. https://hightea.dev").option("--workspace <slug>", "The workspace slug").option("--source <id>", "The source id, e.g. src_km").option("--session-file <file>", "File holding your signed-in ht_session cookie (default: HIGHTEA_SESSION_FILE)").option("--json", "Print one JSON document").exitOverride().action(async (flags) => {
|
|
58
|
+
const { sourceShow } = await import("./chunk-9wxqnv9x.js");
|
|
59
|
+
code = await sourceShow({
|
|
60
|
+
origin: flags.origin ?? "",
|
|
61
|
+
workspace: flags.workspace ?? "",
|
|
62
|
+
source: flags.source ?? "",
|
|
63
|
+
sessionFile: flags.sessionFile,
|
|
64
|
+
json: flags.json === true
|
|
65
|
+
});
|
|
66
|
+
});
|
|
41
67
|
try {
|
|
42
68
|
await program.parseAsync([...argv], { from: "user" });
|
|
43
69
|
} catch (error) {
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
// src/source.ts
|
|
2
|
+
import { readFile, stat } from "node:fs/promises";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
var USAGE = `hightea source bind --origin https://your-deployment --workspace SLUG --source SOURCE --host HOST [--session-file FILE] [--json]
|
|
6
|
+
` + "hightea source show --origin https://your-deployment --workspace SLUG --source SOURCE [--session-file FILE] [--json]";
|
|
7
|
+
var NOT_OWNER = new Set(["FORBIDDEN", "NOT_A_MEMBER", "UNAUTHENTICATED"]);
|
|
8
|
+
var BOUND_ELSEWHERE = "SOURCE_BINDING_CONFLICT";
|
|
9
|
+
function defaults() {
|
|
10
|
+
return {
|
|
11
|
+
fetch: (url, init) => globalThis.fetch(url, init),
|
|
12
|
+
readFile: (path) => readFile(path, "utf8"),
|
|
13
|
+
stat: (path) => stat(path),
|
|
14
|
+
env: process.env,
|
|
15
|
+
home: homedir(),
|
|
16
|
+
out: (line) => {
|
|
17
|
+
process.stdout.write(`${line}
|
|
18
|
+
`);
|
|
19
|
+
},
|
|
20
|
+
err: (line) => {
|
|
21
|
+
process.stderr.write(`${line}
|
|
22
|
+
`);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function checkedOrigin(origin) {
|
|
27
|
+
try {
|
|
28
|
+
const url = new URL(origin);
|
|
29
|
+
return url.protocol === "https:" && url.pathname === "/" && url.search === "" && url.hash === "" ? url.origin : null;
|
|
30
|
+
} catch {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async function readSession(target, io) {
|
|
35
|
+
const file = target.sessionFile?.trim() || io.env.HIGHTEA_SESSION_FILE?.trim() || join(io.env.XDG_CONFIG_HOME?.trim() || join(io.home, ".config"), "hightea", "session");
|
|
36
|
+
let raw;
|
|
37
|
+
let mode;
|
|
38
|
+
try {
|
|
39
|
+
raw = await io.readFile(file);
|
|
40
|
+
mode = (await io.stat(file)).mode;
|
|
41
|
+
} catch (error) {
|
|
42
|
+
return { error: `SOURCE_SESSION_MISSING: no session in ${file} (${error.message}). Sign in to the deployment in a browser and write its ht_session cookie to that file, or pass --session-file.` };
|
|
43
|
+
}
|
|
44
|
+
if ((mode & 63) !== 0) {
|
|
45
|
+
return { error: `SOURCE_SESSION_EXPOSED: ${file} is mode 0${(mode & 511).toString(8).padStart(3, "0")}; run chmod 600 ${file}.` };
|
|
46
|
+
}
|
|
47
|
+
const lines = raw.split(`
|
|
48
|
+
`).map((line) => line.trim()).filter((line) => line.length > 0);
|
|
49
|
+
if (lines.length !== 1) {
|
|
50
|
+
return { error: `SOURCE_SESSION_INVALID: ${file} must hold exactly one non-empty line (the ht_session cookie value); it holds ${lines.length}.` };
|
|
51
|
+
}
|
|
52
|
+
return { cookie: lines[0] };
|
|
53
|
+
}
|
|
54
|
+
async function send(target, io, request) {
|
|
55
|
+
const origin = checkedOrigin(target.origin);
|
|
56
|
+
if (origin === null) {
|
|
57
|
+
return { exit: 1, error: `SOURCE_ORIGIN_INVALID: --origin must be the https deployment origin, e.g. https://hightea.dev (got ${JSON.stringify(target.origin)}).` };
|
|
58
|
+
}
|
|
59
|
+
if (target.workspace.trim().length === 0 || target.source.trim().length === 0) {
|
|
60
|
+
return { exit: 1, error: `SOURCE_INPUT: --workspace and --source are required.
|
|
61
|
+
${USAGE}` };
|
|
62
|
+
}
|
|
63
|
+
const session = await readSession(target, io);
|
|
64
|
+
if ("error" in session)
|
|
65
|
+
return { exit: 1, error: session.error };
|
|
66
|
+
const url = `${origin}/api/ws/${encodeURIComponent(target.workspace)}/sources/${encodeURIComponent(target.source)}${request.path}`;
|
|
67
|
+
let response;
|
|
68
|
+
try {
|
|
69
|
+
response = await io.fetch(url, {
|
|
70
|
+
method: request.method,
|
|
71
|
+
headers: {
|
|
72
|
+
cookie: `ht_session=${session.cookie}`,
|
|
73
|
+
origin,
|
|
74
|
+
accept: "application/json",
|
|
75
|
+
"cache-control": "no-store",
|
|
76
|
+
...request.body === undefined ? {} : { "content-type": "application/json" }
|
|
77
|
+
},
|
|
78
|
+
...request.body === undefined ? {} : { body: JSON.stringify(request.body) }
|
|
79
|
+
});
|
|
80
|
+
} catch (error) {
|
|
81
|
+
return { exit: 1, error: `SOURCE_UNREACHABLE: ${request.what} ${request.method} ${url} did not answer: ${error.message}` };
|
|
82
|
+
}
|
|
83
|
+
const text = await response.text();
|
|
84
|
+
let answer = {};
|
|
85
|
+
if (text.length > 0) {
|
|
86
|
+
try {
|
|
87
|
+
const parsed = JSON.parse(text);
|
|
88
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed))
|
|
89
|
+
throw new SyntaxError("not a JSON object");
|
|
90
|
+
answer = parsed;
|
|
91
|
+
} catch (error) {
|
|
92
|
+
if (!(error instanceof SyntaxError))
|
|
93
|
+
throw error;
|
|
94
|
+
return { exit: 1, error: `SOURCE_ANSWER_INVALID: ${request.what} ${request.method} ${url} answered HTTP ${response.status} with non-JSON: ${text.slice(0, 300)}` };
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (response.ok)
|
|
98
|
+
return { answer };
|
|
99
|
+
const refusal = answer.error;
|
|
100
|
+
const code = typeof refusal?.code === "string" ? refusal.code : `HTTP_${response.status}`;
|
|
101
|
+
const message = typeof refusal?.message === "string" ? refusal.message : text.slice(0, 300);
|
|
102
|
+
const exit = NOT_OWNER.has(code) ? 3 : code === BOUND_ELSEWHERE ? 4 : 1;
|
|
103
|
+
return { exit, error: `${code}: ${message}` };
|
|
104
|
+
}
|
|
105
|
+
function datasetLine(source) {
|
|
106
|
+
const field = (name) => source[name] === null || source[name] === undefined ? "none" : String(source[name]);
|
|
107
|
+
const listing = source.listing === true ? ", first list running" : source.listing === false ? ", no list running" : "";
|
|
108
|
+
return `${field("status")} on ${field("hostId")} as dataset ${field("dataset")} (freshness ${field("freshness")}${listing})`;
|
|
109
|
+
}
|
|
110
|
+
async function sourceBind(target, io = defaults()) {
|
|
111
|
+
if (target.host.trim().length === 0) {
|
|
112
|
+
io.err(`SOURCE_INPUT: --host is required (the host id that serves the source).
|
|
113
|
+
${USAGE}`);
|
|
114
|
+
return 1;
|
|
115
|
+
}
|
|
116
|
+
const sent = await send(target, io, { method: "POST", path: "/bind", body: { hostId: target.host.trim() }, what: "bind" });
|
|
117
|
+
if ("error" in sent) {
|
|
118
|
+
io.err(sent.error);
|
|
119
|
+
return sent.exit;
|
|
120
|
+
}
|
|
121
|
+
if (target.json) {
|
|
122
|
+
io.out(JSON.stringify(sent.answer));
|
|
123
|
+
return 0;
|
|
124
|
+
}
|
|
125
|
+
const source = sent.answer.source ?? {};
|
|
126
|
+
io.out(`bound ${String(source.sourceId ?? target.source)} to ${String(source.hostId ?? target.host)}: ${datasetLine(source)}`);
|
|
127
|
+
io.out("The source's first list fills its dataset; run `hightea source show` to watch its freshness.");
|
|
128
|
+
return 0;
|
|
129
|
+
}
|
|
130
|
+
async function sourceShow(target, io = defaults()) {
|
|
131
|
+
const sent = await send(target, io, { method: "GET", path: "", what: "read" });
|
|
132
|
+
if ("error" in sent) {
|
|
133
|
+
io.err(sent.error);
|
|
134
|
+
return sent.exit;
|
|
135
|
+
}
|
|
136
|
+
if (target.json) {
|
|
137
|
+
io.out(JSON.stringify(sent.answer));
|
|
138
|
+
return 0;
|
|
139
|
+
}
|
|
140
|
+
const source = sent.answer.source ?? {};
|
|
141
|
+
const position = source.position;
|
|
142
|
+
io.out(`${String(source.sourceId ?? target.source)}: ${datasetLine(source)}`);
|
|
143
|
+
io.out(`position ${position === null || position === undefined ? "none" : `${String(position.epoch)}/${String(position.ordinal)}`}, ` + `last error ${source.lastError === null || source.lastError === undefined ? "none" : String(source.lastError)}, ` + `dropped ${String(source.dropped ?? 0)}, duplicates ${String(source.duplicates ?? 0)}`);
|
|
144
|
+
return 0;
|
|
145
|
+
}
|
|
146
|
+
export {
|
|
147
|
+
sourceBind,
|
|
148
|
+
sourceShow
|
|
149
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// ../ahp-host/src/commands.ts
|
|
2
2
|
import { readdir, readFile as readFile2 } from "node:fs/promises";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
3
4
|
import { homedir } from "node:os";
|
|
4
5
|
import { basename, dirname as dirname3, isAbsolute as isAbsolute3, join as join5, resolve } from "node:path";
|
|
5
6
|
import { fromEnvRef as fromEnvRef2, isRecord as isRecord3, readSecret, secretRef as secretRef2 } from "@ahpd/sdk";
|
|
@@ -14,6 +15,7 @@ import { isDeepStrictEqual } from "node:util";
|
|
|
14
15
|
import { fileVault } from "@ahpd/server/dist/vault.js";
|
|
15
16
|
// ../members/src/members-store.ts
|
|
16
17
|
var DEFAULT_SESSION_TTL_MS = 30 * 86400000;
|
|
18
|
+
var AGENT_BINDING_REQUEST_TTL_MS = 15 * 60000;
|
|
17
19
|
// ../../node_modules/.bun/zod@4.6.7/node_modules/zod/v4/core/util.js
|
|
18
20
|
function getEnumValues(entries) {
|
|
19
21
|
const numericValues = Object.values(entries).filter((v) => typeof v === "number");
|
|
@@ -5149,6 +5151,24 @@ function superRefine(fn, params) {
|
|
|
5149
5151
|
return _superRefine(fn, params);
|
|
5150
5152
|
}
|
|
5151
5153
|
// ../members/src/host-join-types.ts
|
|
5154
|
+
var JOIN_ROUTE_REFUSAL_STATUS = {
|
|
5155
|
+
JOIN_LINK_INVALID: 410,
|
|
5156
|
+
JOIN_LINK_NOT_FOUND: 404,
|
|
5157
|
+
ROLE_NOT_ALLOWED: 400,
|
|
5158
|
+
NOT_A_MEMBER: 403,
|
|
5159
|
+
FORBIDDEN: 403,
|
|
5160
|
+
HOST_REGISTRATION_CANCELLED: 410,
|
|
5161
|
+
HOST_REGISTRATION_CONFLICT: 409,
|
|
5162
|
+
AGENT_HOST_CONFLICT: 409,
|
|
5163
|
+
HOST_REGISTRATION_MISSING: 409,
|
|
5164
|
+
INVALID_REQUEST: 400,
|
|
5165
|
+
BAD_ORIGIN: 403,
|
|
5166
|
+
UNAUTHENTICATED: 401,
|
|
5167
|
+
WORKSPACE_NOT_FOUND: 404
|
|
5168
|
+
};
|
|
5169
|
+
function isJoinRouteRefusalCode(value) {
|
|
5170
|
+
return typeof value === "string" && Object.hasOwn(JOIN_ROUTE_REFUSAL_STATUS, value);
|
|
5171
|
+
}
|
|
5152
5172
|
var id = string2().min(1).max(256);
|
|
5153
5173
|
var digest = string2().regex(/^sha256:[a-f0-9]{64}$/u);
|
|
5154
5174
|
var version2 = string2().min(1).max(64);
|
|
@@ -5337,7 +5357,7 @@ async function selectHostClaim(configHome, input) {
|
|
|
5337
5357
|
if (original.origin !== requested.origin || original.workspaceSlug !== requested.workspaceSlug || original.code !== requested.code || !isDeepStrictEqual(original.ownerConfiguration, requested.ownerConfiguration))
|
|
5338
5358
|
refusal("HOST_JOIN_CLAIM_CONFLICT");
|
|
5339
5359
|
await flushHostFile(vaultFile);
|
|
5340
|
-
return { home, vaultFile, authorization, credentialHash: createHash("sha256").update(authorization.slice(7), "utf8").digest("hex")
|
|
5360
|
+
return { home, vaultFile, authorization, credentialHash: `sha256:${createHash("sha256").update(authorization.slice(7), "utf8").digest("hex")}`, intent: original };
|
|
5341
5361
|
} finally {
|
|
5342
5362
|
await rm(candidate, { recursive: true });
|
|
5343
5363
|
}
|
|
@@ -5411,6 +5431,24 @@ async function saveHostJson(claim, directory, name, configuration) {
|
|
|
5411
5431
|
|
|
5412
5432
|
// ../ahp-host/src/join.ts
|
|
5413
5433
|
import { isRecord } from "@ahpd/sdk";
|
|
5434
|
+
class HostJoinRefusal extends Error {
|
|
5435
|
+
kind;
|
|
5436
|
+
status;
|
|
5437
|
+
serverCode;
|
|
5438
|
+
constructor(kind, status, serverCode) {
|
|
5439
|
+
super(kind);
|
|
5440
|
+
this.kind = kind;
|
|
5441
|
+
this.status = status;
|
|
5442
|
+
this.serverCode = serverCode;
|
|
5443
|
+
}
|
|
5444
|
+
}
|
|
5445
|
+
function refusalKind(status, serverCode) {
|
|
5446
|
+
if (status === 401 || status === 403)
|
|
5447
|
+
return "HOST_JOIN_NOT_AUTHORISED";
|
|
5448
|
+
if (serverCode === "AGENT_HOST_CONFLICT" || serverCode === "HOST_REGISTRATION_CONFLICT")
|
|
5449
|
+
return "HOST_JOIN_AGENT_BOUND";
|
|
5450
|
+
return "HOST_JOIN_REJECTED";
|
|
5451
|
+
}
|
|
5414
5452
|
async function redeemHostClaim(claim) {
|
|
5415
5453
|
await flushHostFile(claim.vaultFile);
|
|
5416
5454
|
const intent = claim.intent;
|
|
@@ -5438,8 +5476,14 @@ async function redeemHostClaim(claim) {
|
|
|
5438
5476
|
}
|
|
5439
5477
|
if (response.status >= 500)
|
|
5440
5478
|
throw new Error("HOST_JOIN_REMOTE_UNAVAILABLE");
|
|
5441
|
-
if (!response.ok)
|
|
5442
|
-
|
|
5479
|
+
if (!response.ok) {
|
|
5480
|
+
let error;
|
|
5481
|
+
try {
|
|
5482
|
+
error = await response.json();
|
|
5483
|
+
} catch {}
|
|
5484
|
+
const serverCode = isRecord(error) && isRecord(error.error) && isJoinRouteRefusalCode(error.error.code) ? error.error.code : undefined;
|
|
5485
|
+
throw new HostJoinRefusal(refusalKind(response.status, serverCode), response.status, serverCode);
|
|
5486
|
+
}
|
|
5443
5487
|
let receipt;
|
|
5444
5488
|
try {
|
|
5445
5489
|
receipt = await response.json();
|
|
@@ -5702,6 +5746,8 @@ var DIAGNOSTICS = {
|
|
|
5702
5746
|
HOST_JOIN_CANCELLED: "The owner cancelled this host registration. Keep the existing claim; request a new join code for another registration.",
|
|
5703
5747
|
HOST_JOIN_LINK_UNAVAILABLE: "This join code is expired or unavailable. Keep the existing claim; request a new code if registration was not completed.",
|
|
5704
5748
|
HOST_JOIN_REJECTED: "The deployment rejected registration. Check the deployment and workspace; the selected credential was retained.",
|
|
5749
|
+
HOST_JOIN_NOT_AUTHORISED: "The deployment refused this account for that workspace or agent. Join with the account that owns the agents in --owner-config; the selected credential was retained.",
|
|
5750
|
+
HOST_JOIN_AGENT_BOUND: "An agent in --owner-config already belongs to another host. Remove that host (or its registration) in the workspace, then rerun the same command; the selected credential was retained.",
|
|
5705
5751
|
HOST_JOIN_RECEIPT_INVALID: "The deployment returned an invalid registration receipt. Keep this claim and retry against the correct deployment.",
|
|
5706
5752
|
HOST_JOIN_CONFIG_CONFLICT: "Existing host configuration has different bindings or required settings. It was preserved; reconcile it with the original claim before retrying.",
|
|
5707
5753
|
HOST_JOIN_CONFIG_CORRUPT: "Existing host configuration is invalid JSON. It was preserved for local repair; rerun after repairing it.",
|
|
@@ -5715,6 +5761,34 @@ function xdgHome(variable, fallback) {
|
|
|
5715
5761
|
throw new Error("HOST_JOIN_UNSAFE_PATH");
|
|
5716
5762
|
return home;
|
|
5717
5763
|
}
|
|
5764
|
+
function installedDaemon() {
|
|
5765
|
+
const manifest = createRequire(import.meta.url).resolve("@ahpd/server/package.json");
|
|
5766
|
+
return { node: process.execPath, main: join5(dirname3(manifest), "dist", "main.js") };
|
|
5767
|
+
}
|
|
5768
|
+
var shellQuote = (value) => `'${value.replaceAll("'", "'\\''")}'`;
|
|
5769
|
+
function hostStartCommand(claim, daemon = installedDaemon()) {
|
|
5770
|
+
return `XDG_CONFIG_HOME=${shellQuote(claim)} ${shellQuote(daemon.node)} ${shellQuote(daemon.main)} start`;
|
|
5771
|
+
}
|
|
5772
|
+
var SERVER_REFUSALS = {
|
|
5773
|
+
JOIN_LINK_INVALID: "the join code is no longer valid",
|
|
5774
|
+
JOIN_LINK_NOT_FOUND: "no such join code in that workspace",
|
|
5775
|
+
ROLE_NOT_ALLOWED: "the join code does not allow this role",
|
|
5776
|
+
NOT_A_MEMBER: "the signed-in account is not a member of that workspace",
|
|
5777
|
+
FORBIDDEN: "an agent in --owner-config belongs to another account",
|
|
5778
|
+
HOST_REGISTRATION_CANCELLED: "the owner cancelled this registration",
|
|
5779
|
+
HOST_REGISTRATION_CONFLICT: "this code was redeemed for a different host registration",
|
|
5780
|
+
AGENT_HOST_CONFLICT: "an agent already belongs to another active host",
|
|
5781
|
+
HOST_REGISTRATION_MISSING: "the pending registration is gone",
|
|
5782
|
+
INVALID_REQUEST: "the deployment did not accept this request's shape",
|
|
5783
|
+
BAD_ORIGIN: "the request came from another site",
|
|
5784
|
+
UNAUTHENTICATED: "the request carried no signed-in account",
|
|
5785
|
+
WORKSPACE_NOT_FOUND: "no such workspace for this account"
|
|
5786
|
+
};
|
|
5787
|
+
var REFUSAL_EXIT = { HOST_JOIN_NOT_AUTHORISED: 3, HOST_JOIN_AGENT_BOUND: 4, HOST_JOIN_REJECTED: 1 };
|
|
5788
|
+
function refusalLine(refusal) {
|
|
5789
|
+
const meaning = refusal.serverCode === undefined ? "" : ` The deployment says ${SERVER_REFUSALS[refusal.serverCode]}.`;
|
|
5790
|
+
return `${refusal.kind}: ${DIAGNOSTICS[refusal.kind]}${meaning} (HTTP ${refusal.status}, server code ${refusal.serverCode ?? "unrecognised"})`;
|
|
5791
|
+
}
|
|
5718
5792
|
async function hostJoin(input, plugin) {
|
|
5719
5793
|
try {
|
|
5720
5794
|
const { origin, workspace, code, ownerConfig: ownerFile } = input;
|
|
@@ -5785,9 +5859,13 @@ async function hostJoin(input, plugin) {
|
|
|
5785
5859
|
}
|
|
5786
5860
|
}]
|
|
5787
5861
|
});
|
|
5788
|
-
console.log(
|
|
5862
|
+
console.log(`Host registered; local configuration saved. Start it with: ${hostStartCommand(claim.home)}`);
|
|
5789
5863
|
return 0;
|
|
5790
5864
|
} catch (error) {
|
|
5865
|
+
if (error instanceof HostJoinRefusal) {
|
|
5866
|
+
console.error(refusalLine(error));
|
|
5867
|
+
return REFUSAL_EXIT[error.kind];
|
|
5868
|
+
}
|
|
5791
5869
|
const code = error instanceof Error && /^HOST_JOIN_[A-Z_]+$/u.test(error.message) ? error.message : "HOST_JOIN_INPUT";
|
|
5792
5870
|
console.error(`${code}: ${DIAGNOSTICS[code] ?? "Local claim storage could not be safely published or flushed. Keep the existing files, check filesystem access and retry; no replacement credential was selected."}`);
|
|
5793
5871
|
return 1;
|
|
@@ -5820,6 +5898,7 @@ async function readStatusEntry(claim) {
|
|
|
5820
5898
|
claim,
|
|
5821
5899
|
state: "joined",
|
|
5822
5900
|
config,
|
|
5901
|
+
start: hostStartCommand(claim),
|
|
5823
5902
|
pluginBundle,
|
|
5824
5903
|
bundle,
|
|
5825
5904
|
...installed.ok ? { pluginVersion: installed.bundle.version } : {},
|
|
@@ -5865,6 +5944,7 @@ async function hostStatus(options) {
|
|
|
5865
5944
|
`joined workspace ${entry.workspaceId} host ${entry.hostId}`,
|
|
5866
5945
|
` gateway ${entry.gateway ?? "(none)"}`,
|
|
5867
5946
|
` config ${entry.config}`,
|
|
5947
|
+
` start ${entry.start}`,
|
|
5868
5948
|
` plugin ${entry.pluginBundle} (${entry.bundle}${versionNote(entry.pluginVersion, options.version)})`
|
|
5869
5949
|
].join(`
|
|
5870
5950
|
`));
|
package/dist/plugin/plugin.json
CHANGED