@powerhousedao/ph-cli 6.3.0-dev.9 → 6.4.0-next.0
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.
- package/dist/{build-DuNe06I0.mjs → build-D8_USaRh.mjs} +88 -16
- package/dist/build-D8_USaRh.mjs.map +1 -0
- package/dist/build-FVWjguYr.mjs +4 -0
- package/dist/{check-VOIkykDt.mjs → check-CVRb-CJD.mjs} +3 -3
- package/dist/{check-B8oqVMg7.mjs → check-EpzhIKt1.mjs} +4 -4
- package/dist/{check-B8oqVMg7.mjs.map → check-EpzhIKt1.mjs.map} +1 -1
- package/dist/{check-EzkmRLx6.mjs → check-_K6EAsag.mjs} +4 -4
- package/dist/{check-EzkmRLx6.mjs.map → check-_K6EAsag.mjs.map} +1 -1
- package/dist/{cli-connect-override-D22yFWlC.mjs → cli-connect-override-DwlViDdp.mjs} +5 -5
- package/dist/{cli-connect-override-D22yFWlC.mjs.map → cli-connect-override-DwlViDdp.mjs.map} +1 -1
- package/dist/cli.mjs +15 -31
- package/dist/cli.mjs.map +1 -1
- package/dist/{compound-DKi56SSx-CXQHhS6t.mjs → compound-n-bO0qKh-Dx7fgKWx.mjs} +658 -275
- package/dist/compound-n-bO0qKh-Dx7fgKWx.mjs.map +1 -0
- package/dist/{connect-build-Be8C4skj.mjs → connect-build-BIkm5fcG.mjs} +6 -6
- package/dist/{connect-build-Be8C4skj.mjs.map → connect-build-BIkm5fcG.mjs.map} +1 -1
- package/dist/{connect-config-CVU4xhti.mjs → connect-config-CH0KQqyU.mjs} +4 -4
- package/dist/{connect-config-CVU4xhti.mjs.map → connect-config-CH0KQqyU.mjs.map} +1 -1
- package/dist/{connect-preview-CdFvlANO.mjs → connect-preview-BvxXGo_W.mjs} +7 -6
- package/dist/connect-preview-BvxXGo_W.mjs.map +1 -0
- package/dist/{connect-studio-BnfhpIv8.mjs → connect-studio-C-9WE2Bg.mjs} +16 -7
- package/dist/connect-studio-C-9WE2Bg.mjs.map +1 -0
- package/dist/definitions-worker.mjs +1 -1
- package/dist/{dist-DXcB8fAF.mjs → dist-Dbvm_SmC.mjs} +51 -104
- package/dist/dist-Dbvm_SmC.mjs.map +1 -0
- package/dist/{explain-8OEXF2Dy.mjs → explain-DB7uoJkY.mjs} +67 -21
- package/dist/explain-DB7uoJkY.mjs.map +1 -0
- package/dist/{export-DqbcbFU5.mjs → export-DuYGBuQZ.mjs} +4 -4
- package/dist/{export-DqbcbFU5.mjs.map → export-DuYGBuQZ.mjs.map} +1 -1
- package/dist/{generate-all-0YOnlZM0.mjs → generate-all-Mj_xGZZN.mjs} +4 -4
- package/dist/{generate-all-0YOnlZM0.mjs.map → generate-all-Mj_xGZZN.mjs.map} +1 -1
- package/dist/{generate-desktop-shell-BovoRsR6.mjs → generate-desktop-shell-DD9o4Rcl.mjs} +7 -17
- package/dist/generate-desktop-shell-DD9o4Rcl.mjs.map +1 -0
- package/dist/{get-version-JkZQOcO1.mjs → get-version-DXnnvS_S.mjs} +4 -4
- package/dist/{get-version-JkZQOcO1.mjs.map → get-version-DXnnvS_S.mjs.map} +1 -1
- package/dist/{index-H3AYe65i.d.mts → index-V7TKBh-y.d.mts} +57 -3
- package/dist/index-V7TKBh-y.d.mts.map +1 -0
- package/dist/{inspect-zWJnBDMJ.mjs → inspect-Bxa9y7zM.mjs} +4 -4
- package/dist/{inspect-zWJnBDMJ.mjs.map → inspect-Bxa9y7zM.mjs.map} +1 -1
- package/dist/{mcp-vSCc5KHI.mjs → mcp-DKqOFZlX.mjs} +7 -7
- package/dist/mcp-DKqOFZlX.mjs.map +1 -0
- package/dist/{migrate-C27-tFFC.mjs → migrate-CQpwBF1l.mjs} +5 -5
- package/dist/{migrate-C27-tFFC.mjs.map → migrate-CQpwBF1l.mjs.map} +1 -1
- package/dist/{migrate-document-models-CKnqQnRh.mjs → migrate-document-models-DpXzLDuu.mjs} +4 -4
- package/dist/{migrate-document-models-CKnqQnRh.mjs.map → migrate-document-models-DpXzLDuu.mjs.map} +1 -1
- package/dist/{migrate-subgraphs-B2nTiJ-j.mjs → migrate-subgraphs-CdfkO6l9.mjs} +54 -14
- package/dist/migrate-subgraphs-CdfkO6l9.mjs.map +1 -0
- package/dist/migrate-subgraphs-CoUuwzmR.mjs +4 -0
- package/dist/ph-cli-commands-Daeqh5Me.mjs +4 -0
- package/dist/{ph-cli-commands-DhoNXWGf.mjs → ph-cli-commands-Dq-tIYhy.mjs} +30 -182
- package/dist/ph-cli-commands-Dq-tIYhy.mjs.map +1 -0
- package/dist/run-sugar-Bnab2Z3f.mjs +4 -0
- package/dist/run-sugar-DsG2RRgx.mjs +89 -0
- package/dist/run-sugar-DsG2RRgx.mjs.map +1 -0
- package/dist/runners/connect.d.mts +2 -2
- package/dist/runners/connect.d.mts.map +1 -1
- package/dist/runners/connect.mjs +30 -18
- package/dist/runners/connect.mjs.map +1 -1
- package/dist/runners/switchboard.d.mts +3 -3
- package/dist/runners/switchboard.mjs +11 -11
- package/dist/runners/switchboard.mjs.map +1 -1
- package/dist/scripts/generate-commands-docs.ts +2 -8
- package/dist/service-args-D6y3L0bm.mjs +49 -0
- package/dist/service-args-D6y3L0bm.mjs.map +1 -0
- package/dist/sugar-checks-DBk5q_uJ.mjs +175 -0
- package/dist/sugar-checks-DBk5q_uJ.mjs.map +1 -0
- package/dist/{switchboard-reset-MtTB_GAI.mjs → switchboard-reset-CY6J0lWO.mjs} +4 -4
- package/dist/switchboard-reset-CY6J0lWO.mjs.map +1 -0
- package/dist/utils-BU25LHRE.mjs +4 -0
- package/dist/{utils-9KyRM0mf.mjs → utils-D5VlY5AZ.mjs} +4 -15
- package/dist/utils-D5VlY5AZ.mjs.map +1 -0
- package/dist/{verify-DCf_nRt8.mjs → verify-C_fL8YsF.mjs} +4 -4
- package/dist/{verify-DCf_nRt8.mjs.map → verify-C_fL8YsF.mjs.map} +1 -1
- package/dist/{vetra-host-ChTpJiBJ.mjs → vetra-host-CDfny6E8.mjs} +24 -9
- package/dist/vetra-host-CDfny6E8.mjs.map +1 -0
- package/dist/{vetra-instance-CzhYIjxL.mjs → vetra-instance-DlXAeiU7.mjs} +8 -16
- package/dist/{vetra-instance-CzhYIjxL.mjs.map → vetra-instance-DlXAeiU7.mjs.map} +1 -1
- package/dist/{vetra-launch-qi10Unax.mjs → vetra-launcher-CYX10K2m.mjs} +14 -32
- package/dist/vetra-launcher-CYX10K2m.mjs.map +1 -0
- package/dist/vetra-launcher-TDLXj0tY.mjs +4 -0
- package/dist/{vetra-switchboard-tzdc14KA.mjs → vetra-switchboard-Ctje6iR1.mjs} +4 -4
- package/dist/{vetra-switchboard-tzdc14KA.mjs.map → vetra-switchboard-Ctje6iR1.mjs.map} +1 -1
- package/package.json +16 -16
- package/dist/build-CnTFRBft.mjs +0 -4
- package/dist/build-DuNe06I0.mjs.map +0 -1
- package/dist/classic-args-mH_DVsgC.mjs +0 -48
- package/dist/classic-args-mH_DVsgC.mjs.map +0 -1
- package/dist/classic-warnings-BR0S6lr5.mjs +0 -179
- package/dist/classic-warnings-BR0S6lr5.mjs.map +0 -1
- package/dist/compound-DKi56SSx-CXQHhS6t.mjs.map +0 -1
- package/dist/connect-preview-CdFvlANO.mjs.map +0 -1
- package/dist/connect-studio-BnfhpIv8.mjs.map +0 -1
- package/dist/connect-studio-D58ByAAn.mjs +0 -4
- package/dist/dist-DXcB8fAF.mjs.map +0 -1
- package/dist/explain-8OEXF2Dy.mjs.map +0 -1
- package/dist/generate-desktop-shell-BovoRsR6.mjs.map +0 -1
- package/dist/index-H3AYe65i.d.mts.map +0 -1
- package/dist/mcp-vSCc5KHI.mjs.map +0 -1
- package/dist/migrate-subgraphs-B1_NRwV7.mjs +0 -4
- package/dist/migrate-subgraphs-B2nTiJ-j.mjs.map +0 -1
- package/dist/ph-cli-commands-DhoNXWGf.mjs.map +0 -1
- package/dist/ph-cli-commands-LIME9alJ.mjs +0 -4
- package/dist/run-sugar-DpznOP1e.mjs +0 -56
- package/dist/run-sugar-DpznOP1e.mjs.map +0 -1
- package/dist/scripts/manage-environment +0 -199
- package/dist/scripts/setup-environment +0 -423
- package/dist/scripts/setup-environment.ps1 +0 -313
- package/dist/switchboard-reset-MtTB_GAI.mjs.map +0 -1
- package/dist/utils-9KyRM0mf.mjs.map +0 -1
- package/dist/utils-TO9lB8Xs.mjs +0 -4
- package/dist/vetra-CVNZ46pK.mjs +0 -352
- package/dist/vetra-CVNZ46pK.mjs.map +0 -1
- package/dist/vetra-host-ChTpJiBJ.mjs.map +0 -1
- package/dist/vetra-launch-qi10Unax.mjs.map +0 -1
- package/dist/vetra-switchboard-BrkozIm7.mjs +0 -4
|
@@ -1,127 +1,58 @@
|
|
|
1
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]="
|
|
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]="3552b73c-5e7a-51b0-b33e-d0b1161b9c52")}catch(e){}}();
|
|
3
3
|
import { _ as unknown, b as prettifyError, c as literal, f as record, g as union, i as boolean, l as looseObject, m as string, n as _enum, p as strictObject, r as array, t as ZodType, u as number, v as url, y as toJSONSchema } from "./schemas-DzgKfQIx.mjs";
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
|
-
import fs, { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
5
|
+
import fs, { existsSync, readFileSync, readdirSync, realpathSync, statSync } from "node:fs";
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import { execFileSync } from "node:child_process";
|
|
8
8
|
import { createHash } from "node:crypto";
|
|
9
9
|
import { pathToFileURL } from "node:url";
|
|
10
|
+
import { Worker } from "node:worker_threads";
|
|
10
11
|
import { TOKEN_ESCAPE_KEY, envTokenable, findToken, isToken, switchboardOfDrive, tokenKeyOf, tokenSchema, tokenable } from "@powerhousedao/shared/host-tokens";
|
|
11
12
|
import { isOriginPlaceholderUrl } from "@powerhousedao/shared/connect/origin-placeholder";
|
|
12
13
|
import { resolvePhDir } from "@powerhousedao/shared/clis/ph-dir";
|
|
13
|
-
|
|
14
|
+
import net from "node:net";
|
|
15
|
+
//#region ../../packages/host-core/dist/compound-n-bO0qKh.mjs
|
|
14
16
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* are never plugins themselves.
|
|
22
|
-
*
|
|
23
|
-
* host.js carries the COMPOSITION as `runner.plugins` entries:
|
|
24
|
-
* string | { module, enabled?, verbs?, config? }
|
|
25
|
-
* Presence is activation (enabled defaults true); `verbs` scopes an entry to
|
|
26
|
-
* matching run verbs; `config` is validated against the plugin's declared
|
|
27
|
-
* zod schema. Entries resolve from the PROJECT's dependency tree exactly
|
|
28
|
-
* like runner modules.
|
|
29
|
-
*/
|
|
30
|
-
var PluginError = class extends Error {
|
|
31
|
-
constructor(message, hint) {
|
|
32
|
-
super(hint ? `${message}\n Hint: ${hint}` : message);
|
|
33
|
-
this.name = "PluginError";
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
const pluginEntryObjectSchema = strictObject({
|
|
37
|
-
module: string().min(1),
|
|
38
|
-
/** Presence is activation BY DEFAULT; false is the explicit off-switch. */
|
|
39
|
-
enabled: boolean().optional(),
|
|
40
|
-
/** "*" (default) or the run verbs this entry is active for. */
|
|
41
|
-
verbs: union([literal("*"), array(string().min(1)).min(1)]).optional(),
|
|
42
|
-
/** Validated against the plugin's declared configSchema at resolution. */
|
|
43
|
-
config: record(string(), unknown()).optional()
|
|
44
|
-
});
|
|
45
|
-
const pluginEntrySchema = union([string().min(1), pluginEntryObjectSchema]);
|
|
46
|
-
function normalizePluginEntry(entry) {
|
|
47
|
-
if (typeof entry === "string") return {
|
|
48
|
-
module: entry,
|
|
49
|
-
enabled: true,
|
|
50
|
-
verbs: "*",
|
|
51
|
-
config: {}
|
|
52
|
-
};
|
|
53
|
-
return {
|
|
54
|
-
module: entry.module,
|
|
55
|
-
enabled: entry.enabled ?? true,
|
|
56
|
-
verbs: entry.verbs ?? "*",
|
|
57
|
-
config: entry.config ?? {}
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
/** Module is the identity key: a duplicate makes override targeting and
|
|
61
|
-
* ordering ambiguous, so it fails loudly. */
|
|
62
|
-
function normalizePluginEntries(entries, where) {
|
|
63
|
-
const normalized = entries.map(normalizePluginEntry);
|
|
64
|
-
const seen = /* @__PURE__ */ new Set();
|
|
65
|
-
for (const entry of normalized) {
|
|
66
|
-
if (seen.has(entry.module)) throw new PluginError(`${where}: plugin "${entry.module}" is listed twice.`, "Module specifiers are the identity key of a composition; a plugin meant to run twice needs distinct subpath specifiers.");
|
|
67
|
-
seen.add(entry.module);
|
|
68
|
-
}
|
|
69
|
-
return normalized;
|
|
70
|
-
}
|
|
71
|
-
function entryActiveForVerb(entry, verb) {
|
|
72
|
-
if (!entry.enabled) return false;
|
|
73
|
-
return entry.verbs === "*" || entry.verbs.includes(verb);
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* NODE-ONLY plugin resolution (split from plugins.ts so the pure runner core
|
|
77
|
-
* stays browser-safe for ConnectCore — R3). Resolves host.js entries from the
|
|
78
|
-
* PROJECT dependency tree, exactly like runner modules.
|
|
17
|
+
* The schema half of drives.ts, zod only so `./schema` stays neutral.
|
|
18
|
+
* - slug: the SEEDING KEY (idempotence); id optional (stable identity).
|
|
19
|
+
* - preferredEditor: stored at header.meta.preferredEditor; Connect config's
|
|
20
|
+
* `app` is the legacy alias.
|
|
21
|
+
* - remote.url: a drive served elsewhere; local fields are ignored for it.
|
|
22
|
+
* Token-able (`$output` on a producer's `drives.<slug>.url`).
|
|
79
23
|
*/
|
|
80
|
-
function
|
|
81
|
-
return
|
|
24
|
+
function buildDriveDeclarationSchema(urlField) {
|
|
25
|
+
return strictObject({
|
|
26
|
+
slug: string().min(1),
|
|
27
|
+
id: string().min(1).optional(),
|
|
28
|
+
/** Derive the id from the project path (`<slug>-<hash of the path>`) — the
|
|
29
|
+
* same ids classic `ph vetra` produced. `true` serves the drive under the
|
|
30
|
+
* hashed slug too (the vetra drive's slug IS its hashed id); `"id"` hashes
|
|
31
|
+
* only the id and keeps the declared slug (the classic Workflows drive:
|
|
32
|
+
* `/d/workflows`, id `workflows-<hash>`). */
|
|
33
|
+
projectHash: union([boolean(), literal("id")]).optional(),
|
|
34
|
+
/** What a missing drive is created as. Default powerhouse/document-drive. */
|
|
35
|
+
documentType: _enum(["powerhouse/document-drive", "powerhouse/reactor-drive"]).optional(),
|
|
36
|
+
name: string().min(1).optional(),
|
|
37
|
+
icon: string().optional(),
|
|
38
|
+
preferredEditor: string().optional(),
|
|
39
|
+
sharingType: _enum([
|
|
40
|
+
"public",
|
|
41
|
+
"private",
|
|
42
|
+
"shared"
|
|
43
|
+
]).optional(),
|
|
44
|
+
availableOffline: boolean().optional(),
|
|
45
|
+
remote: strictObject({ url: urlField(string().min(1)) }).optional()
|
|
46
|
+
});
|
|
82
47
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
async function resolvePluginContributions(projectRoot, verb, entries, where) {
|
|
92
|
-
const normalized = normalizePluginEntries(entries, where);
|
|
93
|
-
const projectRequire = createRequire(pathToFileURL(path.join(projectRoot, "package.json")).href);
|
|
94
|
-
const plan = {
|
|
95
|
-
drives: [],
|
|
96
|
-
unresolved: []
|
|
97
|
-
};
|
|
98
|
-
for (const entry of normalized) {
|
|
99
|
-
if (!entryActiveForVerb(entry, verb)) continue;
|
|
100
|
-
let file;
|
|
101
|
-
try {
|
|
102
|
-
file = projectRequire.resolve(entry.module);
|
|
103
|
-
} catch {
|
|
104
|
-
plan.unresolved.push(entry.module);
|
|
105
|
-
continue;
|
|
106
|
-
}
|
|
107
|
-
const exported = (await import(pathToFileURL(file).href)).default;
|
|
108
|
-
let plugin;
|
|
109
|
-
if (typeof exported === "function") plugin = exported(entry.config);
|
|
110
|
-
else if (isHostPluginShape(exported)) plugin = exported;
|
|
111
|
-
else {
|
|
112
|
-
plan.unresolved.push(entry.module);
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
if (plugin.configSchema) {
|
|
116
|
-
const parsed = plugin.configSchema.safeParse(entry.config);
|
|
117
|
-
if (!parsed.success) throw new PluginError(`${where}: config for plugin "${plugin.name}" is invalid:\n` + prettifyError(parsed.error));
|
|
118
|
-
}
|
|
119
|
-
for (const declaration of plugin.contributions?.drives ?? []) plan.drives.push({
|
|
120
|
-
declaration,
|
|
121
|
-
source: plugin.name
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
return plan;
|
|
48
|
+
const driveDeclarationSchema = buildDriveDeclarationSchema(tokenable);
|
|
49
|
+
const drivesSchema = array(driveDeclarationSchema);
|
|
50
|
+
/** The project-hashed drive id (`${slug}-${sha256(projectRoot)[0..8]}`) with
|
|
51
|
+
* the hash function injected, so neutral consumers (a browser monitor) can
|
|
52
|
+
* pass `crypto.subtle`-derived or precomputed hex. drives.ts binds it to
|
|
53
|
+
* node:crypto as `projectDriveId`. */
|
|
54
|
+
function projectDriveIdWith(sha256Hex, projectRoot, slug) {
|
|
55
|
+
return `${slug}-${sha256Hex(projectRoot).substring(0, 8)}`;
|
|
125
56
|
}
|
|
126
57
|
/**
|
|
127
58
|
* The connect config slices each built-in Connect plugin owns, by specifier
|
|
@@ -224,82 +155,65 @@ function alreadyServed(authored, served) {
|
|
|
224
155
|
return Object.keys(want).every((key) => alreadyServed(want[key], have[key]));
|
|
225
156
|
}
|
|
226
157
|
/**
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
* composition active for `verb`. Connect zeroes such a slice, so the value
|
|
230
|
-
* has no effect — e.g. Sektar's `connect.drives.allowAddDrive: true` without
|
|
231
|
-
* the generic plugin.
|
|
158
|
+
* R1 — the host plugin framework (bridge-runners-to-plugins plan,
|
|
159
|
+
* customization-references/host-core as the blueprint).
|
|
232
160
|
*
|
|
233
|
-
*
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
*
|
|
161
|
+
* A plugin is hooks + contributions; hooks are boot wiring (main realm only),
|
|
162
|
+
* contributions are declarative, serializable surface. Host RUNTIMES define
|
|
163
|
+
* the hook vocabulary and interleave their own wiring between stages — they
|
|
164
|
+
* are never plugins themselves.
|
|
165
|
+
*
|
|
166
|
+
* host.js carries the COMPOSITION as `runner.plugins` entries:
|
|
167
|
+
* string | { module, enabled?, verbs?, config? }
|
|
168
|
+
* Presence is activation (enabled defaults true); `verbs` scopes an entry to
|
|
169
|
+
* matching run verbs; `config` is validated against the plugin's declared
|
|
170
|
+
* zod schema. Entries resolve from the PROJECT's dependency tree exactly
|
|
171
|
+
* like runner modules.
|
|
237
172
|
*/
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
for (const [owner, { slices, inertUnless }] of Object.entries(CONNECT_PLUGIN_OWNED_SLICES)) {
|
|
243
|
-
if (active.has(owner)) continue;
|
|
244
|
-
if (inertUnless !== void 0) {
|
|
245
|
-
const gate = slices.find((slice) => slice.path === inertUnless);
|
|
246
|
-
if (alreadyServed(valueAt$1(config, inertUnless), gate?.absent)) continue;
|
|
247
|
-
}
|
|
248
|
-
for (const { path: slicePath, absent, entryKey } of slices) {
|
|
249
|
-
const value = valueAt$1(config, slicePath);
|
|
250
|
-
if (alreadyServed(value, absent)) continue;
|
|
251
|
-
const move = entryKey === void 0 ? `compose "${owner}" (presence is the switch)` : `compose "${owner}" and set \`${entryKey}\` in its entry config`;
|
|
252
|
-
warnings.push({
|
|
253
|
-
path: slicePath,
|
|
254
|
-
value,
|
|
255
|
-
served: absent,
|
|
256
|
-
owner,
|
|
257
|
-
message: `${where}: config.${slicePath} is dead config: it is owned by plugin "${owner}", which this host does not compose for verb "${verb}", so Connect serves ${JSON.stringify(absent)} instead of ${JSON.stringify(value)}.\n Hint: ${move}, or delete the value.`
|
|
258
|
-
});
|
|
259
|
-
}
|
|
173
|
+
var PluginError = class extends Error {
|
|
174
|
+
constructor(message, hint) {
|
|
175
|
+
super(hint ? `${message}\n Hint: ${hint}` : message);
|
|
176
|
+
this.name = "PluginError";
|
|
260
177
|
}
|
|
261
|
-
|
|
178
|
+
};
|
|
179
|
+
const pluginEntryObjectSchema = strictObject({
|
|
180
|
+
module: string().min(1),
|
|
181
|
+
/** Presence is activation BY DEFAULT; false is the explicit off-switch. */
|
|
182
|
+
enabled: boolean().optional(),
|
|
183
|
+
/** "*" (default) or the run verbs this entry is active for. */
|
|
184
|
+
verbs: union([literal("*"), array(string().min(1)).min(1)]).optional(),
|
|
185
|
+
/** Validated against the plugin's declared configSchema at resolution. */
|
|
186
|
+
config: record(string(), unknown()).optional()
|
|
187
|
+
});
|
|
188
|
+
const pluginEntrySchema = union([string().min(1), pluginEntryObjectSchema]);
|
|
189
|
+
function normalizePluginEntry(entry) {
|
|
190
|
+
if (typeof entry === "string") return {
|
|
191
|
+
module: entry,
|
|
192
|
+
enabled: true,
|
|
193
|
+
verbs: "*",
|
|
194
|
+
config: {}
|
|
195
|
+
};
|
|
196
|
+
return {
|
|
197
|
+
module: entry.module,
|
|
198
|
+
enabled: entry.enabled ?? true,
|
|
199
|
+
verbs: entry.verbs ?? "*",
|
|
200
|
+
config: entry.config ?? {}
|
|
201
|
+
};
|
|
262
202
|
}
|
|
263
|
-
/**
|
|
264
|
-
*
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
return
|
|
273
|
-
slug: string().min(1),
|
|
274
|
-
id: string().min(1).optional(),
|
|
275
|
-
/** Derive the id from the project path, like generateProjectDriveId — the
|
|
276
|
-
* same ids classic `ph vetra` produces. `true` serves the drive under the
|
|
277
|
-
* hashed slug too (the vetra drive's slug IS its hashed id); `"id"` hashes
|
|
278
|
-
* only the id and keeps the declared slug (the classic Workflows drive:
|
|
279
|
-
* `/d/workflows`, id `workflows-<hash>`). */
|
|
280
|
-
projectHash: union([boolean(), literal("id")]).optional(),
|
|
281
|
-
/** What a missing drive is created as. Default powerhouse/document-drive. */
|
|
282
|
-
documentType: _enum(["powerhouse/document-drive", "powerhouse/reactor-drive"]).optional(),
|
|
283
|
-
name: string().min(1).optional(),
|
|
284
|
-
icon: string().optional(),
|
|
285
|
-
preferredEditor: string().optional(),
|
|
286
|
-
sharingType: _enum([
|
|
287
|
-
"public",
|
|
288
|
-
"private",
|
|
289
|
-
"shared"
|
|
290
|
-
]).optional(),
|
|
291
|
-
availableOffline: boolean().optional(),
|
|
292
|
-
remote: strictObject({ url: urlField(string().min(1)) }).optional()
|
|
293
|
-
});
|
|
203
|
+
/** Module is the identity key: a duplicate makes override targeting and
|
|
204
|
+
* ordering ambiguous, so it fails loudly. */
|
|
205
|
+
function normalizePluginEntries(entries, where) {
|
|
206
|
+
const normalized = entries.map(normalizePluginEntry);
|
|
207
|
+
const seen = /* @__PURE__ */ new Set();
|
|
208
|
+
for (const entry of normalized) {
|
|
209
|
+
if (seen.has(entry.module)) throw new PluginError(`${where}: plugin "${entry.module}" is listed twice.`, "Module specifiers are the identity key of a composition; a plugin meant to run twice needs distinct subpath specifiers.");
|
|
210
|
+
seen.add(entry.module);
|
|
211
|
+
}
|
|
212
|
+
return normalized;
|
|
294
213
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
* the hash function injected, so neutral consumers (a browser monitor) can
|
|
299
|
-
* pass `crypto.subtle`-derived or precomputed hex. drives.ts binds it to
|
|
300
|
-
* node:crypto as `projectDriveId`. */
|
|
301
|
-
function projectDriveIdWith(sha256Hex, projectRoot, slug) {
|
|
302
|
-
return `${slug}-${sha256Hex(projectRoot).substring(0, 8)}`;
|
|
214
|
+
function entryActiveForVerb(entry, verb) {
|
|
215
|
+
if (!entry.enabled) return false;
|
|
216
|
+
return entry.verbs === "*" || entry.verbs.includes(verb);
|
|
303
217
|
}
|
|
304
218
|
/**
|
|
305
219
|
* The zod single source for host.js blocks (typed-host-configs G1). Every
|
|
@@ -317,6 +231,16 @@ function projectDriveIdWith(sha256Hex, projectRoot, slug) {
|
|
|
317
231
|
const HOST_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
318
232
|
const HOST_NAME_MESSAGE = "A host name is used as a file name, so use only letters, digits, '.', '_' and '-', start with a letter or digit, and keep it to 128 characters.";
|
|
319
233
|
const hostNameSchema = string().min(1).max(128, HOST_NAME_MESSAGE).regex(HOST_NAME_PATTERN, HOST_NAME_MESSAGE);
|
|
234
|
+
/** An npm package name, as `<package>/<host>` names a package that supplies
|
|
235
|
+
* hosts: `name` or `@scope/name`, each part letters, digits, '-', '.', '_'
|
|
236
|
+
* and '~', not starting with '.' or '_'. Each part is one folder name, the
|
|
237
|
+
* one the package has under node_modules. */
|
|
238
|
+
const PACKAGE_NAME_PATTERN = /^(?:@[A-Za-z0-9~-][A-Za-z0-9._~-]*\/)?[A-Za-z0-9~-][A-Za-z0-9._~-]*$/;
|
|
239
|
+
/** How a compound names a member's host: its folder under the project's
|
|
240
|
+
* `hosts/` (or, in a package's compound, the package's first), or
|
|
241
|
+
* `<package>/<host>` for one an installed package supplies. */
|
|
242
|
+
const HOST_REF_PATTERN = new RegExp(`^(?:${PACKAGE_NAME_PATTERN.source.slice(1, -1)}/)?${HOST_NAME_PATTERN.source.slice(1, -1)}$`);
|
|
243
|
+
const HOST_REF_MESSAGE = "A member's host is a host folder (`switchboard`), or `<package>/<host>` (`@acme/tools/studio`) for one an installed package supplies.";
|
|
320
244
|
/**
|
|
321
245
|
* A URL, or one written against the page origin (`${origin}/graphql`): the
|
|
322
246
|
* browser resolves the placeholder when it loads Connect's config, for a
|
|
@@ -341,6 +265,8 @@ const reactorProtocolSchema = strictObject({
|
|
|
341
265
|
unsupportedStoredDocuments: _enum(["refuse", "read-only"]).optional()
|
|
342
266
|
});
|
|
343
267
|
const runnerKindSchema = _enum(["reactor", "compound"]);
|
|
268
|
+
/** A compound member's process: its own, or the compound's (`shared`). */
|
|
269
|
+
const memberProcessSchema = _enum(["own", "shared"]);
|
|
344
270
|
const reactorBackendKindSchema = _enum([
|
|
345
271
|
"in-process",
|
|
346
272
|
"worker",
|
|
@@ -694,8 +620,6 @@ function buildHostSchemas(tokenField) {
|
|
|
694
620
|
provisionalRouteMs: number().int().nonnegative().optional()
|
|
695
621
|
}).optional(),
|
|
696
622
|
protocol: reactorProtocolSchema.optional(),
|
|
697
|
-
/** DEPRECATED (dies in R2): workflows become a listed plugin. */
|
|
698
|
-
workflows: boolean().optional(),
|
|
699
623
|
renown: strictObject({
|
|
700
624
|
url: string().optional(),
|
|
701
625
|
networkId: string().optional(),
|
|
@@ -739,10 +663,15 @@ function buildHostSchemas(tokenField) {
|
|
|
739
663
|
* which key-merges over the member's own. Plugins live in `runner.plugins`
|
|
740
664
|
* (as on a standalone host); there is no wrapper-level `plugins`. */
|
|
741
665
|
const childWrapperSchema = strictObject({
|
|
742
|
-
host: string().min(1),
|
|
666
|
+
host: string().min(1).regex(HOST_REF_PATTERN, HOST_REF_MESSAGE),
|
|
743
667
|
runner: runnerBaseSchema.partial().extend({ port: number().int().min(0).max(65535).optional() }).optional(),
|
|
744
668
|
config: looseObject({}).optional(),
|
|
745
|
-
reactor: reactorSchema.optional()
|
|
669
|
+
reactor: reactorSchema.optional(),
|
|
670
|
+
/** Where the member runs: `own`, a child process of the compound
|
|
671
|
+
* (`ph run <host>`), stopped through its stdin; `shared`, in the
|
|
672
|
+
* compound's own process. Default: `own` next to a foreground member
|
|
673
|
+
* (the Cli runner), `shared` otherwise. */
|
|
674
|
+
process: memberProcessSchema.optional()
|
|
746
675
|
});
|
|
747
676
|
const childrenSchema = record(string(), childWrapperSchema);
|
|
748
677
|
return {
|
|
@@ -813,6 +742,213 @@ resolvedSchemas.compoundHostSchema;
|
|
|
813
742
|
const genericCompound = defineHostSchemas((s) => s.compoundHostSchema.extend({ config: compoundWiringSchema.optional() }).superRefine(refineStartOrder));
|
|
814
743
|
genericCompound.hostSchema;
|
|
815
744
|
genericCompound.declaredHostSchema;
|
|
745
|
+
/**
|
|
746
|
+
* How a host is addressed (decision D5). A bare name (`switchboard`) is the
|
|
747
|
+
* project's own host, `<project>/hosts/switchboard/`, always: a package
|
|
748
|
+
* cannot shadow it. `<package>/<host>` (`@powerhousedao/vetra-cli/studio`,
|
|
749
|
+
* `tools/studio`) is a host an installed package supplies, in the `hosts/`
|
|
750
|
+
* folder it ships: `<package>/hosts/studio/`. The host is the last segment,
|
|
751
|
+
* so a host name has no `/`. Only inside a package's compound does a bare
|
|
752
|
+
* member name look in that package first (`locateHost`'s `scope`).
|
|
753
|
+
*/
|
|
754
|
+
var HostLoadError = class extends Error {
|
|
755
|
+
constructor(message, hint) {
|
|
756
|
+
super(hint ? `${message}\n Hint: ${hint}` : message);
|
|
757
|
+
this.name = "HostLoadError";
|
|
758
|
+
}
|
|
759
|
+
};
|
|
760
|
+
/** Splits a ref at its last `/`; refuses what names no host. */
|
|
761
|
+
function parseHostRef(ref) {
|
|
762
|
+
const slash = ref.lastIndexOf("/");
|
|
763
|
+
if (slash === -1) return { host: ref };
|
|
764
|
+
const pkg = ref.slice(0, slash);
|
|
765
|
+
const host = ref.slice(slash + 1);
|
|
766
|
+
if (/^@[^/]*$/.test(pkg) || ref.startsWith("@") && host === "") throw new HostLoadError(`"${ref}" names a package, not a host.`, `A package's host is <package>/<host>, e.g. \`ph run ${ref.replace(/\/$/, "")}/<host>\`.`);
|
|
767
|
+
if (!PACKAGE_NAME_PATTERN.test(pkg)) throw new HostLoadError(`"${ref}" names no host: a host is <host> (the project's) or <package>/<host>, a host name has no "/", and "${pkg}" is no package name.`);
|
|
768
|
+
if (host === "") throw new HostLoadError(`"${ref}" names package "${pkg}" but no host.`, `Write ${pkg}/<host>.`);
|
|
769
|
+
return {
|
|
770
|
+
package: pkg,
|
|
771
|
+
host
|
|
772
|
+
};
|
|
773
|
+
}
|
|
774
|
+
function formatHostRef(ref) {
|
|
775
|
+
return ref.package === void 0 ? ref.host : `${ref.package}/${ref.host}`;
|
|
776
|
+
}
|
|
777
|
+
/** Where messages point for a host file: `hosts/<host>/host.js`, behind its
|
|
778
|
+
* package for a package's (`@acme/tools/hosts/studio/host.js`). */
|
|
779
|
+
function hostFileLabel(folder, hostPackage) {
|
|
780
|
+
const file = `hosts/${folder}/host.js`;
|
|
781
|
+
return hostPackage ? `${hostPackage.name}/${file}` : file;
|
|
782
|
+
}
|
|
783
|
+
function packageJsonName(dir) {
|
|
784
|
+
try {
|
|
785
|
+
const name = JSON.parse(readFileSync(path.join(dir, "package.json"), "utf8")).name;
|
|
786
|
+
return typeof name === "string" ? name : void 0;
|
|
787
|
+
} catch {
|
|
788
|
+
return;
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
/**
|
|
792
|
+
* The real folder of the installed package `name`, found from `fromRoot` as
|
|
793
|
+
* Node finds it: the first `<dir>/node_modules/<name>/package.json` on the
|
|
794
|
+
* lookup paths of `<fromRoot>/package.json`, by its real path (a pnpm link
|
|
795
|
+
* leads to the package's own folder, whose dependencies are its own). Not
|
|
796
|
+
* through `exports`, which may not list `package.json`. Undefined when it is
|
|
797
|
+
* not installed there.
|
|
798
|
+
*/
|
|
799
|
+
function resolvePackageRoot(fromRoot, name) {
|
|
800
|
+
const root = path.resolve(fromRoot);
|
|
801
|
+
const lookup = createRequire(pathToFileURL(path.join(root, "package.json")).href).resolve.paths(name) ?? [];
|
|
802
|
+
for (const dir of lookup) {
|
|
803
|
+
const candidate = path.join(dir, name);
|
|
804
|
+
if (existsSync(path.join(candidate, "package.json"))) return realpathSync(candidate);
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
/** The installed package `name`, found from the project root
|
|
808
|
+
* (resolvePackageRoot). */
|
|
809
|
+
function findHostPackage(projectRoot, name, host) {
|
|
810
|
+
const root = path.resolve(projectRoot);
|
|
811
|
+
if (packageJsonName(root) === name) throw new HostLoadError(`"${name}/${host}": "${name}" is this project's own package.`, `Run the project's own host by its bare name: \`ph run ${host}\`.`);
|
|
812
|
+
const found = resolvePackageRoot(root, name);
|
|
813
|
+
if (found !== void 0) return {
|
|
814
|
+
name,
|
|
815
|
+
root: found
|
|
816
|
+
};
|
|
817
|
+
throw new HostLoadError(`Package "${name}" is not installed in this project, so it supplies no host "${host}".`, `Add ${name} as a dependency of the project (looked up from ${root}).`);
|
|
818
|
+
}
|
|
819
|
+
/** The `<name>/host.js` folders under `<root>/hosts`, sorted; undefined
|
|
820
|
+
* when there is no hosts/ folder. */
|
|
821
|
+
function hostFolders(root) {
|
|
822
|
+
const dir = path.join(root, "hosts");
|
|
823
|
+
if (!existsSync(dir) || !statSync(dir).isDirectory()) return void 0;
|
|
824
|
+
return readdirSync(dir, { withFileTypes: true }).filter((entry) => entry.isDirectory() && existsSync(path.join(dir, entry.name, "host.js"))).map((entry) => entry.name).sort();
|
|
825
|
+
}
|
|
826
|
+
/** A package's host, or why the package has none by that name. */
|
|
827
|
+
function packageHostLocation(pkg, host) {
|
|
828
|
+
const folders = hostFolders(pkg.root);
|
|
829
|
+
if (folders === void 0 || folders.length === 0) throw new HostLoadError(`Package "${pkg.name}" supplies no hosts: ${pkg.root} has no hosts/<name>/host.js, so "${pkg.name}/${host}" cannot run.`);
|
|
830
|
+
if (!folders.includes(host)) throw new HostLoadError(`Package "${pkg.name}" supplies no host "${host}". Its hosts: ${folders.join(", ")}.`);
|
|
831
|
+
return {
|
|
832
|
+
ref: formatHostRef({
|
|
833
|
+
package: pkg.name,
|
|
834
|
+
host
|
|
835
|
+
}),
|
|
836
|
+
folder: host,
|
|
837
|
+
hostsDir: path.join(pkg.root, "hosts"),
|
|
838
|
+
package: pkg
|
|
839
|
+
};
|
|
840
|
+
}
|
|
841
|
+
/**
|
|
842
|
+
* Where `ref` is. `<package>/<host>` is always the installed package's,
|
|
843
|
+
* found from the project root (also when a package's compound writes it). A
|
|
844
|
+
* bare name is the project's, except in a package's compound (`scope`): there
|
|
845
|
+
* the package's own host of that name comes first. Throws a HostLoadError
|
|
846
|
+
* naming the package and the host. A bare name the project lacks is left to
|
|
847
|
+
* the loader's own message (undefined `package`, project `hostsDir`).
|
|
848
|
+
*/
|
|
849
|
+
function locateHost(projectRoot, ref, scope) {
|
|
850
|
+
const parsed = parseHostRef(ref);
|
|
851
|
+
if (parsed.package !== void 0) return packageHostLocation(findHostPackage(projectRoot, parsed.package, parsed.host), parsed.host);
|
|
852
|
+
const own = {
|
|
853
|
+
ref: parsed.host,
|
|
854
|
+
folder: parsed.host,
|
|
855
|
+
hostsDir: path.join(projectRoot, "hosts")
|
|
856
|
+
};
|
|
857
|
+
if (!scope) return own;
|
|
858
|
+
const supplied = hostFolders(scope.root) ?? [];
|
|
859
|
+
if (supplied.includes(parsed.host)) return packageHostLocation(scope, parsed.host);
|
|
860
|
+
const projects = hostFolders(projectRoot) ?? [];
|
|
861
|
+
if (projects.includes(parsed.host)) return own;
|
|
862
|
+
throw new HostLoadError(`Unknown host "${parsed.host}": package "${scope.name}" supplies none (its hosts: ${supplied.join(", ") || "none"}), and neither does the project (its hosts: ${projects.join(", ") || "none"}).`);
|
|
863
|
+
}
|
|
864
|
+
/**
|
|
865
|
+
* NODE-ONLY plugin resolution (split from plugins.ts so the pure runner core
|
|
866
|
+
* stays browser-safe for ConnectCore — R3). Resolves host.js entries from the
|
|
867
|
+
* PROJECT dependency tree, exactly like runner modules.
|
|
868
|
+
*/
|
|
869
|
+
function isHostPluginShape(value) {
|
|
870
|
+
return value !== null && typeof value === "object" && typeof value.name === "string";
|
|
871
|
+
}
|
|
872
|
+
/**
|
|
873
|
+
* LENIENT resolution for diagnostics (`ph run <host> --explain drives`):
|
|
874
|
+
* collects the drive contributions of the entries active for `verb`. Unlike
|
|
875
|
+
* resolveHostPlugins it does not know the host type (so appliesTo is not
|
|
876
|
+
* checked) and does not fail on a specifier the project tree cannot resolve
|
|
877
|
+
* — the entry is listed under `unresolved` instead. Config is still validated
|
|
878
|
+
* against the plugin's schema, so a bad entry surfaces here too.
|
|
879
|
+
*/
|
|
880
|
+
async function resolvePluginContributions(projectRoot, verb, entries, where) {
|
|
881
|
+
const normalized = normalizePluginEntries(entries, where);
|
|
882
|
+
const projectRequire = createRequire(pathToFileURL(path.join(projectRoot, "package.json")).href);
|
|
883
|
+
const plan = {
|
|
884
|
+
drives: [],
|
|
885
|
+
unresolved: []
|
|
886
|
+
};
|
|
887
|
+
for (const entry of normalized) {
|
|
888
|
+
if (!entryActiveForVerb(entry, verb)) continue;
|
|
889
|
+
let file;
|
|
890
|
+
try {
|
|
891
|
+
file = projectRequire.resolve(entry.module);
|
|
892
|
+
} catch {
|
|
893
|
+
plan.unresolved.push(entry.module);
|
|
894
|
+
continue;
|
|
895
|
+
}
|
|
896
|
+
const exported = (await import(pathToFileURL(file).href)).default;
|
|
897
|
+
let plugin;
|
|
898
|
+
if (typeof exported === "function") plugin = exported(entry.config);
|
|
899
|
+
else if (isHostPluginShape(exported)) plugin = exported;
|
|
900
|
+
else {
|
|
901
|
+
plan.unresolved.push(entry.module);
|
|
902
|
+
continue;
|
|
903
|
+
}
|
|
904
|
+
if (plugin.configSchema) {
|
|
905
|
+
const parsed = plugin.configSchema.safeParse(entry.config);
|
|
906
|
+
if (!parsed.success) throw new PluginError(`${where}: config for plugin "${plugin.name}" is invalid:\n` + prettifyError(parsed.error));
|
|
907
|
+
}
|
|
908
|
+
for (const declaration of plugin.contributions?.drives ?? []) plan.drives.push({
|
|
909
|
+
declaration,
|
|
910
|
+
source: plugin.name
|
|
911
|
+
});
|
|
912
|
+
}
|
|
913
|
+
return plan;
|
|
914
|
+
}
|
|
915
|
+
/**
|
|
916
|
+
* Dead-config warnings for a Connect host (typed-host-configs 1.6): an
|
|
917
|
+
* authored connect config value whose owning plugin is not in the
|
|
918
|
+
* composition active for `verb`. Connect zeroes such a slice, so the value
|
|
919
|
+
* has no effect — e.g. Sektar's `connect.drives.allowAddDrive: true` without
|
|
920
|
+
* the generic plugin.
|
|
921
|
+
*
|
|
922
|
+
* Nothing is reported when the host declares no composition
|
|
923
|
+
* (`runner.plugins` absent: the default composition serves the config as is), or
|
|
924
|
+
* when Connect already serves every leaf of the authored value. Warnings, not
|
|
925
|
+
* errors: the host still boots, it just does not do what the value says.
|
|
926
|
+
*/
|
|
927
|
+
function findDeadConnectConfig(config, entries, verb, where) {
|
|
928
|
+
if (!config || entries === void 0) return [];
|
|
929
|
+
const active = new Set(normalizePluginEntries(entries, where).filter((entry) => entryActiveForVerb(entry, verb)).map((entry) => entry.module));
|
|
930
|
+
const warnings = [];
|
|
931
|
+
for (const [owner, { slices, inertUnless }] of Object.entries(CONNECT_PLUGIN_OWNED_SLICES)) {
|
|
932
|
+
if (active.has(owner)) continue;
|
|
933
|
+
if (inertUnless !== void 0) {
|
|
934
|
+
const gate = slices.find((slice) => slice.path === inertUnless);
|
|
935
|
+
if (alreadyServed(valueAt$1(config, inertUnless), gate?.absent)) continue;
|
|
936
|
+
}
|
|
937
|
+
for (const { path: slicePath, absent, entryKey } of slices) {
|
|
938
|
+
const value = valueAt$1(config, slicePath);
|
|
939
|
+
if (alreadyServed(value, absent)) continue;
|
|
940
|
+
const move = entryKey === void 0 ? `compose "${owner}" (presence is the switch)` : `compose "${owner}" and set \`${entryKey}\` in its entry config`;
|
|
941
|
+
warnings.push({
|
|
942
|
+
path: slicePath,
|
|
943
|
+
value,
|
|
944
|
+
served: absent,
|
|
945
|
+
owner,
|
|
946
|
+
message: `${where}: config.${slicePath} is dead config: it is owned by plugin "${owner}", which this host does not compose for verb "${verb}", so Connect serves ${JSON.stringify(absent)} instead of ${JSON.stringify(value)}.\n Hint: ${move}, or delete the value.`
|
|
947
|
+
});
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
return warnings;
|
|
951
|
+
}
|
|
816
952
|
function isPlainObject(value) {
|
|
817
953
|
if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
|
|
818
954
|
const proto = Object.getPrototypeOf(value);
|
|
@@ -1393,7 +1529,12 @@ function isDriveReference(value) {
|
|
|
1393
1529
|
return keys.length === 2 && keys[0] === "from" && keys[1] === "slug" && typeof value.from === "string" && typeof value.slug === "string";
|
|
1394
1530
|
}
|
|
1395
1531
|
function checkReactor(reactor, base, found) {
|
|
1396
|
-
if (!isPlainObject(reactor)
|
|
1532
|
+
if (!isPlainObject(reactor)) return;
|
|
1533
|
+
if (reactor.workflows !== void 0) found.push({
|
|
1534
|
+
path: `${base}reactor.workflows`,
|
|
1535
|
+
message: "reactor.workflows was removed in 6.4; the workflows plugin under runner.plugins decides: list it to run workflows, leave it out to run none. On a switchboard, PH_WORKFLOWS_ENABLED=0 still switches them off."
|
|
1536
|
+
});
|
|
1537
|
+
if (!isPlainObject(reactor.backends)) return;
|
|
1397
1538
|
for (const [name, backend] of Object.entries(reactor.backends)) {
|
|
1398
1539
|
if (!isPlainObject(backend) || !isPlainObject(backend.remote)) continue;
|
|
1399
1540
|
const host = backend.remote.host;
|
|
@@ -1457,7 +1598,11 @@ function findRemovedForms(host) {
|
|
|
1457
1598
|
return found;
|
|
1458
1599
|
}
|
|
1459
1600
|
/** The always-resolvable `$env` names (also the `"${name}"` sugar). */
|
|
1460
|
-
const BUILTIN_ENV_NAMES = [
|
|
1601
|
+
const BUILTIN_ENV_NAMES = [
|
|
1602
|
+
"userData",
|
|
1603
|
+
"projectRoot",
|
|
1604
|
+
"package"
|
|
1605
|
+
];
|
|
1461
1606
|
function isBuiltinEnvName(name) {
|
|
1462
1607
|
return BUILTIN_ENV_NAMES.includes(name);
|
|
1463
1608
|
}
|
|
@@ -1945,7 +2090,9 @@ function setAt(root, trail, value, omit) {
|
|
|
1945
2090
|
/**
|
|
1946
2091
|
* Resolves a host's `runner.module` specifier from the PROJECT's dependency
|
|
1947
2092
|
* tree (not ph-cli's), imports it, and checks the runner-module contract:
|
|
1948
|
-
* `{ run, hostSchema, kind, outputsSchema?, verbs?, ...optionalVerbs }`.
|
|
2093
|
+
* `{ run, hostSchema, kind, outputsSchema?, verbs?, ...optionalVerbs }`. For
|
|
2094
|
+
* a host an installed package supplies, the caller passes the package's
|
|
2095
|
+
* folder as the root (`moduleRootOf`).
|
|
1949
2096
|
*/
|
|
1950
2097
|
var RunnerError = class extends Error {
|
|
1951
2098
|
constructor(message, hint) {
|
|
@@ -1964,6 +2111,7 @@ const NON_VERB_EXPORTS = /* @__PURE__ */ new Set([
|
|
|
1964
2111
|
"verbs",
|
|
1965
2112
|
"argsSchema",
|
|
1966
2113
|
"kind",
|
|
2114
|
+
"foreground",
|
|
1967
2115
|
"checkBoot",
|
|
1968
2116
|
"default"
|
|
1969
2117
|
]);
|
|
@@ -1989,7 +2137,7 @@ async function resolveRunnerModule(projectRoot, specifier) {
|
|
|
1989
2137
|
const fallback = runnerFallback(specifier);
|
|
1990
2138
|
resolved = resolveFirst(fallback ? [specifier, fallback] : [specifier]);
|
|
1991
2139
|
} catch {
|
|
1992
|
-
throw new RunnerError(`Cannot resolve runner module "${specifier}" from ${projectRoot}.`, "The runner must be a dependency of the project (install it, then retry).");
|
|
2140
|
+
throw new RunnerError(`Cannot resolve runner module "${specifier}" from ${projectRoot}.`, "The runner must be a dependency of the project, or of the package that supplies the host (install it, then retry).");
|
|
1993
2141
|
}
|
|
1994
2142
|
const module = await import(pathToFileURL(resolved).href);
|
|
1995
2143
|
if (typeof module.run !== "function") throw new RunnerError(`Runner "${specifier}" does not export a \`run\` function (required verb).`);
|
|
@@ -1998,6 +2146,7 @@ async function resolveRunnerModule(projectRoot, specifier) {
|
|
|
1998
2146
|
const declared = module.declaredHostSchema;
|
|
1999
2147
|
if (declared !== void 0 && typeof declared.safeParse !== "function") throw new RunnerError(`Runner "${specifier}" exports a \`declaredHostSchema\` without safeParse.`);
|
|
2000
2148
|
if (module.checkBoot !== void 0 && typeof module.checkBoot !== "function") throw new RunnerError(`Runner "${specifier}" exports a \`checkBoot\` that is not a function.`);
|
|
2149
|
+
if (module.foreground !== void 0 && typeof module.foreground !== "boolean") throw new RunnerError(`Runner "${specifier}" exports a \`foreground\` that is not a boolean.`);
|
|
2001
2150
|
const verbs = module.verbs;
|
|
2002
2151
|
if (verbs !== void 0 && (!Array.isArray(verbs) || !verbs.every((verb) => typeof verb === "string" && typeof module[verb] === "function"))) throw new RunnerError(`Runner "${specifier}" exports \`verbs\` ${JSON.stringify(verbs)}, which must list names of exported functions.`);
|
|
2003
2152
|
if (!runnerKindSchema.safeParse(module.kind).success) throw new RunnerError(`Runner "${specifier}" does not export a valid \`kind\` (got ${JSON.stringify(module.kind)}; expected "reactor" | "compound").`);
|
|
@@ -2009,6 +2158,18 @@ async function resolveRunnerModule(projectRoot, specifier) {
|
|
|
2009
2158
|
* the declared host (tokens may remain in token-able fields; a `$map` is
|
|
2010
2159
|
* the empty collection, see `emptyMaps`). */
|
|
2011
2160
|
const ONE_SHOT_VERBS = /* @__PURE__ */ new Set(["build"]);
|
|
2161
|
+
/** Why a one-shot verb (build) does not run on a host an installed package
|
|
2162
|
+
* supplies (`ref`, as the project addresses it): the package ships its hosts
|
|
2163
|
+
* built, and a build here would write into the installed package (a
|
|
2164
|
+
* Connect's outDir) or build the project in its name. The package's own
|
|
2165
|
+
* repository builds them, where they are project hosts. */
|
|
2166
|
+
function packageBuildRefusal(ref, hostPackage, verb) {
|
|
2167
|
+
return {
|
|
2168
|
+
path: "",
|
|
2169
|
+
message: `${ref} is a host ${hostPackage.name} supplies, and a package's hosts are built by the package: "${verb}" does not run on it.`,
|
|
2170
|
+
hint: `${hostPackage.name} ships them built; its own repository builds them, where they are project hosts. Build this project's own hosts by their bare names.`
|
|
2171
|
+
};
|
|
2172
|
+
}
|
|
2012
2173
|
/** Verbs that work on a host's stores and start nothing (`migrate`,
|
|
2013
2174
|
* `migrate-status`, `reset`). Their host is resolved as for `run`, so they
|
|
2014
2175
|
* address the stores `run` opens; they take no lock and return nothing, so
|
|
@@ -2027,7 +2188,7 @@ function getVerb(runner, specifier, verb) {
|
|
|
2027
2188
|
if (typeof candidate !== "function" || !listVerbs(runner).includes(verb)) throw new RunnerError(`Runner "${specifier}" does not support the verb "${verb}". Supported verbs: ${listVerbs(runner).join(", ")}.`);
|
|
2028
2189
|
return candidate;
|
|
2029
2190
|
}
|
|
2030
|
-
function isRecord$
|
|
2191
|
+
function isRecord$3(value) {
|
|
2031
2192
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2032
2193
|
}
|
|
2033
2194
|
/** reactor XOR children, decided by the runner's declared `kind`. */
|
|
@@ -2052,7 +2213,7 @@ function assertKindShape(kind, specifier, host, file) {
|
|
|
2052
2213
|
* this runner exports. */
|
|
2053
2214
|
function knownVerbIssues(runner, specifier, host) {
|
|
2054
2215
|
const options = host.runner;
|
|
2055
|
-
if (!isRecord$
|
|
2216
|
+
if (!isRecord$3(options)) return [];
|
|
2056
2217
|
const verbs = listVerbs(runner);
|
|
2057
2218
|
const unknownVerb = (verb) => typeof verb === "string" && !verbs.includes(verb);
|
|
2058
2219
|
const issues = [];
|
|
@@ -2061,7 +2222,7 @@ function knownVerbIssues(runner, specifier, host) {
|
|
|
2061
2222
|
message: `runner.defaultVerb "${options.defaultVerb}" is not a verb of "${specifier}". Supported verbs: ${verbs.join(", ")}.`
|
|
2062
2223
|
});
|
|
2063
2224
|
(Array.isArray(options.plugins) ? options.plugins : []).forEach((entry, index) => {
|
|
2064
|
-
if (!isRecord$
|
|
2225
|
+
if (!isRecord$3(entry) || !Array.isArray(entry.verbs)) return;
|
|
2065
2226
|
const scoped = entry.verbs;
|
|
2066
2227
|
for (const bad of scoped.filter(unknownVerb)) issues.push({
|
|
2067
2228
|
path: `runner.plugins[${index}].verbs`,
|
|
@@ -2076,7 +2237,7 @@ function formatIssues(issues) {
|
|
|
2076
2237
|
function valueAt(host, path) {
|
|
2077
2238
|
let current = host;
|
|
2078
2239
|
for (const key of path) if (Array.isArray(current) && typeof key === "number") current = current[key];
|
|
2079
|
-
else if (isRecord$
|
|
2240
|
+
else if (isRecord$3(current) && typeof key === "string") current = current[key];
|
|
2080
2241
|
else return;
|
|
2081
2242
|
return current;
|
|
2082
2243
|
}
|
|
@@ -2092,7 +2253,7 @@ function validateHost(runner, specifier, host, file, options = {}) {
|
|
|
2092
2253
|
/** What `validateHost` checks, as data: nothing throws. */
|
|
2093
2254
|
function hostSchemaIssues(runner, schema, specifier, host, options = {}) {
|
|
2094
2255
|
const issues = [];
|
|
2095
|
-
if (isRecord$
|
|
2256
|
+
if (isRecord$3(host)) {
|
|
2096
2257
|
issues.push(...kindShapeIssues(runner.kind, specifier, host));
|
|
2097
2258
|
if (options.tokens !== "allow") {
|
|
2098
2259
|
const token = findToken(host);
|
|
@@ -2144,12 +2305,13 @@ function validateDeclaredHost(runner, specifier, host, file, options = {}) {
|
|
|
2144
2305
|
const issues = checkTokenSites(host);
|
|
2145
2306
|
if (options.outputsSchemaOf) issues.push(...checkOutputPaths(host, options.outputsSchemaOf));
|
|
2146
2307
|
if (issues.length > 0) throw new RunnerError(`${file}: invalid output token:\n${formatIssues(issues)}`);
|
|
2147
|
-
if (isRecord$
|
|
2308
|
+
if (isRecord$3(host)) assertKindShape(runner.kind, specifier, host, file);
|
|
2148
2309
|
if (!runner.declaredHostSchema) return;
|
|
2149
2310
|
parseHost(runner, runner.declaredHostSchema, specifier, host, file, { tokens: "allow" });
|
|
2150
2311
|
}
|
|
2151
2312
|
/**
|
|
2152
|
-
* Loads and pre-validates a `hosts/<name>/host.js` definition
|
|
2313
|
+
* Loads and pre-validates a `hosts/<name>/host.js` definition: the project's
|
|
2314
|
+
* own, or one an installed package supplies (`<package>/<host>`, host-ref.ts).
|
|
2153
2315
|
*
|
|
2154
2316
|
* A host file is a static PROJECTION of powerhouse.config.json: plain ESM,
|
|
2155
2317
|
* default-exporting a data object. Three gates run before any runner sees it:
|
|
@@ -2169,19 +2331,13 @@ function validateDeclaredHost(runner, specifier, host, file, options = {}) {
|
|
|
2169
2331
|
*/
|
|
2170
2332
|
const HOST_FILE = "host.js";
|
|
2171
2333
|
const CONFIG_IMPORT_SUFFIX = "powerhouse.config.json";
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
this.name = "HostLoadError";
|
|
2176
|
-
}
|
|
2177
|
-
};
|
|
2178
|
-
/** A `hosts/` folder with no `<name>/host.js` inside is "empty" — the guard
|
|
2179
|
-
* state: callers warn loudly and fall back to legacy rather than activating
|
|
2180
|
-
* the new architecture off a stray `mkdir hosts`. */
|
|
2334
|
+
/** A `hosts/` folder with no `<name>/host.js` inside is "empty": it defines
|
|
2335
|
+
* no host, so nothing runs from it, as from an absent one
|
|
2336
|
+
* ({@link withoutHostsMessage}). */
|
|
2181
2337
|
function probeHostsFolder(projectRoot) {
|
|
2182
2338
|
const dir = path.join(projectRoot, "hosts");
|
|
2183
|
-
|
|
2184
|
-
|
|
2339
|
+
const hosts = hostFolders(projectRoot);
|
|
2340
|
+
if (hosts === void 0) return { kind: "absent" };
|
|
2185
2341
|
return hosts.length === 0 ? {
|
|
2186
2342
|
kind: "empty",
|
|
2187
2343
|
dir
|
|
@@ -2191,6 +2347,14 @@ function probeHostsFolder(projectRoot) {
|
|
|
2191
2347
|
hosts
|
|
2192
2348
|
};
|
|
2193
2349
|
}
|
|
2350
|
+
/**
|
|
2351
|
+
* Why `subject` cannot run in a project whose hosts/ folder is absent or
|
|
2352
|
+
* empty, and what adds the host files. One wording, for `ph run <host>` and
|
|
2353
|
+
* for the `ph vetra`, `ph connect` and `ph switchboard` sugar.
|
|
2354
|
+
*/
|
|
2355
|
+
function withoutHostsMessage(probe, subject) {
|
|
2356
|
+
return `${probe.kind === "empty" ? `hosts/ exists at ${probe.dir} but contains no <name>/host.js` : "This project has no hosts/ folder"}, so ${subject} cannot run. Run \`ph migrate\` to add the host files.`;
|
|
2357
|
+
}
|
|
2194
2358
|
/** Sibling imports: `../<host>/host.js` — source material for derived
|
|
2195
2359
|
* compositions (full-inclusion wrappers compute over them with plain JS) —
|
|
2196
2360
|
* and `../<host>/outputs.js`, the generated `$output` token tree. */
|
|
@@ -2394,33 +2558,82 @@ function findNonStaticValue(value, trail = "") {
|
|
|
2394
2558
|
if (hit) return hit;
|
|
2395
2559
|
}
|
|
2396
2560
|
}
|
|
2561
|
+
/** Where a loaded host's module specifiers resolve from: its package's
|
|
2562
|
+
* folder, else the project root. */
|
|
2563
|
+
function moduleRootOf(projectRoot, loaded) {
|
|
2564
|
+
return loaded.package?.root ?? projectRoot;
|
|
2565
|
+
}
|
|
2397
2566
|
function assertHostShape(host, file) {
|
|
2398
2567
|
if (typeof host.name !== "string" || host.name.length === 0) throw new HostLoadError(`${file}: \`name\` must be a non-empty string.`);
|
|
2399
2568
|
const runner = host.runner;
|
|
2400
2569
|
if (runner === null || typeof runner !== "object" || typeof runner.module !== "string") throw new HostLoadError(`${file}: \`runner\` must be an object with a \`module\` specifier string.`);
|
|
2401
2570
|
if (host.reactor !== void 0 && host.children !== void 0) throw new HostLoadError(`${file}: \`reactor\` and \`children\` are mutually exclusive — a host is a reactor runner or a compound runner, never both.`);
|
|
2402
2571
|
}
|
|
2403
|
-
|
|
2404
|
-
|
|
2572
|
+
/** `hostName` is a ref: the project's folder name, or `<package>/<host>`. */
|
|
2573
|
+
async function loadHost(projectRoot, hostName, options = {}) {
|
|
2574
|
+
return importHost(projectRoot, hostName, true, false, options.scope);
|
|
2575
|
+
}
|
|
2576
|
+
const FRESH_IMPORT_WORKER = `
|
|
2577
|
+
const { parentPort, workerData } = require("node:worker_threads");
|
|
2578
|
+
import(workerData.url).then(
|
|
2579
|
+
(module) => {
|
|
2580
|
+
try {
|
|
2581
|
+
parentPort.postMessage({ host: module.default });
|
|
2582
|
+
} catch (error) {
|
|
2583
|
+
parentPort.postMessage({ error: String(error) });
|
|
2584
|
+
}
|
|
2585
|
+
},
|
|
2586
|
+
(error) => parentPort.postMessage({ error: String(error) }),
|
|
2587
|
+
);
|
|
2588
|
+
`;
|
|
2589
|
+
/** The default export of a module, evaluated in a worker: a worker has its
|
|
2590
|
+
* own module graph, so the file and its imports are read again. Host files
|
|
2591
|
+
* export data, which is what reaches this thread. */
|
|
2592
|
+
function importDefaultFresh(url, file) {
|
|
2593
|
+
return new Promise((resolve, reject) => {
|
|
2594
|
+
const worker = new Worker(FRESH_IMPORT_WORKER, {
|
|
2595
|
+
eval: true,
|
|
2596
|
+
workerData: { url }
|
|
2597
|
+
});
|
|
2598
|
+
const fail = (reason) => reject(new HostLoadError(`${file} could not be read again: ${reason}`));
|
|
2599
|
+
worker.once("message", (message) => {
|
|
2600
|
+
if (message.error !== void 0) fail(message.error);
|
|
2601
|
+
else resolve(message.host);
|
|
2602
|
+
worker.terminate();
|
|
2603
|
+
});
|
|
2604
|
+
worker.once("error", (error) => fail(String(error)));
|
|
2605
|
+
worker.once("exit", () => fail("its worker exited without an answer"));
|
|
2606
|
+
});
|
|
2405
2607
|
}
|
|
2406
|
-
|
|
2608
|
+
/** Where `ref` is; for the project's own host, the loader's messages when
|
|
2609
|
+
* its hosts/ folder lacks it. */
|
|
2610
|
+
function locateLoadable(projectRoot, ref, scope) {
|
|
2611
|
+
const location = locateHost(projectRoot, ref, scope);
|
|
2612
|
+
if (location.package) return location;
|
|
2407
2613
|
const probe = probeHostsFolder(projectRoot);
|
|
2408
|
-
if (probe.kind
|
|
2409
|
-
if (probe.
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
const
|
|
2614
|
+
if (probe.kind !== "present") throw new HostLoadError(withoutHostsMessage(probe, `the host "${ref}"`));
|
|
2615
|
+
if (!probe.hosts.includes(location.folder)) throw new HostLoadError(`Unknown host "${ref}". Available hosts: ${probe.hosts.join(", ")}.`);
|
|
2616
|
+
return location;
|
|
2617
|
+
}
|
|
2618
|
+
async function importHost(projectRoot, hostName, checkOutputs, fresh = false, scope) {
|
|
2619
|
+
const location = locateLoadable(projectRoot, hostName, scope);
|
|
2620
|
+
const { folder, hostsDir } = location;
|
|
2621
|
+
const file = path.join(hostsDir, folder, HOST_FILE);
|
|
2622
|
+
const producers = lintHostImportGraph(hostsDir, folder);
|
|
2623
|
+
if (checkOutputs) for (const producer of producers) await assertOutputsFileFresh(projectRoot, location, producer);
|
|
2624
|
+
const url = pathToFileURL(file).href;
|
|
2625
|
+
const host = fresh ? await importDefaultFresh(url, file) : (await import(url)).default;
|
|
2415
2626
|
if (host === null || typeof host !== "object" || Array.isArray(host)) throw new HostLoadError(`${file} must default-export the host object (\`export default { name, runner, ... }\`).`);
|
|
2416
2627
|
const nonStatic = findNonStaticValue(host);
|
|
2417
2628
|
if (nonStatic) throw new HostLoadError(`${file} exports a non-static value at \`${nonStatic}\` — host files must survive a JSON round trip.`, "Runtime behavior belongs in the runner; host files only carry data.");
|
|
2418
2629
|
assertHostShape(host, file);
|
|
2419
2630
|
return {
|
|
2420
|
-
name:
|
|
2631
|
+
name: folder,
|
|
2421
2632
|
dir: path.dirname(file),
|
|
2422
2633
|
file,
|
|
2423
|
-
host
|
|
2634
|
+
host,
|
|
2635
|
+
ref: location.ref,
|
|
2636
|
+
...location.package ? { package: location.package } : {}
|
|
2424
2637
|
};
|
|
2425
2638
|
}
|
|
2426
2639
|
const OUTPUTS_HASH_EXPORT = /^export const outputsHash = "([^"]+)";$/m;
|
|
@@ -2448,13 +2661,13 @@ function computeOutputsHash(input) {
|
|
|
2448
2661
|
function isZodSchema(value) {
|
|
2449
2662
|
return value !== null && typeof value === "object" && "_zod" in value;
|
|
2450
2663
|
}
|
|
2451
|
-
function isRecord$
|
|
2664
|
+
function isRecord$2(value) {
|
|
2452
2665
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
2453
2666
|
}
|
|
2454
2667
|
/** Local (non-remote) slugs from a drive declaration list. */
|
|
2455
2668
|
function localDriveSlugs(drives) {
|
|
2456
2669
|
if (!Array.isArray(drives)) return [];
|
|
2457
|
-
return drives.flatMap((drive) => isRecord$
|
|
2670
|
+
return drives.flatMap((drive) => isRecord$2(drive) && typeof drive.slug === "string" && drive.remote === void 0 ? [drive.slug] : []);
|
|
2458
2671
|
}
|
|
2459
2672
|
/**
|
|
2460
2673
|
* Describes the outputs a host's creation produces, for `ph generate hosts`
|
|
@@ -2470,45 +2683,53 @@ function localDriveSlugs(drives) {
|
|
|
2470
2683
|
* key (it is not declared); reach it with a literal `$output` token.
|
|
2471
2684
|
*/
|
|
2472
2685
|
async function describeHostOutputs(projectRoot, hostName) {
|
|
2473
|
-
const
|
|
2686
|
+
const loaded = await importHost(projectRoot, hostName, false);
|
|
2687
|
+
const { host, file } = loaded;
|
|
2688
|
+
const moduleRoot = moduleRootOf(projectRoot, loaded);
|
|
2474
2689
|
const runnerModule = host.runner.module;
|
|
2475
|
-
const schema = (await resolveRunnerModule(
|
|
2690
|
+
const schema = (await resolveRunnerModule(moduleRoot, runnerModule)).outputsSchema;
|
|
2476
2691
|
if (!isZodSchema(schema)) return void 0;
|
|
2477
2692
|
const { $schema: _dialect, ...outputsSchema } = toJSONSchema(schema, {
|
|
2478
2693
|
io: "output",
|
|
2479
2694
|
unrepresentable: "any"
|
|
2480
2695
|
});
|
|
2481
2696
|
const reactor = host.reactor;
|
|
2482
|
-
const drives = localDriveSlugs(isRecord$
|
|
2697
|
+
const drives = localDriveSlugs(isRecord$2(reactor) ? reactor.drives : []);
|
|
2483
2698
|
const entries = (host.runner.plugins ?? []).map((entry) => typeof entry === "string" ? entry : {
|
|
2484
2699
|
...entry,
|
|
2485
2700
|
verbs: "*"
|
|
2486
2701
|
});
|
|
2487
2702
|
if (entries.length > 0) {
|
|
2488
|
-
const plan = await resolvePluginContributions(
|
|
2703
|
+
const plan = await resolvePluginContributions(moduleRoot, "*", entries, path.relative(projectRoot, file));
|
|
2489
2704
|
drives.push(...localDriveSlugs(plan.drives.map((drive) => drive.declaration)));
|
|
2490
2705
|
}
|
|
2491
2706
|
const sortedDrives = [...new Set(drives)].sort();
|
|
2707
|
+
const folder = loaded.name;
|
|
2492
2708
|
return {
|
|
2493
|
-
host:
|
|
2709
|
+
host: folder,
|
|
2494
2710
|
runnerModule,
|
|
2495
2711
|
outputsSchema,
|
|
2496
2712
|
drives: sortedDrives,
|
|
2497
2713
|
hash: computeOutputsHash({
|
|
2498
|
-
host:
|
|
2714
|
+
host: folder,
|
|
2499
2715
|
runnerModule,
|
|
2500
2716
|
outputsSchema,
|
|
2501
2717
|
drives: sortedDrives
|
|
2502
2718
|
})
|
|
2503
2719
|
};
|
|
2504
2720
|
}
|
|
2505
|
-
async function assertOutputsFileFresh(projectRoot,
|
|
2506
|
-
const
|
|
2721
|
+
async function assertOutputsFileFresh(projectRoot, consumer, producer) {
|
|
2722
|
+
const { hostsDir } = consumer;
|
|
2723
|
+
const where = consumer.package ? `${consumer.package.name}/` : "";
|
|
2724
|
+
const rel = `${where}hosts/${producer}/${OUTPUTS_FILE}`;
|
|
2507
2725
|
const actual = readOutputsFileHash(readFileSync(path.join(hostsDir, producer, OUTPUTS_FILE), "utf8"));
|
|
2508
|
-
if (!existsSync(path.join(hostsDir, producer, HOST_FILE))) throw new HostLoadError(
|
|
2509
|
-
const description = await describeHostOutputs(projectRoot,
|
|
2510
|
-
|
|
2511
|
-
|
|
2726
|
+
if (!existsSync(path.join(hostsDir, producer, HOST_FILE))) throw new HostLoadError(`${where}hosts/${consumer.folder} imports ${rel}, but there is no ${hostFileLabel(producer, consumer.package)} to produce it.`, "Delete the orphaned outputs.js and fix the import.");
|
|
2727
|
+
const description = await describeHostOutputs(projectRoot, formatHostRef({
|
|
2728
|
+
package: consumer.package?.name,
|
|
2729
|
+
host: producer
|
|
2730
|
+
}));
|
|
2731
|
+
if (!description) throw new HostLoadError(`${where}hosts/${consumer.folder} imports ${rel}, but ${where}hosts/${producer}'s runner declares no outputsSchema, so it produces no outputs.`);
|
|
2732
|
+
if (actual !== description.hash) throw new HostLoadError(consumer.package ? `${rel} is stale against the runner this project resolves for it (its outputsSchema or declared drives differ from those it was generated from): package "${consumer.package.name}" was built against another version of "${description.runnerModule}".` : `${rel} is stale (its producer's outputsSchema or declared drives changed since it was generated); run \`ph generate hosts\`.`, actual === void 0 ? `${rel} carries no outputsHash export; it was not generated by \`ph generate hosts\`.` : `expected ${description.hash}, found ${actual}.`);
|
|
2512
2733
|
}
|
|
2513
2734
|
const OWN_FLAGS = /* @__PURE__ */ new Set([
|
|
2514
2735
|
"--debug",
|
|
@@ -2549,11 +2770,14 @@ function splitRunArgv(args) {
|
|
|
2549
2770
|
* host and its members produced. Validated on read; a v1 (or any invalid)
|
|
2550
2771
|
* record reads as "not running". `projectName` is kept beyond the plan's
|
|
2551
2772
|
* sketch because the live/foreign probe needs it. `host` is the host's
|
|
2552
|
-
* `name` (the file key), not its folder.
|
|
2773
|
+
* `name` (the file key), not its folder. A host an installed package
|
|
2774
|
+
* supplies has its record in a folder named after the package,
|
|
2775
|
+
* `.ph/run/<package>/<host>.json`, and says which in `package`.
|
|
2553
2776
|
*/
|
|
2554
2777
|
const outputsSchema = record(string(), unknown());
|
|
2555
2778
|
const runRecordMemberSchema = strictObject({
|
|
2556
|
-
/** The member's host folder
|
|
2779
|
+
/** The member's host as the project addresses it: its folder, or
|
|
2780
|
+
* `<package>/<host>` for one a package supplies. */
|
|
2557
2781
|
host: string().min(1),
|
|
2558
2782
|
runnerModule: string().min(1),
|
|
2559
2783
|
kind: runnerKindSchema,
|
|
@@ -2563,6 +2787,9 @@ const runRecordMemberSchema = strictObject({
|
|
|
2563
2787
|
const runRecordSchema = strictObject({
|
|
2564
2788
|
version: literal(2),
|
|
2565
2789
|
host: hostNameSchema,
|
|
2790
|
+
/** The installed package that supplies the host; absent for the
|
|
2791
|
+
* project's own. */
|
|
2792
|
+
package: string().regex(PACKAGE_NAME_PATTERN).optional(),
|
|
2566
2793
|
projectName: string(),
|
|
2567
2794
|
kind: runnerKindSchema,
|
|
2568
2795
|
verb: string().min(1),
|
|
@@ -2575,13 +2802,49 @@ const runRecordSchema = strictObject({
|
|
|
2575
2802
|
/** Host-specific extras (e.g. mcpUrl) a runner wants in the record. */
|
|
2576
2803
|
extra: record(string(), unknown()).optional()
|
|
2577
2804
|
});
|
|
2805
|
+
/** The key a host's record is filed under: its `name`, behind the package
|
|
2806
|
+
* that supplies it when it is not the project's own (`@acme/tools/studio`),
|
|
2807
|
+
* as `ph run` addresses the host. */
|
|
2808
|
+
function runRecordKey(name, hostPackage) {
|
|
2809
|
+
return hostPackage === void 0 ? name : `${hostPackage}/${name}`;
|
|
2810
|
+
}
|
|
2578
2811
|
const runDir = (projectDir, env = process.env) => path.join(resolvePhDir(projectDir, env), "run");
|
|
2579
|
-
function recordPath(projectDir,
|
|
2812
|
+
function recordPath(projectDir, key, env) {
|
|
2580
2813
|
const dir = runDir(projectDir, env);
|
|
2581
|
-
const
|
|
2582
|
-
|
|
2814
|
+
const slash = key.lastIndexOf("/");
|
|
2815
|
+
const hostName = key.slice(slash + 1);
|
|
2816
|
+
const pkg = slash === -1 ? void 0 : key.slice(0, slash);
|
|
2817
|
+
const folder = pkg === void 0 ? path.resolve(dir) : path.resolve(dir, ...pkg.split("/"));
|
|
2818
|
+
const file = path.resolve(folder, `${hostName}.json`);
|
|
2819
|
+
if (!hostNameSchema.safeParse(hostName).success || pkg !== void 0 && !PACKAGE_NAME_PATTERN.test(pkg) || path.dirname(file) !== folder) throw new Error(`"${key}" can't name a run record. ${HOST_NAME_MESSAGE}`);
|
|
2583
2820
|
return file;
|
|
2584
2821
|
}
|
|
2822
|
+
/** The record keys under `.ph/run/`: `<name>.json` files, and those in a
|
|
2823
|
+
* package's folder (`<pkg>/` or `@scope/<pkg>/`). */
|
|
2824
|
+
function recordKeys(dir) {
|
|
2825
|
+
const entries = (at) => {
|
|
2826
|
+
try {
|
|
2827
|
+
return fs.readdirSync(at, { withFileTypes: true });
|
|
2828
|
+
} catch {
|
|
2829
|
+
return [];
|
|
2830
|
+
}
|
|
2831
|
+
};
|
|
2832
|
+
const records = (at, prefix) => entries(at).filter((entry) => entry.isFile() && entry.name.endsWith(".json")).map((entry) => `${prefix}${entry.name.slice(0, -5)}`);
|
|
2833
|
+
const keys = records(dir, "");
|
|
2834
|
+
for (const entry of entries(dir)) {
|
|
2835
|
+
if (!entry.isDirectory()) continue;
|
|
2836
|
+
const at = path.join(dir, entry.name);
|
|
2837
|
+
if (!entry.name.startsWith("@")) {
|
|
2838
|
+
keys.push(...records(at, `${entry.name}/`));
|
|
2839
|
+
continue;
|
|
2840
|
+
}
|
|
2841
|
+
for (const inner of entries(at)) {
|
|
2842
|
+
if (!inner.isDirectory()) continue;
|
|
2843
|
+
keys.push(...records(path.join(at, inner.name), `${entry.name}/${inner.name}/`));
|
|
2844
|
+
}
|
|
2845
|
+
}
|
|
2846
|
+
return keys;
|
|
2847
|
+
}
|
|
2585
2848
|
function readRunRecord(projectDir, hostName, env = process.env) {
|
|
2586
2849
|
let raw;
|
|
2587
2850
|
try {
|
|
@@ -2592,16 +2855,11 @@ function readRunRecord(projectDir, hostName, env = process.env) {
|
|
|
2592
2855
|
const parsed = runRecordSchema.safeParse(raw);
|
|
2593
2856
|
return parsed.success ? parsed.data : void 0;
|
|
2594
2857
|
}
|
|
2595
|
-
/** Every valid v2 record under `.ph/run
|
|
2858
|
+
/** Every valid v2 record under `.ph/run/`, package hosts' included (invalid
|
|
2859
|
+
* and v1 files skipped). */
|
|
2596
2860
|
function listRunRecords(projectDir, env = process.env) {
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
files = fs.readdirSync(runDir(projectDir, env));
|
|
2600
|
-
} catch {
|
|
2601
|
-
return [];
|
|
2602
|
-
}
|
|
2603
|
-
return files.filter((file) => file.endsWith(".json")).flatMap((file) => {
|
|
2604
|
-
const record = readRunRecord(projectDir, file.slice(0, -5), env);
|
|
2861
|
+
return recordKeys(runDir(projectDir, env)).flatMap((key) => {
|
|
2862
|
+
const record = readRunRecord(projectDir, key, env);
|
|
2605
2863
|
return record ? [record] : [];
|
|
2606
2864
|
});
|
|
2607
2865
|
}
|
|
@@ -2706,6 +2964,42 @@ function probeRun(projectDir, hostName, projectName, env = process.env) {
|
|
|
2706
2964
|
record
|
|
2707
2965
|
};
|
|
2708
2966
|
}
|
|
2967
|
+
/**
|
|
2968
|
+
* Windows has no SIGTERM: `process.kill(pid, "SIGTERM")` ends the process at
|
|
2969
|
+
* once, so no handler runs and a stack's stores are left as a crash leaves
|
|
2970
|
+
* them. A started host therefore listens on a pipe named after its pid, and
|
|
2971
|
+
* a connection to it is delivered as the SIGTERM it stands for. Elsewhere
|
|
2972
|
+
* the signal itself does this, and there is no channel.
|
|
2973
|
+
*/
|
|
2974
|
+
function stopChannelPath(pid, platform = process.platform) {
|
|
2975
|
+
return platform === "win32" ? `\\\\.\\pipe\\ph-stop-${pid}` : void 0;
|
|
2976
|
+
}
|
|
2977
|
+
const ASK_TIMEOUT_MS = 2e3;
|
|
2978
|
+
/** Connects to a stop channel; true once the listener took the request. */
|
|
2979
|
+
function askToStop(channel, timeoutMs = ASK_TIMEOUT_MS) {
|
|
2980
|
+
return new Promise((resolve) => {
|
|
2981
|
+
let connected = false;
|
|
2982
|
+
const socket = net.connect(channel);
|
|
2983
|
+
socket.setTimeout(timeoutMs, () => socket.destroy());
|
|
2984
|
+
socket.once("connect", () => connected = true);
|
|
2985
|
+
socket.on("error", () => void 0);
|
|
2986
|
+
socket.once("close", () => resolve(connected));
|
|
2987
|
+
socket.resume();
|
|
2988
|
+
});
|
|
2989
|
+
}
|
|
2990
|
+
/**
|
|
2991
|
+
* Asks the process to stop as SIGTERM would. False when it could not be
|
|
2992
|
+
* asked: on Windows a process without a stop channel (started by an older
|
|
2993
|
+
* version, or not a host), which only a kill ends.
|
|
2994
|
+
*/
|
|
2995
|
+
async function requestStop(pid, platform = process.platform) {
|
|
2996
|
+
const channel = stopChannelPath(pid, platform);
|
|
2997
|
+
if (channel) return askToStop(channel);
|
|
2998
|
+
try {
|
|
2999
|
+
process.kill(pid, "SIGTERM");
|
|
3000
|
+
} catch {}
|
|
3001
|
+
return true;
|
|
3002
|
+
}
|
|
2709
3003
|
/** Generic compound rule: `reactor`/`config` replace, `runner` key-merges. */
|
|
2710
3004
|
function applyChildWrapper(base, wrapper) {
|
|
2711
3005
|
const reactor = wrapper.reactor ?? base.reactor;
|
|
@@ -2734,19 +3028,22 @@ function applyChildWrapper(base, wrapper) {
|
|
|
2734
3028
|
function defaultUserDataDir(projectRoot, env = process.env) {
|
|
2735
3029
|
return env.PH_USER_DATA_DIR ?? path.resolve(projectRoot);
|
|
2736
3030
|
}
|
|
2737
|
-
/** Load every producer host a set of refs names (each once).
|
|
2738
|
-
|
|
3031
|
+
/** Load every producer host a set of refs names (each once). In a host a
|
|
3032
|
+
* package supplies (`scope`), a bare name is that package's host first. */
|
|
3033
|
+
async function loadProducers(projectRoot, refs, scope) {
|
|
2739
3034
|
const producers = /* @__PURE__ */ new Map();
|
|
2740
3035
|
for (const { host: folder } of refs) {
|
|
2741
3036
|
if (producers.has(folder)) continue;
|
|
2742
3037
|
try {
|
|
2743
|
-
const loaded = await loadHost(projectRoot, folder);
|
|
3038
|
+
const loaded = await loadHost(projectRoot, folder, { scope });
|
|
2744
3039
|
const specifier = loaded.host.runner.module;
|
|
2745
3040
|
producers.set(folder, {
|
|
2746
3041
|
folder,
|
|
2747
3042
|
name: loaded.host.name,
|
|
3043
|
+
...loaded.ref !== void 0 ? { ref: loaded.ref } : {},
|
|
3044
|
+
...loaded.package ? { package: loaded.package } : {},
|
|
2748
3045
|
specifier,
|
|
2749
|
-
runner: await resolveRunnerModule(projectRoot, specifier)
|
|
3046
|
+
runner: await resolveRunnerModule(moduleRootOf(projectRoot, loaded), specifier)
|
|
2750
3047
|
});
|
|
2751
3048
|
} catch (error) {
|
|
2752
3049
|
producers.set(folder, { error: `names host "${folder}", which cannot be loaded: ${error instanceof Error ? error.message : String(error)}` });
|
|
@@ -2792,28 +3089,31 @@ function runRecordOutputSource(projectRoot, options) {
|
|
|
2792
3089
|
const env = options.env ?? process.env;
|
|
2793
3090
|
const siblings = siblingEnvs(projectRoot, env);
|
|
2794
3091
|
return { lookup(ref) {
|
|
2795
|
-
const notRunning = `${consumer} needs outputs from host "${ref.host}", which is not running. Start it first: ph run ${ref.host} (or run a compound that includes it).`;
|
|
2796
3092
|
const info = producers.get(ref.host);
|
|
2797
|
-
const
|
|
3093
|
+
const loaded = info && !("error" in info) ? info : void 0;
|
|
3094
|
+
const address = loaded?.ref ?? ref.host;
|
|
3095
|
+
const notRunning = `${consumer} needs outputs from host "${address}", which is not running. Start it first: ph run ${address} (or run a compound that includes it).`;
|
|
3096
|
+
const schema = loaded?.runner.outputsSchema;
|
|
2798
3097
|
const withSchema = schema !== void 0 && schema !== null ? { schema } : {};
|
|
2799
3098
|
const standalone = [];
|
|
2800
|
-
if (ref.member === void 0 &&
|
|
2801
|
-
const
|
|
3099
|
+
if (ref.member === void 0 && loaded) {
|
|
3100
|
+
const key = runRecordKey(loaded.name, loaded.package?.name);
|
|
3101
|
+
const probe = probeRun(projectRoot, key, projectName, env);
|
|
2802
3102
|
if (probe.status === "live" && probe.record.outputs) return {
|
|
2803
3103
|
status: "available",
|
|
2804
3104
|
outputs: probe.record.outputs,
|
|
2805
3105
|
...withSchema
|
|
2806
3106
|
};
|
|
2807
3107
|
for (const sibling of siblings) {
|
|
2808
|
-
const other = probeRun(projectRoot,
|
|
3108
|
+
const other = probeRun(projectRoot, key, projectName, sibling);
|
|
2809
3109
|
if (other.status === "live" && other.record.outputs) standalone.push({
|
|
2810
|
-
label: `"${
|
|
3110
|
+
label: `"${loaded.name}" (pid ${other.record.pid})`,
|
|
2811
3111
|
outputs: other.record.outputs
|
|
2812
3112
|
});
|
|
2813
3113
|
}
|
|
2814
3114
|
}
|
|
2815
|
-
const members = [env, ...siblings].flatMap((root) => listRunRecords(projectRoot, root)).filter((record) => record.members !== void 0 && record.projectName === projectName && isPidAlive(record.pid)).flatMap((record) => Object.entries(record.members ?? {}).filter(([key, member]) => member.host ===
|
|
2816
|
-
label: `member "${key}" of "${record.host}"`,
|
|
3115
|
+
const members = [env, ...siblings].flatMap((root) => listRunRecords(projectRoot, root)).filter((record) => record.members !== void 0 && record.projectName === projectName && isPidAlive(record.pid)).flatMap((record) => Object.entries(record.members ?? {}).filter(([key, member]) => member.host === address && (ref.member === void 0 || key === ref.member)).map(([key, member]) => ({
|
|
3116
|
+
label: `member "${key}" of "${runRecordKey(record.host, record.package)}"`,
|
|
2817
3117
|
outputs: member.outputs
|
|
2818
3118
|
})));
|
|
2819
3119
|
const found = [...standalone, ...members];
|
|
@@ -2824,7 +3124,7 @@ function runRecordOutputSource(projectRoot, options) {
|
|
|
2824
3124
|
};
|
|
2825
3125
|
if (found.length > 1) return {
|
|
2826
3126
|
status: "unavailable",
|
|
2827
|
-
message: `${consumer} needs outputs from host "${
|
|
3127
|
+
message: `${consumer} needs outputs from host "${address}", which runs as ${found.map((m) => m.label).join(" and ")}; stop all but one, or run ${address} on its own.`
|
|
2828
3128
|
};
|
|
2829
3129
|
return {
|
|
2830
3130
|
status: "unavailable",
|
|
@@ -2833,13 +3133,16 @@ function runRecordOutputSource(projectRoot, options) {
|
|
|
2833
3133
|
} };
|
|
2834
3134
|
}
|
|
2835
3135
|
/** The resolving process's `$env` inputs: its environment plus the
|
|
2836
|
-
* always-resolvable built-ins (`userData` honours PH_USER_DATA_DIR).
|
|
2837
|
-
|
|
3136
|
+
* always-resolvable built-ins (`userData` honours PH_USER_DATA_DIR).
|
|
3137
|
+
* `package` is the root of the package that supplies the host being
|
|
3138
|
+
* resolved (`hostPackage`), else the project root. */
|
|
3139
|
+
function processResolveEnv(projectRoot, env = process.env, hostPackage) {
|
|
2838
3140
|
return {
|
|
2839
3141
|
env,
|
|
2840
3142
|
builtins: {
|
|
2841
3143
|
userData: defaultUserDataDir(projectRoot, env),
|
|
2842
|
-
projectRoot: path.resolve(projectRoot)
|
|
3144
|
+
projectRoot: path.resolve(projectRoot),
|
|
3145
|
+
package: hostPackage?.root ?? path.resolve(projectRoot)
|
|
2843
3146
|
}
|
|
2844
3147
|
};
|
|
2845
3148
|
}
|
|
@@ -2870,9 +3173,6 @@ function compoundOutputSource(members, started, compound, schemas) {
|
|
|
2870
3173
|
} };
|
|
2871
3174
|
}
|
|
2872
3175
|
looseObject({ outputs: record(string(), unknown()).optional() });
|
|
2873
|
-
async function memberDraft(projectRoot, member) {
|
|
2874
|
-
return applyChildWrapper((await loadHost(projectRoot, member.host)).host, member);
|
|
2875
|
-
}
|
|
2876
3176
|
/** Whether a member receives the compound's `cspRegistrySync` wiring (as
|
|
2877
3177
|
* `runner.cspRegistrySync`): its runner declares that option (any specifier
|
|
2878
3178
|
* that reaches the Connect runner), or it names the Connect runner. A
|
|
@@ -2880,6 +3180,58 @@ async function memberDraft(projectRoot, member) {
|
|
|
2880
3180
|
function takesCspRegistrySync(m) {
|
|
2881
3181
|
return m.specifier === "@powerhousedao/ph-cli/runners/connect" || declaresKey(m.runner.hostSchema, ["runner"], "cspRegistrySync");
|
|
2882
3182
|
}
|
|
3183
|
+
/**
|
|
3184
|
+
* The member whose runner owns the terminal (`foreground: true`) and the
|
|
3185
|
+
* order the compound starts its members in. Its rules: one such member at
|
|
3186
|
+
* most, in the compound's process, and last, so no member reads its outputs
|
|
3187
|
+
* and a `startOrder` that names it puts it at the end. `runCompound` refuses
|
|
3188
|
+
* the first broken one; `ph host check` reports them all.
|
|
3189
|
+
*/
|
|
3190
|
+
function planForeground(members, plan, wiring) {
|
|
3191
|
+
const owners = members.filter((m) => m.runner.foreground === true);
|
|
3192
|
+
if (owners.length === 0) return {
|
|
3193
|
+
order: plan.order,
|
|
3194
|
+
issues: []
|
|
3195
|
+
};
|
|
3196
|
+
if (owners.length > 1) return {
|
|
3197
|
+
order: plan.order,
|
|
3198
|
+
issues: [{
|
|
3199
|
+
path: "children",
|
|
3200
|
+
message: `members ${owners.map((m) => `"${m.key}"`).join(", ")} each run a runner that owns the terminal; a compound has one.`
|
|
3201
|
+
}]
|
|
3202
|
+
};
|
|
3203
|
+
const [owner] = owners;
|
|
3204
|
+
const where = `member "${owner.key}" (${owner.specifier})`;
|
|
3205
|
+
const issues = [];
|
|
3206
|
+
if (owner.member.process === "own") issues.push({
|
|
3207
|
+
path: `children.${owner.key}.process`,
|
|
3208
|
+
message: `${where} owns the terminal, so it runs in the compound's process, not its own.`,
|
|
3209
|
+
hint: `Remove children.${owner.key}.process.`
|
|
3210
|
+
});
|
|
3211
|
+
const readers = plan.edges.filter((edge) => edge.producer === owner.key);
|
|
3212
|
+
if (readers.length > 0) issues.push({
|
|
3213
|
+
path: "children",
|
|
3214
|
+
message: `${readers.map((edge) => `${edge.consumer}.${edge.path}`).join(", ")} read the outputs of ${where}, which owns the terminal and starts last.`
|
|
3215
|
+
});
|
|
3216
|
+
const named = wiring.startOrder;
|
|
3217
|
+
if (named?.includes(owner.key) && named.at(-1) !== owner.key) issues.push({
|
|
3218
|
+
path: "config.startOrder",
|
|
3219
|
+
message: `config.startOrder starts ${where} before ${named.slice(named.indexOf(owner.key) + 1).join(", ")}, but it owns the terminal and starts last.`,
|
|
3220
|
+
hint: "Put it last in startOrder, or leave it out."
|
|
3221
|
+
});
|
|
3222
|
+
return {
|
|
3223
|
+
foreground: owner.key,
|
|
3224
|
+
order: [...plan.order.filter((key) => key !== owner.key), owner.key],
|
|
3225
|
+
issues
|
|
3226
|
+
};
|
|
3227
|
+
}
|
|
3228
|
+
/** Where a member runs: `own` (a child process) or `shared` (the
|
|
3229
|
+
* compound's). The foreground member and every member at a one-shot verb
|
|
3230
|
+
* share the compound's; next to a foreground member the default is `own`. */
|
|
3231
|
+
function memberProcessOf(member, options) {
|
|
3232
|
+
if (options.foreground || options.oneShot) return "shared";
|
|
3233
|
+
return member.process ?? (options.besideForeground ? "own" : "shared");
|
|
3234
|
+
}
|
|
2883
3235
|
/** The verb the generic compound starts its members at for its own `verb`:
|
|
2884
3236
|
* `run` follows the compound's defaultVerb. */
|
|
2885
3237
|
function compoundStartVerb(verb, runner) {
|
|
@@ -2891,21 +3243,52 @@ function compoundStartVerb(verb, runner) {
|
|
|
2891
3243
|
function memberVerbOf(compoundVerb, runner) {
|
|
2892
3244
|
return compoundVerb === "run" ? runner.defaultVerb ?? "run" : compoundVerb;
|
|
2893
3245
|
}
|
|
2894
|
-
/** One member's draft and runner.
|
|
2895
|
-
|
|
2896
|
-
|
|
3246
|
+
/** One member's draft and runner. `scope`: the package whose compound names
|
|
3247
|
+
* the member, where a bare member host is looked up first; the runner
|
|
3248
|
+
* resolves from the package that supplies the member's host. */
|
|
3249
|
+
async function prepareMember(projectRoot, key, member, scope) {
|
|
3250
|
+
const loaded = await loadHost(projectRoot, member.host, { scope });
|
|
3251
|
+
const draft = applyChildWrapper(loaded.host, member);
|
|
2897
3252
|
const specifier = draft.runner.module;
|
|
2898
3253
|
return {
|
|
2899
3254
|
key,
|
|
2900
3255
|
member,
|
|
2901
3256
|
draft,
|
|
2902
3257
|
specifier,
|
|
2903
|
-
runner: await resolveRunnerModule(projectRoot, specifier),
|
|
2904
|
-
file:
|
|
3258
|
+
runner: await resolveRunnerModule(moduleRootOf(projectRoot, loaded), specifier),
|
|
3259
|
+
file: hostFileLabel(loaded.name, loaded.package),
|
|
3260
|
+
ref: loaded.ref ?? member.host,
|
|
3261
|
+
...loaded.package ? { hostPackage: loaded.package } : {}
|
|
2905
3262
|
};
|
|
2906
3263
|
}
|
|
3264
|
+
/**
|
|
3265
|
+
* A compound that is, through its compound members, a member of itself
|
|
3266
|
+
* would start itself without end: the chain of hosts, as the project
|
|
3267
|
+
* addresses them, when there is one. Each compound member's own members are
|
|
3268
|
+
* looked up as it looks them up (its package first, for a package's). A
|
|
3269
|
+
* reactor member ends a chain.
|
|
3270
|
+
*/
|
|
3271
|
+
async function memberCycle(projectRoot, prepared) {
|
|
3272
|
+
const walk = async (chain, children, scope) => {
|
|
3273
|
+
for (const member of Object.values(children)) {
|
|
3274
|
+
const loaded = await loadHost(projectRoot, member.host, { scope });
|
|
3275
|
+
const ref = loaded.ref ?? member.host;
|
|
3276
|
+
if (chain.includes(ref)) return [...chain, ref];
|
|
3277
|
+
const nested = loaded.host.children;
|
|
3278
|
+
if (!isPlainObject(nested)) continue;
|
|
3279
|
+
const found = await walk([...chain, ref], nested, loaded.package);
|
|
3280
|
+
if (found) return found;
|
|
3281
|
+
}
|
|
3282
|
+
};
|
|
3283
|
+
for (const m of prepared) {
|
|
3284
|
+
const nested = m.draft.children;
|
|
3285
|
+
if (!isPlainObject(nested)) continue;
|
|
3286
|
+
const found = await walk([m.ref], nested, m.hostPackage);
|
|
3287
|
+
if (found) return found;
|
|
3288
|
+
}
|
|
3289
|
+
}
|
|
2907
3290
|
//#endregion
|
|
2908
|
-
export {
|
|
3291
|
+
export { resolveRunnerModule as $, memberCycle as A, planCompound as B, hostSchemaIssues as C, kindShapeIssues as D, isToken as E, normalizePluginEntries as F, processResolveEnv as G, prepareMember as H, normalizePluginEntry as I, readProjectName as J, producerOutputsSchemas as K, outputRefsOf as L, memberProcessOf as M, memberVerbOf as N, loadHost as O, moduleRootOf as P, resolvePluginContributions as Q, outputSitesOf as R, hostFileLabel as S, isPlainObject as T, probeHostsFolder as U, planForeground as V, probeRun as W, requestStop as X, renderTokens as Y, resolveHostOutputs as Z, envSitesOf as _, STORE_VERBS as a, takesCspRegistrySync as at, formatPath as b, checkOutputPaths as c, validateHost as ct, compoundOutputSource as d, runRecordKey as et, compoundStartVerb as f, entryActiveForVerb as g, drivesSchema as h, RunnerError as i, substituteBuiltinEnv as it, memberForRef as j, loadProducers as k, checkTokenSites as l, withoutHostsMessage as lt, describeToken as m, HostLoadError as n, runnerOutputsSchema as nt, TokenResolutionError as o, unsetEnvMessage as ot, declaredHostSchemas as p, projectDriveIdWith as q, ONE_SHOT_VERBS as r, splitRunArgv as rt, applyChildWrapper as s, validateDeclaredHost as st, CONNECT_RUNNER as t, runRecordOutputSource as tt, collectTokenSites as u, findDeadConnectConfig as v, isBuiltinEnvName as w, getVerb as x, findRemovedForms as y, packageBuildRefusal as z };
|
|
2909
3292
|
|
|
2910
|
-
//# sourceMappingURL=compound-
|
|
2911
|
-
//# debugId=
|
|
3293
|
+
//# sourceMappingURL=compound-n-bO0qKh-Dx7fgKWx.mjs.map
|
|
3294
|
+
//# debugId=3552b73c-5e7a-51b0-b33e-d0b1161b9c52
|