sodabase 0.1.7 → 0.1.9

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.
@@ -186,6 +186,16 @@ export class SodabaseClient {
186
186
  await sleepAbortable(2000, signal);
187
187
  }
188
188
  }
189
+ async listConnections() {
190
+ const rows = await this.get("/connections");
191
+ return Array.isArray(rows)
192
+ ? rows.map((c) => ({
193
+ connectionId: c.connection_id,
194
+ status: c.status,
195
+ ...(c.org_slug ? { orgSlug: c.org_slug } : {}),
196
+ }))
197
+ : [];
198
+ }
189
199
  async listProjects(connectionId) {
190
200
  const rows = await this.get(`/connections/${encodeURIComponent(connectionId)}/projects`);
191
201
  return rows.map((p) => ({
@@ -215,12 +225,18 @@ export class SodabaseClient {
215
225
  return rows.map((p) => ({
216
226
  ref: p.ref,
217
227
  name: p.name,
218
- openIssues: p.open_issues ?? 0,
219
- dataQualityIssues: p.data_quality_issues ?? 0,
228
+ // The watched-scoped counts the web app shows — all from the new fields or, on an older API, all from the raw
229
+ // all-tables ones (never mixed, so the breakdown always adds up to the total).
230
+ ...(p.issue_count !== undefined && p.broken_rule_count !== undefined && p.data_quality_count !== undefined
231
+ ? { issueCount: p.issue_count, dataQualityIssues: p.data_quality_count, brokenRules: p.broken_rule_count }
232
+ : {
233
+ issueCount: (p.open_issues ?? 0) + (p.data_quality_issues ?? 0),
234
+ dataQualityIssues: p.data_quality_issues ?? 0,
235
+ brokenRules: p.broken_rules ?? 0,
236
+ }),
220
237
  watched: p.watched ?? 0,
221
238
  monitors: p.monitors ?? 0,
222
239
  rules: p.rules ?? 0,
223
- brokenRules: p.broken_rules ?? 0,
224
240
  status: p.status ?? "ready",
225
241
  }));
226
242
  }
@@ -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", openIssues: 5, dataQualityIssues: 13, watched: 7, monitors: 28, rules: 15, brokenRules: 1, status: "ready" },
93
- { ref: "analytics", name: "Analytics", openIssues: 0, dataQualityIssues: 0, watched: 4, monitors: 18, rules: 10, brokenRules: 0, status: "ready" },
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
- /** Open issues split: anomalies are the open signals that aren't broken rules (openIssues − brokenRules). */
5
- export const anomalyCount = (p) => Math.max(0, p.openIssues - p.brokenRules);
6
- /** The single "issues" number the CLI shows = monitor signals + data-quality findings. */
7
- export const totalIssues = (p) => p.openIssues + p.dataQualityIssues;
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/app.js CHANGED
@@ -1,5 +1,5 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { useApp, useInput, useStdout } from "ink";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Box, useApp, useInput, useStdout } from "ink";
3
3
  import { useCallback, useEffect, useRef, useState } from "react";
4
4
  import { AgentView, Chrome, Connect, Home, ManageProjects, ManageTables, McpInstall, ScopeAdjust, SignIn, TooSmall, WizardProvider, MIN_COLS, MIN_ROWS, } from "./ui.js";
5
5
  // The alternate-screen takeover and dark theming (OSC 11/10) are set up in cli.tsx before the first render;
@@ -118,8 +118,13 @@ export function App({ services, fast, interactive, signedIn, demo, fullscreen })
118
118
  // Too-small guard (fullscreen only): below the minimum the frame clips/wraps, so show a resize prompt rather
119
119
  // than a broken layout. Reactive — useTerminalSize re-renders on resize, so enlarging restores the wizard.
120
120
  // Piped/CI (size null) is never gated: there's no window to resize and the output is plain and scrollable.
121
- if (size && (size.columns < MIN_COLS || size.rows < MIN_ROWS)) {
122
- return (_jsx(WizardProvider, { value: { services, fast, interactive, signedIn, demo }, children: _jsx(TooSmall, { size: size }) }));
123
- }
124
- return (_jsx(WizardProvider, { value: { services, fast, interactive, signedIn, demo }, children: _jsx(Chrome, { size: size, children: Current ? _jsx(Current, { ctx: ctx, onDone: onDone }) : null }) }));
121
+ const tooSmall = !!size && (size.columns < MIN_COLS || size.rows < MIN_ROWS);
122
+ // The wizard stays MOUNTED while the prompt shows — hidden with display:none, not swapped out — so resizing
123
+ // below the minimum and back preserves every screen's state and never re-runs its effects (e.g. AgentView
124
+ // would otherwise re-enqueue the onboarding job on each remount). Only the visible branch is rendered to the
125
+ // terminal; the hidden one lays out as nothing but keeps its React state and timers alive. Because it stays
126
+ // mounted, its input handlers also stay registered — so `tooSmall` is passed down and useGatedInput freezes
127
+ // every screen's useInput while hidden (otherwise a blind keypress could toggle a table or commit scope). The
128
+ // global escape handler above stays live, so the user can still quit from the resize prompt.
129
+ return (_jsxs(WizardProvider, { value: { services, fast, interactive, signedIn, demo, tooSmall }, children: [tooSmall && size && _jsx(TooSmall, { size: size }), _jsx(Box, { display: tooSmall ? "none" : "flex", flexDirection: "column", children: _jsx(Chrome, { size: size, children: Current ? _jsx(Current, { ctx: ctx, onDone: onDone }) : null }) })] }));
125
130
  }
package/dist/ui.js CHANGED
@@ -2,7 +2,7 @@ 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
7
  // ── utils ─────────────────────────────────────────────────────────────────────
8
8
  const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
@@ -25,6 +25,14 @@ function useWizard() {
25
25
  throw new Error("WizardProvider missing");
26
26
  return w;
27
27
  }
28
+ /** useInput for the screens, additionally frozen while the terminal is too small. The wizard is kept mounted
29
+ * (display:none) when too small so its state survives a resize — but its handlers must not act on keystrokes
30
+ * the user can't see (e.g. a blind watch/unwatch or scope commit). The global escape handler lives on raw
31
+ * useInput in app.tsx, so quitting still works while the resize prompt is up. */
32
+ function useGatedInput(handler, options) {
33
+ const { tooSmall } = useWizard();
34
+ useInput(handler, { ...options, isActive: (options?.isActive ?? true) && !tooSmall });
35
+ }
28
36
  // ── Fullscreen chrome ─────────────────────────────────────────────────────────
29
37
  // A persistent top bar (brand + version) and a bottom key-hint bar, with the active screen centered
30
38
  // between them — the whole wizard takes over the terminal (alternate screen; see app.tsx). Screens publish
@@ -258,7 +266,7 @@ export function SignIn({ onDone }) {
258
266
  void go(); // non-interactive: env/default provider, no picker
259
267
  return () => void (on = false);
260
268
  }, []);
261
- useInput((input, key) => {
269
+ useGatedInput((input, key) => {
262
270
  // Escape steps back through the text-entry stages (so it never destroys a half-typed sign-in);
263
271
  // from the picker or a transient stage it quits. SignIn owns escape entirely — App's global
264
272
  // handler defers to the sign-in screen.
@@ -370,88 +378,173 @@ function isWatchable(p) {
370
378
  return !p.status || p.status === "ACTIVE_HEALTHY";
371
379
  }
372
380
  const issuesLabel = (n) => `${n} ${n === 1 ? "issue" : "issues"}`;
381
+ const EMPTY_ORG_MSG = "This Supabase organization has no projects. Create one in Supabase, then run setup again.";
373
382
  export function Connect({ onDone }) {
374
383
  useFooter(_jsx(Text, { dimColor: true, children: "\u2191\u2193 move \u00B7 enter select \u00B7 green = watching \u00B7 yellow = offline \u00B7 esc to go back" }), []);
375
384
  const bodyRows = useBodyRows();
376
385
  const { services, interactive } = useWizard();
377
386
  const spin = useSpinner();
378
- const [connectionId, setConnectionId] = useState(null);
387
+ const [rows, setRows] = useState(null);
388
+ const [multiOrg, setMultiOrg] = useState(false);
389
+ // reused: rows came from EXISTING connection(s) (no browser) — enables the "connect a different org" row.
390
+ // authorizing: a fresh OAuth authorize is in flight (its browser message + abortable poll).
391
+ const [reused, setReused] = useState(false);
392
+ const [authorizing, setAuthorizing] = useState(false);
379
393
  const [alreadyConnected, setAlreadyConnected] = useState(false);
380
- const [projects, setProjects] = useState(null);
381
394
  const [cursor, setCursor] = useState(0);
382
395
  const [chosen, setChosen] = useState(null);
383
396
  const [error, setError] = useState(null);
397
+ // Abort controller for whichever load is in flight (the initial reuse-or-authorize, or a later "connect a
398
+ // different org"). Each async run captures its OWN signal, so leaving the screen (cleanup aborts it) can't set
399
+ // state, and a replacement run can't be revived by a stale one.
400
+ const abortRef = useRef(null);
401
+ function finishRow(row) {
402
+ const project = row?.project;
403
+ // Don't send an offline (paused/transitional) project into onboarding — the DB is unreachable, so it would
404
+ // fail deep in the job. Surface it here, up front and recoverable, instead.
405
+ if (project && !isWatchable(project)) {
406
+ setError(`"${project.name}" is paused in Supabase — resume it there, then run setup again.`);
407
+ return;
408
+ }
409
+ const ref = project?.ref ?? "";
410
+ setChosen(ref);
411
+ // alreadyWatching routes the hub: an already-watched project skips provisioning and goes straight to
412
+ // adjusting its tables; a new one is provisioned first. Set it explicitly so a later pick of a NEW project
413
+ // resets a flag left over from a previous "manage" round.
414
+ onDone({ connectionId: row?.connectionId ?? "", projectRef: ref, alreadyWatching: !!project?.watching });
415
+ }
416
+ // Present the gathered rows: the picker, or (single fresh project / non-interactive) auto-advance. A lone
417
+ // already-watched project shows the picker — there's nothing new to onboard — so reuse of a single watched
418
+ // project never silently advances.
419
+ function present(rws, multi, fromReuse) {
420
+ setRows(rws);
421
+ setMultiOrg(multi);
422
+ setReused(fromReuse);
423
+ setCursor(0);
424
+ if (!interactive || (rws.length === 1 && !rws[0]?.project.watching))
425
+ finishRow(rws[0]);
426
+ }
427
+ // Open the Supabase OAuth authorize (browser), then show the new org's projects. Used when no existing
428
+ // connection is reusable, and when the user picks "connect a different org".
429
+ async function authorize() {
430
+ abortRef.current?.abort();
431
+ const controller = new AbortController();
432
+ abortRef.current = controller;
433
+ const { signal } = controller;
434
+ setError(null);
435
+ setRows(null);
436
+ setChosen(null);
437
+ setReused(false);
438
+ setAuthorizing(true);
439
+ try {
440
+ // connect() opens the browser, polls the hosted handback, and self-completes with our own Bearer.
441
+ const { connectionId: cid, alreadyConnected: ac } = await services.connect(signal);
442
+ if (signal.aborted)
443
+ return;
444
+ setAlreadyConnected(!!ac);
445
+ const projs = await services.listProjects(cid);
446
+ if (signal.aborted)
447
+ return;
448
+ if (projs.length === 0) {
449
+ setError(EMPTY_ORG_MSG);
450
+ return;
451
+ }
452
+ present(projs.map((p) => ({ project: p, connectionId: cid })), false, false);
453
+ }
454
+ catch (e) {
455
+ if (!signal.aborted)
456
+ setError(e instanceof Error ? e.message : String(e));
457
+ }
458
+ finally {
459
+ if (!signal.aborted)
460
+ setAuthorizing(false);
461
+ }
462
+ }
384
463
  useEffect(() => {
385
- let on = true;
386
- // Abort the authorize poll when we leave this screen (escape back to the hub) so an abandoned
387
- // connect doesn't keep polling for up to 5 minutes — and a re-entry can't start a second,
388
- // competing poll loop against the same handback.
389
464
  const controller = new AbortController();
465
+ abortRef.current = controller;
466
+ const { signal } = controller;
467
+ // Reuse EVERY healthy existing connection first (no browser): gather the projects of all connections whose
468
+ // list we can fetch into one picker. Only if none have any projects do we open the authorize flow.
390
469
  (async () => {
470
+ let conns;
391
471
  try {
392
- // connect() opens the browser, polls the hosted handback, and self-completes with our own
393
- // Bearer — no browser web session needed (fixes the 401/403).
394
- const { connectionId: cid, alreadyConnected: ac } = await services.connect(controller.signal);
395
- if (!on)
396
- return;
397
- setConnectionId(cid);
398
- setAlreadyConnected(!!ac);
399
- const projs = await services.listProjects(cid);
400
- if (!on)
472
+ conns = await services.listConnections();
473
+ }
474
+ catch (e) {
475
+ if (signal.aborted)
401
476
  return;
402
- setProjects(projs);
403
- // No projects in the connected org → don't advance with an empty projectRef (which onboards nothing and
404
- // fails deep). Say so plainly.
405
- if (projs.length === 0) {
406
- setError("This Supabase organization has no projects. Create one in Supabase, then run setup again.");
477
+ // A Sodabase-auth failure (expired session) won't be fixed by the Supabase browser flow — surface it.
478
+ if (e instanceof ApiError && e.status === 401) {
479
+ setError("Your Sodabase session has expired. Run `sodabase --login`, then try again.");
407
480
  return;
408
481
  }
409
- if (projs.length === 1 || !interactive)
410
- finish(cid, projs[0]);
482
+ // Anything else (offline / 5xx): fall through to authorize, which surfaces its own errors.
483
+ await authorize();
484
+ return;
411
485
  }
412
- catch (e) {
413
- if (on && !controller.signal.aborted)
414
- setError(e instanceof Error ? e.message : String(e));
486
+ if (signal.aborted)
487
+ return;
488
+ const collected = [];
489
+ const orgs = new Set();
490
+ for (const c of conns) {
491
+ try {
492
+ const projs = await services.listProjects(c.connectionId);
493
+ if (signal.aborted)
494
+ return;
495
+ for (const p of projs)
496
+ collected.push({ project: p, connectionId: c.connectionId, org: c.orgSlug });
497
+ // Count distinct ORGS (so two connections to the same org don't trigger per-row org labels); fall back
498
+ // to the connection id when a slug is missing so each still counts as its own.
499
+ if (projs.length > 0)
500
+ orgs.add(c.orgSlug ?? c.connectionId);
501
+ }
502
+ catch {
503
+ /* stale/unhealthy connection — skip it (an empty org simply contributes no rows) */
504
+ }
415
505
  }
506
+ if (signal.aborted)
507
+ return;
508
+ if (collected.length > 0)
509
+ present(collected, orgs.size > 1, true);
510
+ else
511
+ await authorize(); // no reusable connection has projects → authorize a new org
416
512
  })();
417
- return () => {
418
- on = false;
419
- controller.abort();
420
- };
513
+ // Abort whichever controller is CURRENT — authorize() swaps in its own for the 5-minute connect() poll, so
514
+ // aborting the captured mount controller here would leave that poll running (and setting state) after unmount.
515
+ return () => abortRef.current?.abort();
421
516
  }, []);
422
- function finish(connId, project) {
423
- // Don't send an offline (paused/transitional) project into onboarding — the DB is unreachable, so it would
424
- // fail deep in the job. Surface it here, up front and recoverable, instead. Also covers the single-project
425
- // auto-select path, which skips the picker (and its tag) entirely.
426
- if (project && !isWatchable(project)) {
427
- setError(`"${project.name}" is paused in Supabase — resume it there, then run setup again.`);
428
- return;
429
- }
430
- const ref = project?.ref ?? "";
431
- setChosen(ref);
432
- // alreadyWatching routes the hub: an already-watched project skips provisioning and goes straight to
433
- // adjusting its tables; a new one is provisioned first. Set it explicitly (not just when true) so a
434
- // later pick of a NEW project resets the flag left over from a previous "manage" round.
435
- onDone({ connectionId: connId, projectRef: ref, alreadyWatching: !!project?.watching });
436
- }
437
- useInput((_i, key) => {
438
- if (!projects || chosen)
517
+ // The synthetic "connect a different Supabase org" row sits after the projects when reusing a connection.
518
+ const extraRow = reused;
519
+ useGatedInput((_i, key) => {
520
+ if (!rows || chosen || authorizing)
439
521
  return;
522
+ const max = rows.length - 1 + (extraRow ? 1 : 0);
440
523
  if (key.upArrow)
441
524
  setCursor((c) => Math.max(0, c - 1));
442
525
  else if (key.downArrow)
443
- setCursor((c) => Math.min(projects.length - 1, c + 1));
444
- else if (key.return && connectionId)
445
- finish(connectionId, projects[cursor]);
446
- }, { isActive: interactive && !!projects && !chosen });
447
- const picking = interactive && projects && projects.length > 1 && !chosen;
448
- return (_jsxs(Box, { flexDirection: "column", paddingX: 2, marginTop: 1, alignItems: "center", children: [_jsx(Eyebrow, { children: "Authorize your database" }), _jsx(Box, { marginTop: 1, flexDirection: "column", children: error ? (_jsx(Text, { color: "red", children: error })) : !connectionId ? (_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." }) })] })) : !projects ? (_jsxs(Text, { children: [_jsx(Text, { color: "green", children: spin }), " Loading your projects\u2026"] })) : picking ? ((() => {
449
- const win = windowList(projects, cursor, Math.max(3, bodyRows - 6));
450
- return (_jsxs(_Fragment, { children: [_jsx(Text, { children: "Pick the project to watch:" }), win.moreUp > 0 && _jsx(Text, { dimColor: true, children: ` ↑ ${win.moreUp} more` }), win.slice.map((p, idx) => {
526
+ setCursor((c) => Math.min(max, c + 1));
527
+ else if (key.return) {
528
+ if (extraRow && cursor === rows.length)
529
+ void authorize(); // picked "connect a different org"
530
+ else
531
+ finishRow(rows[cursor]);
532
+ }
533
+ }, { isActive: interactive && !!rows && !chosen && !authorizing });
534
+ // Show the picker whenever there are rows and nothing auto-advanced (chosen stays null). This covers a lone
535
+ // already-watched project on EITHER path — present() deliberately doesn't auto-advance it, so without this it
536
+ // would render the "done" confirmation yet never call onDone.
537
+ const picking = interactive && !!rows && !chosen;
538
+ const heading = authorizing ? "Authorize your database" : rows ? "Pick a project" : "Connect a project";
539
+ 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 ? ((() => {
540
+ const clamped = Math.min(cursor, rows.length - 1);
541
+ const win = windowList(rows, clamped, Math.max(3, bodyRows - (extraRow ? 7 : 6)));
542
+ 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) => {
451
543
  const i = win.start + idx;
452
- return (_jsxs(Text, { color: i === cursor ? "green" : undefined, children: [i === cursor ? "❯ " : " ", p.name, " ", _jsxs(Text, { dimColor: true, children: ["(", p.ref, ")"] }), projectTags(p).map((t) => (_jsxs(Text, { color: t.color, children: [" ", "\u00B7 ", t.label] }, t.label)))] }, p.ref));
453
- }), win.moreDown > 0 && _jsx(Text, { dimColor: true, children: ` ↓ ${win.moreDown} more` })] }));
454
- })()) : (_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 ?? projects[0]?.ref ?? "—" }), _jsx(Text, { color: "green", children: " 🔒 read-only, audited" })] })] })) })] }));
544
+ const p = row.project;
545
+ 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}`));
546
+ }), 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"] }))] }));
547
+ })()) : (_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" })] })] })) })] }));
455
548
  }
456
549
  // ── Phase: the server-side onboarding job (two-panel) ─────────────────────────────
457
550
  // Human labels for the backend onboarding job's step names (machine keys). Unknown names fall back to the raw
@@ -478,7 +571,7 @@ export function AgentView({ ctx, onDone }) {
478
571
  // completed step's line while the job sat on it, printing the same row several times over.
479
572
  const loggedRef = useRef(new Set());
480
573
  useFooter(_jsx(Text, { dimColor: true, children: finished ? "done · enter to continue" : "setting up… · esc to cancel" }), [finished]);
481
- useInput((_i, key) => {
574
+ useGatedInput((_i, key) => {
482
575
  if (key.return)
483
576
  onDone({});
484
577
  }, { isActive: interactive && finished });
@@ -593,7 +686,7 @@ export function ScopeAdjust({ onDone }) {
593
686
  setError(e instanceof Error ? e.message : String(e));
594
687
  }
595
688
  }
596
- useInput((_i, key) => {
689
+ useGatedInput((_i, key) => {
597
690
  if (!proposals || committed)
598
691
  return;
599
692
  if (key.upArrow)
@@ -689,7 +782,7 @@ export function McpInstall({ onDone }) {
689
782
  setError(e instanceof Error ? e.message : String(e));
690
783
  }
691
784
  }
692
- useInput((input, key) => {
785
+ useGatedInput((input, key) => {
693
786
  if (busy)
694
787
  return;
695
788
  if (ready) {
@@ -754,7 +847,7 @@ export function ManageProjects({ onDone }) {
754
847
  };
755
848
  }, []);
756
849
  const onboardRow = projects?.length ?? 0; // the "+ onboard a new project" row sits after the projects
757
- useInput((_i, key) => {
850
+ useGatedInput((_i, key) => {
758
851
  if (!projects)
759
852
  return;
760
853
  if (key.upArrow)
@@ -858,7 +951,7 @@ export function ManageTables({ ctx }) {
858
951
  }
859
952
  })();
860
953
  }
861
- useInput((input, key) => {
954
+ useGatedInput((input, key) => {
862
955
  if (!tables || tables.length === 0)
863
956
  return;
864
957
  if (key.upArrow)
@@ -935,7 +1028,7 @@ export function Home({ ctx, onDone }) {
935
1028
  const t = setTimeout(() => exit(), fast ? 400 : 3200);
936
1029
  return () => clearTimeout(t);
937
1030
  }, [interactive]);
938
- useInput((_i, key) => {
1031
+ useGatedInput((_i, key) => {
939
1032
  if (key.upArrow)
940
1033
  setCursor((c) => Math.max(0, c - 1));
941
1034
  else if (key.downArrow)
@@ -949,15 +1042,17 @@ export function Home({ ctx, onDone }) {
949
1042
  const list = projects ?? [];
950
1043
  const watching = list.length > 0;
951
1044
  const tables = list.reduce((a, p) => a + p.watched, 0);
952
- const issues = list.reduce((a, p) => a + p.openIssues, 0); // all open signals = anomalies + broken rules
1045
+ // The same issue total as the web app: anomalies + broken rules + data-quality findings, on watched tables.
1046
+ const issues = list.reduce((a, p) => a + totalIssues(p), 0);
953
1047
  const brokenRules = list.reduce((a, p) => a + p.brokenRules, 0);
954
- const anomalies = Math.max(0, issues - brokenRules);
1048
+ const dataQuality = list.reduce((a, p) => a + p.dataQualityIssues, 0);
1049
+ const anomalies = list.reduce((a, p) => a + anomalyCount(p), 0);
955
1050
  const monitors = list.reduce((a, p) => a + p.monitors, 0);
956
1051
  const rules = list.reduce((a, p) => a + p.rules, 0);
957
1052
  useFooter(_jsx(Text, { dimColor: true, children: "\u2191\u2193 move \u00B7 enter select \u00B7 esc to quit" }), []);
958
1053
  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 })] })) : (
959
1054
  // No email on the JWT — a role isn't an identity, so just name the workspace.
960
- _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")] })) : (_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) => {
1055
+ _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) => {
961
1056
  const here = i === cursor;
962
1057
  return (_jsxs(Text, { color: here ? "green" : undefined, children: [here ? "❯ " : " ", m.label, " ", _jsxs(Text, { dimColor: true, children: ["\u00B7 ", m.hint] })] }, m.id));
963
1058
  }) }) }))] }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sodabase",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "Sodabase onboarding wizard — interactive CLI (npx sodabase).",
5
5
  "license": "UNLICENSED",
6
6
  "homepage": "https://sodabase.io",
@@ -26,7 +26,7 @@
26
26
  "access": "public"
27
27
  },
28
28
  "bin": {
29
- "sodabase": "./dist/cli.js"
29
+ "sodabase": "dist/cli.js"
30
30
  },
31
31
  "files": [
32
32
  "dist"