@perceo/perceo 0.3.1 → 0.3.3

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.
@@ -189,6 +189,7 @@ var loginCommand = new Command("login").description("Log in to Perceo using Supa
189
189
  });
190
190
 
191
191
  export {
192
+ getGlobalConfigDir,
192
193
  getStoredAuth,
193
194
  clearStoredAuth,
194
195
  isLoggedIn,
package/dist/index.js CHANGED
@@ -2,10 +2,11 @@
2
2
  import {
3
3
  clearStoredAuth,
4
4
  getEffectiveAuth,
5
+ getGlobalConfigDir,
5
6
  getStoredAuth,
6
7
  isLoggedIn,
7
8
  loginCommand
8
- } from "./chunk-Y65GRRTT.js";
9
+ } from "./chunk-WLYZQC65.js";
9
10
 
10
11
  // src/index.ts
11
12
  import { Command as Command6 } from "commander";
@@ -373,6 +374,17 @@ import os from "os";
373
374
  var CONFIG_DIR2 = ".perceo";
374
375
  var CONFIG_FILE = "config.json";
375
376
  var SUPPORTED_FRAMEWORKS = ["nextjs", "react", "remix"];
377
+ function formatDbError(err) {
378
+ if (err instanceof Error) return err.message;
379
+ const o = err;
380
+ if (o && typeof o.message === "string") {
381
+ const parts = [o.message];
382
+ if (typeof o.code === "string") parts.push(`(code: ${o.code})`);
383
+ if (typeof o.details === "string") parts.push(o.details);
384
+ return parts.join(" ");
385
+ }
386
+ return String(err);
387
+ }
376
388
  var initCommand = new Command("init").description("Initialize Perceo in your project and discover flows").option("-d, --dir <directory>", "Project directory", process.cwd()).option("--skip-github", "Skip GitHub Actions setup", false).option("-y, --yes", "Skip confirmation prompt (e.g. for CI)", false).option("-b, --branch <branch>", "Main branch name (default: auto-detect)").option("--configure-personas", "Configure custom user personas instead of auto-generating them", false).action(async (options) => {
377
389
  const projectDir = path3.resolve(options.dir || process.cwd());
378
390
  const loggedIn = await isLoggedIn(projectDir);
@@ -467,7 +479,7 @@ var initCommand = new Command("init").description("Initialize Perceo in your pro
467
479
  } catch (dbError) {
468
480
  spinner.fail("Failed to query project");
469
481
  console.error(chalk3.red("\nDatabase error details:"));
470
- console.error(chalk3.gray(` Error: ${dbError instanceof Error ? dbError.message : String(dbError)}`));
482
+ console.error(chalk3.gray(` ${formatDbError(dbError)}`));
471
483
  throw new Error("Failed to query project from database");
472
484
  }
473
485
  if (!tempProject) {
@@ -482,7 +494,7 @@ var initCommand = new Command("init").description("Initialize Perceo in your pro
482
494
  } catch (createError) {
483
495
  spinner.fail("Failed to create project");
484
496
  console.error(chalk3.red("\nDatabase error details:"));
485
- console.error(chalk3.gray(` Error: ${createError instanceof Error ? createError.message : String(createError)}`));
497
+ console.error(chalk3.gray(` ${formatDbError(createError)}`));
486
498
  throw new Error("Failed to create project in database");
487
499
  }
488
500
  } else {
@@ -747,7 +759,7 @@ Persona ${personaIndex}:`));
747
759
  } catch (dbError) {
748
760
  spinner.fail("Failed to query project");
749
761
  console.error(chalk3.red("\nDatabase error details:"));
750
- console.error(chalk3.gray(` Error: ${dbError instanceof Error ? dbError.message : String(dbError)}`));
762
+ console.error(chalk3.gray(` ${formatDbError(dbError)}`));
751
763
  throw new Error("Failed to query project from database");
752
764
  }
753
765
  if (!project) {
@@ -762,7 +774,7 @@ Persona ${personaIndex}:`));
762
774
  } catch (createError) {
763
775
  spinner.fail("Failed to create project");
764
776
  console.error(chalk3.red("\nDatabase error details:"));
765
- console.error(chalk3.gray(` Error: ${createError instanceof Error ? createError.message : String(createError)}`));
777
+ console.error(chalk3.gray(` ${formatDbError(createError)}`));
766
778
  throw new Error("Failed to create project in database");
767
779
  }
768
780
  } else if (gitRemoteUrl && project.git_remote_url !== gitRemoteUrl) {
@@ -1259,7 +1271,7 @@ async function requireReauth(projectDir) {
1259
1271
  }
1260
1272
  console.log(chalk5.cyan("\nPlease log in again:"));
1261
1273
  try {
1262
- const { loginCommand: loginCommand2 } = await import("./login-47R62VE3.js");
1274
+ const { loginCommand: loginCommand2 } = await import("./login-4TG7LXUP.js");
1263
1275
  await loginCommand2.parseAsync(["login", "--scope", "global"], { from: "user" });
1264
1276
  return true;
1265
1277
  } catch (error) {
@@ -1775,6 +1787,94 @@ function formatDate(dateStr) {
1775
1787
  });
1776
1788
  }
1777
1789
 
1790
+ // src/publicEnv.ts
1791
+ import { readFileSync } from "fs";
1792
+ import fs4 from "fs/promises";
1793
+ import path7 from "path";
1794
+ import { fileURLToPath } from "url";
1795
+ var PUBLIC_ENV_FILE = "public-env.json";
1796
+ var PERCEO_CLOUD_SUPABASE_URL = "https://lygslnolucoidnhaitdn.supabase.co";
1797
+ function getPublicEnvPath() {
1798
+ return path7.join(getGlobalConfigDir(), PUBLIC_ENV_FILE);
1799
+ }
1800
+ function getCliVersion() {
1801
+ try {
1802
+ const dir = path7.dirname(fileURLToPath(import.meta.url));
1803
+ const pkgPath = path7.join(dir, "..", "package.json");
1804
+ const raw = readFileSync(pkgPath, "utf8");
1805
+ const pkg = JSON.parse(raw);
1806
+ return typeof pkg.version === "string" ? pkg.version : "0.0.0";
1807
+ } catch {
1808
+ return "0.0.0";
1809
+ }
1810
+ }
1811
+ async function fileExists4(p) {
1812
+ try {
1813
+ await fs4.access(p);
1814
+ return true;
1815
+ } catch {
1816
+ return false;
1817
+ }
1818
+ }
1819
+ async function readCache(cachePath) {
1820
+ if (!await fileExists4(cachePath)) return null;
1821
+ try {
1822
+ const raw = await fs4.readFile(cachePath, "utf8");
1823
+ const data = JSON.parse(raw);
1824
+ if (!data || typeof data._meta !== "object" || typeof data._meta?.cliVersion !== "string") return null;
1825
+ return data;
1826
+ } catch {
1827
+ return null;
1828
+ }
1829
+ }
1830
+ function applyToProcessEnv(env) {
1831
+ for (const [key, value] of Object.entries(env)) {
1832
+ if (key === "_meta" || typeof value !== "string") continue;
1833
+ if (process.env[key] === void 0) {
1834
+ process.env[key] = value;
1835
+ }
1836
+ }
1837
+ }
1838
+ async function fetchPublicEnv(supabaseUrl) {
1839
+ const url = `${supabaseUrl.replace(/\/$/, "")}/functions/v1/get-public-env`;
1840
+ const res = await fetch(url);
1841
+ if (!res.ok) {
1842
+ throw new Error(`get-public-env failed: ${res.status} ${res.statusText}`);
1843
+ }
1844
+ const data = await res.json();
1845
+ if (data == null || typeof data !== "object") {
1846
+ throw new Error("get-public-env returned invalid JSON");
1847
+ }
1848
+ return data;
1849
+ }
1850
+ async function ensurePublicEnvLoaded() {
1851
+ if (process.env.PERCEO_SUPABASE_URL) {
1852
+ return;
1853
+ }
1854
+ const supabaseUrl = PERCEO_CLOUD_SUPABASE_URL;
1855
+ const cachePath = getPublicEnvPath();
1856
+ const currentVersion = getCliVersion();
1857
+ const cached = await readCache(cachePath);
1858
+ if (cached && cached._meta.cliVersion === currentVersion) {
1859
+ applyToProcessEnv(cached);
1860
+ return;
1861
+ }
1862
+ try {
1863
+ const env = await fetchPublicEnv(supabaseUrl);
1864
+ const toWrite = {
1865
+ _meta: { fetchedAt: (/* @__PURE__ */ new Date()).toISOString(), cliVersion: currentVersion },
1866
+ ...env
1867
+ };
1868
+ await fs4.mkdir(path7.dirname(cachePath), { recursive: true });
1869
+ await fs4.writeFile(cachePath, JSON.stringify(toWrite, null, 2) + "\n", "utf8");
1870
+ applyToProcessEnv(env);
1871
+ } catch {
1872
+ if (cached) {
1873
+ applyToProcessEnv(cached);
1874
+ }
1875
+ }
1876
+ }
1877
+
1778
1878
  // src/index.ts
1779
1879
  var originalEmit = process.emit.bind(process);
1780
1880
  process.emit = function(event, ...args) {
@@ -1785,11 +1885,18 @@ process.emit = function(event, ...args) {
1785
1885
  return originalEmit.apply(process, [event, ...args]);
1786
1886
  };
1787
1887
  var program = new Command6();
1788
- program.name("perceo").description("Intelligent regression testing through multi-agent simulation").version("0.1.0");
1888
+ program.name("perceo").description("Intelligent regression testing through multi-agent simulation").version(getCliVersion());
1789
1889
  program.addCommand(loginCommand);
1790
1890
  program.addCommand(logoutCommand);
1791
1891
  program.addCommand(initCommand);
1792
1892
  program.addCommand(delCommand);
1793
1893
  program.addCommand(analyzeCommand);
1794
1894
  program.addCommand(keysCommand);
1795
- program.parse();
1895
+ async function main() {
1896
+ await ensurePublicEnvLoaded();
1897
+ await program.parseAsync();
1898
+ }
1899
+ main().catch((err) => {
1900
+ console.error(err instanceof Error ? err.message : err);
1901
+ process.exit(1);
1902
+ });
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  loginCommand
3
- } from "./chunk-Y65GRRTT.js";
3
+ } from "./chunk-WLYZQC65.js";
4
4
  export {
5
5
  loginCommand
6
6
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perceo/perceo",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "Intelligent regression testing through multi-agent simulation",
5
5
  "keywords": [
6
6
  "testing",
@@ -37,8 +37,8 @@
37
37
  "commander": "^12.0.0",
38
38
  "ora": "^8.0.1",
39
39
  "tweetnacl": "^1.0.3",
40
- "@perceo/observer-engine": "2.0.1",
41
- "@perceo/supabase": "0.2.0"
40
+ "@perceo/observer-engine": "2.0.3",
41
+ "@perceo/supabase": "0.2.2"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@changesets/cli": "^2.29.8",