@powerhousedao/ph-cli 6.2.3-dev.55 → 6.2.3-dev.56

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 (66) hide show
  1. package/dist/{cli-connect-override-b4kKqgOZ.mjs → cli-connect-override-DGXyoqdV.mjs} +5 -28
  2. package/dist/cli-connect-override-DGXyoqdV.mjs.map +1 -0
  3. package/dist/cli.mjs +15 -1396
  4. package/dist/cli.mjs.map +1 -1
  5. package/dist/{connect-build-BLxeFrSb.mjs → connect-build-EYGNSUc_.mjs} +5 -5
  6. package/dist/{connect-build-BLxeFrSb.mjs.map → connect-build-EYGNSUc_.mjs.map} +1 -1
  7. package/dist/{connect-config-DGfPEeP8.mjs → connect-config-BDmghUZF.mjs} +4 -4
  8. package/dist/{connect-config-DGfPEeP8.mjs.map → connect-config-BDmghUZF.mjs.map} +1 -1
  9. package/dist/connect-preview-Clue7SVp.mjs +122 -0
  10. package/dist/connect-preview-Clue7SVp.mjs.map +1 -0
  11. package/dist/{connect-studio-f3K1qPWd.mjs → connect-studio-CM4t2tWz.mjs} +3 -3
  12. package/dist/{connect-studio-_-O1-oef.mjs → connect-studio-sc-e0xBI.mjs} +4 -4
  13. package/dist/{connect-studio-_-O1-oef.mjs.map → connect-studio-sc-e0xBI.mjs.map} +1 -1
  14. package/dist/dist-BVyjAjXL.mjs +142 -0
  15. package/dist/dist-BVyjAjXL.mjs.map +1 -0
  16. package/dist/feature-flags-DhEVzlCC.mjs +23 -0
  17. package/dist/feature-flags-DhEVzlCC.mjs.map +1 -0
  18. package/dist/{generate-all-CIwP-3aa.mjs → generate-all-CRfVwLJ9.mjs} +5 -3
  19. package/dist/generate-all-CRfVwLJ9.mjs.map +1 -0
  20. package/dist/{generate-document-model-DhDQ_06X.mjs → generate-document-model-ChkXjM1s.mjs} +5 -3
  21. package/dist/generate-document-model-ChkXjM1s.mjs.map +1 -0
  22. package/dist/{generate-subgraph-Dm27O59o.mjs → generate-subgraph-DmcQWVbd.mjs} +5 -3
  23. package/dist/generate-subgraph-DmcQWVbd.mjs.map +1 -0
  24. package/dist/host-schemas-C_MLcYX6-B2qQIdZ-.mjs +4154 -0
  25. package/dist/host-schemas-C_MLcYX6-B2qQIdZ-.mjs.map +1 -0
  26. package/dist/index-s1ABBFjB.d.mts +3752 -0
  27. package/dist/index-s1ABBFjB.d.mts.map +1 -0
  28. package/dist/{init-CIEMyAug.mjs → init-B6dv9eCs.mjs} +6 -4
  29. package/dist/init-B6dv9eCs.mjs.map +1 -0
  30. package/dist/ph-cli-commands-B95L289j.mjs +1439 -0
  31. package/dist/ph-cli-commands-B95L289j.mjs.map +1 -0
  32. package/dist/ph-cli-commands-C-uB91lq.mjs +4 -0
  33. package/dist/reactor-env-BXG9PlMa.mjs +4 -0
  34. package/dist/reactor-env-CtavpGtJ.mjs +29 -0
  35. package/dist/reactor-env-CtavpGtJ.mjs.map +1 -0
  36. package/dist/run-sugar-Dqn7up5U.mjs +39 -0
  37. package/dist/run-sugar-Dqn7up5U.mjs.map +1 -0
  38. package/dist/runners/compound.d.mts +90 -0
  39. package/dist/runners/compound.d.mts.map +1 -0
  40. package/dist/runners/compound.mjs +71 -0
  41. package/dist/runners/compound.mjs.map +1 -0
  42. package/dist/runners/connect.d.mts +100 -0
  43. package/dist/runners/connect.d.mts.map +1 -0
  44. package/dist/runners/connect.mjs +129 -0
  45. package/dist/runners/connect.mjs.map +1 -0
  46. package/dist/runners/switchboard.d.mts +92 -0
  47. package/dist/runners/switchboard.d.mts.map +1 -0
  48. package/dist/runners/switchboard.mjs +88 -0
  49. package/dist/runners/switchboard.mjs.map +1 -0
  50. package/dist/start-run-CAgkeWI1.mjs +36 -0
  51. package/dist/start-run-CAgkeWI1.mjs.map +1 -0
  52. package/dist/superseded-config-9D7BdLvd.mjs +53 -0
  53. package/dist/superseded-config-9D7BdLvd.mjs.map +1 -0
  54. package/dist/{vetra-B1V1iWGR.mjs → vetra-BY-MHg9R.mjs} +9 -22
  55. package/dist/vetra-BY-MHg9R.mjs.map +1 -0
  56. package/dist/warn-subgraph-type-conflicts-Jd6SeN-M.mjs +19 -0
  57. package/dist/warn-subgraph-type-conflicts-Jd6SeN-M.mjs.map +1 -0
  58. package/package.json +34 -12
  59. package/dist/cli-connect-override-b4kKqgOZ.mjs.map +0 -1
  60. package/dist/connect-preview-CzDqR-JN.mjs +0 -32
  61. package/dist/connect-preview-CzDqR-JN.mjs.map +0 -1
  62. package/dist/generate-all-CIwP-3aa.mjs.map +0 -1
  63. package/dist/generate-document-model-DhDQ_06X.mjs.map +0 -1
  64. package/dist/generate-subgraph-Dm27O59o.mjs.map +0 -1
  65. package/dist/init-CIEMyAug.mjs.map +0 -1
  66. package/dist/vetra-B1V1iWGR.mjs.map +0 -1
@@ -0,0 +1,1439 @@
1
+
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="88358263-9b7b-5311-8b4e-eba17c06b895")}catch(e){}}();
3
+ import { n as skipInstallArgs } from "./install-added-dependencies-DVSbzler.mjs";
4
+ import { t as isUniformRunnersEnabled } from "./feature-flags-DhEVzlCC.mjs";
5
+ import { boolean, command, extendType, flag, multioption, oneOf, option, optional, positional, string, subcommands } from "cmd-ts";
6
+ import { AGENTS, accessTokenArgs, buildArgs, connectBuildArgs, connectConfigArgs, connectPreviewArgs, connectStudioArgs, debugArgs, initArgs, inspectArgs, installArgs, listArgs, loginArgs, migrateArgs, publishArgs, registryLoginArgs, switchboardArgs, uninstallArgs, unpublishArgs, vetraArgs } from "@powerhousedao/shared/clis/args";
7
+ import { DEFAULT_EXPIRY_SECONDS } from "@powerhousedao/shared/clis/constants";
8
+ import fs from "node:fs";
9
+ import path from "node:path";
10
+ import path$1 from "path";
11
+ import { execSync } from "node:child_process";
12
+ import { PROCESSOR_APPS } from "@powerhousedao/shared/processors";
13
+ import { execSync as execSync$1 } from "child_process";
14
+ import { createInterface } from "node:readline/promises";
15
+ //#region src/commands/access-token.ts
16
+ const accessToken = command({
17
+ name: "access-token",
18
+ description: `
19
+ The access-token command generates a bearer token for API authentication. This token
20
+ can be used to authenticate requests to Powerhouse APIs like reactor-api (Switchboard).
21
+
22
+ This command:
23
+ 1. Uses your CLI's cryptographic identity (DID) to sign a verifiable credential
24
+ 2. Creates a JWT bearer token with configurable expiration
25
+ 3. Outputs the token to stdout (info to stderr) for easy piping
26
+
27
+ Prerequisites:
28
+ You must have a cryptographic identity. Run 'ph login' first to:
29
+ - Generate a keypair (stored in .ph/.keypair.json)
30
+ - Optionally link your Ethereum address (stored in .ph/.renown.json)
31
+
32
+ Token Details:
33
+ The generated token is a JWT (JSON Web Token) containing:
34
+ - Issuer (iss): Your CLI's DID (did:key:...)
35
+ - Subject (sub): Your CLI's DID
36
+ - Credential Subject: Chain ID, network ID, and address (if authenticated)
37
+ - Expiration (exp): Based on --expiry option
38
+ - Audience (aud): If --audience is specified
39
+
40
+ Output:
41
+ - Token information (DID, address, expiry) is printed to stderr
42
+ - The token itself is printed to stdout for easy piping/copying
43
+
44
+ This allows you to use the command in scripts:
45
+ TOKEN=$(ph access-token)
46
+ curl -H "Authorization: Bearer $TOKEN" http://localhost:4001/graphql
47
+
48
+ Usage with APIs:
49
+ Generate token and use with curl
50
+ TOKEN=$(ph access-token --expiry 1d)
51
+ curl -X POST http://localhost:4001/graphql \\
52
+ -H "Content-Type: application/json" \\
53
+ -H "Authorization: Bearer $TOKEN" \\
54
+ -d '{"query": "{ drives { id name } }"}'
55
+
56
+ Export as environment variable
57
+ export PH_ACCESS_TOKEN=$(ph access-token)
58
+
59
+ Notes:
60
+ - Tokens are self-signed using your CLI's private key
61
+ - No network request is made; tokens are generated locally
62
+ - The recipient API must trust your CLI's DID to accept the token
63
+ - For reactor-api, ensure AUTH_ENABLED=true to require authentication
64
+ `,
65
+ args: accessTokenArgs,
66
+ handler: async (args) => {
67
+ if (args.debug) console.log(args);
68
+ const { generateAccessToken, parseExpiry, formatExpiry } = await import("@renown/sdk/node");
69
+ const { getRenown } = await import("./auth-CNhbN5UM.mjs");
70
+ const renown = await getRenown();
71
+ let expiresIn = DEFAULT_EXPIRY_SECONDS;
72
+ if (args.expiry) expiresIn = parseExpiry(args.expiry);
73
+ const result = await generateAccessToken(renown, {
74
+ expiresIn,
75
+ aud: args.audience
76
+ });
77
+ console.error(`CLI DID: ${result.did}`);
78
+ console.error(`ETH Address: ${result.address}`);
79
+ console.error(`Token expires in: ${formatExpiry(expiresIn)}`);
80
+ console.error("");
81
+ console.log(result.token);
82
+ process.exit(0);
83
+ }
84
+ });
85
+ //#endregion
86
+ //#region src/commands/build.ts
87
+ const build$1 = command({
88
+ name: "build",
89
+ description: `
90
+ Build a Powerhouse package for publishing: a browser bundle and a node bundle of its
91
+ document models, editors, subgraphs and processors, type declarations, and its stylesheet.
92
+
93
+ Pieces under pieces/ are built too, each into its own self-contained module under
94
+ dist/node/pieces/<name>, with a descriptor.json and package.json written beside it and
95
+ the piece listed in dist/powerhouse.manifest.json. A piece takes the package's version: an
96
+ entry in pieces/index.ts that declares version fails the build. A package that ships only
97
+ pieces is an ordinary package: it carries the same boilerplate, and every step above runs
98
+ for it too.
99
+
100
+ tsc runs first. If it reports type errors the build asks whether to go ahead, and stops
101
+ where it can't ask. --ignore-type-errors builds without asking; a package built that way
102
+ can load and still fail at runtime, so don't publish it.`,
103
+ args: buildArgs,
104
+ handler: async (args) => {
105
+ if (args.debug) console.log(args);
106
+ try {
107
+ const { runBuild } = await import("./build-DmqwT-PR.mjs");
108
+ await runBuild(args);
109
+ } catch (error) {
110
+ console.error(error);
111
+ process.exit(1);
112
+ }
113
+ }
114
+ });
115
+ //#endregion
116
+ //#region src/commands/connect.ts
117
+ const studio = command({
118
+ name: "studio",
119
+ description: `The studio command starts the Connect Studio, a development environment for building
120
+ and testing Powerhouse applications. It provides a visual interface for working with
121
+ your project.
122
+
123
+ This command:
124
+ 1. Starts a local Connect Studio server
125
+ 2. Provides a web interface for development
126
+ 3. Allows you to interact with your project components
127
+ 4. Supports various configuration options for customization
128
+ `,
129
+ args: connectStudioArgs,
130
+ handler: async (args) => {
131
+ if (args.debug) console.log(args);
132
+ const { runConnectStudio } = await import("./connect-studio-CM4t2tWz.mjs");
133
+ await runConnectStudio(args);
134
+ }
135
+ });
136
+ const build = command({
137
+ name: "build",
138
+ description: `The Connect build command creates a production build with the project's local and
139
+ external packages included.
140
+
141
+ Runtime-config overrides (all combinable — last wins on collision):
142
+ ph connect build Build with the current source config.
143
+ ph connect build <key> <value> Build with a positional override applied (e.g. ph connect build connect.renown.url https://renown.staging).
144
+ ph connect build --<field> <value> Build with a per-field flag override (e.g. --renown-url https://renown.staging).
145
+ ph connect build --json '{"app":{"workflowsEnabled":true}}'
146
+ Build with a bulk override. The payload is the connect.* block
147
+ without the "connect" wrapper; unknown keys are rejected.
148
+
149
+ Build has no read mode; passing only <key> without <value> errors out (use \`ph connect config <key>\` to read).
150
+ `,
151
+ args: connectBuildArgs,
152
+ handler: async (args) => {
153
+ if (args.debug) console.log(args);
154
+ const { runConnectBuild } = await import("./connect-build-EYGNSUc_.mjs");
155
+ await runConnectBuild(args);
156
+ process.exit(0);
157
+ }
158
+ });
159
+ const preview = command({
160
+ name: "preview",
161
+ description: `The Connect preview command previews a built Connect project.
162
+ NOTE: You must run \`ph connect build\` first
163
+ `,
164
+ args: connectPreviewArgs,
165
+ handler: async (args) => {
166
+ if (args.debug) console.log(args);
167
+ const { runConnectPreview } = await import("./connect-preview-Clue7SVp.mjs");
168
+ await runConnectPreview(args);
169
+ }
170
+ });
171
+ const config = command({
172
+ name: "config",
173
+ description: `Read or update Connect's runtime configuration (powerhouse.config.json).
174
+
175
+ Modes (mutually exclusive — positional, --get, --json, and field flags cannot be combined):
176
+ ph connect config List the effective connect.* block (defaults < source).
177
+ ph connect config <key> Get the value at the dotted path (e.g. ph connect config connect.renown.url).
178
+ ph connect config --get <dotted.path> Same as positional <key> (kept for backward compat).
179
+ ph connect config <key> <value> Set a single field and dual-write to source + dist (positional).
180
+ ph connect config --<field> <value> Set a single field via per-field flag (e.g. --renown-url https://renown.id).
181
+ ph connect config --json '{"renown":{"url":"…"}}'
182
+ Bulk-set multiple fields and dual-write. The payload is the connect.*
183
+ block without the "connect" wrapper; unknown keys are rejected.
184
+
185
+ Writes go to:
186
+ - <project>/powerhouse.config.json (source — picked up by the next build)
187
+ - <dist-dir>/powerhouse.config.json (if it exists — the currently-served SPA picks it up on refresh)
188
+ `,
189
+ args: connectConfigArgs,
190
+ handler: async (args) => {
191
+ const { runConnectConfig } = await import("./connect-config-BDmghUZF.mjs");
192
+ await runConnectConfig(args);
193
+ }
194
+ });
195
+ const connect = subcommands({
196
+ name: "connect",
197
+ description: `Powerhouse Connect commands. Use with \`studio\`, \`build\`, \`preview\`, or \`config\`. Defaults to \`studio\` if not specified.`,
198
+ cmds: {
199
+ studio,
200
+ build,
201
+ preview,
202
+ config
203
+ }
204
+ });
205
+ //#endregion
206
+ //#region src/commands/generate-all.ts
207
+ const generateAllCmd = command({
208
+ name: "all",
209
+ description: "Re-generate all modules in the current project",
210
+ args: { extract: flag({
211
+ long: "extract",
212
+ short: "x",
213
+ description: "Instead of generating code, write a spec for every module into specs/ (one-shot migration to documents-as-source-of-truth)"
214
+ }) },
215
+ handler: async (args) => {
216
+ const { startGenerateAll } = await import("./generate-all-CRfVwLJ9.mjs");
217
+ await startGenerateAll(args, process.cwd());
218
+ process.exit(0);
219
+ }
220
+ });
221
+ //#endregion
222
+ //#region src/utils/fs-args.ts
223
+ const ExistingPath = extendType(string, {
224
+ displayName: "path",
225
+ description: "An existing path",
226
+ from(str) {
227
+ const resolved = path.resolve(str);
228
+ if (!fs.existsSync(resolved)) return Promise.reject(/* @__PURE__ */ new Error("Path doesn't exist"));
229
+ return Promise.resolve(resolved);
230
+ }
231
+ });
232
+ /** A directory, or the directory of a given file. */
233
+ const Directory = extendType(ExistingPath, {
234
+ displayName: "dir",
235
+ description: "A path to a directory or a file within a directory",
236
+ from(resolved) {
237
+ return Promise.resolve(fs.statSync(resolved).isDirectory() ? resolved : path.dirname(resolved));
238
+ }
239
+ });
240
+ /** An existing file. */
241
+ const File = extendType(ExistingPath, {
242
+ displayName: "file",
243
+ description: "A file in the file system",
244
+ from(resolved) {
245
+ if (!fs.statSync(resolved).isFile()) return Promise.reject(/* @__PURE__ */ new Error("Provided path is not a file"));
246
+ return Promise.resolve(resolved);
247
+ }
248
+ });
249
+ //#endregion
250
+ //#region src/utils/comma-separated.ts
251
+ /** Splits comma-separated values so `-t "a,b"` means the same as `-t a -t b`
252
+ * instead of yielding the single value `"a,b"`, which matches nothing. */
253
+ function splitCommaSeparated(values) {
254
+ return values.flatMap((value) => value.split(",")).map((value) => value.trim()).filter((value) => value.length > 0);
255
+ }
256
+ /** `multioption` type accepting repeated and/or comma-separated values. */
257
+ const CommaSeparatedStrings = { from: (values) => Promise.resolve(splitCommaSeparated(values)) };
258
+ //#endregion
259
+ //#region src/commands/generate-app.ts
260
+ const generateAppCmd = command({
261
+ name: "app",
262
+ description: "Generate a drive app",
263
+ args: {
264
+ name: option({
265
+ type: optional(string),
266
+ long: "name",
267
+ short: "n",
268
+ description: "The name of the drive app to generate"
269
+ }),
270
+ allowedDocumentTypes: multioption({
271
+ type: optional(CommaSeparatedStrings),
272
+ long: "document-types",
273
+ short: "t",
274
+ description: "The document types allowed by the new app (repeatable or comma-separated)"
275
+ }),
276
+ document: option({
277
+ type: optional(File),
278
+ long: "document",
279
+ short: "d",
280
+ description: "Path to a powerhouse/app spec file (.phd or .json) to drive codegen"
281
+ }),
282
+ dir: option({
283
+ type: optional(Directory),
284
+ long: "dir",
285
+ description: "Name of the directory of an existing app to re-generate"
286
+ }),
287
+ disableDragAndDrop: flag({
288
+ type: boolean,
289
+ long: "disable-drag-and-drop",
290
+ description: "Do not allow drag and drop in this drive app.",
291
+ defaultValue: () => false,
292
+ defaultValueIsSerializable: true
293
+ }),
294
+ all: flag({
295
+ long: "all",
296
+ short: "a",
297
+ description: "Re-generate all existing apps in the current project"
298
+ }),
299
+ extract: flag({
300
+ long: "extract",
301
+ short: "x",
302
+ description: "Write a powerhouse/app spec for each existing drive app into specs/apps/"
303
+ }),
304
+ ...debugArgs
305
+ },
306
+ handler: async (args) => {
307
+ const { startGenerateApp } = await import("./generate-app-BTs1u-9l.mjs");
308
+ await startGenerateApp(args, process.cwd());
309
+ process.exit(0);
310
+ }
311
+ });
312
+ //#endregion
313
+ //#region src/commands/generate-document-model.ts
314
+ const generateDocumentModelCmd = command({
315
+ name: "document-model",
316
+ aliases: ["doc"],
317
+ description: "Generate a document model",
318
+ args: {
319
+ document: option({
320
+ type: optional(File),
321
+ long: "document",
322
+ short: "d",
323
+ description: "Path to a document model spec (.phd or .json) to generate from"
324
+ }),
325
+ dir: option({
326
+ type: optional(Directory),
327
+ long: "dir",
328
+ description: "Name of the directory of an existing document model to re-generate"
329
+ }),
330
+ all: flag({
331
+ long: "all",
332
+ short: "a",
333
+ description: "Re-generate all existing document models in the current project"
334
+ }),
335
+ extract: flag({
336
+ long: "extract",
337
+ short: "x",
338
+ description: "Write a powerhouse/document-model spec for each existing document model into specs/document-models/"
339
+ }),
340
+ ...debugArgs
341
+ },
342
+ handler: async (args) => {
343
+ const { startGenerateDocumentModel } = await import("./generate-document-model-ChkXjM1s.mjs");
344
+ await startGenerateDocumentModel(args, process.cwd());
345
+ process.exit(0);
346
+ }
347
+ });
348
+ //#endregion
349
+ //#region src/commands/generate-editor.ts
350
+ const generateEditorCmd = command({
351
+ name: "editor",
352
+ description: "Generate a document editor",
353
+ args: {
354
+ name: option({
355
+ type: optional(string),
356
+ long: "name",
357
+ short: "n",
358
+ description: "The name of the document editor to generate"
359
+ }),
360
+ documentType: option({
361
+ type: optional(string),
362
+ long: "document-type",
363
+ short: "t",
364
+ description: "The document type for the new editor"
365
+ }),
366
+ document: option({
367
+ type: optional(File),
368
+ long: "document",
369
+ short: "d",
370
+ description: "Path to a powerhouse/document-editor spec file (.phd or .json) to drive codegen"
371
+ }),
372
+ dir: option({
373
+ type: optional(Directory),
374
+ long: "dir",
375
+ description: "Name of the directory of an existing editor to re-generate"
376
+ }),
377
+ all: flag({
378
+ long: "all",
379
+ short: "a",
380
+ description: "Re-generate all existing editors in the current project"
381
+ }),
382
+ extract: flag({
383
+ long: "extract",
384
+ short: "x",
385
+ description: "Write a powerhouse/document-editor spec for each existing editor into specs/editors/"
386
+ }),
387
+ ...debugArgs
388
+ },
389
+ handler: async (args) => {
390
+ const { startGenerateEditor } = await import("./generate-editor-CW7Do69u.mjs");
391
+ await startGenerateEditor(args, process.cwd());
392
+ process.exit(0);
393
+ }
394
+ });
395
+ //#endregion
396
+ //#region src/commands/generate-migration-file.ts
397
+ const generateMigrationFileCmd = command({
398
+ name: "migration-file",
399
+ description: "Generate a migration file",
400
+ args: {
401
+ migrationFile: option({
402
+ type: string,
403
+ long: "path",
404
+ short: "p",
405
+ description: "Path to the migration file"
406
+ }),
407
+ schemaFile: option({
408
+ type: optional(string),
409
+ long: "schema-file",
410
+ description: "Path to the output file. Defaults to './schema.ts'"
411
+ }),
412
+ ...debugArgs
413
+ },
414
+ handler: async ({ migrationFile, schemaFile }) => {
415
+ const { generateDBSchema } = await import("@powerhousedao/codegen");
416
+ await generateDBSchema({
417
+ migrationFile: path$1.join(process.cwd(), migrationFile),
418
+ schemaFile: schemaFile ? path$1.join(process.cwd(), schemaFile) : void 0
419
+ });
420
+ process.exit(0);
421
+ }
422
+ });
423
+ //#endregion
424
+ //#region src/commands/generate-piece-action.ts
425
+ const generatePieceActionCmd = command({
426
+ name: "piece-action",
427
+ description: "Generate an action inside an existing piece",
428
+ args: {
429
+ namePositional: positional({
430
+ type: optional(string),
431
+ displayName: "name",
432
+ description: "The name of the action, e.g. get-record"
433
+ }),
434
+ name: option({
435
+ type: optional(string),
436
+ long: "name",
437
+ short: "n",
438
+ description: "The name of the action to generate"
439
+ }),
440
+ piece: option({
441
+ type: optional(string),
442
+ long: "piece",
443
+ short: "p",
444
+ description: "The piece directory under pieces/ to add the action to. Optional when the project ships exactly one piece."
445
+ }),
446
+ requireReactor: option({
447
+ type: optional(oneOf(["read", "write"])),
448
+ long: "require-reactor",
449
+ description: "Declare reactor access for the action: read, or write (which includes read). The action then gets context.reactor"
450
+ }),
451
+ ...skipInstallArgs,
452
+ ...debugArgs
453
+ },
454
+ handler: async (args) => {
455
+ const { startGeneratePieceAction } = await import("./generate-piece-action-DbxrzfKY.mjs");
456
+ await startGeneratePieceAction(args, process.cwd());
457
+ process.exit(0);
458
+ }
459
+ });
460
+ //#endregion
461
+ //#region src/commands/generate-piece-trigger.ts
462
+ const generatePieceTriggerCmd = command({
463
+ name: "piece-trigger",
464
+ description: "Generate a trigger inside an existing piece",
465
+ args: {
466
+ namePositional: positional({
467
+ type: optional(string),
468
+ displayName: "name",
469
+ description: "The name of the trigger, e.g. new-record"
470
+ }),
471
+ name: option({
472
+ type: optional(string),
473
+ long: "name",
474
+ short: "n",
475
+ description: "The name of the trigger to generate"
476
+ }),
477
+ piece: option({
478
+ type: optional(string),
479
+ long: "piece",
480
+ short: "p",
481
+ description: "The piece directory under pieces/ to add the trigger to. Optional when the project ships exactly one piece."
482
+ }),
483
+ strategy: option({
484
+ type: oneOf(["polling", "webhook"]),
485
+ long: "strategy",
486
+ description: "How the trigger fires: polled on a schedule, or delivered to a webhook",
487
+ defaultValue: () => "polling",
488
+ defaultValueIsSerializable: true
489
+ }),
490
+ requireReactor: option({
491
+ type: optional(oneOf(["read", "write"])),
492
+ long: "require-reactor",
493
+ description: "Declare reactor access for the trigger: read, or write (which includes read). Its hooks then get context.reactor"
494
+ }),
495
+ ...skipInstallArgs,
496
+ ...debugArgs
497
+ },
498
+ handler: async (args) => {
499
+ const { startGeneratePieceTrigger } = await import("./generate-piece-trigger-CqVOcL9g.mjs");
500
+ await startGeneratePieceTrigger(args, process.cwd());
501
+ process.exit(0);
502
+ }
503
+ });
504
+ //#endregion
505
+ //#region src/commands/generate-piece.ts
506
+ const generatePieceCmd = command({
507
+ name: "piece",
508
+ description: "Generate a piece: a connector whose actions and triggers a workflow can call",
509
+ args: {
510
+ namePositional: positional({
511
+ type: optional(string),
512
+ displayName: "name",
513
+ description: "The name of the piece to generate. Its directory is the kebab-case of this."
514
+ }),
515
+ name: option({
516
+ type: optional(string),
517
+ long: "name",
518
+ short: "n",
519
+ description: "The name of the piece to generate"
520
+ }),
521
+ id: option({
522
+ type: optional(string),
523
+ long: "id",
524
+ description: "The piece id, the pieceName a workflow step holds, e.g. @acme/piece-crm. Defaults to one derived from the package name."
525
+ }),
526
+ auth: option({
527
+ type: oneOf([
528
+ "none",
529
+ "secret",
530
+ "custom"
531
+ ]),
532
+ long: "auth",
533
+ description: "The kind of connection the piece asks for",
534
+ defaultValue: () => "custom",
535
+ defaultValueIsSerializable: true
536
+ }),
537
+ description: option({
538
+ type: optional(string),
539
+ long: "description",
540
+ description: "One line describing what the piece connects to"
541
+ }),
542
+ dir: option({
543
+ type: optional(Directory),
544
+ long: "dir",
545
+ description: "Name of the directory of an existing piece to re-register"
546
+ }),
547
+ all: flag({
548
+ long: "all",
549
+ short: "a",
550
+ description: "Re-register every piece in pieces/: refresh the pieces list and the manifest, and prune what is gone"
551
+ }),
552
+ ...skipInstallArgs,
553
+ ...debugArgs
554
+ },
555
+ handler: async (args) => {
556
+ const { startGeneratePiece } = await import("./generate-piece-QTt-ddt2.mjs");
557
+ await startGeneratePiece(args, process.cwd());
558
+ process.exit(0);
559
+ }
560
+ });
561
+ const generateProcessorCmd = command({
562
+ name: "processor",
563
+ description: "Generate a processor",
564
+ args: {
565
+ name: option({
566
+ type: optional(string),
567
+ long: "name",
568
+ short: "n",
569
+ description: "The name of the processor to generate"
570
+ }),
571
+ type: option({
572
+ type: oneOf(["analytics", "relationalDb"]),
573
+ long: "type",
574
+ description: "The type of processor to generate",
575
+ defaultValue: () => "analytics",
576
+ defaultValueIsSerializable: true
577
+ }),
578
+ documentTypes: multioption({
579
+ type: CommaSeparatedStrings,
580
+ long: "document-types",
581
+ short: "t",
582
+ description: "The document types the processor will run on (repeatable or comma-separated)",
583
+ defaultValue: () => [],
584
+ defaultValueIsSerializable: true
585
+ }),
586
+ apps: multioption({
587
+ long: "apps",
588
+ type: { from(rawProcessorApps) {
589
+ const processorApps = splitCommaSeparated(rawProcessorApps);
590
+ if (processorApps.length === 0) throw new Error(`No arguments provided for processor apps. Must be "connect" and/or "switchboard"`);
591
+ if (processorApps.length > 2) throw new Error(`Too many arguments provided for processor apps. Must be "connect" and/or "switchboard"`);
592
+ const allowed = new Set(PROCESSOR_APPS);
593
+ if (!processorApps.every((p) => allowed.has(p))) throw new Error(`Processor apps can only be "connect" and/or "switchboard".`);
594
+ return Promise.resolve(processorApps);
595
+ } },
596
+ description: "Whether the processor will run in switchboard (nodejs), connect (browser), or both",
597
+ defaultValue: () => ["switchboard", "connect"],
598
+ defaultValueIsSerializable: true
599
+ }),
600
+ document: option({
601
+ type: optional(File),
602
+ long: "document",
603
+ short: "d",
604
+ description: "Path to a powerhouse/processor spec file (.phd or .json) to drive codegen"
605
+ }),
606
+ dir: option({
607
+ type: optional(Directory),
608
+ long: "dir",
609
+ description: "Name of the directory of an existing processor to re-generate"
610
+ }),
611
+ all: flag({
612
+ long: "all",
613
+ short: "a",
614
+ description: "Re-generate all existing processors in the current project"
615
+ }),
616
+ extract: flag({
617
+ long: "extract",
618
+ short: "x",
619
+ description: "Write a powerhouse/processor spec for each existing processor into specs/processors/"
620
+ }),
621
+ ...skipInstallArgs,
622
+ ...debugArgs
623
+ },
624
+ handler: async (args) => {
625
+ const { startGenerateProcessor } = await import("./generate-processor-DBtTkgo5.mjs");
626
+ await startGenerateProcessor(args, process.cwd());
627
+ process.exit(0);
628
+ }
629
+ });
630
+ //#endregion
631
+ //#region src/commands/generate-subgraph.ts
632
+ const generateSubgraphCmd = command({
633
+ name: "subgraph",
634
+ description: "Generate a subgraph",
635
+ args: {
636
+ name: option({
637
+ type: optional(string),
638
+ long: "name",
639
+ short: "n",
640
+ description: "The name of the subgraph to generate"
641
+ }),
642
+ document: option({
643
+ type: optional(File),
644
+ long: "document",
645
+ short: "d",
646
+ description: "Path to a powerhouse/subgraph spec file (.phd or .json) to drive codegen"
647
+ }),
648
+ dir: option({
649
+ type: optional(Directory),
650
+ long: "dir",
651
+ description: "Name of the directory of an existing subgraph to re-generate"
652
+ }),
653
+ all: flag({
654
+ long: "all",
655
+ short: "a",
656
+ description: "Re-generate all existing subgraphs in the current project"
657
+ }),
658
+ extract: flag({
659
+ long: "extract",
660
+ short: "x",
661
+ description: "Write a powerhouse/subgraph spec for each existing subgraph into specs/subgraphs/"
662
+ }),
663
+ ...skipInstallArgs,
664
+ ...debugArgs
665
+ },
666
+ handler: async (args) => {
667
+ const { startGenerateSubgraph } = await import("./generate-subgraph-DmcQWVbd.mjs");
668
+ await startGenerateSubgraph(args, process.cwd());
669
+ process.exit(0);
670
+ }
671
+ });
672
+ //#endregion
673
+ //#region src/commands/generate.ts
674
+ const generate = subcommands({
675
+ name: "generate",
676
+ 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.`,
677
+ cmds: {
678
+ all: generateAllCmd,
679
+ "document-model": generateDocumentModelCmd,
680
+ editor: generateEditorCmd,
681
+ app: generateAppCmd,
682
+ processor: generateProcessorCmd,
683
+ subgraph: generateSubgraphCmd,
684
+ piece: generatePieceCmd,
685
+ "piece-action": generatePieceActionCmd,
686
+ "piece-trigger": generatePieceTriggerCmd,
687
+ "migration-file": generateMigrationFileCmd
688
+ }
689
+ });
690
+ //#endregion
691
+ //#region src/commands/init.ts
692
+ const init = command({
693
+ name: "init",
694
+ description: "Initialize a new project",
695
+ args: initArgs,
696
+ handler: async (args) => {
697
+ if (args.debug) console.log({ args });
698
+ const { startInit } = await import("./init-B6dv9eCs.mjs");
699
+ await startInit(args);
700
+ process.exit(0);
701
+ }
702
+ });
703
+ //#endregion
704
+ //#region src/commands/inspect.ts
705
+ const inspect = command({
706
+ name: "inspect",
707
+ description: `
708
+ The inspect command examines and provides detailed information about a Powerhouse package.
709
+ It helps you understand the structure, dependencies, and configuration of packages in
710
+ your project.
711
+
712
+ This command:
713
+ 1. Analyzes the specified package
714
+ 2. Retrieves detailed information about its structure and configuration
715
+ 3. Displays package metadata, dependencies, and other relevant information
716
+ 4. Helps troubleshoot package-related issues`,
717
+ aliases: ["is"],
718
+ args: inspectArgs,
719
+ handler: async (args) => {
720
+ if (args.debug) console.log(args);
721
+ const { startInspect } = await import("./inspect-BpCB0TPo.mjs");
722
+ startInspect(args);
723
+ process.exit(0);
724
+ }
725
+ });
726
+ //#endregion
727
+ //#region src/commands/install.ts
728
+ const MANIFEST_TIMEOUT_MS = 1e4;
729
+ async function fetchExternalDependencies(registryUrl, dependency) {
730
+ const base = registryUrl.endsWith("/") ? registryUrl : `${registryUrl}/`;
731
+ const spec = dependency.version ? `${dependency.name}@${dependency.version}` : dependency.name;
732
+ try {
733
+ const response = await fetch(`${base}-/cdn/${spec}/powerhouse.manifest.json`, { signal: AbortSignal.timeout(MANIFEST_TIMEOUT_MS) });
734
+ if (!response.ok) return [];
735
+ const external = (await response.json()).externalDependencies;
736
+ return typeof external === "object" && external !== null ? Object.keys(external).sort() : [];
737
+ } catch {
738
+ return [];
739
+ }
740
+ }
741
+ async function warnAboutExternalDependencies(registryUrl, dependencies) {
742
+ const found = await Promise.all(dependencies.map((dependency) => fetchExternalDependencies(registryUrl, dependency)));
743
+ for (const [i, dependency] of dependencies.entries()) {
744
+ const external = found[i];
745
+ if (external.length === 0) continue;
746
+ console.warn(`⚠ ${dependency.name}: its subgraphs and processors need packages with native addons or WebAssembly modules (${external.join(", ")}) and only run when the package is installed locally: ph install --local ${dependency.name}\n Its pieces work either way.`);
747
+ }
748
+ }
749
+ const install = command({
750
+ name: "install",
751
+ aliases: ["add", "i"],
752
+ description: `
753
+ The install command adds Powerhouse dependencies to your project.
754
+
755
+ By default it only registers the package in powerhouse.config.json with
756
+ provider "registry" — Connect will load it from the registry CDN at runtime.
757
+
758
+ With --local, the package is also installed into node_modules and marked
759
+ as provider "local" — it will be bundled into ph connect build so the
760
+ preview works without the registry being reachable.
761
+
762
+ Resolution order for the registry URL:
763
+ --registry flag > PH_REGISTRY_URL env > powerhouse.config.json > default
764
+ `,
765
+ args: installArgs,
766
+ handler: async (args) => {
767
+ if (args.debug) console.log(args);
768
+ const { getPowerhouseProjectInfo, makeDependenciesWithVersions } = await import("@powerhousedao/shared/clis");
769
+ const { projectPath, localProjectPath, globalProjectPath, packageManager, isGlobal } = await getPowerhouseProjectInfo(args);
770
+ if (!projectPath) throw new Error(`Could not find project path to install from.`);
771
+ const { resolveRegistryUrl } = await import("@powerhousedao/shared/registry");
772
+ const registryUrl = resolveRegistryUrl({
773
+ registry: args.registry,
774
+ projectPath
775
+ });
776
+ if (args.debug) console.log(">>> registryUrl", registryUrl);
777
+ const dependenciesWithVersions = await makeDependenciesWithVersions(args.dependencies, registryUrl);
778
+ if (args.debug) {
779
+ console.log(">>> parsedDependencies", dependenciesWithVersions);
780
+ console.log("\n>>> projectInfo", {
781
+ localProjectPath,
782
+ globalProjectPath,
783
+ packageManager,
784
+ isGlobal
785
+ });
786
+ }
787
+ if (args.local) {
788
+ if (dependenciesWithVersions.length === 0) throw new Error("--local requires at least one package name (e.g. ph install --local @scope/pkg)");
789
+ try {
790
+ const specs = dependenciesWithVersions.map((d) => d.version ? `${d.name}@${d.version}` : d.name);
791
+ const scopes = /* @__PURE__ */ new Set();
792
+ for (const dep of dependenciesWithVersions) if (dep.name.startsWith("@")) {
793
+ const scope = dep.name.split("/")[0];
794
+ scopes.add(scope);
795
+ }
796
+ const scopeRegistryArgs = Array.from(scopes).map((scope) => `--${scope}:registry=${registryUrl}`);
797
+ const minReleaseAgeArgs = packageManager === "pnpm" ? ["--config.minimum-release-age=0"] : [];
798
+ const allowBuildArgs = packageManager === "pnpm" && args.allowBuild.length > 0 ? [`--allow-build=${args.allowBuild.join(",")}`] : [];
799
+ const { resolveCommand } = await import("package-manager-detector");
800
+ const resolved = resolveCommand(packageManager, "add", [
801
+ ...specs,
802
+ ...scopeRegistryArgs,
803
+ ...minReleaseAgeArgs,
804
+ ...allowBuildArgs
805
+ ]);
806
+ if (!resolved) throw new Error(`Failed to resolve install command for package manager "${packageManager}".`);
807
+ const installCommand = `${resolved.command} ${resolved.args.join(" ")}`;
808
+ if (scopeRegistryArgs.length > 0) console.log(`Installing dependencies 📦 (routing ${Array.from(scopes).join(", ")} → ${registryUrl})...`);
809
+ else console.log("Installing dependencies 📦...");
810
+ console.log(`> ${installCommand}`);
811
+ execSync$1(installCommand, {
812
+ stdio: "inherit",
813
+ cwd: projectPath
814
+ });
815
+ console.log("Dependency installed successfully 🎉");
816
+ } catch (error) {
817
+ console.error("❌ Failed to install dependencies");
818
+ throw error;
819
+ }
820
+ }
821
+ const { updateConfigFile, updateStylesFile } = await import("./utils-C3c5YG6v.mjs");
822
+ try {
823
+ console.log("⚙️ Updating powerhouse config file...");
824
+ updateConfigFile(dependenciesWithVersions, projectPath, "install", args.local ? "local" : "registry", registryUrl, args.registry !== void 0);
825
+ console.log("Config file updated successfully 🎉");
826
+ } catch (error) {
827
+ console.error("❌ Failed to update config file");
828
+ throw error;
829
+ }
830
+ if (!args.local) await warnAboutExternalDependencies(registryUrl, dependenciesWithVersions);
831
+ if (args.local) try {
832
+ console.log("⚙️ Updating styles.css file...");
833
+ updateStylesFile(dependenciesWithVersions, projectPath);
834
+ console.log("Styles file updated successfully 🎉");
835
+ } catch (error) {
836
+ console.error("❌ Failed to update styles file");
837
+ throw error;
838
+ }
839
+ process.exit(0);
840
+ }
841
+ });
842
+ //#endregion
843
+ //#region src/commands/list.ts
844
+ const list = command({
845
+ name: "list",
846
+ description: `
847
+ The list command displays information about installed Powerhouse packages in your project.
848
+ It reads the powerhouse.config.json file and shows the packages that are currently installed.
849
+
850
+ This command:
851
+ 1. Examines your project configuration
852
+ 2. Lists all installed Powerhouse packages
853
+ 3. Provides a clear overview of your project's dependencies
854
+ 4. Helps you manage and track your Powerhouse components
855
+ `,
856
+ aliases: ["l"],
857
+ args: listArgs,
858
+ handler: async (args) => {
859
+ if (args.debug) console.log(args);
860
+ try {
861
+ const { getPowerhouseProjectInfo } = await import("@powerhousedao/shared/clis");
862
+ const projectInfo = await getPowerhouseProjectInfo();
863
+ const { getConfig } = await import("@powerhousedao/config/node");
864
+ const phConfig = getConfig(projectInfo.projectPath + "/powerhouse.config.json");
865
+ if (!phConfig.packages || phConfig.packages.length === 0) {
866
+ console.log("No packages found in the project");
867
+ return;
868
+ }
869
+ console.log("Installed Packages:\n");
870
+ phConfig.packages.forEach((pkg) => {
871
+ console.log(pkg.version ? `${pkg.packageName}@${pkg.version}` : pkg.packageName);
872
+ });
873
+ } catch (_e) {
874
+ console.log("No packages found in the project");
875
+ }
876
+ process.exit(0);
877
+ }
878
+ });
879
+ //#endregion
880
+ //#region src/commands/login.ts
881
+ const login = command({
882
+ name: "login",
883
+ description: `
884
+ The login command authenticates you with Renown using your Ethereum wallet. This enables
885
+ the CLI to act on behalf of your Ethereum identity for authenticated operations.
886
+
887
+ This command:
888
+ 1. Generates or loads a cryptographic identity (DID) for the CLI
889
+ 2. Opens your browser to the Renown authentication page
890
+ 3. You authorize the CLI's DID to act on behalf of your Ethereum address
891
+ 4. Stores the credentials locally in .ph/.renown.json
892
+ `,
893
+ args: loginArgs,
894
+ handler: async (args) => {
895
+ if (args.debug) console.log(args);
896
+ const { getRenown } = await import("./auth-CNhbN5UM.mjs");
897
+ const renown = await getRenown(args.renownUrl);
898
+ if (args.showDid) {
899
+ console.log(renown.did);
900
+ process.exit(0);
901
+ }
902
+ if (args.status) {
903
+ const { getAuthStatus } = await import("@renown/sdk/node");
904
+ const status = getAuthStatus(renown);
905
+ if (!status.authenticated || !status.address) {
906
+ console.log("Not authenticated with an Ethereum address.");
907
+ console.log("Run \"ph login\" to authenticate.");
908
+ } else {
909
+ console.log("Authenticated");
910
+ console.log(` ETH Address: ${status.address}`);
911
+ console.log(` User DID: ${status.userDid}`);
912
+ console.log(` Chain ID: ${status.chainId}`);
913
+ console.log(` CLI DID: ${status.cliDid}`);
914
+ console.log(` Authenticated at: ${status.authenticatedAt?.toLocaleString()}`);
915
+ console.log(` Renown URL: ${status.baseUrl}`);
916
+ }
917
+ process.exit(0);
918
+ }
919
+ if (args.logout) {
920
+ await handleLogout();
921
+ process.exit(0);
922
+ }
923
+ const { browserLogin } = await import("@renown/sdk/node");
924
+ console.debug("Initializing cryptographic identity...");
925
+ console.log(`CLI DID: ${renown.did}`);
926
+ try {
927
+ const timeoutMs = args.timeout ? args.timeout * 1e3 : void 0;
928
+ const result = await browserLogin(renown, {
929
+ renownUrl: args.renownUrl,
930
+ timeoutMs,
931
+ onLoginUrl: (url, sessionId) => {
932
+ console.log("Opening browser for authentication...");
933
+ console.log(`Session ID: ${sessionId.slice(0, 8)}...`);
934
+ console.log(`Login URL: ${url}`);
935
+ console.log();
936
+ console.log("Waiting for authentication in browser");
937
+ console.log(`(timeout in ${(timeoutMs ?? 3e5) / 1e3} seconds)`);
938
+ console.log();
939
+ console.log("Please connect your wallet and authorize this CLI to act on your behalf.");
940
+ console.log();
941
+ process.stdout.write("Waiting");
942
+ },
943
+ onPollTick: () => process.stdout.write("."),
944
+ onBrowserOpenFailed: (url) => {
945
+ console.error("Failed to open browser automatically.");
946
+ console.log(`Please open this URL manually: ${url}`);
947
+ }
948
+ });
949
+ console.log();
950
+ console.log();
951
+ console.log("Successfully authenticated!");
952
+ console.log(` ETH Address: ${result.user.address}`);
953
+ console.log(` User DID: ${result.user.did}`);
954
+ console.log(` CLI DID: ${result.cliDid}`);
955
+ console.log();
956
+ console.log("The CLI can now act on behalf of your Ethereum identity.");
957
+ } catch (error) {
958
+ console.log();
959
+ throw error;
960
+ }
961
+ process.exit(0);
962
+ }
963
+ });
964
+ async function handleLogout() {
965
+ const { getRenown } = await import("./auth-CNhbN5UM.mjs");
966
+ const renown = await getRenown();
967
+ if (!renown.user) {
968
+ console.log("Not currently authenticated.");
969
+ return;
970
+ }
971
+ try {
972
+ await renown.logout();
973
+ console.log("Successfully logged out.");
974
+ } catch (error) {
975
+ console.error("Failed to clear credentials.");
976
+ console.debug(error);
977
+ }
978
+ }
979
+ //#endregion
980
+ //#region src/commands/logout.ts
981
+ const logout = command({
982
+ name: "logout",
983
+ description: `
984
+ The logout command removes an existing session created with 'ph login'`,
985
+ args: {},
986
+ handler: async () => {
987
+ await handleLogout();
988
+ process.exit(0);
989
+ }
990
+ });
991
+ //#endregion
992
+ //#region src/commands/migrate.ts
993
+ const migrate = command({
994
+ name: "migrate",
995
+ args: migrateArgs,
996
+ description: "Run migrations",
997
+ handler: async (args) => {
998
+ if (args.debug) console.log(args);
999
+ const { startMigrate } = await import("./migrate-DK4HK7Dn.mjs");
1000
+ await startMigrate(args);
1001
+ process.exit(0);
1002
+ }
1003
+ });
1004
+ //#endregion
1005
+ //#region src/commands/publish.ts
1006
+ function hasTagFlag(args) {
1007
+ return args.some((a) => a === "--tag" || a.startsWith("--tag="));
1008
+ }
1009
+ function isInteractive() {
1010
+ return Boolean(process.stdin.isTTY) && !process.env.CI;
1011
+ }
1012
+ async function readPrereleaseTag(projectPath) {
1013
+ try {
1014
+ const [{ readPackageSync }, { prerelease }] = await Promise.all([import("read-pkg"), import("semver")]);
1015
+ const pkg = readPackageSync({ cwd: projectPath });
1016
+ if (!pkg.version) return null;
1017
+ const parts = prerelease(pkg.version);
1018
+ if (!parts || parts.length === 0) return null;
1019
+ const label = String(parts[0]);
1020
+ if (!/^[a-z][a-z0-9-]*$/i.test(label)) return null;
1021
+ return {
1022
+ version: pkg.version,
1023
+ tag: label
1024
+ };
1025
+ } catch {
1026
+ return null;
1027
+ }
1028
+ }
1029
+ const publish = command({
1030
+ name: "publish",
1031
+ description: `
1032
+ Publish a package to the Powerhouse registry. This is a thin wrapper around npm publish
1033
+ that automatically sets the registry URL.
1034
+
1035
+ This command:
1036
+ 1. Resolves the registry URL (--registry flag > PH_REGISTRY_URL env > powerhouse.config.json > default)
1037
+ 2. Checks authentication with the registry via npm whoami
1038
+ 3. Forwards all additional arguments to npm publish
1039
+ `,
1040
+ args: publishArgs,
1041
+ handler: async (args) => {
1042
+ if (args.debug) console.log(args);
1043
+ const { getPowerhouseProjectInfo } = await import("@powerhousedao/shared/clis");
1044
+ const { projectPath } = await getPowerhouseProjectInfo();
1045
+ if (!projectPath) throw new Error("Could not find project path.");
1046
+ const { checkNpmAuth, npmPublish, resolveRegistryUrl } = await import("@powerhousedao/shared/registry");
1047
+ const { mintRegistryAuthToken } = await import("./registry-auth-Bm5AR-fB.mjs");
1048
+ const registryUrl = resolveRegistryUrl({
1049
+ registry: args.registry,
1050
+ projectPath
1051
+ });
1052
+ if (args.debug) console.log(">>> registryUrl", registryUrl);
1053
+ let authToken;
1054
+ try {
1055
+ authToken = await mintRegistryAuthToken(registryUrl, 300);
1056
+ if (args.debug) console.error(`>>> minted renown token for ${registryUrl} (5m TTL)`);
1057
+ } catch (err) {
1058
+ if (args.debug) console.error(`>>> renown token mint skipped: ${err.message}`);
1059
+ try {
1060
+ await checkNpmAuth(registryUrl);
1061
+ } catch {
1062
+ console.error(`Not authenticated with registry: ${registryUrl}`);
1063
+ console.error(`Run: ph login (recommended) or npm adduser --registry ${registryUrl}`);
1064
+ process.exit(1);
1065
+ }
1066
+ }
1067
+ let forwardedArgs = args.forwardedArgs;
1068
+ if (!hasTagFlag(forwardedArgs)) {
1069
+ const prereleaseInfo = await readPrereleaseTag(projectPath);
1070
+ if (prereleaseInfo) {
1071
+ const { version, tag } = prereleaseInfo;
1072
+ if (!isInteractive()) {
1073
+ console.error(`Detected prerelease version ${version}. npm requires an explicit dist-tag for prerelease publishes.`);
1074
+ console.error(`Re-run with --tag <label> (e.g. --tag ${tag}) to proceed.`);
1075
+ process.exit(1);
1076
+ }
1077
+ const enquirer = await import("enquirer");
1078
+ let confirmed;
1079
+ try {
1080
+ confirmed = (await enquirer.default.prompt({
1081
+ type: "confirm",
1082
+ name: "confirmed",
1083
+ message: `Detected prerelease version ${version}. Publish with --tag ${tag}?`,
1084
+ initial: true
1085
+ })).confirmed;
1086
+ } catch {
1087
+ confirmed = false;
1088
+ }
1089
+ if (!confirmed) {
1090
+ console.error(`Aborted. To publish manually: npm publish --registry ${registryUrl} --tag <label>`);
1091
+ process.exit(1);
1092
+ }
1093
+ forwardedArgs = [
1094
+ "--tag",
1095
+ tag,
1096
+ ...forwardedArgs
1097
+ ];
1098
+ }
1099
+ }
1100
+ if (args.debug) console.log(">>> command", `npm publish --registry ${registryUrl} ${forwardedArgs.join(" ")}`);
1101
+ console.log(`Publishing to ${registryUrl}...`);
1102
+ const result = await npmPublish({
1103
+ registryUrl,
1104
+ cwd: projectPath,
1105
+ args: forwardedArgs,
1106
+ authToken
1107
+ });
1108
+ if (result.stdout) console.log(result.stdout);
1109
+ process.exit(0);
1110
+ }
1111
+ });
1112
+ //#endregion
1113
+ //#region src/commands/registry-login.ts
1114
+ const registryLogin = command({
1115
+ name: "registry-login",
1116
+ description: `
1117
+ Log in to a Powerhouse registry using your Renown identity. Mints a longer-lived
1118
+ bearer token (default 30 days) bound to the registry's audience and writes the
1119
+ token into ~/.npmrc so raw 'npm publish' / 'npm install' work without further
1120
+ setup.
1121
+
1122
+ Prerequisites:
1123
+ Run 'ph login' first to establish a Renown identity.
1124
+
1125
+ Usage:
1126
+ ph registry-login # uses powerhouse.config.json / PH_REGISTRY_URL
1127
+ ph registry-login --registry https://registry.vetra.io
1128
+ ph registry-login --expiry 7d
1129
+ `,
1130
+ args: registryLoginArgs,
1131
+ handler: async (args) => {
1132
+ if (args.debug) console.log(args);
1133
+ const { getPowerhouseProjectInfo } = await import("@powerhousedao/shared/clis");
1134
+ const projectPath = (await getPowerhouseProjectInfo().catch(() => null))?.projectPath ?? process.cwd();
1135
+ const [{ resolveRegistryUrl, writeRegistryAuthToken }, { mintRegistryAuthToken }, { parseExpiry, formatExpiry }] = await Promise.all([
1136
+ import("@powerhousedao/shared/registry"),
1137
+ import("./registry-auth-Bm5AR-fB.mjs"),
1138
+ import("@renown/sdk/node")
1139
+ ]);
1140
+ const registryUrl = resolveRegistryUrl({
1141
+ registry: args.registry,
1142
+ projectPath
1143
+ });
1144
+ const expiresIn = parseExpiry(args.expiry);
1145
+ const npmrcPath = await writeRegistryAuthToken(registryUrl, await mintRegistryAuthToken(registryUrl, expiresIn));
1146
+ console.log(`Logged in to ${registryUrl}`);
1147
+ console.log(` Token expires in: ${formatExpiry(expiresIn)}`);
1148
+ console.log(` Wrote: ${npmrcPath}`);
1149
+ process.exit(0);
1150
+ }
1151
+ });
1152
+ //#endregion
1153
+ //#region src/commands/run.ts
1154
+ const runHost = command({
1155
+ name: "run",
1156
+ description: "Run a host from the project's hosts/ folder: `ph run <host> [verb]`. The host's own host.js names the runner module; the verb defaults to `run`. Part of uniform-runners (FEATURE_UNIFORM_RUNNERS_ENABLED).",
1157
+ args: {
1158
+ host: positional({
1159
+ type: string,
1160
+ displayName: "host",
1161
+ description: "Folder name under hosts/ (e.g. vetra, connect)."
1162
+ }),
1163
+ verb: positional({
1164
+ type: optional(string),
1165
+ displayName: "verb",
1166
+ description: "Runner verb (default: run; e.g. dev, build, serve)."
1167
+ }),
1168
+ debug: flag({
1169
+ type: optional(boolean),
1170
+ long: "debug",
1171
+ description: "Print resolved host/runner/verb before dispatch."
1172
+ })
1173
+ },
1174
+ handler: async (args) => {
1175
+ const { startRun } = await import("./start-run-CAgkeWI1.mjs");
1176
+ await startRun({
1177
+ host: args.host,
1178
+ verb: args.verb,
1179
+ debug: args.debug
1180
+ });
1181
+ }
1182
+ });
1183
+ //#endregion
1184
+ //#region src/commands/switchboard.ts
1185
+ const switchboard = command({
1186
+ name: "switchboard",
1187
+ aliases: ["reactor"],
1188
+ description: `
1189
+ The switchboard command starts a local Switchboard instance, which acts as the document
1190
+ processing engine for Powerhouse projects. It provides the infrastructure for document
1191
+ models, processors, and real-time updates.
1192
+
1193
+ This command:
1194
+ 1. Starts a local switchboard server
1195
+ 2. Loads document models and processors
1196
+ 3. Provides an API for document operations
1197
+ 4. Enables real-time document processing
1198
+ 5. Can authenticate with remote services using your identity from 'ph login'`,
1199
+ args: switchboardArgs,
1200
+ handler: async (args) => {
1201
+ if (args.debug) console.log(args);
1202
+ const { basePath, dbPath, migrate, migrateStatus, reset, yes } = args;
1203
+ if (basePath) process.env.BASE_PATH = basePath;
1204
+ if (reset) {
1205
+ const { resetSwitchboardDatabase } = await import("./switchboard-reset-CX_Lzw3O.mjs");
1206
+ await resetSwitchboardDatabase({
1207
+ dbPath,
1208
+ yes
1209
+ });
1210
+ process.exit(0);
1211
+ }
1212
+ if (migrate || migrateStatus) {
1213
+ const { runSwitchboardMigrations } = await import("./switchboard-migrate-7JQZM7-5.mjs");
1214
+ await runSwitchboardMigrations({
1215
+ dbPath,
1216
+ statusOnly: migrateStatus
1217
+ });
1218
+ process.exit(0);
1219
+ }
1220
+ const { startSwitchboard } = await import("./switchboard-BUMqobK4.mjs");
1221
+ const { defaultDriveUrl, renown } = await startSwitchboard(args);
1222
+ console.log(" ➜ Switchboard:", defaultDriveUrl);
1223
+ if (renown) console.log(" ➜ Identity:", renown.did);
1224
+ }
1225
+ });
1226
+ //#endregion
1227
+ //#region src/commands/uninstall.ts
1228
+ const uninstall = command({
1229
+ name: "uninstall",
1230
+ aliases: ["remove"],
1231
+ description: `
1232
+ The uninstall command removes Powerhouse dependencies from your project. It handles the
1233
+ removal of packages, updates configuration files, and ensures proper cleanup.
1234
+
1235
+ This command:
1236
+ 1. Uninstalls specified Powerhouse dependencies using your package manager
1237
+ 2. Updates powerhouse.config.json to remove the dependencies
1238
+ 3. Supports various uninstallation options and configurations
1239
+ 4. Works with ${AGENTS.join(", ")} package managers
1240
+ `,
1241
+ args: uninstallArgs,
1242
+ handler: async (args) => {
1243
+ if (args.debug) console.log(args);
1244
+ const { getPowerhouseProjectInfo, getPowerhouseProjectUninstallCommand, makeDependenciesWithVersions } = await import("@powerhousedao/shared/clis");
1245
+ const { projectPath, localProjectPath, globalProjectPath, packageManager, isGlobal } = await getPowerhouseProjectInfo(args);
1246
+ if (!projectPath) throw new Error(`Could not find project path to uninstall from`);
1247
+ const dependenciesWithVersions = await makeDependenciesWithVersions(args.dependencies);
1248
+ if (args.debug) console.log(">>> parsedDependencies", dependenciesWithVersions);
1249
+ if (args.debug) console.log("\n>>> projectInfo", {
1250
+ localProjectPath,
1251
+ globalProjectPath,
1252
+ packageManager,
1253
+ isGlobal
1254
+ });
1255
+ try {
1256
+ console.log("Uninstalling dependencies 📦 ...");
1257
+ const uninstallCommand = await getPowerhouseProjectUninstallCommand(packageManager, args.dependencies);
1258
+ execSync(uninstallCommand, {
1259
+ stdio: "inherit",
1260
+ cwd: projectPath
1261
+ });
1262
+ console.log("Dependency uninstalled successfully 🎉");
1263
+ } catch (error) {
1264
+ console.error("❌ Failed to uninstall dependencies");
1265
+ throw error;
1266
+ }
1267
+ const { removeStylesImports, updateConfigFile } = await import("./utils-C3c5YG6v.mjs");
1268
+ try {
1269
+ console.log("⚙️ Updating powerhouse config file...");
1270
+ updateConfigFile(dependenciesWithVersions, projectPath, "uninstall");
1271
+ console.log("Config file updated successfully 🎉");
1272
+ } catch (error) {
1273
+ console.error("❌ Failed to update config file");
1274
+ throw error;
1275
+ }
1276
+ try {
1277
+ console.log("⚙️ Updating styles.css file...");
1278
+ removeStylesImports(dependenciesWithVersions, projectPath);
1279
+ console.log("Styles file updated successfully 🎉");
1280
+ } catch (error) {
1281
+ console.error("❌ Failed to update styles file");
1282
+ throw error;
1283
+ }
1284
+ process.exit(0);
1285
+ }
1286
+ });
1287
+ //#endregion
1288
+ //#region src/commands/unpublish.ts
1289
+ const unpublish = command({
1290
+ name: "unpublish",
1291
+ description: `
1292
+ Unpublish a package from the Powerhouse registry. This is a thin wrapper around
1293
+ npm unpublish that automatically targets the Powerhouse registry and never
1294
+ reaches npmjs.org.
1295
+
1296
+ Forms:
1297
+ ph unpublish # unpublish <name>@<version> from cwd's package.json
1298
+ ph unpublish <name> # unpublish the whole package (all versions)
1299
+ ph unpublish <name>@<version> # unpublish a single version
1300
+
1301
+ Flags:
1302
+ --registry <url> # override registry URL
1303
+ --yes, -y # skip the confirmation prompt
1304
+ `,
1305
+ args: unpublishArgs,
1306
+ handler: async (args) => {
1307
+ if (args.debug) console.log(args);
1308
+ const { getPowerhouseProjectInfo } = await import("@powerhousedao/shared/clis");
1309
+ const { projectPath } = await getPowerhouseProjectInfo();
1310
+ if (!projectPath) throw new Error("Could not find project path.");
1311
+ const { checkNpmAuth, npmUnpublish, resolveRegistryUrl } = await import("@powerhousedao/shared/registry");
1312
+ const registryUrl = resolveRegistryUrl({
1313
+ registry: args.registry,
1314
+ projectPath
1315
+ });
1316
+ const spec = await resolveSpec(args.spec, projectPath);
1317
+ if (!spec) {
1318
+ console.error("No package spec provided and could not read name/version from package.json.");
1319
+ process.exit(1);
1320
+ }
1321
+ if (args.debug) {
1322
+ console.log(">>> registryUrl", registryUrl);
1323
+ console.log(">>> spec", spec);
1324
+ }
1325
+ try {
1326
+ await checkNpmAuth(registryUrl);
1327
+ } catch {
1328
+ console.error(`Not authenticated with registry: ${registryUrl}`);
1329
+ console.error(`Run: npm adduser --registry ${registryUrl}`);
1330
+ process.exit(1);
1331
+ }
1332
+ if (!args.yes) {
1333
+ if (!await confirm(`Unpublish ${spec} from ${registryUrl}? [y/N] `)) {
1334
+ console.log("Aborted.");
1335
+ process.exit(0);
1336
+ }
1337
+ }
1338
+ if (args.debug) console.log(">>> command", `npm unpublish ${spec} --registry ${registryUrl} --force ${args.forwardedArgs.join(" ")}`);
1339
+ console.log(`Unpublishing ${spec} from ${registryUrl}...`);
1340
+ try {
1341
+ const result = await npmUnpublish({
1342
+ registryUrl,
1343
+ cwd: projectPath,
1344
+ spec,
1345
+ args: args.forwardedArgs
1346
+ });
1347
+ if (result.stdout) console.log(result.stdout);
1348
+ process.exit(0);
1349
+ } catch (err) {
1350
+ console.error(err instanceof Error ? err.message : String(err));
1351
+ process.exit(1);
1352
+ }
1353
+ }
1354
+ });
1355
+ async function resolveSpec(explicit, projectPath) {
1356
+ if (explicit) return explicit;
1357
+ try {
1358
+ const { readPackageSync } = await import("read-pkg");
1359
+ const pkg = readPackageSync({ cwd: projectPath });
1360
+ if (!pkg.name) return null;
1361
+ return pkg.version ? `${pkg.name}@${pkg.version}` : pkg.name;
1362
+ } catch {
1363
+ return null;
1364
+ }
1365
+ }
1366
+ async function confirm(prompt) {
1367
+ const rl = createInterface({
1368
+ input: process.stdin,
1369
+ output: process.stdout
1370
+ });
1371
+ try {
1372
+ const answer = await rl.question(prompt);
1373
+ return /^y(es)?$/i.test(answer.trim());
1374
+ } finally {
1375
+ rl.close();
1376
+ }
1377
+ }
1378
+ //#endregion
1379
+ //#region src/commands/ph-cli-commands.ts
1380
+ const baseCommands = {
1381
+ init,
1382
+ generate,
1383
+ vetra: command({
1384
+ name: "vetra",
1385
+ description: `
1386
+ The vetra command sets up a Vetra development environment for working with Vetra projects.
1387
+ It starts a Vetra Switchboard and optionally Connect Studio, enabling document collaboration
1388
+ and real-time processing with a "Vetra" drive or connection to remote drives.
1389
+
1390
+ This command:
1391
+ 1. Starts a Vetra Switchboard with a "Vetra" drive for document storage
1392
+ 2. Optionally connects to remote drives instead of creating a local drive
1393
+ 3. Starts Connect Studio pointing to the Switchboard for user interaction (unless disabled)
1394
+ 4. Enables real-time updates, collaboration, and code generation
1395
+
1396
+ Default drives:
1397
+ Connect's default drives resolve to the Vetra drive (and the preview drive
1398
+ when using --watch), plus any drives configured under
1399
+ connect.drives.defaultDrives in powerhouse.config.json - de-duplicated by
1400
+ URL, so configuring project drives does not cost you the Vetra drive.
1401
+ An explicit --default-drives-url is appended to that list (de-duplicated);
1402
+ it never replaces the Vetra drive.
1403
+ `,
1404
+ args: vetraArgs,
1405
+ handler: async (args) => {
1406
+ if (args.debug) console.log(args);
1407
+ const { startVetra } = await import("./vetra-BY-MHg9R.mjs");
1408
+ await startVetra(args);
1409
+ }
1410
+ }),
1411
+ connect,
1412
+ build: build$1,
1413
+ publish,
1414
+ unpublish,
1415
+ "access-token": accessToken,
1416
+ "registry-login": registryLogin,
1417
+ inspect,
1418
+ list,
1419
+ migrate,
1420
+ switchboard,
1421
+ login,
1422
+ logout,
1423
+ install,
1424
+ uninstall
1425
+ };
1426
+ /** Exported for tests; the flag decides whether `run` is registered at all,
1427
+ * so flag-off keeps the command surface byte-identical to before. */
1428
+ function buildPhCliCommands(uniformRunners) {
1429
+ return uniformRunners ? {
1430
+ ...baseCommands,
1431
+ run: runHost
1432
+ } : baseCommands;
1433
+ }
1434
+ const phCliCommands = buildPhCliCommands(isUniformRunnersEnabled());
1435
+ //#endregion
1436
+ export { phCliCommands as n, buildPhCliCommands as t };
1437
+
1438
+ //# sourceMappingURL=ph-cli-commands-B95L289j.mjs.map
1439
+ //# debugId=88358263-9b7b-5311-8b4e-eba17c06b895