@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
|
@@ -1,2114 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { defaultImagePortClaimChecks, imagePortClaimsRootForConfig, } from "../ports/imagePortClaims.js";
|
|
4
|
-
import { rescueImage, } from "../images/imageRescue.js";
|
|
5
|
-
import { repositoryActionToolNames } from "../mcp/imageOperations.js";
|
|
6
|
-
import { loadProjectConfig, plexusProjectConfigFileName, projectConfigId, ProjectConfigError, resolveProjectRuntimePolicy, } from "../config/projectConfig.js";
|
|
7
|
-
import { closeProject } from "./projectClose.js";
|
|
8
|
-
import { cleanupProjectOwnedResources, } from "./projectCleanup.js";
|
|
9
|
-
import { closeProjectGateway, ensureProjectGateway, projectGatewayStatus, } from "../gateway/projectGateway.js";
|
|
10
|
-
import { inspectPortClaim, listPortClaims, releasePortClaim, } from "../ports/portClaims.js";
|
|
11
|
-
import { flushHomeImageCache, homeImageCacheManifestPath, homeImageCacheProfile, homeImageCacheRootPath, listHomeImageCacheManifests, planHomeImageCacheFlush, profileEnvironmentFromPaths, readHomeImageCacheManifest, resolvePlexusHomePath, } from "../images/homeImageCache.js";
|
|
12
|
-
import { createStdioPharoLauncherMcpClient, } from "../launcher/pharoLauncherMcpClient.js";
|
|
13
|
-
import { openProject, ProjectOpenError, } from "./projectOpen.js";
|
|
14
|
-
import { inspectProjectImageRepositoryWorkspace, } from "../workspace/projectRepositoryWorkspace.js";
|
|
15
|
-
import { defaultPlexusStateRoot, defaultTargetId, defaultWorkspaceId, loadProjectState, projectStateRootForConfig, projectStatePathForConfig, projectImageRepositoryWorkspaceStates, projectImageRepositoryWorkspaces, renderProjectImageName, runtimeStatusForImages, sanitizeRuntimeId, saveProjectState, } from "../workspace/projectState.js";
|
|
16
|
-
import { describePharoLauncherMcpProfile, } from "../launcher/pharoLauncherProfile.js";
|
|
17
|
-
import { buildScopedProjectContext, } from "../workspace/scopedProjectContext.js";
|
|
18
|
-
import { plexusRuntimeIdentity, } from "../support/runtimeIdentity.js";
|
|
19
|
-
function remoteWorkspaceTargetForInput(workspace, targetId) {
|
|
20
|
-
return targetId
|
|
21
|
-
? workspace.targets?.find((candidate) => candidate.targetId === targetId)
|
|
22
|
-
: undefined;
|
|
23
|
-
}
|
|
24
|
-
function remoteLifecycleMappingForWorkspace(remoteNode, workspace, workspaceId, targetId) {
|
|
25
|
-
const target = remoteWorkspaceTargetForInput(workspace, targetId);
|
|
26
|
-
if (targetId && workspace.targets && !target) {
|
|
27
|
-
return undefined;
|
|
28
|
-
}
|
|
29
|
-
if (workspace.workspaceId !== workspaceId && !target) {
|
|
30
|
-
return undefined;
|
|
31
|
-
}
|
|
32
|
-
return {
|
|
33
|
-
remoteNode,
|
|
34
|
-
workspace,
|
|
35
|
-
...(target ? { target } : {}),
|
|
36
|
-
workspaceId,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
const defaultGatewayRouteControlMcpPath = "/control-mcp";
|
|
40
|
-
const defaultPharoToolsDiscoveryTimeoutMs = 5_000;
|
|
41
|
-
class ProjectLifecycleInputError extends Error {
|
|
42
|
-
constructor(message) {
|
|
43
|
-
super(message);
|
|
44
|
-
this.name = "ProjectLifecycleInputError";
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
function isObject(value) {
|
|
48
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
49
|
-
}
|
|
50
|
-
function isProjectImageMcpEndpoint(value) {
|
|
51
|
-
return (isObject(value) &&
|
|
52
|
-
value.transport === "http" &&
|
|
53
|
-
typeof value.host === "string" &&
|
|
54
|
-
typeof value.port === "number" &&
|
|
55
|
-
Number.isInteger(value.port) &&
|
|
56
|
-
typeof value.path === "string");
|
|
57
|
-
}
|
|
58
|
-
function requireString(input, key) {
|
|
59
|
-
const value = input[key];
|
|
60
|
-
if (typeof value !== "string" || value.length === 0) {
|
|
61
|
-
throw new ProjectLifecycleInputError(`${key} is required`);
|
|
62
|
-
}
|
|
63
|
-
return value;
|
|
64
|
-
}
|
|
65
|
-
function optionalString(input, key) {
|
|
66
|
-
const value = input[key];
|
|
67
|
-
if (value === undefined) {
|
|
68
|
-
return undefined;
|
|
69
|
-
}
|
|
70
|
-
if (typeof value !== "string" || value.length === 0) {
|
|
71
|
-
throw new ProjectLifecycleInputError(`${key} must be a non-empty string`);
|
|
72
|
-
}
|
|
73
|
-
return value;
|
|
74
|
-
}
|
|
75
|
-
function optionalBoolean(input, key) {
|
|
76
|
-
const value = input[key];
|
|
77
|
-
if (value === undefined) {
|
|
78
|
-
return false;
|
|
79
|
-
}
|
|
80
|
-
if (typeof value !== "boolean") {
|
|
81
|
-
throw new ProjectLifecycleInputError(`${key} must be a boolean`);
|
|
82
|
-
}
|
|
83
|
-
return value;
|
|
84
|
-
}
|
|
85
|
-
function optionalBooleanValue(input, key) {
|
|
86
|
-
const value = input[key];
|
|
87
|
-
if (value === undefined) {
|
|
88
|
-
return undefined;
|
|
89
|
-
}
|
|
90
|
-
if (typeof value !== "boolean") {
|
|
91
|
-
throw new ProjectLifecycleInputError(`${key} must be a boolean`);
|
|
92
|
-
}
|
|
93
|
-
return value;
|
|
94
|
-
}
|
|
95
|
-
function optionalDisplayMode(input, key) {
|
|
96
|
-
const value = input[key];
|
|
97
|
-
if (value === undefined) {
|
|
98
|
-
return undefined;
|
|
99
|
-
}
|
|
100
|
-
if (value === "headless" || value === "interactive") {
|
|
101
|
-
return value;
|
|
102
|
-
}
|
|
103
|
-
throw new ProjectLifecycleInputError(`${key} must be headless or interactive`);
|
|
104
|
-
}
|
|
105
|
-
function optionalRepositoryWorkspaceCleanupPolicy(input) {
|
|
106
|
-
const value = input.repositoryWorkspaceCleanupPolicy;
|
|
107
|
-
if (value === undefined) {
|
|
108
|
-
return undefined;
|
|
109
|
-
}
|
|
110
|
-
if (value === "preserve" ||
|
|
111
|
-
value === "archive" ||
|
|
112
|
-
value === "delete-disposable") {
|
|
113
|
-
return value;
|
|
114
|
-
}
|
|
115
|
-
throw new ProjectLifecycleInputError("repositoryWorkspaceCleanupPolicy must be preserve, archive, or delete-disposable");
|
|
116
|
-
}
|
|
117
|
-
function optionalNumber(input, key) {
|
|
118
|
-
const value = input[key];
|
|
119
|
-
if (value === undefined) {
|
|
120
|
-
return undefined;
|
|
121
|
-
}
|
|
122
|
-
if (typeof value !== "number" || !Number.isInteger(value)) {
|
|
123
|
-
throw new ProjectLifecycleInputError(`${key} must be an integer`);
|
|
124
|
-
}
|
|
125
|
-
return value;
|
|
126
|
-
}
|
|
127
|
-
function optionalObject(input, key) {
|
|
128
|
-
const value = input[key];
|
|
129
|
-
if (value === undefined) {
|
|
130
|
-
return {};
|
|
131
|
-
}
|
|
132
|
-
if (!isObject(value)) {
|
|
133
|
-
throw new ProjectLifecycleInputError(`${key} must be an object`);
|
|
134
|
-
}
|
|
135
|
-
return value;
|
|
136
|
-
}
|
|
137
|
-
function numberArray(value, key) {
|
|
138
|
-
if (value === undefined) {
|
|
139
|
-
return undefined;
|
|
140
|
-
}
|
|
141
|
-
if (!Array.isArray(value) || !value.every(Number.isInteger)) {
|
|
142
|
-
throw new ProjectLifecycleInputError(`${key} must be an array of integers`);
|
|
143
|
-
}
|
|
144
|
-
return value;
|
|
145
|
-
}
|
|
146
|
-
function stringArray(value, key) {
|
|
147
|
-
if (value === undefined) {
|
|
148
|
-
return undefined;
|
|
149
|
-
}
|
|
150
|
-
if (!Array.isArray(value) ||
|
|
151
|
-
!value.every((item) => typeof item === "string" && item.length > 0)) {
|
|
152
|
-
throw new ProjectLifecycleInputError(`${key} must be an array of non-empty strings`);
|
|
153
|
-
}
|
|
154
|
-
return value;
|
|
155
|
-
}
|
|
156
|
-
function optionalEntrySelection(input, key) {
|
|
157
|
-
const value = input[key];
|
|
158
|
-
if (value === undefined) {
|
|
159
|
-
return undefined;
|
|
160
|
-
}
|
|
161
|
-
if (!isObject(value)) {
|
|
162
|
-
throw new ProjectLifecycleInputError(`${key} must be an object`);
|
|
163
|
-
}
|
|
164
|
-
return {
|
|
165
|
-
indexes: numberArray(value.indexes, `${key}.indexes`),
|
|
166
|
-
entryReferences: stringArray(value.entryReferences, `${key}.entryReferences`),
|
|
167
|
-
startIndex: optionalNumber(value, "startIndex"),
|
|
168
|
-
endIndex: optionalNumber(value, "endIndex"),
|
|
169
|
-
latestCount: optionalNumber(value, "latestCount"),
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
function optionalRepositoryActions(input, key) {
|
|
173
|
-
const value = input[key];
|
|
174
|
-
if (value === undefined) {
|
|
175
|
-
return undefined;
|
|
176
|
-
}
|
|
177
|
-
if (!Array.isArray(value)) {
|
|
178
|
-
throw new ProjectLifecycleInputError(`${key} must be an array`);
|
|
179
|
-
}
|
|
180
|
-
return value.map((item, index) => {
|
|
181
|
-
if (!isObject(item)) {
|
|
182
|
-
throw new ProjectLifecycleInputError(`${key}[${index}] must be an object`);
|
|
183
|
-
}
|
|
184
|
-
const toolName = item.toolName;
|
|
185
|
-
if (toolName !== undefined &&
|
|
186
|
-
!repositoryActionToolNames.includes(toolName)) {
|
|
187
|
-
throw new ProjectLifecycleInputError(`${key}[${index}].toolName must be one of ${repositoryActionToolNames.join(", ")}`);
|
|
188
|
-
}
|
|
189
|
-
return {
|
|
190
|
-
label: optionalString(item, "label"),
|
|
191
|
-
toolName: toolName,
|
|
192
|
-
arguments: optionalObject(item, "arguments"),
|
|
193
|
-
};
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
function requireRescueOperation(input) {
|
|
197
|
-
const value = input.operation;
|
|
198
|
-
if (value === "snapshotSource" ||
|
|
199
|
-
value === "plan" ||
|
|
200
|
-
value === "prepareTarget" ||
|
|
201
|
-
value === "applyPlan") {
|
|
202
|
-
return value;
|
|
203
|
-
}
|
|
204
|
-
throw new ProjectLifecycleInputError("operation must be snapshotSource, plan, prepareTarget, or applyPlan");
|
|
205
|
-
}
|
|
206
|
-
function objectInput(input) {
|
|
207
|
-
if (!isObject(input)) {
|
|
208
|
-
return {};
|
|
209
|
-
}
|
|
210
|
-
return input;
|
|
211
|
-
}
|
|
212
|
-
function result(data) {
|
|
213
|
-
return { ok: true, data };
|
|
214
|
-
}
|
|
215
|
-
function failure(error) {
|
|
216
|
-
const diagnostics = {
|
|
217
|
-
toolRuntime: plexusRuntimeIdentity(),
|
|
218
|
-
...(error instanceof ProjectConfigError
|
|
219
|
-
? {
|
|
220
|
-
projectConfig: {
|
|
221
|
-
issues: error.issues,
|
|
222
|
-
},
|
|
223
|
-
}
|
|
224
|
-
: {}),
|
|
225
|
-
...(error instanceof ProjectOpenError
|
|
226
|
-
? {
|
|
227
|
-
projectOpen: {
|
|
228
|
-
statePath: error.result.statePath,
|
|
229
|
-
failures: error.result.failures,
|
|
230
|
-
images: error.result.state.images,
|
|
231
|
-
},
|
|
232
|
-
}
|
|
233
|
-
: {}),
|
|
234
|
-
};
|
|
235
|
-
return {
|
|
236
|
-
ok: false,
|
|
237
|
-
error: error instanceof Error ? error.message : String(error),
|
|
238
|
-
diagnostics,
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
function routeCleanupResource(state) {
|
|
242
|
-
return {
|
|
243
|
-
kind: "route",
|
|
244
|
-
status: "planned",
|
|
245
|
-
id: state.targetId,
|
|
246
|
-
projectId: state.projectId,
|
|
247
|
-
workspaceId: state.workspaceId,
|
|
248
|
-
targetId: state.targetId,
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
function idempotentRouteCleanupReason(error) {
|
|
252
|
-
const message = errorMessage(error);
|
|
253
|
-
if (/\bfetch failed\b/i.test(message) ||
|
|
254
|
-
/\bECONNREFUSED\b/i.test(message) ||
|
|
255
|
-
/\bFailed to fetch\b/i.test(message) ||
|
|
256
|
-
/\bNo route is registered\b/i.test(message)) {
|
|
257
|
-
return `Route cleanup skipped because the route endpoint is already unreachable: ${message}`;
|
|
258
|
-
}
|
|
259
|
-
return undefined;
|
|
260
|
-
}
|
|
261
|
-
function assertLauncherOk(result, toolName) {
|
|
262
|
-
if (result && result.ok === false) {
|
|
263
|
-
throw new Error(`${toolName} returned ok: false`);
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
function cacheEntryStatusFromReadResult(readResult) {
|
|
267
|
-
const key = path.basename(path.dirname(readResult.manifestPath));
|
|
268
|
-
if (readResult.status === "ok") {
|
|
269
|
-
return {
|
|
270
|
-
key: readResult.manifest.key,
|
|
271
|
-
status: "ok",
|
|
272
|
-
manifestPath: readResult.manifestPath,
|
|
273
|
-
cacheImageName: readResult.manifest.cacheImageName,
|
|
274
|
-
preparationStatus: readResult.manifest.pharoMcp.preparationStatus,
|
|
275
|
-
supportStatus: readResult.manifest.pharoMcp.support.status,
|
|
276
|
-
createdAt: readResult.manifest.createdAt,
|
|
277
|
-
updatedAt: readResult.manifest.updatedAt,
|
|
278
|
-
};
|
|
279
|
-
}
|
|
280
|
-
return {
|
|
281
|
-
key,
|
|
282
|
-
status: readResult.status,
|
|
283
|
-
manifestPath: readResult.manifestPath,
|
|
284
|
-
...(readResult.status === "corrupt" ? { error: readResult.error } : {}),
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
function unwrapToolLikeResult(value) {
|
|
288
|
-
if (isObject(value) && typeof value.ok === "boolean") {
|
|
289
|
-
if (value.ok === false) {
|
|
290
|
-
throw new Error(typeof value.error === "string" ? value.error : "Tool call failed");
|
|
291
|
-
}
|
|
292
|
-
return value.data;
|
|
293
|
-
}
|
|
294
|
-
return value;
|
|
295
|
-
}
|
|
296
|
-
function textContent(value) {
|
|
297
|
-
if (!isObject(value) || !Array.isArray(value.content)) {
|
|
298
|
-
return undefined;
|
|
299
|
-
}
|
|
300
|
-
const item = value.content.find((candidate) => isObject(candidate) &&
|
|
301
|
-
candidate.type === "text" &&
|
|
302
|
-
typeof candidate.text === "string");
|
|
303
|
-
return item?.text;
|
|
304
|
-
}
|
|
305
|
-
function decodeMcpToolResult(value) {
|
|
306
|
-
const text = textContent(value);
|
|
307
|
-
if (text === undefined) {
|
|
308
|
-
return value;
|
|
309
|
-
}
|
|
310
|
-
try {
|
|
311
|
-
return JSON.parse(text);
|
|
312
|
-
}
|
|
313
|
-
catch {
|
|
314
|
-
return value;
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
function lifecycleReferenceFromInput(input) {
|
|
318
|
-
return {
|
|
319
|
-
projectId: input.projectId,
|
|
320
|
-
workspaceId: input.workspaceId,
|
|
321
|
-
targetId: input.targetId,
|
|
322
|
-
};
|
|
323
|
-
}
|
|
324
|
-
function lifecycleStatusFromRoute(route, includeDiagnostics = false) {
|
|
325
|
-
if (!isObject(route)) {
|
|
326
|
-
return includeDiagnostics ? { route } : {};
|
|
327
|
-
}
|
|
328
|
-
const statePath = typeof route.statePath === "string" ? route.statePath : undefined;
|
|
329
|
-
const state = statePath ? loadProjectState(statePath) : undefined;
|
|
330
|
-
const status = {
|
|
331
|
-
projectId: typeof route.projectId === "string" ? route.projectId : state?.projectId,
|
|
332
|
-
workspaceId: typeof route.workspaceId === "string"
|
|
333
|
-
? route.workspaceId
|
|
334
|
-
: state?.workspaceId,
|
|
335
|
-
targetId: typeof route.targetId === "string" ? route.targetId : state?.targetId,
|
|
336
|
-
};
|
|
337
|
-
if (!includeDiagnostics) {
|
|
338
|
-
return status;
|
|
339
|
-
}
|
|
340
|
-
return {
|
|
341
|
-
...status,
|
|
342
|
-
projectRoot: typeof route.projectRoot === "string" ? route.projectRoot : undefined,
|
|
343
|
-
statePath,
|
|
344
|
-
state,
|
|
345
|
-
...(state?.gateway ? { gateway: state.gateway } : {}),
|
|
346
|
-
route,
|
|
347
|
-
};
|
|
348
|
-
}
|
|
349
|
-
function errorMessage(error) {
|
|
350
|
-
return error instanceof Error ? error.message : String(error);
|
|
351
|
-
}
|
|
352
|
-
function mergePortClaimChecks(options) {
|
|
353
|
-
const defaults = defaultImagePortClaimChecks();
|
|
354
|
-
return {
|
|
355
|
-
isProcessAlive: options.checks?.isProcessAlive ?? defaults.isProcessAlive,
|
|
356
|
-
isPortListening: options.checks?.isPortListening ?? defaults.isPortListening,
|
|
357
|
-
};
|
|
358
|
-
}
|
|
359
|
-
function currentScopeMatchesClaim(claim, scope) {
|
|
360
|
-
return (claim.projectId === scope.projectId &&
|
|
361
|
-
claim.workspaceId === scope.workspaceId &&
|
|
362
|
-
claim.targetId === scope.targetId);
|
|
363
|
-
}
|
|
364
|
-
function portClaimDiagnostic(claimsRoot, inspection, scope) {
|
|
365
|
-
if (inspection.status === "unreadable") {
|
|
366
|
-
return {
|
|
367
|
-
claimsRoot,
|
|
368
|
-
port: inspection.port,
|
|
369
|
-
status: "unreadable",
|
|
370
|
-
reason: inspection.reason,
|
|
371
|
-
};
|
|
372
|
-
}
|
|
373
|
-
return {
|
|
374
|
-
claimsRoot,
|
|
375
|
-
port: inspection.port,
|
|
376
|
-
status: inspection.status,
|
|
377
|
-
record: inspection.record,
|
|
378
|
-
...(inspection.reason ? { reason: inspection.reason } : {}),
|
|
379
|
-
ownedByCurrentScope: currentScopeMatchesClaim(inspection.record, scope),
|
|
380
|
-
};
|
|
381
|
-
}
|
|
382
|
-
function addCurrentScopePortClaimDiagnostic(buckets, diagnostic) {
|
|
383
|
-
if (diagnostic.status === "stale") {
|
|
384
|
-
buckets.stale.push(diagnostic);
|
|
385
|
-
return;
|
|
386
|
-
}
|
|
387
|
-
buckets.active.push(diagnostic);
|
|
388
|
-
}
|
|
389
|
-
function addForeignScopePortClaimDiagnostic(buckets, diagnostic, currentScopePorts) {
|
|
390
|
-
if (!currentScopePorts.has(diagnostic.port)) {
|
|
391
|
-
buckets.otherScopes.push(diagnostic);
|
|
392
|
-
return;
|
|
393
|
-
}
|
|
394
|
-
if (diagnostic.status === "stale") {
|
|
395
|
-
buckets.stale.push(diagnostic);
|
|
396
|
-
return;
|
|
397
|
-
}
|
|
398
|
-
buckets.conflicts.push(diagnostic);
|
|
399
|
-
}
|
|
400
|
-
function addPortClaimDiagnostic(buckets, diagnostic, currentScopePorts) {
|
|
401
|
-
if (diagnostic.ownedByCurrentScope) {
|
|
402
|
-
addCurrentScopePortClaimDiagnostic(buckets, diagnostic);
|
|
403
|
-
return;
|
|
404
|
-
}
|
|
405
|
-
addForeignScopePortClaimDiagnostic(buckets, diagnostic, currentScopePorts);
|
|
406
|
-
}
|
|
407
|
-
async function inspectClaimRoots(claimsRoots, checks, scope, currentScopePorts) {
|
|
408
|
-
const active = [];
|
|
409
|
-
const stale = [];
|
|
410
|
-
const conflicts = [];
|
|
411
|
-
const otherScopes = [];
|
|
412
|
-
for (const claimsRoot of claimsRoots) {
|
|
413
|
-
const claims = await listPortClaims({ claimsRoot });
|
|
414
|
-
for (const claim of claims) {
|
|
415
|
-
const inspection = await inspectPortClaim({
|
|
416
|
-
claimsRoot,
|
|
417
|
-
port: claim.assignedPort,
|
|
418
|
-
checks,
|
|
419
|
-
});
|
|
420
|
-
if (inspection.status === "available") {
|
|
421
|
-
continue;
|
|
422
|
-
}
|
|
423
|
-
const diagnostic = portClaimDiagnostic(claimsRoot, inspection, scope);
|
|
424
|
-
addPortClaimDiagnostic({ active, stale, conflicts, otherScopes }, diagnostic, currentScopePorts);
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
return {
|
|
428
|
-
roots: claimsRoots,
|
|
429
|
-
active,
|
|
430
|
-
stale,
|
|
431
|
-
conflicts,
|
|
432
|
-
otherScopes,
|
|
433
|
-
};
|
|
434
|
-
}
|
|
435
|
-
function configuredClaimRoots(projectRoot, config, state) {
|
|
436
|
-
return [
|
|
437
|
-
imagePortClaimsRootForConfig(projectRoot, config),
|
|
438
|
-
state?.gateway?.claim?.claimsRoot,
|
|
439
|
-
].filter((value, index, values) => typeof value === "string" && values.indexOf(value) === index);
|
|
440
|
-
}
|
|
441
|
-
function projectDiagnostics(config, state) {
|
|
442
|
-
return {
|
|
443
|
-
declaredImageCount: config.images.length,
|
|
444
|
-
activeImageCount: config.images.filter((image) => image.active).length,
|
|
445
|
-
runtimeImageCount: state?.images.length ?? 0,
|
|
446
|
-
};
|
|
447
|
-
}
|
|
448
|
-
function remoteTopologyDiagnostics(config, runtime) {
|
|
449
|
-
const remoteNodes = runtime.remoteNodes ?? [];
|
|
450
|
-
return {
|
|
451
|
-
nodeId: runtime.nodeId ?? projectConfigId(config),
|
|
452
|
-
policy: "flat-tree",
|
|
453
|
-
status: remoteNodes.length === 0 ? "local-only" : "flat",
|
|
454
|
-
remoteNodeIds: remoteNodes.map((remoteNode) => remoteNode.id),
|
|
455
|
-
remoteNodes: remoteNodes.map((remoteNode) => ({
|
|
456
|
-
id: remoteNode.id,
|
|
457
|
-
...(remoteNode.parentNodeId
|
|
458
|
-
? { parentNodeId: remoteNode.parentNodeId }
|
|
459
|
-
: {}),
|
|
460
|
-
mappedWorkspaceIds: remoteNode.workspaces?.map((workspace) => workspace.workspaceId) ?? [],
|
|
461
|
-
})),
|
|
462
|
-
};
|
|
463
|
-
}
|
|
464
|
-
function imagePortPolicyDiagnostics(runtime, stateRoot, effectiveClaimsRoot) {
|
|
465
|
-
const coordination = runtime.imagePorts.coordination;
|
|
466
|
-
return {
|
|
467
|
-
allocation: runtime.imagePorts.allocation,
|
|
468
|
-
range: runtime.imagePorts.range,
|
|
469
|
-
coordinationMode: coordination.mode,
|
|
470
|
-
...(coordination.root ? { configuredRoot: coordination.root } : {}),
|
|
471
|
-
...(effectiveClaimsRoot ? { effectiveClaimsRoot } : {}),
|
|
472
|
-
projectStateRoot: stateRoot,
|
|
473
|
-
basis: effectiveClaimsRoot ? "host-local-claims" : "project-state",
|
|
474
|
-
};
|
|
475
|
-
}
|
|
476
|
-
function imagePortCoordinationDiagnostics(projectRoot, stateRoot, config) {
|
|
477
|
-
const coordination = resolveProjectRuntimePolicy(config).imagePorts.coordination;
|
|
478
|
-
if (coordination.mode === "host-local") {
|
|
479
|
-
const claimsRoot = imagePortClaimsRootForConfig(projectRoot, config);
|
|
480
|
-
return {
|
|
481
|
-
mode: "host-local",
|
|
482
|
-
basis: "host-local-claims",
|
|
483
|
-
message: "Image MCP ports are coordinated by host-local port claims across PLexus projects on this host.",
|
|
484
|
-
...(claimsRoot ? { claimsRoot } : {}),
|
|
485
|
-
};
|
|
486
|
-
}
|
|
487
|
-
return {
|
|
488
|
-
mode: "project-state",
|
|
489
|
-
basis: "project-state-scanning",
|
|
490
|
-
stateRoot,
|
|
491
|
-
message: "Image MCP ports are coordinated by scanning PLexus project state; this only protects workspaces sharing this state root.",
|
|
492
|
-
};
|
|
493
|
-
}
|
|
494
|
-
function repositoryWorkspaceCleanupDiagnostic(workspace, inspection) {
|
|
495
|
-
const lastDecision = workspace.cleanupState;
|
|
496
|
-
if (!inspection) {
|
|
497
|
-
return {
|
|
498
|
-
defaultPolicy: "preserve",
|
|
499
|
-
destructivePolicyRequired: true,
|
|
500
|
-
reviewRequired: false,
|
|
501
|
-
recommendedAction: "materialize",
|
|
502
|
-
message: "Repository workspace is planned; destructive cleanup is unavailable until it is materialized.",
|
|
503
|
-
...(lastDecision ? { lastDecision } : {}),
|
|
504
|
-
};
|
|
505
|
-
}
|
|
506
|
-
if (!inspection.exists) {
|
|
507
|
-
return {
|
|
508
|
-
defaultPolicy: "preserve",
|
|
509
|
-
destructivePolicyRequired: true,
|
|
510
|
-
reviewRequired: true,
|
|
511
|
-
recommendedAction: "materialize",
|
|
512
|
-
message: "Repository workspace path is missing.",
|
|
513
|
-
...(lastDecision ? { lastDecision } : {}),
|
|
514
|
-
};
|
|
515
|
-
}
|
|
516
|
-
if (!inspection.isGitRepository) {
|
|
517
|
-
return {
|
|
518
|
-
defaultPolicy: "preserve",
|
|
519
|
-
destructivePolicyRequired: true,
|
|
520
|
-
reviewRequired: true,
|
|
521
|
-
recommendedAction: "repair",
|
|
522
|
-
message: "Repository workspace path exists but is not a Git repository.",
|
|
523
|
-
...(lastDecision ? { lastDecision } : {}),
|
|
524
|
-
};
|
|
525
|
-
}
|
|
526
|
-
if (inspection.dirtyState === "dirty") {
|
|
527
|
-
return {
|
|
528
|
-
defaultPolicy: "preserve",
|
|
529
|
-
destructivePolicyRequired: true,
|
|
530
|
-
reviewRequired: true,
|
|
531
|
-
recommendedAction: "review",
|
|
532
|
-
message: "Repository workspace has uncommitted changes; preserve, archive, or hand off before deletion.",
|
|
533
|
-
...(lastDecision ? { lastDecision } : {}),
|
|
534
|
-
};
|
|
535
|
-
}
|
|
536
|
-
return {
|
|
537
|
-
defaultPolicy: "preserve",
|
|
538
|
-
destructivePolicyRequired: true,
|
|
539
|
-
reviewRequired: false,
|
|
540
|
-
recommendedAction: "none",
|
|
541
|
-
message: "Repository workspace is clean; destructive cleanup still requires an explicit policy.",
|
|
542
|
-
...(lastDecision ? { lastDecision } : {}),
|
|
543
|
-
};
|
|
544
|
-
}
|
|
545
|
-
function liveRepositoryWorkspaceState(workspace, inspection) {
|
|
546
|
-
if (!inspection) {
|
|
547
|
-
return workspace;
|
|
548
|
-
}
|
|
549
|
-
return {
|
|
550
|
-
...workspace,
|
|
551
|
-
path: inspection.path,
|
|
552
|
-
dirtyState: inspection.dirtyState,
|
|
553
|
-
diagnostics: [...workspace.diagnostics, ...inspection.diagnostics],
|
|
554
|
-
...(inspection.branch ? { branch: inspection.branch } : {}),
|
|
555
|
-
...(inspection.currentCommit
|
|
556
|
-
? { currentCommit: inspection.currentCommit }
|
|
557
|
-
: {}),
|
|
558
|
-
};
|
|
559
|
-
}
|
|
560
|
-
function repositoryWorkspaceDiagnostics(projectRoot, config, state, scope) {
|
|
561
|
-
return config.images
|
|
562
|
-
.flatMap((imageConfig) => {
|
|
563
|
-
const imageState = state?.images.find((image) => image.id === imageConfig.id);
|
|
564
|
-
const context = {
|
|
565
|
-
projectId: scope.projectId,
|
|
566
|
-
projectName: config.name,
|
|
567
|
-
workspaceId: scope.workspaceId,
|
|
568
|
-
targetId: scope.targetId,
|
|
569
|
-
imageId: imageConfig.id,
|
|
570
|
-
};
|
|
571
|
-
const workspaces = imageState
|
|
572
|
-
? projectImageRepositoryWorkspaces(imageState)
|
|
573
|
-
: projectImageRepositoryWorkspaceStates(imageConfig, context);
|
|
574
|
-
return workspaces.map((workspace) => {
|
|
575
|
-
const inspection = imageState
|
|
576
|
-
? inspectProjectImageRepositoryWorkspace({
|
|
577
|
-
projectRoot,
|
|
578
|
-
imageState,
|
|
579
|
-
workspace,
|
|
580
|
-
})
|
|
581
|
-
: undefined;
|
|
582
|
-
const liveWorkspace = liveRepositoryWorkspaceState(workspace, inspection);
|
|
583
|
-
return {
|
|
584
|
-
imageId: imageConfig.id,
|
|
585
|
-
imageName: imageState?.imageName ??
|
|
586
|
-
renderProjectImageName(imageConfig.imageName, context),
|
|
587
|
-
status: imageState?.status ?? "declared",
|
|
588
|
-
workspace: liveWorkspace,
|
|
589
|
-
cleanup: repositoryWorkspaceCleanupDiagnostic(liveWorkspace, inspection),
|
|
590
|
-
};
|
|
591
|
-
});
|
|
592
|
-
})
|
|
593
|
-
.filter((item) => item !== undefined);
|
|
594
|
-
}
|
|
595
|
-
function dependencyRepositoryDetachDiagnostics(state) {
|
|
596
|
-
return (state?.images ?? [])
|
|
597
|
-
.filter((image) => image.dependencyRepositoryDetach !== undefined)
|
|
598
|
-
.map((image) => ({
|
|
599
|
-
imageId: image.id,
|
|
600
|
-
imageName: image.imageName,
|
|
601
|
-
status: image.status,
|
|
602
|
-
detach: image.dependencyRepositoryDetach,
|
|
603
|
-
}));
|
|
604
|
-
}
|
|
605
|
-
function imageRecoveryDiagnostics(input) {
|
|
606
|
-
return (input.state?.images ?? [])
|
|
607
|
-
.filter((image) => image.status === "failed")
|
|
608
|
-
.map((image) => {
|
|
609
|
-
const actionBase = {
|
|
610
|
-
projectPath: input.projectRoot,
|
|
611
|
-
stateRoot: input.stateRoot,
|
|
612
|
-
workspaceId: input.workspaceId,
|
|
613
|
-
sourceImageId: image.id,
|
|
614
|
-
};
|
|
615
|
-
return {
|
|
616
|
-
imageId: image.id,
|
|
617
|
-
imageName: image.imageName,
|
|
618
|
-
status: image.status,
|
|
619
|
-
message: `Image ${image.id} is failed; use scoped rescue before raw cleanup.`,
|
|
620
|
-
paths: {
|
|
621
|
-
...(image.imagePath ? { imagePath: image.imagePath } : {}),
|
|
622
|
-
...(image.imageDirectoryPath
|
|
623
|
-
? { imageDirectoryPath: image.imageDirectoryPath }
|
|
624
|
-
: {}),
|
|
625
|
-
...(image.changesPath ? { changesPath: image.changesPath } : {}),
|
|
626
|
-
...(image.localDirectoryPath
|
|
627
|
-
? { localDirectoryPath: image.localDirectoryPath }
|
|
628
|
-
: {}),
|
|
629
|
-
...(image.ombuDirectoryPath
|
|
630
|
-
? { ombuDirectoryPath: image.ombuDirectoryPath }
|
|
631
|
-
: {}),
|
|
632
|
-
},
|
|
633
|
-
actions: [
|
|
634
|
-
{
|
|
635
|
-
operation: "plan",
|
|
636
|
-
toolName: "plexus_rescue_image",
|
|
637
|
-
arguments: {
|
|
638
|
-
...actionBase,
|
|
639
|
-
operation: "plan",
|
|
640
|
-
},
|
|
641
|
-
},
|
|
642
|
-
{
|
|
643
|
-
operation: "prepareTarget",
|
|
644
|
-
toolName: "plexus_rescue_image",
|
|
645
|
-
arguments: {
|
|
646
|
-
...actionBase,
|
|
647
|
-
operation: "prepareTarget",
|
|
648
|
-
},
|
|
649
|
-
},
|
|
650
|
-
],
|
|
651
|
-
};
|
|
652
|
-
});
|
|
653
|
-
}
|
|
654
|
-
function imageMcpPorts(state) {
|
|
655
|
-
return (state?.images ?? []).map((image) => ({
|
|
656
|
-
imageId: image.id,
|
|
657
|
-
imageName: image.imageName,
|
|
658
|
-
...(image.displayMode ? { displayMode: image.displayMode } : {}),
|
|
659
|
-
...(image.assignedPort !== undefined ? { port: image.assignedPort } : {}),
|
|
660
|
-
...(image.mcpServers ? { mcpServers: image.mcpServers } : {}),
|
|
661
|
-
routingMode: image.mcpServers?.length ? "endpoint" : "none",
|
|
662
|
-
status: image.status,
|
|
663
|
-
...(image.pid !== undefined ? { pid: image.pid } : {}),
|
|
664
|
-
}));
|
|
665
|
-
}
|
|
666
|
-
function registeredRouteStatePath(route) {
|
|
667
|
-
return isObject(route) && typeof route.statePath === "string"
|
|
668
|
-
? route.statePath
|
|
669
|
-
: undefined;
|
|
670
|
-
}
|
|
671
|
-
function sameResolvedPath(left, right) {
|
|
672
|
-
return (left !== undefined &&
|
|
673
|
-
right !== undefined &&
|
|
674
|
-
path.resolve(left) === path.resolve(right));
|
|
675
|
-
}
|
|
676
|
-
function routeTableDiagnostics(targetId, route, routeError, expectedStatePath, gatewayReconciliation) {
|
|
677
|
-
if (!targetId) {
|
|
678
|
-
return {
|
|
679
|
-
status: "not-configured",
|
|
680
|
-
routableImages: [],
|
|
681
|
-
};
|
|
682
|
-
}
|
|
683
|
-
if (gatewayReconciliation?.status === "dead") {
|
|
684
|
-
return {
|
|
685
|
-
targetId,
|
|
686
|
-
status: "gateway-dead",
|
|
687
|
-
routableImages: [],
|
|
688
|
-
error: gatewayReconciliation.reason,
|
|
689
|
-
};
|
|
690
|
-
}
|
|
691
|
-
if (routeError) {
|
|
692
|
-
const message = errorMessage(routeError);
|
|
693
|
-
return {
|
|
694
|
-
targetId,
|
|
695
|
-
status: message.includes("No route is registered")
|
|
696
|
-
? "missing"
|
|
697
|
-
: "unavailable",
|
|
698
|
-
routableImages: [],
|
|
699
|
-
error: message,
|
|
700
|
-
};
|
|
701
|
-
}
|
|
702
|
-
if (!isObject(route)) {
|
|
703
|
-
return {
|
|
704
|
-
targetId,
|
|
705
|
-
status: "not-configured",
|
|
706
|
-
routableImages: [],
|
|
707
|
-
};
|
|
708
|
-
}
|
|
709
|
-
const images = Array.isArray(route.images) ? route.images : [];
|
|
710
|
-
const statePath = registeredRouteStatePath(route);
|
|
711
|
-
const statePathMismatch = statePath !== undefined &&
|
|
712
|
-
expectedStatePath !== undefined &&
|
|
713
|
-
!sameResolvedPath(statePath, expectedStatePath);
|
|
714
|
-
const routableImages = images
|
|
715
|
-
.filter(isObject)
|
|
716
|
-
.map((image) => {
|
|
717
|
-
const endpoint = isProjectImageMcpEndpoint(image.endpoint)
|
|
718
|
-
? image.endpoint
|
|
719
|
-
: undefined;
|
|
720
|
-
const routingMode = endpoint ? "endpoint" : "none";
|
|
721
|
-
return {
|
|
722
|
-
imageId: typeof image.id === "string" ? image.id : "",
|
|
723
|
-
...(typeof image.mcpServerId === "string"
|
|
724
|
-
? { mcpServerId: image.mcpServerId }
|
|
725
|
-
: {}),
|
|
726
|
-
...(typeof image.port === "number" ? { port: image.port } : {}),
|
|
727
|
-
...(endpoint ? { endpoint } : {}),
|
|
728
|
-
routingMode,
|
|
729
|
-
...(typeof image.status === "string" ? { status: image.status } : {}),
|
|
730
|
-
...(statePathMismatch
|
|
731
|
-
? {
|
|
732
|
-
routable: {
|
|
733
|
-
ok: false,
|
|
734
|
-
code: "image_unavailable",
|
|
735
|
-
message: "Registered gateway route uses a different PLexus runtime state path",
|
|
736
|
-
},
|
|
737
|
-
}
|
|
738
|
-
: "routable" in image
|
|
739
|
-
? { routable: image.routable }
|
|
740
|
-
: {}),
|
|
741
|
-
};
|
|
742
|
-
});
|
|
743
|
-
return {
|
|
744
|
-
targetId,
|
|
745
|
-
status: statePathMismatch ? "unavailable" : "registered",
|
|
746
|
-
...(statePath ? { statePath } : {}),
|
|
747
|
-
...(statePathMismatch && expectedStatePath ? { expectedStatePath } : {}),
|
|
748
|
-
...(statePathMismatch
|
|
749
|
-
? {
|
|
750
|
-
error: `Registered gateway route state path ${statePath} does not match ` +
|
|
751
|
-
`selected lifecycle state path ${expectedStatePath}`,
|
|
752
|
-
}
|
|
753
|
-
: {}),
|
|
754
|
-
routableImages,
|
|
755
|
-
};
|
|
756
|
-
}
|
|
757
|
-
function gatewayRepairAffordance(input) {
|
|
758
|
-
return {
|
|
759
|
-
allowed: true,
|
|
760
|
-
toolName: "plexus_project_open",
|
|
761
|
-
arguments: {
|
|
762
|
-
projectPath: input.projectRoot,
|
|
763
|
-
stateRoot: input.stateRoot,
|
|
764
|
-
workspaceId: input.workspaceId,
|
|
765
|
-
targetId: input.targetId,
|
|
766
|
-
},
|
|
767
|
-
reason: "Reopen the scoped project to start a fresh project-local gateway and re-register routes.",
|
|
768
|
-
};
|
|
769
|
-
}
|
|
770
|
-
function gatewayWithoutRuntimeIdentity(gateway) {
|
|
771
|
-
if (gateway.mode !== "project-local" || !gateway.managedByProject) {
|
|
772
|
-
return gateway;
|
|
773
|
-
}
|
|
774
|
-
const result = { ...gateway };
|
|
775
|
-
delete result.endpoint;
|
|
776
|
-
delete result.controlEndpoint;
|
|
777
|
-
delete result.pid;
|
|
778
|
-
delete result.claim;
|
|
779
|
-
return result;
|
|
780
|
-
}
|
|
781
|
-
function staleGatewayRuntimeIdentity(stale) {
|
|
782
|
-
return {
|
|
783
|
-
...(stale.endpoint ? { endpoint: stale.endpoint } : {}),
|
|
784
|
-
...(stale.controlEndpoint
|
|
785
|
-
? { controlEndpoint: stale.controlEndpoint }
|
|
786
|
-
: {}),
|
|
787
|
-
...(stale.port !== undefined ? { port: stale.port } : {}),
|
|
788
|
-
...(stale.pid !== undefined ? { pid: stale.pid } : {}),
|
|
789
|
-
...(stale.claim ? { claim: stale.claim } : {}),
|
|
790
|
-
};
|
|
791
|
-
}
|
|
792
|
-
function staleGatewayDiagnostic(reconciliation, repair) {
|
|
793
|
-
const stale = reconciliation.staleGateway;
|
|
794
|
-
return {
|
|
795
|
-
mode: stale.mode,
|
|
796
|
-
status: "dead",
|
|
797
|
-
health: "degraded",
|
|
798
|
-
reason: reconciliation.reason,
|
|
799
|
-
host: stale.host,
|
|
800
|
-
portRange: stale.portRange,
|
|
801
|
-
managedByProject: stale.managedByProject,
|
|
802
|
-
stale: staleGatewayRuntimeIdentity(stale),
|
|
803
|
-
repair,
|
|
804
|
-
};
|
|
805
|
-
}
|
|
806
|
-
function gatewayDiagnosticStatus(gateway) {
|
|
807
|
-
if (gateway.mode === "shared") {
|
|
808
|
-
return "shared";
|
|
809
|
-
}
|
|
810
|
-
return gateway.endpoint && gateway.controlEndpoint ? "running" : "not-started";
|
|
811
|
-
}
|
|
812
|
-
function gatewayDiagnosticHealth(status) {
|
|
813
|
-
return status === "not-started" ? "unknown" : "operational";
|
|
814
|
-
}
|
|
815
|
-
function gatewayDiagnosticReason(status) {
|
|
816
|
-
return status === "not-started"
|
|
817
|
-
? "No project-local gateway endpoint is recorded for this scope yet."
|
|
818
|
-
: "Gateway state is available for this scope.";
|
|
819
|
-
}
|
|
820
|
-
function gatewayDiagnostic(gateway, reconciliation, repair) {
|
|
821
|
-
if (reconciliation) {
|
|
822
|
-
return staleGatewayDiagnostic(reconciliation, repair);
|
|
823
|
-
}
|
|
824
|
-
const status = gatewayDiagnosticStatus(gateway);
|
|
825
|
-
return {
|
|
826
|
-
mode: gateway.mode,
|
|
827
|
-
status,
|
|
828
|
-
health: gatewayDiagnosticHealth(status),
|
|
829
|
-
reason: gatewayDiagnosticReason(status),
|
|
830
|
-
endpoint: gateway.endpoint,
|
|
831
|
-
controlEndpoint: gateway.controlEndpoint,
|
|
832
|
-
host: gateway.host,
|
|
833
|
-
port: gateway.port,
|
|
834
|
-
portRange: gateway.portRange,
|
|
835
|
-
managedByProject: gateway.managedByProject,
|
|
836
|
-
pid: gateway.pid,
|
|
837
|
-
...(status === "not-started" ? { repair } : {}),
|
|
838
|
-
};
|
|
839
|
-
}
|
|
840
|
-
function expectedPortClaims(portClaims) {
|
|
841
|
-
return new Set(portClaims.active.map((claim) => claim.port));
|
|
842
|
-
}
|
|
843
|
-
function currentScopeClaimPorts(config, state, gateway) {
|
|
844
|
-
const ports = new Set();
|
|
845
|
-
if (gateway.port !== undefined) {
|
|
846
|
-
ports.add(gateway.port);
|
|
847
|
-
}
|
|
848
|
-
if (gateway.claim?.assignedPort !== undefined) {
|
|
849
|
-
ports.add(gateway.claim.assignedPort);
|
|
850
|
-
}
|
|
851
|
-
for (const image of state?.images ?? []) {
|
|
852
|
-
if (image.assignedPort !== undefined) {
|
|
853
|
-
ports.add(image.assignedPort);
|
|
854
|
-
}
|
|
855
|
-
}
|
|
856
|
-
for (const image of config.images) {
|
|
857
|
-
if (image.mcp.port !== undefined) {
|
|
858
|
-
ports.add(image.mcp.port);
|
|
859
|
-
}
|
|
860
|
-
}
|
|
861
|
-
return ports;
|
|
862
|
-
}
|
|
863
|
-
async function conflictingListenerDiagnostics(state, gateway, portClaims, checks) {
|
|
864
|
-
const ownedClaimPorts = expectedPortClaims(portClaims);
|
|
865
|
-
const diagnostics = [];
|
|
866
|
-
for (const image of state?.images ?? []) {
|
|
867
|
-
if (image.assignedPort === undefined) {
|
|
868
|
-
continue;
|
|
869
|
-
}
|
|
870
|
-
const listening = Boolean(await checks.isPortListening?.(image.assignedPort));
|
|
871
|
-
if (listening &&
|
|
872
|
-
image.status !== "running" &&
|
|
873
|
-
!ownedClaimPorts.has(image.assignedPort)) {
|
|
874
|
-
diagnostics.push({
|
|
875
|
-
port: image.assignedPort,
|
|
876
|
-
purpose: "image-mcp",
|
|
877
|
-
imageId: image.id,
|
|
878
|
-
expectedOwner: `image ${image.id}`,
|
|
879
|
-
message: `Image MCP port ${image.assignedPort} has a listener but the ` +
|
|
880
|
-
`project image ${image.id} is ${image.status} and has no active owned claim.`,
|
|
881
|
-
});
|
|
882
|
-
}
|
|
883
|
-
}
|
|
884
|
-
if (gateway.port !== undefined) {
|
|
885
|
-
const listening = Boolean(await checks.isPortListening?.(gateway.port));
|
|
886
|
-
if (listening &&
|
|
887
|
-
gateway.managedByProject &&
|
|
888
|
-
!ownedClaimPorts.has(gateway.port)) {
|
|
889
|
-
diagnostics.push({
|
|
890
|
-
port: gateway.port,
|
|
891
|
-
purpose: "gateway",
|
|
892
|
-
expectedOwner: "project-local gateway",
|
|
893
|
-
message: `Gateway port ${gateway.port} has a listener but no active owned claim.`,
|
|
894
|
-
});
|
|
895
|
-
}
|
|
896
|
-
}
|
|
897
|
-
return diagnostics;
|
|
898
|
-
}
|
|
899
|
-
async function reconcileDeadProjectGatewayState(input) {
|
|
900
|
-
const stateGateway = input.state?.gateway;
|
|
901
|
-
const gateway = stateGateway ?? input.gateway;
|
|
902
|
-
if (!input.state ||
|
|
903
|
-
!gateway ||
|
|
904
|
-
gateway.mode !== "project-local" ||
|
|
905
|
-
!gateway.managedByProject) {
|
|
906
|
-
return undefined;
|
|
907
|
-
}
|
|
908
|
-
const runtimeStateNeedsGateway = input.state.runtimeStatus === "running" ||
|
|
909
|
-
runtimeStatusForImages(input.state.images) === "running" ||
|
|
910
|
-
stateHasRunningRoutableImage(input.state);
|
|
911
|
-
if (!stateGateway && !runtimeStateNeedsGateway) {
|
|
912
|
-
return undefined;
|
|
913
|
-
}
|
|
914
|
-
const port = gateway.port ?? gateway.claim?.assignedPort;
|
|
915
|
-
const portListening = port === undefined ? false : Boolean(await input.checks.isPortListening?.(port));
|
|
916
|
-
let claimInspection;
|
|
917
|
-
if (gateway.claim) {
|
|
918
|
-
claimInspection = await inspectPortClaim({
|
|
919
|
-
claimsRoot: gateway.claim.claimsRoot,
|
|
920
|
-
port: gateway.claim.assignedPort,
|
|
921
|
-
checks: input.checks,
|
|
922
|
-
});
|
|
923
|
-
}
|
|
924
|
-
const claimShowsDeadProcess = claimInspection?.status === "stale" &&
|
|
925
|
-
claimInspection.reason === "process-dead";
|
|
926
|
-
const claimMissingOrStale = claimInspection?.status === "available" ||
|
|
927
|
-
claimInspection?.status === "stale";
|
|
928
|
-
const gatewayIsDead = !portListening &&
|
|
929
|
-
(claimShowsDeadProcess ||
|
|
930
|
-
(gateway.pid === undefined && port !== undefined) ||
|
|
931
|
-
claimMissingOrStale);
|
|
932
|
-
if (!gatewayIsDead) {
|
|
933
|
-
return undefined;
|
|
934
|
-
}
|
|
935
|
-
let releasedClaim = false;
|
|
936
|
-
if (stateGateway?.claim) {
|
|
937
|
-
const release = await releasePortClaim({
|
|
938
|
-
claimsRoot: stateGateway.claim.claimsRoot,
|
|
939
|
-
claim: {
|
|
940
|
-
claimId: stateGateway.claim.claimId,
|
|
941
|
-
assignedPort: stateGateway.claim.assignedPort,
|
|
942
|
-
},
|
|
943
|
-
});
|
|
944
|
-
releasedClaim = release.released;
|
|
945
|
-
}
|
|
946
|
-
if (stateGateway) {
|
|
947
|
-
delete input.state.gateway;
|
|
948
|
-
input.state.updatedAt = input.now().toISOString();
|
|
949
|
-
saveProjectState(input.statePath, input.state);
|
|
950
|
-
}
|
|
951
|
-
return {
|
|
952
|
-
status: "dead",
|
|
953
|
-
reason: "Recorded project-local gateway state is dead: the owned gateway port is not listening and its managed claim is stale or missing.",
|
|
954
|
-
staleGateway: gateway,
|
|
955
|
-
releasedClaim,
|
|
956
|
-
};
|
|
957
|
-
}
|
|
958
|
-
function runtimeDiagnostics(state, gateway, portClaims, conflictingListeners, routeTable, gatewayReconciliation) {
|
|
959
|
-
if (!state) {
|
|
960
|
-
return {
|
|
961
|
-
status: "not-opened",
|
|
962
|
-
health: "unknown",
|
|
963
|
-
reason: "No project runtime state exists for this workspace yet.",
|
|
964
|
-
};
|
|
965
|
-
}
|
|
966
|
-
if (gatewayReconciliation?.status === "dead") {
|
|
967
|
-
return {
|
|
968
|
-
status: "degraded",
|
|
969
|
-
health: "degraded",
|
|
970
|
-
reason: "Runtime state exists, but the recorded project-local gateway is dead. Reopen the project to repair gateway routing.",
|
|
971
|
-
};
|
|
972
|
-
}
|
|
973
|
-
if (portClaims.stale.length > 0 ||
|
|
974
|
-
portClaims.conflicts.length > 0 ||
|
|
975
|
-
conflictingListeners.length > 0 ||
|
|
976
|
-
routeTable.status === "missing" ||
|
|
977
|
-
routeTable.status === "unavailable" ||
|
|
978
|
-
routeTable.status === "gateway-dead" ||
|
|
979
|
-
!gateway.endpoint ||
|
|
980
|
-
!gateway.controlEndpoint) {
|
|
981
|
-
return {
|
|
982
|
-
status: "degraded",
|
|
983
|
-
health: "degraded",
|
|
984
|
-
reason: "Runtime state exists, but diagnostics found stale claims, conflicts, route-table gaps, or incomplete gateway endpoints.",
|
|
985
|
-
};
|
|
986
|
-
}
|
|
987
|
-
if (state.images.length === 0 && runtimeStatusForImages(state.images) === "idle") {
|
|
988
|
-
return {
|
|
989
|
-
status: "idle",
|
|
990
|
-
health: "operational",
|
|
991
|
-
reason: "Runtime scope, gateway endpoints, and route table are valid; no images are declared for this project.",
|
|
992
|
-
};
|
|
993
|
-
}
|
|
994
|
-
return {
|
|
995
|
-
status: "operational",
|
|
996
|
-
health: "operational",
|
|
997
|
-
reason: "Runtime scope has valid gateway and route diagnostics.",
|
|
998
|
-
};
|
|
999
|
-
}
|
|
1000
|
-
export class HttpGatewayRouteRegistry {
|
|
1001
|
-
url;
|
|
1002
|
-
timeoutMs;
|
|
1003
|
-
fetchFn;
|
|
1004
|
-
constructor(options = {}) {
|
|
1005
|
-
const host = options.host ?? "127.0.0.1";
|
|
1006
|
-
const port = options.port ?? 7331;
|
|
1007
|
-
const mcpPath = options.path ?? defaultGatewayRouteControlMcpPath;
|
|
1008
|
-
this.url = options.url ?? `http://${host}:${port}${mcpPath}`;
|
|
1009
|
-
this.timeoutMs = options.timeoutMs ?? 10_000;
|
|
1010
|
-
this.fetchFn = options.fetch ?? fetch;
|
|
1011
|
-
}
|
|
1012
|
-
registerProjectRoute(input) {
|
|
1013
|
-
return this.callTool("plexus_gateway_register_target", input);
|
|
1014
|
-
}
|
|
1015
|
-
unregisterProjectRoute(input) {
|
|
1016
|
-
return this.callTool("plexus_gateway_unregister_target", input);
|
|
1017
|
-
}
|
|
1018
|
-
getRouteStatus(input) {
|
|
1019
|
-
return this.callTool("plexus_gateway_status", input);
|
|
1020
|
-
}
|
|
1021
|
-
async callTool(name, argumentsValue) {
|
|
1022
|
-
const controller = new AbortController();
|
|
1023
|
-
const timeout = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
1024
|
-
try {
|
|
1025
|
-
const response = await this.fetchFn(this.url, {
|
|
1026
|
-
method: "POST",
|
|
1027
|
-
headers: {
|
|
1028
|
-
accept: "application/json, text/event-stream",
|
|
1029
|
-
"content-type": "application/json",
|
|
1030
|
-
},
|
|
1031
|
-
body: JSON.stringify({
|
|
1032
|
-
jsonrpc: "2.0",
|
|
1033
|
-
id: `plexus-core-${Date.now()}`,
|
|
1034
|
-
method: "tools/call",
|
|
1035
|
-
params: {
|
|
1036
|
-
name,
|
|
1037
|
-
arguments: argumentsValue,
|
|
1038
|
-
},
|
|
1039
|
-
}),
|
|
1040
|
-
signal: controller.signal,
|
|
1041
|
-
});
|
|
1042
|
-
if (!response.ok) {
|
|
1043
|
-
throw new Error(`Gateway MCP request failed with HTTP ${response.status}`);
|
|
1044
|
-
}
|
|
1045
|
-
const payload = (await response.json());
|
|
1046
|
-
if (!isObject(payload)) {
|
|
1047
|
-
throw new Error("Gateway MCP response was not a JSON object");
|
|
1048
|
-
}
|
|
1049
|
-
if ("error" in payload) {
|
|
1050
|
-
throw new Error(JSON.stringify(payload.error));
|
|
1051
|
-
}
|
|
1052
|
-
return unwrapToolLikeResult(decodeMcpToolResult(payload.result));
|
|
1053
|
-
}
|
|
1054
|
-
finally {
|
|
1055
|
-
clearTimeout(timeout);
|
|
1056
|
-
}
|
|
1057
|
-
}
|
|
1058
|
-
}
|
|
1059
|
-
export class HttpProjectLifecycleClient {
|
|
1060
|
-
url;
|
|
1061
|
-
timeoutMs;
|
|
1062
|
-
fetchFn;
|
|
1063
|
-
constructor(options) {
|
|
1064
|
-
this.url = options.url;
|
|
1065
|
-
this.timeoutMs = options.timeoutMs ?? 10_000;
|
|
1066
|
-
this.fetchFn = options.fetch ?? fetch;
|
|
1067
|
-
}
|
|
1068
|
-
async callTool(name, argumentsValue) {
|
|
1069
|
-
const controller = new AbortController();
|
|
1070
|
-
const timeout = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
1071
|
-
try {
|
|
1072
|
-
const response = await this.fetchFn(this.url, {
|
|
1073
|
-
method: "POST",
|
|
1074
|
-
headers: {
|
|
1075
|
-
accept: "application/json, text/event-stream",
|
|
1076
|
-
"content-type": "application/json",
|
|
1077
|
-
},
|
|
1078
|
-
body: JSON.stringify({
|
|
1079
|
-
jsonrpc: "2.0",
|
|
1080
|
-
id: `plexus-project-${Date.now()}`,
|
|
1081
|
-
method: "tools/call",
|
|
1082
|
-
params: {
|
|
1083
|
-
name,
|
|
1084
|
-
arguments: argumentsValue,
|
|
1085
|
-
},
|
|
1086
|
-
}),
|
|
1087
|
-
signal: controller.signal,
|
|
1088
|
-
});
|
|
1089
|
-
if (!response.ok) {
|
|
1090
|
-
throw new Error(`Remote project MCP request failed with HTTP ${response.status}`);
|
|
1091
|
-
}
|
|
1092
|
-
const payload = (await response.json());
|
|
1093
|
-
if (!isObject(payload)) {
|
|
1094
|
-
throw new Error("Remote project MCP response was not a JSON object");
|
|
1095
|
-
}
|
|
1096
|
-
if ("error" in payload) {
|
|
1097
|
-
throw new Error(JSON.stringify(payload.error));
|
|
1098
|
-
}
|
|
1099
|
-
const decoded = decodeMcpToolResult(payload.result);
|
|
1100
|
-
if (isObject(decoded) && typeof decoded.ok === "boolean") {
|
|
1101
|
-
return decoded;
|
|
1102
|
-
}
|
|
1103
|
-
return {
|
|
1104
|
-
ok: true,
|
|
1105
|
-
data: decoded,
|
|
1106
|
-
};
|
|
1107
|
-
}
|
|
1108
|
-
finally {
|
|
1109
|
-
clearTimeout(timeout);
|
|
1110
|
-
}
|
|
1111
|
-
}
|
|
1112
|
-
}
|
|
1113
|
-
function gatewayHasExplicitPharoTools(gateway) {
|
|
1114
|
-
if (gateway?.pharoTools !== undefined) {
|
|
1115
|
-
return true;
|
|
1116
|
-
}
|
|
1117
|
-
const value = gateway?.env?.PLEXUS_PHARO_TOOLS_JSON;
|
|
1118
|
-
if (value === undefined || value.trim().length === 0) {
|
|
1119
|
-
return false;
|
|
1120
|
-
}
|
|
1121
|
-
try {
|
|
1122
|
-
const parsed = JSON.parse(value);
|
|
1123
|
-
return Array.isArray(parsed) && parsed.length > 0;
|
|
1124
|
-
}
|
|
1125
|
-
catch {
|
|
1126
|
-
return true;
|
|
1127
|
-
}
|
|
1128
|
-
}
|
|
1129
|
-
function imageMcpEndpointForToolDiscovery(image) {
|
|
1130
|
-
if (image.status !== "running") {
|
|
1131
|
-
return undefined;
|
|
1132
|
-
}
|
|
1133
|
-
return image.mcpServers?.find((server) => server.id === image.id)?.endpoint;
|
|
1134
|
-
}
|
|
1135
|
-
function stateHasRunningRoutableImage(state) {
|
|
1136
|
-
return state.images.some((image) => image.status === "running" &&
|
|
1137
|
-
Boolean(image.mcpServers?.length));
|
|
1138
|
-
}
|
|
1139
|
-
function hostForUrl(host) {
|
|
1140
|
-
return host.includes(":") && !host.startsWith("[") ? `[${host}]` : host;
|
|
1141
|
-
}
|
|
1142
|
-
function imageMcpEndpointUrl(endpoint) {
|
|
1143
|
-
return `http://${hostForUrl(endpoint.host)}:${endpoint.port}${endpoint.path}`;
|
|
1144
|
-
}
|
|
1145
|
-
function remoteGatewayEndpointFromUrl(value) {
|
|
1146
|
-
const url = new URL(value);
|
|
1147
|
-
if (url.protocol !== "http:") {
|
|
1148
|
-
throw new ProjectLifecycleInputError(`Remote gateway MCP URL must use http for PLexus gateway forwarding: ${value}`);
|
|
1149
|
-
}
|
|
1150
|
-
const port = url.port ? Number(url.port) : 80;
|
|
1151
|
-
if (!Number.isInteger(port) || port < 1 || port > 65_535) {
|
|
1152
|
-
throw new ProjectLifecycleInputError(`Remote gateway MCP URL must include a valid port: ${value}`);
|
|
1153
|
-
}
|
|
1154
|
-
return {
|
|
1155
|
-
transport: "http",
|
|
1156
|
-
host: url.hostname,
|
|
1157
|
-
port,
|
|
1158
|
-
path: url.pathname || "/",
|
|
1159
|
-
};
|
|
1160
|
-
}
|
|
1161
|
-
function toolFromMcpListItem(value, index) {
|
|
1162
|
-
if (!isObject(value) || typeof value.name !== "string") {
|
|
1163
|
-
throw new Error(`MCP tools/list returned an invalid tool at index ${index}`);
|
|
1164
|
-
}
|
|
1165
|
-
if (!isObject(value.inputSchema)) {
|
|
1166
|
-
throw new Error(`MCP tools/list returned tool ${value.name} without an inputSchema object`);
|
|
1167
|
-
}
|
|
1168
|
-
return value;
|
|
1169
|
-
}
|
|
1170
|
-
async function fetchPharoMcpTools(options) {
|
|
1171
|
-
const controller = new AbortController();
|
|
1172
|
-
const timeout = setTimeout(() => controller.abort(), options.timeoutMs);
|
|
1173
|
-
try {
|
|
1174
|
-
const response = await options.fetchFn(imageMcpEndpointUrl(options.endpoint), {
|
|
1175
|
-
method: "POST",
|
|
1176
|
-
headers: {
|
|
1177
|
-
accept: "application/json, text/event-stream",
|
|
1178
|
-
"content-type": "application/json",
|
|
1179
|
-
},
|
|
1180
|
-
body: JSON.stringify({
|
|
1181
|
-
jsonrpc: "2.0",
|
|
1182
|
-
id: `plexus-tools-list-${Date.now()}`,
|
|
1183
|
-
method: "tools/list",
|
|
1184
|
-
}),
|
|
1185
|
-
signal: controller.signal,
|
|
1186
|
-
});
|
|
1187
|
-
if (!response.ok) {
|
|
1188
|
-
throw new Error(`MCP tools/list failed with HTTP ${response.status}`);
|
|
1189
|
-
}
|
|
1190
|
-
const payload = (await response.json());
|
|
1191
|
-
if (!isObject(payload)) {
|
|
1192
|
-
throw new Error("MCP tools/list response was not a JSON object");
|
|
1193
|
-
}
|
|
1194
|
-
if ("error" in payload) {
|
|
1195
|
-
throw new Error(JSON.stringify(payload.error));
|
|
1196
|
-
}
|
|
1197
|
-
const result = payload.result;
|
|
1198
|
-
if (!isObject(result) || !Array.isArray(result.tools)) {
|
|
1199
|
-
throw new Error("MCP tools/list response did not include result.tools");
|
|
1200
|
-
}
|
|
1201
|
-
return result.tools.map((tool, index) => toolFromMcpListItem(tool, index));
|
|
1202
|
-
}
|
|
1203
|
-
finally {
|
|
1204
|
-
clearTimeout(timeout);
|
|
1205
|
-
}
|
|
1206
|
-
}
|
|
1207
|
-
async function discoverPharoMcpToolsFromRunningImages(options) {
|
|
1208
|
-
const errors = [];
|
|
1209
|
-
let attempted = false;
|
|
1210
|
-
for (const image of options.state.images) {
|
|
1211
|
-
const endpoint = imageMcpEndpointForToolDiscovery(image);
|
|
1212
|
-
if (!endpoint) {
|
|
1213
|
-
continue;
|
|
1214
|
-
}
|
|
1215
|
-
attempted = true;
|
|
1216
|
-
try {
|
|
1217
|
-
const tools = await fetchPharoMcpTools({
|
|
1218
|
-
endpoint,
|
|
1219
|
-
fetchFn: options.fetchFn,
|
|
1220
|
-
timeoutMs: options.timeoutMs ?? defaultPharoToolsDiscoveryTimeoutMs,
|
|
1221
|
-
});
|
|
1222
|
-
if (tools.length > 0) {
|
|
1223
|
-
return tools;
|
|
1224
|
-
}
|
|
1225
|
-
errors.push(`${image.id}: MCP tools/list returned no tools`);
|
|
1226
|
-
}
|
|
1227
|
-
catch (error) {
|
|
1228
|
-
errors.push(`${image.id}: ${error instanceof Error ? error.message : String(error)}`);
|
|
1229
|
-
}
|
|
1230
|
-
}
|
|
1231
|
-
if (attempted) {
|
|
1232
|
-
throw new Error(`Unable to discover Pharo MCP tools from running project images: ${errors.join("; ")}`);
|
|
1233
|
-
}
|
|
1234
|
-
return undefined;
|
|
1235
|
-
}
|
|
1236
|
-
function remoteLifecycleMappingForInput(config, projectRoot, input) {
|
|
1237
|
-
const runtime = resolveProjectRuntimePolicy(config);
|
|
1238
|
-
const remoteNodes = runtime.remoteNodes ?? [];
|
|
1239
|
-
if (remoteNodes.length === 0) {
|
|
1240
|
-
return undefined;
|
|
1241
|
-
}
|
|
1242
|
-
const workspaceId = input.workspaceId
|
|
1243
|
-
? sanitizeRuntimeId(input.workspaceId)
|
|
1244
|
-
: defaultWorkspaceId(projectRoot);
|
|
1245
|
-
for (const remoteNode of remoteNodes) {
|
|
1246
|
-
for (const workspace of remoteNode.workspaces ?? []) {
|
|
1247
|
-
const mapping = remoteLifecycleMappingForWorkspace(remoteNode, workspace, workspaceId, input.targetId);
|
|
1248
|
-
if (mapping) {
|
|
1249
|
-
return mapping;
|
|
1250
|
-
}
|
|
1251
|
-
}
|
|
1252
|
-
}
|
|
1253
|
-
return undefined;
|
|
1254
|
-
}
|
|
1255
|
-
function remoteLifecycleArguments(input, mapping) {
|
|
1256
|
-
const projectPath = mapping.workspace?.remoteProjectPath ?? input.projectPath;
|
|
1257
|
-
const workspaceId = mapping.workspace?.remoteWorkspaceId ??
|
|
1258
|
-
input.workspaceId ??
|
|
1259
|
-
mapping.workspaceId;
|
|
1260
|
-
const targetId = mapping.target?.remoteTargetId ?? input.targetId;
|
|
1261
|
-
return Object.fromEntries(Object.entries({
|
|
1262
|
-
...input,
|
|
1263
|
-
projectPath,
|
|
1264
|
-
stateRoot: undefined,
|
|
1265
|
-
workspaceId,
|
|
1266
|
-
targetId,
|
|
1267
|
-
}).filter(([, value]) => value !== undefined));
|
|
1268
|
-
}
|
|
1269
|
-
function hostRemoteRouteContext(input, mapping) {
|
|
1270
|
-
const projectRoot = path.resolve(input.projectPath);
|
|
1271
|
-
const config = loadProjectConfig(projectRoot);
|
|
1272
|
-
const projectId = projectConfigId(config);
|
|
1273
|
-
const workspaceId = mapping.workspaceId;
|
|
1274
|
-
const targetId = input.targetId ?? defaultTargetId(projectId, workspaceId);
|
|
1275
|
-
const stateRoot = projectStateRootForConfig(config, input.stateRoot) ??
|
|
1276
|
-
defaultPlexusStateRoot(projectRoot);
|
|
1277
|
-
const statePath = projectStatePathForConfig({
|
|
1278
|
-
projectRoot,
|
|
1279
|
-
config,
|
|
1280
|
-
workspaceId,
|
|
1281
|
-
stateRoot,
|
|
1282
|
-
});
|
|
1283
|
-
return {
|
|
1284
|
-
projectRoot,
|
|
1285
|
-
config,
|
|
1286
|
-
stateRoot,
|
|
1287
|
-
statePath,
|
|
1288
|
-
projectId,
|
|
1289
|
-
workspaceId,
|
|
1290
|
-
targetId,
|
|
1291
|
-
};
|
|
1292
|
-
}
|
|
1293
|
-
function hostOpenResultForRemoteOpen(input, mapping, openResult, context) {
|
|
1294
|
-
const { gateway: _remoteProjectGateway, projectId: _remoteProjectId, projectName: _remoteProjectName, workspaceId: _remoteWorkspaceId, targetId: _remoteTargetId, sourcePath: remoteSourcePath, ...remoteState } = openResult.state;
|
|
1295
|
-
const sourcePath = input.sourcePath ?? remoteSourcePath;
|
|
1296
|
-
const state = {
|
|
1297
|
-
...remoteState,
|
|
1298
|
-
projectId: context.projectId,
|
|
1299
|
-
projectName: context.config.name,
|
|
1300
|
-
workspaceId: context.workspaceId,
|
|
1301
|
-
targetId: context.targetId,
|
|
1302
|
-
...(sourcePath ? { sourcePath } : {}),
|
|
1303
|
-
remoteGateway: {
|
|
1304
|
-
remoteNodeId: mapping.remoteNode.id,
|
|
1305
|
-
endpoint: remoteGatewayEndpointFromUrl(mapping.remoteNode.gatewayMcpUrl),
|
|
1306
|
-
projectId: openResult.state.projectId,
|
|
1307
|
-
workspaceId: openResult.state.workspaceId,
|
|
1308
|
-
targetId: openResult.state.targetId,
|
|
1309
|
-
},
|
|
1310
|
-
};
|
|
1311
|
-
saveProjectState(context.statePath, state);
|
|
1312
|
-
return {
|
|
1313
|
-
...openResult,
|
|
1314
|
-
projectRoot: context.projectRoot,
|
|
1315
|
-
statePath: context.statePath,
|
|
1316
|
-
state,
|
|
1317
|
-
};
|
|
1318
|
-
}
|
|
1319
|
-
export class PlexusProjectLifecycle {
|
|
1320
|
-
routeRegistry;
|
|
1321
|
-
imageToolCaller;
|
|
1322
|
-
homeImageCacheClient;
|
|
1323
|
-
pharoLauncherMcpClient;
|
|
1324
|
-
defaultStateRoot;
|
|
1325
|
-
projectOpen;
|
|
1326
|
-
projectClose;
|
|
1327
|
-
imageRescue;
|
|
1328
|
-
remoteClientFactory;
|
|
1329
|
-
gateway;
|
|
1330
|
-
constructor(options = {}) {
|
|
1331
|
-
this.routeRegistry = options.routeRegistry;
|
|
1332
|
-
this.imageToolCaller = options.imageToolCaller;
|
|
1333
|
-
this.homeImageCacheClient = options.homeImageCacheClient;
|
|
1334
|
-
this.pharoLauncherMcpClient = options.pharoLauncherMcpClient;
|
|
1335
|
-
this.defaultStateRoot = options.defaultStateRoot;
|
|
1336
|
-
this.projectOpen = options.projectOpen ?? openProject;
|
|
1337
|
-
this.projectClose = options.projectClose ?? closeProject;
|
|
1338
|
-
this.imageRescue = options.imageRescue ?? rescueImage;
|
|
1339
|
-
this.remoteClientFactory = options.remoteClientFactory;
|
|
1340
|
-
this.gateway = options.gateway ?? {};
|
|
1341
|
-
}
|
|
1342
|
-
effectiveStateRoot(stateRoot) {
|
|
1343
|
-
return stateRoot ?? this.defaultStateRoot;
|
|
1344
|
-
}
|
|
1345
|
-
remoteLifecycleMapping(input) {
|
|
1346
|
-
const projectRoot = path.resolve(input.projectPath);
|
|
1347
|
-
if (path.basename(projectRoot) === plexusProjectConfigFileName) {
|
|
1348
|
-
return undefined;
|
|
1349
|
-
}
|
|
1350
|
-
let config;
|
|
1351
|
-
try {
|
|
1352
|
-
config = loadProjectConfig(projectRoot);
|
|
1353
|
-
}
|
|
1354
|
-
catch (error) {
|
|
1355
|
-
if (error instanceof Error &&
|
|
1356
|
-
(error.message.startsWith("ENOENT:") ||
|
|
1357
|
-
error.message.startsWith("ENOTDIR:"))) {
|
|
1358
|
-
return undefined;
|
|
1359
|
-
}
|
|
1360
|
-
throw error;
|
|
1361
|
-
}
|
|
1362
|
-
return remoteLifecycleMappingForInput(config, projectRoot, input);
|
|
1363
|
-
}
|
|
1364
|
-
remoteClientFor(remoteNode) {
|
|
1365
|
-
return (this.remoteClientFactory?.(remoteNode) ??
|
|
1366
|
-
new HttpProjectLifecycleClient({
|
|
1367
|
-
url: remoteNode.projectMcpUrl,
|
|
1368
|
-
timeoutMs: this.gateway.routeRegistryTimeoutMs,
|
|
1369
|
-
fetch: this.gateway.fetch,
|
|
1370
|
-
}));
|
|
1371
|
-
}
|
|
1372
|
-
async registerHostRouteForRemoteOpen(input, mapping, openResult) {
|
|
1373
|
-
const context = hostRemoteRouteContext({
|
|
1374
|
-
...input,
|
|
1375
|
-
stateRoot: this.effectiveStateRoot(input.stateRoot),
|
|
1376
|
-
}, mapping);
|
|
1377
|
-
const hostOpenResult = hostOpenResultForRemoteOpen(input, mapping, openResult, context);
|
|
1378
|
-
await this.ensureGatewayRouteForOpenResult(hostOpenResult);
|
|
1379
|
-
return hostOpenResult;
|
|
1380
|
-
}
|
|
1381
|
-
async unregisterHostRouteForRemote(input, mapping, options = {}) {
|
|
1382
|
-
const context = hostRemoteRouteContext({
|
|
1383
|
-
...input,
|
|
1384
|
-
stateRoot: this.effectiveStateRoot(input.stateRoot),
|
|
1385
|
-
}, mapping);
|
|
1386
|
-
const state = loadProjectState(context.statePath);
|
|
1387
|
-
const routeRegistry = this.routeRegistry ?? this.routeRegistryForProject(context.config, state);
|
|
1388
|
-
await this.unregisterRoute({
|
|
1389
|
-
projectId: context.projectId,
|
|
1390
|
-
workspaceId: context.workspaceId,
|
|
1391
|
-
...(input.targetId ? { targetId: context.targetId } : {}),
|
|
1392
|
-
}, routeRegistry);
|
|
1393
|
-
if (state?.gateway?.managedByProject) {
|
|
1394
|
-
await closeProjectGateway({
|
|
1395
|
-
...this.gateway,
|
|
1396
|
-
state,
|
|
1397
|
-
});
|
|
1398
|
-
state.updatedAt = (this.gateway.now ?? (() => new Date()))().toISOString();
|
|
1399
|
-
saveProjectState(context.statePath, state);
|
|
1400
|
-
}
|
|
1401
|
-
if (options.deleteStateFile) {
|
|
1402
|
-
fs.rmSync(context.statePath, { force: true });
|
|
1403
|
-
}
|
|
1404
|
-
}
|
|
1405
|
-
async open(input) {
|
|
1406
|
-
try {
|
|
1407
|
-
const remote = this.remoteLifecycleMapping(input);
|
|
1408
|
-
if (remote) {
|
|
1409
|
-
const remoteResult = await this.remoteClientFor(remote.remoteNode).callTool("plexus_project_open", remoteLifecycleArguments(input, remote));
|
|
1410
|
-
if (remoteResult.ok && remoteResult.data) {
|
|
1411
|
-
return result(await this.registerHostRouteForRemoteOpen(input, remote, remoteResult.data));
|
|
1412
|
-
}
|
|
1413
|
-
return remoteResult;
|
|
1414
|
-
}
|
|
1415
|
-
const openResult = await this.projectOpen({
|
|
1416
|
-
projectRoot: input.projectPath,
|
|
1417
|
-
sourcePath: input.sourcePath,
|
|
1418
|
-
stateRoot: this.effectiveStateRoot(input.stateRoot),
|
|
1419
|
-
workspaceId: input.workspaceId,
|
|
1420
|
-
targetId: input.targetId,
|
|
1421
|
-
displayMode: input.displayMode,
|
|
1422
|
-
preparedImageCacheApproval: {
|
|
1423
|
-
approved: true,
|
|
1424
|
-
approvalId: "plexus-project-open",
|
|
1425
|
-
},
|
|
1426
|
-
homeImageCacheApproval: {
|
|
1427
|
-
approved: true,
|
|
1428
|
-
approvalId: "plexus-project-open",
|
|
1429
|
-
},
|
|
1430
|
-
});
|
|
1431
|
-
await this.ensureGatewayRouteForOpenResult(openResult);
|
|
1432
|
-
return result(openResult);
|
|
1433
|
-
}
|
|
1434
|
-
catch (error) {
|
|
1435
|
-
if (error instanceof ProjectOpenError &&
|
|
1436
|
-
stateHasRunningRoutableImage(error.result.state)) {
|
|
1437
|
-
try {
|
|
1438
|
-
await this.ensureGatewayRouteForOpenResult(error.result);
|
|
1439
|
-
}
|
|
1440
|
-
catch {
|
|
1441
|
-
// Preserve the project-open failure; diagnostics already carry the
|
|
1442
|
-
// image startup failures that made this repair path partial.
|
|
1443
|
-
}
|
|
1444
|
-
}
|
|
1445
|
-
return failure(error);
|
|
1446
|
-
}
|
|
1447
|
-
}
|
|
1448
|
-
async ensureGatewayRouteForOpenResult(openResult) {
|
|
1449
|
-
let routeRegistry = this.routeRegistry;
|
|
1450
|
-
let startedProjectGateway = false;
|
|
1451
|
-
if (!routeRegistry) {
|
|
1452
|
-
const config = loadProjectConfig(openResult.projectRoot);
|
|
1453
|
-
const discoveredPharoTools = await this.discoverGatewayPharoTools(openResult.state);
|
|
1454
|
-
const gatewayResult = await ensureProjectGateway({
|
|
1455
|
-
...this.gateway,
|
|
1456
|
-
...(discoveredPharoTools !== undefined
|
|
1457
|
-
? { pharoTools: discoveredPharoTools }
|
|
1458
|
-
: {}),
|
|
1459
|
-
projectRoot: openResult.projectRoot,
|
|
1460
|
-
config,
|
|
1461
|
-
state: openResult.state,
|
|
1462
|
-
});
|
|
1463
|
-
startedProjectGateway = gatewayResult.started;
|
|
1464
|
-
saveProjectState(openResult.statePath, openResult.state);
|
|
1465
|
-
routeRegistry = this.routeRegistryFromControlUrl(gatewayResult.routeControlUrl);
|
|
1466
|
-
}
|
|
1467
|
-
try {
|
|
1468
|
-
await this.registerRoute({
|
|
1469
|
-
projectRoot: openResult.projectRoot,
|
|
1470
|
-
statePath: openResult.statePath,
|
|
1471
|
-
state: openResult.state,
|
|
1472
|
-
}, routeRegistry);
|
|
1473
|
-
}
|
|
1474
|
-
catch (error) {
|
|
1475
|
-
if (startedProjectGateway) {
|
|
1476
|
-
await closeProjectGateway({
|
|
1477
|
-
...this.gateway,
|
|
1478
|
-
state: openResult.state,
|
|
1479
|
-
});
|
|
1480
|
-
saveProjectState(openResult.statePath, openResult.state);
|
|
1481
|
-
}
|
|
1482
|
-
throw error;
|
|
1483
|
-
}
|
|
1484
|
-
}
|
|
1485
|
-
async discoverGatewayPharoTools(state) {
|
|
1486
|
-
if (state.remoteGateway) {
|
|
1487
|
-
return undefined;
|
|
1488
|
-
}
|
|
1489
|
-
if (gatewayHasExplicitPharoTools(this.gateway)) {
|
|
1490
|
-
return undefined;
|
|
1491
|
-
}
|
|
1492
|
-
return discoverPharoMcpToolsFromRunningImages({
|
|
1493
|
-
state,
|
|
1494
|
-
fetchFn: this.gateway.fetch ?? fetch,
|
|
1495
|
-
});
|
|
1496
|
-
}
|
|
1497
|
-
async homeImageCacheStatus(input) {
|
|
1498
|
-
try {
|
|
1499
|
-
const projectRoot = path.resolve(input.projectPath);
|
|
1500
|
-
const config = loadProjectConfig(projectRoot);
|
|
1501
|
-
const homePath = resolvePlexusHomePath({ config });
|
|
1502
|
-
const cacheRoot = homeImageCacheRootPath(homePath);
|
|
1503
|
-
const entries = input.key
|
|
1504
|
-
? [
|
|
1505
|
-
cacheEntryStatusFromReadResult(readHomeImageCacheManifest(homeImageCacheManifestPath(cacheRoot, input.key))),
|
|
1506
|
-
]
|
|
1507
|
-
: listHomeImageCacheManifests(cacheRoot).map(cacheEntryStatusFromReadResult);
|
|
1508
|
-
return result({
|
|
1509
|
-
projectRoot,
|
|
1510
|
-
homePath,
|
|
1511
|
-
cacheRoot,
|
|
1512
|
-
entries,
|
|
1513
|
-
});
|
|
1514
|
-
}
|
|
1515
|
-
catch (error) {
|
|
1516
|
-
return failure(error);
|
|
1517
|
-
}
|
|
1518
|
-
}
|
|
1519
|
-
async flushHomeImageCache(input) {
|
|
1520
|
-
try {
|
|
1521
|
-
if (input.confirm !== true) {
|
|
1522
|
-
throw new ProjectLifecycleInputError("confirm: true is required");
|
|
1523
|
-
}
|
|
1524
|
-
const projectRoot = path.resolve(input.projectPath);
|
|
1525
|
-
const config = loadProjectConfig(projectRoot);
|
|
1526
|
-
const plan = planHomeImageCacheFlush({
|
|
1527
|
-
config,
|
|
1528
|
-
key: input.key,
|
|
1529
|
-
});
|
|
1530
|
-
const homeProfile = homeImageCacheProfile(plan.homePath);
|
|
1531
|
-
const manifests = plan.entries
|
|
1532
|
-
.map((entry) => readHomeImageCacheManifest(entry.manifestPath))
|
|
1533
|
-
.filter((readResult) => readResult.status === "ok")
|
|
1534
|
-
.map((readResult) => readResult.manifest);
|
|
1535
|
-
let client = this.homeImageCacheClient;
|
|
1536
|
-
let ownsClient = false;
|
|
1537
|
-
const deletedImages = [];
|
|
1538
|
-
try {
|
|
1539
|
-
if (manifests.length > 0 && !client) {
|
|
1540
|
-
client = await createStdioPharoLauncherMcpClient(undefined, {
|
|
1541
|
-
profileEnvironment: profileEnvironmentFromPaths(homeProfile),
|
|
1542
|
-
});
|
|
1543
|
-
ownsClient = true;
|
|
1544
|
-
}
|
|
1545
|
-
for (const manifest of manifests) {
|
|
1546
|
-
const deleteResult = await client.callTool("pharo_launcher_image_delete", {
|
|
1547
|
-
imageName: manifest.cacheImageName,
|
|
1548
|
-
force: true,
|
|
1549
|
-
confirm: true,
|
|
1550
|
-
});
|
|
1551
|
-
assertLauncherOk(deleteResult, "pharo_launcher_image_delete");
|
|
1552
|
-
deletedImages.push(manifest.cacheImageName);
|
|
1553
|
-
}
|
|
1554
|
-
}
|
|
1555
|
-
finally {
|
|
1556
|
-
if (ownsClient) {
|
|
1557
|
-
await client?.close?.();
|
|
1558
|
-
}
|
|
1559
|
-
}
|
|
1560
|
-
flushHomeImageCache(plan);
|
|
1561
|
-
return result({
|
|
1562
|
-
projectRoot,
|
|
1563
|
-
homePath: plan.homePath,
|
|
1564
|
-
cacheRoot: plan.cacheRoot,
|
|
1565
|
-
entries: listHomeImageCacheManifests(plan.cacheRoot).map(cacheEntryStatusFromReadResult),
|
|
1566
|
-
deletedImages,
|
|
1567
|
-
flushedEntries: plan.entries,
|
|
1568
|
-
});
|
|
1569
|
-
}
|
|
1570
|
-
catch (error) {
|
|
1571
|
-
return failure(error);
|
|
1572
|
-
}
|
|
1573
|
-
}
|
|
1574
|
-
routeRegistryForCloseResult(config, closeResult) {
|
|
1575
|
-
return (this.routeRegistry ??
|
|
1576
|
-
(config && closeResult.state
|
|
1577
|
-
? this.routeRegistryForProject(config, closeResult.state)
|
|
1578
|
-
: undefined));
|
|
1579
|
-
}
|
|
1580
|
-
async unregisterClosedProjectRoute(input, projectRoot, config, closeResult, routeRegistry) {
|
|
1581
|
-
if (closeResult.state) {
|
|
1582
|
-
await this.unregisterRoute({ targetId: closeResult.state.targetId }, routeRegistry);
|
|
1583
|
-
return;
|
|
1584
|
-
}
|
|
1585
|
-
const workspaceId = input.workspaceId
|
|
1586
|
-
? sanitizeRuntimeId(input.workspaceId)
|
|
1587
|
-
: defaultWorkspaceId(projectRoot);
|
|
1588
|
-
await this.unregisterRoute({
|
|
1589
|
-
projectId: config ? projectConfigId(config) : undefined,
|
|
1590
|
-
workspaceId,
|
|
1591
|
-
}, routeRegistry);
|
|
1592
|
-
}
|
|
1593
|
-
async closeManagedProjectGateway(closeResult) {
|
|
1594
|
-
if (!closeResult.state?.gateway?.managedByProject) {
|
|
1595
|
-
return;
|
|
1596
|
-
}
|
|
1597
|
-
await closeProjectGateway({
|
|
1598
|
-
...this.gateway,
|
|
1599
|
-
state: closeResult.state,
|
|
1600
|
-
});
|
|
1601
|
-
closeResult.state.updatedAt = (this.gateway.now ?? (() => new Date()))().toISOString();
|
|
1602
|
-
saveProjectState(closeResult.statePath, closeResult.state);
|
|
1603
|
-
}
|
|
1604
|
-
async unregisterClosedProjectRouteAndGateway(input, projectRoot, config, closeResult, routeRegistry) {
|
|
1605
|
-
let unregisterError;
|
|
1606
|
-
try {
|
|
1607
|
-
await this.unregisterClosedProjectRoute(input, projectRoot, config, closeResult, routeRegistry);
|
|
1608
|
-
}
|
|
1609
|
-
catch (error) {
|
|
1610
|
-
unregisterError = error;
|
|
1611
|
-
}
|
|
1612
|
-
finally {
|
|
1613
|
-
await this.closeManagedProjectGateway(closeResult);
|
|
1614
|
-
}
|
|
1615
|
-
if (unregisterError) {
|
|
1616
|
-
throw unregisterError;
|
|
1617
|
-
}
|
|
1618
|
-
}
|
|
1619
|
-
async close(input) {
|
|
1620
|
-
try {
|
|
1621
|
-
const remote = this.remoteLifecycleMapping(input);
|
|
1622
|
-
if (remote) {
|
|
1623
|
-
const remoteResult = await this.remoteClientFor(remote.remoteNode).callTool("plexus_project_close", remoteLifecycleArguments(input, remote));
|
|
1624
|
-
if (remoteResult.ok) {
|
|
1625
|
-
await this.unregisterHostRouteForRemote(input, remote);
|
|
1626
|
-
}
|
|
1627
|
-
return remoteResult;
|
|
1628
|
-
}
|
|
1629
|
-
const closeResult = await this.projectClose({
|
|
1630
|
-
projectRoot: input.projectPath,
|
|
1631
|
-
stateRoot: this.effectiveStateRoot(input.stateRoot),
|
|
1632
|
-
workspaceId: input.workspaceId,
|
|
1633
|
-
...(input.repositoryWorkspaceCleanupPolicy
|
|
1634
|
-
? {
|
|
1635
|
-
repositoryWorkspaceCleanupPolicy: input.repositoryWorkspaceCleanupPolicy,
|
|
1636
|
-
}
|
|
1637
|
-
: {}),
|
|
1638
|
-
...(input.repositoryWorkspaceArchiveRoot
|
|
1639
|
-
? { repositoryWorkspaceArchiveRoot: input.repositoryWorkspaceArchiveRoot }
|
|
1640
|
-
: {}),
|
|
1641
|
-
});
|
|
1642
|
-
const projectRoot = path.resolve(input.projectPath);
|
|
1643
|
-
const config = !this.routeRegistry || !closeResult.state
|
|
1644
|
-
? loadProjectConfig(projectRoot)
|
|
1645
|
-
: undefined;
|
|
1646
|
-
await this.unregisterClosedProjectRouteAndGateway(input, projectRoot, config, closeResult, this.routeRegistryForCloseResult(config, closeResult));
|
|
1647
|
-
return result(closeResult);
|
|
1648
|
-
}
|
|
1649
|
-
catch (error) {
|
|
1650
|
-
return failure(error);
|
|
1651
|
-
}
|
|
1652
|
-
}
|
|
1653
|
-
async cleanupRouteResource(config, state, routeResource, confirm) {
|
|
1654
|
-
if (!(confirm === true && routeResource && state)) {
|
|
1655
|
-
return undefined;
|
|
1656
|
-
}
|
|
1657
|
-
const routeRegistry = this.routeRegistryForProject(config, state);
|
|
1658
|
-
if (!routeRegistry) {
|
|
1659
|
-
routeResource.status = "skipped";
|
|
1660
|
-
routeResource.reason =
|
|
1661
|
-
"No route registry is configured for this project scope.";
|
|
1662
|
-
return undefined;
|
|
1663
|
-
}
|
|
1664
|
-
try {
|
|
1665
|
-
await this.unregisterRoute({ targetId: state.targetId }, routeRegistry);
|
|
1666
|
-
routeResource.status = "cleaned";
|
|
1667
|
-
return undefined;
|
|
1668
|
-
}
|
|
1669
|
-
catch (error) {
|
|
1670
|
-
const skipReason = idempotentRouteCleanupReason(error);
|
|
1671
|
-
if (skipReason) {
|
|
1672
|
-
routeResource.status = "skipped";
|
|
1673
|
-
routeResource.reason = skipReason;
|
|
1674
|
-
return undefined;
|
|
1675
|
-
}
|
|
1676
|
-
const message = errorMessage(error);
|
|
1677
|
-
routeResource.status = "failed";
|
|
1678
|
-
routeResource.reason = message;
|
|
1679
|
-
return {
|
|
1680
|
-
kind: "route",
|
|
1681
|
-
id: state.targetId,
|
|
1682
|
-
message,
|
|
1683
|
-
};
|
|
1684
|
-
}
|
|
1685
|
-
}
|
|
1686
|
-
async cleanup(input) {
|
|
1687
|
-
try {
|
|
1688
|
-
const remote = this.remoteLifecycleMapping(input);
|
|
1689
|
-
if (remote) {
|
|
1690
|
-
const remoteResult = await this.remoteClientFor(remote.remoteNode).callTool("plexus_project_cleanup", remoteLifecycleArguments(input, remote));
|
|
1691
|
-
if (remoteResult.ok && input.confirm === true) {
|
|
1692
|
-
await this.unregisterHostRouteForRemote(input, remote, {
|
|
1693
|
-
deleteStateFile: input.deleteStateFile === true,
|
|
1694
|
-
});
|
|
1695
|
-
}
|
|
1696
|
-
return remoteResult;
|
|
1697
|
-
}
|
|
1698
|
-
const projectRoot = path.resolve(input.projectPath);
|
|
1699
|
-
const config = loadProjectConfig(projectRoot);
|
|
1700
|
-
const workspaceId = input.workspaceId
|
|
1701
|
-
? sanitizeRuntimeId(input.workspaceId)
|
|
1702
|
-
: defaultWorkspaceId(projectRoot);
|
|
1703
|
-
const stateRoot = projectStateRootForConfig(config, this.effectiveStateRoot(input.stateRoot)) ??
|
|
1704
|
-
defaultPlexusStateRoot(projectRoot);
|
|
1705
|
-
const statePath = projectStatePathForConfig({
|
|
1706
|
-
projectRoot,
|
|
1707
|
-
config,
|
|
1708
|
-
workspaceId,
|
|
1709
|
-
stateRoot,
|
|
1710
|
-
});
|
|
1711
|
-
const state = loadProjectState(statePath);
|
|
1712
|
-
const routeResource = state ? routeCleanupResource(state) : undefined;
|
|
1713
|
-
const routeFailure = await this.cleanupRouteResource(config, state, routeResource, input.confirm);
|
|
1714
|
-
const cleanupResult = await cleanupProjectOwnedResources({
|
|
1715
|
-
projectRoot,
|
|
1716
|
-
stateRoot,
|
|
1717
|
-
workspaceId,
|
|
1718
|
-
confirm: input.confirm,
|
|
1719
|
-
deleteStateFile: input.deleteStateFile,
|
|
1720
|
-
deleteLauncherImages: input.deleteLauncherImages,
|
|
1721
|
-
pharoLauncherMcpClient: this.pharoLauncherMcpClient,
|
|
1722
|
-
repositoryWorkspaceCleanupPolicy: input.repositoryWorkspaceCleanupPolicy,
|
|
1723
|
-
repositoryWorkspaceArchiveRoot: input.repositoryWorkspaceArchiveRoot,
|
|
1724
|
-
gateway: this.gateway,
|
|
1725
|
-
});
|
|
1726
|
-
if (routeResource) {
|
|
1727
|
-
cleanupResult.resources.push(routeResource);
|
|
1728
|
-
}
|
|
1729
|
-
if (routeFailure) {
|
|
1730
|
-
cleanupResult.failures.push(routeFailure);
|
|
1731
|
-
cleanupResult.ok = false;
|
|
1732
|
-
}
|
|
1733
|
-
if (!cleanupResult.ok) {
|
|
1734
|
-
return {
|
|
1735
|
-
ok: false,
|
|
1736
|
-
data: cleanupResult,
|
|
1737
|
-
error: "One or more PLexus-owned resources failed to clean",
|
|
1738
|
-
};
|
|
1739
|
-
}
|
|
1740
|
-
return result(cleanupResult);
|
|
1741
|
-
}
|
|
1742
|
-
catch (error) {
|
|
1743
|
-
return failure(error);
|
|
1744
|
-
}
|
|
1745
|
-
}
|
|
1746
|
-
async status(input) {
|
|
1747
|
-
try {
|
|
1748
|
-
if (input.projectPath) {
|
|
1749
|
-
const remote = this.remoteLifecycleMapping({
|
|
1750
|
-
...input,
|
|
1751
|
-
projectPath: input.projectPath,
|
|
1752
|
-
});
|
|
1753
|
-
if (remote) {
|
|
1754
|
-
return this.remoteClientFor(remote.remoteNode).callTool("plexus_project_status", remoteLifecycleArguments({
|
|
1755
|
-
...input,
|
|
1756
|
-
projectPath: input.projectPath,
|
|
1757
|
-
}, remote));
|
|
1758
|
-
}
|
|
1759
|
-
return result(await this.statusFromProjectPath({
|
|
1760
|
-
...input,
|
|
1761
|
-
projectPath: input.projectPath,
|
|
1762
|
-
}));
|
|
1763
|
-
}
|
|
1764
|
-
if (!this.routeRegistry?.getRouteStatus) {
|
|
1765
|
-
throw new ProjectLifecycleInputError("projectPath is required when no gateway route registry is configured");
|
|
1766
|
-
}
|
|
1767
|
-
const routeStatus = unwrapToolLikeResult(await this.routeRegistry.getRouteStatus({
|
|
1768
|
-
...lifecycleReferenceFromInput(input),
|
|
1769
|
-
refreshHealth: input.refreshHealth,
|
|
1770
|
-
}));
|
|
1771
|
-
const routes = Array.isArray(routeStatus) ? routeStatus : [routeStatus];
|
|
1772
|
-
const statuses = routes.map((route) => lifecycleStatusFromRoute(route, input.includeDiagnostics));
|
|
1773
|
-
return result(Array.isArray(routeStatus) ? statuses : statuses[0]);
|
|
1774
|
-
}
|
|
1775
|
-
catch (error) {
|
|
1776
|
-
return failure(error);
|
|
1777
|
-
}
|
|
1778
|
-
}
|
|
1779
|
-
async rescueImage(input) {
|
|
1780
|
-
try {
|
|
1781
|
-
const imageToolCaller = this.imageToolCaller;
|
|
1782
|
-
const options = {
|
|
1783
|
-
...input,
|
|
1784
|
-
projectRoot: input.projectPath ?? "",
|
|
1785
|
-
stateRoot: this.effectiveStateRoot(input.stateRoot),
|
|
1786
|
-
imageMcpClient: imageToolCaller
|
|
1787
|
-
? {
|
|
1788
|
-
callTool: async (image, toolName, argumentsValue) => imageToolCaller.callImageTool(lifecycleReferenceFromInput(input), image.id, toolName, argumentsValue),
|
|
1789
|
-
}
|
|
1790
|
-
: undefined,
|
|
1791
|
-
};
|
|
1792
|
-
if (!options.projectRoot) {
|
|
1793
|
-
throw new ProjectLifecycleInputError("projectPath is required for image rescue");
|
|
1794
|
-
}
|
|
1795
|
-
const rescueResult = await this.imageRescue(options);
|
|
1796
|
-
if (rescueResult.state) {
|
|
1797
|
-
const config = loadProjectConfig(rescueResult.projectRoot);
|
|
1798
|
-
await this.registerRoute({
|
|
1799
|
-
projectRoot: rescueResult.projectRoot,
|
|
1800
|
-
statePath: rescueResult.statePath,
|
|
1801
|
-
state: rescueResult.state,
|
|
1802
|
-
}, this.routeRegistryForProject(config, rescueResult.state));
|
|
1803
|
-
}
|
|
1804
|
-
return result(rescueResult);
|
|
1805
|
-
}
|
|
1806
|
-
catch (error) {
|
|
1807
|
-
return failure(error);
|
|
1808
|
-
}
|
|
1809
|
-
}
|
|
1810
|
-
async handleTool(name, inputValue) {
|
|
1811
|
-
try {
|
|
1812
|
-
const input = objectInput(inputValue);
|
|
1813
|
-
switch (name) {
|
|
1814
|
-
case "plexus_project_open":
|
|
1815
|
-
return this.open({
|
|
1816
|
-
projectPath: requireString(input, "projectPath"),
|
|
1817
|
-
sourcePath: optionalString(input, "sourcePath"),
|
|
1818
|
-
stateRoot: optionalString(input, "stateRoot"),
|
|
1819
|
-
workspaceId: optionalString(input, "workspaceId"),
|
|
1820
|
-
targetId: optionalString(input, "targetId"),
|
|
1821
|
-
displayMode: optionalDisplayMode(input, "displayMode"),
|
|
1822
|
-
});
|
|
1823
|
-
case "plexus_project_close":
|
|
1824
|
-
return this.close({
|
|
1825
|
-
projectPath: requireString(input, "projectPath"),
|
|
1826
|
-
stateRoot: optionalString(input, "stateRoot"),
|
|
1827
|
-
workspaceId: optionalString(input, "workspaceId"),
|
|
1828
|
-
repositoryWorkspaceCleanupPolicy: optionalRepositoryWorkspaceCleanupPolicy(input),
|
|
1829
|
-
repositoryWorkspaceArchiveRoot: optionalString(input, "repositoryWorkspaceArchiveRoot"),
|
|
1830
|
-
});
|
|
1831
|
-
case "plexus_project_cleanup":
|
|
1832
|
-
return this.cleanup({
|
|
1833
|
-
projectPath: requireString(input, "projectPath"),
|
|
1834
|
-
stateRoot: optionalString(input, "stateRoot"),
|
|
1835
|
-
workspaceId: optionalString(input, "workspaceId"),
|
|
1836
|
-
confirm: optionalBooleanValue(input, "confirm"),
|
|
1837
|
-
deleteStateFile: optionalBooleanValue(input, "deleteStateFile"),
|
|
1838
|
-
deleteLauncherImages: optionalBooleanValue(input, "deleteLauncherImages"),
|
|
1839
|
-
repositoryWorkspaceCleanupPolicy: optionalRepositoryWorkspaceCleanupPolicy(input),
|
|
1840
|
-
repositoryWorkspaceArchiveRoot: optionalString(input, "repositoryWorkspaceArchiveRoot"),
|
|
1841
|
-
});
|
|
1842
|
-
case "plexus_project_status":
|
|
1843
|
-
return this.status({
|
|
1844
|
-
projectPath: optionalString(input, "projectPath"),
|
|
1845
|
-
sourcePath: optionalString(input, "sourcePath"),
|
|
1846
|
-
projectId: optionalString(input, "projectId"),
|
|
1847
|
-
workspaceId: optionalString(input, "workspaceId"),
|
|
1848
|
-
targetId: optionalString(input, "targetId"),
|
|
1849
|
-
stateRoot: optionalString(input, "stateRoot"),
|
|
1850
|
-
refreshHealth: optionalBoolean(input, "refreshHealth"),
|
|
1851
|
-
includeDiagnostics: optionalBoolean(input, "includeDiagnostics"),
|
|
1852
|
-
});
|
|
1853
|
-
case "plexus_home_image_cache_status":
|
|
1854
|
-
return this.homeImageCacheStatus({
|
|
1855
|
-
projectPath: requireString(input, "projectPath"),
|
|
1856
|
-
key: optionalString(input, "key"),
|
|
1857
|
-
});
|
|
1858
|
-
case "plexus_home_image_cache_flush":
|
|
1859
|
-
return this.flushHomeImageCache({
|
|
1860
|
-
projectPath: requireString(input, "projectPath"),
|
|
1861
|
-
key: optionalString(input, "key"),
|
|
1862
|
-
confirm: optionalBooleanValue(input, "confirm"),
|
|
1863
|
-
});
|
|
1864
|
-
case "plexus_rescue_image":
|
|
1865
|
-
return this.rescueImage({
|
|
1866
|
-
projectPath: requireString(input, "projectPath"),
|
|
1867
|
-
projectId: optionalString(input, "projectId"),
|
|
1868
|
-
workspaceId: optionalString(input, "workspaceId"),
|
|
1869
|
-
targetId: optionalString(input, "targetId"),
|
|
1870
|
-
stateRoot: optionalString(input, "stateRoot"),
|
|
1871
|
-
operation: requireRescueOperation(input),
|
|
1872
|
-
sourceImageId: requireString(input, "sourceImageId"),
|
|
1873
|
-
targetImageId: optionalString(input, "targetImageId"),
|
|
1874
|
-
targetImageName: optionalString(input, "targetImageName"),
|
|
1875
|
-
targetTemplateName: optionalString(input, "targetTemplateName"),
|
|
1876
|
-
targetTemplateCategory: optionalString(input, "targetTemplateCategory"),
|
|
1877
|
-
targetMcpPort: optionalNumber(input, "targetMcpPort"),
|
|
1878
|
-
sourceHistoryDirectoryPath: optionalString(input, "sourceHistoryDirectoryPath"),
|
|
1879
|
-
historyFilePath: optionalString(input, "historyFilePath"),
|
|
1880
|
-
selection: optionalEntrySelection(input, "selection"),
|
|
1881
|
-
exclude: optionalEntrySelection(input, "exclude"),
|
|
1882
|
-
codeChangesOnly: optionalBooleanValue(input, "codeChangesOnly"),
|
|
1883
|
-
includeEntryCounts: optionalBooleanValue(input, "includeEntryCounts"),
|
|
1884
|
-
loadRepositories: optionalBooleanValue(input, "loadRepositories"),
|
|
1885
|
-
repositoryActions: optionalRepositoryActions(input, "repositoryActions"),
|
|
1886
|
-
confirm: optionalBooleanValue(input, "confirm"),
|
|
1887
|
-
});
|
|
1888
|
-
default:
|
|
1889
|
-
return {
|
|
1890
|
-
ok: false,
|
|
1891
|
-
error: `Unknown tool: ${name}`,
|
|
1892
|
-
};
|
|
1893
|
-
}
|
|
1894
|
-
}
|
|
1895
|
-
catch (error) {
|
|
1896
|
-
return failure(error);
|
|
1897
|
-
}
|
|
1898
|
-
}
|
|
1899
|
-
async statusFromProjectPath(input) {
|
|
1900
|
-
const projectRoot = path.resolve(input.projectPath);
|
|
1901
|
-
if (path.basename(projectRoot) === plexusProjectConfigFileName) {
|
|
1902
|
-
throw new ProjectLifecycleInputError(`projectPath must point to the PLexus project directory, not ${plexusProjectConfigFileName}: ` +
|
|
1903
|
-
`${projectRoot}. Pass ${path.dirname(projectRoot)} instead.`);
|
|
1904
|
-
}
|
|
1905
|
-
const config = loadProjectConfig(projectRoot);
|
|
1906
|
-
const runtime = resolveProjectRuntimePolicy(config);
|
|
1907
|
-
const workspaceId = input.workspaceId
|
|
1908
|
-
? sanitizeRuntimeId(input.workspaceId)
|
|
1909
|
-
: defaultWorkspaceId(projectRoot);
|
|
1910
|
-
const requestedStateRoot = this.effectiveStateRoot(input.stateRoot);
|
|
1911
|
-
const stateRoot = projectStateRootForConfig(config, requestedStateRoot) ??
|
|
1912
|
-
defaultPlexusStateRoot(projectRoot);
|
|
1913
|
-
const statePath = projectStatePathForConfig({
|
|
1914
|
-
projectRoot,
|
|
1915
|
-
config,
|
|
1916
|
-
workspaceId,
|
|
1917
|
-
stateRoot,
|
|
1918
|
-
});
|
|
1919
|
-
let state = loadProjectState(statePath);
|
|
1920
|
-
const checks = mergePortClaimChecks(this.gateway);
|
|
1921
|
-
const observedGateway = projectGatewayStatus(config, state);
|
|
1922
|
-
const gatewayReconciliation = input.refreshHealth
|
|
1923
|
-
? await reconcileDeadProjectGatewayState({
|
|
1924
|
-
state,
|
|
1925
|
-
statePath,
|
|
1926
|
-
gateway: observedGateway,
|
|
1927
|
-
checks,
|
|
1928
|
-
now: this.gateway.now ?? (() => new Date()),
|
|
1929
|
-
})
|
|
1930
|
-
: undefined;
|
|
1931
|
-
if (gatewayReconciliation) {
|
|
1932
|
-
state = loadProjectState(statePath);
|
|
1933
|
-
}
|
|
1934
|
-
const requestedSourcePath = input.sourcePath ?? state?.sourcePath;
|
|
1935
|
-
const sourcePath = requestedSourcePath
|
|
1936
|
-
? path.resolve(requestedSourcePath)
|
|
1937
|
-
: projectRoot;
|
|
1938
|
-
const gateway = gatewayReconciliation
|
|
1939
|
-
? gatewayWithoutRuntimeIdentity(projectGatewayStatus(config, state))
|
|
1940
|
-
: projectGatewayStatus(config, state);
|
|
1941
|
-
const routeRegistry = gatewayReconciliation
|
|
1942
|
-
? undefined
|
|
1943
|
-
: this.routeRegistryForProject(config, state);
|
|
1944
|
-
let route;
|
|
1945
|
-
let routeError;
|
|
1946
|
-
if (state) {
|
|
1947
|
-
try {
|
|
1948
|
-
route = await this.getRouteStatus({
|
|
1949
|
-
targetId: state.targetId,
|
|
1950
|
-
refreshHealth: input.refreshHealth,
|
|
1951
|
-
}, routeRegistry);
|
|
1952
|
-
if (routeRegistry &&
|
|
1953
|
-
registeredRouteStatePath(route) &&
|
|
1954
|
-
!sameResolvedPath(registeredRouteStatePath(route), statePath)) {
|
|
1955
|
-
await this.registerRoute({
|
|
1956
|
-
projectRoot,
|
|
1957
|
-
statePath,
|
|
1958
|
-
state,
|
|
1959
|
-
}, routeRegistry);
|
|
1960
|
-
route = await this.getRouteStatus({
|
|
1961
|
-
targetId: state.targetId,
|
|
1962
|
-
refreshHealth: input.refreshHealth,
|
|
1963
|
-
}, routeRegistry);
|
|
1964
|
-
}
|
|
1965
|
-
}
|
|
1966
|
-
catch (error) {
|
|
1967
|
-
routeError = error;
|
|
1968
|
-
}
|
|
1969
|
-
}
|
|
1970
|
-
const targetId = state?.targetId ??
|
|
1971
|
-
input.targetId ??
|
|
1972
|
-
defaultTargetId(projectConfigId(config), workspaceId);
|
|
1973
|
-
const scope = {
|
|
1974
|
-
projectId: state?.projectId ?? projectConfigId(config),
|
|
1975
|
-
workspaceId: state?.workspaceId ?? workspaceId,
|
|
1976
|
-
targetId,
|
|
1977
|
-
};
|
|
1978
|
-
const gatewayRepair = gatewayRepairAffordance({
|
|
1979
|
-
projectRoot,
|
|
1980
|
-
stateRoot,
|
|
1981
|
-
workspaceId: scope.workspaceId,
|
|
1982
|
-
targetId: scope.targetId,
|
|
1983
|
-
});
|
|
1984
|
-
const context = buildScopedProjectContext({
|
|
1985
|
-
projectRoot,
|
|
1986
|
-
sourcePath,
|
|
1987
|
-
projectConfig: config,
|
|
1988
|
-
workspaceId: scope.workspaceId,
|
|
1989
|
-
targetId: scope.targetId,
|
|
1990
|
-
stateRoot,
|
|
1991
|
-
projectState: state,
|
|
1992
|
-
});
|
|
1993
|
-
const imageClaimsRoot = imagePortClaimsRootForConfig(projectRoot, config);
|
|
1994
|
-
const portClaims = await inspectClaimRoots(configuredClaimRoots(projectRoot, config, state), checks, scope, currentScopeClaimPorts(config, state, gateway));
|
|
1995
|
-
const routeTable = routeTableDiagnostics(targetId, route, routeError, statePath, gatewayReconciliation);
|
|
1996
|
-
const conflictingListeners = await conflictingListenerDiagnostics(state, gateway, portClaims, checks);
|
|
1997
|
-
const diagnostics = {
|
|
1998
|
-
toolRuntime: plexusRuntimeIdentity(),
|
|
1999
|
-
runtime: runtimeDiagnostics(state, gateway, portClaims, conflictingListeners, routeTable, gatewayReconciliation),
|
|
2000
|
-
project: projectDiagnostics(config, state),
|
|
2001
|
-
scope: {
|
|
2002
|
-
projectRoot,
|
|
2003
|
-
sourcePath,
|
|
2004
|
-
stateRoot,
|
|
2005
|
-
statePath,
|
|
2006
|
-
projectId: scope.projectId,
|
|
2007
|
-
workspaceId: scope.workspaceId,
|
|
2008
|
-
targetId: scope.targetId,
|
|
2009
|
-
},
|
|
2010
|
-
gateway: gatewayDiagnostic(gateway, gatewayReconciliation, gatewayRepair),
|
|
2011
|
-
runtimePolicy: runtime,
|
|
2012
|
-
remoteTopology: remoteTopologyDiagnostics(config, runtime),
|
|
2013
|
-
imagePortPolicy: imagePortPolicyDiagnostics(runtime, stateRoot, imageClaimsRoot),
|
|
2014
|
-
launcherProfile: describePharoLauncherMcpProfile({
|
|
2015
|
-
projectRoot,
|
|
2016
|
-
config,
|
|
2017
|
-
workspaceId: scope.workspaceId,
|
|
2018
|
-
targetId: scope.targetId,
|
|
2019
|
-
stateRoot,
|
|
2020
|
-
env: this.gateway.env,
|
|
2021
|
-
}),
|
|
2022
|
-
repositoryWorkspaces: repositoryWorkspaceDiagnostics(projectRoot, config, state, scope),
|
|
2023
|
-
dependencyRepositoryDetaches: dependencyRepositoryDetachDiagnostics(state),
|
|
2024
|
-
imageRecovery: imageRecoveryDiagnostics({
|
|
2025
|
-
projectRoot,
|
|
2026
|
-
stateRoot,
|
|
2027
|
-
workspaceId: scope.workspaceId,
|
|
2028
|
-
state,
|
|
2029
|
-
}),
|
|
2030
|
-
imageMcpPorts: imageMcpPorts(state),
|
|
2031
|
-
imagePortCoordination: imagePortCoordinationDiagnostics(projectRoot, stateRoot, config),
|
|
2032
|
-
portClaims,
|
|
2033
|
-
conflictingListeners,
|
|
2034
|
-
staleClaims: portClaims.stale,
|
|
2035
|
-
routeTable,
|
|
2036
|
-
};
|
|
2037
|
-
const safeStatus = {
|
|
2038
|
-
projectId: scope.projectId,
|
|
2039
|
-
workspaceId: scope.workspaceId,
|
|
2040
|
-
targetId: scope.targetId,
|
|
2041
|
-
context,
|
|
2042
|
-
};
|
|
2043
|
-
if (!input.includeDiagnostics) {
|
|
2044
|
-
return safeStatus;
|
|
2045
|
-
}
|
|
2046
|
-
return {
|
|
2047
|
-
...safeStatus,
|
|
2048
|
-
projectRoot,
|
|
2049
|
-
stateRoot,
|
|
2050
|
-
statePath,
|
|
2051
|
-
state,
|
|
2052
|
-
gateway,
|
|
2053
|
-
...(route ? { route } : {}),
|
|
2054
|
-
diagnostics,
|
|
2055
|
-
};
|
|
2056
|
-
}
|
|
2057
|
-
async getRouteStatus(input, routeRegistry = this.routeRegistry) {
|
|
2058
|
-
if (!routeRegistry?.getRouteStatus) {
|
|
2059
|
-
return undefined;
|
|
2060
|
-
}
|
|
2061
|
-
return unwrapToolLikeResult(await routeRegistry.getRouteStatus(input));
|
|
2062
|
-
}
|
|
2063
|
-
async registerRoute(input, routeRegistry = this.routeRegistry) {
|
|
2064
|
-
if (!routeRegistry) {
|
|
2065
|
-
return;
|
|
2066
|
-
}
|
|
2067
|
-
unwrapToolLikeResult(await routeRegistry.registerProjectRoute(input));
|
|
2068
|
-
}
|
|
2069
|
-
async unregisterRoute(input, routeRegistry = this.routeRegistry) {
|
|
2070
|
-
if (!routeRegistry) {
|
|
2071
|
-
return;
|
|
2072
|
-
}
|
|
2073
|
-
unwrapToolLikeResult(await routeRegistry.unregisterProjectRoute(input));
|
|
2074
|
-
}
|
|
2075
|
-
routeRegistryFromControlUrl(url) {
|
|
2076
|
-
return new HttpGatewayRouteRegistry({
|
|
2077
|
-
url,
|
|
2078
|
-
timeoutMs: this.gateway.routeRegistryTimeoutMs,
|
|
2079
|
-
fetch: this.gateway.fetch,
|
|
2080
|
-
});
|
|
2081
|
-
}
|
|
2082
|
-
routeRegistryForProject(config, state) {
|
|
2083
|
-
if (this.routeRegistry) {
|
|
2084
|
-
return this.routeRegistry;
|
|
2085
|
-
}
|
|
2086
|
-
const gateway = state?.gateway ?? projectGatewayStatus(config, state);
|
|
2087
|
-
return gateway.controlEndpoint
|
|
2088
|
-
? this.routeRegistryFromControlUrl(gateway.controlEndpoint)
|
|
2089
|
-
: undefined;
|
|
2090
|
-
}
|
|
2091
|
-
}
|
|
2092
|
-
export function createProjectLifecycleFromEnvironment(env = process.env) {
|
|
2093
|
-
const routeControlUrl = env.PLEXUS_GATEWAY_CONTROL_MCP_URL;
|
|
2094
|
-
const routeControlPath = env.PLEXUS_GATEWAY_CONTROL_MCP_PATH;
|
|
2095
|
-
const routeRegistry = routeControlUrl ||
|
|
2096
|
-
routeControlPath ||
|
|
2097
|
-
env.PLEXUS_GATEWAY_HOST ||
|
|
2098
|
-
env.PLEXUS_GATEWAY_PORT
|
|
2099
|
-
? new HttpGatewayRouteRegistry({
|
|
2100
|
-
url: routeControlUrl,
|
|
2101
|
-
host: env.PLEXUS_GATEWAY_HOST,
|
|
2102
|
-
port: env.PLEXUS_GATEWAY_PORT
|
|
2103
|
-
? Number(env.PLEXUS_GATEWAY_PORT)
|
|
2104
|
-
: undefined,
|
|
2105
|
-
path: routeControlPath,
|
|
2106
|
-
})
|
|
2107
|
-
: undefined;
|
|
2108
|
-
return new PlexusProjectLifecycle({
|
|
2109
|
-
routeRegistry,
|
|
2110
|
-
defaultStateRoot: env.PLEXUS_STATE_ROOT,
|
|
2111
|
-
gateway: { env },
|
|
2112
|
-
});
|
|
2113
|
-
}
|
|
2114
|
-
//# sourceMappingURL=projectLifecycle.js.map
|