@evref-bl/plexus 0.7.0 → 0.8.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 +2 -6
- 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 +30 -42
- 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/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 +260 -172
- 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 +47 -99
- 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 +111 -476
- 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
|
@@ -3,14 +3,14 @@ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
|
3
3
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
4
|
import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
5
5
|
import { loadProjectConfig, projectImageCreateCleanupPolicy, projectImageDisplayMode, projectConfigId, resolveProjectRuntimePolicy, } from "../config/projectConfig.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { openProject } from "../lifecycle/projectOpen.js";
|
|
6
|
+
import { ProjectCloseError, stopProjectImage, } from "../lifecycle/projectClose.js";
|
|
7
|
+
import { hostPharoProcesses, processesOnImage, ProjectOpenError, startProjectImage, } from "../lifecycle/projectOpen.js";
|
|
9
8
|
import { formatToolResultPayload, toolResultDetailFromArguments, toolResultDetailSchema, } from "../support/toolResultFormatting.js";
|
|
10
9
|
import { homeImageCacheNetworkPolicy, materializeProjectImageFromHomeCache, } from "../images/homeImageCache.js";
|
|
10
|
+
import { observeImageRuntime, } from "../images/imageRuntime.js";
|
|
11
11
|
import { createStdioPharoLauncherMcpClient, PharoLauncherMcpToolError, } from "./pharoLauncherMcpClient.js";
|
|
12
12
|
import { describePharoLauncherMcpProfile, pharoLauncherMcpProfileEnvironment, } from "./pharoLauncherProfile.js";
|
|
13
|
-
import {
|
|
13
|
+
import { createProjectState, defaultWorkspaceId, loadProjectState, projectStatePathForConfig, projectStateRootForConfig, renderProjectImageName, runtimeStatusForImages, sanitizeRuntimeId, saveProjectState, } from "../workspace/projectState.js";
|
|
14
14
|
import { projectScriptsDirectoryPath } from "../workspace/projectStartupScript.js";
|
|
15
15
|
import { dirnamePathLike, joinPathLike } from "../support/pathStyle.js";
|
|
16
16
|
import { prepareScopedTemplateCatalog, templateCategoryNames, } from "../images/scopedTemplateCatalog.js";
|
|
@@ -29,6 +29,22 @@ function objectSchema(properties, required = []) {
|
|
|
29
29
|
additionalProperties: false,
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* A held client whose opening failed has nothing to close, and a close that
|
|
34
|
+
* fails must not become the operation's error: the work it was holding the
|
|
35
|
+
* client for is already done.
|
|
36
|
+
*/
|
|
37
|
+
async function closeHeldClient(held) {
|
|
38
|
+
if (!held) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
await (await held).close?.();
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
// Nothing left to do with it.
|
|
46
|
+
}
|
|
47
|
+
}
|
|
32
48
|
export class ScopedPharoLauncherError extends Error {
|
|
33
49
|
details;
|
|
34
50
|
constructor(message, details) {
|
|
@@ -189,7 +205,6 @@ async function ensureScopedTemplateCatalogReady(options) {
|
|
|
189
205
|
projectRoot: options.scope.projectRoot,
|
|
190
206
|
config: options.projectConfig,
|
|
191
207
|
workspaceId: options.scope.workspaceId,
|
|
192
|
-
targetId: options.scope.targetId,
|
|
193
208
|
stateRoot: options.scope.stateRoot,
|
|
194
209
|
});
|
|
195
210
|
const bootstrap = await prepareScopedTemplateCatalog({
|
|
@@ -219,7 +234,6 @@ function resolveScope(options) {
|
|
|
219
234
|
projectId: projectConfigId(projectConfig),
|
|
220
235
|
projectName: projectConfig.name,
|
|
221
236
|
workspaceId,
|
|
222
|
-
targetId: options.targetId ?? defaultTargetId(projectConfigId(projectConfig), workspaceId),
|
|
223
237
|
...(stateRoot ? { stateRoot } : {}),
|
|
224
238
|
};
|
|
225
239
|
}
|
|
@@ -228,7 +242,6 @@ function scopeSummary(scope) {
|
|
|
228
242
|
projectId: scope.projectId,
|
|
229
243
|
projectName: scope.projectName,
|
|
230
244
|
workspaceId: scope.workspaceId,
|
|
231
|
-
targetId: scope.targetId,
|
|
232
245
|
};
|
|
233
246
|
}
|
|
234
247
|
function launcherProfileSummary(profile) {
|
|
@@ -237,13 +250,13 @@ function launcherProfileSummary(profile) {
|
|
|
237
250
|
mode: profile.mode,
|
|
238
251
|
};
|
|
239
252
|
}
|
|
240
|
-
function imageSummary(imageConfig, imageState) {
|
|
253
|
+
function imageSummary(imageConfig, imageState, runtime) {
|
|
241
254
|
const defaultDisplayMode = projectImageDisplayMode(imageConfig);
|
|
242
255
|
const displayMode = imageState?.displayMode ?? defaultDisplayMode;
|
|
243
256
|
return {
|
|
244
257
|
imageId: imageConfig.id,
|
|
245
|
-
|
|
246
|
-
|
|
258
|
+
status: runtime.status,
|
|
259
|
+
runtime,
|
|
247
260
|
displayMode,
|
|
248
261
|
displayModes: {
|
|
249
262
|
default: defaultDisplayMode,
|
|
@@ -281,8 +294,8 @@ function sameLeaseOwner(left, right) {
|
|
|
281
294
|
return left.ownerKind === right.ownerKind && left.ownerId === right.ownerId;
|
|
282
295
|
}
|
|
283
296
|
function imageLeaseForMutation(scope, options, now, existingLease, mode = "mutable") {
|
|
284
|
-
const ownerId = options?.ownerId ?? scope.
|
|
285
|
-
const ownerKind = options?.ownerKind ?? "
|
|
297
|
+
const ownerId = options?.ownerId ?? scope.workspaceId;
|
|
298
|
+
const ownerKind = options?.ownerKind ?? "workspace";
|
|
286
299
|
const retainedLease = existingLease?.ownerId === ownerId && existingLease.ownerKind === ownerKind
|
|
287
300
|
? existingLease
|
|
288
301
|
: undefined;
|
|
@@ -345,7 +358,6 @@ function renderedImageName(scope, imageConfig) {
|
|
|
345
358
|
projectId: scope.projectId,
|
|
346
359
|
projectName: scope.projectName,
|
|
347
360
|
workspaceId: scope.workspaceId,
|
|
348
|
-
targetId: scope.targetId,
|
|
349
361
|
imageId: imageConfig.id,
|
|
350
362
|
});
|
|
351
363
|
}
|
|
@@ -367,7 +379,7 @@ function imageCreationState(imageConfig) {
|
|
|
367
379
|
cleanupPolicy: projectImageCreateCleanupPolicy(create),
|
|
368
380
|
route: {
|
|
369
381
|
serverName: "pharo_gateway",
|
|
370
|
-
targetKey: "
|
|
382
|
+
targetKey: "workspaceId",
|
|
371
383
|
imageArgument: "mcpServerId",
|
|
372
384
|
imageId: imageConfig.id,
|
|
373
385
|
},
|
|
@@ -383,9 +395,6 @@ function assertPreviousStateBelongsToScope(previousState, scope) {
|
|
|
383
395
|
if (previousState.workspaceId !== scope.workspaceId) {
|
|
384
396
|
throw new ScopedPharoLauncherError(`State file belongs to workspace ${previousState.workspaceId}; scoped create for workspace ${scope.workspaceId} is rejected`);
|
|
385
397
|
}
|
|
386
|
-
if (previousState.targetId !== scope.targetId) {
|
|
387
|
-
throw new ScopedPharoLauncherError(`State file belongs to target ${previousState.targetId}; scoped create for target ${scope.targetId} is rejected`);
|
|
388
|
-
}
|
|
389
398
|
}
|
|
390
399
|
function assertWorkspaceImagePolicyAllowsCreate(projectConfig, previousState, imageId) {
|
|
391
400
|
const maxCount = resolveProjectRuntimePolicy(projectConfig).workspaceImages?.maxCount;
|
|
@@ -519,10 +528,6 @@ function routeStatus(image, imageState) {
|
|
|
519
528
|
};
|
|
520
529
|
}
|
|
521
530
|
function resetCloseError(imageId, error) {
|
|
522
|
-
const cleanup = error.result.repositoryWorkspaceCleanups.find((record) => record.imageId === imageId);
|
|
523
|
-
if (cleanup) {
|
|
524
|
-
return new ScopedPharoLauncherError(`Image ${imageId} reset could not clean its disposable repository workspace: ${cleanup.decision} (${cleanup.dirtyState})`);
|
|
525
|
-
}
|
|
526
531
|
const failure = error.result.failures.find((record) => record.imageId === imageId);
|
|
527
532
|
if (failure) {
|
|
528
533
|
return new ScopedPharoLauncherError(`Image ${imageId} reset could not close the scoped image`);
|
|
@@ -538,15 +543,6 @@ function resetSummary(imageId, closeResult, deleted, started, image, imageState)
|
|
|
538
543
|
started,
|
|
539
544
|
lifecycle: lifecycleStatus(image),
|
|
540
545
|
route: routeStatus(image, imageState),
|
|
541
|
-
repositoryWorkspaceCleanupPolicy: "delete-disposable",
|
|
542
|
-
repositoryWorkspaceCleanup: {
|
|
543
|
-
attempted: Boolean(closeResult),
|
|
544
|
-
decisions: closeResult?.repositoryWorkspaceCleanups.map((record) => ({
|
|
545
|
-
repositoryId: record.repositoryId,
|
|
546
|
-
decision: record.decision,
|
|
547
|
-
dirtyState: record.dirtyState,
|
|
548
|
-
})) ?? [],
|
|
549
|
-
},
|
|
550
546
|
};
|
|
551
547
|
}
|
|
552
548
|
function launcherHoldsImage(scope, projectConfig, imageName) {
|
|
@@ -554,7 +550,6 @@ function launcherHoldsImage(scope, projectConfig, imageName) {
|
|
|
554
550
|
projectRoot: scope.projectRoot,
|
|
555
551
|
config: projectConfig,
|
|
556
552
|
workspaceId: scope.workspaceId,
|
|
557
|
-
targetId: scope.targetId,
|
|
558
553
|
stateRoot: scope.stateRoot,
|
|
559
554
|
});
|
|
560
555
|
// An external profile keeps its own paths, so we cannot look. Answer the way
|
|
@@ -562,19 +557,9 @@ function launcherHoldsImage(scope, projectConfig, imageName) {
|
|
|
562
557
|
return imagesDir === undefined || fs.existsSync(joinPathLike(imagesDir, imageName));
|
|
563
558
|
}
|
|
564
559
|
function stateWithCreatedImage(projectConfig, scope, previousState, imageId, now) {
|
|
565
|
-
const runtime = resolveProjectRuntimePolicy(projectConfig);
|
|
566
|
-
const reservedPorts = collectReservedProjectPortOwners({
|
|
567
|
-
projectRoot: scope.projectRoot,
|
|
568
|
-
projectId: projectConfigId(projectConfig),
|
|
569
|
-
stateRoot: scope.stateRoot,
|
|
570
|
-
excludeWorkspaceId: scope.workspaceId,
|
|
571
|
-
}).map((owner) => owner.port);
|
|
572
560
|
const state = createProjectState(projectConfig, {
|
|
573
561
|
previousState,
|
|
574
562
|
workspaceId: scope.workspaceId,
|
|
575
|
-
targetId: scope.targetId,
|
|
576
|
-
reservedPorts,
|
|
577
|
-
portRange: runtime.imagePorts.range,
|
|
578
563
|
updatedAt: now.toISOString(),
|
|
579
564
|
});
|
|
580
565
|
const existingImageIds = new Set(previousState?.images.map((image) => image.id) ?? []);
|
|
@@ -608,6 +593,9 @@ export class ScopedPharoLauncher {
|
|
|
608
593
|
constructor(options) {
|
|
609
594
|
this.options = options;
|
|
610
595
|
}
|
|
596
|
+
/** The client held for the operations in flight, and how many hold it. */
|
|
597
|
+
heldClient;
|
|
598
|
+
holdCount = 0;
|
|
611
599
|
currentImageState(scope, projectConfig, imageId) {
|
|
612
600
|
const state = loadProjectState(statePathForScope(scope, projectConfig));
|
|
613
601
|
return state?.images.find((image) => image.id === imageId);
|
|
@@ -628,32 +616,6 @@ export class ScopedPharoLauncher {
|
|
|
628
616
|
saveProjectState(statePath, nextState);
|
|
629
617
|
return nextState;
|
|
630
618
|
}
|
|
631
|
-
routeRegistryForState(state) {
|
|
632
|
-
if (this.options.routeRegistry) {
|
|
633
|
-
return this.options.routeRegistry;
|
|
634
|
-
}
|
|
635
|
-
const controlEndpoint = state.gateway?.controlEndpoint;
|
|
636
|
-
return controlEndpoint
|
|
637
|
-
? new HttpGatewayRouteRegistry({
|
|
638
|
-
url: controlEndpoint,
|
|
639
|
-
fetch: this.options.fetch,
|
|
640
|
-
})
|
|
641
|
-
: undefined;
|
|
642
|
-
}
|
|
643
|
-
async refreshRegisteredProjectRoute(scope, statePath, state) {
|
|
644
|
-
if (!state) {
|
|
645
|
-
return;
|
|
646
|
-
}
|
|
647
|
-
const routeRegistry = this.routeRegistryForState(state);
|
|
648
|
-
if (!routeRegistry) {
|
|
649
|
-
return;
|
|
650
|
-
}
|
|
651
|
-
await routeRegistry.registerProjectRoute({
|
|
652
|
-
projectRoot: scope.projectRoot,
|
|
653
|
-
statePath,
|
|
654
|
-
state,
|
|
655
|
-
});
|
|
656
|
-
}
|
|
657
619
|
async snapshotImageBeforeDisplayModeRestart(scope, imageState) {
|
|
658
620
|
const endpoint = imageMcpSnapshotEndpoint(imageState);
|
|
659
621
|
if (!endpoint) {
|
|
@@ -709,7 +671,29 @@ export class ScopedPharoLauncher {
|
|
|
709
671
|
clearTimeout(timeout);
|
|
710
672
|
}
|
|
711
673
|
}
|
|
712
|
-
|
|
674
|
+
/**
|
|
675
|
+
* What the host is running, asked once for the whole listing. image_start
|
|
676
|
+
* refuses a launch on this same answer, so a listing that did not ask it
|
|
677
|
+
* disagreed with the guard that acts on it: an image someone else started
|
|
678
|
+
* read as stopped, and a dead image whose port had been reused read as
|
|
679
|
+
* running.
|
|
680
|
+
*
|
|
681
|
+
* A listing still answers when the launcher cannot be reached. It says so
|
|
682
|
+
* rather than passing off the record as the host's answer.
|
|
683
|
+
*/
|
|
684
|
+
async hostProcessesForListing(scope, projectConfig) {
|
|
685
|
+
try {
|
|
686
|
+
return {
|
|
687
|
+
processes: await this.withLauncherClient(scope, projectConfig, async (client) => hostPharoProcesses(client)),
|
|
688
|
+
};
|
|
689
|
+
}
|
|
690
|
+
catch (error) {
|
|
691
|
+
return {
|
|
692
|
+
error: error instanceof Error ? error.message : String(error),
|
|
693
|
+
};
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
async listImages() {
|
|
713
697
|
const scope = resolveScope(this.options);
|
|
714
698
|
const projectConfig = loadProjectConfig(scope.projectRoot);
|
|
715
699
|
const state = loadProjectState(statePathForScope(scope, projectConfig));
|
|
@@ -717,17 +701,51 @@ export class ScopedPharoLauncher {
|
|
|
717
701
|
projectRoot: scope.projectRoot,
|
|
718
702
|
config: projectConfig,
|
|
719
703
|
workspaceId: scope.workspaceId,
|
|
720
|
-
targetId: scope.targetId,
|
|
721
704
|
stateRoot: scope.stateRoot,
|
|
722
705
|
});
|
|
706
|
+
const host = await this.hostProcessesForListing(scope, projectConfig);
|
|
723
707
|
return {
|
|
724
708
|
scope: scopeSummary(scope),
|
|
725
709
|
launcherProfile: launcherProfileSummary(launcherProfile),
|
|
726
|
-
|
|
710
|
+
host: host.processes === undefined
|
|
711
|
+
? {
|
|
712
|
+
asked: false,
|
|
713
|
+
...(host.error === undefined ? {} : { error: host.error }),
|
|
714
|
+
}
|
|
715
|
+
: { asked: true, pharoProcesses: host.processes.length },
|
|
716
|
+
images: await Promise.all(projectConfig.images.map(async (imageConfig) => {
|
|
717
|
+
const imageState = state?.images.find((image) => image.id === imageConfig.id);
|
|
718
|
+
const imageName = renderProjectImageName(imageConfig.imageName, {
|
|
719
|
+
projectId: scope.projectId,
|
|
720
|
+
projectName: scope.projectName,
|
|
721
|
+
workspaceId: scope.workspaceId,
|
|
722
|
+
imageId: imageConfig.id,
|
|
723
|
+
});
|
|
724
|
+
return imageSummary(imageConfig, imageState, await observeImageRuntime({
|
|
725
|
+
...scope,
|
|
726
|
+
...(this.options.isPidAlive === undefined
|
|
727
|
+
? {}
|
|
728
|
+
: { isPidAlive: this.options.isPidAlive }),
|
|
729
|
+
...(this.options.isPortListening === undefined
|
|
730
|
+
? {}
|
|
731
|
+
: { isPortListening: this.options.isPortListening }),
|
|
732
|
+
imageId: imageConfig.id,
|
|
733
|
+
imageName,
|
|
734
|
+
...(launcherProfile.imagesDir === undefined
|
|
735
|
+
? {}
|
|
736
|
+
: { imagesDirectory: launcherProfile.imagesDir }),
|
|
737
|
+
...(imageState?.pid === undefined ? {} : { pid: imageState.pid }),
|
|
738
|
+
...(host.processes === undefined
|
|
739
|
+
? {}
|
|
740
|
+
: {
|
|
741
|
+
runningOnHost: processesOnImage(host.processes, imageName).length > 0,
|
|
742
|
+
}),
|
|
743
|
+
}));
|
|
744
|
+
})),
|
|
727
745
|
};
|
|
728
746
|
}
|
|
729
|
-
imageInfo(imageId) {
|
|
730
|
-
const listed = this.listImages();
|
|
747
|
+
async imageInfo(imageId) {
|
|
748
|
+
const listed = await this.listImages();
|
|
731
749
|
const image = listed.images.find((candidate) => candidate.imageId === imageId);
|
|
732
750
|
if (!image) {
|
|
733
751
|
throw new ScopedPharoLauncherError(`Image ${imageId} is not declared in this PLexus workspace`);
|
|
@@ -735,28 +753,65 @@ export class ScopedPharoLauncher {
|
|
|
735
753
|
return {
|
|
736
754
|
scope: listed.scope,
|
|
737
755
|
launcherProfile: listed.launcherProfile,
|
|
756
|
+
host: listed.host,
|
|
738
757
|
image,
|
|
739
758
|
};
|
|
740
759
|
}
|
|
760
|
+
/**
|
|
761
|
+
* One launcher client for one operation.
|
|
762
|
+
*
|
|
763
|
+
* Every step that reaches the launcher used to open its own
|
|
764
|
+
* pharo-launcher-mcp subprocess: a reset closes, deletes, creates and
|
|
765
|
+
* reopens, reporting a listing after each step, which was four. The caller
|
|
766
|
+
* says where an operation begins and ends — a tool call, a CLI command —
|
|
767
|
+
* because this facade cannot tell one from a sequence of them.
|
|
768
|
+
*
|
|
769
|
+
* Operations that overlap share the client, and the last one out closes it.
|
|
770
|
+
* They can: the facade is bound to one project root and workspace, so every
|
|
771
|
+
* client it would open is opened with the same profile environment.
|
|
772
|
+
*/
|
|
773
|
+
async runOperation(action) {
|
|
774
|
+
this.holdCount += 1;
|
|
775
|
+
try {
|
|
776
|
+
return await action();
|
|
777
|
+
}
|
|
778
|
+
finally {
|
|
779
|
+
this.holdCount -= 1;
|
|
780
|
+
if (this.holdCount === 0) {
|
|
781
|
+
const held = this.heldClient;
|
|
782
|
+
this.heldClient = undefined;
|
|
783
|
+
await closeHeldClient(held);
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
async openLauncherClient(scope, projectConfig) {
|
|
788
|
+
const profileEnvironment = pharoLauncherMcpProfileEnvironment({
|
|
789
|
+
projectRoot: scope.projectRoot,
|
|
790
|
+
config: projectConfig,
|
|
791
|
+
workspaceId: scope.workspaceId,
|
|
792
|
+
stateRoot: scope.stateRoot,
|
|
793
|
+
});
|
|
794
|
+
return this.options.createPharoLauncherMcpClient
|
|
795
|
+
? await this.options.createPharoLauncherMcpClient(profileEnvironment)
|
|
796
|
+
: await createStdioPharoLauncherMcpClient(undefined, {
|
|
797
|
+
...(profileEnvironment === undefined ? {} : { profileEnvironment }),
|
|
798
|
+
});
|
|
799
|
+
}
|
|
741
800
|
async withLauncherClient(scope, projectConfig, action) {
|
|
742
|
-
const
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
}));
|
|
752
|
-
const ownsClient = !this.options.pharoLauncherMcpClient;
|
|
801
|
+
const injected = this.options.pharoLauncherMcpClient;
|
|
802
|
+
if (injected) {
|
|
803
|
+
return await action(injected);
|
|
804
|
+
}
|
|
805
|
+
if (this.holdCount > 0) {
|
|
806
|
+
this.heldClient ??= this.openLauncherClient(scope, projectConfig);
|
|
807
|
+
return await action(await this.heldClient);
|
|
808
|
+
}
|
|
809
|
+
const client = await this.openLauncherClient(scope, projectConfig);
|
|
753
810
|
try {
|
|
754
811
|
return await action(client);
|
|
755
812
|
}
|
|
756
813
|
finally {
|
|
757
|
-
|
|
758
|
-
await client.close?.();
|
|
759
|
-
}
|
|
814
|
+
await client.close?.();
|
|
760
815
|
}
|
|
761
816
|
}
|
|
762
817
|
async listTemplates(templateCategory) {
|
|
@@ -779,7 +834,6 @@ export class ScopedPharoLauncher {
|
|
|
779
834
|
projectRoot: scope.projectRoot,
|
|
780
835
|
config: projectConfig,
|
|
781
836
|
workspaceId: scope.workspaceId,
|
|
782
|
-
targetId: scope.targetId,
|
|
783
837
|
stateRoot: scope.stateRoot,
|
|
784
838
|
}).templateSourcesDir);
|
|
785
839
|
if (categories.length === 0) {
|
|
@@ -832,7 +886,6 @@ export class ScopedPharoLauncher {
|
|
|
832
886
|
projectRoot: scope.projectRoot,
|
|
833
887
|
config: projectConfig,
|
|
834
888
|
workspaceId: scope.workspaceId,
|
|
835
|
-
targetId: scope.targetId,
|
|
836
889
|
stateRoot: scope.stateRoot,
|
|
837
890
|
})),
|
|
838
891
|
};
|
|
@@ -841,17 +894,26 @@ export class ScopedPharoLauncher {
|
|
|
841
894
|
const scope = resolveScope(this.options);
|
|
842
895
|
const projectConfig = loadProjectConfig(scope.projectRoot);
|
|
843
896
|
const imageConfig = findImageConfig(projectConfig, imageId);
|
|
844
|
-
|
|
897
|
+
const createPolicy = imageConfig.create;
|
|
898
|
+
if (!createPolicy) {
|
|
845
899
|
throw new ScopedPharoLauncherError(`Image ${imageId} has no approved create policy in project config`);
|
|
846
900
|
}
|
|
847
|
-
if (profileId && profileId !==
|
|
901
|
+
if (profileId && profileId !== createPolicy.profileId) {
|
|
848
902
|
throw new ScopedPharoLauncherError(`Profile ${profileId} is not approved for image ${imageId}`);
|
|
849
903
|
}
|
|
850
904
|
const statePath = statePathForScope(scope, projectConfig);
|
|
851
905
|
const previousState = loadProjectState(statePath);
|
|
852
906
|
assertPreviousStateBelongsToScope(previousState, scope);
|
|
853
|
-
|
|
854
|
-
|
|
907
|
+
// Ask the profile, not the record. A record can name an image the launcher
|
|
908
|
+
// no longer holds, and refusing to create that one is refusing to fix it.
|
|
909
|
+
const imageName = renderProjectImageName(imageConfig.imageName, {
|
|
910
|
+
projectId: scope.projectId,
|
|
911
|
+
projectName: projectConfig.name,
|
|
912
|
+
workspaceId: scope.workspaceId,
|
|
913
|
+
imageId,
|
|
914
|
+
});
|
|
915
|
+
if (launcherHoldsImage(scope, projectConfig, imageName)) {
|
|
916
|
+
throw new ScopedPharoLauncherError(`Image ${imageId} already exists as ${imageName}`);
|
|
855
917
|
}
|
|
856
918
|
assertWorkspaceImagePolicyAllowsCreate(projectConfig, previousState, imageId);
|
|
857
919
|
const now = this.options.now?.() ?? new Date();
|
|
@@ -861,18 +923,7 @@ export class ScopedPharoLauncher {
|
|
|
861
923
|
if (!imageState) {
|
|
862
924
|
throw new ScopedPharoLauncherError(`Image ${imageId} is not declared in this PLexus workspace`);
|
|
863
925
|
}
|
|
864
|
-
|
|
865
|
-
(await createStdioPharoLauncherMcpClient(undefined, {
|
|
866
|
-
profileEnvironment: pharoLauncherMcpProfileEnvironment({
|
|
867
|
-
projectRoot: scope.projectRoot,
|
|
868
|
-
config: projectConfig,
|
|
869
|
-
workspaceId: scope.workspaceId,
|
|
870
|
-
targetId: scope.targetId,
|
|
871
|
-
stateRoot: scope.stateRoot,
|
|
872
|
-
}),
|
|
873
|
-
}));
|
|
874
|
-
const ownsClient = !this.options.pharoLauncherMcpClient;
|
|
875
|
-
try {
|
|
926
|
+
await this.withLauncherClient(scope, projectConfig, async (client) => {
|
|
876
927
|
const homeMaterialization = await materializeProjectImageFromHomeCache({
|
|
877
928
|
runtimeClient: client,
|
|
878
929
|
homeClient: this.options.homeImageCacheClient ??
|
|
@@ -882,7 +933,6 @@ export class ScopedPharoLauncher {
|
|
|
882
933
|
imageConfig,
|
|
883
934
|
imageState,
|
|
884
935
|
workspaceId: scope.workspaceId,
|
|
885
|
-
targetId: scope.targetId,
|
|
886
936
|
stateRoot: scope.stateRoot,
|
|
887
937
|
approval: scopedMutationApproval(this.options.homeImageCacheApproval, "scoped-pharo-launcher-create"),
|
|
888
938
|
now: this.options.now,
|
|
@@ -896,9 +946,9 @@ export class ScopedPharoLauncher {
|
|
|
896
946
|
});
|
|
897
947
|
const result = await client.callTool("pharo_launcher_image_create", {
|
|
898
948
|
newImageName: renderedImageName(scope, imageConfig),
|
|
899
|
-
templateName:
|
|
900
|
-
...(
|
|
901
|
-
? { templateCategory:
|
|
949
|
+
templateName: createPolicy.templateName,
|
|
950
|
+
...(createPolicy.templateCategory
|
|
951
|
+
? { templateCategory: createPolicy.templateCategory }
|
|
902
952
|
: {}),
|
|
903
953
|
noLaunch: true,
|
|
904
954
|
});
|
|
@@ -906,20 +956,11 @@ export class ScopedPharoLauncher {
|
|
|
906
956
|
}
|
|
907
957
|
const nextState = stateWithImageLease(state, imageId, lease, now);
|
|
908
958
|
saveProjectState(statePath, nextState);
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
finally {
|
|
912
|
-
if (ownsClient) {
|
|
913
|
-
await client.close?.();
|
|
914
|
-
}
|
|
915
|
-
}
|
|
916
|
-
return this.imageInfo(imageId);
|
|
959
|
+
});
|
|
960
|
+
return await this.imageInfo(imageId);
|
|
917
961
|
}
|
|
918
962
|
async startImage(imageId, displayMode) {
|
|
919
|
-
const before = this.imageInfo(imageId);
|
|
920
|
-
if (!before.image.active) {
|
|
921
|
-
throw new ScopedPharoLauncherError(`Image ${imageId} is not active in project config; scoped start is rejected`);
|
|
922
|
-
}
|
|
963
|
+
const before = await this.imageInfo(imageId);
|
|
923
964
|
if (before.image.status === "running" || before.image.status === "starting") {
|
|
924
965
|
throw new ScopedPharoLauncherError(`Image ${imageId} is already ${before.image.status}; scoped start is rejected`);
|
|
925
966
|
}
|
|
@@ -927,32 +968,46 @@ export class ScopedPharoLauncher {
|
|
|
927
968
|
const projectConfig = loadProjectConfig(scope.projectRoot);
|
|
928
969
|
const now = this.options.now?.() ?? new Date();
|
|
929
970
|
const lease = this.imageLeaseForMutation(scope, projectConfig, imageId, now);
|
|
930
|
-
const openResult = await (this.options.
|
|
971
|
+
const openResult = await this.startingImage(imageId, () => (this.options.startImage ?? startProjectImage)({
|
|
931
972
|
projectRoot: scope.projectRoot,
|
|
932
973
|
workspaceId: scope.workspaceId,
|
|
933
|
-
targetId: scope.targetId,
|
|
934
974
|
stateRoot: scope.stateRoot,
|
|
935
|
-
|
|
975
|
+
imageId,
|
|
936
976
|
...(displayMode ? { displayMode } : {}),
|
|
937
977
|
homeImageCacheApproval: scopedMutationApproval(this.options.homeImageCacheApproval, "scoped-pharo-launcher-start"),
|
|
938
978
|
homeImageCacheClient: this.options.homeImageCacheClient ??
|
|
939
979
|
this.options.pharoLauncherMcpClient,
|
|
940
|
-
});
|
|
980
|
+
}));
|
|
941
981
|
const statePath = statePathForScope(scope, projectConfig);
|
|
942
982
|
const leasedState = this.recordImageLease(scope, projectConfig, imageId, lease, now);
|
|
943
|
-
await this.
|
|
944
|
-
|
|
983
|
+
return await this.imageInfo(imageId);
|
|
984
|
+
}
|
|
985
|
+
/**
|
|
986
|
+
* "One or more project images failed to open" tells the caller nothing it can
|
|
987
|
+
* act on. The per-image failure says what actually happened — which VM holds
|
|
988
|
+
* the image, which tool frees it — so raise that instead.
|
|
989
|
+
*/
|
|
990
|
+
async startingImage(imageId, start) {
|
|
991
|
+
try {
|
|
992
|
+
return await start();
|
|
993
|
+
}
|
|
994
|
+
catch (error) {
|
|
995
|
+
if (!(error instanceof ProjectOpenError)) {
|
|
996
|
+
throw error;
|
|
997
|
+
}
|
|
998
|
+
const failure = error.result.failures.find((candidate) => candidate.imageId === imageId);
|
|
999
|
+
throw failure
|
|
1000
|
+
? new ScopedPharoLauncherError(failure.message)
|
|
1001
|
+
: error;
|
|
1002
|
+
}
|
|
945
1003
|
}
|
|
946
1004
|
async setImageDisplayMode(imageId, displayMode) {
|
|
947
1005
|
const scope = resolveScope(this.options);
|
|
948
1006
|
const projectConfig = loadProjectConfig(scope.projectRoot);
|
|
949
1007
|
const imageConfig = findImageConfig(projectConfig, imageId);
|
|
950
|
-
const before = this.imageInfo(imageId);
|
|
1008
|
+
const before = await this.imageInfo(imageId);
|
|
951
1009
|
const imageState = this.currentImageState(scope, projectConfig, imageId);
|
|
952
1010
|
const previousDisplayMode = imageState?.displayMode ?? projectImageDisplayMode(imageConfig);
|
|
953
|
-
if (!before.image.active) {
|
|
954
|
-
throw new ScopedPharoLauncherError(`Image ${imageId} is not active in project config; display mode change is rejected`);
|
|
955
|
-
}
|
|
956
1011
|
if (before.image.status === "starting") {
|
|
957
1012
|
throw new ScopedPharoLauncherError(`Image ${imageId} is starting; wait for startup to finish before changing display mode`);
|
|
958
1013
|
}
|
|
@@ -976,7 +1031,7 @@ export class ScopedPharoLauncher {
|
|
|
976
1031
|
}
|
|
977
1032
|
await this.startImage(imageId, displayMode);
|
|
978
1033
|
return {
|
|
979
|
-
...this.imageInfo(imageId),
|
|
1034
|
+
...(await this.imageInfo(imageId)),
|
|
980
1035
|
previousDisplayMode,
|
|
981
1036
|
displayMode,
|
|
982
1037
|
restarted: before.image.status === "running",
|
|
@@ -994,51 +1049,31 @@ export class ScopedPharoLauncher {
|
|
|
994
1049
|
return this.setImageDisplayMode(imageId, "headless");
|
|
995
1050
|
}
|
|
996
1051
|
async stopImage(imageId) {
|
|
997
|
-
this.imageInfo(imageId);
|
|
1052
|
+
await this.imageInfo(imageId);
|
|
998
1053
|
const scope = resolveScope(this.options);
|
|
999
1054
|
const projectConfig = loadProjectConfig(scope.projectRoot);
|
|
1000
1055
|
const now = this.options.now?.() ?? new Date();
|
|
1001
1056
|
const lease = this.imageLeaseForMutation(scope, projectConfig, imageId, now);
|
|
1002
|
-
const closeResult = await (this.options.
|
|
1057
|
+
const closeResult = await (this.options.stopImage ?? stopProjectImage)({
|
|
1003
1058
|
projectRoot: scope.projectRoot,
|
|
1004
1059
|
workspaceId: scope.workspaceId,
|
|
1005
1060
|
stateRoot: scope.stateRoot,
|
|
1006
|
-
|
|
1061
|
+
imageId,
|
|
1007
1062
|
});
|
|
1008
1063
|
const statePath = statePathForScope(scope, projectConfig);
|
|
1009
1064
|
const leasedState = this.recordImageLease(scope, projectConfig, imageId, lease, now);
|
|
1010
|
-
await this.
|
|
1011
|
-
return this.imageInfo(imageId);
|
|
1065
|
+
return await this.imageInfo(imageId);
|
|
1012
1066
|
}
|
|
1013
1067
|
assertResetImageConfig(imageId, imageConfig) {
|
|
1014
|
-
if (!imageConfig.active) {
|
|
1015
|
-
throw new ScopedPharoLauncherError(`Image ${imageId} is not active in project config; scoped reset is rejected`);
|
|
1016
|
-
}
|
|
1017
1068
|
if (!imageConfig.create) {
|
|
1018
1069
|
throw new ScopedPharoLauncherError(`Image ${imageId} has no approved create policy in project config; scoped reset is rejected`);
|
|
1019
1070
|
}
|
|
1020
1071
|
}
|
|
1021
1072
|
async deleteLauncherImage(scope, projectConfig, imageName) {
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
profileEnvironment: pharoLauncherMcpProfileEnvironment({
|
|
1025
|
-
projectRoot: scope.projectRoot,
|
|
1026
|
-
config: projectConfig,
|
|
1027
|
-
workspaceId: scope.workspaceId,
|
|
1028
|
-
targetId: scope.targetId,
|
|
1029
|
-
stateRoot: scope.stateRoot,
|
|
1030
|
-
}),
|
|
1031
|
-
}));
|
|
1032
|
-
const ownsClient = !this.options.pharoLauncherMcpClient;
|
|
1033
|
-
try {
|
|
1034
|
-
const deleteResult = await client.callTool("pharo_launcher_image_delete", { imageName, force: true, confirm: true });
|
|
1073
|
+
await this.withLauncherClient(scope, projectConfig, async (client) => {
|
|
1074
|
+
const deleteResult = await client.callTool("pharo_launcher_image_delete", { imageName, force: true });
|
|
1035
1075
|
assertLauncherOk(deleteResult, "pharo_launcher_image_delete");
|
|
1036
|
-
}
|
|
1037
|
-
finally {
|
|
1038
|
-
if (ownsClient) {
|
|
1039
|
-
await client.close?.();
|
|
1040
|
-
}
|
|
1041
|
-
}
|
|
1076
|
+
});
|
|
1042
1077
|
}
|
|
1043
1078
|
async resetImage(imageId, options = {}) {
|
|
1044
1079
|
const scope = resolveScope(this.options);
|
|
@@ -1057,13 +1092,12 @@ export class ScopedPharoLauncher {
|
|
|
1057
1092
|
let closeResult;
|
|
1058
1093
|
if (previousImage) {
|
|
1059
1094
|
try {
|
|
1060
|
-
closeResult = await (this.options.
|
|
1095
|
+
closeResult = await (this.options.stopImage ?? stopProjectImage)({
|
|
1061
1096
|
projectRoot: scope.projectRoot,
|
|
1062
1097
|
workspaceId: scope.workspaceId,
|
|
1063
1098
|
stateRoot: scope.stateRoot,
|
|
1064
|
-
|
|
1099
|
+
imageId,
|
|
1065
1100
|
pharoLauncherMcpClient: this.options.pharoLauncherMcpClient,
|
|
1066
|
-
repositoryWorkspaceCleanupPolicy: "delete-disposable",
|
|
1067
1101
|
});
|
|
1068
1102
|
}
|
|
1069
1103
|
catch (error) {
|
|
@@ -1093,12 +1127,51 @@ export class ScopedPharoLauncher {
|
|
|
1093
1127
|
if (shouldStart) {
|
|
1094
1128
|
await this.startImage(imageId, options.displayMode);
|
|
1095
1129
|
}
|
|
1096
|
-
const finalInfo = this.imageInfo(imageId);
|
|
1130
|
+
const finalInfo = await this.imageInfo(imageId);
|
|
1097
1131
|
return {
|
|
1098
1132
|
...finalInfo,
|
|
1099
1133
|
reset: resetSummary(imageId, closeResult, deleted, shouldStart, finalInfo.image, this.currentImageState(scope, projectConfig, imageId)),
|
|
1100
1134
|
};
|
|
1101
1135
|
}
|
|
1136
|
+
/**
|
|
1137
|
+
* Delete the image this project declares. No confirm flag: a destructive call
|
|
1138
|
+
* is guarded by refusing a state that conflicts with it, not by a boolean the
|
|
1139
|
+
* caller fills in anyway. Deleting a running image is that conflict.
|
|
1140
|
+
*/
|
|
1141
|
+
async deleteImage(imageId) {
|
|
1142
|
+
const before = await this.imageInfo(imageId);
|
|
1143
|
+
if (before.image.runtime?.status === "running" ||
|
|
1144
|
+
before.image.runtime?.status === "starting") {
|
|
1145
|
+
throw new ScopedPharoLauncherError(`Image ${imageId} is ${before.image.runtime.status}; stop it with ` +
|
|
1146
|
+
`pharo_launcher_image_stop before deleting it.`);
|
|
1147
|
+
}
|
|
1148
|
+
const scope = resolveScope(this.options);
|
|
1149
|
+
const projectConfig = loadProjectConfig(scope.projectRoot);
|
|
1150
|
+
const imageConfig = findImageConfig(projectConfig, imageId);
|
|
1151
|
+
if (!imageConfig) {
|
|
1152
|
+
throw new ScopedPharoLauncherError(`Image ${imageId} is not declared in this project`);
|
|
1153
|
+
}
|
|
1154
|
+
const statePath = statePathForScope(scope, projectConfig);
|
|
1155
|
+
const now = this.options.now?.() ?? new Date();
|
|
1156
|
+
this.imageLeaseForMutation(scope, projectConfig, imageId, now);
|
|
1157
|
+
// Ask the profile what it holds rather than believing the record: a record
|
|
1158
|
+
// can name an image the launcher never made, and deleting that fails.
|
|
1159
|
+
const launcherImage = launcherHoldsImage(scope, projectConfig, imageConfig.imageName);
|
|
1160
|
+
if (launcherImage) {
|
|
1161
|
+
await this.deleteLauncherImage(scope, projectConfig, imageConfig.imageName);
|
|
1162
|
+
}
|
|
1163
|
+
const currentState = loadProjectState(statePath);
|
|
1164
|
+
const runtimeRecord = Boolean(currentState?.images.some((image) => image.id === imageId));
|
|
1165
|
+
if (currentState && runtimeRecord) {
|
|
1166
|
+
saveProjectState(statePath, projectStateWithoutImage(currentState, imageId, now));
|
|
1167
|
+
}
|
|
1168
|
+
const after = await this.imageInfo(imageId);
|
|
1169
|
+
return {
|
|
1170
|
+
scope: after.scope,
|
|
1171
|
+
launcherProfile: after.launcherProfile,
|
|
1172
|
+
deleted: { imageId, launcherImage, runtimeRecord },
|
|
1173
|
+
};
|
|
1174
|
+
}
|
|
1102
1175
|
}
|
|
1103
1176
|
export const scopedPharoLauncherTools = [
|
|
1104
1177
|
{
|
|
@@ -1155,12 +1228,16 @@ export const scopedPharoLauncherTools = [
|
|
|
1155
1228
|
},
|
|
1156
1229
|
{
|
|
1157
1230
|
name: "pharo_launcher_image_stop",
|
|
1158
|
-
description: "Stop one workspace-scoped image
|
|
1231
|
+
description: "Stop the process PLexus started for one workspace-scoped image. Stops only that process, never another VM on the same image.",
|
|
1159
1232
|
inputSchema: objectSchema({
|
|
1160
1233
|
imageId: stringSchema,
|
|
1161
|
-
confirm: { type: "boolean" },
|
|
1162
1234
|
detail: toolResultDetailSchema,
|
|
1163
|
-
}, ["imageId"
|
|
1235
|
+
}, ["imageId"]),
|
|
1236
|
+
},
|
|
1237
|
+
{
|
|
1238
|
+
name: "pharo_launcher_image_delete",
|
|
1239
|
+
description: "Delete one workspace-scoped image and its runtime record. Refused while the image is running.",
|
|
1240
|
+
inputSchema: objectSchema({ imageId: stringSchema, detail: toolResultDetailSchema }, ["imageId"]),
|
|
1164
1241
|
},
|
|
1165
1242
|
{
|
|
1166
1243
|
name: "pharo_launcher_image_reset",
|
|
@@ -1187,15 +1264,26 @@ export function createScopedPharoLauncherServer(options) {
|
|
|
1187
1264
|
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
1188
1265
|
tools: [...scopedPharoLauncherTools],
|
|
1189
1266
|
}));
|
|
1190
|
-
server.setRequestHandler(CallToolRequestSchema, async (request) =>
|
|
1191
|
-
|
|
1267
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => callScopedPharoLauncherTool(facade, request.params.name, request.params.arguments));
|
|
1268
|
+
return server;
|
|
1269
|
+
}
|
|
1270
|
+
/** Shared so the composed `plexus mcp` server dispatches identically. */
|
|
1271
|
+
/**
|
|
1272
|
+
* One tool call is one operation, which is where a launcher client is opened
|
|
1273
|
+
* and closed. A call that reaches the launcher several times — a reset reports
|
|
1274
|
+
* a listing after each of its four steps — opens one, not four.
|
|
1275
|
+
*/
|
|
1276
|
+
export async function callScopedPharoLauncherTool(facade, name, argumentsValue) {
|
|
1277
|
+
return await facade.runOperation(async () => {
|
|
1278
|
+
const input = argumentsValue ?? {};
|
|
1192
1279
|
const detail = toolResultDetailFromArguments(input);
|
|
1280
|
+
const request = { params: { name } };
|
|
1193
1281
|
try {
|
|
1194
|
-
switch (
|
|
1282
|
+
switch (name) {
|
|
1195
1283
|
case "pharo_launcher_image_list":
|
|
1196
|
-
return textResult(facade.listImages(), false, detail);
|
|
1284
|
+
return textResult(await facade.listImages(), false, detail);
|
|
1197
1285
|
case "pharo_launcher_image_info":
|
|
1198
|
-
return textResult(facade.imageInfo(requireString(input, "imageId")), false, detail);
|
|
1286
|
+
return textResult(await facade.imageInfo(requireString(input, "imageId")), false, detail);
|
|
1199
1287
|
case "pharo_launcher_template_list":
|
|
1200
1288
|
return textResult(await facade.listTemplates(optionalString(input, "templateCategory")), false, detail);
|
|
1201
1289
|
case "pharo_launcher_template_category_list":
|
|
@@ -1211,8 +1299,9 @@ export function createScopedPharoLauncherServer(options) {
|
|
|
1211
1299
|
case "pharo_launcher_image_hide":
|
|
1212
1300
|
return textResult(await facade.hideImage(requireString(input, "imageId")), false, detail);
|
|
1213
1301
|
case "pharo_launcher_image_stop":
|
|
1214
|
-
requireConfirm(input);
|
|
1215
1302
|
return textResult(await facade.stopImage(requireString(input, "imageId")), false, detail);
|
|
1303
|
+
case "pharo_launcher_image_delete":
|
|
1304
|
+
return textResult(await facade.deleteImage(requireString(input, "imageId")), false, detail);
|
|
1216
1305
|
case "pharo_launcher_image_reset":
|
|
1217
1306
|
requireConfirm(input);
|
|
1218
1307
|
return textResult(await facade.resetImage(requireString(input, "imageId"), {
|
|
@@ -1227,7 +1316,6 @@ export function createScopedPharoLauncherServer(options) {
|
|
|
1227
1316
|
return textResult(scopedErrorPayload(error), true, detail);
|
|
1228
1317
|
}
|
|
1229
1318
|
});
|
|
1230
|
-
return server;
|
|
1231
1319
|
}
|
|
1232
1320
|
export async function startScopedPharoLauncherServer(options) {
|
|
1233
1321
|
const server = createScopedPharoLauncherServer(options);
|