passcontrol 0.5.0 → 0.5.1

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.
Files changed (2) hide show
  1. package/bin/passcontrol.mjs +104 -10
  2. package/package.json +1 -1
@@ -131,7 +131,7 @@ ${heading("Usage:")}
131
131
  ${cmd} show cockpit status
132
132
  ${cmd} init [--global] create a config profile
133
133
  ${cmd} status [--no-network] show active config
134
- ${cmd} start start the configured local dashboard
134
+ ${cmd} start [--dashboard-only] start the whole local stack (dashboard + Supabase + Redis)
135
135
  ${cmd} stop [--dashboard-only] stop the whole local stack (dashboard + Supabase + Redis)
136
136
  ${cmd} restart restart the CLI-managed local dashboard
137
137
  ${cmd} local-logs [--follow] show local dashboard logs
@@ -478,11 +478,93 @@ async function ensureAppRoot({ clone = false, appDir, yes = false } = {}) {
478
478
  return appRoot;
479
479
  }
480
480
 
481
- function localComposeProjectName() {
481
+ // The Supabase project id setup baked into supabase/config.toml. Read it back
482
+ // rather than re-deriving it from the directory name and a --port-offset: the
483
+ // offset is a setup-time flag nobody passes again on `start`, and config.toml is
484
+ // what the Supabase CLI itself will use.
485
+ function localSupabaseProjectId() {
482
486
  const configPath = path.join(appRoot, "supabase", "config.toml");
483
487
  const configText = fs.existsSync(configPath) ? fs.readFileSync(configPath, "utf8") : "";
484
- const projectId = configText.match(/^project_id\s*=\s*"([^"]+)"\s*$/m)?.[1] ?? path.basename(appRoot);
485
- return `passcontrol_${projectId.replace(/[^A-Za-z0-9]/g, "_").toLowerCase()}`;
488
+ return configText.match(/^project_id\s*=\s*"([^"]+)"\s*$/m)?.[1] ?? path.basename(appRoot);
489
+ }
490
+
491
+ function localComposeProjectName() {
492
+ return `passcontrol_${localSupabaseProjectId().replace(/[^A-Za-z0-9]/g, "_").toLowerCase()}`;
493
+ }
494
+
495
+ // Same container filter scripts/dev-stack.sh uses to find the DB to migrate.
496
+ function localSupabaseIsRunning() {
497
+ try {
498
+ return Boolean(
499
+ execFileSync(
500
+ "docker",
501
+ ["ps", "-q", "--filter", `label=com.supabase.cli.project=${localSupabaseProjectId()}`, "--filter", "name=supabase_db"],
502
+ { encoding: "utf8" }
503
+ ).trim()
504
+ );
505
+ } catch {
506
+ return false;
507
+ }
508
+ }
509
+
510
+ // The port the dashboard will actually reach Redis on, read from the env file
511
+ // rather than assumed. `setup --port-offset N` moves SRH, and bringing compose
512
+ // up on the compose default while the app reads the offset port gives you a
513
+ // Redis that is up and unreachable — every nonce, budget reservation and
514
+ // kill-switch read failing against a container that looks healthy in `docker ps`.
515
+ function localRedisPort() {
516
+ const compose = fs.readFileSync(path.join(appRoot, "docker", "compose.yml"), "utf8");
517
+ const fallback = Number(compose.match(/PASSCONTROL_SRH_PORT:-(\d+)/)?.[1] ?? 8079);
518
+ try {
519
+ const envText = fs.readFileSync(path.join(appRoot, ".env.docker"), "utf8");
520
+ const port = Number(new URL(envText.match(/^UPSTASH_REDIS_REST_URL=(.*)$/m)?.[1]?.trim()).port);
521
+ if (Number.isInteger(port) && port > 0 && port < 65536) return port;
522
+ } catch {
523
+ // An unreadable or malformed env file is reported by the caller's own
524
+ // configuration check; fall back rather than failing here.
525
+ }
526
+ return fallback;
527
+ }
528
+
529
+ // The other half of `passcontrol start`. `stop` takes the dashboard, Supabase and
530
+ // Redis down together; a start that raised only the dashboard left that pair
531
+ // asymmetric, and the result is worse than a plain failure — the Control Tower
532
+ // comes back up and every page on it errors, because the Postgres it reads and
533
+ // the Redis holding the kill switch are both still stopped. Nothing on screen
534
+ // names the cause.
535
+ //
536
+ // Deliberately NOT `npm run dev:stack`. That script also rewrites .env.docker,
537
+ // applies every migration and seeds a dev user: first-run work that belongs to
538
+ // `setup`, and that would turn a routine restart into a schema event. `start`
539
+ // raises exactly what `stop` lowered, and nothing else.
540
+ async function startLocalServices() {
541
+ for (const check of [checkDockerInstalled(), checkDockerDaemon(), checkSupabaseInstalled()]) {
542
+ if (!check.ok) throw new Error(check.message);
543
+ }
544
+
545
+ if (localSupabaseIsRunning()) {
546
+ ok("Supabase already running");
547
+ } else {
548
+ step("Starting Supabase (Postgres, Vault, Auth)…");
549
+ // -x studio mirrors scripts/dev-stack.sh: Studio's image is flaky enough
550
+ // here to fail its health check and roll the whole stack back, and nothing
551
+ // depends on it — PassControl ships its own dashboard.
552
+ await runLocalCommand("supabase", ["start", "-x", "studio"]);
553
+ ok("Supabase running");
554
+ }
555
+
556
+ const redisPort = localRedisPort();
557
+ if (await portIsListening(redisPort)) {
558
+ ok(`Redis already running on port ${redisPort}`);
559
+ } else {
560
+ step("Starting Redis…");
561
+ await runLocalCommand("docker", ["compose", "-f", "docker/compose.yml", "up", "-d"], {
562
+ ...process.env,
563
+ COMPOSE_PROJECT_NAME: localComposeProjectName(),
564
+ PASSCONTROL_SRH_PORT: String(redisPort),
565
+ });
566
+ ok(`Redis running on port ${redisPort}`);
567
+ }
486
568
  }
487
569
 
488
570
  function localDashboard() {
@@ -639,9 +721,23 @@ async function runLocalPrerequisiteChecks({ offset = 0, report = false, enforce
639
721
  return results;
640
722
  }
641
723
 
724
+ // `passcontrol start` — one command for "start PassControl", the mirror of what
725
+ // `stop` already does. The configuration check and the services come BEFORE the
726
+ // gateway health check on purpose: "the dashboard is answering" is not the same
727
+ // claim as "PassControl is up", and returning early on it is how you end up with
728
+ // a Control Tower talking to a stopped database.
642
729
  async function startDashboard(opts = {}) {
643
730
  await ensureAppRoot({ clone: true, appDir: opts.appDir, yes: opts.yes });
644
731
  const dashboard = localDashboard();
732
+
733
+ const envFile = path.join(appRoot, ".env.docker");
734
+ if (!fs.existsSync(envFile)) {
735
+ throw new Error(`Local stack is not configured. Run \`${cliCommand("setup")}\` in ${appRoot} first.`);
736
+ }
737
+
738
+ if (opts.dashboardOnly) step("Leaving Supabase and Redis alone (--dashboard-only).");
739
+ else await startLocalServices();
740
+
645
741
  if ((await gatewayStatus(false)).ok) {
646
742
  ok(`dashboard already online at ${dashboard.url}`);
647
743
  return dashboard;
@@ -657,11 +753,6 @@ async function startDashboard(opts = {}) {
657
753
  throw new Error(`CLI-managed dashboard (PID ${running.pid}) did not become ready. See ${running.logPath}.`);
658
754
  }
659
755
 
660
- const envFile = path.join(appRoot, ".env.docker");
661
- if (!fs.existsSync(envFile)) {
662
- throw new Error(`Local stack is not configured. Run \`${cliCommand("setup")}\` in ${appRoot} first.`);
663
- }
664
-
665
756
  const statePath = dashboardStatePath();
666
757
  const logPath = dashboardLogPath();
667
758
  fs.mkdirSync(path.dirname(statePath), { recursive: true, mode: 0o700 });
@@ -890,7 +981,10 @@ async function setupLocal(opts = {}) {
890
981
  ...process.env,
891
982
  PASSCONTROL_PORT_OFFSET: String(offset),
892
983
  });
893
- await startDashboard(opts);
984
+ // dev:stack has just brought Supabase and Redis up (and would have exited
985
+ // non-zero if it hadn't), so skip start's own service pass rather than print
986
+ // two "already running" lines under a banner that just said the stack is up.
987
+ await startDashboard({ ...opts, dashboardOnly: true });
894
988
  if (!opts.noOpen) await openDashboard(opts);
895
989
  console.log(`\n${formatLabel("Local dashboard", dashboard.url, 19)}`);
896
990
  console.log(formatLabel("Login", "the account you created during setup", 19));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "passcontrol",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "Secure Agent Control Plane & Passport Vault — identity-aware reverse proxy for AI agent credentials.",
5
5
  "license": "BUSL-1.1",
6
6
  "homepage": "https://github.com/Vertias3u/PassControl#readme",