@evref-bl/plexus 0.15.2 → 0.17.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 +8 -12
- package/dist/answers/index.d.ts +97 -0
- package/dist/answers/index.d.ts.map +1 -0
- package/dist/answers/index.js +352 -0
- package/dist/answers/index.js.map +1 -0
- package/dist/answers/texts.d.ts +83 -0
- package/dist/answers/texts.d.ts.map +1 -0
- package/dist/answers/texts.js +216 -0
- package/dist/answers/texts.js.map +1 -0
- package/dist/cli.js +21 -182
- package/dist/cli.js.map +1 -1
- package/dist/commandLine.d.ts +13 -0
- package/dist/commandLine.d.ts.map +1 -0
- package/dist/commandLine.js +259 -0
- package/dist/commandLine.js.map +1 -0
- package/dist/config/pharoMcpVersion.d.ts +6 -7
- package/dist/config/pharoMcpVersion.d.ts.map +1 -1
- package/dist/config/pharoMcpVersion.js +6 -7
- package/dist/config/pharoMcpVersion.js.map +1 -1
- package/dist/errors.d.ts +11 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +17 -0
- package/dist/errors.js.map +1 -0
- package/dist/forward/endpointHandoffFormat.d.ts +23 -0
- package/dist/forward/endpointHandoffFormat.d.ts.map +1 -0
- package/dist/forward/endpointHandoffFormat.js.map +1 -0
- package/dist/forward/index.d.ts +61 -0
- package/dist/forward/index.d.ts.map +1 -0
- package/dist/forward/index.js +133 -0
- package/dist/forward/index.js.map +1 -0
- package/dist/forward/jsonRpc.d.ts +58 -0
- package/dist/forward/jsonRpc.d.ts.map +1 -0
- package/dist/forward/jsonRpc.js +259 -0
- package/dist/forward/jsonRpc.js.map +1 -0
- package/dist/home.d.ts +15 -0
- package/dist/home.d.ts.map +1 -0
- package/dist/home.js +30 -0
- package/dist/home.js.map +1 -0
- package/dist/images/bases.d.ts +41 -0
- package/dist/images/bases.d.ts.map +1 -0
- package/dist/images/bases.js +194 -0
- package/dist/images/bases.js.map +1 -0
- package/dist/images/claims.d.ts +34 -0
- package/dist/images/claims.d.ts.map +1 -0
- package/dist/images/claims.js +119 -0
- package/dist/images/claims.js.map +1 -0
- package/dist/images/context.d.ts +37 -0
- package/dist/images/context.d.ts.map +1 -0
- package/dist/images/context.js +40 -0
- package/dist/images/context.js.map +1 -0
- package/dist/images/create.d.ts +19 -0
- package/dist/images/create.d.ts.map +1 -0
- package/dist/images/create.js +122 -0
- package/dist/images/create.js.map +1 -0
- package/dist/images/delete.d.ts +10 -0
- package/dist/images/delete.d.ts.map +1 -0
- package/dist/images/delete.js +32 -0
- package/dist/images/delete.js.map +1 -0
- package/dist/images/endpoint.d.ts +29 -0
- package/dist/images/endpoint.d.ts.map +1 -0
- package/dist/images/endpoint.js +86 -0
- package/dist/images/endpoint.js.map +1 -0
- package/dist/images/index.d.ts +32 -0
- package/dist/images/index.d.ts.map +1 -0
- package/dist/images/index.js +56 -0
- package/dist/images/index.js.map +1 -0
- package/dist/images/leftovers.d.ts +9 -0
- package/dist/images/leftovers.d.ts.map +1 -0
- package/dist/images/leftovers.js +38 -0
- package/dist/images/leftovers.js.map +1 -0
- package/dist/images/list.d.ts +12 -0
- package/dist/images/list.d.ts.map +1 -0
- package/dist/images/list.js +74 -0
- package/dist/images/list.js.map +1 -0
- package/dist/images/names.d.ts +15 -0
- package/dist/images/names.d.ts.map +1 -0
- package/dist/images/names.js +53 -0
- package/dist/images/names.js.map +1 -0
- package/dist/images/prepare.d.ts +18 -0
- package/dist/images/prepare.d.ts.map +1 -0
- package/dist/images/prepare.js +58 -0
- package/dist/images/prepare.js.map +1 -0
- package/dist/images/processes.d.ts +21 -0
- package/dist/images/processes.d.ts.map +1 -0
- package/dist/images/processes.js +83 -0
- package/dist/images/processes.js.map +1 -0
- package/dist/images/scripts.d.ts +48 -0
- package/dist/images/scripts.d.ts.map +1 -0
- package/dist/images/scripts.js +149 -0
- package/dist/images/scripts.js.map +1 -0
- package/dist/images/start.d.ts +23 -0
- package/dist/images/start.d.ts.map +1 -0
- package/dist/images/start.js +179 -0
- package/dist/images/start.js.map +1 -0
- package/dist/images/stop.d.ts +17 -0
- package/dist/images/stop.d.ts.map +1 -0
- package/dist/images/stop.js +171 -0
- package/dist/images/stop.js.map +1 -0
- package/dist/images/store.d.ts +62 -0
- package/dist/images/store.d.ts.map +1 -0
- package/dist/images/store.js +181 -0
- package/dist/images/store.js.map +1 -0
- package/dist/images/templates.d.ts +14 -0
- package/dist/images/templates.d.ts.map +1 -0
- package/dist/images/templates.js +85 -0
- package/dist/images/templates.js.map +1 -0
- package/dist/index.d.ts +16 -22
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -22
- package/dist/index.js.map +1 -1
- package/dist/launcher/pharoLauncherMcpClient.d.ts +22 -59
- package/dist/launcher/pharoLauncherMcpClient.d.ts.map +1 -1
- package/dist/launcher/pharoLauncherMcpClient.js +121 -98
- package/dist/launcher/pharoLauncherMcpClient.js.map +1 -1
- package/dist/launcher/pharoLauncherProfile.d.ts +5 -32
- package/dist/launcher/pharoLauncherProfile.d.ts.map +1 -1
- package/dist/launcher/pharoLauncherProfile.js +17 -115
- package/dist/launcher/pharoLauncherProfile.js.map +1 -1
- package/dist/mcp/server.d.ts +27 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +269 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/telemetry/reachability.d.ts +59 -0
- package/dist/telemetry/reachability.d.ts.map +1 -0
- package/dist/telemetry/reachability.js +183 -0
- package/dist/telemetry/reachability.js.map +1 -0
- package/dist/telemetry/sdk.d.ts +54 -0
- package/dist/telemetry/sdk.d.ts.map +1 -0
- package/dist/telemetry/sdk.js +167 -0
- package/dist/telemetry/sdk.js.map +1 -0
- package/dist/telemetry/settings.d.ts +16 -0
- package/dist/telemetry/settings.d.ts.map +1 -0
- package/dist/telemetry/settings.js +67 -0
- package/dist/telemetry/settings.js.map +1 -0
- package/dist/telemetry/trace.d.ts +32 -0
- package/dist/telemetry/trace.d.ts.map +1 -0
- package/dist/telemetry/trace.js +79 -0
- package/dist/telemetry/trace.js.map +1 -0
- package/dist/types.d.ts +82 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +5 -0
- package/dist/version.js.map +1 -0
- package/package.json +15 -15
- package/dist/config/config.d.ts +0 -15
- package/dist/config/config.d.ts.map +0 -1
- package/dist/config/config.js +0 -74
- package/dist/config/config.js.map +0 -1
- package/dist/config/plexusHome.d.ts +0 -17
- package/dist/config/plexusHome.d.ts.map +0 -1
- package/dist/config/plexusHome.js +0 -30
- package/dist/config/plexusHome.js.map +0 -1
- package/dist/config/projectConfig.d.ts +0 -141
- package/dist/config/projectConfig.d.ts.map +0 -1
- package/dist/config/projectConfig.js +0 -722
- package/dist/config/projectConfig.js.map +0 -1
- package/dist/config/projectConfigAuthoring.d.ts +0 -53
- package/dist/config/projectConfigAuthoring.d.ts.map +0 -1
- package/dist/config/projectConfigAuthoring.js +0 -159
- package/dist/config/projectConfigAuthoring.js.map +0 -1
- package/dist/gateway/projectImageMcpEndpoint.d.ts +0 -23
- package/dist/gateway/projectImageMcpEndpoint.d.ts.map +0 -1
- package/dist/gateway/projectImageMcpEndpoint.js +0 -40
- package/dist/gateway/projectImageMcpEndpoint.js.map +0 -1
- package/dist/gateway/server/index.d.ts +0 -8
- package/dist/gateway/server/index.d.ts.map +0 -1
- package/dist/gateway/server/index.js +0 -34
- package/dist/gateway/server/index.js.map +0 -1
- package/dist/gateway/server/mcp/server.d.ts +0 -66
- package/dist/gateway/server/mcp/server.d.ts.map +0 -1
- package/dist/gateway/server/mcp/server.js +0 -458
- package/dist/gateway/server/mcp/server.js.map +0 -1
- package/dist/gateway/server/routing/endpointHandoffFormat.d.ts +0 -26
- package/dist/gateway/server/routing/endpointHandoffFormat.d.ts.map +0 -1
- package/dist/gateway/server/routing/endpointHandoffFormat.js.map +0 -1
- package/dist/gateway/server/routing/gateway.d.ts +0 -167
- package/dist/gateway/server/routing/gateway.d.ts.map +0 -1
- package/dist/gateway/server/routing/gateway.js +0 -863
- package/dist/gateway/server/routing/gateway.js.map +0 -1
- package/dist/gateway/server/routing/imageMcpRouter.d.ts +0 -59
- package/dist/gateway/server/routing/imageMcpRouter.d.ts.map +0 -1
- package/dist/gateway/server/routing/imageMcpRouter.js +0 -253
- package/dist/gateway/server/routing/imageMcpRouter.js.map +0 -1
- package/dist/gateway/server/routing/pharoFacade.d.ts +0 -12
- package/dist/gateway/server/routing/pharoFacade.d.ts.map +0 -1
- package/dist/gateway/server/routing/pharoFacade.js +0 -67
- package/dist/gateway/server/routing/pharoFacade.js.map +0 -1
- package/dist/gateway/server/routing/routeDiscovery.d.ts +0 -26
- package/dist/gateway/server/routing/routeDiscovery.d.ts.map +0 -1
- package/dist/gateway/server/routing/routeDiscovery.js +0 -46
- package/dist/gateway/server/routing/routeDiscovery.js.map +0 -1
- package/dist/gateway/server/routing/routingTable.d.ts +0 -120
- package/dist/gateway/server/routing/routingTable.d.ts.map +0 -1
- package/dist/gateway/server/routing/routingTable.js +0 -215
- package/dist/gateway/server/routing/routingTable.js.map +0 -1
- package/dist/gateway/server/support/processLiveness.d.ts +0 -10
- package/dist/gateway/server/support/processLiveness.d.ts.map +0 -1
- package/dist/gateway/server/support/processLiveness.js +0 -25
- package/dist/gateway/server/support/processLiveness.js.map +0 -1
- package/dist/gateway/server/support/sourceBuildPreflight.d.ts +0 -15
- package/dist/gateway/server/support/sourceBuildPreflight.d.ts.map +0 -1
- package/dist/gateway/server/support/sourceBuildPreflight.js +0 -88
- package/dist/gateway/server/support/sourceBuildPreflight.js.map +0 -1
- package/dist/gateway/server/support/toolResultFormatting.d.ts +0 -8
- package/dist/gateway/server/support/toolResultFormatting.d.ts.map +0 -1
- package/dist/gateway/server/support/toolResultFormatting.js +0 -74
- package/dist/gateway/server/support/toolResultFormatting.js.map +0 -1
- package/dist/images/homeImageCache.d.ts +0 -302
- package/dist/images/homeImageCache.d.ts.map +0 -1
- package/dist/images/homeImageCache.js +0 -1031
- package/dist/images/homeImageCache.js.map +0 -1
- package/dist/images/imageRescue.d.ts +0 -151
- package/dist/images/imageRescue.d.ts.map +0 -1
- package/dist/images/imageRescue.js +0 -748
- package/dist/images/imageRescue.js.map +0 -1
- package/dist/images/imageRuntime.d.ts +0 -60
- package/dist/images/imageRuntime.d.ts.map +0 -1
- package/dist/images/imageRuntime.js +0 -90
- package/dist/images/imageRuntime.js.map +0 -1
- package/dist/images/preparedImageCache.d.ts +0 -86
- package/dist/images/preparedImageCache.d.ts.map +0 -1
- package/dist/images/preparedImageCache.js +0 -229
- package/dist/images/preparedImageCache.js.map +0 -1
- package/dist/images/scopedTemplateCatalog.d.ts +0 -33
- package/dist/images/scopedTemplateCatalog.d.ts.map +0 -1
- package/dist/images/scopedTemplateCatalog.js +0 -363
- package/dist/images/scopedTemplateCatalog.js.map +0 -1
- package/dist/internal.d.ts +0 -20
- package/dist/internal.d.ts.map +0 -1
- package/dist/internal.js +0 -20
- package/dist/internal.js.map +0 -1
- package/dist/launcher/scopedPharoLauncherServer.d.ts +0 -349
- package/dist/launcher/scopedPharoLauncherServer.d.ts.map +0 -1
- package/dist/launcher/scopedPharoLauncherServer.js +0 -1307
- package/dist/launcher/scopedPharoLauncherServer.js.map +0 -1
- package/dist/lifecycle/startProjectImage.d.ts +0 -94
- package/dist/lifecycle/startProjectImage.d.ts.map +0 -1
- package/dist/lifecycle/startProjectImage.js +0 -1054
- package/dist/lifecycle/startProjectImage.js.map +0 -1
- package/dist/lifecycle/stopProjectImage.d.ts +0 -31
- package/dist/lifecycle/stopProjectImage.d.ts.map +0 -1
- package/dist/lifecycle/stopProjectImage.js +0 -201
- package/dist/lifecycle/stopProjectImage.js.map +0 -1
- package/dist/mcp/agentServer.d.ts +0 -15
- package/dist/mcp/agentServer.d.ts.map +0 -1
- package/dist/mcp/agentServer.js +0 -67
- package/dist/mcp/agentServer.js.map +0 -1
- package/dist/mcp/imageOperations.d.ts +0 -54
- package/dist/mcp/imageOperations.d.ts.map +0 -1
- package/dist/mcp/imageOperations.js +0 -223
- package/dist/mcp/imageOperations.js.map +0 -1
- package/dist/mcp/pharoMcpHealth.d.ts +0 -26
- package/dist/mcp/pharoMcpHealth.d.ts.map +0 -1
- package/dist/mcp/pharoMcpHealth.js +0 -97
- package/dist/mcp/pharoMcpHealth.js.map +0 -1
- package/dist/support/pathStyle.d.ts +0 -11
- package/dist/support/pathStyle.d.ts.map +0 -1
- package/dist/support/pathStyle.js +0 -61
- package/dist/support/pathStyle.js.map +0 -1
- package/dist/support/toolResultFormatting.d.ts +0 -8
- package/dist/support/toolResultFormatting.d.ts.map +0 -1
- package/dist/support/toolResultFormatting.js +0 -74
- package/dist/support/toolResultFormatting.js.map +0 -1
- package/dist/workspace/projectStartupScript.d.ts +0 -73
- package/dist/workspace/projectStartupScript.d.ts.map +0 -1
- package/dist/workspace/projectStartupScript.js +0 -607
- package/dist/workspace/projectStartupScript.js.map +0 -1
- package/dist/workspace/projectState.d.ts +0 -216
- package/dist/workspace/projectState.d.ts.map +0 -1
- package/dist/workspace/projectState.js +0 -172
- package/dist/workspace/projectState.js.map +0 -1
- /package/dist/{gateway/server/routing → forward}/endpointHandoffFormat.js +0 -0
|
@@ -1,1054 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import { joinPathLike } from "../support/pathStyle.js";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import { loadProjectConfig, projectImageDisplayMode, projectMcpStartupMode, } from "../config/projectConfig.js";
|
|
5
|
-
import { openPharoLauncherClient, PharoLauncherMcpToolError, } from "../launcher/pharoLauncherMcpClient.js";
|
|
6
|
-
import { copyProjectImageFromPreparedCache, } from "../images/preparedImageCache.js";
|
|
7
|
-
import { materializeProjectImageFromHomeCache, projectImageCanUseHomeImageCache, projectImagePharoMcpLoad, recordHomeImageCacheBase, sameHomeImageCachePharoMcpLoad, } from "../images/homeImageCache.js";
|
|
8
|
-
import { isPidAlive } from "../gateway/server/support/processLiveness.js";
|
|
9
|
-
import { pharoLauncherMcpProfileEnvironment } from "../launcher/pharoLauncherProfile.js";
|
|
10
|
-
import { HttpPharoMcpHealthClient, } from "../mcp/pharoMcpHealth.js";
|
|
11
|
-
import { imageMcpEndpointHandoffPath, readImageMcpEndpointHandoff, removeImageMcpEndpointHandoff, } from "../gateway/projectImageMcpEndpoint.js";
|
|
12
|
-
import { createProjectState, defaultWorkspaceId, loadProjectState, projectStatePath, runtimeStatusForImages, sanitizeRuntimeId, saveProjectState, } from "../workspace/projectState.js";
|
|
13
|
-
import { writeProjectImageStartupScript } from "../workspace/projectStartupScript.js";
|
|
14
|
-
import { vmRenewalHint } from "../launcher/vmRenewal.js";
|
|
15
|
-
export class StartProjectImageError extends Error {
|
|
16
|
-
result;
|
|
17
|
-
constructor(message, result) {
|
|
18
|
-
super(message);
|
|
19
|
-
this.result = result;
|
|
20
|
-
this.name = "StartProjectImageError";
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
function defaultSleep(durationMs) {
|
|
24
|
-
return new Promise((resolve) => setTimeout(resolve, durationMs));
|
|
25
|
-
}
|
|
26
|
-
function errorMessage(error) {
|
|
27
|
-
return error instanceof Error ? error.message : String(error);
|
|
28
|
-
}
|
|
29
|
-
function launcherFailureDetails(error) {
|
|
30
|
-
if (!(error instanceof PharoLauncherMcpToolError)) {
|
|
31
|
-
return {};
|
|
32
|
-
}
|
|
33
|
-
const result = error.result;
|
|
34
|
-
const objectResult = isObject(result) ? result : undefined;
|
|
35
|
-
return {
|
|
36
|
-
launcherToolName: error.toolName,
|
|
37
|
-
launcherResult: result,
|
|
38
|
-
...(typeof objectResult?.diagnostic === "string"
|
|
39
|
-
? { diagnostic: objectResult.diagnostic }
|
|
40
|
-
: {}),
|
|
41
|
-
...(typeof objectResult?.action === "string"
|
|
42
|
-
? { action: objectResult.action }
|
|
43
|
-
: {}),
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
function closeClientQuietly(client) {
|
|
47
|
-
void client.close?.().catch(() => undefined);
|
|
48
|
-
}
|
|
49
|
-
function processDirectlyMatchesImage(process, imageName) {
|
|
50
|
-
return (process.imageName === imageName ||
|
|
51
|
-
path.basename(process.imagePath ?? "", ".image") === imageName ||
|
|
52
|
-
process.commandLine.includes(`${imageName}.image`));
|
|
53
|
-
}
|
|
54
|
-
function launcherResultData(result) {
|
|
55
|
-
return result.ok ? result.data : undefined;
|
|
56
|
-
}
|
|
57
|
-
function assertLauncherOk(result, toolName) {
|
|
58
|
-
if (result && result.ok === false) {
|
|
59
|
-
throw new Error(`${toolName} returned ok: false`);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
class ImageStartupExitedBeforeHealthError extends Error {
|
|
63
|
-
launcherResult;
|
|
64
|
-
process;
|
|
65
|
-
constructor(message, launcherResult, process) {
|
|
66
|
-
super(message);
|
|
67
|
-
this.launcherResult = launcherResult;
|
|
68
|
-
this.process = process;
|
|
69
|
-
this.name = "ImageStartupExitedBeforeHealthError";
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
function isObject(value) {
|
|
73
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
74
|
-
}
|
|
75
|
-
function imageMcpEndpointForImage(image) {
|
|
76
|
-
return image.mcpServers?.find((server) => server.id === image.id)?.endpoint;
|
|
77
|
-
}
|
|
78
|
-
function hostForUrl(host) {
|
|
79
|
-
return host.includes(":") && !host.startsWith("[") ? `[${host}]` : host;
|
|
80
|
-
}
|
|
81
|
-
function imageMcpEndpointUrl(endpoint) {
|
|
82
|
-
return `http://${hostForUrl(endpoint.host)}:${endpoint.port}${endpoint.path}`;
|
|
83
|
-
}
|
|
84
|
-
function jsonRpcErrorText(value) {
|
|
85
|
-
if (isObject(value) && typeof value.message === "string") {
|
|
86
|
-
return value.message;
|
|
87
|
-
}
|
|
88
|
-
try {
|
|
89
|
-
return JSON.stringify(value);
|
|
90
|
-
}
|
|
91
|
-
catch {
|
|
92
|
-
return String(value);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
class HttpStartProjectImageMcpClient {
|
|
96
|
-
fetchFn;
|
|
97
|
-
timeoutMs;
|
|
98
|
-
constructor(fetchFn = fetch, timeoutMs = 60_000) {
|
|
99
|
-
this.fetchFn = fetchFn;
|
|
100
|
-
this.timeoutMs = timeoutMs;
|
|
101
|
-
}
|
|
102
|
-
async callTool(image, toolName, argumentsValue) {
|
|
103
|
-
const endpoint = imageMcpEndpointForImage(image);
|
|
104
|
-
if (!endpoint) {
|
|
105
|
-
throw new Error(`Image ${image.id} has no routable Pharo MCP endpoint`);
|
|
106
|
-
}
|
|
107
|
-
const controller = new AbortController();
|
|
108
|
-
const timeout = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
109
|
-
try {
|
|
110
|
-
const response = await this.fetchFn(imageMcpEndpointUrl(endpoint), {
|
|
111
|
-
method: "POST",
|
|
112
|
-
headers: {
|
|
113
|
-
accept: "application/json, text/event-stream",
|
|
114
|
-
"content-type": "application/json",
|
|
115
|
-
},
|
|
116
|
-
body: JSON.stringify({
|
|
117
|
-
jsonrpc: "2.0",
|
|
118
|
-
id: `plexus-open-${image.id}-${Date.now()}`,
|
|
119
|
-
method: "tools/call",
|
|
120
|
-
params: {
|
|
121
|
-
name: toolName,
|
|
122
|
-
arguments: argumentsValue,
|
|
123
|
-
},
|
|
124
|
-
}),
|
|
125
|
-
signal: controller.signal,
|
|
126
|
-
});
|
|
127
|
-
if (!response.ok) {
|
|
128
|
-
throw new Error(`MCP tools/call failed with HTTP ${response.status}`);
|
|
129
|
-
}
|
|
130
|
-
const payload = (await response.json());
|
|
131
|
-
if (!isObject(payload)) {
|
|
132
|
-
throw new Error("MCP tools/call response was not a JSON object");
|
|
133
|
-
}
|
|
134
|
-
if ("error" in payload) {
|
|
135
|
-
throw new Error(`MCP error ${jsonRpcErrorText(payload.error)}`);
|
|
136
|
-
}
|
|
137
|
-
if (!("result" in payload)) {
|
|
138
|
-
throw new Error("MCP tools/call response did not include a result");
|
|
139
|
-
}
|
|
140
|
-
return payload.result;
|
|
141
|
-
}
|
|
142
|
-
finally {
|
|
143
|
-
clearTimeout(timeout);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
function logPathFromLine(line) {
|
|
148
|
-
const separator = line.indexOf(":");
|
|
149
|
-
if (separator < 0) {
|
|
150
|
-
return undefined;
|
|
151
|
-
}
|
|
152
|
-
const key = line.slice(0, separator).trim().toLowerCase();
|
|
153
|
-
if (key !== "stdout" && key !== "stderr" && key !== "log" && key !== "logpath") {
|
|
154
|
-
return undefined;
|
|
155
|
-
}
|
|
156
|
-
const value = line.slice(separator + 1).trim();
|
|
157
|
-
return value.length > 0 ? value : undefined;
|
|
158
|
-
}
|
|
159
|
-
function logPathsFromText(value) {
|
|
160
|
-
return value
|
|
161
|
-
.split(/\r?\n/)
|
|
162
|
-
.map(logPathFromLine)
|
|
163
|
-
.filter((path) => Boolean(path));
|
|
164
|
-
}
|
|
165
|
-
function profileScopedImagePidFromText(value) {
|
|
166
|
-
const match = value.match(/\bDetached\s+profile-scoped\s+Pharo\s+image\s+pid\s+(\d+)\b/i);
|
|
167
|
-
if (!match) {
|
|
168
|
-
return undefined;
|
|
169
|
-
}
|
|
170
|
-
return Number.parseInt(match[1], 10);
|
|
171
|
-
}
|
|
172
|
-
function launcherPidFromValue(value, fieldName) {
|
|
173
|
-
if (typeof value === "number" && Number.isInteger(value) && value > 0) {
|
|
174
|
-
const normalizedFieldName = fieldName?.toLowerCase() ?? "";
|
|
175
|
-
return normalizedFieldName === "pid" || normalizedFieldName === "processid"
|
|
176
|
-
? value
|
|
177
|
-
: undefined;
|
|
178
|
-
}
|
|
179
|
-
if (typeof value === "string") {
|
|
180
|
-
const normalizedFieldName = fieldName?.toLowerCase() ?? "";
|
|
181
|
-
if (normalizedFieldName === "pid" || normalizedFieldName === "processid") {
|
|
182
|
-
const parsed = Number.parseInt(value, 10);
|
|
183
|
-
return Number.isInteger(parsed) && parsed > 0 ? parsed : undefined;
|
|
184
|
-
}
|
|
185
|
-
return profileScopedImagePidFromText(value);
|
|
186
|
-
}
|
|
187
|
-
if (!isObject(value)) {
|
|
188
|
-
return undefined;
|
|
189
|
-
}
|
|
190
|
-
for (const [key, fieldValue] of Object.entries(value)) {
|
|
191
|
-
const pid = launcherPidFromValue(fieldValue, key);
|
|
192
|
-
if (pid !== undefined) {
|
|
193
|
-
return pid;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
return undefined;
|
|
197
|
-
}
|
|
198
|
-
function launcherProcessFromResult(result, imageName) {
|
|
199
|
-
const pid = launcherPidFromValue(result);
|
|
200
|
-
if (pid === undefined) {
|
|
201
|
-
return undefined;
|
|
202
|
-
}
|
|
203
|
-
return {
|
|
204
|
-
pid,
|
|
205
|
-
imageName,
|
|
206
|
-
commandLine: `pharo_launcher_image_start ${imageName}`,
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
function collectLauncherLogPaths(value, fieldName) {
|
|
210
|
-
if (typeof value === "string") {
|
|
211
|
-
if (value.length === 0) {
|
|
212
|
-
return [];
|
|
213
|
-
}
|
|
214
|
-
const paths = logPathsFromText(value);
|
|
215
|
-
if (paths.length > 0) {
|
|
216
|
-
return paths;
|
|
217
|
-
}
|
|
218
|
-
const normalizedFieldName = fieldName?.toLowerCase() ?? "";
|
|
219
|
-
return normalizedFieldName.includes("log") ||
|
|
220
|
-
normalizedFieldName.includes("stdout") ||
|
|
221
|
-
normalizedFieldName.includes("stderr")
|
|
222
|
-
? [value]
|
|
223
|
-
: [];
|
|
224
|
-
}
|
|
225
|
-
if (!isObject(value)) {
|
|
226
|
-
return [];
|
|
227
|
-
}
|
|
228
|
-
const paths = [];
|
|
229
|
-
for (const [key, fieldValue] of Object.entries(value)) {
|
|
230
|
-
paths.push(...collectLauncherLogPaths(fieldValue, key));
|
|
231
|
-
}
|
|
232
|
-
return [...new Set(paths)];
|
|
233
|
-
}
|
|
234
|
-
function startupFailureDetails(error) {
|
|
235
|
-
if (!(error instanceof ImageStartupExitedBeforeHealthError)) {
|
|
236
|
-
return {};
|
|
237
|
-
}
|
|
238
|
-
return {
|
|
239
|
-
launcherToolName: "pharo_launcher_image_start",
|
|
240
|
-
launcherResult: error.launcherResult,
|
|
241
|
-
process: error.process,
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
function parseStatusProperties(filePath) {
|
|
245
|
-
return Object.fromEntries(fs
|
|
246
|
-
.readFileSync(filePath, "utf8")
|
|
247
|
-
.split(/\r\n|\n|\r/)
|
|
248
|
-
.map((line) => {
|
|
249
|
-
if (!line || line.startsWith("#")) {
|
|
250
|
-
return undefined;
|
|
251
|
-
}
|
|
252
|
-
const separator = line.indexOf("=");
|
|
253
|
-
if (separator <= 0) {
|
|
254
|
-
return undefined;
|
|
255
|
-
}
|
|
256
|
-
return [line.slice(0, separator), line.slice(separator + 1)];
|
|
257
|
-
})
|
|
258
|
-
.filter((entry) => entry !== undefined));
|
|
259
|
-
}
|
|
260
|
-
function clearPharoMcpLoadStatus(imageState, statusPath) {
|
|
261
|
-
if (!statusPath) {
|
|
262
|
-
return;
|
|
263
|
-
}
|
|
264
|
-
fs.rmSync(statusPath, { force: true });
|
|
265
|
-
delete imageState.pharoMcpLoad;
|
|
266
|
-
}
|
|
267
|
-
function clearDependencyRepositoryDetachStatus(imageState, statusPath) {
|
|
268
|
-
if (!statusPath) {
|
|
269
|
-
return;
|
|
270
|
-
}
|
|
271
|
-
fs.rmSync(statusPath, { force: true });
|
|
272
|
-
delete imageState.dependencyRepositoryDetach;
|
|
273
|
-
}
|
|
274
|
-
function pharoMcpLoadStatusDetails(properties, statusPath) {
|
|
275
|
-
return {
|
|
276
|
-
statusPath,
|
|
277
|
-
...(properties.source ? { source: properties.source } : {}),
|
|
278
|
-
...(properties.loadScript ? { loadScript: properties.loadScript } : {}),
|
|
279
|
-
...(properties.loadPolicy ? { loadPolicy: properties.loadPolicy } : {}),
|
|
280
|
-
...(properties.repository ? { repository: properties.repository } : {}),
|
|
281
|
-
...(properties.configuredRepositoryHint
|
|
282
|
-
? { configuredRepositoryHint: properties.configuredRepositoryHint }
|
|
283
|
-
: {}),
|
|
284
|
-
...(properties.baseline ? { baseline: properties.baseline } : {}),
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
// An MCP the image already had is the project's own when the base the image
|
|
288
|
-
// was copied from loaded what the project loads now. Without a recorded base,
|
|
289
|
-
// nothing says what the image holds, and this says nothing either.
|
|
290
|
-
function preparedBaseOf(imageState, loadNow) {
|
|
291
|
-
const loaded = imageState.homeImageCacheBase?.pharoMcpLoad;
|
|
292
|
-
if (!loaded || !loadNow) {
|
|
293
|
-
return undefined;
|
|
294
|
-
}
|
|
295
|
-
return sameHomeImageCachePharoMcpLoad(loaded, loadNow) ? "current" : "outdated";
|
|
296
|
-
}
|
|
297
|
-
function refreshPharoMcpLoadStatus(imageState, statusPath, loadNow) {
|
|
298
|
-
if (!statusPath || !fs.existsSync(statusPath)) {
|
|
299
|
-
return undefined;
|
|
300
|
-
}
|
|
301
|
-
const properties = parseStatusProperties(statusPath);
|
|
302
|
-
const status = properties.status;
|
|
303
|
-
const details = pharoMcpLoadStatusDetails(properties, statusPath);
|
|
304
|
-
if (status === "provided" || status === "loaded") {
|
|
305
|
-
const preparedBase = status === "provided" ? preparedBaseOf(imageState, loadNow) : undefined;
|
|
306
|
-
imageState.pharoMcpLoad = {
|
|
307
|
-
state: status,
|
|
308
|
-
...details,
|
|
309
|
-
...(preparedBase ? { preparedBase } : {}),
|
|
310
|
-
};
|
|
311
|
-
return undefined;
|
|
312
|
-
}
|
|
313
|
-
if (status === "failed") {
|
|
314
|
-
const message = properties.message ?? "Pharo MCP load failed without a reported message.";
|
|
315
|
-
imageState.pharoMcpLoad = {
|
|
316
|
-
state: "failed",
|
|
317
|
-
...details,
|
|
318
|
-
error: message,
|
|
319
|
-
};
|
|
320
|
-
return `Pharo MCP load failed for image ${imageState.id}: ${message}`;
|
|
321
|
-
}
|
|
322
|
-
const message = `Invalid Pharo MCP load status at ${statusPath}: ${status ?? "(missing)"}`;
|
|
323
|
-
imageState.pharoMcpLoad = {
|
|
324
|
-
state: "failed",
|
|
325
|
-
...details,
|
|
326
|
-
error: message,
|
|
327
|
-
};
|
|
328
|
-
return message;
|
|
329
|
-
}
|
|
330
|
-
function dependencyRepositoryDetachRepositories(properties) {
|
|
331
|
-
const byIndex = new Map();
|
|
332
|
-
for (const [key, value] of Object.entries(properties)) {
|
|
333
|
-
const match = /^repository\.(\d+)\.(name|location)$/.exec(key);
|
|
334
|
-
if (!match) {
|
|
335
|
-
continue;
|
|
336
|
-
}
|
|
337
|
-
const index = Number.parseInt(match[1], 10);
|
|
338
|
-
const entry = byIndex.get(index) ?? {};
|
|
339
|
-
entry[match[2]] = value;
|
|
340
|
-
byIndex.set(index, entry);
|
|
341
|
-
}
|
|
342
|
-
return [...byIndex.entries()]
|
|
343
|
-
.sort(([left], [right]) => left - right)
|
|
344
|
-
.map(([, entry]) => entry)
|
|
345
|
-
.filter((entry) => Boolean(entry.location))
|
|
346
|
-
.map((entry) => ({
|
|
347
|
-
location: entry.location,
|
|
348
|
-
...(entry.name ? { name: entry.name } : {}),
|
|
349
|
-
}));
|
|
350
|
-
}
|
|
351
|
-
function dependencyRepositoryDetachCount(properties, repositories) {
|
|
352
|
-
const parsed = Number.parseInt(properties.detachedCount ?? "", 10);
|
|
353
|
-
return Number.isFinite(parsed) && parsed >= 0 ? parsed : repositories.length;
|
|
354
|
-
}
|
|
355
|
-
function refreshDependencyRepositoryDetachStatus(imageState, statusPath) {
|
|
356
|
-
if (!statusPath || !fs.existsSync(statusPath)) {
|
|
357
|
-
return undefined;
|
|
358
|
-
}
|
|
359
|
-
const properties = parseStatusProperties(statusPath);
|
|
360
|
-
const status = properties.status;
|
|
361
|
-
const repositories = dependencyRepositoryDetachRepositories(properties);
|
|
362
|
-
const details = {
|
|
363
|
-
statusPath,
|
|
364
|
-
...(properties.cachePath ? { cachePath: properties.cachePath } : {}),
|
|
365
|
-
detachedCount: dependencyRepositoryDetachCount(properties, repositories),
|
|
366
|
-
repositories,
|
|
367
|
-
...(properties.message ? { message: properties.message } : {}),
|
|
368
|
-
};
|
|
369
|
-
if (status === "detached" || status === "skipped") {
|
|
370
|
-
imageState.dependencyRepositoryDetach = {
|
|
371
|
-
state: status,
|
|
372
|
-
...details,
|
|
373
|
-
};
|
|
374
|
-
return undefined;
|
|
375
|
-
}
|
|
376
|
-
if (status === "failed") {
|
|
377
|
-
const message = properties.message ??
|
|
378
|
-
"Dependency repository detach failed without a reported message.";
|
|
379
|
-
imageState.dependencyRepositoryDetach = {
|
|
380
|
-
state: "failed",
|
|
381
|
-
...details,
|
|
382
|
-
error: message,
|
|
383
|
-
};
|
|
384
|
-
return `Dependency repository detach failed for image ${imageState.id}: ${message}`;
|
|
385
|
-
}
|
|
386
|
-
const message = `Invalid dependency repository detach status at ${statusPath}: ${status ?? "(missing)"}`;
|
|
387
|
-
imageState.dependencyRepositoryDetach = {
|
|
388
|
-
state: "failed",
|
|
389
|
-
...details,
|
|
390
|
-
error: message,
|
|
391
|
-
};
|
|
392
|
-
return message;
|
|
393
|
-
}
|
|
394
|
-
async function pollUntil(timeoutMs, intervalMs, sleep, attempt) {
|
|
395
|
-
const startedAt = Date.now();
|
|
396
|
-
while (Date.now() - startedAt <= timeoutMs) {
|
|
397
|
-
const result = await attempt();
|
|
398
|
-
if (result !== undefined) {
|
|
399
|
-
return result;
|
|
400
|
-
}
|
|
401
|
-
await sleep(intervalMs);
|
|
402
|
-
}
|
|
403
|
-
return undefined;
|
|
404
|
-
}
|
|
405
|
-
async function pollProcessForImage(client, imageName, timeoutMs, intervalMs, sleep) {
|
|
406
|
-
return pollUntil(timeoutMs, intervalMs, sleep, async () => {
|
|
407
|
-
return processForImage(client, imageName);
|
|
408
|
-
});
|
|
409
|
-
}
|
|
410
|
-
async function pollStartupProcessForImage(client, imageName, launchedProcess, timeoutMs, intervalMs, sleep) {
|
|
411
|
-
return pollUntil(timeoutMs, intervalMs, sleep, async () => {
|
|
412
|
-
const process = await processForImage(client, imageName);
|
|
413
|
-
if (process) {
|
|
414
|
-
return { kind: "process", process };
|
|
415
|
-
}
|
|
416
|
-
const knownLaunchedProcess = launchedProcess();
|
|
417
|
-
if (knownLaunchedProcess && !isPidAlive(knownLaunchedProcess.pid)) {
|
|
418
|
-
return { kind: "exited", process: knownLaunchedProcess };
|
|
419
|
-
}
|
|
420
|
-
if (knownLaunchedProcess) {
|
|
421
|
-
return { kind: "process", process: knownLaunchedProcess };
|
|
422
|
-
}
|
|
423
|
-
return undefined;
|
|
424
|
-
});
|
|
425
|
-
}
|
|
426
|
-
/**
|
|
427
|
-
* Every VM the host has on this image, ours or not. PLexus owns at most one of
|
|
428
|
-
* them, so the rest are only ever read — to refuse a launch that would make a
|
|
429
|
-
* second, and to name what is in the way.
|
|
430
|
-
*/
|
|
431
|
-
export async function processesForImage(client, imageName) {
|
|
432
|
-
return processesOnImage(await hostPharoProcesses(client), imageName);
|
|
433
|
-
}
|
|
434
|
-
/**
|
|
435
|
-
* Every Pharo VM the host is running, asked once. A caller with several images
|
|
436
|
-
* to answer for asks this and matches locally, rather than asking the host per
|
|
437
|
-
* image.
|
|
438
|
-
*/
|
|
439
|
-
export async function hostPharoProcesses(client) {
|
|
440
|
-
const result = await client.callTool("pharo_launcher_process_list", {});
|
|
441
|
-
assertLauncherOk(result, "pharo_launcher_process_list");
|
|
442
|
-
return launcherResultData(result) ?? [];
|
|
443
|
-
}
|
|
444
|
-
/** Which of those VMs are on this image. One rule, used wherever it is asked. */
|
|
445
|
-
export function processesOnImage(processes, imageName) {
|
|
446
|
-
return processes.filter((process) => processDirectlyMatchesImage(process, imageName));
|
|
447
|
-
}
|
|
448
|
-
async function processForImage(client, imageName) {
|
|
449
|
-
return (await processesForImage(client, imageName))[0];
|
|
450
|
-
}
|
|
451
|
-
/**
|
|
452
|
-
* Two VMs on one image file overwrite each other's saves, so a launch that
|
|
453
|
-
* would make the second is refused rather than reported: reporting it would
|
|
454
|
-
* mean an image has N runtimes, and every tool would need a pid to say which.
|
|
455
|
-
*/
|
|
456
|
-
export class ImageAlreadyRunningError extends Error {
|
|
457
|
-
imageName;
|
|
458
|
-
processes;
|
|
459
|
-
constructor(imageName, processes) {
|
|
460
|
-
const pids = processes.map((process) => process.pid).join(", ");
|
|
461
|
-
super(`Image ${imageName} is already running as pid ${pids}. ` +
|
|
462
|
-
`Saving from two VMs on one image file overwrites the file, so PLexus ` +
|
|
463
|
-
`will not start a second. Stop it with pharo_launcher_image_stop if ` +
|
|
464
|
-
`PLexus started it, or end pid ${pids} yourself if something else did.`);
|
|
465
|
-
this.imageName = imageName;
|
|
466
|
-
this.processes = processes;
|
|
467
|
-
this.name = "ImageAlreadyRunningError";
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
function processTimeoutError(imageName) {
|
|
471
|
-
return new Error(`Timed out waiting for PharoLauncher process for image ${imageName}`);
|
|
472
|
-
}
|
|
473
|
-
async function observeLaunchedProcess(options) {
|
|
474
|
-
const launchedProcess = launcherProcessFromResult(options.launcherResult, options.imageName);
|
|
475
|
-
const outcome = await pollStartupProcessForImage(options.processClient, options.imageName, () => launchedProcess, options.timeoutMs, options.intervalMs, options.sleep);
|
|
476
|
-
if (outcome?.kind === "process") {
|
|
477
|
-
return outcome.process;
|
|
478
|
-
}
|
|
479
|
-
if (outcome?.kind === "exited") {
|
|
480
|
-
throw imageStartupExitedBeforeProcessObservedError({
|
|
481
|
-
imageName: options.imageName,
|
|
482
|
-
launcherResult: options.launcherResult,
|
|
483
|
-
process: outcome.process,
|
|
484
|
-
});
|
|
485
|
-
}
|
|
486
|
-
throw processTimeoutError(options.imageName);
|
|
487
|
-
}
|
|
488
|
-
async function pollEndpointHealth(healthClient, endpoint) {
|
|
489
|
-
if (healthClient.checkEndpoint) {
|
|
490
|
-
return healthClient.checkEndpoint(endpoint);
|
|
491
|
-
}
|
|
492
|
-
return healthClient.check(endpoint.port);
|
|
493
|
-
}
|
|
494
|
-
function pharoMcpLoadFailureReadiness(options) {
|
|
495
|
-
const loadFailure = refreshPharoMcpLoadStatus(options.imageState, options.pharoMcpLoadStatusPath);
|
|
496
|
-
if (!loadFailure) {
|
|
497
|
-
return undefined;
|
|
498
|
-
}
|
|
499
|
-
if (options.failOnLoadFailure) {
|
|
500
|
-
throw new Error(loadFailure);
|
|
501
|
-
}
|
|
502
|
-
return { kind: "loadFailed", message: loadFailure };
|
|
503
|
-
}
|
|
504
|
-
async function endpointHandoffReadiness(options) {
|
|
505
|
-
const handoff = readImageMcpEndpointHandoff(options.endpointHandoffPath);
|
|
506
|
-
if (handoff.status === "invalid") {
|
|
507
|
-
throw new Error(`Invalid Pharo MCP endpoint handoff at ${handoff.path}: ${handoff.error}`);
|
|
508
|
-
}
|
|
509
|
-
if (handoff.status === "valid" &&
|
|
510
|
-
(await pollEndpointHealth(options.healthClient, handoff.endpoint))) {
|
|
511
|
-
return { kind: "endpoint", endpoint: handoff.endpoint };
|
|
512
|
-
}
|
|
513
|
-
return undefined;
|
|
514
|
-
}
|
|
515
|
-
async function processExitReadiness(options) {
|
|
516
|
-
if (!options.processClient || !options.imageName) {
|
|
517
|
-
return undefined;
|
|
518
|
-
}
|
|
519
|
-
const process = await processForImage(options.processClient, options.imageName);
|
|
520
|
-
if (process) {
|
|
521
|
-
return undefined;
|
|
522
|
-
}
|
|
523
|
-
if (!options.launchedProcess) {
|
|
524
|
-
return { kind: "processExited" };
|
|
525
|
-
}
|
|
526
|
-
if (!isPidAlive(options.launchedProcess.pid)) {
|
|
527
|
-
return { kind: "processExited" };
|
|
528
|
-
}
|
|
529
|
-
return undefined;
|
|
530
|
-
}
|
|
531
|
-
async function pollPharoMcpReadiness(options) {
|
|
532
|
-
return pollUntil(options.timeoutMs, options.intervalMs, options.sleep, async () => {
|
|
533
|
-
const loadFailure = pharoMcpLoadFailureReadiness(options);
|
|
534
|
-
if (loadFailure) {
|
|
535
|
-
return loadFailure;
|
|
536
|
-
}
|
|
537
|
-
const handoff = await endpointHandoffReadiness(options);
|
|
538
|
-
if (handoff) {
|
|
539
|
-
return handoff;
|
|
540
|
-
}
|
|
541
|
-
return processExitReadiness(options);
|
|
542
|
-
});
|
|
543
|
-
}
|
|
544
|
-
async function launchImageAndPollProcess(launchClient, processClient, imageName, displayMode, startupScriptPath, timeoutMs, intervalMs, sleep) {
|
|
545
|
-
// Ask the host, not the record: a VM started from PharoLauncher or by another
|
|
546
|
-
// agent counts just as much as one of ours.
|
|
547
|
-
const running = await processesForImage(processClient, imageName);
|
|
548
|
-
if (running.length > 0) {
|
|
549
|
-
throw new ImageAlreadyRunningError(imageName, running);
|
|
550
|
-
}
|
|
551
|
-
const launchOutcome = launchClient
|
|
552
|
-
.callTool("pharo_launcher_image_start", {
|
|
553
|
-
imageName,
|
|
554
|
-
detached: true,
|
|
555
|
-
displayMode,
|
|
556
|
-
script: startupScriptPath,
|
|
557
|
-
})
|
|
558
|
-
.then((result) => ({ kind: "launch", result }), (error) => ({ kind: "launchError", error }));
|
|
559
|
-
const immediateLaunch = await Promise.race([
|
|
560
|
-
launchOutcome,
|
|
561
|
-
new Promise((resolve) => setTimeout(() => resolve(undefined), 0)),
|
|
562
|
-
]);
|
|
563
|
-
if (immediateLaunch?.kind === "launchError") {
|
|
564
|
-
throw immediateLaunch.error;
|
|
565
|
-
}
|
|
566
|
-
if (immediateLaunch?.kind === "launch") {
|
|
567
|
-
assertLauncherOk(immediateLaunch.result, "pharo_launcher_image_start");
|
|
568
|
-
return {
|
|
569
|
-
process: await observeLaunchedProcess({
|
|
570
|
-
processClient,
|
|
571
|
-
imageName,
|
|
572
|
-
launcherResult: immediateLaunch.result,
|
|
573
|
-
timeoutMs,
|
|
574
|
-
intervalMs,
|
|
575
|
-
sleep,
|
|
576
|
-
}),
|
|
577
|
-
launcherResult: immediateLaunch.result,
|
|
578
|
-
};
|
|
579
|
-
}
|
|
580
|
-
let launchedProcess;
|
|
581
|
-
const processOutcome = pollStartupProcessForImage(processClient, imageName, () => launchedProcess, timeoutMs, intervalMs, sleep);
|
|
582
|
-
const first = await Promise.race([launchOutcome, processOutcome]);
|
|
583
|
-
if (!first) {
|
|
584
|
-
throw processTimeoutError(imageName);
|
|
585
|
-
}
|
|
586
|
-
if (first.kind === "launchError") {
|
|
587
|
-
throw first.error;
|
|
588
|
-
}
|
|
589
|
-
if (first.kind === "launch") {
|
|
590
|
-
assertLauncherOk(first.result, "pharo_launcher_image_start");
|
|
591
|
-
launchedProcess = launcherProcessFromResult(first.result, imageName);
|
|
592
|
-
const outcome = await processOutcome;
|
|
593
|
-
if (outcome?.kind === "process") {
|
|
594
|
-
return { process: outcome.process, launcherResult: first.result };
|
|
595
|
-
}
|
|
596
|
-
if (outcome?.kind === "exited") {
|
|
597
|
-
throw imageStartupExitedBeforeProcessObservedError({
|
|
598
|
-
imageName,
|
|
599
|
-
launcherResult: first.result,
|
|
600
|
-
process: outcome.process,
|
|
601
|
-
});
|
|
602
|
-
}
|
|
603
|
-
throw processTimeoutError(imageName);
|
|
604
|
-
}
|
|
605
|
-
if (first.kind === "process") {
|
|
606
|
-
return { process: first.process, launcherResult: undefined };
|
|
607
|
-
}
|
|
608
|
-
throw imageStartupExitedBeforeProcessObservedError({
|
|
609
|
-
imageName,
|
|
610
|
-
launcherResult: undefined,
|
|
611
|
-
process: first.process,
|
|
612
|
-
});
|
|
613
|
-
}
|
|
614
|
-
function imageStartupExitedBeforeProcessObservedError(options) {
|
|
615
|
-
const logPaths = collectLauncherLogPaths(options.launcherResult);
|
|
616
|
-
const logHint = logPaths.length > 0 ? `. Launcher logs: ${logPaths.join(", ")}` : "";
|
|
617
|
-
return new ImageStartupExitedBeforeHealthError(`Image ${options.imageName} process ${options.process.pid} exited before PLexus observed the launcher process${logHint}`
|
|
618
|
-
+ renewalLine(options.launcherResult, logPaths), options.launcherResult, options.process);
|
|
619
|
-
}
|
|
620
|
-
function imageStartupExitedBeforeHealthError(options) {
|
|
621
|
-
const logPaths = collectLauncherLogPaths(options.launcherResult);
|
|
622
|
-
const logHint = logPaths.length > 0 ? `. Launcher logs: ${logPaths.join(", ")}` : "";
|
|
623
|
-
return new ImageStartupExitedBeforeHealthError(`Image ${options.imageName} process ${options.process.pid} exited before Pharo MCP became healthy or wrote its endpoint to ${options.endpointHandoffPath}${logHint}`
|
|
624
|
-
+ renewalLine(options.launcherResult, logPaths), options.launcherResult, options.process);
|
|
625
|
-
}
|
|
626
|
-
// A detached launch leaves the VM's output in the launcher's logs, and its
|
|
627
|
-
// own report of which VM it ran in its result: a VM that stopped with its
|
|
628
|
-
// fatal-error report says there how to renew it.
|
|
629
|
-
function renewalLine(launcherResult, logPaths) {
|
|
630
|
-
const report = launcherReport(launcherResult);
|
|
631
|
-
if (!report) {
|
|
632
|
-
return "";
|
|
633
|
-
}
|
|
634
|
-
const hint = vmRenewalHint(logPaths.map(logTail).join("\n"), report);
|
|
635
|
-
return hint ? `\n${hint}` : "";
|
|
636
|
-
}
|
|
637
|
-
function launcherReport(result) {
|
|
638
|
-
if (!isObject(result)) {
|
|
639
|
-
return undefined;
|
|
640
|
-
}
|
|
641
|
-
const raw = result.raw;
|
|
642
|
-
if (isObject(raw) && typeof raw.stdout === "string") {
|
|
643
|
-
return raw.stdout;
|
|
644
|
-
}
|
|
645
|
-
const data = result.data;
|
|
646
|
-
return isObject(data) && typeof data.message === "string" ? data.message : undefined;
|
|
647
|
-
}
|
|
648
|
-
// The end of a log, where a VM that stopped wrote why; a log that is gone
|
|
649
|
-
// says nothing.
|
|
650
|
-
function logTail(logPath) {
|
|
651
|
-
const tailLength = 64 * 1024;
|
|
652
|
-
try {
|
|
653
|
-
const size = fs.statSync(logPath).size;
|
|
654
|
-
const descriptor = fs.openSync(logPath, "r");
|
|
655
|
-
try {
|
|
656
|
-
const length = Math.min(size, tailLength);
|
|
657
|
-
const buffer = Buffer.alloc(length);
|
|
658
|
-
fs.readSync(descriptor, buffer, 0, length, size - length);
|
|
659
|
-
return buffer.toString("utf8");
|
|
660
|
-
}
|
|
661
|
-
finally {
|
|
662
|
-
fs.closeSync(descriptor);
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
catch {
|
|
666
|
-
return "";
|
|
667
|
-
}
|
|
668
|
-
}
|
|
669
|
-
/**
|
|
670
|
-
* The image this call was asked to start. Starting is an action, so it takes
|
|
671
|
-
* its subject from the request; a declaration no longer decides it.
|
|
672
|
-
*/
|
|
673
|
-
function imageToStart(state, imageId) {
|
|
674
|
-
const image = state.images.find((candidate) => candidate.id === imageId);
|
|
675
|
-
if (image) {
|
|
676
|
-
image.status = "starting";
|
|
677
|
-
}
|
|
678
|
-
return image;
|
|
679
|
-
}
|
|
680
|
-
function imageRequiresPharoMcpHealth(imageConfig, image) {
|
|
681
|
-
return (projectMcpStartupMode(imageConfig.mcp) === "required" &&
|
|
682
|
-
image.pharoMcpContract?.status !== "unsupported");
|
|
683
|
-
}
|
|
684
|
-
function imageCanRouteToPharoMcp(imageConfig, image) {
|
|
685
|
-
return (projectMcpStartupMode(imageConfig.mcp) !== "disabled" &&
|
|
686
|
-
image.pharoMcpContract?.status !== "unsupported");
|
|
687
|
-
}
|
|
688
|
-
function applyScopedImageSelection(state, previousState, imageId) {
|
|
689
|
-
state.images = state.images.filter((image) => {
|
|
690
|
-
if (image.id === imageId) {
|
|
691
|
-
return true;
|
|
692
|
-
}
|
|
693
|
-
const previousImage = previousState?.images.find((candidate) => candidate.id === image.id);
|
|
694
|
-
// An image this open did not touch and nothing has created yet has no
|
|
695
|
-
// runtime at all. Recording it as `stopped` would claim it exists, which
|
|
696
|
-
// is how a created image that is not running reads, and would leave it
|
|
697
|
-
// with no way back: creation refuses an id that already holds runtime
|
|
698
|
-
// state, and nothing can start an image whose files were never made.
|
|
699
|
-
if (!previousImage) {
|
|
700
|
-
return false;
|
|
701
|
-
}
|
|
702
|
-
Object.assign(image, previousImage);
|
|
703
|
-
return true;
|
|
704
|
-
});
|
|
705
|
-
}
|
|
706
|
-
function previousImageState(previousState, imageId) {
|
|
707
|
-
return previousState?.images.find((image) => image.id === imageId);
|
|
708
|
-
}
|
|
709
|
-
// Whether the launcher already holds this image is the launcher's answer, not
|
|
710
|
-
// the record's: a state file left behind by an earlier config names an image id
|
|
711
|
-
// that no longer corresponds to any launcher image, and keying on the id alone
|
|
712
|
-
// then skips materialization for an image nothing ever created.
|
|
713
|
-
function launcherImageMaterialized(options) {
|
|
714
|
-
if (options.imagesDirectory === undefined) {
|
|
715
|
-
return Boolean(previousImageState(options.previousState, options.imageState.id));
|
|
716
|
-
}
|
|
717
|
-
return fs.existsSync(joinPathLike(options.imagesDirectory, options.imageState.imageName));
|
|
718
|
-
}
|
|
719
|
-
function shouldMaterializeImageFromHomeCache(options) {
|
|
720
|
-
return Boolean(options.approval &&
|
|
721
|
-
projectImageCanUseHomeImageCache(options.imageConfig) &&
|
|
722
|
-
!launcherImageMaterialized(options));
|
|
723
|
-
}
|
|
724
|
-
function resolveStartWorkspace(projectRoot, workspaceId) {
|
|
725
|
-
return workspaceId ? sanitizeRuntimeId(workspaceId) : defaultWorkspaceId(projectRoot);
|
|
726
|
-
}
|
|
727
|
-
function resolveStartSourcePath(options) {
|
|
728
|
-
return options.requestedSourcePath
|
|
729
|
-
? path.resolve(options.requestedSourcePath)
|
|
730
|
-
: undefined;
|
|
731
|
-
}
|
|
732
|
-
function applyProjectImageDisplayMode(imageConfig, imageState, displayMode, requestedDisplayMode) {
|
|
733
|
-
if (requestedDisplayMode !== undefined ||
|
|
734
|
-
imageConfig.displayMode !== undefined ||
|
|
735
|
-
imageState.displayMode !== undefined) {
|
|
736
|
-
imageState.displayMode = displayMode;
|
|
737
|
-
}
|
|
738
|
-
}
|
|
739
|
-
async function materializeProjectImageForStart(context, imageConfig, imageState) {
|
|
740
|
-
const existed = launcherImageMaterialized({
|
|
741
|
-
imagesDirectory: context.launcherProfileEnvironment?.PHARO_LAUNCHER_MCP_IMAGES_DIR,
|
|
742
|
-
previousState: context.previousState,
|
|
743
|
-
imageState,
|
|
744
|
-
});
|
|
745
|
-
const homeMaterialization = shouldMaterializeImageFromHomeCache({
|
|
746
|
-
imagesDirectory: context.launcherProfileEnvironment?.PHARO_LAUNCHER_MCP_IMAGES_DIR,
|
|
747
|
-
previousState: context.previousState,
|
|
748
|
-
imageConfig,
|
|
749
|
-
imageState,
|
|
750
|
-
approval: context.options.homeImageCacheApproval,
|
|
751
|
-
})
|
|
752
|
-
? await materializeProjectImageFromHomeCache({
|
|
753
|
-
runtimeClient: context.client,
|
|
754
|
-
homeClient: context.options.homeImageCacheClient ??
|
|
755
|
-
(context.options.pharoLauncherMcpClient ? context.client : undefined),
|
|
756
|
-
projectRoot: context.projectRoot,
|
|
757
|
-
config: context.config,
|
|
758
|
-
imageConfig,
|
|
759
|
-
imageState,
|
|
760
|
-
workspaceId: context.workspaceId,
|
|
761
|
-
stateRoot: context.resolvedStateRoot,
|
|
762
|
-
approval: context.options.homeImageCacheApproval,
|
|
763
|
-
now: context.now,
|
|
764
|
-
})
|
|
765
|
-
: undefined;
|
|
766
|
-
// An image that existed keeps the base it was recorded with; one made now
|
|
767
|
-
// records the base it was copied from, or that it was not copied from one.
|
|
768
|
-
if (homeMaterialization || !existed) {
|
|
769
|
-
recordHomeImageCacheBase(imageState, homeMaterialization);
|
|
770
|
-
}
|
|
771
|
-
if (!homeMaterialization) {
|
|
772
|
-
await copyProjectImageFromPreparedCache({
|
|
773
|
-
client: context.client,
|
|
774
|
-
projectRoot: context.projectRoot,
|
|
775
|
-
config: context.config,
|
|
776
|
-
imageConfig,
|
|
777
|
-
imageState,
|
|
778
|
-
approval: context.options.preparedImageCacheApproval,
|
|
779
|
-
});
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
async function setupProjectImageForStart(context, imageConfig, imageState, displayMode) {
|
|
783
|
-
await materializeProjectImageForStart(context, imageConfig, imageState);
|
|
784
|
-
const endpointHandoffPath = imageMcpEndpointHandoffPath({
|
|
785
|
-
projectRoot: context.projectRoot,
|
|
786
|
-
imageId: imageState.id,
|
|
787
|
-
stateRoot: context.resolvedStateRoot,
|
|
788
|
-
});
|
|
789
|
-
removeImageMcpEndpointHandoff(endpointHandoffPath);
|
|
790
|
-
delete imageState.mcpServers;
|
|
791
|
-
const startupScript = writeProjectImageStartupScript({
|
|
792
|
-
projectRoot: context.projectRoot,
|
|
793
|
-
sourcePath: context.loadSourcePath,
|
|
794
|
-
config: context.config,
|
|
795
|
-
imageId: imageState.id,
|
|
796
|
-
imageState,
|
|
797
|
-
workspaceId: context.workspaceId,
|
|
798
|
-
stateRoot: context.resolvedStateRoot,
|
|
799
|
-
});
|
|
800
|
-
clearPharoMcpLoadStatus(imageState, startupScript.pharoMcpLoadStatusPath);
|
|
801
|
-
clearDependencyRepositoryDetachStatus(imageState, startupScript.dependencyRepositoryDetachStatusPath);
|
|
802
|
-
const launchClient = context.options.pharoLauncherMcpClient
|
|
803
|
-
? context.client
|
|
804
|
-
: openPharoLauncherClient({
|
|
805
|
-
profileEnvironment: context.launcherProfileEnvironment,
|
|
806
|
-
});
|
|
807
|
-
return {
|
|
808
|
-
displayMode,
|
|
809
|
-
endpointHandoffPath,
|
|
810
|
-
pharoMcpLoadStatusPath: startupScript.pharoMcpLoadStatusPath,
|
|
811
|
-
pharoMcpLoadNow: projectImagePharoMcpLoad({
|
|
812
|
-
projectRoot: context.projectRoot,
|
|
813
|
-
config: context.config,
|
|
814
|
-
imageConfig,
|
|
815
|
-
}),
|
|
816
|
-
dependencyRepositoryDetachStatusPath: startupScript.dependencyRepositoryDetachStatusPath,
|
|
817
|
-
startupScript,
|
|
818
|
-
launchClient,
|
|
819
|
-
ownsLaunchClient: !context.options.pharoLauncherMcpClient,
|
|
820
|
-
};
|
|
821
|
-
}
|
|
822
|
-
function handlePharoMcpReadinessResult(options) {
|
|
823
|
-
if (!options.readiness) {
|
|
824
|
-
if (options.requiresHealth) {
|
|
825
|
-
throw new Error(`Timed out waiting for Pharo MCP to write its endpoint to ${options.endpointHandoffPath}`);
|
|
826
|
-
}
|
|
827
|
-
delete options.imageState.mcpServers;
|
|
828
|
-
return;
|
|
829
|
-
}
|
|
830
|
-
if (options.readiness.kind === "processExited") {
|
|
831
|
-
throw imageStartupExitedBeforeHealthError({
|
|
832
|
-
imageName: options.imageState.imageName,
|
|
833
|
-
endpointHandoffPath: options.endpointHandoffPath,
|
|
834
|
-
launcherResult: options.launchRuntime.launcherResult,
|
|
835
|
-
process: options.launchRuntime.process,
|
|
836
|
-
});
|
|
837
|
-
}
|
|
838
|
-
if (options.readiness.kind === "loadFailed") {
|
|
839
|
-
delete options.imageState.mcpServers;
|
|
840
|
-
}
|
|
841
|
-
if (options.readiness.kind === "endpoint") {
|
|
842
|
-
options.imageState.mcpServers = [
|
|
843
|
-
{ id: options.imageState.id, endpoint: options.readiness.endpoint },
|
|
844
|
-
];
|
|
845
|
-
}
|
|
846
|
-
}
|
|
847
|
-
async function routeProjectImageMcp(options) {
|
|
848
|
-
if (!imageCanRouteToPharoMcp(options.imageConfig, options.imageState)) {
|
|
849
|
-
return;
|
|
850
|
-
}
|
|
851
|
-
const requiresHealth = imageRequiresPharoMcpHealth(options.imageConfig, options.imageState);
|
|
852
|
-
const readiness = await pollPharoMcpReadiness({
|
|
853
|
-
imageState: options.imageState,
|
|
854
|
-
endpointHandoffPath: options.setup.endpointHandoffPath,
|
|
855
|
-
healthClient: options.context.healthClient,
|
|
856
|
-
processClient: options.context.client,
|
|
857
|
-
imageName: options.imageState.imageName,
|
|
858
|
-
launchedProcess: options.launchRuntime.process,
|
|
859
|
-
pharoMcpLoadStatusPath: options.setup.pharoMcpLoadStatusPath,
|
|
860
|
-
failOnLoadFailure: requiresHealth,
|
|
861
|
-
timeoutMs: requiresHealth ? options.context.poll.healthTimeoutMs : 0,
|
|
862
|
-
intervalMs: options.context.poll.intervalMs,
|
|
863
|
-
sleep: options.context.sleep,
|
|
864
|
-
});
|
|
865
|
-
handlePharoMcpReadinessResult({
|
|
866
|
-
imageState: options.imageState,
|
|
867
|
-
readiness,
|
|
868
|
-
endpointHandoffPath: options.setup.endpointHandoffPath,
|
|
869
|
-
requiresHealth,
|
|
870
|
-
launchRuntime: options.launchRuntime,
|
|
871
|
-
});
|
|
872
|
-
}
|
|
873
|
-
function assertProjectImageLoadStatuses(options) {
|
|
874
|
-
const pharoMcpLoadFailure = refreshPharoMcpLoadStatus(options.imageState, options.pharoMcpLoadStatusPath, options.pharoMcpLoadNow);
|
|
875
|
-
if (pharoMcpLoadFailure &&
|
|
876
|
-
imageRequiresPharoMcpHealth(options.imageConfig, options.imageState)) {
|
|
877
|
-
throw new Error(pharoMcpLoadFailure);
|
|
878
|
-
}
|
|
879
|
-
const detachFailure = refreshDependencyRepositoryDetachStatus(options.imageState, options.dependencyRepositoryDetachStatusPath);
|
|
880
|
-
if (detachFailure) {
|
|
881
|
-
throw new Error(detachFailure);
|
|
882
|
-
}
|
|
883
|
-
}
|
|
884
|
-
async function launchProjectImage(options) {
|
|
885
|
-
const { context, imageConfig, imageState, setup } = options;
|
|
886
|
-
try {
|
|
887
|
-
const launchRuntime = await launchImageAndPollProcess(setup.launchClient, context.client, imageState.imageName, setup.displayMode, setup.startupScript.filePath, context.poll.processTimeoutMs, context.poll.intervalMs, context.sleep);
|
|
888
|
-
const process = launchRuntime.process;
|
|
889
|
-
imageState.pid = process.pid;
|
|
890
|
-
await routeProjectImageMcp({
|
|
891
|
-
context,
|
|
892
|
-
imageConfig,
|
|
893
|
-
imageState,
|
|
894
|
-
setup,
|
|
895
|
-
launchRuntime,
|
|
896
|
-
});
|
|
897
|
-
assertProjectImageLoadStatuses({
|
|
898
|
-
imageConfig,
|
|
899
|
-
imageState,
|
|
900
|
-
pharoMcpLoadStatusPath: setup.pharoMcpLoadStatusPath,
|
|
901
|
-
pharoMcpLoadNow: setup.pharoMcpLoadNow,
|
|
902
|
-
dependencyRepositoryDetachStatusPath: setup.dependencyRepositoryDetachStatusPath,
|
|
903
|
-
});
|
|
904
|
-
}
|
|
905
|
-
finally {
|
|
906
|
-
if (setup.ownsLaunchClient) {
|
|
907
|
-
closeClientQuietly(setup.launchClient);
|
|
908
|
-
}
|
|
909
|
-
}
|
|
910
|
-
}
|
|
911
|
-
async function recordProjectImageStartFailure(options) {
|
|
912
|
-
options.imageState.status = "failed";
|
|
913
|
-
const pharoMcpLoadFailure = refreshPharoMcpLoadStatus(options.imageState, options.setup?.pharoMcpLoadStatusPath, options.setup?.pharoMcpLoadNow);
|
|
914
|
-
const detachFailure = refreshDependencyRepositoryDetachStatus(options.imageState, options.setup?.dependencyRepositoryDetachStatusPath);
|
|
915
|
-
options.context.failures.push({
|
|
916
|
-
imageId: options.imageState.id,
|
|
917
|
-
imageName: options.imageState.imageName,
|
|
918
|
-
message: detachFailure ?? pharoMcpLoadFailure ??
|
|
919
|
-
errorMessage(options.error),
|
|
920
|
-
...(detachFailure || pharoMcpLoadFailure
|
|
921
|
-
? {}
|
|
922
|
-
: launcherFailureDetails(options.error)),
|
|
923
|
-
...(detachFailure || pharoMcpLoadFailure
|
|
924
|
-
? {}
|
|
925
|
-
: startupFailureDetails(options.error)),
|
|
926
|
-
});
|
|
927
|
-
}
|
|
928
|
-
async function startSelectedImage(context, imageState) {
|
|
929
|
-
const imageConfig = context.config.images.find((image) => image.id === imageState.id);
|
|
930
|
-
if (!imageConfig) {
|
|
931
|
-
return;
|
|
932
|
-
}
|
|
933
|
-
const displayMode = context.options.displayMode ?? projectImageDisplayMode(imageConfig);
|
|
934
|
-
applyProjectImageDisplayMode(imageConfig, imageState, displayMode, context.options.displayMode);
|
|
935
|
-
let setup;
|
|
936
|
-
try {
|
|
937
|
-
setup = await setupProjectImageForStart(context, imageConfig, imageState, displayMode);
|
|
938
|
-
await launchProjectImage({ context, imageConfig, imageState, setup });
|
|
939
|
-
imageState.status = "running";
|
|
940
|
-
}
|
|
941
|
-
catch (error) {
|
|
942
|
-
await recordProjectImageStartFailure({ context, imageState, setup, error });
|
|
943
|
-
}
|
|
944
|
-
}
|
|
945
|
-
/**
|
|
946
|
-
* Start one image the project declares. This is the operation: PLexus acts on
|
|
947
|
-
* an image, named by the caller, and reports what happened to that image.
|
|
948
|
-
*/
|
|
949
|
-
export async function startProjectImage(options) {
|
|
950
|
-
const projectRoot = path.resolve(options.projectRoot);
|
|
951
|
-
const config = loadProjectConfig(projectRoot);
|
|
952
|
-
const workspaceId = resolveStartWorkspace(projectRoot, options.workspaceId);
|
|
953
|
-
const statePath = projectStatePath({
|
|
954
|
-
projectRoot,
|
|
955
|
-
stateRoot: options.stateRoot,
|
|
956
|
-
});
|
|
957
|
-
const resolvedStateRoot = options.stateRoot;
|
|
958
|
-
const previousState = loadProjectState(statePath);
|
|
959
|
-
const requestedSourcePath = options.sourcePath ?? previousState?.sourcePath;
|
|
960
|
-
const sourcePath = resolveStartSourcePath({
|
|
961
|
-
requestedSourcePath,
|
|
962
|
-
projectRoot,
|
|
963
|
-
});
|
|
964
|
-
const loadSourcePath = sourcePath ?? projectRoot;
|
|
965
|
-
const now = options.now ?? (() => new Date());
|
|
966
|
-
const state = createProjectState(config, {
|
|
967
|
-
updatedAt: now().toISOString(),
|
|
968
|
-
previousState,
|
|
969
|
-
workspaceId,
|
|
970
|
-
sourcePath,
|
|
971
|
-
});
|
|
972
|
-
applyScopedImageSelection(state, previousState, options.imageId);
|
|
973
|
-
const imageState = imageToStart(state, options.imageId);
|
|
974
|
-
const failures = [];
|
|
975
|
-
// The project does not declare this image, so there is nothing to start and
|
|
976
|
-
// nothing to report about it beyond the state as it stands.
|
|
977
|
-
if (!imageState) {
|
|
978
|
-
state.runtimeStatus = runtimeStatusForImages(state.images);
|
|
979
|
-
state.updatedAt = now().toISOString();
|
|
980
|
-
saveProjectState(statePath, state);
|
|
981
|
-
return {
|
|
982
|
-
ok: true,
|
|
983
|
-
projectRoot,
|
|
984
|
-
statePath,
|
|
985
|
-
state,
|
|
986
|
-
failures,
|
|
987
|
-
};
|
|
988
|
-
}
|
|
989
|
-
const launcherProfileEnvironment = pharoLauncherMcpProfileEnvironment({
|
|
990
|
-
projectRoot,
|
|
991
|
-
config,
|
|
992
|
-
workspaceId,
|
|
993
|
-
stateRoot: resolvedStateRoot,
|
|
994
|
-
});
|
|
995
|
-
const client = options.pharoLauncherMcpClient ??
|
|
996
|
-
openPharoLauncherClient({
|
|
997
|
-
profileEnvironment: launcherProfileEnvironment,
|
|
998
|
-
});
|
|
999
|
-
const ownsClient = !options.pharoLauncherMcpClient;
|
|
1000
|
-
const healthClient = options.healthClient ?? new HttpPharoMcpHealthClient();
|
|
1001
|
-
const imageMcpClient = options.imageMcpClient ?? new HttpStartProjectImageMcpClient();
|
|
1002
|
-
const poll = {
|
|
1003
|
-
intervalMs: options.poll?.intervalMs ?? 500,
|
|
1004
|
-
processTimeoutMs: options.poll?.processTimeoutMs ?? 30_000,
|
|
1005
|
-
healthTimeoutMs: options.poll?.healthTimeoutMs ?? 5 * 60_000,
|
|
1006
|
-
};
|
|
1007
|
-
const sleep = options.sleep ?? defaultSleep;
|
|
1008
|
-
const context = {
|
|
1009
|
-
options,
|
|
1010
|
-
projectRoot,
|
|
1011
|
-
config,
|
|
1012
|
-
previousState,
|
|
1013
|
-
sourcePath,
|
|
1014
|
-
loadSourcePath,
|
|
1015
|
-
workspaceId,
|
|
1016
|
-
resolvedStateRoot,
|
|
1017
|
-
statePath,
|
|
1018
|
-
state,
|
|
1019
|
-
launcherProfileEnvironment,
|
|
1020
|
-
client,
|
|
1021
|
-
ownsClient,
|
|
1022
|
-
healthClient,
|
|
1023
|
-
imageMcpClient,
|
|
1024
|
-
poll,
|
|
1025
|
-
sleep,
|
|
1026
|
-
failures,
|
|
1027
|
-
now,
|
|
1028
|
-
};
|
|
1029
|
-
try {
|
|
1030
|
-
await startSelectedImage(context, imageState);
|
|
1031
|
-
state.runtimeStatus = runtimeStatusForImages(state.images);
|
|
1032
|
-
state.updatedAt = now().toISOString();
|
|
1033
|
-
saveProjectState(statePath, state);
|
|
1034
|
-
const result = {
|
|
1035
|
-
ok: failures.length === 0,
|
|
1036
|
-
projectRoot,
|
|
1037
|
-
statePath,
|
|
1038
|
-
state,
|
|
1039
|
-
failures,
|
|
1040
|
-
};
|
|
1041
|
-
if (!result.ok) {
|
|
1042
|
-
// One image, so one failure, and its message is the one a caller can
|
|
1043
|
-
// act on. An aggregate sentence here said nothing and hid that.
|
|
1044
|
-
throw new StartProjectImageError(failures[0].message, result);
|
|
1045
|
-
}
|
|
1046
|
-
return result;
|
|
1047
|
-
}
|
|
1048
|
-
finally {
|
|
1049
|
-
if (context.ownsClient) {
|
|
1050
|
-
await client.close?.();
|
|
1051
|
-
}
|
|
1052
|
-
}
|
|
1053
|
-
}
|
|
1054
|
-
//# sourceMappingURL=startProjectImage.js.map
|