@theholocron/cli 5.0.0-alpha.230 → 5.0.0-alpha.232
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/cli.mjs +169 -13
- package/dist/cli.mjs.map +1 -1
- package/dist/index.d.mts +31 -3
- package/dist/index.mjs +140 -1
- package/dist/plugin/capabilities.d.mts +2 -0
- package/package.json +3 -3
package/dist/cli.mjs
CHANGED
|
@@ -25,7 +25,7 @@ import { execFileSync, spawn, spawnSync } from "node:child_process";
|
|
|
25
25
|
import ora from "ora";
|
|
26
26
|
import { findRootSync, isWorkspaceRoot, walkFilesSync } from "@theholocron/fs-utils";
|
|
27
27
|
import { access, copyFile, mkdir, open, readFile, readdir, rename, rm, stat, symlink, unlink, writeFile } from "node:fs/promises";
|
|
28
|
-
import { createHash, randomBytes, randomUUID } from "node:crypto";
|
|
28
|
+
import { createHash, createHmac, randomBytes, randomUUID } from "node:crypto";
|
|
29
29
|
import { createServer } from "node:http";
|
|
30
30
|
import { stringifyJson } from "@theholocron/json-utils";
|
|
31
31
|
import { generateReadme } from "@theholocron/components-doc/markdown";
|
|
@@ -6913,33 +6913,186 @@ function printNextSteps$1(print, inputs) {
|
|
|
6913
6913
|
print(" 7. Commit + push when capability is functionally complete.");
|
|
6914
6914
|
}
|
|
6915
6915
|
//#endregion
|
|
6916
|
+
//#region src/commands/probe/comlink-probes.ts
|
|
6917
|
+
/** The group of probes for the Comlink relay Worker (`apps/comlink`). It is an app, not a provider, so they are the CLI's own. */
|
|
6918
|
+
const COMLINK_PROVIDER = "comlink";
|
|
6919
|
+
/** Where the relay answers and what it is called, from the notifications layout and the `errors` provider. */
|
|
6920
|
+
function relayOf(loader) {
|
|
6921
|
+
const layout = notificationProviders(loader)[0]?.layout;
|
|
6922
|
+
const host = layout?.relay?.host;
|
|
6923
|
+
if (!host) throw new Error("no relay is declared: add `relay.host` to the notifications layout");
|
|
6924
|
+
const found = loader.has("errors") ? loader.get("errors") : void 0;
|
|
6925
|
+
const errors = Array.isArray(found) ? found[0] : found;
|
|
6926
|
+
if (!errors) throw new Error("the relay carries an error tracker's alerts, and no `errors` provider is available");
|
|
6927
|
+
return {
|
|
6928
|
+
host,
|
|
6929
|
+
script: layout.relay?.script ?? "comlink",
|
|
6930
|
+
source: errors.providerName.toLowerCase()
|
|
6931
|
+
};
|
|
6932
|
+
}
|
|
6933
|
+
/** An event-alert delivery in the shape Sentry sends, labelled so nobody mistakes it for a real error. */
|
|
6934
|
+
const testDelivery = () => JSON.stringify({
|
|
6935
|
+
action: "triggered",
|
|
6936
|
+
data: {
|
|
6937
|
+
event: {
|
|
6938
|
+
title: "Holocron probe: Comlink delivery check",
|
|
6939
|
+
culprit: "holocron probe comlink deliver",
|
|
6940
|
+
level: "info",
|
|
6941
|
+
environment: "holocron-probe",
|
|
6942
|
+
project_name: "holocron-probe",
|
|
6943
|
+
datetime: (/* @__PURE__ */ new Date()).toISOString()
|
|
6944
|
+
},
|
|
6945
|
+
triggered_rule: "holocron probe"
|
|
6946
|
+
}
|
|
6947
|
+
});
|
|
6948
|
+
function comlinkProbes(deps) {
|
|
6949
|
+
const http = deps.fetch ?? fetch;
|
|
6950
|
+
const env = deps.env ?? process.env;
|
|
6951
|
+
return {
|
|
6952
|
+
unsigned: {
|
|
6953
|
+
summary: "Send the relay requests it must refuse: a GET (405), an unsigned POST (401), an unknown source (404).",
|
|
6954
|
+
writes: false,
|
|
6955
|
+
async run(probe) {
|
|
6956
|
+
const { host, source } = relayOf(deps.loader);
|
|
6957
|
+
const expect = async (label, want, path, init) => {
|
|
6958
|
+
const res = await http(`https://${host}/${path}`, init);
|
|
6959
|
+
probe.say({
|
|
6960
|
+
status: res.status === want ? "ok" : "fail",
|
|
6961
|
+
label,
|
|
6962
|
+
detail: res.status === want ? `${res.status}` : `got ${res.status}, wanted ${want}${res.status === 404 ? " (is the Worker deployed on this host?)" : ""}`
|
|
6963
|
+
});
|
|
6964
|
+
};
|
|
6965
|
+
await expect(`GET /${source}`, 405, source);
|
|
6966
|
+
await expect(`unsigned POST /${source}`, 401, source, {
|
|
6967
|
+
method: "POST",
|
|
6968
|
+
headers: { "content-type": "application/json" },
|
|
6969
|
+
body: "{}"
|
|
6970
|
+
});
|
|
6971
|
+
await expect("POST /no-such-source", 404, "no-such-source", {
|
|
6972
|
+
method: "POST",
|
|
6973
|
+
body: "{}"
|
|
6974
|
+
});
|
|
6975
|
+
}
|
|
6976
|
+
},
|
|
6977
|
+
bindings: {
|
|
6978
|
+
summary: "Show whether the Worker has the secret bindings it needs, by name (never the values).",
|
|
6979
|
+
writes: false,
|
|
6980
|
+
async run(probe) {
|
|
6981
|
+
const { script, source } = relayOf(deps.loader);
|
|
6982
|
+
const workers = deps.loader.has("workers") ? deps.loader.get("workers") : void 0;
|
|
6983
|
+
if (!workers?.secretNames) throw new Error("the `workers` provider cannot list a Worker's secrets");
|
|
6984
|
+
const have = new Set(await workers.secretNames(script));
|
|
6985
|
+
const need = [[relayWebhookBinding(source), "run `holocron notifications setup`"], [relaySecretBinding(source), "add it to the vault and run `holocron secrets sync`, or `notifications setup`"]];
|
|
6986
|
+
for (const [name, fix] of need) probe.say(have.has(name) ? {
|
|
6987
|
+
status: "ok",
|
|
6988
|
+
label: name,
|
|
6989
|
+
detail: `bound on ${script}`
|
|
6990
|
+
} : {
|
|
6991
|
+
status: "fail",
|
|
6992
|
+
label: name,
|
|
6993
|
+
detail: `missing on ${script}: ${fix}`
|
|
6994
|
+
});
|
|
6995
|
+
const extra = [...have].filter((n) => !need.some(([name]) => name === n));
|
|
6996
|
+
if (extra.length > 0) probe.say({
|
|
6997
|
+
status: "info",
|
|
6998
|
+
label: "other secrets",
|
|
6999
|
+
detail: extra.join(", ")
|
|
7000
|
+
});
|
|
7001
|
+
}
|
|
7002
|
+
},
|
|
7003
|
+
deliver: {
|
|
7004
|
+
summary: "Send the relay a correctly signed test alert, so a labelled embed lands in the errors channel. The message stays there.",
|
|
7005
|
+
writes: true,
|
|
7006
|
+
async run(probe) {
|
|
7007
|
+
const { host, source } = relayOf(deps.loader);
|
|
7008
|
+
if (source !== "sentry") throw new Error(`deliver knows how to sign a Sentry delivery, not a ${source} one`);
|
|
7009
|
+
const name = relaySecretBinding(source);
|
|
7010
|
+
if (probe.dryRun) {
|
|
7011
|
+
probe.say({
|
|
7012
|
+
status: "info",
|
|
7013
|
+
label: "would send a signed test alert to the relay"
|
|
7014
|
+
});
|
|
7015
|
+
return;
|
|
7016
|
+
}
|
|
7017
|
+
let secret = env[name];
|
|
7018
|
+
if (!secret && deps.loader.has("vault")) secret = await deps.loader.get("vault").read(name).catch(() => void 0);
|
|
7019
|
+
if (!secret) throw new Error(`no signing secret: set ${name} in the environment (for example \`doppler run -- holocron probe comlink deliver\`), or run this where the vault holds it`);
|
|
7020
|
+
probe.secret(secret);
|
|
7021
|
+
const body = testDelivery();
|
|
7022
|
+
const status = await probe.write("send a signed test alert to the relay", async () => {
|
|
7023
|
+
return (await http(`https://${host}/${source}`, {
|
|
7024
|
+
method: "POST",
|
|
7025
|
+
headers: {
|
|
7026
|
+
"content-type": "application/json",
|
|
7027
|
+
"sentry-hook-resource": "event_alert",
|
|
7028
|
+
"sentry-hook-signature": createHmac("sha256", secret).update(body).digest("hex")
|
|
7029
|
+
},
|
|
7030
|
+
body
|
|
7031
|
+
})).status;
|
|
7032
|
+
});
|
|
7033
|
+
probe.say(status === 202 ? {
|
|
7034
|
+
status: "ok",
|
|
7035
|
+
label: "the relay accepted it",
|
|
7036
|
+
detail: `look in #errors for "Holocron probe: Comlink delivery check"; delete the message by hand, a probe cannot`
|
|
7037
|
+
} : {
|
|
7038
|
+
status: "fail",
|
|
7039
|
+
label: `the relay answered ${status}, not 202`,
|
|
7040
|
+
detail: status === 401 ? "the signing secret does not match the Worker's" : status === 502 ? "the relay could not post to Discord" : "see the Worker's logs"
|
|
7041
|
+
});
|
|
7042
|
+
}
|
|
7043
|
+
}
|
|
7044
|
+
};
|
|
7045
|
+
}
|
|
7046
|
+
//#endregion
|
|
6916
7047
|
//#region src/commands/probe/core-probes.ts
|
|
6917
7048
|
/** The group of probes that belong to the CLI itself, not to a provider. */
|
|
6918
7049
|
const CORE_PROVIDER = "core";
|
|
6919
7050
|
/**
|
|
6920
|
-
* `core providers`: which
|
|
6921
|
-
*
|
|
7051
|
+
* `core providers`: which capabilities loaded and which did not, and why (a provider that fails to load, for a missing
|
|
7052
|
+
* token or option such as an account id, is skipped quietly by every other command); then each provider and the probes it
|
|
7053
|
+
* offers.
|
|
6922
7054
|
*/
|
|
6923
|
-
function coreProbes(loader) {
|
|
7055
|
+
function coreProbes(loader, builtIn = /* @__PURE__ */ new Map()) {
|
|
6924
7056
|
return { providers: {
|
|
6925
7057
|
summary: "Show which configured providers loaded, and why any did not.",
|
|
6926
7058
|
writes: false,
|
|
6927
7059
|
async run(ctx) {
|
|
6928
|
-
|
|
7060
|
+
ctx.say({
|
|
7061
|
+
status: "heading",
|
|
7062
|
+
label: "Capabilities"
|
|
7063
|
+
});
|
|
6929
7064
|
for (const key of loader.loadedKeys()) ctx.say({
|
|
6930
7065
|
status: "ok",
|
|
6931
7066
|
label: key
|
|
6932
7067
|
});
|
|
6933
|
-
for (const f of
|
|
7068
|
+
for (const f of loader.loadFailures()) ctx.say({
|
|
6934
7069
|
status: "fail",
|
|
6935
7070
|
label: `${f.key} (${f.provider})`,
|
|
6936
7071
|
detail: describeProviderError(f.error)
|
|
6937
7072
|
});
|
|
6938
|
-
const
|
|
7073
|
+
const offered = new Map(loader.probes());
|
|
7074
|
+
const names = /* @__PURE__ */ new Set();
|
|
7075
|
+
for (const key of loader.loadedKeys()) {
|
|
7076
|
+
const impl = loader.get(key);
|
|
7077
|
+
for (const one of Array.isArray(impl) ? impl : [impl]) if (one.providerName) names.add(one.providerName);
|
|
7078
|
+
}
|
|
7079
|
+
for (const name of offered.keys()) names.add(name);
|
|
6939
7080
|
ctx.say({
|
|
7081
|
+
status: "heading",
|
|
7082
|
+
label: "Providers"
|
|
7083
|
+
});
|
|
7084
|
+
for (const name of [...names].sort()) {
|
|
7085
|
+
const own = offered.get(name);
|
|
7086
|
+
ctx.say({
|
|
7087
|
+
status: "info",
|
|
7088
|
+
label: name,
|
|
7089
|
+
detail: own ? Object.keys(own).sort().join(", ") : "no probes yet"
|
|
7090
|
+
});
|
|
7091
|
+
}
|
|
7092
|
+
for (const [name, own] of [...builtIn].sort(([a], [b]) => a.localeCompare(b))) ctx.say({
|
|
6940
7093
|
status: "info",
|
|
6941
|
-
label:
|
|
6942
|
-
detail:
|
|
7094
|
+
label: `${name} (built in)`,
|
|
7095
|
+
detail: Object.keys(own).sort().join(", ")
|
|
6943
7096
|
});
|
|
6944
7097
|
}
|
|
6945
7098
|
} };
|
|
@@ -7027,7 +7180,8 @@ async function runProbe(input) {
|
|
|
7027
7180
|
...row.detail ? { detail: scrub(sanitizeDetail(row.detail)) } : {}
|
|
7028
7181
|
};
|
|
7029
7182
|
rows.push(clean);
|
|
7030
|
-
|
|
7183
|
+
if (clean.status === "heading") print(`\n ${style.header(clean.label)}`);
|
|
7184
|
+
else print(statusRow(clean.status === "info" ? "skip" : clean.status, [clean.label, clean.detail ?? ""]));
|
|
7031
7185
|
};
|
|
7032
7186
|
if (input.probe.writes && !input.dryRun && !input.yes) {
|
|
7033
7187
|
if (!(input.interactive ?? Boolean(process.stdin.isTTY))) throw new NonInteractiveError(`\`${input.name}\` changes things on ${input.provider} (${input.probe.summary}); pass --yes to run it without asking`);
|
|
@@ -7124,7 +7278,9 @@ async function runProbeCommand(input) {
|
|
|
7124
7278
|
const loader = input.loader ?? new PluginLoader(input.loaded.resolved, input.context);
|
|
7125
7279
|
await loader.load();
|
|
7126
7280
|
const groups = new Map(loader.probes());
|
|
7127
|
-
|
|
7281
|
+
const comlink = comlinkProbes({ loader });
|
|
7282
|
+
groups.set(CORE_PROVIDER, coreProbes(loader, /* @__PURE__ */ new Map([[COMLINK_PROVIDER, comlink]])));
|
|
7283
|
+
groups.set(COMLINK_PROVIDER, comlink);
|
|
7128
7284
|
if (!input.provider) {
|
|
7129
7285
|
if (input.pick) await input.pick(groups);
|
|
7130
7286
|
else for (const line of listProbes(groups)) print(line);
|
|
@@ -12203,7 +12359,7 @@ const COMMAND_REGISTRY = [
|
|
|
12203
12359
|
name: "probe",
|
|
12204
12360
|
description: "Poke a live provider on purpose: inspect it, or run a proof that cleans up after itself",
|
|
12205
12361
|
positionals: [],
|
|
12206
|
-
|
|
12362
|
+
opensMenu: true
|
|
12207
12363
|
},
|
|
12208
12364
|
{
|
|
12209
12365
|
name: "repo setup",
|
|
@@ -12592,7 +12748,7 @@ function menuItems(entries, path = []) {
|
|
|
12592
12748
|
const self = family.find((e) => e.name === full);
|
|
12593
12749
|
const nested = family.filter((e) => e.name !== full);
|
|
12594
12750
|
if (nested.length === 0 && self) items.push({
|
|
12595
|
-
name: word,
|
|
12751
|
+
name: self.opensMenu ? `${word} ›` : word,
|
|
12596
12752
|
value: full,
|
|
12597
12753
|
description: self.description,
|
|
12598
12754
|
haystack: haystackOf([self])
|