@supabeast/mcp 0.1.1 → 0.2.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.
- package/README.md +10 -2
- package/package.json +5 -2
- package/skills/supabeast/SKILL.md +1 -1
- package/src/api.mjs +383 -0
- package/src/browser.mjs +195 -0
- package/src/check.mjs +17 -14
- package/src/clients.mjs +311 -72
- package/src/constants.mjs +11 -2
- package/src/credentials.mjs +109 -0
- package/src/index.mjs +1316 -110
- package/src/local-project.mjs +110 -0
- package/src/prompt.mjs +56 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
const PROJECT_REF_RE = /^[a-z]{20}$/;
|
|
5
|
+
const GITHUB_HTTPS_RE = /^https?:\/\/(?:[^@/\s]+@)?github\.com\/([A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+?)(?:\.git)?\/?$/i;
|
|
6
|
+
const GITHUB_SSH_RE = /^(?:ssh:\/\/)?git@github\.com[:/]([A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+?)(?:\.git)?\/?$/i;
|
|
7
|
+
const GIT_SECTION_RE = /^\s*\[(.+)\]\s*$/;
|
|
8
|
+
const GIT_URL_RE = /^\s*url\s*=\s*(.+?)\s*(?:#.*)?$/;
|
|
9
|
+
|
|
10
|
+
/** Parse a GitHub `owner/repo` slug from common HTTPS or SSH remote URLs. */
|
|
11
|
+
export function parseGitHubRemote(remoteUrl) {
|
|
12
|
+
if (typeof remoteUrl !== "string") return null;
|
|
13
|
+
const trimmed = remoteUrl.trim();
|
|
14
|
+
const match = GITHUB_HTTPS_RE.exec(trimmed) ?? GITHUB_SSH_RE.exec(trimmed);
|
|
15
|
+
return match?.[1] ?? null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function resolveGitDirectories(cwd, pathApi) {
|
|
19
|
+
const dotGit = pathApi.join(cwd, ".git");
|
|
20
|
+
if (!existsSync(dotGit)) return null;
|
|
21
|
+
try {
|
|
22
|
+
const stats = statSync(dotGit);
|
|
23
|
+
if (stats.isDirectory()) {
|
|
24
|
+
return { gitDir: dotGit, commonDir: dotGit };
|
|
25
|
+
}
|
|
26
|
+
if (stats.isFile()) {
|
|
27
|
+
const content = readFileSync(dotGit, "utf8");
|
|
28
|
+
const match = /^gitdir:\s*(.+)$/m.exec(content);
|
|
29
|
+
if (!match?.[1]) return null;
|
|
30
|
+
const gitDir = pathApi.resolve(cwd, match[1].trim());
|
|
31
|
+
const commonDirFile = pathApi.join(gitDir, "commondir");
|
|
32
|
+
const commonDir = existsSync(commonDirFile)
|
|
33
|
+
? pathApi.resolve(gitDir, readFileSync(commonDirFile, "utf8").trim())
|
|
34
|
+
: gitDir;
|
|
35
|
+
return { gitDir, commonDir };
|
|
36
|
+
}
|
|
37
|
+
} catch {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function parseGitConfigRemotes(configText) {
|
|
44
|
+
const remotes = new Map();
|
|
45
|
+
let currentRemote = null;
|
|
46
|
+
for (const line of configText.split(/\r?\n/)) {
|
|
47
|
+
const section = GIT_SECTION_RE.exec(line);
|
|
48
|
+
if (section) {
|
|
49
|
+
const remoteMatch = /^remote\s+"([^"]+)"$/i.exec(section[1].trim());
|
|
50
|
+
currentRemote = remoteMatch?.[1] ?? null;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (!currentRemote) continue;
|
|
54
|
+
const urlMatch = GIT_URL_RE.exec(line);
|
|
55
|
+
if (urlMatch?.[1]) {
|
|
56
|
+
remotes.set(currentRemote, urlMatch[1]);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const preferred = remotes.get("origin") ?? [...remotes.values()][0] ?? null;
|
|
60
|
+
return preferred ? parseGitHubRemote(preferred) : null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function readGitBranch(gitDir, pathApi) {
|
|
64
|
+
const headPath = pathApi.join(gitDir, "HEAD");
|
|
65
|
+
if (!existsSync(headPath)) return null;
|
|
66
|
+
try {
|
|
67
|
+
const raw = readFileSync(headPath, "utf8").trim();
|
|
68
|
+
if (raw.startsWith("ref: refs/heads/")) {
|
|
69
|
+
return raw.slice("ref: refs/heads/".length).trim() || null;
|
|
70
|
+
}
|
|
71
|
+
} catch {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Detect local Supabase CLI project ref (`supabase/.temp/project-ref`) and GitHub remote/branch in `cwd`. */
|
|
78
|
+
export function detectLocalProject(options = {}) {
|
|
79
|
+
const { cwd = process.cwd(), pathApi = path } = options;
|
|
80
|
+
|
|
81
|
+
let supabaseProjectRef = null;
|
|
82
|
+
const refPath = pathApi.join(cwd, "supabase", ".temp", "project-ref");
|
|
83
|
+
if (existsSync(refPath)) {
|
|
84
|
+
try {
|
|
85
|
+
const candidate = readFileSync(refPath, "utf8").trim();
|
|
86
|
+
if (PROJECT_REF_RE.test(candidate)) {
|
|
87
|
+
supabaseProjectRef = candidate;
|
|
88
|
+
}
|
|
89
|
+
} catch {
|
|
90
|
+
supabaseProjectRef = null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
let githubRepository = null;
|
|
95
|
+
let gitBranch = null;
|
|
96
|
+
const gitDirs = resolveGitDirectories(cwd, pathApi);
|
|
97
|
+
if (gitDirs) {
|
|
98
|
+
gitBranch = readGitBranch(gitDirs.gitDir, pathApi);
|
|
99
|
+
const configPath = pathApi.join(gitDirs.commonDir, "config");
|
|
100
|
+
if (existsSync(configPath)) {
|
|
101
|
+
try {
|
|
102
|
+
githubRepository = parseGitConfigRemotes(readFileSync(configPath, "utf8"));
|
|
103
|
+
} catch {
|
|
104
|
+
githubRepository = null;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return { supabaseProjectRef, githubRepository, gitBranch };
|
|
110
|
+
}
|
package/src/prompt.mjs
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import readline from "node:readline/promises";
|
|
2
|
+
|
|
3
|
+
/** Return true when both stdin and stdout are attached to an interactive terminal. */
|
|
4
|
+
export function isInteractiveTerminal(stdin = process.stdin, stdout = process.stdout) {
|
|
5
|
+
return Boolean(stdin?.isTTY && stdout?.isTTY);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/** Create an interactive CLI prompter backed by Node's built-in readline/promises interface. */
|
|
9
|
+
export function createTerminalPrompter(options = {}) {
|
|
10
|
+
const { stdin = process.stdin, stdout = process.stdout } = options;
|
|
11
|
+
|
|
12
|
+
async function askLine(question) {
|
|
13
|
+
const rl = readline.createInterface({ input: stdin, output: stdout });
|
|
14
|
+
try {
|
|
15
|
+
return (await rl.question(question)).trim();
|
|
16
|
+
} finally {
|
|
17
|
+
rl.close();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
async confirm(question, defaultYes = true) {
|
|
23
|
+
const suffix = defaultYes ? " [Y/n]: " : " [y/N]: ";
|
|
24
|
+
const answer = (await askLine(`${question}${suffix}`)).toLowerCase();
|
|
25
|
+
if (!answer) return defaultYes;
|
|
26
|
+
return answer === "y" || answer === "yes";
|
|
27
|
+
},
|
|
28
|
+
async input(question, defaultValue = "") {
|
|
29
|
+
const suffix = defaultValue ? ` [${defaultValue}]: ` : ": ";
|
|
30
|
+
const answer = await askLine(`${question}${suffix}`);
|
|
31
|
+
return answer || defaultValue;
|
|
32
|
+
},
|
|
33
|
+
async select(question, items, defaultIndex = 0) {
|
|
34
|
+
if (!Array.isArray(items) || items.length === 0) {
|
|
35
|
+
throw Error("No options available to select.");
|
|
36
|
+
}
|
|
37
|
+
const safeDefault =
|
|
38
|
+
defaultIndex >= 0 && defaultIndex < items.length ? defaultIndex : 0;
|
|
39
|
+
stdout.write(`${question}\n`);
|
|
40
|
+
for (let i = 0; i < items.length; i++) {
|
|
41
|
+
const item = items[i];
|
|
42
|
+
const tag = item.badge ? ` (${item.badge})` : i === safeDefault ? " (default)" : "";
|
|
43
|
+
stdout.write(` [${i + 1}] ${item.label}${tag}\n`);
|
|
44
|
+
}
|
|
45
|
+
const answer = await askLine(`Enter choice [1-${items.length}, default ${safeDefault + 1}]: `);
|
|
46
|
+
if (!answer) return items[safeDefault].value;
|
|
47
|
+
const numeric = Number.parseInt(answer, 10);
|
|
48
|
+
if (Number.isInteger(numeric) && numeric >= 1 && numeric <= items.length) {
|
|
49
|
+
return items[numeric - 1].value;
|
|
50
|
+
}
|
|
51
|
+
const direct = items.find((item) => item.value === answer || item.label === answer);
|
|
52
|
+
if (direct) return direct.value;
|
|
53
|
+
throw Error(`Invalid selection: ${answer}`);
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|