@rafter-security/cli 0.8.10 → 0.9.0

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.
@@ -853,6 +853,59 @@ function hermesMcp() {
853
853
  },
854
854
  };
855
855
  }
856
+ /**
857
+ * OpenCode MCP server entry (~/.config/opencode/opencode.json).
858
+ *
859
+ * OpenCode's schema differs from Cursor/Windsurf: the block is `mcp` (not
860
+ * `mcpServers`), each local server carries `type: "local"`, and command + args
861
+ * are a single `command` array. Verified against
862
+ * https://opencode.ai/docs/mcp-servers/ (sable-l8e5).
863
+ */
864
+ function openCodeMcp() {
865
+ const home = os.homedir();
866
+ const configPath = path.join(home, ".config", "opencode", "opencode.json");
867
+ const entry = {
868
+ type: "local",
869
+ command: [RAFTER_MCP_ENTRY.command, ...RAFTER_MCP_ENTRY.args],
870
+ enabled: true,
871
+ };
872
+ return {
873
+ id: "opencode.mcp",
874
+ platform: "opencode",
875
+ kind: "mcp",
876
+ description: "OpenCode MCP server entry (~/.config/opencode/opencode.json)",
877
+ detectDir: path.join(home, ".config", "opencode"),
878
+ path: configPath,
879
+ isInstalled: () => {
880
+ if (!fs.existsSync(configPath))
881
+ return false;
882
+ const cfg = readJson(configPath);
883
+ return !!cfg.mcp?.rafter;
884
+ },
885
+ install: () => {
886
+ const dir = path.join(home, ".config", "opencode");
887
+ if (!fs.existsSync(dir))
888
+ fs.mkdirSync(dir, { recursive: true });
889
+ let cfg = fs.existsSync(configPath) ? readJson(configPath) : {};
890
+ // Guard against valid-but-non-object top-level JSON (array/string/number).
891
+ if (!cfg || typeof cfg !== "object" || Array.isArray(cfg))
892
+ cfg = {};
893
+ if (!cfg.$schema)
894
+ cfg.$schema = "https://opencode.ai/config.json";
895
+ if (!cfg.mcp || typeof cfg.mcp !== "object" || Array.isArray(cfg.mcp))
896
+ cfg.mcp = {};
897
+ cfg.mcp.rafter = { ...entry };
898
+ writeJson(configPath, cfg);
899
+ },
900
+ uninstall: () => {
901
+ if (!fs.existsSync(configPath))
902
+ return;
903
+ const cfg = readJson(configPath);
904
+ if (removeKey(cfg.mcp, "rafter"))
905
+ writeJson(configPath, cfg);
906
+ },
907
+ };
908
+ }
856
909
  /**
857
910
  * Aider read-only context: writes RAFTER.md and adds it to .aider.conf.yml `read:`.
858
911
  *
@@ -1001,6 +1054,7 @@ export function getComponentRegistry() {
1001
1054
  continueMcp(),
1002
1055
  aiderRead(),
1003
1056
  hermesMcp(),
1057
+ openCodeMcp(),
1004
1058
  openclawSkill(),
1005
1059
  ];
1006
1060
  }
@@ -144,6 +144,11 @@ function printDryRunPlan(plan) {
144
144
  console.log("Hermes (--with-hermes):");
145
145
  W(path.join(plan.root, ".hermes", "config.yaml"), "mcp_servers.rafter entry merged into existing YAML");
146
146
  }
147
+ if (plan.wantOpenCode) {
148
+ console.log();
149
+ console.log("OpenCode (--with-opencode):");
150
+ W(path.join(plan.root, ".config", "opencode", "opencode.json"), "mcp.rafter local/stdio entry merged into existing JSON");
151
+ }
147
152
  if (plan.wantOpenClaw) {
148
153
  console.log();
149
154
  console.log("OpenClaw (--with-openclaw):");
@@ -772,6 +777,60 @@ function installHermesMcp(root) {
772
777
  console.log(fmt.success(`Installed Rafter MCP server to ${configPath}`));
773
778
  return true;
774
779
  }
780
+ /**
781
+ * OpenCode MCP server entry. OpenCode's schema differs from Cursor/Windsurf:
782
+ * the block is `mcp` (not `mcpServers`), each local server has `type: "local"`,
783
+ * and the command + args are a single `command` array (not split). Verified
784
+ * against https://opencode.ai/docs/mcp-servers/ (rf-opencode).
785
+ */
786
+ const RAFTER_OPENCODE_MCP_ENTRY = {
787
+ type: "local",
788
+ command: [RAFTER_MCP_ENTRY.command, ...RAFTER_MCP_ENTRY.args],
789
+ enabled: true,
790
+ };
791
+ /**
792
+ * Install MCP server config for OpenCode (~/.config/opencode/opencode.json).
793
+ *
794
+ * OpenCode reads a global config at ~/.config/opencode/opencode.json and a
795
+ * project-level opencode.json (project takes precedence). We register the
796
+ * local stdio server `rafter mcp serve` under the `mcp` block. The `$schema`
797
+ * pointer is seeded on first write so editors get completion. Any existing
798
+ * keys / other MCP servers are preserved.
799
+ */
800
+ function installOpenCodeMcp(root) {
801
+ const openCodeDir = path.join(root, ".config", "opencode");
802
+ const configPath = path.join(openCodeDir, "opencode.json");
803
+ if (!fs.existsSync(openCodeDir)) {
804
+ fs.mkdirSync(openCodeDir, { recursive: true });
805
+ }
806
+ let config = {};
807
+ if (fs.existsSync(configPath)) {
808
+ try {
809
+ const parsed = JSON.parse(fs.readFileSync(configPath, "utf-8"));
810
+ // Guard against valid-but-non-object top-level JSON (array/string/number).
811
+ // Mirrors the Python `isinstance(loaded, dict)` check so a wrong-shaped
812
+ // file is replaced rather than silently mangled by property assignment.
813
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
814
+ config = parsed;
815
+ }
816
+ else {
817
+ console.log(fmt.warning("Existing OpenCode opencode.json was not a JSON object, creating new one"));
818
+ }
819
+ }
820
+ catch {
821
+ console.log(fmt.warning("Existing OpenCode opencode.json was unreadable, creating new one"));
822
+ }
823
+ }
824
+ if (!config.$schema)
825
+ config.$schema = "https://opencode.ai/config.json";
826
+ if (!config.mcp || typeof config.mcp !== "object" || Array.isArray(config.mcp)) {
827
+ config.mcp = {};
828
+ }
829
+ config.mcp.rafter = { ...RAFTER_OPENCODE_MCP_ENTRY };
830
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2), "utf-8");
831
+ console.log(fmt.success(`Installed Rafter MCP server to ${configPath}`));
832
+ return true;
833
+ }
775
834
  function installAiderRead(root) {
776
835
  const rafterMdPath = path.join(root, "RAFTER.md");
777
836
  const configPath = path.join(root, ".aider.conf.yml");
@@ -942,6 +1001,7 @@ export function createInitCommand() {
942
1001
  .option("--with-windsurf", "Install Windsurf integration")
943
1002
  .option("--with-continue", "Install Continue.dev integration")
944
1003
  .option("--with-hermes", "Install Hermes integration")
1004
+ .option("--with-opencode", "Install OpenCode integration")
945
1005
  .option("--with-betterleaks", "Download and install Betterleaks binary")
946
1006
  .option("--with-skill-scanner", "Install the optional skill-scanner deep engine (heavy; audit-skill --deep)")
947
1007
  .option("--all", "Install all detected integrations and download Betterleaks")
@@ -974,6 +1034,7 @@ export function createInitCommand() {
974
1034
  const hasContinueDev = scope === "user" && fs.existsSync(path.join(os.homedir(), ".continue"));
975
1035
  const hasAider = scope === "user" && fs.existsSync(path.join(os.homedir(), ".aider.conf.yml"));
976
1036
  const hasHermes = scope === "user" && fs.existsSync(path.join(os.homedir(), ".hermes"));
1037
+ const hasOpenCode = scope === "user" && fs.existsSync(path.join(os.homedir(), ".config", "opencode"));
977
1038
  // Resolve opt-in flags (--all enables all detected, --interactive prompts).
978
1039
  // In --local scope, --all is restricted to platforms that have a project-local
979
1040
  // config story (claudeCode, codex, gemini, cursor). The rest require user scope.
@@ -1000,6 +1061,12 @@ export function createInitCommand() {
1000
1061
  // reads ~/.hermes/config.yaml; the project-local install story isn't
1001
1062
  // established. Excluded from --all in --local for the same reason.
1002
1063
  let wantHermes = opts.withHermes || (opts.all && !opts.local);
1064
+ // OpenCode: MCP-based, user scope only. OpenCode reads a global config at
1065
+ // ~/.config/opencode/opencode.json; a project-local install story via
1066
+ // --local isn't wired here, so (like Hermes) it's excluded from --all in
1067
+ // --local scope. It supports MCP local/stdio servers and AGENTS.md
1068
+ // natively (https://opencode.ai/docs/mcp-servers/, sable-l8e5).
1069
+ let wantOpenCode = opts.withOpencode || (opts.all && !opts.local);
1003
1070
  let wantBetterleaks = opts.withBetterleaks || (opts.all && !opts.local);
1004
1071
  // skill-scanner is heavy and opt-in only — deliberately NOT folded into --all.
1005
1072
  const wantSkillScanner = !!opts.withSkillScanner;
@@ -1026,6 +1093,8 @@ export function createInitCommand() {
1026
1093
  wantAider = await askYesNo("Install Aider MCP server?");
1027
1094
  if (hasHermes && !wantHermes)
1028
1095
  wantHermes = await askYesNo("Install Hermes MCP server?");
1096
+ if (hasOpenCode && !wantOpenCode)
1097
+ wantOpenCode = await askYesNo("Install OpenCode MCP server?");
1029
1098
  if (!wantBetterleaks)
1030
1099
  wantBetterleaks = await askYesNo("Download Betterleaks binary (enhanced scanning)?");
1031
1100
  console.log();
@@ -1050,6 +1119,8 @@ export function createInitCommand() {
1050
1119
  detected.push("Aider");
1051
1120
  if (hasHermes)
1052
1121
  detected.push("Hermes");
1122
+ if (hasOpenCode)
1123
+ detected.push("OpenCode");
1053
1124
  if (detected.length > 0) {
1054
1125
  console.log(fmt.info(`Detected environments: ${detected.join(", ")}`));
1055
1126
  }
@@ -1077,6 +1148,8 @@ export function createInitCommand() {
1077
1148
  console.log(fmt.warning("Aider requested but not detected (~/.aider.conf.yml not found)"));
1078
1149
  if (wantHermes && !hasHermes)
1079
1150
  console.log(fmt.warning("Hermes requested but not detected (~/.hermes not found)"));
1151
+ if (wantOpenCode && !hasOpenCode)
1152
+ console.log(fmt.warning("OpenCode requested but not detected (~/.config/opencode not found)"));
1080
1153
  }
1081
1154
  // --dry-run: print every file path the command would touch, then
1082
1155
  // exit before any filesystem write happens (rf-hrtd). The plan is
@@ -1095,6 +1168,7 @@ export function createInitCommand() {
1095
1168
  wantContinue: wantContinue && (hasContinueDev || opts.local),
1096
1169
  wantAider: wantAider && (hasAider || opts.local),
1097
1170
  wantHermes: wantHermes && hasHermes,
1171
+ wantOpenCode: wantOpenCode && hasOpenCode,
1098
1172
  wantBetterleaks,
1099
1173
  wantSkillScanner,
1100
1174
  riskLevel: opts.riskLevel,
@@ -1389,6 +1463,21 @@ export function createInitCommand() {
1389
1463
  console.error(fmt.error(`Failed to install Hermes integration: ${e}`));
1390
1464
  }
1391
1465
  }
1466
+ // Install OpenCode integration if opted in (sable-l8e5).
1467
+ // User scope only — OpenCode reads a global config at
1468
+ // ~/.config/opencode/opencode.json. MCP-based: we register the local
1469
+ // stdio server `rafter mcp serve` under the `mcp` block.
1470
+ let openCodeOk = false;
1471
+ if (wantOpenCode && hasOpenCode) {
1472
+ try {
1473
+ openCodeOk = installOpenCodeMcp(root);
1474
+ if (openCodeOk)
1475
+ manager.set("agent.environments.opencode.enabled", true);
1476
+ }
1477
+ catch (e) {
1478
+ console.error(fmt.error(`Failed to install OpenCode integration: ${e}`));
1479
+ }
1480
+ }
1392
1481
  // Install global instruction files for platforms that support them.
1393
1482
  // Cursor is intentionally absent — Cursor uses per-skill rules + the
1394
1483
  // rafter sub-agent installed in the Cursor branch above (rf-svn3).
@@ -1401,7 +1490,7 @@ export function createInitCommand() {
1401
1490
  console.log();
1402
1491
  console.log(fmt.success("Agent security initialized!"));
1403
1492
  console.log();
1404
- const anyIntegration = openclawOk || claudeCodeOk || codexOk || geminiOk || cursorOk || windsurfOk || continueOk || aiderOk;
1493
+ const anyIntegration = openclawOk || claudeCodeOk || codexOk || geminiOk || cursorOk || windsurfOk || continueOk || aiderOk || hermesOk || openCodeOk;
1405
1494
  if (anyIntegration) {
1406
1495
  console.log("Next steps:");
1407
1496
  if (openclawOk)
@@ -1420,6 +1509,10 @@ export function createInitCommand() {
1420
1509
  console.log(" - Restart Continue.dev to load MCP server");
1421
1510
  if (aiderOk)
1422
1511
  console.log(" - Restart Aider to load RAFTER.md from .aider.conf.yml read:");
1512
+ if (hermesOk)
1513
+ console.log(" - Restart Hermes to load MCP server");
1514
+ if (openCodeOk)
1515
+ console.log(" - Restart OpenCode to load MCP server");
1423
1516
  }
1424
1517
  else if (scope === "project") {
1425
1518
  console.log("No integrations were installed. In --local mode, pass one or more opt-in flags:");
@@ -1449,6 +1542,8 @@ export function createInitCommand() {
1449
1542
  console.log(" rafter agent init --with-aider # Aider only");
1450
1543
  if (hasHermes)
1451
1544
  console.log(" rafter agent init --with-hermes # Hermes only");
1545
+ if (hasOpenCode)
1546
+ console.log(" rafter agent init --with-opencode # OpenCode only");
1452
1547
  }
1453
1548
  else {
1454
1549
  console.log("No agent environments detected. Install an agent tool and re-run with --with-<tool>.");
@@ -148,6 +148,7 @@ export function createStatusCommand() {
148
148
  { name: "Windsurf", flag: "--with-windsurf", configDir: path.join(home, ".codeium", "windsurf"), configFile: path.join(home, ".codeium", "windsurf", "mcp_config.json"), needle: "rafter" },
149
149
  { name: "Continue.dev", flag: "--with-continue", configDir: path.join(home, ".continue"), configFile: path.join(home, ".continue", "config.json"), needle: "rafter" },
150
150
  { name: "Hermes", flag: "--with-hermes", configDir: path.join(home, ".hermes"), configFile: path.join(home, ".hermes", "config.yaml"), needle: "rafter" },
151
+ { name: "OpenCode", flag: "--with-opencode", configDir: path.join(home, ".config", "opencode"), configFile: path.join(home, ".config", "opencode", "opencode.json"), needle: "rafter" },
151
152
  ];
152
153
  for (const agent of mcpAgents) {
153
154
  const label = `${agent.name}:`.padEnd(14);
@@ -251,6 +252,7 @@ function detectAgents(home) {
251
252
  ["continue", path.join(home, ".continue")],
252
253
  ["aider", path.join(home, ".aider.conf.yml")],
253
254
  ["hermes", path.join(home, ".hermes")],
255
+ ["opencode", path.join(home, ".config", "opencode")],
254
256
  ];
255
257
  return candidates
256
258
  .filter(([, p]) => fs.existsSync(p))
@@ -287,6 +287,34 @@ function checkHermes() {
287
287
  return { name, passed: false, optional: true, detail: `Cannot read config: ${e}` };
288
288
  }
289
289
  }
290
+ function checkOpenCode() {
291
+ // OpenCode uses ~/.config/opencode/opencode.json with an `mcp` block
292
+ // (local/stdio servers carry type: "local"; sable-l8e5).
293
+ const name = "OpenCode";
294
+ const homeDir = os.homedir();
295
+ const openCodeDir = path.join(homeDir, ".config", "opencode");
296
+ if (!fs.existsSync(openCodeDir)) {
297
+ return { name, passed: false, optional: true, detail: `Not detected — run 'rafter agent init --with-opencode' to enable` };
298
+ }
299
+ const configPath = path.join(openCodeDir, "opencode.json");
300
+ if (!fs.existsSync(configPath)) {
301
+ return { name, passed: false, optional: true, detail: `Config not found: ${configPath} — run 'rafter agent init --with-opencode'` };
302
+ }
303
+ try {
304
+ const loaded = JSON.parse(fs.readFileSync(configPath, "utf-8"));
305
+ const servers = (loaded && typeof loaded === "object" && !Array.isArray(loaded))
306
+ ? loaded.mcp
307
+ : undefined;
308
+ const hasRafterMcp = servers && typeof servers === "object" && servers.rafter != null;
309
+ if (!hasRafterMcp) {
310
+ return { name, passed: false, optional: true, detail: "Rafter MCP server not configured — run 'rafter agent init --with-opencode'" };
311
+ }
312
+ return { name, passed: true, detail: "MCP server configured" };
313
+ }
314
+ catch (e) {
315
+ return { name, passed: false, optional: true, detail: `Cannot read config: ${e}` };
316
+ }
317
+ }
290
318
  /**
291
319
  * Probe the Claude Code hook integration end-to-end (rf-65zg).
292
320
  *
@@ -378,6 +406,7 @@ export function createVerifyCommand() {
378
406
  checkContinueDev(),
379
407
  checkAider(),
380
408
  checkHermes(),
409
+ checkOpenCode(),
381
410
  ];
382
411
  if (opts.probe) {
383
412
  // Only Claude Code has a probe today (rf-65zg). Codex/Cursor/Gemini
@@ -11,8 +11,13 @@ export async function runRemoteScan(opts) {
11
11
  const key = resolveKey(opts.apiKey);
12
12
  const ghToken = opts.githubToken || process.env.RAFTER_GITHUB_TOKEN;
13
13
  let repo, branch;
14
+ let detectedProvider, detectedRepoUrl;
14
15
  try {
15
- ({ repo, branch } = detectRepo({ repo: opts.repo, branch: opts.branch, quiet: opts.quiet }));
16
+ ({ repo, branch, provider: detectedProvider, repo_url: detectedRepoUrl } = detectRepo({
17
+ repo: opts.repo,
18
+ branch: opts.branch,
19
+ quiet: opts.quiet,
20
+ }));
16
21
  }
17
22
  catch (e) {
18
23
  if (e instanceof Error) {
@@ -23,6 +28,9 @@ export async function runRemoteScan(opts) {
23
28
  }
24
29
  process.exit(EXIT_GENERAL_ERROR);
25
30
  }
31
+ // Explicit flags override inferred values.
32
+ const provider = opts.provider ?? detectedProvider;
33
+ const repoUrl = opts.repoUrl ?? detectedRepoUrl;
26
34
  const body = {
27
35
  repository_name: repo,
28
36
  branch_name: branch,
@@ -30,6 +38,13 @@ export async function runRemoteScan(opts) {
30
38
  };
31
39
  if (ghToken)
32
40
  body.github_token = ghToken;
41
+ // Additive, backward-compatible: only send provider + repo_url for non-github
42
+ // remotes. For github (or an unknown host that defaulted to github), omit both
43
+ // so the request body is byte-identical to the legacy github-only behavior.
44
+ if (provider && provider !== "github" && repoUrl) {
45
+ body.provider = provider;
46
+ body.repo_url = repoUrl;
47
+ }
33
48
  if (!opts.quiet) {
34
49
  const spinner = ora("Submitting scan").start();
35
50
  try {
@@ -99,6 +114,8 @@ function addRunOptions(cmd) {
99
114
  .option("-f, --format <format>", "json | md", "md")
100
115
  .option("-m, --mode <mode>", "scan mode: fast | plus", "fast")
101
116
  .option("--github-token <token>", "GitHub PAT for private repos (or RAFTER_GITHUB_TOKEN env var)")
117
+ .option("--provider <provider>", "git provider: gitlab | gitea | bitbucket (default: auto-detected; github requires nothing)")
118
+ .option("--repo-url <url>", "full https clone URL for non-github remotes (default: auto-detected)")
102
119
  .option("--skip-interactive", "do not wait for scan to complete")
103
120
  .option("--quiet", "suppress status messages");
104
121
  }
@@ -23,6 +23,8 @@ export function createScanGroupCommand() {
23
23
  .option("-f, --format <format>", "json | md", "md")
24
24
  .option("-m, --mode <mode>", "scan mode: fast | plus", "fast")
25
25
  .option("--github-token <token>", "GitHub PAT for private repos (or RAFTER_GITHUB_TOKEN env var)")
26
+ .option("--provider <provider>", "git provider: gitlab | gitea | bitbucket (default: auto-detected; github requires nothing)")
27
+ .option("--repo-url <url>", "full https clone URL for non-github remotes (default: auto-detected)")
26
28
  .option("--skip-interactive", "do not wait for scan to complete")
27
29
  .option("--quiet", "suppress status messages")
28
30
  .action(async (opts) => {
@@ -38,6 +40,8 @@ export function createScanGroupCommand() {
38
40
  .option("-f, --format <format>", "json | md", "md")
39
41
  .option("-m, --mode <mode>", "scan mode: fast | plus", "fast")
40
42
  .option("--github-token <token>", "GitHub PAT for private repos (or RAFTER_GITHUB_TOKEN env var)")
43
+ .option("--provider <provider>", "git provider: gitlab | gitea | bitbucket (default: auto-detected; github requires nothing)")
44
+ .option("--repo-url <url>", "full https clone URL for non-github remotes (default: auto-detected)")
41
45
  .option("--skip-interactive", "do not wait for scan to complete")
42
46
  .option("--quiet", "suppress status messages");
43
47
  scanGroup.addCommand(localCmd, { hidden: true });
@@ -146,6 +146,13 @@ export const DEFAULT_SECRET_PATTERNS = [
146
146
  regex: "pypi-AgEIcHlwaS5vcmc[A-Za-z0-9\\-_]{50,1024}",
147
147
  severity: "critical",
148
148
  description: "PyPI API token detected"
149
+ },
150
+ // DigitalOcean
151
+ {
152
+ name: "DigitalOcean Personal Access Token",
153
+ regex: "dop_v1_[a-f0-9]{64}",
154
+ severity: "critical",
155
+ description: "DigitalOcean Personal Access Token detected"
149
156
  }
150
157
  ];
151
158
  /**
package/dist/utils/git.js CHANGED
@@ -19,19 +19,78 @@ export function parseRemote(url) {
19
19
  const parts = url.split("/");
20
20
  return parts.slice(-2).join("/"); // owner/repo
21
21
  }
22
+ /**
23
+ * Map a git remote host to a provider. `github` is the backward-compatible
24
+ * default for any host we don't recognize — a GitHub user's request is
25
+ * unaffected, and unknown self-hosted hosts fall back to the legacy behavior.
26
+ */
27
+ export function providerForHost(host) {
28
+ host = host.toLowerCase();
29
+ if (host === "github.com")
30
+ return "github";
31
+ if (host === "gitlab.com" || host.endsWith(".gitlab.com"))
32
+ return "gitlab";
33
+ if (host === "bitbucket.org")
34
+ return "bitbucket";
35
+ if (host === "codeberg.org" || host.endsWith(".gitea.io"))
36
+ return "gitea";
37
+ return "github"; // backward-compatible default
38
+ }
39
+ /**
40
+ * Split a git remote URL into its host + owner/repo slug, handling both
41
+ * `git@host:owner/repo(.git)` (scp-like) and `https://host/owner/repo(.git)`.
42
+ * Returns null when the URL can't be parsed into host + slug.
43
+ */
44
+ function splitRemote(url) {
45
+ let rest = url.replace(/^(https?:\/\/|git@)/, "").replace(":", "/");
46
+ if (rest.endsWith(".git"))
47
+ rest = rest.slice(0, -4);
48
+ const parts = rest.split("/").filter((p) => p.length > 0);
49
+ if (parts.length < 3)
50
+ return null; // need host + owner + repo
51
+ const host = parts[0];
52
+ const slug = parts.slice(-2).join("/");
53
+ return { host, slug };
54
+ }
55
+ /**
56
+ * Infer the provider and a canonical `https://<host>/<owner>/<repo>` clone URL
57
+ * from a git remote (either scp-like `git@` or `https://` form). Falls back to
58
+ * `{ provider: "github", repoUrl: undefined }` when the URL can't be parsed.
59
+ */
60
+ export function inferRemote(url) {
61
+ const parts = splitRemote(url);
62
+ if (!parts)
63
+ return { provider: "github" };
64
+ return {
65
+ provider: providerForHost(parts.host),
66
+ repoUrl: `https://${parts.host}/${parts.slug}`,
67
+ };
68
+ }
22
69
  export function detectRepo(opts) {
70
+ // Both explicit — return them as-is. No provider/repo_url is inferred here;
71
+ // the caller's --provider/--repo-url flags fill that in when needed.
23
72
  if (opts.repo && opts.branch)
24
- return opts;
73
+ return { repo: opts.repo, branch: opts.branch };
25
74
  const repoEnv = process.env.GITHUB_REPOSITORY || process.env.CI_REPOSITORY;
26
75
  const branchEnv = process.env.GITHUB_REF_NAME || process.env.CI_COMMIT_BRANCH || process.env.CI_BRANCH;
27
76
  let repoSlug = opts.repo || repoEnv;
28
77
  let branch = opts.branch || branchEnv;
78
+ let provider;
79
+ let repoUrl;
29
80
  try {
30
81
  if (!repoSlug || !branch) {
31
82
  if (git("rev-parse --is-inside-work-tree") !== "true")
32
83
  throw new Error("not a repo");
33
- if (!repoSlug)
34
- repoSlug = parseRemote(git("remote get-url origin"));
84
+ // Read the remote once when we need to detect the slug, and reuse it to
85
+ // infer the provider + canonical clone URL. When repo/branch come from
86
+ // env (CI), we never touch git here — behavior is byte-identical.
87
+ if (!repoSlug) {
88
+ const remoteUrl = git("remote get-url origin");
89
+ repoSlug = parseRemote(remoteUrl);
90
+ const inferred = inferRemote(remoteUrl);
91
+ provider = inferred.provider;
92
+ repoUrl = inferred.repoUrl;
93
+ }
35
94
  if (!branch) {
36
95
  try {
37
96
  branch = safeBranch(git);
@@ -44,7 +103,7 @@ export function detectRepo(opts) {
44
103
  if ((!opts.repo || !opts.branch) && !opts.quiet) {
45
104
  console.error(`Repo auto-detected: ${repoSlug} @ ${branch} (note: scanning remote)`);
46
105
  }
47
- return { repo: repoSlug, branch };
106
+ return { repo: repoSlug, branch, provider, repo_url: repoUrl };
48
107
  }
49
108
  catch {
50
109
  throw new Error("Could not auto-detect Git repository. Please pass --repo and --branch explicitly.");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rafter-security/cli",
3
- "version": "0.8.10",
3
+ "version": "0.9.0",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: rafter-security
3
3
  description: Security toolkit for AI workflows. Use when scanning code or repos for vulnerabilities, auditing third-party skills/MCPs/agent configs before installing, evaluating shell commands before running them, or generating secure design questions for new features. Provides `rafter run` (remote SAST + SCA, needs RAFTER_API_KEY), `rafter secrets` (offline secrets-only), `rafter agent exec --dry-run` (command-risk classification), and `rafter skill review`.
4
- version: 0.8.10
4
+ version: 0.9.0
5
5
  homepage: https://rafter.so
6
6
  metadata:
7
7
  openclaw: