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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (193) hide show
  1. package/README.md +21 -0
  2. package/dist/build-CD_KQkCH.mjs +4 -0
  3. package/dist/build-DDG00Wbj.mjs +3067 -0
  4. package/dist/build-DDG00Wbj.mjs.map +1 -0
  5. package/dist/check-B8oqVMg7.mjs +65 -0
  6. package/dist/check-B8oqVMg7.mjs.map +1 -0
  7. package/dist/check-CpzjVXHj.mjs +4 -0
  8. package/dist/check-Weu9n8OQ.mjs +81 -0
  9. package/dist/check-Weu9n8OQ.mjs.map +1 -0
  10. package/dist/classic-args-mH_DVsgC.mjs +48 -0
  11. package/dist/classic-args-mH_DVsgC.mjs.map +1 -0
  12. package/dist/classic-warnings-BR0S6lr5.mjs +179 -0
  13. package/dist/classic-warnings-BR0S6lr5.mjs.map +1 -0
  14. package/dist/{cli-connect-override-b4kKqgOZ.mjs → cli-connect-override-D22yFWlC.mjs} +6 -29
  15. package/dist/cli-connect-override-D22yFWlC.mjs.map +1 -0
  16. package/dist/cli.mjs +46 -1341
  17. package/dist/cli.mjs.map +1 -1
  18. package/dist/compound-DKi56SSx-CXQHhS6t.mjs +2911 -0
  19. package/dist/compound-DKi56SSx-CXQHhS6t.mjs.map +1 -0
  20. package/dist/connect-build-Bd6sSVwp.mjs +322 -0
  21. package/dist/connect-build-Bd6sSVwp.mjs.map +1 -0
  22. package/dist/{connect-config-_kiSMsbG.mjs → connect-config-CVU4xhti.mjs} +5 -5
  23. package/dist/{connect-config-_kiSMsbG.mjs.map → connect-config-CVU4xhti.mjs.map} +1 -1
  24. package/dist/connect-preview-CdFvlANO.mjs +49 -0
  25. package/dist/connect-preview-CdFvlANO.mjs.map +1 -0
  26. package/dist/connect-studio-BnfhpIv8.mjs +97 -0
  27. package/dist/connect-studio-BnfhpIv8.mjs.map +1 -0
  28. package/dist/{connect-studio-f3K1qPWd.mjs → connect-studio-D58ByAAn.mjs} +3 -3
  29. package/dist/definitions-worker.d.mts +98 -0
  30. package/dist/definitions-worker.d.mts.map +1 -0
  31. package/dist/definitions-worker.mjs +28 -0
  32. package/dist/definitions-worker.mjs.map +1 -0
  33. package/dist/dist-DXcB8fAF.mjs +542 -0
  34. package/dist/dist-DXcB8fAF.mjs.map +1 -0
  35. package/dist/evidence-CavwC5YV.mjs +134 -0
  36. package/dist/evidence-CavwC5YV.mjs.map +1 -0
  37. package/dist/explain-8OEXF2Dy.mjs +230 -0
  38. package/dist/explain-8OEXF2Dy.mjs.map +1 -0
  39. package/dist/export-DqbcbFU5.mjs +42 -0
  40. package/dist/export-DqbcbFU5.mjs.map +1 -0
  41. package/dist/external-M25AgDIE.d.mts +4277 -0
  42. package/dist/external-M25AgDIE.d.mts.map +1 -0
  43. package/dist/files-D6_euBBn.mjs +457 -0
  44. package/dist/files-D6_euBBn.mjs.map +1 -0
  45. package/dist/{generate-all-CIwP-3aa.mjs → generate-all-0YOnlZM0.mjs} +10 -5
  46. package/dist/generate-all-0YOnlZM0.mjs.map +1 -0
  47. package/dist/generate-app-hm6CJ_4O.mjs +72 -0
  48. package/dist/generate-app-hm6CJ_4O.mjs.map +1 -0
  49. package/dist/generate-desktop-shell-BovoRsR6.mjs +372 -0
  50. package/dist/generate-desktop-shell-BovoRsR6.mjs.map +1 -0
  51. package/dist/generate-document-model-BiD6ovXc.mjs +118 -0
  52. package/dist/generate-document-model-BiD6ovXc.mjs.map +1 -0
  53. package/dist/generate-editor-DBj_Pxwa.mjs +64 -0
  54. package/dist/generate-editor-DBj_Pxwa.mjs.map +1 -0
  55. package/dist/generate-hosts-BFmPIW2X.mjs +18 -0
  56. package/dist/generate-hosts-BFmPIW2X.mjs.map +1 -0
  57. package/dist/generate-hosts-RWj7WPHZ.mjs +4 -0
  58. package/dist/generate-migration-file-yK8uA70U.mjs +20 -0
  59. package/dist/generate-migration-file-yK8uA70U.mjs.map +1 -0
  60. package/dist/{generate-piece-QTt-ddt2.mjs → generate-piece-5Nyr2UZj.mjs} +18 -10
  61. package/dist/generate-piece-5Nyr2UZj.mjs.map +1 -0
  62. package/dist/{generate-piece-action-C5WTHsqu.mjs → generate-piece-action-DqR8BcoO.mjs} +10 -7
  63. package/dist/generate-piece-action-DqR8BcoO.mjs.map +1 -0
  64. package/dist/{generate-piece-trigger-DR10CPOG.mjs → generate-piece-trigger-CZaDD-cc.mjs} +8 -7
  65. package/dist/generate-piece-trigger-CZaDD-cc.mjs.map +1 -0
  66. package/dist/{generate-processor-DBtTkgo5.mjs → generate-processor-BVjOsfjJ.mjs} +20 -9
  67. package/dist/generate-processor-BVjOsfjJ.mjs.map +1 -0
  68. package/dist/generate-subgraph-DJZCr0Tk.mjs +86 -0
  69. package/dist/generate-subgraph-DJZCr0Tk.mjs.map +1 -0
  70. package/dist/get-version-ByaMbjqz.mjs +11 -0
  71. package/dist/get-version-ByaMbjqz.mjs.map +1 -0
  72. package/dist/index-H3AYe65i.d.mts +193 -0
  73. package/dist/index-H3AYe65i.d.mts.map +1 -0
  74. package/dist/{init-CIEMyAug.mjs → init-Ltg4cJzm.mjs} +29 -17
  75. package/dist/init-Ltg4cJzm.mjs.map +1 -0
  76. package/dist/inspect-CulIpVsF.mjs +52 -0
  77. package/dist/inspect-CulIpVsF.mjs.map +1 -0
  78. package/dist/{inspect-BpCB0TPo.mjs → inspect-zWJnBDMJ.mjs} +4 -4
  79. package/dist/{inspect-BpCB0TPo.mjs.map → inspect-zWJnBDMJ.mjs.map} +1 -1
  80. package/dist/install-added-dependencies-DnZFR3aE.mjs +18 -0
  81. package/dist/install-added-dependencies-DnZFR3aE.mjs.map +1 -0
  82. package/dist/keyframes-bFo9iDhT.mjs +201 -0
  83. package/dist/keyframes-bFo9iDhT.mjs.map +1 -0
  84. package/dist/mcp-VRTEA0Ib.mjs +263 -0
  85. package/dist/mcp-VRTEA0Ib.mjs.map +1 -0
  86. package/dist/migrate-BGFxHRgP.mjs +209 -0
  87. package/dist/migrate-BGFxHRgP.mjs.map +1 -0
  88. package/dist/migrate-document-models-CFNqYAgo.mjs +489 -0
  89. package/dist/migrate-document-models-CFNqYAgo.mjs.map +1 -0
  90. package/dist/migrate-subgraphs-BG-4KEzt.mjs +4 -0
  91. package/dist/migrate-subgraphs-CIksXwT7.mjs +710 -0
  92. package/dist/migrate-subgraphs-CIksXwT7.mjs.map +1 -0
  93. package/dist/module-dir-1avCXsBi.mjs +17 -0
  94. package/dist/module-dir-1avCXsBi.mjs.map +1 -0
  95. package/dist/npm-args-g1Tgel4s.mjs +78 -0
  96. package/dist/npm-args-g1Tgel4s.mjs.map +1 -0
  97. package/dist/offered-routes-imports-CQInWI6y.mjs +4 -0
  98. package/dist/offered-routes-imports-CalXK9dh.mjs +96 -0
  99. package/dist/offered-routes-imports-CalXK9dh.mjs.map +1 -0
  100. package/dist/ph-cli-commands-CcMT6rdd.mjs +4 -0
  101. package/dist/ph-cli-commands-Dy4vWwUm.mjs +1821 -0
  102. package/dist/ph-cli-commands-Dy4vWwUm.mjs.map +1 -0
  103. package/dist/render-3M3DwFzO.mjs +4 -0
  104. package/dist/render-SVfj3m8A.mjs +77 -0
  105. package/dist/render-SVfj3m8A.mjs.map +1 -0
  106. package/dist/run--de_-WAz.mjs +112 -0
  107. package/dist/run--de_-WAz.mjs.map +1 -0
  108. package/dist/run-LRGy7zGo.mjs +4 -0
  109. package/dist/run-sugar-DpznOP1e.mjs +56 -0
  110. package/dist/run-sugar-DpznOP1e.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 +83 -0
  114. package/dist/runners/connect.mjs.map +1 -0
  115. package/dist/runners/switchboard.d.mts +24 -0
  116. package/dist/runners/switchboard.d.mts.map +1 -0
  117. package/dist/runners/switchboard.mjs +178 -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 +19 -0
  123. package/dist/scripts/manage-environment +0 -0
  124. package/dist/scripts/setup.sh +0 -0
  125. package/dist/subgraph-gate-BJ2PWXVY.mjs +26 -0
  126. package/dist/subgraph-gate-BJ2PWXVY.mjs.map +1 -0
  127. package/dist/subgraph-gate-j9ywj6KA.mjs +4 -0
  128. package/dist/subgraphs-7OYWwP-C.mjs +134 -0
  129. package/dist/subgraphs-7OYWwP-C.mjs.map +1 -0
  130. package/dist/{switchboard-migrate-7JQZM7-5.mjs → switchboard-migrate-BqSdKJ7u.mjs} +4 -5
  131. package/dist/switchboard-migrate-BqSdKJ7u.mjs.map +1 -0
  132. package/dist/switchboard-proxy-CGfMtENM.mjs +37 -0
  133. package/dist/switchboard-proxy-CGfMtENM.mjs.map +1 -0
  134. package/dist/{switchboard-reset-Ctegiqdm.mjs → switchboard-reset-MtTB_GAI.mjs} +8 -6
  135. package/dist/switchboard-reset-MtTB_GAI.mjs.map +1 -0
  136. package/dist/sync-connect-routes-BtAsFPXN.mjs +4 -0
  137. package/dist/sync-connect-routes-t0Slg-P6.mjs +25 -0
  138. package/dist/sync-connect-routes-t0Slg-P6.mjs.map +1 -0
  139. package/dist/{utils-CvmDmCVd.mjs → utils-9KyRM0mf.mjs} +6 -34
  140. package/dist/{utils-CvmDmCVd.mjs.map → utils-9KyRM0mf.mjs.map} +1 -1
  141. package/dist/utils-TO9lB8Xs.mjs +4 -0
  142. package/dist/verify-D4V5VLnG.mjs +71 -0
  143. package/dist/verify-D4V5VLnG.mjs.map +1 -0
  144. package/dist/vetra-CVNZ46pK.mjs +352 -0
  145. package/dist/vetra-CVNZ46pK.mjs.map +1 -0
  146. package/dist/vetra-host-ChTpJiBJ.mjs +79 -0
  147. package/dist/vetra-host-ChTpJiBJ.mjs.map +1 -0
  148. package/dist/vetra-instance-CzhYIjxL.mjs +201 -0
  149. package/dist/vetra-instance-CzhYIjxL.mjs.map +1 -0
  150. package/dist/vetra-launch-qi10Unax.mjs +237 -0
  151. package/dist/vetra-launch-qi10Unax.mjs.map +1 -0
  152. package/dist/vetra-switchboard-BrkozIm7.mjs +4 -0
  153. package/dist/vetra-switchboard-tzdc14KA.mjs +230 -0
  154. package/dist/vetra-switchboard-tzdc14KA.mjs.map +1 -0
  155. package/dist/warn-subgraph-type-conflicts-BOHBmThq.mjs +19 -0
  156. package/dist/warn-subgraph-type-conflicts-BOHBmThq.mjs.map +1 -0
  157. package/package.json +41 -15
  158. package/dist/build-CTvPQFMi.mjs +0 -4
  159. package/dist/build-sO3PcZxl.mjs +0 -166
  160. package/dist/build-sO3PcZxl.mjs.map +0 -1
  161. package/dist/cli-connect-override-b4kKqgOZ.mjs.map +0 -1
  162. package/dist/connect-build-BMaR9w4G.mjs +0 -153
  163. package/dist/connect-build-BMaR9w4G.mjs.map +0 -1
  164. package/dist/connect-preview-CzDqR-JN.mjs +0 -32
  165. package/dist/connect-preview-CzDqR-JN.mjs.map +0 -1
  166. package/dist/connect-studio-_-O1-oef.mjs +0 -36
  167. package/dist/connect-studio-_-O1-oef.mjs.map +0 -1
  168. package/dist/generate-all-CIwP-3aa.mjs.map +0 -1
  169. package/dist/generate-app-BTs1u-9l.mjs +0 -50
  170. package/dist/generate-app-BTs1u-9l.mjs.map +0 -1
  171. package/dist/generate-document-model-DhDQ_06X.mjs +0 -44
  172. package/dist/generate-document-model-DhDQ_06X.mjs.map +0 -1
  173. package/dist/generate-editor-CW7Do69u.mjs +0 -50
  174. package/dist/generate-editor-CW7Do69u.mjs.map +0 -1
  175. package/dist/generate-piece-QTt-ddt2.mjs.map +0 -1
  176. package/dist/generate-piece-action-C5WTHsqu.mjs.map +0 -1
  177. package/dist/generate-piece-trigger-DR10CPOG.mjs.map +0 -1
  178. package/dist/generate-processor-DBtTkgo5.mjs.map +0 -1
  179. package/dist/generate-subgraph-Dm27O59o.mjs +0 -42
  180. package/dist/generate-subgraph-Dm27O59o.mjs.map +0 -1
  181. package/dist/init-CIEMyAug.mjs.map +0 -1
  182. package/dist/install-added-dependencies-DVSbzler.mjs +0 -33
  183. package/dist/install-added-dependencies-DVSbzler.mjs.map +0 -1
  184. package/dist/migrate-B6QBYDNX.mjs +0 -83
  185. package/dist/migrate-B6QBYDNX.mjs.map +0 -1
  186. package/dist/switchboard-CgVB4U76.mjs +0 -87
  187. package/dist/switchboard-CgVB4U76.mjs.map +0 -1
  188. package/dist/switchboard-migrate-7JQZM7-5.mjs.map +0 -1
  189. package/dist/switchboard-nHCI3pha.mjs +0 -4
  190. package/dist/switchboard-reset-Ctegiqdm.mjs.map +0 -1
  191. package/dist/utils-C3c5YG6v.mjs +0 -4
  192. package/dist/vetra-s8gWslse.mjs +0 -627
  193. package/dist/vetra-s8gWslse.mjs.map +0 -1
@@ -0,0 +1,542 @@
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]="0c9d00c4-c737-56e0-bf6f-c78db46b6bfc")}catch(e){}}();
3
+ import { a as custom, b as prettifyError, c as literal, f as record, m as string, p as strictObject } from "./schemas-DzgKfQIx.mjs";
4
+ import { B as projectDriveIdWith, C as isPlainObject, D as loadProducers, E as loadHost, F as prepareMember, G as resolveRunnerModule, M as outputRefsOf, N as outputSitesOf, O as memberForRef, P as planCompound, R as processResolveEnv, S as isBuiltinEnvName, T as kindShapeIssues, U as resolveHostOutputs, V as readProjectName, X as takesCspRegistrySync, Y as substituteBuiltinEnv, Z as unsetEnvMessage, a as TokenResolutionError, b as getVerb, c as checkTokenSites, d as compoundStartVerb, f as declaredHostSchemas, g as envSitesOf, k as memberVerbOf, n as HostLoadError, q as runnerOutputsSchema, r as ONE_SHOT_VERBS, s as checkOutputPaths, v as findRemovedForms, x as hostSchemaIssues, z as producerOutputsSchemas } from "./compound-DKi56SSx-CXQHhS6t.mjs";
5
+ import "node:module";
6
+ import { DEFAULT_CONNECT_STUDIO_PORT, DEFAULT_SWITCHBOARD_PORT } from "@powerhousedao/shared/clis/constants";
7
+ import "node:fs";
8
+ import path from "node:path";
9
+ import "node:child_process";
10
+ import crypto from "node:crypto";
11
+ import "node:url";
12
+ import "@powerhousedao/shared/host-tokens";
13
+ import "@powerhousedao/shared/connect/origin-placeholder";
14
+ import net from "node:net";
15
+ import { DRIVE_ICON_MAX_BYTES, resolveImageRef } from "@powerhousedao/shared/connect/image-ref";
16
+ //#region ../../packages/host-core/dist/index.mjs
17
+ /**
18
+ * Windows has no SIGTERM: `process.kill(pid, "SIGTERM")` ends the process at
19
+ * once, so no handler runs and a stack's stores are left as a crash leaves
20
+ * them. A started host therefore listens on a pipe named after its pid, and
21
+ * a connection to it is delivered as the SIGTERM it stands for. Elsewhere
22
+ * the signal itself does this, and there is no channel.
23
+ */
24
+ function stopChannelPath(pid, platform = process.platform) {
25
+ return platform === "win32" ? `\\\\.\\pipe\\ph-stop-${pid}` : void 0;
26
+ }
27
+ /** Calls `onStop` for each connection to `channel`. The server holds no
28
+ * process open, and one that cannot listen leaves the host running without
29
+ * a channel rather than not running. */
30
+ function listenForStop(channel, onStop) {
31
+ const server = net.createServer((socket) => {
32
+ socket.on("error", () => void 0);
33
+ socket.end();
34
+ onStop();
35
+ });
36
+ server.on("error", () => void 0);
37
+ server.listen(channel);
38
+ server.unref();
39
+ return server;
40
+ }
41
+ let installed = false;
42
+ /** What a host's process calls once before it starts anything: from then on
43
+ * {@link requestStop} reaches its SIGTERM handlers on every platform. */
44
+ function installStopChannel() {
45
+ const channel = stopChannelPath(process.pid);
46
+ if (!channel || installed) return;
47
+ installed = true;
48
+ listenForStop(channel, () => {
49
+ if (!process.emit("SIGTERM", "SIGTERM")) process.exit(143);
50
+ });
51
+ }
52
+ const ASK_TIMEOUT_MS = 2e3;
53
+ /** Connects to a stop channel; true once the listener took the request. */
54
+ function askToStop(channel, timeoutMs = ASK_TIMEOUT_MS) {
55
+ return new Promise((resolve) => {
56
+ let connected = false;
57
+ const socket = net.connect(channel);
58
+ socket.setTimeout(timeoutMs, () => socket.destroy());
59
+ socket.once("connect", () => connected = true);
60
+ socket.on("error", () => void 0);
61
+ socket.once("close", () => resolve(connected));
62
+ socket.resume();
63
+ });
64
+ }
65
+ /**
66
+ * Asks the process to stop as SIGTERM would. False when it could not be
67
+ * asked: on Windows a process without a stop channel (started by an older
68
+ * version, or not a host), which only a kill ends.
69
+ */
70
+ async function requestStop(pid, platform = process.platform) {
71
+ const channel = stopChannelPath(pid, platform);
72
+ if (channel) return askToStop(channel);
73
+ try {
74
+ process.kill(pid, "SIGTERM");
75
+ } catch {}
76
+ return true;
77
+ }
78
+ /** The `ph run` pipeline up to the verb, collecting every issue; starts nothing. */
79
+ async function checkHost(name, options) {
80
+ const result = {
81
+ issues: [],
82
+ warnings: [],
83
+ deferred: []
84
+ };
85
+ const file = `hosts/${name}/host.js`;
86
+ const issue = issuer(result, file);
87
+ const verb = options.verb ?? "run";
88
+ let host;
89
+ let runner;
90
+ try {
91
+ host = (await loadHost(options.projectRoot, name)).host;
92
+ runner = await resolveRunnerModule(options.projectRoot, host.runner.module);
93
+ } catch (error) {
94
+ issue("load", "", error);
95
+ return result;
96
+ }
97
+ const specifier = host.runner.module;
98
+ if (runner.kind === "compound") {
99
+ await checkCompound(result, options, {
100
+ file,
101
+ host,
102
+ runner,
103
+ specifier,
104
+ verb
105
+ });
106
+ return result;
107
+ }
108
+ const refs = outputRefsOf(host);
109
+ const producers = await loadProducers(options.projectRoot, refs);
110
+ await checkSubject(result, options, {
111
+ file,
112
+ host,
113
+ runner,
114
+ specifier,
115
+ verb,
116
+ outputsSchemaOf: producerOutputsSchemas(producers),
117
+ self: "outputs"
118
+ });
119
+ return result;
120
+ }
121
+ /** Declared validation; returns whether its tokens and its shape passed. */
122
+ function checkDeclared(result, subject, outputsSchemaOf) {
123
+ const issue = issuer(result, subject.file);
124
+ const { host, runner, specifier } = subject;
125
+ try {
126
+ getVerb(runner, specifier, subject.verb);
127
+ } catch (error) {
128
+ issue("declared", "", error);
129
+ }
130
+ const tokenIssues = [
131
+ ...findRemovedForms(host),
132
+ ...checkTokenSites(host),
133
+ ...outputsSchemaOf ? checkOutputPaths(host, outputsSchemaOf) : []
134
+ ];
135
+ for (const i of tokenIssues) issue("declared", i);
136
+ const shapeIssues = runner.declaredHostSchema ? schemaIssuesOf(runner, runner.declaredHostSchema, specifier, host, true) : kindShapeIssues(runner.kind, specifier, host);
137
+ for (const i of shapeIssues) issue("declared", i);
138
+ return {
139
+ tokens: tokenIssues.length === 0,
140
+ shape: shapeIssues.length === 0
141
+ };
142
+ }
143
+ function schemaIssuesOf(runner, schema, specifier, host, allowTokens) {
144
+ const checked = hostSchemaIssues(runner, schema, specifier, host, { tokens: allowTokens ? "allow" : "forbid" });
145
+ return [...checked.issues, ...checked.schemaIssues ?? []];
146
+ }
147
+ async function checkSubject(result, options, subject) {
148
+ const issue = issuer(result, subject.file);
149
+ const { runner, specifier, file } = subject;
150
+ const declared = checkDeclared(result, subject, subject.outputsSchemaOf);
151
+ const resolveEnv = processResolveEnv(options.projectRoot, options.env);
152
+ const patch = subject.patch ?? ((host) => host);
153
+ if (ONE_SHOT_VERBS.has(subject.verb)) {
154
+ if (!declared.tokens || !declared.shape) return;
155
+ const host = patch(substituteBuiltinEnv(subject.host, resolveEnv.builtins ?? {}));
156
+ const schema = runner.declaredHostSchema ?? runner.hostSchema;
157
+ for (const i of schemaIssuesOf(runner, schema, specifier, host, true)) issue("resolved", i);
158
+ return;
159
+ }
160
+ const unset = envSitesOf(subject.host).filter((site) => !site.optional && !isBuiltinEnvName(site.name) && options.env[site.name] === void 0);
161
+ for (const site of unset) issue("resolve", {
162
+ path: site.path,
163
+ message: unsetEnvMessage(site.name)
164
+ });
165
+ if (!declared.tokens || unset.length > 0) return;
166
+ let resolved;
167
+ let deferred = [];
168
+ try {
169
+ if (options.outputs) resolved = resolveHostOutputs(subject.host, {
170
+ outputs: options.outputs,
171
+ ...resolveEnv
172
+ });
173
+ else {
174
+ const partial = resolveHostOutputs(subject.host, resolveEnv, { deferSelf: subject.self });
175
+ resolved = partial.host;
176
+ deferred = partial.deferred;
177
+ }
178
+ } catch (error) {
179
+ if (error instanceof TokenResolutionError && error.detail) issue("resolve", {
180
+ path: error.detail.path,
181
+ message: error.detail.reason
182
+ });
183
+ else issue("resolve", "", error);
184
+ return;
185
+ }
186
+ result.deferred.push(...deferred.map((d) => ({
187
+ ...d,
188
+ file
189
+ })));
190
+ if (!declared.shape) return;
191
+ const allow = deferred.length > 0;
192
+ const schema = allow ? runner.declaredHostSchema ?? runner.hostSchema : runner.hostSchema;
193
+ const checked = hostSchemaIssues(runner, schema, specifier, patch(resolved), { tokens: allow ? "allow" : "forbid" });
194
+ const resolvedIssues = [...checked.issues, ...checked.schemaIssues ?? []];
195
+ for (const i of resolvedIssues) issue("resolved", i);
196
+ if (resolvedIssues.length > 0 || !runner.checkBoot) return;
197
+ try {
198
+ const boot = await runner.checkBoot(checked.data, {
199
+ projectRoot: options.projectRoot,
200
+ verb: subject.verb,
201
+ env: options.env,
202
+ file
203
+ });
204
+ for (const i of boot) issue("boot", {
205
+ ...i,
206
+ path: i.path ?? ""
207
+ });
208
+ } catch (error) {
209
+ issue("boot", "", error);
210
+ }
211
+ }
212
+ async function checkCompound(result, options, subject) {
213
+ const issue = issuer(result, subject.file);
214
+ const { host, runner, specifier } = subject;
215
+ const declared = checkDeclared(result, subject);
216
+ if (!declared.tokens || !declared.shape) return;
217
+ if (!runner.declaredHostSchema) {
218
+ const own = schemaIssuesOf(runner, runner.hostSchema, specifier, host, true);
219
+ for (const i of own) issue("resolved", i);
220
+ if (own.length > 0) return;
221
+ }
222
+ const children = isPlainObject(host.children) ? host.children : {};
223
+ const wiring = isPlainObject(host.config) ? host.config : {};
224
+ const verb = compoundStartVerb(subject.verb, host.runner);
225
+ const prepared = [];
226
+ for (const [key, member] of Object.entries(children)) try {
227
+ prepared.push(await prepareMember(options.projectRoot, key, member));
228
+ } catch (error) {
229
+ issuer(result, `hosts/${member.host}/host.js`)("load", "", error);
230
+ }
231
+ const members = Object.entries(children).map(([key, m]) => ({
232
+ key,
233
+ host: m.host
234
+ }));
235
+ if (prepared.length === members.length) try {
236
+ planCompound(prepared.map((m) => ({
237
+ key: m.key,
238
+ host: m.member.host,
239
+ refs: outputSitesOf(m.draft).map(({ ref, path }) => ({
240
+ ref,
241
+ path
242
+ }))
243
+ })), wiring.startOrder);
244
+ } catch (error) {
245
+ issue("declared", "", error);
246
+ }
247
+ result.warnings.push(...sharedPortWarnings(subject.file, prepared));
248
+ const byKey = new Map(prepared.map((m) => [m.key, m]));
249
+ const outputsSchemaOf = (ref) => {
250
+ const target = memberForRef(ref, members);
251
+ if ("error" in target) return { error: target.error };
252
+ const producer = byKey.get(target.key);
253
+ return producer ? runnerOutputsSchema(producer.runner, producer.specifier, `member "${target.key}"`) : { error: `names member "${target.key}", which was not prepared.` };
254
+ };
255
+ for (const m of prepared) {
256
+ const csp = wiring.cspRegistrySync === true && takesCspRegistrySync(m);
257
+ await checkSubject(result, options, {
258
+ file: m.file,
259
+ host: m.draft,
260
+ runner: m.runner,
261
+ specifier: m.specifier,
262
+ verb: memberVerbOf(verb, m.draft.runner),
263
+ outputsSchemaOf,
264
+ self: { members },
265
+ ...csp ? { patch: (resolved) => ({
266
+ ...resolved,
267
+ runner: {
268
+ ...resolved.runner,
269
+ cspRegistrySync: true
270
+ }
271
+ }) } : {}
272
+ });
273
+ }
274
+ }
275
+ const SWITCHBOARD_RUNNER = "@powerhousedao/ph-cli/runners/switchboard";
276
+ /** The port a member binds: its own literal, else its ph-cli runner's default. */
277
+ function boundPortOf(m) {
278
+ const port = m.draft.runner.port;
279
+ if (port === void 0) {
280
+ if (m.specifier === "@powerhousedao/ph-cli/runners/connect") return DEFAULT_CONNECT_STUDIO_PORT;
281
+ if (m.specifier === SWITCHBOARD_RUNNER) return DEFAULT_SWITCHBOARD_PORT;
282
+ return;
283
+ }
284
+ return typeof port === "number" && Number.isInteger(port) && port > 0 ? port : void 0;
285
+ }
286
+ /** Members binding one port: under `ph run` the later one moves or fails. */
287
+ function sharedPortWarnings(file, prepared) {
288
+ const owners = /* @__PURE__ */ new Map();
289
+ const warnings = [];
290
+ for (const m of prepared) {
291
+ const port = boundPortOf(m);
292
+ if (port === void 0) continue;
293
+ const other = owners.get(port);
294
+ if (!other) {
295
+ owners.set(port, m);
296
+ continue;
297
+ }
298
+ const connects = m.specifier === "@powerhousedao/ph-cli/runners/connect" && other.specifier === "@powerhousedao/ph-cli/runners/connect";
299
+ warnings.push({
300
+ stage: "declared",
301
+ file,
302
+ path: `children.${m.key}.runner.port`,
303
+ message: connects ? `${other.key} and ${m.key} both use port ${port}. One will move to the next free port and lose its browser data.` : `${other.key} and ${m.key} both use port ${port}. One will move to the next free port or fail to start.`
304
+ });
305
+ }
306
+ return warnings;
307
+ }
308
+ function issuer(result, file) {
309
+ return (stage, found, error) => {
310
+ if (typeof found !== "string") {
311
+ const { path, message, hint } = found;
312
+ result.issues.push({
313
+ stage,
314
+ file,
315
+ path,
316
+ message,
317
+ ...hint ? { hint } : {}
318
+ });
319
+ return;
320
+ }
321
+ const [message, hint] = (error instanceof Error ? error.message : String(error)).split("\n Hint: ");
322
+ result.issues.push({
323
+ stage,
324
+ file,
325
+ path: found,
326
+ message,
327
+ ...hint ? { hint } : {}
328
+ });
329
+ };
330
+ }
331
+ function isRecord$1(value) {
332
+ return typeof value === "object" && value !== null && !Array.isArray(value);
333
+ }
334
+ function childFolders$1(host) {
335
+ if (!isRecord$1(host) || !isRecord$1(host.children)) return [];
336
+ return Object.entries(host.children).flatMap(([key, child]) => isRecord$1(child) && typeof child.host === "string" ? [[key, child.host]] : []);
337
+ }
338
+ const declaredHostSchema = custom().superRefine((host, ctx) => {
339
+ const result = (isRecord$1(host) && "children" in host ? declaredHostSchemas.compoundHostSchema : declaredHostSchemas.reactorHostSchema).safeParse(host);
340
+ if (result.success) return;
341
+ for (const issue of result.error.issues) ctx.addIssue({
342
+ code: "custom",
343
+ message: issue.message,
344
+ path: issue.path
345
+ });
346
+ });
347
+ /** `ph host export`: a declared host plus its members, keyed by folder. */
348
+ const hostExportSchema = strictObject({
349
+ format: literal("ph-host-export"),
350
+ version: literal(1),
351
+ project: strictObject({
352
+ name: string().min(1),
353
+ root: string().min(1)
354
+ }),
355
+ name: string().min(1),
356
+ host: declaredHostSchema,
357
+ members: record(string(), declaredHostSchema)
358
+ }).superRefine((value, ctx) => {
359
+ const reached = /* @__PURE__ */ new Set();
360
+ const pending = [[["host"], value.host]];
361
+ for (let next = pending.shift(); next; next = pending.shift()) {
362
+ const [at, host] = next;
363
+ for (const [key, folder] of childFolders$1(host)) {
364
+ if (!(folder in value.members)) {
365
+ ctx.addIssue({
366
+ code: "custom",
367
+ path: [
368
+ ...at,
369
+ "children",
370
+ key,
371
+ "host"
372
+ ],
373
+ message: `Member folder "${folder}" is missing from members.`
374
+ });
375
+ continue;
376
+ }
377
+ if (reached.has(folder)) continue;
378
+ reached.add(folder);
379
+ pending.push([["members", folder], value.members[folder]]);
380
+ }
381
+ }
382
+ for (const folder of Object.keys(value.members)) {
383
+ if (reached.has(folder)) continue;
384
+ ctx.addIssue({
385
+ code: "custom",
386
+ path: ["members", folder],
387
+ message: `Member "${folder}" is not reached from the host's children.`
388
+ });
389
+ }
390
+ });
391
+ function checkHint(name) {
392
+ return `Run \`ph host check ${name}\`.`;
393
+ }
394
+ function childFolders(host, name) {
395
+ if (!("children" in host)) return [];
396
+ const parsed = declaredHostSchemas.childrenSchema.safeParse(host.children);
397
+ if (!parsed.success) throw new HostLoadError(`hosts/${name}/host.js: invalid \`children\`:\n${prettifyError(parsed.error)}`, checkHint(name));
398
+ return Object.values(parsed.data).map((child) => child.host);
399
+ }
400
+ /** A host as declared and every member it reaches, raw `loadHost` bodies. */
401
+ async function exportHost(projectRoot, name) {
402
+ const root = path.resolve(projectRoot);
403
+ const { host } = await loadHost(root, name);
404
+ const members = {};
405
+ const visit = async (folders) => {
406
+ for (const folder of folders) {
407
+ if (folder in members) continue;
408
+ const member = (await loadHost(root, folder)).host;
409
+ members[folder] = member;
410
+ await visit(childFolders(member, folder));
411
+ }
412
+ };
413
+ await visit(childFolders(host, name));
414
+ const envelope = {
415
+ format: "ph-host-export",
416
+ version: 1,
417
+ project: {
418
+ name: readProjectName(root),
419
+ root
420
+ },
421
+ name,
422
+ host,
423
+ members
424
+ };
425
+ const parsed = hostExportSchema.safeParse(JSON.parse(JSON.stringify(envelope)));
426
+ if (!parsed.success) throw new HostLoadError(`hosts/${name}/host.js: the export is not a valid host export:\n${prettifyError(parsed.error)}`, checkHint(name));
427
+ return envelope;
428
+ }
429
+ const sha256Hex = (input) => crypto.createHash("sha256").update(input).digest("hex");
430
+ function projectDriveId(projectRoot, slug) {
431
+ return projectDriveIdWith(sha256Hex, projectRoot, slug);
432
+ }
433
+ function resolveDriveDeclaration(projectRoot, decl) {
434
+ const id = decl.projectHash ? projectDriveId(projectRoot, decl.slug) : decl.id;
435
+ const slug = decl.projectHash === true ? id : decl.slug;
436
+ if (decl.remote) return {
437
+ kind: "remote",
438
+ id,
439
+ slug,
440
+ name: decl.name ?? decl.slug,
441
+ remoteUrl: decl.remote.url,
442
+ sharingType: decl.sharingType ?? "public",
443
+ availableOffline: decl.availableOffline ?? true
444
+ };
445
+ return {
446
+ kind: "local",
447
+ id,
448
+ slug,
449
+ documentType: decl.documentType,
450
+ name: decl.name ?? decl.slug,
451
+ icon: resolveImageRef(projectRoot, decl.icon, {
452
+ maxBytes: DRIVE_ICON_MAX_BYTES,
453
+ warn: (m) => console.warn(m)
454
+ }),
455
+ preferredEditor: decl.preferredEditor,
456
+ sharingType: decl.sharingType ?? "public",
457
+ availableOffline: decl.availableOffline ?? true
458
+ };
459
+ }
460
+ /** Merge host-declared drives with plugin contributions, slug-keyed — the
461
+ * host file wins on conflicts (it is the most explicit source). */
462
+ function mergeDrivePlan(projectRoot, hostDeclared, contributed) {
463
+ const plan = /* @__PURE__ */ new Map();
464
+ for (const { declaration, source } of contributed) {
465
+ const drive = resolveDriveDeclaration(projectRoot, declaration);
466
+ plan.set(drive.slug, {
467
+ drive,
468
+ source
469
+ });
470
+ }
471
+ for (const declaration of hostDeclared) {
472
+ const drive = resolveDriveDeclaration(projectRoot, declaration);
473
+ plan.set(drive.slug, {
474
+ drive,
475
+ source: "host"
476
+ });
477
+ }
478
+ return [...plan.values()];
479
+ }
480
+ function explainDrivePlan(plan) {
481
+ if (plan.length === 0) return "(no drives declared)";
482
+ return ["drives:", ...plan.map(({ drive, source }) => {
483
+ const kind = drive.kind === "remote" ? `remote ${drive.remoteUrl}` : "local";
484
+ const editor = drive.preferredEditor ? ` editor=${drive.preferredEditor}` : "";
485
+ const id = drive.id ?? "generated";
486
+ return ` ${drive.slug} (${kind}, id=${id}${editor}) [${source}]`;
487
+ })].join("\n");
488
+ }
489
+ /**
490
+ * Instance-fact projection for compound hosts: the drives a compound's
491
+ * reactor member created, projected into the Connect member's runtime-config
492
+ * override. Pure functions, moved from ph-cli's vetra service so the generic
493
+ * compound and the classic path share one implementation.
494
+ */
495
+ function isLocalDrive(drive) {
496
+ return "local" in drive;
497
+ }
498
+ const driveKey = (drive) => isLocalDrive(drive) ? `local:${drive.id}` : drive.url;
499
+ /**
500
+ * Concatenate groups of `connect.drives.defaultDrives` in the order given,
501
+ * de-duplicating by drive identity (URL for remote entries, id for local
502
+ * ones). The first occurrence of a drive wins, so earlier groups keep their
503
+ * position and metadata — e.g. the Vetra drive `ph vetra` starts stays first
504
+ * even when the project's `powerhouse.config.json` lists the same drive.
505
+ */
506
+ function mergeDefaultDrives(...groups) {
507
+ const seen = /* @__PURE__ */ new Set();
508
+ const out = [];
509
+ for (const group of groups) for (const drive of group) {
510
+ const key = driveKey(drive);
511
+ if (seen.has(key)) continue;
512
+ seen.add(key);
513
+ out.push(drive);
514
+ }
515
+ return out;
516
+ }
517
+ /**
518
+ * Rebase a local drive URL onto a public base: keeps the /d/<slug> path,
519
+ * swaps the loopback origin for the public base. Browser clients behind a
520
+ * reverse proxy can't reach http://localhost:<port>. Non-loopback URLs
521
+ * (e.g. a remote drive) are already public and pass through unchanged, as do
522
+ * unparseable ones.
523
+ */
524
+ function rebaseDriveUrl(driveUrl, publicBase) {
525
+ let url;
526
+ try {
527
+ url = new URL(driveUrl);
528
+ } catch {
529
+ return driveUrl;
530
+ }
531
+ if (![
532
+ "localhost",
533
+ "127.0.0.1",
534
+ "[::1]"
535
+ ].includes(url.hostname)) return driveUrl;
536
+ return `${publicBase.replace(/\/+$/, "")}${url.pathname}`;
537
+ }
538
+ //#endregion
539
+ export { mergeDefaultDrives as a, rebaseDriveUrl as c, installStopChannel as i, requestStop as l, explainDrivePlan as n, mergeDrivePlan as o, exportHost as r, projectDriveId as s, checkHost as t, resolveDriveDeclaration as u };
540
+
541
+ //# sourceMappingURL=dist-DXcB8fAF.mjs.map
542
+ //# debugId=0c9d00c4-c737-56e0-bf6f-c78db46b6bfc