@theholocron/cli 5.0.0-alpha.394 → 5.0.0-alpha.395

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
@@ -35,8 +35,8 @@ import { access, copyFile, lstat, mkdir, open, readFile, readdir, realpath, rena
35
35
  import { createHash, createHmac, randomBytes, randomUUID } from "node:crypto";
36
36
  import { createGitHubClient, getApp, listAppInstallations } from "@theholocron/github-client";
37
37
  import { createServer } from "node:http";
38
- import { moveMajorTag } from "@theholocron/kyber/git";
39
38
  import { ADR_DIR, ADR_STATUSES, CLOSED_STATUSES, SPEC_DIRS, SPEC_STATUSES, WITHDRAWN_STATE, assignSpecIds, checkSpecs, classifySpecPath, discussionBody, discussionIdLine, discussionPrLine, discussionTitle, evaluateDocsPresence, isAddedDocComment, isFeat, packageOf, parseFrontmatter, parseSkipDocs, reconcileSpecStatus, specSummary, specTitle, updateFrontmatter } from "@theholocron/astromech/repo-validation";
39
+ import { moveMajorTag } from "@theholocron/kyber/git";
40
40
  import { loadConfigPath } from "@theholocron/datapad";
41
41
  import { fetchLatestFromNpm, runUpgradeNode } from "@theholocron/astromech/upgrade";
42
42
  import { lintCommitMsgFile } from "@theholocron/astromech/lint";
@@ -221,6 +221,17 @@ function validateGitHubApps(apps) {
221
221
  }
222
222
  });
223
223
  }
224
+ /** Throws a {@link ConfigError} naming the first thing wrong with the `ideas` block. */
225
+ function validateIdeas(ideas) {
226
+ const nonEmpty = (value) => typeof value === "string" && value.trim() !== "";
227
+ const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
228
+ if (!isObject(ideas)) throw new ConfigError$1("`ideas` must be an object: { dir, states? }");
229
+ if (!nonEmpty(ideas.dir)) throw new ConfigError$1("`ideas.dir` must be the path of the notes folder, got an empty value");
230
+ if (ideas.states !== void 0) {
231
+ if (!isObject(ideas.states)) throw new ConfigError$1("`ideas.states` must be an object: { file? }");
232
+ if (ideas.states.file !== void 0 && !nonEmpty(ideas.states.file)) throw new ConfigError$1("`ideas.states.file` must be a state name, got an empty value");
233
+ }
234
+ }
224
235
  /** Throws a {@link ConfigError} naming the first thing wrong with the `dev` block. */
225
236
  function validateDev(dev) {
226
237
  const nonEmpty = (value) => typeof value === "string" && value.trim() !== "";
@@ -277,6 +288,7 @@ function resolveConfig(raw) {
277
288
  }
278
289
  if (raw.dev !== void 0) validateDev(raw.dev);
279
290
  if (raw.githubApps !== void 0) validateGitHubApps(raw.githubApps);
291
+ if (raw.ideas !== void 0) validateIdeas(raw.ideas);
280
292
  validateVariablesSync(raw.repo?.variables);
281
293
  const credentialsEntry = providers.credentials;
282
294
  if (credentialsEntry?.cardinality === "many") for (const tuple of credentialsEntry.tuples) {
@@ -308,6 +320,7 @@ function resolveConfig(raw) {
308
320
  credentials: raw.credentials,
309
321
  dev: raw.dev,
310
322
  githubApps: raw.githubApps,
323
+ ideas: raw.ideas,
311
324
  log: raw.log,
312
325
  telemetry: raw.telemetry,
313
326
  eslint: raw.eslint
@@ -783,7 +796,8 @@ const COMMAND_CONTEXTS = {
783
796
  "repo sync": "workspace",
784
797
  "repo cleanup branches": "workspace",
785
798
  "sync github": "workspace",
786
- "sync issues": "workspace"
799
+ "sync issues": "workspace",
800
+ "ideas sync": "workspace"
787
801
  };
788
802
  /**
789
803
  * The context for a command name from `argv._`. Falls back to the leading
@@ -1482,12 +1496,12 @@ async function runDoctorTokens(input) {
1482
1496
  try {
1483
1497
  module = await importer(pkg);
1484
1498
  } catch (err) {
1485
- rows.push(row$9(pkg, "skip", `cannot load the plugin: ${errorMessage(err)}`));
1499
+ rows.push(row$10(pkg, "skip", `cannot load the plugin: ${errorMessage(err)}`));
1486
1500
  continue;
1487
1501
  }
1488
1502
  for (const token of module.tokens ?? []) rows.push(await checkToken$1(token, module, env, readToken, now()));
1489
1503
  }
1490
- if (rows.length === 0) rows.push(row$9("tokens", "skip", "no configured plugin lists the tokens it takes"));
1504
+ if (rows.length === 0) rows.push(row$10("tokens", "skip", "no configured plugin lists the tokens it takes"));
1491
1505
  printCheckRows(rows, print);
1492
1506
  const summary = summariseChecks(rows);
1493
1507
  printCheckSummary(summary, print);
@@ -1519,11 +1533,11 @@ async function loadCredentials(input) {
1519
1533
  try {
1520
1534
  await loader.load();
1521
1535
  } catch (err) {
1522
- return [row$9("credentials", "skip", `could not load the credentials providers: ${errorMessage(err)}`)];
1536
+ return [row$10("credentials", "skip", `could not load the credentials providers: ${errorMessage(err)}`)];
1523
1537
  }
1524
- return loader.loadFailures().filter((failure) => failure.key === "credentials").map((failure) => row$9(`credentials ${failure.provider}`, "fail", `could not be read: ${errorMessage(failure.error)}`));
1538
+ return loader.loadFailures().filter((failure) => failure.key === "credentials").map((failure) => row$10(`credentials ${failure.provider}`, "fail", `could not be read: ${errorMessage(failure.error)}`));
1525
1539
  }
1526
- function row$9(id, status, detail) {
1540
+ function row$10(id, status, detail) {
1527
1541
  return {
1528
1542
  id,
1529
1543
  title: id,
@@ -1537,21 +1551,21 @@ async function checkToken$1(token, module, env, readToken, now) {
1537
1551
  const fromEnv = env.get(envName) ? envName : vendorEnvName && env.get(vendorEnvName) ? vendorEnvName : void 0;
1538
1552
  const stored = fromEnv ? void 0 : findCredential(...vendorEnvName ? [envName, vendorEnvName] : [envName]);
1539
1553
  const value = fromEnv ? env.get(fromEnv) : stored?.value ?? readToken(keyringKey);
1540
- if (!value) return row$9(keyringKey, "skip", `not set (${vendorEnvName ? `${envName} / ${vendorEnvName}` : envName}, or \`holocron auth set ${keyringKey}\`)`);
1554
+ if (!value) return row$10(keyringKey, "skip", `not set (${vendorEnvName ? `${envName} / ${vendorEnvName}` : envName}, or \`holocron auth set ${keyringKey}\`)`);
1541
1555
  const verify = token.verify ?? (token.verifiable === false ? void 0 : module.verifyToken);
1542
- if (!verify) return row$9(keyringKey, "skip", "set, but its plugin cannot verify it");
1556
+ if (!verify) return row$10(keyringKey, "skip", "set, but its plugin cannot verify it");
1543
1557
  const from = fromEnv ?? stored?.source ?? "keyring";
1544
1558
  try {
1545
1559
  const verified = await verify(value);
1546
- if (!verified.ok) return row$9(keyringKey, "fail", `rejected (${from}): ${verified.message}`);
1560
+ if (!verified.ok) return row$10(keyringKey, "fail", `rejected (${from}): ${verified.message}`);
1547
1561
  const expiry = verified.expiresAt ? describeExpiry(verified.expiresAt, now) : void 0;
1548
- if (!expiry) return row$9(keyringKey, "ok", `${verified.subject} (${from})`);
1562
+ if (!expiry) return row$10(keyringKey, "ok", `${verified.subject} (${from})`);
1549
1563
  return expiry.soon ? {
1550
- ...row$9(keyringKey, "fail", `${verified.subject} (${from}), ${expiry.text}`),
1564
+ ...row$10(keyringKey, "fail", `${verified.subject} (${from}), ${expiry.text}`),
1551
1565
  problems: [`${expiry.text}: renew it`]
1552
- } : row$9(keyringKey, "ok", `${verified.subject} (${from}), ${expiry.text}`);
1566
+ } : row$10(keyringKey, "ok", `${verified.subject} (${from}), ${expiry.text}`);
1553
1567
  } catch (err) {
1554
- return row$9(keyringKey, "fail", `could not be verified (${from}): ${errorMessage(err)}`);
1568
+ return row$10(keyringKey, "fail", `could not be verified (${from}): ${errorMessage(err)}`);
1555
1569
  }
1556
1570
  }
1557
1571
  // src/commands/doctor-tokens/doctor-tokens.command.ts
@@ -2133,6 +2147,14 @@ const githubAppCreateEntry = {
2133
2147
  ],
2134
2148
  supportsDryRun: false
2135
2149
  };
2150
+ // src/commands/ideas-sync/ideas-sync.entry.ts
2151
+ const ideasSyncEntry = {
2152
+ name: "ideas sync",
2153
+ description: "File the idea notes that are ready as issues and record the issue in each note",
2154
+ positionals: [],
2155
+ skipOptions: ["yes"],
2156
+ supportsDryRun: true
2157
+ };
2136
2158
  // src/commands/migrate/migrate-issue/migrate-issue.entry.ts
2137
2159
  const migrateIssueEntry = {
2138
2160
  name: "migrate issue",
@@ -2803,6 +2825,7 @@ const registry = createCommandRegistry([
2803
2825
  skipOptions: ["yes"],
2804
2826
  supportsDryRun: true
2805
2827
  },
2828
+ ideasSyncEntry,
2806
2829
  {
2807
2830
  name: "repo sync readme",
2808
2831
  description: "Sync the Installation + Usage block in README.md from package.json",
@@ -3587,6 +3610,45 @@ const deployStageArgs = (y) => y.option("package-dir", {
3587
3610
  type: "string",
3588
3611
  describe: "Where to write the payload. Default: `.vercel-deploy` inside the package."
3589
3612
  });
3613
+ // src/commands/deploy-stage/alpha-release/alpha-release.ts
3614
+ /**
3615
+ * The release npm's `alpha` dist-tag points at for `name`, with the peer ranges it declares
3616
+ * (`npm view <name>@alpha version peerDependencies --json`).
3617
+ *
3618
+ * @returns `undefined` when the package or its `alpha` tag does not exist (npm's E404).
3619
+ * @throws when npm cannot be run or the registry cannot be reached: staging then would pin whatever is
3620
+ * installed, which is the stale version this lookup exists to replace.
3621
+ */
3622
+ function alphaRelease(name) {
3623
+ const result = spawnSync("npm", [
3624
+ "view",
3625
+ `${name}@alpha`,
3626
+ "version",
3627
+ "peerDependencies",
3628
+ "--json"
3629
+ ], {
3630
+ encoding: "utf8",
3631
+ stdio: [
3632
+ "ignore",
3633
+ "pipe",
3634
+ "pipe"
3635
+ ]
3636
+ });
3637
+ if (result.error) throw new Error(`cannot run npm to look up ${name}@alpha: ${result.error.message}`);
3638
+ if (result.status !== 0) {
3639
+ if (/E404|code E404/.test(`${result.stdout}${result.stderr}`)) return void 0;
3640
+ const reason = (result.stderr || result.stdout).split("\n").find((line) => line.trim()) ?? `exit ${result.status}`;
3641
+ throw new Error(`cannot look up ${name}@alpha on npm (is the registry reachable?): ${reason.trim()}`);
3642
+ }
3643
+ const parsed = JSON.parse(result.stdout);
3644
+ const view = typeof parsed === "string" ? { version: parsed } : parsed;
3645
+ if (typeof view.version !== "string") return void 0;
3646
+ const peers = view.peerDependencies;
3647
+ return {
3648
+ version: view.version,
3649
+ ...peers && typeof peers === "object" ? { peerDependencies: peers } : {}
3650
+ };
3651
+ }
3590
3652
  // src/commands/deploy-stage/installed-peers.ts
3591
3653
  /**
3592
3654
  * The `package.json` of `peer` as the package at `manifestPath` would resolve it: the closest `node_modules`
@@ -3626,6 +3688,40 @@ function installedPeers(packageDir, dependency) {
3626
3688
  collectPeers(realpathSync(manifestPath), peers);
3627
3689
  return peers;
3628
3690
  }
3691
+ // src/commands/deploy-stage/pin-alpha-releases/pin-alpha-releases.ts
3692
+ const OWN_SCOPE = "@theholocron/";
3693
+ const ALPHA_VERSION = /-alpha\./;
3694
+ const EXACT_VERSION = /^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$/;
3695
+ /**
3696
+ * Moves every `@theholocron/*` dependency installed at an `alpha` prerelease to the version npm's `alpha` tag points
3697
+ * at. A workspace package's `package.json` keeps the version it had when it was last committed, and a release only
3698
+ * writes the new one into the published copy, so the installed version of a plugin can be hundreds of releases behind
3699
+ * what npm serves, with a peer on a CLI it was never published with. A version that is not an `alpha` prerelease, a
3700
+ * package outside the scope and a package npm has no `alpha` tag for stay as they are.
3701
+ *
3702
+ * `mismatches` lists each exact peer a pinned release declares (`@theholocron/cli` is one) that differs from the
3703
+ * version staged for it, so a release cut between two lookups shows up instead of failing at runtime.
3704
+ */
3705
+ function pinAlphaReleases(dependencies, lookup) {
3706
+ const pinned = {};
3707
+ const changes = [];
3708
+ const peerRanges = [];
3709
+ for (const [name, version] of Object.entries(dependencies)) {
3710
+ const release = name.startsWith(OWN_SCOPE) && ALPHA_VERSION.test(version) ? lookup(name) : void 0;
3711
+ pinned[name] = release?.version ?? version;
3712
+ if (release && release.version !== version) changes.push(`${name} ${version} → ${release.version}`);
3713
+ if (release?.peerDependencies) peerRanges.push([
3714
+ name,
3715
+ release.version,
3716
+ release.peerDependencies
3717
+ ]);
3718
+ }
3719
+ return {
3720
+ dependencies: pinned,
3721
+ changes,
3722
+ mismatches: peerRanges.flatMap(([name, version, peers]) => Object.entries(peers).filter(([peer, range]) => peer in pinned && EXACT_VERSION.test(range) && pinned[peer] !== range).map(([peer, range]) => `${name}@${version} peers ${peer}@${range}, but ${peer}@${pinned[peer]} is staged`))
3723
+ };
3724
+ }
3629
3725
  // src/commands/deploy-stage/undeclared-externals.ts
3630
3726
  /** `"@scope/pkg/sub"` → `"@scope/pkg"`, `"pkg/sub"` → `"pkg"`. */
3631
3727
  function packageName(specifier) {
@@ -3720,8 +3816,10 @@ function vercelEngines(engines) {
3720
3816
  * here. They stay in `dependencies` because a repo's own `holocron.config.ts`
3721
3817
  * imports `@theholocron/cli` / `astromech/config` at runtime (only
3722
3818
  * `defineConfig`, an identity function, so a version skew there is harmless).
3723
- * Pinned versions still have to exist on npm: deploy from a synced `alpha`
3724
- * checkout, not an unreleased local branch.
3819
+ * Pinned versions still have to exist on npm. A workspace package's `package.json` is not updated when it is
3820
+ * released (the plugins sit at 5.0.0-alpha.132 on disk and 5.0.0-alpha.393 on npm, and each peers on exactly one CLI
3821
+ * version), so an `@theholocron/*` dependency installed at an `alpha` prerelease is pinned to npm's `alpha` tag
3822
+ * instead (`pinAlphaReleases()`); the lookup fails when npm cannot be reached, rather than staging the stale version.
3725
3823
  */
3726
3824
  function installedVersion(packageDir, name) {
3727
3825
  const pkgPath = join(packageDir, "node_modules", name, "package.json");
@@ -3754,10 +3852,12 @@ function stageDeploy(input) {
3754
3852
  ].join("\n"));
3755
3853
  const direct = Object.fromEntries(Object.keys(pkg.dependencies ?? {}).map((name) => [name, resolveVersion(packageDir, name)]));
3756
3854
  const peers = Object.fromEntries(Object.keys(direct).flatMap((name) => Object.entries(resolvePeers(packageDir, name))).filter(([name]) => !(name in direct)));
3757
- const dependencies = Object.fromEntries(Object.entries({
3855
+ const { dependencies, changes, mismatches } = pinAlphaReleases(Object.fromEntries(Object.entries({
3758
3856
  ...direct,
3759
3857
  ...peers
3760
- }).sort(([a], [b]) => a.localeCompare(b)));
3858
+ }).sort(([a], [b]) => a.localeCompare(b))), input.alphaRelease ?? alphaRelease);
3859
+ for (const change of changes) print(` pinned to npm's alpha tag: ${change}`);
3860
+ for (const mismatch of mismatches) print(` warning: ${mismatch}`);
3761
3861
  rmSync(outDir, {
3762
3862
  recursive: true,
3763
3863
  force: true
@@ -4741,7 +4841,7 @@ function parseList(text) {
4741
4841
  }
4742
4842
  // src/commands/doctor-ci/unquote.ts
4743
4843
  /** The text of a YAML scalar without its surrounding quotes. */
4744
- function unquote$1(value) {
4844
+ function unquote$2(value) {
4745
4845
  return value.trim().replace(/^(["'])(.*)\1$/, "$2");
4746
4846
  }
4747
4847
  // src/commands/doctor-ci/parse-caller.ts
@@ -4773,7 +4873,7 @@ function parseCaller(file, text) {
4773
4873
  continue;
4774
4874
  }
4775
4875
  const name = /^ {4}name:\s*(.+?)\s*$/.exec(line);
4776
- if (name && current) current.name = unquote$1(name[1]);
4876
+ if (name && current) current.name = unquote$2(name[1]);
4777
4877
  const uses = /^ {4}uses:\s*(\S+)/.exec(line);
4778
4878
  if (uses && current) current.uses = uses[1];
4779
4879
  }
@@ -4784,8 +4884,8 @@ function parseCaller(file, text) {
4784
4884
  return {
4785
4885
  file,
4786
4886
  jobs,
4787
- ...workflowName === void 0 ? {} : { name: unquote$1(workflowName) },
4788
- ...expected === void 0 ? {} : { expected: parseList(unquote$1(expected)) }
4887
+ ...workflowName === void 0 ? {} : { name: unquote$2(workflowName) },
4888
+ ...expected === void 0 ? {} : { expected: parseList(unquote$2(expected)) }
4789
4889
  };
4790
4890
  }
4791
4891
  // src/commands/doctor-ci/real-ci-io.ts
@@ -4906,7 +5006,7 @@ async function runDoctorCredentials(input) {
4906
5006
  };
4907
5007
  }
4908
5008
  /** A row for the provider as a whole, or for one of its variables when `name` is given. */
4909
- function row$8(provider, status, detail, name) {
5009
+ function row$9(provider, status, detail, name) {
4910
5010
  return name === void 0 ? {
4911
5011
  id: provider,
4912
5012
  title: provider,
@@ -4923,32 +5023,32 @@ function row$8(provider, status, detail, name) {
4923
5023
  }
4924
5024
  async function checkCredentials(input, loader) {
4925
5025
  const { resolved } = input.loaded;
4926
- if (!resolved.providers.credentials) return [row$8("credentials", "skip", "no `credentials` provider is configured")];
4927
- const rows = loader.loadFailures().filter((f) => f.key === "credentials").map((f) => row$8(f.provider, "fail", `failed to load: ${errorMessage(f.error)}`));
5026
+ if (!resolved.providers.credentials) return [row$9("credentials", "skip", "no `credentials` provider is configured")];
5027
+ const rows = loader.loadFailures().filter((f) => f.key === "credentials").map((f) => row$9(f.provider, "fail", `failed to load: ${errorMessage(f.error)}`));
4928
5028
  if (!loader.has("credentials")) return rows;
4929
5029
  const expected = await expectedTokens(input);
4930
5030
  const { tuples } = resolved.providers.credentials;
4931
5031
  for (const impl of loader.get("credentials")) {
4932
5032
  const tuple = tuples.find((t) => t.provider === impl.providerName);
4933
5033
  const environment = tuple && credentialsEnvironment(tuple, resolved);
4934
- rows.push(...environment ? await checkProvider(impl, environment, expected) : [row$8(impl.providerName, "skip", "no `environment` option and `credentials.environment` is not set")]);
5034
+ rows.push(...environment ? await checkProvider(impl, environment, expected) : [row$9(impl.providerName, "skip", "no `environment` option and `credentials.environment` is not set")]);
4935
5035
  }
4936
5036
  return rows;
4937
5037
  }
4938
5038
  async function checkProvider(impl, environment, expected) {
4939
5039
  const provider = impl.providerName;
4940
- if (!impl.inspect) return [row$8(provider, "skip", "cannot list the variables without reading their values")];
4941
- if (expected.length === 0) return [row$8(provider, "skip", "no configured plugin lists the tokens it takes")];
5040
+ if (!impl.inspect) return [row$9(provider, "skip", "cannot list the variables without reading their values")];
5041
+ if (expected.length === 0) return [row$9(provider, "skip", "no configured plugin lists the tokens it takes")];
4942
5042
  try {
4943
5043
  const found = await impl.inspect(environment);
4944
5044
  const held = new Set(found.names);
4945
5045
  const where = found.environment === environment ? `"${found.environment}"` : `"${found.environment}" (the config writes "${environment}")`;
4946
5046
  return expected.map(({ name, optional }) => {
4947
- if (held.has(name)) return row$8(provider, "ok", `present in ${where}`, name);
4948
- return optional ? row$8(provider, "skip", `optional, not set in ${where}`, name) : row$8(provider, "fail", `missing from ${where}`, name);
5047
+ if (held.has(name)) return row$9(provider, "ok", `present in ${where}`, name);
5048
+ return optional ? row$9(provider, "skip", `optional, not set in ${where}`, name) : row$9(provider, "fail", `missing from ${where}`, name);
4949
5049
  });
4950
5050
  } catch (err) {
4951
- return [row$8(provider, "fail", errorMessage(err))];
5051
+ return [row$9(provider, "fail", errorMessage(err))];
4952
5052
  }
4953
5053
  }
4954
5054
  /**
@@ -5779,7 +5879,7 @@ async function runDoctorDns(input) {
5779
5879
  });
5780
5880
  else if (!loader.has("dns")) {
5781
5881
  const why = whyMissing(loader, "dns", "no `dns` provider to check them with");
5782
- for (const zone of zones) rows.push(row$7(zone, "skip", why));
5882
+ for (const zone of zones) rows.push(row$8(zone, "skip", why));
5783
5883
  for (const { hostname } of domains) rows.push(domainRow(hostname, "skip", why));
5784
5884
  } else {
5785
5885
  const dns = loader.get("dns");
@@ -5801,7 +5901,7 @@ async function runDoctorDns(input) {
5801
5901
  ...status === "skip" ? { reason: [...new Set(rows.map((r) => r.detail))].join("; ") } : {}
5802
5902
  };
5803
5903
  }
5804
- function row$7(zone, status, detail, problems = []) {
5904
+ function row$8(zone, status, detail, problems = []) {
5805
5905
  return {
5806
5906
  id: `dns-${zone}`,
5807
5907
  title: `${zone} records exist`,
@@ -5830,7 +5930,7 @@ async function checkDomain(dns, deploy, project, hostname) {
5830
5930
  return noToken !== void 0 ? domainRow(hostname, "skip", noToken) : domainRow(hostname, "fail", errorMessage(err));
5831
5931
  }
5832
5932
  }
5833
- async function checkZone(dns, zone, wanted, rowOf = (...args) => row$7(zone, ...args)) {
5933
+ async function checkZone(dns, zone, wanted, rowOf = (...args) => row$8(zone, ...args)) {
5834
5934
  try {
5835
5935
  const have = await dns.listRecords(zone);
5836
5936
  const problems = declaredVsActual(new Map(wanted.map((w) => [keyOf(w), w])), new Map(have.map((h) => [keyOf(h), h])), {
@@ -5965,7 +6065,7 @@ function installationSettingsUrl(account, id) {
5965
6065
  return `https://github.com/settings/installations/${id}`;
5966
6066
  }
5967
6067
  // src/commands/doctor-github-app/app-rows.ts
5968
- const row$6 = (name, what, problems, ok) => ({
6068
+ const row$7 = (name, what, problems, ok) => ({
5969
6069
  id: `${name}:${what}`,
5970
6070
  title: `${name}: ${what}`,
5971
6071
  status: problems.length > 0 ? "fail" : "ok",
@@ -5992,9 +6092,9 @@ function appRows(name, manifest, app, installations) {
5992
6092
  return [`${who} has not accepted the current App: ${gaps.join("; ")}`, `fix: ${who} accepts the update at ${url}`];
5993
6093
  });
5994
6094
  return [
5995
- row$6(name, "events", eventProblems.length > 0 ? [...eventProblems, fix] : [], `all ${manifest.events.length} subscribed${extrasNote("extra event(s)", extraEvents)}`),
5996
- row$6(name, "permissions", permissionProblems.length > 0 ? [...permissionProblems, fix] : [], `all ${Object.keys(manifest.permissions).length} granted${extrasNote("extra permission(s)", extraPermissions)}`),
5997
- row$6(name, "installations", installationProblems, `${installations.length} installation(s) up to date`)
6095
+ row$7(name, "events", eventProblems.length > 0 ? [...eventProblems, fix] : [], `all ${manifest.events.length} subscribed${extrasNote("extra event(s)", extraEvents)}`),
6096
+ row$7(name, "permissions", permissionProblems.length > 0 ? [...permissionProblems, fix] : [], `all ${Object.keys(manifest.permissions).length} granted${extrasNote("extra permission(s)", extraPermissions)}`),
6097
+ row$7(name, "installations", installationProblems, `${installations.length} installation(s) up to date`)
5998
6098
  ];
5999
6099
  }
6000
6100
  // src/commands/doctor-github-app/parse-manifest.ts
@@ -6052,7 +6152,7 @@ async function runDoctorGitHubApp(input) {
6052
6152
  assertPluginsResolvable$1(loader, "doctor github-app");
6053
6153
  }
6054
6154
  const rows = [];
6055
- if (instances.length === 0) rows.push(row$5("github-app", "reachable", "skip", "no `githubApps` are declared in holocron.config.ts"));
6155
+ if (instances.length === 0) rows.push(row$6("github-app", "reachable", "skip", "no `githubApps` are declared in holocron.config.ts"));
6056
6156
  for (const instance of instances) rows.push(...await checkInstance(instance, loader, input));
6057
6157
  printCheckRows(rows, print);
6058
6158
  const summary = summariseChecks(rows);
@@ -6069,7 +6169,7 @@ async function runDoctorGitHubApp(input) {
6069
6169
  ...status === "skip" ? { reason: [...new Set(rows.map((r) => r.detail))].join("; ") } : {}
6070
6170
  };
6071
6171
  }
6072
- function row$5(name, what, status, detail) {
6172
+ function row$6(name, what, status, detail) {
6073
6173
  return {
6074
6174
  id: `${name}:${what}`,
6075
6175
  title: `${name}: ${what}`,
@@ -6112,19 +6212,19 @@ async function checkInstance(instance, loader, input) {
6112
6212
  try {
6113
6213
  manifest = parseManifest(readManifest(instance.manifest));
6114
6214
  } catch (err) {
6115
- return [row$5(name, "manifest", "fail", `cannot read ${instance.manifest}: ${errorMessage(err)}`)];
6215
+ return [row$6(name, "manifest", "fail", `cannot read ${instance.manifest}: ${errorMessage(err)}`)];
6116
6216
  }
6117
6217
  const read = await readCredentials(instance, loader);
6118
- if ("reason" in read) return [row$5(name, "reachable", "skip", read.reason)];
6218
+ if ("reason" in read) return [row$6(name, "reachable", "skip", read.reason)];
6119
6219
  const api = input.api ?? defaultApi;
6120
6220
  const secrets = [read.creds.privateKey];
6121
6221
  try {
6122
6222
  const app = await api.getApp(read.creds);
6123
6223
  const installations = await api.listAppInstallations(read.creds);
6124
6224
  const owner = app.owner ? `, owned by ${app.owner.login}` : "";
6125
- return [row$5(name, "reachable", "ok", `${app.slug}${owner}, settings: ${appSettingsUrl(app)}`), ...appRows(name, manifest, app, installations)];
6225
+ return [row$6(name, "reachable", "ok", `${app.slug}${owner}, settings: ${appSettingsUrl(app)}`), ...appRows(name, manifest, app, installations)];
6126
6226
  } catch (err) {
6127
- return [row$5(name, "reachable", "fail", `cannot call GitHub as the App: ${scrubbed(err, secrets)}`)];
6227
+ return [row$6(name, "reachable", "fail", `cannot call GitHub as the App: ${scrubbed(err, secrets)}`)];
6128
6228
  }
6129
6229
  }
6130
6230
  // src/commands/doctor-github-app/doctor-github-app.command.ts
@@ -6191,7 +6291,7 @@ function datasetTargets(config) {
6191
6291
  * dataset, shared by every environment in it). Only a dataset the provider says is missing, or a token it refuses, fails;
6192
6292
  * a name, a token or a response that cannot be read is a skip with the reason.
6193
6293
  */
6194
- const row$4 = (id, title, status, detail, problems = []) => ({
6294
+ const row$5 = (id, title, status, detail, problems = []) => ({
6195
6295
  id,
6196
6296
  title,
6197
6297
  status,
@@ -6208,7 +6308,7 @@ async function runDoctorLogs(input) {
6208
6308
  if (!loader.has("logs")) {
6209
6309
  const failure = loader.loadFailures().find((f) => f.key === "logs");
6210
6310
  const why = failure ? `\`${failure.provider}\` failed to load: ${describeError(failure.error)}` : "no `logs` provider is configured in holocron.config.ts";
6211
- rows.push(row$4("logs", "logs", "skip", why));
6311
+ rows.push(row$5("logs", "logs", "skip", why));
6212
6312
  } else rows.push(...await checkLogs(loader.get("logs"), datasetTargets(input.loaded.resolved)));
6213
6313
  printCheckRows(rows, print);
6214
6314
  const summary = summariseChecks(rows);
@@ -6232,38 +6332,38 @@ async function checkLogs(logs, targets) {
6232
6332
  for (const target of targets) {
6233
6333
  const id = `logs:dataset:${target.id}`;
6234
6334
  const title = `dataset for ${target.label}`;
6235
- if (!target.name) rows.push(row$4(id, title, "skip", `${target.variable} is not set here, so there is no name to look for`));
6236
- else if (!token.usable) rows.push(row$4(id, title, "skip", `${target.name}: not checked, the token is not usable`));
6237
- else if (!logs.readDataset) rows.push(row$4(id, title, "skip", `${logs.providerName} cannot read a dataset`));
6335
+ if (!target.name) rows.push(row$5(id, title, "skip", `${target.variable} is not set here, so there is no name to look for`));
6336
+ else if (!token.usable) rows.push(row$5(id, title, "skip", `${target.name}: not checked, the token is not usable`));
6337
+ else if (!logs.readDataset) rows.push(row$5(id, title, "skip", `${logs.providerName} cannot read a dataset`));
6238
6338
  else rows.push(...await checkDataset(logs, target, target.name, id, title));
6239
6339
  }
6240
6340
  const org = resolveValue$2(["AXIOM_ORG"], void 0, { prefix: PREFIX });
6241
- rows.push(org ? row$4("logs:org", "organization", "ok", `${PREFIX}_AXIOM_ORG (or AXIOM_ORG) is set`) : row$4("logs:org", "organization", "skip", `${PREFIX}_AXIOM_ORG (or AXIOM_ORG) is not set here; Sentinel's log links and check-dispatched need it`));
6341
+ rows.push(org ? row$5("logs:org", "organization", "ok", `${PREFIX}_AXIOM_ORG (or AXIOM_ORG) is set`) : row$5("logs:org", "organization", "skip", `${PREFIX}_AXIOM_ORG (or AXIOM_ORG) is not set here; Sentinel's log links and check-dispatched need it`));
6242
6342
  return rows;
6243
6343
  }
6244
6344
  /** Whether the provider accepts the token. `usable` is false when it was refused or could not be tried. */
6245
6345
  async function checkToken(logs) {
6246
6346
  const title = "token is accepted";
6247
6347
  if (!logs.checkToken) return {
6248
- row: row$4("logs:token", title, "skip", `${logs.providerName} cannot check a token`),
6348
+ row: row$5("logs:token", title, "skip", `${logs.providerName} cannot check a token`),
6249
6349
  usable: true
6250
6350
  };
6251
6351
  try {
6252
6352
  const result = await logs.checkToken();
6253
6353
  if (result.ok) return {
6254
- row: row$4("logs:token", title, "ok", `${logs.providerName} accepts the token`),
6354
+ row: row$5("logs:token", title, "ok", `${logs.providerName} accepts the token`),
6255
6355
  usable: true
6256
6356
  };
6257
6357
  const reason = result.reason ?? `${logs.providerName} refused the token`;
6258
6358
  return {
6259
- row: row$4("logs:token", title, "fail", reason, [reason]),
6359
+ row: row$5("logs:token", title, "fail", reason, [reason]),
6260
6360
  usable: false
6261
6361
  };
6262
6362
  } catch (err) {
6263
6363
  const noToken = missingTokenReason(err);
6264
6364
  const detail = noToken ?? `could not check the token: ${describeError(err)}`;
6265
6365
  return {
6266
- row: row$4("logs:token", title, "skip", detail),
6366
+ row: row$5("logs:token", title, "skip", detail),
6267
6367
  usable: noToken === void 0
6268
6368
  };
6269
6369
  }
@@ -6273,13 +6373,13 @@ async function checkDataset(logs, target, name, id, title) {
6273
6373
  const found = await logs.readDataset(name);
6274
6374
  if (!found.exists) {
6275
6375
  const problem = `dataset ${name} does not exist (${target.variable}); ${target.fix}`;
6276
- return [row$4(id, title, "fail", `${name} does not exist`, [problem])];
6376
+ return [row$5(id, title, "fail", `${name} does not exist`, [problem])];
6277
6377
  }
6278
6378
  const retention = found.retentionDays === void 0 ? `retention: ${logs.providerName} did not report one for ${name}` : `retention: ${found.retentionDays} days for ${name}`;
6279
- return [row$4(id, title, "ok", `${name} exists`), row$4(`logs:retention:${target.id}`, `retention of ${name}`, "skip", `info: ${retention}; one setting shared by every environment in the dataset (ADR-0019)`)];
6379
+ return [row$5(id, title, "ok", `${name} exists`), row$5(`logs:retention:${target.id}`, `retention of ${name}`, "skip", `info: ${retention}; one setting shared by every environment in the dataset (ADR-0019)`)];
6280
6380
  } catch (err) {
6281
6381
  const detail = missingTokenReason(err) ?? `could not read ${name}: ${describeError(err)}`;
6282
- return [row$4(id, title, "skip", detail)];
6382
+ return [row$5(id, title, "skip", detail)];
6283
6383
  }
6284
6384
  }
6285
6385
  // src/commands/doctor-logs/doctor-logs.command.ts
@@ -7933,7 +8033,7 @@ const GROUP_NAMES = /* @__PURE__ */ new Set([
7933
8033
  /** What a task id looks like: lowercase letters and digits, with a hyphen or a colon inside. */
7934
8034
  const ID = /^[a-z][a-z0-9:-]*$/;
7935
8035
  /** The unquoted text of a YAML list entry's value. */
7936
- const unquote = (value) => value.trim().replace(/^(["'])(.*)\1$/, "$2");
8036
+ const unquote$1 = (value) => value.trim().replace(/^(["'])(.*)\1$/, "$2");
7937
8037
  /**
7938
8038
  * Problems with the workflow names a workflow lists under `workflow_run: workflows:`, as human-readable lines: one for
7939
8039
  * each name that is an old group name (`Verification`), an old dotted task name or a lowercase name that is no task id.
@@ -7942,7 +8042,7 @@ const unquote = (value) => value.trim().replace(/^(["'])(.*)\1$/, "$2");
7942
8042
  * alone: this reads the text, not the repo's workflows.
7943
8043
  */
7944
8044
  function workflowNameProblems(text) {
7945
- return [...(/^ {2}workflow_run:\n {4}workflows:\n((?: {6}- [^\n]+\n)+)/m.exec(text)?.[1] ?? "").matchAll(/^ {6}- ([^\n#]+)/gm)].map((m) => unquote(m[1])).flatMap((name) => {
8045
+ return [...(/^ {2}workflow_run:\n {4}workflows:\n((?: {6}- [^\n]+\n)+)/m.exec(text)?.[1] ?? "").matchAll(/^ {6}- ([^\n#]+)/gm)].map((m) => unquote$1(m[1])).flatMap((name) => {
7946
8046
  if (GROUP_NAMES.has(name)) return [`${name}: an old group name; a caller's workflow is named for its task id`];
7947
8047
  if (!ID.test(name)) return [];
7948
8048
  if (name in LEGACY_NAMES) return [`${name}: an old task name; a caller's workflow is named for its task id`];
@@ -9268,7 +9368,7 @@ const info = (id, title, noun, extras) => ({
9268
9368
  detail: `info: ${extras.length} ${noun} not in the template (never deleted)`,
9269
9369
  problems: extras
9270
9370
  });
9271
- const row$3 = (id, title, problems, ok) => ({
9371
+ const row$4 = (id, title, problems, ok) => ({
9272
9372
  id,
9273
9373
  title,
9274
9374
  status: problems.length > 0 ? "fail" : "ok",
@@ -9304,19 +9404,19 @@ function viewProblems(want, found) {
9304
9404
  function boardRows(boardName, template, state) {
9305
9405
  const id = `project:${boardName}`;
9306
9406
  const rows = [];
9307
- rows.push(row$3(`${id}:statuses`, `${boardName}: statuses`, listProblems("status", "statuses", template.statuses.map((s) => s.name), state.statuses), `${template.statuses.length} in order`));
9407
+ rows.push(row$4(`${id}:statuses`, `${boardName}: statuses`, listProblems("status", "statuses", template.statuses.map((s) => s.name), state.statuses), `${template.statuses.length} in order`));
9308
9408
  const extraStatuses = state.statuses.filter((s) => !template.statuses.some((t) => t.name === s));
9309
9409
  if (extraStatuses.length > 0) rows.push(info(`${id}:extra-statuses`, `${boardName}: extra statuses`, "status(es)", extraStatuses));
9310
- for (const want of template.fields) rows.push(row$3(`${id}:field:${want.name}`, `${boardName}: field ${want.name}`, fieldProblems(want, state.fields.find((f) => f.name === want.name)), want.options ? `${want.options.length} options in order` : want.type));
9410
+ for (const want of template.fields) rows.push(row$4(`${id}:field:${want.name}`, `${boardName}: field ${want.name}`, fieldProblems(want, state.fields.find((f) => f.name === want.name)), want.options ? `${want.options.length} options in order` : want.type));
9311
9411
  const extraFields = state.fields.filter((f) => !template.fields.some((t) => t.name === f.name));
9312
9412
  if (extraFields.length > 0) rows.push(info(`${id}:extra-fields`, `${boardName}: extra fields`, "field(s)", extraFields.map((f) => f.name)));
9313
- for (const want of template.views) rows.push(row$3(`${id}:view:${want.name}`, `${boardName}: view ${want.name}`, viewProblems(want, state.views.find((v) => v.name === want.name)), `${want.layout}${want.filter ? `, ${want.filter}` : ""}`));
9413
+ for (const want of template.views) rows.push(row$4(`${id}:view:${want.name}`, `${boardName}: view ${want.name}`, viewProblems(want, state.views.find((v) => v.name === want.name)), `${want.layout}${want.filter ? `, ${want.filter}` : ""}`));
9314
9414
  const extraViews = state.views.filter((v) => !template.views.some((t) => t.name === v.name));
9315
9415
  if (extraViews.length > 0) rows.push(info(`${id}:extra-views`, `${boardName}: extra views`, "view(s)", extraViews.map((v) => v.name)));
9316
9416
  for (const name of template.rules ?? []) {
9317
9417
  const found = state.rules.find((r) => r.name === name);
9318
9418
  const problems = !found ? [`missing rule ${name}`] : found.enabled ? [] : [`rule ${name} is off`];
9319
- rows.push(row$3(`${id}:rule:${name}`, `${boardName}: rule ${name}`, problems, "on"));
9419
+ rows.push(row$4(`${id}:rule:${name}`, `${boardName}: rule ${name}`, problems, "on"));
9320
9420
  }
9321
9421
  return rows;
9322
9422
  }
@@ -9376,7 +9476,7 @@ function itemRows(boardName, items) {
9376
9476
  * never fail the run. A template file that does not read is a failure naming the file. `--post [channel]` shares the
9377
9477
  * failing rows through the `notifications` provider's bot, like `doctor notifications --post`.
9378
9478
  */
9379
- const row$2 = (id, title, status, detail, problems = []) => ({
9479
+ const row$3 = (id, title, status, detail, problems = []) => ({
9380
9480
  id,
9381
9481
  title,
9382
9482
  status,
@@ -9430,14 +9530,14 @@ async function checkBoards(input, loader) {
9430
9530
  loader,
9431
9531
  ...input.io ? { io: input.io } : {}
9432
9532
  });
9433
- if (!opened.ok) return [row$2("project", "project", opened.kind, opened.reason, opened.problems)];
9533
+ if (!opened.ok) return [row$3("project", "project", opened.kind, opened.reason, opened.problems)];
9434
9534
  const { projects, owner, boards, templates, templateProblems } = opened.context;
9435
9535
  const rows = templateProblems.map((problem) => {
9436
9536
  /* v8 ignore next -- split always returns at least one element; the fallback only satisfies noUncheckedIndexedAccess */
9437
9537
  const file = problem.split(": ")[0] ?? problem;
9438
- return row$2(`project:template:${file}`, `template file ${file}`, "fail", problem);
9538
+ return row$3(`project:template:${file}`, `template file ${file}`, "fail", problem);
9439
9539
  });
9440
- if (boards.length === 0) return [...rows, row$2("project", "project", "skip", "no boards are declared in `providers.projects.boards`")];
9540
+ if (boards.length === 0) return [...rows, row$3("project", "project", "skip", "no boards are declared in `providers.projects.boards`")];
9441
9541
  for (const declared of boards) {
9442
9542
  const template = templates[declared.template];
9443
9543
  const title = `${declared.name}: board exists and is open`;
@@ -9445,18 +9545,18 @@ async function checkBoards(input, loader) {
9445
9545
  const board = await projects.find(owner, declared.name);
9446
9546
  if (!board) {
9447
9547
  const closed = (await projects.list(owner)).some((b) => b.name === declared.name && b.closed);
9448
- rows.push(row$2(`project:${declared.name}`, title, "fail", closed ? "the board is closed" : "no open board has this name", [closed ? "reopen it, or run `holocron project setup` to make a new one" : "run `holocron project setup`"]));
9548
+ rows.push(row$3(`project:${declared.name}`, title, "fail", closed ? "the board is closed" : "no open board has this name", [closed ? "reopen it, or run `holocron project setup` to make a new one" : "run `holocron project setup`"]));
9449
9549
  continue;
9450
9550
  }
9451
- rows.push(row$2(`project:${declared.name}`, title, "ok", board.url));
9551
+ rows.push(row$3(`project:${declared.name}`, title, "ok", board.url));
9452
9552
  if (!template) {
9453
- rows.push(row$2(`project:${declared.name}:template`, `${declared.name}: template ${declared.template}`, "fail", "no built-in or file template has this name"));
9553
+ rows.push(row$3(`project:${declared.name}:template`, `${declared.name}: template ${declared.template}`, "fail", "no built-in or file template has this name"));
9454
9554
  continue;
9455
9555
  }
9456
9556
  rows.push(...boardRows(declared.name, template, await projects.read(owner, board)));
9457
- rows.push(...projects.items ? itemRows(declared.name, await projects.items(owner, board, template)) : [row$2(`project:${declared.name}:items`, `${declared.name}: items`, "skip", "the provider cannot list a board's items")]);
9557
+ rows.push(...projects.items ? itemRows(declared.name, await projects.items(owner, board, template)) : [row$3(`project:${declared.name}:items`, `${declared.name}: items`, "skip", "the provider cannot list a board's items")]);
9458
9558
  } catch (err) {
9459
- rows.push(row$2(`project:${declared.name}`, title, "fail", describeError(err)));
9559
+ rows.push(row$3(`project:${declared.name}`, title, "fail", describeError(err)));
9460
9560
  }
9461
9561
  }
9462
9562
  return rows;
@@ -10131,19 +10231,19 @@ async function runDoctorRepo(input) {
10131
10231
  const rows = [];
10132
10232
  if (!loader.has("source")) {
10133
10233
  const why = whyMissing(loader, "source", "no `source` provider to read the repository with");
10134
- for (const check of checks) rows.push(row$1(check, { skip: why }));
10234
+ for (const check of checks) rows.push(row$2(check, { skip: why }));
10135
10235
  } else {
10136
10236
  const source = loader.get("source");
10137
10237
  for (const check of checks) {
10138
10238
  if (typeof source[check.needs] !== "function") {
10139
- rows.push(row$1(check, { skip: `provider does not implement ${check.needs}` }));
10239
+ rows.push(row$2(check, { skip: `provider does not implement ${check.needs}` }));
10140
10240
  continue;
10141
10241
  }
10142
10242
  try {
10143
- rows.push(row$1(check, await check.run(source)));
10243
+ rows.push(row$2(check, await check.run(source)));
10144
10244
  } catch (err) {
10145
10245
  const noToken = missingTokenReason(err);
10146
- if (noToken !== void 0) rows.push(row$1(check, { skip: noToken }));
10246
+ if (noToken !== void 0) rows.push(row$2(check, { skip: noToken }));
10147
10247
  else rows.push({
10148
10248
  id: check.id,
10149
10249
  title: check.title,
@@ -10169,7 +10269,7 @@ async function runDoctorRepo(input) {
10169
10269
  ...status === "skip" ? { reason: rows.map((r) => r.detail).join("; ") } : {}
10170
10270
  };
10171
10271
  }
10172
- function row$1(check, result) {
10272
+ function row$2(check, result) {
10173
10273
  const { id, title } = check;
10174
10274
  if ("skip" in result) return {
10175
10275
  id,
@@ -10577,14 +10677,14 @@ async function runDoctorVariables(input) {
10577
10677
  });
10578
10678
  else if (!loader.has("source")) {
10579
10679
  const why = whyMissing(loader, "source", "no `source` provider to read them with");
10580
- for (const check of checks) rows.push(row(check, { skip: why }));
10680
+ for (const check of checks) rows.push(row$1(check, { skip: why }));
10581
10681
  } else {
10582
10682
  const source = loader.get("source");
10583
10683
  for (const check of checks) try {
10584
- rows.push(row(check, await check.run(source)));
10684
+ rows.push(row$1(check, await check.run(source)));
10585
10685
  } catch (err) {
10586
10686
  const noToken = missingTokenReason(err);
10587
- if (noToken !== void 0) rows.push(row(check, { skip: noToken }));
10687
+ if (noToken !== void 0) rows.push(row$1(check, { skip: noToken }));
10588
10688
  else rows.push({
10589
10689
  id: check.id,
10590
10690
  title: check.title,
@@ -10609,7 +10709,7 @@ async function runDoctorVariables(input) {
10609
10709
  ...status === "skip" ? { reason: rows.map((r) => r.detail).join("; ") } : {}
10610
10710
  };
10611
10711
  }
10612
- function row(check, result) {
10712
+ function row$1(check, result) {
10613
10713
  const { id, title } = check;
10614
10714
  if ("skip" in result) return {
10615
10715
  id,
@@ -11372,6 +11472,280 @@ const githubAppCommand = {
11372
11472
  builder: (y) => y.command(githubAppCreateCommand).command(groupMenu$1("github-app")),
11373
11473
  handler: () => {}
11374
11474
  };
11475
+ // src/commands/ideas-sync/list-notes/list-notes.ts
11476
+ /**
11477
+ * Every Markdown note under `dir`, as paths relative to it with `/` separators, sorted. A folder whose name starts
11478
+ * with `_` or `.` (`.obsidian`, `.trash`, `_archive`) is not entered. `undefined` when `dir` itself cannot be read.
11479
+ */
11480
+ function listNotes(io, dir) {
11481
+ const top = io.readDir(dir);
11482
+ if (!top) return void 0;
11483
+ const found = [];
11484
+ const walk = (relative, entries) => {
11485
+ for (const entry of entries ?? []) {
11486
+ const path = relative === "" ? entry.name : `${relative}/${entry.name}`;
11487
+ if (entry.directory) {
11488
+ if (!/^[_.]/.test(entry.name)) walk(path, io.readDir(join(dir, path)));
11489
+ } else if (entry.name.toLowerCase().endsWith(".md") && !entry.name.startsWith(".")) found.push(path);
11490
+ }
11491
+ };
11492
+ walk("", top);
11493
+ return found.sort();
11494
+ }
11495
+ // src/commands/ideas-sync/parse-note/parse-note.ts
11496
+ const FRONTMATTER = /^---\r?\n[\s\S]*?\r?\n---[ \t]*(?:\r?\n|$)/;
11497
+ const FENCE = /^(```|~~~)[\s\S]*?^\1/gm;
11498
+ const WEB_ADDRESS = /^[a-z][a-z0-9+.-]*:/i;
11499
+ const unquote = (value) => value.replace(/^(["'])(.*)\1$/, "$2").trim();
11500
+ /**
11501
+ * Reads one note: its `status:` and `issue:` properties, its title, its text without the frontmatter and the files it
11502
+ * embeds. The title is the first `#` heading, else `fileName` without `.md`. An embed is `![[x]]` (any) or `![](x)`
11503
+ * where `x` is not an address with a scheme; embeds inside a code fence are text and do not count.
11504
+ */
11505
+ function parseNote(text, fileName) {
11506
+ const fields = parseFrontmatter(text.replace(/\r\n/g, "\n"));
11507
+ const body = text.replace(FRONTMATTER, "");
11508
+ const prose = body.replace(/\r/g, "").replace(FENCE, "");
11509
+ const heading = /^#[ \t]+(.+?)[ \t]*$/m.exec(prose);
11510
+ const wiki = [...prose.matchAll(/!\[\[[^\]]+\]\]/g)].map((m) => m[0]);
11511
+ const links = [...prose.matchAll(/!\[[^\]]*\]\(([^)\s]+)[^)]*\)/g)].filter((m) => !WEB_ADDRESS.test(m[1])).map((m) => m[0]);
11512
+ return {
11513
+ status: unquote(fields?.get("status")?.value ?? ""),
11514
+ issue: unquote(fields?.get("issue")?.value ?? ""),
11515
+ title: heading?.[1] ?? fileName.replace(/\.md$/i, ""),
11516
+ body,
11517
+ attachments: [...wiki, ...links]
11518
+ };
11519
+ }
11520
+ // src/commands/ideas-sync/real-ideas-io/real-ideas-io.ts
11521
+ /** The `ideas sync` inputs from the real filesystem. */
11522
+ function realIdeasIo() {
11523
+ /* v8 ignore start -- reads the real filesystem; the command is tested with an injected io */
11524
+ return {
11525
+ readDir: (path) => {
11526
+ try {
11527
+ return readdirSync(path, { withFileTypes: true }).map((e) => ({
11528
+ name: e.name,
11529
+ directory: e.isDirectory()
11530
+ }));
11531
+ } catch {
11532
+ return;
11533
+ }
11534
+ },
11535
+ read: (path) => {
11536
+ try {
11537
+ return readFileSync(path, "utf8");
11538
+ } catch {
11539
+ return;
11540
+ }
11541
+ },
11542
+ write: (path, text) => writeFileSync(path, text, "utf8"),
11543
+ home: () => homedir()
11544
+ };
11545
+ /* v8 ignore stop */
11546
+ }
11547
+ // src/commands/ideas-sync/resolve-ideas-dir/resolve-ideas-dir.ts
11548
+ /**
11549
+ * The folder of idea notes: `HOLOCRON_IDEAS_DIR` (then `IDEAS_DIR`) when set, else `ideas.dir` of the config.
11550
+ * A leading `~` is the home folder. `undefined` when neither names one.
11551
+ */
11552
+ function resolveIdeasDir(ideas, home, source) {
11553
+ const dir = holocronEnv(source).get("IDEAS_DIR") ?? ideas?.dir;
11554
+ if (dir === void 0) return void 0;
11555
+ if (dir === "~") return home;
11556
+ return dir.startsWith("~/") ? join(home, dir.slice(2)) : dir;
11557
+ }
11558
+ // src/commands/ideas-sync/write-issue-key/write-issue-key.ts
11559
+ const BLOCK = /^---(\r?\n)([\s\S]*?)(\r?\n)---/;
11560
+ /**
11561
+ * The note's text with `issue: <key>` in its frontmatter: a blank `issue:` line is filled in, else a line is added at
11562
+ * the end of the block. Everything else, including line endings and the body, is left byte for byte. A note with no
11563
+ * frontmatter is returned unchanged (such a note has no `status:`, so it is never filed).
11564
+ */
11565
+ function writeIssueKey(text, key) {
11566
+ const match = BLOCK.exec(text);
11567
+ if (!match) return text;
11568
+ const [whole, open, inner, close] = match;
11569
+ const lines = inner.split(/\r?\n/);
11570
+ const separators = inner.match(/\r?\n/g) ?? [];
11571
+ const at = lines.findIndex((line) => /^issue:/.test(line));
11572
+ const next = at === -1 ? [...lines, `issue: ${key}`] : lines.map((line, i) => i === at ? `issue: ${key}` : line);
11573
+ let rebuilt = next[0];
11574
+ next.slice(1).forEach((line, i) => {
11575
+ rebuilt += (separators[i] ?? close) + line;
11576
+ });
11577
+ return `---${open}${rebuilt}${close}---${text.slice(whole.length)}`;
11578
+ }
11579
+ // src/commands/ideas-sync/run-ideas-sync/run-ideas-sync.ts
11580
+ /**
11581
+ * `holocron ideas sync` — files the idea notes that are ready.
11582
+ *
11583
+ * It reads every Markdown note in `ideas.dir` (not in a folder whose name starts with `_` or `.`). A note whose
11584
+ * `status:` is the filing state (default `in-progress`) and that has no `issue:` becomes an issue through the repo's
11585
+ * `issues` provider, and its `issue:` property is then written in the tracker's own syntax, which is what makes the
11586
+ * step run once. A note with embedded files is reported and skipped, since an issue body cannot carry them. Only
11587
+ * notes to be filed, and notes that need the person's attention, get a row; the rest are counted. The issue body ends
11588
+ * with a hidden `<!-- holocron:idea <path> -->` line, and an issue that carries it is reused instead of making a second
11589
+ * one (found with `Issues.search`, the recent issues only). It never deletes anything, and a note it cannot file is a
11590
+ * failing row (the run goes on). It writes, so it asks first unless `--dry-run` or `--yes` (without a terminal it refuses instead).
11591
+ */
11592
+ /** The state that files a note when the config names none. */
11593
+ const DEFAULT_FILING_STATE = "in-progress";
11594
+ const row = (id, status, detail) => ({
11595
+ id,
11596
+ title: id,
11597
+ status,
11598
+ detail,
11599
+ problems: []
11600
+ });
11601
+ /**
11602
+ * The hidden line that ties an issue to its note. A later run looks for it before it creates an issue, so a note whose
11603
+ * `issue:` could not be written is not filed twice.
11604
+ */
11605
+ const marker = (path) => `<!-- holocron:idea ${path} -->`;
11606
+ /** The issue's body: the note's text, the line that traces the issue to its idea, and the hidden marker. */
11607
+ const issueBody = (note, path) => `${note.body.trim()}\n\nFiled from idea: ${note.title}\n${marker(path)}`;
11608
+ /** How many recent issues are searched for the marker (the narrowest existing method, `Issues.search`). */
11609
+ const SEARCH_LIMIT = 100;
11610
+ async function runIdeasSync(input) {
11611
+ /* v8 ignore next -- the console is only used outside tests, which inject `print` */
11612
+ const print = input.print ?? ((line) => console.log(line));
11613
+ /* v8 ignore next -- the real disk is only used outside tests, which inject `io` */
11614
+ const io = input.io ?? realIdeasIo();
11615
+ const dryRun = Boolean(input.context.dryRun);
11616
+ let notReady = 0;
11617
+ const finish = (rows, status) => {
11618
+ printCheckRows(rows, print);
11619
+ const summary = summariseChecks(rows);
11620
+ printCheckSummary(summary, print);
11621
+ if (notReady > 0) print(` ${notReady} note(s) not ready (another status, or already filed), shown in no row`);
11622
+ return {
11623
+ status: status ?? (summary.fail > 0 ? "fail" : "ok"),
11624
+ rows
11625
+ };
11626
+ };
11627
+ print(style.header(`Holocron ideas sync${dryRun ? " (dry-run)" : ""}`));
11628
+ print("");
11629
+ const ideas = input.loaded.resolved.ideas;
11630
+ const dir = resolveIdeasDir(ideas, io.home(), input.env);
11631
+ if (!dir) return finish([row("ideas", "fail", "no notes folder: set `ideas.dir` in holocron.config or HOLOCRON_IDEAS_DIR")]);
11632
+ const paths = listNotes(io, dir);
11633
+ if (!paths) return finish([row(dir, "fail", "the notes folder does not exist or cannot be read")]);
11634
+ const fileState = ideas?.states?.file ?? DEFAULT_FILING_STATE;
11635
+ const rows = [];
11636
+ const ready = [];
11637
+ for (const path of paths) {
11638
+ const text = io.read(join(dir, path));
11639
+ if (text === void 0) {
11640
+ rows.push(row(path, "fail", "cannot be read"));
11641
+ continue;
11642
+ }
11643
+ const note = parseNote(text, path.slice(path.lastIndexOf("/") + 1));
11644
+ if (note.status !== fileState || note.issue !== "") notReady++;
11645
+ else if (note.attachments.length > 0) rows.push(row(path, "skip", `has embedded files an issue cannot carry (${note.attachments.join(", ")}); not filed`));
11646
+ else ready.push({
11647
+ path,
11648
+ note
11649
+ });
11650
+ }
11651
+ if (ready.length === 0) return finish(rows);
11652
+ if (dryRun) {
11653
+ for (const { path, note } of ready) rows.push(row(path, "skip", `would file "${note.title}"`));
11654
+ return finish(rows.sort((a, b) => a.id.localeCompare(b.id)));
11655
+ }
11656
+ if (!input.yes) {
11657
+ if (!(input.interactive ?? Boolean(process.stdin.isTTY))) throw new NonInteractiveError(`\`ideas sync\` creates ${ready.length} issue(s) and edits the notes; pass --yes to run it without asking, or --dry-run to preview`);
11658
+ if (!await (input.confirm ?? ((message) => confirm({
11659
+ message,
11660
+ default: false
11661
+ })))(`File ${ready.length} idea(s) as issues and record the issue in each note?`)) {
11662
+ print(` ${style.skip("cancelled; nothing was changed")}`);
11663
+ return {
11664
+ status: "cancelled",
11665
+ rows: []
11666
+ };
11667
+ }
11668
+ }
11669
+ /* v8 ignore next -- the real loader is only built outside tests, which always inject one */
11670
+ const loader = input.loader ?? new PluginLoader(input.loaded.resolved, input.context);
11671
+ await loader.load();
11672
+ assertPluginsResolvable$1(loader, "ideas sync");
11673
+ const issues = loader.has("issues") ? loader.get("issues") : void 0;
11674
+ let recent = [];
11675
+ let searchError;
11676
+ if (issues) try {
11677
+ recent = await issues.search({ limit: SEARCH_LIMIT });
11678
+ } catch (err) {
11679
+ searchError = err;
11680
+ }
11681
+ const searchFailed = searchError !== void 0;
11682
+ for (const { path, note } of ready) {
11683
+ if (!issues) {
11684
+ rows.push(row(path, "fail", "the config has no `issues` provider to file it with"));
11685
+ continue;
11686
+ }
11687
+ if (searchFailed) {
11688
+ rows.push(row(path, "fail", `could not check for an existing issue, so none was created: ${describeError(searchError)}`));
11689
+ continue;
11690
+ }
11691
+ let key;
11692
+ const existing = recent.find((issue) => issue.body?.includes(marker(path)));
11693
+ if (existing) key = existing.key;
11694
+ else try {
11695
+ ({key} = await issues.create({
11696
+ summary: note.title,
11697
+ body: issueBody(note, path)
11698
+ }));
11699
+ } catch (err) {
11700
+ rows.push(row(path, "fail", `could not create the issue: ${describeError(err)}`));
11701
+ continue;
11702
+ }
11703
+ try {
11704
+ const current = io.read(join(dir, path));
11705
+ if (current === void 0) throw new Error("the note can no longer be read");
11706
+ io.write(join(dir, path), writeIssueKey(current, key));
11707
+ rows.push(row(path, "ok", `${existing ? "already filed" : "filed"} as ${key}`));
11708
+ } catch (err) {
11709
+ rows.push({
11710
+ ...row(path, "fail", `issue ${key} was created but \`issue:\` was not written: ${describeError(err)}`),
11711
+ problems: [`add \`issue: ${key}\` to the note by hand`]
11712
+ });
11713
+ }
11714
+ }
11715
+ return finish(rows.sort((a, b) => a.id.localeCompare(b.id)));
11716
+ }
11717
+ // src/commands/ideas-sync/ideas-sync.command.ts
11718
+ const ideasSyncCommand = {
11719
+ command: "sync",
11720
+ describe: "File the idea notes that are ready as issues, and record the issue in each note",
11721
+ builder: (y) => y.option("yes", {
11722
+ type: "boolean",
11723
+ describe: "File without asking (required without a terminal)"
11724
+ }),
11725
+ handler: async (argv) => {
11726
+ const tokens = tokenContext$1(argv.token);
11727
+ if (!tokens) return;
11728
+ const loaded = await loadConfig(argv.cwd);
11729
+ applyResolvedConfig(argv, loaded.resolved);
11730
+ if ((await runIdeasSync({
11731
+ loaded,
11732
+ context: {
11733
+ repoRoot: argv.cwd,
11734
+ dryRun: argv.dryRun,
11735
+ ...tokens,
11736
+ org: resolveOrg(argv, loaded.resolved)
11737
+ },
11738
+ ...argv.yes ? { yes: true } : {}
11739
+ })).status === "fail") process.exitCode = 1;
11740
+ }
11741
+ };
11742
+ // src/commands/ideas/ideas.command.ts
11743
+ const ideasCommand = {
11744
+ command: "ideas",
11745
+ describe: "Work with the idea notes that sit in front of the issue tracker",
11746
+ builder: (y) => y.command(ideasSyncCommand).command(groupMenu$1("ideas")),
11747
+ handler: () => {}
11748
+ };
11375
11749
  // src/commands/menu/menu.command.ts
11376
11750
  /**
11377
11751
  * Print the dim version line once per terminal session — keyed by the
@@ -15010,7 +15384,7 @@ function workspaceFilterArgs(cwd, scope = {}) {
15010
15384
  *
15011
15385
  * $ pnpm install --frozen-lockfile
15012
15386
  * $ pnpm build
15013
- * $ pnpm exec tsx cli/cli/src/cli/cli.ts package publish --initial
15387
+ * $ pnpm --filter @theholocron/cli run start:source package publish --initial
15014
15388
  *
15015
15389
  * `npm login --auth-type=web` runs automatically the first time — no
15016
15390
  * separate manual step. `pnpm install` + `pnpm build` stay outside the
@@ -15164,7 +15538,7 @@ async function runPublish(input = {}) {
15164
15538
  if (publish.stdout.includes("EOTP") || publish.stderr.includes("EOTP")) {
15165
15539
  print("");
15166
15540
  print(" → hint: your npm account requires 2FA for writes. Re-run with `--otp <code>`:");
15167
- print(` pnpm exec tsx cli/cli/src/cli/cli.ts package publish --initial --otp <6-digit-code>`);
15541
+ print(` pnpm --filter @theholocron/cli run start:source package publish --initial --otp <6-digit-code>`);
15168
15542
  }
15169
15543
  for (const entry of newEntries) print(statusRow("fail", [
15170
15544
  pad(entry.name, nameWidth),
@@ -24515,7 +24889,7 @@ try {
24515
24889
  org: argv.org
24516
24890
  });
24517
24891
  finishCommand = startCommand(name);
24518
- }).command(cloneCommand).command(doctorCommand).command(skillsCommand).command(runCommand).command(configShowCommand).command(authCommand).command(menuCommand(CLI_VERSION)).command(repoCommand).command(newCommand).command(probeCommand).command(providerCommand).command(secretsCommand).command(notificationsCommand).command(githubAppCommand).command(specsCommand).command(tunnelCommand).command(projectCommand).command(migrateCommand).command(devCommand).command(syncCommand).command(packageCommand).command(deployCommand).command(monitoringCommand).command(projectCommand).strict().help().epilogue(`Execution contexts:
24892
+ }).command(cloneCommand).command(doctorCommand).command(skillsCommand).command(runCommand).command(configShowCommand).command(authCommand).command(menuCommand(CLI_VERSION)).command(repoCommand).command(newCommand).command(probeCommand).command(providerCommand).command(secretsCommand).command(notificationsCommand).command(githubAppCommand).command(specsCommand).command(tunnelCommand).command(projectCommand).command(migrateCommand).command(devCommand).command(syncCommand).command(ideasCommand).command(packageCommand).command(deployCommand).command(monitoringCommand).command(projectCommand).strict().help().epilogue(`Execution contexts:
24519
24893
  global works from a bare 'npm i -g': ${commandsInContext("global").join(", ")}\n repo-aware needs ./holocron.config in cwd: ${commandsInContext("repo-aware").join(", ")}\n workspace also needs the plugin packages: ${commandsInContext("workspace").join(", ")}\n https://docs.theholocron.dev/holocron/execution-contexts`).fail((msg, err) => {
24520
24894
  if (err instanceof Error && USER_FACING_ERRORS.has(err.name)) {
24521
24895
  captureException(err);