@powerhousedao/ph-cli 6.4.0-next.2 → 6.4.0-next.5
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/README.md +6 -5
- package/dist/auth-5bqHASGL.mjs +4 -0
- package/dist/auth-DYknkWfW.mjs +23 -0
- package/dist/auth-DYknkWfW.mjs.map +1 -0
- package/dist/{build-C7RBpPwa.mjs → build-CBKlv5E3.mjs} +6 -6
- package/dist/{build-C7RBpPwa.mjs.map → build-CBKlv5E3.mjs.map} +1 -1
- package/dist/build-Dr1lnv4h.mjs +4 -0
- package/dist/{check-1Hfe0lVO.mjs → check-CW81vbe9.mjs} +4 -4
- package/dist/{check-1Hfe0lVO.mjs.map → check-CW81vbe9.mjs.map} +1 -1
- package/dist/{check-MBdw9Lbm.mjs → check-Cx_AeBQe.mjs} +7 -7
- package/dist/check-Cx_AeBQe.mjs.map +1 -0
- package/dist/{check-ClxYRer4.mjs → check-DhFd9tO8.mjs} +3 -3
- package/dist/{cli-connect-override-DsuuectH.mjs → cli-connect-override-DKxY3lCi.mjs} +4 -4
- package/dist/{cli-connect-override-DsuuectH.mjs.map → cli-connect-override-DKxY3lCi.mjs.map} +1 -1
- package/dist/cli.mjs +9 -8
- package/dist/cli.mjs.map +1 -1
- package/dist/{compound-Q9sZSEZF-zZWzQ7VC.mjs → compound-g6x_KkWp-Bs7olmlI.mjs} +464 -360
- package/dist/compound-g6x_KkWp-Bs7olmlI.mjs.map +1 -0
- package/dist/{connect-build-DAnGPSF5.mjs → connect-build-DpGUrtct.mjs} +5 -5
- package/dist/{connect-build-DAnGPSF5.mjs.map → connect-build-DpGUrtct.mjs.map} +1 -1
- package/dist/{connect-config-C0QZ7zTf.mjs → connect-config-BpzwJln3.mjs} +4 -4
- package/dist/{connect-config-C0QZ7zTf.mjs.map → connect-config-BpzwJln3.mjs.map} +1 -1
- package/dist/{connect-preview-BvxXGo_W.mjs → connect-preview-B_E4SIV6.mjs} +21 -4
- package/dist/connect-preview-B_E4SIV6.mjs.map +1 -0
- package/dist/connect-studio-BPZOcwUM.mjs +214 -0
- package/dist/connect-studio-BPZOcwUM.mjs.map +1 -0
- package/dist/credentials-CmtYywgk.mjs +132 -0
- package/dist/credentials-CmtYywgk.mjs.map +1 -0
- package/dist/definitions-worker.mjs +4 -4
- package/dist/definitions-worker.mjs.map +1 -1
- package/dist/dev-host-CM-Jg2kY.mjs +19 -0
- package/dist/dev-host-CM-Jg2kY.mjs.map +1 -0
- package/dist/{dist-CRR5Anp2.mjs → dist-DPj_FB8H.mjs} +5 -5
- package/dist/dist-DPj_FB8H.mjs.map +1 -0
- package/dist/{explain-BfOC7Ngv.mjs → explain-DQ5ymlco.mjs} +5 -5
- package/dist/{explain-BfOC7Ngv.mjs.map → explain-DQ5ymlco.mjs.map} +1 -1
- package/dist/{export-CdTqYviH.mjs → export-CzeF8pob.mjs} +4 -4
- package/dist/{export-CdTqYviH.mjs.map → export-CzeF8pob.mjs.map} +1 -1
- package/dist/{generate-all-HujZHqCG.mjs → generate-all-B9MwWXlq.mjs} +6 -21
- package/dist/generate-all-B9MwWXlq.mjs.map +1 -0
- package/dist/{generate-app-hm6CJ_4O.mjs → generate-app-C7n0j8Ak.mjs} +5 -18
- package/dist/generate-app-C7n0j8Ak.mjs.map +1 -0
- package/dist/{generate-document-model-BiD6ovXc.mjs → generate-document-model-D3LKY1D7.mjs} +11 -35
- package/dist/generate-document-model-D3LKY1D7.mjs.map +1 -0
- package/dist/{generate-editor-DBj_Pxwa.mjs → generate-editor-DKuRUeIt.mjs} +5 -18
- package/dist/generate-editor-DKuRUeIt.mjs.map +1 -0
- package/dist/{generate-processor-BVjOsfjJ.mjs → generate-processor-CwJvJDpd.mjs} +5 -18
- package/dist/generate-processor-CwJvJDpd.mjs.map +1 -0
- package/dist/{generate-subgraph-DJZCr0Tk.mjs → generate-subgraph-Q1VLh3SC.mjs} +13 -39
- package/dist/generate-subgraph-Q1VLh3SC.mjs.map +1 -0
- package/dist/{get-version-DAYhm6MX.mjs → get-version-CTP__ORu.mjs} +4 -4
- package/dist/{get-version-DAYhm6MX.mjs.map → get-version-CTP__ORu.mjs.map} +1 -1
- package/dist/identity-DXZFeQfC.mjs +137 -0
- package/dist/identity-DXZFeQfC.mjs.map +1 -0
- package/dist/{index-Bs1PfL3W.d.mts → index-aosqo7aM.d.mts} +5 -4
- package/dist/index-aosqo7aM.d.mts.map +1 -0
- package/dist/{inspect-CulIpVsF.mjs → inspect-BgKI8Fhd.mjs} +6 -6
- package/dist/{inspect-CulIpVsF.mjs.map → inspect-BgKI8Fhd.mjs.map} +1 -1
- package/dist/{keyframes-bFo9iDhT.mjs → keyframes-BkeORfEu.mjs} +4 -4
- package/dist/{keyframes-bFo9iDhT.mjs.map → keyframes-BkeORfEu.mjs.map} +1 -1
- package/dist/{mcp-rtMGg307.mjs → mcp-gcG7SW9L.mjs} +152 -10
- package/dist/mcp-gcG7SW9L.mjs.map +1 -0
- package/dist/{migrate-CWCJP19Q.mjs → migrate-BaWZhorc.mjs} +4 -4
- package/dist/{migrate-CWCJP19Q.mjs.map → migrate-BaWZhorc.mjs.map} +1 -1
- package/dist/{migrate-document-models-DTxM7D7p.mjs → migrate-document-models-DYmkJzq3.mjs} +5 -6
- package/dist/migrate-document-models-DYmkJzq3.mjs.map +1 -0
- package/dist/{migrate-subgraphs-_yRnF7xt.mjs → migrate-subgraphs-BUgTeHcm.mjs} +6 -7
- package/dist/migrate-subgraphs-BUgTeHcm.mjs.map +1 -0
- package/dist/migrate-subgraphs-ChhXynqd.mjs +4 -0
- package/dist/{ph-cli-commands-FLZClR4x.mjs → ph-cli-commands-B5VkGW99.mjs} +179 -190
- package/dist/ph-cli-commands-B5VkGW99.mjs.map +1 -0
- package/dist/ph-cli-commands-CGXSo1wx.mjs +4 -0
- package/dist/{registry-auth-Bm5AR-fB.mjs → registry-auth-C8D5cno2.mjs} +4 -4
- package/dist/{registry-auth-Bm5AR-fB.mjs.map → registry-auth-C8D5cno2.mjs.map} +1 -1
- package/dist/render-BQE20Cnd.mjs +4 -0
- package/dist/{render-SVfj3m8A.mjs → render-CQdi685k.mjs} +6 -6
- package/dist/render-CQdi685k.mjs.map +1 -0
- package/dist/{run-LRGy7zGo.mjs → run-C6Vha5VN.mjs} +3 -3
- package/dist/{run--de_-WAz.mjs → run-sVzTTEUx.mjs} +5 -36
- package/dist/run-sVzTTEUx.mjs.map +1 -0
- package/dist/{run-sugar-DUiDFl_T.mjs → run-sugar-BuxOaRzE.mjs} +16 -8
- package/dist/run-sugar-BuxOaRzE.mjs.map +1 -0
- package/dist/{run-sugar-YDxw0iV9.mjs → run-sugar-Dz-rpeMO.mjs} +3 -3
- package/dist/runners/connect.d.mts +20 -3
- package/dist/runners/connect.d.mts.map +1 -1
- package/dist/runners/connect.mjs +37 -15
- package/dist/runners/connect.mjs.map +1 -1
- package/dist/runners/switchboard.d.mts +1 -1
- package/dist/runners/switchboard.mjs +3 -3
- package/dist/scripts/generate-commands-docs.ts +12 -0
- package/dist/{subgraphs-7OYWwP-C.mjs → subgraphs-Bm9NHTCn.mjs} +5 -38
- package/dist/subgraphs-Bm9NHTCn.mjs.map +1 -0
- package/dist/{sugar-checks-BFu3sfFJ.mjs → sugar-checks-DL-J3l2y.mjs} +16 -15
- package/dist/sugar-checks-DL-J3l2y.mjs.map +1 -0
- package/dist/{verify-Dkb6K1fc.mjs → verify-BLn76w09.mjs} +4 -4
- package/dist/{verify-Dkb6K1fc.mjs.map → verify-BLn76w09.mjs.map} +1 -1
- package/dist/{vetra-gateway-BMzq0mqX.mjs → vetra-gateway-D30pZgha.mjs} +5 -5
- package/dist/{vetra-gateway-BMzq0mqX.mjs.map → vetra-gateway-D30pZgha.mjs.map} +1 -1
- package/dist/vetra-gateway-DE5Hc0Fp.mjs +4 -0
- package/dist/vetra-host-0rSW35_r.mjs +230 -0
- package/dist/vetra-host-0rSW35_r.mjs.map +1 -0
- package/dist/{vetra-launcher-Dq0tWyNW.mjs → vetra-launcher-6NKfi6Au.mjs} +56 -13
- package/dist/vetra-launcher-6NKfi6Au.mjs.map +1 -0
- package/dist/vetra-launcher-XMk_Hv0c.mjs +4 -0
- package/dist/{vetra-instance-CLUzbtbh.mjs → vetra-runtime-Bk6CW-BE.mjs} +6 -24
- package/dist/vetra-runtime-Bk6CW-BE.mjs.map +1 -0
- package/dist/warn-subgraph-type-conflicts-BZ4NwLx5.mjs +131 -0
- package/dist/warn-subgraph-type-conflicts-BZ4NwLx5.mjs.map +1 -0
- package/package.json +17 -16
- package/dist/auth-BFUq7CvE.mjs +0 -18
- package/dist/auth-BFUq7CvE.mjs.map +0 -1
- package/dist/auth-CNhbN5UM.mjs +0 -4
- package/dist/build-BUpe1j4m.mjs +0 -4
- package/dist/check-MBdw9Lbm.mjs.map +0 -1
- package/dist/compound-Q9sZSEZF-zZWzQ7VC.mjs.map +0 -1
- package/dist/connect-preview-BvxXGo_W.mjs.map +0 -1
- package/dist/connect-studio-BUth3UYP.mjs +0 -106
- package/dist/connect-studio-BUth3UYP.mjs.map +0 -1
- package/dist/dist-CRR5Anp2.mjs.map +0 -1
- package/dist/generate-all-HujZHqCG.mjs.map +0 -1
- package/dist/generate-app-hm6CJ_4O.mjs.map +0 -1
- package/dist/generate-document-model-BiD6ovXc.mjs.map +0 -1
- package/dist/generate-editor-DBj_Pxwa.mjs.map +0 -1
- package/dist/generate-processor-BVjOsfjJ.mjs.map +0 -1
- package/dist/generate-subgraph-DJZCr0Tk.mjs.map +0 -1
- package/dist/index-Bs1PfL3W.d.mts.map +0 -1
- package/dist/mcp-rtMGg307.mjs.map +0 -1
- package/dist/migrate-document-models-DTxM7D7p.mjs.map +0 -1
- package/dist/migrate-subgraphs-DcJjLMFd.mjs +0 -4
- package/dist/migrate-subgraphs-_yRnF7xt.mjs.map +0 -1
- package/dist/ph-cli-commands-CRwA1aVX.mjs +0 -4
- package/dist/ph-cli-commands-FLZClR4x.mjs.map +0 -1
- package/dist/render-3M3DwFzO.mjs +0 -4
- package/dist/render-SVfj3m8A.mjs.map +0 -1
- package/dist/run--de_-WAz.mjs.map +0 -1
- package/dist/run-sugar-DUiDFl_T.mjs.map +0 -1
- package/dist/subgraphs-7OYWwP-C.mjs.map +0 -1
- package/dist/sugar-checks-BFu3sfFJ.mjs.map +0 -1
- package/dist/vetra-gateway-BP6Catg4.mjs +0 -4
- package/dist/vetra-host-C37IGwBM.mjs +0 -94
- package/dist/vetra-host-C37IGwBM.mjs.map +0 -1
- package/dist/vetra-instance-CLUzbtbh.mjs.map +0 -1
- package/dist/vetra-launcher-CJ01qmS1.mjs +0 -4
- package/dist/vetra-launcher-Dq0tWyNW.mjs.map +0 -1
- package/dist/warn-subgraph-type-conflicts-BOHBmThq.mjs +0 -19
- package/dist/warn-subgraph-type-conflicts-BOHBmThq.mjs.map +0 -1
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="796b8518-026b-5e47-b5fa-909b5b07437b")}catch(e){}}();
|
|
3
3
|
import { _ as unknown, b as prettifyError, c as literal, f as record, g as union, i as boolean, l as looseObject, m as string, n as _enum, p as strictObject, r as array, t as ZodType, u as number, v as url, y as toJSONSchema } from "./schemas-DzgKfQIx.mjs";
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
5
|
import fs, { existsSync, readFileSync, readdirSync, realpathSync, statSync } from "node:fs";
|
|
6
6
|
import path from "node:path";
|
|
7
|
+
import { TOKEN_ESCAPE_KEY, envTokenable, findToken, isToken, switchboardOfDrive, tokenKeyOf, tokenSchema, tokenable } from "@powerhousedao/shared/host-tokens";
|
|
8
|
+
import { isOriginPlaceholderUrl } from "@powerhousedao/shared/connect/origin-placeholder";
|
|
7
9
|
import { execFileSync } from "node:child_process";
|
|
10
|
+
import "@powerhousedao/shared/clis/owner-only";
|
|
8
11
|
import { createHash } from "node:crypto";
|
|
9
|
-
import net from "node:net";
|
|
10
12
|
import { pathToFileURL } from "node:url";
|
|
11
13
|
import { Worker } from "node:worker_threads";
|
|
12
|
-
import {
|
|
13
|
-
import
|
|
14
|
-
|
|
15
|
-
//#region ../../packages/host-core/dist/compound-Q9sZSEZF.mjs
|
|
14
|
+
import { openInBrowser, opensBrowser, signInLink } from "@powerhousedao/shared/clis/local-sign-in";
|
|
15
|
+
import "@powerhousedao/shared/clis/ph-dir";
|
|
16
|
+
//#region ../../packages/host-core/dist/run-record-C6oTZF_C.mjs
|
|
16
17
|
/**
|
|
17
18
|
* The schema half of drives.ts, zod only so `./schema` stays neutral.
|
|
18
19
|
* - slug: the SEEDING KEY (idempotence); id optional (stable identity).
|
|
@@ -55,106 +56,6 @@ function projectDriveIdWith(sha256Hex, projectRoot, slug) {
|
|
|
55
56
|
return `${slug}-${sha256Hex(projectRoot).substring(0, 8)}`;
|
|
56
57
|
}
|
|
57
58
|
/**
|
|
58
|
-
* The connect config slices each built-in Connect plugin owns, by specifier
|
|
59
|
-
* (typed-host-configs 1.6). Under a declared composition Connect zeroes a
|
|
60
|
-
* slice whose plugin is absent — presence is activation — so an authored
|
|
61
|
-
* value there is dead config. Connect's built-ins are browser modules with no
|
|
62
|
-
* Node-resolvable identity, so their ownership is declared here as data; a
|
|
63
|
-
* Connect test pins it to plugin-host's zeroing.
|
|
64
|
-
*/
|
|
65
|
-
const CONNECT_PLUGIN_OWNED_SLICES = {
|
|
66
|
-
"@powerhousedao/connect/plugins/generic": { slices: [
|
|
67
|
-
{
|
|
68
|
-
path: "drives.allowAddDrive",
|
|
69
|
-
absent: false,
|
|
70
|
-
entryKey: "allowAddDrive"
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
path: "drives.sections",
|
|
74
|
-
absent: {
|
|
75
|
-
remote: {
|
|
76
|
-
enabled: false,
|
|
77
|
-
allowAdd: false,
|
|
78
|
-
allowDelete: false
|
|
79
|
-
},
|
|
80
|
-
local: {
|
|
81
|
-
enabled: false,
|
|
82
|
-
allowAdd: false,
|
|
83
|
-
allowDelete: false
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
entryKey: "sections"
|
|
87
|
-
},
|
|
88
|
-
{
|
|
89
|
-
path: "drives.icons",
|
|
90
|
-
absent: null,
|
|
91
|
-
entryKey: "icons"
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
path: "home.background",
|
|
95
|
-
absent: null,
|
|
96
|
-
entryKey: "homeBackground"
|
|
97
|
-
}
|
|
98
|
-
] },
|
|
99
|
-
"@powerhousedao/connect/plugins/sentry": { slices: [{
|
|
100
|
-
path: "sentry.dsn",
|
|
101
|
-
absent: null,
|
|
102
|
-
entryKey: "dsn"
|
|
103
|
-
}] },
|
|
104
|
-
"@powerhousedao/connect/plugins/openpanel": {
|
|
105
|
-
slices: [
|
|
106
|
-
{
|
|
107
|
-
path: "openPanel.clientId",
|
|
108
|
-
absent: "",
|
|
109
|
-
entryKey: "clientId"
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
path: "openPanel.trackUiEvents",
|
|
113
|
-
absent: false,
|
|
114
|
-
entryKey: "trackUiEvents"
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
path: "openPanel.trackOperations",
|
|
118
|
-
absent: false,
|
|
119
|
-
entryKey: "trackOperations"
|
|
120
|
-
}
|
|
121
|
-
],
|
|
122
|
-
inertUnless: "openPanel.clientId"
|
|
123
|
-
},
|
|
124
|
-
"@powerhousedao/connect/plugins/assistant": { slices: [{
|
|
125
|
-
path: "ai.assistantEnabled",
|
|
126
|
-
absent: false
|
|
127
|
-
}] },
|
|
128
|
-
"@powerhousedao/vetra-studio/connect": { slices: [{
|
|
129
|
-
path: "app.studioMode",
|
|
130
|
-
absent: false
|
|
131
|
-
}] },
|
|
132
|
-
"@powerhousedao/connect/plugins/workflows": { slices: [{
|
|
133
|
-
path: "app.workflowsEnabled",
|
|
134
|
-
absent: false
|
|
135
|
-
}] }
|
|
136
|
-
};
|
|
137
|
-
function valueAt$1(root, dotted) {
|
|
138
|
-
let current = root;
|
|
139
|
-
for (const key of dotted.split(".")) {
|
|
140
|
-
if (current === null || typeof current !== "object") return void 0;
|
|
141
|
-
current = current[key];
|
|
142
|
-
}
|
|
143
|
-
return current;
|
|
144
|
-
}
|
|
145
|
-
/** Whether Connect already serves what the author wrote: every authored leaf
|
|
146
|
-
* equals the served one. An unset leaf asks for nothing, so a partial object
|
|
147
|
-
* (`sections: { remote: { enabled: false } }`) is satisfied by the zeroed
|
|
148
|
-
* slice. */
|
|
149
|
-
function alreadyServed(authored, served) {
|
|
150
|
-
if (authored === void 0 || Object.is(authored, served)) return true;
|
|
151
|
-
if (authored === null || served === null || typeof authored !== "object" || typeof served !== "object" || Array.isArray(authored) !== Array.isArray(served)) return false;
|
|
152
|
-
if (Array.isArray(authored) && authored.length !== served.length) return false;
|
|
153
|
-
const want = authored;
|
|
154
|
-
const have = served;
|
|
155
|
-
return Object.keys(want).every((key) => alreadyServed(want[key], have[key]));
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
59
|
* R1 — the host plugin framework (bridge-runners-to-plugins plan,
|
|
159
60
|
* customization-references/host-core as the blueprint).
|
|
160
61
|
*
|
|
@@ -216,6 +117,27 @@ function entryActiveForVerb(entry, verb) {
|
|
|
216
117
|
return entry.verbs === "*" || entry.verbs.includes(verb);
|
|
217
118
|
}
|
|
218
119
|
/**
|
|
120
|
+
* The appliesTo hierarchy. "reactor" is the base every reactor host extends;
|
|
121
|
+
* "compound" is its own branch (plugins over the member set — e.g. the clint
|
|
122
|
+
* proxy). Host runtimes register their id with a parent; compatibility walks
|
|
123
|
+
* the parent chain.
|
|
124
|
+
*/
|
|
125
|
+
const HOST_TYPE_PARENTS = {
|
|
126
|
+
reactor: null,
|
|
127
|
+
compound: null,
|
|
128
|
+
connect: "reactor",
|
|
129
|
+
switchboard: "reactor",
|
|
130
|
+
mastra: "reactor"
|
|
131
|
+
};
|
|
132
|
+
function hostTypeSatisfies(hostType, appliesTo) {
|
|
133
|
+
let current = hostType;
|
|
134
|
+
while (current !== null) {
|
|
135
|
+
if (current === appliesTo) return true;
|
|
136
|
+
current = current in HOST_TYPE_PARENTS ? HOST_TYPE_PARENTS[current] : null;
|
|
137
|
+
}
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
219
141
|
* The zod single source for host.js blocks (typed-host-configs G1). Every
|
|
220
142
|
* host type is z.input/z.output of these schemas; nothing is hand-mirrored.
|
|
221
143
|
* Top-level host objects and the `reactor` block are STRICT (a typo fails);
|
|
@@ -728,20 +650,350 @@ function defineHostSchemas(build) {
|
|
|
728
650
|
hostSchema: build(resolvedSchemas)
|
|
729
651
|
};
|
|
730
652
|
}
|
|
731
|
-
const declaredSchemas = makeHostSchemas({ tokens: "allow" });
|
|
732
|
-
const resolvedSchemas = makeHostSchemas({ tokens: "forbid" });
|
|
733
|
-
const declaredHostSchemas = declaredSchemas;
|
|
734
|
-
resolvedSchemas.reactorBackendSchema;
|
|
735
|
-
resolvedSchemas.reactorSchema;
|
|
736
|
-
resolvedSchemas.runnerBaseSchema;
|
|
737
|
-
resolvedSchemas.childWrapperSchema;
|
|
738
|
-
resolvedSchemas.childrenSchema;
|
|
739
|
-
resolvedSchemas.reactorHostSchema;
|
|
740
|
-
resolvedSchemas.compoundHostSchema;
|
|
741
|
-
/** The generic compound runner's host: the base with its wiring config. */
|
|
742
|
-
const genericCompound = defineHostSchemas((s) => s.compoundHostSchema.extend({ config: compoundWiringSchema.optional() }).superRefine(refineStartOrder));
|
|
743
|
-
genericCompound.hostSchema;
|
|
744
|
-
genericCompound.declaredHostSchema;
|
|
653
|
+
const declaredSchemas = makeHostSchemas({ tokens: "allow" });
|
|
654
|
+
const resolvedSchemas = makeHostSchemas({ tokens: "forbid" });
|
|
655
|
+
const declaredHostSchemas = declaredSchemas;
|
|
656
|
+
resolvedSchemas.reactorBackendSchema;
|
|
657
|
+
resolvedSchemas.reactorSchema;
|
|
658
|
+
resolvedSchemas.runnerBaseSchema;
|
|
659
|
+
resolvedSchemas.childWrapperSchema;
|
|
660
|
+
resolvedSchemas.childrenSchema;
|
|
661
|
+
resolvedSchemas.reactorHostSchema;
|
|
662
|
+
resolvedSchemas.compoundHostSchema;
|
|
663
|
+
/** The generic compound runner's host: the base with its wiring config. */
|
|
664
|
+
const genericCompound = defineHostSchemas((s) => s.compoundHostSchema.extend({ config: compoundWiringSchema.optional() }).superRefine(refineStartOrder));
|
|
665
|
+
genericCompound.hostSchema;
|
|
666
|
+
genericCompound.declaredHostSchema;
|
|
667
|
+
/** The data folder of a project: where its `.ph` tree is. */
|
|
668
|
+
function instanceDataDir(projectDir = process.cwd(), env = process.env) {
|
|
669
|
+
return path.resolve(env.PH_USER_DATA_DIR ?? projectDir);
|
|
670
|
+
}
|
|
671
|
+
/** The key of `host` (a record key, see `runRecordKey`) in a project. */
|
|
672
|
+
function instanceKey(host, projectDir = process.cwd(), env = process.env) {
|
|
673
|
+
const dataDir = instanceDataDir(projectDir, env);
|
|
674
|
+
return {
|
|
675
|
+
host,
|
|
676
|
+
dataDir,
|
|
677
|
+
id: `${host}@${process.platform === "win32" ? dataDir.toLowerCase() : dataDir}`
|
|
678
|
+
};
|
|
679
|
+
}
|
|
680
|
+
/** The `.ph` tree of a data folder. */
|
|
681
|
+
function instancePhDir(key) {
|
|
682
|
+
return path.join(key.dataDir, ".ph");
|
|
683
|
+
}
|
|
684
|
+
/** Where the run records of a data folder are: the one place they are kept. */
|
|
685
|
+
function instanceRunDir(key) {
|
|
686
|
+
return path.join(instancePhDir(key), "run");
|
|
687
|
+
}
|
|
688
|
+
/**
|
|
689
|
+
* `.ph/run/<host>.json`, version 2 (typed-host-configs 3.6): what a running
|
|
690
|
+
* host and its members produced. Validated on read; a v1 (or any invalid)
|
|
691
|
+
* record reads as "not running". `projectName` is kept beyond the plan's
|
|
692
|
+
* sketch because the live/foreign probe needs it. `host` is the host's
|
|
693
|
+
* `name` (the file key), not its folder. A host an installed package
|
|
694
|
+
* supplies has its record in a folder named after the package,
|
|
695
|
+
* `.ph/run/<package>/<host>.json`, and says which in `package`.
|
|
696
|
+
*/
|
|
697
|
+
const outputsSchema = record(string(), unknown());
|
|
698
|
+
const runRecordMemberSchema = strictObject({
|
|
699
|
+
/** The member's host as the project addresses it: its folder, or
|
|
700
|
+
* `<package>/<host>` for one a package supplies. */
|
|
701
|
+
host: string().min(1),
|
|
702
|
+
runnerModule: string().min(1),
|
|
703
|
+
kind: runnerKindSchema,
|
|
704
|
+
verb: string().min(1),
|
|
705
|
+
outputs: outputsSchema
|
|
706
|
+
});
|
|
707
|
+
const runRecordSchema = strictObject({
|
|
708
|
+
version: literal(2),
|
|
709
|
+
host: hostNameSchema,
|
|
710
|
+
/** The installed package that supplies the host; absent for the
|
|
711
|
+
* project's own. */
|
|
712
|
+
package: string().regex(PACKAGE_NAME_PATTERN).optional(),
|
|
713
|
+
projectName: string(),
|
|
714
|
+
kind: runnerKindSchema,
|
|
715
|
+
verb: string().min(1),
|
|
716
|
+
pid: number().int(),
|
|
717
|
+
startedAt: string(),
|
|
718
|
+
/** Standalone hosts: the runner's outputs. */
|
|
719
|
+
outputs: outputsSchema.optional(),
|
|
720
|
+
/** Compounds: one entry per started member, keyed by member name. */
|
|
721
|
+
members: record(string(), runRecordMemberSchema).optional(),
|
|
722
|
+
/** Host-specific extras (e.g. mcpUrl) a runner wants in the record. */
|
|
723
|
+
extra: record(string(), unknown()).optional()
|
|
724
|
+
});
|
|
725
|
+
/** The key a host's record is filed under: its `name`, behind the package
|
|
726
|
+
* that supplies it when it is not the project's own (`@acme/tools/studio`),
|
|
727
|
+
* as `ph run` addresses the host. */
|
|
728
|
+
function runRecordKey(name, hostPackage) {
|
|
729
|
+
return hostPackage === void 0 ? name : `${hostPackage}/${name}`;
|
|
730
|
+
}
|
|
731
|
+
/** The key of a record as read: where it is filed. */
|
|
732
|
+
function recordKeyOf(record) {
|
|
733
|
+
return runRecordKey(record.host, record.package);
|
|
734
|
+
}
|
|
735
|
+
const runDir = (projectDir, env = process.env) => instanceRunDir(instanceKey("", projectDir, env));
|
|
736
|
+
/** The file of an instance's record: `(host, data folder)` is its path. */
|
|
737
|
+
function runRecordPath(projectDir, key, env) {
|
|
738
|
+
return recordPath(projectDir, key, env);
|
|
739
|
+
}
|
|
740
|
+
function recordPath(projectDir, key, env) {
|
|
741
|
+
const dir = runDir(projectDir, env);
|
|
742
|
+
const slash = key.lastIndexOf("/");
|
|
743
|
+
const hostName = key.slice(slash + 1);
|
|
744
|
+
const pkg = slash === -1 ? void 0 : key.slice(0, slash);
|
|
745
|
+
const folder = pkg === void 0 ? path.resolve(dir) : path.resolve(dir, ...pkg.split("/"));
|
|
746
|
+
const file = path.resolve(folder, `${hostName}.json`);
|
|
747
|
+
if (!hostNameSchema.safeParse(hostName).success || pkg !== void 0 && !PACKAGE_NAME_PATTERN.test(pkg) || path.dirname(file) !== folder) throw new Error(`"${key}" can't name a run record. ${HOST_NAME_MESSAGE}`);
|
|
748
|
+
return file;
|
|
749
|
+
}
|
|
750
|
+
/** The record keys under `.ph/run/`: `<name>.json` files, and those in a
|
|
751
|
+
* package's folder (`<pkg>/` or `@scope/<pkg>/`). */
|
|
752
|
+
function recordKeys(dir) {
|
|
753
|
+
const entries = (at) => {
|
|
754
|
+
try {
|
|
755
|
+
return fs.readdirSync(at, { withFileTypes: true });
|
|
756
|
+
} catch {
|
|
757
|
+
return [];
|
|
758
|
+
}
|
|
759
|
+
};
|
|
760
|
+
const records = (at, prefix) => entries(at).filter((entry) => entry.isFile() && entry.name.endsWith(".json")).map((entry) => `${prefix}${entry.name.slice(0, -5)}`);
|
|
761
|
+
const keys = records(dir, "");
|
|
762
|
+
for (const entry of entries(dir)) {
|
|
763
|
+
if (!entry.isDirectory()) continue;
|
|
764
|
+
const at = path.join(dir, entry.name);
|
|
765
|
+
if (!entry.name.startsWith("@")) {
|
|
766
|
+
keys.push(...records(at, `${entry.name}/`));
|
|
767
|
+
continue;
|
|
768
|
+
}
|
|
769
|
+
for (const inner of entries(at)) {
|
|
770
|
+
if (!inner.isDirectory()) continue;
|
|
771
|
+
keys.push(...records(path.join(at, inner.name), `${entry.name}/${inner.name}/`));
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
return keys;
|
|
775
|
+
}
|
|
776
|
+
function readRunRecord(projectDir, hostName, env = process.env) {
|
|
777
|
+
let raw;
|
|
778
|
+
try {
|
|
779
|
+
raw = JSON.parse(fs.readFileSync(recordPath(projectDir, hostName, env), "utf8"));
|
|
780
|
+
} catch {
|
|
781
|
+
return;
|
|
782
|
+
}
|
|
783
|
+
const parsed = runRecordSchema.safeParse(raw);
|
|
784
|
+
return parsed.success ? parsed.data : void 0;
|
|
785
|
+
}
|
|
786
|
+
/** Every valid v2 record under `.ph/run/`, package hosts' included (invalid
|
|
787
|
+
* and v1 files skipped). */
|
|
788
|
+
function listRunRecords(projectDir, env = process.env) {
|
|
789
|
+
return recordKeys(runDir(projectDir, env)).flatMap((key) => {
|
|
790
|
+
const record = readRunRecord(projectDir, key, env);
|
|
791
|
+
return record ? [record] : [];
|
|
792
|
+
});
|
|
793
|
+
}
|
|
794
|
+
/** The project identity the live/foreign probe compares: package.json
|
|
795
|
+
* `name`, else the folder name. */
|
|
796
|
+
function readProjectName(projectDir) {
|
|
797
|
+
try {
|
|
798
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(projectDir, "package.json"), "utf8"));
|
|
799
|
+
if (typeof pkg.name === "string" && pkg.name) return pkg.name;
|
|
800
|
+
} catch {}
|
|
801
|
+
return path.basename(path.resolve(projectDir));
|
|
802
|
+
}
|
|
803
|
+
function isPidAlive(pid) {
|
|
804
|
+
try {
|
|
805
|
+
process.kill(pid, 0);
|
|
806
|
+
return true;
|
|
807
|
+
} catch (error) {
|
|
808
|
+
return error.code === "EPERM";
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
/** When a process started, in ms since the epoch; undefined when the
|
|
812
|
+
* platform does not tell (the process is gone, the tool is missing). */
|
|
813
|
+
function processStartedAtMs(pid) {
|
|
814
|
+
try {
|
|
815
|
+
if (process.platform === "linux") {
|
|
816
|
+
const stat = fs.readFileSync(`/proc/${pid}/stat`, "utf8");
|
|
817
|
+
const ticks = Number(stat.slice(stat.lastIndexOf(")") + 2).split(" ")[19]);
|
|
818
|
+
const boot = /^btime (\d+)$/m.exec(fs.readFileSync("/proc/stat", "utf8"));
|
|
819
|
+
if (!boot || !Number.isFinite(ticks)) return void 0;
|
|
820
|
+
return (Number(boot[1]) + ticks / 100) * 1e3;
|
|
821
|
+
}
|
|
822
|
+
const [command, args] = process.platform === "win32" ? ["powershell.exe", [
|
|
823
|
+
"-NoProfile",
|
|
824
|
+
"-NonInteractive",
|
|
825
|
+
"-Command",
|
|
826
|
+
`(Get-Process -Id ${pid}).StartTime.ToUniversalTime().ToString('o')`
|
|
827
|
+
]] : ["ps", [
|
|
828
|
+
"-o",
|
|
829
|
+
"lstart=",
|
|
830
|
+
"-p",
|
|
831
|
+
String(pid)
|
|
832
|
+
]];
|
|
833
|
+
const out = execFileSync(command, args, {
|
|
834
|
+
encoding: "utf8",
|
|
835
|
+
stdio: [
|
|
836
|
+
"ignore",
|
|
837
|
+
"pipe",
|
|
838
|
+
"ignore"
|
|
839
|
+
],
|
|
840
|
+
timeout: 1e4,
|
|
841
|
+
windowsHide: true,
|
|
842
|
+
env: {
|
|
843
|
+
...process.env,
|
|
844
|
+
LC_ALL: "C"
|
|
845
|
+
}
|
|
846
|
+
}).trim();
|
|
847
|
+
const started = Date.parse(out);
|
|
848
|
+
return Number.isFinite(started) ? started : void 0;
|
|
849
|
+
} catch {
|
|
850
|
+
return;
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
const START_SLACK_MS = 5e3;
|
|
854
|
+
const confirmedRecords = /* @__PURE__ */ new Set();
|
|
855
|
+
/** True when the recorded pid now names another process: one that started
|
|
856
|
+
* after the record was written. False when that cannot be told. */
|
|
857
|
+
function isPidReused(record) {
|
|
858
|
+
if (record.pid === process.pid) return false;
|
|
859
|
+
const recordedAt = Date.parse(record.startedAt);
|
|
860
|
+
if (!Number.isFinite(recordedAt)) return false;
|
|
861
|
+
const key = `${record.pid}:${record.startedAt}`;
|
|
862
|
+
if (confirmedRecords.has(key)) return false;
|
|
863
|
+
const startedAt = processStartedAtMs(record.pid);
|
|
864
|
+
if (startedAt === void 0) return false;
|
|
865
|
+
if (startedAt > recordedAt + START_SLACK_MS) return true;
|
|
866
|
+
confirmedRecords.add(key);
|
|
867
|
+
return false;
|
|
868
|
+
}
|
|
869
|
+
/**
|
|
870
|
+
* Decide whether the recorded instance is this project's live host.
|
|
871
|
+
*
|
|
872
|
+
* pid liveness alone proves nothing (pids are reused): a live pid counts
|
|
873
|
+
* only when its process started before the record was written. The recorded
|
|
874
|
+
* projectName is what separates "my instance" from "a different project that
|
|
875
|
+
* happens to hold this storage root" — the confusion the vetra lock exists to
|
|
876
|
+
* prevent. A stale record (dead or reused pid) is reported so the caller can
|
|
877
|
+
* clear it; a foreign one (live pid, different project) is left alone.
|
|
878
|
+
*/
|
|
879
|
+
function probeRun(projectDir, hostName, projectName, env = process.env) {
|
|
880
|
+
const record = readRunRecord(projectDir, hostName, env);
|
|
881
|
+
if (!record) return { status: "none" };
|
|
882
|
+
if (!isPidAlive(record.pid) || isPidReused(record)) return {
|
|
883
|
+
status: "stale",
|
|
884
|
+
record
|
|
885
|
+
};
|
|
886
|
+
if (record.projectName !== projectName) return {
|
|
887
|
+
status: "foreign",
|
|
888
|
+
record
|
|
889
|
+
};
|
|
890
|
+
return {
|
|
891
|
+
status: "live",
|
|
892
|
+
record
|
|
893
|
+
};
|
|
894
|
+
}
|
|
895
|
+
//#endregion
|
|
896
|
+
//#region ../../packages/host-core/dist/compound-g6x_KkWp.mjs
|
|
897
|
+
/**
|
|
898
|
+
* The connect config slices each built-in Connect plugin owns, by specifier
|
|
899
|
+
* (typed-host-configs 1.6). Under a declared composition Connect zeroes a
|
|
900
|
+
* slice whose plugin is absent — presence is activation — so an authored
|
|
901
|
+
* value there is dead config. Connect's built-ins are browser modules with no
|
|
902
|
+
* Node-resolvable identity, so their ownership is declared here as data; a
|
|
903
|
+
* Connect test pins it to plugin-host's zeroing.
|
|
904
|
+
*/
|
|
905
|
+
const CONNECT_PLUGIN_OWNED_SLICES = {
|
|
906
|
+
"@powerhousedao/connect/plugins/generic": { slices: [
|
|
907
|
+
{
|
|
908
|
+
path: "drives.allowAddDrive",
|
|
909
|
+
absent: false,
|
|
910
|
+
entryKey: "allowAddDrive"
|
|
911
|
+
},
|
|
912
|
+
{
|
|
913
|
+
path: "drives.sections",
|
|
914
|
+
absent: {
|
|
915
|
+
remote: {
|
|
916
|
+
enabled: false,
|
|
917
|
+
allowAdd: false,
|
|
918
|
+
allowDelete: false
|
|
919
|
+
},
|
|
920
|
+
local: {
|
|
921
|
+
enabled: false,
|
|
922
|
+
allowAdd: false,
|
|
923
|
+
allowDelete: false
|
|
924
|
+
}
|
|
925
|
+
},
|
|
926
|
+
entryKey: "sections"
|
|
927
|
+
},
|
|
928
|
+
{
|
|
929
|
+
path: "drives.icons",
|
|
930
|
+
absent: null,
|
|
931
|
+
entryKey: "icons"
|
|
932
|
+
},
|
|
933
|
+
{
|
|
934
|
+
path: "home.background",
|
|
935
|
+
absent: null,
|
|
936
|
+
entryKey: "homeBackground"
|
|
937
|
+
}
|
|
938
|
+
] },
|
|
939
|
+
"@powerhousedao/connect/plugins/sentry": { slices: [{
|
|
940
|
+
path: "sentry.dsn",
|
|
941
|
+
absent: null,
|
|
942
|
+
entryKey: "dsn"
|
|
943
|
+
}] },
|
|
944
|
+
"@powerhousedao/connect/plugins/openpanel": {
|
|
945
|
+
slices: [
|
|
946
|
+
{
|
|
947
|
+
path: "openPanel.clientId",
|
|
948
|
+
absent: "",
|
|
949
|
+
entryKey: "clientId"
|
|
950
|
+
},
|
|
951
|
+
{
|
|
952
|
+
path: "openPanel.trackUiEvents",
|
|
953
|
+
absent: false,
|
|
954
|
+
entryKey: "trackUiEvents"
|
|
955
|
+
},
|
|
956
|
+
{
|
|
957
|
+
path: "openPanel.trackOperations",
|
|
958
|
+
absent: false,
|
|
959
|
+
entryKey: "trackOperations"
|
|
960
|
+
}
|
|
961
|
+
],
|
|
962
|
+
inertUnless: "openPanel.clientId"
|
|
963
|
+
},
|
|
964
|
+
"@powerhousedao/connect/plugins/assistant": { slices: [{
|
|
965
|
+
path: "ai.assistantEnabled",
|
|
966
|
+
absent: false
|
|
967
|
+
}] },
|
|
968
|
+
"@powerhousedao/vetra-studio/connect": { slices: [{
|
|
969
|
+
path: "app.studioMode",
|
|
970
|
+
absent: false
|
|
971
|
+
}] },
|
|
972
|
+
"@powerhousedao/connect/plugins/workflows": { slices: [{
|
|
973
|
+
path: "app.workflowsEnabled",
|
|
974
|
+
absent: false
|
|
975
|
+
}] }
|
|
976
|
+
};
|
|
977
|
+
function valueAt$1(root, dotted) {
|
|
978
|
+
let current = root;
|
|
979
|
+
for (const key of dotted.split(".")) {
|
|
980
|
+
if (current === null || typeof current !== "object") return void 0;
|
|
981
|
+
current = current[key];
|
|
982
|
+
}
|
|
983
|
+
return current;
|
|
984
|
+
}
|
|
985
|
+
/** Whether Connect already serves what the author wrote: every authored leaf
|
|
986
|
+
* equals the served one. An unset leaf asks for nothing, so a partial object
|
|
987
|
+
* (`sections: { remote: { enabled: false } }`) is satisfied by the zeroed
|
|
988
|
+
* slice. */
|
|
989
|
+
function alreadyServed(authored, served) {
|
|
990
|
+
if (authored === void 0 || Object.is(authored, served)) return true;
|
|
991
|
+
if (authored === null || served === null || typeof authored !== "object" || typeof served !== "object" || Array.isArray(authored) !== Array.isArray(served)) return false;
|
|
992
|
+
if (Array.isArray(authored) && authored.length !== served.length) return false;
|
|
993
|
+
const want = authored;
|
|
994
|
+
const have = served;
|
|
995
|
+
return Object.keys(want).every((key) => alreadyServed(want[key], have[key]));
|
|
996
|
+
}
|
|
745
997
|
/**
|
|
746
998
|
* How a host is addressed (decision D5). A bare name (`switchboard`) is the
|
|
747
999
|
* project's own host, `<project>/hosts/switchboard/`, always: a package
|
|
@@ -870,6 +1122,44 @@ function isHostPluginShape(value) {
|
|
|
870
1122
|
return value !== null && typeof value === "object" && typeof value.name === "string";
|
|
871
1123
|
}
|
|
872
1124
|
/**
|
|
1125
|
+
* Resolve host.js plugin entries into live plugins for one host boot:
|
|
1126
|
+
* verb-filter → module resolution from the project tree (default condition,
|
|
1127
|
+
* like runners) → factory/object contract → config validation → appliesTo.
|
|
1128
|
+
*/
|
|
1129
|
+
async function resolveHostPlugins(projectRoot, hostType, verb, entries, where) {
|
|
1130
|
+
const normalized = normalizePluginEntries(entries, where);
|
|
1131
|
+
const projectRequire = createRequire(pathToFileURL(path.join(projectRoot, "package.json")).href);
|
|
1132
|
+
const resolved = [];
|
|
1133
|
+
for (const entry of normalized) {
|
|
1134
|
+
if (!entryActiveForVerb(entry, verb)) continue;
|
|
1135
|
+
let file;
|
|
1136
|
+
try {
|
|
1137
|
+
file = projectRequire.resolve(entry.module);
|
|
1138
|
+
} catch {
|
|
1139
|
+
throw new PluginError(`${where}: cannot resolve plugin "${entry.module}" from ${projectRoot}.`, "Plugins resolve from the project dependency tree, exactly like runner modules.");
|
|
1140
|
+
}
|
|
1141
|
+
const exported = (await import(pathToFileURL(file).href)).default;
|
|
1142
|
+
let plugin;
|
|
1143
|
+
if (typeof exported === "function") plugin = exported(entry.config);
|
|
1144
|
+
else if (isHostPluginShape(exported)) {
|
|
1145
|
+
if (Object.keys(entry.config).length > 0 && !exported.configSchema) throw new PluginError(`${where}: plugin "${entry.module}" takes no config, but the entry passes one.`);
|
|
1146
|
+
plugin = exported;
|
|
1147
|
+
} else throw new PluginError(`${where}: "${entry.module}" does not default-export a plugin object or factory.`, "Export `{ name, hooks?, contributions? }` or `(config) => plugin`.");
|
|
1148
|
+
if (plugin.configSchema) {
|
|
1149
|
+
const parsed = plugin.configSchema.safeParse(entry.config);
|
|
1150
|
+
if (!parsed.success) throw new PluginError(`${where}: config for plugin "${plugin.name}" is invalid:\n` + prettifyError(parsed.error));
|
|
1151
|
+
}
|
|
1152
|
+
const appliesTo = plugin.appliesTo ?? "reactor";
|
|
1153
|
+
if (!hostTypeSatisfies(hostType, appliesTo)) throw new PluginError(`${where}: plugin "${plugin.name}" applies to "${appliesTo}" hosts, but this host is "${hostType}".`);
|
|
1154
|
+
resolved.push({
|
|
1155
|
+
entry,
|
|
1156
|
+
plugin,
|
|
1157
|
+
provenance: "dependency"
|
|
1158
|
+
});
|
|
1159
|
+
}
|
|
1160
|
+
return resolved;
|
|
1161
|
+
}
|
|
1162
|
+
/**
|
|
873
1163
|
* LENIENT resolution for diagnostics (`ph run <host> --explain drives`):
|
|
874
1164
|
* collects the drive contributions of the entries active for `verb`. Unlike
|
|
875
1165
|
* resolveHostPlugins it does not know the host type (so appliesTo is not
|
|
@@ -2188,7 +2478,7 @@ function getVerb(runner, specifier, verb) {
|
|
|
2188
2478
|
if (typeof candidate !== "function" || !listVerbs(runner).includes(verb)) throw new RunnerError(`Runner "${specifier}" does not support the verb "${verb}". Supported verbs: ${listVerbs(runner).join(", ")}.`);
|
|
2189
2479
|
return candidate;
|
|
2190
2480
|
}
|
|
2191
|
-
function isRecord$
|
|
2481
|
+
function isRecord$4(value) {
|
|
2192
2482
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2193
2483
|
}
|
|
2194
2484
|
/** reactor XOR children, decided by the runner's declared `kind`. */
|
|
@@ -2213,7 +2503,7 @@ function assertKindShape(kind, specifier, host, file) {
|
|
|
2213
2503
|
* this runner exports. */
|
|
2214
2504
|
function knownVerbIssues(runner, specifier, host) {
|
|
2215
2505
|
const options = host.runner;
|
|
2216
|
-
if (!isRecord$
|
|
2506
|
+
if (!isRecord$4(options)) return [];
|
|
2217
2507
|
const verbs = listVerbs(runner);
|
|
2218
2508
|
const unknownVerb = (verb) => typeof verb === "string" && !verbs.includes(verb);
|
|
2219
2509
|
const issues = [];
|
|
@@ -2222,7 +2512,7 @@ function knownVerbIssues(runner, specifier, host) {
|
|
|
2222
2512
|
message: `runner.defaultVerb "${options.defaultVerb}" is not a verb of "${specifier}". Supported verbs: ${verbs.join(", ")}.`
|
|
2223
2513
|
});
|
|
2224
2514
|
(Array.isArray(options.plugins) ? options.plugins : []).forEach((entry, index) => {
|
|
2225
|
-
if (!isRecord$
|
|
2515
|
+
if (!isRecord$4(entry) || !Array.isArray(entry.verbs)) return;
|
|
2226
2516
|
const scoped = entry.verbs;
|
|
2227
2517
|
for (const bad of scoped.filter(unknownVerb)) issues.push({
|
|
2228
2518
|
path: `runner.plugins[${index}].verbs`,
|
|
@@ -2237,7 +2527,7 @@ function formatIssues(issues) {
|
|
|
2237
2527
|
function valueAt(host, path) {
|
|
2238
2528
|
let current = host;
|
|
2239
2529
|
for (const key of path) if (Array.isArray(current) && typeof key === "number") current = current[key];
|
|
2240
|
-
else if (isRecord$
|
|
2530
|
+
else if (isRecord$4(current) && typeof key === "string") current = current[key];
|
|
2241
2531
|
else return;
|
|
2242
2532
|
return current;
|
|
2243
2533
|
}
|
|
@@ -2253,7 +2543,7 @@ function validateHost(runner, specifier, host, file, options = {}) {
|
|
|
2253
2543
|
/** What `validateHost` checks, as data: nothing throws. */
|
|
2254
2544
|
function hostSchemaIssues(runner, schema, specifier, host, options = {}) {
|
|
2255
2545
|
const issues = [];
|
|
2256
|
-
if (isRecord$
|
|
2546
|
+
if (isRecord$4(host)) {
|
|
2257
2547
|
issues.push(...kindShapeIssues(runner.kind, specifier, host));
|
|
2258
2548
|
if (options.tokens !== "allow") {
|
|
2259
2549
|
const token = findToken(host);
|
|
@@ -2305,7 +2595,7 @@ function validateDeclaredHost(runner, specifier, host, file, options = {}) {
|
|
|
2305
2595
|
const issues = checkTokenSites(host);
|
|
2306
2596
|
if (options.outputsSchemaOf) issues.push(...checkOutputPaths(host, options.outputsSchemaOf));
|
|
2307
2597
|
if (issues.length > 0) throw new RunnerError(`${file}: invalid output token:\n${formatIssues(issues)}`);
|
|
2308
|
-
if (isRecord$
|
|
2598
|
+
if (isRecord$4(host)) assertKindShape(runner.kind, specifier, host, file);
|
|
2309
2599
|
if (!runner.declaredHostSchema) return;
|
|
2310
2600
|
parseHost(runner, runner.declaredHostSchema, specifier, host, file, { tokens: "allow" });
|
|
2311
2601
|
}
|
|
@@ -2661,13 +2951,13 @@ function computeOutputsHash(input) {
|
|
|
2661
2951
|
function isZodSchema(value) {
|
|
2662
2952
|
return value !== null && typeof value === "object" && "_zod" in value;
|
|
2663
2953
|
}
|
|
2664
|
-
function isRecord$
|
|
2954
|
+
function isRecord$3(value) {
|
|
2665
2955
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
2666
2956
|
}
|
|
2667
2957
|
/** Local (non-remote) slugs from a drive declaration list. */
|
|
2668
2958
|
function localDriveSlugs(drives) {
|
|
2669
2959
|
if (!Array.isArray(drives)) return [];
|
|
2670
|
-
return drives.flatMap((drive) => isRecord$
|
|
2960
|
+
return drives.flatMap((drive) => isRecord$3(drive) && typeof drive.slug === "string" && drive.remote === void 0 ? [drive.slug] : []);
|
|
2671
2961
|
}
|
|
2672
2962
|
/**
|
|
2673
2963
|
* Describes the outputs a host's creation produces, for `ph generate hosts`
|
|
@@ -2694,7 +2984,7 @@ async function describeHostOutputs(projectRoot, hostName) {
|
|
|
2694
2984
|
unrepresentable: "any"
|
|
2695
2985
|
});
|
|
2696
2986
|
const reactor = host.reactor;
|
|
2697
|
-
const drives = localDriveSlugs(isRecord$
|
|
2987
|
+
const drives = localDriveSlugs(isRecord$3(reactor) ? reactor.drives : []);
|
|
2698
2988
|
const entries = (host.runner.plugins ?? []).map((entry) => typeof entry === "string" ? entry : {
|
|
2699
2989
|
...entry,
|
|
2700
2990
|
verbs: "*"
|
|
@@ -2766,240 +3056,54 @@ function splitRunArgv(args) {
|
|
|
2766
3056
|
return result;
|
|
2767
3057
|
}
|
|
2768
3058
|
/**
|
|
2769
|
-
*
|
|
2770
|
-
*
|
|
2771
|
-
*
|
|
2772
|
-
*
|
|
2773
|
-
*
|
|
2774
|
-
* supplies has its record in a folder named after the package,
|
|
2775
|
-
* `.ph/run/<package>/<host>.json`, and says which in `package`.
|
|
3059
|
+
* Sign-in by link (F3d), as a stack sees it: the compound makes a secret at
|
|
3060
|
+
* each start, hands it to the members that serve Connect, and keeps it in
|
|
3061
|
+
* its owner-only run record (`extra.signIn`), beside the control channel's
|
|
3062
|
+
* token. Whoever holds the record mints a link with a fresh code: the
|
|
3063
|
+
* compound at start, the Cli of a stack that has one, a second start.
|
|
2776
3064
|
*/
|
|
2777
|
-
const
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
const
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
startedAt: string(),
|
|
2798
|
-
/** Standalone hosts: the runner's outputs. */
|
|
2799
|
-
outputs: outputsSchema.optional(),
|
|
2800
|
-
/** Compounds: one entry per started member, keyed by member name. */
|
|
2801
|
-
members: record(string(), runRecordMemberSchema).optional(),
|
|
2802
|
-
/** Host-specific extras (e.g. mcpUrl) a runner wants in the record. */
|
|
2803
|
-
extra: record(string(), unknown()).optional()
|
|
2804
|
-
});
|
|
2805
|
-
/** The key a host's record is filed under: its `name`, behind the package
|
|
2806
|
-
* that supplies it when it is not the project's own (`@acme/tools/studio`),
|
|
2807
|
-
* as `ph run` addresses the host. */
|
|
2808
|
-
function runRecordKey(name, hostPackage) {
|
|
2809
|
-
return hostPackage === void 0 ? name : `${hostPackage}/${name}`;
|
|
2810
|
-
}
|
|
2811
|
-
const runDir = (projectDir, env = process.env) => path.join(resolvePhDir(projectDir, env), "run");
|
|
2812
|
-
function recordPath(projectDir, key, env) {
|
|
2813
|
-
const dir = runDir(projectDir, env);
|
|
2814
|
-
const slash = key.lastIndexOf("/");
|
|
2815
|
-
const hostName = key.slice(slash + 1);
|
|
2816
|
-
const pkg = slash === -1 ? void 0 : key.slice(0, slash);
|
|
2817
|
-
const folder = pkg === void 0 ? path.resolve(dir) : path.resolve(dir, ...pkg.split("/"));
|
|
2818
|
-
const file = path.resolve(folder, `${hostName}.json`);
|
|
2819
|
-
if (!hostNameSchema.safeParse(hostName).success || pkg !== void 0 && !PACKAGE_NAME_PATTERN.test(pkg) || path.dirname(file) !== folder) throw new Error(`"${key}" can't name a run record. ${HOST_NAME_MESSAGE}`);
|
|
2820
|
-
return file;
|
|
2821
|
-
}
|
|
2822
|
-
/** The record keys under `.ph/run/`: `<name>.json` files, and those in a
|
|
2823
|
-
* package's folder (`<pkg>/` or `@scope/<pkg>/`). */
|
|
2824
|
-
function recordKeys(dir) {
|
|
2825
|
-
const entries = (at) => {
|
|
2826
|
-
try {
|
|
2827
|
-
return fs.readdirSync(at, { withFileTypes: true });
|
|
2828
|
-
} catch {
|
|
2829
|
-
return [];
|
|
2830
|
-
}
|
|
2831
|
-
};
|
|
2832
|
-
const records = (at, prefix) => entries(at).filter((entry) => entry.isFile() && entry.name.endsWith(".json")).map((entry) => `${prefix}${entry.name.slice(0, -5)}`);
|
|
2833
|
-
const keys = records(dir, "");
|
|
2834
|
-
for (const entry of entries(dir)) {
|
|
2835
|
-
if (!entry.isDirectory()) continue;
|
|
2836
|
-
const at = path.join(dir, entry.name);
|
|
2837
|
-
if (!entry.name.startsWith("@")) {
|
|
2838
|
-
keys.push(...records(at, `${entry.name}/`));
|
|
2839
|
-
continue;
|
|
2840
|
-
}
|
|
2841
|
-
for (const inner of entries(at)) {
|
|
2842
|
-
if (!inner.isDirectory()) continue;
|
|
2843
|
-
keys.push(...records(path.join(at, inner.name), `${entry.name}/${inner.name}/`));
|
|
2844
|
-
}
|
|
2845
|
-
}
|
|
2846
|
-
return keys;
|
|
2847
|
-
}
|
|
2848
|
-
function readRunRecord(projectDir, hostName, env = process.env) {
|
|
2849
|
-
let raw;
|
|
2850
|
-
try {
|
|
2851
|
-
raw = JSON.parse(fs.readFileSync(recordPath(projectDir, hostName, env), "utf8"));
|
|
2852
|
-
} catch {
|
|
2853
|
-
return;
|
|
2854
|
-
}
|
|
2855
|
-
const parsed = runRecordSchema.safeParse(raw);
|
|
2856
|
-
return parsed.success ? parsed.data : void 0;
|
|
2857
|
-
}
|
|
2858
|
-
/** Every valid v2 record under `.ph/run/`, package hosts' included (invalid
|
|
2859
|
-
* and v1 files skipped). */
|
|
2860
|
-
function listRunRecords(projectDir, env = process.env) {
|
|
2861
|
-
return recordKeys(runDir(projectDir, env)).flatMap((key) => {
|
|
2862
|
-
const record = readRunRecord(projectDir, key, env);
|
|
2863
|
-
return record ? [record] : [];
|
|
3065
|
+
const isRecord$2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3066
|
+
/** The secret a stack's record keeps, if any. */
|
|
3067
|
+
function signInSecretOf(record) {
|
|
3068
|
+
const signIn = record?.extra?.signIn;
|
|
3069
|
+
return isRecord$2(signIn) && typeof signIn.secret === "string" ? signIn.secret : void 0;
|
|
3070
|
+
}
|
|
3071
|
+
/** The members of a stack that sign pages in by link (their outputs say
|
|
3072
|
+
* `localSignIn`), and their app URLs. */
|
|
3073
|
+
function signInMembersOf(members) {
|
|
3074
|
+
return Object.entries(members).flatMap(([member, entry]) => {
|
|
3075
|
+
const outputs = entry.outputs;
|
|
3076
|
+
if (!isRecord$2(outputs) || !isRecord$2(outputs.localSignIn)) return [];
|
|
3077
|
+
const app = isRecord$2(outputs.endpoints) ? outputs.endpoints.connect : void 0;
|
|
3078
|
+
if (typeof app !== "string") return [];
|
|
3079
|
+
const { open } = outputs.localSignIn;
|
|
3080
|
+
return [{
|
|
3081
|
+
member,
|
|
3082
|
+
app,
|
|
3083
|
+
...typeof open === "boolean" ? { open } : {}
|
|
3084
|
+
}];
|
|
2864
3085
|
});
|
|
2865
3086
|
}
|
|
2866
|
-
/**
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
}
|
|
2875
|
-
function isPidAlive(pid) {
|
|
2876
|
-
try {
|
|
2877
|
-
process.kill(pid, 0);
|
|
2878
|
-
return true;
|
|
2879
|
-
} catch (error) {
|
|
2880
|
-
return error.code === "EPERM";
|
|
2881
|
-
}
|
|
3087
|
+
/** A fresh link for each member of the stack that signs pages in by link. */
|
|
3088
|
+
function signInLinksOf(record) {
|
|
3089
|
+
const secret = signInSecretOf(record);
|
|
3090
|
+
if (!secret) return [];
|
|
3091
|
+
return signInMembersOf(record.members ?? {}).map(({ member, app, open }) => ({
|
|
3092
|
+
member,
|
|
3093
|
+
link: signInLink(app, secret),
|
|
3094
|
+
...open === void 0 ? {} : { open }
|
|
3095
|
+
}));
|
|
2882
3096
|
}
|
|
2883
|
-
/**
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
if (
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
if (!boot || !Number.isFinite(ticks)) return void 0;
|
|
2892
|
-
return (Number(boot[1]) + ticks / 100) * 1e3;
|
|
2893
|
-
}
|
|
2894
|
-
const [command, args] = process.platform === "win32" ? ["powershell.exe", [
|
|
2895
|
-
"-NoProfile",
|
|
2896
|
-
"-NonInteractive",
|
|
2897
|
-
"-Command",
|
|
2898
|
-
`(Get-Process -Id ${pid}).StartTime.ToUniversalTime().ToString('o')`
|
|
2899
|
-
]] : ["ps", [
|
|
2900
|
-
"-o",
|
|
2901
|
-
"lstart=",
|
|
2902
|
-
"-p",
|
|
2903
|
-
String(pid)
|
|
2904
|
-
]];
|
|
2905
|
-
const out = execFileSync(command, args, {
|
|
2906
|
-
encoding: "utf8",
|
|
2907
|
-
stdio: [
|
|
2908
|
-
"ignore",
|
|
2909
|
-
"pipe",
|
|
2910
|
-
"ignore"
|
|
2911
|
-
],
|
|
2912
|
-
timeout: 1e4,
|
|
2913
|
-
windowsHide: true,
|
|
2914
|
-
env: {
|
|
2915
|
-
...process.env,
|
|
2916
|
-
LC_ALL: "C"
|
|
2917
|
-
}
|
|
2918
|
-
}).trim();
|
|
2919
|
-
const started = Date.parse(out);
|
|
2920
|
-
return Number.isFinite(started) ? started : void 0;
|
|
2921
|
-
} catch {
|
|
2922
|
-
return;
|
|
3097
|
+
/** Prints each link, and opens it as asked, else on a terminal. */
|
|
3098
|
+
function announceSignInLinks(links, open = openInBrowser) {
|
|
3099
|
+
for (const { link, open: asked } of links) {
|
|
3100
|
+
console.log(` ➜ Sign in: ${link}`);
|
|
3101
|
+
if (opensBrowser({
|
|
3102
|
+
asked,
|
|
3103
|
+
isTTY: process.stdout.isTTY
|
|
3104
|
+
})) open(link);
|
|
2923
3105
|
}
|
|
2924
3106
|
}
|
|
2925
|
-
const START_SLACK_MS = 5e3;
|
|
2926
|
-
const confirmedRecords = /* @__PURE__ */ new Set();
|
|
2927
|
-
/** True when the recorded pid now names another process: one that started
|
|
2928
|
-
* after the record was written. False when that cannot be told. */
|
|
2929
|
-
function isPidReused(record) {
|
|
2930
|
-
if (record.pid === process.pid) return false;
|
|
2931
|
-
const recordedAt = Date.parse(record.startedAt);
|
|
2932
|
-
if (!Number.isFinite(recordedAt)) return false;
|
|
2933
|
-
const key = `${record.pid}:${record.startedAt}`;
|
|
2934
|
-
if (confirmedRecords.has(key)) return false;
|
|
2935
|
-
const startedAt = processStartedAtMs(record.pid);
|
|
2936
|
-
if (startedAt === void 0) return false;
|
|
2937
|
-
if (startedAt > recordedAt + START_SLACK_MS) return true;
|
|
2938
|
-
confirmedRecords.add(key);
|
|
2939
|
-
return false;
|
|
2940
|
-
}
|
|
2941
|
-
/**
|
|
2942
|
-
* Decide whether the recorded instance is this project's live host.
|
|
2943
|
-
*
|
|
2944
|
-
* pid liveness alone proves nothing (pids are reused): a live pid counts
|
|
2945
|
-
* only when its process started before the record was written. The recorded
|
|
2946
|
-
* projectName is what separates "my instance" from "a different project that
|
|
2947
|
-
* happens to hold this storage root" — the confusion the vetra lock exists to
|
|
2948
|
-
* prevent. A stale record (dead or reused pid) is reported so the caller can
|
|
2949
|
-
* clear it; a foreign one (live pid, different project) is left alone.
|
|
2950
|
-
*/
|
|
2951
|
-
function probeRun(projectDir, hostName, projectName, env = process.env) {
|
|
2952
|
-
const record = readRunRecord(projectDir, hostName, env);
|
|
2953
|
-
if (!record) return { status: "none" };
|
|
2954
|
-
if (!isPidAlive(record.pid) || isPidReused(record)) return {
|
|
2955
|
-
status: "stale",
|
|
2956
|
-
record
|
|
2957
|
-
};
|
|
2958
|
-
if (record.projectName !== projectName) return {
|
|
2959
|
-
status: "foreign",
|
|
2960
|
-
record
|
|
2961
|
-
};
|
|
2962
|
-
return {
|
|
2963
|
-
status: "live",
|
|
2964
|
-
record
|
|
2965
|
-
};
|
|
2966
|
-
}
|
|
2967
|
-
/**
|
|
2968
|
-
* Windows has no SIGTERM: `process.kill(pid, "SIGTERM")` ends the process at
|
|
2969
|
-
* once, so no handler runs and a stack's stores are left as a crash leaves
|
|
2970
|
-
* them. A started host therefore listens on a pipe named after its pid, and
|
|
2971
|
-
* a connection to it is delivered as the SIGTERM it stands for. Elsewhere
|
|
2972
|
-
* the signal itself does this, and there is no channel.
|
|
2973
|
-
*/
|
|
2974
|
-
function stopChannelPath(pid, platform = process.platform) {
|
|
2975
|
-
return platform === "win32" ? `\\\\.\\pipe\\ph-stop-${pid}` : void 0;
|
|
2976
|
-
}
|
|
2977
|
-
const ASK_TIMEOUT_MS = 2e3;
|
|
2978
|
-
/** Connects to a stop channel; true once the listener took the request. */
|
|
2979
|
-
function askToStop(channel, timeoutMs = ASK_TIMEOUT_MS) {
|
|
2980
|
-
return new Promise((resolve) => {
|
|
2981
|
-
let connected = false;
|
|
2982
|
-
const socket = net.connect(channel);
|
|
2983
|
-
socket.setTimeout(timeoutMs, () => socket.destroy());
|
|
2984
|
-
socket.once("connect", () => connected = true);
|
|
2985
|
-
socket.on("error", () => void 0);
|
|
2986
|
-
socket.once("close", () => resolve(connected));
|
|
2987
|
-
socket.resume();
|
|
2988
|
-
});
|
|
2989
|
-
}
|
|
2990
|
-
/**
|
|
2991
|
-
* Asks the process to stop as SIGTERM would. False when it could not be
|
|
2992
|
-
* asked: on Windows a process without a stop channel (started by an older
|
|
2993
|
-
* version, or not a host), which only a kill ends.
|
|
2994
|
-
*/
|
|
2995
|
-
async function requestStop(pid, platform = process.platform) {
|
|
2996
|
-
const channel = stopChannelPath(pid, platform);
|
|
2997
|
-
if (channel) return askToStop(channel);
|
|
2998
|
-
try {
|
|
2999
|
-
process.kill(pid, "SIGTERM");
|
|
3000
|
-
} catch {}
|
|
3001
|
-
return true;
|
|
3002
|
-
}
|
|
3003
3107
|
/** Generic compound rule: `reactor`/`config` replace, `runner` key-merges. */
|
|
3004
3108
|
function applyChildWrapper(base, wrapper) {
|
|
3005
3109
|
const reactor = wrapper.reactor ?? base.reactor;
|
|
@@ -3288,7 +3392,7 @@ async function memberCycle(projectRoot, prepared) {
|
|
|
3288
3392
|
}
|
|
3289
3393
|
}
|
|
3290
3394
|
//#endregion
|
|
3291
|
-
export {
|
|
3395
|
+
export { unsetEnvMessage as $, memberVerbOf as A, producerOutputsSchemas as B, isPlainObject as C, memberCycle as D, loadProducers as E, planCompound as F, resolvePluginContributions as G, resolveHostOutputs as H, planForeground as I, runnerOutputsSchema as J, resolveRunnerModule as K, prepareMember as L, outputRefsOf as M, outputSitesOf as N, memberForRef as O, packageBuildRefusal as P, takesCspRegistrySync as Q, probeHostsFolder as R, isBuiltinEnvName as S, loadHost as T, resolveHostPlugins as U, renderTokens as V, resolvePackageRoot as W, splitRunArgv as X, signInLinksOf as Y, substituteBuiltinEnv as Z, findRemovedForms as _, STORE_VERBS as a, drivesSchema as at, hostFileLabel as b, applyChildWrapper as c, isToken as ct, collectTokenSites as d, probeRun as dt, validateDeclaredHost as et, compoundOutputSource as f, projectDriveIdWith as ft, findDeadConnectConfig as g, runRecordPath as gt, envSitesOf as h, runRecordKey as ht, RunnerError as i, declaredHostSchemas as it, moduleRootOf as j, memberProcessOf as k, checkOutputPaths as l, normalizePluginEntries as lt, describeToken as m, recordKeyOf as mt, HostLoadError as n, withoutHostsMessage as nt, TokenResolutionError as o, entryActiveForVerb as ot, compoundStartVerb as p, readProjectName as pt, runRecordOutputSource as q, ONE_SHOT_VERBS as r, PluginError as rt, announceSignInLinks as s, instanceKey as st, CONNECT_RUNNER as t, validateHost as tt, checkTokenSites as u, normalizePluginEntry as ut, formatPath as v, kindShapeIssues as w, hostSchemaIssues as x, getVerb as y, processResolveEnv as z };
|
|
3292
3396
|
|
|
3293
|
-
//# sourceMappingURL=compound-
|
|
3294
|
-
//# debugId=
|
|
3397
|
+
//# sourceMappingURL=compound-g6x_KkWp-Bs7olmlI.mjs.map
|
|
3398
|
+
//# debugId=796b8518-026b-5e47-b5fa-909b5b07437b
|