@powerhousedao/ph-run 0.0.0-stage → 6.2.3-dev.89

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 (48) hide show
  1. package/LICENSE +661 -0
  2. package/dist/classic-args-BYccyIIC.mjs +33 -0
  3. package/dist/classic-args-BYccyIIC.mjs.map +1 -0
  4. package/dist/classic-args-Dm0_3O5p.d.mts +194 -0
  5. package/dist/classic-args-Dm0_3O5p.d.mts.map +1 -0
  6. package/dist/cli.d.mts +2 -0
  7. package/dist/cli.mjs +29 -0
  8. package/dist/cli.mjs.map +1 -0
  9. package/dist/connect-plugin-configs-CPRA8hQJ.mjs +47 -0
  10. package/dist/connect-plugin-configs-CPRA8hQJ.mjs.map +1 -0
  11. package/dist/connect-serve-0fIQ7xCs.mjs +187 -0
  12. package/dist/connect-serve-0fIQ7xCs.mjs.map +1 -0
  13. package/dist/connect-serve-B2u6WAdw.d.mts +62 -0
  14. package/dist/connect-serve-B2u6WAdw.d.mts.map +1 -0
  15. package/dist/member-config-BcEWRVq4.mjs +152 -0
  16. package/dist/member-config-BcEWRVq4.mjs.map +1 -0
  17. package/dist/runners/connect.d.mts +1263 -0
  18. package/dist/runners/connect.d.mts.map +1 -0
  19. package/dist/runners/connect.mjs +268 -0
  20. package/dist/runners/connect.mjs.map +1 -0
  21. package/dist/runners/member-config.d.mts +786 -0
  22. package/dist/runners/member-config.d.mts.map +1 -0
  23. package/dist/runners/member-config.mjs +2 -0
  24. package/dist/runners/switchboard.d.mts +1736 -0
  25. package/dist/runners/switchboard.d.mts.map +1 -0
  26. package/dist/runners/switchboard.mjs +704 -0
  27. package/dist/runners/switchboard.mjs.map +1 -0
  28. package/dist/services/classic-args.d.mts +3 -0
  29. package/dist/services/classic-args.mjs +2 -0
  30. package/dist/services/connect-serve.d.mts +3 -0
  31. package/dist/services/connect-serve.mjs +2 -0
  32. package/dist/services/connect-server.d.mts +26 -0
  33. package/dist/services/connect-server.d.mts.map +1 -0
  34. package/dist/services/connect-server.mjs +215 -0
  35. package/dist/services/connect-server.mjs.map +1 -0
  36. package/dist/services/run/start-run.d.mts +29 -0
  37. package/dist/services/run/start-run.d.mts.map +1 -0
  38. package/dist/services/run/start-run.mjs +2 -0
  39. package/dist/services/switchboard.d.mts +79 -0
  40. package/dist/services/switchboard.d.mts.map +1 -0
  41. package/dist/services/switchboard.mjs +188 -0
  42. package/dist/services/switchboard.mjs.map +1 -0
  43. package/dist/start-run-DWn2cVyi.mjs +122 -0
  44. package/dist/start-run-DWn2cVyi.mjs.map +1 -0
  45. package/dist/superseded-config-CpHrCuNq.mjs +50 -0
  46. package/dist/superseded-config-CpHrCuNq.mjs.map +1 -0
  47. package/package.json +93 -3
  48. package/README.md +0 -3
@@ -0,0 +1,188 @@
1
+ import { DEFAULT_DRIVE_ICON } from "@powerhousedao/shared/clis";
2
+ import { callerOverEnv } from "@powerhousedao/switchboard/config";
3
+ import { switchboardConfigFromEnv } from "@powerhousedao/switchboard/config/env";
4
+ import { addDefaultDrive } from "@powerhousedao/switchboard/utils";
5
+ import { initSwitchboardProcess, startSwitchboard as startSwitchboard$1 } from "@powerhousedao/switchboard/server";
6
+ import { createHash } from "node:crypto";
7
+ //#region src/utils/drive-icons.ts
8
+ /**
9
+ * Icon for the drives ph-cli creates, inlined as a data URI.
10
+ *
11
+ * This used to be an IPFS URL on a private gateway, which now answers 403 -
12
+ * and a drive stores its icon as a plain URL in document state, so the moment
13
+ * that URL rots every client renders a broken image, for as long as the drive
14
+ * exists. A public gateway would only move the problem: IPFS gateways are
15
+ * frequently overloaded, and a drive icon must not depend on the network at
16
+ * all.
17
+ *
18
+ * A data URI keeps the asset inside this package and inside the drive: no
19
+ * fetch, no gateway, no deploy-base or cross-origin question, and nothing to
20
+ * 404. A few hundred bytes - the size of the string below is the entire cost,
21
+ * paid once in the drive's state.
22
+ *
23
+ * Kept URL-encoded rather than base64 so the markup stays readable and
24
+ * reviewable (`#` must be `%23`; `<`, `>`, `"` and the CSS braces are legal
25
+ * enough in a data URI but are encoded so the value is also safe to paste
26
+ * into markup).
27
+ */
28
+ /** Encodes an SVG for use in a `data:` URI, smaller than base64 and readable. */
29
+ function svgDataUri(svg) {
30
+ return `data:image/svg+xml,${svg.replace(/\s+/g, " ").trim().replace(/%/g, "%25").replace(/#/g, "%23").replace(/</g, "%3C").replace(/>/g, "%3E").replace(/"/g, "%22").replace(/\{/g, "%7B").replace(/\}/g, "%7D")}`;
31
+ }
32
+ const PETALS = [
33
+ "M0 4.6C0 2.1 2.1 0 4.6 0h21.2c2.5 0 4.6 2.1 4.6 4.6v2.8c0 12.7-10.3 23-23 23H4.6C2.1 30.4 0 28.4 0 25.8V4.6Z",
34
+ "M33.6 56.6c0-12.7 10.3-23 23-23h2.8c2.5 0 4.6 2.1 4.6 4.6v21.2c0 2.5-2.1 4.6-4.6 4.6H38.2c-2.5 0-4.6-2.1-4.6-4.6v-2.8Z",
35
+ "M0 38.2c0-2.5 2.1-4.6 4.6-4.6h2.8c12.7 0 23 10.3 23 23v2.8c0 2.5-2.1 4.6-4.6 4.6H4.6C2.1 64 0 61.9 0 59.4V38.2Z",
36
+ "M33.6 4.6C33.6 2.1 35.6 0 38.2 0h21.2C61.9 0 64 2.1 64 4.6v21.2c0 2.5-2.1 4.6-4.6 4.6h-2.8c-12.7 0-23-10.3-23-23V4.6Z"
37
+ ];
38
+ /** Icon for the drives ph-cli creates. */
39
+ const POWERHOUSE_DRIVE_ICON = svgDataUri(`
40
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="32" height="32">
41
+ <style>
42
+ path { fill: #404345 }
43
+ @media (prefers-color-scheme: dark) { path { fill: #F3F5F7 } }
44
+ </style>
45
+ <path d="${PETALS[0]}"/>
46
+ <path d="${PETALS[1]}"/>
47
+ <path d="${PETALS[2]}"/>
48
+ <path d="${PETALS[3]}"/>
49
+ </svg>`);
50
+ //#endregion
51
+ //#region src/services/switchboard.ts
52
+ const EGRESS_ALLOW_ENV = "PH_WORKFLOWS_EGRESS_ALLOW_ADDRESSES";
53
+ const LOCALHOST_ADDRESSES = ["127.0.0.1/32", "::1/128"];
54
+ function allowLocalhostEgress(env = process.env) {
55
+ const current = (env[EGRESS_ALLOW_ENV] ?? "").split(",").map((entry) => entry.trim()).filter((entry) => entry !== "");
56
+ const missing = LOCALHOST_ADDRESSES.filter((address) => !current.includes(address));
57
+ if (missing.length > 0) env[EGRESS_ALLOW_ENV] = [...current, ...missing].join(",");
58
+ }
59
+ const defaultSwitchboardOptions = {
60
+ port: 4001,
61
+ drive: {
62
+ id: "powerhouse",
63
+ slug: "powerhouse",
64
+ global: {
65
+ name: "Powerhouse",
66
+ icon: DEFAULT_DRIVE_ICON
67
+ },
68
+ local: {
69
+ availableOffline: true,
70
+ listeners: [],
71
+ sharingType: "public",
72
+ triggers: []
73
+ }
74
+ },
75
+ mcp: true
76
+ };
77
+ function getDefaultVetraSwitchboardOptions(vetraDriveId) {
78
+ return {
79
+ port: 4001,
80
+ drive: {
81
+ id: vetraDriveId,
82
+ slug: vetraDriveId,
83
+ global: {
84
+ name: "Vetra",
85
+ icon: POWERHOUSE_DRIVE_ICON
86
+ },
87
+ preferredEditor: "vetra-drive-app",
88
+ local: {
89
+ availableOffline: true,
90
+ listeners: [],
91
+ sharingType: "public",
92
+ triggers: []
93
+ }
94
+ }
95
+ };
96
+ }
97
+ async function startSwitchboard(options, logger, base) {
98
+ const { readyAfter, ...serverOptions } = options;
99
+ const { config, finalOptions } = switchboardConfigOf(serverOptions, logger, base);
100
+ initSwitchboardProcess(config);
101
+ return await startSwitchboard$1(config, {
102
+ logger,
103
+ pluginComposition: finalOptions.pluginComposition,
104
+ signalHandlers: finalOptions.signalHandlers,
105
+ readyAfter,
106
+ fatalErrorShutdown: true
107
+ });
108
+ }
109
+ /** The server config a start runs with: the command's options over `base`. */
110
+ function switchboardConfigOf(options, logger, base) {
111
+ const { packages: packagesString, remoteDrives, useVetraDrive, vetraDriveId, useIdentity, keypairPath, requireIdentity, basePath, ...serverOptions } = options;
112
+ if (useVetraDrive || serverOptions.dev) allowLocalhostEgress();
113
+ const defaultOptions = useVetraDrive ? getDefaultVetraSwitchboardOptions(vetraDriveId) : defaultSwitchboardOptions;
114
+ const identity = useIdentity || keypairPath || requireIdentity ? {
115
+ keypairPath,
116
+ requireExisting: requireIdentity
117
+ } : void 0;
118
+ const packages = packagesString?.split(",");
119
+ const finalOptions = remoteDrives.length > 0 ? {
120
+ ...defaultOptions,
121
+ drive: void 0,
122
+ ...serverOptions,
123
+ remoteDrives,
124
+ identity,
125
+ packages,
126
+ logger
127
+ } : {
128
+ ...defaultOptions,
129
+ ...serverOptions,
130
+ remoteDrives,
131
+ identity,
132
+ packages,
133
+ logger
134
+ };
135
+ return {
136
+ config: callerOverEnv(base ?? switchboardConfigFromEnv(process.env, { logger }), configLayerOf(finalOptions, basePath)),
137
+ finalOptions
138
+ };
139
+ }
140
+ /** The keys of the server's options view this command sets, as a config layer. */
141
+ function configLayerOf(options, basePath) {
142
+ const dbPath = options.dbPath || void 0;
143
+ return {
144
+ server: {
145
+ basePath: basePath || void 0,
146
+ port: options.port,
147
+ strictPort: options.strictPort,
148
+ dev: options.dev,
149
+ https: options.https
150
+ },
151
+ storage: {
152
+ readModel: { url: dbPath },
153
+ reactor: { url: dbPath }
154
+ },
155
+ features: { mcp: options.mcp },
156
+ packages: {
157
+ list: options.packages,
158
+ disableLocal: options.disableLocalPackages
159
+ },
160
+ identity: options.identity,
161
+ drive: options.drive,
162
+ remoteDrives: options.remoteDrives,
163
+ processorConfig: options.processorConfig
164
+ };
165
+ }
166
+ /** A drive's id for this project: the same path always gives the same one. */
167
+ function projectDriveId(name, projectRoot) {
168
+ return `${name}-${createHash("sha256").update(projectRoot).digest("hex").substring(0, 8)}`;
169
+ }
170
+ /** The drive `reactor.workflows` seeds, the same one `ph vetra` does. */
171
+ async function seedWorkflowsDrive(reactor, port, projectRoot) {
172
+ return await addDefaultDrive(reactor, {
173
+ id: projectDriveId("workflows", projectRoot),
174
+ slug: "workflows",
175
+ global: { name: "Workflows" },
176
+ preferredEditor: "workflow-studio",
177
+ local: {
178
+ availableOffline: true,
179
+ listeners: [],
180
+ sharingType: "public",
181
+ triggers: []
182
+ }
183
+ }, port) ?? null;
184
+ }
185
+ //#endregion
186
+ export { POWERHOUSE_DRIVE_ICON, allowLocalhostEgress, defaultSwitchboardOptions, projectDriveId, seedWorkflowsDrive, startSwitchboard, switchboardConfigOf };
187
+
188
+ //# sourceMappingURL=switchboard.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"switchboard.mjs","names":["startSwitchboardServer"],"sources":["../../src/utils/drive-icons.ts","../../src/services/switchboard.ts"],"sourcesContent":["/**\n * Icon for the drives ph-cli creates, inlined as a data URI.\n *\n * This used to be an IPFS URL on a private gateway, which now answers 403 -\n * and a drive stores its icon as a plain URL in document state, so the moment\n * that URL rots every client renders a broken image, for as long as the drive\n * exists. A public gateway would only move the problem: IPFS gateways are\n * frequently overloaded, and a drive icon must not depend on the network at\n * all.\n *\n * A data URI keeps the asset inside this package and inside the drive: no\n * fetch, no gateway, no deploy-base or cross-origin question, and nothing to\n * 404. A few hundred bytes - the size of the string below is the entire cost,\n * paid once in the drive's state.\n *\n * Kept URL-encoded rather than base64 so the markup stays readable and\n * reviewable (`#` must be `%23`; `<`, `>`, `\"` and the CSS braces are legal\n * enough in a data URI but are encoded so the value is also safe to paste\n * into markup).\n */\n\n/** Encodes an SVG for use in a `data:` URI, smaller than base64 and readable. */\nfunction svgDataUri(svg: string): string {\n const compact = svg.replace(/\\s+/g, \" \").trim();\n return `data:image/svg+xml,${compact\n .replace(/%/g, \"%25\")\n .replace(/#/g, \"%23\")\n .replace(/</g, \"%3C\")\n .replace(/>/g, \"%3E\")\n .replace(/\"/g, \"%22\")\n .replace(/\\{/g, \"%7B\")\n .replace(/\\}/g, \"%7D\")}`;\n}\n\n// The Powerhouse mark: four petals on a 64 grid, each a square with one\n// quarter-circle bite taken out of its inner corner.\nconst PETALS = [\n \"M0 4.6C0 2.1 2.1 0 4.6 0h21.2c2.5 0 4.6 2.1 4.6 4.6v2.8c0 12.7-10.3 23-23 23H4.6C2.1 30.4 0 28.4 0 25.8V4.6Z\",\n \"M33.6 56.6c0-12.7 10.3-23 23-23h2.8c2.5 0 4.6 2.1 4.6 4.6v21.2c0 2.5-2.1 4.6-4.6 4.6H38.2c-2.5 0-4.6-2.1-4.6-4.6v-2.8Z\",\n \"M0 38.2c0-2.5 2.1-4.6 4.6-4.6h2.8c12.7 0 23 10.3 23 23v2.8c0 2.5-2.1 4.6-4.6 4.6H4.6C2.1 64 0 61.9 0 59.4V38.2Z\",\n \"M33.6 4.6C33.6 2.1 35.6 0 38.2 0h21.2C61.9 0 64 2.1 64 4.6v21.2c0 2.5-2.1 4.6-4.6 4.6h-2.8c-12.7 0-23-10.3-23-23V4.6Z\",\n];\n\n/** The mark in the light theme's grey. */\nconst LIGHT_FILL = \"#404345\";\n\n/** The mark in the dark theme's grey. */\nconst DARK_FILL = \"#F3F5F7\";\n\n// Drawn in one grey that follows the theme, so the icon sits in the sidebar\n// beside the single-tone `currentcolor` glyphs of the other drives instead of\n// competing with them.\n//\n// A data URI rendered through an `<img>` is its own document and cannot see\n// the host page's `.dark` class, so the theme is read from the embedded\n// document's own color scheme. That is the OS preference by default; the\n// renderer propagates an explicit in-app theme choice by setting\n// `color-scheme` on the `<img>`, which overrides it where the browser\n// supports the propagation.\nconst MARK_SVG = `\n<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 64 64\" width=\"32\" height=\"32\">\n <style>\n path { fill: ${LIGHT_FILL} }\n @media (prefers-color-scheme: dark) { path { fill: ${DARK_FILL} } }\n </style>\n <path d=\"${PETALS[0]}\"/>\n <path d=\"${PETALS[1]}\"/>\n <path d=\"${PETALS[2]}\"/>\n <path d=\"${PETALS[3]}\"/>\n</svg>`;\n\n/** Icon for the drives ph-cli creates. */\nexport const POWERHOUSE_DRIVE_ICON = svgDataUri(MARK_SVG);\n","import type { ResolvedPlugin } from \"@powerhousedao/host-core\";\nimport { DEFAULT_DRIVE_ICON } from \"@powerhousedao/shared/clis\";\nimport {\n callerOverEnv,\n type SwitchboardConfigInput,\n} from \"@powerhousedao/switchboard/config\";\nimport { switchboardConfigFromEnv } from \"@powerhousedao/switchboard/config/env\";\nimport { addDefaultDrive } from \"@powerhousedao/switchboard/utils\";\nimport {\n initSwitchboardProcess,\n startSwitchboard as startSwitchboardServer,\n type IdentityOptions,\n type StartServerOptions,\n} from \"@powerhousedao/switchboard/server\";\nimport type { ILogger } from \"document-model\";\nimport { createHash } from \"node:crypto\";\nimport type { SwitchboardArgs } from \"./classic-args.js\";\nimport { POWERHOUSE_DRIVE_ICON } from \"../utils/drive-icons.js\";\n\nexport { POWERHOUSE_DRIVE_ICON };\n\nconst EGRESS_ALLOW_ENV = \"PH_WORKFLOWS_EGRESS_ALLOW_ADDRESSES\";\nconst LOCALHOST_ADDRESSES = [\"127.0.0.1/32\", \"::1/128\"];\n\n// Lets pieces reach services on this machine, keeping any addresses already set\nexport function allowLocalhostEgress(env: NodeJS.ProcessEnv = process.env) {\n const current = (env[EGRESS_ALLOW_ENV] ?? \"\")\n .split(\",\")\n .map((entry) => entry.trim())\n .filter((entry) => entry !== \"\");\n const missing = LOCALHOST_ADDRESSES.filter(\n (address) => !current.includes(address),\n );\n if (missing.length > 0)\n env[EGRESS_ALLOW_ENV] = [...current, ...missing].join(\",\");\n}\n\n// No `dbPath` default here: the classic commands always carry the parsed\n// `dbPath` key (undefined without --db-path) and so always overrode it — the\n// server's own split defaults (`.ph/reactor-storage` for the reactor,\n// `.ph/read-storage` for the read model) are the legacy layout. A default\n// here resurfaces for any caller that omits the key and then names ONE dir\n// for both PGlite stores (two writers on one PGDATA).\nexport const defaultSwitchboardOptions = {\n port: 4001,\n drive: {\n id: \"powerhouse\",\n slug: \"powerhouse\",\n global: {\n name: \"Powerhouse\",\n icon: DEFAULT_DRIVE_ICON,\n },\n local: {\n availableOffline: true,\n listeners: [],\n sharingType: \"public\",\n triggers: [],\n },\n },\n mcp: true,\n} satisfies StartServerOptions;\n\nfunction getDefaultVetraSwitchboardOptions(\n vetraDriveId: string,\n): Partial<StartServerOptions> {\n return {\n port: 4001,\n drive: {\n id: vetraDriveId,\n slug: vetraDriveId,\n global: {\n name: \"Vetra\",\n icon: POWERHOUSE_DRIVE_ICON,\n },\n preferredEditor: \"vetra-drive-app\",\n local: {\n availableOffline: true,\n listeners: [],\n sharingType: \"public\",\n triggers: [],\n },\n },\n };\n}\n\nexport type StartSwitchboardOptions = Omit<SwitchboardArgs, \"mcp\"> & {\n /** A declared composition (R2) leaves this unset: the mcp plugin's presence sets it. */\n mcp?: boolean;\n /** `undefined` suppresses the default drive (declared drives replace it). */\n drive?: StartServerOptions[\"drive\"];\n strictPort?: boolean;\n processorConfig?: Map<string, unknown>;\n /** False under a supervising compound, which owns SIGINT/SIGTERM. */\n signalHandlers?: boolean;\n /** A declared composition (R2), resolved by the runner. */\n pluginComposition?: ResolvedPlugin[];\n /** Drives the caller seeds after start; `/ready` waits for them. */\n readyAfter?: Promise<unknown>;\n};\n\nexport async function startSwitchboard(\n options: StartSwitchboardOptions,\n logger?: ILogger,\n /** The layer under the command's options; default: this process's env. */\n base?: SwitchboardConfigInput,\n) {\n const { readyAfter, ...serverOptions } = options;\n const { config, finalOptions } = switchboardConfigOf(\n serverOptions,\n logger,\n base,\n );\n initSwitchboardProcess(config);\n const reactor = await startSwitchboardServer(config, {\n logger,\n pluginComposition: finalOptions.pluginComposition,\n signalHandlers: finalOptions.signalHandlers,\n readyAfter,\n fatalErrorShutdown: true,\n });\n\n return reactor;\n}\n\n/** The server config a start runs with: the command's options over `base`. */\nexport function switchboardConfigOf(\n options: StartSwitchboardOptions,\n logger?: ILogger,\n base?: SwitchboardConfigInput,\n): {\n config: SwitchboardConfigInput;\n finalOptions: StartServerOptions;\n} {\n const {\n packages: packagesString,\n remoteDrives,\n useVetraDrive,\n vetraDriveId,\n useIdentity,\n keypairPath,\n requireIdentity,\n basePath,\n ...serverOptions\n } = options;\n\n // Vetra and dev mode run against local services\n if (useVetraDrive || serverOptions.dev) allowLocalhostEgress();\n\n // Choose the appropriate default configuration\n const defaultOptions = useVetraDrive\n ? getDefaultVetraSwitchboardOptions(vetraDriveId)\n : defaultSwitchboardOptions;\n\n // Build identity options if enabled\n const identity: IdentityOptions | undefined =\n useIdentity || keypairPath || requireIdentity\n ? {\n keypairPath,\n requireExisting: requireIdentity,\n }\n : undefined;\n\n const packages = packagesString?.split(\",\");\n\n // Only include the default drive if no remote drives are provided\n const finalOptions =\n remoteDrives.length > 0\n ? {\n ...defaultOptions,\n drive: undefined, // Don't create default drive when syncing with remote\n ...serverOptions,\n remoteDrives,\n identity,\n packages,\n logger,\n }\n : {\n ...defaultOptions,\n ...serverOptions,\n remoteDrives,\n identity,\n packages,\n logger,\n };\n\n // The env (or the caller's base) under the command's own options.\n const config = callerOverEnv(\n base ?? switchboardConfigFromEnv(process.env, { logger }),\n configLayerOf(finalOptions, basePath),\n );\n return { config, finalOptions };\n}\n\n/** The keys of the server's options view this command sets, as a config layer. */\nfunction configLayerOf(\n options: StartServerOptions,\n basePath: string | undefined,\n): SwitchboardConfigInput {\n const dbPath = options.dbPath || undefined;\n return {\n server: {\n basePath: basePath || undefined,\n port: options.port,\n strictPort: options.strictPort,\n dev: options.dev,\n https: options.https,\n },\n storage: {\n // `dbPath` names both stores, over the env, as it did as an option.\n readModel: { url: dbPath },\n reactor: { url: dbPath },\n },\n features: { mcp: options.mcp },\n packages: {\n list: options.packages,\n disableLocal: options.disableLocalPackages,\n },\n identity: options.identity,\n drive: options.drive,\n remoteDrives: options.remoteDrives,\n processorConfig: options.processorConfig,\n };\n}\n\n/** A drive's id for this project: the same path always gives the same one. */\nexport function projectDriveId(name: string, projectRoot: string): string {\n const hash = createHash(\"sha256\").update(projectRoot).digest(\"hex\");\n return `${name}-${hash.substring(0, 8)}`;\n}\n\n/** The drive `reactor.workflows` seeds, the same one `ph vetra` does. */\nexport async function seedWorkflowsDrive(\n reactor: Parameters<typeof addDefaultDrive>[0],\n port: number,\n projectRoot: string,\n): Promise<string | null> {\n const driveUrl = await addDefaultDrive(\n reactor,\n {\n id: projectDriveId(\"workflows\", projectRoot),\n slug: \"workflows\",\n global: { name: \"Workflows\" },\n preferredEditor: \"workflow-studio\",\n local: {\n availableOffline: true,\n listeners: [],\n sharingType: \"public\" as const,\n triggers: [],\n },\n },\n port,\n );\n return driveUrl ?? null;\n}\n"],"mappings":"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"}
@@ -0,0 +1,122 @@
1
+ import { ONE_SHOT_VERBS, clearRunRecord, getVerb, isSchemaLike, loadHost, loadProducers, outputRefsOf, probeRun, processResolveEnv, producerOutputsSchemas, readProjectName, readRunRecord, resolveHostOutputs, resolveRunnerModule, runRecordOutputSource, toStartedHandle, validateDeclaredHost, validateHost, writeRunRecord } from "@powerhousedao/host-core";
2
+ //#region src/services/run/start-run.ts
3
+ /**
4
+ * `ph run <host> [verb]`: dispatch the verb (default `run`) of the host's
5
+ * declared runner. There is deliberately no type→runner registry — what a
6
+ * host does is written in its own file.
7
+ *
8
+ * The pipeline (typed-host-configs 3.5): declared validation (token shapes,
9
+ * `$output` paths against the producers' outputsSchemas, the runner's
10
+ * declaredHostSchema), the live-instance lock, resolution (`$output` from
11
+ * the producers' live run records, `$env` from this process, the
12
+ * `${userData}` sugar), resolved validation, then the verb with the parsed
13
+ * host. A compound runner gets its declared host: its members resolve their
14
+ * own tokens as they start.
15
+ *
16
+ * A reactor runner that exports `outputsSchema` has its handle's outputs
17
+ * published in a v2 `.ph/run/<name>.json` record once ready; this is the only
18
+ * standalone writer (mastra included). Compounds write their own record with
19
+ * the members in it; one-shot verbs (`build`) return nothing and write none.
20
+ */
21
+ async function startRun(args) {
22
+ if (ONE_SHOT_VERBS.has(args.verb ?? "run")) process.env.NODE_ENV ??= "production";
23
+ const projectRoot = args.projectRoot ?? process.cwd();
24
+ const loaded = await loadHost(projectRoot, args.host);
25
+ const { warnSupersededConfigKeys } = await import("./superseded-config-CpHrCuNq.mjs");
26
+ warnSupersededConfigKeys(projectRoot);
27
+ const specifier = loaded.host.runner.module;
28
+ const runner = await resolveRunnerModule(projectRoot, specifier);
29
+ const verb = args.verb ?? "run";
30
+ const fn = getVerb(runner, specifier, verb);
31
+ const file = loaded.file;
32
+ if (args.debug) console.log({
33
+ host: loaded.host.name,
34
+ runner: specifier,
35
+ verb
36
+ });
37
+ if (runner.kind === "compound") {
38
+ validateDeclaredHost(runner, specifier, loaded.host, file);
39
+ return fn(validateHost(runner, specifier, loaded.host, file, { tokens: "allow" }), {
40
+ projectRoot,
41
+ verb,
42
+ env: process.env
43
+ });
44
+ }
45
+ const projectName = readProjectName(projectRoot);
46
+ const producers = await loadProducers(projectRoot, outputRefsOf(loaded.host));
47
+ validateDeclaredHost(runner, specifier, loaded.host, file, { outputsSchemaOf: producerOutputsSchemas(producers) });
48
+ if (ONE_SHOT_VERBS.has(verb)) return fn(validateHost(runner, specifier, loaded.host, file, { tokens: "allow" }), {
49
+ projectRoot,
50
+ verb,
51
+ env: process.env
52
+ });
53
+ const publishes = isSchemaLike(runner.outputsSchema);
54
+ if (publishes) assertNotRunning(projectRoot, loaded.host.name, projectName);
55
+ const resolved = resolveHostOutputs(loaded.host, {
56
+ outputs: runRecordOutputSource(projectRoot, {
57
+ consumer: args.host,
58
+ producers,
59
+ projectName
60
+ }),
61
+ ...processResolveEnv(projectRoot),
62
+ where: `hosts/${args.host}/host.js`
63
+ });
64
+ const result = await fn(validateHost(runner, specifier, resolved, file), {
65
+ projectRoot,
66
+ verb,
67
+ env: process.env
68
+ });
69
+ if (publishes && result !== void 0 && result !== null) await publishOutputs(runner, result, {
70
+ projectRoot,
71
+ projectName,
72
+ hostName: loaded.host.name,
73
+ specifier,
74
+ verb
75
+ });
76
+ return result;
77
+ }
78
+ function assertNotRunning(projectRoot, hostName, projectName) {
79
+ const probe = probeRun(projectRoot, hostName, projectName);
80
+ if (probe.status === "live" && probe.record.pid !== process.pid) throw new Error(`${hostName} is already running for this project (pid ${probe.record.pid}). Stop it before starting another.`);
81
+ if (probe.status === "foreign") throw new Error(`.ph/run/${hostName}.json describes a live "${probe.record.projectName}", but this project is "${projectName}". Refusing to start a second instance.`);
82
+ }
83
+ /** Await `ready`, validate the outputs, write the v2 record and clear it on
84
+ * exit. A handle that never gets ready or reports invalid outputs is shut
85
+ * down before the error propagates. */
86
+ async function publishOutputs(runner, result, target) {
87
+ const where = `${target.specifier} ${target.verb}`;
88
+ const handle = toStartedHandle(result, where);
89
+ const name = target.projectName;
90
+ let outputs;
91
+ try {
92
+ if (!isSchemaLike(runner.outputsSchema)) return;
93
+ assertNotRunning(target.projectRoot, target.hostName, name);
94
+ if (handle.ready) await handle.ready;
95
+ const parsed = runner.outputsSchema.safeParse(handle.outputs);
96
+ if (!parsed.success) {
97
+ const issues = parsed.error.issues.map((issue) => ` - ${issue.path.map(String).join(".") || "<root>"}: ${issue.message}`).join("\n");
98
+ throw new Error(`${where} reported outputs that fail its outputsSchema:\n${issues}`);
99
+ }
100
+ outputs = parsed.data;
101
+ } catch (error) {
102
+ await handle.shutdown?.();
103
+ throw error;
104
+ }
105
+ writeRunRecord(target.projectRoot, {
106
+ version: 2,
107
+ host: target.hostName,
108
+ projectName: name,
109
+ kind: "reactor",
110
+ verb: target.verb,
111
+ pid: process.pid,
112
+ startedAt: (/* @__PURE__ */ new Date()).toISOString(),
113
+ outputs
114
+ });
115
+ process.on("exit", () => {
116
+ if (readRunRecord(target.projectRoot, target.hostName)?.pid === process.pid) clearRunRecord(target.projectRoot, target.hostName);
117
+ });
118
+ }
119
+ //#endregion
120
+ export { startRun as t };
121
+
122
+ //# sourceMappingURL=start-run-DWn2cVyi.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"start-run-DWn2cVyi.mjs","names":[],"sources":["../src/services/run/start-run.ts"],"sourcesContent":["import {\n clearRunRecord,\n getVerb,\n isSchemaLike,\n loadHost,\n loadProducers,\n ONE_SHOT_VERBS,\n outputRefsOf,\n probeRun,\n processResolveEnv,\n producerOutputsSchemas,\n readProjectName,\n readRunRecord,\n resolveHostOutputs,\n resolveRunnerModule,\n runRecordOutputSource,\n toStartedHandle,\n validateDeclaredHost,\n validateHost,\n writeRunRecord,\n type RunnerModule,\n} from \"@powerhousedao/host-core\";\n\nexport interface StartRunArgs {\n host: string;\n verb?: string;\n projectRoot?: string;\n debug?: boolean;\n}\n\n/**\n * `ph run <host> [verb]`: dispatch the verb (default `run`) of the host's\n * declared runner. There is deliberately no type→runner registry — what a\n * host does is written in its own file.\n *\n * The pipeline (typed-host-configs 3.5): declared validation (token shapes,\n * `$output` paths against the producers' outputsSchemas, the runner's\n * declaredHostSchema), the live-instance lock, resolution (`$output` from\n * the producers' live run records, `$env` from this process, the\n * `${userData}` sugar), resolved validation, then the verb with the parsed\n * host. A compound runner gets its declared host: its members resolve their\n * own tokens as they start.\n *\n * A reactor runner that exports `outputsSchema` has its handle's outputs\n * published in a v2 `.ph/run/<name>.json` record once ready; this is the only\n * standalone writer (mastra included). Compounds write their own record with\n * the members in it; one-shot verbs (`build`) return nothing and write none.\n */\nexport async function startRun(args: StartRunArgs): Promise<unknown> {\n // Loading a host loads its plugins, and React settles on its development or\n // production build the first time it's loaded. `vite build` sets NODE_ENV only\n // after that, so a build would run one half of React with the other half's\n // renderer (TypeError: dispatcher.getOwner is not a function).\n if (ONE_SHOT_VERBS.has(args.verb ?? \"run\")) {\n process.env.NODE_ENV ??= \"production\";\n }\n const projectRoot = args.projectRoot ?? process.cwd();\n const loaded = await loadHost(projectRoot, args.host);\n const { warnSupersededConfigKeys } = await import(\"./superseded-config.js\");\n warnSupersededConfigKeys(projectRoot);\n const specifier = loaded.host.runner.module;\n const runner = await resolveRunnerModule(projectRoot, specifier);\n const verb = args.verb ?? \"run\";\n const fn = getVerb(runner, specifier, verb);\n const file = loaded.file;\n if (args.debug) {\n console.log({ host: loaded.host.name, runner: specifier, verb });\n }\n\n if (runner.kind === \"compound\") {\n validateDeclaredHost(runner, specifier, loaded.host, file);\n const host = validateHost(runner, specifier, loaded.host, file, {\n tokens: \"allow\",\n });\n return fn(host, { projectRoot, verb, env: process.env });\n }\n\n const projectName = readProjectName(projectRoot);\n const producers = await loadProducers(projectRoot, outputRefsOf(loaded.host));\n validateDeclaredHost(runner, specifier, loaded.host, file, {\n outputsSchemaOf: producerOutputsSchemas(producers),\n });\n const oneShot = ONE_SHOT_VERBS.has(verb);\n if (oneShot) {\n // `build` reads no other host's outputs: no producer needs to run.\n const host = validateHost(runner, specifier, loaded.host, file, {\n tokens: \"allow\",\n });\n return fn(host, { projectRoot, verb, env: process.env });\n }\n const publishes = isSchemaLike(runner.outputsSchema);\n // Before the verb starts anything: a second live instance would take\n // over the first one's record (and clear it on exit).\n if (publishes) assertNotRunning(projectRoot, loaded.host.name, projectName);\n const resolved = resolveHostOutputs(loaded.host, {\n outputs: runRecordOutputSource(projectRoot, {\n consumer: args.host,\n producers,\n projectName,\n }),\n ...processResolveEnv(projectRoot),\n where: `hosts/${args.host}/host.js`,\n });\n const host = validateHost(runner, specifier, resolved, file);\n const result = await fn(host, { projectRoot, verb, env: process.env });\n if (publishes && result !== undefined && result !== null) {\n await publishOutputs(runner, result, {\n projectRoot,\n projectName,\n hostName: loaded.host.name,\n specifier,\n verb,\n });\n }\n return result;\n}\n\nfunction assertNotRunning(\n projectRoot: string,\n hostName: string,\n projectName: string,\n): void {\n const probe = probeRun(projectRoot, hostName, projectName);\n if (probe.status === \"live\" && probe.record.pid !== process.pid) {\n throw new Error(\n `${hostName} is already running for this project (pid ${probe.record.pid}). Stop it before starting another.`,\n );\n }\n if (probe.status === \"foreign\") {\n throw new Error(\n `.ph/run/${hostName}.json describes a live \"${probe.record.projectName}\", but this project is \"${projectName}\". Refusing to start a second instance.`,\n );\n }\n}\n\ninterface PublishTarget {\n projectRoot: string;\n projectName: string;\n hostName: string;\n specifier: string;\n verb: string;\n}\n\n/** Await `ready`, validate the outputs, write the v2 record and clear it on\n * exit. A handle that never gets ready or reports invalid outputs is shut\n * down before the error propagates. */\nasync function publishOutputs(\n runner: RunnerModule,\n result: unknown,\n target: PublishTarget,\n): Promise<void> {\n const where = `${target.specifier} ${target.verb}`;\n const handle = toStartedHandle(result, where);\n const name = target.projectName;\n let outputs: unknown;\n try {\n if (!isSchemaLike(runner.outputsSchema)) return;\n // Checked again after the start: an instance that started meanwhile.\n assertNotRunning(target.projectRoot, target.hostName, name);\n if (handle.ready) await handle.ready;\n const parsed = runner.outputsSchema.safeParse(handle.outputs);\n if (!parsed.success) {\n const issues = parsed.error.issues\n .map(\n (issue) =>\n ` - ${issue.path.map(String).join(\".\") || \"<root>\"}: ${issue.message}`,\n )\n .join(\"\\n\");\n throw new Error(\n `${where} reported outputs that fail its outputsSchema:\\n${issues}`,\n );\n }\n outputs = parsed.data;\n } catch (error) {\n await handle.shutdown?.();\n throw error;\n }\n\n writeRunRecord(target.projectRoot, {\n version: 2,\n host: target.hostName,\n projectName: name,\n kind: \"reactor\",\n verb: target.verb,\n pid: process.pid,\n startedAt: new Date().toISOString(),\n outputs: outputs as Record<string, unknown>,\n });\n // No SIGINT/SIGTERM handler: the switchboard reactor's own handler kills\n // the reactor before draining the api, and a parallel shutdown() would\n // break that order. Without an exit event the record keeps a dead pid,\n // which probeRun reports as stale.\n process.on(\"exit\", () => {\n if (readRunRecord(target.projectRoot, target.hostName)?.pid === process.pid)\n clearRunRecord(target.projectRoot, target.hostName);\n });\n}\n"],"mappings":"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"}
@@ -0,0 +1,50 @@
1
+ import path from "node:path";
2
+ import fs from "node:fs";
3
+ //#region src/services/run/superseded-config.ts
4
+ /**
5
+ * P2.7 — the fixed legacy→hosts mapping table. With hosts/ active, these
6
+ * powerhouse.config.json keys are superseded by host.js structure and the run
7
+ * path ignores them; each present key warns ONCE per run, naming its new home.
8
+ *
9
+ * Keys the scaffolded host files REFERENCE (studio.port, reactor.port,
10
+ * vetra.connectPort, assistant.port, and the WHOLE connect.* block — handed to the runtime
11
+ * unchanged, connect.instance.* included) are expected to remain and are
12
+ * deliberately absent from this table.
13
+ */
14
+ const SUPERSEDED = {
15
+ "studio.host": "hosts/connect/host.js → runner.host",
16
+ "studio.https": "hosts/connect/host.js → runner.https",
17
+ "studio.openBrowser": "hosts/connect/host.js → runner.openBrowser",
18
+ "reactor.https": "hosts/switchboard/host.js → runner.https",
19
+ "reactor.storage": "hosts/switchboard/host.js → reactor.backends.<name>.storage",
20
+ "switchboard.database.url": "hosts/switchboard/host.js → reactor.backends.<name>.storage.url"
21
+ };
22
+ function lookup(config, dottedKey) {
23
+ let cursor = config;
24
+ for (const part of dottedKey.split(".")) {
25
+ if (cursor === null || typeof cursor !== "object") return void 0;
26
+ cursor = cursor[part];
27
+ }
28
+ return cursor;
29
+ }
30
+ /** Warn once per run for each superseded key present in the project config.
31
+ * Returns the warned keys (for tests). Never throws — a malformed config is
32
+ * the loader's problem, not the warner's. */
33
+ function warnSupersededConfigKeys(projectRoot, warn = console.warn) {
34
+ let config;
35
+ try {
36
+ config = JSON.parse(fs.readFileSync(path.join(projectRoot, "powerhouse.config.json"), "utf8"));
37
+ } catch {
38
+ return [];
39
+ }
40
+ const warned = [];
41
+ for (const [key, newHome] of Object.entries(SUPERSEDED)) if (lookup(config, key) !== void 0) {
42
+ warned.push(key);
43
+ warn(`[ph run] powerhouse.config.json "${key}" is ignored in hosts projects — its home is now ${newHome}.`);
44
+ }
45
+ return warned;
46
+ }
47
+ //#endregion
48
+ export { warnSupersededConfigKeys };
49
+
50
+ //# sourceMappingURL=superseded-config-CpHrCuNq.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"superseded-config-CpHrCuNq.mjs","names":[],"sources":["../src/services/run/superseded-config.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\n\n/**\n * P2.7 — the fixed legacy→hosts mapping table. With hosts/ active, these\n * powerhouse.config.json keys are superseded by host.js structure and the run\n * path ignores them; each present key warns ONCE per run, naming its new home.\n *\n * Keys the scaffolded host files REFERENCE (studio.port, reactor.port,\n * vetra.connectPort, assistant.port, and the WHOLE connect.* block — handed to the runtime\n * unchanged, connect.instance.* included) are expected to remain and are\n * deliberately absent from this table.\n */\nconst SUPERSEDED: Record<string, string> = {\n \"studio.host\": \"hosts/connect/host.js → runner.host\",\n \"studio.https\": \"hosts/connect/host.js → runner.https\",\n \"studio.openBrowser\": \"hosts/connect/host.js → runner.openBrowser\",\n \"reactor.https\": \"hosts/switchboard/host.js → runner.https\",\n \"reactor.storage\":\n \"hosts/switchboard/host.js → reactor.backends.<name>.storage\",\n \"switchboard.database.url\":\n \"hosts/switchboard/host.js → reactor.backends.<name>.storage.url\",\n};\n\nfunction lookup(config: unknown, dottedKey: string): unknown {\n let cursor: unknown = config;\n for (const part of dottedKey.split(\".\")) {\n if (cursor === null || typeof cursor !== \"object\") return undefined;\n cursor = (cursor as Record<string, unknown>)[part];\n }\n return cursor;\n}\n\n/** Warn once per run for each superseded key present in the project config.\n * Returns the warned keys (for tests). Never throws — a malformed config is\n * the loader's problem, not the warner's. */\nexport function warnSupersededConfigKeys(\n projectRoot: string,\n warn: (message: string) => void = console.warn,\n): string[] {\n let config: unknown;\n try {\n config = JSON.parse(\n fs.readFileSync(path.join(projectRoot, \"powerhouse.config.json\"), \"utf8\"),\n );\n } catch {\n return [];\n }\n const warned: string[] = [];\n for (const [key, newHome] of Object.entries(SUPERSEDED)) {\n if (lookup(config, key) !== undefined) {\n warned.push(key);\n warn(\n `[ph run] powerhouse.config.json \"${key}\" is ignored in hosts projects — ` +\n `its home is now ${newHome}.`,\n );\n }\n }\n return warned;\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,MAAM,aAAqC;CACzC,eAAe;CACf,gBAAgB;CAChB,sBAAsB;CACtB,iBAAiB;CACjB,mBACE;CACF,4BACE;AACJ;AAEA,SAAS,OAAO,QAAiB,WAA4B;CAC3D,IAAI,SAAkB;CACtB,KAAK,MAAM,QAAQ,UAAU,MAAM,GAAG,GAAG;EACvC,IAAI,WAAW,QAAQ,OAAO,WAAW,UAAU,OAAO,KAAA;EAC1D,SAAU,OAAmC;CAC/C;CACA,OAAO;AACT;;;;AAKA,SAAgB,yBACd,aACA,OAAkC,QAAQ,MAChC;CACV,IAAI;CACJ,IAAI;EACF,SAAS,KAAK,MACZ,GAAG,aAAa,KAAK,KAAK,aAAa,wBAAwB,GAAG,MAAM,CAC1E;CACF,QAAQ;EACN,OAAO,CAAC;CACV;CACA,MAAM,SAAmB,CAAC;CAC1B,KAAK,MAAM,CAAC,KAAK,YAAY,OAAO,QAAQ,UAAU,GACpD,IAAI,OAAO,QAAQ,GAAG,MAAM,KAAA,GAAW;EACrC,OAAO,KAAK,GAAG;EACf,KACE,oCAAoC,IAAI,mDACnB,QAAQ,EAC/B;CACF;CAEF,OAAO;AACT"}
package/package.json CHANGED
@@ -1,6 +1,96 @@
1
1
  {
2
2
  "name": "@powerhousedao/ph-run",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "6.2.3-dev.89",
4
+ "description": "Runs a project's hosts, with none of the tools that build one",
5
+ "license": "AGPL-3.0-only",
6
+ "type": "module",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/powerhouse-inc/powerhouse"
10
+ },
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "engines": {
15
+ "node": ">=24.0.0"
16
+ },
17
+ "bin": {
18
+ "ph-run": "./dist/cli.mjs"
19
+ },
20
+ "exports": {
21
+ "./package.json": "./package.json",
22
+ "./runners/connect": {
23
+ "source": "./src/runners/connect.ts",
24
+ "types": "./dist/runners/connect.d.mts",
25
+ "import": "./dist/runners/connect.mjs",
26
+ "default": "./dist/runners/connect.mjs"
27
+ },
28
+ "./runners/switchboard": {
29
+ "source": "./src/runners/switchboard.ts",
30
+ "types": "./dist/runners/switchboard.d.mts",
31
+ "import": "./dist/runners/switchboard.mjs",
32
+ "default": "./dist/runners/switchboard.mjs"
33
+ },
34
+ "./classic-args": {
35
+ "source": "./src/services/classic-args.ts",
36
+ "types": "./dist/services/classic-args.d.mts",
37
+ "import": "./dist/services/classic-args.mjs",
38
+ "default": "./dist/services/classic-args.mjs"
39
+ },
40
+ "./connect-serve": {
41
+ "source": "./src/services/connect-serve.ts",
42
+ "types": "./dist/services/connect-serve.d.mts",
43
+ "import": "./dist/services/connect-serve.mjs",
44
+ "default": "./dist/services/connect-serve.mjs"
45
+ },
46
+ "./connect-server": {
47
+ "source": "./src/services/connect-server.ts",
48
+ "types": "./dist/services/connect-server.d.mts",
49
+ "import": "./dist/services/connect-server.mjs",
50
+ "default": "./dist/services/connect-server.mjs"
51
+ },
52
+ "./member-config": {
53
+ "source": "./src/runners/member-config.ts",
54
+ "types": "./dist/runners/member-config.d.mts",
55
+ "import": "./dist/runners/member-config.mjs",
56
+ "default": "./dist/runners/member-config.mjs"
57
+ },
58
+ "./start-run": {
59
+ "source": "./src/services/run/start-run.ts",
60
+ "types": "./dist/services/run/start-run.d.mts",
61
+ "import": "./dist/services/run/start-run.mjs",
62
+ "default": "./dist/services/run/start-run.mjs"
63
+ },
64
+ "./switchboard": {
65
+ "source": "./src/services/switchboard.ts",
66
+ "types": "./dist/services/switchboard.d.mts",
67
+ "import": "./dist/services/switchboard.mjs",
68
+ "default": "./dist/services/switchboard.mjs"
69
+ }
70
+ },
71
+ "files": [
72
+ "dist"
73
+ ],
74
+ "dependencies": {
75
+ "@powerhousedao/config": "6.2.3-dev.89",
76
+ "@powerhousedao/host-core": "6.2.3-dev.89",
77
+ "@powerhousedao/reactor": "6.2.3-dev.89",
78
+ "@powerhousedao/shared": "6.2.3-dev.89",
79
+ "@powerhousedao/switchboard": "6.2.3-dev.89",
80
+ "cmd-ts": "0.15.0",
81
+ "document-model": "6.2.3-dev.89",
82
+ "dotenv": "16.4.7",
83
+ "sirv": "^3.0.2",
84
+ "zod": "^4.5.4"
85
+ },
86
+ "devDependencies": {
87
+ "@types/node": "25.2.3",
88
+ "tsdown": "0.23.0"
89
+ },
90
+ "scripts": {
91
+ "tsc": "tsc",
92
+ "lint": "cd ../.. && oxlint clis/ph-run",
93
+ "test": "vitest --run",
94
+ "build": "tsdown"
95
+ }
6
96
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.