@powerhousedao/ph-cli 6.2.3-dev.7 → 6.2.3-dev.71
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/{auth-AR3VxAIk.mjs → auth-BFUq7CvE.mjs} +3 -3
- package/dist/{auth-AR3VxAIk.mjs.map → auth-BFUq7CvE.mjs.map} +1 -1
- package/dist/auth-CNhbN5UM.mjs +4 -0
- package/dist/build-C78yPntL.mjs +4 -0
- package/dist/build-Dj8qfSSe.mjs +349 -0
- package/dist/build-Dj8qfSSe.mjs.map +1 -0
- package/dist/{cli-connect-override-D3hh4aH_.mjs → cli-connect-override-CEJhQWRX.mjs} +39 -27
- package/dist/cli-connect-override-CEJhQWRX.mjs.map +1 -0
- package/dist/cli.d.mts +2 -1
- package/dist/cli.mjs +31 -1175
- package/dist/cli.mjs.map +1 -1
- package/dist/compound-B6RZMA0Y-Cv3XMQ3Y.mjs +2459 -0
- package/dist/compound-B6RZMA0Y-Cv3XMQ3Y.mjs.map +1 -0
- package/dist/connect-build-BfhOGbha.mjs +253 -0
- package/dist/connect-build-BfhOGbha.mjs.map +1 -0
- package/dist/{connect-config-BWGiW3IB.mjs → connect-config-DblqJgxR.mjs} +19 -12
- package/dist/connect-config-DblqJgxR.mjs.map +1 -0
- package/dist/connect-plugin-configs-D2fwYpMw.mjs +50 -0
- package/dist/connect-plugin-configs-D2fwYpMw.mjs.map +1 -0
- package/dist/connect-preview-8-qLgWKt.mjs +215 -0
- package/dist/connect-preview-8-qLgWKt.mjs.map +1 -0
- package/dist/{connect-studio-D6rfWCNB.mjs → connect-studio-DX7r4iyI.mjs} +18 -11
- package/dist/connect-studio-DX7r4iyI.mjs.map +1 -0
- package/dist/connect-studio-DmjcV8I2.mjs +4 -0
- package/dist/dist-CCLkwpTS.mjs +313 -0
- package/dist/dist-CCLkwpTS.mjs.map +1 -0
- package/dist/explain-DUXbB9jf.mjs +241 -0
- package/dist/explain-DUXbB9jf.mjs.map +1 -0
- package/dist/feature-flags-xwqcHEWC.mjs +4 -0
- package/dist/{generate-all-DrT4ZxHX.mjs → generate-all-Dgyy_kT-.mjs} +9 -3
- package/dist/generate-all-Dgyy_kT-.mjs.map +1 -0
- package/dist/{generate-app-DNNqA-H3.mjs → generate-app-BTs1u-9l.mjs} +7 -5
- package/dist/{generate-app-DNNqA-H3.mjs.map → generate-app-BTs1u-9l.mjs.map} +1 -1
- package/dist/generate-desktop-shell-Bj_3bJDL.mjs +317 -0
- package/dist/generate-desktop-shell-Bj_3bJDL.mjs.map +1 -0
- package/dist/{generate-document-model-BJXyODfm.mjs → generate-document-model-BfFIQ35q.mjs} +19 -7
- package/dist/generate-document-model-BfFIQ35q.mjs.map +1 -0
- package/dist/{generate-editor-BejvaVVT.mjs → generate-editor-CW7Do69u.mjs} +7 -5
- package/dist/{generate-editor-BejvaVVT.mjs.map → generate-editor-CW7Do69u.mjs.map} +1 -1
- package/dist/generate-hosts-BFmPIW2X.mjs +18 -0
- package/dist/generate-hosts-BFmPIW2X.mjs.map +1 -0
- package/dist/generate-hosts-RWj7WPHZ.mjs +4 -0
- package/dist/generate-piece-QTt-ddt2.mjs +65 -0
- package/dist/generate-piece-QTt-ddt2.mjs.map +1 -0
- package/dist/generate-piece-action-DbxrzfKY.mjs +29 -0
- package/dist/generate-piece-action-DbxrzfKY.mjs.map +1 -0
- package/dist/generate-piece-trigger-CqVOcL9g.mjs +30 -0
- package/dist/generate-piece-trigger-CqVOcL9g.mjs.map +1 -0
- package/dist/{generate-processor-_WOx-mMe.mjs → generate-processor-DBtTkgo5.mjs} +15 -8
- package/dist/generate-processor-DBtTkgo5.mjs.map +1 -0
- package/dist/{generate-subgraph-BsHUstpl.mjs → generate-subgraph-CVlTo7qk.mjs} +12 -6
- package/dist/generate-subgraph-CVlTo7qk.mjs.map +1 -0
- package/dist/index-BIbx17vt.d.mts +4459 -0
- package/dist/index-BIbx17vt.d.mts.map +1 -0
- package/dist/{init-BZP6gvYd.mjs → init-ScuT3z7P.mjs} +7 -5
- package/dist/init-ScuT3z7P.mjs.map +1 -0
- package/dist/{inspect-DXjbQEV_.mjs → inspect-zWJnBDMJ.mjs} +11 -4
- package/dist/inspect-zWJnBDMJ.mjs.map +1 -0
- package/dist/install-added-dependencies-DVSbzler.mjs +33 -0
- package/dist/install-added-dependencies-DVSbzler.mjs.map +1 -0
- package/dist/{migrate-jGKfE02L.mjs → migrate-DK4HK7Dn.mjs} +4 -4
- package/dist/{migrate-jGKfE02L.mjs.map → migrate-DK4HK7Dn.mjs.map} +1 -1
- package/dist/ph-cli-commands-BhzvcuzR.mjs +4 -0
- package/dist/ph-cli-commands-pyxDifSE.mjs +1493 -0
- package/dist/ph-cli-commands-pyxDifSE.mjs.map +1 -0
- package/dist/precompress-P6cJDPVC.mjs +77 -0
- package/dist/precompress-P6cJDPVC.mjs.map +1 -0
- package/dist/{registry-auth-DxEWCJu2.mjs → registry-auth-Bm5AR-fB.mjs} +4 -4
- package/dist/{registry-auth-DxEWCJu2.mjs.map → registry-auth-Bm5AR-fB.mjs.map} +1 -1
- package/dist/run-sugar-Ns53R6lU.mjs +39 -0
- package/dist/run-sugar-Ns53R6lU.mjs.map +1 -0
- package/dist/runners/connect.d.mts +1173 -0
- package/dist/runners/connect.d.mts.map +1 -0
- package/dist/runners/connect.mjs +270 -0
- package/dist/runners/connect.mjs.map +1 -0
- package/dist/runners/switchboard.d.mts +340 -0
- package/dist/runners/switchboard.d.mts.map +1 -0
- package/dist/runners/switchboard.mjs +294 -0
- package/dist/runners/switchboard.mjs.map +1 -0
- package/dist/schemas-D5N5U_Mf.mjs +5738 -0
- package/dist/schemas-D5N5U_Mf.mjs.map +1 -0
- package/dist/scripts/emit-runner-schemas.ts +24 -0
- package/dist/scripts/generate-commands-docs.ts +8 -0
- package/dist/scripts/manage-environment +0 -0
- package/dist/scripts/setup.sh +0 -0
- package/dist/start-run-BIaYSpHh.mjs +124 -0
- package/dist/start-run-BIaYSpHh.mjs.map +1 -0
- package/dist/superseded-config-CbSTFun2.mjs +53 -0
- package/dist/superseded-config-CbSTFun2.mjs.map +1 -0
- package/dist/switchboard-C5zgkRl2.mjs +4 -0
- package/dist/switchboard-h4-XgP1h.mjs +129 -0
- package/dist/switchboard-h4-XgP1h.mjs.map +1 -0
- package/dist/{switchboard-migrate-NQ7LHWSi.mjs → switchboard-migrate-7JQZM7-5.mjs} +5 -4
- package/dist/{switchboard-migrate-NQ7LHWSi.mjs.map → switchboard-migrate-7JQZM7-5.mjs.map} +1 -1
- package/dist/{switchboard-reset-BcQXlcVf.mjs → switchboard-reset-MtTB_GAI.mjs} +8 -6
- package/dist/switchboard-reset-MtTB_GAI.mjs.map +1 -0
- package/dist/{utils-C4isxXSO.mjs → utils-9KyRM0mf.mjs} +6 -34
- package/dist/{utils-C4isxXSO.mjs.map → utils-9KyRM0mf.mjs.map} +1 -1
- package/dist/utils-DAux4Ga7.mjs +4 -0
- package/dist/{vetra-DkF6EJMY.mjs → vetra-CnrGDPX0.mjs} +70 -35
- package/dist/vetra-CnrGDPX0.mjs.map +1 -0
- package/dist/warn-subgraph-type-conflicts-BOHBmThq.mjs +19 -0
- package/dist/warn-subgraph-type-conflicts-BOHBmThq.mjs.map +1 -0
- package/package.json +39 -18
- package/dist/auth-BNkN6kS9.mjs +0 -4
- package/dist/build-C-A5-ipO.mjs +0 -4
- package/dist/build-uQXq6_HU.mjs +0 -71
- package/dist/build-uQXq6_HU.mjs.map +0 -1
- package/dist/cli-connect-override-D3hh4aH_.mjs.map +0 -1
- package/dist/connect-build-WL4axo4z.mjs +0 -43
- package/dist/connect-build-WL4axo4z.mjs.map +0 -1
- package/dist/connect-config-BWGiW3IB.mjs.map +0 -1
- package/dist/connect-preview-D7ypzFDc.mjs +0 -28
- package/dist/connect-preview-D7ypzFDc.mjs.map +0 -1
- package/dist/connect-studio-BIQzyq5B.mjs +0 -5
- package/dist/connect-studio-D6rfWCNB.mjs.map +0 -1
- package/dist/generate-all-DrT4ZxHX.mjs.map +0 -1
- package/dist/generate-document-model-BJXyODfm.mjs.map +0 -1
- package/dist/generate-processor-_WOx-mMe.mjs.map +0 -1
- package/dist/generate-subgraph-BsHUstpl.mjs.map +0 -1
- package/dist/init-BZP6gvYd.mjs.map +0 -1
- package/dist/inspect-DXjbQEV_.mjs.map +0 -1
- package/dist/switchboard-CJMoMzWx.mjs +0 -75
- package/dist/switchboard-CJMoMzWx.mjs.map +0 -1
- package/dist/switchboard-iRFugh8I.mjs +0 -4
- package/dist/switchboard-reset-BcQXlcVf.mjs.map +0 -1
- package/dist/utils-BzwczAW-.mjs +0 -4
- package/dist/vetra-DkF6EJMY.mjs.map +0 -1
|
@@ -0,0 +1,2459 @@
|
|
|
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]="4521b21a-8bc8-5253-a45e-5f2575622f79")}catch(e){}}();
|
|
3
|
+
import { a as looseObject, c as strictObject, d as unknown, f as url, i as literal, l as string, m as prettifyError, n as array, o as number, p as toJSONSchema, r as boolean, s as record, t as _enum, u as union } from "./schemas-D5N5U_Mf.mjs";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
import fs, { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { createHash } from "node:crypto";
|
|
8
|
+
import { pathToFileURL } from "node:url";
|
|
9
|
+
import { TOKEN_ESCAPE_KEY, envTokenable, findToken, isToken, tokenKeyOf, tokenSchema, tokenable } from "@powerhousedao/shared/host-tokens";
|
|
10
|
+
import { resolvePhDir } from "@powerhousedao/shared/clis/ph-dir";
|
|
11
|
+
//#region ../../packages/host-core/dist/compound-B6RZMA0Y.mjs
|
|
12
|
+
/**
|
|
13
|
+
* R1 — the host plugin framework (bridge-runners-to-plugins plan,
|
|
14
|
+
* customization-references/host-core as the blueprint).
|
|
15
|
+
*
|
|
16
|
+
* A plugin is hooks + contributions; hooks are boot wiring (main realm only),
|
|
17
|
+
* contributions are declarative, serializable surface. Host RUNTIMES define
|
|
18
|
+
* the hook vocabulary and interleave their own wiring between stages — they
|
|
19
|
+
* are never plugins themselves.
|
|
20
|
+
*
|
|
21
|
+
* host.js carries the COMPOSITION as `runner.plugins` entries:
|
|
22
|
+
* string | { module, enabled?, verbs?, config? }
|
|
23
|
+
* Presence is activation (enabled defaults true); `verbs` scopes an entry to
|
|
24
|
+
* matching run verbs; `config` is validated against the plugin's declared
|
|
25
|
+
* zod schema. Entries resolve from the PROJECT's dependency tree exactly
|
|
26
|
+
* like runner modules.
|
|
27
|
+
*/
|
|
28
|
+
var PluginError = class extends Error {
|
|
29
|
+
constructor(message, hint) {
|
|
30
|
+
super(hint ? `${message}\n Hint: ${hint}` : message);
|
|
31
|
+
this.name = "PluginError";
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const pluginEntryObjectSchema = strictObject({
|
|
35
|
+
module: string().min(1),
|
|
36
|
+
/** Presence is activation BY DEFAULT; false is the explicit off-switch. */
|
|
37
|
+
enabled: boolean().optional(),
|
|
38
|
+
/** "*" (default) or the run verbs this entry is active for. */
|
|
39
|
+
verbs: union([literal("*"), array(string().min(1)).min(1)]).optional(),
|
|
40
|
+
/** Validated against the plugin's declared configSchema at resolution. */
|
|
41
|
+
config: record(string(), unknown()).optional()
|
|
42
|
+
});
|
|
43
|
+
const pluginEntrySchema = union([string().min(1), pluginEntryObjectSchema]);
|
|
44
|
+
function normalizePluginEntry(entry) {
|
|
45
|
+
if (typeof entry === "string") return {
|
|
46
|
+
module: entry,
|
|
47
|
+
enabled: true,
|
|
48
|
+
verbs: "*",
|
|
49
|
+
config: {}
|
|
50
|
+
};
|
|
51
|
+
return {
|
|
52
|
+
module: entry.module,
|
|
53
|
+
enabled: entry.enabled ?? true,
|
|
54
|
+
verbs: entry.verbs ?? "*",
|
|
55
|
+
config: entry.config ?? {}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/** Module is the identity key: a duplicate makes override targeting and
|
|
59
|
+
* ordering ambiguous, so it fails loudly. */
|
|
60
|
+
function normalizePluginEntries(entries, where) {
|
|
61
|
+
const normalized = entries.map(normalizePluginEntry);
|
|
62
|
+
const seen = /* @__PURE__ */ new Set();
|
|
63
|
+
for (const entry of normalized) {
|
|
64
|
+
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.");
|
|
65
|
+
seen.add(entry.module);
|
|
66
|
+
}
|
|
67
|
+
return normalized;
|
|
68
|
+
}
|
|
69
|
+
function entryActiveForVerb(entry, verb) {
|
|
70
|
+
if (!entry.enabled) return false;
|
|
71
|
+
return entry.verbs === "*" || entry.verbs.includes(verb);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The appliesTo hierarchy. "reactor" is the base every reactor host extends;
|
|
75
|
+
* "compound" is its own branch (plugins over the member set — e.g. the clint
|
|
76
|
+
* proxy). Host runtimes register their id with a parent; compatibility walks
|
|
77
|
+
* the parent chain.
|
|
78
|
+
*/
|
|
79
|
+
const HOST_TYPE_PARENTS = {
|
|
80
|
+
reactor: null,
|
|
81
|
+
compound: null,
|
|
82
|
+
connect: "reactor",
|
|
83
|
+
switchboard: "reactor",
|
|
84
|
+
mastra: "reactor"
|
|
85
|
+
};
|
|
86
|
+
function hostTypeSatisfies(hostType, appliesTo) {
|
|
87
|
+
let current = hostType;
|
|
88
|
+
while (current !== null) {
|
|
89
|
+
if (current === appliesTo) return true;
|
|
90
|
+
current = current in HOST_TYPE_PARENTS ? HOST_TYPE_PARENTS[current] : null;
|
|
91
|
+
}
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* NODE-ONLY plugin resolution (split from plugins.ts so the pure runner core
|
|
96
|
+
* stays browser-safe for ConnectCore — R3). Resolves host.js entries from the
|
|
97
|
+
* PROJECT dependency tree, exactly like runner modules.
|
|
98
|
+
*/
|
|
99
|
+
function isHostPluginShape(value) {
|
|
100
|
+
return value !== null && typeof value === "object" && typeof value.name === "string";
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Resolve host.js plugin entries into live plugins for one host boot:
|
|
104
|
+
* verb-filter → module resolution from the project tree (default condition,
|
|
105
|
+
* like runners) → factory/object contract → config validation → appliesTo.
|
|
106
|
+
*/
|
|
107
|
+
async function resolveHostPlugins(projectRoot, hostType, verb, entries, where) {
|
|
108
|
+
const normalized = normalizePluginEntries(entries, where);
|
|
109
|
+
const projectRequire = createRequire(pathToFileURL(path.join(projectRoot, "package.json")).href);
|
|
110
|
+
const resolved = [];
|
|
111
|
+
for (const entry of normalized) {
|
|
112
|
+
if (!entryActiveForVerb(entry, verb)) continue;
|
|
113
|
+
let file;
|
|
114
|
+
try {
|
|
115
|
+
file = projectRequire.resolve(entry.module);
|
|
116
|
+
} catch {
|
|
117
|
+
throw new PluginError(`${where}: cannot resolve plugin "${entry.module}" from ${projectRoot}.`, "Plugins resolve from the project dependency tree, exactly like runner modules.");
|
|
118
|
+
}
|
|
119
|
+
const exported = (await import(pathToFileURL(file).href)).default;
|
|
120
|
+
let plugin;
|
|
121
|
+
if (typeof exported === "function") plugin = exported(entry.config);
|
|
122
|
+
else if (isHostPluginShape(exported)) {
|
|
123
|
+
if (Object.keys(entry.config).length > 0 && !exported.configSchema) throw new PluginError(`${where}: plugin "${entry.module}" takes no config, but the entry passes one.`);
|
|
124
|
+
plugin = exported;
|
|
125
|
+
} else throw new PluginError(`${where}: "${entry.module}" does not default-export a plugin object or factory.`, "Export `{ name, hooks?, contributions? }` or `(config) => plugin`.");
|
|
126
|
+
if (plugin.configSchema) {
|
|
127
|
+
const parsed = plugin.configSchema.safeParse(entry.config);
|
|
128
|
+
if (!parsed.success) throw new PluginError(`${where}: config for plugin "${plugin.name}" is invalid:\n` + prettifyError(parsed.error));
|
|
129
|
+
}
|
|
130
|
+
const appliesTo = plugin.appliesTo ?? "reactor";
|
|
131
|
+
if (!hostTypeSatisfies(hostType, appliesTo)) throw new PluginError(`${where}: plugin "${plugin.name}" applies to "${appliesTo}" hosts, but this host is "${hostType}".`);
|
|
132
|
+
resolved.push({
|
|
133
|
+
entry,
|
|
134
|
+
plugin,
|
|
135
|
+
provenance: "dependency"
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
return resolved;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* LENIENT resolution for diagnostics (`ph run <host> --explain drives`):
|
|
142
|
+
* collects the drive contributions of the entries active for `verb`. Unlike
|
|
143
|
+
* resolveHostPlugins it does not know the host type (so appliesTo is not
|
|
144
|
+
* checked) and does not fail on a specifier the project tree cannot resolve
|
|
145
|
+
* — the entry is listed under `unresolved` instead. Config is still validated
|
|
146
|
+
* against the plugin's schema, so a bad entry surfaces here too.
|
|
147
|
+
*/
|
|
148
|
+
async function resolvePluginContributions(projectRoot, verb, entries, where) {
|
|
149
|
+
const normalized = normalizePluginEntries(entries, where);
|
|
150
|
+
const projectRequire = createRequire(pathToFileURL(path.join(projectRoot, "package.json")).href);
|
|
151
|
+
const plan = {
|
|
152
|
+
drives: [],
|
|
153
|
+
unresolved: []
|
|
154
|
+
};
|
|
155
|
+
for (const entry of normalized) {
|
|
156
|
+
if (!entryActiveForVerb(entry, verb)) continue;
|
|
157
|
+
let file;
|
|
158
|
+
try {
|
|
159
|
+
file = projectRequire.resolve(entry.module);
|
|
160
|
+
} catch {
|
|
161
|
+
plan.unresolved.push(entry.module);
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
const exported = (await import(pathToFileURL(file).href)).default;
|
|
165
|
+
let plugin;
|
|
166
|
+
if (typeof exported === "function") plugin = exported(entry.config);
|
|
167
|
+
else if (isHostPluginShape(exported)) plugin = exported;
|
|
168
|
+
else {
|
|
169
|
+
plan.unresolved.push(entry.module);
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
if (plugin.configSchema) {
|
|
173
|
+
const parsed = plugin.configSchema.safeParse(entry.config);
|
|
174
|
+
if (!parsed.success) throw new PluginError(`${where}: config for plugin "${plugin.name}" is invalid:\n` + prettifyError(parsed.error));
|
|
175
|
+
}
|
|
176
|
+
for (const declaration of plugin.contributions?.drives ?? []) plan.drives.push({
|
|
177
|
+
declaration,
|
|
178
|
+
source: plugin.name
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
return plan;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* The connect config slices each built-in Connect plugin owns, by specifier
|
|
185
|
+
* (typed-host-configs 1.6). Under a declared composition Connect zeroes a
|
|
186
|
+
* slice whose plugin is absent — presence is activation — so an authored
|
|
187
|
+
* value there is dead config. Connect's built-ins are browser modules with no
|
|
188
|
+
* Node-resolvable identity, so their ownership is declared here as data; a
|
|
189
|
+
* Connect test pins it to plugin-host's zeroing.
|
|
190
|
+
*/
|
|
191
|
+
const CONNECT_PLUGIN_OWNED_SLICES = {
|
|
192
|
+
"@powerhousedao/connect/plugins/generic": { slices: [
|
|
193
|
+
{
|
|
194
|
+
path: "drives.allowAddDrive",
|
|
195
|
+
absent: false,
|
|
196
|
+
entryKey: "allowAddDrive"
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
path: "drives.sections",
|
|
200
|
+
absent: {
|
|
201
|
+
remote: {
|
|
202
|
+
enabled: false,
|
|
203
|
+
allowAdd: false,
|
|
204
|
+
allowDelete: false
|
|
205
|
+
},
|
|
206
|
+
local: {
|
|
207
|
+
enabled: false,
|
|
208
|
+
allowAdd: false,
|
|
209
|
+
allowDelete: false
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
entryKey: "sections"
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
path: "drives.icons",
|
|
216
|
+
absent: null,
|
|
217
|
+
entryKey: "icons"
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
path: "home.background",
|
|
221
|
+
absent: null,
|
|
222
|
+
entryKey: "homeBackground"
|
|
223
|
+
}
|
|
224
|
+
] },
|
|
225
|
+
"@powerhousedao/connect/plugins/sentry": { slices: [{
|
|
226
|
+
path: "sentry.dsn",
|
|
227
|
+
absent: null,
|
|
228
|
+
entryKey: "dsn"
|
|
229
|
+
}] },
|
|
230
|
+
"@powerhousedao/connect/plugins/openpanel": {
|
|
231
|
+
slices: [
|
|
232
|
+
{
|
|
233
|
+
path: "openPanel.clientId",
|
|
234
|
+
absent: "",
|
|
235
|
+
entryKey: "clientId"
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
path: "openPanel.trackUiEvents",
|
|
239
|
+
absent: false,
|
|
240
|
+
entryKey: "trackUiEvents"
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
path: "openPanel.trackOperations",
|
|
244
|
+
absent: false,
|
|
245
|
+
entryKey: "trackOperations"
|
|
246
|
+
}
|
|
247
|
+
],
|
|
248
|
+
inertUnless: "openPanel.clientId"
|
|
249
|
+
},
|
|
250
|
+
"@powerhousedao/connect/plugins/assistant": { slices: [{
|
|
251
|
+
path: "ai.assistantEnabled",
|
|
252
|
+
absent: false
|
|
253
|
+
}] },
|
|
254
|
+
"@powerhousedao/vetra-studio/connect": { slices: [{
|
|
255
|
+
path: "app.studioMode",
|
|
256
|
+
absent: false
|
|
257
|
+
}] },
|
|
258
|
+
"@powerhousedao/connect/plugins/workflows": { slices: [{
|
|
259
|
+
path: "app.workflowsEnabled",
|
|
260
|
+
absent: false
|
|
261
|
+
}] }
|
|
262
|
+
};
|
|
263
|
+
function valueAt$1(root, dotted) {
|
|
264
|
+
let current = root;
|
|
265
|
+
for (const key of dotted.split(".")) {
|
|
266
|
+
if (current === null || typeof current !== "object") return void 0;
|
|
267
|
+
current = current[key];
|
|
268
|
+
}
|
|
269
|
+
return current;
|
|
270
|
+
}
|
|
271
|
+
/** Whether Connect already serves what the author wrote: every authored leaf
|
|
272
|
+
* equals the served one. An unset leaf asks for nothing, so a partial object
|
|
273
|
+
* (`sections: { remote: { enabled: false } }`) is satisfied by the zeroed
|
|
274
|
+
* slice. */
|
|
275
|
+
function alreadyServed(authored, served) {
|
|
276
|
+
if (authored === void 0 || Object.is(authored, served)) return true;
|
|
277
|
+
if (authored === null || served === null || typeof authored !== "object" || typeof served !== "object" || Array.isArray(authored) !== Array.isArray(served)) return false;
|
|
278
|
+
if (Array.isArray(authored) && authored.length !== served.length) return false;
|
|
279
|
+
const want = authored;
|
|
280
|
+
const have = served;
|
|
281
|
+
return Object.keys(want).every((key) => alreadyServed(want[key], have[key]));
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Dead-config warnings for a Connect host (typed-host-configs 1.6): an
|
|
285
|
+
* authored connect config value whose owning plugin is not in the
|
|
286
|
+
* composition active for `verb`. Connect zeroes such a slice, so the value
|
|
287
|
+
* has no effect — e.g. Sektar's `connect.drives.allowAddDrive: true` without
|
|
288
|
+
* the generic plugin.
|
|
289
|
+
*
|
|
290
|
+
* Nothing is reported when the host declares no composition
|
|
291
|
+
* (`runner.plugins` absent: the classic boot serves the config as is), or
|
|
292
|
+
* when Connect already serves every leaf of the authored value. Warnings, not
|
|
293
|
+
* errors: the host still boots, it just does not do what the value says.
|
|
294
|
+
*/
|
|
295
|
+
function findDeadConnectConfig(config, entries, verb, where) {
|
|
296
|
+
if (!config || entries === void 0) return [];
|
|
297
|
+
const active = new Set(normalizePluginEntries(entries, where).filter((entry) => entryActiveForVerb(entry, verb)).map((entry) => entry.module));
|
|
298
|
+
const warnings = [];
|
|
299
|
+
for (const [owner, { slices, inertUnless }] of Object.entries(CONNECT_PLUGIN_OWNED_SLICES)) {
|
|
300
|
+
if (active.has(owner)) continue;
|
|
301
|
+
if (inertUnless !== void 0) {
|
|
302
|
+
const gate = slices.find((slice) => slice.path === inertUnless);
|
|
303
|
+
if (alreadyServed(valueAt$1(config, inertUnless), gate?.absent)) continue;
|
|
304
|
+
}
|
|
305
|
+
for (const { path: slicePath, absent, entryKey } of slices) {
|
|
306
|
+
const value = valueAt$1(config, slicePath);
|
|
307
|
+
if (alreadyServed(value, absent)) continue;
|
|
308
|
+
const move = entryKey === void 0 ? `compose "${owner}" (presence is the switch)` : `compose "${owner}" and set \`${entryKey}\` in its entry config`;
|
|
309
|
+
warnings.push({
|
|
310
|
+
path: slicePath,
|
|
311
|
+
value,
|
|
312
|
+
served: absent,
|
|
313
|
+
owner,
|
|
314
|
+
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.`
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
return warnings;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* The schema half of drives.ts, zod only so `./schema` stays neutral.
|
|
322
|
+
* - slug: the SEEDING KEY (idempotence); id optional (stable identity).
|
|
323
|
+
* - preferredEditor: stored at header.meta.preferredEditor; Connect config's
|
|
324
|
+
* `app` is the legacy alias.
|
|
325
|
+
* - remote.url: a drive served elsewhere; local fields are ignored for it.
|
|
326
|
+
* Token-able (`$output` on a producer's `drives.<slug>.url`).
|
|
327
|
+
*/
|
|
328
|
+
function buildDriveDeclarationSchema(urlField) {
|
|
329
|
+
return strictObject({
|
|
330
|
+
slug: string().min(1),
|
|
331
|
+
id: string().min(1).optional(),
|
|
332
|
+
/** Derive the id from the project path, like generateProjectDriveId — the
|
|
333
|
+
* same ids classic `ph vetra` produces. `true` serves the drive under the
|
|
334
|
+
* hashed slug too (the vetra drive's slug IS its hashed id); `"id"` hashes
|
|
335
|
+
* only the id and keeps the declared slug (the classic Workflows drive:
|
|
336
|
+
* `/d/workflows`, id `workflows-<hash>`). */
|
|
337
|
+
projectHash: union([boolean(), literal("id")]).optional(),
|
|
338
|
+
name: string().min(1).optional(),
|
|
339
|
+
icon: string().optional(),
|
|
340
|
+
preferredEditor: string().optional(),
|
|
341
|
+
sharingType: _enum([
|
|
342
|
+
"public",
|
|
343
|
+
"private",
|
|
344
|
+
"shared"
|
|
345
|
+
]).optional(),
|
|
346
|
+
availableOffline: boolean().optional(),
|
|
347
|
+
remote: strictObject({ url: urlField(string().min(1)) }).optional()
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
const driveDeclarationSchema = buildDriveDeclarationSchema(tokenable);
|
|
351
|
+
const drivesSchema = array(driveDeclarationSchema);
|
|
352
|
+
/** The project-hashed drive id (`${slug}-${sha256(projectRoot)[0..8]}`) with
|
|
353
|
+
* the hash function injected, so neutral consumers (a browser monitor) can
|
|
354
|
+
* pass `crypto.subtle`-derived or precomputed hex. drives.ts binds it to
|
|
355
|
+
* node:crypto as `projectDriveId`. */
|
|
356
|
+
function projectDriveIdWith(sha256Hex, projectRoot, slug) {
|
|
357
|
+
return `${slug}-${sha256Hex(projectRoot).substring(0, 8)}`;
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* The zod single source for host.js blocks (typed-host-configs G1). Every
|
|
361
|
+
* host type is z.input/z.output of these schemas; nothing is hand-mirrored.
|
|
362
|
+
* Top-level host objects and the `reactor` block are STRICT (a typo fails);
|
|
363
|
+
* `runner` stays loose until each runner declares its options (T2), and
|
|
364
|
+
* `config` is runner-defined.
|
|
365
|
+
*
|
|
366
|
+
* Token-able fields (typed-host-configs 3.5): `reactor.backends.*.remote.url`
|
|
367
|
+
* (required), `reactor.drives` (whole list, e.g. `$map`),
|
|
368
|
+
* `reactor.drives[].remote.url` and `storage.dataDir` (`$env` only). Their z.input admits tokens, their z.output is the resolved type.
|
|
369
|
+
*/
|
|
370
|
+
const profileSchema = strictObject({
|
|
371
|
+
appId: string().min(1).optional(),
|
|
372
|
+
name: string().min(1).optional(),
|
|
373
|
+
description: string().optional(),
|
|
374
|
+
icon: string().optional()
|
|
375
|
+
});
|
|
376
|
+
const reactorProtocolSchema = strictObject({
|
|
377
|
+
featureFlags: strictObject({
|
|
378
|
+
documentDecisions: boolean().optional(),
|
|
379
|
+
authEnforcement: boolean().optional(),
|
|
380
|
+
authGroups: boolean().optional(),
|
|
381
|
+
authConditions: boolean().optional()
|
|
382
|
+
}).optional(),
|
|
383
|
+
createSignaturePolicy: _enum(["legacy", "v2-required"]).optional(),
|
|
384
|
+
unsupportedStoredDocuments: _enum(["refuse", "read-only"]).optional()
|
|
385
|
+
});
|
|
386
|
+
const runnerKindSchema = _enum(["reactor", "compound"]);
|
|
387
|
+
const reactorBackendKindSchema = _enum([
|
|
388
|
+
"in-process",
|
|
389
|
+
"worker",
|
|
390
|
+
"remote"
|
|
391
|
+
]);
|
|
392
|
+
const samePath = (a, b) => {
|
|
393
|
+
const norm = (p) => p.replace(/\\/g, "/").replace(/\/+$/, "").replace(/^\.\//, "");
|
|
394
|
+
return norm(a) === norm(b);
|
|
395
|
+
};
|
|
396
|
+
/** Compound wiring: the generic compound runner's `config` block.
|
|
397
|
+
* (`projectDrivesIntoConnect` and `drivesPublicBase` were removed in T3: a
|
|
398
|
+
* member consumes another member's drives through `$output` tokens.) */
|
|
399
|
+
const compoundWiringSchema = strictObject({
|
|
400
|
+
/** Member start order; must name declared children and agree with the
|
|
401
|
+
* output-token dependencies (resolve/plan.ts). Optional: without it the
|
|
402
|
+
* order is derived from the tokens. Unnamed members start after the named
|
|
403
|
+
* ones, in declaration order. */
|
|
404
|
+
startOrder: array(string().min(1)).optional(),
|
|
405
|
+
/** Write .ph/run/<host>.json (default true). */
|
|
406
|
+
runtimeRecord: boolean().optional(),
|
|
407
|
+
/** Patch the baked CSP for the runtime registry on a served Connect
|
|
408
|
+
* member (forwarded as `runner.cspRegistrySync` to every member whose
|
|
409
|
+
* runner is `@powerhousedao/ph-cli/runners/connect`). */
|
|
410
|
+
cspRegistrySync: boolean().optional()
|
|
411
|
+
});
|
|
412
|
+
/** `config.startOrder ⊆ keys(children)`, checked where both are visible.
|
|
413
|
+
* Apply it LAST (`.superRefine(refineStartOrder)`) to a runner's final host
|
|
414
|
+
* schema: zod refuses to `.extend()` a refined object. */
|
|
415
|
+
function refineStartOrder(host, ctx) {
|
|
416
|
+
const startOrder = host.config?.startOrder;
|
|
417
|
+
if (!Array.isArray(startOrder)) return;
|
|
418
|
+
const members = Object.keys(host.children);
|
|
419
|
+
startOrder.forEach((name, index) => {
|
|
420
|
+
if (startOrder.indexOf(name) !== index) {
|
|
421
|
+
ctx.addIssue({
|
|
422
|
+
code: "custom",
|
|
423
|
+
path: [
|
|
424
|
+
"config",
|
|
425
|
+
"startOrder",
|
|
426
|
+
index
|
|
427
|
+
],
|
|
428
|
+
message: `startOrder names "${String(name)}" twice; each member starts once.`
|
|
429
|
+
});
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
if (typeof name === "string" && members.includes(name)) return;
|
|
433
|
+
ctx.addIssue({
|
|
434
|
+
code: "custom",
|
|
435
|
+
path: [
|
|
436
|
+
"config",
|
|
437
|
+
"startOrder",
|
|
438
|
+
index
|
|
439
|
+
],
|
|
440
|
+
message: `startOrder names "${String(name)}", which is not a member. Members: ${members.join(", ") || "(none)"}.`
|
|
441
|
+
});
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
const ALLOW_TOKENS = {
|
|
445
|
+
any: tokenable,
|
|
446
|
+
env: envTokenable
|
|
447
|
+
};
|
|
448
|
+
const FORBID_TOKENS = {
|
|
449
|
+
any: (schema) => union([schema]),
|
|
450
|
+
env: (schema) => union([schema])
|
|
451
|
+
};
|
|
452
|
+
/**
|
|
453
|
+
* Builds the host schema set. "allow" (declared form) accepts `T | Token` in
|
|
454
|
+
* every token-able field; "forbid" (resolved form) accepts `T` only.
|
|
455
|
+
*/
|
|
456
|
+
function buildHostSchemas(tokenField) {
|
|
457
|
+
const reactorBackendSchema = strictObject({
|
|
458
|
+
kind: reactorBackendKindSchema,
|
|
459
|
+
storage: strictObject({
|
|
460
|
+
kind: _enum([
|
|
461
|
+
"idb",
|
|
462
|
+
"memory",
|
|
463
|
+
"path",
|
|
464
|
+
"postgres"
|
|
465
|
+
]),
|
|
466
|
+
/** `"${userData}/…"` sugar or `{ $env: "NAME" }`. */
|
|
467
|
+
dataDir: tokenField.env(string()).optional(),
|
|
468
|
+
url: string().optional()
|
|
469
|
+
}).optional(),
|
|
470
|
+
readModel: strictObject({ url: string().optional() }).optional(),
|
|
471
|
+
packages: strictObject({
|
|
472
|
+
cdnUrl: string().optional(),
|
|
473
|
+
specs: array(string()).optional(),
|
|
474
|
+
/** on-demand model resolution (was DYNAMIC_MODEL_LOADING). */
|
|
475
|
+
dynamic: boolean().optional()
|
|
476
|
+
}).optional(),
|
|
477
|
+
remote: strictObject({ url: tokenField.any(url()) }).optional(),
|
|
478
|
+
projection: strictObject({
|
|
479
|
+
enabled: boolean().optional(),
|
|
480
|
+
dbPoolSize: number().int().positive().optional()
|
|
481
|
+
}).optional(),
|
|
482
|
+
executors: strictObject({ numWorkers: union([number().int().positive(), literal("auto")]).optional() }).optional()
|
|
483
|
+
}).superRefine((backend, ctx) => {
|
|
484
|
+
if (backend.kind === "remote" && !backend.remote) ctx.addIssue({
|
|
485
|
+
code: "custom",
|
|
486
|
+
path: ["remote", "url"],
|
|
487
|
+
message: "a \"remote\" backend needs remote.url: remote: { url: switchboard.endpoints.graphql } with switchboard from ../switchboard/outputs.js, or remote: { url: { $output: { host: \"switchboard\", path: [\"endpoints\", \"graphql\"] } } }."
|
|
488
|
+
});
|
|
489
|
+
const store = backend.storage;
|
|
490
|
+
const storeDir = store?.kind === "path" ? store.dataDir : void 0;
|
|
491
|
+
const readModel = backend.readModel?.url;
|
|
492
|
+
if (typeof storeDir === "string" && readModel && samePath(storeDir, readModel)) ctx.addIssue({
|
|
493
|
+
code: "custom",
|
|
494
|
+
path: ["readModel", "url"],
|
|
495
|
+
message: `readModel.url must not be the reactor's storage dir (${readModel}): two PGlite instances on one data dir corrupt it. Omit readModel.url to get the classic <root>/.ph/read-storage next to the reactor store.`
|
|
496
|
+
});
|
|
497
|
+
});
|
|
498
|
+
const reactorSchema = strictObject({
|
|
499
|
+
backends: record(string(), reactorBackendSchema).optional(),
|
|
500
|
+
placement: strictObject({
|
|
501
|
+
primary: string().optional(),
|
|
502
|
+
default: looseObject({}).optional()
|
|
503
|
+
}).optional(),
|
|
504
|
+
protocol: reactorProtocolSchema.optional(),
|
|
505
|
+
/** DEPRECATED (dies in R2): workflows become a listed plugin. */
|
|
506
|
+
workflows: boolean().optional(),
|
|
507
|
+
renown: strictObject({
|
|
508
|
+
url: string().optional(),
|
|
509
|
+
networkId: string().optional(),
|
|
510
|
+
chainId: number().int().optional()
|
|
511
|
+
}).optional(),
|
|
512
|
+
packages: strictObject({ registryUrl: string().optional() }).optional(),
|
|
513
|
+
namespace: string().min(1).optional(),
|
|
514
|
+
auth: strictObject({
|
|
515
|
+
enabled: boolean().optional(),
|
|
516
|
+
admins: array(string()).optional(),
|
|
517
|
+
renown: looseObject({}).optional()
|
|
518
|
+
}).optional(),
|
|
519
|
+
drives: tokenField.any(array(buildDriveDeclarationSchema(tokenField.any))).optional()
|
|
520
|
+
});
|
|
521
|
+
/** Common runner options; runner modules extend it with their own. */
|
|
522
|
+
const runnerBaseSchema = looseObject({
|
|
523
|
+
module: string().min(1),
|
|
524
|
+
defaultVerb: string().min(1).optional(),
|
|
525
|
+
port: number().int().positive().optional(),
|
|
526
|
+
/** Bind address; each runner documents its default. */
|
|
527
|
+
host: string().min(1).optional(),
|
|
528
|
+
/** THE COMPOSITION: plugin entries; presence is activation. */
|
|
529
|
+
plugins: array(pluginEntrySchema).optional()
|
|
530
|
+
});
|
|
531
|
+
/** A compound member wrapper. Sections are FULL STATEMENTS except `runner`,
|
|
532
|
+
* which key-merges over the member's own. Plugins live in `runner.plugins`
|
|
533
|
+
* (as on a standalone host); there is no wrapper-level `plugins`. */
|
|
534
|
+
const childWrapperSchema = strictObject({
|
|
535
|
+
host: string().min(1),
|
|
536
|
+
runner: runnerBaseSchema.partial().optional(),
|
|
537
|
+
config: looseObject({}).optional(),
|
|
538
|
+
reactor: reactorSchema.optional()
|
|
539
|
+
});
|
|
540
|
+
const childrenSchema = record(string(), childWrapperSchema);
|
|
541
|
+
return {
|
|
542
|
+
reactorBackendSchema,
|
|
543
|
+
reactorSchema,
|
|
544
|
+
runnerBaseSchema,
|
|
545
|
+
childWrapperSchema,
|
|
546
|
+
childrenSchema,
|
|
547
|
+
reactorHostSchema: strictObject({
|
|
548
|
+
name: string().min(1),
|
|
549
|
+
runner: runnerBaseSchema,
|
|
550
|
+
config: looseObject({}).optional(),
|
|
551
|
+
profile: profileSchema.optional(),
|
|
552
|
+
reactor: reactorSchema.optional()
|
|
553
|
+
}),
|
|
554
|
+
compoundHostSchema: strictObject({
|
|
555
|
+
name: string().min(1),
|
|
556
|
+
runner: runnerBaseSchema,
|
|
557
|
+
children: childrenSchema,
|
|
558
|
+
config: looseObject({}).optional(),
|
|
559
|
+
profile: profileSchema.optional()
|
|
560
|
+
}),
|
|
561
|
+
/** This set's field wrapper, for a runner's OWN token-able fields inside
|
|
562
|
+
* `defineHostSchemas`: declared, `T | Token` in and `T` out; resolved,
|
|
563
|
+
* `T` only. Both modes share one static type. */
|
|
564
|
+
tokenable: tokenField.any,
|
|
565
|
+
/** As `tokenable`, but the only token accepted is `$env`. */
|
|
566
|
+
envTokenable: tokenField.env
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
/** The host schema set in declared ("allow": token-able fields take tokens)
|
|
570
|
+
* or resolved ("forbid") form. */
|
|
571
|
+
function makeHostSchemas(options) {
|
|
572
|
+
return buildHostSchemas(options.tokens === "allow" ? ALLOW_TOKENS : FORBID_TOKENS);
|
|
573
|
+
}
|
|
574
|
+
/**
|
|
575
|
+
* One runner definition, two schemas (3.5): `build` runs over the DECLARED
|
|
576
|
+
* set (tokens allowed; its z.input types host files) and the RESOLVED set
|
|
577
|
+
* (no tokens; `validateHost` checks it before the verb). Export both, type
|
|
578
|
+
* the host as `z.input<typeof declaredHostSchema>`, refine last inside the
|
|
579
|
+
* builder (zod can't extend a refined object), and wrap the runner's own
|
|
580
|
+
* token-able fields with `s.tokenable` / `s.envTokenable`.
|
|
581
|
+
*/
|
|
582
|
+
function defineHostSchemas(build) {
|
|
583
|
+
return {
|
|
584
|
+
declaredHostSchema: build(declaredSchemas),
|
|
585
|
+
hostSchema: build(resolvedSchemas)
|
|
586
|
+
};
|
|
587
|
+
}
|
|
588
|
+
const declaredSchemas = makeHostSchemas({ tokens: "allow" });
|
|
589
|
+
const resolvedSchemas = makeHostSchemas({ tokens: "forbid" });
|
|
590
|
+
const declaredHostSchemas = declaredSchemas;
|
|
591
|
+
resolvedSchemas.reactorBackendSchema;
|
|
592
|
+
resolvedSchemas.reactorSchema;
|
|
593
|
+
resolvedSchemas.runnerBaseSchema;
|
|
594
|
+
resolvedSchemas.childWrapperSchema;
|
|
595
|
+
resolvedSchemas.childrenSchema;
|
|
596
|
+
resolvedSchemas.reactorHostSchema;
|
|
597
|
+
resolvedSchemas.compoundHostSchema;
|
|
598
|
+
/** The generic compound runner's host: the base with its wiring config. */
|
|
599
|
+
const genericCompound = defineHostSchemas((s) => s.compoundHostSchema.extend({ config: compoundWiringSchema.optional() }).superRefine(refineStartOrder));
|
|
600
|
+
genericCompound.hostSchema;
|
|
601
|
+
genericCompound.declaredHostSchema;
|
|
602
|
+
function isPlainObject(value) {
|
|
603
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
|
|
604
|
+
const proto = Object.getPrototypeOf(value);
|
|
605
|
+
return proto === Object.prototype || proto === null;
|
|
606
|
+
}
|
|
607
|
+
/** `a.b[2].c` (or `<root>`). */
|
|
608
|
+
function formatPath(path) {
|
|
609
|
+
let out = "";
|
|
610
|
+
for (const segment of path) if (typeof segment === "number") out += `[${segment}]`;
|
|
611
|
+
else out += out ? `.${segment}` : segment;
|
|
612
|
+
return out || "<root>";
|
|
613
|
+
}
|
|
614
|
+
/** Is this object a `$$` escape (`{ $$: literal }`)? */
|
|
615
|
+
function isEscape(value) {
|
|
616
|
+
const keys = Object.keys(value);
|
|
617
|
+
return keys.length === 1 && keys[0] === TOKEN_ESCAPE_KEY;
|
|
618
|
+
}
|
|
619
|
+
/** Every token in `value`, in document order. `$concat` parts and `$map`
|
|
620
|
+
* operands (`over`, then the `to` template) are visited: they may hold tokens
|
|
621
|
+
* themselves. Each site carries the `$map` scopes it sits in. A `$$` escape
|
|
622
|
+
* hides its operand. */
|
|
623
|
+
function collectTokenSites(value) {
|
|
624
|
+
const sites = [];
|
|
625
|
+
visit(value, [], "root", [], sites);
|
|
626
|
+
return sites;
|
|
627
|
+
}
|
|
628
|
+
function visit(value, path, position, scopes, sites) {
|
|
629
|
+
const key = tokenKeyOf(value);
|
|
630
|
+
if (key && isPlainObject(value)) {
|
|
631
|
+
sites.push({
|
|
632
|
+
path,
|
|
633
|
+
key,
|
|
634
|
+
token: value,
|
|
635
|
+
position,
|
|
636
|
+
scopes
|
|
637
|
+
});
|
|
638
|
+
const operand = value[key];
|
|
639
|
+
if (key === "$concat" && Array.isArray(operand)) operand.forEach((part, index) => visit(part, [
|
|
640
|
+
...path,
|
|
641
|
+
"$concat",
|
|
642
|
+
index
|
|
643
|
+
], "concat", scopes, sites));
|
|
644
|
+
if (key === "$map" && isPlainObject(operand)) {
|
|
645
|
+
const at = [...path, "$map"];
|
|
646
|
+
if ("over" in operand) visit(operand.over, [...at, "over"], "over", scopes, sites);
|
|
647
|
+
if ("to" in operand) {
|
|
648
|
+
const scope = {
|
|
649
|
+
path,
|
|
650
|
+
token: value,
|
|
651
|
+
...typeof operand.as === "string" ? { as: operand.as } : {}
|
|
652
|
+
};
|
|
653
|
+
visit(operand.to, [...at, "to"], "template", [...scopes, scope], sites);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
return;
|
|
657
|
+
}
|
|
658
|
+
if (Array.isArray(value)) {
|
|
659
|
+
value.forEach((child, index) => visit(child, [...path, index], "element", scopes, sites));
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
if (!isPlainObject(value) || isEscape(value)) return;
|
|
663
|
+
for (const [childKey, child] of Object.entries(value)) visit(child, [...path, childKey], "property", scopes, sites);
|
|
664
|
+
}
|
|
665
|
+
/** An `$item` path as text: `url`, `drives.x`, `<element>` for `[]`. */
|
|
666
|
+
function pathText(path) {
|
|
667
|
+
if (path.length === 0) return "<element>";
|
|
668
|
+
return formatPath(path.filter((p) => typeof p === "string" || typeof p === "number"));
|
|
669
|
+
}
|
|
670
|
+
/** A one-line human rendering of a token, for `--explain` and messages. */
|
|
671
|
+
function describeToken(token) {
|
|
672
|
+
const key = tokenKeyOf(token);
|
|
673
|
+
if (!key || !isPlainObject(token)) return JSON.stringify(token);
|
|
674
|
+
const operand = token[key];
|
|
675
|
+
if (key === "$output" && isPlainObject(operand)) return `$output ${typeof operand.host === "string" ? operand.host : "?"}${typeof operand.member === "string" ? ` (member ${operand.member})` : ""} › ${Array.isArray(operand.path) ? formatPath(operand.path.filter((p) => typeof p === "string" || typeof p === "number")) : "?"}`;
|
|
676
|
+
if (key === "$env") {
|
|
677
|
+
if (typeof operand === "string") return `$env ${operand}`;
|
|
678
|
+
if (isPlainObject(operand) && typeof operand.name === "string") return `$env ${operand.name} (optional)`;
|
|
679
|
+
}
|
|
680
|
+
if (key === "$item") {
|
|
681
|
+
const named = isPlainObject(operand) ? operand : void 0;
|
|
682
|
+
const raw = named ? named.path : operand;
|
|
683
|
+
const path = Array.isArray(raw) ? pathText(raw) : "?";
|
|
684
|
+
return `$item${named && typeof named.as === "string" ? `(${named.as})` : ""} ${path}`;
|
|
685
|
+
}
|
|
686
|
+
if (key === "$key") return typeof operand === "string" ? `$key(${operand})` : "$key";
|
|
687
|
+
if (key === "$map" && isPlainObject(operand)) {
|
|
688
|
+
const as = typeof operand.as === "string" ? ` as ${operand.as}` : "";
|
|
689
|
+
const into = operand.into === "record" ? " into record" : "";
|
|
690
|
+
return `$map over [${describeToken(operand.over)}]${as}${into} → ${JSON.stringify(render(operand.to))}`;
|
|
691
|
+
}
|
|
692
|
+
if (key === "$concat" && Array.isArray(operand)) return `$concat ${operand.map((part) => typeof part === "string" ? JSON.stringify(part) : typeof part === "number" ? String(part) : `[${describeToken(part)}]`).join(" + ")}`;
|
|
693
|
+
return `${key} ${JSON.stringify(operand)}`;
|
|
694
|
+
}
|
|
695
|
+
/** A display copy of `value` with every token replaced by `«description»`
|
|
696
|
+
* (for printing declared hosts, e.g. `--explain drives`). */
|
|
697
|
+
function renderTokens(value) {
|
|
698
|
+
return render(value);
|
|
699
|
+
}
|
|
700
|
+
function render(value) {
|
|
701
|
+
if (tokenKeyOf(value)) return `«${describeToken(value)}»`;
|
|
702
|
+
if (Array.isArray(value)) return value.map(render);
|
|
703
|
+
if (!isPlainObject(value) || isEscape(value)) return value;
|
|
704
|
+
const out = {};
|
|
705
|
+
for (const [key, child] of Object.entries(value)) out[key] = render(child);
|
|
706
|
+
return out;
|
|
707
|
+
}
|
|
708
|
+
/** A copy of `value` with every `$$` escape replaced by its operand (the
|
|
709
|
+
* literal it protects). Run after the no-token walk. */
|
|
710
|
+
function unwrapEscapes(value) {
|
|
711
|
+
return unwrap(value);
|
|
712
|
+
}
|
|
713
|
+
function unwrap(value) {
|
|
714
|
+
if (Array.isArray(value)) return value.map(unwrap);
|
|
715
|
+
if (!isPlainObject(value)) return value;
|
|
716
|
+
if (isEscape(value)) return structuredClone(value[TOKEN_ESCAPE_KEY]);
|
|
717
|
+
const out = {};
|
|
718
|
+
for (const [key, child] of Object.entries(value)) out[key] = unwrap(child);
|
|
719
|
+
return out;
|
|
720
|
+
}
|
|
721
|
+
function refOf(site) {
|
|
722
|
+
const operand = site.token.$output;
|
|
723
|
+
if (!isPlainObject(operand) || typeof operand.host !== "string") return;
|
|
724
|
+
return typeof operand.member === "string" ? {
|
|
725
|
+
host: operand.host,
|
|
726
|
+
member: operand.member
|
|
727
|
+
} : { host: operand.host };
|
|
728
|
+
}
|
|
729
|
+
function pathOf(site) {
|
|
730
|
+
const operand = site.token.$output;
|
|
731
|
+
if (!isPlainObject(operand) || !Array.isArray(operand.path)) return [];
|
|
732
|
+
return operand.path.filter((p) => typeof p === "string" || typeof p === "number");
|
|
733
|
+
}
|
|
734
|
+
function refKey(ref) {
|
|
735
|
+
return ref.member ? `${ref.host}#${ref.member}` : ref.host;
|
|
736
|
+
}
|
|
737
|
+
/** The distinct producers a host's `$output` tokens name, in document order. */
|
|
738
|
+
function outputRefsOf(host) {
|
|
739
|
+
const seen = /* @__PURE__ */ new Map();
|
|
740
|
+
for (const site of collectTokenSites(host)) {
|
|
741
|
+
if (site.key !== "$output") continue;
|
|
742
|
+
const ref = refOf(site);
|
|
743
|
+
if (ref && !seen.has(refKey(ref))) seen.set(refKey(ref), ref);
|
|
744
|
+
}
|
|
745
|
+
return [...seen.values()];
|
|
746
|
+
}
|
|
747
|
+
/** Every `$output` token with its host path and producer (for the plan and
|
|
748
|
+
* `--explain outputs`). */
|
|
749
|
+
function outputSitesOf(host) {
|
|
750
|
+
return collectTokenSites(host).flatMap((site) => {
|
|
751
|
+
if (site.key !== "$output") return [];
|
|
752
|
+
const ref = refOf(site);
|
|
753
|
+
return ref ? [{
|
|
754
|
+
path: formatPath(site.path),
|
|
755
|
+
ref,
|
|
756
|
+
outputPath: pathOf(site)
|
|
757
|
+
}] : [];
|
|
758
|
+
});
|
|
759
|
+
}
|
|
760
|
+
/** Every `$env` token with its host path (for `--explain outputs`). */
|
|
761
|
+
function envSitesOf(host) {
|
|
762
|
+
return collectTokenSites(host).flatMap((site) => {
|
|
763
|
+
if (site.key !== "$env") return [];
|
|
764
|
+
const operand = site.token.$env;
|
|
765
|
+
if (typeof operand === "string") return [{
|
|
766
|
+
path: formatPath(site.path),
|
|
767
|
+
name: operand,
|
|
768
|
+
optional: false
|
|
769
|
+
}];
|
|
770
|
+
if (isPlainObject(operand) && typeof operand.name === "string") return [{
|
|
771
|
+
path: formatPath(site.path),
|
|
772
|
+
name: operand.name,
|
|
773
|
+
optional: true
|
|
774
|
+
}];
|
|
775
|
+
return [];
|
|
776
|
+
});
|
|
777
|
+
}
|
|
778
|
+
/** The binding name an `$item`/`$key` site names (undefined: innermost). */
|
|
779
|
+
function bindingNameOf(site) {
|
|
780
|
+
const operand = site.token[site.key];
|
|
781
|
+
if (site.key === "$key") return typeof operand === "string" ? operand : void 0;
|
|
782
|
+
if (site.key === "$item" && isPlainObject(operand)) return typeof operand.as === "string" ? operand.as : void 0;
|
|
783
|
+
}
|
|
784
|
+
/** The enclosing `$map` an `$item`/`$key` site binds to, or why none. */
|
|
785
|
+
function scopeOf(site) {
|
|
786
|
+
const name = bindingNameOf(site);
|
|
787
|
+
if (site.scopes.length === 0) return { error: `${site.key} is used outside any $map; it reads the element a $map template is rendering, so it is legal only inside a $map's \`to\` (or a nested $map's \`over\`).` };
|
|
788
|
+
if (name === void 0) return site.scopes[site.scopes.length - 1];
|
|
789
|
+
for (let i = site.scopes.length - 1; i >= 0; i--) if (site.scopes[i].as === name) return site.scopes[i];
|
|
790
|
+
const named = site.scopes.flatMap((s) => s.as ? [`"${s.as}"`] : []);
|
|
791
|
+
return { error: `${describeToken(site.token)} names the $map binding "${name}", which no enclosing $map declares (enclosing bindings: ${named.join(", ") || "none; add as: \"" + name + "\" to the outer $map"}).` };
|
|
792
|
+
}
|
|
793
|
+
/** Item path of an `$item` site. */
|
|
794
|
+
function itemPathOf(site) {
|
|
795
|
+
const operand = site.token.$item;
|
|
796
|
+
const raw = isPlainObject(operand) ? operand.path : operand;
|
|
797
|
+
return Array.isArray(raw) ? raw.filter((p) => typeof p === "string" || typeof p === "number") : [];
|
|
798
|
+
}
|
|
799
|
+
/** Operator shapes and placement: malformed operands, `$item`/`$key`
|
|
800
|
+
* outside any `$map` or naming an unknown binding, and
|
|
801
|
+
* `{ $env: { name, optional: true } }` anywhere but the direct value of an
|
|
802
|
+
* object property (it omits that property when unset). */
|
|
803
|
+
function checkTokenSites(host) {
|
|
804
|
+
const issues = [];
|
|
805
|
+
for (const site of collectTokenSites(host)) {
|
|
806
|
+
const path = formatPath(site.path);
|
|
807
|
+
if (!tokenSchema.safeParse(site.token).success) {
|
|
808
|
+
issues.push({
|
|
809
|
+
path,
|
|
810
|
+
message: `malformed ${site.key} token ${JSON.stringify(site.token)}. Shapes: { $output: { host, member?, path: [...] } }, { $concat: [string | number | token, ...] }, { $env: "NAME" } or { $env: { name: "NAME", optional: true } }, { $map: { over: $output | $item, as?: "name", to: template, into?: "record" } }, { $item: [path] } or { $item: { as: "name", path: [...] } }, { $key: true } or { $key: "name" }.`
|
|
811
|
+
});
|
|
812
|
+
continue;
|
|
813
|
+
}
|
|
814
|
+
if (site.key === "$item" || site.key === "$key") {
|
|
815
|
+
const scope = scopeOf(site);
|
|
816
|
+
if ("error" in scope) issues.push({
|
|
817
|
+
path,
|
|
818
|
+
message: scope.error
|
|
819
|
+
});
|
|
820
|
+
continue;
|
|
821
|
+
}
|
|
822
|
+
const operand = site.token.$env;
|
|
823
|
+
if (site.key === "$env" && isPlainObject(operand) && site.position !== "property") {
|
|
824
|
+
const where = site.position === "concat" ? "a $concat part" : site.position === "element" ? "an array element" : site.position === "template" ? "the whole $map template" : "the whole host";
|
|
825
|
+
issues.push({
|
|
826
|
+
path,
|
|
827
|
+
message: `{ $env: { name, optional: true } } is legal only as the direct value of an object property (it omits that property when ${String(operand.name)} is unset), not as ${where}. Use { $env: ${JSON.stringify(operand.name)} } here.`
|
|
828
|
+
});
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
return issues;
|
|
832
|
+
}
|
|
833
|
+
function defOf(schema) {
|
|
834
|
+
if (!isPlainObjectLike(schema)) return void 0;
|
|
835
|
+
const internals = schema._zod;
|
|
836
|
+
if (!isPlainObjectLike(internals)) return void 0;
|
|
837
|
+
const def = internals.def;
|
|
838
|
+
if (!isPlainObjectLike(def) || typeof def.type !== "string") return void 0;
|
|
839
|
+
return {
|
|
840
|
+
...def,
|
|
841
|
+
type: def.type
|
|
842
|
+
};
|
|
843
|
+
}
|
|
844
|
+
function isPlainObjectLike(value) {
|
|
845
|
+
return (typeof value === "object" || typeof value === "function") && value !== null;
|
|
846
|
+
}
|
|
847
|
+
const WRAPPERS = /* @__PURE__ */ new Set([
|
|
848
|
+
"optional",
|
|
849
|
+
"nullable",
|
|
850
|
+
"default",
|
|
851
|
+
"prefault",
|
|
852
|
+
"readonly",
|
|
853
|
+
"nonoptional",
|
|
854
|
+
"catch",
|
|
855
|
+
"success"
|
|
856
|
+
]);
|
|
857
|
+
/** The schema at `path` inside a zod schema (walking objects, records,
|
|
858
|
+
* arrays, tuples, unions and wrappers), or why the path does not exist. */
|
|
859
|
+
function schemaAtPath(schema, path) {
|
|
860
|
+
let current = schema;
|
|
861
|
+
for (let i = 0; i <= path.length; i++) {
|
|
862
|
+
for (let guard = 0; guard < 32; guard++) {
|
|
863
|
+
const def = defOf(current);
|
|
864
|
+
if (!def) break;
|
|
865
|
+
if (WRAPPERS.has(def.type)) current = def.innerType;
|
|
866
|
+
else if (def.type === "lazy" && typeof def.getter === "function") {
|
|
867
|
+
const getter = def.getter;
|
|
868
|
+
current = getter();
|
|
869
|
+
} else if (def.type === "pipe") {
|
|
870
|
+
const out = defOf(def.out);
|
|
871
|
+
current = out && out.type !== "transform" ? def.out : def.in;
|
|
872
|
+
} else break;
|
|
873
|
+
}
|
|
874
|
+
if (i === path.length) return {
|
|
875
|
+
ok: true,
|
|
876
|
+
schema: current
|
|
877
|
+
};
|
|
878
|
+
const segment = path[i];
|
|
879
|
+
const def = defOf(current);
|
|
880
|
+
if (!def) return {
|
|
881
|
+
ok: false,
|
|
882
|
+
at: i,
|
|
883
|
+
reason: "is not a schema"
|
|
884
|
+
};
|
|
885
|
+
switch (def.type) {
|
|
886
|
+
case "any":
|
|
887
|
+
case "unknown": return {
|
|
888
|
+
ok: true,
|
|
889
|
+
schema: current
|
|
890
|
+
};
|
|
891
|
+
case "object": {
|
|
892
|
+
const shape = isPlainObjectLike(def.shape) ? def.shape : {};
|
|
893
|
+
if (typeof segment === "string" && segment in shape) {
|
|
894
|
+
current = shape[segment];
|
|
895
|
+
break;
|
|
896
|
+
}
|
|
897
|
+
const catchall = defOf(def.catchall);
|
|
898
|
+
if (catchall && catchall.type !== "never") {
|
|
899
|
+
current = def.catchall;
|
|
900
|
+
break;
|
|
901
|
+
}
|
|
902
|
+
const keys = Object.keys(shape);
|
|
903
|
+
return {
|
|
904
|
+
ok: false,
|
|
905
|
+
at: i,
|
|
906
|
+
reason: `has no key ${JSON.stringify(segment)} (keys: ${keys.join(", ") || "none"})`
|
|
907
|
+
};
|
|
908
|
+
}
|
|
909
|
+
case "record":
|
|
910
|
+
if (typeof segment !== "string") return {
|
|
911
|
+
ok: false,
|
|
912
|
+
at: i,
|
|
913
|
+
reason: "is a record (string keys)"
|
|
914
|
+
};
|
|
915
|
+
current = def.valueType;
|
|
916
|
+
break;
|
|
917
|
+
case "array":
|
|
918
|
+
if (typeof segment !== "number") return {
|
|
919
|
+
ok: false,
|
|
920
|
+
at: i,
|
|
921
|
+
reason: "is an array (numeric index)"
|
|
922
|
+
};
|
|
923
|
+
current = def.element;
|
|
924
|
+
break;
|
|
925
|
+
case "tuple": {
|
|
926
|
+
const items = Array.isArray(def.items) ? def.items : [];
|
|
927
|
+
if (typeof segment !== "number" || segment >= items.length) return {
|
|
928
|
+
ok: false,
|
|
929
|
+
at: i,
|
|
930
|
+
reason: `is a ${items.length}-tuple`
|
|
931
|
+
};
|
|
932
|
+
current = items[segment];
|
|
933
|
+
break;
|
|
934
|
+
}
|
|
935
|
+
case "union": {
|
|
936
|
+
const options = Array.isArray(def.options) ? def.options : [];
|
|
937
|
+
for (const option of options) {
|
|
938
|
+
const hit = schemaAtPath(option, path.slice(i));
|
|
939
|
+
if (hit.ok) return hit;
|
|
940
|
+
}
|
|
941
|
+
return {
|
|
942
|
+
ok: false,
|
|
943
|
+
at: i,
|
|
944
|
+
reason: "matches no union member"
|
|
945
|
+
};
|
|
946
|
+
}
|
|
947
|
+
default: return {
|
|
948
|
+
ok: false,
|
|
949
|
+
at: i,
|
|
950
|
+
reason: `is a ${def.type}, not a container`
|
|
951
|
+
};
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
return {
|
|
955
|
+
ok: true,
|
|
956
|
+
schema: current
|
|
957
|
+
};
|
|
958
|
+
}
|
|
959
|
+
/** Whether a (property) schema admits an absent value on the OUTPUT side:
|
|
960
|
+
* `.optional()` does; `.default()`/`.prefault()` fill it in, and
|
|
961
|
+
* `.nonoptional()` forbids it. */
|
|
962
|
+
function mayBeAbsent(schema) {
|
|
963
|
+
let current = schema;
|
|
964
|
+
for (let guard = 0; guard < 32; guard++) {
|
|
965
|
+
const internals = isPlainObjectLike(current) ? current._zod : void 0;
|
|
966
|
+
if (isPlainObjectLike(internals) && internals.optout === "optional") return true;
|
|
967
|
+
const def = defOf(current);
|
|
968
|
+
if (!def) return false;
|
|
969
|
+
if (def.type === "optional") return true;
|
|
970
|
+
if (def.type === "default" || def.type === "prefault" || def.type === "nonoptional" || !WRAPPERS.has(def.type)) return false;
|
|
971
|
+
current = def.innerType;
|
|
972
|
+
}
|
|
973
|
+
return false;
|
|
974
|
+
}
|
|
975
|
+
/** Whether `key` may be absent from a value of the object schema `schema`:
|
|
976
|
+
* an optional property, or (in a union) one some member makes optional or
|
|
977
|
+
* lacks. A record value or an array element is never optional. */
|
|
978
|
+
function optionalKeyIn(schema, key) {
|
|
979
|
+
const unwrapped = schemaAtPath(schema, []);
|
|
980
|
+
const def = unwrapped.ok ? defOf(unwrapped.schema) : void 0;
|
|
981
|
+
if (def?.type === "object") {
|
|
982
|
+
const shape = isPlainObjectLike(def.shape) ? def.shape : {};
|
|
983
|
+
return key in shape && mayBeAbsent(shape[key]);
|
|
984
|
+
}
|
|
985
|
+
if (def?.type === "union" && Array.isArray(def.options)) return def.options.some((option) => {
|
|
986
|
+
const inner = schemaAtPath(option, []);
|
|
987
|
+
const optionDef = inner.ok ? defOf(inner.schema) : void 0;
|
|
988
|
+
const shape = optionDef?.type === "object" && isPlainObjectLike(optionDef.shape) ? optionDef.shape : void 0;
|
|
989
|
+
return shape !== void 0 && (!(key in shape) || mayBeAbsent(shape[key]));
|
|
990
|
+
});
|
|
991
|
+
return false;
|
|
992
|
+
}
|
|
993
|
+
/**
|
|
994
|
+
* Whether the field `path[at]` is OPTIONAL in `schema` (a producer's
|
|
995
|
+
* `outputsSchema`, or a `$map` element schema), given that `path[0..at-1]`
|
|
996
|
+
* exists: the codegen'd `OutputToken<T | undefined>` / `ItemToken<T |
|
|
997
|
+
* undefined>` positions, whose rendered property the resolver omits when
|
|
998
|
+
* the field is absent. False for a record key, an array index, or a path
|
|
999
|
+
* the schema does not describe.
|
|
1000
|
+
*/
|
|
1001
|
+
function isOptionalField(schema, path, at) {
|
|
1002
|
+
const key = path[at];
|
|
1003
|
+
if (typeof key !== "string") return false;
|
|
1004
|
+
const parent = schemaAtPath(schema, path.slice(0, at));
|
|
1005
|
+
return parent.ok && optionalKeyIn(parent.schema, key);
|
|
1006
|
+
}
|
|
1007
|
+
/** The element schema of a collection schema (array element, record
|
|
1008
|
+
* value), or undefined when the schema does not say. */
|
|
1009
|
+
function elementSchemaOf(schema) {
|
|
1010
|
+
const collection = collectionOf(schema);
|
|
1011
|
+
return collection.kind === "array" || collection.kind === "record" ? collection.element : void 0;
|
|
1012
|
+
}
|
|
1013
|
+
/** The collection kind of a schema (unwrapped): array, record, unknown (no
|
|
1014
|
+
* check possible) or something else. */
|
|
1015
|
+
function collectionOf(schema) {
|
|
1016
|
+
const unwrapped = schemaAtPath(schema, []);
|
|
1017
|
+
const def = unwrapped.ok ? defOf(unwrapped.schema) : void 0;
|
|
1018
|
+
if (!def) return { kind: "unknown" };
|
|
1019
|
+
if (def.type === "array") return {
|
|
1020
|
+
kind: "array",
|
|
1021
|
+
element: def.element
|
|
1022
|
+
};
|
|
1023
|
+
if (def.type === "record") return {
|
|
1024
|
+
kind: "record",
|
|
1025
|
+
element: def.valueType
|
|
1026
|
+
};
|
|
1027
|
+
if (def.type === "object") {
|
|
1028
|
+
const catchall = defOf(def.catchall);
|
|
1029
|
+
if (catchall && catchall.type !== "never") {
|
|
1030
|
+
const shape = isPlainObjectLike(def.shape) ? def.shape : {};
|
|
1031
|
+
return Object.keys(shape).length === 0 ? {
|
|
1032
|
+
kind: "record",
|
|
1033
|
+
element: def.catchall
|
|
1034
|
+
} : {
|
|
1035
|
+
kind: "record",
|
|
1036
|
+
element: void 0
|
|
1037
|
+
};
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
if (def.type === "tuple") return {
|
|
1041
|
+
kind: "array",
|
|
1042
|
+
element: void 0
|
|
1043
|
+
};
|
|
1044
|
+
if (def.type === "any" || def.type === "unknown" || def.type === "union") return { kind: "unknown" };
|
|
1045
|
+
return {
|
|
1046
|
+
kind: "other",
|
|
1047
|
+
type: def.type
|
|
1048
|
+
};
|
|
1049
|
+
}
|
|
1050
|
+
/** Every `$output` token's producer exists and its path is valid against
|
|
1051
|
+
* the producer's `outputsSchema`; every `$map`'s `over` is a collection
|
|
1052
|
+
* there (a record under `into: "record"`), and every `$item` path exists
|
|
1053
|
+
* in the element schema of the map it binds. */
|
|
1054
|
+
function checkOutputPaths(host, outputsSchemaOf) {
|
|
1055
|
+
const issues = [];
|
|
1056
|
+
const elements = /* @__PURE__ */ new Map();
|
|
1057
|
+
const elementOf = (scope) => "error" in scope ? void 0 : elements.get(scope.token);
|
|
1058
|
+
for (const site of collectTokenSites(host)) {
|
|
1059
|
+
if (!tokenSchema.safeParse(site.token).success) continue;
|
|
1060
|
+
if (site.key === "$map") {
|
|
1061
|
+
elements.set(site.token, checkMap(site, outputsSchemaOf, elementOf, issues));
|
|
1062
|
+
continue;
|
|
1063
|
+
}
|
|
1064
|
+
if (site.key === "$item") {
|
|
1065
|
+
const scope = scopeOf(site);
|
|
1066
|
+
const element = elementOf(scope);
|
|
1067
|
+
if (!element || element.element === void 0 || "error" in scope) continue;
|
|
1068
|
+
const itemPath = itemPathOf(site);
|
|
1069
|
+
const hit = schemaAtPath(element.element, itemPath);
|
|
1070
|
+
if (!hit.ok) {
|
|
1071
|
+
const parent = itemPath.slice(0, hit.at);
|
|
1072
|
+
issues.push({
|
|
1073
|
+
path: formatPath(site.path),
|
|
1074
|
+
message: `${describeToken(site.token)}: the element${parent.length ? `'s ${formatPath(parent)}` : ""} of the $map at ${formatPath(scope.path)}${scope.as ? ` (as "${scope.as}")` : ""} ${hit.reason} (element of ${element.label}).`
|
|
1075
|
+
});
|
|
1076
|
+
}
|
|
1077
|
+
continue;
|
|
1078
|
+
}
|
|
1079
|
+
if (site.key !== "$output") continue;
|
|
1080
|
+
const ref = refOf(site);
|
|
1081
|
+
if (!ref) continue;
|
|
1082
|
+
const path = formatPath(site.path);
|
|
1083
|
+
const lookup = outputsSchemaOf(ref);
|
|
1084
|
+
if ("error" in lookup) {
|
|
1085
|
+
issues.push({
|
|
1086
|
+
path,
|
|
1087
|
+
message: lookup.error
|
|
1088
|
+
});
|
|
1089
|
+
continue;
|
|
1090
|
+
}
|
|
1091
|
+
const outputPath = pathOf(site);
|
|
1092
|
+
const hit = schemaAtPath(lookup.schema, outputPath);
|
|
1093
|
+
if (!hit.ok) {
|
|
1094
|
+
const parent = outputPath.slice(0, hit.at);
|
|
1095
|
+
const where = parent.length ? `outputs.${formatPath(parent)}` : "the outputs";
|
|
1096
|
+
issues.push({
|
|
1097
|
+
path,
|
|
1098
|
+
message: `${describeToken(site.token)}: ${where} ${hit.reason} in the outputsSchema of ${lookup.label}.`
|
|
1099
|
+
});
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
return issues;
|
|
1103
|
+
}
|
|
1104
|
+
/** A `$map`'s `over` against its schema: a collection (a record under
|
|
1105
|
+
* `into: "record"`). Returns the element schema for the map's `$item`s. */
|
|
1106
|
+
function checkMap(site, outputsSchemaOf, elementOf, issues) {
|
|
1107
|
+
const operand = site.token.$map;
|
|
1108
|
+
if (!isPlainObject(operand)) return void 0;
|
|
1109
|
+
const over = operand.over;
|
|
1110
|
+
const into = operand.into === "record";
|
|
1111
|
+
let schema;
|
|
1112
|
+
let label;
|
|
1113
|
+
if (isPlainObject(over) && "$output" in over) {
|
|
1114
|
+
const overSite = {
|
|
1115
|
+
...site,
|
|
1116
|
+
key: "$output",
|
|
1117
|
+
token: over
|
|
1118
|
+
};
|
|
1119
|
+
const ref = refOf(overSite);
|
|
1120
|
+
if (!ref) return void 0;
|
|
1121
|
+
const lookup = outputsSchemaOf(ref);
|
|
1122
|
+
if ("error" in lookup) return void 0;
|
|
1123
|
+
const hit = schemaAtPath(lookup.schema, pathOf(overSite));
|
|
1124
|
+
if (!hit.ok) return void 0;
|
|
1125
|
+
schema = hit.schema;
|
|
1126
|
+
label = `${describeToken(over)} in the outputsSchema of ${lookup.label}`;
|
|
1127
|
+
} else if (isPlainObject(over) && "$item" in over) {
|
|
1128
|
+
const overSite = {
|
|
1129
|
+
...site,
|
|
1130
|
+
key: "$item",
|
|
1131
|
+
token: over
|
|
1132
|
+
};
|
|
1133
|
+
const outer = elementOf(scopeOf(overSite));
|
|
1134
|
+
if (!outer || outer.element === void 0) return void 0;
|
|
1135
|
+
const hit = schemaAtPath(outer.element, itemPathOf(overSite));
|
|
1136
|
+
if (!hit.ok) return void 0;
|
|
1137
|
+
schema = hit.schema;
|
|
1138
|
+
label = `${describeToken(over)} (element of ${outer.label})`;
|
|
1139
|
+
} else return;
|
|
1140
|
+
const path = formatPath(site.path);
|
|
1141
|
+
const collection = collectionOf(schema);
|
|
1142
|
+
if (collection.kind === "unknown") return void 0;
|
|
1143
|
+
if (collection.kind === "other") {
|
|
1144
|
+
issues.push({
|
|
1145
|
+
path,
|
|
1146
|
+
message: `$map over ${label} is a ${collection.type}, not an array or a record; a $map iterates a collection.`
|
|
1147
|
+
});
|
|
1148
|
+
return;
|
|
1149
|
+
}
|
|
1150
|
+
if (into && collection.kind === "array") {
|
|
1151
|
+
issues.push({
|
|
1152
|
+
path,
|
|
1153
|
+
message: `$map with into: "record" maps over ${label}, which is an array: an array has no keys to keep. Drop into: "record" (the result is an array) or map over a record.`
|
|
1154
|
+
});
|
|
1155
|
+
return;
|
|
1156
|
+
}
|
|
1157
|
+
return {
|
|
1158
|
+
element: collection.element,
|
|
1159
|
+
label
|
|
1160
|
+
};
|
|
1161
|
+
}
|
|
1162
|
+
function outputToken(host, path, member) {
|
|
1163
|
+
return `{ $output: { host: "${host}"${member ? `, member: "${member}"` : ""}, path: [${path.map((p) => JSON.stringify(p)).join(", ")}] } }`;
|
|
1164
|
+
}
|
|
1165
|
+
function isDriveReference(value) {
|
|
1166
|
+
if (!isPlainObject(value)) return false;
|
|
1167
|
+
const keys = Object.keys(value).sort();
|
|
1168
|
+
return keys.length === 2 && keys[0] === "from" && keys[1] === "slug" && typeof value.from === "string" && typeof value.slug === "string";
|
|
1169
|
+
}
|
|
1170
|
+
function checkReactor(reactor, base, found) {
|
|
1171
|
+
if (!isPlainObject(reactor) || !isPlainObject(reactor.backends)) return;
|
|
1172
|
+
for (const [name, backend] of Object.entries(reactor.backends)) {
|
|
1173
|
+
if (!isPlainObject(backend) || !isPlainObject(backend.remote)) continue;
|
|
1174
|
+
const host = backend.remote.host;
|
|
1175
|
+
if (host === void 0) continue;
|
|
1176
|
+
const producer = typeof host === "string" ? host : "switchboard";
|
|
1177
|
+
found.push({
|
|
1178
|
+
path: `${base}reactor.backends.${name}.remote.host`,
|
|
1179
|
+
message: `remote: { host } was removed; use remote: { url: ${producer}.endpoints.graphql } with ${producer} from ../${producer}/outputs.js, or remote: { url: ${outputToken(producer, ["endpoints", "graphql"])} }.`
|
|
1180
|
+
});
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
function checkPlugins(runner, base, memberHosts, found) {
|
|
1184
|
+
if (!isPlainObject(runner) || !Array.isArray(runner.plugins)) return;
|
|
1185
|
+
runner.plugins.forEach((entry, index) => {
|
|
1186
|
+
if (!isPlainObject(entry) || !isPlainObject(entry.config)) return;
|
|
1187
|
+
for (const [key, value] of Object.entries(entry.config)) {
|
|
1188
|
+
if (!isDriveReference(value)) continue;
|
|
1189
|
+
const host = memberHosts[value.from] ?? value.from;
|
|
1190
|
+
const member = memberHosts[value.from] ? value.from : void 0;
|
|
1191
|
+
found.push({
|
|
1192
|
+
path: `${base}runner.plugins[${index}].config.${key}`,
|
|
1193
|
+
message: `${key}: { from, slug } was removed; use ${host}.drives.${value.slug}.url from ../${host}/outputs.js, or ${outputToken(host, [
|
|
1194
|
+
"drives",
|
|
1195
|
+
value.slug,
|
|
1196
|
+
"url"
|
|
1197
|
+
])}${member ? ` (add member: "${member}" if two members run host "${host}")` : ""}.`
|
|
1198
|
+
});
|
|
1199
|
+
}
|
|
1200
|
+
});
|
|
1201
|
+
}
|
|
1202
|
+
/** Every removed form in a host file (reactor or compound), in document
|
|
1203
|
+
* order. Compound wrappers are checked too. */
|
|
1204
|
+
function findRemovedForms(host) {
|
|
1205
|
+
const found = [];
|
|
1206
|
+
if (!isPlainObject(host)) return found;
|
|
1207
|
+
const children = isPlainObject(host.children) ? host.children : void 0;
|
|
1208
|
+
const memberHosts = {};
|
|
1209
|
+
for (const [key, wrapper] of Object.entries(children ?? {})) if (isPlainObject(wrapper) && typeof wrapper.host === "string") memberHosts[key] = wrapper.host;
|
|
1210
|
+
checkReactor(host.reactor, "", found);
|
|
1211
|
+
checkPlugins(host.runner, "", memberHosts, found);
|
|
1212
|
+
for (const [key, wrapper] of Object.entries(children ?? {})) {
|
|
1213
|
+
if (!isPlainObject(wrapper)) continue;
|
|
1214
|
+
checkReactor(wrapper.reactor, `children.${key}.`, found);
|
|
1215
|
+
checkPlugins(wrapper.runner, `children.${key}.`, memberHosts, found);
|
|
1216
|
+
}
|
|
1217
|
+
if (children && isPlainObject(host.config)) for (const key of ["projectDrivesIntoConnect", "drivesPublicBase"]) {
|
|
1218
|
+
if (host.config[key] === void 0) continue;
|
|
1219
|
+
found.push({
|
|
1220
|
+
path: `config.${key}`,
|
|
1221
|
+
message: `config.${key} was removed; declare the drives on the member that consumes them, by output token: reactor.drives: [{ slug: "<slug>", remote: { url: ${outputToken("switchboard", [
|
|
1222
|
+
"drives",
|
|
1223
|
+
"<slug>",
|
|
1224
|
+
"url"
|
|
1225
|
+
])} } }].`
|
|
1226
|
+
});
|
|
1227
|
+
}
|
|
1228
|
+
return found;
|
|
1229
|
+
}
|
|
1230
|
+
const BUILTIN = /\$\{(userData|projectRoot)\}/g;
|
|
1231
|
+
function substitute(text, env) {
|
|
1232
|
+
return text.replace(BUILTIN, (match, name) => env[name] ?? match);
|
|
1233
|
+
}
|
|
1234
|
+
/** Deep-substitute the built-ins that `env` provides in every string; an
|
|
1235
|
+
* absent built-in is left as written. The input is never mutated. */
|
|
1236
|
+
function substituteBuiltinEnv(value, env) {
|
|
1237
|
+
return substituteValue(value, env);
|
|
1238
|
+
}
|
|
1239
|
+
function substituteValue(value, env) {
|
|
1240
|
+
if (typeof value === "string") return substitute(value, env);
|
|
1241
|
+
if (Array.isArray(value)) return value.map((v) => substituteValue(v, env));
|
|
1242
|
+
if (value !== null && typeof value === "object") {
|
|
1243
|
+
const out = {};
|
|
1244
|
+
for (const [k, v] of Object.entries(value)) out[k] = substituteValue(v, env);
|
|
1245
|
+
return out;
|
|
1246
|
+
}
|
|
1247
|
+
return value;
|
|
1248
|
+
}
|
|
1249
|
+
/**
|
|
1250
|
+
* The dependency plan (pipeline step 4): which compound member consumes
|
|
1251
|
+
* which member's outputs, and the start order that follows. Producers start
|
|
1252
|
+
* before consumers; `config.startOrder` is optional and, when given, must
|
|
1253
|
+
* agree with the tokens. Cycles fail. Pure.
|
|
1254
|
+
*/
|
|
1255
|
+
var PlanError = class extends Error {
|
|
1256
|
+
constructor(message) {
|
|
1257
|
+
super(message);
|
|
1258
|
+
this.name = "PlanError";
|
|
1259
|
+
}
|
|
1260
|
+
};
|
|
1261
|
+
/** The member a ref names: the unique member running `ref.host`, or the
|
|
1262
|
+
* member `ref.member` when given (it must run `ref.host`). */
|
|
1263
|
+
function memberForRef(ref, members) {
|
|
1264
|
+
if (ref.member !== void 0) {
|
|
1265
|
+
const named = members.find((m) => m.key === ref.member);
|
|
1266
|
+
if (!named) return { error: `names member "${ref.member}", which this compound does not declare (members: ${members.map((m) => m.key).join(", ")}).` };
|
|
1267
|
+
if (named.host !== ref.host) return { error: `names member "${ref.member}" of host "${ref.host}", but that member runs host "${named.host}".` };
|
|
1268
|
+
return { key: named.key };
|
|
1269
|
+
}
|
|
1270
|
+
const running = members.filter((m) => m.host === ref.host);
|
|
1271
|
+
if (running.length === 1) return { key: running[0].key };
|
|
1272
|
+
if (running.length === 0) return { error: `names host "${ref.host}", which no member of this compound runs (members run: ${[...new Set(members.map((m) => m.host))].join(", ")}).` };
|
|
1273
|
+
return { error: `names host "${ref.host}", which members ${running.map((m) => `"${m.key}"`).join(" and ")} both run; add member: "<key>" to pick one.` };
|
|
1274
|
+
}
|
|
1275
|
+
function edgesOf(members) {
|
|
1276
|
+
const edges = [];
|
|
1277
|
+
const problems = [];
|
|
1278
|
+
for (const member of members) {
|
|
1279
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1280
|
+
for (const { ref, path } of member.refs) {
|
|
1281
|
+
const target = memberForRef(ref, members);
|
|
1282
|
+
if ("error" in target) {
|
|
1283
|
+
problems.push(`${member.key}: ${path} ${target.error}`);
|
|
1284
|
+
continue;
|
|
1285
|
+
}
|
|
1286
|
+
if (target.key === member.key) {
|
|
1287
|
+
problems.push(`${member.key}: ${path} reads ${refKey(ref)}'s outputs, which is this member itself.`);
|
|
1288
|
+
continue;
|
|
1289
|
+
}
|
|
1290
|
+
if (seen.has(target.key)) continue;
|
|
1291
|
+
seen.add(target.key);
|
|
1292
|
+
edges.push({
|
|
1293
|
+
consumer: member.key,
|
|
1294
|
+
producer: target.key,
|
|
1295
|
+
path
|
|
1296
|
+
});
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
if (problems.length > 0) throw new PlanError(problems.join("\n"));
|
|
1300
|
+
return edges;
|
|
1301
|
+
}
|
|
1302
|
+
/** Declared start order: the named members first, then the rest in
|
|
1303
|
+
* declaration order. */
|
|
1304
|
+
function declaredOrder(members, startOrder) {
|
|
1305
|
+
const keys = members.map((m) => m.key);
|
|
1306
|
+
const named = [...new Set(startOrder)].filter((k) => keys.includes(k));
|
|
1307
|
+
return [...named, ...keys.filter((k) => !named.includes(k))];
|
|
1308
|
+
}
|
|
1309
|
+
function planCompound(members, startOrder) {
|
|
1310
|
+
const edges = edgesOf(members);
|
|
1311
|
+
if (startOrder) {
|
|
1312
|
+
const order = declaredOrder(members, startOrder);
|
|
1313
|
+
const index = new Map(order.map((k, i) => [k, i]));
|
|
1314
|
+
const bad = edges.filter((e) => (index.get(e.producer) ?? 0) > (index.get(e.consumer) ?? 0));
|
|
1315
|
+
if (bad.length > 0) throw new PlanError(bad.map((e) => `config.startOrder starts "${e.consumer}" before "${e.producer}", but ${e.consumer}.${e.path} consumes "${e.producer}"'s outputs. Reorder startOrder (or omit it: the order follows the tokens).`).join("\n"));
|
|
1316
|
+
return {
|
|
1317
|
+
order,
|
|
1318
|
+
edges,
|
|
1319
|
+
source: "startOrder"
|
|
1320
|
+
};
|
|
1321
|
+
}
|
|
1322
|
+
const pending = new Map(members.map((m) => [m.key, /* @__PURE__ */ new Set()]));
|
|
1323
|
+
for (const e of edges) pending.get(e.consumer)?.add(e.producer);
|
|
1324
|
+
const order = [];
|
|
1325
|
+
while (order.length < members.length) {
|
|
1326
|
+
const next = members.find((m) => !order.includes(m.key) && pending.get(m.key)?.size === 0);
|
|
1327
|
+
if (!next) {
|
|
1328
|
+
const stuck = members.filter((m) => !order.includes(m.key));
|
|
1329
|
+
throw new PlanError(`output tokens form a cycle between ${stuck.map((m) => `"${m.key}"`).join(", ")}: ${edges.filter((e) => stuck.some((m) => m.key === e.consumer) && stuck.some((m) => m.key === e.producer)).map((e) => `${e.consumer} (${e.path}) needs ${e.producer}`).join("; ")}.`);
|
|
1330
|
+
}
|
|
1331
|
+
order.push(next.key);
|
|
1332
|
+
for (const set of pending.values()) set.delete(next.key);
|
|
1333
|
+
}
|
|
1334
|
+
return {
|
|
1335
|
+
order,
|
|
1336
|
+
edges,
|
|
1337
|
+
source: "tokens"
|
|
1338
|
+
};
|
|
1339
|
+
}
|
|
1340
|
+
var TokenResolutionError = class extends Error {
|
|
1341
|
+
constructor(message) {
|
|
1342
|
+
super(message);
|
|
1343
|
+
this.name = "TokenResolutionError";
|
|
1344
|
+
}
|
|
1345
|
+
};
|
|
1346
|
+
/** A resolved `{ $env: { name, optional: true } }` whose variable is unset,
|
|
1347
|
+
* or an `$output`/`$item` reading an absent optional field: its enclosing
|
|
1348
|
+
* property is omitted. */
|
|
1349
|
+
const OMIT = Symbol("omit");
|
|
1350
|
+
/** `reactor.drives["workflows"]` (or `…[2]` for an array element). */
|
|
1351
|
+
function elementText(binding) {
|
|
1352
|
+
const key = typeof binding.key === "number" ? `[${binding.key}]` : `[${JSON.stringify(binding.key)}]`;
|
|
1353
|
+
return `${formatPath(binding.path)}${key}`;
|
|
1354
|
+
}
|
|
1355
|
+
/** Provenance of `$map`-rendered arrays: element index → the input key
|
|
1356
|
+
* (record key, or array index) it was rendered from. Lets resolved
|
|
1357
|
+
* validation name the element key, not just the result index. */
|
|
1358
|
+
const renderedKeys = /* @__PURE__ */ new WeakMap();
|
|
1359
|
+
/**
|
|
1360
|
+
* The `$map` elements an issue path (from resolved validation of a resolved
|
|
1361
|
+
* host) passes through, as text: `$map element "workflows"`. Undefined when
|
|
1362
|
+
* the path crosses no `$map`-rendered array. Walk the SAME object
|
|
1363
|
+
* `resolveHostOutputs` returned (provenance is by identity).
|
|
1364
|
+
*/
|
|
1365
|
+
function describeMapElements(host, path) {
|
|
1366
|
+
const found = [];
|
|
1367
|
+
let current = host;
|
|
1368
|
+
for (const segment of path) if (Array.isArray(current) && typeof segment === "number") {
|
|
1369
|
+
const key = renderedKeys.get(current)?.[segment];
|
|
1370
|
+
if (key !== void 0) found.push(`$map element ${typeof key === "number" ? `[${key}]` : JSON.stringify(key)}`);
|
|
1371
|
+
current = current[segment];
|
|
1372
|
+
} else if (isPlainObject(current) && typeof segment === "string") current = current[segment];
|
|
1373
|
+
else break;
|
|
1374
|
+
return found.length ? found.join(" › ") : void 0;
|
|
1375
|
+
}
|
|
1376
|
+
/** A deep copy of a resolved (JSON-shaped) value that keeps the `$map`
|
|
1377
|
+
* provenance of its rendered arrays (structuredClone would drop it). */
|
|
1378
|
+
function cloneWithProvenance(value) {
|
|
1379
|
+
if (Array.isArray(value)) {
|
|
1380
|
+
const copy = value.map(cloneWithProvenance);
|
|
1381
|
+
const keys = renderedKeys.get(value);
|
|
1382
|
+
if (keys) renderedKeys.set(copy, keys);
|
|
1383
|
+
return copy;
|
|
1384
|
+
}
|
|
1385
|
+
if (isPlainObject(value)) {
|
|
1386
|
+
const copy = {};
|
|
1387
|
+
for (const [key, child] of Object.entries(value)) copy[key] = cloneWithProvenance(child);
|
|
1388
|
+
return copy;
|
|
1389
|
+
}
|
|
1390
|
+
return value;
|
|
1391
|
+
}
|
|
1392
|
+
/** The value at `path` inside `root` (output data: records and arrays). */
|
|
1393
|
+
function walkPath(root, path) {
|
|
1394
|
+
let current = root;
|
|
1395
|
+
for (let i = 0; i < path.length; i++) {
|
|
1396
|
+
const segment = path[i];
|
|
1397
|
+
const next = Array.isArray(current) ? typeof segment === "number" ? current[segment] : void 0 : isPlainObject(current) && typeof segment === "string" ? current[segment] : void 0;
|
|
1398
|
+
if (next === void 0) {
|
|
1399
|
+
const has = isPlainObject(current) ? Object.keys(current).join(", ") || "nothing" : Array.isArray(current) ? `${current.length} elements` : JSON.stringify(current);
|
|
1400
|
+
return {
|
|
1401
|
+
ok: false,
|
|
1402
|
+
at: i,
|
|
1403
|
+
has
|
|
1404
|
+
};
|
|
1405
|
+
}
|
|
1406
|
+
current = next;
|
|
1407
|
+
}
|
|
1408
|
+
return {
|
|
1409
|
+
ok: true,
|
|
1410
|
+
value: current
|
|
1411
|
+
};
|
|
1412
|
+
}
|
|
1413
|
+
/** The schema at `path` inside `schema`, when both are known. */
|
|
1414
|
+
function schemaOf(schema, path) {
|
|
1415
|
+
if (schema === void 0) return void 0;
|
|
1416
|
+
const hit = schemaAtPath(schema, path);
|
|
1417
|
+
return hit.ok ? hit.schema : void 0;
|
|
1418
|
+
}
|
|
1419
|
+
function pathSegments(path) {
|
|
1420
|
+
return path.filter((p) => typeof p === "string" || typeof p === "number");
|
|
1421
|
+
}
|
|
1422
|
+
var Resolver = class {
|
|
1423
|
+
sources;
|
|
1424
|
+
self;
|
|
1425
|
+
deferred = [];
|
|
1426
|
+
/** What the last OMIT stood for, for the "nothing to omit" errors. */
|
|
1427
|
+
omitted = "an optional $env";
|
|
1428
|
+
constructor(sources, self) {
|
|
1429
|
+
this.sources = sources;
|
|
1430
|
+
this.self = self;
|
|
1431
|
+
}
|
|
1432
|
+
/** The member keys a token reads (`$output` on a member's host), when
|
|
1433
|
+
* resolving a compound's own fields with `deferSelf`. */
|
|
1434
|
+
selfRefs(token, trail) {
|
|
1435
|
+
if (!this.self) return [];
|
|
1436
|
+
const keys = /* @__PURE__ */ new Set();
|
|
1437
|
+
for (const site of collectTokenSites(token)) {
|
|
1438
|
+
const operand = site.token.$output;
|
|
1439
|
+
if (site.key !== "$output" || !isPlainObject(operand)) continue;
|
|
1440
|
+
if (typeof operand.host !== "string") continue;
|
|
1441
|
+
const ref = typeof operand.member === "string" ? {
|
|
1442
|
+
host: operand.host,
|
|
1443
|
+
member: operand.member
|
|
1444
|
+
} : { host: operand.host };
|
|
1445
|
+
if (!this.self.members.some((m) => m.host === ref.host)) continue;
|
|
1446
|
+
const target = memberForRef(ref, this.self.members);
|
|
1447
|
+
if ("error" in target) this.fail([...trail, ...site.path], `in a compound ${target.error}`);
|
|
1448
|
+
keys.add(target.key);
|
|
1449
|
+
}
|
|
1450
|
+
return [...keys];
|
|
1451
|
+
}
|
|
1452
|
+
fail(trail, message, scope = []) {
|
|
1453
|
+
const where = this.sources.where ? `${this.sources.where}: ` : "";
|
|
1454
|
+
const inside = scope.length ? ` (rendering $map element ${scope.map(elementText).join(" › ")})` : "";
|
|
1455
|
+
throw new TokenResolutionError(`${where}\`${formatPath(trail)}\` ${message}${inside}`);
|
|
1456
|
+
}
|
|
1457
|
+
value(value, trail, scope = []) {
|
|
1458
|
+
if (typeof value === "string") return this.sources.builtins ? substituteBuiltinEnv(value, this.sources.builtins) : value;
|
|
1459
|
+
if (Array.isArray(value)) return value.map((child, index) => {
|
|
1460
|
+
const out = this.value(child, [...trail, index], scope);
|
|
1461
|
+
if (out === OMIT) this.fail([...trail, index], `is ${this.omitted} inside an array.`, scope);
|
|
1462
|
+
return out;
|
|
1463
|
+
});
|
|
1464
|
+
if (!isPlainObject(value)) return value;
|
|
1465
|
+
if (isEscape(value)) return structuredClone(value);
|
|
1466
|
+
if (tokenKeyOf(value)) {
|
|
1467
|
+
const members = scope.length === 0 ? this.selfRefs(value, trail) : [];
|
|
1468
|
+
if (members.length > 0) {
|
|
1469
|
+
this.deferred.push({
|
|
1470
|
+
trail,
|
|
1471
|
+
token: value,
|
|
1472
|
+
members
|
|
1473
|
+
});
|
|
1474
|
+
return structuredClone(value);
|
|
1475
|
+
}
|
|
1476
|
+
return this.token(value, trail, scope);
|
|
1477
|
+
}
|
|
1478
|
+
const out = {};
|
|
1479
|
+
for (const [key, child] of Object.entries(value)) {
|
|
1480
|
+
if (this.self && trail.length === 0 && key === "children") {
|
|
1481
|
+
out[key] = child;
|
|
1482
|
+
continue;
|
|
1483
|
+
}
|
|
1484
|
+
const resolved = this.value(child, [...trail, key], scope);
|
|
1485
|
+
if (resolved !== OMIT) out[key] = resolved;
|
|
1486
|
+
}
|
|
1487
|
+
return out;
|
|
1488
|
+
}
|
|
1489
|
+
token(token, trail, scope = []) {
|
|
1490
|
+
if (!tokenSchema.safeParse(token).success) this.fail(trail, `is a malformed token: ${JSON.stringify(token)}.`, scope);
|
|
1491
|
+
switch (tokenKeyOf(token)) {
|
|
1492
|
+
case "$output": return this.output(token, trail, scope);
|
|
1493
|
+
case "$env": return this.env(token.$env, trail, scope);
|
|
1494
|
+
case "$concat": return this.concat(token.$concat, trail, scope);
|
|
1495
|
+
case "$map": return this.map(token.$map, trail, scope);
|
|
1496
|
+
case "$item": return this.item(token.$item, trail, scope);
|
|
1497
|
+
case "$key": return this.key(token.$key, trail, scope);
|
|
1498
|
+
default: return this.fail(trail, `is not a token.`, scope);
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
/** The binding an `$item`/`$key` names: the innermost map, or the
|
|
1502
|
+
* enclosing map whose `as` is `name`. */
|
|
1503
|
+
binding(name, operator, trail, scope) {
|
|
1504
|
+
if (scope.length === 0) return this.fail(trail, `uses ${operator} outside any $map; ${operator} reads the element a $map template is rendering.`);
|
|
1505
|
+
if (name === void 0) return scope[scope.length - 1];
|
|
1506
|
+
for (let i = scope.length - 1; i >= 0; i--) if (scope[i].as === name) return scope[i];
|
|
1507
|
+
const named = scope.flatMap((b) => b.as ? [`"${b.as}"`] : []);
|
|
1508
|
+
return this.fail(trail, `uses ${operator} with binding "${name}", which no enclosing $map declares (as: ${named.join(", ") || "none"}).`, scope);
|
|
1509
|
+
}
|
|
1510
|
+
map(operand, trail, scope) {
|
|
1511
|
+
if (!isPlainObject(operand)) return this.fail(trail, "is a malformed $map token.", scope);
|
|
1512
|
+
const into = operand.into === "record";
|
|
1513
|
+
const as = typeof operand.as === "string" ? operand.as : void 0;
|
|
1514
|
+
const read = this.readWithSchema(operand.over, [
|
|
1515
|
+
...trail,
|
|
1516
|
+
"$map",
|
|
1517
|
+
"over"
|
|
1518
|
+
], scope);
|
|
1519
|
+
const over = read.value;
|
|
1520
|
+
if (over === OMIT) return OMIT;
|
|
1521
|
+
const element = read.schema === void 0 ? void 0 : elementSchemaOf(read.schema);
|
|
1522
|
+
const render = (key, item) => {
|
|
1523
|
+
const inner = [...scope, {
|
|
1524
|
+
path: trail,
|
|
1525
|
+
key,
|
|
1526
|
+
item,
|
|
1527
|
+
...as !== void 0 ? { as } : {},
|
|
1528
|
+
...element !== void 0 ? { schema: element } : {}
|
|
1529
|
+
}];
|
|
1530
|
+
const at = [
|
|
1531
|
+
...trail,
|
|
1532
|
+
"$map",
|
|
1533
|
+
"to"
|
|
1534
|
+
];
|
|
1535
|
+
const out = this.value(operand.to, at, inner);
|
|
1536
|
+
if (out === OMIT) return this.fail(at, `is ${this.omitted} as the whole $map template; there is no property to omit.`, inner);
|
|
1537
|
+
return out;
|
|
1538
|
+
};
|
|
1539
|
+
if (Array.isArray(over)) {
|
|
1540
|
+
if (into) return this.fail(trail, `is a $map with into: "record", but its over (${describeToken(operand.over)}) resolved to an array, which has no keys to keep. Drop into: "record" (the result is an array) or map over a record.`, scope);
|
|
1541
|
+
const rendered = over.map((item, index) => render(index, item));
|
|
1542
|
+
renderedKeys.set(rendered, over.map((_, index) => index));
|
|
1543
|
+
return rendered;
|
|
1544
|
+
}
|
|
1545
|
+
if (isPlainObject(over)) {
|
|
1546
|
+
const keys = Object.keys(over).sort();
|
|
1547
|
+
if (!into) {
|
|
1548
|
+
const rendered = keys.map((key) => render(key, over[key]));
|
|
1549
|
+
renderedKeys.set(rendered, keys);
|
|
1550
|
+
return rendered;
|
|
1551
|
+
}
|
|
1552
|
+
const out = {};
|
|
1553
|
+
for (const key of keys) out[key] = render(key, over[key]);
|
|
1554
|
+
return out;
|
|
1555
|
+
}
|
|
1556
|
+
return this.fail(trail, `is a $map whose over (${describeToken(operand.over)}) resolved to ${JSON.stringify(over)}${into ? `; into: "record" needs a record` : ", which is not an array or a record"}.`, scope);
|
|
1557
|
+
}
|
|
1558
|
+
item(operand, trail, scope) {
|
|
1559
|
+
return this.readItem(operand, trail, scope).value;
|
|
1560
|
+
}
|
|
1561
|
+
/** A `$map`'s `over` with the schema describing it, when it reads a
|
|
1562
|
+
* schema'd `$output` (or an `$item` of a schema'd element). */
|
|
1563
|
+
readWithSchema(value, trail, scope) {
|
|
1564
|
+
const key = tokenKeyOf(value);
|
|
1565
|
+
if (isPlainObject(value) && (key === "$output" || key === "$item") && tokenSchema.safeParse(value).success) return key === "$output" ? this.readOutput(value, trail, scope) : this.readItem(value.$item, trail, scope);
|
|
1566
|
+
return { value: this.value(value, trail, scope) };
|
|
1567
|
+
}
|
|
1568
|
+
omit(what) {
|
|
1569
|
+
this.omitted = what;
|
|
1570
|
+
return { value: OMIT };
|
|
1571
|
+
}
|
|
1572
|
+
readItem(operand, trail, scope) {
|
|
1573
|
+
const named = isPlainObject(operand) ? operand : void 0;
|
|
1574
|
+
const name = named && typeof named.as === "string" ? named.as : void 0;
|
|
1575
|
+
const raw = named ? named.path : operand;
|
|
1576
|
+
const path = pathSegments(Array.isArray(raw) ? raw : []);
|
|
1577
|
+
const binding = this.binding(name, "$item", trail, scope);
|
|
1578
|
+
const hit = walkPath(binding.item, path);
|
|
1579
|
+
if (!hit.ok) {
|
|
1580
|
+
if (binding.schema !== void 0 && isOptionalField(binding.schema, path, hit.at)) return this.omit("an absent optional $item field");
|
|
1581
|
+
const missing = formatPath(path.slice(0, hit.at + 1));
|
|
1582
|
+
return this.fail(trail, `reads $item ${formatPath(path)}, but $map element ${elementText(binding)} has no ${missing} (it has: ${hit.has}).`, scope);
|
|
1583
|
+
}
|
|
1584
|
+
return {
|
|
1585
|
+
value: structuredClone(hit.value),
|
|
1586
|
+
schema: schemaOf(binding.schema, path)
|
|
1587
|
+
};
|
|
1588
|
+
}
|
|
1589
|
+
key(operand, trail, scope) {
|
|
1590
|
+
const name = typeof operand === "string" ? operand : void 0;
|
|
1591
|
+
return this.binding(name, "$key", trail, scope).key;
|
|
1592
|
+
}
|
|
1593
|
+
output(token, trail, scope = []) {
|
|
1594
|
+
return this.readOutput(token, trail, scope).value;
|
|
1595
|
+
}
|
|
1596
|
+
readOutput(token, trail, scope) {
|
|
1597
|
+
const operand = token.$output;
|
|
1598
|
+
if (!isPlainObject(operand) || typeof operand.host !== "string") return this.fail(trail, "is a malformed $output token.", scope);
|
|
1599
|
+
const ref = typeof operand.member === "string" ? {
|
|
1600
|
+
host: operand.host,
|
|
1601
|
+
member: operand.member
|
|
1602
|
+
} : { host: operand.host };
|
|
1603
|
+
const path = pathSegments(Array.isArray(operand.path) ? operand.path : []);
|
|
1604
|
+
if (!this.sources.outputs) return this.fail(trail, `reads ${describeToken(token)}, but no outputs are available here.`, scope);
|
|
1605
|
+
const lookup = this.sources.outputs.lookup(ref);
|
|
1606
|
+
if (lookup.status === "unavailable") throw new TokenResolutionError(`${this.sources.where ? `${this.sources.where}: ` : ""}${lookup.message}\n (needed by \`${formatPath(trail)}\`: ${describeToken(token)})`);
|
|
1607
|
+
const hit = walkPath(lookup.outputs, path);
|
|
1608
|
+
if (!hit.ok) {
|
|
1609
|
+
if (lookup.schema !== void 0 && isOptionalField(lookup.schema, path, hit.at)) return this.omit("an absent optional output");
|
|
1610
|
+
const parent = path.slice(0, hit.at);
|
|
1611
|
+
const container = parent.length ? `outputs.${formatPath(parent)}` : "its outputs";
|
|
1612
|
+
const missing = formatPath(path.slice(0, hit.at + 1));
|
|
1613
|
+
return this.fail(trail, `reads ${describeToken(token)}, but host "${ref.host}" has no output at ${missing} (${container} has: ${hit.has}).`, scope);
|
|
1614
|
+
}
|
|
1615
|
+
return {
|
|
1616
|
+
value: structuredClone(hit.value),
|
|
1617
|
+
schema: schemaOf(lookup.schema, path)
|
|
1618
|
+
};
|
|
1619
|
+
}
|
|
1620
|
+
env(operand, trail, scope = []) {
|
|
1621
|
+
const optional = isPlainObject(operand);
|
|
1622
|
+
const name = optional ? operand.name : operand;
|
|
1623
|
+
if (typeof name !== "string") return this.fail(trail, "is a malformed $env token.", scope);
|
|
1624
|
+
const builtins = this.sources.builtins;
|
|
1625
|
+
if ((name === "userData" || name === "projectRoot") && builtins?.[name]) return builtins[name];
|
|
1626
|
+
const value = this.sources.env?.[name];
|
|
1627
|
+
if (value !== void 0) return value;
|
|
1628
|
+
if (optional) return this.omit("an optional $env").value;
|
|
1629
|
+
return this.fail(trail, `reads $env ${name}, which is not set. Set ${name} in the environment of the process that resolves this host (or declare { $env: { name: "${name}", optional: true } } to omit the property when unset).`, scope);
|
|
1630
|
+
}
|
|
1631
|
+
concat(parts, trail, scope = []) {
|
|
1632
|
+
if (!Array.isArray(parts)) return this.fail(trail, "is a malformed $concat token.", scope);
|
|
1633
|
+
return parts.map((part, index) => {
|
|
1634
|
+
const at = [
|
|
1635
|
+
...trail,
|
|
1636
|
+
"$concat",
|
|
1637
|
+
index
|
|
1638
|
+
];
|
|
1639
|
+
const value = this.value(part, at, scope);
|
|
1640
|
+
if (value === OMIT) return this.fail(at, `is ${this.omitted} inside $concat.`, scope);
|
|
1641
|
+
if (typeof value === "string") return value;
|
|
1642
|
+
if (typeof value === "number") return String(value);
|
|
1643
|
+
return this.fail(at, `resolved to ${JSON.stringify(value)}; every $concat part must be a string or a number.`, scope);
|
|
1644
|
+
}).join("");
|
|
1645
|
+
}
|
|
1646
|
+
};
|
|
1647
|
+
function resolveHostOutputs(host, sources, options) {
|
|
1648
|
+
const resolver = new Resolver(sources, options?.deferSelf);
|
|
1649
|
+
const out = resolver.value(host, []);
|
|
1650
|
+
if (out === OMIT) resolver.fail([], `is ${resolver.omitted} with nothing to omit it from.`);
|
|
1651
|
+
const partial = out;
|
|
1652
|
+
if (!options) return partial;
|
|
1653
|
+
const sites = resolver.deferred;
|
|
1654
|
+
return {
|
|
1655
|
+
host: partial,
|
|
1656
|
+
deferred: sites.map((d) => ({
|
|
1657
|
+
path: formatPath(d.trail),
|
|
1658
|
+
members: d.members
|
|
1659
|
+
})),
|
|
1660
|
+
needs: [...new Set(sites.flatMap((d) => d.members))],
|
|
1661
|
+
finish(outputs) {
|
|
1662
|
+
const done = cloneWithProvenance(partial);
|
|
1663
|
+
const late = new Resolver({
|
|
1664
|
+
...sources,
|
|
1665
|
+
outputs
|
|
1666
|
+
});
|
|
1667
|
+
for (const site of sites) {
|
|
1668
|
+
const value = late.token(site.token, site.trail);
|
|
1669
|
+
if (value === OMIT && typeof site.trail.at(-1) === "number") late.fail(site.trail, `is ${late.omitted} inside an array.`);
|
|
1670
|
+
setAt(done, site.trail, value === OMIT ? void 0 : value, value === OMIT);
|
|
1671
|
+
}
|
|
1672
|
+
return done;
|
|
1673
|
+
}
|
|
1674
|
+
};
|
|
1675
|
+
}
|
|
1676
|
+
function setAt(root, trail, value, omit) {
|
|
1677
|
+
let current = root;
|
|
1678
|
+
for (const key of trail.slice(0, -1)) if (Array.isArray(current) && typeof key === "number") current = current[key];
|
|
1679
|
+
else if (isPlainObject(current) && typeof key === "string") current = current[key];
|
|
1680
|
+
else return;
|
|
1681
|
+
const last = trail[trail.length - 1];
|
|
1682
|
+
if (Array.isArray(current) && typeof last === "number") current[last] = value;
|
|
1683
|
+
else if (isPlainObject(current) && typeof last === "string") {
|
|
1684
|
+
if (omit) delete current[last];
|
|
1685
|
+
else current[last] = value;
|
|
1686
|
+
}
|
|
1687
|
+
}
|
|
1688
|
+
/**
|
|
1689
|
+
* Resolves a host's `runner.module` specifier from the PROJECT's dependency
|
|
1690
|
+
* tree (not ph-cli's), imports it, and checks the runner-module contract:
|
|
1691
|
+
* `{ run, hostSchema, kind, outputsSchema?, verbs?, ...optionalVerbs }`.
|
|
1692
|
+
*/
|
|
1693
|
+
var RunnerError = class extends Error {
|
|
1694
|
+
constructor(message, hint) {
|
|
1695
|
+
super(hint ? `${message}\n Hint: ${hint}` : message);
|
|
1696
|
+
this.name = "RunnerError";
|
|
1697
|
+
}
|
|
1698
|
+
};
|
|
1699
|
+
/** Whether a value is zod-shaped (has a `safeParse` function): a runner's
|
|
1700
|
+
* `outputsSchema`, a plugin's config schema. */
|
|
1701
|
+
function isSchemaLike(value) {
|
|
1702
|
+
return typeof value === "object" && value !== null && "safeParse" in value && typeof value.safeParse === "function";
|
|
1703
|
+
}
|
|
1704
|
+
/** The Connect runner's specifier: compounds forward `cspRegistrySync` to
|
|
1705
|
+
* it, and `--explain` prints its dead-config warnings. */
|
|
1706
|
+
const CONNECT_RUNNER = "@powerhousedao/ph-cli/runners/connect";
|
|
1707
|
+
/** Exports that are part of the contract but are not verbs. */
|
|
1708
|
+
const NON_VERB_EXPORTS = /* @__PURE__ */ new Set([
|
|
1709
|
+
"hostSchema",
|
|
1710
|
+
"declaredHostSchema",
|
|
1711
|
+
"outputsSchema",
|
|
1712
|
+
"verbs",
|
|
1713
|
+
"kind",
|
|
1714
|
+
"default"
|
|
1715
|
+
]);
|
|
1716
|
+
async function resolveRunnerModule(projectRoot, specifier) {
|
|
1717
|
+
const projectRequire = createRequire(pathToFileURL(path.join(projectRoot, "package.json")).href);
|
|
1718
|
+
let resolved;
|
|
1719
|
+
try {
|
|
1720
|
+
resolved = projectRequire.resolve(specifier);
|
|
1721
|
+
} catch {
|
|
1722
|
+
throw new RunnerError(`Cannot resolve runner module "${specifier}" from ${projectRoot}.`, "The runner must be a dependency of the project (install it, then retry).");
|
|
1723
|
+
}
|
|
1724
|
+
const module = await import(pathToFileURL(resolved).href);
|
|
1725
|
+
if (typeof module.run !== "function") throw new RunnerError(`Runner "${specifier}" does not export a \`run\` function (required verb).`);
|
|
1726
|
+
const hostSchema = module.hostSchema;
|
|
1727
|
+
if (!hostSchema || typeof hostSchema.safeParse !== "function") throw new RunnerError(`Runner "${specifier}" does not export a \`hostSchema\` — runners validate their own host shape.`);
|
|
1728
|
+
const declared = module.declaredHostSchema;
|
|
1729
|
+
if (declared !== void 0 && typeof declared.safeParse !== "function") throw new RunnerError(`Runner "${specifier}" exports a \`declaredHostSchema\` without safeParse.`);
|
|
1730
|
+
const verbs = module.verbs;
|
|
1731
|
+
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.`);
|
|
1732
|
+
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").`);
|
|
1733
|
+
return module;
|
|
1734
|
+
}
|
|
1735
|
+
/** Verbs that produce something and start nothing (`build`): no outputs, no
|
|
1736
|
+
* record, no lock — and no token resolution, since what they read (output
|
|
1737
|
+
* dirs, packages) never comes from another host's outputs. Their verb gets
|
|
1738
|
+
* the declared host (tokens may remain in token-able fields). */
|
|
1739
|
+
const ONE_SHOT_VERBS = /* @__PURE__ */ new Set(["build"]);
|
|
1740
|
+
function listVerbs(runner) {
|
|
1741
|
+
if (runner.verbs) return runner.verbs.filter((name) => typeof runner[name] === "function").toSorted();
|
|
1742
|
+
return Object.entries(runner).filter(([name, value]) => typeof value === "function" && !NON_VERB_EXPORTS.has(name)).map(([name]) => name).sort();
|
|
1743
|
+
}
|
|
1744
|
+
function getVerb(runner, specifier, verb) {
|
|
1745
|
+
const candidate = runner[verb];
|
|
1746
|
+
if (typeof candidate !== "function" || !listVerbs(runner).includes(verb)) throw new RunnerError(`Runner "${specifier}" does not support the verb "${verb}". Supported verbs: ${listVerbs(runner).join(", ")}.`);
|
|
1747
|
+
return candidate;
|
|
1748
|
+
}
|
|
1749
|
+
function isRecord$2(value) {
|
|
1750
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1751
|
+
}
|
|
1752
|
+
/** reactor XOR children, decided by the runner's declared `kind`. */
|
|
1753
|
+
function assertKindShape(kind, specifier, host, file) {
|
|
1754
|
+
if (kind === "reactor" && host.children !== void 0) throw new RunnerError(`${file}: "${specifier}" is a reactor runner, so the host must not declare \`children\`.`, "`children` belongs to compound hosts; a reactor host configures its own `reactor` block.");
|
|
1755
|
+
if (kind === "compound" && host.reactor !== void 0) throw new RunnerError(`${file}: "${specifier}" is a compound runner, so the host must not declare \`reactor\`.`, "A compound's reactors are its members': configure them in the member host or a wrapper's `reactor` override.");
|
|
1756
|
+
}
|
|
1757
|
+
/** `runner.defaultVerb` and every plugin entry's `verbs` must name verbs
|
|
1758
|
+
* this runner exports. */
|
|
1759
|
+
function assertKnownVerbs(runner, specifier, host, file) {
|
|
1760
|
+
const options = host.runner;
|
|
1761
|
+
if (!isRecord$2(options)) return;
|
|
1762
|
+
const verbs = listVerbs(runner);
|
|
1763
|
+
const unknownVerb = (verb) => typeof verb === "string" && !verbs.includes(verb);
|
|
1764
|
+
if (unknownVerb(options.defaultVerb)) throw new RunnerError(`${file}: runner.defaultVerb "${options.defaultVerb}" is not a verb of "${specifier}". Supported verbs: ${verbs.join(", ")}.`);
|
|
1765
|
+
const plugins = Array.isArray(options.plugins) ? options.plugins : [];
|
|
1766
|
+
for (const entry of plugins) {
|
|
1767
|
+
if (!isRecord$2(entry) || !Array.isArray(entry.verbs)) continue;
|
|
1768
|
+
const bad = entry.verbs.find(unknownVerb);
|
|
1769
|
+
if (bad !== void 0) throw new RunnerError(`${file}: plugin "${String(entry.module)}" is scoped to verb "${bad}", which "${specifier}" does not export. Supported verbs: ${verbs.join(", ")}.`);
|
|
1770
|
+
}
|
|
1771
|
+
}
|
|
1772
|
+
function formatIssues(issues) {
|
|
1773
|
+
return issues.map((i) => ` - ${i.path}: ${i.message}`).join("\n");
|
|
1774
|
+
}
|
|
1775
|
+
function valueAt(host, path) {
|
|
1776
|
+
let current = host;
|
|
1777
|
+
for (const key of path) if (Array.isArray(current) && typeof key === "number") current = current[key];
|
|
1778
|
+
else if (isRecord$2(current) && typeof key === "string") current = current[key];
|
|
1779
|
+
else return;
|
|
1780
|
+
return current;
|
|
1781
|
+
}
|
|
1782
|
+
/**
|
|
1783
|
+
* Resolved validation (pipeline step 6): validate a RESOLVED host against
|
|
1784
|
+
* its runner's `hostSchema` and return the PARSED host (what the verb
|
|
1785
|
+
* receives). Run `resolveHostOutputs` first; a token still present fails
|
|
1786
|
+
* with its path.
|
|
1787
|
+
*/
|
|
1788
|
+
function validateHost(runner, specifier, host, file, options = {}) {
|
|
1789
|
+
return parseHost(runner, options.tokens === "allow" ? runner.declaredHostSchema ?? runner.hostSchema : runner.hostSchema, specifier, host, file, options);
|
|
1790
|
+
}
|
|
1791
|
+
function parseHost(runner, schema, specifier, host, file, options) {
|
|
1792
|
+
if (isRecord$2(host)) {
|
|
1793
|
+
assertKindShape(runner.kind, specifier, host, file);
|
|
1794
|
+
if (options.tokens !== "allow") {
|
|
1795
|
+
const token = findToken(host);
|
|
1796
|
+
if (token) throw new RunnerError(`${file}: \`${token.path}\` is an unresolved output token (${token.key}).`, "Resolve the host (resolveHostOutputs) before validating it for a verb; `ph run` does this.");
|
|
1797
|
+
}
|
|
1798
|
+
assertKnownVerbs(runner, specifier, host, file);
|
|
1799
|
+
}
|
|
1800
|
+
const result = schema.safeParse(unwrapEscapes(host));
|
|
1801
|
+
if (!result.success) throw new RunnerError(`${file} failed validation against the hostSchema of "${specifier}":\n${result.error.issues.map((issue) => {
|
|
1802
|
+
const element = describeMapElements(host, issue.path);
|
|
1803
|
+
return ` - ${(issue.path.map(String).join(".") || "<root>") + (element ? ` (${element})` : "")}: ${tokenKeyOf(valueAt(host, issue.path)) ? "this field does not take an output token (it is not token-able); spell the value literally." : issue.message}`;
|
|
1804
|
+
}).join("\n") || " (no details reported)"}`);
|
|
1805
|
+
return result.data;
|
|
1806
|
+
}
|
|
1807
|
+
/**
|
|
1808
|
+
* Declared validation (pipeline step 3): the removed cross-host forms
|
|
1809
|
+
* (each error names its token form), token shapes and `$env` `optional`
|
|
1810
|
+
* placement, `$output` paths against the producers' `outputsSchema`s, then
|
|
1811
|
+
* the runner's `declaredHostSchema` (tokens allowed in token-able fields).
|
|
1812
|
+
* Reads no environment value and needs no producer running. Throws on the
|
|
1813
|
+
* first failing stage; resolve, then `validateHost`, before a verb runs.
|
|
1814
|
+
*/
|
|
1815
|
+
function validateDeclaredHost(runner, specifier, host, file, options = {}) {
|
|
1816
|
+
const removed = findRemovedForms(host);
|
|
1817
|
+
if (removed.length > 0) throw new RunnerError(`${file}: removed form:\n${formatIssues(removed)}`);
|
|
1818
|
+
const issues = checkTokenSites(host);
|
|
1819
|
+
if (options.outputsSchemaOf) issues.push(...checkOutputPaths(host, options.outputsSchemaOf));
|
|
1820
|
+
if (issues.length > 0) throw new RunnerError(`${file}: invalid output token:\n${formatIssues(issues)}`);
|
|
1821
|
+
if (isRecord$2(host)) assertKindShape(runner.kind, specifier, host, file);
|
|
1822
|
+
if (!runner.declaredHostSchema) return;
|
|
1823
|
+
parseHost(runner, runner.declaredHostSchema, specifier, host, file, { tokens: "allow" });
|
|
1824
|
+
}
|
|
1825
|
+
/**
|
|
1826
|
+
* Loads and pre-validates a `hosts/<name>/host.js` definition.
|
|
1827
|
+
*
|
|
1828
|
+
* A host file is a static PROJECTION of powerhouse.config.json: plain ESM,
|
|
1829
|
+
* default-exporting a data object. Three gates run before any runner sees it:
|
|
1830
|
+
* 1. import lint — the only legal imports are the project's
|
|
1831
|
+
* powerhouse.config.json, sibling `../<host>/host.js` files and sibling
|
|
1832
|
+
* generated `../<host>/outputs.js` token trees (host files are data, not
|
|
1833
|
+
* programs; `process.` is banned, environment values go through `$env`).
|
|
1834
|
+
* An imported outputs.js whose schema hash no longer matches its
|
|
1835
|
+
* producer fails here ("run `ph generate hosts`");
|
|
1836
|
+
* 2. static check — the exported object must survive a JSON round trip
|
|
1837
|
+
* (functions, undefined, class instances, Dates etc. are rejected,
|
|
1838
|
+
* reporting the offending path);
|
|
1839
|
+
* 3. shape pre-check — `name`, `runner.module`, and the reactor XOR children
|
|
1840
|
+
* rule. Full validation is the runner's `hostSchema` (phase 2).
|
|
1841
|
+
*
|
|
1842
|
+
* This module never exits the process — callers own error presentation.
|
|
1843
|
+
*/
|
|
1844
|
+
const HOST_FILE = "host.js";
|
|
1845
|
+
const CONFIG_IMPORT_SUFFIX = "powerhouse.config.json";
|
|
1846
|
+
var HostLoadError = class extends Error {
|
|
1847
|
+
constructor(message, hint) {
|
|
1848
|
+
super(hint ? `${message}\n Hint: ${hint}` : message);
|
|
1849
|
+
this.name = "HostLoadError";
|
|
1850
|
+
}
|
|
1851
|
+
};
|
|
1852
|
+
/** A `hosts/` folder with no `<name>/host.js` inside is "empty" — the guard
|
|
1853
|
+
* state: callers warn loudly and fall back to legacy rather than activating
|
|
1854
|
+
* the new architecture off a stray `mkdir hosts`. */
|
|
1855
|
+
function probeHostsFolder(projectRoot) {
|
|
1856
|
+
const dir = path.join(projectRoot, "hosts");
|
|
1857
|
+
if (!existsSync(dir) || !statSync(dir).isDirectory()) return { kind: "absent" };
|
|
1858
|
+
const hosts = readdirSync(dir, { withFileTypes: true }).filter((entry) => entry.isDirectory() && existsSync(path.join(dir, entry.name, HOST_FILE))).map((entry) => entry.name).sort();
|
|
1859
|
+
return hosts.length === 0 ? {
|
|
1860
|
+
kind: "empty",
|
|
1861
|
+
dir
|
|
1862
|
+
} : {
|
|
1863
|
+
kind: "present",
|
|
1864
|
+
dir,
|
|
1865
|
+
hosts
|
|
1866
|
+
};
|
|
1867
|
+
}
|
|
1868
|
+
/** Sibling imports: `../<host>/host.js` — source material for derived
|
|
1869
|
+
* compositions (full-inclusion wrappers compute over them with plain JS) —
|
|
1870
|
+
* and `../<host>/outputs.js`, the generated `$output` token tree. */
|
|
1871
|
+
const SIBLING_IMPORT = /^\.\.\/([A-Za-z0-9_-]+)\/(host\.js|outputs\.js)$/;
|
|
1872
|
+
/** The generated per-host token tree (`ph generate hosts`). */
|
|
1873
|
+
const OUTPUTS_FILE = "outputs.js";
|
|
1874
|
+
const GENERATE_HINT = "Run `ph generate hosts` to (re)generate hosts/<name>/outputs.js from the producer's runner outputsSchema and declared drives.";
|
|
1875
|
+
/**
|
|
1876
|
+
* One pass over JS source that blanks every comment and, with
|
|
1877
|
+
* `literals: "blank"`, the CONTENTS of string literals and template-literal
|
|
1878
|
+
* text (quotes, backticks and `${`/`}` kept). A template's `${…}` holes are
|
|
1879
|
+
* code: they are scanned like the rest (strings, nested templates and braces
|
|
1880
|
+
* inside them included). Every newline survives, so line-anchored checks and
|
|
1881
|
+
* line numbers still match the original source. Regex literals are not
|
|
1882
|
+
* recognised (host files are data; a regex is not one).
|
|
1883
|
+
*/
|
|
1884
|
+
function scanSource(source, literals) {
|
|
1885
|
+
const blank = (text) => text.replace(/[^\n]/g, " ");
|
|
1886
|
+
const literal = (text) => literals === "blank" ? blank(text) : text;
|
|
1887
|
+
let out = "";
|
|
1888
|
+
let i = 0;
|
|
1889
|
+
const holes = [];
|
|
1890
|
+
/** Template text from `i` (just after a backtick or a hole's `}`) up to
|
|
1891
|
+
* and including its closing backtick, or up to and including the next
|
|
1892
|
+
* `${` (pushing a hole). */
|
|
1893
|
+
const templateText = () => {
|
|
1894
|
+
let j = i;
|
|
1895
|
+
while (j < source.length) {
|
|
1896
|
+
const ch = source[j];
|
|
1897
|
+
if (ch === "\\") {
|
|
1898
|
+
j += 2;
|
|
1899
|
+
continue;
|
|
1900
|
+
}
|
|
1901
|
+
if (ch === "`") break;
|
|
1902
|
+
if (ch === "$" && source[j + 1] === "{") break;
|
|
1903
|
+
j++;
|
|
1904
|
+
}
|
|
1905
|
+
out += literal(source.slice(i, Math.min(j, source.length)));
|
|
1906
|
+
if (j >= source.length) i = source.length;
|
|
1907
|
+
else if (source[j] === "`") {
|
|
1908
|
+
out += "`";
|
|
1909
|
+
i = j + 1;
|
|
1910
|
+
} else {
|
|
1911
|
+
out += "${";
|
|
1912
|
+
holes.push(0);
|
|
1913
|
+
i = j + 2;
|
|
1914
|
+
}
|
|
1915
|
+
};
|
|
1916
|
+
while (i < source.length) {
|
|
1917
|
+
const ch = source[i];
|
|
1918
|
+
const next = source[i + 1];
|
|
1919
|
+
if (ch === "/" && next === "/") {
|
|
1920
|
+
const end = source.indexOf("\n", i);
|
|
1921
|
+
const stop = end === -1 ? source.length : end;
|
|
1922
|
+
out += blank(source.slice(i, stop));
|
|
1923
|
+
i = stop;
|
|
1924
|
+
continue;
|
|
1925
|
+
}
|
|
1926
|
+
if (ch === "/" && next === "*") {
|
|
1927
|
+
const end = source.indexOf("*/", i + 2);
|
|
1928
|
+
const stop = end === -1 ? source.length : end + 2;
|
|
1929
|
+
out += blank(source.slice(i, stop));
|
|
1930
|
+
i = stop;
|
|
1931
|
+
continue;
|
|
1932
|
+
}
|
|
1933
|
+
if (ch === "\"" || ch === "'") {
|
|
1934
|
+
let j = i + 1;
|
|
1935
|
+
while (j < source.length && source[j] !== ch && source[j] !== "\n") j += source[j] === "\\" ? 2 : 1;
|
|
1936
|
+
const close = source[j] === ch ? ch : "";
|
|
1937
|
+
out += ch + literal(source.slice(i + 1, Math.min(j, source.length)));
|
|
1938
|
+
out += close;
|
|
1939
|
+
i = close ? j + 1 : j;
|
|
1940
|
+
continue;
|
|
1941
|
+
}
|
|
1942
|
+
if (ch === "`") {
|
|
1943
|
+
out += "`";
|
|
1944
|
+
i++;
|
|
1945
|
+
templateText();
|
|
1946
|
+
continue;
|
|
1947
|
+
}
|
|
1948
|
+
if (holes.length > 0 && ch === "{") holes[holes.length - 1]++;
|
|
1949
|
+
if (holes.length > 0 && ch === "}") {
|
|
1950
|
+
if (holes[holes.length - 1] === 0) {
|
|
1951
|
+
holes.pop();
|
|
1952
|
+
out += "}";
|
|
1953
|
+
i++;
|
|
1954
|
+
templateText();
|
|
1955
|
+
continue;
|
|
1956
|
+
}
|
|
1957
|
+
holes[holes.length - 1]--;
|
|
1958
|
+
}
|
|
1959
|
+
out += ch;
|
|
1960
|
+
i++;
|
|
1961
|
+
}
|
|
1962
|
+
return out;
|
|
1963
|
+
}
|
|
1964
|
+
/** Blank out `//` and block comments, keeping string and template literals
|
|
1965
|
+
* (URLs contain `//`) and every newline, so line-anchored checks still see
|
|
1966
|
+
* the code's own lines. A JSDoc `import("…")` type is a comment, not code. */
|
|
1967
|
+
function stripComments(source) {
|
|
1968
|
+
return scanSource(source, "keep");
|
|
1969
|
+
}
|
|
1970
|
+
/** Blank out comments and the contents of string literals and
|
|
1971
|
+
* template-literal text, so a word inside a string (a URL, a description,
|
|
1972
|
+
* an apostrophe in template text) is neither mistaken for code nor able to
|
|
1973
|
+
* hide code. Template `${…}` holes are code and are kept. */
|
|
1974
|
+
function blankLiterals(source) {
|
|
1975
|
+
return scanSource(source, "blank");
|
|
1976
|
+
}
|
|
1977
|
+
const PROCESS_ACCESS = /(?<![.\w$])process\s*(?:\?\.|\.|\[)/;
|
|
1978
|
+
/** Host files and generated outputs.js are data: reading the environment
|
|
1979
|
+
* through `process.` is banned (typed-host-configs decision 9). Environment
|
|
1980
|
+
* values go through `$env`, which resolves at start in the resolving
|
|
1981
|
+
* process. Comments are already stripped, so a mention there is fine. */
|
|
1982
|
+
function rejectProcessAccess(source, file) {
|
|
1983
|
+
const match = PROCESS_ACCESS.exec(blankLiterals(source));
|
|
1984
|
+
if (!match) return;
|
|
1985
|
+
const line = source.slice(0, match.index).split("\n").length;
|
|
1986
|
+
throw new HostLoadError(`${file}:${line} reads \`process.\` — host files cannot read the environment directly.`, "Use an $env token instead: { $env: \"NAME\" } (fails when unset), or { $env: { name: \"NAME\", optional: true } } as a property value to omit the property when unset. It resolves when the host starts.");
|
|
1987
|
+
}
|
|
1988
|
+
/** Lints a host file and returns what it imports. Rejects every import
|
|
1989
|
+
* except the project's powerhouse.config.json, SIBLING host files (R1:
|
|
1990
|
+
* derived compositions) and sibling generated outputs.js token trees; any
|
|
1991
|
+
* dynamic `import(...)` or `require(...)`; and any `process.` access.
|
|
1992
|
+
* Source-level enforcement: the JSON round trip below is the hard gate; this
|
|
1993
|
+
* one produces the better error. */
|
|
1994
|
+
function scanHostImports(rawSource, file) {
|
|
1995
|
+
const source = stripComments(rawSource);
|
|
1996
|
+
const imports = {
|
|
1997
|
+
hosts: [],
|
|
1998
|
+
outputs: []
|
|
1999
|
+
};
|
|
2000
|
+
for (const match of source.matchAll(/^\s*import\b[^;'"]*?from\s+["']([^"']+)["']/gm)) {
|
|
2001
|
+
const specifier = match[1];
|
|
2002
|
+
if (specifier.endsWith(CONFIG_IMPORT_SUFFIX)) continue;
|
|
2003
|
+
const sibling = SIBLING_IMPORT.exec(specifier);
|
|
2004
|
+
if (sibling) {
|
|
2005
|
+
(sibling[2] === HOST_FILE ? imports.hosts : imports.outputs).push(sibling[1]);
|
|
2006
|
+
continue;
|
|
2007
|
+
}
|
|
2008
|
+
throw new HostLoadError(`${file} imports "${specifier}" — a host file may only import the project's powerhouse.config.json, sibling hosts/<name>/host.js files or generated hosts/<name>/${OUTPUTS_FILE} token trees.`, "Host files are static projections; code belongs in plugins or the runner.");
|
|
2009
|
+
}
|
|
2010
|
+
if (/^\s*import\s+["']/m.test(source)) throw new HostLoadError(`${file} contains a side-effect import — a host file may only import the project's powerhouse.config.json or sibling host files.`);
|
|
2011
|
+
if (/\bimport\s*\(/.test(source) || /\brequire\s*\(/.test(source)) throw new HostLoadError(`${file} uses dynamic import()/require() — host files are static data.`);
|
|
2012
|
+
rejectProcessAccess(source, file);
|
|
2013
|
+
return imports;
|
|
2014
|
+
}
|
|
2015
|
+
/** A generated `outputs.js` is plain data: no imports of any kind, no
|
|
2016
|
+
* dynamic import/require, no `process.`. */
|
|
2017
|
+
function lintOutputsFile(rawSource, file) {
|
|
2018
|
+
const source = stripComments(rawSource);
|
|
2019
|
+
if (/^\s*import\b/m.test(source) || /^\s*export\b[^;]*?\bfrom\s+["']/m.test(source) || /\bimport\s*\(/.test(source) || /\brequire\s*\(/.test(source)) throw new HostLoadError(`${file} imports a module — a generated ${OUTPUTS_FILE} is plain data.`, "Regenerate it with `ph generate hosts` instead of editing it.");
|
|
2020
|
+
rejectProcessAccess(source, file);
|
|
2021
|
+
}
|
|
2022
|
+
/** Walks the sibling-import graph from `hostName`, linting every visited file
|
|
2023
|
+
* (and every outputs.js it imports) and failing on a cycle (an ESM circular
|
|
2024
|
+
* would otherwise surface as an undefined default export with no useful
|
|
2025
|
+
* message). Returns the hosts whose outputs.js the graph imports, sorted. */
|
|
2026
|
+
function lintHostImportGraph(hostsDir, hostName) {
|
|
2027
|
+
const state = /* @__PURE__ */ new Map();
|
|
2028
|
+
const producers = /* @__PURE__ */ new Set();
|
|
2029
|
+
const visit = (name, chain) => {
|
|
2030
|
+
const mark = state.get(name);
|
|
2031
|
+
if (mark === "done") return;
|
|
2032
|
+
if (mark === "visiting") throw new HostLoadError(`Host import cycle: ${[...chain, name].map((n) => `hosts/${n}`).join(" -> ")}.`, "Hoist the shared data into one host (or powerhouse.config.json) instead of importing both ways.");
|
|
2033
|
+
const file = path.join(hostsDir, name, HOST_FILE);
|
|
2034
|
+
if (!existsSync(file)) throw new HostLoadError(`hosts/${chain[chain.length - 1] ?? name} imports sibling "hosts/${name}/host.js", which does not exist.`);
|
|
2035
|
+
state.set(name, "visiting");
|
|
2036
|
+
const imports = scanHostImports(readFileSync(file, "utf8"), file);
|
|
2037
|
+
for (const producer of imports.outputs) {
|
|
2038
|
+
if (producers.has(producer)) continue;
|
|
2039
|
+
const outputsFile = path.join(hostsDir, producer, OUTPUTS_FILE);
|
|
2040
|
+
if (!existsSync(outputsFile)) throw new HostLoadError(`hosts/${name}/host.js imports "hosts/${producer}/${OUTPUTS_FILE}", which does not exist.`, GENERATE_HINT);
|
|
2041
|
+
lintOutputsFile(readFileSync(outputsFile, "utf8"), outputsFile);
|
|
2042
|
+
producers.add(producer);
|
|
2043
|
+
}
|
|
2044
|
+
for (const sibling of imports.hosts) visit(sibling, [...chain, name]);
|
|
2045
|
+
state.set(name, "done");
|
|
2046
|
+
};
|
|
2047
|
+
visit(hostName, []);
|
|
2048
|
+
return [...producers].sort();
|
|
2049
|
+
}
|
|
2050
|
+
/** Returns the path of the first value that would not survive a JSON round
|
|
2051
|
+
* trip, or undefined when the object is fully static. */
|
|
2052
|
+
function findNonStaticValue(value, trail = "") {
|
|
2053
|
+
if (value === null) return void 0;
|
|
2054
|
+
const kind = typeof value;
|
|
2055
|
+
if (kind === "string" || kind === "number" || kind === "boolean") return;
|
|
2056
|
+
if (kind !== "object") return `${trail || "<root>"} (${kind})`;
|
|
2057
|
+
if (Array.isArray(value)) {
|
|
2058
|
+
for (let i = 0; i < value.length; i++) {
|
|
2059
|
+
const hit = findNonStaticValue(value[i], `${trail}[${i}]`);
|
|
2060
|
+
if (hit) return hit;
|
|
2061
|
+
}
|
|
2062
|
+
return;
|
|
2063
|
+
}
|
|
2064
|
+
const proto = Object.getPrototypeOf(value);
|
|
2065
|
+
if (proto !== Object.prototype && proto !== null) return `${trail || "<root>"} (non-plain object)`;
|
|
2066
|
+
for (const [key, child] of Object.entries(value)) {
|
|
2067
|
+
const hit = findNonStaticValue(child, trail ? `${trail}.${key}` : key);
|
|
2068
|
+
if (hit) return hit;
|
|
2069
|
+
}
|
|
2070
|
+
}
|
|
2071
|
+
function assertHostShape(host, file) {
|
|
2072
|
+
if (typeof host.name !== "string" || host.name.length === 0) throw new HostLoadError(`${file}: \`name\` must be a non-empty string.`);
|
|
2073
|
+
const runner = host.runner;
|
|
2074
|
+
if (runner === null || typeof runner !== "object" || typeof runner.module !== "string") throw new HostLoadError(`${file}: \`runner\` must be an object with a \`module\` specifier string.`);
|
|
2075
|
+
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.`);
|
|
2076
|
+
}
|
|
2077
|
+
async function loadHost(projectRoot, hostName) {
|
|
2078
|
+
return importHost(projectRoot, hostName, true);
|
|
2079
|
+
}
|
|
2080
|
+
async function importHost(projectRoot, hostName, checkOutputs) {
|
|
2081
|
+
const probe = probeHostsFolder(projectRoot);
|
|
2082
|
+
if (probe.kind === "absent") throw new HostLoadError(`No hosts/ folder found in ${projectRoot}.`, "Scaffold one with `ph init --uniform-runners` (or create hosts/<name>/host.js).");
|
|
2083
|
+
if (probe.kind === "empty") throw new HostLoadError(`hosts/ exists at ${probe.dir} but contains no <name>/host.js.`, "An empty hosts/ folder does not activate the uniform-runners architecture; add a host definition or remove the folder.");
|
|
2084
|
+
if (!probe.hosts.includes(hostName)) throw new HostLoadError(`Unknown host "${hostName}". Available hosts: ${probe.hosts.join(", ")}.`);
|
|
2085
|
+
const file = path.join(probe.dir, hostName, HOST_FILE);
|
|
2086
|
+
const producers = lintHostImportGraph(probe.dir, hostName);
|
|
2087
|
+
if (checkOutputs) for (const producer of producers) await assertOutputsFileFresh(projectRoot, probe.dir, hostName, producer);
|
|
2088
|
+
const host = (await import(pathToFileURL(file).href)).default;
|
|
2089
|
+
if (host === null || typeof host !== "object" || Array.isArray(host)) throw new HostLoadError(`${file} must default-export the host object (\`export default { name, runner, ... }\`).`);
|
|
2090
|
+
const nonStatic = findNonStaticValue(host);
|
|
2091
|
+
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.");
|
|
2092
|
+
assertHostShape(host, file);
|
|
2093
|
+
return {
|
|
2094
|
+
name: hostName,
|
|
2095
|
+
dir: path.dirname(file),
|
|
2096
|
+
file,
|
|
2097
|
+
host
|
|
2098
|
+
};
|
|
2099
|
+
}
|
|
2100
|
+
const OUTPUTS_HASH_EXPORT = /^export const outputsHash = "([^"]+)";$/m;
|
|
2101
|
+
/** The hash a generated outputs.js carries, or undefined. */
|
|
2102
|
+
function readOutputsFileHash(source) {
|
|
2103
|
+
return OUTPUTS_HASH_EXPORT.exec(source)?.[1];
|
|
2104
|
+
}
|
|
2105
|
+
function canonicalJson(value) {
|
|
2106
|
+
if (Array.isArray(value)) return `[${value.map(canonicalJson).join(",")}]`;
|
|
2107
|
+
if (value !== null && typeof value === "object") return `{${Object.entries(value).filter(([, child]) => child !== void 0).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([key, child]) => `${JSON.stringify(key)}:${canonicalJson(child)}`).join(",")}}`;
|
|
2108
|
+
return JSON.stringify(value);
|
|
2109
|
+
}
|
|
2110
|
+
/** sha256 over the canonical JSON of the generator's inputs. The host name
|
|
2111
|
+
* is one: every token in the file carries it, so a copied or renamed host
|
|
2112
|
+
* folder makes its outputs.js stale. */
|
|
2113
|
+
function computeOutputsHash(input) {
|
|
2114
|
+
return `sha256:${createHash("sha256").update(canonicalJson({
|
|
2115
|
+
v: 1,
|
|
2116
|
+
host: input.host,
|
|
2117
|
+
runnerModule: input.runnerModule,
|
|
2118
|
+
outputsSchema: input.outputsSchema,
|
|
2119
|
+
drives: [...new Set(input.drives)].sort()
|
|
2120
|
+
})).digest("hex").slice(0, 32)}`;
|
|
2121
|
+
}
|
|
2122
|
+
function isZodSchema(value) {
|
|
2123
|
+
return value !== null && typeof value === "object" && "_zod" in value;
|
|
2124
|
+
}
|
|
2125
|
+
function isRecord$1(value) {
|
|
2126
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
2127
|
+
}
|
|
2128
|
+
/** Local (non-remote) slugs from a drive declaration list. */
|
|
2129
|
+
function localDriveSlugs(drives) {
|
|
2130
|
+
if (!Array.isArray(drives)) return [];
|
|
2131
|
+
return drives.flatMap((drive) => isRecord$1(drive) && typeof drive.slug === "string" && drive.remote === void 0 ? [drive.slug] : []);
|
|
2132
|
+
}
|
|
2133
|
+
/**
|
|
2134
|
+
* Describes the outputs a host's creation produces, for `ph generate hosts`
|
|
2135
|
+
* and the loader's staleness check: the runner's `outputsSchema` as JSON
|
|
2136
|
+
* Schema and the host's declared local drives (the keys `drives.<slug>` of a
|
|
2137
|
+
* switchboard-like runner). Returns undefined when the runner exports no
|
|
2138
|
+
* `outputsSchema` (the host produces nothing a token can reference).
|
|
2139
|
+
*
|
|
2140
|
+
* Plugin-contributed drives are collected across every verb (verb scoping
|
|
2141
|
+
* is ignored: a drive any verb serves is referenceable). Plugins the project
|
|
2142
|
+
* tree cannot resolve contribute nothing, exactly as at boot. The implicit
|
|
2143
|
+
* default drive a switchboard serves when it declares none is NOT a known
|
|
2144
|
+
* key (it is not declared); reach it with a literal `$output` token.
|
|
2145
|
+
*/
|
|
2146
|
+
async function describeHostOutputs(projectRoot, hostName) {
|
|
2147
|
+
const { host, file } = await importHost(projectRoot, hostName, false);
|
|
2148
|
+
const runnerModule = host.runner.module;
|
|
2149
|
+
const schema = (await resolveRunnerModule(projectRoot, runnerModule)).outputsSchema;
|
|
2150
|
+
if (!isZodSchema(schema)) return void 0;
|
|
2151
|
+
const { $schema: _dialect, ...outputsSchema } = toJSONSchema(schema, {
|
|
2152
|
+
io: "output",
|
|
2153
|
+
unrepresentable: "any"
|
|
2154
|
+
});
|
|
2155
|
+
const reactor = host.reactor;
|
|
2156
|
+
const drives = localDriveSlugs(isRecord$1(reactor) ? reactor.drives : []);
|
|
2157
|
+
const entries = (host.runner.plugins ?? []).map((entry) => typeof entry === "string" ? entry : {
|
|
2158
|
+
...entry,
|
|
2159
|
+
verbs: "*"
|
|
2160
|
+
});
|
|
2161
|
+
if (entries.length > 0) {
|
|
2162
|
+
const plan = await resolvePluginContributions(projectRoot, "*", entries, path.relative(projectRoot, file));
|
|
2163
|
+
drives.push(...localDriveSlugs(plan.drives.map((drive) => drive.declaration)));
|
|
2164
|
+
}
|
|
2165
|
+
const sortedDrives = [...new Set(drives)].sort();
|
|
2166
|
+
return {
|
|
2167
|
+
host: hostName,
|
|
2168
|
+
runnerModule,
|
|
2169
|
+
outputsSchema,
|
|
2170
|
+
drives: sortedDrives,
|
|
2171
|
+
hash: computeOutputsHash({
|
|
2172
|
+
host: hostName,
|
|
2173
|
+
runnerModule,
|
|
2174
|
+
outputsSchema,
|
|
2175
|
+
drives: sortedDrives
|
|
2176
|
+
})
|
|
2177
|
+
};
|
|
2178
|
+
}
|
|
2179
|
+
async function assertOutputsFileFresh(projectRoot, hostsDir, consumer, producer) {
|
|
2180
|
+
const rel = `hosts/${producer}/${OUTPUTS_FILE}`;
|
|
2181
|
+
const actual = readOutputsFileHash(readFileSync(path.join(hostsDir, producer, OUTPUTS_FILE), "utf8"));
|
|
2182
|
+
if (!existsSync(path.join(hostsDir, producer, HOST_FILE))) throw new HostLoadError(`hosts/${consumer} imports ${rel}, but there is no hosts/${producer}/host.js to produce it.`, "Delete the orphaned outputs.js and fix the import.");
|
|
2183
|
+
const description = await describeHostOutputs(projectRoot, producer);
|
|
2184
|
+
if (!description) throw new HostLoadError(`hosts/${consumer} imports ${rel}, but hosts/${producer}'s runner declares no outputsSchema, so it produces no outputs.`);
|
|
2185
|
+
if (actual !== description.hash) throw new HostLoadError(`${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}.`);
|
|
2186
|
+
}
|
|
2187
|
+
/**
|
|
2188
|
+
* `.ph/run/<host>.json`, version 2 (typed-host-configs 3.6): what a running
|
|
2189
|
+
* host and its members produced. Validated on read; a v1 (or any invalid)
|
|
2190
|
+
* record reads as "not running". `projectName` is kept beyond the plan's
|
|
2191
|
+
* sketch because the live/foreign probe needs it. `host` is the host's
|
|
2192
|
+
* `name` (the file key), not its folder.
|
|
2193
|
+
*/
|
|
2194
|
+
const outputsSchema = record(string(), unknown());
|
|
2195
|
+
const runRecordMemberSchema = strictObject({
|
|
2196
|
+
/** The member's host folder (`children.<key>.host`). */
|
|
2197
|
+
host: string().min(1),
|
|
2198
|
+
runnerModule: string().min(1),
|
|
2199
|
+
kind: runnerKindSchema,
|
|
2200
|
+
verb: string().min(1),
|
|
2201
|
+
outputs: outputsSchema
|
|
2202
|
+
});
|
|
2203
|
+
const runRecordSchema = strictObject({
|
|
2204
|
+
version: literal(2),
|
|
2205
|
+
host: string().min(1),
|
|
2206
|
+
projectName: string(),
|
|
2207
|
+
kind: runnerKindSchema,
|
|
2208
|
+
verb: string().min(1),
|
|
2209
|
+
pid: number().int(),
|
|
2210
|
+
startedAt: string(),
|
|
2211
|
+
/** Standalone hosts: the runner's outputs. */
|
|
2212
|
+
outputs: outputsSchema.optional(),
|
|
2213
|
+
/** Compounds: one entry per started member, keyed by member name. */
|
|
2214
|
+
members: record(string(), runRecordMemberSchema).optional(),
|
|
2215
|
+
/** Host-specific extras (e.g. mcpUrl) a runner wants in the record. */
|
|
2216
|
+
extra: record(string(), unknown()).optional()
|
|
2217
|
+
});
|
|
2218
|
+
const runDir = (projectDir) => path.join(resolvePhDir(projectDir), "run");
|
|
2219
|
+
const recordPath = (projectDir, hostName) => path.join(runDir(projectDir), `${hostName}.json`);
|
|
2220
|
+
function readRunRecord(projectDir, hostName) {
|
|
2221
|
+
let raw;
|
|
2222
|
+
try {
|
|
2223
|
+
raw = JSON.parse(fs.readFileSync(recordPath(projectDir, hostName), "utf8"));
|
|
2224
|
+
} catch {
|
|
2225
|
+
return;
|
|
2226
|
+
}
|
|
2227
|
+
const parsed = runRecordSchema.safeParse(raw);
|
|
2228
|
+
return parsed.success ? parsed.data : void 0;
|
|
2229
|
+
}
|
|
2230
|
+
/** Every valid v2 record under `.ph/run/` (invalid and v1 files skipped). */
|
|
2231
|
+
function listRunRecords(projectDir) {
|
|
2232
|
+
let files;
|
|
2233
|
+
try {
|
|
2234
|
+
files = fs.readdirSync(runDir(projectDir));
|
|
2235
|
+
} catch {
|
|
2236
|
+
return [];
|
|
2237
|
+
}
|
|
2238
|
+
return files.filter((file) => file.endsWith(".json")).flatMap((file) => {
|
|
2239
|
+
const record = readRunRecord(projectDir, file.slice(0, -5));
|
|
2240
|
+
return record ? [record] : [];
|
|
2241
|
+
});
|
|
2242
|
+
}
|
|
2243
|
+
/** The project identity the live/foreign probe compares: package.json
|
|
2244
|
+
* `name`, else the folder name. */
|
|
2245
|
+
function readProjectName(projectDir) {
|
|
2246
|
+
try {
|
|
2247
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(projectDir, "package.json"), "utf8"));
|
|
2248
|
+
if (typeof pkg.name === "string" && pkg.name) return pkg.name;
|
|
2249
|
+
} catch {}
|
|
2250
|
+
return path.basename(path.resolve(projectDir));
|
|
2251
|
+
}
|
|
2252
|
+
function writeRunRecord(projectDir, record) {
|
|
2253
|
+
const target = recordPath(projectDir, record.host);
|
|
2254
|
+
const valid = runRecordSchema.parse(record);
|
|
2255
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
2256
|
+
fs.writeFileSync(target, `${JSON.stringify(valid, null, 2)}\n`);
|
|
2257
|
+
}
|
|
2258
|
+
function clearRunRecord(projectDir, hostName) {
|
|
2259
|
+
try {
|
|
2260
|
+
fs.rmSync(recordPath(projectDir, hostName));
|
|
2261
|
+
} catch {}
|
|
2262
|
+
}
|
|
2263
|
+
function isPidAlive(pid) {
|
|
2264
|
+
try {
|
|
2265
|
+
process.kill(pid, 0);
|
|
2266
|
+
return true;
|
|
2267
|
+
} catch (error) {
|
|
2268
|
+
return error.code === "EPERM";
|
|
2269
|
+
}
|
|
2270
|
+
}
|
|
2271
|
+
/**
|
|
2272
|
+
* Decide whether the recorded instance is this project's live host.
|
|
2273
|
+
*
|
|
2274
|
+
* pid liveness alone proves nothing (pids are reused), and the recorded
|
|
2275
|
+
* projectName is what separates "my instance" from "a different project that
|
|
2276
|
+
* happens to hold this storage root" — the confusion the vetra lock exists to
|
|
2277
|
+
* prevent. A stale record (dead pid) is reported so the caller can clear it; a
|
|
2278
|
+
* foreign one (live pid, different project) is left alone.
|
|
2279
|
+
*/
|
|
2280
|
+
function probeRun(projectDir, hostName, projectName) {
|
|
2281
|
+
const record = readRunRecord(projectDir, hostName);
|
|
2282
|
+
if (!record) return { status: "none" };
|
|
2283
|
+
if (!isPidAlive(record.pid)) return {
|
|
2284
|
+
status: "stale",
|
|
2285
|
+
record
|
|
2286
|
+
};
|
|
2287
|
+
if (record.projectName !== projectName) return {
|
|
2288
|
+
status: "foreign",
|
|
2289
|
+
record
|
|
2290
|
+
};
|
|
2291
|
+
return {
|
|
2292
|
+
status: "live",
|
|
2293
|
+
record
|
|
2294
|
+
};
|
|
2295
|
+
}
|
|
2296
|
+
/**
|
|
2297
|
+
* `${userData}` resolution for host files (desktop shape): storage paths in a
|
|
2298
|
+
* host must not derive from the instance name (renames must stay safe), so
|
|
2299
|
+
* the host file writes `${userData}/.ph/reactor-storage` and the RUNNER
|
|
2300
|
+
* resolves it at start. `${userData}` is a PROJECT-SHAPED root: its `.ph`
|
|
2301
|
+
* subtree carries the same names the classic commands use under
|
|
2302
|
+
* `<project>/.ph` (see `resolvePhDir`). In the CLI it IS the project root, so
|
|
2303
|
+
* `ph run desktop` in a project shares the one `.ph` tree `ph vetra` uses;
|
|
2304
|
+
* a shell (Tauri) points it at the OS profile via PH_USER_DATA_DIR, and the
|
|
2305
|
+
* whole `.ph` tree — stores, identity, run records — follows.
|
|
2306
|
+
*/
|
|
2307
|
+
function defaultUserDataDir(projectRoot, env = process.env) {
|
|
2308
|
+
return env.PH_USER_DATA_DIR ?? path.resolve(projectRoot);
|
|
2309
|
+
}
|
|
2310
|
+
/** Load every producer host a set of refs names (each once). */
|
|
2311
|
+
async function loadProducers(projectRoot, refs) {
|
|
2312
|
+
const producers = /* @__PURE__ */ new Map();
|
|
2313
|
+
for (const { host: folder } of refs) {
|
|
2314
|
+
if (producers.has(folder)) continue;
|
|
2315
|
+
try {
|
|
2316
|
+
const loaded = await loadHost(projectRoot, folder);
|
|
2317
|
+
const specifier = loaded.host.runner.module;
|
|
2318
|
+
producers.set(folder, {
|
|
2319
|
+
folder,
|
|
2320
|
+
name: loaded.host.name,
|
|
2321
|
+
specifier,
|
|
2322
|
+
runner: await resolveRunnerModule(projectRoot, specifier)
|
|
2323
|
+
});
|
|
2324
|
+
} catch (error) {
|
|
2325
|
+
producers.set(folder, { error: `names host "${folder}", which cannot be loaded: ${error instanceof Error ? error.message : String(error)}` });
|
|
2326
|
+
}
|
|
2327
|
+
}
|
|
2328
|
+
return producers;
|
|
2329
|
+
}
|
|
2330
|
+
/** The outputs schema of a runner module, or why it has none. */
|
|
2331
|
+
function runnerOutputsSchema(runner, specifier, label) {
|
|
2332
|
+
const schema = runner.outputsSchema;
|
|
2333
|
+
if (schema === void 0 || schema === null) return { error: `${label} runs "${specifier}", which exports no outputsSchema, so it produces no outputs a token can read.` };
|
|
2334
|
+
return {
|
|
2335
|
+
schema,
|
|
2336
|
+
label: `"${specifier}" (${label})`
|
|
2337
|
+
};
|
|
2338
|
+
}
|
|
2339
|
+
/** Declared-validation lookup for a standalone host's producers. */
|
|
2340
|
+
function producerOutputsSchemas(producers) {
|
|
2341
|
+
return (ref) => {
|
|
2342
|
+
const info = producers.get(ref.host);
|
|
2343
|
+
if (!info) return { error: `names host "${ref.host}", which was not loaded.` };
|
|
2344
|
+
if ("error" in info) return { error: info.error };
|
|
2345
|
+
return runnerOutputsSchema(info.runner, info.specifier, `host "${ref.host}"`);
|
|
2346
|
+
};
|
|
2347
|
+
}
|
|
2348
|
+
/**
|
|
2349
|
+
* Standalone `$output` source: the producer's live v2 run record. Its own
|
|
2350
|
+
* standalone record first (keyed by the producer's `name`); else a live
|
|
2351
|
+
* compound of this project with exactly one member running that host. A
|
|
2352
|
+
* missing, stale, foreign or output-less record means "not running", and the
|
|
2353
|
+
* lookup fails naming the producer and how to start it (no fallback to the
|
|
2354
|
+
* producer's declared config, no waiting).
|
|
2355
|
+
*/
|
|
2356
|
+
function runRecordOutputSource(projectRoot, options) {
|
|
2357
|
+
const { consumer, producers, projectName } = options;
|
|
2358
|
+
return { lookup(ref) {
|
|
2359
|
+
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).`;
|
|
2360
|
+
const info = producers.get(ref.host);
|
|
2361
|
+
const schema = info && !("error" in info) ? info.runner.outputsSchema : void 0;
|
|
2362
|
+
const withSchema = schema !== void 0 && schema !== null ? { schema } : {};
|
|
2363
|
+
if (ref.member === void 0 && info && !("error" in info)) {
|
|
2364
|
+
const probe = probeRun(projectRoot, info.name, projectName);
|
|
2365
|
+
if (probe.status === "live" && probe.record.outputs) return {
|
|
2366
|
+
status: "available",
|
|
2367
|
+
outputs: probe.record.outputs,
|
|
2368
|
+
...withSchema
|
|
2369
|
+
};
|
|
2370
|
+
}
|
|
2371
|
+
const members = listRunRecords(projectRoot).filter((record) => record.members !== void 0 && record.projectName === projectName && isPidAlive(record.pid)).flatMap((record) => Object.entries(record.members ?? {}).filter(([key, member]) => member.host === ref.host && (ref.member === void 0 || key === ref.member)).map(([key, member]) => ({
|
|
2372
|
+
compound: record.host,
|
|
2373
|
+
key,
|
|
2374
|
+
member
|
|
2375
|
+
})));
|
|
2376
|
+
if (members.length === 1) return {
|
|
2377
|
+
status: "available",
|
|
2378
|
+
outputs: members[0].member.outputs,
|
|
2379
|
+
...withSchema
|
|
2380
|
+
};
|
|
2381
|
+
if (members.length > 1) return {
|
|
2382
|
+
status: "unavailable",
|
|
2383
|
+
message: `${consumer} needs outputs from host "${ref.host}", which runs as ${members.map((m) => `member "${m.key}" of "${m.compound}"`).join(" and ")}; stop all but one, or run ${ref.host} on its own.`
|
|
2384
|
+
};
|
|
2385
|
+
return {
|
|
2386
|
+
status: "unavailable",
|
|
2387
|
+
message: notRunning
|
|
2388
|
+
};
|
|
2389
|
+
} };
|
|
2390
|
+
}
|
|
2391
|
+
/** The resolving process's `$env` inputs: its environment plus the
|
|
2392
|
+
* always-resolvable built-ins (`userData` honours PH_USER_DATA_DIR). */
|
|
2393
|
+
function processResolveEnv(projectRoot, env = process.env) {
|
|
2394
|
+
return {
|
|
2395
|
+
env,
|
|
2396
|
+
builtins: {
|
|
2397
|
+
userData: defaultUserDataDir(projectRoot, env),
|
|
2398
|
+
projectRoot: path.resolve(projectRoot)
|
|
2399
|
+
}
|
|
2400
|
+
};
|
|
2401
|
+
}
|
|
2402
|
+
/**
|
|
2403
|
+
* The compound output source: a member's `$output` tokens read the live
|
|
2404
|
+
* `RunnerHandle.outputs` of the members started before it. `schemas` (member
|
|
2405
|
+
* key → its runner's `outputsSchema`) lets an absent optional output field
|
|
2406
|
+
* omit the consuming property. Pure (the run-record source for standalone
|
|
2407
|
+
* hosts is node: ./node.ts).
|
|
2408
|
+
*/
|
|
2409
|
+
function compoundOutputSource(members, started, compound, schemas) {
|
|
2410
|
+
return { lookup(ref) {
|
|
2411
|
+
const target = memberForRef(ref, members);
|
|
2412
|
+
if ("error" in target) return {
|
|
2413
|
+
status: "unavailable",
|
|
2414
|
+
message: `compound "${compound}": a token ${target.error}`
|
|
2415
|
+
};
|
|
2416
|
+
if (!started.has(target.key)) return {
|
|
2417
|
+
status: "unavailable",
|
|
2418
|
+
message: `compound "${compound}": member "${target.key}" (host "${ref.host}") has not started yet; a producer must start before its consumers.`
|
|
2419
|
+
};
|
|
2420
|
+
const schema = schemas?.get(target.key);
|
|
2421
|
+
return {
|
|
2422
|
+
status: "available",
|
|
2423
|
+
outputs: started.get(target.key),
|
|
2424
|
+
...schema !== void 0 ? { schema } : {}
|
|
2425
|
+
};
|
|
2426
|
+
} };
|
|
2427
|
+
}
|
|
2428
|
+
/** The data half of a handle, validated by the compound. `ready`/`shutdown`
|
|
2429
|
+
* are functions and promises, so they are checked as TS fields, not here. */
|
|
2430
|
+
const runnerHandleSchema = looseObject({ outputs: record(string(), unknown()).optional() });
|
|
2431
|
+
function isRecord(value) {
|
|
2432
|
+
return typeof value === "object" && value !== null;
|
|
2433
|
+
}
|
|
2434
|
+
function isPromiseLike(value) {
|
|
2435
|
+
return isRecord(value) && typeof value.then === "function";
|
|
2436
|
+
}
|
|
2437
|
+
function isCallable(value) {
|
|
2438
|
+
return typeof value === "function";
|
|
2439
|
+
}
|
|
2440
|
+
/** Normalize what a verb returned. `undefined` (a self-sustaining bridge)
|
|
2441
|
+
* is an empty handle; anything else must match runnerHandleSchema. */
|
|
2442
|
+
function toStartedHandle(value, where) {
|
|
2443
|
+
if (value === void 0 || value === null) return { outputs: {} };
|
|
2444
|
+
const parsed = runnerHandleSchema.safeParse(value);
|
|
2445
|
+
if (!parsed.success) throw new Error(`${where} returned an invalid runner handle:\n${prettifyError(parsed.error)}`);
|
|
2446
|
+
const live = isRecord(value) ? value : {};
|
|
2447
|
+
const shutdown = live.shutdown;
|
|
2448
|
+
return {
|
|
2449
|
+
...parsed.data,
|
|
2450
|
+
outputs: parsed.data.outputs ?? {},
|
|
2451
|
+
...isPromiseLike(live.ready) ? { ready: live.ready } : {},
|
|
2452
|
+
...isCallable(shutdown) ? { shutdown: () => shutdown.call(value) } : {}
|
|
2453
|
+
};
|
|
2454
|
+
}
|
|
2455
|
+
//#endregion
|
|
2456
|
+
export { readProjectName as A, validateDeclaredHost as B, outputSitesOf as C, processResolveEnv as D, probeRun as E, resolvePluginContributions as F, writeRunRecord as H, resolveRunnerModule as I, runRecordOutputSource as L, renderTokens as M, resolveHostOutputs as N, producerOutputsSchemas as O, resolveHostPlugins as P, runnerOutputsSchema as R, outputRefsOf as S, probeHostsFolder as T, validateHost as V, isToken as _, collectTokenSites as a, memberForRef as b, defineHostSchemas as c, entryActiveForVerb as d, envSitesOf as f, isSchemaLike as g, getVerb as h, clearRunRecord as i, readRunRecord as j, projectDriveIdWith as k, describeToken as l, formatPath as m, ONE_SHOT_VERBS as n, compoundOutputSource as o, findDeadConnectConfig as p, PluginError as r, declaredHostSchemas as s, CONNECT_RUNNER as t, drivesSchema as u, loadHost as v, planCompound as w, normalizePluginEntries as x, loadProducers as y, toStartedHandle as z };
|
|
2457
|
+
|
|
2458
|
+
//# sourceMappingURL=compound-B6RZMA0Y-Cv3XMQ3Y.mjs.map
|
|
2459
|
+
//# debugId=4521b21a-8bc8-5253-a45e-5f2575622f79
|