@cosmicstack/mercury-agent 0.3.2 → 0.3.4

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/index.js CHANGED
@@ -79,7 +79,7 @@ function getDefaultConfig() {
79
79
  },
80
80
  github: {
81
81
  username: getEnv("GITHUB_USERNAME", ""),
82
- email: getEnv("GITHUB_EMAIL", ""),
82
+ email: getEnv("GITHUB_EMAIL", "mercury@cosmicstack.org"),
83
83
  defaultOwner: getEnv("GITHUB_DEFAULT_OWNER", ""),
84
84
  defaultRepo: getEnv("GITHUB_DEFAULT_REPO", "")
85
85
  },
@@ -4667,6 +4667,14 @@ function appendToEnv(key, value) {
4667
4667
  writeFileSync13(envPath, lines.join("\n") + "\n", "utf-8");
4668
4668
  process.env[key] = value;
4669
4669
  }
4670
+ function parseGithubRepo(input) {
4671
+ const trimmed = input.trim().replace(/\/+$/, "");
4672
+ const urlMatch = trimmed.match(/github\.com\/([^/]+)\/([^/]+)/);
4673
+ if (urlMatch) return { owner: urlMatch[1], repo: urlMatch[2] };
4674
+ const shortMatch = trimmed.match(/^([^/\s]+)\/([^/\s]+)$/);
4675
+ if (shortMatch) return { owner: shortMatch[1], repo: shortMatch[2] };
4676
+ return null;
4677
+ }
4670
4678
  async function configure(existingConfig) {
4671
4679
  const isReconfig = !!existingConfig;
4672
4680
  const config = existingConfig ?? loadConfig();
@@ -4765,28 +4773,45 @@ async function configure(existingConfig) {
4765
4773
  }
4766
4774
  hr();
4767
4775
  console.log("");
4768
- console.log(chalk6.bold.white(" GitHub (optional)"));
4769
- console.log(chalk6.dim(" Connect Mercury to GitHub for PRs, issues, and co-authored commits."));
4776
+ console.log(chalk6.bold.white(" GitHub Integration (optional)"));
4777
+ console.log(chalk6.dim(" Connect Mercury to GitHub so it can create PRs, manage issues,"));
4778
+ console.log(chalk6.dim(" review code, and co-author commits on your behalf."));
4770
4779
  console.log(chalk6.dim(" Leave empty to skip. You can add it later with mercury doctor."));
4771
4780
  console.log("");
4772
4781
  const ghUserCurrent = isReconfig && config.github.username ? ` [${config.github.username}]` : "";
4773
- const ghUsername = await ask(chalk6.white(` GitHub username${ghUserCurrent}: `));
4782
+ const ghUsername = await ask(chalk6.white(` 1. Your GitHub username${ghUserCurrent}: `));
4774
4783
  if (ghUsername) config.github.username = ghUsername;
4775
- const ghEmailCurrent = isReconfig && config.github.email ? ` [${config.github.email}]` : "";
4776
- const ghEmail = await ask(chalk6.white(` GitHub email${ghEmailCurrent}: `));
4777
- if (ghEmail) config.github.email = ghEmail;
4784
+ if (!config.github.email) {
4785
+ config.github.email = "mercury@cosmicstack.org";
4786
+ }
4787
+ console.log("");
4788
+ console.log(chalk6.dim(" You need a Personal Access Token (PAT) with repo access."));
4789
+ console.log(chalk6.dim(" Fine-grained (recommended): github.com/settings/personal-access-tokens/new"));
4790
+ console.log(chalk6.dim(" \u2192 Permissions: Contents (R/W), Pull requests (R/W), Issues (R/W)"));
4791
+ console.log(chalk6.dim(" Classic: github.com/settings/tokens/new"));
4792
+ console.log(chalk6.dim(" \u2192 Scope: repo (full control)"));
4778
4793
  const ghTokenCurrent = process.env.GITHUB_TOKEN ? ` [${maskKey(process.env.GITHUB_TOKEN)}]` : "";
4779
- const ghToken = await ask(chalk6.white(` GitHub PAT (repo scope)${ghTokenCurrent}: `));
4794
+ const ghToken = await ask(chalk6.white(` 2. GitHub PAT${ghTokenCurrent}: `));
4780
4795
  if (ghToken) {
4781
4796
  appendToEnv("GITHUB_TOKEN", ghToken);
4782
4797
  }
4783
4798
  if (config.github.username || process.env.GITHUB_TOKEN) {
4784
- const ghOwnerCurrent = isReconfig && config.github.defaultOwner ? ` [${config.github.defaultOwner}]` : "";
4785
- const ghOwner = await ask(chalk6.white(` Default GitHub owner/org${ghOwnerCurrent}: `));
4786
- if (ghOwner) config.github.defaultOwner = ghOwner;
4787
- const ghRepoCurrent = isReconfig && config.github.defaultRepo ? ` [${config.github.defaultRepo}]` : "";
4788
- const ghRepo = await ask(chalk6.white(` Default repo name${ghRepoCurrent}: `));
4789
- if (ghRepo) config.github.defaultRepo = ghRepo;
4799
+ console.log("");
4800
+ console.log(chalk6.dim(' Set a default repo so you can say "create an issue" without'));
4801
+ console.log(chalk6.dim(" specifying the repo every time. Enter owner/name or a full URL."));
4802
+ console.log(chalk6.dim(" Example: hotheadhacker/mercury-agent"));
4803
+ console.log(chalk6.dim(" Example: https://github.com/hotheadhacker/mercury-agent"));
4804
+ const ghOwnerCurrent = isReconfig && config.github.defaultOwner ? ` [${config.github.defaultOwner}/${config.github.defaultRepo}]` : "";
4805
+ const ghRepoInput = await ask(chalk6.white(` 3. Default repo${ghOwnerCurrent}: `));
4806
+ if (ghRepoInput) {
4807
+ const parsed = parseGithubRepo(ghRepoInput);
4808
+ if (parsed) {
4809
+ config.github.defaultOwner = parsed.owner;
4810
+ config.github.defaultRepo = parsed.repo;
4811
+ } else {
4812
+ console.log(chalk6.yellow(" Could not parse repo. Use format: owner/repo or a GitHub URL."));
4813
+ }
4814
+ }
4790
4815
  }
4791
4816
  hr();
4792
4817
  console.log("");