@theholocron/cli 5.0.0-alpha.600 → 5.0.0-alpha.601

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;
@@ -5715,15 +5715,17 @@ async function provisionChannel(deps, spec) {
5715
5715
  }
5716
5716
  print(` ${style.success(`${hook.created ? "created" : "found "} webhook ${webhookName}; URL stored in ${secretName}`)}`);
5717
5717
  if (tally) tally.ok++;
5718
+ if (webhookCfg.handOff) deps.onHandOffWebhook?.(secretName, hook.url);
5718
5719
  outcome.webhook = {
5719
5720
  name: webhookName,
5720
5721
  created: hook.created,
5721
5722
  secret: secretName,
5722
5723
  stored: true,
5724
+ ...webhookCfg.handOff ? { handOff: true } : {},
5723
5725
  ...avatarSet ? { updated: ["avatar"] } : {}
5724
5726
  };
5725
5727
  } 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`;
5728
+ 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
5729
  print(` ${style.warn(note)}`);
5728
5730
  outcome.webhook = {
5729
5731
  name: webhookName,
@@ -16651,6 +16653,118 @@ async function resolvePinnedFiles(layout, repoRoot, read = readRepoText) {
16651
16653
  pinned: resolved
16652
16654
  } };
16653
16655
  }
16656
+ // src/private-dir/ignore-advice/ignore-advice.ts
16657
+ /** The line that says how to fix a credentials path the version control ignore rules do not cover. */
16658
+ function ignoreAdvice(isDefault, choose) {
16659
+ return isDefault ? "the private directory's ignore rule is missing: run `holocron sync` to add it" : `add it to .gitignore, or ${choose}`;
16660
+ }
16661
+ // src/private-dir/private-dir.ts
16662
+ /** The directory, relative to the repository root, for files that hold secrets and must never be committed. */
16663
+ const PRIVATE_DIR = ".holocron/.private";
16664
+ /** The file `export tokens` and `new github-app` write by default, relative to the repository root. */
16665
+ const PRIVATE_CREDENTIALS_FILE = `${PRIVATE_DIR}/.credentials`;
16666
+ /** The tracked file that keeps the otherwise ignored directory in the checkout. */
16667
+ const PRIVATE_KEEP_FILE = `${PRIVATE_DIR}/.gitkeep`;
16668
+ /**
16669
+ * The managed block `setup` and `sync` keep in `.gitignore`: everything in the private directory is ignored
16670
+ * except the `.gitkeep`. The start marker must not be a substring of the end marker.
16671
+ */
16672
+ const PRIVATE_IGNORE_BLOCK = {
16673
+ start: "# managed by holocron setup — private directory",
16674
+ end: "# end managed by holocron setup — private directory",
16675
+ lines: [`${PRIVATE_DIR}/*`, `!${PRIVATE_KEEP_FILE}`]
16676
+ };
16677
+ // src/private-dir/resolve-credentials-file/resolve-credentials-file.ts
16678
+ /**
16679
+ * The credentials file for a command: `file` (relative to `base`) when given, else `.holocron/.private/.credentials`
16680
+ * under `base`. The default's directory is created when missing (owner-only), because the ignore check can only ask
16681
+ * about a path whose directory exists and the file cannot be written without it.
16682
+ */
16683
+ function resolveCredentialsFile(base, file, makeDir = (dir) => void mkdirSync(dir, {
16684
+ recursive: true,
16685
+ mode: 448
16686
+ })) {
16687
+ if (file) return {
16688
+ path: resolve(base, file),
16689
+ isDefault: false
16690
+ };
16691
+ const path = resolve(base, PRIVATE_CREDENTIALS_FILE);
16692
+ makeDir(dirname(path));
16693
+ return {
16694
+ path,
16695
+ isDefault: true
16696
+ };
16697
+ }
16698
+ // src/commands/webhook-handoff/webhook-handoff.ts
16699
+ /**
16700
+ * Hand the webhook URLs of channels that ask for it (`webhook: { handOff: true }`) to 1Password. A webhook URL is a
16701
+ * credential (it lets anyone post as the channel) and the CLI cannot write to a 1Password Environment, so the hand-off
16702
+ * is the private import file the heartbeats use: `.holocron/.private/.credentials`, mode 0600, never overwritten,
16703
+ * deleted once the import is done. The lines go only to that file: nothing here prints, logs or returns a URL.
16704
+ */
16705
+ async function handOffWebhooks(input) {
16706
+ const { print } = input;
16707
+ const fail = (reason, ...message) => {
16708
+ for (const line of message) print(line);
16709
+ return {
16710
+ status: "fail",
16711
+ written: [],
16712
+ reason
16713
+ };
16714
+ };
16715
+ if (input.webhooks.length === 0) return {
16716
+ status: "skip",
16717
+ written: [],
16718
+ reason: "no webhook to hand over"
16719
+ };
16720
+ const lines = /* @__PURE__ */ new Map();
16721
+ for (const hook of input.webhooks) {
16722
+ if (lines.has(hook.secret)) return fail("collision", `two channels hand over ${hook.secret}: rename one`);
16723
+ const line = dotenvLine(hook.secret, hook.url);
16724
+ if (line === null) return fail("unsupported", `${hook.secret}: its address is not one a dotenv file can carry`);
16725
+ lines.set(hook.secret, line);
16726
+ }
16727
+ if ((input.platform ?? process.platform) === "win32") return fail("windows", "cannot make the file private on Windows: its mode bits are not enforced");
16728
+ const target = resolveCredentialsFile(input.base, void 0, input.makeDir);
16729
+ const file = target.path;
16730
+ const git = (input.isIgnored ?? isGitIgnored)(file);
16731
+ 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"));
16732
+ const names = [...lines.keys()].sort();
16733
+ let identity;
16734
+ try {
16735
+ identity = (input.writeFile ?? writeCredentialsFile)(file, `${names.map((n) => lines.get(n)).join("\n")}\n`, false);
16736
+ } catch (err) {
16737
+ return fail("write", `could not write ${file}: ${errorMessage(err)}`, "an existing file is never overwritten: finish importing it, delete it, then run setup again");
16738
+ }
16739
+ print(`wrote ${names.length} webhook URL(s) for import: ${names.join(", ")}`);
16740
+ print("import them into the 1Password Environment of the layer that posts to the channel (for example `agent`)");
16741
+ return await finishCredentialsFile({
16742
+ path: file,
16743
+ identity,
16744
+ print,
16745
+ holds: "the channels' webhook URLs",
16746
+ importHint: "import it in the 1Password app: Developer, View Environments, the layer's Environment, Import .env file",
16747
+ keep: input.keep,
16748
+ interactive: input.interactive,
16749
+ shred: input.shred,
16750
+ waitForImport: input.waitForImport
16751
+ }) ? {
16752
+ status: "ok",
16753
+ written: names
16754
+ } : {
16755
+ status: "fail",
16756
+ written: names,
16757
+ reason: "file-left"
16758
+ };
16759
+ }
16760
+ // src/commands/webhook-handoff-problem/webhook-handoff-problem.ts
16761
+ /** The first reason a channel's `webhook.handOff` cannot work (it is not a boolean), or undefined. */
16762
+ function webhookHandOffProblem(layout) {
16763
+ for (const channel of (layout.categories ?? []).flatMap((c) => c.channels ?? [])) {
16764
+ const hand = typeof channel.webhook === "object" && channel.webhook ? channel.webhook.handOff : void 0;
16765
+ if (hand !== void 0 && typeof hand !== "boolean") return `channel \`${channel.name}\`: \`webhook.handOff\` must be true or false, not ${String(hand)}`;
16766
+ }
16767
+ }
16654
16768
  // src/commands/notifications-setup/picture-sources/picture-sources.ts
16655
16769
  /**
16656
16770
  * 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 +17231,8 @@ async function runNotificationsSetup(input$1) {
17117
17231
  if (accessProblem) return refuse(accessProblem);
17118
17232
  const forumProblem = forumLayoutProblem(layout);
17119
17233
  if (forumProblem) return refuse(forumProblem);
17234
+ const handOffProblem = webhookHandOffProblem(layout);
17235
+ if (handOffProblem) return refuse(handOffProblem);
17120
17236
  const serverProblem = serverLayoutProblem(layout);
17121
17237
  if (serverProblem) return refuse(serverProblem);
17122
17238
  const emojiImages = /* @__PURE__ */ new Map();
@@ -17173,6 +17289,7 @@ async function runNotificationsSetup(input$1) {
17173
17289
  }
17174
17290
  }
17175
17291
  const relayWebhooks = /* @__PURE__ */ new Map();
17292
+ const handOffs = [];
17176
17293
  const tally = {
17177
17294
  ok: 0,
17178
17295
  skip: 0
@@ -17285,6 +17402,7 @@ async function runNotificationsSetup(input$1) {
17285
17402
  const webhook = own ? {
17286
17403
  ...own.name ? { name: own.name } : {},
17287
17404
  ...own.secret ? { secret: own.secret } : {},
17405
+ ...own.handOff ? { handOff: true } : {},
17288
17406
  ...sources.length > 0 ? { avatar: avatars.get(JSON.stringify(sources)) } : {}
17289
17407
  } : void 0;
17290
17408
  const outcome = await provisionChannel({
@@ -17292,6 +17410,10 @@ async function runNotificationsSetup(input$1) {
17292
17410
  ...secrets ? { secrets } : {},
17293
17411
  ...monitoring ? { monitoring } : {},
17294
17412
  onRelayWebhook: (url, source) => void relayWebhooks.set(source ?? errors.providerName, url),
17413
+ onHandOffWebhook: (secret, url) => void handOffs.push({
17414
+ secret,
17415
+ url
17416
+ }),
17295
17417
  scope: scope ?? { kind: "repo" },
17296
17418
  dryRun,
17297
17419
  print,
@@ -17329,6 +17451,27 @@ async function runNotificationsSetup(input$1) {
17329
17451
  });
17330
17452
  });
17331
17453
  }
17454
+ if (handOffs.length > 0) {
17455
+ const step = "webhook URLs for import";
17456
+ const handed = await handOffWebhooks({
17457
+ webhooks: handOffs,
17458
+ base: dirname(input$1.loaded.filepath),
17459
+ print: (line) => print(` ${line}`),
17460
+ interactive: input$1.interactive ?? Boolean(process.stdin.isTTY),
17461
+ ...input$1.handOffWebhooks
17462
+ });
17463
+ if (handed.status === "ok") {
17464
+ print(` ${style.success(`${step}: ${handed.written.join(", ")} written for import, not printed`)}`);
17465
+ made(true);
17466
+ } else {
17467
+ const message = `${handed.written.length > 0 ? `${handed.written.join(", ")}: ` : ""}${handed.reason}`;
17468
+ print(` ${style.fail(`${step}: ${message}`)}`);
17469
+ report.failures.push({
17470
+ step,
17471
+ message
17472
+ });
17473
+ }
17474
+ }
17332
17475
  if (workers && dns && (wantsErrors || wantsAnyRelay(layout))) {
17333
17476
  print(`\n${style.header("Relay")}`);
17334
17477
  const tracker = layout.relay.errors;
@@ -24011,48 +24154,6 @@ const doctorCommand = {
24011
24154
  })).summary.fail > 0) process.exitCode = 1;
24012
24155
  }
24013
24156
  };
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
24157
  // src/commands/auth-export/auth-export.ts
24057
24158
  /**
24058
24159
  * `holocron export tokens` — print the tokens a configured plugin takes as `NAME=value` lines, to move them into a