@evref-bl/plexus 0.0.0-stage → 0.1.0-alpha.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 +11 -2
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +298 -0
- package/dist/cli.js.map +1 -0
- package/dist/config/config.d.ts +29 -0
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/config.js +111 -0
- package/dist/config/config.js.map +1 -0
- package/dist/config/plexusHome.d.ts +17 -0
- package/dist/config/plexusHome.d.ts.map +1 -0
- package/dist/config/plexusHome.js +30 -0
- package/dist/config/plexusHome.js.map +1 -0
- package/dist/config/projectConfig.d.ts +233 -0
- package/dist/config/projectConfig.d.ts.map +1 -0
- package/dist/config/projectConfig.js +1181 -0
- package/dist/config/projectConfig.js.map +1 -0
- package/dist/config/target.d.ts +19 -0
- package/dist/config/target.d.ts.map +1 -0
- package/dist/config/target.js +2 -0
- package/dist/config/target.js.map +1 -0
- package/dist/config.d.ts +29 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +111 -0
- package/dist/config.js.map +1 -0
- package/dist/gateway/projectGateway.d.ts +80 -0
- package/dist/gateway/projectGateway.d.ts.map +1 -0
- package/dist/gateway/projectGateway.js +435 -0
- package/dist/gateway/projectGateway.js.map +1 -0
- package/dist/gateway/projectImageMcpEndpoint.d.ts +24 -0
- package/dist/gateway/projectImageMcpEndpoint.d.ts.map +1 -0
- package/dist/gateway/projectImageMcpEndpoint.js +79 -0
- package/dist/gateway/projectImageMcpEndpoint.js.map +1 -0
- package/dist/homeImageCache.d.ts +264 -0
- package/dist/homeImageCache.d.ts.map +1 -0
- package/dist/homeImageCache.js +930 -0
- package/dist/homeImageCache.js.map +1 -0
- package/dist/imagePortClaims.d.ts +41 -0
- package/dist/imagePortClaims.d.ts.map +1 -0
- package/dist/imagePortClaims.js +337 -0
- package/dist/imagePortClaims.js.map +1 -0
- package/dist/imageRescue.d.ts +155 -0
- package/dist/imageRescue.d.ts.map +1 -0
- package/dist/imageRescue.js +847 -0
- package/dist/imageRescue.js.map +1 -0
- package/dist/images/homeImageCache.d.ts +264 -0
- package/dist/images/homeImageCache.d.ts.map +1 -0
- package/dist/images/homeImageCache.js +930 -0
- package/dist/images/homeImageCache.js.map +1 -0
- package/dist/images/imageRescue.d.ts +155 -0
- package/dist/images/imageRescue.d.ts.map +1 -0
- package/dist/images/imageRescue.js +847 -0
- package/dist/images/imageRescue.js.map +1 -0
- package/dist/images/preparedImageCache.d.ts +90 -0
- package/dist/images/preparedImageCache.d.ts.map +1 -0
- package/dist/images/preparedImageCache.js +237 -0
- package/dist/images/preparedImageCache.js.map +1 -0
- package/dist/images/scopedTemplateCatalog.d.ts +32 -0
- package/dist/images/scopedTemplateCatalog.d.ts.map +1 -0
- package/dist/images/scopedTemplateCatalog.js +316 -0
- package/dist/images/scopedTemplateCatalog.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/launcher/pharoLauncherMcpClient.d.ts +17 -0
- package/dist/launcher/pharoLauncherMcpClient.d.ts.map +1 -0
- package/dist/launcher/pharoLauncherMcpClient.js +78 -0
- package/dist/launcher/pharoLauncherMcpClient.js.map +1 -0
- package/dist/launcher/pharoLauncherProfile.d.ts +31 -0
- package/dist/launcher/pharoLauncherProfile.d.ts.map +1 -0
- package/dist/launcher/pharoLauncherProfile.js +122 -0
- package/dist/launcher/pharoLauncherProfile.js.map +1 -0
- package/dist/launcher/scopedPharoLauncherServer.d.ts +247 -0
- package/dist/launcher/scopedPharoLauncherServer.d.ts.map +1 -0
- package/dist/launcher/scopedPharoLauncherServer.js +1112 -0
- package/dist/launcher/scopedPharoLauncherServer.js.map +1 -0
- package/dist/lifecycle/projectCleanup.d.ts +59 -0
- package/dist/lifecycle/projectCleanup.d.ts.map +1 -0
- package/dist/lifecycle/projectCleanup.js +483 -0
- package/dist/lifecycle/projectCleanup.js.map +1 -0
- package/dist/lifecycle/projectClose.d.ts +35 -0
- package/dist/lifecycle/projectClose.d.ts.map +1 -0
- package/dist/lifecycle/projectClose.js +273 -0
- package/dist/lifecycle/projectClose.js.map +1 -0
- package/dist/lifecycle/projectLifecycle.d.ts +429 -0
- package/dist/lifecycle/projectLifecycle.d.ts.map +1 -0
- package/dist/lifecycle/projectLifecycle.js +2150 -0
- package/dist/lifecycle/projectLifecycle.js.map +1 -0
- package/dist/lifecycle/projectOpen.d.ts +68 -0
- package/dist/lifecycle/projectOpen.d.ts.map +1 -0
- package/dist/lifecycle/projectOpen.js +1472 -0
- package/dist/lifecycle/projectOpen.js.map +1 -0
- package/dist/mcp/pharoMcpHealth.d.ts +26 -0
- package/dist/mcp/pharoMcpHealth.d.ts.map +1 -0
- package/dist/mcp/pharoMcpHealth.js +97 -0
- package/dist/mcp/pharoMcpHealth.js.map +1 -0
- package/dist/mcp/server.d.ts +86 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +357 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/pathStyle.d.ts +11 -0
- package/dist/pathStyle.d.ts.map +1 -0
- package/dist/pathStyle.js +61 -0
- package/dist/pathStyle.js.map +1 -0
- package/dist/pharoLauncherMcpClient.d.ts +17 -0
- package/dist/pharoLauncherMcpClient.d.ts.map +1 -0
- package/dist/pharoLauncherMcpClient.js +78 -0
- package/dist/pharoLauncherMcpClient.js.map +1 -0
- package/dist/pharoLauncherProfile.d.ts +31 -0
- package/dist/pharoLauncherProfile.d.ts.map +1 -0
- package/dist/pharoLauncherProfile.js +122 -0
- package/dist/pharoLauncherProfile.js.map +1 -0
- package/dist/pharoMcpHealth.d.ts +26 -0
- package/dist/pharoMcpHealth.d.ts.map +1 -0
- package/dist/pharoMcpHealth.js +97 -0
- package/dist/pharoMcpHealth.js.map +1 -0
- package/dist/plexusHome.d.ts +17 -0
- package/dist/plexusHome.d.ts.map +1 -0
- package/dist/plexusHome.js +30 -0
- package/dist/plexusHome.js.map +1 -0
- package/dist/portClaims.d.ts +116 -0
- package/dist/portClaims.d.ts.map +1 -0
- package/dist/portClaims.js +393 -0
- package/dist/portClaims.js.map +1 -0
- package/dist/ports/imagePortClaims.d.ts +41 -0
- package/dist/ports/imagePortClaims.d.ts.map +1 -0
- package/dist/ports/imagePortClaims.js +337 -0
- package/dist/ports/imagePortClaims.js.map +1 -0
- package/dist/ports/portClaims.d.ts +116 -0
- package/dist/ports/portClaims.d.ts.map +1 -0
- package/dist/ports/portClaims.js +393 -0
- package/dist/ports/portClaims.js.map +1 -0
- package/dist/preparedImageCache.d.ts +90 -0
- package/dist/preparedImageCache.d.ts.map +1 -0
- package/dist/preparedImageCache.js +237 -0
- package/dist/preparedImageCache.js.map +1 -0
- package/dist/projectCleanup.d.ts +59 -0
- package/dist/projectCleanup.d.ts.map +1 -0
- package/dist/projectCleanup.js +483 -0
- package/dist/projectCleanup.js.map +1 -0
- package/dist/projectClose.d.ts +35 -0
- package/dist/projectClose.d.ts.map +1 -0
- package/dist/projectClose.js +273 -0
- package/dist/projectClose.js.map +1 -0
- package/dist/projectConfig.d.ts +233 -0
- package/dist/projectConfig.d.ts.map +1 -0
- package/dist/projectConfig.js +1181 -0
- package/dist/projectConfig.js.map +1 -0
- package/dist/projectGateway.d.ts +80 -0
- package/dist/projectGateway.d.ts.map +1 -0
- package/dist/projectGateway.js +435 -0
- package/dist/projectGateway.js.map +1 -0
- package/dist/projectImageMcpEndpoint.d.ts +24 -0
- package/dist/projectImageMcpEndpoint.d.ts.map +1 -0
- package/dist/projectImageMcpEndpoint.js +79 -0
- package/dist/projectImageMcpEndpoint.js.map +1 -0
- package/dist/projectLifecycle.d.ts +428 -0
- package/dist/projectLifecycle.d.ts.map +1 -0
- package/dist/projectLifecycle.js +2147 -0
- package/dist/projectLifecycle.js.map +1 -0
- package/dist/projectOpen.d.ts +68 -0
- package/dist/projectOpen.d.ts.map +1 -0
- package/dist/projectOpen.js +1472 -0
- package/dist/projectOpen.js.map +1 -0
- package/dist/projectRepositoryWorkspace.d.ts +74 -0
- package/dist/projectRepositoryWorkspace.d.ts.map +1 -0
- package/dist/projectRepositoryWorkspace.js +553 -0
- package/dist/projectRepositoryWorkspace.js.map +1 -0
- package/dist/projectStartupScript.d.ts +74 -0
- package/dist/projectStartupScript.d.ts.map +1 -0
- package/dist/projectStartupScript.js +748 -0
- package/dist/projectStartupScript.js.map +1 -0
- package/dist/projectState.d.ts +315 -0
- package/dist/projectState.d.ts.map +1 -0
- package/dist/projectState.js +399 -0
- package/dist/projectState.js.map +1 -0
- package/dist/runtimeIdentity.d.ts +15 -0
- package/dist/runtimeIdentity.d.ts.map +1 -0
- package/dist/runtimeIdentity.js +25 -0
- package/dist/runtimeIdentity.js.map +1 -0
- package/dist/scopedPharoLauncherServer.d.ts +247 -0
- package/dist/scopedPharoLauncherServer.d.ts.map +1 -0
- package/dist/scopedPharoLauncherServer.js +1112 -0
- package/dist/scopedPharoLauncherServer.js.map +1 -0
- package/dist/scopedProjectContext.d.ts +169 -0
- package/dist/scopedProjectContext.d.ts.map +1 -0
- package/dist/scopedProjectContext.js +358 -0
- package/dist/scopedProjectContext.js.map +1 -0
- package/dist/scopedTemplateCatalog.d.ts +32 -0
- package/dist/scopedTemplateCatalog.d.ts.map +1 -0
- package/dist/scopedTemplateCatalog.js +316 -0
- package/dist/scopedTemplateCatalog.js.map +1 -0
- package/dist/server.d.ts +86 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +357 -0
- package/dist/server.js.map +1 -0
- package/dist/support/pathStyle.d.ts +11 -0
- package/dist/support/pathStyle.d.ts.map +1 -0
- package/dist/support/pathStyle.js +61 -0
- package/dist/support/pathStyle.js.map +1 -0
- package/dist/support/runtimeIdentity.d.ts +15 -0
- package/dist/support/runtimeIdentity.d.ts.map +1 -0
- package/dist/support/runtimeIdentity.js +40 -0
- package/dist/support/runtimeIdentity.js.map +1 -0
- package/dist/support/toolResultFormatting.d.ts +8 -0
- package/dist/support/toolResultFormatting.d.ts.map +1 -0
- package/dist/support/toolResultFormatting.js +81 -0
- package/dist/support/toolResultFormatting.js.map +1 -0
- package/dist/target.d.ts +19 -0
- package/dist/target.d.ts.map +1 -0
- package/dist/target.js +2 -0
- package/dist/target.js.map +1 -0
- package/dist/toolResultFormatting.d.ts +8 -0
- package/dist/toolResultFormatting.d.ts.map +1 -0
- package/dist/toolResultFormatting.js +81 -0
- package/dist/toolResultFormatting.js.map +1 -0
- package/dist/workspace/projectRepositoryWorkspace.d.ts +74 -0
- package/dist/workspace/projectRepositoryWorkspace.d.ts.map +1 -0
- package/dist/workspace/projectRepositoryWorkspace.js +553 -0
- package/dist/workspace/projectRepositoryWorkspace.js.map +1 -0
- package/dist/workspace/projectStartupScript.d.ts +74 -0
- package/dist/workspace/projectStartupScript.d.ts.map +1 -0
- package/dist/workspace/projectStartupScript.js +748 -0
- package/dist/workspace/projectStartupScript.js.map +1 -0
- package/dist/workspace/projectState.d.ts +320 -0
- package/dist/workspace/projectState.d.ts.map +1 -0
- package/dist/workspace/projectState.js +399 -0
- package/dist/workspace/projectState.js.map +1 -0
- package/dist/workspace/scopedProjectContext.d.ts +169 -0
- package/dist/workspace/scopedProjectContext.d.ts.map +1 -0
- package/dist/workspace/scopedProjectContext.js +358 -0
- package/dist/workspace/scopedProjectContext.js.map +1 -0
- package/dist/workspace/workspaceMcpConfig.d.ts +51 -0
- package/dist/workspace/workspaceMcpConfig.d.ts.map +1 -0
- package/dist/workspace/workspaceMcpConfig.js +98 -0
- package/dist/workspace/workspaceMcpConfig.js.map +1 -0
- package/dist/workspaceMcpConfig.d.ts +51 -0
- package/dist/workspaceMcpConfig.d.ts.map +1 -0
- package/dist/workspaceMcpConfig.js +98 -0
- package/dist/workspaceMcpConfig.js.map +1 -0
- package/package.json +39 -4
|
@@ -0,0 +1,1112 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
3
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
+
import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
5
|
+
import { loadProjectConfig, projectImageCreateCleanupPolicy, projectImageDisplayMode, projectConfigId, resolveProjectRuntimePolicy, } from "../config/projectConfig.js";
|
|
6
|
+
import { closeProject, ProjectCloseError, } from "../lifecycle/projectClose.js";
|
|
7
|
+
import { HttpGatewayRouteRegistry, } from "../lifecycle/projectLifecycle.js";
|
|
8
|
+
import { openProject } from "../lifecycle/projectOpen.js";
|
|
9
|
+
import { formatToolResultPayload, toolResultDetailFromArguments, toolResultDetailSchema, } from "../support/toolResultFormatting.js";
|
|
10
|
+
import { homeImageCacheNetworkPolicy, materializeProjectImageFromHomeCache, } from "../images/homeImageCache.js";
|
|
11
|
+
import { createStdioPharoLauncherMcpClient, PharoLauncherMcpToolError, } from "./pharoLauncherMcpClient.js";
|
|
12
|
+
import { describePharoLauncherMcpProfile, pharoLauncherMcpProfileEnvironment, } from "./pharoLauncherProfile.js";
|
|
13
|
+
import { collectReservedProjectPortOwners, createProjectState, defaultTargetId, defaultWorkspaceId, loadProjectState, projectStatePathForConfig, projectStateRootForConfig, renderProjectImageName, runtimeStatusForImages, sanitizeRuntimeId, saveProjectState, } from "../workspace/projectState.js";
|
|
14
|
+
import { projectScriptsDirectoryPath } from "../workspace/projectStartupScript.js";
|
|
15
|
+
import { dirnamePathLike, joinPathLike } from "../support/pathStyle.js";
|
|
16
|
+
import { prepareScopedTemplateCatalog } from "../images/scopedTemplateCatalog.js";
|
|
17
|
+
const stringSchema = { type: "string", minLength: 1 };
|
|
18
|
+
const displayModeSchema = {
|
|
19
|
+
type: "string",
|
|
20
|
+
enum: ["headless", "interactive"],
|
|
21
|
+
};
|
|
22
|
+
const displayModeSnapshotTimeoutMs = 60_000;
|
|
23
|
+
const displayModeSnapshotPollIntervalMs = 100;
|
|
24
|
+
function objectSchema(properties, required = []) {
|
|
25
|
+
return {
|
|
26
|
+
type: "object",
|
|
27
|
+
properties,
|
|
28
|
+
required,
|
|
29
|
+
additionalProperties: false,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export class ScopedPharoLauncherError extends Error {
|
|
33
|
+
details;
|
|
34
|
+
constructor(message, details) {
|
|
35
|
+
super(message);
|
|
36
|
+
this.details = details;
|
|
37
|
+
this.name = "ScopedPharoLauncherError";
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function textResult(value, isError = false, detail = "summary") {
|
|
41
|
+
return {
|
|
42
|
+
content: [
|
|
43
|
+
{
|
|
44
|
+
type: "text",
|
|
45
|
+
text: JSON.stringify(formatToolResultPayload(value, detail), null, 2),
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
...(isError ? { isError } : {}),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function scopedErrorPayload(error) {
|
|
52
|
+
const payload = {
|
|
53
|
+
ok: false,
|
|
54
|
+
error: error instanceof Error ? error.message : String(error),
|
|
55
|
+
};
|
|
56
|
+
if (error instanceof PharoLauncherMcpToolError) {
|
|
57
|
+
return {
|
|
58
|
+
...payload,
|
|
59
|
+
cause: {
|
|
60
|
+
toolName: error.toolName,
|
|
61
|
+
result: error.result,
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
if (error instanceof ScopedPharoLauncherError &&
|
|
66
|
+
error.details !== undefined) {
|
|
67
|
+
return {
|
|
68
|
+
...payload,
|
|
69
|
+
cause: error.details,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
return payload;
|
|
73
|
+
}
|
|
74
|
+
function objectInput(input) {
|
|
75
|
+
if (!input || typeof input !== "object" || Array.isArray(input)) {
|
|
76
|
+
return {};
|
|
77
|
+
}
|
|
78
|
+
return input;
|
|
79
|
+
}
|
|
80
|
+
function requireString(input, key) {
|
|
81
|
+
const value = input[key];
|
|
82
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
83
|
+
throw new ScopedPharoLauncherError(`${key} is required`);
|
|
84
|
+
}
|
|
85
|
+
return value;
|
|
86
|
+
}
|
|
87
|
+
function optionalString(input, key) {
|
|
88
|
+
const value = input[key];
|
|
89
|
+
if (value === undefined) {
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
93
|
+
throw new ScopedPharoLauncherError(`${key} must be a non-empty string`);
|
|
94
|
+
}
|
|
95
|
+
return value;
|
|
96
|
+
}
|
|
97
|
+
function optionalBoolean(input, key) {
|
|
98
|
+
const value = input[key];
|
|
99
|
+
if (value === undefined) {
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
if (typeof value !== "boolean") {
|
|
103
|
+
throw new ScopedPharoLauncherError(`${key} must be a boolean`);
|
|
104
|
+
}
|
|
105
|
+
return value;
|
|
106
|
+
}
|
|
107
|
+
function optionalDisplayMode(input, key) {
|
|
108
|
+
const value = input[key];
|
|
109
|
+
if (value === undefined) {
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
if (value === "headless" || value === "interactive") {
|
|
113
|
+
return value;
|
|
114
|
+
}
|
|
115
|
+
throw new ScopedPharoLauncherError(`${key} must be headless or interactive`);
|
|
116
|
+
}
|
|
117
|
+
function requireConfirm(input) {
|
|
118
|
+
if (input.confirm !== true) {
|
|
119
|
+
throw new ScopedPharoLauncherError("confirm: true is required");
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
const leaseOwnerKinds = new Set([
|
|
123
|
+
"target",
|
|
124
|
+
"workspace",
|
|
125
|
+
"thread",
|
|
126
|
+
"session",
|
|
127
|
+
"workItem",
|
|
128
|
+
"agent",
|
|
129
|
+
"human",
|
|
130
|
+
"unknown",
|
|
131
|
+
]);
|
|
132
|
+
function nonEmptyEnv(value) {
|
|
133
|
+
const trimmed = value?.trim();
|
|
134
|
+
return trimmed && trimmed.length > 0 ? trimmed : undefined;
|
|
135
|
+
}
|
|
136
|
+
function leaseOwnerKindFromText(value) {
|
|
137
|
+
const normalized = value === "work-item" ? "workItem" : value;
|
|
138
|
+
if (!normalized) {
|
|
139
|
+
return undefined;
|
|
140
|
+
}
|
|
141
|
+
if (!leaseOwnerKinds.has(normalized)) {
|
|
142
|
+
throw new ScopedPharoLauncherError(`PLEXUS_IMAGE_LEASE_OWNER_KIND must be one of ${[...leaseOwnerKinds].join(", ")}`);
|
|
143
|
+
}
|
|
144
|
+
return normalized;
|
|
145
|
+
}
|
|
146
|
+
function leaseTtlMsFromText(value) {
|
|
147
|
+
if (!value) {
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
150
|
+
const ttlMs = Number(value);
|
|
151
|
+
if (!Number.isInteger(ttlMs) || ttlMs <= 0) {
|
|
152
|
+
throw new ScopedPharoLauncherError("PLEXUS_IMAGE_LEASE_TTL_MS must be a positive integer");
|
|
153
|
+
}
|
|
154
|
+
return ttlMs;
|
|
155
|
+
}
|
|
156
|
+
export function scopedImageLeaseOptionsFromEnvironment(env) {
|
|
157
|
+
const ownerId = nonEmptyEnv(env.PLEXUS_IMAGE_LEASE_OWNER_ID);
|
|
158
|
+
const ownerKind = leaseOwnerKindFromText(nonEmptyEnv(env.PLEXUS_IMAGE_LEASE_OWNER_KIND));
|
|
159
|
+
const purpose = nonEmptyEnv(env.PLEXUS_IMAGE_LEASE_PURPOSE);
|
|
160
|
+
const repositoryPath = nonEmptyEnv(env.PLEXUS_IMAGE_LEASE_REPOSITORY_PATH);
|
|
161
|
+
const branch = nonEmptyEnv(env.PLEXUS_IMAGE_LEASE_BRANCH);
|
|
162
|
+
const ttlMs = leaseTtlMsFromText(nonEmptyEnv(env.PLEXUS_IMAGE_LEASE_TTL_MS));
|
|
163
|
+
const cleanupCommand = nonEmptyEnv(env.PLEXUS_IMAGE_LEASE_CLEANUP_COMMAND);
|
|
164
|
+
if (!ownerId &&
|
|
165
|
+
!ownerKind &&
|
|
166
|
+
!purpose &&
|
|
167
|
+
!repositoryPath &&
|
|
168
|
+
!branch &&
|
|
169
|
+
ttlMs === undefined &&
|
|
170
|
+
!cleanupCommand) {
|
|
171
|
+
return undefined;
|
|
172
|
+
}
|
|
173
|
+
return {
|
|
174
|
+
...(ownerId ? { ownerId } : {}),
|
|
175
|
+
...(ownerKind ? { ownerKind } : {}),
|
|
176
|
+
...(purpose ? { purpose } : {}),
|
|
177
|
+
...(repositoryPath ? { repositoryPath } : {}),
|
|
178
|
+
...(branch ? { branch } : {}),
|
|
179
|
+
...(ttlMs !== undefined ? { ttlMs } : {}),
|
|
180
|
+
...(cleanupCommand ? { cleanupCommand } : {}),
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
function assertLauncherOk(result, toolName) {
|
|
184
|
+
if (result && result.ok === false) {
|
|
185
|
+
throw new ScopedPharoLauncherError(`${toolName} returned ok: false`, {
|
|
186
|
+
toolName,
|
|
187
|
+
result,
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
async function ensureScopedTemplateCatalogReady(options) {
|
|
192
|
+
const runtime = resolveProjectRuntimePolicy(options.projectConfig);
|
|
193
|
+
const launcherProfile = describePharoLauncherMcpProfile({
|
|
194
|
+
projectRoot: options.scope.projectRoot,
|
|
195
|
+
config: options.projectConfig,
|
|
196
|
+
workspaceId: options.scope.workspaceId,
|
|
197
|
+
targetId: options.scope.targetId,
|
|
198
|
+
stateRoot: options.scope.stateRoot,
|
|
199
|
+
});
|
|
200
|
+
const bootstrap = await prepareScopedTemplateCatalog({
|
|
201
|
+
destinationDirectory: launcherProfile.templateSourcesDir,
|
|
202
|
+
policy: runtime.launcherProfile.templateCatalog,
|
|
203
|
+
networkPolicy: homeImageCacheNetworkPolicy(options.projectConfig),
|
|
204
|
+
fetch: options.fetch,
|
|
205
|
+
});
|
|
206
|
+
if (!bootstrap.ok) {
|
|
207
|
+
throw new ScopedPharoLauncherError(bootstrap.message, bootstrap.details);
|
|
208
|
+
}
|
|
209
|
+
if (!bootstrap.refreshTemplateCatalog) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
const result = await options.client.callTool("pharo_launcher_template_update", {});
|
|
213
|
+
assertLauncherOk(result, "pharo_launcher_template_update");
|
|
214
|
+
}
|
|
215
|
+
function scopedMutationApproval(approval, operation) {
|
|
216
|
+
return approval ?? { approved: true, runnerId: operation };
|
|
217
|
+
}
|
|
218
|
+
function resolveScope(options) {
|
|
219
|
+
const projectConfig = loadProjectConfig(options.projectRoot);
|
|
220
|
+
const workspaceId = options.workspaceId ?? defaultWorkspaceId(options.projectRoot);
|
|
221
|
+
const stateRoot = projectStateRootForConfig(projectConfig, options.stateRoot);
|
|
222
|
+
return {
|
|
223
|
+
projectRoot: options.projectRoot,
|
|
224
|
+
projectId: projectConfigId(projectConfig),
|
|
225
|
+
projectName: projectConfig.name,
|
|
226
|
+
workspaceId,
|
|
227
|
+
targetId: options.targetId ?? defaultTargetId(projectConfigId(projectConfig), workspaceId),
|
|
228
|
+
...(stateRoot ? { stateRoot } : {}),
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
function scopeSummary(scope) {
|
|
232
|
+
return {
|
|
233
|
+
projectId: scope.projectId,
|
|
234
|
+
projectName: scope.projectName,
|
|
235
|
+
workspaceId: scope.workspaceId,
|
|
236
|
+
targetId: scope.targetId,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
function launcherProfileSummary(profile) {
|
|
240
|
+
return {
|
|
241
|
+
ownership: profile.ownership,
|
|
242
|
+
mode: profile.mode,
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
function imageSummary(imageConfig, imageState) {
|
|
246
|
+
const defaultDisplayMode = projectImageDisplayMode(imageConfig);
|
|
247
|
+
const displayMode = imageState?.displayMode ?? defaultDisplayMode;
|
|
248
|
+
return {
|
|
249
|
+
imageId: imageConfig.id,
|
|
250
|
+
active: imageConfig.active,
|
|
251
|
+
status: imageState?.status ?? "declared",
|
|
252
|
+
displayMode,
|
|
253
|
+
displayModes: {
|
|
254
|
+
default: defaultDisplayMode,
|
|
255
|
+
...(imageState?.displayMode ? { current: imageState.displayMode } : {}),
|
|
256
|
+
start: defaultDisplayMode,
|
|
257
|
+
interactiveOpen: "interactive",
|
|
258
|
+
show: "interactive",
|
|
259
|
+
hide: "headless",
|
|
260
|
+
},
|
|
261
|
+
...(imageState?.pharoMcpContract
|
|
262
|
+
? { pharoMcpContract: imageState.pharoMcpContract }
|
|
263
|
+
: {}),
|
|
264
|
+
...(imageState?.lease ? { lease: imageState.lease } : {}),
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
function statePathForScope(scope, projectConfig = loadProjectConfig(scope.projectRoot)) {
|
|
268
|
+
return projectStatePathForConfig({
|
|
269
|
+
projectRoot: scope.projectRoot,
|
|
270
|
+
config: projectConfig,
|
|
271
|
+
workspaceId: scope.workspaceId,
|
|
272
|
+
stateRoot: scope.stateRoot,
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
function leaseOwnerDescription(lease) {
|
|
276
|
+
return `${lease.ownerKind} ${lease.ownerId}`;
|
|
277
|
+
}
|
|
278
|
+
function leaseExpired(lease, now) {
|
|
279
|
+
if (!lease.expiresAt) {
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
const expiresAt = Date.parse(lease.expiresAt);
|
|
283
|
+
return Number.isFinite(expiresAt) && expiresAt <= now.getTime();
|
|
284
|
+
}
|
|
285
|
+
function sameLeaseOwner(left, right) {
|
|
286
|
+
return left.ownerKind === right.ownerKind && left.ownerId === right.ownerId;
|
|
287
|
+
}
|
|
288
|
+
function imageLeaseForMutation(scope, options, now, existingLease, mode = "mutable") {
|
|
289
|
+
const ownerId = options?.ownerId ?? scope.targetId;
|
|
290
|
+
const ownerKind = options?.ownerKind ?? "target";
|
|
291
|
+
const retainedLease = existingLease?.ownerId === ownerId && existingLease.ownerKind === ownerKind
|
|
292
|
+
? existingLease
|
|
293
|
+
: undefined;
|
|
294
|
+
const createdAt = retainedLease?.createdAt ?? now.toISOString();
|
|
295
|
+
const expiresAt = options?.ttlMs !== undefined
|
|
296
|
+
? new Date(now.getTime() + options.ttlMs).toISOString()
|
|
297
|
+
: retainedLease?.expiresAt;
|
|
298
|
+
return {
|
|
299
|
+
ownerId,
|
|
300
|
+
ownerKind,
|
|
301
|
+
mode,
|
|
302
|
+
purpose: options?.purpose ??
|
|
303
|
+
retainedLease?.purpose ??
|
|
304
|
+
"Scoped Pharo image lifecycle",
|
|
305
|
+
createdAt,
|
|
306
|
+
heartbeatAt: now.toISOString(),
|
|
307
|
+
...(expiresAt ? { expiresAt } : {}),
|
|
308
|
+
...(options?.repositoryPath ?? retainedLease?.repositoryPath
|
|
309
|
+
? {
|
|
310
|
+
repositoryPath: options?.repositoryPath ?? retainedLease?.repositoryPath,
|
|
311
|
+
}
|
|
312
|
+
: {}),
|
|
313
|
+
...(options?.branch ?? retainedLease?.branch
|
|
314
|
+
? { branch: options?.branch ?? retainedLease?.branch }
|
|
315
|
+
: {}),
|
|
316
|
+
...(options?.cleanupCommand ?? retainedLease?.cleanupCommand
|
|
317
|
+
? {
|
|
318
|
+
cleanupCommand: options?.cleanupCommand ?? retainedLease?.cleanupCommand,
|
|
319
|
+
}
|
|
320
|
+
: {}),
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
function assertImageLeaseAllowsMutation(imageId, existingLease, requestedLease, now) {
|
|
324
|
+
if (!existingLease ||
|
|
325
|
+
leaseExpired(existingLease, now) ||
|
|
326
|
+
sameLeaseOwner(existingLease, requestedLease)) {
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
const expiry = existingLease.expiresAt
|
|
330
|
+
? ` until ${existingLease.expiresAt}`
|
|
331
|
+
: "";
|
|
332
|
+
throw new ScopedPharoLauncherError(`Image ${imageId} is leased to ${leaseOwnerDescription(existingLease)} for ${existingLease.purpose}${expiry}; mutation requires ${leaseOwnerDescription(requestedLease)}`);
|
|
333
|
+
}
|
|
334
|
+
function stateWithImageLease(state, imageId, lease, updatedAt) {
|
|
335
|
+
return {
|
|
336
|
+
...state,
|
|
337
|
+
images: state.images.map((image) => image.id === imageId ? { ...image, lease } : image),
|
|
338
|
+
updatedAt: updatedAt.toISOString(),
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
function findImageConfig(projectConfig, imageId) {
|
|
342
|
+
const imageConfig = projectConfig.images.find((image) => image.id === imageId);
|
|
343
|
+
if (!imageConfig) {
|
|
344
|
+
throw new ScopedPharoLauncherError(`Image ${imageId} is not declared in this PLexus workspace`);
|
|
345
|
+
}
|
|
346
|
+
return imageConfig;
|
|
347
|
+
}
|
|
348
|
+
function renderedImageName(scope, imageConfig) {
|
|
349
|
+
return renderProjectImageName(imageConfig.imageName, {
|
|
350
|
+
projectId: scope.projectId,
|
|
351
|
+
projectName: scope.projectName,
|
|
352
|
+
workspaceId: scope.workspaceId,
|
|
353
|
+
targetId: scope.targetId,
|
|
354
|
+
imageId: imageConfig.id,
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
function imageCreationState(imageConfig) {
|
|
358
|
+
const create = imageConfig.create;
|
|
359
|
+
if (!create) {
|
|
360
|
+
return undefined;
|
|
361
|
+
}
|
|
362
|
+
return {
|
|
363
|
+
...(create.role ? { role: create.role } : {}),
|
|
364
|
+
source: {
|
|
365
|
+
kind: create.kind,
|
|
366
|
+
...(create.profileId ? { profileId: create.profileId } : {}),
|
|
367
|
+
templateName: create.templateName,
|
|
368
|
+
...(create.templateCategory
|
|
369
|
+
? { templateCategory: create.templateCategory }
|
|
370
|
+
: {}),
|
|
371
|
+
},
|
|
372
|
+
cleanupPolicy: projectImageCreateCleanupPolicy(create),
|
|
373
|
+
route: {
|
|
374
|
+
serverName: "pharo_gateway",
|
|
375
|
+
targetKey: "targetId",
|
|
376
|
+
imageArgument: "mcpServerId",
|
|
377
|
+
imageId: imageConfig.id,
|
|
378
|
+
},
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
function assertPreviousStateBelongsToScope(previousState, scope) {
|
|
382
|
+
if (!previousState) {
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
if (previousState.projectId !== scope.projectId) {
|
|
386
|
+
throw new ScopedPharoLauncherError(`State file belongs to project ${previousState.projectId}; scoped create for project ${scope.projectId} is rejected`);
|
|
387
|
+
}
|
|
388
|
+
if (previousState.workspaceId !== scope.workspaceId) {
|
|
389
|
+
throw new ScopedPharoLauncherError(`State file belongs to workspace ${previousState.workspaceId}; scoped create for workspace ${scope.workspaceId} is rejected`);
|
|
390
|
+
}
|
|
391
|
+
if (previousState.targetId !== scope.targetId) {
|
|
392
|
+
throw new ScopedPharoLauncherError(`State file belongs to target ${previousState.targetId}; scoped create for target ${scope.targetId} is rejected`);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
function assertWorkspaceImagePolicyAllowsCreate(projectConfig, previousState, imageId) {
|
|
396
|
+
const maxCount = resolveProjectRuntimePolicy(projectConfig).workspaceImages?.maxCount;
|
|
397
|
+
if (maxCount === undefined) {
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
const currentImageCount = previousState?.images.length ?? 0;
|
|
401
|
+
if (currentImageCount >= maxCount) {
|
|
402
|
+
throw new ScopedPharoLauncherError(`Workspace image policy allows at most ${maxCount} image${maxCount === 1 ? "" : "s"}; scoped create for image ${imageId} is rejected`);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
function imageMcpSnapshotEndpoint(imageState) {
|
|
406
|
+
if (imageState.mcpEndpoint) {
|
|
407
|
+
return imageState.mcpEndpoint;
|
|
408
|
+
}
|
|
409
|
+
if (imageState.assignedPort !== undefined) {
|
|
410
|
+
return {
|
|
411
|
+
transport: "http",
|
|
412
|
+
host: "127.0.0.1",
|
|
413
|
+
port: imageState.assignedPort,
|
|
414
|
+
path: "/",
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
return undefined;
|
|
418
|
+
}
|
|
419
|
+
function endpointUrl(endpoint) {
|
|
420
|
+
const host = endpoint.host.includes(":") && !endpoint.host.startsWith("[")
|
|
421
|
+
? `[${endpoint.host}]`
|
|
422
|
+
: endpoint.host;
|
|
423
|
+
return `http://${host}:${endpoint.port}${endpoint.path}`;
|
|
424
|
+
}
|
|
425
|
+
function smalltalkString(value) {
|
|
426
|
+
return `'${value.replaceAll("'", "''")}'`;
|
|
427
|
+
}
|
|
428
|
+
function smalltalkPath(value) {
|
|
429
|
+
return smalltalkString(value.replace(/\\/g, "/"));
|
|
430
|
+
}
|
|
431
|
+
function isObject(value) {
|
|
432
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
433
|
+
}
|
|
434
|
+
function defaultSleep(durationMs) {
|
|
435
|
+
return new Promise((resolve) => setTimeout(resolve, durationMs));
|
|
436
|
+
}
|
|
437
|
+
function displayModeSnapshotStatusPath(scope, imageId, now) {
|
|
438
|
+
const scriptsDirectory = projectScriptsDirectoryPath({
|
|
439
|
+
projectRoot: scope.projectRoot,
|
|
440
|
+
projectId: scope.projectId,
|
|
441
|
+
workspaceId: scope.workspaceId,
|
|
442
|
+
stateRoot: scope.stateRoot,
|
|
443
|
+
});
|
|
444
|
+
return joinPathLike(scriptsDirectory, `display-mode-snapshot-${sanitizeRuntimeId(imageId)}-${now.getTime()}.properties`);
|
|
445
|
+
}
|
|
446
|
+
function displayModeSnapshotScript(statusPath) {
|
|
447
|
+
return `| snapshotStatusFile |
|
|
448
|
+
snapshotStatusFile := ${smalltalkPath(statusPath)} asFileReference.
|
|
449
|
+
[
|
|
450
|
+
(Delay forMilliseconds: 500) wait.
|
|
451
|
+
[
|
|
452
|
+
| server |
|
|
453
|
+
server := Smalltalk globals at: #PLexusMCPServer ifAbsent: [ nil ].
|
|
454
|
+
server ifNotNil: [
|
|
455
|
+
[ server stop ] on: Error do: [ :error | nil ].
|
|
456
|
+
Smalltalk globals removeKey: #PLexusMCPServer ifAbsent: [ nil ] ].
|
|
457
|
+
Smalltalk snapshot: true andQuit: false.
|
|
458
|
+
snapshotStatusFile writeStreamDo: [ :stream |
|
|
459
|
+
stream nextPutAll: 'status=saved'; cr ]
|
|
460
|
+
] on: Error do: [ :error |
|
|
461
|
+
snapshotStatusFile writeStreamDo: [ :stream |
|
|
462
|
+
stream nextPutAll: 'status=error'; cr.
|
|
463
|
+
stream nextPutAll: 'message='; nextPutAll: error asString; cr ] ]
|
|
464
|
+
] forkAt: Processor userBackgroundPriority.
|
|
465
|
+
'display mode snapshot scheduled'.`;
|
|
466
|
+
}
|
|
467
|
+
function parseProperties(contents) {
|
|
468
|
+
const result = {};
|
|
469
|
+
for (const line of contents.split(/\r\n|\r|\n/)) {
|
|
470
|
+
const separator = line.indexOf("=");
|
|
471
|
+
if (separator < 0) {
|
|
472
|
+
continue;
|
|
473
|
+
}
|
|
474
|
+
result[line.slice(0, separator)] = line.slice(separator + 1);
|
|
475
|
+
}
|
|
476
|
+
return result;
|
|
477
|
+
}
|
|
478
|
+
async function waitForDisplayModeSnapshotStatus(imageId, statusPath) {
|
|
479
|
+
const deadline = Date.now() + displayModeSnapshotTimeoutMs;
|
|
480
|
+
while (Date.now() <= deadline) {
|
|
481
|
+
if (fs.existsSync(statusPath)) {
|
|
482
|
+
const status = parseProperties(fs.readFileSync(statusPath, "utf8"));
|
|
483
|
+
if (status.status === "saved") {
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
if (status.status === "error") {
|
|
487
|
+
throw new ScopedPharoLauncherError(`Image ${imageId} snapshot failed: ${status.message ?? "unknown error"}`);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
await defaultSleep(displayModeSnapshotPollIntervalMs);
|
|
491
|
+
}
|
|
492
|
+
throw new ScopedPharoLauncherError(`Image ${imageId} snapshot did not finish within ${displayModeSnapshotTimeoutMs}ms`);
|
|
493
|
+
}
|
|
494
|
+
function projectStateWithoutImage(state, imageId, updatedAt) {
|
|
495
|
+
const images = state.images.filter((image) => image.id !== imageId);
|
|
496
|
+
return {
|
|
497
|
+
...state,
|
|
498
|
+
images,
|
|
499
|
+
runtimeStatus: runtimeStatusForImages(images),
|
|
500
|
+
updatedAt: updatedAt.toISOString(),
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
function lifecycleStatus(image) {
|
|
504
|
+
return {
|
|
505
|
+
imageId: image.imageId,
|
|
506
|
+
status: image.status,
|
|
507
|
+
displayMode: image.displayMode,
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
function routeStatus(image, imageState) {
|
|
511
|
+
const endpointRecorded = Boolean(imageState?.mcpEndpoint || imageState?.assignedPort !== undefined);
|
|
512
|
+
const contractStatus = imageState?.pharoMcpContract?.status;
|
|
513
|
+
let status;
|
|
514
|
+
if (image.status !== "running" || !endpointRecorded) {
|
|
515
|
+
status = "image_unavailable";
|
|
516
|
+
}
|
|
517
|
+
else if (contractStatus === "mismatched" || contractStatus === "unsupported") {
|
|
518
|
+
status = "contract_mismatch";
|
|
519
|
+
}
|
|
520
|
+
else if (contractStatus === undefined || contractStatus === "unknown") {
|
|
521
|
+
status = "contract_unknown";
|
|
522
|
+
}
|
|
523
|
+
else {
|
|
524
|
+
status = "routable";
|
|
525
|
+
}
|
|
526
|
+
return {
|
|
527
|
+
serverName: "pharo_gateway",
|
|
528
|
+
requiredArgument: "mcpServerId",
|
|
529
|
+
mcpServerId: image.imageId,
|
|
530
|
+
status,
|
|
531
|
+
routable: status === "routable",
|
|
532
|
+
endpointRecorded,
|
|
533
|
+
...(contractStatus ? { contractStatus } : {}),
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
function resetCloseError(imageId, error) {
|
|
537
|
+
const cleanup = error.result.repositoryWorkspaceCleanups.find((record) => record.imageId === imageId);
|
|
538
|
+
if (cleanup) {
|
|
539
|
+
return new ScopedPharoLauncherError(`Image ${imageId} reset could not clean its disposable repository workspace: ${cleanup.decision} (${cleanup.dirtyState})`);
|
|
540
|
+
}
|
|
541
|
+
const failure = error.result.failures.find((record) => record.imageId === imageId);
|
|
542
|
+
if (failure) {
|
|
543
|
+
return new ScopedPharoLauncherError(`Image ${imageId} reset could not close the scoped image`);
|
|
544
|
+
}
|
|
545
|
+
return new ScopedPharoLauncherError(`Image ${imageId} reset could not close the scoped image cleanly`);
|
|
546
|
+
}
|
|
547
|
+
function resetSummary(imageId, closeResult, deleted, started, image, imageState) {
|
|
548
|
+
return {
|
|
549
|
+
imageId,
|
|
550
|
+
closed: Boolean(closeResult),
|
|
551
|
+
deleted,
|
|
552
|
+
created: true,
|
|
553
|
+
started,
|
|
554
|
+
lifecycle: lifecycleStatus(image),
|
|
555
|
+
route: routeStatus(image, imageState),
|
|
556
|
+
repositoryWorkspaceCleanupPolicy: "delete-disposable",
|
|
557
|
+
repositoryWorkspaceCleanup: {
|
|
558
|
+
attempted: Boolean(closeResult),
|
|
559
|
+
decisions: closeResult?.repositoryWorkspaceCleanups.map((record) => ({
|
|
560
|
+
repositoryId: record.repositoryId,
|
|
561
|
+
decision: record.decision,
|
|
562
|
+
dirtyState: record.dirtyState,
|
|
563
|
+
})) ?? [],
|
|
564
|
+
},
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
function stateWithCreatedImage(projectConfig, scope, previousState, imageId, now) {
|
|
568
|
+
const runtime = resolveProjectRuntimePolicy(projectConfig);
|
|
569
|
+
const reservedPorts = collectReservedProjectPortOwners({
|
|
570
|
+
projectRoot: scope.projectRoot,
|
|
571
|
+
projectId: projectConfigId(projectConfig),
|
|
572
|
+
stateRoot: scope.stateRoot,
|
|
573
|
+
excludeWorkspaceId: scope.workspaceId,
|
|
574
|
+
}).map((owner) => owner.port);
|
|
575
|
+
const state = createProjectState(projectConfig, {
|
|
576
|
+
previousState,
|
|
577
|
+
workspaceId: scope.workspaceId,
|
|
578
|
+
targetId: scope.targetId,
|
|
579
|
+
reservedPorts,
|
|
580
|
+
portRange: runtime.imagePorts.range,
|
|
581
|
+
updatedAt: now.toISOString(),
|
|
582
|
+
});
|
|
583
|
+
const existingImageIds = new Set(previousState?.images.map((image) => image.id) ?? []);
|
|
584
|
+
state.images = state.images.filter((image) => image.id === imageId || existingImageIds.has(image.id));
|
|
585
|
+
for (const image of state.images) {
|
|
586
|
+
const previousImage = previousState?.images.find((candidate) => candidate.id === image.id);
|
|
587
|
+
if (image.id === imageId) {
|
|
588
|
+
const imageConfig = findImageConfig(projectConfig, imageId);
|
|
589
|
+
image.status = "stopped";
|
|
590
|
+
delete image.pid;
|
|
591
|
+
image.creation = imageCreationState(imageConfig);
|
|
592
|
+
}
|
|
593
|
+
else if (previousImage) {
|
|
594
|
+
Object.assign(image, previousImage);
|
|
595
|
+
}
|
|
596
|
+
else {
|
|
597
|
+
image.status = "stopped";
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
state.runtimeStatus = runtimeStatusForImages(state.images);
|
|
601
|
+
return state;
|
|
602
|
+
}
|
|
603
|
+
export class ScopedPharoLauncher {
|
|
604
|
+
options;
|
|
605
|
+
constructor(options) {
|
|
606
|
+
this.options = options;
|
|
607
|
+
}
|
|
608
|
+
currentImageState(scope, projectConfig, imageId) {
|
|
609
|
+
const state = loadProjectState(statePathForScope(scope, projectConfig));
|
|
610
|
+
return state?.images.find((image) => image.id === imageId);
|
|
611
|
+
}
|
|
612
|
+
imageLeaseForMutation(scope, projectConfig, imageId, now) {
|
|
613
|
+
const imageState = this.currentImageState(scope, projectConfig, imageId);
|
|
614
|
+
const lease = imageLeaseForMutation(scope, this.options.imageLease, now, imageState?.lease);
|
|
615
|
+
assertImageLeaseAllowsMutation(imageId, imageState?.lease, lease, now);
|
|
616
|
+
return lease;
|
|
617
|
+
}
|
|
618
|
+
recordImageLease(scope, projectConfig, imageId, lease, now) {
|
|
619
|
+
const statePath = statePathForScope(scope, projectConfig);
|
|
620
|
+
const state = loadProjectState(statePath);
|
|
621
|
+
if (!state?.images.some((image) => image.id === imageId)) {
|
|
622
|
+
return undefined;
|
|
623
|
+
}
|
|
624
|
+
const nextState = stateWithImageLease(state, imageId, lease, now);
|
|
625
|
+
saveProjectState(statePath, nextState);
|
|
626
|
+
return nextState;
|
|
627
|
+
}
|
|
628
|
+
routeRegistryForState(state) {
|
|
629
|
+
if (this.options.routeRegistry) {
|
|
630
|
+
return this.options.routeRegistry;
|
|
631
|
+
}
|
|
632
|
+
const controlEndpoint = state.gateway?.controlEndpoint;
|
|
633
|
+
return controlEndpoint
|
|
634
|
+
? new HttpGatewayRouteRegistry({
|
|
635
|
+
url: controlEndpoint,
|
|
636
|
+
fetch: this.options.fetch,
|
|
637
|
+
})
|
|
638
|
+
: undefined;
|
|
639
|
+
}
|
|
640
|
+
async refreshRegisteredProjectRoute(scope, statePath, state) {
|
|
641
|
+
if (!state) {
|
|
642
|
+
return;
|
|
643
|
+
}
|
|
644
|
+
const routeRegistry = this.routeRegistryForState(state);
|
|
645
|
+
if (!routeRegistry) {
|
|
646
|
+
return;
|
|
647
|
+
}
|
|
648
|
+
await routeRegistry.registerProjectRoute({
|
|
649
|
+
projectRoot: scope.projectRoot,
|
|
650
|
+
statePath,
|
|
651
|
+
state,
|
|
652
|
+
});
|
|
653
|
+
}
|
|
654
|
+
async snapshotImageBeforeDisplayModeRestart(scope, imageState) {
|
|
655
|
+
const endpoint = imageMcpSnapshotEndpoint(imageState);
|
|
656
|
+
if (!endpoint) {
|
|
657
|
+
throw new ScopedPharoLauncherError(`Image ${imageState.id} has no routable Pharo MCP endpoint; display mode restart cannot snapshot before close`);
|
|
658
|
+
}
|
|
659
|
+
const statusPath = displayModeSnapshotStatusPath(scope, imageState.id, this.options.now?.() ?? new Date());
|
|
660
|
+
fs.mkdirSync(dirnamePathLike(statusPath), { recursive: true });
|
|
661
|
+
fs.rmSync(statusPath, { force: true });
|
|
662
|
+
const controller = new AbortController();
|
|
663
|
+
const timeout = setTimeout(() => controller.abort(), displayModeSnapshotTimeoutMs);
|
|
664
|
+
try {
|
|
665
|
+
const response = await (this.options.fetch ?? fetch)(endpointUrl(endpoint), {
|
|
666
|
+
method: "POST",
|
|
667
|
+
headers: {
|
|
668
|
+
accept: "application/json, text/event-stream",
|
|
669
|
+
"content-type": "application/json",
|
|
670
|
+
},
|
|
671
|
+
body: JSON.stringify({
|
|
672
|
+
jsonrpc: "2.0",
|
|
673
|
+
id: `plexus-display-mode-snapshot-${imageState.id}-${Date.now()}`,
|
|
674
|
+
method: "tools/call",
|
|
675
|
+
params: {
|
|
676
|
+
name: "evaluate",
|
|
677
|
+
arguments: {
|
|
678
|
+
code: displayModeSnapshotScript(statusPath),
|
|
679
|
+
},
|
|
680
|
+
},
|
|
681
|
+
}),
|
|
682
|
+
signal: controller.signal,
|
|
683
|
+
});
|
|
684
|
+
if (!response.ok) {
|
|
685
|
+
throw new ScopedPharoLauncherError(`Image ${imageState.id} snapshot failed with HTTP ${response.status}`);
|
|
686
|
+
}
|
|
687
|
+
const payload = (await response.json());
|
|
688
|
+
if (!isObject(payload)) {
|
|
689
|
+
throw new ScopedPharoLauncherError(`Image ${imageState.id} snapshot returned a non-object response`);
|
|
690
|
+
}
|
|
691
|
+
if ("error" in payload) {
|
|
692
|
+
throw new ScopedPharoLauncherError(`Image ${imageState.id} snapshot failed: ${JSON.stringify(payload.error)}`);
|
|
693
|
+
}
|
|
694
|
+
const result = payload.result;
|
|
695
|
+
if (isObject(result) && result.isError === true) {
|
|
696
|
+
throw new ScopedPharoLauncherError(`Image ${imageState.id} snapshot tool returned an error`);
|
|
697
|
+
}
|
|
698
|
+
await waitForDisplayModeSnapshotStatus(imageState.id, statusPath);
|
|
699
|
+
return {
|
|
700
|
+
attempted: true,
|
|
701
|
+
status: "saved",
|
|
702
|
+
endpoint,
|
|
703
|
+
};
|
|
704
|
+
}
|
|
705
|
+
finally {
|
|
706
|
+
clearTimeout(timeout);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
listImages() {
|
|
710
|
+
const scope = resolveScope(this.options);
|
|
711
|
+
const projectConfig = loadProjectConfig(scope.projectRoot);
|
|
712
|
+
const state = loadProjectState(statePathForScope(scope, projectConfig));
|
|
713
|
+
const launcherProfile = describePharoLauncherMcpProfile({
|
|
714
|
+
projectRoot: scope.projectRoot,
|
|
715
|
+
config: projectConfig,
|
|
716
|
+
workspaceId: scope.workspaceId,
|
|
717
|
+
targetId: scope.targetId,
|
|
718
|
+
stateRoot: scope.stateRoot,
|
|
719
|
+
});
|
|
720
|
+
return {
|
|
721
|
+
scope: scopeSummary(scope),
|
|
722
|
+
launcherProfile: launcherProfileSummary(launcherProfile),
|
|
723
|
+
images: projectConfig.images.map((imageConfig) => imageSummary(imageConfig, state?.images.find((image) => image.id === imageConfig.id))),
|
|
724
|
+
};
|
|
725
|
+
}
|
|
726
|
+
imageInfo(imageId) {
|
|
727
|
+
const listed = this.listImages();
|
|
728
|
+
const image = listed.images.find((candidate) => candidate.imageId === imageId);
|
|
729
|
+
if (!image) {
|
|
730
|
+
throw new ScopedPharoLauncherError(`Image ${imageId} is not declared in this PLexus workspace`);
|
|
731
|
+
}
|
|
732
|
+
return {
|
|
733
|
+
scope: listed.scope,
|
|
734
|
+
launcherProfile: listed.launcherProfile,
|
|
735
|
+
image,
|
|
736
|
+
};
|
|
737
|
+
}
|
|
738
|
+
async createImage(imageId, profileId) {
|
|
739
|
+
const scope = resolveScope(this.options);
|
|
740
|
+
const projectConfig = loadProjectConfig(scope.projectRoot);
|
|
741
|
+
const imageConfig = findImageConfig(projectConfig, imageId);
|
|
742
|
+
if (!imageConfig.create) {
|
|
743
|
+
throw new ScopedPharoLauncherError(`Image ${imageId} has no approved create policy in project config`);
|
|
744
|
+
}
|
|
745
|
+
if (profileId && profileId !== imageConfig.create.profileId) {
|
|
746
|
+
throw new ScopedPharoLauncherError(`Profile ${profileId} is not approved for image ${imageId}`);
|
|
747
|
+
}
|
|
748
|
+
const statePath = statePathForScope(scope, projectConfig);
|
|
749
|
+
const previousState = loadProjectState(statePath);
|
|
750
|
+
assertPreviousStateBelongsToScope(previousState, scope);
|
|
751
|
+
if (previousState?.images.some((image) => image.id === imageId)) {
|
|
752
|
+
throw new ScopedPharoLauncherError(`Image ${imageId} already has runtime state`);
|
|
753
|
+
}
|
|
754
|
+
assertWorkspaceImagePolicyAllowsCreate(projectConfig, previousState, imageId);
|
|
755
|
+
const now = this.options.now?.() ?? new Date();
|
|
756
|
+
const lease = this.imageLeaseForMutation(scope, projectConfig, imageId, now);
|
|
757
|
+
const state = stateWithCreatedImage(projectConfig, scope, previousState, imageId, now);
|
|
758
|
+
const imageState = state.images.find((image) => image.id === imageId);
|
|
759
|
+
if (!imageState) {
|
|
760
|
+
throw new ScopedPharoLauncherError(`Image ${imageId} is not declared in this PLexus workspace`);
|
|
761
|
+
}
|
|
762
|
+
const client = this.options.pharoLauncherMcpClient ??
|
|
763
|
+
(await createStdioPharoLauncherMcpClient(undefined, {
|
|
764
|
+
profileEnvironment: pharoLauncherMcpProfileEnvironment({
|
|
765
|
+
projectRoot: scope.projectRoot,
|
|
766
|
+
config: projectConfig,
|
|
767
|
+
workspaceId: scope.workspaceId,
|
|
768
|
+
targetId: scope.targetId,
|
|
769
|
+
stateRoot: scope.stateRoot,
|
|
770
|
+
}),
|
|
771
|
+
}));
|
|
772
|
+
const ownsClient = !this.options.pharoLauncherMcpClient;
|
|
773
|
+
try {
|
|
774
|
+
const homeMaterialization = await materializeProjectImageFromHomeCache({
|
|
775
|
+
runtimeClient: client,
|
|
776
|
+
homeClient: this.options.homeImageCacheClient ??
|
|
777
|
+
(this.options.pharoLauncherMcpClient ? client : undefined),
|
|
778
|
+
projectRoot: scope.projectRoot,
|
|
779
|
+
config: projectConfig,
|
|
780
|
+
imageConfig,
|
|
781
|
+
imageState,
|
|
782
|
+
workspaceId: scope.workspaceId,
|
|
783
|
+
targetId: scope.targetId,
|
|
784
|
+
stateRoot: scope.stateRoot,
|
|
785
|
+
approval: scopedMutationApproval(this.options.homeImageCacheApproval, "scoped-pharo-launcher-create"),
|
|
786
|
+
now: this.options.now,
|
|
787
|
+
});
|
|
788
|
+
if (!homeMaterialization) {
|
|
789
|
+
await ensureScopedTemplateCatalogReady({
|
|
790
|
+
client,
|
|
791
|
+
scope,
|
|
792
|
+
projectConfig,
|
|
793
|
+
fetch: this.options.fetch,
|
|
794
|
+
});
|
|
795
|
+
const result = await client.callTool("pharo_launcher_image_create", {
|
|
796
|
+
newImageName: renderedImageName(scope, imageConfig),
|
|
797
|
+
templateName: imageConfig.create.templateName,
|
|
798
|
+
...(imageConfig.create.templateCategory
|
|
799
|
+
? { templateCategory: imageConfig.create.templateCategory }
|
|
800
|
+
: {}),
|
|
801
|
+
noLaunch: true,
|
|
802
|
+
});
|
|
803
|
+
assertLauncherOk(result, "pharo_launcher_image_create");
|
|
804
|
+
}
|
|
805
|
+
const nextState = stateWithImageLease(state, imageId, lease, now);
|
|
806
|
+
saveProjectState(statePath, nextState);
|
|
807
|
+
await this.refreshRegisteredProjectRoute(scope, statePath, nextState);
|
|
808
|
+
}
|
|
809
|
+
finally {
|
|
810
|
+
if (ownsClient) {
|
|
811
|
+
await client.close?.();
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
return this.imageInfo(imageId);
|
|
815
|
+
}
|
|
816
|
+
async startImage(imageId, displayMode) {
|
|
817
|
+
const before = this.imageInfo(imageId);
|
|
818
|
+
if (!before.image.active) {
|
|
819
|
+
throw new ScopedPharoLauncherError(`Image ${imageId} is not active in project config; scoped start is rejected`);
|
|
820
|
+
}
|
|
821
|
+
if (before.image.status === "running" || before.image.status === "starting") {
|
|
822
|
+
throw new ScopedPharoLauncherError(`Image ${imageId} is already ${before.image.status}; scoped start is rejected`);
|
|
823
|
+
}
|
|
824
|
+
const scope = resolveScope(this.options);
|
|
825
|
+
const projectConfig = loadProjectConfig(scope.projectRoot);
|
|
826
|
+
const now = this.options.now?.() ?? new Date();
|
|
827
|
+
const lease = this.imageLeaseForMutation(scope, projectConfig, imageId, now);
|
|
828
|
+
const openResult = await (this.options.projectOpen ?? openProject)({
|
|
829
|
+
projectRoot: scope.projectRoot,
|
|
830
|
+
workspaceId: scope.workspaceId,
|
|
831
|
+
targetId: scope.targetId,
|
|
832
|
+
stateRoot: scope.stateRoot,
|
|
833
|
+
imageIds: [imageId],
|
|
834
|
+
...(displayMode ? { displayMode } : {}),
|
|
835
|
+
homeImageCacheApproval: scopedMutationApproval(this.options.homeImageCacheApproval, "scoped-pharo-launcher-start"),
|
|
836
|
+
homeImageCacheClient: this.options.homeImageCacheClient ??
|
|
837
|
+
this.options.pharoLauncherMcpClient,
|
|
838
|
+
});
|
|
839
|
+
const statePath = statePathForScope(scope, projectConfig);
|
|
840
|
+
const leasedState = this.recordImageLease(scope, projectConfig, imageId, lease, now);
|
|
841
|
+
await this.refreshRegisteredProjectRoute(scope, statePath, leasedState ?? openResult.state);
|
|
842
|
+
return this.imageInfo(imageId);
|
|
843
|
+
}
|
|
844
|
+
async setImageDisplayMode(imageId, displayMode) {
|
|
845
|
+
const scope = resolveScope(this.options);
|
|
846
|
+
const projectConfig = loadProjectConfig(scope.projectRoot);
|
|
847
|
+
const imageConfig = findImageConfig(projectConfig, imageId);
|
|
848
|
+
const before = this.imageInfo(imageId);
|
|
849
|
+
const imageState = this.currentImageState(scope, projectConfig, imageId);
|
|
850
|
+
const previousDisplayMode = imageState?.displayMode ?? projectImageDisplayMode(imageConfig);
|
|
851
|
+
if (!before.image.active) {
|
|
852
|
+
throw new ScopedPharoLauncherError(`Image ${imageId} is not active in project config; display mode change is rejected`);
|
|
853
|
+
}
|
|
854
|
+
if (before.image.status === "starting") {
|
|
855
|
+
throw new ScopedPharoLauncherError(`Image ${imageId} is starting; wait for startup to finish before changing display mode`);
|
|
856
|
+
}
|
|
857
|
+
if (before.image.status === "running" && previousDisplayMode === displayMode) {
|
|
858
|
+
return {
|
|
859
|
+
...before,
|
|
860
|
+
previousDisplayMode,
|
|
861
|
+
displayMode,
|
|
862
|
+
restarted: false,
|
|
863
|
+
runtimeStateUnchanged: true,
|
|
864
|
+
};
|
|
865
|
+
}
|
|
866
|
+
this.imageLeaseForMutation(scope, projectConfig, imageId, this.options.now?.() ?? new Date());
|
|
867
|
+
let snapshotBeforeRestart;
|
|
868
|
+
if (before.image.status === "running") {
|
|
869
|
+
if (imageState) {
|
|
870
|
+
snapshotBeforeRestart =
|
|
871
|
+
await this.snapshotImageBeforeDisplayModeRestart(scope, imageState);
|
|
872
|
+
}
|
|
873
|
+
await this.stopImage(imageId);
|
|
874
|
+
}
|
|
875
|
+
await this.startImage(imageId, displayMode);
|
|
876
|
+
return {
|
|
877
|
+
...this.imageInfo(imageId),
|
|
878
|
+
previousDisplayMode,
|
|
879
|
+
displayMode,
|
|
880
|
+
restarted: before.image.status === "running",
|
|
881
|
+
runtimeStateUnchanged: false,
|
|
882
|
+
...(snapshotBeforeRestart ? { snapshotBeforeRestart } : {}),
|
|
883
|
+
};
|
|
884
|
+
}
|
|
885
|
+
async openImageInteractive(imageId) {
|
|
886
|
+
return this.setImageDisplayMode(imageId, "interactive");
|
|
887
|
+
}
|
|
888
|
+
async showImage(imageId) {
|
|
889
|
+
return this.setImageDisplayMode(imageId, "interactive");
|
|
890
|
+
}
|
|
891
|
+
async hideImage(imageId) {
|
|
892
|
+
return this.setImageDisplayMode(imageId, "headless");
|
|
893
|
+
}
|
|
894
|
+
async stopImage(imageId) {
|
|
895
|
+
this.imageInfo(imageId);
|
|
896
|
+
const scope = resolveScope(this.options);
|
|
897
|
+
const projectConfig = loadProjectConfig(scope.projectRoot);
|
|
898
|
+
const now = this.options.now?.() ?? new Date();
|
|
899
|
+
const lease = this.imageLeaseForMutation(scope, projectConfig, imageId, now);
|
|
900
|
+
const closeResult = await (this.options.projectClose ?? closeProject)({
|
|
901
|
+
projectRoot: scope.projectRoot,
|
|
902
|
+
workspaceId: scope.workspaceId,
|
|
903
|
+
stateRoot: scope.stateRoot,
|
|
904
|
+
imageIds: [imageId],
|
|
905
|
+
});
|
|
906
|
+
const statePath = statePathForScope(scope, projectConfig);
|
|
907
|
+
const leasedState = this.recordImageLease(scope, projectConfig, imageId, lease, now);
|
|
908
|
+
await this.refreshRegisteredProjectRoute(scope, statePath, leasedState ?? closeResult.state);
|
|
909
|
+
return this.imageInfo(imageId);
|
|
910
|
+
}
|
|
911
|
+
assertResetImageConfig(imageId, imageConfig) {
|
|
912
|
+
if (!imageConfig.active) {
|
|
913
|
+
throw new ScopedPharoLauncherError(`Image ${imageId} is not active in project config; scoped reset is rejected`);
|
|
914
|
+
}
|
|
915
|
+
if (!imageConfig.create) {
|
|
916
|
+
throw new ScopedPharoLauncherError(`Image ${imageId} has no approved create policy in project config; scoped reset is rejected`);
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
async resetImage(imageId, options = {}) {
|
|
920
|
+
const scope = resolveScope(this.options);
|
|
921
|
+
const projectConfig = loadProjectConfig(scope.projectRoot);
|
|
922
|
+
const imageConfig = findImageConfig(projectConfig, imageId);
|
|
923
|
+
this.assertResetImageConfig(imageId, imageConfig);
|
|
924
|
+
const statePath = statePathForScope(scope, projectConfig);
|
|
925
|
+
const previousState = loadProjectState(statePath);
|
|
926
|
+
const previousImage = previousState?.images.find((image) => image.id === imageId);
|
|
927
|
+
if (previousImage) {
|
|
928
|
+
this.imageLeaseForMutation(scope, projectConfig, imageId, this.options.now?.() ?? new Date());
|
|
929
|
+
}
|
|
930
|
+
if (previousImage?.status === "starting") {
|
|
931
|
+
throw new ScopedPharoLauncherError(`Image ${imageId} is starting; wait for startup to finish before resetting`);
|
|
932
|
+
}
|
|
933
|
+
let closeResult;
|
|
934
|
+
if (previousImage) {
|
|
935
|
+
try {
|
|
936
|
+
closeResult = await (this.options.projectClose ?? closeProject)({
|
|
937
|
+
projectRoot: scope.projectRoot,
|
|
938
|
+
workspaceId: scope.workspaceId,
|
|
939
|
+
stateRoot: scope.stateRoot,
|
|
940
|
+
imageIds: [imageId],
|
|
941
|
+
pharoLauncherMcpClient: this.options.pharoLauncherMcpClient,
|
|
942
|
+
repositoryWorkspaceCleanupPolicy: "delete-disposable",
|
|
943
|
+
});
|
|
944
|
+
}
|
|
945
|
+
catch (error) {
|
|
946
|
+
if (error instanceof ProjectCloseError) {
|
|
947
|
+
throw resetCloseError(imageId, error);
|
|
948
|
+
}
|
|
949
|
+
throw error;
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
let deleted = false;
|
|
953
|
+
if (previousImage) {
|
|
954
|
+
const client = this.options.pharoLauncherMcpClient ??
|
|
955
|
+
(await createStdioPharoLauncherMcpClient(undefined, {
|
|
956
|
+
profileEnvironment: pharoLauncherMcpProfileEnvironment({
|
|
957
|
+
projectRoot: scope.projectRoot,
|
|
958
|
+
config: projectConfig,
|
|
959
|
+
workspaceId: scope.workspaceId,
|
|
960
|
+
targetId: scope.targetId,
|
|
961
|
+
stateRoot: scope.stateRoot,
|
|
962
|
+
}),
|
|
963
|
+
}));
|
|
964
|
+
const ownsClient = !this.options.pharoLauncherMcpClient;
|
|
965
|
+
try {
|
|
966
|
+
const deleteResult = await client.callTool("pharo_launcher_image_delete", {
|
|
967
|
+
imageName: previousImage.imageName,
|
|
968
|
+
force: true,
|
|
969
|
+
confirm: true,
|
|
970
|
+
});
|
|
971
|
+
assertLauncherOk(deleteResult, "pharo_launcher_image_delete");
|
|
972
|
+
deleted = true;
|
|
973
|
+
}
|
|
974
|
+
finally {
|
|
975
|
+
if (ownsClient) {
|
|
976
|
+
await client.close?.();
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
const currentState = loadProjectState(statePath);
|
|
980
|
+
if (currentState) {
|
|
981
|
+
saveProjectState(statePath, projectStateWithoutImage(currentState, imageId, this.options.now?.() ?? new Date()));
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
await this.createImage(imageId, imageConfig.create.profileId);
|
|
985
|
+
const shouldStart = options.start ?? true;
|
|
986
|
+
if (shouldStart) {
|
|
987
|
+
await this.startImage(imageId, options.displayMode);
|
|
988
|
+
}
|
|
989
|
+
const finalInfo = this.imageInfo(imageId);
|
|
990
|
+
return {
|
|
991
|
+
...finalInfo,
|
|
992
|
+
reset: resetSummary(imageId, closeResult, deleted, shouldStart, finalInfo.image, this.currentImageState(scope, projectConfig, imageId)),
|
|
993
|
+
};
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
export const scopedPharoLauncherTools = [
|
|
997
|
+
{
|
|
998
|
+
name: "pharo_launcher_image_list",
|
|
999
|
+
description: "List Pharo images declared in the current PLexus project/workspace scope.",
|
|
1000
|
+
inputSchema: objectSchema({ detail: toolResultDetailSchema }),
|
|
1001
|
+
},
|
|
1002
|
+
{
|
|
1003
|
+
name: "pharo_launcher_image_info",
|
|
1004
|
+
description: "Return scoped state for one Pharo image handle in the current PLexus workspace.",
|
|
1005
|
+
inputSchema: objectSchema({ imageId: stringSchema, detail: toolResultDetailSchema }, ["imageId"]),
|
|
1006
|
+
},
|
|
1007
|
+
{
|
|
1008
|
+
name: "pharo_launcher_image_create",
|
|
1009
|
+
description: "Create a declared workspace-scoped image from an approved PLexus project create policy.",
|
|
1010
|
+
inputSchema: objectSchema({
|
|
1011
|
+
imageId: stringSchema,
|
|
1012
|
+
profileId: stringSchema,
|
|
1013
|
+
detail: toolResultDetailSchema,
|
|
1014
|
+
}, ["imageId"]),
|
|
1015
|
+
},
|
|
1016
|
+
{
|
|
1017
|
+
name: "pharo_launcher_image_start",
|
|
1018
|
+
description: "Start a workspace-scoped active image through PLexus project open policy.",
|
|
1019
|
+
inputSchema: objectSchema({ imageId: stringSchema, displayMode: displayModeSchema }, ["imageId"]),
|
|
1020
|
+
},
|
|
1021
|
+
{
|
|
1022
|
+
name: "pharo_launcher_image_open_interactive",
|
|
1023
|
+
description: "Explicitly open a workspace-scoped active image in interactive display mode for human image work.",
|
|
1024
|
+
inputSchema: objectSchema({ imageId: stringSchema, detail: toolResultDetailSchema }, ["imageId"]),
|
|
1025
|
+
},
|
|
1026
|
+
{
|
|
1027
|
+
name: "pharo_launcher_image_show",
|
|
1028
|
+
description: "Switch a workspace-scoped active image to interactive display mode through PLexus lifecycle policy.",
|
|
1029
|
+
inputSchema: objectSchema({ imageId: stringSchema, detail: toolResultDetailSchema }, ["imageId"]),
|
|
1030
|
+
},
|
|
1031
|
+
{
|
|
1032
|
+
name: "pharo_launcher_image_hide",
|
|
1033
|
+
description: "Switch a workspace-scoped active image to headless display mode through PLexus lifecycle policy.",
|
|
1034
|
+
inputSchema: objectSchema({ imageId: stringSchema, detail: toolResultDetailSchema }, ["imageId"]),
|
|
1035
|
+
},
|
|
1036
|
+
{
|
|
1037
|
+
name: "pharo_launcher_image_stop",
|
|
1038
|
+
description: "Stop one workspace-scoped image through PLexus project close policy.",
|
|
1039
|
+
inputSchema: objectSchema({
|
|
1040
|
+
imageId: stringSchema,
|
|
1041
|
+
confirm: { type: "boolean" },
|
|
1042
|
+
detail: toolResultDetailSchema,
|
|
1043
|
+
}, ["imageId", "confirm"]),
|
|
1044
|
+
},
|
|
1045
|
+
{
|
|
1046
|
+
name: "pharo_launcher_image_reset",
|
|
1047
|
+
description: "Reset a disposable workspace-scoped image by closing it, deleting the owned launcher image, recreating it from approved project policy, and reopening unless start is false. Requires confirm: true.",
|
|
1048
|
+
inputSchema: objectSchema({
|
|
1049
|
+
imageId: stringSchema,
|
|
1050
|
+
confirm: { type: "boolean" },
|
|
1051
|
+
start: { type: "boolean" },
|
|
1052
|
+
displayMode: displayModeSchema,
|
|
1053
|
+
detail: toolResultDetailSchema,
|
|
1054
|
+
}, ["imageId", "confirm"]),
|
|
1055
|
+
},
|
|
1056
|
+
];
|
|
1057
|
+
export function createScopedPharoLauncherServer(options) {
|
|
1058
|
+
const facade = new ScopedPharoLauncher(options);
|
|
1059
|
+
const server = new Server({
|
|
1060
|
+
name: "pharo-launcher",
|
|
1061
|
+
version: "0.1.0",
|
|
1062
|
+
}, {
|
|
1063
|
+
capabilities: {
|
|
1064
|
+
tools: {},
|
|
1065
|
+
},
|
|
1066
|
+
});
|
|
1067
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
1068
|
+
tools: [...scopedPharoLauncherTools],
|
|
1069
|
+
}));
|
|
1070
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
1071
|
+
const input = request.params.arguments ?? {};
|
|
1072
|
+
const detail = toolResultDetailFromArguments(input);
|
|
1073
|
+
try {
|
|
1074
|
+
switch (request.params.name) {
|
|
1075
|
+
case "pharo_launcher_image_list":
|
|
1076
|
+
return textResult(facade.listImages(), false, detail);
|
|
1077
|
+
case "pharo_launcher_image_info":
|
|
1078
|
+
return textResult(facade.imageInfo(requireString(input, "imageId")), false, detail);
|
|
1079
|
+
case "pharo_launcher_image_create":
|
|
1080
|
+
return textResult(await facade.createImage(requireString(input, "imageId"), optionalString(input, "profileId")), false, detail);
|
|
1081
|
+
case "pharo_launcher_image_start":
|
|
1082
|
+
return textResult(await facade.startImage(requireString(input, "imageId"), optionalDisplayMode(input, "displayMode")), false, detail);
|
|
1083
|
+
case "pharo_launcher_image_open_interactive":
|
|
1084
|
+
return textResult(await facade.openImageInteractive(requireString(input, "imageId")), false, detail);
|
|
1085
|
+
case "pharo_launcher_image_show":
|
|
1086
|
+
return textResult(await facade.showImage(requireString(input, "imageId")), false, detail);
|
|
1087
|
+
case "pharo_launcher_image_hide":
|
|
1088
|
+
return textResult(await facade.hideImage(requireString(input, "imageId")), false, detail);
|
|
1089
|
+
case "pharo_launcher_image_stop":
|
|
1090
|
+
requireConfirm(input);
|
|
1091
|
+
return textResult(await facade.stopImage(requireString(input, "imageId")), false, detail);
|
|
1092
|
+
case "pharo_launcher_image_reset":
|
|
1093
|
+
requireConfirm(input);
|
|
1094
|
+
return textResult(await facade.resetImage(requireString(input, "imageId"), {
|
|
1095
|
+
start: optionalBoolean(input, "start"),
|
|
1096
|
+
displayMode: optionalDisplayMode(input, "displayMode"),
|
|
1097
|
+
}), false, detail);
|
|
1098
|
+
default:
|
|
1099
|
+
return textResult({ ok: false, error: `Unknown tool: ${request.params.name}` }, true, detail);
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
catch (error) {
|
|
1103
|
+
return textResult(scopedErrorPayload(error), true, detail);
|
|
1104
|
+
}
|
|
1105
|
+
});
|
|
1106
|
+
return server;
|
|
1107
|
+
}
|
|
1108
|
+
export async function startScopedPharoLauncherServer(options) {
|
|
1109
|
+
const server = createScopedPharoLauncherServer(options);
|
|
1110
|
+
await server.connect(new StdioServerTransport());
|
|
1111
|
+
}
|
|
1112
|
+
//# sourceMappingURL=scopedPharoLauncherServer.js.map
|