@powerhousedao/ph-cli 6.2.3-dev.10 → 6.2.3-dev.100

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 (180) hide show
  1. package/README.md +21 -0
  2. package/dist/{auth-AR3VxAIk.mjs → auth-BFUq7CvE.mjs} +3 -3
  3. package/dist/{auth-AR3VxAIk.mjs.map → auth-BFUq7CvE.mjs.map} +1 -1
  4. package/dist/auth-CNhbN5UM.mjs +4 -0
  5. package/dist/authoring-mode-DWbbsuWh.mjs +23 -0
  6. package/dist/authoring-mode-DWbbsuWh.mjs.map +1 -0
  7. package/dist/build-C1mmZvlb.mjs +3011 -0
  8. package/dist/build-C1mmZvlb.mjs.map +1 -0
  9. package/dist/build-Ws5hhqol.mjs +4 -0
  10. package/dist/check-Cco7-UC2.mjs +65 -0
  11. package/dist/check-Cco7-UC2.mjs.map +1 -0
  12. package/dist/check-CjFMilhk.mjs +4 -0
  13. package/dist/check-DvG9Xy4c.mjs +60 -0
  14. package/dist/check-DvG9Xy4c.mjs.map +1 -0
  15. package/dist/{cli-connect-override-D3hh4aH_.mjs → cli-connect-override-D3N3gbp_.mjs} +39 -27
  16. package/dist/cli-connect-override-D3N3gbp_.mjs.map +1 -0
  17. package/dist/cli.d.mts +2 -1
  18. package/dist/cli.mjs +54 -1178
  19. package/dist/cli.mjs.map +1 -1
  20. package/dist/compound-DO_mvh0O-Dp1YPhR0.mjs +2806 -0
  21. package/dist/compound-DO_mvh0O-Dp1YPhR0.mjs.map +1 -0
  22. package/dist/connect-build-COdexcA8.mjs +322 -0
  23. package/dist/connect-build-COdexcA8.mjs.map +1 -0
  24. package/dist/{connect-config-BWGiW3IB.mjs → connect-config-C6hKMsUG.mjs} +19 -12
  25. package/dist/connect-config-C6hKMsUG.mjs.map +1 -0
  26. package/dist/connect-preview-CdFvlANO.mjs +49 -0
  27. package/dist/connect-preview-CdFvlANO.mjs.map +1 -0
  28. package/dist/connect-studio-C7Bbh50O.mjs +81 -0
  29. package/dist/connect-studio-C7Bbh50O.mjs.map +1 -0
  30. package/dist/connect-studio-xQNYl142.mjs +4 -0
  31. package/dist/definitions-worker.d.mts +98 -0
  32. package/dist/definitions-worker.d.mts.map +1 -0
  33. package/dist/definitions-worker.mjs +28 -0
  34. package/dist/definitions-worker.mjs.map +1 -0
  35. package/dist/dist-B-_lMGlB.mjs +480 -0
  36. package/dist/dist-B-_lMGlB.mjs.map +1 -0
  37. package/dist/evidence-Dchpoogs.mjs +120 -0
  38. package/dist/evidence-Dchpoogs.mjs.map +1 -0
  39. package/dist/explain-lynfOtDg.mjs +230 -0
  40. package/dist/explain-lynfOtDg.mjs.map +1 -0
  41. package/dist/export-YkeGUZjR.mjs +42 -0
  42. package/dist/export-YkeGUZjR.mjs.map +1 -0
  43. package/dist/external-M25AgDIE.d.mts +4277 -0
  44. package/dist/external-M25AgDIE.d.mts.map +1 -0
  45. package/dist/feature-flags-xwqcHEWC.mjs +4 -0
  46. package/dist/files-D6_euBBn.mjs +457 -0
  47. package/dist/files-D6_euBBn.mjs.map +1 -0
  48. package/dist/generate-all-_7S0Iii2.mjs +36 -0
  49. package/dist/generate-all-_7S0Iii2.mjs.map +1 -0
  50. package/dist/generate-app-hm6CJ_4O.mjs +72 -0
  51. package/dist/generate-app-hm6CJ_4O.mjs.map +1 -0
  52. package/dist/generate-desktop-shell-CEcE_1gb.mjs +323 -0
  53. package/dist/generate-desktop-shell-CEcE_1gb.mjs.map +1 -0
  54. package/dist/generate-document-model-DCjzz3Sa.mjs +114 -0
  55. package/dist/generate-document-model-DCjzz3Sa.mjs.map +1 -0
  56. package/dist/generate-editor-DdoapkEK.mjs +64 -0
  57. package/dist/generate-editor-DdoapkEK.mjs.map +1 -0
  58. package/dist/generate-hosts-BFmPIW2X.mjs +18 -0
  59. package/dist/generate-hosts-BFmPIW2X.mjs.map +1 -0
  60. package/dist/generate-hosts-RWj7WPHZ.mjs +4 -0
  61. package/dist/generate-migration-file-yK8uA70U.mjs +20 -0
  62. package/dist/generate-migration-file-yK8uA70U.mjs.map +1 -0
  63. package/dist/generate-piece-5Nyr2UZj.mjs +73 -0
  64. package/dist/generate-piece-5Nyr2UZj.mjs.map +1 -0
  65. package/dist/generate-piece-action-DqR8BcoO.mjs +31 -0
  66. package/dist/generate-piece-action-DqR8BcoO.mjs.map +1 -0
  67. package/dist/generate-piece-trigger-CZaDD-cc.mjs +30 -0
  68. package/dist/generate-piece-trigger-CZaDD-cc.mjs.map +1 -0
  69. package/dist/generate-processor-BVjOsfjJ.mjs +58 -0
  70. package/dist/generate-processor-BVjOsfjJ.mjs.map +1 -0
  71. package/dist/generate-subgraph-CrHbYK91.mjs +64 -0
  72. package/dist/generate-subgraph-CrHbYK91.mjs.map +1 -0
  73. package/dist/get-version-BBiGShxz.mjs +11 -0
  74. package/dist/get-version-BBiGShxz.mjs.map +1 -0
  75. package/dist/index-BdxG1c0H.d.mts +188 -0
  76. package/dist/index-BdxG1c0H.d.mts.map +1 -0
  77. package/dist/{init-BZP6gvYd.mjs → init-BjwbWklG.mjs} +24 -15
  78. package/dist/init-BjwbWklG.mjs.map +1 -0
  79. package/dist/inspect-BpVHe9vz.mjs +46 -0
  80. package/dist/inspect-BpVHe9vz.mjs.map +1 -0
  81. package/dist/{inspect-DXjbQEV_.mjs → inspect-zWJnBDMJ.mjs} +11 -4
  82. package/dist/inspect-zWJnBDMJ.mjs.map +1 -0
  83. package/dist/install-added-dependencies-DnZFR3aE.mjs +18 -0
  84. package/dist/install-added-dependencies-DnZFR3aE.mjs.map +1 -0
  85. package/dist/keyframes-bFo9iDhT.mjs +201 -0
  86. package/dist/keyframes-bFo9iDhT.mjs.map +1 -0
  87. package/dist/mcp-BK-qb1ZS.mjs +262 -0
  88. package/dist/mcp-BK-qb1ZS.mjs.map +1 -0
  89. package/dist/migrate-B-MM9TlS.mjs +177 -0
  90. package/dist/migrate-B-MM9TlS.mjs.map +1 -0
  91. package/dist/module-dir-1avCXsBi.mjs +17 -0
  92. package/dist/module-dir-1avCXsBi.mjs.map +1 -0
  93. package/dist/npm-args-g1Tgel4s.mjs +78 -0
  94. package/dist/npm-args-g1Tgel4s.mjs.map +1 -0
  95. package/dist/offered-routes-imports-CQInWI6y.mjs +4 -0
  96. package/dist/offered-routes-imports-CalXK9dh.mjs +96 -0
  97. package/dist/offered-routes-imports-CalXK9dh.mjs.map +1 -0
  98. package/dist/ph-cli-commands-DwSp4Sbq.mjs +1770 -0
  99. package/dist/ph-cli-commands-DwSp4Sbq.mjs.map +1 -0
  100. package/dist/ph-cli-commands-HLM5KIpd.mjs +4 -0
  101. package/dist/{registry-auth-DxEWCJu2.mjs → registry-auth-Bm5AR-fB.mjs} +4 -4
  102. package/dist/{registry-auth-DxEWCJu2.mjs.map → registry-auth-Bm5AR-fB.mjs.map} +1 -1
  103. package/dist/render-BO-Nwn2H.mjs +71 -0
  104. package/dist/render-BO-Nwn2H.mjs.map +1 -0
  105. package/dist/render-DdieUjtg.mjs +4 -0
  106. package/dist/run-DEKE4MJY.mjs +111 -0
  107. package/dist/run-DEKE4MJY.mjs.map +1 -0
  108. package/dist/run-DP3fNgPv.mjs +4 -0
  109. package/dist/run-sugar-D9lIzhAx.mjs +39 -0
  110. package/dist/run-sugar-D9lIzhAx.mjs.map +1 -0
  111. package/dist/runners/connect.d.mts +17 -0
  112. package/dist/runners/connect.d.mts.map +1 -0
  113. package/dist/runners/connect.mjs +63 -0
  114. package/dist/runners/connect.mjs.map +1 -0
  115. package/dist/runners/switchboard.d.mts +11 -0
  116. package/dist/runners/switchboard.d.mts.map +1 -0
  117. package/dist/runners/switchboard.mjs +21 -0
  118. package/dist/runners/switchboard.mjs.map +1 -0
  119. package/dist/schemas-DzgKfQIx.mjs +6024 -0
  120. package/dist/schemas-DzgKfQIx.mjs.map +1 -0
  121. package/dist/scripts/emit-runner-schemas.ts +24 -0
  122. package/dist/scripts/generate-commands-docs.ts +17 -0
  123. package/dist/scripts/manage-environment +0 -0
  124. package/dist/scripts/setup.sh +0 -0
  125. package/dist/{switchboard-migrate-NQ7LHWSi.mjs → switchboard-migrate-Docb8Cjv.mjs} +6 -5
  126. package/dist/{switchboard-migrate-NQ7LHWSi.mjs.map → switchboard-migrate-Docb8Cjv.mjs.map} +1 -1
  127. package/dist/switchboard-proxy-CGfMtENM.mjs +37 -0
  128. package/dist/switchboard-proxy-CGfMtENM.mjs.map +1 -0
  129. package/dist/{switchboard-reset-BcQXlcVf.mjs → switchboard-reset-MtTB_GAI.mjs} +8 -6
  130. package/dist/switchboard-reset-MtTB_GAI.mjs.map +1 -0
  131. package/dist/sync-connect-routes-BtAsFPXN.mjs +4 -0
  132. package/dist/sync-connect-routes-t0Slg-P6.mjs +25 -0
  133. package/dist/sync-connect-routes-t0Slg-P6.mjs.map +1 -0
  134. package/dist/{utils-C4isxXSO.mjs → utils-9KyRM0mf.mjs} +6 -34
  135. package/dist/{utils-C4isxXSO.mjs.map → utils-9KyRM0mf.mjs.map} +1 -1
  136. package/dist/utils-TO9lB8Xs.mjs +4 -0
  137. package/dist/verify-l5f7BDmy.mjs +71 -0
  138. package/dist/verify-l5f7BDmy.mjs.map +1 -0
  139. package/dist/{vetra-DkF6EJMY.mjs → vetra-DSFzAl_1.mjs} +115 -148
  140. package/dist/vetra-DSFzAl_1.mjs.map +1 -0
  141. package/dist/vetra-launch-DQDZxGTV.mjs +343 -0
  142. package/dist/vetra-launch-DQDZxGTV.mjs.map +1 -0
  143. package/dist/warn-subgraph-type-conflicts-BOHBmThq.mjs +19 -0
  144. package/dist/warn-subgraph-type-conflicts-BOHBmThq.mjs.map +1 -0
  145. package/package.json +45 -18
  146. package/dist/auth-BNkN6kS9.mjs +0 -4
  147. package/dist/build-C-A5-ipO.mjs +0 -4
  148. package/dist/build-uQXq6_HU.mjs +0 -71
  149. package/dist/build-uQXq6_HU.mjs.map +0 -1
  150. package/dist/cli-connect-override-D3hh4aH_.mjs.map +0 -1
  151. package/dist/connect-build-WL4axo4z.mjs +0 -43
  152. package/dist/connect-build-WL4axo4z.mjs.map +0 -1
  153. package/dist/connect-config-BWGiW3IB.mjs.map +0 -1
  154. package/dist/connect-preview-D7ypzFDc.mjs +0 -28
  155. package/dist/connect-preview-D7ypzFDc.mjs.map +0 -1
  156. package/dist/connect-studio-BIQzyq5B.mjs +0 -5
  157. package/dist/connect-studio-D6rfWCNB.mjs +0 -31
  158. package/dist/connect-studio-D6rfWCNB.mjs.map +0 -1
  159. package/dist/generate-all-DrT4ZxHX.mjs +0 -30
  160. package/dist/generate-all-DrT4ZxHX.mjs.map +0 -1
  161. package/dist/generate-app-DNNqA-H3.mjs +0 -48
  162. package/dist/generate-app-DNNqA-H3.mjs.map +0 -1
  163. package/dist/generate-document-model-BJXyODfm.mjs +0 -34
  164. package/dist/generate-document-model-BJXyODfm.mjs.map +0 -1
  165. package/dist/generate-editor-BejvaVVT.mjs +0 -48
  166. package/dist/generate-editor-BejvaVVT.mjs.map +0 -1
  167. package/dist/generate-processor-_WOx-mMe.mjs +0 -40
  168. package/dist/generate-processor-_WOx-mMe.mjs.map +0 -1
  169. package/dist/generate-subgraph-BsHUstpl.mjs +0 -38
  170. package/dist/generate-subgraph-BsHUstpl.mjs.map +0 -1
  171. package/dist/init-BZP6gvYd.mjs.map +0 -1
  172. package/dist/inspect-DXjbQEV_.mjs.map +0 -1
  173. package/dist/migrate-jGKfE02L.mjs +0 -83
  174. package/dist/migrate-jGKfE02L.mjs.map +0 -1
  175. package/dist/switchboard-CJMoMzWx.mjs +0 -75
  176. package/dist/switchboard-CJMoMzWx.mjs.map +0 -1
  177. package/dist/switchboard-iRFugh8I.mjs +0 -4
  178. package/dist/switchboard-reset-BcQXlcVf.mjs.map +0 -1
  179. package/dist/utils-BzwczAW-.mjs +0 -4
  180. package/dist/vetra-DkF6EJMY.mjs.map +0 -1
@@ -0,0 +1,1770 @@
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]="37fde983-b6ea-569a-b3e3-06baeb22c1f1")}catch(e){}}();
3
+ import { n as skipInstallArgs } from "./install-added-dependencies-DnZFR3aE.mjs";
4
+ import { t as isUniformRunnersEnabled } from "./feature-flags-xwqcHEWC.mjs";
5
+ import { boolean, command, extendType, flag, multioption, number, oneOf, option, optional, positional, string, subcommands } from "cmd-ts";
6
+ import { AGENTS, accessTokenArgs, buildArgs, connectBuildArgs, connectConfigArgs, connectPreviewArgs, connectStudioArgs, debugArgs, hostCheckArgs, hostExportArgs, initArgs, inspectArgs, installArgs, keyframesArgs, listArgs, loginArgs, mcpArgs, migrateArgs, modelCheckArgs, modelInspectArgs, 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 { PROCESSOR_APPS } from "@powerhousedao/shared/processors";
11
+ import { execSync } from "child_process";
12
+ import { execSync as execSync$1 } from "node:child_process";
13
+ import { createInterface } from "node:readline/promises";
14
+ //#region src/commands/access-token.ts
15
+ const accessToken = command({
16
+ name: "access-token",
17
+ description: `
18
+ The access-token command generates a bearer token for API authentication. This token
19
+ can be used to authenticate requests to Powerhouse APIs like reactor-api (Switchboard).
20
+
21
+ This command:
22
+ 1. Uses your CLI's cryptographic identity (DID) to sign a verifiable credential
23
+ 2. Creates a JWT bearer token with configurable expiration
24
+ 3. Outputs the token to stdout (info to stderr) for easy piping
25
+
26
+ Prerequisites:
27
+ You must have a cryptographic identity. Run 'ph login' first to:
28
+ - Generate a keypair (stored in .ph/.keypair.json)
29
+ - Optionally link your Ethereum address (stored in .ph/.renown.json)
30
+
31
+ Token Details:
32
+ The generated token is a JWT (JSON Web Token) containing:
33
+ - Issuer (iss): Your CLI's DID (did:key:...)
34
+ - Subject (sub): Your CLI's DID
35
+ - Credential Subject: Chain ID, network ID, and address (if authenticated)
36
+ - Expiration (exp): Based on --expiry option
37
+ - Audience (aud): If --audience is specified
38
+
39
+ Output:
40
+ - Token information (DID, address, expiry) is printed to stderr
41
+ - The token itself is printed to stdout for easy piping/copying
42
+
43
+ This allows you to use the command in scripts:
44
+ TOKEN=$(ph access-token)
45
+ curl -H "Authorization: Bearer $TOKEN" http://localhost:4001/graphql
46
+
47
+ Usage with APIs:
48
+ Generate token and use with curl
49
+ TOKEN=$(ph access-token --expiry 1d)
50
+ curl -X POST http://localhost:4001/graphql \\
51
+ -H "Content-Type: application/json" \\
52
+ -H "Authorization: Bearer $TOKEN" \\
53
+ -d '{"query": "{ drives { id name } }"}'
54
+
55
+ Export as environment variable
56
+ export PH_ACCESS_TOKEN=$(ph access-token)
57
+
58
+ Notes:
59
+ - Tokens are self-signed using your CLI's private key
60
+ - No network request is made; tokens are generated locally
61
+ - The recipient API must trust your CLI's DID to accept the token
62
+ - For reactor-api, ensure AUTH_ENABLED=true to require authentication
63
+ `,
64
+ args: accessTokenArgs,
65
+ handler: async (args) => {
66
+ if (args.debug) console.log(args);
67
+ const { generateAccessToken, parseExpiry, formatExpiry } = await import("@renown/sdk/node");
68
+ const { getRenown } = await import("./auth-CNhbN5UM.mjs");
69
+ const renown = await getRenown();
70
+ let expiresIn = DEFAULT_EXPIRY_SECONDS;
71
+ if (args.expiry) expiresIn = parseExpiry(args.expiry);
72
+ const result = await generateAccessToken(renown, {
73
+ expiresIn,
74
+ aud: args.audience
75
+ });
76
+ console.error(`CLI DID: ${result.did}`);
77
+ console.error(`ETH Address: ${result.address}`);
78
+ console.error(`Token expires in: ${formatExpiry(expiresIn)}`);
79
+ console.error("");
80
+ console.log(result.token);
81
+ process.exit(0);
82
+ }
83
+ });
84
+ //#endregion
85
+ //#region src/commands/build.ts
86
+ const build$1 = command({
87
+ name: "build",
88
+ description: `
89
+ Build a Powerhouse package for publishing: a browser bundle and a node bundle of its
90
+ document models, scalars, editors, subgraphs and processors, type declarations, and its
91
+ 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-Ws5hhqol.mjs");
108
+ await runBuild(args, {
109
+ checkDefinitions: true,
110
+ ownsProcess: true
111
+ });
112
+ } catch (error) {
113
+ console.error(args.debug || !(error instanceof Error) ? error : error.message);
114
+ process.exit(1);
115
+ }
116
+ }
117
+ });
118
+ //#endregion
119
+ //#region src/commands/connect.ts
120
+ const studio = command({
121
+ name: "studio",
122
+ description: `The studio command starts the Connect Studio, a development environment for building
123
+ and testing Powerhouse applications. It provides a visual interface for working with
124
+ your project.
125
+
126
+ This command:
127
+ 1. Starts a local Connect Studio server
128
+ 2. Provides a web interface for development
129
+ 3. Allows you to interact with your project components
130
+ 4. Supports various configuration options for customization
131
+ `,
132
+ args: connectStudioArgs,
133
+ handler: async (args) => {
134
+ if (args.debug) console.log(args);
135
+ const { runConnectStudio } = await import("./connect-studio-xQNYl142.mjs");
136
+ await runConnectStudio(args, void 0, void 0, { reloadOnConfigChange: true });
137
+ }
138
+ });
139
+ const build = command({
140
+ name: "build",
141
+ description: `The Connect build command creates a production build with the project's local and
142
+ external packages included.
143
+
144
+ Runtime-config overrides (all combinable — last wins on collision):
145
+ ph connect build Build with the current source config.
146
+ ph connect build <key> <value> Build with a positional override applied (e.g. ph connect build connect.renown.url https://renown.staging).
147
+ ph connect build --<field> <value> Build with a per-field flag override (e.g. --renown-url https://renown.staging).
148
+ ph connect build --json '{"app":{"workflowsEnabled":true}}'
149
+ Build with a bulk override. The payload is the connect.* block
150
+ without the "connect" wrapper; unknown keys are rejected.
151
+
152
+ Build has no read mode; passing only <key> without <value> errors out (use \`ph connect config <key>\` to read).
153
+ `,
154
+ args: connectBuildArgs,
155
+ handler: async (args) => {
156
+ if (args.debug) console.log(args);
157
+ const { runConnectBuild } = await import("./connect-build-COdexcA8.mjs");
158
+ await runConnectBuild(args);
159
+ process.exit(0);
160
+ }
161
+ });
162
+ const preview = command({
163
+ name: "preview",
164
+ description: `The Connect preview command previews a built Connect project.
165
+ NOTE: You must run \`ph connect build\` first
166
+ `,
167
+ args: connectPreviewArgs,
168
+ handler: async (args) => {
169
+ if (args.debug) console.log(args);
170
+ const { runConnectPreview } = await import("./connect-preview-CdFvlANO.mjs");
171
+ await runConnectPreview(args);
172
+ }
173
+ });
174
+ const config = command({
175
+ name: "config",
176
+ description: `Read or update Connect's runtime configuration (powerhouse.config.json).
177
+
178
+ Modes (mutually exclusive — positional, --get, --json, and field flags cannot be combined):
179
+ ph connect config List the effective connect.* block (defaults < source).
180
+ ph connect config <key> Get the value at the dotted path (e.g. ph connect config connect.renown.url).
181
+ ph connect config --get <dotted.path> Same as positional <key> (kept for backward compat).
182
+ ph connect config <key> <value> Set a single field and dual-write to source + dist (positional).
183
+ ph connect config --<field> <value> Set a single field via per-field flag (e.g. --renown-url https://renown.id).
184
+ ph connect config --json '{"renown":{"url":"…"}}'
185
+ Bulk-set multiple fields and dual-write. The payload is the connect.*
186
+ block without the "connect" wrapper; unknown keys are rejected.
187
+
188
+ Writes go to:
189
+ - <project>/powerhouse.config.json (source — picked up by the next build)
190
+ - <dist-dir>/powerhouse.config.json (if it exists — the currently-served SPA picks it up on refresh)
191
+ `,
192
+ args: connectConfigArgs,
193
+ handler: async (args) => {
194
+ const { runConnectConfig } = await import("./connect-config-C6hKMsUG.mjs");
195
+ await runConnectConfig(args);
196
+ }
197
+ });
198
+ const connect = subcommands({
199
+ name: "connect",
200
+ description: `Powerhouse Connect commands. Use with \`studio\`, \`build\`, \`preview\`, or \`config\`. Defaults to \`studio\` if not specified.`,
201
+ cmds: {
202
+ studio,
203
+ build,
204
+ preview,
205
+ config
206
+ }
207
+ });
208
+ //#endregion
209
+ //#region src/commands/generate-all.ts
210
+ const generateAllCmd = command({
211
+ name: "all",
212
+ description: "Re-generate all modules in the current project",
213
+ args: { extract: flag({
214
+ long: "extract",
215
+ short: "x",
216
+ description: "Instead of generating code, write a spec for every module into specs/ (one-shot migration to documents-as-source-of-truth)"
217
+ }) },
218
+ handler: async (args) => {
219
+ const { startGenerateAll } = await import("./generate-all-_7S0Iii2.mjs");
220
+ await startGenerateAll(args, process.cwd());
221
+ process.exit(0);
222
+ }
223
+ });
224
+ //#endregion
225
+ //#region src/utils/fs-args.ts
226
+ const ExistingPath = extendType(string, {
227
+ displayName: "path",
228
+ description: "An existing path",
229
+ from(str) {
230
+ const resolved = path.resolve(str);
231
+ if (!fs.existsSync(resolved)) return Promise.reject(/* @__PURE__ */ new Error("Path doesn't exist"));
232
+ return Promise.resolve(resolved);
233
+ }
234
+ });
235
+ extendType(ExistingPath, {
236
+ displayName: "dir",
237
+ description: "A path to a directory or a file within a directory",
238
+ from(resolved) {
239
+ return Promise.resolve(fs.statSync(resolved).isDirectory() ? resolved : path.dirname(resolved));
240
+ }
241
+ });
242
+ /** An existing file. */
243
+ const File = extendType(ExistingPath, {
244
+ displayName: "file",
245
+ description: "A file in the file system",
246
+ from(resolved) {
247
+ if (!fs.statSync(resolved).isFile()) return Promise.reject(/* @__PURE__ */ new Error("Provided path is not a file"));
248
+ return Promise.resolve(resolved);
249
+ }
250
+ });
251
+ /** A module's directory name or path, resolved by the command against the project. */
252
+ const ModuleDir = extendType(string, {
253
+ displayName: "dir",
254
+ description: "A module's directory name or path",
255
+ from: (dir) => Promise.resolve(dir)
256
+ });
257
+ //#endregion
258
+ //#region src/utils/comma-separated.ts
259
+ /** Splits comma-separated values so `-t "a,b"` means the same as `-t a -t b`
260
+ * instead of yielding the single value `"a,b"`, which matches nothing. */
261
+ function splitCommaSeparated(values) {
262
+ return values.flatMap((value) => value.split(",")).map((value) => value.trim()).filter((value) => value.length > 0);
263
+ }
264
+ /** `multioption` type accepting repeated and/or comma-separated values. */
265
+ const CommaSeparatedStrings = { from: (values) => Promise.resolve(splitCommaSeparated(values)) };
266
+ //#endregion
267
+ //#region src/commands/generate-app.ts
268
+ const generateAppCmd = command({
269
+ name: "app",
270
+ description: "Generate a drive app",
271
+ args: {
272
+ name: option({
273
+ type: optional(string),
274
+ long: "name",
275
+ short: "n",
276
+ description: "The name of the drive app to generate"
277
+ }),
278
+ allowedDocumentTypes: multioption({
279
+ type: optional(CommaSeparatedStrings),
280
+ long: "document-types",
281
+ short: "t",
282
+ description: "The document types allowed by the new app (repeatable or comma-separated)"
283
+ }),
284
+ document: option({
285
+ type: optional(File),
286
+ long: "document",
287
+ short: "d",
288
+ description: "Path to a powerhouse/app spec file (.phd or .json) to drive codegen"
289
+ }),
290
+ dir: option({
291
+ type: optional(ModuleDir),
292
+ long: "dir",
293
+ description: "Name of the directory of an existing app to re-generate (my-app or editors/my-app)"
294
+ }),
295
+ disableDragAndDrop: flag({
296
+ type: boolean,
297
+ long: "disable-drag-and-drop",
298
+ description: "Do not allow drag and drop in this drive app.",
299
+ defaultValue: () => false,
300
+ defaultValueIsSerializable: true
301
+ }),
302
+ all: flag({
303
+ long: "all",
304
+ short: "a",
305
+ description: "Re-generate all existing apps in the current project"
306
+ }),
307
+ extract: flag({
308
+ long: "extract",
309
+ short: "x",
310
+ description: "Write a powerhouse/app spec for each existing drive app into specs/apps/"
311
+ }),
312
+ ...debugArgs
313
+ },
314
+ handler: async (args) => {
315
+ const { startGenerateApp } = await import("./generate-app-hm6CJ_4O.mjs");
316
+ await startGenerateApp(args, process.cwd());
317
+ process.exit(0);
318
+ }
319
+ });
320
+ //#endregion
321
+ //#region src/commands/generate-connect-routes.ts
322
+ const generateConnectRoutesCmd = command({
323
+ name: "connect-routes",
324
+ description: "Generate .ph/connect-routes.gen.ts, the route tree hosts/connect/routes/ type-checks against, and fail if a route the package offers imports @powerhousedao/connect",
325
+ args: { ...debugArgs },
326
+ handler: async () => {
327
+ const { syncProjectConnectRoutes } = await import("./sync-connect-routes-BtAsFPXN.mjs");
328
+ const { checkOfferedRoutesImports } = await import("./offered-routes-imports-CQInWI6y.mjs");
329
+ await syncProjectConnectRoutes(process.cwd());
330
+ await checkOfferedRoutesImports(process.cwd());
331
+ }
332
+ });
333
+ //#endregion
334
+ //#region src/commands/generate-desktop-shell.ts
335
+ const generateDesktopShellCmd = command({
336
+ name: "desktop-shell",
337
+ description: "Scaffold a builder-owned desktop identity (hosts/desktop/app.json + icon). `ph run desktop dev|build` then projects it into a native Tauri shell — no Rust.",
338
+ args: {
339
+ name: option({
340
+ type: optional(string),
341
+ long: "name",
342
+ short: "n",
343
+ description: "Product name (window title + macOS app name). Default: the project's package name."
344
+ }),
345
+ identifier: option({
346
+ type: optional(string),
347
+ long: "identifier",
348
+ short: "i",
349
+ description: "Reverse-DNS app identifier, e.g. com.acme.app. Default: inc.powerhouse.desktop.<project>."
350
+ }),
351
+ force: flag({
352
+ long: "force",
353
+ short: "f",
354
+ description: "Overwrite an existing app.json (protects edits by default)."
355
+ }),
356
+ ...debugArgs
357
+ },
358
+ handler: async (args) => {
359
+ const { startGenerateDesktopShell } = await import("./generate-desktop-shell-CEcE_1gb.mjs");
360
+ startGenerateDesktopShell(args, process.cwd());
361
+ process.exit(0);
362
+ }
363
+ });
364
+ //#endregion
365
+ //#region src/commands/generate-document-model.ts
366
+ const generateDocumentModelCmd = command({
367
+ name: "document-model",
368
+ aliases: ["doc"],
369
+ description: "Generate a document model",
370
+ args: {
371
+ document: option({
372
+ type: optional(File),
373
+ long: "document",
374
+ short: "d",
375
+ description: "Path to a document model spec (.phd or .json) to generate from"
376
+ }),
377
+ dir: option({
378
+ type: optional(ModuleDir),
379
+ long: "dir",
380
+ description: "Name of the directory of an existing document model to re-generate (my-document-model or document-models/my-document-model)"
381
+ }),
382
+ all: flag({
383
+ long: "all",
384
+ short: "a",
385
+ description: "Re-generate all existing document models in the current project"
386
+ }),
387
+ extract: flag({
388
+ long: "extract",
389
+ short: "x",
390
+ description: "Write a powerhouse/document-model spec for each existing document model into specs/document-models/"
391
+ }),
392
+ /** @experimental Code-first scaffolding is being tested in production. */
393
+ name: option({
394
+ type: optional(string),
395
+ long: "name",
396
+ short: "n",
397
+ description: "Experimental. Create a code-first document model with this name, with its editor"
398
+ }),
399
+ /** @experimental Opts into the code-first authoring strategy. */
400
+ codeFirst: flag({
401
+ long: "code-first",
402
+ description: "Experimental. Generate with code-first authoring, whatever definitionSources in powerhouse.config.json selects"
403
+ }),
404
+ ...debugArgs
405
+ },
406
+ handler: async (args) => {
407
+ const { startGenerateDocumentModel } = await import("./generate-document-model-DCjzz3Sa.mjs");
408
+ await startGenerateDocumentModel(args, process.cwd());
409
+ process.exit(0);
410
+ }
411
+ });
412
+ //#endregion
413
+ //#region src/commands/generate-editor.ts
414
+ const generateEditorCmd = command({
415
+ name: "editor",
416
+ description: "Generate a document editor",
417
+ args: {
418
+ name: option({
419
+ type: optional(string),
420
+ long: "name",
421
+ short: "n",
422
+ description: "The name of the document editor to generate"
423
+ }),
424
+ documentType: option({
425
+ type: optional(string),
426
+ long: "document-type",
427
+ short: "t",
428
+ description: "The document type for the new editor"
429
+ }),
430
+ document: option({
431
+ type: optional(File),
432
+ long: "document",
433
+ short: "d",
434
+ description: "Path to a powerhouse/document-editor spec file (.phd or .json) to drive codegen"
435
+ }),
436
+ dir: option({
437
+ type: optional(ModuleDir),
438
+ long: "dir",
439
+ description: "Name of the directory of an existing editor to re-generate (my-editor or editors/my-editor)"
440
+ }),
441
+ all: flag({
442
+ long: "all",
443
+ short: "a",
444
+ description: "Re-generate all existing editors in the current project"
445
+ }),
446
+ extract: flag({
447
+ long: "extract",
448
+ short: "x",
449
+ description: "Write a powerhouse/document-editor spec for each existing editor into specs/editors/"
450
+ }),
451
+ ...debugArgs
452
+ },
453
+ handler: async (args) => {
454
+ const { startGenerateEditor } = await import("./generate-editor-DdoapkEK.mjs");
455
+ await startGenerateEditor(args, process.cwd());
456
+ process.exit(0);
457
+ }
458
+ });
459
+ //#endregion
460
+ //#region src/commands/generate-hosts.ts
461
+ const generateHostsCmd = command({
462
+ name: "hosts",
463
+ description: "Generate hosts/<name>/outputs.js + outputs.d.ts (typed $output token trees) for every host whose runner declares outputs, and refresh hosts/types.d.ts. Rerun after changing a producer's runner or declared drives: a stale outputs.js fails the load.",
464
+ args: {},
465
+ handler: async () => {
466
+ const { startGenerateHosts } = await import("./generate-hosts-RWj7WPHZ.mjs");
467
+ const ok = await startGenerateHosts(process.cwd());
468
+ process.exit(ok ? 0 : 1);
469
+ }
470
+ });
471
+ //#endregion
472
+ //#region src/commands/generate-migration-file.ts
473
+ const generateMigrationFileCmd = command({
474
+ name: "migration-file",
475
+ description: "Generate a migration file",
476
+ args: {
477
+ migrationFile: option({
478
+ type: string,
479
+ long: "path",
480
+ short: "p",
481
+ description: "Path to the migration file"
482
+ }),
483
+ schemaFile: option({
484
+ type: optional(string),
485
+ long: "schema-file",
486
+ description: "Path to the output file. Defaults to './schema.ts'"
487
+ }),
488
+ ...skipInstallArgs,
489
+ ...debugArgs
490
+ },
491
+ handler: async (args) => {
492
+ const { startGenerateMigrationFile } = await import("./generate-migration-file-yK8uA70U.mjs");
493
+ await startGenerateMigrationFile(args, process.cwd());
494
+ process.exit(0);
495
+ }
496
+ });
497
+ //#endregion
498
+ //#region src/commands/generate-piece-action.ts
499
+ const generatePieceActionCmd = command({
500
+ name: "piece-action",
501
+ description: "Generate an action inside an existing piece",
502
+ args: {
503
+ namePositional: positional({
504
+ type: optional(string),
505
+ displayName: "name",
506
+ description: "The name of the action, e.g. get-record"
507
+ }),
508
+ name: option({
509
+ type: optional(string),
510
+ long: "name",
511
+ short: "n",
512
+ description: "The name of the action to generate"
513
+ }),
514
+ piece: option({
515
+ type: optional(string),
516
+ long: "piece",
517
+ short: "p",
518
+ description: "The piece directory under pieces/ to add the action to. Optional when the project ships exactly one piece."
519
+ }),
520
+ requireReactor: option({
521
+ type: optional(oneOf(["read", "write"])),
522
+ long: "require-reactor",
523
+ description: "Declare reactor access for the action: read, or write (which includes read). The action then gets context.reactor"
524
+ }),
525
+ defaultTimeoutSeconds: option({
526
+ type: optional(number),
527
+ long: "default-timeout-seconds",
528
+ description: "Write defaultTimeoutSeconds: the step timeout used when the workflow sets none"
529
+ }),
530
+ defaultMaxAttempts: option({
531
+ type: optional(number),
532
+ long: "default-max-attempts",
533
+ description: "Write defaultRetry: { maxAttempts }: the attempts (1 is no retry) used when the workflow sets no retry"
534
+ }),
535
+ ...skipInstallArgs,
536
+ ...debugArgs
537
+ },
538
+ handler: async (args) => {
539
+ const { startGeneratePieceAction } = await import("./generate-piece-action-DqR8BcoO.mjs");
540
+ await startGeneratePieceAction(args, process.cwd());
541
+ process.exit(0);
542
+ }
543
+ });
544
+ //#endregion
545
+ //#region src/commands/generate-piece-trigger.ts
546
+ const generatePieceTriggerCmd = command({
547
+ name: "piece-trigger",
548
+ description: "Generate a trigger inside an existing piece",
549
+ args: {
550
+ namePositional: positional({
551
+ type: optional(string),
552
+ displayName: "name",
553
+ description: "The name of the trigger, e.g. new-record"
554
+ }),
555
+ name: option({
556
+ type: optional(string),
557
+ long: "name",
558
+ short: "n",
559
+ description: "The name of the trigger to generate"
560
+ }),
561
+ piece: option({
562
+ type: optional(string),
563
+ long: "piece",
564
+ short: "p",
565
+ description: "The piece directory under pieces/ to add the trigger to. Optional when the project ships exactly one piece."
566
+ }),
567
+ strategy: option({
568
+ type: oneOf(["polling", "webhook"]),
569
+ long: "strategy",
570
+ description: "How the trigger fires: polled on a schedule, or delivered to a webhook",
571
+ defaultValue: () => "polling",
572
+ defaultValueIsSerializable: true
573
+ }),
574
+ requireReactor: option({
575
+ type: optional(oneOf(["read", "write"])),
576
+ long: "require-reactor",
577
+ description: "Declare reactor access for the trigger: read, or write (which includes read). Its hooks then get context.reactor"
578
+ }),
579
+ ...skipInstallArgs,
580
+ ...debugArgs
581
+ },
582
+ handler: async (args) => {
583
+ const { startGeneratePieceTrigger } = await import("./generate-piece-trigger-CZaDD-cc.mjs");
584
+ await startGeneratePieceTrigger(args, process.cwd());
585
+ process.exit(0);
586
+ }
587
+ });
588
+ //#endregion
589
+ //#region src/commands/generate-piece.ts
590
+ const generatePieceCmd = command({
591
+ name: "piece",
592
+ description: "Generate a piece: a connector whose actions and triggers a workflow can call",
593
+ args: {
594
+ namePositional: positional({
595
+ type: optional(string),
596
+ displayName: "name",
597
+ description: "The name of the piece to generate. Its directory is the kebab-case of this."
598
+ }),
599
+ name: option({
600
+ type: optional(string),
601
+ long: "name",
602
+ short: "n",
603
+ description: "The name of the piece to generate"
604
+ }),
605
+ id: option({
606
+ type: optional(string),
607
+ long: "id",
608
+ description: "The piece id, the pieceName a workflow step holds, e.g. @acme/piece-crm. Defaults to one derived from the package name."
609
+ }),
610
+ auth: option({
611
+ type: oneOf([
612
+ "none",
613
+ "secret",
614
+ "custom"
615
+ ]),
616
+ long: "auth",
617
+ description: "The kind of connection the piece asks for",
618
+ defaultValue: () => "custom",
619
+ defaultValueIsSerializable: true
620
+ }),
621
+ description: option({
622
+ type: optional(string),
623
+ long: "description",
624
+ description: "One line describing what the piece connects to"
625
+ }),
626
+ dir: option({
627
+ type: optional(ModuleDir),
628
+ long: "dir",
629
+ description: "Name of the directory of an existing piece to re-register (my-piece or pieces/my-piece)"
630
+ }),
631
+ all: flag({
632
+ long: "all",
633
+ short: "a",
634
+ description: "Re-register every piece in pieces/: refresh the pieces list and the manifest, and prune what is gone"
635
+ }),
636
+ ...skipInstallArgs,
637
+ ...debugArgs
638
+ },
639
+ handler: async (args) => {
640
+ const { startGeneratePiece } = await import("./generate-piece-5Nyr2UZj.mjs");
641
+ await startGeneratePiece(args, process.cwd());
642
+ process.exit(0);
643
+ }
644
+ });
645
+ //#endregion
646
+ //#region src/commands/generate.ts
647
+ const baseGenerateCmds = {
648
+ all: generateAllCmd,
649
+ "document-model": generateDocumentModelCmd,
650
+ editor: generateEditorCmd,
651
+ app: generateAppCmd,
652
+ processor: command({
653
+ name: "processor",
654
+ description: "Generate a processor",
655
+ args: {
656
+ name: option({
657
+ type: optional(string),
658
+ long: "name",
659
+ short: "n",
660
+ description: "The name of the processor to generate"
661
+ }),
662
+ type: option({
663
+ type: oneOf(["analytics", "relationalDb"]),
664
+ long: "type",
665
+ description: "The type of processor to generate",
666
+ defaultValue: () => "analytics",
667
+ defaultValueIsSerializable: true
668
+ }),
669
+ documentTypes: multioption({
670
+ type: CommaSeparatedStrings,
671
+ long: "document-types",
672
+ short: "t",
673
+ description: "The document types the processor will run on (repeatable or comma-separated)",
674
+ defaultValue: () => [],
675
+ defaultValueIsSerializable: true
676
+ }),
677
+ apps: multioption({
678
+ long: "apps",
679
+ type: { from(rawProcessorApps) {
680
+ const processorApps = splitCommaSeparated(rawProcessorApps);
681
+ if (processorApps.length === 0) throw new Error(`No arguments provided for processor apps. Must be "connect" and/or "switchboard"`);
682
+ if (processorApps.length > 2) throw new Error(`Too many arguments provided for processor apps. Must be "connect" and/or "switchboard"`);
683
+ const allowed = new Set(PROCESSOR_APPS);
684
+ if (!processorApps.every((p) => allowed.has(p))) throw new Error(`Processor apps can only be "connect" and/or "switchboard".`);
685
+ return Promise.resolve(processorApps);
686
+ } },
687
+ description: "Whether the processor will run in switchboard (nodejs), connect (browser), or both",
688
+ defaultValue: () => ["switchboard", "connect"],
689
+ defaultValueIsSerializable: true
690
+ }),
691
+ document: option({
692
+ type: optional(File),
693
+ long: "document",
694
+ short: "d",
695
+ description: "Path to a powerhouse/processor spec file (.phd or .json) to drive codegen"
696
+ }),
697
+ dir: option({
698
+ type: optional(ModuleDir),
699
+ long: "dir",
700
+ description: "Name of the directory of an existing processor to re-generate (my-processor or processors/my-processor)"
701
+ }),
702
+ all: flag({
703
+ long: "all",
704
+ short: "a",
705
+ description: "Re-generate all existing processors in the current project"
706
+ }),
707
+ extract: flag({
708
+ long: "extract",
709
+ short: "x",
710
+ description: "Write a powerhouse/processor spec for each existing processor into specs/processors/"
711
+ }),
712
+ ...skipInstallArgs,
713
+ ...debugArgs
714
+ },
715
+ handler: async (args) => {
716
+ const { startGenerateProcessor } = await import("./generate-processor-BVjOsfjJ.mjs");
717
+ await startGenerateProcessor(args, process.cwd());
718
+ process.exit(0);
719
+ }
720
+ }),
721
+ subgraph: command({
722
+ name: "subgraph",
723
+ description: "Generate a subgraph",
724
+ args: {
725
+ name: option({
726
+ type: optional(string),
727
+ long: "name",
728
+ short: "n",
729
+ description: "The name of the subgraph to generate"
730
+ }),
731
+ document: option({
732
+ type: optional(File),
733
+ long: "document",
734
+ short: "d",
735
+ description: "Path to a powerhouse/subgraph spec file (.phd or .json) to drive codegen"
736
+ }),
737
+ dir: option({
738
+ type: optional(ModuleDir),
739
+ long: "dir",
740
+ description: "Name of the directory of an existing subgraph to re-generate (my-subgraph or subgraphs/my-subgraph)"
741
+ }),
742
+ all: flag({
743
+ long: "all",
744
+ short: "a",
745
+ description: "Re-generate all existing subgraphs in the current project"
746
+ }),
747
+ extract: flag({
748
+ long: "extract",
749
+ short: "x",
750
+ description: "Write a powerhouse/subgraph spec for each existing subgraph into specs/subgraphs/"
751
+ }),
752
+ ...skipInstallArgs,
753
+ ...debugArgs
754
+ },
755
+ handler: async (args) => {
756
+ const { startGenerateSubgraph } = await import("./generate-subgraph-CrHbYK91.mjs");
757
+ await startGenerateSubgraph(args, process.cwd());
758
+ process.exit(0);
759
+ }
760
+ }),
761
+ piece: generatePieceCmd,
762
+ "piece-action": generatePieceActionCmd,
763
+ "piece-trigger": generatePieceTriggerCmd,
764
+ "migration-file": generateMigrationFileCmd,
765
+ "connect-routes": generateConnectRoutesCmd,
766
+ "desktop-shell": generateDesktopShellCmd
767
+ };
768
+ /** Exported for tests; `hosts` exists only with uniform runners enabled, so
769
+ * flag-off keeps the command surface unchanged. */
770
+ function buildGenerateCmds(uniformRunners) {
771
+ return uniformRunners ? {
772
+ ...baseGenerateCmds,
773
+ hosts: generateHostsCmd
774
+ } : baseGenerateCmds;
775
+ }
776
+ const generate = subcommands({
777
+ name: "generate",
778
+ 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.`,
779
+ cmds: buildGenerateCmds(isUniformRunnersEnabled())
780
+ });
781
+ //#endregion
782
+ //#region src/commands/host.ts
783
+ const check = command({
784
+ name: "check",
785
+ description: "Check a host the way `ph run` would, without starting it: every load, validation, resolution and boot issue, grouped by host file. Exits 1 on any issue. `--env <file>` checks against that file alone.",
786
+ args: hostCheckArgs,
787
+ handler: async (args) => {
788
+ const { runHostCheck } = await import("./check-Cco7-UC2.mjs");
789
+ const { output, exitCode } = await runHostCheck(args);
790
+ console.log(output);
791
+ process.exitCode = exitCode;
792
+ }
793
+ });
794
+ const exportCmd = command({
795
+ name: "export",
796
+ description: "Print a host as declared, with every member a compound names, as JSON (tokens unresolved). `--out` writes it to a file instead.",
797
+ args: hostExportArgs,
798
+ handler: async (args) => {
799
+ const { runHostExport } = await import("./export-YkeGUZjR.mjs");
800
+ const { stdout, stderr, exitCode } = await runHostExport(args);
801
+ if (stdout !== void 0) process.stdout.write(stdout);
802
+ if (stderr !== void 0) process.stderr.write(stderr);
803
+ process.exitCode = exitCode;
804
+ }
805
+ });
806
+ const host = subcommands({
807
+ name: "host",
808
+ description: "Inspect the project's hosts/ (FEATURE_UNIFORM_RUNNERS_ENABLED): `check`, `export`.",
809
+ cmds: {
810
+ check,
811
+ export: exportCmd
812
+ }
813
+ });
814
+ //#endregion
815
+ //#region src/commands/init.ts
816
+ const init = command({
817
+ name: "init",
818
+ description: "Initialize a new project",
819
+ args: initArgs,
820
+ handler: async (args) => {
821
+ if (args.debug) console.log({ args });
822
+ const { startInit } = await import("./init-BjwbWklG.mjs");
823
+ await startInit(args);
824
+ process.exit(0);
825
+ }
826
+ });
827
+ //#endregion
828
+ //#region src/commands/inspect.ts
829
+ const inspect = command({
830
+ name: "inspect",
831
+ description: `
832
+ The inspect command examines and provides detailed information about a Powerhouse package.
833
+ It helps you understand the structure, dependencies, and configuration of packages in
834
+ your project.
835
+
836
+ This command:
837
+ 1. Analyzes the specified package
838
+ 2. Retrieves detailed information about its structure and configuration
839
+ 3. Displays package metadata, dependencies, and other relevant information
840
+ 4. Helps troubleshoot package-related issues`,
841
+ aliases: ["is"],
842
+ args: inspectArgs,
843
+ handler: async (args) => {
844
+ if (args.debug) console.log(args);
845
+ const { startInspect } = await import("./inspect-zWJnBDMJ.mjs");
846
+ startInspect(args);
847
+ process.exit(0);
848
+ }
849
+ });
850
+ //#endregion
851
+ //#region src/commands/install.ts
852
+ const MANIFEST_TIMEOUT_MS = 1e4;
853
+ async function fetchExternalDependencies(registryUrl, dependency) {
854
+ const base = registryUrl.endsWith("/") ? registryUrl : `${registryUrl}/`;
855
+ const spec = dependency.version ? `${dependency.name}@${dependency.version}` : dependency.name;
856
+ try {
857
+ const response = await fetch(`${base}-/cdn/${spec}/powerhouse.manifest.json`, { signal: AbortSignal.timeout(MANIFEST_TIMEOUT_MS) });
858
+ if (!response.ok) return [];
859
+ const external = (await response.json()).externalDependencies;
860
+ return typeof external === "object" && external !== null ? Object.keys(external).sort() : [];
861
+ } catch {
862
+ return [];
863
+ }
864
+ }
865
+ async function warnAboutExternalDependencies(registryUrl, dependencies) {
866
+ const found = await Promise.all(dependencies.map((dependency) => fetchExternalDependencies(registryUrl, dependency)));
867
+ for (const [i, dependency] of dependencies.entries()) {
868
+ const external = found[i];
869
+ if (external.length === 0) continue;
870
+ 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.`);
871
+ }
872
+ }
873
+ const install = command({
874
+ name: "install",
875
+ aliases: ["add", "i"],
876
+ description: `
877
+ The install command adds Powerhouse dependencies to your project.
878
+
879
+ By default it only registers the package in powerhouse.config.json with
880
+ provider "registry" — Connect will load it from the registry CDN at runtime.
881
+
882
+ With --local, the package is also installed into node_modules and marked
883
+ as provider "local" — it will be bundled into ph connect build so the
884
+ preview works without the registry being reachable.
885
+
886
+ Resolution order for the registry URL:
887
+ --registry flag > PH_REGISTRY_URL env > powerhouse.config.json > default
888
+ `,
889
+ args: installArgs,
890
+ handler: async (args) => {
891
+ if (args.debug) console.log(args);
892
+ const { getPowerhouseProjectInfo, makeDependenciesWithVersions } = await import("@powerhousedao/shared/clis");
893
+ const { projectPath, localProjectPath, globalProjectPath, packageManager, isGlobal } = await getPowerhouseProjectInfo(args);
894
+ if (!projectPath) throw new Error(`Could not find project path to install from.`);
895
+ const { resolveRegistryUrl } = await import("@powerhousedao/shared/registry");
896
+ const registryUrl = resolveRegistryUrl({
897
+ registry: args.registry,
898
+ projectPath
899
+ });
900
+ if (args.debug) console.log(">>> registryUrl", registryUrl);
901
+ const dependenciesWithVersions = await makeDependenciesWithVersions(args.dependencies, registryUrl);
902
+ if (args.debug) {
903
+ console.log(">>> parsedDependencies", dependenciesWithVersions);
904
+ console.log("\n>>> projectInfo", {
905
+ localProjectPath,
906
+ globalProjectPath,
907
+ packageManager,
908
+ isGlobal
909
+ });
910
+ }
911
+ if (args.local) {
912
+ if (dependenciesWithVersions.length === 0) throw new Error("--local requires at least one package name (e.g. ph install --local @scope/pkg)");
913
+ try {
914
+ const specs = dependenciesWithVersions.map((d) => d.version ? `${d.name}@${d.version}` : d.name);
915
+ const scopes = /* @__PURE__ */ new Set();
916
+ for (const dep of dependenciesWithVersions) if (dep.name.startsWith("@")) {
917
+ const scope = dep.name.split("/")[0];
918
+ scopes.add(scope);
919
+ }
920
+ const scopeRegistryArgs = Array.from(scopes).map((scope) => `--${scope}:registry=${registryUrl}`);
921
+ const minReleaseAgeArgs = packageManager === "pnpm" ? ["--config.minimum-release-age=0"] : [];
922
+ const allowBuildArgs = packageManager === "pnpm" && args.allowBuild.length > 0 ? [`--allow-build=${args.allowBuild.join(",")}`] : [];
923
+ const { resolveCommand } = await import("package-manager-detector");
924
+ const resolved = resolveCommand(packageManager, "add", [
925
+ ...specs,
926
+ ...scopeRegistryArgs,
927
+ ...minReleaseAgeArgs,
928
+ ...allowBuildArgs
929
+ ]);
930
+ if (!resolved) throw new Error(`Failed to resolve install command for package manager "${packageManager}".`);
931
+ const installCommand = `${resolved.command} ${resolved.args.join(" ")}`;
932
+ if (scopeRegistryArgs.length > 0) console.log(`Installing dependencies 📦 (routing ${Array.from(scopes).join(", ")} → ${registryUrl})...`);
933
+ else console.log("Installing dependencies 📦...");
934
+ console.log(`> ${installCommand}`);
935
+ execSync(installCommand, {
936
+ stdio: "inherit",
937
+ cwd: projectPath
938
+ });
939
+ console.log("Dependency installed successfully 🎉");
940
+ } catch (error) {
941
+ console.error("❌ Failed to install dependencies");
942
+ throw error;
943
+ }
944
+ }
945
+ const { updateConfigFile } = await import("./utils-TO9lB8Xs.mjs");
946
+ try {
947
+ console.log("⚙️ Updating powerhouse config file...");
948
+ updateConfigFile(dependenciesWithVersions, projectPath, "install", args.local ? "local" : "registry", registryUrl, args.registry !== void 0);
949
+ console.log("Config file updated successfully 🎉");
950
+ } catch (error) {
951
+ console.error("❌ Failed to update config file");
952
+ throw error;
953
+ }
954
+ if (args.local) {
955
+ const { syncPackageSkills } = await import("@powerhousedao/codegen/file-builders");
956
+ for (const { path, action } of await syncPackageSkills(projectPath)) console.log(` ${path}: ${action}`);
957
+ }
958
+ if (!args.local) await warnAboutExternalDependencies(registryUrl, dependenciesWithVersions);
959
+ process.exit(0);
960
+ }
961
+ });
962
+ //#endregion
963
+ //#region src/commands/keyframes.ts
964
+ const keyframes = command({
965
+ name: "keyframes",
966
+ description: `
967
+ The keyframes command reports on and cleans up the keyframes of a running switchboard,
968
+ through its inspection-admin endpoint.
969
+
970
+ Prerequisites:
971
+ - The host serves inspection-admin (INSPECTION_ADMIN_ENABLED=true).
972
+ - The caller is one of the host's auth admins.
973
+ - The keep rules are in powerhouse.config.json under reactor.keyframes, or in PH_KEYFRAMES.
974
+
975
+ Run preview first: it only reads. clean then removes the keyframes past each type's keep
976
+ count and all keyframes of deleted documents, in small paced statements beside live
977
+ traffic. Running it again is safe. A later read that misses a keyframe replays from the
978
+ operation log, so a clean-up costs time on cold reads and never changes a document.
979
+
980
+ The disk only shrinks after reclaim, which rewrites the Keyframe table once the store is
981
+ quiet. On PGlite the store answers nothing while it rewrites. On Postgres it says what to
982
+ run by hand.
983
+ `,
984
+ args: keyframesArgs,
985
+ handler: async (args) => {
986
+ if (args.debug) console.log(args);
987
+ const { runKeyframesCommand } = await import("./keyframes-bFo9iDhT.mjs");
988
+ const exitCode = await runKeyframesCommand(args);
989
+ process.exit(exitCode);
990
+ }
991
+ });
992
+ //#endregion
993
+ //#region src/commands/list.ts
994
+ const list = command({
995
+ name: "list",
996
+ description: `
997
+ The list command displays information about installed Powerhouse packages in your project.
998
+ It reads the powerhouse.config.json file and shows the packages that are currently installed.
999
+
1000
+ This command:
1001
+ 1. Examines your project configuration
1002
+ 2. Lists all installed Powerhouse packages
1003
+ 3. Provides a clear overview of your project's dependencies
1004
+ 4. Helps you manage and track your Powerhouse components
1005
+ `,
1006
+ aliases: ["l"],
1007
+ args: listArgs,
1008
+ handler: async (args) => {
1009
+ if (args.debug) console.log(args);
1010
+ try {
1011
+ const { getPowerhouseProjectInfo } = await import("@powerhousedao/shared/clis");
1012
+ const projectInfo = await getPowerhouseProjectInfo();
1013
+ const { getConfig } = await import("@powerhousedao/config/node");
1014
+ const phConfig = getConfig(projectInfo.projectPath + "/powerhouse.config.json");
1015
+ if (!phConfig.packages || phConfig.packages.length === 0) {
1016
+ console.log("No packages found in the project");
1017
+ return;
1018
+ }
1019
+ console.log("Installed Packages:\n");
1020
+ phConfig.packages.forEach((pkg) => {
1021
+ console.log(pkg.version ? `${pkg.packageName}@${pkg.version}` : pkg.packageName);
1022
+ });
1023
+ } catch (_e) {
1024
+ console.log("No packages found in the project");
1025
+ }
1026
+ process.exit(0);
1027
+ }
1028
+ });
1029
+ //#endregion
1030
+ //#region src/commands/login.ts
1031
+ const login = command({
1032
+ name: "login",
1033
+ description: `
1034
+ The login command authenticates you with Renown using your Ethereum wallet. This enables
1035
+ the CLI to act on behalf of your Ethereum identity for authenticated operations.
1036
+
1037
+ This command:
1038
+ 1. Generates or loads a cryptographic identity (DID) for the CLI
1039
+ 2. Opens your browser to the Renown authentication page
1040
+ 3. You authorize the CLI's DID to act on behalf of your Ethereum address
1041
+ 4. Stores the credentials locally in .ph/.renown.json
1042
+ `,
1043
+ args: loginArgs,
1044
+ handler: async (args) => {
1045
+ if (args.debug) console.log(args);
1046
+ const { getRenown } = await import("./auth-CNhbN5UM.mjs");
1047
+ const renown = await getRenown(args.renownUrl);
1048
+ if (args.showDid) {
1049
+ console.log(renown.did);
1050
+ process.exit(0);
1051
+ }
1052
+ if (args.status) {
1053
+ const { getAuthStatus } = await import("@renown/sdk/node");
1054
+ const status = getAuthStatus(renown);
1055
+ if (!status.authenticated || !status.address) {
1056
+ console.log("Not authenticated with an Ethereum address.");
1057
+ console.log("Run \"ph login\" to authenticate.");
1058
+ } else {
1059
+ console.log("Authenticated");
1060
+ console.log(` ETH Address: ${status.address}`);
1061
+ console.log(` User DID: ${status.userDid}`);
1062
+ console.log(` Chain ID: ${status.chainId}`);
1063
+ console.log(` CLI DID: ${status.cliDid}`);
1064
+ console.log(` Authenticated at: ${status.authenticatedAt?.toLocaleString()}`);
1065
+ console.log(` Renown URL: ${status.baseUrl}`);
1066
+ }
1067
+ process.exit(0);
1068
+ }
1069
+ if (args.logout) {
1070
+ await handleLogout();
1071
+ process.exit(0);
1072
+ }
1073
+ const { browserLogin } = await import("@renown/sdk/node");
1074
+ console.debug("Initializing cryptographic identity...");
1075
+ console.log(`CLI DID: ${renown.did}`);
1076
+ try {
1077
+ const timeoutMs = args.timeout ? args.timeout * 1e3 : void 0;
1078
+ const result = await browserLogin(renown, {
1079
+ renownUrl: args.renownUrl,
1080
+ timeoutMs,
1081
+ onLoginUrl: (url, sessionId) => {
1082
+ console.log("Opening browser for authentication...");
1083
+ console.log(`Session ID: ${sessionId.slice(0, 8)}...`);
1084
+ console.log(`Login URL: ${url}`);
1085
+ console.log();
1086
+ console.log("Waiting for authentication in browser");
1087
+ console.log(`(timeout in ${(timeoutMs ?? 3e5) / 1e3} seconds)`);
1088
+ console.log();
1089
+ console.log("Please connect your wallet and authorize this CLI to act on your behalf.");
1090
+ console.log();
1091
+ process.stdout.write("Waiting");
1092
+ },
1093
+ onPollTick: () => process.stdout.write("."),
1094
+ onBrowserOpenFailed: (url) => {
1095
+ console.error("Failed to open browser automatically.");
1096
+ console.log(`Please open this URL manually: ${url}`);
1097
+ }
1098
+ });
1099
+ console.log();
1100
+ console.log();
1101
+ console.log("Successfully authenticated!");
1102
+ console.log(` ETH Address: ${result.user.address}`);
1103
+ console.log(` User DID: ${result.user.did}`);
1104
+ console.log(` CLI DID: ${result.cliDid}`);
1105
+ console.log();
1106
+ console.log("The CLI can now act on behalf of your Ethereum identity.");
1107
+ } catch (error) {
1108
+ console.log();
1109
+ throw error;
1110
+ }
1111
+ process.exit(0);
1112
+ }
1113
+ });
1114
+ async function handleLogout() {
1115
+ const { getRenown } = await import("./auth-CNhbN5UM.mjs");
1116
+ const renown = await getRenown();
1117
+ if (!renown.user) {
1118
+ console.log("Not currently authenticated.");
1119
+ return;
1120
+ }
1121
+ try {
1122
+ await renown.logout();
1123
+ console.log("Successfully logged out.");
1124
+ } catch (error) {
1125
+ console.error("Failed to clear credentials.");
1126
+ console.debug(error);
1127
+ }
1128
+ }
1129
+ //#endregion
1130
+ //#region src/commands/logout.ts
1131
+ const logout = command({
1132
+ name: "logout",
1133
+ description: `
1134
+ The logout command removes an existing session created with 'ph login'`,
1135
+ args: {},
1136
+ handler: async () => {
1137
+ await handleLogout();
1138
+ process.exit(0);
1139
+ }
1140
+ });
1141
+ //#endregion
1142
+ //#region src/commands/mcp.ts
1143
+ const mcp = command({
1144
+ name: "mcp",
1145
+ args: mcpArgs,
1146
+ description: `
1147
+ Serve the project's reactor-mcp tools to a coding agent over stdio.
1148
+
1149
+ Use it as the MCP server command in .mcp.json, .cursor/mcp.json and
1150
+ .gemini/settings.json. Tools are listed at once, without waiting for Vetra.
1151
+ The first tool call connects to the project's running Vetra (found through
1152
+ .ph/vetra-runtime.json), or starts \`ph vetra --strictPort --watch\` in the
1153
+ background and waits for it to be ready, reporting how the start goes as MCP
1154
+ progress notifications when the client sent a progressToken, else on stderr.
1155
+ Startup failures come back as tool errors carrying Vetra's output, which is
1156
+ also written to .ph/vetra.log.
1157
+
1158
+ Beside reactor-mcp's tools it serves restartVetra, which stops the project's
1159
+ Vetra, starts it again and returns its URLs. When Vetra restarts some other
1160
+ way (\`ph vetra --restart\`), the next tool call connects to the new one.
1161
+ `,
1162
+ handler: async (args) => {
1163
+ if (args.debug) console.error(args);
1164
+ const { startMcpLauncher } = await import("./mcp-BK-qb1ZS.mjs");
1165
+ await startMcpLauncher({
1166
+ projectDir: args.projectDir,
1167
+ startTimeoutSeconds: args.startTimeout
1168
+ });
1169
+ }
1170
+ });
1171
+ //#endregion
1172
+ //#region src/commands/migrate.ts
1173
+ const migrate = command({
1174
+ name: "migrate",
1175
+ args: migrateArgs,
1176
+ description: "Run migrations",
1177
+ handler: async (args) => {
1178
+ if (args.debug) console.log(args);
1179
+ const { startMigrate } = await import("./migrate-B-MM9TlS.mjs");
1180
+ await startMigrate(args);
1181
+ process.exit(0);
1182
+ }
1183
+ });
1184
+ //#endregion
1185
+ //#region src/commands/model.ts
1186
+ const EXPERIMENTAL = "Experimental: the command, its output and the JSON report can change in any release.";
1187
+ const EXIT_CODES = `Exit codes:
1188
+ 0 ok, or skipped. Skipped means no code-first source is selected and the
1189
+ package has no stored model, so nothing was read. Read "status".
1190
+ 1 invalid. The models were read and at least one is wrong.
1191
+ 2 failed. The configuration or a module could not be read, the arguments
1192
+ are wrong, or the command could not run.`;
1193
+ const OUTPUT = (name) => `Output:
1194
+ ph model ${name} a readable report on stdout
1195
+ ph model ${name} --json exactly one JSON report on stdout and nothing else
1196
+ Logs, including what the package's modules print while they load, go to
1197
+ stderr. When the command cannot run at all, it prints only a message on
1198
+ stderr and exits 2.`;
1199
+ const modelCheck = command({
1200
+ name: "check",
1201
+ description: `Check this package's document models: the code-first sources
1202
+ definitionSources selects and the stored schema-first models in
1203
+ documentModelsDir, through one set of checks. Writes nothing.
1204
+
1205
+ \`tsc\` cannot run these checks: a code-first model compiles when its module is
1206
+ evaluated.
1207
+
1208
+ --release (experimental) runs the checks \`ph build --release\` runs: these,
1209
+ the release checks, and host validation, which validates every model and the
1210
+ package's scalars entry as a host that installed the package would.
1211
+
1212
+ --prepack (experimental) loads nothing. It reads the release approval
1213
+ \`ph build --release\` wrote in .ph/build/release-approval.json and exits 0
1214
+ when it matches this package, 1 when it does not (missing, unreadable, stale
1215
+ or refused), naming the reasons, and 2 when it cannot be checked. To stop a
1216
+ plain \`npm publish\` too, add it to package.json, then run
1217
+ \`ph build --release\` (package.json is published, so the approval covers it):
1218
+ "scripts": { "prepack": "ph-cli model check --prepack" }
1219
+ With --json it prints {"decision": ..., "reasons": [...]}.
1220
+
1221
+ ${EXIT_CODES}
1222
+
1223
+ ${OUTPUT("check")}
1224
+
1225
+ ${EXPERIMENTAL}`,
1226
+ args: modelCheckArgs,
1227
+ handler: async (args) => {
1228
+ if (args.debug) console.error(args);
1229
+ const [{ runModelCheck }, { exitWithModelCommand }] = await Promise.all([import("./check-CjFMilhk.mjs"), import("./run-DP3fNgPv.mjs")]);
1230
+ await exitWithModelCommand(args.json, (streams) => runModelCheck(args, { streams }));
1231
+ }
1232
+ });
1233
+ const modelInspect = command({
1234
+ name: "inspect",
1235
+ description: `Describe this package's document models without checking them: for each
1236
+ model its digest and compatibility, and for each of its versions the source,
1237
+ scopes, scalars and operations. With <documentType>@<version>, describe that
1238
+ version only and add its full definition to the JSON report. Writes nothing.
1239
+
1240
+ ${EXIT_CODES}
1241
+
1242
+ ${OUTPUT("inspect")}
1243
+
1244
+ ${EXPERIMENTAL}`,
1245
+ args: modelInspectArgs,
1246
+ handler: async (args) => {
1247
+ if (args.debug) console.error(args);
1248
+ const [{ runModelInspect }, { exitWithModelCommand }] = await Promise.all([import("./inspect-BpVHe9vz.mjs"), import("./run-DP3fNgPv.mjs")]);
1249
+ await exitWithModelCommand(args.json, (streams) => runModelInspect(args, { streams }));
1250
+ }
1251
+ });
1252
+ const model = subcommands({
1253
+ name: "model",
1254
+ description: "Check or inspect this package's document models (experimental): `check`, `inspect`.",
1255
+ cmds: {
1256
+ check: modelCheck,
1257
+ inspect: modelInspect
1258
+ }
1259
+ });
1260
+ //#endregion
1261
+ //#region src/commands/publish.ts
1262
+ function hasTagFlag(args) {
1263
+ return args.some((a) => a === "--tag" || a.startsWith("--tag="));
1264
+ }
1265
+ function isInteractive() {
1266
+ return Boolean(process.stdin.isTTY) && !process.env.CI;
1267
+ }
1268
+ async function readPrereleaseTag(projectPath, packedVersion) {
1269
+ try {
1270
+ const [{ readPackageSync }, { prerelease }] = await Promise.all([import("read-pkg"), import("semver")]);
1271
+ const version = packedVersion ?? readPackageSync({ cwd: projectPath }).version;
1272
+ if (!version) return null;
1273
+ const parts = prerelease(version);
1274
+ if (!parts || parts.length === 0) return null;
1275
+ const label = String(parts[0]);
1276
+ if (!/^[a-z][a-z0-9-]*$/i.test(label)) return null;
1277
+ return {
1278
+ version,
1279
+ tag: label
1280
+ };
1281
+ } catch {
1282
+ return null;
1283
+ }
1284
+ }
1285
+ const publish = command({
1286
+ name: "publish",
1287
+ description: `
1288
+ Publish a package to the Powerhouse registry. This is a thin wrapper around npm publish
1289
+ that automatically sets the registry URL.
1290
+
1291
+ This command:
1292
+ 0. With a release approval from ph build --release (experimental), checks that it matches
1293
+ the package and warns when it does not. --require-approval exits 1 instead; it forwards
1294
+ only --tag, --access, --otp, --dry-run, --provenance, --json and --loglevel to npm,
1295
+ refuses npm configuration in the environment that selects another package
1296
+ (npm_config_workspace, npm_config_workspaces, npm_config_include_workspace_root),
1297
+ packs the package once, checks that tarball, and publishes that tarball with
1298
+ --ignore-scripts, so a file changed after the check is not published
1299
+ 1. Resolves the registry URL (--registry flag > PH_REGISTRY_URL env > powerhouse.config.json > default)
1300
+ 2. Checks authentication with the registry via npm whoami
1301
+ 3. Forwards all additional arguments to npm publish
1302
+ `,
1303
+ args: publishArgs,
1304
+ handler: async (args) => {
1305
+ if (args.debug) console.log(args);
1306
+ const { getPowerhouseProjectInfo } = await import("@powerhousedao/shared/clis");
1307
+ const { projectPath } = await getPowerhouseProjectInfo();
1308
+ if (!projectPath) throw new Error("Could not find project path.");
1309
+ const { checkApprovalBeforePublish } = await import("./verify-l5f7BDmy.mjs");
1310
+ if (args.requireApproval) {
1311
+ const { ALLOWED_NPM_ARGUMENTS, refusedNpmArguments, targetSelectingNpmEnvironment } = await import("./npm-args-g1Tgel4s.mjs");
1312
+ const refused = refusedNpmArguments(args.forwardedArgs);
1313
+ if (refused.length > 0) {
1314
+ console.error(`✘ ph publish --require-approval publishes only the package it checked, so it forwards only these npm arguments: ${ALLOWED_NPM_ARGUMENTS}. Not allowed: ${refused.join(" ")}`);
1315
+ process.exit(1);
1316
+ }
1317
+ const selecting = targetSelectingNpmEnvironment(process.env);
1318
+ if (selecting.length > 0) {
1319
+ console.error(`✘ ph publish --require-approval publishes only the package it checked, but the environment sets npm configuration that selects another package: ${selecting.join(", ")}. Unset it and publish again.`);
1320
+ process.exit(1);
1321
+ }
1322
+ }
1323
+ const checked = checkApprovalBeforePublish(projectPath, args.requireApproval);
1324
+ if (!checked.proceed) process.exit(1);
1325
+ const { packed } = checked;
1326
+ if (packed) process.once("exit", packed.dispose);
1327
+ try {
1328
+ const { checkNpmAuth, npmPublish, resolveRegistryUrl } = await import("@powerhousedao/shared/registry");
1329
+ const { mintRegistryAuthToken } = await import("./registry-auth-Bm5AR-fB.mjs");
1330
+ const registryUrl = resolveRegistryUrl({
1331
+ registry: args.registry,
1332
+ projectPath
1333
+ });
1334
+ if (args.debug) console.log(">>> registryUrl", registryUrl);
1335
+ let authToken;
1336
+ try {
1337
+ authToken = await mintRegistryAuthToken(registryUrl, 300);
1338
+ if (args.debug) console.error(`>>> minted renown token for ${registryUrl} (5m TTL)`);
1339
+ } catch (err) {
1340
+ if (args.debug) console.error(`>>> renown token mint skipped: ${err.message}`);
1341
+ try {
1342
+ await checkNpmAuth(registryUrl);
1343
+ } catch {
1344
+ console.error(`Not authenticated with registry: ${registryUrl}`);
1345
+ console.error(`Run: ph login (recommended) or npm adduser --registry ${registryUrl}`);
1346
+ process.exit(1);
1347
+ }
1348
+ }
1349
+ let forwardedArgs = args.forwardedArgs;
1350
+ if (!hasTagFlag(forwardedArgs)) {
1351
+ const prereleaseInfo = await readPrereleaseTag(projectPath, packed?.manifest.version);
1352
+ if (prereleaseInfo) {
1353
+ const { version, tag } = prereleaseInfo;
1354
+ if (!isInteractive()) {
1355
+ console.error(`Detected prerelease version ${version}. npm requires an explicit dist-tag for prerelease publishes.`);
1356
+ console.error(`Re-run with --tag <label> (e.g. --tag ${tag}) to proceed.`);
1357
+ process.exit(1);
1358
+ }
1359
+ const enquirer = await import("enquirer");
1360
+ let confirmed;
1361
+ try {
1362
+ confirmed = (await enquirer.default.prompt({
1363
+ type: "confirm",
1364
+ name: "confirmed",
1365
+ message: `Detected prerelease version ${version}. Publish with --tag ${tag}?`,
1366
+ initial: true
1367
+ })).confirmed;
1368
+ } catch {
1369
+ confirmed = false;
1370
+ }
1371
+ if (!confirmed) {
1372
+ console.error(`Aborted. To publish manually: npm publish --registry ${registryUrl} --tag <label>`);
1373
+ process.exit(1);
1374
+ }
1375
+ forwardedArgs = [
1376
+ "--tag",
1377
+ tag,
1378
+ ...forwardedArgs
1379
+ ];
1380
+ }
1381
+ }
1382
+ if (args.debug) console.log(">>> command", `npm publish --registry ${registryUrl} ${forwardedArgs.join(" ")}`);
1383
+ if (args.requireApproval) {
1384
+ forwardedArgs = [
1385
+ ...forwardedArgs,
1386
+ "--ignore-scripts",
1387
+ "--workspaces=false"
1388
+ ];
1389
+ console.log("Lifecycle scripts are skipped (--ignore-scripts) and workspaces are off (--workspaces=false), so npm publishes the tarball the approval matched.");
1390
+ }
1391
+ console.log(`Publishing to ${registryUrl}...`);
1392
+ const result = await npmPublish({
1393
+ registryUrl,
1394
+ cwd: projectPath,
1395
+ args: packed ? [packed.tarball, ...forwardedArgs] : forwardedArgs,
1396
+ authToken
1397
+ });
1398
+ if (result.stdout) console.log(result.stdout);
1399
+ process.exit(0);
1400
+ } finally {
1401
+ packed?.dispose();
1402
+ }
1403
+ }
1404
+ });
1405
+ //#endregion
1406
+ //#region src/commands/registry-login.ts
1407
+ const registryLogin = command({
1408
+ name: "registry-login",
1409
+ description: `
1410
+ Log in to a Powerhouse registry using your Renown identity. Mints a longer-lived
1411
+ bearer token (default 30 days) bound to the registry's audience and writes the
1412
+ token into ~/.npmrc so raw 'npm publish' / 'npm install' work without further
1413
+ setup.
1414
+
1415
+ Prerequisites:
1416
+ Run 'ph login' first to establish a Renown identity.
1417
+
1418
+ Usage:
1419
+ ph registry-login # uses powerhouse.config.json / PH_REGISTRY_URL
1420
+ ph registry-login --registry https://registry.vetra.io
1421
+ ph registry-login --expiry 7d
1422
+ `,
1423
+ args: registryLoginArgs,
1424
+ handler: async (args) => {
1425
+ if (args.debug) console.log(args);
1426
+ const { getPowerhouseProjectInfo } = await import("@powerhousedao/shared/clis");
1427
+ const projectPath = (await getPowerhouseProjectInfo().catch(() => null))?.projectPath ?? process.cwd();
1428
+ const [{ resolveRegistryUrl, writeRegistryAuthToken }, { mintRegistryAuthToken }, { parseExpiry, formatExpiry }] = await Promise.all([
1429
+ import("@powerhousedao/shared/registry"),
1430
+ import("./registry-auth-Bm5AR-fB.mjs"),
1431
+ import("@renown/sdk/node")
1432
+ ]);
1433
+ const registryUrl = resolveRegistryUrl({
1434
+ registry: args.registry,
1435
+ projectPath
1436
+ });
1437
+ const expiresIn = parseExpiry(args.expiry);
1438
+ const npmrcPath = await writeRegistryAuthToken(registryUrl, await mintRegistryAuthToken(registryUrl, expiresIn));
1439
+ console.log(`Logged in to ${registryUrl}`);
1440
+ console.log(` Token expires in: ${formatExpiry(expiresIn)}`);
1441
+ console.log(` Wrote: ${npmrcPath}`);
1442
+ process.exit(0);
1443
+ }
1444
+ });
1445
+ //#endregion
1446
+ //#region src/commands/run.ts
1447
+ const runHost = command({
1448
+ name: "run",
1449
+ 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).",
1450
+ args: {
1451
+ host: positional({
1452
+ type: string,
1453
+ displayName: "host",
1454
+ description: "Folder name under hosts/ (e.g. vetra, connect)."
1455
+ }),
1456
+ verb: positional({
1457
+ type: optional(string),
1458
+ displayName: "verb",
1459
+ description: "Runner verb (default: run; e.g. dev, build, serve)."
1460
+ }),
1461
+ debug: flag({
1462
+ type: optional(boolean),
1463
+ long: "debug",
1464
+ description: "Print resolved host/runner/verb before dispatch."
1465
+ }),
1466
+ explain: option({
1467
+ type: optional(string),
1468
+ long: "explain",
1469
+ description: "Explain a resolved aspect instead of running: `--explain drives` prints the merged drive plan with provenance; `--explain outputs` prints what each host produces, the output tokens it reads and the start order they imply."
1470
+ })
1471
+ },
1472
+ handler: async (args) => {
1473
+ if (args.explain !== void 0) {
1474
+ const { explainHost } = await import("./explain-lynfOtDg.mjs");
1475
+ await explainHost({
1476
+ host: args.host,
1477
+ topic: args.explain
1478
+ });
1479
+ return;
1480
+ }
1481
+ const { startRun } = await import("@powerhousedao/ph-run/start-run");
1482
+ await startRun({
1483
+ host: args.host,
1484
+ verb: args.verb,
1485
+ debug: args.debug
1486
+ });
1487
+ }
1488
+ });
1489
+ //#endregion
1490
+ //#region src/commands/switchboard.ts
1491
+ const switchboard = command({
1492
+ name: "switchboard",
1493
+ aliases: ["reactor"],
1494
+ description: `
1495
+ The switchboard command starts a local Switchboard instance, which acts as the document
1496
+ processing engine for Powerhouse projects. It provides the infrastructure for document
1497
+ models, processors, and real-time updates.
1498
+
1499
+ This command:
1500
+ 1. Starts a local switchboard server
1501
+ 2. Loads document models and processors
1502
+ 3. Provides an API for document operations
1503
+ 4. Enables real-time document processing
1504
+ 5. Can authenticate with remote services using your identity from 'ph login'`,
1505
+ args: switchboardArgs,
1506
+ handler: async (args) => {
1507
+ if (args.debug) console.log(args);
1508
+ const { dbPath, migrate, migrateStatus, reset, yes } = args;
1509
+ if (reset) {
1510
+ const { resetSwitchboardDatabase } = await import("./switchboard-reset-MtTB_GAI.mjs");
1511
+ await resetSwitchboardDatabase({
1512
+ dbPath,
1513
+ yes
1514
+ });
1515
+ process.exit(0);
1516
+ }
1517
+ if (migrate || migrateStatus) {
1518
+ const { runSwitchboardMigrations } = await import("./switchboard-migrate-Docb8Cjv.mjs");
1519
+ await runSwitchboardMigrations({
1520
+ dbPath,
1521
+ statusOnly: migrateStatus
1522
+ });
1523
+ process.exit(0);
1524
+ }
1525
+ const { startSwitchboard } = await import("@powerhousedao/ph-run/switchboard");
1526
+ const { defaultDriveUrl, renown } = await startSwitchboard(args);
1527
+ console.log(" ➜ Switchboard:", defaultDriveUrl);
1528
+ if (renown) console.log(" ➜ Identity:", renown.did);
1529
+ }
1530
+ });
1531
+ //#endregion
1532
+ //#region src/commands/uninstall.ts
1533
+ const uninstall = command({
1534
+ name: "uninstall",
1535
+ aliases: ["remove"],
1536
+ description: `
1537
+ The uninstall command removes Powerhouse dependencies from your project. It handles the
1538
+ removal of packages, updates configuration files, and ensures proper cleanup.
1539
+
1540
+ This command:
1541
+ 1. Uninstalls specified Powerhouse dependencies using your package manager
1542
+ 2. Updates powerhouse.config.json to remove the dependencies
1543
+ 3. Supports various uninstallation options and configurations
1544
+ 4. Works with ${AGENTS.join(", ")} package managers
1545
+ `,
1546
+ args: uninstallArgs,
1547
+ handler: async (args) => {
1548
+ if (args.debug) console.log(args);
1549
+ const { getPowerhouseProjectInfo, getPowerhouseProjectUninstallCommand, makeDependenciesWithVersions } = await import("@powerhousedao/shared/clis");
1550
+ const { projectPath, localProjectPath, globalProjectPath, packageManager, isGlobal } = await getPowerhouseProjectInfo(args);
1551
+ if (!projectPath) throw new Error(`Could not find project path to uninstall from`);
1552
+ const dependenciesWithVersions = await makeDependenciesWithVersions(args.dependencies);
1553
+ if (args.debug) console.log(">>> parsedDependencies", dependenciesWithVersions);
1554
+ if (args.debug) console.log("\n>>> projectInfo", {
1555
+ localProjectPath,
1556
+ globalProjectPath,
1557
+ packageManager,
1558
+ isGlobal
1559
+ });
1560
+ try {
1561
+ console.log("Uninstalling dependencies 📦 ...");
1562
+ const uninstallCommand = await getPowerhouseProjectUninstallCommand(packageManager, args.dependencies);
1563
+ execSync$1(uninstallCommand, {
1564
+ stdio: "inherit",
1565
+ cwd: projectPath
1566
+ });
1567
+ console.log("Dependency uninstalled successfully 🎉");
1568
+ } catch (error) {
1569
+ console.error("❌ Failed to uninstall dependencies");
1570
+ throw error;
1571
+ }
1572
+ const { removeStylesImports, updateConfigFile } = await import("./utils-TO9lB8Xs.mjs");
1573
+ try {
1574
+ console.log("⚙️ Updating powerhouse config file...");
1575
+ updateConfigFile(dependenciesWithVersions, projectPath, "uninstall");
1576
+ console.log("Config file updated successfully 🎉");
1577
+ } catch (error) {
1578
+ console.error("❌ Failed to update config file");
1579
+ throw error;
1580
+ }
1581
+ const { syncPackageSkills } = await import("@powerhousedao/codegen/file-builders");
1582
+ for (const { path, action } of await syncPackageSkills(projectPath)) console.log(` ${path}: ${action}`);
1583
+ try {
1584
+ console.log("⚙️ Updating styles.css file...");
1585
+ removeStylesImports(dependenciesWithVersions, projectPath);
1586
+ console.log("Styles file updated successfully 🎉");
1587
+ } catch (error) {
1588
+ console.error("❌ Failed to update styles file");
1589
+ throw error;
1590
+ }
1591
+ process.exit(0);
1592
+ }
1593
+ });
1594
+ //#endregion
1595
+ //#region src/commands/unpublish.ts
1596
+ const unpublish = command({
1597
+ name: "unpublish",
1598
+ description: `
1599
+ Unpublish a package from the Powerhouse registry. This is a thin wrapper around
1600
+ npm unpublish that automatically targets the Powerhouse registry and never
1601
+ reaches npmjs.org.
1602
+
1603
+ Forms:
1604
+ ph unpublish # unpublish <name>@<version> from cwd's package.json
1605
+ ph unpublish <name> # unpublish the whole package (all versions)
1606
+ ph unpublish <name>@<version> # unpublish a single version
1607
+
1608
+ Flags:
1609
+ --registry <url> # override registry URL
1610
+ --yes, -y # skip the confirmation prompt
1611
+ `,
1612
+ args: unpublishArgs,
1613
+ handler: async (args) => {
1614
+ if (args.debug) console.log(args);
1615
+ const { getPowerhouseProjectInfo } = await import("@powerhousedao/shared/clis");
1616
+ const { projectPath } = await getPowerhouseProjectInfo();
1617
+ if (!projectPath) throw new Error("Could not find project path.");
1618
+ const { checkNpmAuth, npmUnpublish, resolveRegistryUrl } = await import("@powerhousedao/shared/registry");
1619
+ const registryUrl = resolveRegistryUrl({
1620
+ registry: args.registry,
1621
+ projectPath
1622
+ });
1623
+ const spec = await resolveSpec(args.spec, projectPath);
1624
+ if (!spec) {
1625
+ console.error("No package spec provided and could not read name/version from package.json.");
1626
+ process.exit(1);
1627
+ }
1628
+ if (args.debug) {
1629
+ console.log(">>> registryUrl", registryUrl);
1630
+ console.log(">>> spec", spec);
1631
+ }
1632
+ try {
1633
+ await checkNpmAuth(registryUrl);
1634
+ } catch {
1635
+ console.error(`Not authenticated with registry: ${registryUrl}`);
1636
+ console.error(`Run: npm adduser --registry ${registryUrl}`);
1637
+ process.exit(1);
1638
+ }
1639
+ if (!args.yes) {
1640
+ if (!await confirm(`Unpublish ${spec} from ${registryUrl}? [y/N] `)) {
1641
+ console.log("Aborted.");
1642
+ process.exit(0);
1643
+ }
1644
+ }
1645
+ if (args.debug) console.log(">>> command", `npm unpublish ${spec} --registry ${registryUrl} --force ${args.forwardedArgs.join(" ")}`);
1646
+ console.log(`Unpublishing ${spec} from ${registryUrl}...`);
1647
+ try {
1648
+ const result = await npmUnpublish({
1649
+ registryUrl,
1650
+ cwd: projectPath,
1651
+ spec,
1652
+ args: args.forwardedArgs
1653
+ });
1654
+ if (result.stdout) console.log(result.stdout);
1655
+ process.exit(0);
1656
+ } catch (err) {
1657
+ console.error(err instanceof Error ? err.message : String(err));
1658
+ process.exit(1);
1659
+ }
1660
+ }
1661
+ });
1662
+ async function resolveSpec(explicit, projectPath) {
1663
+ if (explicit) return explicit;
1664
+ try {
1665
+ const { readPackageSync } = await import("read-pkg");
1666
+ const pkg = readPackageSync({ cwd: projectPath });
1667
+ if (!pkg.name) return null;
1668
+ return pkg.version ? `${pkg.name}@${pkg.version}` : pkg.name;
1669
+ } catch {
1670
+ return null;
1671
+ }
1672
+ }
1673
+ async function confirm(prompt) {
1674
+ const rl = createInterface({
1675
+ input: process.stdin,
1676
+ output: process.stdout
1677
+ });
1678
+ try {
1679
+ const answer = await rl.question(prompt);
1680
+ return /^y(es)?$/i.test(answer.trim());
1681
+ } finally {
1682
+ rl.close();
1683
+ }
1684
+ }
1685
+ //#endregion
1686
+ //#region src/commands/ph-cli-commands.ts
1687
+ const baseCommands = {
1688
+ init,
1689
+ generate,
1690
+ vetra: command({
1691
+ name: "vetra",
1692
+ description: `
1693
+ The vetra command sets up a Vetra development environment for working with Vetra projects.
1694
+ It starts a Vetra Switchboard and optionally Connect Studio, enabling document collaboration
1695
+ and real-time processing with a "Vetra" drive or connection to remote drives.
1696
+
1697
+ This command:
1698
+ 1. Starts a Vetra Switchboard with a "Vetra" drive for document storage
1699
+ 2. Optionally connects to remote drives instead of creating a local drive
1700
+ 3. Starts Connect Studio pointing to the Switchboard for user interaction (unless disabled)
1701
+ 4. Enables real-time updates, collaboration, and code generation
1702
+
1703
+ Default drives:
1704
+ Connect's default drives resolve to the Vetra drive (and the preview drive
1705
+ when using --watch), plus any drives configured under
1706
+ connect.drives.defaultDrives in powerhouse.config.json - de-duplicated by
1707
+ URL, so configuring project drives does not cost you the Vetra drive.
1708
+ An explicit --default-drives-url is appended to that list (de-duplicated);
1709
+ it never replaces the Vetra drive.
1710
+
1711
+ Every drive on the local Switchboard:
1712
+ Studio has no reactor of its own: it reads and writes on the local
1713
+ Switchboard (connect.instance.reactorClient "remote"), so it lists every
1714
+ drive there, such as one an agent adds through MCP, and a drive created in
1715
+ Studio lands there too. Not with --remote-drive, or when the project sets
1716
+ connect.instance.multiReactor or reactorClient itself.
1717
+
1718
+ Preview drive app:
1719
+ Set vetra.previewDrive.app in powerhouse.config.json to the id of a drive
1720
+ app, and ph vetra --watch opens the Vetra Preview drive in that app: it sets
1721
+ the drive's app when it creates the drive and each time it starts. Without
1722
+ the field the drive keeps the app it has.
1723
+
1724
+ One Vetra per project:
1725
+ A running Vetra is recorded in .ph/vetra-runtime.json (its pid and the
1726
+ Connect, Switchboard and MCP URLs); a second \`ph vetra\` prints those and
1727
+ exits. --restart stops the recorded Vetra first, then starts this one; the
1728
+ \`ph mcp\` launcher reconnects to it on its next tool call. Studio restarts
1729
+ by itself when powerhouse.config.json changes.
1730
+ `,
1731
+ args: vetraArgs,
1732
+ handler: async (args) => {
1733
+ if (args.debug) console.log(args);
1734
+ const { startVetra } = await import("./vetra-DSFzAl_1.mjs");
1735
+ await startVetra(args);
1736
+ }
1737
+ }),
1738
+ connect,
1739
+ build: build$1,
1740
+ publish,
1741
+ unpublish,
1742
+ "access-token": accessToken,
1743
+ "registry-login": registryLogin,
1744
+ inspect,
1745
+ keyframes,
1746
+ list,
1747
+ mcp,
1748
+ migrate,
1749
+ model,
1750
+ switchboard,
1751
+ login,
1752
+ logout,
1753
+ install,
1754
+ uninstall
1755
+ };
1756
+ /** Exported for tests; the flag decides whether `run` and `host` are
1757
+ * registered at all, so flag-off keeps the command surface byte-identical. */
1758
+ function buildPhCliCommands(uniformRunners) {
1759
+ return uniformRunners ? {
1760
+ ...baseCommands,
1761
+ run: runHost,
1762
+ host
1763
+ } : baseCommands;
1764
+ }
1765
+ const phCliCommands = buildPhCliCommands(isUniformRunnersEnabled());
1766
+ //#endregion
1767
+ export { phCliCommands as n, buildPhCliCommands as t };
1768
+
1769
+ //# sourceMappingURL=ph-cli-commands-DwSp4Sbq.mjs.map
1770
+ //# debugId=37fde983-b6ea-569a-b3e3-06baeb22c1f1