@powerhousedao/ph-cli 6.0.2-staging.1 → 6.0.2-staging.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/README.md +2 -2
  2. package/dist/assign-env-vars-W-lZmdMi.mjs +18 -0
  3. package/dist/assign-env-vars-W-lZmdMi.mjs.map +1 -0
  4. package/dist/auth-AR3VxAIk.mjs +18 -0
  5. package/dist/auth-AR3VxAIk.mjs.map +1 -0
  6. package/dist/auth-BNkN6kS9.mjs +4 -0
  7. package/dist/build-CqtYNjiI.mjs +4 -0
  8. package/dist/build-vccTv_Jp.mjs +49 -0
  9. package/dist/build-vccTv_Jp.mjs.map +1 -0
  10. package/dist/cli.d.mts +1 -0
  11. package/dist/cli.mjs +1199 -0
  12. package/dist/cli.mjs.map +1 -0
  13. package/dist/connect-build-B7I7HJu0.mjs +38 -0
  14. package/dist/connect-build-B7I7HJu0.mjs.map +1 -0
  15. package/dist/connect-preview-CNJkhtxL.mjs +30 -0
  16. package/dist/connect-preview-CNJkhtxL.mjs.map +1 -0
  17. package/dist/connect-studio-DTdSFftL.mjs +31 -0
  18. package/dist/connect-studio-DTdSFftL.mjs.map +1 -0
  19. package/dist/connect-studio-DySbZFEc.mjs +5 -0
  20. package/dist/generate-all-Cj8zjFhN.mjs +15 -0
  21. package/dist/generate-all-Cj8zjFhN.mjs.map +1 -0
  22. package/dist/generate-app-KE0rbE-b.mjs +38 -0
  23. package/dist/generate-app-KE0rbE-b.mjs.map +1 -0
  24. package/dist/generate-document-model-Cut44i6D.mjs +24 -0
  25. package/dist/generate-document-model-Cut44i6D.mjs.map +1 -0
  26. package/dist/generate-editor-DmSzWm3W.mjs +38 -0
  27. package/dist/generate-editor-DmSzWm3W.mjs.map +1 -0
  28. package/dist/generate-processor-B-fChg4W.mjs +30 -0
  29. package/dist/generate-processor-B-fChg4W.mjs.map +1 -0
  30. package/dist/generate-subgraph-C6dWIQzP.mjs +28 -0
  31. package/dist/generate-subgraph-C6dWIQzP.mjs.map +1 -0
  32. package/dist/init-Cw_5H_Z1.mjs +128 -0
  33. package/dist/init-Cw_5H_Z1.mjs.map +1 -0
  34. package/dist/inspect-BwuBW_zW.mjs +48 -0
  35. package/dist/inspect-BwuBW_zW.mjs.map +1 -0
  36. package/dist/migrate-CfgiCNQo.mjs +83 -0
  37. package/dist/migrate-CfgiCNQo.mjs.map +1 -0
  38. package/dist/registry-auth-CNH84uo4.mjs +25 -0
  39. package/dist/registry-auth-CNH84uo4.mjs.map +1 -0
  40. package/dist/scripts/generate-commands-docs.ts +14 -0
  41. package/dist/scripts/setup.sh +3 -3
  42. package/dist/switchboard-CERuSM8r.mjs +75 -0
  43. package/dist/switchboard-CERuSM8r.mjs.map +1 -0
  44. package/dist/switchboard-ChH1PMaE.mjs +4 -0
  45. package/dist/switchboard-migrate-BumRp7rC.mjs +53 -0
  46. package/dist/switchboard-migrate-BumRp7rC.mjs.map +1 -0
  47. package/dist/switchboard-reset-1YcJEVqc.mjs +87 -0
  48. package/dist/switchboard-reset-1YcJEVqc.mjs.map +1 -0
  49. package/dist/utils-C6581aex.mjs +4 -0
  50. package/dist/utils-mth8NsDA.mjs +165 -0
  51. package/dist/utils-mth8NsDA.mjs.map +1 -0
  52. package/dist/vetra-yCsUKy_u.mjs +425 -0
  53. package/dist/vetra-yCsUKy_u.mjs.map +1 -0
  54. package/package.json +31 -26
  55. package/dist/bundle.d.ts +0 -2
  56. package/dist/bundle.d.ts.map +0 -1
  57. package/dist/scripts/generate-commands-docs.d.ts +0 -2
  58. package/dist/scripts/generate-commands-docs.d.ts.map +0 -1
  59. package/dist/src/cli.d.ts +0 -3
  60. package/dist/src/cli.d.ts.map +0 -1
  61. package/dist/src/cli.js +0 -395510
  62. package/dist/src/commands/access-token.d.ts +0 -14
  63. package/dist/src/commands/access-token.d.ts.map +0 -1
  64. package/dist/src/commands/connect.d.ts +0 -249
  65. package/dist/src/commands/connect.d.ts.map +0 -1
  66. package/dist/src/commands/generate.d.ts +0 -62
  67. package/dist/src/commands/generate.d.ts.map +0 -1
  68. package/dist/src/commands/index.d.ts +0 -13
  69. package/dist/src/commands/index.d.ts.map +0 -1
  70. package/dist/src/commands/inspect.d.ts +0 -12
  71. package/dist/src/commands/inspect.d.ts.map +0 -1
  72. package/dist/src/commands/install.d.ts +0 -22
  73. package/dist/src/commands/install.d.ts.map +0 -1
  74. package/dist/src/commands/list.d.ts +0 -10
  75. package/dist/src/commands/list.d.ts.map +0 -1
  76. package/dist/src/commands/login.d.ts +0 -24
  77. package/dist/src/commands/login.d.ts.map +0 -1
  78. package/dist/src/commands/logout.d.ts +0 -6
  79. package/dist/src/commands/logout.d.ts.map +0 -1
  80. package/dist/src/commands/migrate.d.ts +0 -12
  81. package/dist/src/commands/migrate.d.ts.map +0 -1
  82. package/dist/src/commands/ph-cli-commands.d.ts +0 -419
  83. package/dist/src/commands/ph-cli-commands.d.ts.map +0 -1
  84. package/dist/src/commands/ph-cli-help.d.ts +0 -400
  85. package/dist/src/commands/ph-cli-help.d.ts.map +0 -1
  86. package/dist/src/commands/ph-cli.d.ts +0 -506
  87. package/dist/src/commands/ph-cli.d.ts.map +0 -1
  88. package/dist/src/commands/service.d.ts +0 -12
  89. package/dist/src/commands/service.d.ts.map +0 -1
  90. package/dist/src/commands/switchboard.d.ts +0 -46
  91. package/dist/src/commands/switchboard.d.ts.map +0 -1
  92. package/dist/src/commands/uninstall.d.ts +0 -22
  93. package/dist/src/commands/uninstall.d.ts.map +0 -1
  94. package/dist/src/commands/vetra.d.ts +0 -64
  95. package/dist/src/commands/vetra.d.ts.map +0 -1
  96. package/dist/src/get-version.d.ts +0 -2
  97. package/dist/src/get-version.d.ts.map +0 -1
  98. package/dist/src/help.d.ts +0 -65
  99. package/dist/src/help.d.ts.map +0 -1
  100. package/dist/src/services/auth.d.ts +0 -21
  101. package/dist/src/services/auth.d.ts.map +0 -1
  102. package/dist/src/services/connect-build.d.ts +0 -3
  103. package/dist/src/services/connect-build.d.ts.map +0 -1
  104. package/dist/src/services/connect-preview.d.ts +0 -3
  105. package/dist/src/services/connect-preview.d.ts.map +0 -1
  106. package/dist/src/services/connect-studio.d.ts +0 -4
  107. package/dist/src/services/connect-studio.d.ts.map +0 -1
  108. package/dist/src/services/generate.d.ts +0 -3
  109. package/dist/src/services/generate.d.ts.map +0 -1
  110. package/dist/src/services/inspect.d.ts +0 -3
  111. package/dist/src/services/inspect.d.ts.map +0 -1
  112. package/dist/src/services/migrate.d.ts +0 -3
  113. package/dist/src/services/migrate.d.ts.map +0 -1
  114. package/dist/src/services/switchboard-migrate.d.ts +0 -7
  115. package/dist/src/services/switchboard-migrate.d.ts.map +0 -1
  116. package/dist/src/services/switchboard.d.ts +0 -23
  117. package/dist/src/services/switchboard.d.ts.map +0 -1
  118. package/dist/src/services/vetra.d.ts +0 -3
  119. package/dist/src/services/vetra.d.ts.map +0 -1
  120. package/dist/src/types.d.ts +0 -28
  121. package/dist/src/types.d.ts.map +0 -1
  122. package/dist/src/utils/assign-env-vars.d.ts +0 -3
  123. package/dist/src/utils/assign-env-vars.d.ts.map +0 -1
  124. package/dist/src/utils/configure-vetra-github-url.d.ts +0 -12
  125. package/dist/src/utils/configure-vetra-github-url.d.ts.map +0 -1
  126. package/dist/src/utils/constants.d.ts +0 -2
  127. package/dist/src/utils/constants.d.ts.map +0 -1
  128. package/dist/src/utils/resolve-connect-dirs.d.ts +0 -5
  129. package/dist/src/utils/resolve-connect-dirs.d.ts.map +0 -1
  130. package/dist/src/utils.d.ts +0 -112
  131. package/dist/src/utils.d.ts.map +0 -1
  132. package/dist/tsconfig.tsbuildinfo +0 -1
  133. package/dist/vitest.config.d.ts +0 -3
  134. package/dist/vitest.config.d.ts.map +0 -1
package/dist/cli.mjs ADDED
@@ -0,0 +1,1199 @@
1
+ #!/usr/bin/env node
2
+
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]="19f46d7c-6663-5ffa-ac40-1a71c0a3d790")}catch(e){}}();
4
+ import { initCliTelemetry } from "@powerhousedao/shared/clis/telemetry";
5
+ import { assertNodeVersion } from "@powerhousedao/shared/clis/utils";
6
+ import { array, boolean, command, flag, multioption, oneOf, option, optional, run, string, subcommands } from "cmd-ts";
7
+ import { AGENTS, accessTokenArgs, buildArgs, connectBuildArgs, connectPreviewArgs, connectStudioArgs, debugArgs, initArgs, inspectArgs, installArgs, listArgs, loginArgs, migrateArgs, phCliHelpCommands, publishArgs, registryLoginArgs, switchboardArgs, uninstallArgs, unpublishArgs, vetraArgs } from "@powerhousedao/shared/clis/args";
8
+ import { DEFAULT_EXPIRY_SECONDS } from "@powerhousedao/shared/clis/constants";
9
+ import { Directory, File } from "cmd-ts/dist/cjs/batteries/fs.js";
10
+ import path from "path";
11
+ import { PROCESSOR_APPS } from "@powerhousedao/shared/processors";
12
+ import { execSync } from "child_process";
13
+ import { execSync as execSync$1 } from "node:child_process";
14
+ import { createInterface } from "node:readline/promises";
15
+ import { bold, yellow } from "colorette";
16
+ //#region src/get-version.ts
17
+ function getVersion() {
18
+ return "6.0.2-staging.10";
19
+ }
20
+ //#endregion
21
+ //#region src/utils/constants.ts
22
+ const PH_CLI_DESCRIPTION = "The Powerhouse CLI (ph-cli) is a command-line interface tool that provides essential commands for managing Powerhouse projects. The tool and it's commands are fundamental for creating, building, and running Document Models as a builder in studio mode.";
23
+ const phCliHelp = subcommands({
24
+ name: "ph-cli",
25
+ description: PH_CLI_DESCRIPTION,
26
+ version: getVersion(),
27
+ cmds: phCliHelpCommands
28
+ });
29
+ //#endregion
30
+ //#region src/commands/access-token.ts
31
+ const accessToken = command({
32
+ name: "access-token",
33
+ description: `
34
+ The access-token command generates a bearer token for API authentication. This token
35
+ can be used to authenticate requests to Powerhouse APIs like reactor-api (Switchboard).
36
+
37
+ This command:
38
+ 1. Uses your CLI's cryptographic identity (DID) to sign a verifiable credential
39
+ 2. Creates a JWT bearer token with configurable expiration
40
+ 3. Outputs the token to stdout (info to stderr) for easy piping
41
+
42
+ Prerequisites:
43
+ You must have a cryptographic identity. Run 'ph login' first to:
44
+ - Generate a keypair (stored in .ph/.keypair.json)
45
+ - Optionally link your Ethereum address (stored in .ph/.renown.json)
46
+
47
+ Token Details:
48
+ The generated token is a JWT (JSON Web Token) containing:
49
+ - Issuer (iss): Your CLI's DID (did:key:...)
50
+ - Subject (sub): Your CLI's DID
51
+ - Credential Subject: Chain ID, network ID, and address (if authenticated)
52
+ - Expiration (exp): Based on --expiry option
53
+ - Audience (aud): If --audience is specified
54
+
55
+ Output:
56
+ - Token information (DID, address, expiry) is printed to stderr
57
+ - The token itself is printed to stdout for easy piping/copying
58
+
59
+ This allows you to use the command in scripts:
60
+ TOKEN=$(ph access-token)
61
+ curl -H "Authorization: Bearer $TOKEN" http://localhost:4001/graphql
62
+
63
+ Usage with APIs:
64
+ Generate token and use with curl
65
+ TOKEN=$(ph access-token --expiry 1d)
66
+ curl -X POST http://localhost:4001/graphql \\
67
+ -H "Content-Type: application/json" \\
68
+ -H "Authorization: Bearer $TOKEN" \\
69
+ -d '{"query": "{ drives { id name } }"}'
70
+
71
+ Export as environment variable
72
+ export PH_ACCESS_TOKEN=$(ph access-token)
73
+
74
+ Notes:
75
+ - Tokens are self-signed using your CLI's private key
76
+ - No network request is made; tokens are generated locally
77
+ - The recipient API must trust your CLI's DID to accept the token
78
+ - For reactor-api, ensure AUTH_ENABLED=true to require authentication
79
+ `,
80
+ args: accessTokenArgs,
81
+ handler: async (args) => {
82
+ if (args.debug) console.log(args);
83
+ const { generateAccessToken, parseExpiry, formatExpiry } = await import("@renown/sdk/node");
84
+ const { getRenown } = await import("./auth-BNkN6kS9.mjs");
85
+ const renown = await getRenown();
86
+ let expiresIn = DEFAULT_EXPIRY_SECONDS;
87
+ if (args.expiry) expiresIn = parseExpiry(args.expiry);
88
+ const result = await generateAccessToken(renown, {
89
+ expiresIn,
90
+ aud: args.audience
91
+ });
92
+ console.error(`CLI DID: ${result.did}`);
93
+ console.error(`ETH Address: ${result.address}`);
94
+ console.error(`Token expires in: ${formatExpiry(expiresIn)}`);
95
+ console.error("");
96
+ console.log(result.token);
97
+ process.exit(0);
98
+ }
99
+ });
100
+ //#endregion
101
+ //#region src/commands/build.ts
102
+ const build$1 = command({
103
+ name: "build",
104
+ args: buildArgs,
105
+ handler: async (args) => {
106
+ if (args.debug) console.log(args);
107
+ try {
108
+ const { runBuild } = await import("./build-CqtYNjiI.mjs");
109
+ await runBuild(args);
110
+ } catch (error) {
111
+ console.error(error);
112
+ process.exit(1);
113
+ }
114
+ }
115
+ });
116
+ const connect = subcommands({
117
+ name: "connect",
118
+ description: `Powerhouse Connect commands. Use with \`studio\`, \`build\` or \`preview\`. Defaults to \`studio\` if not specified.`,
119
+ cmds: {
120
+ studio: command({
121
+ name: "studio",
122
+ description: `The studio command starts the Connect Studio, a development environment for building
123
+ and testing Powerhouse applications. It provides a visual interface for working with
124
+ your project.
125
+
126
+ This command:
127
+ 1. Starts a local Connect Studio server
128
+ 2. Provides a web interface for development
129
+ 3. Allows you to interact with your project components
130
+ 4. Supports various configuration options for customization
131
+ `,
132
+ args: connectStudioArgs,
133
+ handler: async (args) => {
134
+ if (args.debug) console.log(args);
135
+ const { runConnectStudio } = await import("./connect-studio-DySbZFEc.mjs");
136
+ await runConnectStudio(args);
137
+ }
138
+ }),
139
+ build: command({
140
+ name: "build",
141
+ description: `The Connect build command creates a production build with the project's local and
142
+ external packages included
143
+ `,
144
+ args: connectBuildArgs,
145
+ handler: async (args) => {
146
+ if (args.debug) console.log(args);
147
+ const { runConnectBuild } = await import("./connect-build-B7I7HJu0.mjs");
148
+ await runConnectBuild(args);
149
+ process.exit(0);
150
+ }
151
+ }),
152
+ preview: command({
153
+ name: "preview",
154
+ description: `The Connect preview command previews a built Connect project.
155
+ NOTE: You must run \`ph connect build\` first
156
+ `,
157
+ args: connectPreviewArgs,
158
+ handler: async (args) => {
159
+ if (args.debug) console.log(args);
160
+ const { runConnectPreview } = await import("./connect-preview-CNJkhtxL.mjs");
161
+ await runConnectPreview(args);
162
+ }
163
+ })
164
+ }
165
+ });
166
+ //#endregion
167
+ //#region src/commands/generate-all.ts
168
+ const generateAllCmd = command({
169
+ name: "all",
170
+ description: "Re-generate all modules in the current project",
171
+ args: {},
172
+ handler: async () => {
173
+ const { startGenerateAll } = await import("./generate-all-Cj8zjFhN.mjs");
174
+ await startGenerateAll(process.cwd());
175
+ process.exit(0);
176
+ }
177
+ });
178
+ //#endregion
179
+ //#region src/commands/generate-app.ts
180
+ const generateAppCmd = command({
181
+ name: "app",
182
+ description: "Generate a drive app",
183
+ args: {
184
+ name: option({
185
+ type: optional(string),
186
+ long: "name",
187
+ short: "n",
188
+ description: "The name of the drive app to generate"
189
+ }),
190
+ allowedDocumentTypes: multioption({
191
+ type: optional(array(string)),
192
+ long: "document-types",
193
+ short: "t",
194
+ description: "The document types allowed by the new app"
195
+ }),
196
+ dir: option({
197
+ type: optional(Directory),
198
+ long: "dir",
199
+ short: "d",
200
+ description: "Name of the directory of an existing app to re-generate"
201
+ }),
202
+ disableDragAndDrop: flag({
203
+ type: boolean,
204
+ long: "disable-drag-and-drop",
205
+ description: "Do not allow drag and drop in this drive app.",
206
+ defaultValue: () => false,
207
+ defaultValueIsSerializable: true
208
+ }),
209
+ all: flag({
210
+ long: "all",
211
+ short: "a",
212
+ description: "Re-generate all existing apps in the current project"
213
+ }),
214
+ ...debugArgs
215
+ },
216
+ handler: async (args) => {
217
+ const { startGenerateApp } = await import("./generate-app-KE0rbE-b.mjs");
218
+ await startGenerateApp(args, process.cwd());
219
+ process.exit(0);
220
+ }
221
+ });
222
+ //#endregion
223
+ //#region src/commands/generate-document-model.ts
224
+ const generateDocumentModelCmd = command({
225
+ name: "document-model",
226
+ aliases: ["doc"],
227
+ description: "Generate a document model",
228
+ args: {
229
+ file: option({
230
+ type: optional(File),
231
+ long: "file",
232
+ short: "f",
233
+ description: "Path to the file to generate the document model from"
234
+ }),
235
+ dir: option({
236
+ type: optional(Directory),
237
+ long: "dir",
238
+ short: "d",
239
+ description: "Name of the directory of an existing document model to re-generate"
240
+ }),
241
+ all: flag({
242
+ long: "all",
243
+ short: "a",
244
+ description: "Re-generate all existing document models in the current project"
245
+ }),
246
+ ...debugArgs
247
+ },
248
+ handler: async (args) => {
249
+ const { startGenerateDocumentModel } = await import("./generate-document-model-Cut44i6D.mjs");
250
+ await startGenerateDocumentModel(args, process.cwd());
251
+ process.exit(0);
252
+ }
253
+ });
254
+ //#endregion
255
+ //#region src/commands/generate-editor.ts
256
+ const generateEditorCmd = command({
257
+ name: "editor",
258
+ description: "Generate a document editor",
259
+ args: {
260
+ name: option({
261
+ type: optional(string),
262
+ long: "name",
263
+ short: "n",
264
+ description: "The name of the document editor to generate"
265
+ }),
266
+ documentType: option({
267
+ type: optional(string),
268
+ long: "document-type",
269
+ short: "t",
270
+ description: "The document type for the new editor"
271
+ }),
272
+ dir: option({
273
+ type: optional(Directory),
274
+ long: "dir",
275
+ short: "d",
276
+ description: "Name of the directory of an existing editor to re-generate"
277
+ }),
278
+ all: flag({
279
+ long: "all",
280
+ short: "a",
281
+ description: "Re-generate all existing editors in the current project"
282
+ }),
283
+ ...debugArgs
284
+ },
285
+ handler: async (args) => {
286
+ const { startGenerateEditor } = await import("./generate-editor-DmSzWm3W.mjs");
287
+ await startGenerateEditor(args, process.cwd());
288
+ process.exit(0);
289
+ }
290
+ });
291
+ //#endregion
292
+ //#region src/commands/generate-migration-file.ts
293
+ const generateMigrationFileCmd = command({
294
+ name: "migration-file",
295
+ description: "Generate a migration file",
296
+ args: {
297
+ migrationFile: option({
298
+ type: string,
299
+ long: "path",
300
+ short: "p",
301
+ description: "Path to the migration file"
302
+ }),
303
+ schemaFile: option({
304
+ type: optional(string),
305
+ long: "schema-file",
306
+ description: "Path to the output file. Defaults to './schema.ts'"
307
+ }),
308
+ ...debugArgs
309
+ },
310
+ handler: async ({ migrationFile, schemaFile }) => {
311
+ const { generateDBSchema } = await import("@powerhousedao/codegen");
312
+ await generateDBSchema({
313
+ migrationFile: path.join(process.cwd(), migrationFile),
314
+ schemaFile: schemaFile ? path.join(process.cwd(), schemaFile) : void 0
315
+ });
316
+ process.exit(0);
317
+ }
318
+ });
319
+ const generateProcessorCmd = command({
320
+ name: "processor",
321
+ description: "Generate a processor",
322
+ args: {
323
+ name: option({
324
+ type: optional(string),
325
+ long: "name",
326
+ short: "n",
327
+ description: "The name of the processor to generate"
328
+ }),
329
+ type: option({
330
+ type: oneOf(["analytics", "relationalDb"]),
331
+ long: "type",
332
+ description: "The type of processor to generate",
333
+ defaultValue: () => "analytics",
334
+ defaultValueIsSerializable: true
335
+ }),
336
+ documentTypes: multioption({
337
+ type: array(string),
338
+ long: "document-types",
339
+ short: "t",
340
+ description: "The document types the processor will run on",
341
+ defaultValue: () => [],
342
+ defaultValueIsSerializable: true
343
+ }),
344
+ apps: multioption({
345
+ long: "apps",
346
+ type: { from(processorApps) {
347
+ if (processorApps.length === 0) throw new Error(`No arguments provided for processor apps. Must be "connect" and/or "switchboard"`);
348
+ if (processorApps.length > 2) throw new Error(`Too many arguments provided for processor apps. Must be "connect" and/or "switchboard"`);
349
+ const allowed = new Set(PROCESSOR_APPS);
350
+ if (!processorApps.every((p) => allowed.has(p))) throw new Error(`Processor apps can only be "connect" and/or "switchboard".`);
351
+ return Promise.resolve(processorApps);
352
+ } },
353
+ description: "Whether the processor will run in switchboard (nodejs), connect (browser), or both",
354
+ defaultValue: () => ["switchboard", "connect"],
355
+ defaultValueIsSerializable: true
356
+ }),
357
+ dir: option({
358
+ type: optional(Directory),
359
+ long: "dir",
360
+ short: "d",
361
+ description: "Name of the directory of an existing processor to re-generate"
362
+ }),
363
+ all: flag({
364
+ long: "all",
365
+ short: "a",
366
+ description: "Re-generate all existing processors in the current project"
367
+ }),
368
+ ...debugArgs
369
+ },
370
+ handler: async (args) => {
371
+ const { startGenerateProcessor } = await import("./generate-processor-B-fChg4W.mjs");
372
+ await startGenerateProcessor(args, process.cwd());
373
+ process.exit(0);
374
+ }
375
+ });
376
+ //#endregion
377
+ //#region src/commands/generate-subgraph.ts
378
+ const generateSubgraphCmd = command({
379
+ name: "subgraph",
380
+ description: "Generate a subgraph",
381
+ args: {
382
+ name: option({
383
+ type: optional(string),
384
+ long: "name",
385
+ short: "n",
386
+ description: "The name of the subgraph to generate"
387
+ }),
388
+ dir: option({
389
+ type: optional(Directory),
390
+ long: "dir",
391
+ short: "d",
392
+ description: "Name of the directory of an existing subgraph to re-generate"
393
+ }),
394
+ all: flag({
395
+ long: "all",
396
+ short: "a",
397
+ description: "Re-generate all existing subgraphs in the current project"
398
+ }),
399
+ ...debugArgs
400
+ },
401
+ handler: async (args) => {
402
+ const { startGenerateSubgraph } = await import("./generate-subgraph-C6dWIQzP.mjs");
403
+ await startGenerateSubgraph(args, process.cwd());
404
+ process.exit(0);
405
+ }
406
+ });
407
+ //#endregion
408
+ //#region src/commands/generate.ts
409
+ const generate = subcommands({
410
+ name: "generate",
411
+ description: `The generate command creates code for Powerhouse modules. It helps you create new code from scratch, or to re-generate existing code in your project.`,
412
+ cmds: {
413
+ all: generateAllCmd,
414
+ "document-model": generateDocumentModelCmd,
415
+ editor: generateEditorCmd,
416
+ app: generateAppCmd,
417
+ processor: generateProcessorCmd,
418
+ subgraph: generateSubgraphCmd,
419
+ "migration-file": generateMigrationFileCmd
420
+ }
421
+ });
422
+ //#endregion
423
+ //#region src/commands/init.ts
424
+ const init = command({
425
+ name: "init",
426
+ description: "Initialize a new project",
427
+ args: initArgs,
428
+ handler: async (args) => {
429
+ if (args.debug) console.log({ args });
430
+ const { startInit } = await import("./init-Cw_5H_Z1.mjs");
431
+ await startInit(args);
432
+ process.exit(0);
433
+ }
434
+ });
435
+ //#endregion
436
+ //#region src/commands/inspect.ts
437
+ const inspect = command({
438
+ name: "inspect",
439
+ description: `
440
+ The inspect command examines and provides detailed information about a Powerhouse package.
441
+ It helps you understand the structure, dependencies, and configuration of packages in
442
+ your project.
443
+
444
+ This command:
445
+ 1. Analyzes the specified package
446
+ 2. Retrieves detailed information about its structure and configuration
447
+ 3. Displays package metadata, dependencies, and other relevant information
448
+ 4. Helps troubleshoot package-related issues`,
449
+ aliases: ["is"],
450
+ args: inspectArgs,
451
+ handler: async (args) => {
452
+ if (args.debug) console.log(args);
453
+ const { startInspect } = await import("./inspect-BwuBW_zW.mjs");
454
+ startInspect(args);
455
+ process.exit(0);
456
+ }
457
+ });
458
+ //#endregion
459
+ //#region src/commands/install.ts
460
+ const install = command({
461
+ name: "install",
462
+ aliases: ["add", "i"],
463
+ description: `
464
+ The install command adds Powerhouse dependencies to your project.
465
+
466
+ By default it only registers the package in powerhouse.config.json with
467
+ provider "registry" — Connect will load it from the registry CDN at runtime.
468
+
469
+ With --local, the package is also installed into node_modules and marked
470
+ as provider "local" — it will be bundled into ph connect build so the
471
+ preview works without the registry being reachable.
472
+
473
+ Resolution order for the registry URL:
474
+ --registry flag > PH_REGISTRY_URL env > powerhouse.config.json > default
475
+ `,
476
+ args: installArgs,
477
+ handler: async (args) => {
478
+ if (args.debug) console.log(args);
479
+ const { getPowerhouseProjectInfo, makeDependenciesWithVersions } = await import("@powerhousedao/shared/clis");
480
+ const { projectPath, localProjectPath, globalProjectPath, packageManager, isGlobal } = await getPowerhouseProjectInfo(args);
481
+ if (!projectPath) throw new Error(`Could not find project path to install from.`);
482
+ const { resolveRegistryUrl } = await import("@powerhousedao/shared/registry");
483
+ const registryUrl = resolveRegistryUrl({
484
+ registry: args.registry,
485
+ projectPath
486
+ });
487
+ if (args.debug) console.log(">>> registryUrl", registryUrl);
488
+ const dependenciesWithVersions = await makeDependenciesWithVersions(args.dependencies, registryUrl);
489
+ if (args.debug) {
490
+ console.log(">>> parsedDependencies", dependenciesWithVersions);
491
+ console.log("\n>>> projectInfo", {
492
+ localProjectPath,
493
+ globalProjectPath,
494
+ packageManager,
495
+ isGlobal
496
+ });
497
+ }
498
+ if (args.local) {
499
+ if (dependenciesWithVersions.length === 0) throw new Error("--local requires at least one package name (e.g. ph install --local @scope/pkg)");
500
+ try {
501
+ const specs = dependenciesWithVersions.map((d) => d.version ? `${d.name}@${d.version}` : d.name);
502
+ const scopes = /* @__PURE__ */ new Set();
503
+ for (const dep of dependenciesWithVersions) if (dep.name.startsWith("@")) {
504
+ const scope = dep.name.split("/")[0];
505
+ scopes.add(scope);
506
+ }
507
+ const scopeRegistryArgs = Array.from(scopes).map((scope) => `--${scope}:registry=${registryUrl}`);
508
+ const minReleaseAgeArgs = packageManager === "pnpm" ? ["--config.minimum-release-age=0"] : [];
509
+ const allowBuildArgs = packageManager === "pnpm" && args.allowBuild.length > 0 ? [`--allow-build=${args.allowBuild.join(",")}`] : [];
510
+ const { resolveCommand } = await import("package-manager-detector");
511
+ const resolved = resolveCommand(packageManager, "add", [
512
+ ...specs,
513
+ ...scopeRegistryArgs,
514
+ ...minReleaseAgeArgs,
515
+ ...allowBuildArgs
516
+ ]);
517
+ if (!resolved) throw new Error(`Failed to resolve install command for package manager "${packageManager}".`);
518
+ const installCommand = `${resolved.command} ${resolved.args.join(" ")}`;
519
+ if (scopeRegistryArgs.length > 0) console.log(`Installing dependencies 📦 (routing ${Array.from(scopes).join(", ")} → ${registryUrl})...`);
520
+ else console.log("Installing dependencies 📦...");
521
+ console.log(`> ${installCommand}`);
522
+ execSync(installCommand, {
523
+ stdio: "inherit",
524
+ cwd: projectPath
525
+ });
526
+ console.log("Dependency installed successfully 🎉");
527
+ } catch (error) {
528
+ console.error("❌ Failed to install dependencies");
529
+ throw error;
530
+ }
531
+ }
532
+ const { updateConfigFile, updateStylesFile } = await import("./utils-C6581aex.mjs");
533
+ try {
534
+ console.log("⚙️ Updating powerhouse config file...");
535
+ updateConfigFile(dependenciesWithVersions, projectPath, "install", args.local ? "local" : "registry", registryUrl);
536
+ console.log("Config file updated successfully 🎉");
537
+ } catch (error) {
538
+ console.error("❌ Failed to update config file");
539
+ throw error;
540
+ }
541
+ if (args.local) try {
542
+ console.log("⚙️ Updating styles.css file...");
543
+ updateStylesFile(dependenciesWithVersions, projectPath);
544
+ console.log("Styles file updated successfully 🎉");
545
+ } catch (error) {
546
+ console.error("❌ Failed to update styles file");
547
+ throw error;
548
+ }
549
+ process.exit(0);
550
+ }
551
+ });
552
+ //#endregion
553
+ //#region src/commands/list.ts
554
+ const list = command({
555
+ name: "list",
556
+ description: `
557
+ The list command displays information about installed Powerhouse packages in your project.
558
+ It reads the powerhouse.config.json file and shows the packages that are currently installed.
559
+
560
+ This command:
561
+ 1. Examines your project configuration
562
+ 2. Lists all installed Powerhouse packages
563
+ 3. Provides a clear overview of your project's dependencies
564
+ 4. Helps you manage and track your Powerhouse components
565
+ `,
566
+ aliases: ["l"],
567
+ args: listArgs,
568
+ handler: async (args) => {
569
+ if (args.debug) console.log(args);
570
+ try {
571
+ const { getPowerhouseProjectInfo } = await import("@powerhousedao/shared/clis");
572
+ const projectInfo = await getPowerhouseProjectInfo();
573
+ console.log("\n>>> projectInfo", projectInfo);
574
+ const { getConfig } = await import("@powerhousedao/config/node");
575
+ const phConfig = getConfig(projectInfo.projectPath + "/powerhouse.config.json");
576
+ if (!phConfig.packages || phConfig.packages.length === 0) {
577
+ console.log("No packages found in the project");
578
+ return;
579
+ }
580
+ console.log("Installed Packages:\n");
581
+ phConfig.packages.forEach((pkg) => {
582
+ console.log(pkg.packageName);
583
+ });
584
+ } catch (e) {
585
+ console.log("No packages found in the project");
586
+ }
587
+ process.exit(0);
588
+ }
589
+ });
590
+ //#endregion
591
+ //#region src/commands/login.ts
592
+ const login = command({
593
+ name: "login",
594
+ description: `
595
+ The login command authenticates you with Renown using your Ethereum wallet. This enables
596
+ the CLI to act on behalf of your Ethereum identity for authenticated operations.
597
+
598
+ This command:
599
+ 1. Generates or loads a cryptographic identity (DID) for the CLI
600
+ 2. Opens your browser to the Renown authentication page
601
+ 3. You authorize the CLI's DID to act on behalf of your Ethereum address
602
+ 4. Stores the credentials locally in .ph/.renown.json
603
+ `,
604
+ args: loginArgs,
605
+ handler: async (args) => {
606
+ if (args.debug) console.log(args);
607
+ const { getRenown } = await import("./auth-BNkN6kS9.mjs");
608
+ const renown = await getRenown(args.renownUrl);
609
+ if (args.showDid) {
610
+ console.log(renown.did);
611
+ process.exit(0);
612
+ }
613
+ if (args.status) {
614
+ const { getAuthStatus } = await import("@renown/sdk/node");
615
+ const status = getAuthStatus(renown);
616
+ if (!status.authenticated || !status.address) {
617
+ console.log("Not authenticated with an Ethereum address.");
618
+ console.log("Run \"ph login\" to authenticate.");
619
+ } else {
620
+ console.log("Authenticated");
621
+ console.log(` ETH Address: ${status.address}`);
622
+ console.log(` User DID: ${status.userDid}`);
623
+ console.log(` Chain ID: ${status.chainId}`);
624
+ console.log(` CLI DID: ${status.cliDid}`);
625
+ console.log(` Authenticated at: ${status.authenticatedAt?.toLocaleString()}`);
626
+ console.log(` Renown URL: ${status.baseUrl}`);
627
+ }
628
+ process.exit(0);
629
+ }
630
+ if (args.logout) {
631
+ await handleLogout();
632
+ process.exit(0);
633
+ }
634
+ const { browserLogin } = await import("@renown/sdk/node");
635
+ console.debug("Initializing cryptographic identity...");
636
+ console.log(`CLI DID: ${renown.did}`);
637
+ try {
638
+ const timeoutMs = args.timeout ? args.timeout * 1e3 : void 0;
639
+ const result = await browserLogin(renown, {
640
+ renownUrl: args.renownUrl,
641
+ timeoutMs,
642
+ onLoginUrl: (url, sessionId) => {
643
+ console.log("Opening browser for authentication...");
644
+ console.log(`Session ID: ${sessionId.slice(0, 8)}...`);
645
+ console.log(`Login URL: ${url}`);
646
+ console.log();
647
+ console.log("Waiting for authentication in browser");
648
+ console.log(`(timeout in ${(timeoutMs ?? 3e5) / 1e3} seconds)`);
649
+ console.log();
650
+ console.log("Please connect your wallet and authorize this CLI to act on your behalf.");
651
+ console.log();
652
+ process.stdout.write("Waiting");
653
+ },
654
+ onPollTick: () => process.stdout.write("."),
655
+ onBrowserOpenFailed: (url) => {
656
+ console.error("Failed to open browser automatically.");
657
+ console.log(`Please open this URL manually: ${url}`);
658
+ }
659
+ });
660
+ console.log();
661
+ console.log();
662
+ console.log("Successfully authenticated!");
663
+ console.log(` ETH Address: ${result.user.address}`);
664
+ console.log(` User DID: ${result.user.did}`);
665
+ console.log(` CLI DID: ${result.cliDid}`);
666
+ console.log();
667
+ console.log("The CLI can now act on behalf of your Ethereum identity.");
668
+ } catch (error) {
669
+ console.log();
670
+ throw error;
671
+ }
672
+ process.exit(0);
673
+ }
674
+ });
675
+ async function handleLogout() {
676
+ const { getRenown } = await import("./auth-BNkN6kS9.mjs");
677
+ const renown = await getRenown();
678
+ if (!renown.user) {
679
+ console.log("Not currently authenticated.");
680
+ return;
681
+ }
682
+ try {
683
+ await renown.logout();
684
+ console.log("Successfully logged out.");
685
+ } catch (error) {
686
+ console.error("Failed to clear credentials.");
687
+ console.debug(error);
688
+ }
689
+ }
690
+ //#endregion
691
+ //#region src/commands/logout.ts
692
+ const logout = command({
693
+ name: "logout",
694
+ description: `
695
+ The logout command removes an existing session created with 'ph login'`,
696
+ args: {},
697
+ handler: async () => {
698
+ await handleLogout();
699
+ process.exit(0);
700
+ }
701
+ });
702
+ //#endregion
703
+ //#region src/commands/migrate.ts
704
+ const migrate = command({
705
+ name: "migrate",
706
+ args: migrateArgs,
707
+ description: "Run migrations",
708
+ handler: async (args) => {
709
+ if (args.debug) console.log(args);
710
+ const { startMigrate } = await import("./migrate-CfgiCNQo.mjs");
711
+ await startMigrate(args);
712
+ process.exit(0);
713
+ }
714
+ });
715
+ //#endregion
716
+ //#region src/commands/publish.ts
717
+ function hasTagFlag(args) {
718
+ return args.some((a) => a === "--tag" || a.startsWith("--tag="));
719
+ }
720
+ function isInteractive() {
721
+ return Boolean(process.stdin.isTTY) && !process.env.CI;
722
+ }
723
+ async function readPrereleaseTag(projectPath) {
724
+ try {
725
+ const [{ readPackageSync }, { prerelease }] = await Promise.all([import("read-pkg"), import("semver")]);
726
+ const pkg = readPackageSync({ cwd: projectPath });
727
+ if (!pkg.version) return null;
728
+ const parts = prerelease(pkg.version);
729
+ if (!parts || parts.length === 0) return null;
730
+ const label = String(parts[0]);
731
+ if (!/^[a-z][a-z0-9-]*$/i.test(label)) return null;
732
+ return {
733
+ version: pkg.version,
734
+ tag: label
735
+ };
736
+ } catch {
737
+ return null;
738
+ }
739
+ }
740
+ const publish = command({
741
+ name: "publish",
742
+ description: `
743
+ Publish a package to the Powerhouse registry. This is a thin wrapper around npm publish
744
+ that automatically sets the registry URL.
745
+
746
+ This command:
747
+ 1. Resolves the registry URL (--registry flag > PH_REGISTRY_URL env > powerhouse.config.json > default)
748
+ 2. Checks authentication with the registry via npm whoami
749
+ 3. Forwards all additional arguments to npm publish
750
+ `,
751
+ args: publishArgs,
752
+ handler: async (args) => {
753
+ if (args.debug) console.log(args);
754
+ const { getPowerhouseProjectInfo } = await import("@powerhousedao/shared/clis");
755
+ const { projectPath } = await getPowerhouseProjectInfo();
756
+ if (!projectPath) throw new Error("Could not find project path.");
757
+ const { checkNpmAuth, npmPublish, resolveRegistryUrl } = await import("@powerhousedao/shared/registry");
758
+ const { mintRegistryAuthToken } = await import("./registry-auth-CNH84uo4.mjs");
759
+ const registryUrl = resolveRegistryUrl({
760
+ registry: args.registry,
761
+ projectPath
762
+ });
763
+ if (args.debug) console.log(">>> registryUrl", registryUrl);
764
+ let authToken;
765
+ try {
766
+ authToken = await mintRegistryAuthToken(registryUrl, 300);
767
+ if (args.debug) console.error(`>>> minted renown token for ${registryUrl} (5m TTL)`);
768
+ } catch (err) {
769
+ if (args.debug) console.error(`>>> renown token mint skipped: ${err.message}`);
770
+ try {
771
+ await checkNpmAuth(registryUrl);
772
+ } catch {
773
+ console.error(`Not authenticated with registry: ${registryUrl}`);
774
+ console.error(`Run: ph login (recommended) or npm adduser --registry ${registryUrl}`);
775
+ process.exit(1);
776
+ }
777
+ }
778
+ let forwardedArgs = args.forwardedArgs;
779
+ if (!hasTagFlag(forwardedArgs)) {
780
+ const prereleaseInfo = await readPrereleaseTag(projectPath);
781
+ if (prereleaseInfo) {
782
+ const { version, tag } = prereleaseInfo;
783
+ if (!isInteractive()) {
784
+ console.error(`Detected prerelease version ${version}. npm requires an explicit dist-tag for prerelease publishes.`);
785
+ console.error(`Re-run with --tag <label> (e.g. --tag ${tag}) to proceed.`);
786
+ process.exit(1);
787
+ }
788
+ const enquirer = await import("enquirer");
789
+ let confirmed = false;
790
+ try {
791
+ confirmed = (await enquirer.default.prompt({
792
+ type: "confirm",
793
+ name: "confirmed",
794
+ message: `Detected prerelease version ${version}. Publish with --tag ${tag}?`,
795
+ initial: true
796
+ })).confirmed;
797
+ } catch {
798
+ confirmed = false;
799
+ }
800
+ if (!confirmed) {
801
+ console.error(`Aborted. To publish manually: npm publish --registry ${registryUrl} --tag <label>`);
802
+ process.exit(1);
803
+ }
804
+ forwardedArgs = [
805
+ "--tag",
806
+ tag,
807
+ ...forwardedArgs
808
+ ];
809
+ }
810
+ }
811
+ if (args.debug) console.log(">>> command", `npm publish --registry ${registryUrl} ${forwardedArgs.join(" ")}`);
812
+ console.log(`Publishing to ${registryUrl}...`);
813
+ const result = await npmPublish({
814
+ registryUrl,
815
+ cwd: projectPath,
816
+ args: forwardedArgs,
817
+ authToken
818
+ });
819
+ if (result.stdout) console.log(result.stdout);
820
+ process.exit(0);
821
+ }
822
+ });
823
+ //#endregion
824
+ //#region src/commands/registry-login.ts
825
+ const registryLogin = command({
826
+ name: "registry-login",
827
+ description: `
828
+ Log in to a Powerhouse registry using your Renown identity. Mints a longer-lived
829
+ bearer token (default 30 days) bound to the registry's audience and writes the
830
+ token into ~/.npmrc so raw 'npm publish' / 'npm install' work without further
831
+ setup.
832
+
833
+ Prerequisites:
834
+ Run 'ph login' first to establish a Renown identity.
835
+
836
+ Usage:
837
+ ph registry-login # uses powerhouse.config.json / PH_REGISTRY_URL
838
+ ph registry-login --registry https://registry.dev.vetra.io
839
+ ph registry-login --expiry 7d
840
+ `,
841
+ args: registryLoginArgs,
842
+ handler: async (args) => {
843
+ if (args.debug) console.log(args);
844
+ const { getPowerhouseProjectInfo } = await import("@powerhousedao/shared/clis");
845
+ const projectPath = (await getPowerhouseProjectInfo().catch(() => null))?.projectPath ?? process.cwd();
846
+ const [{ resolveRegistryUrl, writeRegistryAuthToken }, { mintRegistryAuthToken }, { parseExpiry, formatExpiry }] = await Promise.all([
847
+ import("@powerhousedao/shared/registry"),
848
+ import("./registry-auth-CNH84uo4.mjs"),
849
+ import("@renown/sdk/node")
850
+ ]);
851
+ const registryUrl = resolveRegistryUrl({
852
+ registry: args.registry,
853
+ projectPath
854
+ });
855
+ const expiresIn = parseExpiry(args.expiry);
856
+ const npmrcPath = await writeRegistryAuthToken(registryUrl, await mintRegistryAuthToken(registryUrl, expiresIn));
857
+ console.log(`Logged in to ${registryUrl}`);
858
+ console.log(` Token expires in: ${formatExpiry(expiresIn)}`);
859
+ console.log(` Wrote: ${npmrcPath}`);
860
+ process.exit(0);
861
+ }
862
+ });
863
+ //#endregion
864
+ //#region src/commands/switchboard.ts
865
+ const switchboard = command({
866
+ name: "switchboard",
867
+ aliases: ["reactor"],
868
+ description: `
869
+ The switchboard command starts a local Switchboard instance, which acts as the document
870
+ processing engine for Powerhouse projects. It provides the infrastructure for document
871
+ models, processors, and real-time updates.
872
+
873
+ This command:
874
+ 1. Starts a local switchboard server
875
+ 2. Loads document models and processors
876
+ 3. Provides an API for document operations
877
+ 4. Enables real-time document processing
878
+ 5. Can authenticate with remote services using your identity from 'ph login'`,
879
+ args: switchboardArgs,
880
+ handler: async (args) => {
881
+ if (args.debug) console.log(args);
882
+ const { basePath, dbPath, migrate, migrateStatus, reset, yes } = args;
883
+ if (basePath) process.env.BASE_PATH = basePath;
884
+ if (reset) {
885
+ const { resetSwitchboardDatabase } = await import("./switchboard-reset-1YcJEVqc.mjs");
886
+ await resetSwitchboardDatabase({
887
+ dbPath,
888
+ yes
889
+ });
890
+ process.exit(0);
891
+ }
892
+ if (migrate || migrateStatus) {
893
+ const { runSwitchboardMigrations } = await import("./switchboard-migrate-BumRp7rC.mjs");
894
+ await runSwitchboardMigrations({
895
+ dbPath,
896
+ statusOnly: migrateStatus
897
+ });
898
+ process.exit(0);
899
+ }
900
+ const { startSwitchboard } = await import("./switchboard-ChH1PMaE.mjs");
901
+ const { defaultDriveUrl, renown } = await startSwitchboard(args);
902
+ console.log(" ➜ Switchboard:", defaultDriveUrl);
903
+ if (renown) console.log(" ➜ Identity:", renown.did);
904
+ }
905
+ });
906
+ //#endregion
907
+ //#region src/commands/uninstall.ts
908
+ const uninstall = command({
909
+ name: "uninstall",
910
+ aliases: ["remove"],
911
+ description: `
912
+ The uninstall command removes Powerhouse dependencies from your project. It handles the
913
+ removal of packages, updates configuration files, and ensures proper cleanup.
914
+
915
+ This command:
916
+ 1. Uninstalls specified Powerhouse dependencies using your package manager
917
+ 2. Updates powerhouse.config.json to remove the dependencies
918
+ 3. Supports various uninstallation options and configurations
919
+ 4. Works with ${AGENTS.join(", ")} package managers
920
+ `,
921
+ args: uninstallArgs,
922
+ handler: async (args) => {
923
+ if (args.debug) console.log(args);
924
+ const { getPowerhouseProjectInfo, getPowerhouseProjectUninstallCommand, makeDependenciesWithVersions } = await import("@powerhousedao/shared/clis");
925
+ const { projectPath, localProjectPath, globalProjectPath, packageManager, isGlobal } = await getPowerhouseProjectInfo(args);
926
+ if (!projectPath) throw new Error(`Could not find project path to uninstall from`);
927
+ const dependenciesWithVersions = await makeDependenciesWithVersions(args.dependencies);
928
+ if (args.debug) console.log(">>> parsedDependencies", dependenciesWithVersions);
929
+ if (args.debug) console.log("\n>>> projectInfo", {
930
+ localProjectPath,
931
+ globalProjectPath,
932
+ packageManager,
933
+ isGlobal
934
+ });
935
+ try {
936
+ console.log("Uninstalling dependencies 📦 ...");
937
+ execSync$1(await getPowerhouseProjectUninstallCommand(packageManager, args.dependencies), {
938
+ stdio: "inherit",
939
+ cwd: projectPath
940
+ });
941
+ console.log("Dependency uninstalled successfully 🎉");
942
+ } catch (error) {
943
+ console.error("❌ Failed to uninstall dependencies");
944
+ throw error;
945
+ }
946
+ const { removeStylesImports, updateConfigFile } = await import("./utils-C6581aex.mjs");
947
+ try {
948
+ console.log("⚙️ Updating powerhouse config file...");
949
+ updateConfigFile(dependenciesWithVersions, projectPath, "uninstall");
950
+ console.log("Config file updated successfully 🎉");
951
+ } catch (error) {
952
+ console.error("❌ Failed to update config file");
953
+ throw error;
954
+ }
955
+ try {
956
+ console.log("⚙️ Updating styles.css file...");
957
+ removeStylesImports(dependenciesWithVersions, projectPath);
958
+ console.log("Styles file updated successfully 🎉");
959
+ } catch (error) {
960
+ console.error("❌ Failed to update styles file");
961
+ throw error;
962
+ }
963
+ process.exit(0);
964
+ }
965
+ });
966
+ //#endregion
967
+ //#region src/commands/unpublish.ts
968
+ const unpublish = command({
969
+ name: "unpublish",
970
+ description: `
971
+ Unpublish a package from the Powerhouse registry. This is a thin wrapper around
972
+ npm unpublish that automatically targets the Powerhouse registry and never
973
+ reaches npmjs.org.
974
+
975
+ Forms:
976
+ ph unpublish # unpublish <name>@<version> from cwd's package.json
977
+ ph unpublish <name> # unpublish the whole package (all versions)
978
+ ph unpublish <name>@<version> # unpublish a single version
979
+
980
+ Flags:
981
+ --registry <url> # override registry URL
982
+ --yes, -y # skip the confirmation prompt
983
+ `,
984
+ args: unpublishArgs,
985
+ handler: async (args) => {
986
+ if (args.debug) console.log(args);
987
+ const { getPowerhouseProjectInfo } = await import("@powerhousedao/shared/clis");
988
+ const { projectPath } = await getPowerhouseProjectInfo();
989
+ if (!projectPath) throw new Error("Could not find project path.");
990
+ const { checkNpmAuth, npmUnpublish, resolveRegistryUrl } = await import("@powerhousedao/shared/registry");
991
+ const registryUrl = resolveRegistryUrl({
992
+ registry: args.registry,
993
+ projectPath
994
+ });
995
+ const spec = await resolveSpec(args.spec, projectPath);
996
+ if (!spec) {
997
+ console.error("No package spec provided and could not read name/version from package.json.");
998
+ process.exit(1);
999
+ }
1000
+ if (args.debug) {
1001
+ console.log(">>> registryUrl", registryUrl);
1002
+ console.log(">>> spec", spec);
1003
+ }
1004
+ try {
1005
+ await checkNpmAuth(registryUrl);
1006
+ } catch {
1007
+ console.error(`Not authenticated with registry: ${registryUrl}`);
1008
+ console.error(`Run: npm adduser --registry ${registryUrl}`);
1009
+ process.exit(1);
1010
+ }
1011
+ if (!args.yes) {
1012
+ if (!await confirm(`Unpublish ${spec} from ${registryUrl}? [y/N] `)) {
1013
+ console.log("Aborted.");
1014
+ process.exit(0);
1015
+ }
1016
+ }
1017
+ if (args.debug) console.log(">>> command", `npm unpublish ${spec} --registry ${registryUrl} --force ${args.forwardedArgs.join(" ")}`);
1018
+ console.log(`Unpublishing ${spec} from ${registryUrl}...`);
1019
+ try {
1020
+ const result = await npmUnpublish({
1021
+ registryUrl,
1022
+ cwd: projectPath,
1023
+ spec,
1024
+ args: args.forwardedArgs
1025
+ });
1026
+ if (result.stdout) console.log(result.stdout);
1027
+ process.exit(0);
1028
+ } catch (err) {
1029
+ console.error(err instanceof Error ? err.message : String(err));
1030
+ process.exit(1);
1031
+ }
1032
+ }
1033
+ });
1034
+ async function resolveSpec(explicit, projectPath) {
1035
+ if (explicit) return explicit;
1036
+ try {
1037
+ const { readPackageSync } = await import("read-pkg");
1038
+ const pkg = readPackageSync({ cwd: projectPath });
1039
+ if (!pkg.name) return null;
1040
+ return pkg.version ? `${pkg.name}@${pkg.version}` : pkg.name;
1041
+ } catch {
1042
+ return null;
1043
+ }
1044
+ }
1045
+ async function confirm(prompt) {
1046
+ const rl = createInterface({
1047
+ input: process.stdin,
1048
+ output: process.stdout
1049
+ });
1050
+ try {
1051
+ const answer = await rl.question(prompt);
1052
+ return /^y(es)?$/i.test(answer.trim());
1053
+ } finally {
1054
+ rl.close();
1055
+ }
1056
+ }
1057
+ //#endregion
1058
+ //#region src/commands/ph-cli-commands.ts
1059
+ const phCliCommands = {
1060
+ init,
1061
+ generate,
1062
+ vetra: command({
1063
+ name: "vetra",
1064
+ description: `
1065
+ The vetra command sets up a Vetra development environment for working with Vetra projects.
1066
+ It starts a Vetra Switchboard and optionally Connect Studio, enabling document collaboration
1067
+ and real-time processing with a "Vetra" drive or connection to remote drives.
1068
+
1069
+ This command:
1070
+ 1. Starts a Vetra Switchboard with a "Vetra" drive for document storage
1071
+ 2. Optionally connects to remote drives instead of creating a local drive
1072
+ 3. Starts Connect Studio pointing to the Switchboard for user interaction (unless disabled)
1073
+ 4. Enables real-time updates, collaboration, and code generation`,
1074
+ args: vetraArgs,
1075
+ handler: async (args) => {
1076
+ if (args.debug) console.log(args);
1077
+ const { startVetra } = await import("./vetra-yCsUKy_u.mjs");
1078
+ await startVetra(args);
1079
+ }
1080
+ }),
1081
+ connect,
1082
+ build: build$1,
1083
+ publish,
1084
+ unpublish,
1085
+ "access-token": accessToken,
1086
+ "registry-login": registryLogin,
1087
+ inspect,
1088
+ list,
1089
+ migrate,
1090
+ switchboard,
1091
+ login,
1092
+ logout,
1093
+ install,
1094
+ uninstall
1095
+ };
1096
+ const phCli = subcommands({
1097
+ name: "ph-cli",
1098
+ description: PH_CLI_DESCRIPTION,
1099
+ version: getVersion(),
1100
+ cmds: phCliCommands
1101
+ });
1102
+ //#endregion
1103
+ //#region src/utils/db-error-hint.ts
1104
+ const UNRECOVERABLE_DB_PATTERNS = [
1105
+ /Database migration failed:/i,
1106
+ /Migration .* failed/i,
1107
+ /relation "[^"]+" already exists/i,
1108
+ /column "[^"]+" does not exist/i,
1109
+ /schema "reactor" does not exist/i,
1110
+ /Unsupported PGLite data dir/i,
1111
+ /PG_VERSION/i
1112
+ ];
1113
+ function collectMessages(err) {
1114
+ const messages = [];
1115
+ let current = err;
1116
+ const seen = /* @__PURE__ */ new Set();
1117
+ while (current && !seen.has(current)) {
1118
+ seen.add(current);
1119
+ if (current instanceof Error) {
1120
+ messages.push(current.message);
1121
+ current = current.cause;
1122
+ } else {
1123
+ messages.push(String(current));
1124
+ break;
1125
+ }
1126
+ }
1127
+ return messages;
1128
+ }
1129
+ function isUnrecoverableDbError(err) {
1130
+ return collectMessages(err).some((msg) => UNRECOVERABLE_DB_PATTERNS.some((re) => re.test(msg)));
1131
+ }
1132
+ function printDbRecoveryHint(err) {
1133
+ const offending = collectMessages(err).find((msg) => UNRECOVERABLE_DB_PATTERNS.some((re) => re.test(msg)));
1134
+ console.error("");
1135
+ console.error(yellow(bold("Switchboard hit an unrecoverable database error.")));
1136
+ if (offending) console.error(yellow(` ${offending}`));
1137
+ console.error("");
1138
+ console.error(yellow("If this is a local PGlite store, you can reset it with:"));
1139
+ console.error(yellow(" ph switchboard --reset"));
1140
+ console.error(yellow("This is destructive: it wipes the local .ph/reactor-storage and .ph/read-storage directories."));
1141
+ console.error(yellow("For Postgres-backed deployments (PH_REACTOR_DATABASE_URL / DATABASE_URL), reset the database manually instead."));
1142
+ console.error("");
1143
+ }
1144
+ //#endregion
1145
+ //#region src/cli.ts
1146
+ let sentryClient = void 0;
1147
+ const COMMANDS_WITH_SUBCOMMANDS = new Set(["connect", "vetra"]);
1148
+ function detectPackageManager() {
1149
+ const ua = process.env.npm_config_user_agent;
1150
+ if (!ua) return void 0;
1151
+ return ua.split(" ")[0]?.split("/")[0] || void 0;
1152
+ }
1153
+ async function main() {
1154
+ assertNodeVersion();
1155
+ sentryClient = await initCliTelemetry({
1156
+ cliName: "ph-cli",
1157
+ release: getVersion()
1158
+ });
1159
+ const args = process.argv.slice(2);
1160
+ const command = args[0];
1161
+ const subcommand = command && COMMANDS_WITH_SUBCOMMANDS.has(command) && args[1] && !args[1].startsWith("-") ? args[1] : void 0;
1162
+ sentryClient?.attachInvocationContext({
1163
+ command,
1164
+ subcommand,
1165
+ pm: detectPackageManager(),
1166
+ argv: args,
1167
+ cwd: process.cwd()
1168
+ });
1169
+ const hasNoArgs = args.length === 0;
1170
+ const isHelp = args.some((arg) => arg === "--help" || arg === "-h");
1171
+ const isTopLevelHelp = isHelp && args.length === 1;
1172
+ const cli = hasNoArgs || isTopLevelHelp ? phCliHelp : phCli;
1173
+ const restArgs = args.slice(1);
1174
+ if (command === "connect" && ![
1175
+ "studio",
1176
+ "build",
1177
+ "preview"
1178
+ ].includes(args[1]) && !isHelp) await run(cli, [
1179
+ "connect",
1180
+ "studio",
1181
+ ...restArgs
1182
+ ]);
1183
+ else await run(cli, args);
1184
+ }
1185
+ await main().catch(async (error) => {
1186
+ const isDebug = process.argv.slice(2).includes("--debug");
1187
+ await sentryClient?.captureCliError(error);
1188
+ if (isDebug) throw error;
1189
+ if (error instanceof Error) {
1190
+ console.error(error.message);
1191
+ if (isUnrecoverableDbError(error)) printDbRecoveryHint(error);
1192
+ process.exit(1);
1193
+ } else throw error;
1194
+ });
1195
+ //#endregion
1196
+ export {};
1197
+
1198
+ //# sourceMappingURL=cli.mjs.map
1199
+ //# debugId=19f46d7c-6663-5ffa-ac40-1a71c0a3d790