@powerhousedao/ph-cli 6.2.3-dev.6 → 6.2.3-dev.60

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 (122) hide show
  1. package/dist/{auth-AR3VxAIk.mjs → auth-BFUq7CvE.mjs} +3 -3
  2. package/dist/{auth-AR3VxAIk.mjs.map → auth-BFUq7CvE.mjs.map} +1 -1
  3. package/dist/auth-CNhbN5UM.mjs +4 -0
  4. package/dist/build-DmqwT-PR.mjs +4 -0
  5. package/dist/build-skPHsKkL.mjs +210 -0
  6. package/dist/build-skPHsKkL.mjs.map +1 -0
  7. package/dist/{cli-connect-override-D3hh4aH_.mjs → cli-connect-override-65mFEDEB.mjs} +38 -26
  8. package/dist/cli-connect-override-65mFEDEB.mjs.map +1 -0
  9. package/dist/cli.d.mts +2 -1
  10. package/dist/cli.mjs +31 -1175
  11. package/dist/cli.mjs.map +1 -1
  12. package/dist/connect-build-D9zrBKG4.mjs +218 -0
  13. package/dist/connect-build-D9zrBKG4.mjs.map +1 -0
  14. package/dist/{connect-config-BWGiW3IB.mjs → connect-config-C1tf7DqD.mjs} +19 -12
  15. package/dist/connect-config-C1tf7DqD.mjs.map +1 -0
  16. package/dist/connect-preview-Clue7SVp.mjs +122 -0
  17. package/dist/connect-preview-Clue7SVp.mjs.map +1 -0
  18. package/dist/connect-studio-BbsQuED_.mjs +4 -0
  19. package/dist/{connect-studio-D6rfWCNB.mjs → connect-studio-Q93rzqnC.mjs} +15 -10
  20. package/dist/{connect-studio-D6rfWCNB.mjs.map → connect-studio-Q93rzqnC.mjs.map} +1 -1
  21. package/dist/dist-D-CZUgtS.mjs +222 -0
  22. package/dist/dist-D-CZUgtS.mjs.map +1 -0
  23. package/dist/explain-BHB_4rJ3.mjs +27 -0
  24. package/dist/explain-BHB_4rJ3.mjs.map +1 -0
  25. package/dist/feature-flags-xwqcHEWC.mjs +4 -0
  26. package/dist/{generate-all-DrT4ZxHX.mjs → generate-all-CRfVwLJ9.mjs} +5 -3
  27. package/dist/generate-all-CRfVwLJ9.mjs.map +1 -0
  28. package/dist/{generate-app-DNNqA-H3.mjs → generate-app-BTs1u-9l.mjs} +7 -5
  29. package/dist/{generate-app-DNNqA-H3.mjs.map → generate-app-BTs1u-9l.mjs.map} +1 -1
  30. package/dist/{generate-document-model-BJXyODfm.mjs → generate-document-model-ChkXjM1s.mjs} +19 -7
  31. package/dist/generate-document-model-ChkXjM1s.mjs.map +1 -0
  32. package/dist/{generate-editor-BejvaVVT.mjs → generate-editor-CW7Do69u.mjs} +7 -5
  33. package/dist/{generate-editor-BejvaVVT.mjs.map → generate-editor-CW7Do69u.mjs.map} +1 -1
  34. package/dist/generate-piece-QTt-ddt2.mjs +65 -0
  35. package/dist/generate-piece-QTt-ddt2.mjs.map +1 -0
  36. package/dist/generate-piece-action-DbxrzfKY.mjs +29 -0
  37. package/dist/generate-piece-action-DbxrzfKY.mjs.map +1 -0
  38. package/dist/generate-piece-trigger-CqVOcL9g.mjs +30 -0
  39. package/dist/generate-piece-trigger-CqVOcL9g.mjs.map +1 -0
  40. package/dist/{generate-processor-_WOx-mMe.mjs → generate-processor-DBtTkgo5.mjs} +15 -8
  41. package/dist/generate-processor-DBtTkgo5.mjs.map +1 -0
  42. package/dist/{generate-subgraph-BsHUstpl.mjs → generate-subgraph-DmcQWVbd.mjs} +12 -6
  43. package/dist/generate-subgraph-DmcQWVbd.mjs.map +1 -0
  44. package/dist/host-schemas-CL_wFpY7-DOvIjrBA.mjs +478 -0
  45. package/dist/host-schemas-CL_wFpY7-DOvIjrBA.mjs.map +1 -0
  46. package/dist/index-CApW1xbO.d.mts +3752 -0
  47. package/dist/index-CApW1xbO.d.mts.map +1 -0
  48. package/dist/{init-BZP6gvYd.mjs → init-ScuT3z7P.mjs} +7 -5
  49. package/dist/init-ScuT3z7P.mjs.map +1 -0
  50. package/dist/{inspect-DXjbQEV_.mjs → inspect-BpCB0TPo.mjs} +11 -4
  51. package/dist/inspect-BpCB0TPo.mjs.map +1 -0
  52. package/dist/install-added-dependencies-DVSbzler.mjs +33 -0
  53. package/dist/install-added-dependencies-DVSbzler.mjs.map +1 -0
  54. package/dist/{migrate-jGKfE02L.mjs → migrate-DK4HK7Dn.mjs} +4 -4
  55. package/dist/{migrate-jGKfE02L.mjs.map → migrate-DK4HK7Dn.mjs.map} +1 -1
  56. package/dist/ph-cli-commands-BxKtXZgb.mjs +4 -0
  57. package/dist/ph-cli-commands-DGOKk392.mjs +1452 -0
  58. package/dist/ph-cli-commands-DGOKk392.mjs.map +1 -0
  59. package/dist/plugins-DtJUVtyg.mjs +4046 -0
  60. package/dist/plugins-DtJUVtyg.mjs.map +1 -0
  61. package/dist/reactor-env-CchCHhA0.mjs +4 -0
  62. package/dist/reactor-env-DHBr4V4W.mjs +29 -0
  63. package/dist/reactor-env-DHBr4V4W.mjs.map +1 -0
  64. package/dist/{registry-auth-DxEWCJu2.mjs → registry-auth-Bm5AR-fB.mjs} +4 -4
  65. package/dist/{registry-auth-DxEWCJu2.mjs.map → registry-auth-Bm5AR-fB.mjs.map} +1 -1
  66. package/dist/run-sugar-Dq3ZrLL_.mjs +39 -0
  67. package/dist/run-sugar-Dq3ZrLL_.mjs.map +1 -0
  68. package/dist/runners/compound.d.mts +127 -0
  69. package/dist/runners/compound.d.mts.map +1 -0
  70. package/dist/runners/compound.mjs +72 -0
  71. package/dist/runners/compound.mjs.map +1 -0
  72. package/dist/runners/connect.d.mts +144 -0
  73. package/dist/runners/connect.d.mts.map +1 -0
  74. package/dist/runners/connect.mjs +184 -0
  75. package/dist/runners/connect.mjs.map +1 -0
  76. package/dist/runners/switchboard.d.mts +139 -0
  77. package/dist/runners/switchboard.d.mts.map +1 -0
  78. package/dist/runners/switchboard.mjs +141 -0
  79. package/dist/runners/switchboard.mjs.map +1 -0
  80. package/dist/scripts/generate-commands-docs.ts +8 -0
  81. package/dist/scripts/manage-environment +0 -0
  82. package/dist/scripts/setup.sh +0 -0
  83. package/dist/start-run-DsZRHbM1.mjs +36 -0
  84. package/dist/start-run-DsZRHbM1.mjs.map +1 -0
  85. package/dist/superseded-config-9D7BdLvd.mjs +53 -0
  86. package/dist/superseded-config-9D7BdLvd.mjs.map +1 -0
  87. package/dist/switchboard-BUMqobK4.mjs +4 -0
  88. package/dist/{switchboard-migrate-NQ7LHWSi.mjs → switchboard-migrate-7JQZM7-5.mjs} +5 -4
  89. package/dist/{switchboard-migrate-NQ7LHWSi.mjs.map → switchboard-migrate-7JQZM7-5.mjs.map} +1 -1
  90. package/dist/{switchboard-reset-BcQXlcVf.mjs → switchboard-reset-CX_Lzw3O.mjs} +4 -4
  91. package/dist/{switchboard-reset-BcQXlcVf.mjs.map → switchboard-reset-CX_Lzw3O.mjs.map} +1 -1
  92. package/dist/switchboard-tQS3fhqa.mjs +132 -0
  93. package/dist/switchboard-tQS3fhqa.mjs.map +1 -0
  94. package/dist/{utils-BzwczAW-.mjs → utils-C3c5YG6v.mjs} +3 -3
  95. package/dist/{utils-C4isxXSO.mjs → utils-CvmDmCVd.mjs} +3 -3
  96. package/dist/{utils-C4isxXSO.mjs.map → utils-CvmDmCVd.mjs.map} +1 -1
  97. package/dist/{vetra-DkF6EJMY.mjs → vetra-BNJZ5LHN.mjs} +66 -31
  98. package/dist/vetra-BNJZ5LHN.mjs.map +1 -0
  99. package/dist/warn-subgraph-type-conflicts-Jd6SeN-M.mjs +19 -0
  100. package/dist/warn-subgraph-type-conflicts-Jd6SeN-M.mjs.map +1 -0
  101. package/package.json +41 -17
  102. package/dist/auth-BNkN6kS9.mjs +0 -4
  103. package/dist/build-C-A5-ipO.mjs +0 -4
  104. package/dist/build-uQXq6_HU.mjs +0 -71
  105. package/dist/build-uQXq6_HU.mjs.map +0 -1
  106. package/dist/cli-connect-override-D3hh4aH_.mjs.map +0 -1
  107. package/dist/connect-build-WL4axo4z.mjs +0 -43
  108. package/dist/connect-build-WL4axo4z.mjs.map +0 -1
  109. package/dist/connect-config-BWGiW3IB.mjs.map +0 -1
  110. package/dist/connect-preview-D7ypzFDc.mjs +0 -28
  111. package/dist/connect-preview-D7ypzFDc.mjs.map +0 -1
  112. package/dist/connect-studio-BIQzyq5B.mjs +0 -5
  113. package/dist/generate-all-DrT4ZxHX.mjs.map +0 -1
  114. package/dist/generate-document-model-BJXyODfm.mjs.map +0 -1
  115. package/dist/generate-processor-_WOx-mMe.mjs.map +0 -1
  116. package/dist/generate-subgraph-BsHUstpl.mjs.map +0 -1
  117. package/dist/init-BZP6gvYd.mjs.map +0 -1
  118. package/dist/inspect-DXjbQEV_.mjs.map +0 -1
  119. package/dist/switchboard-CJMoMzWx.mjs +0 -75
  120. package/dist/switchboard-CJMoMzWx.mjs.map +0 -1
  121. package/dist/switchboard-iRFugh8I.mjs +0 -4
  122. package/dist/vetra-DkF6EJMY.mjs.map +0 -1
@@ -0,0 +1,53 @@
1
+
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="0ed57c92-e10e-5f6c-a833-8f0a8c8d722c")}catch(e){}}();
3
+ import fs from "node:fs";
4
+ import path from "node:path";
5
+ //#region src/services/run/superseded-config.ts
6
+ /**
7
+ * P2.7 — the fixed legacy→hosts mapping table. With hosts/ active, these
8
+ * powerhouse.config.json keys are superseded by host.js structure and the run
9
+ * path ignores them; each present key warns ONCE per run, naming its new home.
10
+ *
11
+ * Keys the scaffolded host files REFERENCE (studio.port, reactor.port,
12
+ * vetra.connectPort, and the WHOLE connect.* block — handed to the runtime
13
+ * unchanged, connect.instance.* included) are expected to remain and are
14
+ * deliberately absent from this table.
15
+ */
16
+ const SUPERSEDED = {
17
+ "studio.host": "hosts/connect/host.js → runner.host",
18
+ "studio.https": "hosts/connect/host.js → runner.https",
19
+ "studio.openBrowser": "hosts/connect/host.js → runner.openBrowser",
20
+ "reactor.https": "hosts/switchboard/host.js → runner.https",
21
+ "reactor.storage": "hosts/switchboard/host.js → reactor.backends.<name>.storage",
22
+ "switchboard.database.url": "hosts/switchboard/host.js → reactor.backends.<name>.storage.url"
23
+ };
24
+ function lookup(config, dottedKey) {
25
+ let cursor = config;
26
+ for (const part of dottedKey.split(".")) {
27
+ if (cursor === null || typeof cursor !== "object") return void 0;
28
+ cursor = cursor[part];
29
+ }
30
+ return cursor;
31
+ }
32
+ /** Warn once per run for each superseded key present in the project config.
33
+ * Returns the warned keys (for tests). Never throws — a malformed config is
34
+ * the loader's problem, not the warner's. */
35
+ function warnSupersededConfigKeys(projectRoot, warn = console.warn) {
36
+ let config;
37
+ try {
38
+ config = JSON.parse(fs.readFileSync(path.join(projectRoot, "powerhouse.config.json"), "utf8"));
39
+ } catch {
40
+ return [];
41
+ }
42
+ const warned = [];
43
+ for (const [key, newHome] of Object.entries(SUPERSEDED)) if (lookup(config, key) !== void 0) {
44
+ warned.push(key);
45
+ warn(`[ph run] powerhouse.config.json "${key}" is ignored in hosts projects — its home is now ${newHome}.`);
46
+ }
47
+ return warned;
48
+ }
49
+ //#endregion
50
+ export { warnSupersededConfigKeys };
51
+
52
+ //# sourceMappingURL=superseded-config-9D7BdLvd.mjs.map
53
+ //# debugId=0ed57c92-e10e-5f6c-a833-8f0a8c8d722c
@@ -0,0 +1 @@
1
+ {"version":3,"file":"superseded-config-9D7BdLvd.mjs","sources":["../src/services/run/superseded-config.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\n\n/**\n * P2.7 — the fixed legacy→hosts mapping table. With hosts/ active, these\n * powerhouse.config.json keys are superseded by host.js structure and the run\n * path ignores them; each present key warns ONCE per run, naming its new home.\n *\n * Keys the scaffolded host files REFERENCE (studio.port, reactor.port,\n * vetra.connectPort, and the WHOLE connect.* block — handed to the runtime\n * unchanged, connect.instance.* included) are expected to remain and are\n * deliberately absent from this table.\n */\nconst SUPERSEDED: Record<string, string> = {\n \"studio.host\": \"hosts/connect/host.js → runner.host\",\n \"studio.https\": \"hosts/connect/host.js → runner.https\",\n \"studio.openBrowser\": \"hosts/connect/host.js → runner.openBrowser\",\n \"reactor.https\": \"hosts/switchboard/host.js → runner.https\",\n \"reactor.storage\":\n \"hosts/switchboard/host.js → reactor.backends.<name>.storage\",\n \"switchboard.database.url\":\n \"hosts/switchboard/host.js → reactor.backends.<name>.storage.url\",\n};\n\nfunction lookup(config: unknown, dottedKey: string): unknown {\n let cursor: unknown = config;\n for (const part of dottedKey.split(\".\")) {\n if (cursor === null || typeof cursor !== \"object\") return undefined;\n cursor = (cursor as Record<string, unknown>)[part];\n }\n return cursor;\n}\n\n/** Warn once per run for each superseded key present in the project config.\n * Returns the warned keys (for tests). Never throws — a malformed config is\n * the loader's problem, not the warner's. */\nexport function warnSupersededConfigKeys(\n projectRoot: string,\n warn: (message: string) => void = console.warn,\n): string[] {\n let config: unknown;\n try {\n config = JSON.parse(\n fs.readFileSync(path.join(projectRoot, \"powerhouse.config.json\"), \"utf8\"),\n );\n } catch {\n return [];\n }\n const warned: string[] = [];\n for (const [key, newHome] of Object.entries(SUPERSEDED)) {\n if (lookup(config, key) !== undefined) {\n warned.push(key);\n warn(\n `[ph run] powerhouse.config.json \"${key}\" is ignored in hosts projects — ` +\n `its home is now ${newHome}.`,\n );\n }\n }\n return warned;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAaA,MAAM,aAAqC;CACzC,eAAe;CACf,gBAAgB;CAChB,sBAAsB;CACtB,iBAAiB;CACjB,mBACE;CACF,4BACE;AACJ;AAEA,SAAS,OAAO,QAAiB,WAA4B;CAC3D,IAAI,SAAkB;CACtB,KAAK,MAAM,QAAQ,UAAU,MAAM,GAAG,GAAG;EACvC,IAAI,WAAW,QAAQ,OAAO,WAAW,UAAU,OAAO,KAAA;EAC1D,SAAU,OAAmC;CAC/C;CACA,OAAO;AACT;;;;AAKA,SAAgB,yBACd,aACA,OAAkC,QAAQ,MAChC;CACV,IAAI;CACJ,IAAI;EACF,SAAS,KAAK,MACZ,GAAG,aAAa,KAAK,KAAK,aAAa,wBAAwB,GAAG,MAAM,CAC1E;CACF,QAAQ;EACN,OAAO,CAAC;CACV;CACA,MAAM,SAAmB,CAAC;CAC1B,KAAK,MAAM,CAAC,KAAK,YAAY,OAAO,QAAQ,UAAU,GACpD,IAAI,OAAO,QAAQ,GAAG,MAAM,KAAA,GAAW;EACrC,OAAO,KAAK,GAAG;EACf,KACE,oCAAoC,IAAI,mDACnB,QAAQ,EAC/B;CACF;CAEF,OAAO;AACT","debug_id":"0ed57c92-e10e-5f6c-a833-8f0a8c8d722c"}
@@ -0,0 +1,4 @@
1
+ import { r as startSwitchboard } from "./switchboard-tQS3fhqa.mjs";
2
+ export { startSwitchboard };
3
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="54e39bab-94e6-5440-9af6-8843b25d4c2b")}catch(e){}}();
4
+ //# debugId=54e39bab-94e6-5440-9af6-8843b25d4c2b
@@ -1,5 +1,5 @@
1
1
 
2
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="9ca57982-bee9-5f08-aa81-5fb5a7ca8324")}catch(e){}}();
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="8ee54547-f686-5213-81f6-e06f7bd4b297")}catch(e){}}();
3
3
  import { Kysely, PostgresDialect } from "kysely";
4
4
  import { Pool } from "pg";
5
5
  import { REACTOR_SCHEMA, getMigrationStatus, runMigrations } from "@powerhousedao/reactor";
@@ -15,7 +15,8 @@ async function runSwitchboardMigrations(options) {
15
15
  return;
16
16
  }
17
17
  console.log(`Database: ${dbPath}`);
18
- const db = new Kysely({ dialect: new PostgresDialect({ pool: new Pool({ connectionString: dbPath }) }) });
18
+ const pool = new Pool({ connectionString: dbPath });
19
+ const db = new Kysely({ dialect: new PostgresDialect({ pool }) });
19
20
  try {
20
21
  if (options.statusOnly) {
21
22
  console.log("\nChecking migration status...");
@@ -49,5 +50,5 @@ async function runSwitchboardMigrations(options) {
49
50
  //#endregion
50
51
  export { runSwitchboardMigrations };
51
52
 
52
- //# sourceMappingURL=switchboard-migrate-NQ7LHWSi.mjs.map
53
- //# debugId=9ca57982-bee9-5f08-aa81-5fb5a7ca8324
53
+ //# sourceMappingURL=switchboard-migrate-7JQZM7-5.mjs.map
54
+ //# debugId=8ee54547-f686-5213-81f6-e06f7bd4b297
@@ -1 +1 @@
1
- {"version":3,"file":"switchboard-migrate-NQ7LHWSi.mjs","sources":["../src/services/switchboard-migrate.ts"],"sourcesContent":["import { Kysely, PostgresDialect } from \"kysely\";\nimport { Pool } from \"pg\";\nimport {\n runMigrations,\n getMigrationStatus,\n REACTOR_SCHEMA,\n} from \"@powerhousedao/reactor\";\n\ninterface MigrationOptions {\n dbPath?: string;\n statusOnly?: boolean;\n}\n\nfunction isPostgresUrl(url: string): boolean {\n return url.startsWith(\"postgresql://\") || url.startsWith(\"postgres://\");\n}\n\nexport async function runSwitchboardMigrations(\n options: MigrationOptions,\n): Promise<void> {\n const dbPath =\n options.dbPath ??\n process.env.PH_REACTOR_DATABASE_URL ??\n process.env.DATABASE_URL;\n\n if (!dbPath || !isPostgresUrl(dbPath)) {\n console.log(\"No PostgreSQL URL configured. Skipping migrations.\");\n console.log(\"(PGlite migrations are handled automatically on startup)\");\n return;\n }\n\n console.log(`Database: ${dbPath}`);\n\n const pool = new Pool({ connectionString: dbPath });\n\n const db = new Kysely<any>({\n dialect: new PostgresDialect({ pool }),\n });\n\n try {\n if (options.statusOnly) {\n console.log(\"\\nChecking migration status...\");\n const migrations = await getMigrationStatus(db, REACTOR_SCHEMA);\n\n console.log(\"\\nMigration Status:\");\n console.log(\"=================\");\n\n for (const migration of migrations) {\n const status = migration.executedAt\n ? `[OK] Executed at ${migration.executedAt.toISOString()}`\n : \"[--] Pending\";\n console.log(`${status} - ${migration.name}`);\n }\n } else {\n console.log(\"\\nRunning migrations...\");\n const result = await runMigrations(db, REACTOR_SCHEMA);\n\n if (!result.success) {\n console.error(\"Migration failed:\", result.error?.message);\n process.exit(1);\n }\n\n if (result.migrationsExecuted.length === 0) {\n console.log(\"No migrations to run - database is up to date\");\n } else {\n console.log(\n `Successfully executed ${result.migrationsExecuted.length} migration(s):`,\n );\n for (const name of result.migrationsExecuted) {\n console.log(` - ${name}`);\n }\n }\n }\n } catch (error) {\n console.error(\n \"Error:\",\n error instanceof Error ? error.message : String(error),\n );\n process.exit(1);\n } finally {\n await db.destroy();\n }\n}\n"],"names":[],"mappings":";;;;;;AAaA,SAAS,cAAc,KAAsB;AAC3C,QAAO,IAAI,WAAW,gBAAgB,IAAI,IAAI,WAAW,cAAc;;AAGzE,eAAsB,yBACpB,SACe;CACf,MAAM,SACJ,QAAQ,UACR,QAAQ,IAAI,2BACZ,QAAQ,IAAI;AAEd,KAAI,CAAC,UAAU,CAAC,cAAc,OAAO,EAAE;AACrC,UAAQ,IAAI,qDAAqD;AACjE,UAAQ,IAAI,2DAA2D;AACvE;;AAGF,SAAQ,IAAI,aAAa,SAAS;CAIlC,MAAM,KAAK,IAAI,OAAY,EACzB,SAAS,IAAI,gBAAgB,EAAE,MAHpB,IAAI,KAAK,EAAE,kBAAkB,QAAQ,CAAC,EAGZ,CAAC,EACvC,CAAC;AAEF,KAAI;AACF,MAAI,QAAQ,YAAY;AACtB,WAAQ,IAAI,iCAAiC;GAC7C,MAAM,aAAa,MAAM,mBAAmB,IAAI,eAAe;AAE/D,WAAQ,IAAI,sBAAsB;AAClC,WAAQ,IAAI,oBAAoB;AAEhC,QAAK,MAAM,aAAa,YAAY;IAClC,MAAM,SAAS,UAAU,aACrB,oBAAoB,UAAU,WAAW,aAAa,KACtD;AACJ,YAAQ,IAAI,GAAG,OAAO,KAAK,UAAU,OAAO;;SAEzC;AACL,WAAQ,IAAI,0BAA0B;GACtC,MAAM,SAAS,MAAM,cAAc,IAAI,eAAe;AAEtD,OAAI,CAAC,OAAO,SAAS;AACnB,YAAQ,MAAM,qBAAqB,OAAO,OAAO,QAAQ;AACzD,YAAQ,KAAK,EAAE;;AAGjB,OAAI,OAAO,mBAAmB,WAAW,EACvC,SAAQ,IAAI,gDAAgD;QACvD;AACL,YAAQ,IACN,yBAAyB,OAAO,mBAAmB,OAAO,gBAC3D;AACD,SAAK,MAAM,QAAQ,OAAO,mBACxB,SAAQ,IAAI,OAAO,OAAO;;;UAIzB,OAAO;AACd,UAAQ,MACN,UACA,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,CACvD;AACD,UAAQ,KAAK,EAAE;WACP;AACR,QAAM,GAAG,SAAS","debug_id":"9ca57982-bee9-5f08-aa81-5fb5a7ca8324"}
1
+ {"version":3,"file":"switchboard-migrate-7JQZM7-5.mjs","sources":["../src/services/switchboard-migrate.ts"],"sourcesContent":["import { Kysely, PostgresDialect } from \"kysely\";\nimport { Pool } from \"pg\";\nimport {\n runMigrations,\n getMigrationStatus,\n REACTOR_SCHEMA,\n} from \"@powerhousedao/reactor\";\n\ninterface MigrationOptions {\n dbPath?: string;\n statusOnly?: boolean;\n}\n\nfunction isPostgresUrl(url: string): boolean {\n return url.startsWith(\"postgresql://\") || url.startsWith(\"postgres://\");\n}\n\nexport async function runSwitchboardMigrations(\n options: MigrationOptions,\n): Promise<void> {\n const dbPath =\n options.dbPath ??\n process.env.PH_REACTOR_DATABASE_URL ??\n process.env.DATABASE_URL;\n\n if (!dbPath || !isPostgresUrl(dbPath)) {\n console.log(\"No PostgreSQL URL configured. Skipping migrations.\");\n console.log(\"(PGlite migrations are handled automatically on startup)\");\n return;\n }\n\n console.log(`Database: ${dbPath}`);\n\n const pool = new Pool({ connectionString: dbPath });\n\n const db = new Kysely<any>({\n dialect: new PostgresDialect({ pool }),\n });\n\n try {\n if (options.statusOnly) {\n console.log(\"\\nChecking migration status...\");\n const migrations = await getMigrationStatus(db, REACTOR_SCHEMA);\n\n console.log(\"\\nMigration Status:\");\n console.log(\"=================\");\n\n for (const migration of migrations) {\n const status = migration.executedAt\n ? `[OK] Executed at ${migration.executedAt.toISOString()}`\n : \"[--] Pending\";\n console.log(`${status} - ${migration.name}`);\n }\n } else {\n console.log(\"\\nRunning migrations...\");\n const result = await runMigrations(db, REACTOR_SCHEMA);\n\n if (!result.success) {\n console.error(\"Migration failed:\", result.error?.message);\n process.exit(1);\n }\n\n if (result.migrationsExecuted.length === 0) {\n console.log(\"No migrations to run - database is up to date\");\n } else {\n console.log(\n `Successfully executed ${result.migrationsExecuted.length} migration(s):`,\n );\n for (const name of result.migrationsExecuted) {\n console.log(` - ${name}`);\n }\n }\n }\n } catch (error) {\n console.error(\n \"Error:\",\n error instanceof Error ? error.message : String(error),\n );\n process.exit(1);\n } finally {\n await db.destroy();\n }\n}\n"],"names":[],"mappings":";;;;;;AAaA,SAAS,cAAc,KAAsB;CAC3C,OAAO,IAAI,WAAW,eAAe,KAAK,IAAI,WAAW,aAAa;AACxE;AAEA,eAAsB,yBACpB,SACe;CACf,MAAM,SACJ,QAAQ,UACR,QAAQ,IAAI,2BACZ,QAAQ,IAAI;CAEd,IAAI,CAAC,UAAU,CAAC,cAAc,MAAM,GAAG;EACrC,QAAQ,IAAI,oDAAoD;EAChE,QAAQ,IAAI,0DAA0D;EACtE;CACF;CAEA,QAAQ,IAAI,aAAa,QAAQ;CAEjC,MAAM,OAAO,IAAI,KAAK,EAAE,kBAAkB,OAAO,CAAC;CAElD,MAAM,KAAK,IAAI,OAAY,EACzB,SAAS,IAAI,gBAAgB,EAAE,KAAK,CAAC,EACvC,CAAC;CAED,IAAI;EACF,IAAI,QAAQ,YAAY;GACtB,QAAQ,IAAI,gCAAgC;GAC5C,MAAM,aAAa,MAAM,mBAAmB,IAAI,cAAc;GAE9D,QAAQ,IAAI,qBAAqB;GACjC,QAAQ,IAAI,mBAAmB;GAE/B,KAAK,MAAM,aAAa,YAAY;IAClC,MAAM,SAAS,UAAU,aACrB,oBAAoB,UAAU,WAAW,YAAY,MACrD;IACJ,QAAQ,IAAI,GAAG,OAAO,KAAK,UAAU,MAAM;GAC7C;EACF,OAAO;GACL,QAAQ,IAAI,yBAAyB;GACrC,MAAM,SAAS,MAAM,cAAc,IAAI,cAAc;GAErD,IAAI,CAAC,OAAO,SAAS;IACnB,QAAQ,MAAM,qBAAqB,OAAO,OAAO,OAAO;IACxD,QAAQ,KAAK,CAAC;GAChB;GAEA,IAAI,OAAO,mBAAmB,WAAW,GACvC,QAAQ,IAAI,+CAA+C;QACtD;IACL,QAAQ,IACN,yBAAyB,OAAO,mBAAmB,OAAO,eAC5D;IACA,KAAK,MAAM,QAAQ,OAAO,oBACxB,QAAQ,IAAI,OAAO,MAAM;GAE7B;EACF;CACF,SAAS,OAAO;EACd,QAAQ,MACN,UACA,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CACvD;EACA,QAAQ,KAAK,CAAC;CAChB,UAAU;EACR,MAAM,GAAG,QAAQ;CACnB;AACF","debug_id":"8ee54547-f686-5213-81f6-e06f7bd4b297"}
@@ -1,7 +1,7 @@
1
1
 
2
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="6dc443d3-91f6-5215-973e-7898511565eb")}catch(e){}}();
3
- import { cyan, green, red, yellow } from "colorette";
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="7ed66b10-4157-58df-9f3d-8a23c6950440")}catch(e){}}();
4
3
  import { promises } from "node:fs";
4
+ import { cyan, green, red, yellow } from "colorette";
5
5
  //#region src/services/switchboard-reset.ts
6
6
  const CONFIRMATION_TOKEN = "reset";
7
7
  function isPostgresUrl(url) {
@@ -83,5 +83,5 @@ async function resetSwitchboardDatabase(options) {
83
83
  //#endregion
84
84
  export { resetSwitchboardDatabase };
85
85
 
86
- //# sourceMappingURL=switchboard-reset-BcQXlcVf.mjs.map
87
- //# debugId=6dc443d3-91f6-5215-973e-7898511565eb
86
+ //# sourceMappingURL=switchboard-reset-CX_Lzw3O.mjs.map
87
+ //# debugId=7ed66b10-4157-58df-9f3d-8a23c6950440
@@ -1 +1 @@
1
- {"version":3,"file":"switchboard-reset-BcQXlcVf.mjs","sources":["../src/services/switchboard-reset.ts"],"sourcesContent":["import { yellow, red, green, cyan } from \"colorette\";\nimport { promises as fs } from \"node:fs\";\n\nexport interface ResetSwitchboardOptions {\n dbPath?: string;\n yes?: boolean;\n}\n\nexport interface ResolvedResetPaths {\n reactorDir: string | null;\n readModelDir: string | null;\n postgresUrl: string | null;\n}\n\nconst CONFIRMATION_TOKEN = \"reset\";\n\nexport function isPostgresUrl(url: string): boolean {\n return url.startsWith(\"postgresql://\") || url.startsWith(\"postgres://\");\n}\n\nfunction isInteractive(): boolean {\n return Boolean(process.stdin.isTTY) && !process.env.CI;\n}\n\n/**\n * Resolves the on-disk PGlite directories that `--reset` would delete.\n * Mirrors the resolution in apps/switchboard/src/server.mts so we touch the\n * same paths the running switchboard uses. When a Postgres URL is configured\n * the corresponding directory is null and `postgresUrl` is populated so the\n * caller can refuse.\n */\nexport function resolveResetPaths(\n options: ResetSwitchboardOptions,\n env: NodeJS.ProcessEnv = process.env,\n): ResolvedResetPaths {\n const readModelDbPath =\n options.dbPath ?? env.DATABASE_URL ?? env.PH_SWITCHBOARD_DATABASE_URL;\n const readModelPath = readModelDbPath || \".ph/read-storage\";\n const reactorDbUrl =\n options.dbPath ??\n env.PH_REACTOR_DATABASE_URL ??\n env.PH_SWITCHBOARD_DATABASE_URL;\n const reactorPath = reactorDbUrl || \"./.ph/reactor-storage\";\n\n const reactorIsPostgres = !!reactorDbUrl && isPostgresUrl(reactorDbUrl);\n const readModelIsPostgres =\n !!readModelDbPath && isPostgresUrl(readModelDbPath);\n\n let postgresUrl: string | null = null;\n if (reactorIsPostgres) postgresUrl = reactorDbUrl as string;\n else if (readModelIsPostgres) postgresUrl = readModelDbPath as string;\n\n return {\n reactorDir: reactorIsPostgres ? null : reactorPath,\n readModelDir: readModelIsPostgres ? null : readModelPath,\n postgresUrl,\n };\n}\n\nasync function promptForConfirmation(): Promise<boolean> {\n const enquirer = await import(\"enquirer\");\n try {\n const answer = await enquirer.default.prompt<{ confirmation: string }>({\n type: \"input\",\n name: \"confirmation\",\n message: `Type \"${CONFIRMATION_TOKEN}\" to confirm wiping the local switchboard databases:`,\n });\n return answer.confirmation.trim() === CONFIRMATION_TOKEN;\n } catch {\n return false;\n }\n}\n\nexport async function resetSwitchboardDatabase(\n options: ResetSwitchboardOptions,\n): Promise<void> {\n const paths = resolveResetPaths(options);\n\n if (paths.postgresUrl) {\n console.error(\n red(\n `Refusing to reset: a PostgreSQL URL is configured (${paths.postgresUrl}).`,\n ),\n );\n console.error(\n yellow(\n \"`ph switchboard --reset` only wipes the local PGlite stores. \" +\n \"To reset a Postgres-backed switchboard, drop/recreate the database manually.\",\n ),\n );\n process.exit(1);\n }\n\n const targets = [paths.reactorDir, paths.readModelDir].filter(\n (d): d is string => d !== null,\n );\n\n if (targets.length === 0) {\n console.error(red(\"No local PGlite directories resolved; nothing to do.\"));\n process.exit(1);\n }\n\n console.log(yellow(\"The following directories will be permanently deleted:\"));\n for (const dir of targets) {\n console.log(` - ${dir}`);\n }\n console.log(\n yellow(\n \"This will wipe all local switchboard state. Migrations will re-run on next `ph switchboard`.\",\n ),\n );\n\n let confirmed = false;\n if (options.yes) {\n confirmed = true;\n } else if (isInteractive()) {\n confirmed = await promptForConfirmation();\n } else {\n console.error(\n red(\n \"Refusing to reset in a non-interactive context without --yes. Re-run with --yes to confirm.\",\n ),\n );\n process.exit(1);\n }\n\n if (!confirmed) {\n console.error(red(\"Aborted: confirmation not provided.\"));\n process.exit(1);\n }\n\n for (const dir of targets) {\n await fs.rm(dir, { recursive: true, force: true });\n console.log(cyan(`Removed ${dir}`));\n }\n\n console.log(\n green(\n \"Switchboard local storage reset. Run `ph switchboard` to re-initialize.\",\n ),\n );\n}\n"],"names":["fs"],"mappings":";;;;;AAcA,MAAM,qBAAqB;AAE3B,SAAgB,cAAc,KAAsB;AAClD,QAAO,IAAI,WAAW,gBAAgB,IAAI,IAAI,WAAW,cAAc;;AAGzE,SAAS,gBAAyB;AAChC,QAAO,QAAQ,QAAQ,MAAM,MAAM,IAAI,CAAC,QAAQ,IAAI;;;;;;;;;AAUtD,SAAgB,kBACd,SACA,MAAyB,QAAQ,KACb;CACpB,MAAM,kBACJ,QAAQ,UAAU,IAAI,gBAAgB,IAAI;CAC5C,MAAM,gBAAgB,mBAAmB;CACzC,MAAM,eACJ,QAAQ,UACR,IAAI,2BACJ,IAAI;CACN,MAAM,cAAc,gBAAgB;CAEpC,MAAM,oBAAoB,CAAC,CAAC,gBAAgB,cAAc,aAAa;CACvE,MAAM,sBACJ,CAAC,CAAC,mBAAmB,cAAc,gBAAgB;CAErD,IAAI,cAA6B;AACjC,KAAI,kBAAmB,eAAc;UAC5B,oBAAqB,eAAc;AAE5C,QAAO;EACL,YAAY,oBAAoB,OAAO;EACvC,cAAc,sBAAsB,OAAO;EAC3C;EACD;;AAGH,eAAe,wBAA0C;CACvD,MAAM,WAAW,MAAM,OAAO;AAC9B,KAAI;AAMF,UALe,MAAM,SAAS,QAAQ,OAAiC;GACrE,MAAM;GACN,MAAM;GACN,SAAS,SAAS,mBAAmB;GACtC,CAAC,EACY,aAAa,MAAM,KAAK;SAChC;AACN,SAAO;;;AAIX,eAAsB,yBACpB,SACe;CACf,MAAM,QAAQ,kBAAkB,QAAQ;AAExC,KAAI,MAAM,aAAa;AACrB,UAAQ,MACN,IACE,sDAAsD,MAAM,YAAY,IACzE,CACF;AACD,UAAQ,MACN,OACE,4IAED,CACF;AACD,UAAQ,KAAK,EAAE;;CAGjB,MAAM,UAAU,CAAC,MAAM,YAAY,MAAM,aAAa,CAAC,QACpD,MAAmB,MAAM,KAC3B;AAED,KAAI,QAAQ,WAAW,GAAG;AACxB,UAAQ,MAAM,IAAI,uDAAuD,CAAC;AAC1E,UAAQ,KAAK,EAAE;;AAGjB,SAAQ,IAAI,OAAO,yDAAyD,CAAC;AAC7E,MAAK,MAAM,OAAO,QAChB,SAAQ,IAAI,OAAO,MAAM;AAE3B,SAAQ,IACN,OACE,+FACD,CACF;CAED,IAAI,YAAY;AAChB,KAAI,QAAQ,IACV,aAAY;UACH,eAAe,CACxB,aAAY,MAAM,uBAAuB;MACpC;AACL,UAAQ,MACN,IACE,8FACD,CACF;AACD,UAAQ,KAAK,EAAE;;AAGjB,KAAI,CAAC,WAAW;AACd,UAAQ,MAAM,IAAI,sCAAsC,CAAC;AACzD,UAAQ,KAAK,EAAE;;AAGjB,MAAK,MAAM,OAAO,SAAS;AACzB,QAAMA,SAAG,GAAG,KAAK;GAAE,WAAW;GAAM,OAAO;GAAM,CAAC;AAClD,UAAQ,IAAI,KAAK,WAAW,MAAM,CAAC;;AAGrC,SAAQ,IACN,MACE,0EACD,CACF","debug_id":"6dc443d3-91f6-5215-973e-7898511565eb"}
1
+ {"version":3,"file":"switchboard-reset-CX_Lzw3O.mjs","sources":["../src/services/switchboard-reset.ts"],"sourcesContent":["import { yellow, red, green, cyan } from \"colorette\";\nimport { promises as fs } from \"node:fs\";\n\nexport interface ResetSwitchboardOptions {\n dbPath?: string;\n yes?: boolean;\n}\n\nexport interface ResolvedResetPaths {\n reactorDir: string | null;\n readModelDir: string | null;\n postgresUrl: string | null;\n}\n\nconst CONFIRMATION_TOKEN = \"reset\";\n\nexport function isPostgresUrl(url: string): boolean {\n return url.startsWith(\"postgresql://\") || url.startsWith(\"postgres://\");\n}\n\nfunction isInteractive(): boolean {\n return Boolean(process.stdin.isTTY) && !process.env.CI;\n}\n\n/**\n * Resolves the on-disk PGlite directories that `--reset` would delete.\n * Mirrors the resolution in apps/switchboard/src/server.mts so we touch the\n * same paths the running switchboard uses. When a Postgres URL is configured\n * the corresponding directory is null and `postgresUrl` is populated so the\n * caller can refuse.\n */\nexport function resolveResetPaths(\n options: ResetSwitchboardOptions,\n env: NodeJS.ProcessEnv = process.env,\n): ResolvedResetPaths {\n const readModelDbPath =\n options.dbPath ?? env.DATABASE_URL ?? env.PH_SWITCHBOARD_DATABASE_URL;\n const readModelPath = readModelDbPath || \".ph/read-storage\";\n const reactorDbUrl =\n options.dbPath ??\n env.PH_REACTOR_DATABASE_URL ??\n env.PH_SWITCHBOARD_DATABASE_URL;\n const reactorPath = reactorDbUrl || \"./.ph/reactor-storage\";\n\n const reactorIsPostgres = !!reactorDbUrl && isPostgresUrl(reactorDbUrl);\n const readModelIsPostgres =\n !!readModelDbPath && isPostgresUrl(readModelDbPath);\n\n let postgresUrl: string | null = null;\n if (reactorIsPostgres) postgresUrl = reactorDbUrl as string;\n else if (readModelIsPostgres) postgresUrl = readModelDbPath as string;\n\n return {\n reactorDir: reactorIsPostgres ? null : reactorPath,\n readModelDir: readModelIsPostgres ? null : readModelPath,\n postgresUrl,\n };\n}\n\nasync function promptForConfirmation(): Promise<boolean> {\n const enquirer = await import(\"enquirer\");\n try {\n const answer = await enquirer.default.prompt<{ confirmation: string }>({\n type: \"input\",\n name: \"confirmation\",\n message: `Type \"${CONFIRMATION_TOKEN}\" to confirm wiping the local switchboard databases:`,\n });\n return answer.confirmation.trim() === CONFIRMATION_TOKEN;\n } catch {\n return false;\n }\n}\n\nexport async function resetSwitchboardDatabase(\n options: ResetSwitchboardOptions,\n): Promise<void> {\n const paths = resolveResetPaths(options);\n\n if (paths.postgresUrl) {\n console.error(\n red(\n `Refusing to reset: a PostgreSQL URL is configured (${paths.postgresUrl}).`,\n ),\n );\n console.error(\n yellow(\n \"`ph switchboard --reset` only wipes the local PGlite stores. \" +\n \"To reset a Postgres-backed switchboard, drop/recreate the database manually.\",\n ),\n );\n process.exit(1);\n }\n\n const targets = [paths.reactorDir, paths.readModelDir].filter(\n (d): d is string => d !== null,\n );\n\n if (targets.length === 0) {\n console.error(red(\"No local PGlite directories resolved; nothing to do.\"));\n process.exit(1);\n }\n\n console.log(yellow(\"The following directories will be permanently deleted:\"));\n for (const dir of targets) {\n console.log(` - ${dir}`);\n }\n console.log(\n yellow(\n \"This will wipe all local switchboard state. Migrations will re-run on next `ph switchboard`.\",\n ),\n );\n\n let confirmed = false;\n if (options.yes) {\n confirmed = true;\n } else if (isInteractive()) {\n confirmed = await promptForConfirmation();\n } else {\n console.error(\n red(\n \"Refusing to reset in a non-interactive context without --yes. Re-run with --yes to confirm.\",\n ),\n );\n process.exit(1);\n }\n\n if (!confirmed) {\n console.error(red(\"Aborted: confirmation not provided.\"));\n process.exit(1);\n }\n\n for (const dir of targets) {\n await fs.rm(dir, { recursive: true, force: true });\n console.log(cyan(`Removed ${dir}`));\n }\n\n console.log(\n green(\n \"Switchboard local storage reset. Run `ph switchboard` to re-initialize.\",\n ),\n );\n}\n"],"names":["fs"],"mappings":";;;;;AAcA,MAAM,qBAAqB;AAE3B,SAAgB,cAAc,KAAsB;CAClD,OAAO,IAAI,WAAW,eAAe,KAAK,IAAI,WAAW,aAAa;AACxE;AAEA,SAAS,gBAAyB;CAChC,OAAO,QAAQ,QAAQ,MAAM,KAAK,KAAK,CAAC,QAAQ,IAAI;AACtD;;;;;;;;AASA,SAAgB,kBACd,SACA,MAAyB,QAAQ,KACb;CACpB,MAAM,kBACJ,QAAQ,UAAU,IAAI,gBAAgB,IAAI;CAC5C,MAAM,gBAAgB,mBAAmB;CACzC,MAAM,eACJ,QAAQ,UACR,I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W;EACd,QAAQ,MAAM,IAAI,qCAAqC,CAAC;EACxD,QAAQ,KAAK,CAAC;CAChB;CAEA,KAAK,MAAM,OAAO,SAAS;EACzB,MAAMA,SAAG,GAAG,KAAK;GAAE,WAAW;GAAM,OAAO;EAAK,CAAC;EACjD,QAAQ,IAAI,KAAK,WAAW,KAAK,CAAC;CACpC;CAEA,QAAQ,IACN,MACE,yEACF,CACF;AACF","debug_id":"7ed66b10-4157-58df-9f3d-8a23c6950440"}
@@ -0,0 +1,132 @@
1
+
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="f2520f1a-0b2d-5086-beca-ab486259ddfe")}catch(e){}}();
3
+ import path from "node:path";
4
+ import { DEFAULT_DRIVE_ICON } from "@powerhousedao/shared/clis";
5
+ import { startSwitchboard } from "@powerhousedao/switchboard/server";
6
+ //#region src/utils/drive-icons.ts
7
+ /**
8
+ * Icon for the drives ph-cli creates, inlined as a data URI.
9
+ *
10
+ * This used to be an IPFS URL on a private gateway, which now answers 403 -
11
+ * and a drive stores its icon as a plain URL in document state, so the moment
12
+ * that URL rots every client renders a broken image, for as long as the drive
13
+ * exists. A public gateway would only move the problem: IPFS gateways are
14
+ * frequently overloaded, and a drive icon must not depend on the network at
15
+ * all.
16
+ *
17
+ * A data URI keeps the asset inside this package and inside the drive: no
18
+ * fetch, no gateway, no deploy-base or cross-origin question, and nothing to
19
+ * 404. A few hundred bytes - the size of the string below is the entire cost,
20
+ * paid once in the drive's state.
21
+ *
22
+ * Kept URL-encoded rather than base64 so the markup stays readable and
23
+ * reviewable (`#` must be `%23`; `<`, `>`, `"` and the CSS braces are legal
24
+ * enough in a data URI but are encoded so the value is also safe to paste
25
+ * into markup).
26
+ */
27
+ /** Encodes an SVG for use in a `data:` URI, smaller than base64 and readable. */
28
+ function svgDataUri(svg) {
29
+ return `data:image/svg+xml,${svg.replace(/\s+/g, " ").trim().replace(/%/g, "%25").replace(/#/g, "%23").replace(/</g, "%3C").replace(/>/g, "%3E").replace(/"/g, "%22").replace(/\{/g, "%7B").replace(/\}/g, "%7D")}`;
30
+ }
31
+ const PETALS = [
32
+ "M0 4.6C0 2.1 2.1 0 4.6 0h21.2c2.5 0 4.6 2.1 4.6 4.6v2.8c0 12.7-10.3 23-23 23H4.6C2.1 30.4 0 28.4 0 25.8V4.6Z",
33
+ "M33.6 56.6c0-12.7 10.3-23 23-23h2.8c2.5 0 4.6 2.1 4.6 4.6v21.2c0 2.5-2.1 4.6-4.6 4.6H38.2c-2.5 0-4.6-2.1-4.6-4.6v-2.8Z",
34
+ "M0 38.2c0-2.5 2.1-4.6 4.6-4.6h2.8c12.7 0 23 10.3 23 23v2.8c0 2.5-2.1 4.6-4.6 4.6H4.6C2.1 64 0 61.9 0 59.4V38.2Z",
35
+ "M33.6 4.6C33.6 2.1 35.6 0 38.2 0h21.2C61.9 0 64 2.1 64 4.6v21.2c0 2.5-2.1 4.6-4.6 4.6h-2.8c-12.7 0-23-10.3-23-23V4.6Z"
36
+ ];
37
+ /** Icon for the drives ph-cli creates. */
38
+ const POWERHOUSE_DRIVE_ICON = svgDataUri(`
39
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="32" height="32">
40
+ <style>
41
+ path { fill: #404345 }
42
+ @media (prefers-color-scheme: dark) { path { fill: #F3F5F7 } }
43
+ </style>
44
+ <path d="${PETALS[0]}"/>
45
+ <path d="${PETALS[1]}"/>
46
+ <path d="${PETALS[2]}"/>
47
+ <path d="${PETALS[3]}"/>
48
+ </svg>`);
49
+ //#endregion
50
+ //#region src/services/switchboard.ts
51
+ const EGRESS_ALLOW_ENV = "PH_WORKFLOWS_EGRESS_ALLOW_ADDRESSES";
52
+ const LOCALHOST_ADDRESSES = ["127.0.0.1/32", "::1/128"];
53
+ function allowLocalhostEgress(env = process.env) {
54
+ const current = (env[EGRESS_ALLOW_ENV] ?? "").split(",").map((entry) => entry.trim()).filter((entry) => entry !== "");
55
+ const missing = LOCALHOST_ADDRESSES.filter((address) => !current.includes(address));
56
+ if (missing.length > 0) env[EGRESS_ALLOW_ENV] = [...current, ...missing].join(",");
57
+ }
58
+ const defaultSwitchboardOptions = {
59
+ port: 4001,
60
+ dbPath: path.join(process.cwd(), ".ph/read-model.db"),
61
+ drive: {
62
+ id: "powerhouse",
63
+ slug: "powerhouse",
64
+ global: {
65
+ name: "Powerhouse",
66
+ icon: DEFAULT_DRIVE_ICON
67
+ },
68
+ local: {
69
+ availableOffline: true,
70
+ listeners: [],
71
+ sharingType: "public",
72
+ triggers: []
73
+ }
74
+ },
75
+ mcp: true
76
+ };
77
+ function getDefaultVetraSwitchboardOptions(vetraDriveId) {
78
+ return {
79
+ port: 4001,
80
+ dbPath: path.join(process.cwd(), ".ph/read-model.db"),
81
+ drive: {
82
+ id: vetraDriveId,
83
+ slug: vetraDriveId,
84
+ global: {
85
+ name: "Vetra",
86
+ icon: POWERHOUSE_DRIVE_ICON
87
+ },
88
+ preferredEditor: "vetra-drive-app",
89
+ local: {
90
+ availableOffline: true,
91
+ listeners: [],
92
+ sharingType: "public",
93
+ triggers: []
94
+ }
95
+ }
96
+ };
97
+ }
98
+ async function startSwitchboard$1(options, logger) {
99
+ const { packages: packagesString, remoteDrives, useVetraDrive, vetraDriveId, useIdentity, keypairPath, requireIdentity, ...serverOptions } = options;
100
+ if (useVetraDrive || serverOptions.dev) allowLocalhostEgress();
101
+ const defaultOptions = useVetraDrive ? getDefaultVetraSwitchboardOptions(vetraDriveId) : defaultSwitchboardOptions;
102
+ const identity = useIdentity || keypairPath || requireIdentity ? {
103
+ keypairPath,
104
+ requireExisting: requireIdentity
105
+ } : void 0;
106
+ const packages = packagesString?.split(",");
107
+ const finalOptions = remoteDrives.length > 0 ? {
108
+ ...defaultOptions,
109
+ drive: void 0,
110
+ ...serverOptions,
111
+ remoteDrives,
112
+ identity,
113
+ packages,
114
+ logger
115
+ } : {
116
+ ...defaultOptions,
117
+ ...serverOptions,
118
+ remoteDrives,
119
+ identity,
120
+ packages,
121
+ logger
122
+ };
123
+ return await startSwitchboard({
124
+ ...finalOptions,
125
+ fatalErrorShutdown: true
126
+ });
127
+ }
128
+ //#endregion
129
+ export { POWERHOUSE_DRIVE_ICON as i, defaultSwitchboardOptions as n, startSwitchboard$1 as r, allowLocalhostEgress as t };
130
+
131
+ //# sourceMappingURL=switchboard-tQS3fhqa.mjs.map
132
+ //# debugId=f2520f1a-0b2d-5086-beca-ab486259ddfe
@@ -0,0 +1 @@
1
+ {"version":3,"file":"switchboard-tQS3fhqa.mjs","sources":["../src/utils/drive-icons.ts","../src/services/switchboard.ts"],"sourcesContent":["/**\n * Icon for the drives ph-cli creates, inlined as a data URI.\n *\n * This used to be an IPFS URL on a private gateway, which now answers 403 -\n * and a drive stores its icon as a plain URL in document state, so the moment\n * that URL rots every client renders a broken image, for as long as the drive\n * exists. A public gateway would only move the problem: IPFS gateways are\n * frequently overloaded, and a drive icon must not depend on the network at\n * all.\n *\n * A data URI keeps the asset inside this package and inside the drive: no\n * fetch, no gateway, no deploy-base or cross-origin question, and nothing to\n * 404. A few hundred bytes - the size of the string below is the entire cost,\n * paid once in the drive's state.\n *\n * Kept URL-encoded rather than base64 so the markup stays readable and\n * reviewable (`#` must be `%23`; `<`, `>`, `\"` and the CSS braces are legal\n * enough in a data URI but are encoded so the value is also safe to paste\n * into markup).\n */\n\n/** Encodes an SVG for use in a `data:` URI, smaller than base64 and readable. */\nfunction svgDataUri(svg: string): string {\n const compact = svg.replace(/\\s+/g, \" \").trim();\n return `data:image/svg+xml,${compact\n .replace(/%/g, \"%25\")\n .replace(/#/g, \"%23\")\n .replace(/</g, \"%3C\")\n .replace(/>/g, \"%3E\")\n .replace(/\"/g, \"%22\")\n .replace(/\\{/g, \"%7B\")\n .replace(/\\}/g, \"%7D\")}`;\n}\n\n// The Powerhouse mark: four petals on a 64 grid, each a square with one\n// quarter-circle bite taken out of its inner corner.\nconst PETALS = [\n \"M0 4.6C0 2.1 2.1 0 4.6 0h21.2c2.5 0 4.6 2.1 4.6 4.6v2.8c0 12.7-10.3 23-23 23H4.6C2.1 30.4 0 28.4 0 25.8V4.6Z\",\n \"M33.6 56.6c0-12.7 10.3-23 23-23h2.8c2.5 0 4.6 2.1 4.6 4.6v21.2c0 2.5-2.1 4.6-4.6 4.6H38.2c-2.5 0-4.6-2.1-4.6-4.6v-2.8Z\",\n \"M0 38.2c0-2.5 2.1-4.6 4.6-4.6h2.8c12.7 0 23 10.3 23 23v2.8c0 2.5-2.1 4.6-4.6 4.6H4.6C2.1 64 0 61.9 0 59.4V38.2Z\",\n \"M33.6 4.6C33.6 2.1 35.6 0 38.2 0h21.2C61.9 0 64 2.1 64 4.6v21.2c0 2.5-2.1 4.6-4.6 4.6h-2.8c-12.7 0-23-10.3-23-23V4.6Z\",\n];\n\n/** The mark in the light theme's grey. */\nconst LIGHT_FILL = \"#404345\";\n\n/** The mark in the dark theme's grey. */\nconst DARK_FILL = \"#F3F5F7\";\n\n// Drawn in one grey that follows the theme, so the icon sits in the sidebar\n// beside the single-tone `currentcolor` glyphs of the other drives instead of\n// competing with them.\n//\n// A data URI rendered through an `<img>` is its own document and cannot see\n// the host page's `.dark` class, so the theme is read from the embedded\n// document's own color scheme. That is the OS preference by default; the\n// renderer propagates an explicit in-app theme choice by setting\n// `color-scheme` on the `<img>`, which overrides it where the browser\n// supports the propagation.\nconst MARK_SVG = `\n<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 64 64\" width=\"32\" height=\"32\">\n <style>\n path { fill: ${LIGHT_FILL} }\n @media (prefers-color-scheme: dark) { path { fill: ${DARK_FILL} } }\n </style>\n <path d=\"${PETALS[0]}\"/>\n <path d=\"${PETALS[1]}\"/>\n <path d=\"${PETALS[2]}\"/>\n <path d=\"${PETALS[3]}\"/>\n</svg>`;\n\n/** Icon for the drives ph-cli creates. */\nexport const POWERHOUSE_DRIVE_ICON = svgDataUri(MARK_SVG);\n","import type {\n IdentityOptions,\n StartServerOptions,\n} from \"@powerhousedao/switchboard/server\";\nimport { DEFAULT_DRIVE_ICON } from \"@powerhousedao/shared/clis\";\nimport { startSwitchboard as startSwitchboardServer } from \"@powerhousedao/switchboard/server\";\nimport type { ILogger } from \"document-model\";\nimport path from \"node:path\";\nimport type { SwitchboardArgs } from \"../types.js\";\nimport { POWERHOUSE_DRIVE_ICON } from \"../utils/drive-icons.js\";\n\nconst EGRESS_ALLOW_ENV = \"PH_WORKFLOWS_EGRESS_ALLOW_ADDRESSES\";\nconst LOCALHOST_ADDRESSES = [\"127.0.0.1/32\", \"::1/128\"];\n\n// Lets pieces reach services on this machine, keeping any addresses already set\nexport function allowLocalhostEgress(env: NodeJS.ProcessEnv = process.env) {\n const current = (env[EGRESS_ALLOW_ENV] ?? \"\")\n .split(\",\")\n .map((entry) => entry.trim())\n .filter((entry) => entry !== \"\");\n const missing = LOCALHOST_ADDRESSES.filter(\n (address) => !current.includes(address),\n );\n if (missing.length > 0)\n env[EGRESS_ALLOW_ENV] = [...current, ...missing].join(\",\");\n}\n\nexport const defaultSwitchboardOptions = {\n port: 4001,\n dbPath: path.join(process.cwd(), \".ph/read-model.db\"),\n drive: {\n id: \"powerhouse\",\n slug: \"powerhouse\",\n global: {\n name: \"Powerhouse\",\n icon: DEFAULT_DRIVE_ICON,\n },\n local: {\n availableOffline: true,\n listeners: [],\n sharingType: \"public\",\n triggers: [],\n },\n },\n mcp: true,\n} satisfies StartServerOptions;\n\nfunction getDefaultVetraSwitchboardOptions(\n vetraDriveId: string,\n): Partial<StartServerOptions> {\n return {\n port: 4001,\n dbPath: path.join(process.cwd(), \".ph/read-model.db\"),\n drive: {\n id: vetraDriveId,\n slug: vetraDriveId,\n global: {\n name: \"Vetra\",\n icon: POWERHOUSE_DRIVE_ICON,\n },\n preferredEditor: \"vetra-drive-app\",\n local: {\n availableOffline: true,\n listeners: [],\n sharingType: \"public\",\n triggers: [],\n },\n },\n };\n}\n\nexport async function startSwitchboard(\n options: SwitchboardArgs & {\n strictPort?: boolean;\n processorConfig?: Map<string, unknown>;\n },\n logger?: ILogger,\n) {\n const {\n packages: packagesString,\n remoteDrives,\n useVetraDrive,\n vetraDriveId,\n useIdentity,\n keypairPath,\n requireIdentity,\n ...serverOptions\n } = options;\n\n // Vetra and dev mode run against local services\n if (useVetraDrive || serverOptions.dev) allowLocalhostEgress();\n\n // Choose the appropriate default configuration\n const defaultOptions = useVetraDrive\n ? getDefaultVetraSwitchboardOptions(vetraDriveId)\n : defaultSwitchboardOptions;\n\n // Build identity options if enabled\n const identity: IdentityOptions | undefined =\n useIdentity || keypairPath || requireIdentity\n ? {\n keypairPath,\n requireExisting: requireIdentity,\n }\n : undefined;\n\n const packages = packagesString?.split(\",\");\n\n // Only include the default drive if no remote drives are provided\n const finalOptions =\n remoteDrives.length > 0\n ? {\n ...defaultOptions,\n drive: undefined, // Don't create default drive when syncing with remote\n ...serverOptions,\n remoteDrives,\n identity,\n packages,\n logger,\n }\n : {\n ...defaultOptions,\n ...serverOptions,\n remoteDrives,\n identity,\n packages,\n logger,\n };\n\n const reactor = await startSwitchboardServer({\n ...finalOptions,\n fatalErrorShutdown: true,\n });\n\n return reactor;\n}\n"],"names":["startSwitchboard","startSwitchboardServer"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAS,WAAW,KAAqB;CAEvC,OAAO,sBADS,IAAI,QAAQ,QAAQ,GAAG,CAAC,CAAC,KACN,CAAC,CACjC,QAAQ,MAAM,KAAK,CAAC,CACpB,QAAQ,MAAM,KAAK,CAAC,CACpB,QAAQ,MAAM,KAAK,CAAC,CACpB,QAAQ,MAAM,KAAK,CAAC,CACpB,QAAQ,MAAM,KAAK,CAAC,CACpB,QAAQ,OAAO,KAAK,CAAC,CACrB,QAAQ,OAAO,KAAK;AACzB;AAIA,MAAM,SAAS;CACb;CACA;CACA;CACA;AACF;;AA+BA,MA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AAkC,YAAY,IAC9C;CAGJ,MAAM,WACJ,eAAe,eAAe,kBAC1B;EACE;EACA,iBAAiB;CACnB,IACA,KAAA;CAEN,MAAM,WAAW,gBAAgB,MAAM,GAAG;CAG1C,MAAM,eACJ,aAAa,SAAS,IAClB;EACE,GAAG;EACH,OAAO,KAAA;EACP,GAAG;EACH;EACA;EACA;EACA;CACF,IACA;EACE,GAAG;EACH,GAAG;EACH;EACA;EACA;EACA;CACF;CAON,OAAO,MALeC,iBAAuB;EAC3C,GAAG;EACH,oBAAoB;CACtB,CAAC;AAGH","debug_id":"f2520f1a-0b2d-5086-beca-ab486259ddfe"}
@@ -1,4 +1,4 @@
1
- import { d as updateConfigFile, p as updateStylesFile, u as removeStylesImports } from "./utils-C4isxXSO.mjs";
1
+ import { d as updateConfigFile, p as updateStylesFile, u as removeStylesImports } from "./utils-CvmDmCVd.mjs";
2
2
  export { removeStylesImports, updateConfigFile, updateStylesFile };
3
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="33804f1d-c6ad-5650-aedb-dd51a31d17aa")}catch(e){}}();
4
- //# debugId=33804f1d-c6ad-5650-aedb-dd51a31d17aa
3
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="8a927382-3953-53ce-9038-f76fc626e4b5")}catch(e){}}();
4
+ //# debugId=8a927382-3953-53ce-9038-f76fc626e4b5
@@ -1,5 +1,5 @@
1
1
 
2
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="73159d3c-22a7-5dc6-8bd4-7b15f3b94c79")}catch(e){}}();
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="fa6f49e1-f268-5ae2-8e22-cc7adc8fbfba")}catch(e){}}();
3
3
  import fs from "node:fs";
4
4
  import path, { dirname } from "node:path";
5
5
  import crypto from "node:crypto";
@@ -161,5 +161,5 @@ function removeStylesImports(dependencies, projectPath) {
161
161
  //#endregion
162
162
  export { generateProjectDriveId as a, isPowerhouseProject as c, updateConfigFile as d, updatePackagesArray as f, findNodeProjectRoot as i, packageManagers as l, POWERHOUSE_GLOBAL_DIR as n, getPackageManagerFromLockfile as o, updateStylesFile as p, defaultPathValidation as r, getProjectInfo as s, POWERHOUSE_CONFIG_FILE as t, removeStylesImports as u };
163
163
 
164
- //# sourceMappingURL=utils-C4isxXSO.mjs.map
165
- //# debugId=73159d3c-22a7-5dc6-8bd4-7b15f3b94c79
164
+ //# sourceMappingURL=utils-CvmDmCVd.mjs.map
165
+ //# debugId=fa6f49e1-f268-5ae2-8e22-cc7adc8fbfba
@@ -1 +1 @@
1
- {"version":3,"file":"utils-C4isxXSO.mjs","sources":["../src/utils.ts"],"sourcesContent":["import type { PowerhouseConfig } from \"@powerhousedao/config\";\nimport crypto from \"node:crypto\";\nimport fs from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport path, { dirname } from \"node:path\";\nexport const POWERHOUSE_CONFIG_FILE = \"powerhouse.config.json\";\nexport const POWERHOUSE_GLOBAL_DIR = path.join(homedir(), \".ph\");\nexport const SUPPORTED_PACKAGE_MANAGERS = [\"npm\", \"yarn\", \"pnpm\", \"bun\"];\n\nexport const packageManagers = {\n bun: {\n globalPathRegexp: /[\\\\/].bun[\\\\/]/,\n installCommand: \"bun add {{dependency}}\",\n uninstallCommand: \"bun remove {{dependency}}\",\n workspaceOption: \"\",\n lockfile: \"bun.lock\",\n updateCommand: \"bun update {{dependency}}\",\n buildAffected: \"bun run build:affected\",\n },\n pnpm: {\n globalPathRegexp: /[\\\\/]pnpm[\\\\/]/,\n installCommand: \"pnpm add {{dependency}}\",\n uninstallCommand: \"pnpm remove {{dependency}}\",\n workspaceOption: \"--workspace-root\",\n lockfile: \"pnpm-lock.yaml\",\n updateCommand: \"pnpm update {{dependency}}\",\n buildAffected: \"pnpm run build:affected\",\n },\n yarn: {\n globalPathRegexp: /[\\\\/]yarn[\\\\/]/,\n installCommand: \"yarn add {{dependency}}\",\n uninstallCommand: \"yarn remove {{dependency}}\",\n workspaceOption: \"-W\",\n lockfile: \"yarn.lock\",\n updateCommand: \"yarn upgrade {{dependency}}\",\n buildAffected: \"yarn run build:affected\",\n },\n npm: {\n installCommand: \"npm install {{dependency}}\",\n uninstallCommand: \"npm uninstall {{dependency}}\",\n workspaceOption: \"\",\n lockfile: \"package-lock.json\",\n updateCommand: \"npm update {{dependency}} --save\",\n buildAffected: \"npm run build:affected\",\n },\n};\n\ntype PathValidation = (dir: string) => boolean;\n\nexport type PackageManager = \"npm\" | \"yarn\" | \"pnpm\" | \"bun\";\n\nexport type ProjectInfo = {\n isGlobal: boolean;\n path: string;\n packageManager: PackageManager;\n};\n\nexport function defaultPathValidation() {\n return true;\n}\n\nexport function isPowerhouseProject(dir: string) {\n const powerhouseConfigPath = path.join(dir, POWERHOUSE_CONFIG_FILE);\n\n return fs.existsSync(powerhouseConfigPath);\n}\n\nexport function findNodeProjectRoot(\n dir: string,\n pathValidation: PathValidation = defaultPathValidation,\n) {\n const packageJsonPath = path.join(dir, \"package.json\");\n\n if (fs.existsSync(packageJsonPath) && pathValidation(dir)) {\n return dir;\n }\n\n const parentDir = dirname(dir);\n\n if (parentDir === dir) {\n return null;\n }\n\n return findNodeProjectRoot(parentDir, pathValidation);\n}\n\nexport function getProjectInfo(debug?: boolean): ProjectInfo {\n const currentPath = process.cwd();\n\n if (debug) {\n console.log(\">>> currentPath\", currentPath);\n }\n\n const projectPath = findNodeProjectRoot(currentPath, isPowerhouseProject);\n\n if (!projectPath) {\n return {\n isGlobal: true,\n path: POWERHOUSE_GLOBAL_DIR,\n packageManager: getPackageManagerFromLockfile(POWERHOUSE_GLOBAL_DIR),\n };\n }\n\n return {\n isGlobal: false,\n path: projectPath,\n packageManager: getPackageManagerFromLockfile(projectPath),\n };\n}\n\n/**\n * Generates a unique drive ID based on the project path.\n * The same project path will always generate the same ID.\n * @param name - The name prefix for the drive ID (e.g., \"vetra\", \"powerhouse\")\n * @returns A unique drive ID in the format \"{name}-{hash}\"\n */\nexport function generateProjectDriveId(name: string): string {\n const projectInfo = getProjectInfo();\n const hash = crypto\n .createHash(\"sha256\")\n .update(projectInfo.path)\n .digest(\"hex\");\n const shortHash = hash.substring(0, 8);\n return `${name}-${shortHash}`;\n}\n\nexport function getPackageManagerFromLockfile(dir: string): PackageManager {\n if (fs.existsSync(path.join(dir, packageManagers.pnpm.lockfile))) {\n return \"pnpm\";\n } else if (fs.existsSync(path.join(dir, packageManagers.yarn.lockfile))) {\n return \"yarn\";\n } else if (fs.existsSync(path.join(dir, packageManagers.bun.lockfile))) {\n return \"bun\";\n }\n\n return \"npm\";\n}\n\nexport function updatePackagesArray(\n currentPackages: PowerhouseConfig[\"packages\"] = [],\n dependencies: { name: string; version: string | undefined }[],\n task: \"install\" | \"uninstall\" = \"install\",\n provider: \"registry\" | \"local\" = \"registry\",\n): PowerhouseConfig[\"packages\"] {\n const isInstall = task === \"install\";\n const mappedPackages = dependencies.map((dep) => ({\n packageName: dep.name,\n version: dep.version,\n provider,\n }));\n\n if (isInstall) {\n // Overwrite existing package if version is different\n const filteredPackages = currentPackages.filter(\n (pkg) => !dependencies.find((dep) => dep.name === pkg.packageName),\n );\n return [...filteredPackages, ...mappedPackages];\n }\n\n return currentPackages.filter(\n (pkg) => !dependencies.map((dep) => dep.name).includes(pkg.packageName),\n );\n}\n\n// Modify updateConfigFile to use the new function\nexport function updateConfigFile(\n dependencies: { name: string; version: string | undefined }[],\n projectPath: string,\n task: \"install\" | \"uninstall\" = \"install\",\n provider: \"registry\" | \"local\" = \"registry\",\n registryUrl?: string,\n registryUrlExplicit = false,\n) {\n const configPath = path.join(projectPath, POWERHOUSE_CONFIG_FILE);\n\n if (!fs.existsSync(configPath)) {\n throw new Error(\n `powerhouse.config.json file not found. projectPath: ${projectPath}`,\n );\n }\n\n const config = JSON.parse(\n fs.readFileSync(configPath, \"utf-8\"),\n ) as PowerhouseConfig;\n\n const updatedConfig: PowerhouseConfig = {\n ...config,\n packages: updatePackagesArray(\n config.packages,\n dependencies,\n task,\n provider,\n ),\n };\n\n if (\n task === \"install\" &&\n registryUrl &&\n (registryUrlExplicit || !config.packageRegistryUrl) &&\n dependencies.length > 0\n ) {\n updatedConfig.packageRegistryUrl = registryUrl;\n }\n\n fs.writeFileSync(configPath, JSON.stringify(updatedConfig, null, 2));\n}\n\n/**\n * Recursively searches for a specific file by traversing up the directory tree.\n * Starting from the given path, it checks each parent directory until it finds\n * the target file or reaches the root directory.\n *\n * @param startPath - The absolute path of the directory to start searching from\n * @param targetFile - The name of the file to search for (e.g., 'package.json', 'pnpm-workspace.yaml')\n * @returns The absolute path of the directory containing the target file, or null if not found\n *\n * @example\n * // Find the workspace root directory\n * const workspaceRoot = findContainerDirectory('/path/to/project/src', 'pnpm-workspace.yaml');\n *\n * // Find the nearest package.json\n * const packageDir = findContainerDirectory('/path/to/project/src/components', 'package.json');\n */\nexport const findContainerDirectory = (\n startPath: string,\n targetFile: string,\n): string | null => {\n const filePath = path.join(startPath, targetFile);\n\n if (fs.existsSync(filePath)) {\n return startPath;\n }\n\n const parentDir = path.dirname(startPath);\n\n //reached the root directory and haven't found the file\n if (parentDir === startPath) {\n return null;\n }\n\n return findContainerDirectory(parentDir, targetFile);\n};\n\n/**\n * Updates the styles.css file to include imports for newly installed packages\n * @param dependencies - Array of dependencies that were installed\n * @param projectPath - Path to the project root\n */\nexport function updateStylesFile(\n dependencies: { name: string; version: string | undefined }[],\n projectPath: string,\n) {\n const stylesPath = path.join(projectPath, \"style.css\");\n\n // Check if styles.css exists\n if (!fs.existsSync(stylesPath)) {\n console.warn(\"⚠️ Warning: style.css file not found in project root\");\n return;\n }\n\n const currentStyles = fs.readFileSync(stylesPath, \"utf-8\");\n let updatedStyles = currentStyles;\n\n for (const dep of dependencies) {\n const cssPath = `./node_modules/${dep.name}/dist/style.css`;\n const fullCssPath = path.join(projectPath, cssPath);\n const importStatement = `@import '${cssPath}';`;\n\n // Check if the CSS file exists\n if (!fs.existsSync(fullCssPath)) {\n console.warn(`⚠️ Warning: CSS file not found at ${cssPath}`);\n continue;\n }\n\n // Check if import already exists\n if (currentStyles.includes(importStatement)) {\n continue;\n }\n\n // Find the last @import statement\n const importLines = currentStyles\n .split(\"\\n\")\n .filter((line) => line.trim().startsWith(\"@import\"));\n const lastImport = importLines[importLines.length - 1];\n\n if (lastImport) {\n // Insert new import after the last existing import\n updatedStyles = currentStyles.replace(\n lastImport,\n `${lastImport}\\n${importStatement}`,\n );\n } else {\n // If no imports exist, add at the top of the file\n updatedStyles = `${importStatement}\\n${currentStyles}`;\n }\n }\n\n // Only write if changes were made\n if (updatedStyles !== currentStyles) {\n fs.writeFileSync(stylesPath, updatedStyles);\n }\n}\n\n/**\n * Removes CSS imports for uninstalled packages from styles.css\n */\nexport function removeStylesImports(\n dependencies: { name: string; version: string | undefined }[],\n projectPath: string,\n) {\n const stylesPath = path.join(projectPath, \"style.css\");\n\n // Check if styles.css exists\n if (!fs.existsSync(stylesPath)) {\n console.warn(\"⚠️ Warning: style.css file not found in project root\");\n return;\n }\n\n const currentStyles = fs.readFileSync(stylesPath, \"utf-8\");\n let updatedStyles = currentStyles;\n\n for (const dep of dependencies) {\n const cssPath = `./node_modules/${dep.name}/dist/style.css`;\n const importStatement = `@import '${cssPath}';`;\n\n // Remove the import line if it exists\n const lines = updatedStyles.split(\"\\n\");\n const filteredLines = lines.filter(\n (line) => !line.trim().includes(importStatement),\n );\n\n if (filteredLines.length !== lines.length) {\n updatedStyles = filteredLines.join(\"\\n\");\n }\n }\n\n // Only write if changes were made\n if (updatedStyles !== currentStyles) {\n fs.writeFileSync(stylesPath, updatedStyles);\n }\n}\n"],"names":[],"mappings":";;;;;;;AAKA,MAAa,yBAAyB;AACtC,MAAa,wBAAwB,KAAK,KAAK,SAAS,EAAE,MAAM;AAGhE,MAAa,kBAAkB;CAC7B,KAAK;EACH,kBAAkB;EAClB,gBAAgB;EAChB,kBAAkB;EAClB,iBAAiB;EACjB,UAAU;EACV,eAAe;EACf,eAAe;EAChB;CACD,MAAM;EACJ,kBAAkB;EAClB,gBAAgB;EAChB,kBAAkB;EAClB,iBAAiB;EACjB,UAAU;EACV,eAAe;EACf,eAAe;EAChB;CACD,MAAM;EACJ,kBAAkB;EAClB,gBAAgB;EAChB,kBAAkB;EAClB,iBAAiB;EACjB,UAAU;EACV,eAAe;EACf,eAAe;EAChB;CACD,KAAK;EACH,gBAAgB;EAChB,kBAAkB;EAClB,iBAAiB;EACjB,UAAU;EACV,eAAe;EACf,eAAe;EAChB;CACF;AAYD,SAAgB,wBAAwB;AACtC,QAAO;;AAGT,SAAgB,oBAAoB,KAAa;CAC/C,MAAM,uBAAuB,KAAK,KAAK,KAAK,uBAAuB;AAEnE,QAAO,GAAG,WAAW,qBAAqB;;AAG5C,SAAgB,oBACd,KACA,iBAAiC,uBACjC;CACA,MAAM,kBAAkB,KAAK,KAAK,KAAK,eAAe;AAEtD,KAAI,GAAG,WAAW,gBAAgB,IAAI,eAAe,IAAI,CACvD,QAAO;CAGT,MAAM,YAAY,QAAQ,IAAI;AAE9B,KAAI,cAAc,IAChB,QAAO;AAGT,QAAO,oBAAoB,WAAW,eAAe;;AAGvD,SAAgB,eAAe,OAA8B;CAC3D,MAAM,cAAc,QAAQ,KAAK;AAEjC,KAAI,MACF,SAAQ,IAAI,mBAAmB,YAAY;CAG7C,MA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AAK,uDAAuD;AACpE;;CAGF,MAAM,gBAAgB,GAAG,aAAa,YAAY,QAAQ;CAC1D,IAAI,gBAAgB;AAEpB,MAAK,MAAM,OAAO,cAAc;EAE9B,MAAM,kBAAkB,YADR,kBAAkB,IAAI,KAAK,iBACC;EAG5C,MAAM,QAAQ,cAAc,MAAM,KAAK;EACvC,MAAM,gBAAgB,MAAM,QACzB,SAAS,CAAC,KAAK,MAAM,CAAC,SAAS,gBAAgB,CACjD;AAED,MAAI,cAAc,WAAW,MAAM,OACjC,iBAAgB,cAAc,KAAK,KAAK;;AAK5C,KAAI,kBAAkB,cACpB,IAAG,cAAc,YAAY,cAAc","debug_id":"73159d3c-22a7-5dc6-8bd4-7b15f3b94c79"}
1
+ {"version":3,"file":"utils-CvmDmCVd.mjs","sources":["../src/utils.ts"],"sourcesContent":["import type { PowerhouseConfig } from \"@powerhousedao/config\";\nimport crypto from \"node:crypto\";\nimport fs from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport path, { dirname } from \"node:path\";\nexport const POWERHOUSE_CONFIG_FILE = \"powerhouse.config.json\";\nexport const POWERHOUSE_GLOBAL_DIR = path.join(homedir(), \".ph\");\nexport const SUPPORTED_PACKAGE_MANAGERS = [\"npm\", \"yarn\", \"pnpm\", \"bun\"];\n\nexport const packageManagers = {\n bun: {\n globalPathRegexp: /[\\\\/].bun[\\\\/]/,\n installCommand: \"bun add {{dependency}}\",\n uninstallCommand: \"bun remove {{dependency}}\",\n workspaceOption: \"\",\n lockfile: \"bun.lock\",\n updateCommand: \"bun update {{dependency}}\",\n buildAffected: \"bun run build:affected\",\n },\n pnpm: {\n globalPathRegexp: /[\\\\/]pnpm[\\\\/]/,\n installCommand: \"pnpm add {{dependency}}\",\n uninstallCommand: \"pnpm remove {{dependency}}\",\n workspaceOption: \"--workspace-root\",\n lockfile: \"pnpm-lock.yaml\",\n updateCommand: \"pnpm update {{dependency}}\",\n buildAffected: \"pnpm run build:affected\",\n },\n yarn: {\n globalPathRegexp: /[\\\\/]yarn[\\\\/]/,\n installCommand: \"yarn add {{dependency}}\",\n uninstallCommand: \"yarn remove {{dependency}}\",\n workspaceOption: \"-W\",\n lockfile: \"yarn.lock\",\n updateCommand: \"yarn upgrade {{dependency}}\",\n buildAffected: \"yarn run build:affected\",\n },\n npm: {\n installCommand: \"npm install {{dependency}}\",\n uninstallCommand: \"npm uninstall {{dependency}}\",\n workspaceOption: \"\",\n lockfile: \"package-lock.json\",\n updateCommand: \"npm update {{dependency}} --save\",\n buildAffected: \"npm run build:affected\",\n },\n};\n\ntype PathValidation = (dir: string) => boolean;\n\nexport type PackageManager = \"npm\" | \"yarn\" | \"pnpm\" | \"bun\";\n\nexport type ProjectInfo = {\n isGlobal: boolean;\n path: string;\n packageManager: PackageManager;\n};\n\nexport function defaultPathValidation() {\n return true;\n}\n\nexport function isPowerhouseProject(dir: string) {\n const powerhouseConfigPath = path.join(dir, POWERHOUSE_CONFIG_FILE);\n\n return fs.existsSync(powerhouseConfigPath);\n}\n\nexport function findNodeProjectRoot(\n dir: string,\n pathValidation: PathValidation = defaultPathValidation,\n) {\n const packageJsonPath = path.join(dir, \"package.json\");\n\n if (fs.existsSync(packageJsonPath) && pathValidation(dir)) {\n return dir;\n }\n\n const parentDir = dirname(dir);\n\n if (parentDir === dir) {\n return null;\n }\n\n return findNodeProjectRoot(parentDir, pathValidation);\n}\n\nexport function getProjectInfo(debug?: boolean): ProjectInfo {\n const currentPath = process.cwd();\n\n if (debug) {\n console.log(\">>> currentPath\", currentPath);\n }\n\n const projectPath = findNodeProjectRoot(currentPath, isPowerhouseProject);\n\n if (!projectPath) {\n return {\n isGlobal: true,\n path: POWERHOUSE_GLOBAL_DIR,\n packageManager: getPackageManagerFromLockfile(POWERHOUSE_GLOBAL_DIR),\n };\n }\n\n return {\n isGlobal: false,\n path: projectPath,\n packageManager: getPackageManagerFromLockfile(projectPath),\n };\n}\n\n/**\n * Generates a unique drive ID based on the project path.\n * The same project path will always generate the same ID.\n * @param name - The name prefix for the drive ID (e.g., \"vetra\", \"powerhouse\")\n * @returns A unique drive ID in the format \"{name}-{hash}\"\n */\nexport function generateProjectDriveId(name: string): string {\n const projectInfo = getProjectInfo();\n const hash = crypto\n .createHash(\"sha256\")\n .update(projectInfo.path)\n .digest(\"hex\");\n const shortHash = hash.substring(0, 8);\n return `${name}-${shortHash}`;\n}\n\nexport function getPackageManagerFromLockfile(dir: string): PackageManager {\n if (fs.existsSync(path.join(dir, packageManagers.pnpm.lockfile))) {\n return \"pnpm\";\n } else if (fs.existsSync(path.join(dir, packageManagers.yarn.lockfile))) {\n return \"yarn\";\n } else if (fs.existsSync(path.join(dir, packageManagers.bun.lockfile))) {\n return \"bun\";\n }\n\n return \"npm\";\n}\n\nexport function updatePackagesArray(\n currentPackages: PowerhouseConfig[\"packages\"] = [],\n dependencies: { name: string; version: string | undefined }[],\n task: \"install\" | \"uninstall\" = \"install\",\n provider: \"registry\" | \"local\" = \"registry\",\n): PowerhouseConfig[\"packages\"] {\n const isInstall = task === \"install\";\n const mappedPackages = dependencies.map((dep) => ({\n packageName: dep.name,\n version: dep.version,\n provider,\n }));\n\n if (isInstall) {\n // Overwrite existing package if version is different\n const filteredPackages = currentPackages.filter(\n (pkg) => !dependencies.find((dep) => dep.name === pkg.packageName),\n );\n return [...filteredPackages, ...mappedPackages];\n }\n\n return currentPackages.filter(\n (pkg) => !dependencies.map((dep) => dep.name).includes(pkg.packageName),\n );\n}\n\n// Modify updateConfigFile to use the new function\nexport function updateConfigFile(\n dependencies: { name: string; version: string | undefined }[],\n projectPath: string,\n task: \"install\" | \"uninstall\" = \"install\",\n provider: \"registry\" | \"local\" = \"registry\",\n registryUrl?: string,\n registryUrlExplicit = false,\n) {\n const configPath = path.join(projectPath, POWERHOUSE_CONFIG_FILE);\n\n if (!fs.existsSync(configPath)) {\n throw new Error(\n `powerhouse.config.json file not found. projectPath: ${projectPath}`,\n );\n }\n\n const config = JSON.parse(\n fs.readFileSync(configPath, \"utf-8\"),\n ) as PowerhouseConfig;\n\n const updatedConfig: PowerhouseConfig = {\n ...config,\n packages: updatePackagesArray(\n config.packages,\n dependencies,\n task,\n provider,\n ),\n };\n\n if (\n task === \"install\" &&\n registryUrl &&\n (registryUrlExplicit || !config.packageRegistryUrl) &&\n dependencies.length > 0\n ) {\n updatedConfig.packageRegistryUrl = registryUrl;\n }\n\n fs.writeFileSync(configPath, JSON.stringify(updatedConfig, null, 2));\n}\n\n/**\n * Recursively searches for a specific file by traversing up the directory tree.\n * Starting from the given path, it checks each parent directory until it finds\n * the target file or reaches the root directory.\n *\n * @param startPath - The absolute path of the directory to start searching from\n * @param targetFile - The name of the file to search for (e.g., 'package.json', 'pnpm-workspace.yaml')\n * @returns The absolute path of the directory containing the target file, or null if not found\n *\n * @example\n * // Find the workspace root directory\n * const workspaceRoot = findContainerDirectory('/path/to/project/src', 'pnpm-workspace.yaml');\n *\n * // Find the nearest package.json\n * const packageDir = findContainerDirectory('/path/to/project/src/components', 'package.json');\n */\nexport const findContainerDirectory = (\n startPath: string,\n targetFile: string,\n): string | null => {\n const filePath = path.join(startPath, targetFile);\n\n if (fs.existsSync(filePath)) {\n return startPath;\n }\n\n const parentDir = path.dirname(startPath);\n\n //reached the root directory and haven't found the file\n if (parentDir === startPath) {\n return null;\n }\n\n return findContainerDirectory(parentDir, targetFile);\n};\n\n/**\n * Updates the styles.css file to include imports for newly installed packages\n * @param dependencies - Array of dependencies that were installed\n * @param projectPath - Path to the project root\n */\nexport function updateStylesFile(\n dependencies: { name: string; version: string | undefined }[],\n projectPath: string,\n) {\n const stylesPath = path.join(projectPath, \"style.css\");\n\n // Check if styles.css exists\n if (!fs.existsSync(stylesPath)) {\n console.warn(\"⚠️ Warning: style.css file not found in project root\");\n return;\n }\n\n const currentStyles = fs.readFileSync(stylesPath, \"utf-8\");\n let updatedStyles = currentStyles;\n\n for (const dep of dependencies) {\n const cssPath = `./node_modules/${dep.name}/dist/style.css`;\n const fullCssPath = path.join(projectPath, cssPath);\n const importStatement = `@import '${cssPath}';`;\n\n // Check if the CSS file exists\n if (!fs.existsSync(fullCssPath)) {\n console.warn(`⚠️ Warning: CSS file not found at ${cssPath}`);\n continue;\n }\n\n // Check if import already exists\n if (currentStyles.includes(importStatement)) {\n continue;\n }\n\n // Find the last @import statement\n const importLines = currentStyles\n .split(\"\\n\")\n .filter((line) => line.trim().startsWith(\"@import\"));\n const lastImport = importLines[importLines.length - 1];\n\n if (lastImport) {\n // Insert new import after the last existing import\n updatedStyles = currentStyles.replace(\n lastImport,\n `${lastImport}\\n${importStatement}`,\n );\n } else {\n // If no imports exist, add at the top of the file\n updatedStyles = `${importStatement}\\n${currentStyles}`;\n }\n }\n\n // Only write if changes were made\n if (updatedStyles !== currentStyles) {\n fs.writeFileSync(stylesPath, updatedStyles);\n }\n}\n\n/**\n * Removes CSS imports for uninstalled packages from styles.css\n */\nexport function removeStylesImports(\n dependencies: { name: string; version: string | undefined }[],\n projectPath: string,\n) {\n const stylesPath = path.join(projectPath, \"style.css\");\n\n // Check if styles.css exists\n if (!fs.existsSync(stylesPath)) {\n console.warn(\"⚠️ Warning: style.css file not found in project root\");\n return;\n }\n\n const currentStyles = fs.readFileSync(stylesPath, \"utf-8\");\n let updatedStyles = currentStyles;\n\n for (const dep of dependencies) {\n const cssPath = `./node_modules/${dep.name}/dist/style.css`;\n const importStatement = `@import '${cssPath}';`;\n\n // Remove the import line if it exists\n const lines = updatedStyles.split(\"\\n\");\n const filteredLines = lines.filter(\n (line) => !line.trim().includes(importStatement),\n );\n\n if (filteredLines.length !== lines.length) {\n updatedStyles = filteredLines.join(\"\\n\");\n }\n }\n\n // Only write if changes were made\n if (updatedStyles !== currentStyles) {\n fs.writeFileSync(stylesPath, updatedStyles);\n }\n}\n"],"names":[],"mappings":";;;;;;;AAKA,MAAa,yBAAyB;AACtC,MAAa,wBAAwB,KAAK,KAAK,QAAQ,GAAG,KAAK;AAG/D,MAAa,kBAAkB;CAC7B,KAAK;EACH,kBAAkB;EAClB,gBAAgB;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AAK,KAAK,CAAC,CAAC,SAAS,eAAe,CACjD;EAEA,IAAI,cAAc,WAAW,MAAM,QACjC,gBAAgB,cAAc,KAAK,IAAI;CAE3C;CAGA,IAAI,kBAAkB,eACpB,GAAG,cAAc,YAAY,aAAa;AAE9C","debug_id":"fa6f49e1-f268-5ae2-8e22-cc7adc8fbfba"}
@@ -1,13 +1,15 @@
1
1
 
2
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="0be7e354-5024-5332-aa33-5bc37e651ed4")}catch(e){}}();
3
- import { a as parseDefaultDrivesUrl } from "./cli-connect-override-D3hh4aH_.mjs";
4
- import { t as runConnectStudio } from "./connect-studio-D6rfWCNB.mjs";
5
- import { a as generateProjectDriveId } from "./utils-C4isxXSO.mjs";
6
- import { n as startSwitchboard$1 } from "./switchboard-CJMoMzWx.mjs";
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="1f610f34-3f2c-5063-83b1-65fd3499afdb")}catch(e){}}();
3
+ import { a as mergeDefaultDrives, d as rebaseDriveUrl } from "./host-schemas-CL_wFpY7-DOvIjrBA.mjs";
4
+ import { a as parseDefaultDrivesUrl, i as wasFlagExplicitlyPassed } from "./cli-connect-override-65mFEDEB.mjs";
5
+ import { t as runConnectStudio } from "./connect-studio-Q93rzqnC.mjs";
6
+ import { a as generateProjectDriveId } from "./utils-CvmDmCVd.mjs";
7
+ import { i as POWERHOUSE_DRIVE_ICON, r as startSwitchboard$1 } from "./switchboard-tQS3fhqa.mjs";
8
+ import fs from "node:fs";
9
+ import path, { join } from "node:path";
7
10
  import { execSync } from "node:child_process";
8
11
  import { blue, green, red, yellow } from "colorette";
9
- import fs from "node:fs";
10
- import path from "node:path";
12
+ import { getConfig } from "@powerhousedao/shared/clis";
11
13
  import { createLogger } from "vite";
12
14
  import { createVetraDocument, getVetraDocuments, setPackageGithubUrl } from "@powerhousedao/common/utils";
13
15
  import { isPortAvailable } from "@powerhousedao/switchboard/server";
@@ -355,20 +357,6 @@ function syncMcpPort(projectDir, port) {
355
357
  const VETRA_DRIVE_NAME = "vetra";
356
358
  const getDefaultVetraUrl = (port) => `http://localhost:${port}/d/${generateProjectDriveId(VETRA_DRIVE_NAME)}`;
357
359
  const getDriveId = (driveUrl) => driveUrl?.split("/").pop() ?? generateProjectDriveId(VETRA_DRIVE_NAME);
358
- const rebaseDriveUrl = (driveUrl, publicBase) => {
359
- let url;
360
- try {
361
- url = new URL(driveUrl);
362
- } catch {
363
- return driveUrl;
364
- }
365
- if (![
366
- "localhost",
367
- "127.0.0.1",
368
- "[::1]"
369
- ].includes(url.hostname)) return driveUrl;
370
- return `${publicBase.replace(/\/+$/, "")}${url.pathname}`;
371
- };
372
360
  function createViteLogger(color) {
373
361
  const customLogger = createLogger("info");
374
362
  const loggerInfo = customLogger.info.bind(customLogger);
@@ -396,7 +384,7 @@ async function startVetraPreviewDrive(reactor, port, verbose) {
396
384
  slug: previewDriveId,
397
385
  global: {
398
386
  name: "Vetra Preview",
399
- icon: "https://azure-elderly-tortoise-212.mypinata.cloud/ipfs/bafkreifddkbopiyvcirf7vaqar74th424r5phlxkdxniirdyg3qgu2ajha",
387
+ icon: POWERHOUSE_DRIVE_ICON,
400
388
  nodes: []
401
389
  },
402
390
  local: {
@@ -409,6 +397,23 @@ async function startVetraPreviewDrive(reactor, port, verbose) {
409
397
  if (verbose) console.log(blue(`Vetra Switchboard: Preview drive: ${driveUrl}`));
410
398
  return driveUrl;
411
399
  }
400
+ async function seedWorkflowsDrive(reactor, port, verbose) {
401
+ const workflowsDrive = {
402
+ id: generateProjectDriveId("workflows"),
403
+ slug: "workflows",
404
+ global: { name: "Workflows" },
405
+ preferredEditor: "workflow-studio",
406
+ local: {
407
+ availableOffline: true,
408
+ listeners: [],
409
+ sharingType: "public",
410
+ triggers: []
411
+ }
412
+ };
413
+ const driveUrl = await addDefaultDrive(reactor, workflowsDrive, port);
414
+ if (verbose) console.log(blue(`Vetra Switchboard: Workflows drive: ${driveUrl}`));
415
+ return driveUrl;
416
+ }
412
417
  async function startLocalVetraSwitchboard(args, logger) {
413
418
  const { connectPort, switchboardPort, dev, packages, disableLocalPackages, debug, httpsKeyFile, httpsCertFile, remoteDrive, interactive, watch, verbose } = args;
414
419
  const remoteDrives = remoteDrive ? [remoteDrive] : [];
@@ -454,6 +459,12 @@ async function startLocalVetraSwitchboard(args, logger) {
454
459
  } catch (error) {
455
460
  console.error(error);
456
461
  }
462
+ let workflowsDriveUrl = null;
463
+ if (switchboard.workflowsEnabled) try {
464
+ workflowsDriveUrl = await seedWorkflowsDrive(switchboard.reactor, actualSwitchboardPort, verbose);
465
+ } catch (error) {
466
+ console.error(error);
467
+ }
457
468
  if (verbose) {
458
469
  console.log(blue(`Vetra Switchboard: Started successfully`));
459
470
  if (remoteDrive) console.log(blue(`Vetra Switchboard: Syncing with remote drive: ${remoteDrive}`));
@@ -462,10 +473,12 @@ async function startLocalVetraSwitchboard(args, logger) {
462
473
  console.log(blue(`Vetra Switchboard: http://localhost:${actualSwitchboardPort}/graphql`));
463
474
  console.log(blue(` ➜ Drive URL: ${switchboard.defaultDriveUrl}`));
464
475
  if (previewDriveUrl) console.log(blue(` ➜ Preview Drive URL: ${previewDriveUrl}`));
476
+ if (workflowsDriveUrl) console.log(blue(` ➜ Workflows Drive URL: ${workflowsDriveUrl}`));
465
477
  }
466
478
  return {
467
479
  driveUrl: switchboard.defaultDriveUrl || "",
468
480
  previewDriveUrl,
481
+ workflowsDriveUrl,
469
482
  switchboardPort: actualSwitchboardPort
470
483
  };
471
484
  } catch (error) {
@@ -511,6 +524,7 @@ async function startVetra(args) {
511
524
  }, switchboardLogger);
512
525
  const driveUrl = switchboardResult.driveUrl || remoteDrive || "";
513
526
  const previewDriveUrl = switchboardResult.previewDriveUrl;
527
+ const workflowsDriveUrl = switchboardResult.workflowsDriveUrl;
514
528
  const actualSwitchboardPort = switchboardResult.switchboardPort;
515
529
  writeVetraRuntime(projectDir, {
516
530
  pid: process.pid,
@@ -539,19 +553,40 @@ async function startVetra(args) {
539
553
  }
540
554
  if (verbose) console.log("Starting Codegen Reactor...");
541
555
  if (!disableConnect) {
556
+ const publicBase = args.drivesPublicBase;
557
+ const browserDriveUrl = publicBase ? rebaseDriveUrl(driveUrl, publicBase) : driveUrl;
558
+ const browserPreviewDriveUrl = previewDriveUrl && publicBase ? rebaseDriveUrl(previewDriveUrl, publicBase) : previewDriveUrl;
559
+ const browserWorkflowsDriveUrl = workflowsDriveUrl && publicBase ? rebaseDriveUrl(workflowsDriveUrl, publicBase) : workflowsDriveUrl;
560
+ const vetraDriveEntries = [
561
+ ...browserDriveUrl ? [{
562
+ url: browserDriveUrl,
563
+ name: null,
564
+ icon: null
565
+ }] : [],
566
+ ...browserPreviewDriveUrl ? [{
567
+ url: browserPreviewDriveUrl,
568
+ name: null,
569
+ icon: null
570
+ }] : [],
571
+ ...browserWorkflowsDriveUrl ? [{
572
+ url: browserWorkflowsDriveUrl,
573
+ name: null,
574
+ icon: null
575
+ }] : []
576
+ ];
577
+ const configuredDefaultDrives = getConfig(join(projectDir, "powerhouse.config.json")).connect?.drives?.defaultDrives ?? [];
578
+ const resolvedDefaultDrives = mergeDefaultDrives(vetraDriveEntries, configuredDefaultDrives);
542
579
  if (verbose) {
543
580
  console.log("Starting Connect...");
544
- const drives = previewDriveUrl ? `${driveUrl}, ${previewDriveUrl}` : driveUrl;
545
- console.log(` ➜ Connect will use drives: ${drives}`);
581
+ const flagDefaultDrives = wasFlagExplicitlyPassed("default-drives-url") ? parseDefaultDrivesUrl(args.defaultDrivesUrl ?? "") : [];
582
+ const printedDefaultDrives = mergeDefaultDrives(resolvedDefaultDrives, flagDefaultDrives);
583
+ console.log(` ➜ Connect will use default drives: ${printedDefaultDrives.map((d) => "url" in d ? d.url : `local:${d.id}`).join(", ")}`);
546
584
  }
547
585
  console.log();
548
586
  console.log(green(`Vetra Connect: http://localhost:${connectPort}`));
549
587
  const customViteLogger = createViteLogger(green);
550
- const publicBase = args.drivesPublicBase;
551
- const browserDriveUrl = publicBase ? rebaseDriveUrl(driveUrl, publicBase) : driveUrl;
552
- const browserPreviewDriveUrl = previewDriveUrl && publicBase ? rebaseDriveUrl(previewDriveUrl, publicBase) : previewDriveUrl;
553
588
  const vetraDrivesOverride = { drives: {
554
- defaultDrives: parseDefaultDrivesUrl(browserPreviewDriveUrl ? [browserDriveUrl, browserPreviewDriveUrl].join(",") : browserDriveUrl),
589
+ defaultDrives: resolvedDefaultDrives,
555
590
  preserveStrategy: "preserve-all"
556
591
  } };
557
592
  await runConnectStudio({
@@ -573,7 +608,7 @@ async function startVetra(args) {
573
608
  }
574
609
  }
575
610
  //#endregion
576
- export { startVetra };
611
+ export { seedWorkflowsDrive, startVetra };
577
612
 
578
- //# sourceMappingURL=vetra-DkF6EJMY.mjs.map
579
- //# debugId=0be7e354-5024-5332-aa33-5bc37e651ed4
613
+ //# sourceMappingURL=vetra-BNJZ5LHN.mjs.map
614
+ //# debugId=1f610f34-3f2c-5063-83b1-65fd3499afdb