@evref-bl/plexus 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/cli.js +79 -187
- package/dist/cli.js.map +1 -1
- package/dist/config/config.d.ts +0 -14
- package/dist/config/config.d.ts.map +1 -1
- package/dist/config/config.js +0 -49
- package/dist/config/config.js.map +1 -1
- package/dist/config/projectConfig.d.ts +0 -81
- package/dist/config/projectConfig.d.ts.map +1 -1
- package/dist/config/projectConfig.js +0 -410
- package/dist/config/projectConfig.js.map +1 -1
- package/dist/gateway/projectImageMcpEndpoint.d.ts +0 -1
- package/dist/gateway/projectImageMcpEndpoint.d.ts.map +1 -1
- package/dist/gateway/projectImageMcpEndpoint.js +3 -43
- package/dist/gateway/projectImageMcpEndpoint.js.map +1 -1
- package/dist/gateway/server/index.d.ts +8 -0
- package/dist/gateway/server/index.d.ts.map +1 -0
- package/dist/gateway/server/index.js +34 -0
- package/dist/gateway/server/index.js.map +1 -0
- package/dist/gateway/server/mcp/server.d.ts +66 -0
- package/dist/gateway/server/mcp/server.d.ts.map +1 -0
- package/dist/gateway/server/mcp/server.js +458 -0
- package/dist/gateway/server/mcp/server.js.map +1 -0
- package/dist/gateway/server/routing/endpointHandoffFormat.d.ts +26 -0
- package/dist/gateway/server/routing/endpointHandoffFormat.d.ts.map +1 -0
- package/dist/gateway/server/routing/endpointHandoffFormat.js +52 -0
- package/dist/gateway/server/routing/endpointHandoffFormat.js.map +1 -0
- package/dist/gateway/server/routing/gateway.d.ts +167 -0
- package/dist/gateway/server/routing/gateway.d.ts.map +1 -0
- package/dist/gateway/server/routing/gateway.js +863 -0
- package/dist/gateway/server/routing/gateway.js.map +1 -0
- package/dist/gateway/server/routing/imageMcpRouter.d.ts +59 -0
- package/dist/gateway/server/routing/imageMcpRouter.d.ts.map +1 -0
- package/dist/gateway/server/routing/imageMcpRouter.js +248 -0
- package/dist/gateway/server/routing/imageMcpRouter.js.map +1 -0
- package/dist/gateway/server/routing/pharoFacade.d.ts +12 -0
- package/dist/gateway/server/routing/pharoFacade.d.ts.map +1 -0
- package/dist/gateway/server/routing/pharoFacade.js +67 -0
- package/dist/gateway/server/routing/pharoFacade.js.map +1 -0
- package/dist/gateway/server/routing/routeDiscovery.d.ts +26 -0
- package/dist/gateway/server/routing/routeDiscovery.d.ts.map +1 -0
- package/dist/gateway/server/routing/routeDiscovery.js +46 -0
- package/dist/gateway/server/routing/routeDiscovery.js.map +1 -0
- package/dist/gateway/server/routing/routingTable.d.ts +116 -0
- package/dist/gateway/server/routing/routingTable.d.ts.map +1 -0
- package/dist/gateway/server/routing/routingTable.js +215 -0
- package/dist/gateway/server/routing/routingTable.js.map +1 -0
- package/dist/gateway/server/support/processLiveness.d.ts +10 -0
- package/dist/gateway/server/support/processLiveness.d.ts.map +1 -0
- package/dist/gateway/server/support/processLiveness.js +25 -0
- package/dist/gateway/server/support/processLiveness.js.map +1 -0
- package/dist/gateway/server/support/sourceBuildPreflight.d.ts +15 -0
- package/dist/gateway/server/support/sourceBuildPreflight.d.ts.map +1 -0
- package/dist/gateway/server/support/sourceBuildPreflight.js +88 -0
- package/dist/gateway/server/support/sourceBuildPreflight.js.map +1 -0
- package/dist/gateway/server/support/toolResultFormatting.d.ts +8 -0
- package/dist/gateway/server/support/toolResultFormatting.d.ts.map +1 -0
- package/dist/gateway/server/support/toolResultFormatting.js +81 -0
- package/dist/gateway/server/support/toolResultFormatting.js.map +1 -0
- package/dist/images/homeImageCache.d.ts +0 -2
- package/dist/images/homeImageCache.d.ts.map +1 -1
- package/dist/images/homeImageCache.js +4 -8
- package/dist/images/homeImageCache.js.map +1 -1
- package/dist/images/imageRescue.d.ts +1 -4
- package/dist/images/imageRescue.d.ts.map +1 -1
- package/dist/images/imageRescue.js +32 -44
- package/dist/images/imageRescue.js.map +1 -1
- package/dist/images/imageRuntime.d.ts +60 -0
- package/dist/images/imageRuntime.d.ts.map +1 -0
- package/dist/images/imageRuntime.js +94 -0
- package/dist/images/imageRuntime.js.map +1 -0
- package/dist/images/preparedImageCache.d.ts +0 -1
- package/dist/images/preparedImageCache.d.ts.map +1 -1
- package/dist/images/preparedImageCache.js +0 -4
- package/dist/images/preparedImageCache.js.map +1 -1
- package/dist/images/scopedTemplateCatalog.js +2 -2
- package/dist/images/scopedTemplateCatalog.js.map +1 -1
- package/dist/index.d.ts +1 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -9
- package/dist/index.js.map +1 -1
- package/dist/launcher/pharoLauncherMcpClient.d.ts +12 -6
- package/dist/launcher/pharoLauncherMcpClient.d.ts.map +1 -1
- package/dist/launcher/pharoLauncherMcpClient.js +68 -61
- package/dist/launcher/pharoLauncherMcpClient.js.map +1 -1
- package/dist/launcher/pharoLauncherProfile.d.ts +0 -1
- package/dist/launcher/pharoLauncherProfile.d.ts.map +1 -1
- package/dist/launcher/pharoLauncherProfile.js.map +1 -1
- package/dist/launcher/scopedPharoLauncherServer.d.ts +96 -26
- package/dist/launcher/scopedPharoLauncherServer.d.ts.map +1 -1
- package/dist/launcher/scopedPharoLauncherServer.js +261 -173
- package/dist/launcher/scopedPharoLauncherServer.js.map +1 -1
- package/dist/lifecycle/projectClose.d.ts +10 -6
- package/dist/lifecycle/projectClose.d.ts.map +1 -1
- package/dist/lifecycle/projectClose.js +50 -102
- package/dist/lifecycle/projectClose.js.map +1 -1
- package/dist/lifecycle/projectOpen.d.ts +38 -5
- package/dist/lifecycle/projectOpen.d.ts.map +1 -1
- package/dist/lifecycle/projectOpen.js +115 -480
- package/dist/lifecycle/projectOpen.js.map +1 -1
- package/dist/mcp/agentServer.d.ts +15 -0
- package/dist/mcp/agentServer.d.ts.map +1 -0
- package/dist/mcp/agentServer.js +71 -0
- package/dist/mcp/agentServer.js.map +1 -0
- package/dist/mcp/imageOperations.d.ts +0 -5
- package/dist/mcp/imageOperations.d.ts.map +1 -1
- package/dist/mcp/imageOperations.js +0 -15
- package/dist/mcp/imageOperations.js.map +1 -1
- package/dist/workspace/projectStartupScript.d.ts +3 -10
- package/dist/workspace/projectStartupScript.d.ts.map +1 -1
- package/dist/workspace/projectStartupScript.js +21 -170
- package/dist/workspace/projectStartupScript.js.map +1 -1
- package/dist/workspace/projectState.d.ts +4 -121
- package/dist/workspace/projectState.d.ts.map +1 -1
- package/dist/workspace/projectState.js +4 -212
- package/dist/workspace/projectState.js.map +1 -1
- package/package.json +10 -5
- package/dist/config/target.d.ts +0 -19
- package/dist/config/target.d.ts.map +0 -1
- package/dist/config/target.js +0 -2
- package/dist/config/target.js.map +0 -1
- package/dist/gateway/projectGateway.d.ts +0 -80
- package/dist/gateway/projectGateway.d.ts.map +0 -1
- package/dist/gateway/projectGateway.js +0 -435
- package/dist/gateway/projectGateway.js.map +0 -1
- package/dist/lifecycle/projectCleanup.d.ts +0 -59
- package/dist/lifecycle/projectCleanup.d.ts.map +0 -1
- package/dist/lifecycle/projectCleanup.js +0 -483
- package/dist/lifecycle/projectCleanup.js.map +0 -1
- package/dist/lifecycle/projectLifecycle.d.ts +0 -422
- package/dist/lifecycle/projectLifecycle.d.ts.map +0 -1
- package/dist/lifecycle/projectLifecycle.js +0 -2114
- package/dist/lifecycle/projectLifecycle.js.map +0 -1
- package/dist/mcp/server.d.ts +0 -86
- package/dist/mcp/server.d.ts.map +0 -1
- package/dist/mcp/server.js +0 -358
- package/dist/mcp/server.js.map +0 -1
- package/dist/ports/imagePortClaims.d.ts +0 -41
- package/dist/ports/imagePortClaims.d.ts.map +0 -1
- package/dist/ports/imagePortClaims.js +0 -337
- package/dist/ports/imagePortClaims.js.map +0 -1
- package/dist/ports/portClaims.d.ts +0 -116
- package/dist/ports/portClaims.d.ts.map +0 -1
- package/dist/ports/portClaims.js +0 -393
- package/dist/ports/portClaims.js.map +0 -1
- package/dist/support/runtimeIdentity.d.ts +0 -13
- package/dist/support/runtimeIdentity.d.ts.map +0 -1
- package/dist/support/runtimeIdentity.js +0 -38
- package/dist/support/runtimeIdentity.js.map +0 -1
- package/dist/workspace/projectRepositoryWorkspace.d.ts +0 -74
- package/dist/workspace/projectRepositoryWorkspace.d.ts.map +0 -1
- package/dist/workspace/projectRepositoryWorkspace.js +0 -553
- package/dist/workspace/projectRepositoryWorkspace.js.map +0 -1
- package/dist/workspace/scopedProjectContext.d.ts +0 -169
- package/dist/workspace/scopedProjectContext.d.ts.map +0 -1
- package/dist/workspace/scopedProjectContext.js +0 -358
- package/dist/workspace/scopedProjectContext.js.map +0 -1
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
|
+
import { joinPathLike } from "../support/pathStyle.js";
|
|
2
3
|
import path from "node:path";
|
|
3
|
-
import { loadProjectConfig, projectImageDisplayMode,
|
|
4
|
-
import {
|
|
5
|
-
import { defaultImagePortClaimChecks, imagePortClaimsRootForConfig, prepareImagePortClaims, recordImagePortClaimProcess, releaseImagePortClaimIfOwned, releasePreparedImagePortClaims, } from "../ports/imagePortClaims.js";
|
|
6
|
-
import { createStdioPharoLauncherMcpClient, PharoLauncherMcpToolError, } from "../launcher/pharoLauncherMcpClient.js";
|
|
4
|
+
import { loadProjectConfig, projectImageDisplayMode, projectMcpStartupMode, } from "../config/projectConfig.js";
|
|
5
|
+
import { openPharoLauncherClient, PharoLauncherMcpToolError, } from "../launcher/pharoLauncherMcpClient.js";
|
|
7
6
|
import { copyProjectImageFromPreparedCache, } from "../images/preparedImageCache.js";
|
|
8
7
|
import { materializeProjectImageFromHomeCache, projectImageCanUseHomeImageCache, } from "../images/homeImageCache.js";
|
|
8
|
+
import { isPidAlive } from "../gateway/server/support/processLiveness.js";
|
|
9
9
|
import { pharoLauncherMcpProfileEnvironment } from "../launcher/pharoLauncherProfile.js";
|
|
10
10
|
import { HttpPharoMcpHealthClient, } from "../mcp/pharoMcpHealth.js";
|
|
11
|
-
import { assertRepositoryIdentity, registerRepository, repositoryIsRegistered, } from "../mcp/imageOperations.js";
|
|
12
11
|
import { imageMcpEndpointHandoffPath, readImageMcpEndpointHandoff, removeImageMcpEndpointHandoff, } from "../gateway/projectImageMcpEndpoint.js";
|
|
13
|
-
import {
|
|
12
|
+
import { createProjectState, defaultWorkspaceId, loadProjectState, projectStatePathForConfig, projectStateRootForConfig, runtimeStatusForImages, sanitizeRuntimeId, saveProjectState, } from "../workspace/projectState.js";
|
|
14
13
|
import { writeProjectImageStartupScript } from "../workspace/projectStartupScript.js";
|
|
15
|
-
import { materializeProjectImageRepositoryWorkspaces } from "../workspace/projectRepositoryWorkspace.js";
|
|
16
14
|
export class ProjectOpenError extends Error {
|
|
17
15
|
result;
|
|
18
16
|
constructor(message, result) {
|
|
@@ -74,15 +72,7 @@ function isObject(value) {
|
|
|
74
72
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
75
73
|
}
|
|
76
74
|
function imageMcpEndpointForImage(image) {
|
|
77
|
-
return
|
|
78
|
-
(image.assignedPort === undefined
|
|
79
|
-
? undefined
|
|
80
|
-
: {
|
|
81
|
-
transport: "http",
|
|
82
|
-
host: "127.0.0.1",
|
|
83
|
-
port: image.assignedPort,
|
|
84
|
-
path: "/",
|
|
85
|
-
}));
|
|
75
|
+
return image.mcpServers?.find((server) => server.id === image.id)?.endpoint;
|
|
86
76
|
}
|
|
87
77
|
function hostForUrl(host) {
|
|
88
78
|
return host.includes(":") && !host.startsWith("[") ? `[${host}]` : host;
|
|
@@ -153,39 +143,6 @@ class HttpProjectOpenImageMcpClient {
|
|
|
153
143
|
}
|
|
154
144
|
}
|
|
155
145
|
}
|
|
156
|
-
function optionalStringField(value, key) {
|
|
157
|
-
return typeof value[key] === "string" && value[key].length > 0
|
|
158
|
-
? value[key]
|
|
159
|
-
: undefined;
|
|
160
|
-
}
|
|
161
|
-
function launcherImageInfo(value) {
|
|
162
|
-
if (!isObject(value)) {
|
|
163
|
-
return undefined;
|
|
164
|
-
}
|
|
165
|
-
const originTemplate = isObject(value.originTemplate)
|
|
166
|
-
? {
|
|
167
|
-
...(optionalStringField(value.originTemplate, "name")
|
|
168
|
-
? { name: optionalStringField(value.originTemplate, "name") }
|
|
169
|
-
: {}),
|
|
170
|
-
...(optionalStringField(value.originTemplate, "url")
|
|
171
|
-
? { url: optionalStringField(value.originTemplate, "url") }
|
|
172
|
-
: {}),
|
|
173
|
-
}
|
|
174
|
-
: undefined;
|
|
175
|
-
const pharoVersion = typeof value.pharoVersion === "string" || typeof value.pharoVersion === "number"
|
|
176
|
-
? value.pharoVersion
|
|
177
|
-
: undefined;
|
|
178
|
-
return {
|
|
179
|
-
imagePath: optionalStringField(value, "imagePath"),
|
|
180
|
-
imageDirectoryPath: optionalStringField(value, "imageDirectoryPath"),
|
|
181
|
-
changesPath: optionalStringField(value, "changesPath"),
|
|
182
|
-
localDirectoryPath: optionalStringField(value, "localDirectoryPath"),
|
|
183
|
-
ombuDirectoryPath: optionalStringField(value, "ombuDirectoryPath"),
|
|
184
|
-
...(pharoVersion !== undefined ? { pharoVersion } : {}),
|
|
185
|
-
vmId: optionalStringField(value, "vmId"),
|
|
186
|
-
...(originTemplate ? { originTemplate } : {}),
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
146
|
function logPathFromLine(line) {
|
|
190
147
|
const separator = line.indexOf(":");
|
|
191
148
|
if (separator < 0) {
|
|
@@ -245,18 +202,9 @@ function launcherProcessFromResult(result, imageName) {
|
|
|
245
202
|
return {
|
|
246
203
|
pid,
|
|
247
204
|
imageName,
|
|
248
|
-
commandLine: `
|
|
205
|
+
commandLine: `pharo_launcher_image_start ${imageName}`,
|
|
249
206
|
};
|
|
250
207
|
}
|
|
251
|
-
function isPidAlive(pid) {
|
|
252
|
-
try {
|
|
253
|
-
globalThis.process.kill(pid, 0);
|
|
254
|
-
return true;
|
|
255
|
-
}
|
|
256
|
-
catch (error) {
|
|
257
|
-
return isObject(error) && error.code === "ESRCH" ? false : true;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
208
|
function collectLauncherLogPaths(value, fieldName) {
|
|
261
209
|
if (typeof value === "string") {
|
|
262
210
|
if (value.length === 0) {
|
|
@@ -287,156 +235,11 @@ function startupFailureDetails(error) {
|
|
|
287
235
|
return {};
|
|
288
236
|
}
|
|
289
237
|
return {
|
|
290
|
-
launcherToolName: "
|
|
238
|
+
launcherToolName: "pharo_launcher_image_start",
|
|
291
239
|
launcherResult: error.launcherResult,
|
|
292
240
|
process: error.process,
|
|
293
241
|
};
|
|
294
242
|
}
|
|
295
|
-
function profileImagesDirectory(value) {
|
|
296
|
-
if (!isObject(value) || !isObject(value.profile) || !isObject(value.profile.imagesDir)) {
|
|
297
|
-
return undefined;
|
|
298
|
-
}
|
|
299
|
-
return optionalStringField(value.profile.imagesDir, "path");
|
|
300
|
-
}
|
|
301
|
-
async function launcherImagesDirectory(client) {
|
|
302
|
-
const result = await client.callTool("pharo_launcher_config", {});
|
|
303
|
-
assertLauncherOk(result, "pharo_launcher_config");
|
|
304
|
-
return profileImagesDirectory(launcherResultData(result));
|
|
305
|
-
}
|
|
306
|
-
function normalizeImagePath(imagePath, imagesDirectory) {
|
|
307
|
-
if (isAbsolutePathLike(imagePath)) {
|
|
308
|
-
return resolvePathLike(imagePath);
|
|
309
|
-
}
|
|
310
|
-
return imagesDirectory ? joinPathLike(imagesDirectory, imagePath) : imagePath;
|
|
311
|
-
}
|
|
312
|
-
function applyLauncherImageInfo(imageState, info, imagesDirectory) {
|
|
313
|
-
if (!info) {
|
|
314
|
-
return;
|
|
315
|
-
}
|
|
316
|
-
const imagePath = info.imagePath
|
|
317
|
-
? normalizeImagePath(info.imagePath, imagesDirectory)
|
|
318
|
-
: undefined;
|
|
319
|
-
const imageDirectoryPath = info.imageDirectoryPath ??
|
|
320
|
-
(imagePath ? dirnamePathLike(imagePath) : undefined);
|
|
321
|
-
imageState.imagePath = imagePath ?? imageState.imagePath;
|
|
322
|
-
imageState.imageDirectoryPath =
|
|
323
|
-
imageDirectoryPath ?? imageState.imageDirectoryPath;
|
|
324
|
-
imageState.changesPath =
|
|
325
|
-
info.changesPath ??
|
|
326
|
-
(imagePath ? imagePath.replace(/\.image$/i, ".changes") : imageState.changesPath);
|
|
327
|
-
imageState.localDirectoryPath =
|
|
328
|
-
info.localDirectoryPath ??
|
|
329
|
-
(imageDirectoryPath
|
|
330
|
-
? joinPathLike(imageDirectoryPath, "pharo-local")
|
|
331
|
-
: imageState.localDirectoryPath);
|
|
332
|
-
imageState.ombuDirectoryPath =
|
|
333
|
-
info.ombuDirectoryPath ??
|
|
334
|
-
(imageDirectoryPath
|
|
335
|
-
? joinPathLike(imageDirectoryPath, "ombu")
|
|
336
|
-
: imageState.ombuDirectoryPath);
|
|
337
|
-
imageState.vmId = info.vmId ?? imageState.vmId;
|
|
338
|
-
imageState.pharoVersion =
|
|
339
|
-
info.pharoVersion !== undefined
|
|
340
|
-
? String(info.pharoVersion)
|
|
341
|
-
: imageState.pharoVersion;
|
|
342
|
-
imageState.originTemplate = info.originTemplate ?? imageState.originTemplate;
|
|
343
|
-
}
|
|
344
|
-
function applyLauncherProfileImagePathFallback(imageState, imagesDirectory) {
|
|
345
|
-
if (!imagesDirectory || !repositoryWorkspaceNeedsLauncherPaths(imageState)) {
|
|
346
|
-
return;
|
|
347
|
-
}
|
|
348
|
-
const imageDirectoryPath = joinPathLike(imagesDirectory, imageState.imageName);
|
|
349
|
-
const imagePath = joinPathLike(imageDirectoryPath, `${imageState.imageName}.image`);
|
|
350
|
-
if (!fs.existsSync(imagePath)) {
|
|
351
|
-
return;
|
|
352
|
-
}
|
|
353
|
-
applyLauncherImageInfo(imageState, {
|
|
354
|
-
imagePath,
|
|
355
|
-
imageDirectoryPath,
|
|
356
|
-
changesPath: joinPathLike(imageDirectoryPath, `${imageState.imageName}.changes`),
|
|
357
|
-
localDirectoryPath: joinPathLike(imageDirectoryPath, "pharo-local"),
|
|
358
|
-
ombuDirectoryPath: joinPathLike(imageDirectoryPath, "ombu"),
|
|
359
|
-
});
|
|
360
|
-
}
|
|
361
|
-
function repositoryWorkspaceNeedsLauncherPaths(imageState) {
|
|
362
|
-
return (!imageState.localDirectoryPath &&
|
|
363
|
-
projectImageRepositoryWorkspaces(imageState).some((workspace) => workspace.path.startsWith("image-local://")));
|
|
364
|
-
}
|
|
365
|
-
function appendRepositoryWorkspaceDiagnostic(workspace, message) {
|
|
366
|
-
if (workspace.diagnostics.includes(message)) {
|
|
367
|
-
return;
|
|
368
|
-
}
|
|
369
|
-
workspace.diagnostics = [...workspace.diagnostics, message];
|
|
370
|
-
}
|
|
371
|
-
function repositoryWorkspaceSourcePath(workspace) {
|
|
372
|
-
return workspace.loadSourcePath ?? joinPathLike(workspace.path, workspace.sourceDirectory);
|
|
373
|
-
}
|
|
374
|
-
function inferTonelPackageNames(sourcePath) {
|
|
375
|
-
if (!fs.existsSync(sourcePath)) {
|
|
376
|
-
return [];
|
|
377
|
-
}
|
|
378
|
-
return fs
|
|
379
|
-
.readdirSync(sourcePath, { withFileTypes: true })
|
|
380
|
-
.filter((entry) => entry.isDirectory() &&
|
|
381
|
-
fs.existsSync(joinPathLike(sourcePath, entry.name, "package.st")))
|
|
382
|
-
.map((entry) => entry.name)
|
|
383
|
-
.sort((left, right) => left.localeCompare(right));
|
|
384
|
-
}
|
|
385
|
-
async function ensureRepositoryWorkspaceRegistered(options) {
|
|
386
|
-
const workspace = options.workspace;
|
|
387
|
-
if (!workspace || workspace.loadState !== "loaded") {
|
|
388
|
-
return;
|
|
389
|
-
}
|
|
390
|
-
const endpoint = imageMcpEndpointForImage(options.imageState);
|
|
391
|
-
if (!endpoint) {
|
|
392
|
-
const message = `Repository workspace registration skipped for image ${options.imageState.id}: image has no routable Pharo MCP endpoint.`;
|
|
393
|
-
workspace.registrationState = "skipped";
|
|
394
|
-
workspace.registrationError = message;
|
|
395
|
-
appendRepositoryWorkspaceDiagnostic(workspace, message);
|
|
396
|
-
if (imageRequiresPharoMcpHealth(options.imageConfig, options.imageState)) {
|
|
397
|
-
workspace.registrationState = "failed";
|
|
398
|
-
throw new Error(message);
|
|
399
|
-
}
|
|
400
|
-
return;
|
|
401
|
-
}
|
|
402
|
-
if (!imageCanRouteToPharoMcp(options.imageConfig, options.imageState)) {
|
|
403
|
-
const message = `Repository workspace registration skipped for image ${options.imageState.id}: Pharo MCP startup is disabled or unsupported.`;
|
|
404
|
-
workspace.registrationState = "skipped";
|
|
405
|
-
workspace.registrationError = message;
|
|
406
|
-
appendRepositoryWorkspaceDiagnostic(workspace, message);
|
|
407
|
-
return;
|
|
408
|
-
}
|
|
409
|
-
workspace.registrationState = "pending";
|
|
410
|
-
delete workspace.registrationError;
|
|
411
|
-
delete workspace.registeredRepositoryName;
|
|
412
|
-
delete workspace.registeredPackageNames;
|
|
413
|
-
const packages = inferTonelPackageNames(repositoryWorkspaceSourcePath(workspace));
|
|
414
|
-
const repositoryPath = workspace.path;
|
|
415
|
-
const repositoryName = workspace.repository.id;
|
|
416
|
-
const repository = {
|
|
417
|
-
name: repositoryName,
|
|
418
|
-
location: repositoryPath,
|
|
419
|
-
subdirectory: workspace.sourceDirectory,
|
|
420
|
-
packages,
|
|
421
|
-
};
|
|
422
|
-
try {
|
|
423
|
-
const alreadyRegistered = await repositoryIsRegistered(options.imageMcpClient, options.imageState, repository);
|
|
424
|
-
await registerRepository(options.imageMcpClient, options.imageState, repository, { alreadyRegistered });
|
|
425
|
-
// The image now manages exactly what was just asked of it, so the same
|
|
426
|
-
// expectations read as a post-condition: anything it refused shows up here.
|
|
427
|
-
await assertRepositoryIdentity(options.imageMcpClient, options.imageState, repository);
|
|
428
|
-
workspace.registrationState = "registered";
|
|
429
|
-
workspace.registeredRepositoryName = repositoryName;
|
|
430
|
-
workspace.registeredPackageNames = packages;
|
|
431
|
-
}
|
|
432
|
-
catch (error) {
|
|
433
|
-
const message = errorMessage(error);
|
|
434
|
-
workspace.registrationState = "failed";
|
|
435
|
-
workspace.registrationError = message;
|
|
436
|
-
appendRepositoryWorkspaceDiagnostic(workspace, message);
|
|
437
|
-
throw new Error(`Repository workspace registration failed for image ${options.imageState.id}: ${message}`);
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
243
|
function parseStatusProperties(filePath) {
|
|
441
244
|
return Object.fromEntries(fs
|
|
442
245
|
.readFileSync(filePath, "utf8")
|
|
@@ -575,83 +378,6 @@ function refreshDependencyRepositoryDetachStatus(imageState, statusPath) {
|
|
|
575
378
|
};
|
|
576
379
|
return message;
|
|
577
380
|
}
|
|
578
|
-
function clearRepositoryWorkspaceLoadStatuses(statusPaths) {
|
|
579
|
-
if (!statusPaths) {
|
|
580
|
-
return;
|
|
581
|
-
}
|
|
582
|
-
for (const statusPath of Object.values(statusPaths)) {
|
|
583
|
-
fs.rmSync(statusPath, { force: true });
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
function prepareRepositoryWorkspaceLoadStatuses(imageState, statusPaths) {
|
|
587
|
-
if (!statusPaths) {
|
|
588
|
-
return;
|
|
589
|
-
}
|
|
590
|
-
for (const workspace of projectImageRepositoryWorkspaces(imageState)) {
|
|
591
|
-
const statusPath = statusPaths[workspace.repository.id];
|
|
592
|
-
if (!statusPath) {
|
|
593
|
-
continue;
|
|
594
|
-
}
|
|
595
|
-
workspace.loadState = "pending";
|
|
596
|
-
workspace.loadStatusPath = statusPath;
|
|
597
|
-
workspace.loadSourcePath = joinPathLike(workspace.path, workspace.sourceDirectory);
|
|
598
|
-
delete workspace.loadError;
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
function refreshRepositoryWorkspaceLoadStatus(imageState, workspace) {
|
|
602
|
-
if (!workspace?.loadStatusPath) {
|
|
603
|
-
return undefined;
|
|
604
|
-
}
|
|
605
|
-
if (!fs.existsSync(workspace.loadStatusPath)) {
|
|
606
|
-
appendRepositoryWorkspaceDiagnostic(workspace, `Pharo project load has not reported status at ${workspace.loadStatusPath}.`);
|
|
607
|
-
return undefined;
|
|
608
|
-
}
|
|
609
|
-
const properties = parseStatusProperties(workspace.loadStatusPath);
|
|
610
|
-
const status = properties.status;
|
|
611
|
-
workspace.loadSourcePath = properties.sourcePath ?? workspace.loadSourcePath;
|
|
612
|
-
if (properties.message) {
|
|
613
|
-
workspace.loadError = properties.message;
|
|
614
|
-
}
|
|
615
|
-
if (status === "loaded") {
|
|
616
|
-
workspace.loadState = "loaded";
|
|
617
|
-
delete workspace.loadError;
|
|
618
|
-
return undefined;
|
|
619
|
-
}
|
|
620
|
-
if (status === "failed") {
|
|
621
|
-
workspace.loadState = "failed";
|
|
622
|
-
workspace.loadError =
|
|
623
|
-
properties.message ?? "Pharo project load failed without a reported message.";
|
|
624
|
-
appendRepositoryWorkspaceDiagnostic(workspace, workspace.loadError);
|
|
625
|
-
return `Pharo project load failed for image ${imageState.id}: ${workspace.loadError}`;
|
|
626
|
-
}
|
|
627
|
-
workspace.loadState = "failed";
|
|
628
|
-
workspace.loadError = `Invalid Pharo project load status at ${workspace.loadStatusPath}: ${status ?? "(missing)"}`;
|
|
629
|
-
appendRepositoryWorkspaceDiagnostic(workspace, workspace.loadError);
|
|
630
|
-
return workspace.loadError;
|
|
631
|
-
}
|
|
632
|
-
function refreshRepositoryWorkspaceLoadStatuses(imageState) {
|
|
633
|
-
let firstFailure;
|
|
634
|
-
for (const workspace of projectImageRepositoryWorkspaces(imageState)) {
|
|
635
|
-
const failure = refreshRepositoryWorkspaceLoadStatus(imageState, workspace);
|
|
636
|
-
firstFailure ??= failure;
|
|
637
|
-
}
|
|
638
|
-
return firstFailure;
|
|
639
|
-
}
|
|
640
|
-
async function hydrateRepositoryWorkspaceImagePaths(client, imageState, fallbackImagesDirectory) {
|
|
641
|
-
if (!repositoryWorkspaceNeedsLauncherPaths(imageState)) {
|
|
642
|
-
return;
|
|
643
|
-
}
|
|
644
|
-
const infoResult = await client.callTool("pharo_launcher_image_info", {
|
|
645
|
-
imageName: imageState.imageName,
|
|
646
|
-
});
|
|
647
|
-
assertLauncherOk(infoResult, "pharo_launcher_image_info");
|
|
648
|
-
const info = launcherImageInfo(launcherResultData(infoResult));
|
|
649
|
-
const imagesDirectory = info?.imagePath && !isAbsolutePathLike(info.imagePath)
|
|
650
|
-
? await launcherImagesDirectory(client)
|
|
651
|
-
: undefined;
|
|
652
|
-
applyLauncherImageInfo(imageState, info, imagesDirectory);
|
|
653
|
-
applyLauncherProfileImagePathFallback(imageState, fallbackImagesDirectory);
|
|
654
|
-
}
|
|
655
381
|
async function pollUntil(timeoutMs, intervalMs, sleep, attempt) {
|
|
656
382
|
const startedAt = Date.now();
|
|
657
383
|
while (Date.now() - startedAt <= timeoutMs) {
|
|
@@ -684,11 +410,49 @@ async function pollStartupProcessForImage(client, imageName, launchedProcess, ti
|
|
|
684
410
|
return undefined;
|
|
685
411
|
});
|
|
686
412
|
}
|
|
687
|
-
|
|
413
|
+
/**
|
|
414
|
+
* Every VM the host has on this image, ours or not. PLexus owns at most one of
|
|
415
|
+
* them, so the rest are only ever read — to refuse a launch that would make a
|
|
416
|
+
* second, and to name what is in the way.
|
|
417
|
+
*/
|
|
418
|
+
export async function processesForImage(client, imageName) {
|
|
419
|
+
return processesOnImage(await hostPharoProcesses(client), imageName);
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Every Pharo VM the host is running, asked once. A caller with several images
|
|
423
|
+
* to answer for asks this and matches locally, rather than asking the host per
|
|
424
|
+
* image.
|
|
425
|
+
*/
|
|
426
|
+
export async function hostPharoProcesses(client) {
|
|
688
427
|
const result = await client.callTool("pharo_launcher_process_list", {});
|
|
689
428
|
assertLauncherOk(result, "pharo_launcher_process_list");
|
|
690
|
-
|
|
691
|
-
|
|
429
|
+
return launcherResultData(result) ?? [];
|
|
430
|
+
}
|
|
431
|
+
/** Which of those VMs are on this image. One rule, used wherever it is asked. */
|
|
432
|
+
export function processesOnImage(processes, imageName) {
|
|
433
|
+
return processes.filter((process) => processDirectlyMatchesImage(process, imageName));
|
|
434
|
+
}
|
|
435
|
+
async function processForImage(client, imageName) {
|
|
436
|
+
return (await processesForImage(client, imageName))[0];
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Two VMs on one image file overwrite each other's saves, so a launch that
|
|
440
|
+
* would make the second is refused rather than reported: reporting it would
|
|
441
|
+
* mean an image has N runtimes, and every tool would need a pid to say which.
|
|
442
|
+
*/
|
|
443
|
+
export class ImageAlreadyRunningError extends Error {
|
|
444
|
+
imageName;
|
|
445
|
+
processes;
|
|
446
|
+
constructor(imageName, processes) {
|
|
447
|
+
const pids = processes.map((process) => process.pid).join(", ");
|
|
448
|
+
super(`Image ${imageName} is already running as pid ${pids}. ` +
|
|
449
|
+
`Saving from two VMs on one image file overwrites the file, so PLexus ` +
|
|
450
|
+
`will not start a second. Stop it with pharo_launcher_image_stop if ` +
|
|
451
|
+
`PLexus started it, or end pid ${pids} yourself if something else did.`);
|
|
452
|
+
this.imageName = imageName;
|
|
453
|
+
this.processes = processes;
|
|
454
|
+
this.name = "ImageAlreadyRunningError";
|
|
455
|
+
}
|
|
692
456
|
}
|
|
693
457
|
function processTimeoutError(imageName) {
|
|
694
458
|
return new Error(`Timed out waiting for PharoLauncher process for image ${imageName}`);
|
|
@@ -725,9 +489,6 @@ function pharoMcpLoadFailureReadiness(options) {
|
|
|
725
489
|
return { kind: "loadFailed", message: loadFailure };
|
|
726
490
|
}
|
|
727
491
|
async function endpointHandoffReadiness(options) {
|
|
728
|
-
if (!options.preferEndpointHandoff) {
|
|
729
|
-
return undefined;
|
|
730
|
-
}
|
|
731
492
|
const handoff = readImageMcpEndpointHandoff(options.endpointHandoffPath);
|
|
732
493
|
if (handoff.status === "invalid") {
|
|
733
494
|
throw new Error(`Invalid Pharo MCP endpoint handoff at ${handoff.path}: ${handoff.error}`);
|
|
@@ -738,15 +499,6 @@ async function endpointHandoffReadiness(options) {
|
|
|
738
499
|
}
|
|
739
500
|
return undefined;
|
|
740
501
|
}
|
|
741
|
-
async function assignedPortReadiness(options) {
|
|
742
|
-
if (options.imageState.assignedPort === undefined) {
|
|
743
|
-
return undefined;
|
|
744
|
-
}
|
|
745
|
-
if (!(await options.healthClient.check(options.imageState.assignedPort))) {
|
|
746
|
-
return undefined;
|
|
747
|
-
}
|
|
748
|
-
return { kind: "assignedPort", port: options.imageState.assignedPort };
|
|
749
|
-
}
|
|
750
502
|
async function processExitReadiness(options) {
|
|
751
503
|
if (!options.processClient || !options.imageName) {
|
|
752
504
|
return undefined;
|
|
@@ -773,16 +525,18 @@ async function pollPharoMcpReadiness(options) {
|
|
|
773
525
|
if (handoff) {
|
|
774
526
|
return handoff;
|
|
775
527
|
}
|
|
776
|
-
const assignedPort = await assignedPortReadiness(options);
|
|
777
|
-
if (assignedPort) {
|
|
778
|
-
return assignedPort;
|
|
779
|
-
}
|
|
780
528
|
return processExitReadiness(options);
|
|
781
529
|
});
|
|
782
530
|
}
|
|
783
531
|
async function launchImageAndPollProcess(launchClient, processClient, imageName, displayMode, startupScriptPath, timeoutMs, intervalMs, sleep) {
|
|
532
|
+
// Ask the host, not the record: a VM started from PharoLauncher or by another
|
|
533
|
+
// agent counts just as much as one of ours.
|
|
534
|
+
const running = await processesForImage(processClient, imageName);
|
|
535
|
+
if (running.length > 0) {
|
|
536
|
+
throw new ImageAlreadyRunningError(imageName, running);
|
|
537
|
+
}
|
|
784
538
|
const launchOutcome = launchClient
|
|
785
|
-
.callTool("
|
|
539
|
+
.callTool("pharo_launcher_image_start", {
|
|
786
540
|
imageName,
|
|
787
541
|
detached: true,
|
|
788
542
|
displayMode,
|
|
@@ -797,7 +551,7 @@ async function launchImageAndPollProcess(launchClient, processClient, imageName,
|
|
|
797
551
|
throw immediateLaunch.error;
|
|
798
552
|
}
|
|
799
553
|
if (immediateLaunch?.kind === "launch") {
|
|
800
|
-
assertLauncherOk(immediateLaunch.result, "
|
|
554
|
+
assertLauncherOk(immediateLaunch.result, "pharo_launcher_image_start");
|
|
801
555
|
return {
|
|
802
556
|
process: await observeLaunchedProcess({
|
|
803
557
|
processClient,
|
|
@@ -820,7 +574,7 @@ async function launchImageAndPollProcess(launchClient, processClient, imageName,
|
|
|
820
574
|
throw first.error;
|
|
821
575
|
}
|
|
822
576
|
if (first.kind === "launch") {
|
|
823
|
-
assertLauncherOk(first.result, "
|
|
577
|
+
assertLauncherOk(first.result, "pharo_launcher_image_start");
|
|
824
578
|
launchedProcess = launcherProcessFromResult(first.result, imageName);
|
|
825
579
|
const outcome = await processOutcome;
|
|
826
580
|
if (outcome?.kind === "process") {
|
|
@@ -850,18 +604,24 @@ function imageStartupExitedBeforeProcessObservedError(options) {
|
|
|
850
604
|
return new ImageStartupExitedBeforeHealthError(`Image ${options.imageName} process ${options.process.pid} exited before PLexus observed the launcher process${logHint}`, options.launcherResult, options.process);
|
|
851
605
|
}
|
|
852
606
|
function imageStartupExitedBeforeHealthError(options) {
|
|
853
|
-
const endpointHint = options.preferEndpointHandoff
|
|
854
|
-
? ` or endpoint handoff at ${options.endpointHandoffPath}`
|
|
855
|
-
: "";
|
|
856
|
-
const portHint = options.assignedPort === undefined
|
|
857
|
-
? ""
|
|
858
|
-
: ` on port ${options.assignedPort}`;
|
|
859
607
|
const logPaths = collectLauncherLogPaths(options.launcherResult);
|
|
860
608
|
const logHint = logPaths.length > 0 ? `. Launcher logs: ${logPaths.join(", ")}` : "";
|
|
861
|
-
return new ImageStartupExitedBeforeHealthError(`Image ${options.imageName} process ${options.process.pid} exited before Pharo MCP became healthy${
|
|
609
|
+
return new ImageStartupExitedBeforeHealthError(`Image ${options.imageName} process ${options.process.pid} exited before Pharo MCP became healthy or wrote its endpoint to ${options.endpointHandoffPath}${logHint}`, options.launcherResult, options.process);
|
|
862
610
|
}
|
|
863
|
-
|
|
864
|
-
|
|
611
|
+
/**
|
|
612
|
+
* The images this call was asked to open. Opening is an action, so it takes
|
|
613
|
+
* its subjects from the request; a declaration no longer decides it.
|
|
614
|
+
*/
|
|
615
|
+
function imagesToOpenFor(state, imageIds) {
|
|
616
|
+
if (!imageIds) {
|
|
617
|
+
return [];
|
|
618
|
+
}
|
|
619
|
+
const selected = new Set(imageIds);
|
|
620
|
+
const images = state.images.filter((image) => selected.has(image.id));
|
|
621
|
+
for (const image of images) {
|
|
622
|
+
image.status = "starting";
|
|
623
|
+
}
|
|
624
|
+
return images;
|
|
865
625
|
}
|
|
866
626
|
function imageRequiresPharoMcpHealth(imageConfig, image) {
|
|
867
627
|
return (projectMcpStartupMode(imageConfig.mcp) === "required" &&
|
|
@@ -871,18 +631,6 @@ function imageCanRouteToPharoMcp(imageConfig, image) {
|
|
|
871
631
|
return (projectMcpStartupMode(imageConfig.mcp) !== "disabled" &&
|
|
872
632
|
image.pharoMcpContract?.status !== "unsupported");
|
|
873
633
|
}
|
|
874
|
-
async function releaseOptionalPharoMcpRoute(options) {
|
|
875
|
-
if (options.claimsRoot && options.imageState.assignedPort !== undefined) {
|
|
876
|
-
await releaseImagePortClaimIfOwned({
|
|
877
|
-
state: options.state,
|
|
878
|
-
image: options.imageState,
|
|
879
|
-
claimsRoot: options.claimsRoot,
|
|
880
|
-
checks: options.checks,
|
|
881
|
-
});
|
|
882
|
-
}
|
|
883
|
-
delete options.imageState.assignedPort;
|
|
884
|
-
delete options.imageState.mcpServers;
|
|
885
|
-
}
|
|
886
634
|
function applyScopedImageSelection(state, previousState, imageIds) {
|
|
887
635
|
if (!imageIds) {
|
|
888
636
|
return;
|
|
@@ -908,10 +656,20 @@ function applyScopedImageSelection(state, previousState, imageIds) {
|
|
|
908
656
|
function previousImageState(previousState, imageId) {
|
|
909
657
|
return previousState?.images.find((image) => image.id === imageId);
|
|
910
658
|
}
|
|
659
|
+
// Whether the launcher already holds this image is the launcher's answer, not
|
|
660
|
+
// the record's: a state file left behind by an earlier config names an image id
|
|
661
|
+
// that no longer corresponds to any launcher image, and keying on the id alone
|
|
662
|
+
// then skips materialization for an image nothing ever created.
|
|
663
|
+
function launcherImageMaterialized(options) {
|
|
664
|
+
if (options.imagesDirectory === undefined) {
|
|
665
|
+
return Boolean(previousImageState(options.previousState, options.imageState.id));
|
|
666
|
+
}
|
|
667
|
+
return fs.existsSync(joinPathLike(options.imagesDirectory, options.imageState.imageName));
|
|
668
|
+
}
|
|
911
669
|
function shouldMaterializeImageFromHomeCache(options) {
|
|
912
670
|
return Boolean(options.approval &&
|
|
913
671
|
projectImageCanUseHomeImageCache(options.imageConfig) &&
|
|
914
|
-
!
|
|
672
|
+
!launcherImageMaterialized(options));
|
|
915
673
|
}
|
|
916
674
|
function resolveProjectOpenWorkspace(projectRoot, workspaceId) {
|
|
917
675
|
return workspaceId ? sanitizeRuntimeId(workspaceId) : defaultWorkspaceId(projectRoot);
|
|
@@ -930,6 +688,7 @@ function applyProjectImageDisplayMode(imageConfig, imageState, displayMode, requ
|
|
|
930
688
|
}
|
|
931
689
|
async function materializeProjectImageForOpen(context, imageConfig, imageState) {
|
|
932
690
|
const homeMaterialization = shouldMaterializeImageFromHomeCache({
|
|
691
|
+
imagesDirectory: context.launcherProfileEnvironment?.PHARO_LAUNCHER_MCP_IMAGES_DIR,
|
|
933
692
|
previousState: context.previousState,
|
|
934
693
|
imageConfig,
|
|
935
694
|
imageState,
|
|
@@ -944,7 +703,6 @@ async function materializeProjectImageForOpen(context, imageConfig, imageState)
|
|
|
944
703
|
imageConfig,
|
|
945
704
|
imageState,
|
|
946
705
|
workspaceId: context.workspaceId,
|
|
947
|
-
targetId: context.state.targetId,
|
|
948
706
|
stateRoot: context.resolvedStateRoot,
|
|
949
707
|
approval: context.options.homeImageCacheApproval,
|
|
950
708
|
now: context.now,
|
|
@@ -960,13 +718,6 @@ async function materializeProjectImageForOpen(context, imageConfig, imageState)
|
|
|
960
718
|
approval: context.options.preparedImageCacheApproval,
|
|
961
719
|
});
|
|
962
720
|
}
|
|
963
|
-
await hydrateRepositoryWorkspaceImagePaths(context.client, imageState, context.launcherProfileEnvironment?.PHARO_LAUNCHER_MCP_IMAGES_DIR);
|
|
964
|
-
materializeProjectImageRepositoryWorkspaces({
|
|
965
|
-
projectRoot: context.projectRoot,
|
|
966
|
-
imageConfig,
|
|
967
|
-
imageState,
|
|
968
|
-
sourcePath: context.loadSourcePath,
|
|
969
|
-
});
|
|
970
721
|
}
|
|
971
722
|
async function setupProjectImageForOpen(context, imageConfig, imageState, displayMode) {
|
|
972
723
|
await materializeProjectImageForOpen(context, imageConfig, imageState);
|
|
@@ -990,11 +741,9 @@ async function setupProjectImageForOpen(context, imageConfig, imageState, displa
|
|
|
990
741
|
});
|
|
991
742
|
clearPharoMcpLoadStatus(imageState, startupScript.pharoMcpLoadStatusPath);
|
|
992
743
|
clearDependencyRepositoryDetachStatus(imageState, startupScript.dependencyRepositoryDetachStatusPath);
|
|
993
|
-
clearRepositoryWorkspaceLoadStatuses(startupScript.repositoryWorkspaceLoadStatusPaths);
|
|
994
|
-
prepareRepositoryWorkspaceLoadStatuses(imageState, startupScript.repositoryWorkspaceLoadStatusPaths);
|
|
995
744
|
const launchClient = context.options.pharoLauncherMcpClient
|
|
996
745
|
? context.client
|
|
997
|
-
:
|
|
746
|
+
: openPharoLauncherClient({
|
|
998
747
|
profileEnvironment: context.launcherProfileEnvironment,
|
|
999
748
|
});
|
|
1000
749
|
return {
|
|
@@ -1007,97 +756,39 @@ async function setupProjectImageForOpen(context, imageConfig, imageState, displa
|
|
|
1007
756
|
ownsLaunchClient: !context.options.pharoLauncherMcpClient,
|
|
1008
757
|
};
|
|
1009
758
|
}
|
|
1010
|
-
function
|
|
1011
|
-
context.preparedPortClaims = context.preparedPortClaims.filter((candidate) => candidate.imageId !== imageId);
|
|
1012
|
-
}
|
|
1013
|
-
async function recordLaunchedImagePortClaim(context, imageState, pid) {
|
|
1014
|
-
if (!context.claimsRoot) {
|
|
1015
|
-
return;
|
|
1016
|
-
}
|
|
1017
|
-
const preparedClaim = context.preparedPortClaims.find((candidate) => candidate.imageId === imageState.id);
|
|
1018
|
-
if (preparedClaim) {
|
|
1019
|
-
await recordImagePortClaimProcess({
|
|
1020
|
-
claimsRoot: context.claimsRoot,
|
|
1021
|
-
preparedClaim,
|
|
1022
|
-
pid,
|
|
1023
|
-
now: context.now,
|
|
1024
|
-
});
|
|
1025
|
-
}
|
|
1026
|
-
}
|
|
1027
|
-
async function releaseOptionalRouteForImage(context, imageState) {
|
|
1028
|
-
await releaseOptionalPharoMcpRoute({
|
|
1029
|
-
state: context.state,
|
|
1030
|
-
imageState,
|
|
1031
|
-
claimsRoot: context.claimsRoot,
|
|
1032
|
-
checks: context.portClaimChecks,
|
|
1033
|
-
});
|
|
1034
|
-
removePreparedPortClaimsForImage(context, imageState.id);
|
|
1035
|
-
}
|
|
1036
|
-
async function handleMissingPharoMcpReadiness(options) {
|
|
1037
|
-
if (!options.requiresHealth) {
|
|
1038
|
-
await releaseOptionalRouteForImage(options.context, options.imageState);
|
|
1039
|
-
return;
|
|
1040
|
-
}
|
|
1041
|
-
const endpointHint = options.preferEndpointHandoff
|
|
1042
|
-
? ` or endpoint handoff at ${options.endpointHandoffPath}`
|
|
1043
|
-
: "";
|
|
1044
|
-
const portHint = options.imageState.assignedPort === undefined
|
|
1045
|
-
? ""
|
|
1046
|
-
: ` on port ${options.imageState.assignedPort}`;
|
|
1047
|
-
throw new Error(`Timed out waiting for Pharo MCP health${portHint}${endpointHint}`);
|
|
1048
|
-
}
|
|
1049
|
-
async function handleEndpointReadiness(options) {
|
|
1050
|
-
options.imageState.mcpServers = [
|
|
1051
|
-
{ id: options.imageState.id, endpoint: options.endpoint },
|
|
1052
|
-
];
|
|
1053
|
-
if (options.context.claimsRoot &&
|
|
1054
|
-
options.imageState.assignedPort !== undefined) {
|
|
1055
|
-
await releaseImagePortClaimIfOwned({
|
|
1056
|
-
state: options.context.state,
|
|
1057
|
-
image: options.imageState,
|
|
1058
|
-
claimsRoot: options.context.claimsRoot,
|
|
1059
|
-
checks: options.context.portClaimChecks,
|
|
1060
|
-
});
|
|
1061
|
-
removePreparedPortClaimsForImage(options.context, options.imageState.id);
|
|
1062
|
-
}
|
|
1063
|
-
delete options.imageState.assignedPort;
|
|
1064
|
-
}
|
|
1065
|
-
async function handlePharoMcpReadinessResult(options) {
|
|
759
|
+
function handlePharoMcpReadinessResult(options) {
|
|
1066
760
|
if (!options.readiness) {
|
|
1067
|
-
|
|
761
|
+
if (options.requiresHealth) {
|
|
762
|
+
throw new Error(`Timed out waiting for Pharo MCP to write its endpoint to ${options.endpointHandoffPath}`);
|
|
763
|
+
}
|
|
764
|
+
delete options.imageState.mcpServers;
|
|
1068
765
|
return;
|
|
1069
766
|
}
|
|
1070
767
|
if (options.readiness.kind === "processExited") {
|
|
1071
768
|
throw imageStartupExitedBeforeHealthError({
|
|
1072
769
|
imageName: options.imageState.imageName,
|
|
1073
|
-
assignedPort: options.imageState.assignedPort,
|
|
1074
770
|
endpointHandoffPath: options.endpointHandoffPath,
|
|
1075
|
-
preferEndpointHandoff: options.preferEndpointHandoff,
|
|
1076
771
|
launcherResult: options.launchRuntime.launcherResult,
|
|
1077
772
|
process: options.launchRuntime.process,
|
|
1078
773
|
});
|
|
1079
774
|
}
|
|
1080
775
|
if (options.readiness.kind === "loadFailed") {
|
|
1081
|
-
|
|
776
|
+
delete options.imageState.mcpServers;
|
|
1082
777
|
}
|
|
1083
778
|
if (options.readiness.kind === "endpoint") {
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
endpoint: options.readiness.endpoint,
|
|
1088
|
-
});
|
|
779
|
+
options.imageState.mcpServers = [
|
|
780
|
+
{ id: options.imageState.id, endpoint: options.readiness.endpoint },
|
|
781
|
+
];
|
|
1089
782
|
}
|
|
1090
783
|
}
|
|
1091
784
|
async function routeProjectImageMcp(options) {
|
|
1092
785
|
if (!imageCanRouteToPharoMcp(options.imageConfig, options.imageState)) {
|
|
1093
786
|
return;
|
|
1094
787
|
}
|
|
1095
|
-
const preferEndpointHandoff = options.imageConfig.mcp.port === undefined;
|
|
1096
788
|
const requiresHealth = imageRequiresPharoMcpHealth(options.imageConfig, options.imageState);
|
|
1097
789
|
const readiness = await pollPharoMcpReadiness({
|
|
1098
790
|
imageState: options.imageState,
|
|
1099
791
|
endpointHandoffPath: options.setup.endpointHandoffPath,
|
|
1100
|
-
preferEndpointHandoff,
|
|
1101
792
|
healthClient: options.context.healthClient,
|
|
1102
793
|
processClient: options.context.client,
|
|
1103
794
|
imageName: options.imageState.imageName,
|
|
@@ -1108,12 +799,10 @@ async function routeProjectImageMcp(options) {
|
|
|
1108
799
|
intervalMs: options.context.poll.intervalMs,
|
|
1109
800
|
sleep: options.context.sleep,
|
|
1110
801
|
});
|
|
1111
|
-
|
|
1112
|
-
context: options.context,
|
|
802
|
+
handlePharoMcpReadinessResult({
|
|
1113
803
|
imageState: options.imageState,
|
|
1114
804
|
readiness,
|
|
1115
805
|
endpointHandoffPath: options.setup.endpointHandoffPath,
|
|
1116
|
-
preferEndpointHandoff,
|
|
1117
806
|
requiresHealth,
|
|
1118
807
|
launchRuntime: options.launchRuntime,
|
|
1119
808
|
});
|
|
@@ -1124,32 +813,17 @@ function assertProjectImageLoadStatuses(options) {
|
|
|
1124
813
|
imageRequiresPharoMcpHealth(options.imageConfig, options.imageState)) {
|
|
1125
814
|
throw new Error(pharoMcpLoadFailure);
|
|
1126
815
|
}
|
|
1127
|
-
const loadFailure = refreshRepositoryWorkspaceLoadStatuses(options.imageState);
|
|
1128
|
-
if (loadFailure) {
|
|
1129
|
-
throw new Error(loadFailure);
|
|
1130
|
-
}
|
|
1131
816
|
const detachFailure = refreshDependencyRepositoryDetachStatus(options.imageState, options.dependencyRepositoryDetachStatusPath);
|
|
1132
817
|
if (detachFailure) {
|
|
1133
818
|
throw new Error(detachFailure);
|
|
1134
819
|
}
|
|
1135
820
|
}
|
|
1136
|
-
async function ensureProjectImageRepositoryWorkspaces(options) {
|
|
1137
|
-
for (const workspace of projectImageRepositoryWorkspaces(options.imageState)) {
|
|
1138
|
-
await ensureRepositoryWorkspaceRegistered({
|
|
1139
|
-
imageConfig: options.imageConfig,
|
|
1140
|
-
imageState: options.imageState,
|
|
1141
|
-
workspace,
|
|
1142
|
-
imageMcpClient: options.imageMcpClient,
|
|
1143
|
-
});
|
|
1144
|
-
}
|
|
1145
|
-
}
|
|
1146
821
|
async function launchProjectImage(options) {
|
|
1147
822
|
const { context, imageConfig, imageState, setup } = options;
|
|
1148
823
|
try {
|
|
1149
824
|
const launchRuntime = await launchImageAndPollProcess(setup.launchClient, context.client, imageState.imageName, setup.displayMode, setup.startupScript.filePath, context.poll.processTimeoutMs, context.poll.intervalMs, context.sleep);
|
|
1150
825
|
const process = launchRuntime.process;
|
|
1151
826
|
imageState.pid = process.pid;
|
|
1152
|
-
await recordLaunchedImagePortClaim(context, imageState, process.pid);
|
|
1153
827
|
await routeProjectImageMcp({
|
|
1154
828
|
context,
|
|
1155
829
|
imageConfig,
|
|
@@ -1163,11 +837,6 @@ async function launchProjectImage(options) {
|
|
|
1163
837
|
pharoMcpLoadStatusPath: setup.pharoMcpLoadStatusPath,
|
|
1164
838
|
dependencyRepositoryDetachStatusPath: setup.dependencyRepositoryDetachStatusPath,
|
|
1165
839
|
});
|
|
1166
|
-
await ensureProjectImageRepositoryWorkspaces({
|
|
1167
|
-
imageConfig,
|
|
1168
|
-
imageState,
|
|
1169
|
-
imageMcpClient: context.imageMcpClient,
|
|
1170
|
-
});
|
|
1171
840
|
}
|
|
1172
841
|
finally {
|
|
1173
842
|
if (setup.ownsLaunchClient) {
|
|
@@ -1175,33 +844,19 @@ async function launchProjectImage(options) {
|
|
|
1175
844
|
}
|
|
1176
845
|
}
|
|
1177
846
|
}
|
|
1178
|
-
async function releaseCreatedPreparedPortClaim(context, imageState) {
|
|
1179
|
-
if (!context.claimsRoot) {
|
|
1180
|
-
return;
|
|
1181
|
-
}
|
|
1182
|
-
const claim = context.preparedPortClaims.find((candidate) => candidate.imageId === imageState.id);
|
|
1183
|
-
if (claim?.created) {
|
|
1184
|
-
await releasePreparedImagePortClaims(context.claimsRoot, [claim]);
|
|
1185
|
-
context.preparedPortClaims = context.preparedPortClaims.filter((candidate) => candidate !== claim);
|
|
1186
|
-
}
|
|
1187
|
-
}
|
|
1188
847
|
async function recordProjectImageOpenFailure(options) {
|
|
1189
848
|
options.imageState.status = "failed";
|
|
1190
|
-
await releaseCreatedPreparedPortClaim(options.context, options.imageState);
|
|
1191
849
|
const pharoMcpLoadFailure = refreshPharoMcpLoadStatus(options.imageState, options.setup?.pharoMcpLoadStatusPath);
|
|
1192
|
-
const loadFailure = refreshRepositoryWorkspaceLoadStatuses(options.imageState);
|
|
1193
850
|
const detachFailure = refreshDependencyRepositoryDetachStatus(options.imageState, options.setup?.dependencyRepositoryDetachStatusPath);
|
|
1194
851
|
options.context.failures.push({
|
|
1195
852
|
imageId: options.imageState.id,
|
|
1196
853
|
imageName: options.imageState.imageName,
|
|
1197
|
-
message: detachFailure ??
|
|
1198
|
-
loadFailure ??
|
|
1199
|
-
pharoMcpLoadFailure ??
|
|
854
|
+
message: detachFailure ?? pharoMcpLoadFailure ??
|
|
1200
855
|
errorMessage(options.error),
|
|
1201
|
-
...(detachFailure ||
|
|
856
|
+
...(detachFailure || pharoMcpLoadFailure
|
|
1202
857
|
? {}
|
|
1203
858
|
: launcherFailureDetails(options.error)),
|
|
1204
|
-
...(detachFailure ||
|
|
859
|
+
...(detachFailure || pharoMcpLoadFailure
|
|
1205
860
|
? {}
|
|
1206
861
|
: startupFailureDetails(options.error)),
|
|
1207
862
|
});
|
|
@@ -1228,6 +883,19 @@ async function openActiveProjectImages(context, imagesToOpen) {
|
|
|
1228
883
|
await openProjectImage(context, imageState);
|
|
1229
884
|
}
|
|
1230
885
|
}
|
|
886
|
+
/**
|
|
887
|
+
* Start one image the project declares. This is the operation: PLexus acts on
|
|
888
|
+
* an image, named by the caller, and reports what happened to that image.
|
|
889
|
+
*/
|
|
890
|
+
export async function startProjectImage(options) {
|
|
891
|
+
const { imageId, ...rest } = options;
|
|
892
|
+
return await openProject({ ...rest, imageIds: [imageId] });
|
|
893
|
+
}
|
|
894
|
+
/**
|
|
895
|
+
* @deprecated Use `startProjectImage`. The plural form only survives because
|
|
896
|
+
* `pharo-agent-plugin` still imports it, always with a single id; it goes when
|
|
897
|
+
* the plugin moves.
|
|
898
|
+
*/
|
|
1231
899
|
export async function openProject(options) {
|
|
1232
900
|
const projectRoot = path.resolve(options.projectRoot);
|
|
1233
901
|
const config = loadProjectConfig(projectRoot);
|
|
@@ -1247,27 +915,14 @@ export async function openProject(options) {
|
|
|
1247
915
|
});
|
|
1248
916
|
const loadSourcePath = sourcePath ?? projectRoot;
|
|
1249
917
|
const now = options.now ?? (() => new Date());
|
|
1250
|
-
const runtime = resolveProjectRuntimePolicy(config);
|
|
1251
|
-
const portRange = options.portRange ?? runtime.imagePorts.range;
|
|
1252
|
-
const claimsRoot = imagePortClaimsRootForConfig(projectRoot, config);
|
|
1253
|
-
const projectReservedOwners = collectReservedProjectPortOwners({
|
|
1254
|
-
projectRoot,
|
|
1255
|
-
projectId: projectConfigId(config),
|
|
1256
|
-
stateRoot: resolvedStateRoot,
|
|
1257
|
-
excludeWorkspaceId: workspaceId,
|
|
1258
|
-
});
|
|
1259
918
|
const state = createProjectState(config, {
|
|
1260
919
|
updatedAt: now().toISOString(),
|
|
1261
920
|
previousState,
|
|
1262
921
|
workspaceId,
|
|
1263
|
-
targetId: options.targetId,
|
|
1264
922
|
sourcePath,
|
|
1265
|
-
reservedPorts: claimsRoot
|
|
1266
|
-
? projectReservedOwners.map((owner) => owner.port)
|
|
1267
|
-
: undefined,
|
|
1268
923
|
});
|
|
1269
924
|
applyScopedImageSelection(state, previousState, options.imageIds);
|
|
1270
|
-
const imagesToOpen =
|
|
925
|
+
const imagesToOpen = imagesToOpenFor(state, options.imageIds);
|
|
1271
926
|
const failures = [];
|
|
1272
927
|
if (imagesToOpen.length === 0) {
|
|
1273
928
|
state.runtimeStatus = runtimeStatusForImages(state.images);
|
|
@@ -1281,32 +936,16 @@ export async function openProject(options) {
|
|
|
1281
936
|
failures,
|
|
1282
937
|
};
|
|
1283
938
|
}
|
|
1284
|
-
const portClaimChecks = options.portClaimChecks ?? defaultImagePortClaimChecks();
|
|
1285
939
|
const launcherProfileEnvironment = pharoLauncherMcpProfileEnvironment({
|
|
1286
940
|
projectRoot,
|
|
1287
941
|
config,
|
|
1288
942
|
workspaceId,
|
|
1289
|
-
targetId: state.targetId,
|
|
1290
943
|
stateRoot: resolvedStateRoot,
|
|
1291
944
|
});
|
|
1292
|
-
let preparedPortClaims = [];
|
|
1293
|
-
if (claimsRoot) {
|
|
1294
|
-
preparedPortClaims = await prepareImagePortClaims({
|
|
1295
|
-
config,
|
|
1296
|
-
state,
|
|
1297
|
-
previousState,
|
|
1298
|
-
images: imagesToOpen,
|
|
1299
|
-
projectReservedOwners,
|
|
1300
|
-
claimsRoot,
|
|
1301
|
-
portRange,
|
|
1302
|
-
checks: portClaimChecks,
|
|
1303
|
-
now,
|
|
1304
|
-
});
|
|
1305
|
-
}
|
|
1306
945
|
const client = options.pharoLauncherMcpClient ??
|
|
1307
|
-
(
|
|
946
|
+
openPharoLauncherClient({
|
|
1308
947
|
profileEnvironment: launcherProfileEnvironment,
|
|
1309
|
-
})
|
|
948
|
+
});
|
|
1310
949
|
const ownsClient = !options.pharoLauncherMcpClient;
|
|
1311
950
|
const healthClient = options.healthClient ?? new HttpPharoMcpHealthClient();
|
|
1312
951
|
const imageMcpClient = options.imageMcpClient ?? new HttpProjectOpenImageMcpClient();
|
|
@@ -1327,11 +966,7 @@ export async function openProject(options) {
|
|
|
1327
966
|
resolvedStateRoot,
|
|
1328
967
|
statePath,
|
|
1329
968
|
state,
|
|
1330
|
-
claimsRoot,
|
|
1331
|
-
projectReservedOwners,
|
|
1332
|
-
portClaimChecks,
|
|
1333
969
|
launcherProfileEnvironment,
|
|
1334
|
-
preparedPortClaims,
|
|
1335
970
|
client,
|
|
1336
971
|
ownsClient,
|
|
1337
972
|
healthClient,
|