@theholocron/cli 5.0.0-alpha.600 → 5.0.0-alpha.602
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
CHANGED
|
@@ -5655,7 +5655,7 @@ async function provisionChannel(deps, spec) {
|
|
|
5655
5655
|
if (dryRun) {
|
|
5656
5656
|
print(` ${style.skip(`would ensure channel ${spec.name}${where}`)}`);
|
|
5657
5657
|
if (tally) tally.skip += webhookCfg ? 2 : 1;
|
|
5658
|
-
if (webhookCfg) print(` ${style.skip(`would ensure webhook ${webhookName} and store its URL in ${secretName}`)}`);
|
|
5658
|
+
if (webhookCfg) print(` ${style.skip(`would ensure webhook ${webhookName} and store its URL in ${secretName}${webhookCfg.handOff ? " and the private credentials file" : ""}`)}`);
|
|
5659
5659
|
if (feed) {
|
|
5660
5660
|
print(` ${style.skip(`would ensure webhook ${feed.webhook} and alert channel ${feed.name} (monitoring)`)}`);
|
|
5661
5661
|
if (tally) tally.skip += 2;
|
|
@@ -5711,19 +5711,30 @@ async function provisionChannel(deps, spec) {
|
|
|
5711
5711
|
try {
|
|
5712
5712
|
await secrets.setSecret(scope, secretName, hook.url);
|
|
5713
5713
|
} catch (err) {
|
|
5714
|
-
|
|
5714
|
+
const stored = `webhook ${webhookName} was ${hook.created ? "created" : "found"} but storing its URL in ${secretName} failed (${describeError(err)})`;
|
|
5715
|
+
if (hook.created && hook.id && notifications.deleteWebhook) {
|
|
5716
|
+
try {
|
|
5717
|
+
await notifications.deleteWebhook(hook.id);
|
|
5718
|
+
} catch (deleteErr) {
|
|
5719
|
+
throw new Error(`${stored}; deleting the webhook it created failed too (${describeError(deleteErr)}) — webhook id ${hook.id} is left in the provider, delete it and re-run`, { cause: deleteErr });
|
|
5720
|
+
}
|
|
5721
|
+
throw new Error(`${stored} — the webhook it created was deleted, so re-run once that is fixed`, { cause: err });
|
|
5722
|
+
}
|
|
5723
|
+
throw new Error(`${stored} — delete the webhook in the provider and re-run to get a fresh URL`, { cause: err });
|
|
5715
5724
|
}
|
|
5716
5725
|
print(` ${style.success(`${hook.created ? "created" : "found "} webhook ${webhookName}; URL stored in ${secretName}`)}`);
|
|
5717
5726
|
if (tally) tally.ok++;
|
|
5727
|
+
if (webhookCfg.handOff) deps.onHandOffWebhook?.(secretName, hook.url);
|
|
5718
5728
|
outcome.webhook = {
|
|
5719
5729
|
name: webhookName,
|
|
5720
5730
|
created: hook.created,
|
|
5721
5731
|
secret: secretName,
|
|
5722
5732
|
stored: true,
|
|
5733
|
+
...webhookCfg.handOff ? { handOff: true } : {},
|
|
5723
5734
|
...avatarSet ? { updated: ["avatar"] } : {}
|
|
5724
5735
|
};
|
|
5725
5736
|
} else {
|
|
5726
|
-
const note = `webhook ${webhookName} already exists and its URL cannot be read back — delete it in the provider and re-run, or set ${secretName} yourself
|
|
5737
|
+
const note = `webhook ${webhookName} already exists and its URL cannot be read back — delete it in the provider and re-run, or set ${secretName} yourself` + (webhookCfg.handOff ? " (nothing to hand off: the bot did not make it)" : "");
|
|
5727
5738
|
print(` ${style.warn(note)}`);
|
|
5728
5739
|
outcome.webhook = {
|
|
5729
5740
|
name: webhookName,
|
|
@@ -16651,6 +16662,118 @@ async function resolvePinnedFiles(layout, repoRoot, read = readRepoText) {
|
|
|
16651
16662
|
pinned: resolved
|
|
16652
16663
|
} };
|
|
16653
16664
|
}
|
|
16665
|
+
// src/private-dir/ignore-advice/ignore-advice.ts
|
|
16666
|
+
/** The line that says how to fix a credentials path the version control ignore rules do not cover. */
|
|
16667
|
+
function ignoreAdvice(isDefault, choose) {
|
|
16668
|
+
return isDefault ? "the private directory's ignore rule is missing: run `holocron sync` to add it" : `add it to .gitignore, or ${choose}`;
|
|
16669
|
+
}
|
|
16670
|
+
// src/private-dir/private-dir.ts
|
|
16671
|
+
/** The directory, relative to the repository root, for files that hold secrets and must never be committed. */
|
|
16672
|
+
const PRIVATE_DIR = ".holocron/.private";
|
|
16673
|
+
/** The file `export tokens` and `new github-app` write by default, relative to the repository root. */
|
|
16674
|
+
const PRIVATE_CREDENTIALS_FILE = `${PRIVATE_DIR}/.credentials`;
|
|
16675
|
+
/** The tracked file that keeps the otherwise ignored directory in the checkout. */
|
|
16676
|
+
const PRIVATE_KEEP_FILE = `${PRIVATE_DIR}/.gitkeep`;
|
|
16677
|
+
/**
|
|
16678
|
+
* The managed block `setup` and `sync` keep in `.gitignore`: everything in the private directory is ignored
|
|
16679
|
+
* except the `.gitkeep`. The start marker must not be a substring of the end marker.
|
|
16680
|
+
*/
|
|
16681
|
+
const PRIVATE_IGNORE_BLOCK = {
|
|
16682
|
+
start: "# managed by holocron setup — private directory",
|
|
16683
|
+
end: "# end managed by holocron setup — private directory",
|
|
16684
|
+
lines: [`${PRIVATE_DIR}/*`, `!${PRIVATE_KEEP_FILE}`]
|
|
16685
|
+
};
|
|
16686
|
+
// src/private-dir/resolve-credentials-file/resolve-credentials-file.ts
|
|
16687
|
+
/**
|
|
16688
|
+
* The credentials file for a command: `file` (relative to `base`) when given, else `.holocron/.private/.credentials`
|
|
16689
|
+
* under `base`. The default's directory is created when missing (owner-only), because the ignore check can only ask
|
|
16690
|
+
* about a path whose directory exists and the file cannot be written without it.
|
|
16691
|
+
*/
|
|
16692
|
+
function resolveCredentialsFile(base, file, makeDir = (dir) => void mkdirSync(dir, {
|
|
16693
|
+
recursive: true,
|
|
16694
|
+
mode: 448
|
|
16695
|
+
})) {
|
|
16696
|
+
if (file) return {
|
|
16697
|
+
path: resolve(base, file),
|
|
16698
|
+
isDefault: false
|
|
16699
|
+
};
|
|
16700
|
+
const path = resolve(base, PRIVATE_CREDENTIALS_FILE);
|
|
16701
|
+
makeDir(dirname(path));
|
|
16702
|
+
return {
|
|
16703
|
+
path,
|
|
16704
|
+
isDefault: true
|
|
16705
|
+
};
|
|
16706
|
+
}
|
|
16707
|
+
// src/commands/webhook-handoff/webhook-handoff.ts
|
|
16708
|
+
/**
|
|
16709
|
+
* Hand the webhook URLs of channels that ask for it (`webhook: { handOff: true }`) to 1Password. A webhook URL is a
|
|
16710
|
+
* credential (it lets anyone post as the channel) and the CLI cannot write to a 1Password Environment, so the hand-off
|
|
16711
|
+
* is the private import file the heartbeats use: `.holocron/.private/.credentials`, mode 0600, never overwritten,
|
|
16712
|
+
* deleted once the import is done. The lines go only to that file: nothing here prints, logs or returns a URL.
|
|
16713
|
+
*/
|
|
16714
|
+
async function handOffWebhooks(input) {
|
|
16715
|
+
const { print } = input;
|
|
16716
|
+
const fail = (reason, ...message) => {
|
|
16717
|
+
for (const line of message) print(line);
|
|
16718
|
+
return {
|
|
16719
|
+
status: "fail",
|
|
16720
|
+
written: [],
|
|
16721
|
+
reason
|
|
16722
|
+
};
|
|
16723
|
+
};
|
|
16724
|
+
if (input.webhooks.length === 0) return {
|
|
16725
|
+
status: "skip",
|
|
16726
|
+
written: [],
|
|
16727
|
+
reason: "no webhook to hand over"
|
|
16728
|
+
};
|
|
16729
|
+
const lines = /* @__PURE__ */ new Map();
|
|
16730
|
+
for (const hook of input.webhooks) {
|
|
16731
|
+
if (lines.has(hook.secret)) return fail("collision", `two channels hand over ${hook.secret}: rename one`);
|
|
16732
|
+
const line = dotenvLine(hook.secret, hook.url);
|
|
16733
|
+
if (line === null) return fail("unsupported", `${hook.secret}: its address is not one a dotenv file can carry`);
|
|
16734
|
+
lines.set(hook.secret, line);
|
|
16735
|
+
}
|
|
16736
|
+
if ((input.platform ?? process.platform) === "win32") return fail("windows", "cannot make the file private on Windows: its mode bits are not enforced");
|
|
16737
|
+
const target = resolveCredentialsFile(input.base, void 0, input.makeDir);
|
|
16738
|
+
const file = target.path;
|
|
16739
|
+
const git = (input.isIgnored ?? isGitIgnored)(file);
|
|
16740
|
+
if (git === "tracked" || git === "unknown") return fail("not-ignored", git === "tracked" ? `refusing to write webhook URLs to ${file}: git does not ignore it, so it could be committed` : `refusing to write webhook URLs to ${file}: git could not say whether it ignores it`, ignoreAdvice(target.isDefault, "choose a path outside the repository"));
|
|
16741
|
+
const names = [...lines.keys()].sort();
|
|
16742
|
+
let identity;
|
|
16743
|
+
try {
|
|
16744
|
+
identity = (input.writeFile ?? writeCredentialsFile)(file, `${names.map((n) => lines.get(n)).join("\n")}\n`, false);
|
|
16745
|
+
} catch (err) {
|
|
16746
|
+
return fail("write", `could not write ${file}: ${errorMessage(err)}`, "an existing file is never overwritten: finish importing it, delete it, then run setup again");
|
|
16747
|
+
}
|
|
16748
|
+
print(`wrote ${names.length} webhook URL(s) for import: ${names.join(", ")}`);
|
|
16749
|
+
print("import them into the 1Password Environment of the layer that posts to the channel (for example `agent`)");
|
|
16750
|
+
return await finishCredentialsFile({
|
|
16751
|
+
path: file,
|
|
16752
|
+
identity,
|
|
16753
|
+
print,
|
|
16754
|
+
holds: "the channels' webhook URLs",
|
|
16755
|
+
importHint: "import it in the 1Password app: Developer, View Environments, the layer's Environment, Import .env file",
|
|
16756
|
+
keep: input.keep,
|
|
16757
|
+
interactive: input.interactive,
|
|
16758
|
+
shred: input.shred,
|
|
16759
|
+
waitForImport: input.waitForImport
|
|
16760
|
+
}) ? {
|
|
16761
|
+
status: "ok",
|
|
16762
|
+
written: names
|
|
16763
|
+
} : {
|
|
16764
|
+
status: "fail",
|
|
16765
|
+
written: names,
|
|
16766
|
+
reason: "file-left"
|
|
16767
|
+
};
|
|
16768
|
+
}
|
|
16769
|
+
// src/commands/webhook-handoff-problem/webhook-handoff-problem.ts
|
|
16770
|
+
/** The first reason a channel's `webhook.handOff` cannot work (it is not a boolean), or undefined. */
|
|
16771
|
+
function webhookHandOffProblem(layout) {
|
|
16772
|
+
for (const channel of (layout.categories ?? []).flatMap((c) => c.channels ?? [])) {
|
|
16773
|
+
const hand = typeof channel.webhook === "object" && channel.webhook ? channel.webhook.handOff : void 0;
|
|
16774
|
+
if (hand !== void 0 && typeof hand !== "boolean") return `channel \`${channel.name}\`: \`webhook.handOff\` must be true or false, not ${String(hand)}`;
|
|
16775
|
+
}
|
|
16776
|
+
}
|
|
16654
16777
|
// src/commands/notifications-setup/picture-sources/picture-sources.ts
|
|
16655
16778
|
/**
|
|
16656
16779
|
* The sources a picture names, in the order to try them: a single path or URL, or the `url` and then the `image`.
|
|
@@ -17117,6 +17240,8 @@ async function runNotificationsSetup(input$1) {
|
|
|
17117
17240
|
if (accessProblem) return refuse(accessProblem);
|
|
17118
17241
|
const forumProblem = forumLayoutProblem(layout);
|
|
17119
17242
|
if (forumProblem) return refuse(forumProblem);
|
|
17243
|
+
const handOffProblem = webhookHandOffProblem(layout);
|
|
17244
|
+
if (handOffProblem) return refuse(handOffProblem);
|
|
17120
17245
|
const serverProblem = serverLayoutProblem(layout);
|
|
17121
17246
|
if (serverProblem) return refuse(serverProblem);
|
|
17122
17247
|
const emojiImages = /* @__PURE__ */ new Map();
|
|
@@ -17173,6 +17298,7 @@ async function runNotificationsSetup(input$1) {
|
|
|
17173
17298
|
}
|
|
17174
17299
|
}
|
|
17175
17300
|
const relayWebhooks = /* @__PURE__ */ new Map();
|
|
17301
|
+
const handOffs = [];
|
|
17176
17302
|
const tally = {
|
|
17177
17303
|
ok: 0,
|
|
17178
17304
|
skip: 0
|
|
@@ -17285,6 +17411,7 @@ async function runNotificationsSetup(input$1) {
|
|
|
17285
17411
|
const webhook = own ? {
|
|
17286
17412
|
...own.name ? { name: own.name } : {},
|
|
17287
17413
|
...own.secret ? { secret: own.secret } : {},
|
|
17414
|
+
...own.handOff ? { handOff: true } : {},
|
|
17288
17415
|
...sources.length > 0 ? { avatar: avatars.get(JSON.stringify(sources)) } : {}
|
|
17289
17416
|
} : void 0;
|
|
17290
17417
|
const outcome = await provisionChannel({
|
|
@@ -17292,6 +17419,10 @@ async function runNotificationsSetup(input$1) {
|
|
|
17292
17419
|
...secrets ? { secrets } : {},
|
|
17293
17420
|
...monitoring ? { monitoring } : {},
|
|
17294
17421
|
onRelayWebhook: (url, source) => void relayWebhooks.set(source ?? errors.providerName, url),
|
|
17422
|
+
onHandOffWebhook: (secret, url) => void handOffs.push({
|
|
17423
|
+
secret,
|
|
17424
|
+
url
|
|
17425
|
+
}),
|
|
17295
17426
|
scope: scope ?? { kind: "repo" },
|
|
17296
17427
|
dryRun,
|
|
17297
17428
|
print,
|
|
@@ -17329,6 +17460,27 @@ async function runNotificationsSetup(input$1) {
|
|
|
17329
17460
|
});
|
|
17330
17461
|
});
|
|
17331
17462
|
}
|
|
17463
|
+
if (handOffs.length > 0) {
|
|
17464
|
+
const step = "webhook URLs for import";
|
|
17465
|
+
const handed = await handOffWebhooks({
|
|
17466
|
+
webhooks: handOffs,
|
|
17467
|
+
base: dirname(input$1.loaded.filepath),
|
|
17468
|
+
print: (line) => print(` ${line}`),
|
|
17469
|
+
interactive: input$1.interactive ?? Boolean(process.stdin.isTTY),
|
|
17470
|
+
...input$1.handOffWebhooks
|
|
17471
|
+
});
|
|
17472
|
+
if (handed.status === "ok") {
|
|
17473
|
+
print(` ${style.success(`${step}: ${handed.written.join(", ")} written for import, not printed`)}`);
|
|
17474
|
+
made(true);
|
|
17475
|
+
} else {
|
|
17476
|
+
const message = `${handed.written.length > 0 ? `${handed.written.join(", ")}: ` : ""}${handed.reason}`;
|
|
17477
|
+
print(` ${style.fail(`${step}: ${message}`)}`);
|
|
17478
|
+
report.failures.push({
|
|
17479
|
+
step,
|
|
17480
|
+
message
|
|
17481
|
+
});
|
|
17482
|
+
}
|
|
17483
|
+
}
|
|
17332
17484
|
if (workers && dns && (wantsErrors || wantsAnyRelay(layout))) {
|
|
17333
17485
|
print(`\n${style.header("Relay")}`);
|
|
17334
17486
|
const tracker = layout.relay.errors;
|
|
@@ -24011,48 +24163,6 @@ const doctorCommand = {
|
|
|
24011
24163
|
})).summary.fail > 0) process.exitCode = 1;
|
|
24012
24164
|
}
|
|
24013
24165
|
};
|
|
24014
|
-
// src/private-dir/ignore-advice/ignore-advice.ts
|
|
24015
|
-
/** The line that says how to fix a credentials path the version control ignore rules do not cover. */
|
|
24016
|
-
function ignoreAdvice(isDefault, choose) {
|
|
24017
|
-
return isDefault ? "the private directory's ignore rule is missing: run `holocron sync` to add it" : `add it to .gitignore, or ${choose}`;
|
|
24018
|
-
}
|
|
24019
|
-
// src/private-dir/private-dir.ts
|
|
24020
|
-
/** The directory, relative to the repository root, for files that hold secrets and must never be committed. */
|
|
24021
|
-
const PRIVATE_DIR = ".holocron/.private";
|
|
24022
|
-
/** The file `export tokens` and `new github-app` write by default, relative to the repository root. */
|
|
24023
|
-
const PRIVATE_CREDENTIALS_FILE = `${PRIVATE_DIR}/.credentials`;
|
|
24024
|
-
/** The tracked file that keeps the otherwise ignored directory in the checkout. */
|
|
24025
|
-
const PRIVATE_KEEP_FILE = `${PRIVATE_DIR}/.gitkeep`;
|
|
24026
|
-
/**
|
|
24027
|
-
* The managed block `setup` and `sync` keep in `.gitignore`: everything in the private directory is ignored
|
|
24028
|
-
* except the `.gitkeep`. The start marker must not be a substring of the end marker.
|
|
24029
|
-
*/
|
|
24030
|
-
const PRIVATE_IGNORE_BLOCK = {
|
|
24031
|
-
start: "# managed by holocron setup — private directory",
|
|
24032
|
-
end: "# end managed by holocron setup — private directory",
|
|
24033
|
-
lines: [`${PRIVATE_DIR}/*`, `!${PRIVATE_KEEP_FILE}`]
|
|
24034
|
-
};
|
|
24035
|
-
// src/private-dir/resolve-credentials-file/resolve-credentials-file.ts
|
|
24036
|
-
/**
|
|
24037
|
-
* The credentials file for a command: `file` (relative to `base`) when given, else `.holocron/.private/.credentials`
|
|
24038
|
-
* under `base`. The default's directory is created when missing (owner-only), because the ignore check can only ask
|
|
24039
|
-
* about a path whose directory exists and the file cannot be written without it.
|
|
24040
|
-
*/
|
|
24041
|
-
function resolveCredentialsFile(base, file, makeDir = (dir) => void mkdirSync(dir, {
|
|
24042
|
-
recursive: true,
|
|
24043
|
-
mode: 448
|
|
24044
|
-
})) {
|
|
24045
|
-
if (file) return {
|
|
24046
|
-
path: resolve(base, file),
|
|
24047
|
-
isDefault: false
|
|
24048
|
-
};
|
|
24049
|
-
const path = resolve(base, PRIVATE_CREDENTIALS_FILE);
|
|
24050
|
-
makeDir(dirname(path));
|
|
24051
|
-
return {
|
|
24052
|
-
path,
|
|
24053
|
-
isDefault: true
|
|
24054
|
-
};
|
|
24055
|
-
}
|
|
24056
24166
|
// src/commands/auth-export/auth-export.ts
|
|
24057
24167
|
/**
|
|
24058
24168
|
* `holocron export tokens` — print the tokens a configured plugin takes as `NAME=value` lines, to move them into a
|