@powerhousedao/ph-cli 6.0.0-dev.17 → 6.0.0-dev.170

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 (175) hide show
  1. package/dist/assign-env-vars-CzHgn5ax.mjs +15 -0
  2. package/dist/assign-env-vars-CzHgn5ax.mjs.map +1 -0
  3. package/dist/auth-BeA5gDPQ.mjs +23 -0
  4. package/dist/auth-BeA5gDPQ.mjs.map +1 -0
  5. package/dist/build-BflSHYLP.mjs +33 -0
  6. package/dist/build-BflSHYLP.mjs.map +1 -0
  7. package/dist/cli.d.mts +1 -0
  8. package/dist/cli.mjs +745 -0
  9. package/dist/cli.mjs.map +1 -0
  10. package/dist/connect-build-CrnmJlav.mjs +21 -0
  11. package/dist/connect-build-CrnmJlav.mjs.map +1 -0
  12. package/dist/connect-preview-4Xe7Lm1V.mjs +27 -0
  13. package/dist/connect-preview-4Xe7Lm1V.mjs.map +1 -0
  14. package/dist/connect-studio-38_NrT_a.mjs +28 -0
  15. package/dist/connect-studio-38_NrT_a.mjs.map +1 -0
  16. package/dist/connect-studio-DuH6WcoA.mjs +3 -0
  17. package/dist/generate-CMQGYRrW.mjs +2 -0
  18. package/dist/generate-Dq80G8n4.mjs +58 -0
  19. package/dist/generate-Dq80G8n4.mjs.map +1 -0
  20. package/dist/init-BsmDWu9-.mjs +124 -0
  21. package/dist/init-BsmDWu9-.mjs.map +1 -0
  22. package/dist/inspect-Dl8KWl3u.mjs +45 -0
  23. package/dist/inspect-Dl8KWl3u.mjs.map +1 -0
  24. package/dist/migrate-CMNF8puQ.mjs +245 -0
  25. package/dist/migrate-CMNF8puQ.mjs.map +1 -0
  26. package/dist/scripts/generate-commands-docs.ts +45 -0
  27. package/dist/switchboard-Bht39Myv.mjs +2 -0
  28. package/dist/switchboard-DBqOSS0c.mjs +72 -0
  29. package/dist/switchboard-DBqOSS0c.mjs.map +1 -0
  30. package/dist/switchboard-migrate-1lOCPmX0.mjs +50 -0
  31. package/dist/switchboard-migrate-1lOCPmX0.mjs.map +1 -0
  32. package/dist/utils-DbFSkp_Q.mjs +161 -0
  33. package/dist/utils-DbFSkp_Q.mjs.map +1 -0
  34. package/dist/vetra-CuBxTrw7.mjs +360 -0
  35. package/dist/vetra-CuBxTrw7.mjs.map +1 -0
  36. package/package.json +38 -33
  37. package/dist/scripts/generate-commands-md.d.ts +0 -2
  38. package/dist/scripts/generate-commands-md.d.ts.map +0 -1
  39. package/dist/scripts/generate-commands-md.js +0 -72
  40. package/dist/scripts/generate-commands-md.js.map +0 -1
  41. package/dist/scripts/generate-commands-md.ts +0 -84
  42. package/dist/scripts/generate-version.d.ts +0 -2
  43. package/dist/scripts/generate-version.d.ts.map +0 -1
  44. package/dist/scripts/generate-version.js +0 -13
  45. package/dist/scripts/generate-version.js.map +0 -1
  46. package/dist/scripts/generate-version.ts +0 -22
  47. package/dist/src/cli.d.ts +0 -3
  48. package/dist/src/cli.d.ts.map +0 -1
  49. package/dist/src/cli.js +0 -42
  50. package/dist/src/cli.js.map +0 -1
  51. package/dist/src/commands/access-token.d.ts +0 -9
  52. package/dist/src/commands/access-token.d.ts.map +0 -1
  53. package/dist/src/commands/access-token.js +0 -110
  54. package/dist/src/commands/access-token.js.map +0 -1
  55. package/dist/src/commands/connect.d.ts +0 -19
  56. package/dist/src/commands/connect.d.ts.map +0 -1
  57. package/dist/src/commands/connect.js +0 -85
  58. package/dist/src/commands/connect.js.map +0 -1
  59. package/dist/src/commands/generate.d.ts +0 -9
  60. package/dist/src/commands/generate.d.ts.map +0 -1
  61. package/dist/src/commands/generate.js +0 -41
  62. package/dist/src/commands/generate.js.map +0 -1
  63. package/dist/src/commands/help.d.ts +0 -3
  64. package/dist/src/commands/help.d.ts.map +0 -1
  65. package/dist/src/commands/help.js +0 -9
  66. package/dist/src/commands/help.js.map +0 -1
  67. package/dist/src/commands/index.d.ts +0 -14
  68. package/dist/src/commands/index.d.ts.map +0 -1
  69. package/dist/src/commands/index.js +0 -14
  70. package/dist/src/commands/index.js.map +0 -1
  71. package/dist/src/commands/inspect.d.ts +0 -6
  72. package/dist/src/commands/inspect.d.ts.map +0 -1
  73. package/dist/src/commands/inspect.js +0 -21
  74. package/dist/src/commands/inspect.js.map +0 -1
  75. package/dist/src/commands/install.d.ts +0 -15
  76. package/dist/src/commands/install.d.ts.map +0 -1
  77. package/dist/src/commands/install.js +0 -127
  78. package/dist/src/commands/install.js.map +0 -1
  79. package/dist/src/commands/list.d.ts +0 -9
  80. package/dist/src/commands/list.d.ts.map +0 -1
  81. package/dist/src/commands/list.js +0 -36
  82. package/dist/src/commands/list.js.map +0 -1
  83. package/dist/src/commands/login.d.ts +0 -12
  84. package/dist/src/commands/login.d.ts.map +0 -1
  85. package/dist/src/commands/login.js +0 -208
  86. package/dist/src/commands/login.js.map +0 -1
  87. package/dist/src/commands/migrate.d.ts +0 -10
  88. package/dist/src/commands/migrate.d.ts.map +0 -1
  89. package/dist/src/commands/migrate.js +0 -12
  90. package/dist/src/commands/migrate.js.map +0 -1
  91. package/dist/src/commands/register-commands.d.ts +0 -5
  92. package/dist/src/commands/register-commands.d.ts.map +0 -1
  93. package/dist/src/commands/register-commands.js +0 -32
  94. package/dist/src/commands/register-commands.js.map +0 -1
  95. package/dist/src/commands/service.d.ts +0 -5
  96. package/dist/src/commands/service.d.ts.map +0 -1
  97. package/dist/src/commands/service.js +0 -67
  98. package/dist/src/commands/service.js.map +0 -1
  99. package/dist/src/commands/switchboard.d.ts +0 -9
  100. package/dist/src/commands/switchboard.d.ts.map +0 -1
  101. package/dist/src/commands/switchboard.js +0 -78
  102. package/dist/src/commands/switchboard.js.map +0 -1
  103. package/dist/src/commands/uninstall.d.ts +0 -15
  104. package/dist/src/commands/uninstall.d.ts.map +0 -1
  105. package/dist/src/commands/uninstall.js +0 -120
  106. package/dist/src/commands/uninstall.js.map +0 -1
  107. package/dist/src/commands/vetra.d.ts +0 -11
  108. package/dist/src/commands/vetra.d.ts.map +0 -1
  109. package/dist/src/commands/vetra.js +0 -35
  110. package/dist/src/commands/vetra.js.map +0 -1
  111. package/dist/src/help.d.ts +0 -65
  112. package/dist/src/help.d.ts.map +0 -1
  113. package/dist/src/help.js +0 -770
  114. package/dist/src/help.js.map +0 -1
  115. package/dist/src/index.d.ts +0 -5
  116. package/dist/src/index.d.ts.map +0 -1
  117. package/dist/src/index.js +0 -5
  118. package/dist/src/index.js.map +0 -1
  119. package/dist/src/services/auth.d.ts +0 -69
  120. package/dist/src/services/auth.d.ts.map +0 -1
  121. package/dist/src/services/auth.js +0 -171
  122. package/dist/src/services/auth.js.map +0 -1
  123. package/dist/src/services/connect.d.ts +0 -2
  124. package/dist/src/services/connect.d.ts.map +0 -1
  125. package/dist/src/services/connect.js +0 -2
  126. package/dist/src/services/connect.js.map +0 -1
  127. package/dist/src/services/generate.d.ts +0 -30
  128. package/dist/src/services/generate.d.ts.map +0 -1
  129. package/dist/src/services/generate.js +0 -106
  130. package/dist/src/services/generate.js.map +0 -1
  131. package/dist/src/services/inspect.d.ts +0 -5
  132. package/dist/src/services/inspect.d.ts.map +0 -1
  133. package/dist/src/services/inspect.js +0 -49
  134. package/dist/src/services/inspect.js.map +0 -1
  135. package/dist/src/services/migrate.d.ts +0 -7
  136. package/dist/src/services/migrate.d.ts.map +0 -1
  137. package/dist/src/services/migrate.js +0 -289
  138. package/dist/src/services/migrate.js.map +0 -1
  139. package/dist/src/services/switchboard-migrate.d.ts +0 -7
  140. package/dist/src/services/switchboard-migrate.d.ts.map +0 -1
  141. package/dist/src/services/switchboard-migrate.js +0 -60
  142. package/dist/src/services/switchboard-migrate.js.map +0 -1
  143. package/dist/src/services/switchboard.d.ts +0 -54
  144. package/dist/src/services/switchboard.d.ts.map +0 -1
  145. package/dist/src/services/switchboard.js +0 -79
  146. package/dist/src/services/switchboard.js.map +0 -1
  147. package/dist/src/services/vetra.d.ts +0 -15
  148. package/dist/src/services/vetra.d.ts.map +0 -1
  149. package/dist/src/services/vetra.js +0 -176
  150. package/dist/src/services/vetra.js.map +0 -1
  151. package/dist/src/types.d.ts +0 -2
  152. package/dist/src/types.d.ts.map +0 -1
  153. package/dist/src/types.js +0 -2
  154. package/dist/src/types.js.map +0 -1
  155. package/dist/src/utils/configure-vetra-github-url.d.ts +0 -12
  156. package/dist/src/utils/configure-vetra-github-url.d.ts.map +0 -1
  157. package/dist/src/utils/configure-vetra-github-url.js +0 -230
  158. package/dist/src/utils/configure-vetra-github-url.js.map +0 -1
  159. package/dist/src/utils.d.ts +0 -116
  160. package/dist/src/utils.d.ts.map +0 -1
  161. package/dist/src/utils.js +0 -261
  162. package/dist/src/utils.js.map +0 -1
  163. package/dist/src/version.d.ts +0 -2
  164. package/dist/src/version.d.ts.map +0 -1
  165. package/dist/src/version.js +0 -3
  166. package/dist/src/version.js.map +0 -1
  167. package/dist/test/utils.test.d.ts +0 -2
  168. package/dist/test/utils.test.d.ts.map +0 -1
  169. package/dist/test/utils.test.js +0 -132
  170. package/dist/test/utils.test.js.map +0 -1
  171. package/dist/tsconfig.tsbuildinfo +0 -1
  172. package/dist/vitest.config.d.ts +0 -3
  173. package/dist/vitest.config.d.ts.map +0 -1
  174. package/dist/vitest.config.js +0 -7
  175. package/dist/vitest.config.js.map +0 -1
package/dist/cli.mjs ADDED
@@ -0,0 +1,745 @@
1
+ #!/usr/bin/env node
2
+ import { t as runBuild } from "./build-BflSHYLP.mjs";
3
+ import { a as updateStylesFile, i as updateConfigFile, r as removeStylesImports } from "./utils-DbFSkp_Q.mjs";
4
+ import { DEFAULT_EXPIRY_SECONDS, SECONDS_IN_DAY, accessTokenArgs, assertNodeVersion, buildArgs, connectBuildArgs, connectPreviewArgs, connectStudioArgs, generateArgs, getConfig, getPowerhouseProjectInfo, getPowerhouseProjectInstallCommand, getPowerhouseProjectUninstallCommand, initArgs, inspectArgs, installArgs, listArgs, loginArgs, makeDependenciesWithVersions, migrateArgs, phCliHelpCommands, publishArgs, switchboardArgs, uninstallArgs, vetraArgs } from "@powerhousedao/shared/clis";
5
+ import { command, run, subcommands } from "cmd-ts";
6
+ import { AGENTS } from "package-manager-detector";
7
+ import { DEFAULT_REGISTRY_URL } from "@powerhousedao/config";
8
+ import { execSync } from "child_process";
9
+ import { join } from "path";
10
+ import { getConfig as getConfig$1 } from "@powerhousedao/config/node";
11
+ //#region src/get-version.ts
12
+ function getVersion() {
13
+ return process.env.WORKSPACE_VERSION || process.env.npm_package_version || "unknown";
14
+ }
15
+ //#endregion
16
+ //#region src/utils/constants.ts
17
+ 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.";
18
+ const phCliHelp = subcommands({
19
+ name: "ph-cli",
20
+ description: PH_CLI_DESCRIPTION,
21
+ version: getVersion(),
22
+ cmds: phCliHelpCommands
23
+ });
24
+ //#endregion
25
+ //#region src/commands/access-token.ts
26
+ const accessToken = command({
27
+ name: "access-token",
28
+ description: `
29
+ The access-token command generates a bearer token for API authentication. This token
30
+ can be used to authenticate requests to Powerhouse APIs like reactor-api (Switchboard).
31
+
32
+ This command:
33
+ 1. Uses your CLI's cryptographic identity (DID) to sign a verifiable credential
34
+ 2. Creates a JWT bearer token with configurable expiration
35
+ 3. Outputs the token to stdout (info to stderr) for easy piping
36
+
37
+ Prerequisites:
38
+ You must have a cryptographic identity. Run 'ph login' first to:
39
+ - Generate a keypair (stored in .ph/.keypair.json)
40
+ - Optionally link your Ethereum address (stored in .ph/.renown.json)
41
+
42
+ Token Details:
43
+ The generated token is a JWT (JSON Web Token) containing:
44
+ - Issuer (iss): Your CLI's DID (did:key:...)
45
+ - Subject (sub): Your CLI's DID
46
+ - Credential Subject: Chain ID, network ID, and address (if authenticated)
47
+ - Expiration (exp): Based on --expiry option
48
+ - Audience (aud): If --audience is specified
49
+
50
+ Output:
51
+ - Token information (DID, address, expiry) is printed to stderr
52
+ - The token itself is printed to stdout for easy piping/copying
53
+
54
+ This allows you to use the command in scripts:
55
+ TOKEN=$(ph access-token)
56
+ curl -H "Authorization: Bearer $TOKEN" http://localhost:4001/graphql
57
+
58
+ Usage with APIs:
59
+ Generate token and use with curl
60
+ TOKEN=$(ph access-token --expiry 1d)
61
+ curl -X POST http://localhost:4001/graphql \\
62
+ -H "Content-Type: application/json" \\
63
+ -H "Authorization: Bearer $TOKEN" \\
64
+ -d '{"query": "{ drives { id name } }"}'
65
+
66
+ Export as environment variable
67
+ export PH_ACCESS_TOKEN=$(ph access-token)
68
+
69
+ Notes:
70
+ - Tokens are self-signed using your CLI's private key
71
+ - No network request is made; tokens are generated locally
72
+ - The recipient API must trust your CLI's DID to accept the token
73
+ - For reactor-api, ensure AUTH_ENABLED=true to require authentication
74
+ `,
75
+ args: accessTokenArgs,
76
+ handler: async (args) => {
77
+ if (args.debug) console.log(args);
78
+ const { getRenown } = await import("./auth-BeA5gDPQ.mjs");
79
+ const renown = await getRenown();
80
+ const did = renown.did;
81
+ const user = renown.user;
82
+ if (!user || !user.credential) throw new Error("Not authenticated. Run 'ph login' first to authenticate with Renown. A Renown credential is required to generate valid bearer tokens.");
83
+ const address = user.address;
84
+ let expiresIn = DEFAULT_EXPIRY_SECONDS;
85
+ if (args.expiry) expiresIn = parseExpiry(args.expiry);
86
+ const token = await renown.getBearerToken({
87
+ expiresIn,
88
+ aud: args.audience
89
+ }, true);
90
+ const expiryDays = Math.floor(expiresIn / SECONDS_IN_DAY);
91
+ const expiryHours = Math.floor(expiresIn % SECONDS_IN_DAY / 3600);
92
+ let expiryStr;
93
+ if (expiryDays > 0) expiryStr = expiryHours > 0 ? `${expiryDays} day${expiryDays > 1 ? "s" : ""} and ${expiryHours} hour${expiryHours > 1 ? "s" : ""}` : `${expiryDays} day${expiryDays > 1 ? "s" : ""}`;
94
+ else if (expiryHours > 0) expiryStr = `${expiryHours} hour${expiryHours > 1 ? "s" : ""}`;
95
+ else expiryStr = `${expiresIn} seconds`;
96
+ console.error(`CLI DID: ${did}`);
97
+ console.error(`ETH Address: ${address}`);
98
+ console.error(`Token expires in: ${expiryStr}`);
99
+ console.error("");
100
+ console.log(token);
101
+ process.exit(0);
102
+ }
103
+ });
104
+ /**
105
+ * Parse expiry string to seconds
106
+ * Supports formats: "7d" (days), "24h" (hours), "3600" (seconds), "3600s" (seconds)
107
+ */
108
+ function parseExpiry(expiry) {
109
+ const trimmed = expiry.trim().toLowerCase();
110
+ if (trimmed.endsWith("d")) {
111
+ const days = parseInt(trimmed.slice(0, -1), 10);
112
+ if (isNaN(days) || days <= 0) throw new Error(`Invalid expiry format: ${expiry}. Days must be a positive number.`);
113
+ return days * SECONDS_IN_DAY;
114
+ }
115
+ if (trimmed.endsWith("h")) {
116
+ const hours = parseInt(trimmed.slice(0, -1), 10);
117
+ if (isNaN(hours) || hours <= 0) throw new Error(`Invalid expiry format: ${expiry}. Hours must be a positive number.`);
118
+ return hours * 60 * 60;
119
+ }
120
+ const numericValue = trimmed.endsWith("s") ? trimmed.slice(0, -1) : trimmed;
121
+ const seconds = parseInt(numericValue, 10);
122
+ if (isNaN(seconds) || seconds <= 0) throw new Error(`Invalid expiry format: ${expiry}. Expected a positive number or format like "7d", "24h", "3600s".`);
123
+ return seconds;
124
+ }
125
+ //#endregion
126
+ //#region src/commands/build.ts
127
+ const build$1 = command({
128
+ name: "build",
129
+ args: buildArgs,
130
+ handler: async (args) => {
131
+ if (args.debug) console.log(args);
132
+ try {
133
+ await runBuild(args);
134
+ } catch (error) {
135
+ console.error(error);
136
+ process.exit(1);
137
+ }
138
+ }
139
+ });
140
+ const connect = subcommands({
141
+ name: "connect",
142
+ description: `Powerhouse Connect commands. Use with \`studio\`, \`build\` or \`preview\`. Defaults to \`studio\` if not specified.`,
143
+ cmds: {
144
+ studio: command({
145
+ name: "studio",
146
+ description: `The studio command starts the Connect Studio, a development environment for building
147
+ and testing Powerhouse applications. It provides a visual interface for working with
148
+ your project.
149
+
150
+ This command:
151
+ 1. Starts a local Connect Studio server
152
+ 2. Provides a web interface for development
153
+ 3. Allows you to interact with your project components
154
+ 4. Supports various configuration options for customization
155
+ `,
156
+ args: connectStudioArgs,
157
+ handler: async (args) => {
158
+ if (args.debug) console.log(args);
159
+ const { runConnectStudio } = await import("./connect-studio-DuH6WcoA.mjs");
160
+ await runConnectStudio(args);
161
+ }
162
+ }),
163
+ build: command({
164
+ name: "build",
165
+ description: `The Connect build command creates a production build with the project's local and
166
+ external packages included
167
+ `,
168
+ args: connectBuildArgs,
169
+ handler: async (args) => {
170
+ if (args.debug) console.log(args);
171
+ const { runConnectBuild } = await import("./connect-build-CrnmJlav.mjs");
172
+ await runConnectBuild(args);
173
+ process.exit(0);
174
+ }
175
+ }),
176
+ preview: command({
177
+ name: "preview",
178
+ description: `The Connect preview command previews a built Connect project.
179
+ NOTE: You must run \`ph connect build\` first
180
+ `,
181
+ args: connectPreviewArgs,
182
+ handler: async (args) => {
183
+ if (args.debug) console.log(args);
184
+ const { runConnectPreview } = await import("./connect-preview-4Xe7Lm1V.mjs");
185
+ await runConnectPreview(args);
186
+ }
187
+ })
188
+ }
189
+ });
190
+ //#endregion
191
+ //#region src/commands/generate.ts
192
+ const generate = command({
193
+ name: "generate",
194
+ description: `
195
+ The generate command creates code from document models. It helps you build editors,
196
+ processors, and other components based on your document model files.
197
+
198
+ This command:
199
+ 1. Reads document model definitions
200
+ 2. Generates code for specified components (editors, processors, etc.)
201
+ 3. Supports customization of output and generation options
202
+ 4. Can watch files for changes and regenerate code automatically
203
+ `,
204
+ args: generateArgs,
205
+ handler: async (args) => {
206
+ if (args.debug) console.log(args);
207
+ const { startGenerate } = await import("./generate-CMQGYRrW.mjs");
208
+ await startGenerate(args);
209
+ process.exit(0);
210
+ }
211
+ });
212
+ //#endregion
213
+ //#region src/commands/init.ts
214
+ const init = command({
215
+ name: "init",
216
+ description: "Initialize a new project",
217
+ args: initArgs,
218
+ handler: async (args) => {
219
+ if (args.debug) console.log({ args });
220
+ const { startInit } = await import("./init-BsmDWu9-.mjs");
221
+ await startInit(args);
222
+ process.exit(0);
223
+ }
224
+ });
225
+ //#endregion
226
+ //#region src/commands/inspect.ts
227
+ const inspect = command({
228
+ name: "inspect",
229
+ description: `
230
+ The inspect command examines and provides detailed information about a Powerhouse package.
231
+ It helps you understand the structure, dependencies, and configuration of packages in
232
+ your project.
233
+
234
+ This command:
235
+ 1. Analyzes the specified package
236
+ 2. Retrieves detailed information about its structure and configuration
237
+ 3. Displays package metadata, dependencies, and other relevant information
238
+ 4. Helps troubleshoot package-related issues`,
239
+ aliases: ["is"],
240
+ args: inspectArgs,
241
+ handler: async (args) => {
242
+ if (args.debug) console.log(args);
243
+ const { startInspect } = await import("./inspect-Dl8KWl3u.mjs");
244
+ startInspect(args);
245
+ process.exit(0);
246
+ }
247
+ });
248
+ //#endregion
249
+ //#region src/commands/install.ts
250
+ const install = command({
251
+ name: "install",
252
+ aliases: ["add", "i"],
253
+ description: `
254
+ The install command adds Powerhouse dependencies to your project. It installs packages
255
+ from the Powerhouse registry by default and updates configuration files.
256
+
257
+ This command:
258
+ 1. Resolves the registry URL (--registry flag > powerhouse.config.json > PH_REGISTRY_URL env > default)
259
+ 2. Installs the package using your package manager with the resolved registry
260
+ 3. Updates powerhouse.config.json to include the new dependencies
261
+ 4. Updates style.css with CSS imports if applicable
262
+ `,
263
+ args: installArgs,
264
+ handler: async (args) => {
265
+ if (args.debug) console.log(args);
266
+ const { projectPath, localProjectPath, globalProjectPath, packageManager, isGlobal } = await getPowerhouseProjectInfo(args);
267
+ if (!projectPath) throw new Error(`Could not find project path to install from.`);
268
+ const config = getConfig(join(projectPath, "powerhouse.config.json"));
269
+ const registryUrl = args.registry ?? config.packageRegistryUrl ?? process.env.PH_REGISTRY_URL ?? DEFAULT_REGISTRY_URL;
270
+ if (args.debug) console.log(">>> registryUrl", registryUrl);
271
+ const dependenciesWithVersions = await makeDependenciesWithVersions(args.dependencies, registryUrl);
272
+ if (args.debug) console.log(">>> parsedDependencies", dependenciesWithVersions);
273
+ if (args.debug) console.log("\n>>> projectInfo", {
274
+ localProjectPath,
275
+ globalProjectPath,
276
+ packageManager,
277
+ isGlobal
278
+ });
279
+ try {
280
+ console.log(`installing dependencies 📦 from ${registryUrl}...`);
281
+ execSync(getPowerhouseProjectInstallCommand(packageManager, ["--registry", registryUrl]), {
282
+ stdio: "inherit",
283
+ cwd: projectPath
284
+ });
285
+ console.log("Dependency installed successfully 🎉");
286
+ } catch (error) {
287
+ console.error("❌ Failed to install dependencies");
288
+ throw error;
289
+ }
290
+ if (args.debug) {
291
+ console.log("\n>>> updateConfigFile arguments:");
292
+ console.log(">>> dependencies", args.dependencies);
293
+ console.log(">>> projectPath", projectPath);
294
+ }
295
+ try {
296
+ console.log("⚙️ Updating powerhouse config file...");
297
+ updateConfigFile(dependenciesWithVersions, projectPath, "install");
298
+ console.log("Config file updated successfully 🎉");
299
+ } catch (error) {
300
+ console.error("❌ Failed to update config file");
301
+ throw error;
302
+ }
303
+ try {
304
+ console.log("⚙️ Updating styles.css file...");
305
+ updateStylesFile(dependenciesWithVersions, projectPath);
306
+ console.log("Styles file updated successfully 🎉");
307
+ } catch (error) {
308
+ console.error("❌ Failed to update styles file");
309
+ throw error;
310
+ }
311
+ process.exit(0);
312
+ }
313
+ });
314
+ //#endregion
315
+ //#region src/commands/list.ts
316
+ const list = command({
317
+ name: "list",
318
+ description: `
319
+ The list command displays information about installed Powerhouse packages in your project.
320
+ It reads the powerhouse.config.json file and shows the packages that are currently installed.
321
+
322
+ This command:
323
+ 1. Examines your project configuration
324
+ 2. Lists all installed Powerhouse packages
325
+ 3. Provides a clear overview of your project's dependencies
326
+ 4. Helps you manage and track your Powerhouse components
327
+ `,
328
+ aliases: ["l"],
329
+ args: listArgs,
330
+ handler: async (args) => {
331
+ if (args.debug) console.log(args);
332
+ try {
333
+ const projectInfo = await getPowerhouseProjectInfo();
334
+ console.log("\n>>> projectInfo", projectInfo);
335
+ const phConfig = getConfig$1(projectInfo.projectPath + "/powerhouse.config.json");
336
+ if (!phConfig.packages || phConfig.packages.length === 0) {
337
+ console.log("No packages found in the project");
338
+ return;
339
+ }
340
+ console.log("Installed Packages:\n");
341
+ phConfig.packages.forEach((pkg) => {
342
+ console.log(pkg.packageName);
343
+ });
344
+ } catch (e) {
345
+ console.log("No packages found in the project");
346
+ }
347
+ process.exit(0);
348
+ }
349
+ });
350
+ //#endregion
351
+ //#region src/commands/login.ts
352
+ const login = command({
353
+ name: "login",
354
+ description: `
355
+ The login command authenticates you with Renown using your Ethereum wallet. This enables
356
+ the CLI to act on behalf of your Ethereum identity for authenticated operations.
357
+
358
+ This command:
359
+ 1. Generates or loads a cryptographic identity (DID) for the CLI
360
+ 2. Opens your browser to the Renown authentication page
361
+ 3. You authorize the CLI's DID to act on behalf of your Ethereum address
362
+ 4. Stores the credentials locally in .ph/.renown.json
363
+ `,
364
+ args: loginArgs,
365
+ handler: async (args) => {
366
+ if (args.debug) console.log(args);
367
+ if (args.showDid) {
368
+ await showDid();
369
+ process.exit(0);
370
+ }
371
+ if (args.status) {
372
+ await showStatus();
373
+ process.exit(0);
374
+ }
375
+ if (args.logout) {
376
+ await handleLogout();
377
+ process.exit(0);
378
+ }
379
+ const renownUrl = args.renownUrl;
380
+ const timeoutMs = args.timeout ? args.timeout * 1e3 : DEFAULT_TIMEOUT_MS;
381
+ console.debug("Initializing cryptographic identity...");
382
+ const { generateSessionId, getRenown } = await import("./auth-BeA5gDPQ.mjs");
383
+ const renown = await getRenown();
384
+ if (renown.user) {
385
+ console.error(`Already authenticated as ${renown.user.address}\nUse "ph logout" to sign out first.`);
386
+ process.exit(1);
387
+ }
388
+ console.log(`CLI DID: ${renown.did}`);
389
+ const sessionId = generateSessionId();
390
+ const loginUrl = new URL(`${renownUrl}/console`);
391
+ loginUrl.searchParams.set("session", sessionId);
392
+ loginUrl.searchParams.set("connect", renown.did);
393
+ loginUrl.searchParams.set("app", renown.did);
394
+ console.log("Opening browser for authentication...");
395
+ console.log(`Session ID: ${sessionId.slice(0, 8)}...`);
396
+ console.log();
397
+ await openBrowser(loginUrl.toString());
398
+ console.log("Waiting for authentication in browser");
399
+ console.log(`(timeout in ${timeoutMs / 1e3} seconds)`);
400
+ console.log();
401
+ console.log("Please connect your wallet and authorize this CLI to act on your behalf.");
402
+ console.log();
403
+ process.stdout.write("Waiting");
404
+ const result = await pollSession(renownUrl, sessionId, timeoutMs);
405
+ console.log();
406
+ if (!result) throw new Error("\nAuthentication timed out. \nPlease try again with: ph login");
407
+ const user = await renown.login(result.did);
408
+ console.log();
409
+ console.log("Successfully authenticated!");
410
+ console.log(` ETH Address: ${user.address}`);
411
+ console.log(` User DID: ${user.did}`);
412
+ console.log(` CLI DID: ${renown.did}`);
413
+ console.log();
414
+ console.log("The CLI can now act on behalf of your Ethereum identity.");
415
+ process.exit(0);
416
+ }
417
+ });
418
+ const DEFAULT_TIMEOUT_MS = 300 * 1e3;
419
+ const POLL_INTERVAL_MS = 2e3;
420
+ /**
421
+ * Open a URL in the default browser
422
+ */
423
+ async function openBrowser(url) {
424
+ const { exec } = await import("node:child_process");
425
+ const { promisify } = await import("node:util");
426
+ const execAsync = promisify(exec);
427
+ const platform = process.platform;
428
+ try {
429
+ if (platform === "darwin") await execAsync(`open "${url}"`);
430
+ else if (platform === "win32") await execAsync(`start "" "${url}"`);
431
+ else await execAsync(`xdg-open "${url}"`);
432
+ } catch (error) {
433
+ console.error("Failed to open browser automatically.");
434
+ console.log(`Please open this URL manually: ${url}`);
435
+ }
436
+ }
437
+ /**
438
+ * Poll the session endpoint until ready or timeout
439
+ */
440
+ async function pollSession(renownUrl, sessionId, timeoutMs) {
441
+ const startTime = Date.now();
442
+ const sessionUrl = `${renownUrl}/api/console/session/${sessionId}`;
443
+ while (Date.now() - startTime < timeoutMs) try {
444
+ const response = await fetch(sessionUrl);
445
+ if (!response.ok) {
446
+ console.error(`Session check failed: ${response.status}`);
447
+ await sleep(POLL_INTERVAL_MS);
448
+ continue;
449
+ }
450
+ const data = await response.json();
451
+ if (data.status === "ready") return data;
452
+ process.stdout.write(".");
453
+ await sleep(POLL_INTERVAL_MS);
454
+ } catch (error) {
455
+ await sleep(POLL_INTERVAL_MS);
456
+ }
457
+ return null;
458
+ }
459
+ function sleep(ms) {
460
+ return new Promise((resolve) => setTimeout(resolve, ms));
461
+ }
462
+ /**
463
+ * Show current authentication status
464
+ */
465
+ async function showStatus() {
466
+ const { getRenown } = await import("./auth-BeA5gDPQ.mjs");
467
+ const renown = await getRenown();
468
+ const user = renown.user;
469
+ if (!user || !user.credential) {
470
+ console.log("Not authenticated with an Ethereum address.");
471
+ console.log("Run \"ph login\" to authenticate.");
472
+ return;
473
+ }
474
+ const issuanceDate = new Date(user.credential.issuanceDate);
475
+ console.log("Authenticated");
476
+ console.log(` ETH Address: ${user.address}`);
477
+ console.log(` User DID: ${user.did}`);
478
+ console.log(` Chain ID: ${user.chainId}`);
479
+ console.log(` CLI DID: ${renown.did}`);
480
+ console.log(` Authenticated at: ${issuanceDate.toLocaleString()}`);
481
+ console.log(` Renown URL: ${renown.baseUrl}`);
482
+ process.exit(0);
483
+ }
484
+ /**
485
+ * Show just the CLI DID
486
+ */
487
+ async function showDid() {
488
+ try {
489
+ const { generateSessionId, getRenown } = await import("./auth-BeA5gDPQ.mjs");
490
+ const renown = await getRenown();
491
+ console.log(renown.did);
492
+ } catch (e) {
493
+ console.error("Failed to get DID:");
494
+ throw e;
495
+ }
496
+ }
497
+ /**
498
+ * Logout and clear credentials
499
+ */
500
+ async function handleLogout() {
501
+ const { getRenown } = await import("./auth-BeA5gDPQ.mjs");
502
+ const renown = await getRenown();
503
+ if (!renown.user) {
504
+ console.log("Not currently authenticated.");
505
+ return;
506
+ }
507
+ try {
508
+ await renown.logout();
509
+ console.log("Successfully logged out.");
510
+ } catch (error) {
511
+ console.error("Failed to clear credentials.");
512
+ console.debug(error);
513
+ }
514
+ }
515
+ //#endregion
516
+ //#region src/commands/logout.ts
517
+ const logout = command({
518
+ name: "logout",
519
+ description: `
520
+ The logout command removes an existing session created with 'ph login'`,
521
+ args: {},
522
+ handler: async () => {
523
+ await handleLogout();
524
+ process.exit(0);
525
+ }
526
+ });
527
+ //#endregion
528
+ //#region src/commands/migrate.ts
529
+ const migrate = command({
530
+ name: "migrate",
531
+ args: migrateArgs,
532
+ description: "Run migrations",
533
+ handler: async (args) => {
534
+ if (args.debug) console.log(args);
535
+ const { startMigrate } = await import("./migrate-CMNF8puQ.mjs");
536
+ await startMigrate(args);
537
+ process.exit(0);
538
+ }
539
+ });
540
+ //#endregion
541
+ //#region src/commands/publish.ts
542
+ const publish = command({
543
+ name: "publish",
544
+ description: `
545
+ Publish a package to the Powerhouse registry. This is a thin wrapper around npm publish
546
+ that automatically sets the registry URL.
547
+
548
+ This command:
549
+ 1. Resolves the registry URL (--registry flag > powerhouse.config.json > PH_REGISTRY_URL env > default)
550
+ 2. Checks authentication with the registry via npm whoami
551
+ 3. Forwards all additional arguments to npm publish
552
+ `,
553
+ args: publishArgs,
554
+ handler: async (args) => {
555
+ if (args.debug) console.log(args);
556
+ const { projectPath } = await getPowerhouseProjectInfo();
557
+ if (!projectPath) throw new Error("Could not find project path.");
558
+ const config = getConfig$1(join(projectPath, "powerhouse.config.json"));
559
+ const registryUrl = args.registry ?? process.env.PH_REGISTRY_URL ?? config.packageRegistryUrl ?? DEFAULT_REGISTRY_URL;
560
+ if (args.debug) console.log(">>> registryUrl", registryUrl);
561
+ try {
562
+ execSync(`npm whoami --registry ${registryUrl}`, { stdio: "pipe" });
563
+ } catch {
564
+ console.error(`Not authenticated with registry: ${registryUrl}`);
565
+ console.error(`Run: npm adduser --registry ${registryUrl}`);
566
+ process.exit(1);
567
+ }
568
+ const cmd = `npm publish --registry ${registryUrl} ${args.forwardedArgs.join(" ")}`.trim();
569
+ if (args.debug) console.log(">>> command", cmd);
570
+ console.log(`Publishing to ${registryUrl}...`);
571
+ execSync(cmd, {
572
+ stdio: "inherit",
573
+ cwd: projectPath
574
+ });
575
+ process.exit(0);
576
+ }
577
+ });
578
+ //#endregion
579
+ //#region src/commands/switchboard.ts
580
+ const switchboard = command({
581
+ name: "switchboard",
582
+ aliases: ["reactor"],
583
+ description: `
584
+ The switchboard command starts a local Switchboard instance, which acts as the document
585
+ processing engine for Powerhouse projects. It provides the infrastructure for document
586
+ models, processors, and real-time updates.
587
+
588
+ This command:
589
+ 1. Starts a local switchboard server
590
+ 2. Loads document models and processors
591
+ 3. Provides an API for document operations
592
+ 4. Enables real-time document processing
593
+ 5. Can authenticate with remote services using your identity from 'ph login'`,
594
+ args: switchboardArgs,
595
+ handler: async (args) => {
596
+ if (args.debug) console.log(args);
597
+ const { basePath, dbPath, migrate, migrateStatus } = args;
598
+ if (basePath) process.env.BASE_PATH = basePath;
599
+ if (migrate || migrateStatus) {
600
+ const { runSwitchboardMigrations } = await import("./switchboard-migrate-1lOCPmX0.mjs");
601
+ await runSwitchboardMigrations({
602
+ dbPath,
603
+ statusOnly: migrateStatus
604
+ });
605
+ process.exit(0);
606
+ }
607
+ const { startSwitchboard } = await import("./switchboard-Bht39Myv.mjs");
608
+ const { defaultDriveUrl, renown } = await startSwitchboard(args);
609
+ console.log(" ➜ Switchboard:", defaultDriveUrl);
610
+ if (renown) console.log(" ➜ Identity:", renown.did);
611
+ }
612
+ });
613
+ //#endregion
614
+ //#region src/commands/uninstall.ts
615
+ const uninstall = command({
616
+ name: "uninstall",
617
+ aliases: ["remove"],
618
+ description: `
619
+ The uninstall command removes Powerhouse dependencies from your project. It handles the
620
+ removal of packages, updates configuration files, and ensures proper cleanup.
621
+
622
+ This command:
623
+ 1. Uninstalls specified Powerhouse dependencies using your package manager
624
+ 2. Updates powerhouse.config.json to remove the dependencies
625
+ 3. Supports various uninstallation options and configurations
626
+ 4. Works with ${AGENTS.join(", ")} package managers
627
+ `,
628
+ args: uninstallArgs,
629
+ handler: async (args) => {
630
+ if (args.debug) console.log(args);
631
+ const { projectPath, localProjectPath, globalProjectPath, packageManager, isGlobal } = await getPowerhouseProjectInfo(args);
632
+ if (!projectPath) throw new Error(`Could not find project path to uninstall from`);
633
+ const dependenciesWithVersions = await makeDependenciesWithVersions(args.dependencies);
634
+ if (args.debug) console.log(">>> parsedDependencies", dependenciesWithVersions);
635
+ if (args.debug) console.log("\n>>> projectInfo", {
636
+ localProjectPath,
637
+ globalProjectPath,
638
+ packageManager,
639
+ isGlobal
640
+ });
641
+ try {
642
+ console.log("Uninstalling dependencies 📦 ...");
643
+ execSync(await getPowerhouseProjectUninstallCommand(packageManager), {
644
+ stdio: "inherit",
645
+ cwd: projectPath
646
+ });
647
+ console.log("Dependency uninstalled successfully 🎉");
648
+ } catch (error) {
649
+ console.error("❌ Failed to uninstall dependencies");
650
+ throw error;
651
+ }
652
+ try {
653
+ console.log("⚙️ Updating powerhouse config file...");
654
+ updateConfigFile(dependenciesWithVersions, projectPath, "uninstall");
655
+ console.log("Config file updated successfully 🎉");
656
+ } catch (error) {
657
+ console.error("❌ Failed to update config file");
658
+ throw error;
659
+ }
660
+ try {
661
+ console.log("⚙️ Updating styles.css file...");
662
+ removeStylesImports(dependenciesWithVersions, projectPath);
663
+ console.log("Styles file updated successfully 🎉");
664
+ } catch (error) {
665
+ console.error("❌ Failed to update styles file");
666
+ throw error;
667
+ }
668
+ process.exit(0);
669
+ }
670
+ });
671
+ //#endregion
672
+ //#region src/commands/ph-cli-commands.ts
673
+ const phCliCommands = {
674
+ init,
675
+ generate,
676
+ vetra: command({
677
+ name: "vetra",
678
+ description: `
679
+ The vetra command sets up a Vetra development environment for working with Vetra projects.
680
+ It starts a Vetra Switchboard and optionally Connect Studio, enabling document collaboration
681
+ and real-time processing with a "Vetra" drive or connection to remote drives.
682
+
683
+ This command:
684
+ 1. Starts a Vetra Switchboard with a "Vetra" drive for document storage
685
+ 2. Optionally connects to remote drives instead of creating a local drive
686
+ 3. Starts Connect Studio pointing to the Switchboard for user interaction (unless disabled)
687
+ 4. Enables real-time updates, collaboration, and code generation`,
688
+ args: vetraArgs,
689
+ handler: async (args) => {
690
+ if (args.debug) console.log(args);
691
+ const { startVetra } = await import("./vetra-CuBxTrw7.mjs");
692
+ await startVetra(args);
693
+ }
694
+ }),
695
+ connect,
696
+ build: build$1,
697
+ publish,
698
+ "access-token": accessToken,
699
+ inspect,
700
+ list,
701
+ migrate,
702
+ switchboard,
703
+ login,
704
+ logout,
705
+ install,
706
+ uninstall
707
+ };
708
+ const phCli = subcommands({
709
+ name: "ph-cli",
710
+ description: PH_CLI_DESCRIPTION,
711
+ version: getVersion(),
712
+ cmds: phCliCommands
713
+ });
714
+ //#endregion
715
+ //#region src/cli.ts
716
+ async function main() {
717
+ assertNodeVersion();
718
+ const args = process.argv.slice(2);
719
+ const hasNoArgs = args.length === 0;
720
+ const isHelp = args.some((arg) => arg === "--help" || arg === "-h");
721
+ const isTopLevelHelp = isHelp && args.length === 1;
722
+ const cli = hasNoArgs || isTopLevelHelp ? phCliHelp : phCli;
723
+ const [command, ...restArgs] = args;
724
+ if (command === "connect" && ![
725
+ "studio",
726
+ "build",
727
+ "preview"
728
+ ].includes(args[1]) && !isHelp) await run(cli, [
729
+ "connect",
730
+ "studio",
731
+ ...restArgs
732
+ ]);
733
+ else await run(cli, args);
734
+ }
735
+ await main().catch((error) => {
736
+ if (process.argv.slice(2).includes("--debug")) throw error;
737
+ if (error instanceof Error) {
738
+ console.error(error.message);
739
+ process.exit(1);
740
+ } else throw error;
741
+ });
742
+ //#endregion
743
+ export {};
744
+
745
+ //# sourceMappingURL=cli.mjs.map