sodabase 0.1.8 → 0.1.10
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 +17 -1
- package/dist/agentPicker.js +58 -0
- package/dist/api/client.js +21 -4
- package/dist/api/fakeClient.js +8 -2
- package/dist/api/types.js +4 -4
- package/dist/cli.js +49 -0
- package/dist/installMcp.js +171 -0
- package/dist/ui.js +163 -79
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,13 +22,29 @@ node dist/cli.js # run the built CLI
|
|
|
22
22
|
npm run dev # node --experimental-strip-types src/cli.tsx
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
+
## Install just the MCP
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npx sodabase install-mcp # checkbox list, agents found locally pre-ticked
|
|
29
|
+
npx sodabase install-mcp -a cursor -a codex # or --agent cursor,codex / --all
|
|
30
|
+
npx sodabase install-mcp --no-skill # MCP only, skip the trust-advisor skill
|
|
31
|
+
npx sodabase install-mcp --no-input # no list: install for the agents found (CI/scripts)
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Without `--agent`, a terminal run shows a checkbox list with the agents found on this
|
|
35
|
+
machine pre-ticked (Claude Code if none); a piped run installs for those directly. Skips the wizard and sign-in (the agent signs in on its first MCP call) and runs the same
|
|
36
|
+
`add-mcp` + `skills add` installs as the hub's "Install MCP" step. Exits 1 only if the MCP
|
|
37
|
+
install fails; a skill failure warns with a manual fallback.
|
|
38
|
+
|
|
25
39
|
Point at a local backend with `SODABASE_API_URL=http://localhost:8080`.
|
|
26
40
|
|
|
27
41
|
## Layout
|
|
28
42
|
|
|
29
43
|
```
|
|
30
44
|
src/
|
|
31
|
-
cli.tsx entry — renders <App/>
|
|
45
|
+
cli.tsx entry — renders <App/> (or runs the install-mcp subcommand)
|
|
46
|
+
installMcp.ts `install-mcp`: arg parsing, agent detection, plain-output install
|
|
47
|
+
agentPicker.tsx `install-mcp`'s inline agent checkbox list
|
|
32
48
|
app.tsx the Ink app (flow orchestrator + screens)
|
|
33
49
|
api/
|
|
34
50
|
client.ts HTTP client for the real endpoints (device grant, onboarding
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// The agent checkbox list: the state + keys (useAgentChecklist) and the rows (AgentChecklist) are shared by the
|
|
3
|
+
// wizard's MCP step (ui.tsx) and `npx sodabase install-mcp`, which renders it inline (no fullscreen) via
|
|
4
|
+
// pickAgents. Agents found on this machine start ticked and are marked "found"; ones that already have the MCP
|
|
5
|
+
// are marked "already set up" and start unticked.
|
|
6
|
+
import { Box, Text, render, useApp, useInput } from "ink";
|
|
7
|
+
import { useState } from "react";
|
|
8
|
+
import { MCP_AGENTS } from "./installMcp.js";
|
|
9
|
+
/** Which agents are ticked + the cursor, and the ↑↓/space handling. `handleKey` returns true if it used the key. */
|
|
10
|
+
export function useAgentChecklist(preselected) {
|
|
11
|
+
const [sel, setSel] = useState(() => MCP_AGENTS.map((a) => preselected.includes(a)));
|
|
12
|
+
const [cursor, setCursor] = useState(0);
|
|
13
|
+
const handleKey = (input, key) => {
|
|
14
|
+
if (key.upArrow)
|
|
15
|
+
setCursor((c) => Math.max(0, c - 1));
|
|
16
|
+
else if (key.downArrow)
|
|
17
|
+
setCursor((c) => Math.min(MCP_AGENTS.length - 1, c + 1));
|
|
18
|
+
else if (input === " ")
|
|
19
|
+
setSel((s) => s.map((v, i) => (i === cursor ? !v : v)));
|
|
20
|
+
else
|
|
21
|
+
return false;
|
|
22
|
+
return true;
|
|
23
|
+
};
|
|
24
|
+
return { sel, cursor, handleKey, picked: () => MCP_AGENTS.filter((_, i) => sel[i]) };
|
|
25
|
+
}
|
|
26
|
+
export function AgentChecklist({ sel, cursor, found, installed }) {
|
|
27
|
+
return (_jsx(Box, { flexDirection: "column", children: MCP_AGENTS.map((a, i) => {
|
|
28
|
+
const on = sel[i];
|
|
29
|
+
return (_jsxs(Text, { color: on ? "green" : undefined, dimColor: !on, children: [i === cursor ? "❯ " : " ", on ? "[x]" : "[ ]", " ", a, installed.includes(a) ? (_jsx(Text, { color: "green", children: " \u00B7 already set up" })) : (found.includes(a) && _jsx(Text, { dimColor: true, children: " \u00B7 found" }))] }, a));
|
|
30
|
+
}) }));
|
|
31
|
+
}
|
|
32
|
+
function AgentPicker({ preselected, found, installed, skill, onDone }) {
|
|
33
|
+
const { exit } = useApp();
|
|
34
|
+
const list = useAgentChecklist(preselected);
|
|
35
|
+
const finish = (agents) => {
|
|
36
|
+
onDone(agents);
|
|
37
|
+
exit();
|
|
38
|
+
};
|
|
39
|
+
useInput((input, key) => {
|
|
40
|
+
if (list.handleKey(input, key))
|
|
41
|
+
return;
|
|
42
|
+
if (key.return)
|
|
43
|
+
finish(list.picked());
|
|
44
|
+
else if (key.escape || input === "q" || (key.ctrl && input === "c"))
|
|
45
|
+
finish(null);
|
|
46
|
+
});
|
|
47
|
+
return (_jsxs(Box, { flexDirection: "column", marginY: 1, children: [_jsxs(Text, { children: ["Install the Sodabase MCP", skill ? " + trust-advisor skill" : "", " for:"] }), _jsx(Box, { marginTop: 1, children: _jsx(AgentChecklist, { sel: list.sel, cursor: list.cursor, found: found, installed: installed }) }), installed.length > 0 && (_jsx(Box, { marginTop: 1, children: _jsx(Text, { dimColor: true, children: "Already set up agents stay as they are unless you tick them (reinstalls)." }) })), _jsx(Box, { marginTop: 1, children: _jsx(Text, { dimColor: true, children: "\u2191\u2193 move \u00B7 space toggle \u00B7 enter install \u00B7 esc cancel" }) })] }));
|
|
48
|
+
}
|
|
49
|
+
/** Show the checkbox list; resolves to the ticked agents, or null if the user cancelled. */
|
|
50
|
+
export async function pickAgents(preselected, found, installed, skill) {
|
|
51
|
+
let picked = null;
|
|
52
|
+
// exitOnCtrlC off: ctrl+c is handled above as a cancel, so we still print a clean "nothing installed".
|
|
53
|
+
const app = render(_jsx(AgentPicker, { preselected: preselected, found: found, installed: installed, skill: skill, onDone: (a) => (picked = a) }), {
|
|
54
|
+
exitOnCtrlC: false,
|
|
55
|
+
});
|
|
56
|
+
await app.waitUntilExit();
|
|
57
|
+
return picked;
|
|
58
|
+
}
|
package/dist/api/client.js
CHANGED
|
@@ -7,7 +7,8 @@ import { existsSync, readFileSync } from "node:fs";
|
|
|
7
7
|
import { join } from "node:path";
|
|
8
8
|
import { emailOtpStart, emailOtpVerify, loopbackSignIn, resolveGoTrueConfig } from "./gotrueAuth.js";
|
|
9
9
|
import { ApiError, } from "./types.js";
|
|
10
|
-
|
|
10
|
+
/** The MCP endpoint on the same origin the client talks to, so a dev install (SODABASE_API_URL) points at the dev MCP. */
|
|
11
|
+
export const MCP_URL = `${(process.env.SODABASE_API_URL ?? "https://sodabase.io").replace(/\/$/, "")}/mcp`;
|
|
11
12
|
/** The trust-advisor skill repo, resolved by the `skills` CLI (owner/repo on its default branch). */
|
|
12
13
|
export const SKILL_REF = "sodabase/agent-skills";
|
|
13
14
|
/** An error thrown when `connect()`'s poll is aborted (the user left the connect screen). */
|
|
@@ -186,6 +187,16 @@ export class SodabaseClient {
|
|
|
186
187
|
await sleepAbortable(2000, signal);
|
|
187
188
|
}
|
|
188
189
|
}
|
|
190
|
+
async listConnections() {
|
|
191
|
+
const rows = await this.get("/connections");
|
|
192
|
+
return Array.isArray(rows)
|
|
193
|
+
? rows.map((c) => ({
|
|
194
|
+
connectionId: c.connection_id,
|
|
195
|
+
status: c.status,
|
|
196
|
+
...(c.org_slug ? { orgSlug: c.org_slug } : {}),
|
|
197
|
+
}))
|
|
198
|
+
: [];
|
|
199
|
+
}
|
|
189
200
|
async listProjects(connectionId) {
|
|
190
201
|
const rows = await this.get(`/connections/${encodeURIComponent(connectionId)}/projects`);
|
|
191
202
|
return rows.map((p) => ({
|
|
@@ -215,12 +226,18 @@ export class SodabaseClient {
|
|
|
215
226
|
return rows.map((p) => ({
|
|
216
227
|
ref: p.ref,
|
|
217
228
|
name: p.name,
|
|
218
|
-
|
|
219
|
-
|
|
229
|
+
// The watched-scoped counts the web app shows — all from the new fields or, on an older API, all from the raw
|
|
230
|
+
// all-tables ones (never mixed, so the breakdown always adds up to the total).
|
|
231
|
+
...(p.issue_count !== undefined && p.broken_rule_count !== undefined && p.data_quality_count !== undefined
|
|
232
|
+
? { issueCount: p.issue_count, dataQualityIssues: p.data_quality_count, brokenRules: p.broken_rule_count }
|
|
233
|
+
: {
|
|
234
|
+
issueCount: (p.open_issues ?? 0) + (p.data_quality_issues ?? 0),
|
|
235
|
+
dataQualityIssues: p.data_quality_issues ?? 0,
|
|
236
|
+
brokenRules: p.broken_rules ?? 0,
|
|
237
|
+
}),
|
|
220
238
|
watched: p.watched ?? 0,
|
|
221
239
|
monitors: p.monitors ?? 0,
|
|
222
240
|
rules: p.rules ?? 0,
|
|
223
|
-
brokenRules: p.broken_rules ?? 0,
|
|
224
241
|
status: p.status ?? "ready",
|
|
225
242
|
}));
|
|
226
243
|
}
|
package/dist/api/fakeClient.js
CHANGED
|
@@ -73,6 +73,12 @@ export class FakeClient {
|
|
|
73
73
|
throw new Error("connect aborted");
|
|
74
74
|
return { connectionId: "conn_demo" };
|
|
75
75
|
}
|
|
76
|
+
async listConnections() {
|
|
77
|
+
// A healthy existing connection, so --demo exercises the reuse path (onboarding skips the fake authorize
|
|
78
|
+
// and lists projects straight away).
|
|
79
|
+
await this.tick(250);
|
|
80
|
+
return [{ connectionId: "conn_demo", status: "connected", orgSlug: "demo-org" }];
|
|
81
|
+
}
|
|
76
82
|
async listProjects(_connectionId) {
|
|
77
83
|
await this.tick(500);
|
|
78
84
|
return [
|
|
@@ -89,8 +95,8 @@ export class FakeClient {
|
|
|
89
95
|
async dashboardProjects() {
|
|
90
96
|
await this.tick(300);
|
|
91
97
|
return [
|
|
92
|
-
{ ref: "supabase-demo", name: "Supabase Demo",
|
|
93
|
-
{ ref: "analytics", name: "Analytics",
|
|
98
|
+
{ ref: "supabase-demo", name: "Supabase Demo", issueCount: 18, dataQualityIssues: 13, watched: 7, monitors: 28, rules: 15, brokenRules: 1, status: "ready" },
|
|
99
|
+
{ ref: "analytics", name: "Analytics", issueCount: 0, dataQualityIssues: 0, watched: 4, monitors: 18, rules: 10, brokenRules: 0, status: "ready" },
|
|
94
100
|
];
|
|
95
101
|
}
|
|
96
102
|
async jobStatus(jobId) {
|
package/dist/api/types.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// Wire types for the Sodabase /api/v1 API, as the v2 CLI consumes them.
|
|
2
2
|
// Verified against the real route definitions on main. The CLI is a GoTrue client:
|
|
3
3
|
// every /api/v1 call needs Authorization: Bearer <GoTrue JWT, aud="authenticated">.
|
|
4
|
-
/**
|
|
5
|
-
export const anomalyCount = (p) => Math.max(0, p.
|
|
6
|
-
/** The single "issues" number the CLI shows
|
|
7
|
-
export const totalIssues = (p) => p.
|
|
4
|
+
/** issueCount split: anomalies are the issues that are neither broken rules nor data-quality findings. */
|
|
5
|
+
export const anomalyCount = (p) => Math.max(0, p.issueCount - p.brokenRules - p.dataQualityIssues);
|
|
6
|
+
/** The single "issues" number the CLI shows — the same as the web app's sidebar and dashboard. */
|
|
7
|
+
export const totalIssues = (p) => p.issueCount;
|
|
8
8
|
export class ApiError extends Error {
|
|
9
9
|
status;
|
|
10
10
|
code;
|
package/dist/cli.js
CHANGED
|
@@ -7,15 +7,64 @@ import { homedir } from "node:os";
|
|
|
7
7
|
import { join } from "node:path";
|
|
8
8
|
import { SodabaseClient } from "./api/client.js";
|
|
9
9
|
import { FakeClient } from "./api/fakeClient.js";
|
|
10
|
+
import { pickAgents } from "./agentPicker.js";
|
|
10
11
|
import { App } from "./app.js";
|
|
11
12
|
import { clearCreds, loadCreds } from "./config/tokenStore.js";
|
|
13
|
+
import { INSTALL_MCP_HELP, detectAgents, installedAgents, parseInstallMcpArgs, resolveAgents, runInstallMcp, } from "./installMcp.js";
|
|
12
14
|
const argv = process.argv.slice(2);
|
|
13
15
|
const args = new Set(argv);
|
|
16
|
+
/** process.exit() drops output still queued on a pipe (async on macOS, e.g. `| tee log`): await this first. */
|
|
17
|
+
async function drained() {
|
|
18
|
+
await Promise.all([process.stdout, process.stderr].map((s) => new Promise((done) => s.write("", done))));
|
|
19
|
+
}
|
|
20
|
+
// `install-mcp`: a one-shot, non-interactive install of the MCP + skill — no wizard, no sign-in.
|
|
21
|
+
if (argv[0] === "install-mcp") {
|
|
22
|
+
const opts = parseInstallMcpArgs(argv.slice(1));
|
|
23
|
+
if ("error" in opts) {
|
|
24
|
+
process.stderr.write(`sodabase install-mcp: ${opts.error}\n\n${INSTALL_MCP_HELP}`);
|
|
25
|
+
await drained();
|
|
26
|
+
process.exit(2);
|
|
27
|
+
}
|
|
28
|
+
if (opts.help) {
|
|
29
|
+
process.stdout.write(INSTALL_MCP_HELP);
|
|
30
|
+
await drained();
|
|
31
|
+
process.exit(0);
|
|
32
|
+
}
|
|
33
|
+
const found = detectAgents();
|
|
34
|
+
// With --agent, only those agents' configs matter (for the "refreshed" label) — don't read the others.
|
|
35
|
+
const installed = installedAgents(undefined, opts.skill, undefined, undefined, opts.agents.length ? opts.agents : undefined);
|
|
36
|
+
let target = resolveAgents(opts.agents, found, installed);
|
|
37
|
+
// No --agent in a terminal: always let the user choose, starting from what we found. Piped/CI runs
|
|
38
|
+
// (or --no-input) skip the list and install for the detected agents that don't have it yet. Both ends
|
|
39
|
+
// must be a TTY: with stdout piped (`| tee log`) the list would render invisibly and look like a hang.
|
|
40
|
+
if (!opts.agents.length && opts.input && process.stdin.isTTY && process.stdout.isTTY) {
|
|
41
|
+
const picked = await pickAgents(target.agents, found, installed, opts.skill);
|
|
42
|
+
if (!picked?.length) {
|
|
43
|
+
process.stdout.write("Nothing installed.\n");
|
|
44
|
+
await drained();
|
|
45
|
+
process.exit(0);
|
|
46
|
+
}
|
|
47
|
+
target = { agents: picked, detected: false };
|
|
48
|
+
}
|
|
49
|
+
if (!target.agents.length) {
|
|
50
|
+
// Only reachable from auto-target: every detected agent is already set up.
|
|
51
|
+
process.stdout.write(`Already set up for ${installed.join(", ")}. Nothing to do.\n`);
|
|
52
|
+
await drained();
|
|
53
|
+
process.exit(0);
|
|
54
|
+
}
|
|
55
|
+
const code = await runInstallMcp(new SodabaseClient(), { ...opts, ...target, installed }, (line) => process.stdout.write(`${line}\n`));
|
|
56
|
+
await drained();
|
|
57
|
+
process.exit(code);
|
|
58
|
+
}
|
|
14
59
|
if (args.has("--help") || args.has("-h")) {
|
|
15
60
|
process.stdout.write([
|
|
16
61
|
"sodabase — data-quality onboarding wizard",
|
|
17
62
|
"",
|
|
18
63
|
"Usage: npx sodabase [options]",
|
|
64
|
+
" npx sodabase install-mcp [-a, --agent <id>] [--all] [--no-skill] [--no-input]",
|
|
65
|
+
"",
|
|
66
|
+
"Commands:",
|
|
67
|
+
" install-mcp install the MCP + trust-advisor skill for your coding agent, then exit",
|
|
19
68
|
"",
|
|
20
69
|
"Options:",
|
|
21
70
|
" --demo run the whole flow offline against a fake backend",
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// `npx sodabase install-mcp` — the hub's "Install MCP for your agent" step as a one-shot subcommand:
|
|
2
|
+
// no sign-in, no fullscreen, just the agent checkbox list (agentPicker.tsx) unless --agent is given. Runs the same add-mcp + skills installs as the wizard
|
|
3
|
+
// (Services.installMcp / installSkill) and prints a plain summary. Sign-in isn't needed here: the MCP server
|
|
4
|
+
// runs its own OAuth the first time the agent calls it.
|
|
5
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
6
|
+
import { homedir } from "node:os";
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
import { MCP_URL, SKILL_REF } from "./api/client.js";
|
|
9
|
+
// These ids are forwarded verbatim to BOTH `add-mcp -a` and `skills -a` (see client.ts).
|
|
10
|
+
// Keep every id in this list valid for both CLIs — all three are today; an id only one of
|
|
11
|
+
// them knows would make that tool's install fail (non-fatal, but all-or-nothing for skills).
|
|
12
|
+
// It's also the allowlist for --agent: on Windows the installs spawn through a shell, so a
|
|
13
|
+
// user-supplied id must never reach argv unchecked.
|
|
14
|
+
export const MCP_AGENTS = ["claude-code", "cursor", "codex"];
|
|
15
|
+
const FALLBACK_AGENTS = ["claude-code"];
|
|
16
|
+
// Where each agent leaves its config once installed — used to pick targets when no --agent is given.
|
|
17
|
+
const AGENT_MARKERS = {
|
|
18
|
+
"claude-code": [".claude.json", ".claude"],
|
|
19
|
+
cursor: [".cursor"],
|
|
20
|
+
codex: [".codex"],
|
|
21
|
+
};
|
|
22
|
+
/** The supported agents that look installed under `home` (any marker present). */
|
|
23
|
+
export function detectAgents(home = homedir(), exists = existsSync) {
|
|
24
|
+
return MCP_AGENTS.filter((a) => AGENT_MARKERS[a].some((m) => exists(join(home, m))));
|
|
25
|
+
}
|
|
26
|
+
// The global MCP config add-mcp writes for each agent, how to spot OUR entry in it (name + current URL, so a
|
|
27
|
+
// stale `sodabase` entry pointing at an old/dev host gets refreshed), and where `skills` puts the skill.
|
|
28
|
+
// The substring check first skips parsing a large `~/.claude.json` when our URL isn't in it at all.
|
|
29
|
+
const hasJsonEntry = (text) => text.includes(MCP_URL) &&
|
|
30
|
+
JSON.parse(text).mcpServers?.sodabase?.url === MCP_URL;
|
|
31
|
+
// Line by line, not one regex: our table's keys run from `[mcp_servers.sodabase]` to the next table header, a
|
|
32
|
+
// value may itself contain `[` (`args = ["x"]`), and a `url` under a subtable (`[mcp_servers.sodabase.env]`) isn't ours.
|
|
33
|
+
const TOML_HEADER = /^\s*\[\[?\s*([^\]]+?)\s*\]\]?\s*(#.*)?$/;
|
|
34
|
+
const TOML_URL = /^\s*url\s*=\s*(["'])(.*?)\1\s*(#.*)?$/;
|
|
35
|
+
function hasTomlEntry(text) {
|
|
36
|
+
let ours = false;
|
|
37
|
+
for (const line of text.split(/\r?\n/)) {
|
|
38
|
+
const header = TOML_HEADER.exec(line);
|
|
39
|
+
if (header)
|
|
40
|
+
ours = header[1] === "mcp_servers.sodabase";
|
|
41
|
+
else if (ours && TOML_URL.exec(line)?.[2] === MCP_URL)
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
// Each agent's global skills dir, as the `skills` CLI (1.7.x) has it: Cursor reads its own, Codex the shared one.
|
|
47
|
+
const SKILL_DIR = join("skills", "sodabase-trust-advisor", "SKILL.md");
|
|
48
|
+
const MCP_CONFIGS = {
|
|
49
|
+
"claude-code": { file: ".claude.json", has: hasJsonEntry, skill: join(".claude", SKILL_DIR) },
|
|
50
|
+
cursor: { file: join(".cursor", "mcp.json"), has: hasJsonEntry, skill: join(".cursor", SKILL_DIR) },
|
|
51
|
+
codex: { file: join(".codex", "config.toml"), has: hasTomlEntry, skill: join(".agents", SKILL_DIR) },
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* The agents (of `among`) already fully set up: a `sodabase` MCP entry at the current URL in their global
|
|
55
|
+
* config, plus the trust-advisor skill when `skill` is wanted (so a missing skill still gets installed).
|
|
56
|
+
* Unreadable/malformed config = not set up.
|
|
57
|
+
*/
|
|
58
|
+
export function installedAgents(home = homedir(), skill = true, read = (p) => readFileSync(p, "utf8"), exists = existsSync, among = MCP_AGENTS) {
|
|
59
|
+
return MCP_AGENTS.filter((a) => among.includes(a)).filter((a) => {
|
|
60
|
+
const c = MCP_CONFIGS[a];
|
|
61
|
+
try {
|
|
62
|
+
return c.has(read(join(home, c.file))) && (!skill || exists(join(home, c.skill)));
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Explicit --agent/--all wins (reinstalling is harmless). Otherwise every detected agent that doesn't have
|
|
71
|
+
* the MCP yet — empty when they all do — falling back to Claude Code when no agent is detected at all.
|
|
72
|
+
*/
|
|
73
|
+
export function resolveAgents(explicit, detected, installed = []) {
|
|
74
|
+
if (explicit.length)
|
|
75
|
+
return { agents: explicit, detected: false };
|
|
76
|
+
if (!detected.length)
|
|
77
|
+
return { agents: FALLBACK_AGENTS, detected: false };
|
|
78
|
+
return { agents: detected.filter((a) => !installed.includes(a)), detected: true };
|
|
79
|
+
}
|
|
80
|
+
export const INSTALL_MCP_HELP = [
|
|
81
|
+
"sodabase install-mcp — install the Sodabase MCP + trust-advisor skill for your coding agent",
|
|
82
|
+
"",
|
|
83
|
+
"Usage: npx sodabase install-mcp [options]",
|
|
84
|
+
"",
|
|
85
|
+
"Options:",
|
|
86
|
+
` -a, --agent <id> agent to install for; repeat or comma-separate`,
|
|
87
|
+
` one of: ${MCP_AGENTS.join(", ")}`,
|
|
88
|
+
" --all install for every supported agent",
|
|
89
|
+
" --no-skill install only the MCP, skip the trust-advisor skill",
|
|
90
|
+
" --no-input don't show the agent checkbox list",
|
|
91
|
+
" --help, -h show this help",
|
|
92
|
+
"",
|
|
93
|
+
"Without --agent, shows a checkbox list with the agents found on this machine ticked, except",
|
|
94
|
+
"those that already have the MCP (claude-code if none found). Without a terminal (or with",
|
|
95
|
+
"--no-input), installs for those directly.",
|
|
96
|
+
"",
|
|
97
|
+
"No sign-in needed: your agent signs in to Sodabase the first time it uses the MCP.",
|
|
98
|
+
"",
|
|
99
|
+
].join("\n");
|
|
100
|
+
/** Parse the args AFTER `install-mcp`. Returns the options, or an error message for bad input. */
|
|
101
|
+
export function parseInstallMcpArgs(argv) {
|
|
102
|
+
// --help wins over everything else on the line, including bad options.
|
|
103
|
+
if (argv.some((a) => a === "--help" || a === "-h"))
|
|
104
|
+
return { agents: [], skill: true, help: true, input: true };
|
|
105
|
+
const agents = [];
|
|
106
|
+
let skill = true;
|
|
107
|
+
let input = true;
|
|
108
|
+
for (let i = 0; i < argv.length; i++) {
|
|
109
|
+
const arg = argv[i];
|
|
110
|
+
if (arg === "--no-skill")
|
|
111
|
+
skill = false;
|
|
112
|
+
else if (arg === "--no-input")
|
|
113
|
+
input = false;
|
|
114
|
+
else if (arg === "--all")
|
|
115
|
+
agents.push(...MCP_AGENTS);
|
|
116
|
+
else if (arg === "-a" || arg === "--agent") {
|
|
117
|
+
const value = argv[++i];
|
|
118
|
+
if (!value || value.startsWith("-"))
|
|
119
|
+
return { error: `${arg} needs an agent id (${MCP_AGENTS.join(", ")})` };
|
|
120
|
+
agents.push(...value.split(","));
|
|
121
|
+
}
|
|
122
|
+
else if (arg.startsWith("--agent=")) {
|
|
123
|
+
const value = arg.slice("--agent=".length);
|
|
124
|
+
// An empty value (e.g. an unset $AGENT) must fail like `-a` with no value, not fall back to auto-detect.
|
|
125
|
+
if (!value.split(",").some((v) => v.trim()))
|
|
126
|
+
return { error: `--agent needs an agent id (${MCP_AGENTS.join(", ")})` };
|
|
127
|
+
agents.push(...value.split(","));
|
|
128
|
+
}
|
|
129
|
+
else
|
|
130
|
+
return { error: `unknown option: ${arg}` };
|
|
131
|
+
}
|
|
132
|
+
const ids = [...new Set(agents.map((a) => a.trim()).filter(Boolean))];
|
|
133
|
+
const unknown = ids.filter((a) => !MCP_AGENTS.includes(a));
|
|
134
|
+
if (unknown.length)
|
|
135
|
+
return { error: `unknown agent: ${unknown.join(", ")} (supported: ${MCP_AGENTS.join(", ")})` };
|
|
136
|
+
return { agents: ids, skill, help: false, input };
|
|
137
|
+
}
|
|
138
|
+
/** Run the install and print the outcome. Returns the process exit code (1 only if the MCP itself failed). */
|
|
139
|
+
export async function runInstallMcp(services, opts, out) {
|
|
140
|
+
out(`Installing the Sodabase MCP for ${opts.agents.join(", ")}${opts.detected ? " (found on this machine)" : ""}…`);
|
|
141
|
+
try {
|
|
142
|
+
const r = await services.installMcp(opts.agents);
|
|
143
|
+
out(`Ran: ${r.command}`);
|
|
144
|
+
for (const w of r.wrote)
|
|
145
|
+
out(` ✔ ${w.agent} → ${w.path}${opts.installed?.includes(w.agent) ? " (was already set up, refreshed)" : ""}`);
|
|
146
|
+
}
|
|
147
|
+
catch (e) {
|
|
148
|
+
out(`Couldn't auto-install the MCP: ${e instanceof Error ? e.message : String(e)}`);
|
|
149
|
+
out("Add it yourself:");
|
|
150
|
+
for (const a of opts.agents)
|
|
151
|
+
out(a === "claude-code"
|
|
152
|
+
? ` claude mcp add --scope user --transport http sodabase ${MCP_URL}`
|
|
153
|
+
: ` npx add-mcp ${MCP_URL} -g -a ${a}`);
|
|
154
|
+
return 1;
|
|
155
|
+
}
|
|
156
|
+
// Same contract as the wizard: the MCP is the main thing, so a skill failure warns with a manual
|
|
157
|
+
// fallback but doesn't fail the command.
|
|
158
|
+
if (opts.skill) {
|
|
159
|
+
try {
|
|
160
|
+
await services.installSkill(opts.agents);
|
|
161
|
+
out(` ✔ trust-advisor skill → ${SKILL_REF}`);
|
|
162
|
+
}
|
|
163
|
+
catch (e) {
|
|
164
|
+
out(`Couldn't install the trust-advisor skill: ${e instanceof Error ? e.message : String(e)}`);
|
|
165
|
+
out("Add it yourself:");
|
|
166
|
+
out(` npx skills add ${SKILL_REF}`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
out("Ready next time you restart your agent.");
|
|
170
|
+
return 0;
|
|
171
|
+
}
|
package/dist/ui.js
CHANGED
|
@@ -2,8 +2,11 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
2
2
|
import { Box, Text, useApp, useInput } from "ink";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import React, { createContext, useContext, useEffect, useRef, useState } from "react";
|
|
5
|
-
import { totalIssues } from "./api/types.js";
|
|
5
|
+
import { ApiError, anomalyCount, totalIssues } from "./api/types.js";
|
|
6
6
|
import { saveCreds } from "./config/tokenStore.js";
|
|
7
|
+
import { AgentChecklist, useAgentChecklist } from "./agentPicker.js";
|
|
8
|
+
import { MCP_URL } from "./api/client.js";
|
|
9
|
+
import { detectAgents, installedAgents as agentsSetUp, resolveAgents } from "./installMcp.js";
|
|
7
10
|
// ── utils ─────────────────────────────────────────────────────────────────────
|
|
8
11
|
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
9
12
|
function useSpinner() {
|
|
@@ -378,88 +381,173 @@ function isWatchable(p) {
|
|
|
378
381
|
return !p.status || p.status === "ACTIVE_HEALTHY";
|
|
379
382
|
}
|
|
380
383
|
const issuesLabel = (n) => `${n} ${n === 1 ? "issue" : "issues"}`;
|
|
384
|
+
const EMPTY_ORG_MSG = "This Supabase organization has no projects. Create one in Supabase, then run setup again.";
|
|
381
385
|
export function Connect({ onDone }) {
|
|
382
386
|
useFooter(_jsx(Text, { dimColor: true, children: "\u2191\u2193 move \u00B7 enter select \u00B7 green = watching \u00B7 yellow = offline \u00B7 esc to go back" }), []);
|
|
383
387
|
const bodyRows = useBodyRows();
|
|
384
388
|
const { services, interactive } = useWizard();
|
|
385
389
|
const spin = useSpinner();
|
|
386
|
-
const [
|
|
390
|
+
const [rows, setRows] = useState(null);
|
|
391
|
+
const [multiOrg, setMultiOrg] = useState(false);
|
|
392
|
+
// reused: rows came from EXISTING connection(s) (no browser) — enables the "connect a different org" row.
|
|
393
|
+
// authorizing: a fresh OAuth authorize is in flight (its browser message + abortable poll).
|
|
394
|
+
const [reused, setReused] = useState(false);
|
|
395
|
+
const [authorizing, setAuthorizing] = useState(false);
|
|
387
396
|
const [alreadyConnected, setAlreadyConnected] = useState(false);
|
|
388
|
-
const [projects, setProjects] = useState(null);
|
|
389
397
|
const [cursor, setCursor] = useState(0);
|
|
390
398
|
const [chosen, setChosen] = useState(null);
|
|
391
399
|
const [error, setError] = useState(null);
|
|
400
|
+
// Abort controller for whichever load is in flight (the initial reuse-or-authorize, or a later "connect a
|
|
401
|
+
// different org"). Each async run captures its OWN signal, so leaving the screen (cleanup aborts it) can't set
|
|
402
|
+
// state, and a replacement run can't be revived by a stale one.
|
|
403
|
+
const abortRef = useRef(null);
|
|
404
|
+
function finishRow(row) {
|
|
405
|
+
const project = row?.project;
|
|
406
|
+
// Don't send an offline (paused/transitional) project into onboarding — the DB is unreachable, so it would
|
|
407
|
+
// fail deep in the job. Surface it here, up front and recoverable, instead.
|
|
408
|
+
if (project && !isWatchable(project)) {
|
|
409
|
+
setError(`"${project.name}" is paused in Supabase — resume it there, then run setup again.`);
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
const ref = project?.ref ?? "";
|
|
413
|
+
setChosen(ref);
|
|
414
|
+
// alreadyWatching routes the hub: an already-watched project skips provisioning and goes straight to
|
|
415
|
+
// adjusting its tables; a new one is provisioned first. Set it explicitly so a later pick of a NEW project
|
|
416
|
+
// resets a flag left over from a previous "manage" round.
|
|
417
|
+
onDone({ connectionId: row?.connectionId ?? "", projectRef: ref, alreadyWatching: !!project?.watching });
|
|
418
|
+
}
|
|
419
|
+
// Present the gathered rows: the picker, or (single fresh project / non-interactive) auto-advance. A lone
|
|
420
|
+
// already-watched project shows the picker — there's nothing new to onboard — so reuse of a single watched
|
|
421
|
+
// project never silently advances.
|
|
422
|
+
function present(rws, multi, fromReuse) {
|
|
423
|
+
setRows(rws);
|
|
424
|
+
setMultiOrg(multi);
|
|
425
|
+
setReused(fromReuse);
|
|
426
|
+
setCursor(0);
|
|
427
|
+
if (!interactive || (rws.length === 1 && !rws[0]?.project.watching))
|
|
428
|
+
finishRow(rws[0]);
|
|
429
|
+
}
|
|
430
|
+
// Open the Supabase OAuth authorize (browser), then show the new org's projects. Used when no existing
|
|
431
|
+
// connection is reusable, and when the user picks "connect a different org".
|
|
432
|
+
async function authorize() {
|
|
433
|
+
abortRef.current?.abort();
|
|
434
|
+
const controller = new AbortController();
|
|
435
|
+
abortRef.current = controller;
|
|
436
|
+
const { signal } = controller;
|
|
437
|
+
setError(null);
|
|
438
|
+
setRows(null);
|
|
439
|
+
setChosen(null);
|
|
440
|
+
setReused(false);
|
|
441
|
+
setAuthorizing(true);
|
|
442
|
+
try {
|
|
443
|
+
// connect() opens the browser, polls the hosted handback, and self-completes with our own Bearer.
|
|
444
|
+
const { connectionId: cid, alreadyConnected: ac } = await services.connect(signal);
|
|
445
|
+
if (signal.aborted)
|
|
446
|
+
return;
|
|
447
|
+
setAlreadyConnected(!!ac);
|
|
448
|
+
const projs = await services.listProjects(cid);
|
|
449
|
+
if (signal.aborted)
|
|
450
|
+
return;
|
|
451
|
+
if (projs.length === 0) {
|
|
452
|
+
setError(EMPTY_ORG_MSG);
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
present(projs.map((p) => ({ project: p, connectionId: cid })), false, false);
|
|
456
|
+
}
|
|
457
|
+
catch (e) {
|
|
458
|
+
if (!signal.aborted)
|
|
459
|
+
setError(e instanceof Error ? e.message : String(e));
|
|
460
|
+
}
|
|
461
|
+
finally {
|
|
462
|
+
if (!signal.aborted)
|
|
463
|
+
setAuthorizing(false);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
392
466
|
useEffect(() => {
|
|
393
|
-
let on = true;
|
|
394
|
-
// Abort the authorize poll when we leave this screen (escape back to the hub) so an abandoned
|
|
395
|
-
// connect doesn't keep polling for up to 5 minutes — and a re-entry can't start a second,
|
|
396
|
-
// competing poll loop against the same handback.
|
|
397
467
|
const controller = new AbortController();
|
|
468
|
+
abortRef.current = controller;
|
|
469
|
+
const { signal } = controller;
|
|
470
|
+
// Reuse EVERY healthy existing connection first (no browser): gather the projects of all connections whose
|
|
471
|
+
// list we can fetch into one picker. Only if none have any projects do we open the authorize flow.
|
|
398
472
|
(async () => {
|
|
473
|
+
let conns;
|
|
399
474
|
try {
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
if (
|
|
404
|
-
return;
|
|
405
|
-
setConnectionId(cid);
|
|
406
|
-
setAlreadyConnected(!!ac);
|
|
407
|
-
const projs = await services.listProjects(cid);
|
|
408
|
-
if (!on)
|
|
475
|
+
conns = await services.listConnections();
|
|
476
|
+
}
|
|
477
|
+
catch (e) {
|
|
478
|
+
if (signal.aborted)
|
|
409
479
|
return;
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
if (projs.length === 0) {
|
|
414
|
-
setError("This Supabase organization has no projects. Create one in Supabase, then run setup again.");
|
|
480
|
+
// A Sodabase-auth failure (expired session) won't be fixed by the Supabase browser flow — surface it.
|
|
481
|
+
if (e instanceof ApiError && e.status === 401) {
|
|
482
|
+
setError("Your Sodabase session has expired. Run `sodabase --login`, then try again.");
|
|
415
483
|
return;
|
|
416
484
|
}
|
|
417
|
-
|
|
418
|
-
|
|
485
|
+
// Anything else (offline / 5xx): fall through to authorize, which surfaces its own errors.
|
|
486
|
+
await authorize();
|
|
487
|
+
return;
|
|
419
488
|
}
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
489
|
+
if (signal.aborted)
|
|
490
|
+
return;
|
|
491
|
+
const collected = [];
|
|
492
|
+
const orgs = new Set();
|
|
493
|
+
for (const c of conns) {
|
|
494
|
+
try {
|
|
495
|
+
const projs = await services.listProjects(c.connectionId);
|
|
496
|
+
if (signal.aborted)
|
|
497
|
+
return;
|
|
498
|
+
for (const p of projs)
|
|
499
|
+
collected.push({ project: p, connectionId: c.connectionId, org: c.orgSlug });
|
|
500
|
+
// Count distinct ORGS (so two connections to the same org don't trigger per-row org labels); fall back
|
|
501
|
+
// to the connection id when a slug is missing so each still counts as its own.
|
|
502
|
+
if (projs.length > 0)
|
|
503
|
+
orgs.add(c.orgSlug ?? c.connectionId);
|
|
504
|
+
}
|
|
505
|
+
catch {
|
|
506
|
+
/* stale/unhealthy connection — skip it (an empty org simply contributes no rows) */
|
|
507
|
+
}
|
|
423
508
|
}
|
|
509
|
+
if (signal.aborted)
|
|
510
|
+
return;
|
|
511
|
+
if (collected.length > 0)
|
|
512
|
+
present(collected, orgs.size > 1, true);
|
|
513
|
+
else
|
|
514
|
+
await authorize(); // no reusable connection has projects → authorize a new org
|
|
424
515
|
})();
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
};
|
|
516
|
+
// Abort whichever controller is CURRENT — authorize() swaps in its own for the 5-minute connect() poll, so
|
|
517
|
+
// aborting the captured mount controller here would leave that poll running (and setting state) after unmount.
|
|
518
|
+
return () => abortRef.current?.abort();
|
|
429
519
|
}, []);
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
// fail deep in the job. Surface it here, up front and recoverable, instead. Also covers the single-project
|
|
433
|
-
// auto-select path, which skips the picker (and its tag) entirely.
|
|
434
|
-
if (project && !isWatchable(project)) {
|
|
435
|
-
setError(`"${project.name}" is paused in Supabase — resume it there, then run setup again.`);
|
|
436
|
-
return;
|
|
437
|
-
}
|
|
438
|
-
const ref = project?.ref ?? "";
|
|
439
|
-
setChosen(ref);
|
|
440
|
-
// alreadyWatching routes the hub: an already-watched project skips provisioning and goes straight to
|
|
441
|
-
// adjusting its tables; a new one is provisioned first. Set it explicitly (not just when true) so a
|
|
442
|
-
// later pick of a NEW project resets the flag left over from a previous "manage" round.
|
|
443
|
-
onDone({ connectionId: connId, projectRef: ref, alreadyWatching: !!project?.watching });
|
|
444
|
-
}
|
|
520
|
+
// The synthetic "connect a different Supabase org" row sits after the projects when reusing a connection.
|
|
521
|
+
const extraRow = reused;
|
|
445
522
|
useGatedInput((_i, key) => {
|
|
446
|
-
if (!
|
|
523
|
+
if (!rows || chosen || authorizing)
|
|
447
524
|
return;
|
|
525
|
+
const max = rows.length - 1 + (extraRow ? 1 : 0);
|
|
448
526
|
if (key.upArrow)
|
|
449
527
|
setCursor((c) => Math.max(0, c - 1));
|
|
450
528
|
else if (key.downArrow)
|
|
451
|
-
setCursor((c) => Math.min(
|
|
452
|
-
else if (key.return
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
529
|
+
setCursor((c) => Math.min(max, c + 1));
|
|
530
|
+
else if (key.return) {
|
|
531
|
+
if (extraRow && cursor === rows.length)
|
|
532
|
+
void authorize(); // picked "connect a different org"
|
|
533
|
+
else
|
|
534
|
+
finishRow(rows[cursor]);
|
|
535
|
+
}
|
|
536
|
+
}, { isActive: interactive && !!rows && !chosen && !authorizing });
|
|
537
|
+
// Show the picker whenever there are rows and nothing auto-advanced (chosen stays null). This covers a lone
|
|
538
|
+
// already-watched project on EITHER path — present() deliberately doesn't auto-advance it, so without this it
|
|
539
|
+
// would render the "done" confirmation yet never call onDone.
|
|
540
|
+
const picking = interactive && !!rows && !chosen;
|
|
541
|
+
const heading = authorizing ? "Authorize your database" : rows ? "Pick a project" : "Connect a project";
|
|
542
|
+
return (_jsxs(Box, { flexDirection: "column", paddingX: 2, marginTop: 1, alignItems: "center", children: [_jsx(Eyebrow, { children: heading }), _jsx(Box, { marginTop: 1, flexDirection: "column", children: error ? (_jsx(Text, { color: "red", children: error })) : authorizing && !rows ? (_jsxs(_Fragment, { children: [_jsxs(Text, { children: [_jsx(Text, { color: "green", children: spin }), " Opening your browser to authorize\u2026"] }), _jsx(Box, { width: 62, children: _jsx(Text, { dimColor: true, children: "Read-only \u2014 no connection string to paste. Approve on Supabase, then return here." }) })] })) : !rows ? (_jsxs(Text, { children: [_jsx(Text, { color: "green", children: spin }), " Checking your Supabase connections\u2026"] })) : picking ? ((() => {
|
|
543
|
+
const clamped = Math.min(cursor, rows.length - 1);
|
|
544
|
+
const win = windowList(rows, clamped, Math.max(3, bodyRows - (extraRow ? 7 : 6)));
|
|
545
|
+
return (_jsxs(_Fragment, { children: [_jsx(Text, { children: "Pick a project to watch:" }), win.moreUp > 0 && _jsx(Text, { dimColor: true, children: ` ↑ ${win.moreUp} more` }), win.slice.map((row, idx) => {
|
|
459
546
|
const i = win.start + idx;
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
547
|
+
const p = row.project;
|
|
548
|
+
return (_jsxs(Text, { color: i === cursor ? "green" : undefined, children: [i === cursor ? "❯ " : " ", p.name, " ", _jsxs(Text, { dimColor: true, children: ["(", p.ref, ")"] }), multiOrg && _jsxs(Text, { dimColor: true, children: [" \u00B7 ", row.org ?? "other org"] }), projectTags(p).map((t) => (_jsxs(Text, { color: t.color, children: [" ", "\u00B7 ", t.label] }, t.label)))] }, `${row.connectionId}:${p.ref}`));
|
|
549
|
+
}), win.moreDown > 0 && _jsx(Text, { dimColor: true, children: ` ↓ ${win.moreDown} more` }), extraRow && (_jsxs(Text, { color: cursor === rows.length ? "green" : undefined, dimColor: cursor !== rows.length, children: [cursor === rows.length ? "❯ " : " ", "+ Connect a different Supabase org"] }))] }));
|
|
550
|
+
})()) : (_jsxs(_Fragment, { children: [alreadyConnected && (_jsxs(Text, { dimColor: true, children: [_jsx(Text, { color: "green", children: "\u2713" }), " Already connected \u2014 continuing on your existing connection."] })), _jsxs(Text, { children: [_jsx(Text, { color: "green", children: "\u2714" }), " Connected \u00B7 project ", _jsx(Text, { bold: true, children: chosen ?? rows[0]?.project.ref ?? "—" }), _jsx(Text, { color: "green", children: " 🔒 read-only, audited" })] })] })) })] }));
|
|
463
551
|
}
|
|
464
552
|
// ── Phase: the server-side onboarding job (two-panel) ─────────────────────────────
|
|
465
553
|
// Human labels for the backend onboarding job's step names (machine keys). Unknown names fall back to the raw
|
|
@@ -626,14 +714,16 @@ export function ScopeAdjust({ onDone }) {
|
|
|
626
714
|
})()) })] }));
|
|
627
715
|
}
|
|
628
716
|
// ── Phase: consented in-flow MCP install ─────────────────────────────────────────
|
|
629
|
-
//
|
|
630
|
-
// Keep every id in this list valid for both CLIs — all three are today; an id only one of
|
|
631
|
-
// them knows would make that tool's install fail (non-fatal, but all-or-nothing for skills).
|
|
632
|
-
const AGENTS = ["claude-code", "cursor", "codex"];
|
|
717
|
+
// Same agents, preselection and checkbox list as `install-mcp` (see installMcp.ts / agentPicker.tsx).
|
|
633
718
|
export function McpInstall({ onDone }) {
|
|
634
719
|
const { services, fast, interactive } = useWizard();
|
|
635
|
-
|
|
636
|
-
const [
|
|
720
|
+
// Ticked to start: the agents found on this machine that don't have the MCP yet (claude-code if none found).
|
|
721
|
+
const [local] = useState(() => {
|
|
722
|
+
const found = detectAgents();
|
|
723
|
+
const installed = agentsSetUp();
|
|
724
|
+
return { found, installed, preselected: resolveAgents([], found, installed).agents };
|
|
725
|
+
});
|
|
726
|
+
const list = useAgentChecklist(local.preselected);
|
|
637
727
|
const [result, setResult] = useState(null);
|
|
638
728
|
const [skillResult, setSkillResult] = useState(null);
|
|
639
729
|
const [skillError, setSkillError] = useState(null);
|
|
@@ -717,22 +807,14 @@ export function McpInstall({ onDone }) {
|
|
|
717
807
|
onDone({ installed: [] });
|
|
718
808
|
return;
|
|
719
809
|
}
|
|
720
|
-
if (key
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
setCursor((c) => Math.min(AGENTS.length - 1, c + 1));
|
|
724
|
-
else if (input === " ")
|
|
725
|
-
setSel((s) => s.map((v, i) => (i === cursor ? !v : v)));
|
|
726
|
-
else if (input === "n")
|
|
810
|
+
if (list.handleKey(input, key))
|
|
811
|
+
return;
|
|
812
|
+
if (input === "n")
|
|
727
813
|
void run([]);
|
|
728
814
|
else if (key.return)
|
|
729
|
-
void run(
|
|
815
|
+
void run(list.picked());
|
|
730
816
|
}, { isActive: interactive && !busy && (!result || skillError !== null || ready) });
|
|
731
|
-
return (_jsxs(Box, { flexDirection: "column", paddingX: 2, marginTop: 1, alignItems: "center", children: [_jsx(Eyebrow, { children: "Set up your coding agent (optional)" }), error ? (_jsxs(Box, { marginTop: 1, flexDirection: "column", children: [_jsxs(Text, { color: "yellow", children: ["Couldn't auto-install the MCP: ", error] }), _jsx(Text, { dimColor: true, children: "Add it yourself (Claude Code):" }), _jsxs(Text, { color: "cyan", children: [" ", "claude mcp add --transport http sodabase
|
|
732
|
-
const on = sel[i];
|
|
733
|
-
const here = interactive && i === cursor;
|
|
734
|
-
return (_jsxs(Text, { color: on ? "green" : undefined, dimColor: !on, children: [here ? "❯ " : " ", on ? "[x]" : "[ ]", " ", a] }, a));
|
|
735
|
-
}) })] }))] }));
|
|
817
|
+
return (_jsxs(Box, { flexDirection: "column", paddingX: 2, marginTop: 1, alignItems: "center", children: [_jsx(Eyebrow, { children: "Set up your coding agent (optional)" }), error ? (_jsxs(Box, { marginTop: 1, flexDirection: "column", children: [_jsxs(Text, { color: "yellow", children: ["Couldn't auto-install the MCP: ", error] }), _jsx(Text, { dimColor: true, children: "Add it yourself (Claude Code):" }), _jsxs(Text, { color: "cyan", children: [" ", "claude mcp add --transport http sodabase ", MCP_URL] }), interactive && (_jsx(Box, { marginTop: 1, children: _jsx(Text, { dimColor: true, children: "enter to continue" }) }))] })) : result ? (_jsxs(Box, { marginTop: 1, flexDirection: "column", children: [_jsxs(Text, { dimColor: true, children: ["Ran: ", result.command] }), result.wrote.map((w) => (_jsxs(Text, { children: [" ", _jsx(Text, { color: "green", children: "\u2714" }), " ", w.agent, " ", _jsxs(Text, { dimColor: true, children: ["\u2192 ", w.path] })] }, w.agent))), skillResult && (_jsxs(Text, { children: [" ", _jsx(Text, { color: "green", children: "\u2714" }), " trust-advisor skill ", _jsx(Text, { dimColor: true, children: "\u2192 sodabase/agent-skills" })] })), skillError && (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Text, { color: "yellow", children: ["Couldn't install the trust-advisor skill: ", skillError] }), _jsx(Text, { dimColor: true, children: "Add it yourself:" }), _jsxs(Text, { color: "cyan", children: [" ", "npx skills add sodabase/agent-skills"] })] })), _jsx(Text, { color: "green", children: "Ready next time you restart your agent." }), (ready || skillError) && interactive && (_jsx(Box, { marginTop: 1, children: _jsx(Text, { dimColor: true, children: "enter to continue" }) }))] })) : (_jsxs(_Fragment, { children: [_jsxs(Box, { marginTop: 1, flexDirection: "column", children: [_jsx(Text, { dimColor: true, children: "Install the Sodabase MCP + trust-advisor skill so your agent can ask \"is this data safe to trust?\"" }), _jsx(Text, { dimColor: true, children: "Explicit \u2014 we show the exact change and only write on your confirm." })] }), _jsx(Box, { marginTop: 1, children: _jsx(AgentChecklist, { sel: list.sel, cursor: interactive ? list.cursor : null, found: local.found, installed: local.installed }) })] }))] }));
|
|
736
818
|
}
|
|
737
819
|
// ── Phase: manage projects (the hub's "Manage projects" entry) ───────────────────
|
|
738
820
|
// A picker over the projects already being watched; selecting one drills into its watched tables.
|
|
@@ -957,15 +1039,17 @@ export function Home({ ctx, onDone }) {
|
|
|
957
1039
|
const list = projects ?? [];
|
|
958
1040
|
const watching = list.length > 0;
|
|
959
1041
|
const tables = list.reduce((a, p) => a + p.watched, 0);
|
|
960
|
-
|
|
1042
|
+
// The same issue total as the web app: anomalies + broken rules + data-quality findings, on watched tables.
|
|
1043
|
+
const issues = list.reduce((a, p) => a + totalIssues(p), 0);
|
|
961
1044
|
const brokenRules = list.reduce((a, p) => a + p.brokenRules, 0);
|
|
962
|
-
const
|
|
1045
|
+
const dataQuality = list.reduce((a, p) => a + p.dataQualityIssues, 0);
|
|
1046
|
+
const anomalies = list.reduce((a, p) => a + anomalyCount(p), 0);
|
|
963
1047
|
const monitors = list.reduce((a, p) => a + p.monitors, 0);
|
|
964
1048
|
const rules = list.reduce((a, p) => a + p.rules, 0);
|
|
965
1049
|
useFooter(_jsx(Text, { dimColor: true, children: "\u2191\u2193 move \u00B7 enter select \u00B7 esc to quit" }), []);
|
|
966
1050
|
return (_jsxs(Box, { flexDirection: "column", paddingX: 2, marginTop: 1, alignItems: "center", children: [_jsx(Eyebrow, { children: watching ? "Sodabase is watching" : "Welcome to Sodabase" }), identity && (_jsx(Box, { marginTop: 1, children: identity.email ? (_jsxs(Text, { dimColor: true, children: ["Signed in as ", _jsx(Text, { color: WHITE, children: identity.email }), " \u00B7 workspace", " ", _jsx(Text, { color: WHITE, children: identity.workspaceName })] })) : (
|
|
967
1051
|
// No email on the JWT — a role isn't an identity, so just name the workspace.
|
|
968
|
-
_jsxs(Text, { dimColor: true, children: ["Workspace ", _jsx(Text, { color: WHITE, children: identity.workspaceName })] })) })), _jsx(Box, { marginTop: 1, flexDirection: "column", children: projects === null ? (_jsx(Text, { dimColor: true, children: "loading your trust report\u2026" })) : watching ? (_jsxs(_Fragment, { children: [_jsxs(StatRow, { label: "Tables watched", children: [_jsx(Text, { color: "green", bold: true, children: tables }), " ", "across ", plural(list.length, "project")] }), _jsxs(StatRow, { label: "Issues", children: [_jsx(Text, { color: issues > 0 ? "yellow" : "green", bold: true, children: issues }), " ", issues > 0 ? (_jsxs(Text, { dimColor: true, children: ["\u00B7 ", anomalyLabel(anomalies), "
|
|
1052
|
+
_jsxs(Text, { dimColor: true, children: ["Workspace ", _jsx(Text, { color: WHITE, children: identity.workspaceName })] })) })), _jsx(Box, { marginTop: 1, flexDirection: "column", children: projects === null ? (_jsx(Text, { dimColor: true, children: "loading your trust report\u2026" })) : watching ? (_jsxs(_Fragment, { children: [_jsxs(StatRow, { label: "Tables watched", children: [_jsx(Text, { color: "green", bold: true, children: tables }), " ", "across ", plural(list.length, "project")] }), _jsxs(StatRow, { label: "Issues", children: [_jsx(Text, { color: issues > 0 ? "yellow" : "green", bold: true, children: issues }), " ", issues > 0 ? (_jsxs(Text, { dimColor: true, children: ["\u00B7 ", anomalyLabel(anomalies), ", ", plural(brokenRules, "broken rule"), " &", " ", plural(dataQuality, "data-quality issue")] })) : (_jsx(Text, { dimColor: true, children: "\u00B7 all clear" }))] }), _jsxs(StatRow, { label: "Coverage", children: [_jsx(Text, { bold: true, children: plural(monitors, "monitor") }), _jsx(Text, { dimColor: true, children: " & " }), _jsx(Text, { bold: true, children: plural(rules, "rule") })] }), ctx.installed && ctx.installed.length > 0 && (_jsxs(StatRow, { label: "MCP", children: [_jsx(Text, { color: "green", children: "\u2714" }), " installed for ", ctx.installed.join(", ")] }))] })) : (_jsxs(_Fragment, { children: [_jsx(Text, { children: "You're not watching any projects yet." }), _jsx(Text, { dimColor: true, children: "Pick one below \u2014 Sodabase sets up read-only monitoring, no code changes." })] })) }), interactive && projects !== null && (_jsx(_Fragment, { children: _jsx(Box, { marginTop: 1, flexDirection: "column", children: HOME_MENU.map((m, i) => {
|
|
969
1053
|
const here = i === cursor;
|
|
970
1054
|
return (_jsxs(Text, { color: here ? "green" : undefined, children: [here ? "❯ " : " ", m.label, " ", _jsxs(Text, { dimColor: true, children: ["\u00B7 ", m.hint] })] }, m.id));
|
|
971
1055
|
}) }) }))] }));
|