@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
|
@@ -0,0 +1,230 @@
|
|
|
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]="f0ec947e-cbe3-5e93-ade4-32e8e91cd95f")}catch(e){}}();
|
|
3
|
+
import { _ as unknown, d as object, m as string, r as array, u as number } from "./schemas-DzgKfQIx.mjs";
|
|
4
|
+
import { T as loadHost, Y as signInLinksOf, a as STORE_VERBS, dt as probeRun, gt as runRecordPath, ht as runRecordKey, mt as recordKeyOf, pt as readProjectName, r as ONE_SHOT_VERBS, s as announceSignInLinks, st as instanceKey } from "./compound-g6x_KkWp-Bs7olmlI.mjs";
|
|
5
|
+
import { a as syncMcpPortNotices, o as vetraRuntimeRecord, r as probeVetraRuntime, s as writeVetraRuntime, t as clearVetraRuntime } from "./vetra-runtime-Bk6CW-BE.mjs";
|
|
6
|
+
import "node:fs";
|
|
7
|
+
import "node:path";
|
|
8
|
+
import "node:crypto";
|
|
9
|
+
import "node:net";
|
|
10
|
+
import { yellow } from "colorette";
|
|
11
|
+
import { outputsSchema } from "@powerhousedao/ph-run/runners/connect";
|
|
12
|
+
import { outputsSchema as outputsSchema$1 } from "@powerhousedao/ph-run/runners/switchboard";
|
|
13
|
+
import { startRun } from "@powerhousedao/ph-run/start-run";
|
|
14
|
+
//#region ../../packages/host-core/dist/control-channel.mjs
|
|
15
|
+
/** A run record's `extra.control`. */
|
|
16
|
+
const controlRecordSchema = object({
|
|
17
|
+
protocol: number().int(),
|
|
18
|
+
address: string().min(1),
|
|
19
|
+
token: string().min(1)
|
|
20
|
+
});
|
|
21
|
+
/** The control channel a live run of this record answers on, when it has
|
|
22
|
+
* one of a protocol this version speaks. */
|
|
23
|
+
function controlRecordOf(record) {
|
|
24
|
+
const parsed = controlRecordSchema.safeParse(record?.extra?.control);
|
|
25
|
+
if (!parsed.success || parsed.data.protocol !== 2) return;
|
|
26
|
+
return parsed.data;
|
|
27
|
+
}
|
|
28
|
+
/** The protocol of the control channel a record names, whichever it is. */
|
|
29
|
+
function controlProtocolOf(record) {
|
|
30
|
+
const parsed = controlRecordSchema.safeParse(record?.extra?.control);
|
|
31
|
+
return parsed.success ? parsed.data.protocol : void 0;
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region ../../packages/host-core/dist/instance.mjs
|
|
35
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
36
|
+
function portOf$1(url) {
|
|
37
|
+
if (typeof url !== "string") return void 0;
|
|
38
|
+
try {
|
|
39
|
+
const parsed = new URL(url);
|
|
40
|
+
if (parsed.port) return Number(parsed.port);
|
|
41
|
+
if (parsed.protocol === "https:") return 443;
|
|
42
|
+
if (parsed.protocol === "http:") return 80;
|
|
43
|
+
} catch {}
|
|
44
|
+
}
|
|
45
|
+
function drivesOf(outputs) {
|
|
46
|
+
const drives = {};
|
|
47
|
+
if (!isRecord(outputs.drives)) return drives;
|
|
48
|
+
for (const [slug, drive] of Object.entries(outputs.drives)) if (isRecord(drive) && typeof drive.id === "string" && typeof drive.url === "string") drives[slug] = {
|
|
49
|
+
id: drive.id,
|
|
50
|
+
url: drive.url
|
|
51
|
+
};
|
|
52
|
+
return drives;
|
|
53
|
+
}
|
|
54
|
+
/** What a record says of a live instance. */
|
|
55
|
+
function instanceOfRecord(projectDir, record, env = process.env) {
|
|
56
|
+
const host = recordKeyOf(record);
|
|
57
|
+
const instance = {
|
|
58
|
+
key: instanceKey(host, projectDir, env),
|
|
59
|
+
record,
|
|
60
|
+
recordPath: runRecordPath(projectDir, host, env),
|
|
61
|
+
pid: record.pid,
|
|
62
|
+
drives: {},
|
|
63
|
+
endpoints: {},
|
|
64
|
+
ports: {}
|
|
65
|
+
};
|
|
66
|
+
const control = controlRecordOf(record);
|
|
67
|
+
if (control) instance.control = control;
|
|
68
|
+
const controlProtocol = controlProtocolOf(record);
|
|
69
|
+
if (controlProtocol !== void 0) instance.controlProtocol = controlProtocol;
|
|
70
|
+
const read = (name, outputs, prefix) => {
|
|
71
|
+
if (!isRecord(outputs)) return;
|
|
72
|
+
const origin = typeof outputs.origin === "string" ? outputs.origin : void 0;
|
|
73
|
+
if (origin !== void 0) instance.endpoints[`${prefix}origin`] = origin;
|
|
74
|
+
const port = portOf$1(origin);
|
|
75
|
+
if (port !== void 0) instance.ports[name] = port;
|
|
76
|
+
if (isRecord(outputs.endpoints)) {
|
|
77
|
+
for (const [key, url] of Object.entries(outputs.endpoints)) if (typeof url === "string") instance.endpoints[`${prefix}${key}`] = url;
|
|
78
|
+
}
|
|
79
|
+
if (instance.switchboardUrl === void 0 && origin !== void 0 && isRecord(outputs.drives)) {
|
|
80
|
+
instance.switchboardUrl = origin;
|
|
81
|
+
instance.drives = drivesOf(outputs);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
read(record.host, record.outputs, "");
|
|
85
|
+
for (const [name, member] of Object.entries(record.members ?? {})) read(name, member.outputs, `${name}.`);
|
|
86
|
+
return instance;
|
|
87
|
+
}
|
|
88
|
+
/** The live instance of one key; undefined when none runs. A record another
|
|
89
|
+
* project left on this data folder (a foreign one) is not this project's. */
|
|
90
|
+
function runningInstance(projectDir, host, options = {}) {
|
|
91
|
+
const env = options.env ?? process.env;
|
|
92
|
+
const probe = probeRun(projectDir, host, options.projectName ?? readProjectName(projectDir), env);
|
|
93
|
+
return probe.status === "live" ? instanceOfRecord(projectDir, probe.record, env) : void 0;
|
|
94
|
+
}
|
|
95
|
+
/** What a second start on a running key prints: the instance, and how to
|
|
96
|
+
* stop it. */
|
|
97
|
+
function describeInstance(instance) {
|
|
98
|
+
const { key, record } = instance;
|
|
99
|
+
const lines = [`${key.host} is already running for this project (pid ${record.pid}, started ${record.startedAt}).`, ` data folder: ${key.dataDir}`];
|
|
100
|
+
for (const [name, url] of Object.entries(instance.endpoints)) lines.push(` ${name}: ${url}`);
|
|
101
|
+
lines.push(` record: ${instance.recordPath}`);
|
|
102
|
+
lines.push(`Nothing was started. Stop it with \`ph run ${key.host} --stop\`.`);
|
|
103
|
+
return lines.join("\n");
|
|
104
|
+
}
|
|
105
|
+
function isAlreadyRunning(value) {
|
|
106
|
+
return isRecord(value) && isRecord(value.running) && isRecord(value.running.key) && isRecord(value.running.record);
|
|
107
|
+
}
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region src/utils/vetra-instance.ts
|
|
110
|
+
/**
|
|
111
|
+
* One dev stack per project. `ph run dev` (hosts/vetra in a project that has
|
|
112
|
+
* only that one) records its stack in `.ph/run/<host>.json` and, once ready,
|
|
113
|
+
* in `.ph/vetra-runtime.json`, which is what a start asks here: whether a
|
|
114
|
+
* stack already holds the project.
|
|
115
|
+
*/
|
|
116
|
+
/** Why the dev host must not start: a live one holds the project. */
|
|
117
|
+
async function vetraRuntimeRefusal(projectDir, projectName) {
|
|
118
|
+
const probe = await probeVetraRuntime(projectDir, projectName);
|
|
119
|
+
if (probe.status === "live" || probe.status === "starting") {
|
|
120
|
+
if (probe.record.pid === process.pid) return void 0;
|
|
121
|
+
return `Vetra is already running for this project (pid ${probe.record.pid}). Stop it before starting another.`;
|
|
122
|
+
}
|
|
123
|
+
if (probe.status === "foreign") return `.ph/vetra-runtime.json describes a live Vetra for "${probe.record.projectName}", but this project is "${projectName}". Refusing to start a second instance. Delete .ph/vetra-runtime.json if that record is wrong.`;
|
|
124
|
+
}
|
|
125
|
+
//#endregion
|
|
126
|
+
//#region src/services/run/vetra-host.ts
|
|
127
|
+
/**
|
|
128
|
+
* `ph run dev` (and `ph run vetra` in a project with that host): the dev host
|
|
129
|
+
* is the generic compound runner over a switchboard and a connect member, so
|
|
130
|
+
* nothing below `ph run` knows it is the dev stack. What makes the stack the
|
|
131
|
+
* project's own is done here around startRun: refuse while another one holds
|
|
132
|
+
* the project, publish `.ph/vetra-runtime.json` once the stack is ready,
|
|
133
|
+
* clear it on exit, and correct a drifted `.mcp.json`. `--restart` is its own
|
|
134
|
+
* argument, not a runner's: it stops the recorded Vetra first.
|
|
135
|
+
*/
|
|
136
|
+
async function runVetraHost(args) {
|
|
137
|
+
const verb = args.verb ?? "run";
|
|
138
|
+
if (ONE_SHOT_VERBS.has(verb) || STORE_VERBS.has(verb)) return startRun(args);
|
|
139
|
+
const projectDir = args.projectRoot ?? process.cwd();
|
|
140
|
+
const projectName = readProjectName(projectDir);
|
|
141
|
+
const restart = args.argv?.includes(RESTART_FLAG) ?? false;
|
|
142
|
+
if (restart) {
|
|
143
|
+
const { stopVetra } = await import("./vetra-launcher-XMk_Hv0c.mjs");
|
|
144
|
+
await stopVetra({
|
|
145
|
+
projectDir,
|
|
146
|
+
projectName,
|
|
147
|
+
onProgress: (message) => console.log(message)
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
const argv = args.argv?.filter((arg) => arg !== RESTART_FLAG) ?? [];
|
|
151
|
+
const running = argv.length === 0 ? await runningDevHost(projectDir, args.host, projectName) : void 0;
|
|
152
|
+
if (running && running.pid !== process.pid) {
|
|
153
|
+
console.log(describeInstance(running));
|
|
154
|
+
announceSignInLinks(signInLinksOf(running.record));
|
|
155
|
+
return { running };
|
|
156
|
+
}
|
|
157
|
+
const refusal = await vetraRuntimeRefusal(projectDir, projectName);
|
|
158
|
+
if (refusal) throw new Error(refusal);
|
|
159
|
+
const result = await startRun(restart ? {
|
|
160
|
+
...args,
|
|
161
|
+
argv
|
|
162
|
+
} : args);
|
|
163
|
+
if (isAlreadyRunning(result)) return result;
|
|
164
|
+
publishVetraRuntime(projectDir, projectName, result);
|
|
165
|
+
return result;
|
|
166
|
+
}
|
|
167
|
+
/** The live instance of the host `ref` names. A host that does not load is
|
|
168
|
+
* startRun's to report. */
|
|
169
|
+
async function runningDevHost(projectDir, ref, projectName) {
|
|
170
|
+
let key;
|
|
171
|
+
try {
|
|
172
|
+
const loaded = await loadHost(projectDir, ref);
|
|
173
|
+
key = runRecordKey(loaded.host.name, loaded.package?.name);
|
|
174
|
+
} catch {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
return runningInstance(projectDir, key, { projectName });
|
|
178
|
+
}
|
|
179
|
+
/** `ph run dev --restart`, which `ph dev --restart` is sugar for. */
|
|
180
|
+
const RESTART_FLAG = "--restart";
|
|
181
|
+
const startedSchema = object({ started: array(object({ outputs: unknown() })) });
|
|
182
|
+
const portOf = (url) => Number(new URL(url).port);
|
|
183
|
+
function firstMatch(schema, candidates) {
|
|
184
|
+
for (const candidate of candidates) {
|
|
185
|
+
const match = schema.safeParse(candidate);
|
|
186
|
+
if (match.success) return match.data;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* The record of a ready compound: its members are told apart by the outputs
|
|
191
|
+
* their runners publish, since a host file is free to name them.
|
|
192
|
+
*/
|
|
193
|
+
function vetraRecordOfRun(projectName, result) {
|
|
194
|
+
const parsed = startedSchema.safeParse(result);
|
|
195
|
+
const outputs = parsed.success ? parsed.data.started.map((member) => member.outputs) : [];
|
|
196
|
+
const switchboard = firstMatch(outputsSchema$1, outputs);
|
|
197
|
+
if (!switchboard) return void 0;
|
|
198
|
+
const connect = firstMatch(outputsSchema, outputs);
|
|
199
|
+
return vetraRuntimeRecord({
|
|
200
|
+
projectName,
|
|
201
|
+
switchboardPort: portOf(switchboard.origin),
|
|
202
|
+
connectPort: connect ? portOf(connect.origin) : 0,
|
|
203
|
+
switchboardUrl: switchboard.endpoints.graphql,
|
|
204
|
+
mcpUrl: switchboard.endpoints.mcp,
|
|
205
|
+
connectUrl: connect?.endpoints.connect
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Publishes the record of the stack startRun returned and syncs the MCP
|
|
210
|
+
* configs to its port. Returns what clears the record again; it also runs on
|
|
211
|
+
* exit. No SIGINT/SIGTERM handler: the compound owns the exit, and its
|
|
212
|
+
* process.exit reaches the exit event.
|
|
213
|
+
*/
|
|
214
|
+
function publishVetraRuntime(projectDir, projectName, result) {
|
|
215
|
+
const record = vetraRecordOfRun(projectName, result);
|
|
216
|
+
if (!record) {
|
|
217
|
+
console.warn(yellow("No switchboard member is running, so .ph/vetra-runtime.json is not written and `ph mcp` will not find this stack."));
|
|
218
|
+
return () => {};
|
|
219
|
+
}
|
|
220
|
+
writeVetraRuntime(projectDir, record);
|
|
221
|
+
const release = () => clearVetraRuntime(projectDir, process.pid);
|
|
222
|
+
process.on("exit", release);
|
|
223
|
+
for (const notice of syncMcpPortNotices(projectDir, record.switchboardPort)) console.log(yellow(notice));
|
|
224
|
+
return release;
|
|
225
|
+
}
|
|
226
|
+
//#endregion
|
|
227
|
+
export { runVetraHost };
|
|
228
|
+
|
|
229
|
+
//# sourceMappingURL=vetra-host-0rSW35_r.mjs.map
|
|
230
|
+
//# debugId=f0ec947e-cbe3-5e93-ade4-32e8e91cd95f
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vetra-host-0rSW35_r.mjs","sources":["../../../packages/host-core/dist/control-channel.mjs","../../../packages/host-core/dist/instance.mjs","../src/utils/vetra-instance.ts","../src/services/run/vetra-host.ts"],"sourcesContent":["import crypto from \"node:crypto\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport { z } from \"zod\";\nimport { execFile } from \"node:child_process\";\nimport net from \"node:net\";\nimport os from \"node:os\";\n//#region src/control-channel.ts\n/**\n* The control channel of a process that keeps running (a serving Cli, a\n* compound with one): a local stream other processes of the same OS user\n* send requests to, so a command typed in a second terminal acts on what\n* runs in the first. A named pipe on Windows, a socket file elsewhere. Its\n* address and token are in the process's run record (`extra.control`).\n*\n* Same user only. Elsewhere the socket is mode 0600 in a 0700 folder of the\n* user. On Windows the pipe's access list is replaced once it listens: the\n* user alone, and no caller from the network ({@link ControlChannel.ownerOnly}\n* says whether that took). Until then, and when it did not take, the pipe has\n* the system's default list: only its creator, administrators and the system\n* write to it, everyone may open it to read. So the server sends nothing\n* before a request that carries the token, and drops a caller that sends\n* none in time.\n*\n* One JSON value per line. A request is\n* `{ protocol, id, token, method, params }`. Its answer ends with\n* `{ id, ok: true, result }` or `{ id, ok: false, error: { code, message } }`;\n* before that a handler may send output as it is produced:\n* `{ id, stream: \"stdout\" | \"stderr\", data }`, in the order it was written.\n* `{ protocol, id, token, cancel: true }` cancels the request `id` of the\n* same connection, and so does the end of the connection.\n*\n* A caller that can answer questions while its request runs lists their\n* kinds in the request, `asks: [kind, ...]`. The handler may then ask one:\n* `{ id, ask: { seq, kind, payload } }`, and the caller answers on the same\n* connection with `{ protocol, id, token, answer: { seq, ok: true, result } }`\n* or `{ ..., answer: { seq, ok: false, error: { code, message } } }`. An\n* answer is taken at once, not behind the request it answers.\n*/\n/** 2: output frames, `cancel`, and asks for the kinds a request lists. A\n* caller and a process of different protocols refuse each other, each naming\n* both. */\nconst CONTROL_PROTOCOL = 2;\n/** How long an ask waits for its answer unless told otherwise. */\nconst ASK_TIMEOUT_MS = 6e5;\n/** A run record's `extra.control`. */\nconst controlRecordSchema = z.object({\n\tprotocol: z.number().int(),\n\taddress: z.string().min(1),\n\ttoken: z.string().min(1)\n});\nconst ERROR_CODES = /* @__PURE__ */ new Set([\n\t\"unauthorized\",\n\t\"protocol\",\n\t\"bad-request\",\n\t\"unknown-method\",\n\t\"failed\",\n\t\"cancelled\",\n\t\"unreachable\",\n\t\"unsupported\",\n\t\"refused\",\n\t\"timeout\"\n]);\n/** `code` when it is one of ours, else `failed`. */\nfunction errorCodeOf(code) {\n\treturn typeof code === \"string\" && ERROR_CODES.has(code) ? code : \"failed\";\n}\nvar ControlError = class extends Error {\n\tcode;\n\tconstructor(code, message) {\n\t\tsuper(message);\n\t\tthis.code = code;\n\t\tthis.name = \"ControlError\";\n\t}\n};\n/** The longest request line, and the longest line of output. */\nconst MAX_LINE_BYTES = 1048576;\nconst MAX_FRAME_CHARS = 65536;\nconst HANDSHAKE_TIMEOUT_MS = 5e3;\nconst MAX_CONNECTIONS = 64;\n/** The control channel a live run of this record answers on, when it has\n* one of a protocol this version speaks. */\nfunction controlRecordOf(record) {\n\tconst parsed = controlRecordSchema.safeParse(record?.extra?.control);\n\tif (!parsed.success || parsed.data.protocol !== 2) return;\n\treturn parsed.data;\n}\n/** The protocol of the control channel a record names, whichever it is. */\nfunction controlProtocolOf(record) {\n\tconst parsed = controlRecordSchema.safeParse(record?.extra?.control);\n\treturn parsed.success ? parsed.data.protocol : void 0;\n}\n/** What a caller of one protocol is told about a process of another. */\nfunction protocolMismatch(theirs) {\n\treturn `It speaks control protocol ${JSON.stringify(theirs)}, this process speaks 2: both must run the same version.`;\n}\nfunction sameToken(given, token) {\n\tif (typeof given !== \"string\") return false;\n\tconst a = Buffer.from(given);\n\tconst b = Buffer.from(token);\n\treturn a.length === b.length && crypto.timingSafeEqual(a, b);\n}\n/** The user's folder for socket files: theirs alone, or none. */\nfunction userSocketDir(given) {\n\tconst uid = process.getuid?.() ?? 0;\n\tconst dir = given ?? path.join(os.tmpdir(), `ph-control-${uid}`);\n\tfs.mkdirSync(dir, {\n\t\trecursive: true,\n\t\tmode: 448\n\t});\n\tconst stat = fs.lstatSync(dir);\n\tif (!stat.isDirectory() || stat.uid !== uid) throw new Error(`${dir} is not a folder of this user.`);\n\tif ((stat.mode & 63) !== 0) fs.chmodSync(dir, 448);\n\treturn dir;\n}\n/** Socket files whose process is gone (it was killed). */\nfunction sweepSockets(dir) {\n\tfor (const name of fs.readdirSync(dir)) {\n\t\tconst pid = Number(/^(\\d+)-[\\da-f]+\\.sock$/.exec(name)?.[1]);\n\t\tif (!Number.isInteger(pid) || pid === process.pid) continue;\n\t\ttry {\n\t\t\tprocess.kill(pid, 0);\n\t\t} catch (error) {\n\t\t\tif (error.code !== \"ESRCH\") continue;\n\t\t\tfs.rmSync(path.join(dir, name), { force: true });\n\t\t}\n\t}\n}\nfunction listen(server, address) {\n\treturn new Promise((resolve, reject) => {\n\t\tserver.once(\"error\", reject);\n\t\tserver.listen(address, () => {\n\t\t\tserver.off(\"error\", reject);\n\t\t\tresolve();\n\t\t});\n\t});\n}\n/** Windows PowerShell, by its own path: never one found through PATH. */\nfunction windowsPowerShell() {\n\treturn path.join(process.env.SystemRoot ?? \"C:\\\\Windows\", \"System32\", \"WindowsPowerShell\", \"v1.0\", \"powershell.exe\");\n}\n/** `$pipe`: the pipe `name`, opened with `rights`. */\nconst openPipe = (name, rights) => `$pipe = New-Object System.IO.Pipes.NamedPipeClientStream('.', '${name}', [System.IO.Pipes.PipeAccessRights]'${rights}', [System.IO.Pipes.PipeOptions]::None, [System.Security.Principal.TokenImpersonationLevel]::None, [System.IO.HandleInheritability]::None); \\$pipe.Connect(2000); `;\nfunction powerShell(script) {\n\treturn new Promise((resolve) => {\n\t\texecFile(windowsPowerShell(), [\n\t\t\t\"-NoProfile\",\n\t\t\t\"-NonInteractive\",\n\t\t\t\"-Command\",\n\t\t\tscript\n\t\t], {\n\t\t\twindowsHide: true,\n\t\t\ttimeout: 15e3,\n\t\t\tencoding: \"utf8\"\n\t\t}, (error, stdout) => resolve(error ? void 0 : stdout.trim()));\n\t});\n}\n/**\n* The access list (SDDL) of the pipe `name` (as in `\\\\.\\pipe\\<name>`);\n* undefined when it cannot be read. Windows only.\n*/\nfunction pipeAccessList(name) {\n\treturn powerShell(\"$ErrorActionPreference = 'Stop'; \" + openPipe(name, \"ReadData, ReadPermissions\") + \"try { $pipe.GetAccessControl().GetSecurityDescriptorSddlForm('Access') } finally { $pipe.Dispose() }\");\n}\n/** The access list a control pipe gets: no caller from the network, and the\n* user `sid` alone. */\nconst ownerOnlyPipeAccess = (sid) => `D:P(D;;FA;;;NU)(A;;FA;;;${sid})`;\n/**\n* Replaces the access list of this process's pipe `name` with\n* {@link ownerOnlyPipeAccess}. Node creates a pipe with the system's default\n* list and has no call to set another, so a helper process of the same user\n* does it (.NET's PipeSecurity through Windows PowerShell). Resolves false\n* when that failed: the pipe keeps the default list.\n*/\nasync function restrictPipe(name) {\n\treturn await powerShell(\"$ErrorActionPreference = 'Stop'; $sid = [System.Security.Principal.WindowsIdentity]::GetCurrent().User.Value; \" + openPipe(name, \"ReadData, ReadPermissions, ChangePermissions\") + `try { \\$security = New-Object System.IO.Pipes.PipeSecurity; $security.SetSecurityDescriptorSddlForm('${ownerOnlyPipeAccess(\"' + $sid + '\")}', 'Access'); \\$pipe.SetAccessControl(\\$security); 'restricted' } finally { \\$pipe.Dispose() }`) === \"restricted\";\n}\n/**\n* Opens a control channel for this process and resolves once it listens.\n* The server holds no process open. `hello` is answered by the channel\n* itself: `{ protocol, pid, mode, methods }` and what `describe` added.\n*/\nasync function openControlChannel(options = {}) {\n\tconst token = crypto.randomBytes(32).toString(\"base64url\");\n\tconst name = `${process.pid}-${crypto.randomBytes(8).toString(\"hex\")}`;\n\tconst handlers = /* @__PURE__ */ new Map();\n\tlet description = {};\n\thandlers.set(\"hello\", () => ({\n\t\t...description,\n\t\tprotocol: 2,\n\t\tpid: process.pid,\n\t\tmode: options.mode ?? \"ad hoc\",\n\t\tmethods: [...handlers.keys()]\n\t}));\n\t/** The request a line holds, or the refusal it gets. */\n\tconst read = (line) => {\n\t\tlet request;\n\t\ttry {\n\t\t\tconst parsed = JSON.parse(line);\n\t\t\tif (typeof parsed !== \"object\" || parsed === null) throw new Error();\n\t\t\trequest = parsed;\n\t\t} catch {\n\t\t\treturn { refused: refusal(void 0, \"bad-request\", \"The request is not JSON.\") };\n\t\t}\n\t\tconst { id } = request;\n\t\tif (!sameToken(request.token, token)) return { refused: refusal(id, \"unauthorized\", \"The token is missing or wrong.\") };\n\t\tif (request.protocol !== 2) return { refused: refusal(id, \"protocol\", `This process speaks control protocol 2, the request is of protocol ${JSON.stringify(request.protocol)}: both must run the same version.`) };\n\t\treturn { request };\n\t};\n\tconst answer = async (request, call) => {\n\t\tconst { id } = request;\n\t\tconst handler = typeof request.method === \"string\" ? handlers.get(request.method) : void 0;\n\t\tif (!handler) return refusal(id, \"unknown-method\", `Nothing here answers \"${String(request.method)}\".`);\n\t\ttry {\n\t\t\treturn {\n\t\t\t\tid,\n\t\t\t\tok: true,\n\t\t\t\tresult: await handler(request.params, call) ?? null\n\t\t\t};\n\t\t} catch (error) {\n\t\t\treturn refusal(id, call.signal.aborted ? \"cancelled\" : \"failed\", error instanceof Error ? error.message : String(error));\n\t\t}\n\t};\n\tconst sockets = /* @__PURE__ */ new Set();\n\tconst server = net.createServer((socket) => {\n\t\tsockets.add(socket);\n\t\tconst running = /* @__PURE__ */ new Map();\n\t\tlet handshake = setTimeout(() => socket.destroy(), options.handshakeTimeoutMs ?? HANDSHAKE_TIMEOUT_MS);\n\t\thandshake.unref();\n\t\tsocket.once(\"close\", () => {\n\t\t\tsockets.delete(socket);\n\t\t\tclearTimeout(handshake);\n\t\t\tfor (const { controller } of running.values()) controller.abort();\n\t\t});\n\t\tsocket.on(\"error\", () => void 0);\n\t\tsocket.setEncoding(\"utf8\");\n\t\tlet pending = \"\";\n\t\tlet dropped = false;\n\t\tlet queue = Promise.resolve();\n\t\tconst send = (value, end = false) => {\n\t\t\tif (socket.destroyed) return;\n\t\t\tconst text = `${JSON.stringify(value)}\\n`;\n\t\t\tif (end) socket.end(text);\n\t\t\telse socket.write(text);\n\t\t};\n\t\tconst take = (line) => {\n\t\t\tif (dropped) return;\n\t\t\tconst parsed = read(line);\n\t\t\tif (\"refused\" in parsed) {\n\t\t\t\tconst { error } = parsed.refused;\n\t\t\t\tdropped = error.code !== \"protocol\";\n\t\t\t\tqueue = queue.then(() => send(parsed.refused, dropped));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tclearTimeout(handshake);\n\t\t\thandshake = void 0;\n\t\t\tconst { request } = parsed;\n\t\t\tconst { id } = request;\n\t\t\tif (request.cancel === true) {\n\t\t\t\trunning.get(id)?.controller.abort();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (\"answer\" in request) {\n\t\t\t\tsettleAsk(running.get(id), request.answer);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst controller = new AbortController();\n\t\t\tconst asks = /* @__PURE__ */ new Map();\n\t\t\trunning.set(id, {\n\t\t\t\tcontroller,\n\t\t\t\tasks\n\t\t\t});\n\t\t\tlet seq = 0;\n\t\t\tconst call = {\n\t\t\t\tsignal: controller.signal,\n\t\t\t\twrite: (stream, data) => {\n\t\t\t\t\tif (controller.signal.aborted) return;\n\t\t\t\t\tfor (let at = 0; at < data.length; at += MAX_FRAME_CHARS) send({\n\t\t\t\t\t\tid,\n\t\t\t\t\t\tstream,\n\t\t\t\t\t\tdata: data.slice(at, at + MAX_FRAME_CHARS)\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t\tasks: asksOf(request),\n\t\t\t\task: (kind, payload, askOptions = {}) => askCaller({\n\t\t\t\t\tid,\n\t\t\t\t\tkind,\n\t\t\t\t\tpayload,\n\t\t\t\t\tseq: ++seq,\n\t\t\t\t\tasks,\n\t\t\t\t\tcall,\n\t\t\t\t\tsend\n\t\t\t\t}, askOptions.timeoutMs ?? 6e5)\n\t\t\t};\n\t\t\tqueue = queue.then(async () => {\n\t\t\t\tconst response = controller.signal.aborted ? refusal(id, \"cancelled\", \"The request was cancelled.\") : await answer(request, call);\n\t\t\t\trunning.delete(id);\n\t\t\t\tfor (const pending of asks.values()) pending.reject(new ControlError(\"cancelled\", \"The request ended first.\"));\n\t\t\t\tasks.clear();\n\t\t\t\tsend(response);\n\t\t\t});\n\t\t};\n\t\tsocket.on(\"data\", (chunk) => {\n\t\t\tpending += chunk;\n\t\t\tfor (;;) {\n\t\t\t\tconst end = pending.indexOf(\"\\n\");\n\t\t\t\tif (end === -1) break;\n\t\t\t\tconst line = pending.slice(0, end);\n\t\t\t\tpending = pending.slice(end + 1);\n\t\t\t\tif (line.trim() === \"\") continue;\n\t\t\t\tif (Buffer.byteLength(line) > 1048576) {\n\t\t\t\t\tsocket.destroy();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\ttake(line);\n\t\t\t}\n\t\t\tif (Buffer.byteLength(pending) > 1048576) socket.destroy();\n\t\t});\n\t});\n\tserver.maxConnections = MAX_CONNECTIONS;\n\tserver.on(\"error\", () => void 0);\n\tlet address;\n\tlet socketFile;\n\tlet ownerOnly;\n\tif (process.platform === \"win32\") {\n\t\taddress = `\\\\\\\\.\\\\pipe\\\\ph-control-${name}`;\n\t\tawait listen(server, address);\n\t\townerOnly = await restrictPipe(`ph-control-${name}`);\n\t} else {\n\t\tconst dir = userSocketDir(options.socketDir);\n\t\tsweepSockets(dir);\n\t\taddress = socketFile = path.join(dir, `${name}.sock`);\n\t\tlet umask;\n\t\ttry {\n\t\t\tumask = process.umask(127);\n\t\t} catch {}\n\t\ttry {\n\t\t\tawait listen(server, address);\n\t\t} finally {\n\t\t\tif (umask !== void 0) process.umask(umask);\n\t\t}\n\t\tfs.chmodSync(address, 384);\n\t\townerOnly = true;\n\t}\n\tserver.unref();\n\tconst removeSocket = () => {\n\t\tif (socketFile) fs.rmSync(socketFile, { force: true });\n\t};\n\tprocess.once(\"exit\", removeSocket);\n\tlet closing;\n\treturn {\n\t\trecord: {\n\t\t\tprotocol: 2,\n\t\t\taddress,\n\t\t\ttoken\n\t\t},\n\t\townerOnly,\n\t\thandle(method, handler) {\n\t\t\thandlers.set(method, handler);\n\t\t},\n\t\tdescribe(info) {\n\t\t\tdescription = {\n\t\t\t\t...description,\n\t\t\t\t...info\n\t\t\t};\n\t\t},\n\t\tclose: () => closing ??= new Promise((resolve) => {\n\t\t\tprocess.off(\"exit\", removeSocket);\n\t\t\tfor (const socket of sockets) socket.destroy();\n\t\t\tserver.close(() => {\n\t\t\t\tremoveSocket();\n\t\t\t\tresolve();\n\t\t\t});\n\t\t})\n\t};\n}\nfunction refusal(id, code, message) {\n\treturn {\n\t\tid,\n\t\tok: false,\n\t\terror: {\n\t\t\tcode,\n\t\t\tmessage\n\t\t}\n\t};\n}\n/** The kinds of ask a request says its caller answers. */\nfunction asksOf(request) {\n\tconst { asks } = request;\n\treturn new Set(Array.isArray(asks) ? asks.filter((kind) => typeof kind === \"string\") : []);\n}\n/** Settles the ask an answer line names; one that names none is dropped. */\nfunction settleAsk(request, answer) {\n\tif (!request || typeof answer !== \"object\" || answer === null) return;\n\tconst { seq, ok, result, error } = answer;\n\tif (typeof seq !== \"number\") return;\n\tconst pending = request.asks.get(seq);\n\tif (!pending) return;\n\trequest.asks.delete(seq);\n\tif (ok === true) {\n\t\tpending.resolve(result);\n\t\treturn;\n\t}\n\tpending.reject(new ControlError(errorCodeOf(error?.code), typeof error?.message === \"string\" ? error.message : \"The caller did not answer.\"));\n}\n/** Sends one ask to the caller and waits for its answer. */\nfunction askCaller(o, timeoutMs) {\n\tconst { id, kind, seq, asks, call } = o;\n\tif (!call.asks.has(kind)) return Promise.reject(new ControlError(\"unsupported\", `The caller does not answer \"${kind}\": it runs another version.`));\n\tif (call.signal.aborted) return Promise.reject(new ControlError(\"cancelled\", \"The request was cancelled.\"));\n\tconst frame = {\n\t\tid,\n\t\task: {\n\t\t\tseq,\n\t\t\tkind,\n\t\t\tpayload: o.payload ?? null\n\t\t}\n\t};\n\tif (Buffer.byteLength(JSON.stringify(frame)) > 1047552) return Promise.reject(new ControlError(\"bad-request\", `\"${kind}\" is too large to ask the caller (${Math.floor(MAX_LINE_BYTES / 1024)} KiB at most).`));\n\treturn new Promise((resolve, reject) => {\n\t\tconst done = () => {\n\t\t\tclearTimeout(timer);\n\t\t\tcall.signal.removeEventListener(\"abort\", cancelled);\n\t\t\tasks.delete(seq);\n\t\t};\n\t\tconst cancelled = () => {\n\t\t\tdone();\n\t\t\treject(new ControlError(\"cancelled\", \"The request was cancelled.\"));\n\t\t};\n\t\tconst timer = setTimeout(() => {\n\t\t\tdone();\n\t\t\treject(new ControlError(\"timeout\", `The caller did not answer \"${kind}\" within ${Math.round(timeoutMs / 1e3)} s.`));\n\t\t}, timeoutMs);\n\t\ttimer.unref();\n\t\tcall.signal.addEventListener(\"abort\", cancelled, { once: true });\n\t\tasks.set(seq, {\n\t\t\tresolve: (result) => {\n\t\t\t\tdone();\n\t\t\t\tresolve(result);\n\t\t\t},\n\t\t\treject: (error) => {\n\t\t\t\tdone();\n\t\t\t\treject(error);\n\t\t\t}\n\t\t});\n\t\to.send(frame);\n\t});\n}\nconst SLOT = Symbol.for(\"@powerhousedao/host-core/control-channel\");\nconst slot = () => globalThis[SLOT] ??= {};\n/**\n* This process's control channel, opened on the first call. Undefined when\n* it cannot be opened: the process then runs without one, as before.\n*/\nasync function ensureProcessControlChannel(options = {}) {\n\tconst held = slot();\n\tif (held.channel) return held.channel;\n\theld.opening ??= openControlChannel(options);\n\ttry {\n\t\theld.channel = await held.opening;\n\t\treturn held.channel;\n\t} catch {\n\t\treturn;\n\t} finally {\n\t\theld.opening = void 0;\n\t}\n}\n/** This process's control channel, when it has opened one. */\nfunction processControlChannel() {\n\treturn slot().channel;\n}\n/** Closes this process's control channel, if it has one. */\nasync function closeProcessControlChannel() {\n\tconst held = slot();\n\tconst channel = held.channel;\n\theld.channel = void 0;\n\tawait channel?.close();\n}\nconst CONNECT_TIMEOUT_MS = 2e3;\n/**\n* One request to the control channel a run record names. Resolves with the\n* result; rejects with a {@link ControlError}: `unreachable` when nothing\n* answers there, `protocol` when it speaks another protocol, else the code\n* the other process refused with. A request that is cancelled, or whose\n* caller ends, is cancelled in the other process.\n*/\nfunction callControl(control, method, params, options = {}) {\n\tif (control.protocol !== 2) return Promise.reject(new ControlError(\"protocol\", `Cannot ask the process at ${control.address} for \"${method}\". ${protocolMismatch(control.protocol)}`));\n\tconst { signal } = options;\n\tif (signal?.aborted) return Promise.reject(new ControlError(\"cancelled\", `\"${method}\" was cancelled.`));\n\treturn new Promise((resolve, reject) => {\n\t\tconst socket = net.connect(control.address);\n\t\tif (options.unref) socket.unref();\n\t\tlet settled = false;\n\t\tlet connected = false;\n\t\tlet pending = \"\";\n\t\tconst timers = [];\n\t\tconst request = {\n\t\t\tprotocol: 2,\n\t\t\tid: 1,\n\t\t\ttoken: control.token\n\t\t};\n\t\tconst cancel = () => {\n\t\t\tconst stop = () => reject(new ControlError(\"cancelled\", `\"${method}\" was cancelled.`));\n\t\t\tif (settled) return;\n\t\t\tif (!connected) {\n\t\t\t\tsettle(stop);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsettled = true;\n\t\t\tfor (const timer of timers) clearTimeout(timer);\n\t\t\tsocket.end(`${JSON.stringify({\n\t\t\t\t...request,\n\t\t\t\tcancel: true\n\t\t\t})}\\n`);\n\t\t\tsetTimeout(() => socket.destroy(), 500).unref();\n\t\t\tstop();\n\t\t};\n\t\tconst settle = (finish) => {\n\t\t\tif (settled) return;\n\t\t\tsettled = true;\n\t\t\tfor (const timer of timers) clearTimeout(timer);\n\t\t\tsignal?.removeEventListener(\"abort\", cancel);\n\t\t\tasking.abort();\n\t\t\tsocket.destroy();\n\t\t\tfinish();\n\t\t};\n\t\tconst asking = new AbortController();\n\t\tsignal?.addEventListener(\"abort\", () => asking.abort(), { once: true });\n\t\tconst answerAsk = async (ask) => {\n\t\t\tconst reply = (answer) => {\n\t\t\t\tif (settled || socket.destroyed) return;\n\t\t\t\tsocket.write(`${JSON.stringify({\n\t\t\t\t\t...request,\n\t\t\t\t\tanswer: {\n\t\t\t\t\t\tseq: ask.seq,\n\t\t\t\t\t\t...answer\n\t\t\t\t\t}\n\t\t\t\t})}\\n`);\n\t\t\t};\n\t\t\tconst kind = typeof ask.kind === \"string\" ? ask.kind : \"\";\n\t\t\tif (!options.onAsk || !options.asks?.includes(kind)) {\n\t\t\t\treply({\n\t\t\t\t\tok: false,\n\t\t\t\t\terror: {\n\t\t\t\t\t\tcode: \"unsupported\",\n\t\t\t\t\t\tmessage: `This process does not answer \"${kind}\".`\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\treply({\n\t\t\t\t\tok: true,\n\t\t\t\t\tresult: await options.onAsk(kind, ask.payload, asking.signal) ?? null\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\treply({\n\t\t\t\t\tok: false,\n\t\t\t\t\terror: {\n\t\t\t\t\t\tcode: errorCodeOf(error?.code),\n\t\t\t\t\t\tmessage: error instanceof Error ? error.message : String(error)\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t};\n\t\tsignal?.addEventListener(\"abort\", cancel, { once: true });\n\t\tconst unreachable = (why) => settle(() => reject(new ControlError(\"unreachable\", why)));\n\t\tconst limit = (ms, why) => {\n\t\t\tconst timer = setTimeout(() => unreachable(why), ms);\n\t\t\tif (options.unref) timer.unref();\n\t\t\ttimers.push(timer);\n\t\t\treturn timer;\n\t\t};\n\t\tconst connecting = limit(options.connectTimeoutMs ?? CONNECT_TIMEOUT_MS, `No answer at the control channel ${control.address}.`);\n\t\tsocket.setEncoding(\"utf8\");\n\t\tsocket.once(\"connect\", () => {\n\t\t\tconnected = true;\n\t\t\tclearTimeout(connecting);\n\t\t\tif (options.timeoutMs !== void 0) limit(options.timeoutMs, `\"${method}\" was not answered within ${options.timeoutMs} ms.`);\n\t\t\tsocket.write(`${JSON.stringify({\n\t\t\t\t...request,\n\t\t\t\tmethod,\n\t\t\t\t...params === void 0 ? {} : { params },\n\t\t\t\t...options.onAsk && options.asks?.length ? { asks: options.asks } : {}\n\t\t\t})}\\n`);\n\t\t});\n\t\tconst take = (line) => {\n\t\t\tlet frame;\n\t\t\ttry {\n\t\t\t\tframe = JSON.parse(line);\n\t\t\t} catch {\n\t\t\t\tunreachable(`The control channel ${control.address} answered no JSON.`);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (frame.stream === \"stdout\" || frame.stream === \"stderr\") {\n\t\t\t\tif (typeof frame.data === \"string\") options.onOutput?.(frame.stream, frame.data);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (typeof frame.ask === \"object\" && frame.ask !== null) {\n\t\t\t\tanswerAsk(frame.ask);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (frame.ok === true) {\n\t\t\t\tsettle(() => resolve(frame.result));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsettle(() => reject(new ControlError(frame.error?.code ?? \"failed\", frame.error?.message ?? `\"${method}\" failed.`)));\n\t\t};\n\t\tsocket.on(\"data\", (chunk) => {\n\t\t\tpending += chunk;\n\t\t\tfor (;;) {\n\t\t\t\tif (settled) return;\n\t\t\t\tconst end = pending.indexOf(\"\\n\");\n\t\t\t\tif (end === -1) break;\n\t\t\t\tconst line = pending.slice(0, end);\n\t\t\t\tpending = pending.slice(end + 1);\n\t\t\t\tif (line.trim() !== \"\") take(line);\n\t\t\t}\n\t\t});\n\t\tsocket.once(\"error\", (error) => unreachable(`Cannot reach the control channel ${control.address}: ${error.message}`));\n\t\tsocket.once(\"close\", () => unreachable(`The process behind the control channel ${control.address} went away before it answered \"${method}\".`));\n\t});\n}\n//#endregion\nexport { ASK_TIMEOUT_MS, CONTROL_PROTOCOL, ControlError, MAX_LINE_BYTES, callControl, closeProcessControlChannel, controlProtocolOf, controlRecordOf, controlRecordSchema, ensureProcessControlChannel, openControlChannel, ownerOnlyPipeAccess, pipeAccessList, processControlChannel, protocolMismatch };\n\n//# sourceMappingURL=control-channel.mjs.map","import { S as instanceServicesDir, b as instancePhDir, c as recordKeyOf, i as probeRun, o as readProjectName, r as listRunRecords, u as runRecordPath, v as instanceDataDir, x as instanceRunDir, y as instanceKey } from \"./run-record-C6oTZF_C.mjs\";\nimport { controlProtocolOf, controlRecordOf } from \"./control-channel.mjs\";\n//#region src/instance.ts\nconst isRecord = (value) => typeof value === \"object\" && value !== null && !Array.isArray(value);\nfunction portOf(url) {\n\tif (typeof url !== \"string\") return void 0;\n\ttry {\n\t\tconst parsed = new URL(url);\n\t\tif (parsed.port) return Number(parsed.port);\n\t\tif (parsed.protocol === \"https:\") return 443;\n\t\tif (parsed.protocol === \"http:\") return 80;\n\t} catch {}\n}\nfunction drivesOf(outputs) {\n\tconst drives = {};\n\tif (!isRecord(outputs.drives)) return drives;\n\tfor (const [slug, drive] of Object.entries(outputs.drives)) if (isRecord(drive) && typeof drive.id === \"string\" && typeof drive.url === \"string\") drives[slug] = {\n\t\tid: drive.id,\n\t\turl: drive.url\n\t};\n\treturn drives;\n}\n/** What a record says of a live instance. */\nfunction instanceOfRecord(projectDir, record, env = process.env) {\n\tconst host = recordKeyOf(record);\n\tconst instance = {\n\t\tkey: instanceKey(host, projectDir, env),\n\t\trecord,\n\t\trecordPath: runRecordPath(projectDir, host, env),\n\t\tpid: record.pid,\n\t\tdrives: {},\n\t\tendpoints: {},\n\t\tports: {}\n\t};\n\tconst control = controlRecordOf(record);\n\tif (control) instance.control = control;\n\tconst controlProtocol = controlProtocolOf(record);\n\tif (controlProtocol !== void 0) instance.controlProtocol = controlProtocol;\n\tconst read = (name, outputs, prefix) => {\n\t\tif (!isRecord(outputs)) return;\n\t\tconst origin = typeof outputs.origin === \"string\" ? outputs.origin : void 0;\n\t\tif (origin !== void 0) instance.endpoints[`${prefix}origin`] = origin;\n\t\tconst port = portOf(origin);\n\t\tif (port !== void 0) instance.ports[name] = port;\n\t\tif (isRecord(outputs.endpoints)) {\n\t\t\tfor (const [key, url] of Object.entries(outputs.endpoints)) if (typeof url === \"string\") instance.endpoints[`${prefix}${key}`] = url;\n\t\t}\n\t\tif (instance.switchboardUrl === void 0 && origin !== void 0 && isRecord(outputs.drives)) {\n\t\t\tinstance.switchboardUrl = origin;\n\t\t\tinstance.drives = drivesOf(outputs);\n\t\t}\n\t};\n\tread(record.host, record.outputs, \"\");\n\tfor (const [name, member] of Object.entries(record.members ?? {})) read(name, member.outputs, `${name}.`);\n\treturn instance;\n}\n/** The live instance of one key; undefined when none runs. A record another\n* project left on this data folder (a foreign one) is not this project's. */\nfunction runningInstance(projectDir, host, options = {}) {\n\tconst env = options.env ?? process.env;\n\tconst probe = probeRun(projectDir, host, options.projectName ?? readProjectName(projectDir), env);\n\treturn probe.status === \"live\" ? instanceOfRecord(projectDir, probe.record, env) : void 0;\n}\n/** Every live instance on the project's data folder. */\nfunction listRunningInstances(projectDir, options = {}) {\n\tconst env = options.env ?? process.env;\n\treturn listRunRecords(projectDir, env).flatMap((record) => {\n\t\tconst instance = runningInstance(projectDir, recordKeyOf(record), options);\n\t\treturn instance ? [instance] : [];\n\t});\n}\n/**\n* The running instance that belongs to a project folder and its data folder:\n* its record, its control channel and its switchboard. Undefined when none\n* runs.\n*/\nfunction findRunningInstance(projectDir = process.cwd(), options = {}) {\n\tconst { host, ...rest } = options;\n\tif (host !== void 0) {\n\t\tfor (const key of typeof host === \"string\" ? [host] : host) {\n\t\t\tconst instance = runningInstance(projectDir, key, rest);\n\t\t\tif (instance) return instance;\n\t\t}\n\t\treturn;\n\t}\n\tconst live = listRunningInstances(projectDir, rest);\n\treturn live.find((i) => i.record.kind === \"compound\") ?? live.at(0);\n}\n/** What a second start on a running key prints: the instance, and how to\n* stop it. */\nfunction describeInstance(instance) {\n\tconst { key, record } = instance;\n\tconst lines = [`${key.host} is already running for this project (pid ${record.pid}, started ${record.startedAt}).`, ` data folder: ${key.dataDir}`];\n\tfor (const [name, url] of Object.entries(instance.endpoints)) lines.push(` ${name}: ${url}`);\n\tlines.push(` record: ${instance.recordPath}`);\n\tlines.push(`Nothing was started. Stop it with \\`ph run ${key.host} --stop\\`.`);\n\treturn lines.join(\"\\n\");\n}\nfunction isAlreadyRunning(value) {\n\treturn isRecord(value) && isRecord(value.running) && isRecord(value.running.key) && isRecord(value.running.record);\n}\n/**\n* The restart rule of the host layer: an instance that was ready and ended\n* on its own restarts after `delay`, at most `maxRetries` times in a row (a\n* ready start resets the count). Never while its supervisor stops.\n*/\nfunction restartDecision(policy, state) {\n\tif (!policy?.enabled) return { action: \"none\" };\n\tif (state.attempt >= policy.maxRetries) return {\n\t\taction: \"give-up\",\n\t\tattempts: state.attempt\n\t};\n\tif (state.closing || !state.wasReady) return { action: \"none\" };\n\treturn {\n\t\taction: \"restart\",\n\t\tattempt: state.attempt + 1,\n\t\tdelayMs: policy.delay\n\t};\n}\nfunction exitWords(exit) {\n\treturn exit.signal !== null ? `signal ${exit.signal}` : `code ${exit.code}`;\n}\n/**\n* What a supervisor knows of an instance beyond its status, one line each,\n* in the words every listing uses: the version that runs it, where its\n* restart policy stands, and what cannot be done with it.\n*/\nfunction supervisedFactLines(facts) {\n\tconst lines = [];\n\tif (facts.runnerVersion !== void 0) lines.push(`runner version: ${facts.runnerVersion}`);\n\tconst { restart } = facts;\n\tif (restart) {\n\t\tconst parts = [`restarted by the supervisor: up to ${restart.maxRetries} time(s) in a row, ${restart.delay} ms apart`, `attempt ${restart.attempt} of ${restart.maxRetries}`];\n\t\tif (restart.lastExit) parts.push(`last ended with ${exitWords(restart.lastExit)} at ${restart.lastExit.at}`);\n\t\tif (restart.nextAt !== void 0) parts.push(`next start at ${restart.nextAt}`);\n\t\tlines.push(parts.join(\"; \"));\n\t\tif (restart.failed !== void 0) lines.push(`failed: ${restart.failed}`);\n\t}\n\tfor (const line of facts.missing ?? []) lines.push(`- ${line}`);\n\treturn lines;\n}\n//#endregion\nexport { describeInstance, findRunningInstance, instanceDataDir, instanceKey, instanceOfRecord, instancePhDir, instanceRunDir, instanceServicesDir, isAlreadyRunning, listRunningInstances, restartDecision, runningInstance, supervisedFactLines };\n\n//# sourceMappingURL=instance.mjs.map","import { probeVetraRuntime } from \"./vetra-runtime.js\";\n\n/**\n * One dev stack per project. `ph run dev` (hosts/vetra in a project that has\n * only that one) records its stack in `.ph/run/<host>.json` and, once ready,\n * in `.ph/vetra-runtime.json`, which is what a start asks here: whether a\n * stack already holds the project.\n */\n\n/** Why the dev host must not start: a live one holds the project. */\nexport async function vetraRuntimeRefusal(\n projectDir: string,\n projectName: string,\n): Promise<string | undefined> {\n const probe = await probeVetraRuntime(projectDir, projectName);\n if (probe.status === \"live\" || probe.status === \"starting\") {\n if (probe.record.pid === process.pid) return undefined;\n return `Vetra is already running for this project (pid ${probe.record.pid}). Stop it before starting another.`;\n }\n if (probe.status === \"foreign\") {\n return (\n `.ph/vetra-runtime.json describes a live Vetra for \"${probe.record.projectName}\", ` +\n `but this project is \"${projectName}\". Refusing to start a second instance. ` +\n `Delete .ph/vetra-runtime.json if that record is wrong.`\n );\n }\n return undefined;\n}\n","import {\n announceSignInLinks,\n describeInstance,\n isAlreadyRunning,\n loadHost,\n ONE_SHOT_VERBS,\n readProjectName,\n runningInstance,\n runRecordKey,\n signInLinksOf,\n STORE_VERBS,\n type AlreadyRunning,\n type RunningInstance,\n} from \"@powerhousedao/host-core\";\nimport { outputsSchema as connectOutputsSchema } from \"@powerhousedao/ph-run/runners/connect\";\nimport { outputsSchema as switchboardOutputsSchema } from \"@powerhousedao/ph-run/runners/switchboard\";\nimport { startRun, type StartRunArgs } from \"@powerhousedao/ph-run/start-run\";\nimport { yellow } from \"colorette\";\nimport { z } from \"zod\";\nimport { vetraRuntimeRefusal } from \"../../utils/vetra-instance.js\";\nimport {\n clearVetraRuntime,\n syncMcpPortNotices,\n vetraRuntimeRecord,\n writeVetraRuntime,\n type VetraRuntimeRecord,\n} from \"../../utils/vetra-runtime.js\";\n\n/**\n * `ph run dev` (and `ph run vetra` in a project with that host): the dev host\n * is the generic compound runner over a switchboard and a connect member, so\n * nothing below `ph run` knows it is the dev stack. What makes the stack the\n * project's own is done here around startRun: refuse while another one holds\n * the project, publish `.ph/vetra-runtime.json` once the stack is ready,\n * clear it on exit, and correct a drifted `.mcp.json`. `--restart` is its own\n * argument, not a runner's: it stops the recorded Vetra first.\n */\nexport async function runVetraHost(args: StartRunArgs): Promise<unknown> {\n const verb = args.verb ?? \"run\";\n // `build` starts nothing; a store verb is refused for a compound.\n if (ONE_SHOT_VERBS.has(verb) || STORE_VERBS.has(verb)) {\n return startRun(args);\n }\n const projectDir = args.projectRoot ?? process.cwd();\n const projectName = readProjectName(projectDir);\n const restart = args.argv?.includes(RESTART_FLAG) ?? false;\n if (restart) {\n const { stopVetra } = await import(\"../../utils/vetra-launcher.js\");\n await stopVetra({\n projectDir,\n projectName,\n onProgress: (message) => console.log(message),\n });\n }\n const argv = args.argv?.filter((arg) => arg !== RESTART_FLAG) ?? [];\n // One instance per (host, data folder): a second start is the running\n // one, shown. A stack with no run record (an earlier version's) is refused.\n const running =\n argv.length === 0\n ? await runningDevHost(projectDir, args.host, projectName)\n : undefined;\n if (running && running.pid !== process.pid) {\n console.log(describeInstance(running));\n // How a page that lost its sign-in gets a fresh link (F3d).\n announceSignInLinks(signInLinksOf(running.record));\n return { running } satisfies AlreadyRunning;\n }\n const refusal = await vetraRuntimeRefusal(projectDir, projectName);\n if (refusal) throw new Error(refusal);\n\n const result = await startRun(restart ? { ...args, argv } : args);\n if (isAlreadyRunning(result)) return result;\n publishVetraRuntime(projectDir, projectName, result);\n return result;\n}\n\n/** The live instance of the host `ref` names. A host that does not load is\n * startRun's to report. */\nasync function runningDevHost(\n projectDir: string,\n ref: string,\n projectName: string,\n): Promise<RunningInstance | undefined> {\n let key: string;\n try {\n const loaded = await loadHost(projectDir, ref);\n key = runRecordKey(loaded.host.name, loaded.package?.name);\n } catch {\n return undefined;\n }\n return runningInstance(projectDir, key, { projectName });\n}\n\n/** `ph run dev --restart`, which `ph dev --restart` is sugar for. */\nconst RESTART_FLAG = \"--restart\";\n\nconst startedSchema = z.object({\n started: z.array(z.object({ outputs: z.unknown() })),\n});\n\nconst portOf = (url: string) => Number(new URL(url).port);\n\nfunction firstMatch<T>(\n schema: z.ZodType<T>,\n candidates: unknown[],\n): T | undefined {\n for (const candidate of candidates) {\n const match = schema.safeParse(candidate);\n if (match.success) return match.data;\n }\n return undefined;\n}\n\n/**\n * The record of a ready compound: its members are told apart by the outputs\n * their runners publish, since a host file is free to name them.\n */\nexport function vetraRecordOfRun(\n projectName: string,\n result: unknown,\n): VetraRuntimeRecord | undefined {\n const parsed = startedSchema.safeParse(result);\n const outputs = parsed.success\n ? parsed.data.started.map((member) => member.outputs)\n : [];\n const switchboard = firstMatch(switchboardOutputsSchema, outputs);\n if (!switchboard) return undefined;\n const connect = firstMatch(connectOutputsSchema, outputs);\n return vetraRuntimeRecord({\n projectName,\n switchboardPort: portOf(switchboard.origin),\n // Vite may have taken another port, and the base path is Connect's.\n connectPort: connect ? portOf(connect.origin) : 0,\n switchboardUrl: switchboard.endpoints.graphql,\n mcpUrl: switchboard.endpoints.mcp,\n connectUrl: connect?.endpoints.connect,\n });\n}\n\n/**\n * Publishes the record of the stack startRun returned and syncs the MCP\n * configs to its port. Returns what clears the record again; it also runs on\n * exit. No SIGINT/SIGTERM handler: the compound owns the exit, and its\n * process.exit reaches the exit event.\n */\nexport function publishVetraRuntime(\n projectDir: string,\n projectName: string,\n result: unknown,\n): () => void {\n const record = vetraRecordOfRun(projectName, result);\n if (!record) {\n console.warn(\n yellow(\n \"No switchboard member is running, so .ph/vetra-runtime.json is not written and `ph mcp` will not find this stack.\",\n ),\n );\n return () => {};\n }\n // Record what the stack actually bound, so a second Vetra can tell a live\n // instance from a stale file, and so an agent can see the real ports.\n writeVetraRuntime(projectDir, record);\n // A restarted Vetra may already have written its own.\n const release = () => clearVetraRuntime(projectDir, process.pid);\n process.on(\"exit\", release);\n\n for (const notice of syncMcpPortNotices(projectDir, record.switchboardPort)) {\n console.log(yellow(notice));\n }\n return release;\n}\n"],"names":["z.object","z.number","z.string","portOf","z.object","z.array","z.unknown","switchbo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;EACxC,IAAI,MAAM,SAAS,OAAO,MAAM;CAClC;AAEF;;;;;AAMA,SAAgB,iBACd,aACA,QACgC;CAChC,MAAM,SAAS,cAAc,UAAU,MAAM;CAC7C,MAAM,UAAU,OAAO,UACnB,OAAO,KAAK,QAAQ,KAAK,WAAW,OAAO,OAAO,IAClD,CAAC;CACL,MAAM,cAAc,WAAWC,iBAA0B,OAAO;CAChE,IAAI,CAAC,aAAa,OAAO,KAAA;CACzB,MAAM,UAAU,WAAWC,eAAsB,OAAO;CACxD,OAAO,mBAAmB;EACxB;EACA,iBAAiB,OAAO,YAAY,MAAM;EAE1C,aAAa,UAAU,OAAO,QAAQ,MAAM,IAAI;EAChD,gBAAgB,YAAY,UAAU;EACtC,QAAQ,YAAY,UAAU;EAC9B,YAAY,SAAS,UAAU;CACjC,CAAC;AACH;;;;;;;AAQA,SAAgB,oBACd,YACA,aACA,QACY;CACZ,MAAM,SAAS,iBAAiB,aAAa,MAAM;CACnD,IAAI,CAAC,QAAQ;EACX,QAAQ,KACN,OACE,mHACF,CACF;EACA,aAAa,CAAC;CAChB;CAGA,kBAAkB,YAAY,MAAM;CAEpC,MAAM,gBAAgB,kBAAkB,YAAY,QAAQ,GAAG;CAC/D,QAAQ,GAAG,QAAQ,OAAO;CAE1B,KAAK,MAAM,UAAU,mBAAmB,YAAY,OAAO,eAAe,GACxE,QAAQ,IAAI,OAAO,MAAM,CAAC;CAE5B,OAAO;AACT","debug_id":"f0ec947e-cbe3-5e93-ade4-32e8e91cd95f"}
|
|
@@ -1,12 +1,53 @@
|
|
|
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]="
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
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]="3faa11c1-df67-5bd4-9c7c-d2e9ec978ec1")}catch(e){}}();
|
|
3
|
+
import { t as devHostOf } from "./dev-host-CM-Jg2kY.mjs";
|
|
4
|
+
import { n as isPortInUse, r as probeVetraRuntime, t as clearVetraRuntime } from "./vetra-runtime-Bk6CW-BE.mjs";
|
|
5
|
+
import "node:module";
|
|
5
6
|
import fs from "node:fs";
|
|
6
7
|
import path from "node:path";
|
|
7
8
|
import { spawn } from "node:child_process";
|
|
9
|
+
import net from "node:net";
|
|
10
|
+
import "node:url";
|
|
8
11
|
import { resolvePhDir } from "@powerhousedao/shared/clis/ph-dir";
|
|
9
12
|
import { stripVTControlCharacters } from "node:util";
|
|
13
|
+
//#region ../../packages/host-core/dist/host-entry-B8n_590_.mjs
|
|
14
|
+
/**
|
|
15
|
+
* Windows has no SIGTERM: `process.kill(pid, "SIGTERM")` ends the process at
|
|
16
|
+
* once, so no handler runs and a stack's stores are left as a crash leaves
|
|
17
|
+
* them. A started host therefore listens on a pipe named after its pid, and
|
|
18
|
+
* a connection to it is delivered as the SIGTERM it stands for. Elsewhere
|
|
19
|
+
* the signal itself does this, and there is no channel.
|
|
20
|
+
*/
|
|
21
|
+
function stopChannelPath(pid, platform = process.platform) {
|
|
22
|
+
return platform === "win32" ? `\\\\.\\pipe\\ph-stop-${pid}` : void 0;
|
|
23
|
+
}
|
|
24
|
+
const ASK_TIMEOUT_MS = 2e3;
|
|
25
|
+
/** Connects to a stop channel; true once the listener took the request. */
|
|
26
|
+
function askToStop(channel, timeoutMs = ASK_TIMEOUT_MS) {
|
|
27
|
+
return new Promise((resolve) => {
|
|
28
|
+
let connected = false;
|
|
29
|
+
const socket = net.connect(channel);
|
|
30
|
+
socket.setTimeout(timeoutMs, () => socket.destroy());
|
|
31
|
+
socket.once("connect", () => connected = true);
|
|
32
|
+
socket.on("error", () => void 0);
|
|
33
|
+
socket.once("close", () => resolve(connected));
|
|
34
|
+
socket.resume();
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Asks the process to stop as SIGTERM would. False when it could not be
|
|
39
|
+
* asked: on Windows a process without a stop channel (started by an older
|
|
40
|
+
* version, or not a host), which only a kill ends.
|
|
41
|
+
*/
|
|
42
|
+
async function requestStop(pid, platform = process.platform) {
|
|
43
|
+
const channel = stopChannelPath(pid, platform);
|
|
44
|
+
if (channel) return askToStop(channel);
|
|
45
|
+
try {
|
|
46
|
+
process.kill(pid, "SIGTERM");
|
|
47
|
+
} catch {}
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
10
51
|
//#region src/utils/vetra-launcher.ts
|
|
11
52
|
var VetraStartError = class extends Error {};
|
|
12
53
|
const PORT_GRACE_MS = 1e4;
|
|
@@ -16,20 +57,22 @@ const lockPath = (projectDir) => path.join(resolvePhDir(projectDir), "vetra-star
|
|
|
16
57
|
const vetraLogPath = (projectDir) => path.join(resolvePhDir(projectDir), "vetra.log");
|
|
17
58
|
const shownLogPath = (projectDir) => path.relative(projectDir, vetraLogPath(projectDir)).split(path.sep).join("/");
|
|
18
59
|
/**
|
|
19
|
-
* What starts a project's
|
|
20
|
-
*
|
|
21
|
-
*
|
|
60
|
+
* What starts a project's dev stack: `ph run dev --strictPort` (hosts/vetra
|
|
61
|
+
* in a project that has only that one), run by the ph-cli executing this
|
|
62
|
+
* code. The host's own defaultVerb picks the verb. In a project without the
|
|
63
|
+
* host it fails, and its output says why.
|
|
22
64
|
*/
|
|
23
|
-
function currentPhCliRunVetraCommand() {
|
|
65
|
+
function currentPhCliRunVetraCommand(projectDir) {
|
|
66
|
+
const host = devHostOf(projectDir);
|
|
24
67
|
return {
|
|
25
68
|
command: process.execPath,
|
|
26
69
|
args: [
|
|
27
70
|
process.argv[1],
|
|
28
71
|
"run",
|
|
29
|
-
|
|
72
|
+
host,
|
|
30
73
|
"--strictPort"
|
|
31
74
|
],
|
|
32
|
-
label: `ph run ${
|
|
75
|
+
label: `ph run ${host}`
|
|
33
76
|
};
|
|
34
77
|
}
|
|
35
78
|
function isPidAlive(pid) {
|
|
@@ -101,7 +144,7 @@ async function waitForLive(options, deadline, stillStarting) {
|
|
|
101
144
|
await sleep(pollMs);
|
|
102
145
|
}
|
|
103
146
|
}
|
|
104
|
-
/** This project's live
|
|
147
|
+
/** This project's live dev stack, or a detached `ph run dev` started and awaited; never a second reactor. */
|
|
105
148
|
async function ensureVetra(options) {
|
|
106
149
|
const { projectDir, projectName, switchboardPort, timeoutMs } = options;
|
|
107
150
|
const deadline = Date.now() + timeoutMs;
|
|
@@ -164,7 +207,7 @@ async function ensureVetra(options) {
|
|
|
164
207
|
if (spawnError) throw new VetraStartError(`Could not run \`${options.command.command}\`: ${spawnError.message}`);
|
|
165
208
|
if (exit) {
|
|
166
209
|
const how = exit.signal !== null ? `was killed by ${exit.signal}` : `exited with code ${exit.code}`;
|
|
167
|
-
throw withOutput(`\`${options.command.label ?? `ph run
|
|
210
|
+
throw withOutput(`\`${options.command.label ?? `ph run ${devHostOf(projectDir)}`}\` ${how} before it was ready.`, projectDir);
|
|
168
211
|
}
|
|
169
212
|
keepLock = true;
|
|
170
213
|
throw withOutput(`Vetra (pid ${child.pid}) did not answer /ready on port ${switchboardPort} within ${seconds}s. It is still running; the next tool call waits for it again.`, projectDir);
|
|
@@ -215,5 +258,5 @@ async function restartVetra(options) {
|
|
|
215
258
|
//#endregion
|
|
216
259
|
export { restartVetra as a, readLogTail as i, currentPhCliRunVetraCommand as n, stopVetra as o, ensureVetra as r, vetraLogPath as s, VetraStartError as t };
|
|
217
260
|
|
|
218
|
-
//# sourceMappingURL=vetra-launcher-
|
|
219
|
-
//# debugId=
|
|
261
|
+
//# sourceMappingURL=vetra-launcher-6NKfi6Au.mjs.map
|
|
262
|
+
//# debugId=3faa11c1-df67-5bd4-9c7c-d2e9ec978ec1
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vetra-launcher-6NKfi6Au.mjs","sources":["../../../packages/host-core/dist/host-entry-B8n_590_.mjs","../src/utils/vetra-launcher.ts"],"sourcesContent":["import { i as probeRun, n as isPidAlive, o as readProjectName, s as readRunRecord, t as clearRunRecord } from \"./run-record-C6oTZF_C.mjs\";\nimport { createRequire } from \"node:module\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport net from \"node:net\";\n//#region src/stop-channel.ts\n/** Set by a supervisor that holds this process's stdin. */\nconst STOP_ON_STDIN_ENV = \"PH_STOP_ON_STDIN\";\n/**\n* Windows has no SIGTERM: `process.kill(pid, \"SIGTERM\")` ends the process at\n* once, so no handler runs and a stack's stores are left as a crash leaves\n* them. A started host therefore listens on a pipe named after its pid, and\n* a connection to it is delivered as the SIGTERM it stands for. Elsewhere\n* the signal itself does this, and there is no channel.\n*/\nfunction stopChannelPath(pid, platform = process.platform) {\n\treturn platform === \"win32\" ? `\\\\\\\\.\\\\pipe\\\\ph-stop-${pid}` : void 0;\n}\n/** Calls `onStop` for each connection to `channel`. The server holds no\n* process open, and one that cannot listen leaves the host running without\n* a channel rather than not running. */\nfunction listenForStop(channel, onStop) {\n\tconst server = net.createServer((socket) => {\n\t\tsocket.on(\"error\", () => void 0);\n\t\tsocket.end();\n\t\tonStop();\n\t});\n\tserver.on(\"error\", () => void 0);\n\tserver.listen(channel);\n\tserver.unref();\n\treturn server;\n}\nlet installed = false;\n/** What a host's process calls once before it starts anything: from then on\n* {@link requestStop} reaches its SIGTERM handlers on every platform. */\nfunction installStopChannel() {\n\tconst channel = stopChannelPath(process.pid);\n\tif (!channel || installed) return;\n\tinstalled = true;\n\tlistenForStop(channel, () => {\n\t\tif (!process.emit(\"SIGTERM\", \"SIGTERM\")) process.exit(143);\n\t});\n}\nconst ASK_TIMEOUT_MS = 2e3;\n/** Connects to a stop channel; true once the listener took the request. */\nfunction askToStop(channel, timeoutMs = ASK_TIMEOUT_MS) {\n\treturn new Promise((resolve) => {\n\t\tlet connected = false;\n\t\tconst socket = net.connect(channel);\n\t\tsocket.setTimeout(timeoutMs, () => socket.destroy());\n\t\tsocket.once(\"connect\", () => connected = true);\n\t\tsocket.on(\"error\", () => void 0);\n\t\tsocket.once(\"close\", () => resolve(connected));\n\t\tsocket.resume();\n\t});\n}\n/**\n* Asks the process to stop as SIGTERM would. False when it could not be\n* asked: on Windows a process without a stop channel (started by an older\n* version, or not a host), which only a kill ends.\n*/\nasync function requestStop(pid, platform = process.platform) {\n\tconst channel = stopChannelPath(pid, platform);\n\tif (channel) return askToStop(channel);\n\ttry {\n\t\tprocess.kill(pid, \"SIGTERM\");\n\t} catch {}\n\treturn true;\n}\nconst STOP_RUN_TIMEOUT_MS = 6e4;\n/** Asks the project's running `hostName` to stop and waits until its process\n* is gone. It never kills: a host that does not answer keeps running. */\nasync function stopRun(projectDir, hostName, options = {}) {\n\tconst env = options.env ?? process.env;\n\tconst projectName = readProjectName(projectDir);\n\tconst probe = probeRun(projectDir, hostName, projectName, env);\n\tif (probe.status === \"none\" || probe.status === \"stale\") return { status: \"none\" };\n\tconst { pid } = probe.record;\n\tif (probe.status === \"foreign\") return {\n\t\tstatus: \"foreign\",\n\t\tpid,\n\t\tprojectName: probe.record.projectName\n\t};\n\tif (!await requestStop(pid)) return {\n\t\tstatus: \"unreachable\",\n\t\tpid\n\t};\n\tconst deadline = Date.now() + (options.timeoutMs ?? 6e4);\n\twhile (isPidAlive(pid)) {\n\t\tif (Date.now() >= deadline) return {\n\t\t\tstatus: \"timeout\",\n\t\t\tpid\n\t\t};\n\t\tawait new Promise((resolve) => setTimeout(resolve, 100));\n\t}\n\tif (readRunRecord(projectDir, hostName, env)?.pid === pid) clearRunRecord(projectDir, hostName, env);\n\treturn {\n\t\tstatus: \"stopped\",\n\t\tpid\n\t};\n}\n//#endregion\n//#region src/host-entry.ts\n/**\n* How a host is started as a child of the process that supervises it: the\n* project's own `ph run`, in an environment of its own. Read by `spawnHost`\n* and by the supervisor, which loads nothing of the project.\n*/\nconst BASE_ENV_KEYS = [\n\t\"PATH\",\n\t\"HOME\",\n\t\"TMPDIR\"\n];\nconst WIN32_ENV_KEYS = [\n\t\"SystemRoot\",\n\t\"USERPROFILE\",\n\t\"APPDATA\",\n\t\"LOCALAPPDATA\",\n\t\"TEMP\",\n\t\"TMP\",\n\t\"ComSpec\",\n\t\"PATHEXT\"\n];\n/** The child's whole env: without a `baseEnv`, no other `process.env` key\n* reaches it. */\nfunction childEnv(dataDir, env = {}, baseEnv) {\n\tif (\"PH_USER_DATA_DIR\" in env) throw new Error(\"spawnHost: set the data dir with `dataDir`, not env.PH_USER_DATA_DIR.\");\n\tif (baseEnv) {\n\t\tconst base = {};\n\t\tfor (const [key, value] of Object.entries(baseEnv)) if (value !== void 0) base[key] = value;\n\t\treturn {\n\t\t\t...base,\n\t\t\tPH_USER_DATA_DIR: dataDir,\n\t\t\t...env\n\t\t};\n\t}\n\tconst keys = process.platform === \"win32\" ? [...BASE_ENV_KEYS, ...WIN32_ENV_KEYS] : BASE_ENV_KEYS;\n\tconst base = {};\n\tfor (const key of keys) {\n\t\tconst value = process.env[key];\n\t\tif (value !== void 0) base[key] = value;\n\t}\n\treturn {\n\t\t...base,\n\t\tPH_USER_DATA_DIR: dataDir,\n\t\tPH_NO_TELEMETRY: \"1\",\n\t\tPH_NO_DOTENV: \"1\",\n\t\t...env\n\t};\n}\n/** The version of the package an entry of {@link resolvePhCliEntry} is in. */\nfunction phCliEntryVersion(entry) {\n\ttry {\n\t\tconst pkg = JSON.parse(fs.readFileSync(path.join(path.dirname(path.dirname(entry)), \"package.json\"), \"utf8\"));\n\t\treturn typeof pkg.version === \"string\" ? pkg.version : void 0;\n\t} catch {\n\t\treturn;\n\t}\n}\n/** Whether a standalone host of that release stops when its stdin ends\n* (6.4 on); an earlier one is asked over its stop channel. An unknown\n* version counts as this one. */\nfunction stopsOnStdin(version) {\n\tconst match = /^(\\d+)\\.(\\d+)\\./.exec(version ?? \"\");\n\tif (!match) return true;\n\tconst major = Number(match[1]);\n\treturn major > 6 || major === 6 && Number(match[2]) >= 4;\n}\n/** The project's ph-cli, else its ph-run (a packaged app has only that). */\nfunction resolvePhCliEntry(projectRoot) {\n\tconst require_ = createRequire(pathToFileURL(path.join(projectRoot, \"package.json\")).href);\n\tlet pkgPath;\n\ttry {\n\t\tpkgPath = require_.resolve(\"@powerhousedao/ph-cli/package.json\");\n\t} catch (error) {\n\t\ttry {\n\t\t\tpkgPath = require_.resolve(\"@powerhousedao/ph-run/package.json\");\n\t\t} catch {\n\t\t\tthrow error;\n\t\t}\n\t}\n\treturn path.join(path.dirname(pkgPath), \"dist\", \"cli.mjs\");\n}\n//#endregion\nexport { STOP_ON_STDIN_ENV as a, installStopChannel as c, stopChannelPath as d, stopRun as f, stopsOnStdin as i, listenForStop as l, phCliEntryVersion as n, STOP_RUN_TIMEOUT_MS as o, resolvePhCliEntry as r, askToStop as s, childEnv as t, requestStop as u };\n\n//# sourceMappingURL=host-entry-B8n_590_.mjs.map","import { requestStop } from \"@powerhousedao/host-core\";\nimport { resolvePhDir } from \"@powerhousedao/shared/clis/ph-dir\";\nimport { spawn } from \"node:child_process\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport { stripVTControlCharacters } from \"node:util\";\nimport { devHostOf } from \"./dev-host.js\";\nimport {\n clearVetraRuntime,\n isPortInUse,\n probeVetraRuntime,\n type VetraRuntimeRecord,\n} from \"./vetra-runtime.js\";\n\nexport type VetraCommand = {\n command: string;\n args: string[];\n /** How messages name it; `ph run <the project's dev host>` when left out. */\n label?: string;\n};\n\nexport type EnsureVetraOptions = {\n projectDir: string;\n projectName: string;\n /** The port a strict-port Vetra will bind. */\n switchboardPort: number;\n command: VetraCommand;\n timeoutMs: number;\n pollMs?: number;\n /** Told what it waits on while Vetra is not ready yet, about once a second. */\n onProgress?: (message: string) => void;\n};\n\nexport class VetraStartError extends Error {}\n\nconst LOG_TAIL_LINES = 60;\nconst PORT_GRACE_MS = 10_000;\nconst STOP_TIMEOUT_MS = 15_000;\nconst PROGRESS_EVERY_MS = 1000;\n\nconst lockPath = (projectDir: string) =>\n path.join(resolvePhDir(projectDir), \"vetra-start.lock\");\n\nexport const vetraLogPath = (projectDir: string) =>\n path.join(resolvePhDir(projectDir), \"vetra.log\");\n\n// Forward slashes, so messages read the same on every platform.\nconst shownLogPath = (projectDir: string) =>\n path.relative(projectDir, vetraLogPath(projectDir)).split(path.sep).join(\"/\");\n\n/**\n * What starts a project's dev stack: `ph run dev --strictPort` (hosts/vetra\n * in a project that has only that one), run by the ph-cli executing this\n * code. The host's own defaultVerb picks the verb. In a project without the\n * host it fails, and its output says why.\n */\nexport function currentPhCliRunVetraCommand(projectDir: string): VetraCommand {\n const host = devHostOf(projectDir);\n return {\n command: process.execPath,\n args: [process.argv[1], \"run\", host, \"--strictPort\"],\n label: `ph run ${host}`,\n };\n}\n\nfunction isPidAlive(pid: number | undefined): boolean {\n if (!pid) return false;\n try {\n process.kill(pid, 0);\n return true;\n } catch (error) {\n return (error as NodeJS.ErrnoException).code === \"EPERM\";\n }\n}\n\nconst sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));\n\ntype LockRecord = { pid: number; vetraPid?: number };\n\nfunction readLock(projectDir: string): LockRecord | undefined {\n try {\n return JSON.parse(\n fs.readFileSync(lockPath(projectDir), \"utf8\"),\n ) as LockRecord;\n } catch {\n return undefined;\n }\n}\n\nfunction isLockHeld(lock: LockRecord | undefined): boolean {\n return !!lock && (isPidAlive(lock.pid) || isPidAlive(lock.vetraPid));\n}\n\n/** Held while the launcher or the Vetra it started is alive. */\nfunction tryAcquireLock(projectDir: string): boolean {\n const target = lockPath(projectDir);\n fs.mkdirSync(path.dirname(target), { recursive: true });\n for (let attempt = 0; attempt < 2; attempt++) {\n try {\n fs.writeFileSync(target, JSON.stringify({ pid: process.pid }), {\n flag: \"wx\",\n });\n return true;\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== \"EEXIST\") throw error;\n if (isLockHeld(readLock(projectDir))) return false;\n fs.rmSync(target, { force: true });\n }\n }\n return false;\n}\n\nfunction releaseLock(projectDir: string): void {\n if (readLock(projectDir)?.pid === process.pid) {\n fs.rmSync(lockPath(projectDir), { force: true });\n }\n}\n\nexport function readLogTail(projectDir: string): string {\n try {\n const text = fs.readFileSync(vetraLogPath(projectDir), \"utf8\");\n const lines = stripVTControlCharacters(text).trimEnd().split(\"\\n\");\n return lines.slice(-LOG_TAIL_LINES).join(\"\\n\");\n } catch {\n return \"\";\n }\n}\n\nfunction withOutput(message: string, projectDir: string): VetraStartError {\n const tail = readLogTail(projectDir);\n const where = shownLogPath(projectDir);\n return new VetraStartError(\n tail\n ? `${message}\\n\\nVetra output (last lines of ${where}):\\n${tail}`\n : message,\n );\n}\n\nfunction foreignError(record: VetraRuntimeRecord): VetraStartError {\n return new VetraStartError(\n `.ph/vetra-runtime.json describes a live Vetra for \"${record.projectName}\" (pid ${record.pid}), not this project. ` +\n `Refusing to start a second reactor. Delete .ph/vetra-runtime.json if that record is wrong.`,\n );\n}\n\nasync function waitForLive(\n options: EnsureVetraOptions,\n deadline: number,\n stillStarting: () => boolean,\n): Promise<VetraRuntimeRecord | undefined> {\n const { projectDir, projectName, pollMs = 250, onProgress } = options;\n const startedAt = Date.now();\n let reportedAt = startedAt;\n while (Date.now() < deadline) {\n const probe = await probeVetraRuntime(projectDir, projectName);\n if (probe.status === \"live\") return probe.record;\n if (probe.status === \"foreign\") throw foreignError(probe.record);\n if (probe.status !== \"starting\" && !stillStarting()) return undefined;\n if (onProgress && Date.now() - reportedAt >= PROGRESS_EVERY_MS) {\n reportedAt = Date.now();\n const seconds = Math.round((reportedAt - startedAt) / 1000);\n onProgress(`Waiting for Vetra to be ready (${seconds}s)...`);\n }\n await sleep(pollMs);\n }\n return undefined;\n}\n\n/** This project's live dev stack, or a detached `ph run dev` started and awaited; never a second reactor. */\nexport async function ensureVetra(\n options: EnsureVetraOptions,\n): Promise<VetraRuntimeRecord> {\n const { projectDir, projectName, switchboardPort, timeoutMs } = options;\n const deadline = Date.now() + timeoutMs;\n const seconds = Math.round(timeoutMs / 1000);\n const report = options.onProgress ?? (() => {});\n\n const probe = await probeVetraRuntime(projectDir, projectName);\n if (probe.status === \"live\") return probe.record;\n if (probe.status === \"foreign\") throw foreignError(probe.record);\n if (probe.status === \"starting\") {\n report(`Vetra (pid ${probe.record.pid}) is starting; waiting for it...`);\n const record = await waitForLive(options, deadline, () => false);\n if (record) return record;\n throw withOutput(\n `Vetra (pid ${probe.record.pid}) is running but did not answer /ready within ${seconds}s.`,\n projectDir,\n );\n }\n\n while (!tryAcquireLock(projectDir)) {\n // Another launcher is starting Vetra for this project.\n report(\"Another process is starting Vetra for this project; waiting...\");\n const record = await waitForLive(options, deadline, () =>\n isLockHeld(readLock(projectDir)),\n );\n if (record) return record;\n if (Date.now() >= deadline) {\n throw withOutput(\n `Another process is starting Vetra for this project and it did not become ready within ${seconds}s.`,\n projectDir,\n );\n }\n }\n\n let keepLock = false;\n try {\n const again = await probeVetraRuntime(projectDir, projectName);\n if (again.status === \"live\") return again.record;\n if (again.status === \"foreign\") throw foreignError(again.record);\n\n if (again.status === \"starting\" || (await isPortInUse(switchboardPort))) {\n // Maybe a Vetra that bound the port but has not written its record yet.\n const grace = Date.now() + PORT_GRACE_MS;\n const record = await waitForLive(\n options,\n deadline,\n () => Date.now() < grace,\n );\n if (record) return record;\n throw new VetraStartError(\n `Port ${switchboardPort} is in use, but .ph/vetra-runtime.json names no live Vetra for this project. ` +\n `Stop whatever holds the port, or move this project's port (reactor.port in powerhouse.config.json).`,\n );\n }\n\n const logFile = vetraLogPath(projectDir);\n report(`Starting Vetra; its output goes to ${shownLogPath(projectDir)}...`);\n const logFd = fs.openSync(logFile, \"w\");\n let exit: { code: number | null; signal: string | null } | undefined;\n let spawnError: Error | undefined;\n const child = spawn(options.command.command, options.command.args, {\n cwd: projectDir,\n detached: true,\n stdio: [\"ignore\", logFd, logFd],\n windowsHide: true,\n });\n fs.closeSync(logFd);\n child.once(\"error\", (error) => (spawnError = error));\n child.once(\"exit\", (code, signal) => (exit = { code, signal }));\n child.unref();\n if (child.pid) {\n fs.writeFileSync(\n lockPath(projectDir),\n JSON.stringify({ pid: process.pid, vetraPid: child.pid }),\n );\n }\n\n const record = await waitForLive(\n options,\n deadline,\n () => !exit && !spawnError,\n );\n if (record) return record;\n\n if (spawnError) {\n throw new VetraStartError(\n `Could not run \\`${options.command.command}\\`: ${spawnError.message}`,\n );\n }\n if (exit) {\n const how =\n exit.signal !== null\n ? `was killed by ${exit.signal}`\n : `exited with code ${exit.code}`;\n throw withOutput(\n `\\`${options.command.label ?? `ph run ${devHostOf(projectDir)}`}\\` ${how} before it was ready.`,\n projectDir,\n );\n }\n // Still booting: keep the lock on its pid so the next call waits instead of spawning.\n keepLock = true;\n throw withOutput(\n `Vetra (pid ${child.pid}) did not answer /ready on port ${switchboardPort} within ${seconds}s. ` +\n `It is still running; the next tool call waits for it again.`,\n projectDir,\n );\n } finally {\n if (!keepLock) releaseLock(projectDir);\n }\n}\n\nasync function waitForExit(\n record: VetraRuntimeRecord,\n deadline: number,\n): Promise<boolean> {\n while (Date.now() < deadline) {\n const gone =\n !isPidAlive(record.pid) && !(await isPortInUse(record.switchboardPort));\n if (gone) return true;\n await sleep(100);\n }\n return false;\n}\n\n/** Stops this project's running Vetra, if any; resolves to the record it stopped. */\nexport async function stopVetra(options: {\n projectDir: string;\n projectName: string;\n timeoutMs?: number;\n onProgress?: (message: string) => void;\n}): Promise<VetraRuntimeRecord | undefined> {\n const { projectDir, projectName, timeoutMs = STOP_TIMEOUT_MS } = options;\n const probe = await probeVetraRuntime(projectDir, projectName);\n if (probe.status === \"foreign\") throw foreignError(probe.record);\n if (probe.status !== \"live\" && probe.status !== \"starting\") return undefined;\n const { record } = probe;\n const signal = (name: NodeJS.Signals) => {\n try {\n process.kill(record.pid, name);\n } catch {\n // Already gone.\n }\n };\n options.onProgress?.(`Stopping Vetra (pid ${record.pid})...`);\n // On Windows SIGTERM is a kill: ask through the stop channel, and signal\n // only a Vetra that has none.\n if (!(await requestStop(record.pid))) signal(\"SIGTERM\");\n if (!(await waitForExit(record, Date.now() + timeoutMs))) {\n signal(\"SIGKILL\");\n if (!(await waitForExit(record, Date.now() + timeoutMs))) {\n throw new VetraStartError(\n `Vetra (pid ${record.pid}) did not stop within ${Math.round((2 * timeoutMs) / 1000)}s.`,\n );\n }\n }\n clearVetraRuntime(projectDir, record.pid);\n if (readLock(projectDir)?.vetraPid === record.pid) {\n fs.rmSync(lockPath(projectDir), { force: true });\n }\n return record;\n}\n\n/** Stops this project's Vetra and starts it again, detached, as {@link ensureVetra} does. */\nexport async function restartVetra(\n options: EnsureVetraOptions,\n): Promise<VetraRuntimeRecord> {\n const { projectDir, projectName, onProgress } = options;\n const stopped = await stopVetra({ projectDir, projectName, onProgress });\n if (stopped) onProgress?.(`Stopped Vetra (pid ${stopped.pid}).`);\n return ensureVetra(options);\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAgBA,SAAS,gBAAgB,KAAK,WAAW,QAAQ,UAAU;CAC1D,OAAO,aAAa,UAAU,wBAAwB,QAAQ,KAAK;AACpE;AA0BA,MAAM,iBAAiB;;AAEvB,SAAS,UAAU,SAAS,YAAY,gBAAgB;CACvD,OAAO,IAAI,SAAS,YAAY;EAC/B,IAAI,YAAY;EAChB,MAAM,SAAS,IAAI,QAAQ,OAAO;EAClC,OAAO,WAAW,iBAAiB,OAAO,QAAQ,CAAC;EACnD,OAAO,KAAK,iBAAiB,YAAY,IAAI;EAC7C,OAAO,GAAG,eAAe,KAAK,CAAC;EAC/B,OAAO,KAAK,eAAe,QAAQ,SAAS,CAAC;EAC7C,OAAO,OAAO;CACf,CAAC;AACF;;;;;;AAMA,eAAe,YAAY,KAAK,WAAW,QAAQ,UAAU;CAC5D,MAAM,UAAU,gBAAgB,KAAK,QAAQ;CAC7C,IAAI,SAAS,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,EAAE,YAAY,aAAa,eAAe;CAChD,MAAM,UAAU,MAAM,UAAU;EAAE;EAAY;EAAa;CAAW,CAAC;CACvE,IAAI,SAAS,aAAa,sBAAsB,QAAQ,IAAI,GAAG;CAC/D,OAAO,YAAY,OAAO;AAC5B","debug_id":"3faa11c1-df67-5bd4-9c7c-d2e9ec978ec1"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { o as stopVetra } from "./vetra-launcher-6NKfi6Au.mjs";
|
|
2
|
+
export { stopVetra };
|
|
3
|
+
!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]="912c8d67-0dd0-5014-b84d-802cf0ebba6f")}catch(e){}}();
|
|
4
|
+
//# debugId=912c8d67-0dd0-5014-b84d-802cf0ebba6f
|
|
@@ -1,5 +1,5 @@
|
|
|
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]="fc15a2c7-5c9c-5739-b1e2-0bad2ebaa456")}catch(e){}}();
|
|
3
3
|
import fs from "node:fs";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import net from "node:net";
|
|
@@ -20,8 +20,8 @@ function writeVetraRuntime(projectDir, record) {
|
|
|
20
20
|
fs.writeFileSync(target, `${JSON.stringify(record, null, 2)}\n`);
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
|
-
* The record this process publishes for the
|
|
24
|
-
* `ph run
|
|
23
|
+
* The record this process publishes for the dev stack it started. `ph dev`
|
|
24
|
+
* and `ph run dev` both build it here, so the two write the same fields. The
|
|
25
25
|
* Switchboard's URLs follow from its port unless the caller knows them.
|
|
26
26
|
*/
|
|
27
27
|
function vetraRuntimeRecord(input) {
|
|
@@ -169,25 +169,7 @@ function syncMcpPortNotices(projectDir, port) {
|
|
|
169
169
|
return notices;
|
|
170
170
|
}
|
|
171
171
|
//#endregion
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* One Vetra per project. `ph run vetra` records its stack in
|
|
175
|
-
* `.ph/run/vetra.json` and, once ready, in `.ph/vetra-runtime.json`, which is
|
|
176
|
-
* what a start asks here: whether a Vetra already holds the project.
|
|
177
|
-
*/
|
|
178
|
-
/** The host folder `ph dev` runs, and the name its host file carries. */
|
|
179
|
-
const VETRA_HOST = "vetra";
|
|
180
|
-
/** Why `ph run vetra` must not start: a live Vetra holds the project. */
|
|
181
|
-
async function vetraRuntimeRefusal(projectDir, projectName) {
|
|
182
|
-
const probe = await probeVetraRuntime(projectDir, projectName);
|
|
183
|
-
if (probe.status === "live" || probe.status === "starting") {
|
|
184
|
-
if (probe.record.pid === process.pid) return void 0;
|
|
185
|
-
return `Vetra is already running for this project (pid ${probe.record.pid}). Stop it before starting another.`;
|
|
186
|
-
}
|
|
187
|
-
if (probe.status === "foreign") return `.ph/vetra-runtime.json describes a live Vetra for "${probe.record.projectName}", but this project is "${projectName}". Refusing to start a second instance. Delete .ph/vetra-runtime.json if that record is wrong.`;
|
|
188
|
-
}
|
|
189
|
-
//#endregion
|
|
190
|
-
export { probeVetraRuntime as a, vetraRuntimeRecord as c, isPortInUse as i, writeVetraRuntime as l, vetraRuntimeRefusal as n, readVetraRuntime as o, clearVetraRuntime as r, syncMcpPortNotices as s, VETRA_HOST as t };
|
|
172
|
+
export { syncMcpPortNotices as a, readVetraRuntime as i, isPortInUse as n, vetraRuntimeRecord as o, probeVetraRuntime as r, writeVetraRuntime as s, clearVetraRuntime as t };
|
|
191
173
|
|
|
192
|
-
//# sourceMappingURL=vetra-
|
|
193
|
-
//# debugId=
|
|
174
|
+
//# sourceMappingURL=vetra-runtime-Bk6CW-BE.mjs.map
|
|
175
|
+
//# debugId=fc15a2c7-5c9c-5739-b1e2-0bad2ebaa456
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vetra-runtime-Bk6CW-BE.mjs","sources":["../src/utils/vetra-runtime.ts"],"sourcesContent":["import { resolvePhDir } from \"@powerhousedao/shared/clis/ph-dir\";\nimport fs from \"node:fs\";\nimport net from \"node:net\";\nimport path from \"node:path\";\n\nexport type VetraRuntimeRecord = {\n pid: number;\n projectName: string;\n switchboardPort: number;\n connectPort: number;\n /** The Switchboard's GraphQL endpoint; absent in records from before it was written. */\n switchboardUrl?: string;\n mcpUrl: string;\n /** Vetra Studio; absent with --disable-connect. */\n connectUrl?: string;\n startedAt: string;\n};\n\nexport type VetraProbe =\n | { status: \"none\" }\n | { status: \"stale\" }\n | { status: \"starting\"; record: VetraRuntimeRecord }\n | { status: \"live\"; record: VetraRuntimeRecord }\n | { status: \"foreign\"; record: VetraRuntimeRecord };\n\nconst READY_TIMEOUT_MS = 2000;\n\n// Under the project's .ph tree — relocated with it by PH_USER_DATA_DIR.\nconst recordPath = (projectDir: string) =>\n path.join(resolvePhDir(projectDir), \"vetra-runtime.json\");\n\nexport function readVetraRuntime(\n projectDir: string,\n): VetraRuntimeRecord | undefined {\n try {\n return JSON.parse(\n fs.readFileSync(recordPath(projectDir), \"utf8\"),\n ) as VetraRuntimeRecord;\n } catch {\n // Missing or corrupt: either way there is no usable record.\n return undefined;\n }\n}\n\nexport function writeVetraRuntime(\n projectDir: string,\n record: VetraRuntimeRecord,\n): void {\n const target = recordPath(projectDir);\n fs.mkdirSync(path.dirname(target), { recursive: true });\n fs.writeFileSync(target, `${JSON.stringify(record, null, 2)}\\n`);\n}\n\n/**\n * The record this process publishes for the dev stack it started. `ph dev`\n * and `ph run dev` both build it here, so the two write the same fields. The\n * Switchboard's URLs follow from its port unless the caller knows them.\n */\nexport function vetraRuntimeRecord(input: {\n projectName: string;\n switchboardPort: number;\n connectPort: number;\n switchboardUrl?: string;\n mcpUrl?: string;\n /** Left out when no Vetra Studio runs. */\n connectUrl?: string;\n}): VetraRuntimeRecord {\n const { switchboardPort, connectUrl } = input;\n return {\n pid: process.pid,\n projectName: input.projectName,\n switchboardPort,\n connectPort: input.connectPort,\n switchboardUrl:\n input.switchboardUrl ?? `http://localhost:${switchboardPort}/graphql`,\n mcpUrl: input.mcpUrl ?? `http://localhost:${switchboardPort}/mcp`,\n ...(connectUrl ? { connectUrl } : {}),\n startedAt: new Date().toISOString(),\n };\n}\n\n/** Deletes the record; with `pid`, only the record of that process. */\nexport function clearVetraRuntime(projectDir: string, pid?: number): void {\n if (pid !== undefined && readVetraRuntime(projectDir)?.pid !== pid) return;\n try {\n fs.rmSync(recordPath(projectDir));\n } catch {\n // Already gone.\n }\n}\n\nfunction isPidAlive(pid: number): boolean {\n try {\n process.kill(pid, 0);\n return true;\n } catch (error) {\n // EPERM means the process exists but belongs to another user.\n return (error as NodeJS.ErrnoException).code === \"EPERM\";\n }\n}\n\nexport function isPortInUse(port: number): Promise<boolean> {\n return new Promise((resolve) => {\n const socket = net.connect({ port, host: \"localhost\" });\n socket.once(\"connect\", () => {\n socket.destroy();\n resolve(true);\n });\n socket.once(\"error\", () => resolve(false));\n });\n}\n\nasync function isReady(port: number): Promise<boolean> {\n try {\n const response = await fetch(`http://localhost:${port}/ready`, {\n signal: AbortSignal.timeout(READY_TIMEOUT_MS),\n });\n return response.ok;\n } catch {\n return false;\n }\n}\n\n/**\n * Decide whether the recorded instance is actually serving this project.\n *\n * All three checks are load-bearing. A pid can be reused by an unrelated\n * process, so a live pid proves nothing on its own. Another project's\n * switchboard would answer `/ready` on its own port, so a healthy `/ready`\n * proves nothing either. And the recorded `projectName` is what separates\n * \"my instance\" from \"someone else's instance that happens to hold this\n * port\" — which is precisely the confusion that let an agent write document\n * models into a different project's drive.\n *\n * A stale record is deleted so the next start is unblocked. A foreign one is\n * left alone: it describes something that is alive.\n */\nexport async function probeVetraRuntime(\n projectDir: string,\n projectName: string,\n): Promise<VetraProbe> {\n const record = readVetraRuntime(projectDir);\n if (!record) return { status: \"none\" };\n\n const alive = isPidAlive(record.pid);\n const ready = alive && (await isReady(record.switchboardPort));\n // The record lands once the port is bound; `/ready` turns 200 later.\n const starting =\n alive && !ready && (await isPortInUse(record.switchboardPort));\n if (!ready && !starting) {\n clearVetraRuntime(projectDir);\n return { status: \"stale\" };\n }\n\n if (record.projectName !== projectName) {\n return { status: \"foreign\", record };\n }\n return ready ? { status: \"live\", record } : { status: \"starting\", record };\n}\n\nconst MCP_FILES = [\n \".mcp.json\",\n path.join(\".cursor\", \"mcp.json\"),\n path.join(\".gemini\", \"settings.json\"),\n];\n\ntype McpConfig = { mcpServers?: Record<string, { url?: string }> };\ntype UrlMcpConfig = [string, McpConfig, { url?: string }];\n\n/** Each MCP config whose `reactor-mcp` entry still points at a URL. */\nfunction urlMcpConfigs(projectDir: string): UrlMcpConfig[] {\n const found: UrlMcpConfig[] = [];\n for (const rel of MCP_FILES) {\n const target = path.join(projectDir, rel);\n if (!fs.existsSync(target)) continue;\n let parsed: McpConfig;\n try {\n parsed = JSON.parse(fs.readFileSync(target, \"utf8\")) as McpConfig;\n } catch {\n // Hand-broken JSON is the author's to fix; don't clobber it.\n continue;\n }\n const server = parsed.mcpServers?.[\"reactor-mcp\"];\n if (server?.url) found.push([rel, parsed, server]);\n }\n return found;\n}\n\n/** The MCP configs `ph migrate` would move to the `ph mcp` launcher. */\nexport function legacyMcpConfigs(projectDir: string): string[] {\n return urlMcpConfigs(projectDir).map(([rel]) => rel);\n}\n\n/**\n * Point every URL-style `reactor-mcp` entry at `port`, returning the files\n * changed. Stdio entries (`ph mcp`) carry no port and are left alone; this\n * keeps projects that have not run `ph migrate` working.\n */\nexport function syncMcpPort(projectDir: string, port: number): string[] {\n const changed: string[] = [];\n const wanted = `http://localhost:${port}/mcp`;\n for (const [rel, parsed, server] of urlMcpConfigs(projectDir)) {\n if (server.url === wanted) continue;\n server.url = wanted;\n fs.writeFileSync(\n path.join(projectDir, rel),\n `${JSON.stringify(parsed, null, 2)}\\n`,\n );\n changed.push(rel);\n }\n return changed;\n}\n\n/**\n * {@link syncMcpPort} for a Vetra that just bound `port`, returning what to\n * tell the user. An MCP client resolved `.mcp.json` before this process\n * started and cannot re-read it, so a drifted literal means the agent is\n * pointed at the wrong port — possibly another project's reactor. Correct the\n * file and say so plainly; we cannot fix the already-open client ourselves.\n */\nexport function syncMcpPortNotices(projectDir: string, port: number): string[] {\n const notices: string[] = [];\n const driftedMcpFiles = syncMcpPort(projectDir, port);\n if (driftedMcpFiles.length > 0) {\n notices.push(\n `Updated ${driftedMcpFiles.join(\" and \")} to port ${port}. ` +\n `Reconnect your MCP client (/mcp) to pick it up. ` +\n `This edit is local — do not commit it.`,\n );\n }\n if (legacyMcpConfigs(projectDir).length > 0) {\n notices.push(\n \"reactor-mcp still points at a URL; run `ph migrate` to switch it to the `ph mcp` launcher.\",\n );\n }\n return notices;\n}\n"],"names":[],"mappings":";;;;;;;AAyBA,MAAM,mBAAmB;AAGzB,MAAM,cAAc,eAClB,KAAK,KAAK,aAAa,UAAU,GAAG,oBAAoB;AAE1D,SAAgB,iBACd,YACgC;CAChC,IAAI;EACF,OAAO,KAAK,MACV,GAAG,aAAa,WAAW,UAAU,GAAG,MAAM,CAChD;CACF,QAAQ;EAEN;CACF;AACF;AAEA,SAAgB,kBACd,YACA,QACM;CACN,MAAM,SAAS,WAAW,UAAU;CACpC,GAAG,UAAU,KAAK,QAAQ,MAAM,GAAG,EAAE,WAAW,KAAK,CAAC;CACtD,GAAG,cAAc,QAAQ,GAAG,KAAK,UAAU,QAAQ,MAAM,CAAC,EAAE,GAAG;AACjE;;;;;;AAOA,SAAgB,mBAAmB,OAQZ;CACrB,MAAM,EAAE,iBA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