@evref-bl/pharo-launcher-mcp 0.1.2 → 0.1.4
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 +229 -199
- package/bin/pharo-launcher.cmd +46 -46
- package/bin/pharo-launcher.sh +0 -0
- package/dist/commandCatalog.d.ts.map +1 -1
- package/dist/commandCatalog.js +23 -6
- package/dist/commandCatalog.js.map +1 -1
- package/dist/config.d.ts +21 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +75 -6
- package/dist/config.js.map +1 -1
- package/dist/crossProfileCopy.d.ts +88 -0
- package/dist/crossProfileCopy.d.ts.map +1 -0
- package/dist/crossProfileCopy.js +511 -0
- package/dist/crossProfileCopy.js.map +1 -0
- package/dist/discovery.d.ts +165 -1
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +803 -3
- package/dist/discovery.js.map +1 -1
- package/dist/imageMetadata.d.ts +1 -0
- package/dist/imageMetadata.d.ts.map +1 -1
- package/dist/imageMetadata.js +35 -2
- package/dist/imageMetadata.js.map +1 -1
- package/dist/launcherCli.d.ts +2 -0
- package/dist/launcherCli.d.ts.map +1 -1
- package/dist/launcherCli.js +589 -62
- package/dist/launcherCli.js.map +1 -1
- package/dist/models.d.ts +3 -1
- package/dist/models.d.ts.map +1 -1
- package/dist/parser.d.ts.map +1 -1
- package/dist/parser.js +48 -13
- package/dist/parser.js.map +1 -1
- package/dist/platform.d.ts +2 -0
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +21 -0
- package/dist/platform.js.map +1 -1
- package/dist/processTools.d.ts.map +1 -1
- package/dist/processTools.js +13 -7
- package/dist/processTools.js.map +1 -1
- package/dist/resultNormalizer.d.ts +5 -1
- package/dist/resultNormalizer.d.ts.map +1 -1
- package/dist/resultNormalizer.js +79 -6
- package/dist/resultNormalizer.js.map +1 -1
- package/dist/server.d.ts +3 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +475 -83
- package/dist/server.js.map +1 -1
- package/dist/textTokens.d.ts +10 -0
- package/dist/textTokens.d.ts.map +1 -0
- package/dist/textTokens.js +68 -0
- package/dist/textTokens.js.map +1 -0
- package/docs/README.md +26 -0
- package/docs/cleanup-hook-boundary.md +94 -0
- package/docs/development.md +59 -23
- package/docs/reference/tools.md +179 -0
- package/docs/troubleshooting.md +135 -0
- package/docs/user/getting-started.md +172 -0
- package/docs/user/profile-mode.md +183 -0
- package/package.json +59 -52
package/dist/server.d.ts
CHANGED
|
@@ -12,9 +12,12 @@ export interface CallToolOptions {
|
|
|
12
12
|
config?: PharoLauncherConfig;
|
|
13
13
|
runner?: LauncherCliRunner;
|
|
14
14
|
timeoutMs?: number;
|
|
15
|
+
includeRaw?: boolean;
|
|
15
16
|
imageCopyVerificationTimeoutMs?: number;
|
|
16
17
|
imageCopyVerificationPollMs?: number;
|
|
17
18
|
sleep?: (milliseconds: number) => Promise<void>;
|
|
19
|
+
templateSourcesUrl?: string;
|
|
20
|
+
fetchTemplateSources?: (url: string) => Promise<string>;
|
|
18
21
|
}
|
|
19
22
|
export declare function callTool(name: string, argumentsValue: unknown, options?: CallToolOptions): Promise<ToolResult>;
|
|
20
23
|
export declare function createServer(): Server;
|
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAanE,OAAO,EAEL,KAAK,mBAAmB,EACzB,MAAM,aAAa,CAAC;AACrB,OAAO,EAKL,KAAK,iBAAiB,EAIvB,MAAM,gBAAgB,CAAC;AA4IxB,KAAK,UAAU,GAAG;IAChB,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/C,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,MAAM,WAAW,eAAe;IAC9B,MAAM,CAAC,EAAE,mBAAmB,CAAC;IAC7B,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,8BAA8B,CAAC,EAAE,MAAM,CAAC;IACxC,2BAA2B,CAAC,EAAE,MAAM,CAAC;IACrC,KAAK,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,oBAAoB,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;CACzD;AAuuBD,wBAAsB,QAAQ,CAC5B,IAAI,EAAE,MAAM,EACZ,cAAc,EAAE,OAAO,EACvB,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,UAAU,CAAC,CA4BrB;AAED,wBAAgB,YAAY,IAAI,MAAM,CAsBrC;AAED,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAItD"}
|
package/dist/server.js
CHANGED
|
@@ -1,21 +1,96 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
1
3
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
2
4
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
3
5
|
import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
4
6
|
import { buildLauncherCommandArgs, launcherCommandTools, rawCommandTool, ToolInputError, } from "./commandCatalog.js";
|
|
7
|
+
import { copyImageBetweenProfiles } from "./crossProfileCopy.js";
|
|
5
8
|
import { loadPharoLauncherConfig, } from "./config.js";
|
|
6
|
-
import { getPharoLauncherConfigReport, getPharoLauncherHealth, getPharoLauncherVersion, validatePharoLauncherInstallation, } from "./discovery.js";
|
|
7
|
-
import { runLauncherCli } from "./launcherCli.js";
|
|
9
|
+
import { getPharoLauncherConfigReport, getPharoLauncherHealth, getPharoLauncherInventory, getPharoLauncherVersion, validatePharoLauncherInstallation, } from "./discovery.js";
|
|
10
|
+
import { buildLauncherCliInvocation, launcherInvocationFailureDiagnostic, runLauncherCli, } from "./launcherCli.js";
|
|
8
11
|
import { runNativeProcessTool, shouldUseNativeProcessTool, } from "./processTools.js";
|
|
9
12
|
import { repairCopiedImageMetadata } from "./imageMetadata.js";
|
|
10
13
|
import { normalizeLauncherResult } from "./resultNormalizer.js";
|
|
11
14
|
const serverVersion = "0.1.1";
|
|
12
15
|
const imageCopyVerificationTimeoutMs = 30_000;
|
|
13
16
|
const imageCopyVerificationPollMs = 1_000;
|
|
17
|
+
const defaultTemplateSourcesUrl = "https://files.pharo.org/pharo-launcher/sources.list";
|
|
18
|
+
const templateSourcesFileName = "sources.list";
|
|
14
19
|
const emptyInputSchema = {
|
|
15
20
|
type: "object",
|
|
16
21
|
properties: {},
|
|
17
22
|
additionalProperties: false,
|
|
18
23
|
};
|
|
24
|
+
const stringSchema = { type: "string", minLength: 1 };
|
|
25
|
+
const booleanSchema = { type: "boolean" };
|
|
26
|
+
const declaredImageSchema = {
|
|
27
|
+
type: "object",
|
|
28
|
+
properties: {
|
|
29
|
+
imageId: stringSchema,
|
|
30
|
+
imageName: stringSchema,
|
|
31
|
+
projectId: stringSchema,
|
|
32
|
+
workspaceId: stringSchema,
|
|
33
|
+
targetId: stringSchema,
|
|
34
|
+
active: booleanSchema,
|
|
35
|
+
status: stringSchema,
|
|
36
|
+
},
|
|
37
|
+
required: ["imageId"],
|
|
38
|
+
additionalProperties: false,
|
|
39
|
+
};
|
|
40
|
+
const templateCreateRequestSchema = {
|
|
41
|
+
type: "object",
|
|
42
|
+
properties: {
|
|
43
|
+
templateName: stringSchema,
|
|
44
|
+
templateCategory: stringSchema,
|
|
45
|
+
},
|
|
46
|
+
required: ["templateName"],
|
|
47
|
+
additionalProperties: false,
|
|
48
|
+
};
|
|
49
|
+
const inventoryInputSchema = {
|
|
50
|
+
type: "object",
|
|
51
|
+
properties: {
|
|
52
|
+
declaredImages: {
|
|
53
|
+
type: "array",
|
|
54
|
+
items: declaredImageSchema,
|
|
55
|
+
description: "Project/workspace-declared image handles supplied by a scoped caller.",
|
|
56
|
+
},
|
|
57
|
+
templateCreateRequest: {
|
|
58
|
+
...templateCreateRequestSchema,
|
|
59
|
+
description: "Optional template image create request to evaluate for offline readiness without mutation or download.",
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
additionalProperties: false,
|
|
63
|
+
};
|
|
64
|
+
const scopedProfileSchema = {
|
|
65
|
+
type: "object",
|
|
66
|
+
properties: {
|
|
67
|
+
stateRoot: stringSchema,
|
|
68
|
+
launcherConfiguration: stringSchema,
|
|
69
|
+
imagesDir: stringSchema,
|
|
70
|
+
vmsDir: stringSchema,
|
|
71
|
+
templateSourcesDir: stringSchema,
|
|
72
|
+
initScriptsDir: stringSchema,
|
|
73
|
+
logsDir: stringSchema,
|
|
74
|
+
profileName: stringSchema,
|
|
75
|
+
},
|
|
76
|
+
additionalProperties: false,
|
|
77
|
+
};
|
|
78
|
+
const copyBetweenProfilesInputSchema = {
|
|
79
|
+
type: "object",
|
|
80
|
+
properties: {
|
|
81
|
+
sourceProfile: scopedProfileSchema,
|
|
82
|
+
destinationProfile: scopedProfileSchema,
|
|
83
|
+
sourceImageName: stringSchema,
|
|
84
|
+
destinationImageName: stringSchema,
|
|
85
|
+
},
|
|
86
|
+
required: [
|
|
87
|
+
"sourceProfile",
|
|
88
|
+
"destinationProfile",
|
|
89
|
+
"sourceImageName",
|
|
90
|
+
"destinationImageName",
|
|
91
|
+
],
|
|
92
|
+
additionalProperties: false,
|
|
93
|
+
};
|
|
19
94
|
const tools = [
|
|
20
95
|
{
|
|
21
96
|
name: "pharo_launcher_health",
|
|
@@ -37,6 +112,16 @@ const tools = [
|
|
|
37
112
|
description: "Validate resolved paths and run a harmless PharoLauncher --version call.",
|
|
38
113
|
inputSchema: emptyInputSchema,
|
|
39
114
|
},
|
|
115
|
+
{
|
|
116
|
+
name: "pharo_launcher_inventory",
|
|
117
|
+
description: "Return read-only scoped Pharo Launcher templates, versions, active profile roots, existing images, and caller-declared image handles for safe lifecycle planning.",
|
|
118
|
+
inputSchema: inventoryInputSchema,
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
name: "pharo_launcher_image_copy_between_profiles",
|
|
122
|
+
description: "Copy a launcher image from one explicitly supplied scoped launcher profile to another explicitly supplied scoped launcher profile.",
|
|
123
|
+
inputSchema: copyBetweenProfilesInputSchema,
|
|
124
|
+
},
|
|
40
125
|
...launcherCommandTools,
|
|
41
126
|
rawCommandTool,
|
|
42
127
|
];
|
|
@@ -55,8 +140,125 @@ function runnerOptions(options) {
|
|
|
55
140
|
...(options.timeoutMs !== undefined ? { timeoutMs: options.timeoutMs } : {}),
|
|
56
141
|
};
|
|
57
142
|
}
|
|
143
|
+
function inputObject(input) {
|
|
144
|
+
if (!input || typeof input !== "object" || Array.isArray(input)) {
|
|
145
|
+
return {};
|
|
146
|
+
}
|
|
147
|
+
return input;
|
|
148
|
+
}
|
|
149
|
+
function optionalString(input, key) {
|
|
150
|
+
const value = input[key];
|
|
151
|
+
if (value === undefined) {
|
|
152
|
+
return undefined;
|
|
153
|
+
}
|
|
154
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
155
|
+
throw new ToolInputError(`${key} must be a non-empty string`);
|
|
156
|
+
}
|
|
157
|
+
return value;
|
|
158
|
+
}
|
|
159
|
+
function optionalBoolean(input, key) {
|
|
160
|
+
const value = input[key];
|
|
161
|
+
if (value === undefined) {
|
|
162
|
+
return undefined;
|
|
163
|
+
}
|
|
164
|
+
if (typeof value !== "boolean") {
|
|
165
|
+
throw new ToolInputError(`${key} must be a boolean`);
|
|
166
|
+
}
|
|
167
|
+
return value;
|
|
168
|
+
}
|
|
169
|
+
function commandResultOptions(argumentsValue, options) {
|
|
170
|
+
const includeRaw = optionalBoolean(inputObject(argumentsValue), "includeRaw");
|
|
171
|
+
return includeRaw === undefined ? options : { ...options, includeRaw };
|
|
172
|
+
}
|
|
173
|
+
function normalizeToolResult(toolName, args, result, options) {
|
|
174
|
+
return normalizeLauncherResult(toolName, args, result, {
|
|
175
|
+
includeRaw: options.includeRaw,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
function declaredImagesFromInput(input) {
|
|
179
|
+
const object = inputObject(input);
|
|
180
|
+
const declaredImages = object.declaredImages;
|
|
181
|
+
if (declaredImages === undefined) {
|
|
182
|
+
return [];
|
|
183
|
+
}
|
|
184
|
+
if (!Array.isArray(declaredImages)) {
|
|
185
|
+
throw new ToolInputError("declaredImages must be an array");
|
|
186
|
+
}
|
|
187
|
+
return declaredImages.map((candidate, index) => {
|
|
188
|
+
const image = inputObject(candidate);
|
|
189
|
+
const imageId = optionalString(image, "imageId");
|
|
190
|
+
if (!imageId) {
|
|
191
|
+
throw new ToolInputError(`declaredImages[${index}].imageId is required`);
|
|
192
|
+
}
|
|
193
|
+
return {
|
|
194
|
+
imageId,
|
|
195
|
+
...(optionalString(image, "imageName")
|
|
196
|
+
? { imageName: optionalString(image, "imageName") }
|
|
197
|
+
: {}),
|
|
198
|
+
...(optionalString(image, "projectId")
|
|
199
|
+
? { projectId: optionalString(image, "projectId") }
|
|
200
|
+
: {}),
|
|
201
|
+
...(optionalString(image, "workspaceId")
|
|
202
|
+
? { workspaceId: optionalString(image, "workspaceId") }
|
|
203
|
+
: {}),
|
|
204
|
+
...(optionalString(image, "targetId")
|
|
205
|
+
? { targetId: optionalString(image, "targetId") }
|
|
206
|
+
: {}),
|
|
207
|
+
...(optionalBoolean(image, "active") !== undefined
|
|
208
|
+
? { active: optionalBoolean(image, "active") }
|
|
209
|
+
: {}),
|
|
210
|
+
...(optionalString(image, "status")
|
|
211
|
+
? { status: optionalString(image, "status") }
|
|
212
|
+
: {}),
|
|
213
|
+
};
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
function templateCreateRequestFromInput(input) {
|
|
217
|
+
const object = inputObject(input);
|
|
218
|
+
const value = object.templateCreateRequest;
|
|
219
|
+
if (value === undefined) {
|
|
220
|
+
return undefined;
|
|
221
|
+
}
|
|
222
|
+
const request = inputObject(value);
|
|
223
|
+
const templateName = optionalString(request, "templateName");
|
|
224
|
+
if (!templateName) {
|
|
225
|
+
throw new ToolInputError("templateCreateRequest.templateName is required");
|
|
226
|
+
}
|
|
227
|
+
const templateCategory = optionalString(request, "templateCategory");
|
|
228
|
+
return {
|
|
229
|
+
templateName,
|
|
230
|
+
...(templateCategory ? { templateCategory } : {}),
|
|
231
|
+
};
|
|
232
|
+
}
|
|
58
233
|
async function runLauncherToolCommand(runner, args, options) {
|
|
59
|
-
|
|
234
|
+
const startTime = Date.now();
|
|
235
|
+
try {
|
|
236
|
+
return await runner(args, runnerOptions(options));
|
|
237
|
+
}
|
|
238
|
+
catch (error) {
|
|
239
|
+
return {
|
|
240
|
+
exitCode: null,
|
|
241
|
+
stdout: "",
|
|
242
|
+
stderr: runnerExceptionDiagnostic(args, options, error),
|
|
243
|
+
durationMs: Date.now() - startTime,
|
|
244
|
+
timedOut: false,
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
function runnerExceptionDiagnostic(args, options, error) {
|
|
249
|
+
const normalizedError = error instanceof Error ? error : new Error(String(error));
|
|
250
|
+
try {
|
|
251
|
+
const invocation = buildLauncherCliInvocation(args, options.config ?? loadPharoLauncherConfig());
|
|
252
|
+
return launcherInvocationFailureDiagnostic(invocation, normalizedError);
|
|
253
|
+
}
|
|
254
|
+
catch (contextError) {
|
|
255
|
+
const contextMessage = contextError instanceof Error ? contextError.message : String(contextError);
|
|
256
|
+
return [
|
|
257
|
+
`Failed to start PharoLauncher CLI command: ${normalizedError.message}`,
|
|
258
|
+
`args: ${args.join(" ")}`,
|
|
259
|
+
`diagnosticContextError: ${contextMessage}`,
|
|
260
|
+
].join("\n");
|
|
261
|
+
}
|
|
60
262
|
}
|
|
61
263
|
function sleep(milliseconds) {
|
|
62
264
|
return new Promise((resolve) => setTimeout(resolve, milliseconds));
|
|
@@ -73,7 +275,44 @@ function imagesFromData(data) {
|
|
|
73
275
|
function namedImage(data, imageName) {
|
|
74
276
|
return imagesFromData(data).find((image) => image.name === imageName);
|
|
75
277
|
}
|
|
76
|
-
async function
|
|
278
|
+
async function inspectImageVerificationAttempt(runner, newImageName, operationLabel, options) {
|
|
279
|
+
const listArgs = buildLauncherCommandArgs("pharo_launcher_image_list", {
|
|
280
|
+
nameFilter: newImageName,
|
|
281
|
+
format: "ston",
|
|
282
|
+
});
|
|
283
|
+
const listResult = await runLauncherToolCommand(runner, listArgs ?? [], options);
|
|
284
|
+
const normalizedList = normalizeToolResult("pharo_launcher_image_list", listArgs ?? [], listResult, options);
|
|
285
|
+
const listedImage = normalizedList.ok
|
|
286
|
+
? namedImage(normalizedList.data, newImageName)
|
|
287
|
+
: undefined;
|
|
288
|
+
if (!normalizedList.ok || !listedImage) {
|
|
289
|
+
return {
|
|
290
|
+
list: normalizedList,
|
|
291
|
+
diagnostic: normalizedList.ok
|
|
292
|
+
? `${operationLabel} image did not appear in image list.`
|
|
293
|
+
: `Image list failed while verifying ${operationLabel.toLowerCase()} image.`,
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
const infoArgs = buildLauncherCommandArgs("pharo_launcher_image_info", {
|
|
297
|
+
imageName: newImageName,
|
|
298
|
+
format: "ston",
|
|
299
|
+
});
|
|
300
|
+
const infoResult = await runLauncherToolCommand(runner, infoArgs ?? [], options);
|
|
301
|
+
const normalizedInfo = normalizeToolResult("pharo_launcher_image_info", infoArgs ?? [], infoResult, options);
|
|
302
|
+
const inspectedImage = normalizedInfo.ok
|
|
303
|
+
? namedImage(normalizedInfo.data, newImageName)
|
|
304
|
+
: undefined;
|
|
305
|
+
return {
|
|
306
|
+
listedImage,
|
|
307
|
+
...(inspectedImage ? { inspectedImage } : {}),
|
|
308
|
+
list: normalizedList,
|
|
309
|
+
info: normalizedInfo,
|
|
310
|
+
diagnostic: normalizedInfo.ok && !inspectedImage
|
|
311
|
+
? `${operationLabel} image appeared in image list but could not be inspected.`
|
|
312
|
+
: `${operationLabel} image appeared in image list, but image info failed.`,
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
async function verifyImage(runner, newImageName, operationLabel, options) {
|
|
77
316
|
const startedAt = Date.now();
|
|
78
317
|
const deadline = startedAt +
|
|
79
318
|
(options.imageCopyVerificationTimeoutMs ?? imageCopyVerificationTimeoutMs);
|
|
@@ -82,51 +321,25 @@ async function verifyCopiedImage(runner, newImageName, options) {
|
|
|
82
321
|
let attempts = 0;
|
|
83
322
|
let lastList;
|
|
84
323
|
let lastInfo;
|
|
85
|
-
let diagnostic =
|
|
324
|
+
let diagnostic = `${operationLabel} image did not appear in image list.`;
|
|
86
325
|
while (true) {
|
|
87
326
|
attempts += 1;
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
});
|
|
103
|
-
const infoResult = await runLauncherToolCommand(runner, infoArgs ?? [], options);
|
|
104
|
-
const normalizedInfo = normalizeLauncherResult("pharo_launcher_image_info", infoArgs ?? [], infoResult);
|
|
105
|
-
lastInfo = normalizedInfo;
|
|
106
|
-
const inspectedImage = normalizedInfo.ok
|
|
107
|
-
? namedImage(normalizedInfo.data, newImageName)
|
|
108
|
-
: undefined;
|
|
109
|
-
if (normalizedInfo.ok && inspectedImage) {
|
|
110
|
-
return {
|
|
111
|
-
ok: true,
|
|
112
|
-
targetImageName: newImageName,
|
|
113
|
-
attempts,
|
|
114
|
-
elapsedMs: Date.now() - startedAt,
|
|
115
|
-
listedImage,
|
|
116
|
-
inspectedImage,
|
|
117
|
-
list: normalizedList,
|
|
118
|
-
info: normalizedInfo,
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
diagnostic = normalizedInfo.ok
|
|
122
|
-
? "Copied image appeared in image list but could not be inspected."
|
|
123
|
-
: "Copied image appeared in image list, but image info failed.";
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
diagnostic = normalizedList.ok
|
|
127
|
-
? "Copied image did not appear in image list."
|
|
128
|
-
: "Image list failed while verifying copied image.";
|
|
327
|
+
const attempt = await inspectImageVerificationAttempt(runner, newImageName, operationLabel, options);
|
|
328
|
+
lastList = attempt.list;
|
|
329
|
+
lastInfo = attempt.info;
|
|
330
|
+
if (attempt.listedImage && attempt.inspectedImage) {
|
|
331
|
+
return {
|
|
332
|
+
ok: true,
|
|
333
|
+
targetImageName: newImageName,
|
|
334
|
+
attempts,
|
|
335
|
+
elapsedMs: Date.now() - startedAt,
|
|
336
|
+
listedImage: attempt.listedImage,
|
|
337
|
+
inspectedImage: attempt.inspectedImage,
|
|
338
|
+
list: attempt.list,
|
|
339
|
+
...(attempt.info ? { info: attempt.info } : {}),
|
|
340
|
+
};
|
|
129
341
|
}
|
|
342
|
+
diagnostic = attempt.diagnostic ?? diagnostic;
|
|
130
343
|
const remainingMs = deadline - Date.now();
|
|
131
344
|
if (remainingMs <= 0) {
|
|
132
345
|
break;
|
|
@@ -146,13 +359,13 @@ async function verifyCopiedImage(runner, newImageName, options) {
|
|
|
146
359
|
async function imageCopyResult(args, options) {
|
|
147
360
|
const runner = options.runner ?? runLauncherCli;
|
|
148
361
|
const result = await runLauncherToolCommand(runner, args, options);
|
|
149
|
-
const normalized =
|
|
362
|
+
const normalized = normalizeToolResult("pharo_launcher_image_copy", args, result, options);
|
|
150
363
|
const newImageName = args[3];
|
|
151
364
|
if (!normalized.ok || !newImageName) {
|
|
152
365
|
return jsonResult(normalized, true);
|
|
153
366
|
}
|
|
154
367
|
const metadataRepair = repairCopiedImageMetadata(options.config ?? loadPharoLauncherConfig(), args[2], newImageName);
|
|
155
|
-
const verification = await
|
|
368
|
+
const verification = await verifyImage(runner, newImageName, "Copied", options);
|
|
156
369
|
const copyResult = {
|
|
157
370
|
...normalized,
|
|
158
371
|
ok: verification.ok,
|
|
@@ -178,16 +391,220 @@ async function imageCopyResult(args, options) {
|
|
|
178
391
|
};
|
|
179
392
|
return jsonResult(copyResult, !copyResult.ok);
|
|
180
393
|
}
|
|
394
|
+
async function imageCreateResult(args, options) {
|
|
395
|
+
const runner = options.runner ?? runLauncherCli;
|
|
396
|
+
const result = await runLauncherToolCommand(runner, args, options);
|
|
397
|
+
const normalized = normalizeToolResult("pharo_launcher_image_create", args, result, options);
|
|
398
|
+
const newImageName = args.at(-1);
|
|
399
|
+
if (!normalized.ok || !newImageName) {
|
|
400
|
+
return jsonResult(normalized, true);
|
|
401
|
+
}
|
|
402
|
+
const verification = await verifyImage(runner, newImageName, "Created", options);
|
|
403
|
+
const createResult = {
|
|
404
|
+
...normalized,
|
|
405
|
+
ok: verification.ok,
|
|
406
|
+
...(verification.ok
|
|
407
|
+
? {
|
|
408
|
+
data: {
|
|
409
|
+
...(typeof normalized.data === "object" && normalized.data !== null
|
|
410
|
+
? normalized.data
|
|
411
|
+
: {}),
|
|
412
|
+
targetImageName: newImageName,
|
|
413
|
+
listedImage: verification.listedImage,
|
|
414
|
+
inspectedImage: verification.inspectedImage,
|
|
415
|
+
createdImage: verification.inspectedImage,
|
|
416
|
+
},
|
|
417
|
+
}
|
|
418
|
+
: {}),
|
|
419
|
+
...(!verification.ok
|
|
420
|
+
? {
|
|
421
|
+
diagnostic: `Image create command exited successfully, but target image ${newImageName} was not listable and inspectable: ${verification.diagnostic}`,
|
|
422
|
+
}
|
|
423
|
+
: {}),
|
|
424
|
+
createVerification: verification,
|
|
425
|
+
};
|
|
426
|
+
return jsonResult(createResult, !createResult.ok);
|
|
427
|
+
}
|
|
428
|
+
function profileTemplateSourcesFile(config) {
|
|
429
|
+
return config?.profile
|
|
430
|
+
? path.join(config.profile.templateSourcesDir, templateSourcesFileName)
|
|
431
|
+
: undefined;
|
|
432
|
+
}
|
|
433
|
+
function nonEmptyFile(filePath) {
|
|
434
|
+
try {
|
|
435
|
+
const stat = fs.statSync(filePath);
|
|
436
|
+
return stat.isFile() && stat.size > 0;
|
|
437
|
+
}
|
|
438
|
+
catch {
|
|
439
|
+
return false;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
async function defaultFetchTemplateSources(url) {
|
|
443
|
+
const response = await fetch(url);
|
|
444
|
+
if (!response.ok) {
|
|
445
|
+
throw new Error(`HTTP ${response.status} ${response.statusText}`.trim());
|
|
446
|
+
}
|
|
447
|
+
return response.text();
|
|
448
|
+
}
|
|
449
|
+
async function ensureProfileTemplateSourcesBootstrap(config, options) {
|
|
450
|
+
const sourcesPath = profileTemplateSourcesFile(config);
|
|
451
|
+
if (!sourcesPath) {
|
|
452
|
+
return { ok: true, action: "not_applicable" };
|
|
453
|
+
}
|
|
454
|
+
if (nonEmptyFile(sourcesPath)) {
|
|
455
|
+
return {
|
|
456
|
+
ok: true,
|
|
457
|
+
action: "already_present",
|
|
458
|
+
path: sourcesPath,
|
|
459
|
+
bytes: fs.statSync(sourcesPath).size,
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
const url = options.templateSourcesUrl ?? defaultTemplateSourcesUrl;
|
|
463
|
+
try {
|
|
464
|
+
const fetchTemplateSources = options.fetchTemplateSources ?? defaultFetchTemplateSources;
|
|
465
|
+
const body = await fetchTemplateSources(url);
|
|
466
|
+
if (body.trim().length === 0) {
|
|
467
|
+
throw new Error("downloaded template source list was empty");
|
|
468
|
+
}
|
|
469
|
+
fs.mkdirSync(path.dirname(sourcesPath), { recursive: true });
|
|
470
|
+
const tempPath = `${sourcesPath}.${process.pid}.${Date.now()}.tmp`;
|
|
471
|
+
fs.writeFileSync(tempPath, body, "utf8");
|
|
472
|
+
fs.renameSync(tempPath, sourcesPath);
|
|
473
|
+
return {
|
|
474
|
+
ok: true,
|
|
475
|
+
action: "created",
|
|
476
|
+
path: sourcesPath,
|
|
477
|
+
url,
|
|
478
|
+
bytes: Buffer.byteLength(body, "utf8"),
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
catch (error) {
|
|
482
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
483
|
+
return {
|
|
484
|
+
ok: false,
|
|
485
|
+
action: "failed",
|
|
486
|
+
path: sourcesPath,
|
|
487
|
+
url,
|
|
488
|
+
diagnostic: "Pharo Launcher template update completed, but the active profile template source bootstrap file is missing or empty.",
|
|
489
|
+
error: message,
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
async function templateUpdateResult(args, options) {
|
|
494
|
+
const runner = options.runner ?? runLauncherCli;
|
|
495
|
+
const config = options.config ?? loadPharoLauncherConfig();
|
|
496
|
+
const commandOptions = {
|
|
497
|
+
...options,
|
|
498
|
+
config,
|
|
499
|
+
};
|
|
500
|
+
const result = await runLauncherToolCommand(runner, args, commandOptions);
|
|
501
|
+
const normalized = normalizeToolResult("pharo_launcher_template_update", args, result, commandOptions);
|
|
502
|
+
if (!normalized.ok) {
|
|
503
|
+
return jsonResult(normalized, true);
|
|
504
|
+
}
|
|
505
|
+
const bootstrap = await ensureProfileTemplateSourcesBootstrap(config, commandOptions);
|
|
506
|
+
if (!bootstrap.ok) {
|
|
507
|
+
return jsonResult({
|
|
508
|
+
...normalized,
|
|
509
|
+
ok: false,
|
|
510
|
+
diagnostic: bootstrap.diagnostic,
|
|
511
|
+
action: "Fetch or seed the active profile sources.list, then run pharo_launcher_template_update again before planning image creation.",
|
|
512
|
+
templateSourcesBootstrap: bootstrap,
|
|
513
|
+
}, true);
|
|
514
|
+
}
|
|
515
|
+
if (bootstrap.action === "not_applicable") {
|
|
516
|
+
return jsonResult({
|
|
517
|
+
...normalized,
|
|
518
|
+
templateSourcesBootstrap: bootstrap,
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
const probeArgs = ["template", "list", "--ston"];
|
|
522
|
+
const probeResult = normalizeToolResult("pharo_launcher_template_list", probeArgs, await runLauncherToolCommand(runner, probeArgs, commandOptions), commandOptions);
|
|
523
|
+
if (!probeResult.ok) {
|
|
524
|
+
return jsonResult({
|
|
525
|
+
...normalized,
|
|
526
|
+
ok: false,
|
|
527
|
+
diagnostic: probeResult.diagnostic ??
|
|
528
|
+
"Pharo Launcher template update completed, but template list still failed for the active profile.",
|
|
529
|
+
action: probeResult.action ??
|
|
530
|
+
"Inspect pharo_launcher_inventory diagnostics before planning image creation.",
|
|
531
|
+
templateSourcesBootstrap: bootstrap,
|
|
532
|
+
templateSourcesProbe: probeResult,
|
|
533
|
+
}, true);
|
|
534
|
+
}
|
|
535
|
+
return jsonResult({
|
|
536
|
+
...normalized,
|
|
537
|
+
templateSourcesBootstrap: bootstrap,
|
|
538
|
+
templateSourcesProbe: probeResult,
|
|
539
|
+
});
|
|
540
|
+
}
|
|
181
541
|
async function cliResult(toolName, args, options) {
|
|
182
542
|
if (toolName === "pharo_launcher_image_copy") {
|
|
183
543
|
return imageCopyResult(args, options);
|
|
184
544
|
}
|
|
545
|
+
if (toolName === "pharo_launcher_image_create") {
|
|
546
|
+
return imageCreateResult(args, options);
|
|
547
|
+
}
|
|
548
|
+
if (toolName === "pharo_launcher_template_update") {
|
|
549
|
+
return templateUpdateResult(args, options);
|
|
550
|
+
}
|
|
185
551
|
const runner = options.runner ?? runLauncherCli;
|
|
186
552
|
const result = toolName.startsWith("pharo_launcher_process_") && shouldUseNativeProcessTool()
|
|
187
553
|
? await runNativeProcessTool(args, options.timeoutMs)
|
|
188
554
|
: await runLauncherToolCommand(runner, args, options);
|
|
189
555
|
const isError = result.exitCode !== 0 || result.timedOut;
|
|
190
|
-
return jsonResult(
|
|
556
|
+
return jsonResult(normalizeToolResult(toolName, args, result, options), isError);
|
|
557
|
+
}
|
|
558
|
+
async function withToolInputErrorResult(operation) {
|
|
559
|
+
try {
|
|
560
|
+
return await operation();
|
|
561
|
+
}
|
|
562
|
+
catch (error) {
|
|
563
|
+
if (error instanceof ToolInputError) {
|
|
564
|
+
return jsonResult({ error: error.message }, true);
|
|
565
|
+
}
|
|
566
|
+
throw error;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
async function launcherVersionResult(runner, options) {
|
|
570
|
+
const result = await getPharoLauncherVersion(runner, options.config);
|
|
571
|
+
return jsonResult(result, !result.ok);
|
|
572
|
+
}
|
|
573
|
+
async function launcherInstallationValidationResult(runner, options) {
|
|
574
|
+
const result = await validatePharoLauncherInstallation(runner, options.config);
|
|
575
|
+
return jsonResult(result, !result.ok);
|
|
576
|
+
}
|
|
577
|
+
async function launcherInventoryResult(runner, argumentsValue, options) {
|
|
578
|
+
return withToolInputErrorResult(async () => {
|
|
579
|
+
const templateCreateRequest = templateCreateRequestFromInput(argumentsValue);
|
|
580
|
+
const result = await getPharoLauncherInventory(runner, options.config, {
|
|
581
|
+
declaredImages: declaredImagesFromInput(argumentsValue),
|
|
582
|
+
...(templateCreateRequest ? { templateCreateRequest } : {}),
|
|
583
|
+
...(options.timeoutMs !== undefined ? { timeoutMs: options.timeoutMs } : {}),
|
|
584
|
+
});
|
|
585
|
+
return jsonResult(result, !result.ok);
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
function profileImageCopyResult(argumentsValue) {
|
|
589
|
+
return withToolInputErrorResult(() => {
|
|
590
|
+
const result = copyImageBetweenProfiles(argumentsValue);
|
|
591
|
+
return jsonResult(result, !result.ok);
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
async function commandCatalogToolResult(name, argumentsValue, options) {
|
|
595
|
+
return withToolInputErrorResult(async () => {
|
|
596
|
+
const resultOptions = commandResultOptions(argumentsValue, options);
|
|
597
|
+
const commandArgs = buildLauncherCommandArgs(name, argumentsValue);
|
|
598
|
+
if (commandArgs) {
|
|
599
|
+
return cliResult(name, commandArgs, resultOptions);
|
|
600
|
+
}
|
|
601
|
+
if (name === rawCommandTool.name) {
|
|
602
|
+
return cliResult(name, rawCommandTool.buildArgs(argumentsValue), resultOptions);
|
|
603
|
+
}
|
|
604
|
+
return jsonResult({
|
|
605
|
+
error: `Unknown tool: ${name}`,
|
|
606
|
+
}, true);
|
|
607
|
+
});
|
|
191
608
|
}
|
|
192
609
|
export async function callTool(name, argumentsValue, options = {}) {
|
|
193
610
|
const runner = options.runner ?? runLauncherCli;
|
|
@@ -199,41 +616,16 @@ export async function callTool(name, argumentsValue, options = {}) {
|
|
|
199
616
|
});
|
|
200
617
|
case "pharo_launcher_config":
|
|
201
618
|
return jsonResult(getPharoLauncherConfigReport(options.config));
|
|
202
|
-
case "pharo_launcher_version":
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
case "
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
619
|
+
case "pharo_launcher_version":
|
|
620
|
+
return launcherVersionResult(runner, options);
|
|
621
|
+
case "pharo_launcher_validate_installation":
|
|
622
|
+
return launcherInstallationValidationResult(runner, options);
|
|
623
|
+
case "pharo_launcher_inventory":
|
|
624
|
+
return launcherInventoryResult(runner, argumentsValue, options);
|
|
625
|
+
case "pharo_launcher_image_copy_between_profiles":
|
|
626
|
+
return profileImageCopyResult(argumentsValue);
|
|
210
627
|
default:
|
|
211
|
-
|
|
212
|
-
const commandArgs = buildLauncherCommandArgs(name, argumentsValue);
|
|
213
|
-
if (commandArgs) {
|
|
214
|
-
return cliResult(name, commandArgs, options);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
catch (error) {
|
|
218
|
-
if (error instanceof ToolInputError) {
|
|
219
|
-
return jsonResult({ error: error.message }, true);
|
|
220
|
-
}
|
|
221
|
-
throw error;
|
|
222
|
-
}
|
|
223
|
-
if (name === rawCommandTool.name) {
|
|
224
|
-
try {
|
|
225
|
-
return cliResult(name, rawCommandTool.buildArgs(argumentsValue), options);
|
|
226
|
-
}
|
|
227
|
-
catch (error) {
|
|
228
|
-
if (error instanceof ToolInputError) {
|
|
229
|
-
return jsonResult({ error: error.message }, true);
|
|
230
|
-
}
|
|
231
|
-
throw error;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
return jsonResult({
|
|
235
|
-
error: `Unknown tool: ${name}`,
|
|
236
|
-
}, true);
|
|
628
|
+
return commandCatalogToolResult(name, argumentsValue, options);
|
|
237
629
|
}
|
|
238
630
|
}
|
|
239
631
|
export function createServer() {
|