@evref-bl/pharo-launcher-mcp 0.1.4 → 0.3.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.
Files changed (46) hide show
  1. package/README.md +56 -38
  2. package/dist/commandCatalog.d.ts +0 -2
  3. package/dist/commandCatalog.d.ts.map +1 -1
  4. package/dist/commandCatalog.js +14 -275
  5. package/dist/commandCatalog.js.map +1 -1
  6. package/dist/crossProfileCopy.d.ts.map +1 -1
  7. package/dist/crossProfileCopy.js +19 -0
  8. package/dist/crossProfileCopy.js.map +1 -1
  9. package/dist/discovery.d.ts +0 -151
  10. package/dist/discovery.d.ts.map +1 -1
  11. package/dist/discovery.js +0 -728
  12. package/dist/discovery.js.map +1 -1
  13. package/dist/launcher.d.ts +109 -0
  14. package/dist/launcher.d.ts.map +1 -0
  15. package/dist/launcher.js +421 -0
  16. package/dist/launcher.js.map +1 -0
  17. package/dist/launcherCli.d.ts.map +1 -1
  18. package/dist/launcherCli.js +43 -80
  19. package/dist/launcherCli.js.map +1 -1
  20. package/dist/launcherScript.d.ts +0 -1
  21. package/dist/launcherScript.d.ts.map +1 -1
  22. package/dist/launcherScript.js.map +1 -1
  23. package/dist/models.d.ts +0 -8
  24. package/dist/models.d.ts.map +1 -1
  25. package/dist/parser.d.ts +1 -3
  26. package/dist/parser.d.ts.map +1 -1
  27. package/dist/parser.js +10 -40
  28. package/dist/parser.js.map +1 -1
  29. package/dist/processTools.d.ts.map +1 -1
  30. package/dist/processTools.js +12 -4
  31. package/dist/processTools.js.map +1 -1
  32. package/dist/resultNormalizer.d.ts.map +1 -1
  33. package/dist/resultNormalizer.js +3 -14
  34. package/dist/resultNormalizer.js.map +1 -1
  35. package/dist/server.d.ts +5 -15
  36. package/dist/server.d.ts.map +1 -1
  37. package/dist/server.js +13 -530
  38. package/dist/server.js.map +1 -1
  39. package/docs/README.md +1 -1
  40. package/docs/cleanup-hook-boundary.md +5 -8
  41. package/docs/development.md +7 -1
  42. package/docs/reference/tools.md +33 -76
  43. package/docs/troubleshooting.md +11 -18
  44. package/docs/user/getting-started.md +8 -16
  45. package/docs/user/profile-mode.md +5 -8
  46. package/package.json +11 -4
package/dist/discovery.js CHANGED
@@ -1,92 +1,13 @@
1
1
  import fs from "node:fs";
2
- import crypto from "node:crypto";
3
- import path from "node:path";
4
2
  import { loadPharoLauncherConfig, } from "./config.js";
5
3
  import { runLauncherCli } from "./launcherCli.js";
6
4
  import { resolveLauncherScriptDetails, } from "./launcherScript.js";
7
- import { compactTokenText } from "./textTokens.js";
8
- import { parseLauncherTemplatesFromSton } from "./parser.js";
9
- import { normalizeLauncherResult } from "./resultNormalizer.js";
10
5
  function pathStatus(path) {
11
6
  return {
12
7
  path,
13
8
  exists: fs.existsSync(path),
14
9
  };
15
10
  }
16
- function safeIdentifierSegment(value) {
17
- return encodeURIComponent(value).replaceAll("%20", "+");
18
- }
19
- function profileId(name) {
20
- return `profile:${safeIdentifierSegment(name)}`;
21
- }
22
- function templateId(source, template) {
23
- const category = safeIdentifierSegment(template.category ?? "uncategorized");
24
- const name = safeIdentifierSegment(template.name ?? template.url ?? "unnamed");
25
- const url = template.url ? `:${safeIdentifierSegment(template.url)}` : "";
26
- return `${source}:template:${category}:${name}${url}`;
27
- }
28
- function imageId(imageName) {
29
- return `image:${safeIdentifierSegment(imageName)}`;
30
- }
31
- function versionId(pharoVersion) {
32
- return `pharo:${safeIdentifierSegment(pharoVersion)}`;
33
- }
34
- function pathKind(value) {
35
- try {
36
- const stat = fs.statSync(value);
37
- if (stat.isDirectory()) {
38
- return "directory";
39
- }
40
- if (stat.isFile()) {
41
- return "file";
42
- }
43
- return "other";
44
- }
45
- catch {
46
- return "missing";
47
- }
48
- }
49
- function isReadable(value) {
50
- try {
51
- fs.accessSync(value, fs.constants.R_OK);
52
- return true;
53
- }
54
- catch {
55
- return false;
56
- }
57
- }
58
- function addPathDiagnostic(diagnostics, input) {
59
- const kind = pathKind(input.path);
60
- if (kind === "missing") {
61
- diagnostics.push({
62
- severity: "error",
63
- code: `${input.code}_missing`,
64
- message: `${input.label} is missing: ${input.path}`,
65
- action: input.action,
66
- path: input.path,
67
- });
68
- return;
69
- }
70
- if (kind !== input.expected) {
71
- diagnostics.push({
72
- severity: "error",
73
- code: `${input.code}_not_${input.expected}`,
74
- message: `${input.label} must be an accessible ${input.expected}: ${input.path}`,
75
- action: input.action,
76
- path: input.path,
77
- });
78
- return;
79
- }
80
- if (!isReadable(input.path)) {
81
- diagnostics.push({
82
- severity: "error",
83
- code: `${input.code}_not_readable`,
84
- message: `${input.label} is not readable: ${input.path}`,
85
- action: input.action,
86
- path: input.path,
87
- });
88
- }
89
- }
90
11
  function getProfileReport(config) {
91
12
  if (!config.profile) {
92
13
  return undefined;
@@ -134,107 +55,6 @@ function installationDiscoveryReport(config) {
134
55
  candidates: discovery.candidates.map(installationCandidateReport),
135
56
  };
136
57
  }
137
- function getInventoryProfile(config) {
138
- if (!config.profile) {
139
- return undefined;
140
- }
141
- return {
142
- id: profileId(config.profile.name),
143
- active: true,
144
- name: config.profile.name,
145
- stateRoot: pathStatus(config.profile.stateRoot),
146
- launcherImage: pathStatus(config.profile.launcherImage),
147
- imagesRoot: pathStatus(config.profile.imagesDir),
148
- vmRoot: pathStatus(config.profile.vmsDir),
149
- templateSourceRoot: pathStatus(config.profile.templateSourcesDir),
150
- initScriptRoot: pathStatus(config.profile.initScriptsDir),
151
- logRoot: pathStatus(config.profile.logsDir),
152
- };
153
- }
154
- function addConfigurationDiagnostics(config, diagnostics) {
155
- addPathDiagnostic(diagnostics, {
156
- code: "launcher_dir",
157
- label: "Pharo Launcher directory",
158
- path: config.launcherDir,
159
- expected: "directory",
160
- action: "Install Pharo Launcher or set PHARO_LAUNCHER_DIR to the launcher installation directory.",
161
- });
162
- addPathDiagnostic(diagnostics, {
163
- code: "launcher_vm",
164
- label: "Pharo Launcher VM",
165
- path: config.launcherVm,
166
- expected: "file",
167
- action: "Install Pharo Launcher or set PHARO_LAUNCHER_VM to the launcher VM executable.",
168
- });
169
- addPathDiagnostic(diagnostics, {
170
- code: "launcher_image",
171
- label: "Active Pharo Launcher control image",
172
- path: config.launcherImage,
173
- expected: "file",
174
- action: "Copy or restore the active Pharo Launcher control image, or set PHARO_LAUNCHER_MCP_LAUNCHER_IMAGE/PHARO_LAUNCHER_IMAGE to an existing image.",
175
- });
176
- if (config.launcherConfiguration) {
177
- addPathDiagnostic(diagnostics, {
178
- code: "launcher_configuration",
179
- label: "Pharo Launcher CLI configuration",
180
- path: config.launcherConfiguration,
181
- expected: "file",
182
- action: "Create the launcher CLI configuration or set PHARO_LAUNCHER_MCP_LAUNCHER_CONFIGURATION to an existing configuration file.",
183
- });
184
- }
185
- }
186
- function addProfileDiagnostics(config, diagnostics) {
187
- if (!config.profile) {
188
- return;
189
- }
190
- addPathDiagnostic(diagnostics, {
191
- code: "profile_state_root",
192
- label: "Active launcher profile state root",
193
- path: config.profile.stateRoot,
194
- expected: "directory",
195
- action: "Create PHARO_LAUNCHER_MCP_STATE_ROOT or point it at an accessible profile state directory.",
196
- });
197
- for (const [code, label, directory, envName] of [
198
- [
199
- "profile_images_root",
200
- "Active launcher profile images root",
201
- config.profile.imagesDir,
202
- "PHARO_LAUNCHER_MCP_IMAGES_DIR",
203
- ],
204
- [
205
- "profile_vm_root",
206
- "Active launcher profile VM root",
207
- config.profile.vmsDir,
208
- "PHARO_LAUNCHER_MCP_VMS_DIR",
209
- ],
210
- [
211
- "profile_template_source_root",
212
- "Active launcher profile template source root",
213
- config.profile.templateSourcesDir,
214
- "PHARO_LAUNCHER_MCP_TEMPLATE_SOURCES_DIR",
215
- ],
216
- [
217
- "profile_init_script_root",
218
- "Active launcher profile init-script root",
219
- config.profile.initScriptsDir,
220
- "PHARO_LAUNCHER_MCP_INIT_SCRIPTS_DIR",
221
- ],
222
- [
223
- "profile_log_root",
224
- "Active launcher profile log root",
225
- config.profile.logsDir,
226
- "PHARO_LAUNCHER_MCP_LOGS_DIR",
227
- ],
228
- ]) {
229
- addPathDiagnostic(diagnostics, {
230
- code,
231
- label,
232
- path: directory,
233
- expected: "directory",
234
- action: `Create ${directory} or set ${envName} to an accessible directory.`,
235
- });
236
- }
237
- }
238
58
  export function getPharoLauncherConfigReport(config = loadPharoLauncherConfig()) {
239
59
  return {
240
60
  discovery: installationDiscoveryReport(config),
@@ -243,7 +63,6 @@ export function getPharoLauncherConfigReport(config = loadPharoLauncherConfig())
243
63
  installationLauncherImage: pathStatus(config.installationLauncherImage),
244
64
  launcherImage: pathStatus(config.launcherImage),
245
65
  launcherScript: resolveLauncherScriptDetails({
246
- launcherDir: config.launcherDir,
247
66
  env: {
248
67
  ...process.env,
249
68
  ...(config.launcherScript
@@ -268,553 +87,6 @@ export function getPharoLauncherHealth(config = loadPharoLauncherConfig()) {
268
87
  config: report,
269
88
  };
270
89
  }
271
- function templatesFromData(data) {
272
- if (Array.isArray(data)) {
273
- return data.filter((item) => typeof item === "object" && item !== null);
274
- }
275
- if (typeof data === "object" && data !== null) {
276
- return [data];
277
- }
278
- return [];
279
- }
280
- function imagesFromData(data) {
281
- if (Array.isArray(data)) {
282
- return data.filter((item) => typeof item === "object" && item !== null);
283
- }
284
- if (typeof data === "object" && data !== null) {
285
- return [data];
286
- }
287
- return [];
288
- }
289
- function normalizePharoVersion(value) {
290
- const trimmed = value.trim();
291
- const numeric = trimmed.match(/^(\d{2,3})(?:\.(\d+))?$/);
292
- if (!numeric) {
293
- return trimmed;
294
- }
295
- const major = numeric[1];
296
- const minor = numeric[2] ?? (major.length === 2 ? "0" : "");
297
- return `${major}${minor}`;
298
- }
299
- function pharoVersionFromTemplate(template) {
300
- const urlVersion = template.url?.match(/(?:^|[/-])(\d{2,3})(?:[./-]|$)/)?.[1];
301
- if (urlVersion) {
302
- return normalizePharoVersion(urlVersion);
303
- }
304
- const nameVersion = template.name?.match(/\b(?:Pharo|Moose)\D*(\d{2,3}(?:\.\d+)?)/i)?.[1];
305
- return nameVersion ? normalizePharoVersion(nameVersion) : undefined;
306
- }
307
- function architectureFromTemplate(template) {
308
- const source = `${template.name ?? ""} ${template.url ?? ""}`;
309
- const lower = source.toLowerCase();
310
- const compact = compactTokenText(source);
311
- if (lower.includes("aarch64") || lower.includes("arm64")) {
312
- return "arm64";
313
- }
314
- if (lower.includes("x64") || compact.includes("64bit")) {
315
- return "64";
316
- }
317
- if (lower.includes("x86") || compact.includes("32bit")) {
318
- return "32";
319
- }
320
- return undefined;
321
- }
322
- function templateSourceFile(filePath) {
323
- try {
324
- const stat = fs.statSync(filePath);
325
- if (!stat.isFile()) {
326
- return undefined;
327
- }
328
- return {
329
- path: filePath,
330
- sizeBytes: stat.size,
331
- mtimeMs: stat.mtimeMs,
332
- sha256: crypto
333
- .createHash("sha256")
334
- .update(fs.readFileSync(filePath))
335
- .digest("hex"),
336
- };
337
- }
338
- catch {
339
- return undefined;
340
- }
341
- }
342
- function inventoryTemplate(source, template, sourcePath) {
343
- if (!template.name) {
344
- return undefined;
345
- }
346
- const pharoVersion = pharoVersionFromTemplate(template);
347
- const architecture = architectureFromTemplate(template);
348
- const sourceFile = sourcePath ? templateSourceFile(sourcePath) : undefined;
349
- const category = template.category ?? "uncategorized";
350
- return {
351
- id: templateId(source, template),
352
- source,
353
- name: template.name,
354
- ...(template.category ? { category: template.category } : {}),
355
- ...(template.url ? { url: template.url } : {}),
356
- ...(architecture ? { architecture } : {}),
357
- ...(pharoVersion ? { pharoVersion } : {}),
358
- ...(sourcePath ? { sourcePath } : {}),
359
- ...(sourceFile ? { sourceFile } : {}),
360
- identity: {
361
- source,
362
- category,
363
- name: template.name,
364
- ...(template.url ? { url: template.url } : {}),
365
- ...(pharoVersion ? { pharoVersion } : {}),
366
- ...(architecture ? { architecture } : {}),
367
- ...(sourceFile ? { sourceFileSha256: sourceFile.sha256 } : {}),
368
- },
369
- createRequest: {
370
- templateName: template.name,
371
- ...(template.category ? { templateCategory: template.category } : {}),
372
- },
373
- };
374
- }
375
- function inventoryImage(image) {
376
- if (!image.name) {
377
- return undefined;
378
- }
379
- return {
380
- id: imageId(image.name),
381
- imageName: image.name,
382
- ...(image.architecture ? { architecture: image.architecture } : {}),
383
- ...(image.pharoVersion ? { pharoVersion: image.pharoVersion } : {}),
384
- ...(image.formatNumber ? { formatNumber: image.formatNumber } : {}),
385
- ...(image.imagePath ? { imagePath: image.imagePath } : {}),
386
- ...(image.originTemplate ? { originTemplate: image.originTemplate } : {}),
387
- ...(image.vmId ? { vmId: image.vmId } : {}),
388
- identity: {
389
- imageName: image.name,
390
- ...(image.architecture ? { architecture: image.architecture } : {}),
391
- ...(image.pharoVersion ? { pharoVersion: image.pharoVersion } : {}),
392
- ...(image.formatNumber ? { formatNumber: image.formatNumber } : {}),
393
- ...(image.imagePath ? { imagePath: image.imagePath } : {}),
394
- ...(image.originTemplate?.name
395
- ? { originTemplateName: image.originTemplate.name }
396
- : {}),
397
- ...(image.originTemplate?.url
398
- ? { originTemplateUrl: image.originTemplate.url }
399
- : {}),
400
- ...(image.vmId ? { vmId: image.vmId } : {}),
401
- },
402
- copyRequest: {
403
- imageName: image.name,
404
- },
405
- };
406
- }
407
- function readInstalledTemplatesFromFile(filePath, diagnostics) {
408
- try {
409
- return parseLauncherTemplatesFromSton(fs.readFileSync(filePath, "utf8"))
410
- .map((template) => inventoryTemplate("installed", template, filePath))
411
- .filter((template) => template !== undefined);
412
- }
413
- catch (error) {
414
- diagnostics.push({
415
- severity: "warning",
416
- code: "installed_template_source_unreadable",
417
- message: `Installed template source could not be read: ${filePath}`,
418
- action: "Check file permissions or remove the unreadable template source from the active profile.",
419
- path: filePath,
420
- });
421
- return [];
422
- }
423
- }
424
- function readInstalledTemplates(config, diagnostics) {
425
- if (!config.profile) {
426
- diagnostics.push({
427
- severity: "warning",
428
- code: "installed_templates_unknown_without_profile",
429
- message: "Installed template sources are only scoped when a pharo-launcher-mcp profile is active.",
430
- action: "Set PHARO_LAUNCHER_MCP_PROFILE and PHARO_LAUNCHER_MCP_STATE_ROOT to expose scoped installed template sources.",
431
- });
432
- return [];
433
- }
434
- const root = config.profile.templateSourcesDir;
435
- const kind = pathKind(root);
436
- if (kind === "file") {
437
- return readInstalledTemplatesFromFile(root, diagnostics);
438
- }
439
- if (kind !== "directory" || !isReadable(root)) {
440
- return [];
441
- }
442
- const sourcesFilePath = path.join(root, "sources.list");
443
- const sourcesFileKind = pathKind(sourcesFilePath);
444
- if (sourcesFileKind === "missing") {
445
- diagnostics.push({
446
- severity: "warning",
447
- code: "profile_template_sources_bootstrap_missing",
448
- message: "The active profile template source bootstrap file is missing, so template update/list may not populate scoped template inventory.",
449
- action: "Run pharo_launcher_template_update to fetch or seed the active profile sources.list before planning image creation.",
450
- path: sourcesFilePath,
451
- });
452
- }
453
- else if (sourcesFileKind === "file" &&
454
- fs.statSync(sourcesFilePath).size === 0) {
455
- diagnostics.push({
456
- severity: "warning",
457
- code: "profile_template_sources_bootstrap_empty",
458
- message: "The active profile template source bootstrap file is empty, so template update/list may not populate scoped template inventory.",
459
- action: "Run pharo_launcher_template_update to refresh the active profile sources.list before planning image creation.",
460
- path: sourcesFilePath,
461
- });
462
- }
463
- return fs
464
- .readdirSync(root, { withFileTypes: true })
465
- .sort((left, right) => left.name.localeCompare(right.name))
466
- .flatMap((entry) => {
467
- const entryPath = path.join(root, entry.name);
468
- if (entry.isFile() && entry.name.toLowerCase().endsWith(".ston")) {
469
- return readInstalledTemplatesFromFile(entryPath, diagnostics);
470
- }
471
- if (entry.isDirectory()) {
472
- return (inventoryTemplate("installed", { name: entry.name }, entryPath) ?? []);
473
- }
474
- return [];
475
- });
476
- }
477
- function probeSummary(result, diagnostic) {
478
- return {
479
- ok: result.ok,
480
- args: result.command.args,
481
- parserStatus: result.parser.status,
482
- durationMs: result.command.durationMs,
483
- exitCode: result.command.exitCode,
484
- timedOut: result.command.timedOut,
485
- ...(diagnostic ? { diagnostic } : {}),
486
- };
487
- }
488
- async function runInventoryProbe(toolName, args, runner, config, timeoutMs) {
489
- const result = await runner(args, {
490
- config,
491
- ...(timeoutMs !== undefined ? { timeoutMs } : {}),
492
- });
493
- return normalizeLauncherResult(toolName, args, result);
494
- }
495
- function addCommandDiagnostic(diagnostics, code, label, result) {
496
- if (result.ok) {
497
- return undefined;
498
- }
499
- const diagnostic = result.diagnostic ??
500
- `${label} failed with exit code ${result.command.exitCode ?? "unknown"}.`;
501
- diagnostics.push({
502
- severity: "error",
503
- code,
504
- message: diagnostic,
505
- action: result.action ??
506
- "Run pharo_launcher_validate_installation and inspect the command stderr before planning image creation.",
507
- });
508
- return diagnostic;
509
- }
510
- function addEmptyTemplateInventoryDiagnostic(diagnostics, config) {
511
- diagnostics.push({
512
- severity: "error",
513
- code: "template_inventory_empty",
514
- message: "The active launcher profile has no installed or downloadable templates, so image creation cannot choose a template.",
515
- action: "Run pharo_launcher_template_update, verify the active profile template source root, and seed or repair template-source bootstrap state before planning image creation.",
516
- ...(config.profile ? { path: config.profile.templateSourcesDir } : {}),
517
- });
518
- }
519
- function addProbeErrorDiagnostic(diagnostics, code, label, error) {
520
- const message = error instanceof Error ? error.message : String(error);
521
- const diagnostic = `${label} could not be executed: ${message}`;
522
- diagnostics.push({
523
- severity: "error",
524
- code,
525
- message: diagnostic,
526
- action: "Check the resolved launcher configuration and filesystem paths before planning image creation.",
527
- });
528
- return diagnostic;
529
- }
530
- function collectVersions(templates, images) {
531
- const byVersion = new Map();
532
- function versionEntry(pharoVersion) {
533
- const existing = byVersion.get(pharoVersion);
534
- if (existing) {
535
- return existing;
536
- }
537
- const entry = {
538
- id: versionId(pharoVersion),
539
- pharoVersion,
540
- templateIds: [],
541
- installedTemplateIds: [],
542
- downloadableTemplateIds: [],
543
- imageIds: [],
544
- };
545
- byVersion.set(pharoVersion, entry);
546
- return entry;
547
- }
548
- for (const template of templates) {
549
- if (!template.pharoVersion) {
550
- continue;
551
- }
552
- const entry = versionEntry(template.pharoVersion);
553
- entry.templateIds.push(template.id);
554
- if (template.source === "installed") {
555
- entry.installedTemplateIds.push(template.id);
556
- }
557
- else {
558
- entry.downloadableTemplateIds.push(template.id);
559
- }
560
- }
561
- for (const image of images) {
562
- if (!image.pharoVersion) {
563
- continue;
564
- }
565
- versionEntry(image.pharoVersion).imageIds.push(image.id);
566
- }
567
- return [...byVersion.values()].sort((left, right) => left.pharoVersion.localeCompare(right.pharoVersion, undefined, {
568
- numeric: true,
569
- }));
570
- }
571
- function templateMatchesCreateRequest(template, request) {
572
- if (template.name !== request.templateName) {
573
- return false;
574
- }
575
- return (!request.templateCategory || template.category === request.templateCategory);
576
- }
577
- function imageMatchesTemplate(image, template) {
578
- if (template.url && image.originTemplate?.url === template.url) {
579
- return true;
580
- }
581
- if (template.name && image.originTemplate?.name === template.name) {
582
- return true;
583
- }
584
- if (!template.pharoVersion || image.pharoVersion !== template.pharoVersion) {
585
- return false;
586
- }
587
- return !template.architecture || image.architecture === template.architecture;
588
- }
589
- function vmNameMatchesTemplate(value, template) {
590
- const normalized = value.toLowerCase();
591
- const version = template.pharoVersion?.toLowerCase();
592
- const majorVersion = version && version.endsWith("0") ? version.slice(0, -1) : version;
593
- const versionMatches = !version ||
594
- normalized.includes(version) ||
595
- Boolean(majorVersion && normalized.includes(majorVersion));
596
- const architecture = template.architecture?.toLowerCase();
597
- const architectureMatches = !architecture ||
598
- normalized.includes(architecture) ||
599
- (architecture === "64" && /\b(?:x64|64|64bit)\b/.test(normalized)) ||
600
- (architecture === "arm64" && /\b(?:arm64|aarch64)\b/.test(normalized));
601
- return versionMatches && architectureMatches;
602
- }
603
- function findLocalVmProof(config, template) {
604
- if (!config.profile) {
605
- return {
606
- name: "vm",
607
- status: "unknown",
608
- diagnostic: "VM readiness is unknown because no scoped launcher profile is active.",
609
- };
610
- }
611
- const root = config.profile.vmsDir;
612
- if (pathKind(root) !== "directory" || !isReadable(root)) {
613
- return {
614
- name: "vm",
615
- status: "missing",
616
- path: root,
617
- diagnostic: "The active profile VM root is missing or unreadable, so no local VM can be proven.",
618
- };
619
- }
620
- if (!template?.pharoVersion) {
621
- return {
622
- name: "vm",
623
- status: "unknown",
624
- path: root,
625
- diagnostic: "VM readiness is unknown because the selected template has no Pharo version metadata.",
626
- };
627
- }
628
- const entries = fs.readdirSync(root, { withFileTypes: true });
629
- const match = entries.find((entry) => vmNameMatchesTemplate(entry.name, template));
630
- if (!match) {
631
- return {
632
- name: "vm",
633
- status: "missing",
634
- path: root,
635
- diagnostic: "No profile-local VM matched the selected template version and architecture.",
636
- };
637
- }
638
- return {
639
- name: "vm",
640
- status: "ready",
641
- path: path.join(root, match.name),
642
- diagnostic: "A profile-local VM matches the selected template version and architecture.",
643
- };
644
- }
645
- function selectedTemplate(options) {
646
- const installedTemplate = options.installedTemplates.find((template) => templateMatchesCreateRequest(template, options.request));
647
- const downloadableTemplate = options.downloadableTemplates.find((template) => templateMatchesCreateRequest(template, options.request));
648
- const template = installedTemplate ?? downloadableTemplate;
649
- return { installedTemplate, downloadableTemplate, template };
650
- }
651
- function templateSourceReadinessInput(options, installedTemplate, downloadableTemplate) {
652
- if (installedTemplate) {
653
- return {
654
- name: "templateSource",
655
- status: "ready",
656
- templateId: installedTemplate.id,
657
- ...(installedTemplate.sourcePath
658
- ? { path: installedTemplate.sourcePath }
659
- : {}),
660
- diagnostic: "The selected template is present in the active profile template source catalog.",
661
- };
662
- }
663
- return {
664
- name: "templateSource",
665
- status: "missing",
666
- ...(options.config.profile
667
- ? { path: options.config.profile.templateSourcesDir }
668
- : {}),
669
- diagnostic: downloadableTemplate
670
- ? "The selected template is known only from downloadable inventory, not from the active profile template source catalog."
671
- : "The selected template is not present in the active profile template source catalog.",
672
- };
673
- }
674
- function baseImageReadinessInput(baseImage, existingKnown) {
675
- if (baseImage) {
676
- return {
677
- name: "baseImage",
678
- status: "ready",
679
- imageId: baseImage.id,
680
- ...(baseImage.imagePath ? { path: baseImage.imagePath } : {}),
681
- diagnostic: "An existing image proves the selected template base artifact is already local.",
682
- };
683
- }
684
- return {
685
- name: "baseImage",
686
- status: existingKnown ? "missing" : "unknown",
687
- diagnostic: existingKnown
688
- ? "No existing image proves the selected template base artifact is already local."
689
- : "Base image artifact readiness is unknown because existing image inventory could not be read.",
690
- };
691
- }
692
- function readinessStatus(inputs) {
693
- return inputs.some((input) => input.status === "missing")
694
- ? "missing"
695
- : inputs.some((input) => input.status === "unknown")
696
- ? "unknown"
697
- : "ready";
698
- }
699
- function templateCreateReadiness(options) {
700
- const { installedTemplate, downloadableTemplate, template } = selectedTemplate(options);
701
- const baseImage = template &&
702
- options.existingImages.find((image) => imageMatchesTemplate(image, template));
703
- const inputs = [
704
- templateSourceReadinessInput(options, installedTemplate, downloadableTemplate),
705
- baseImageReadinessInput(baseImage, options.existingKnown),
706
- findLocalVmProof(options.config, template),
707
- ];
708
- return {
709
- status: readinessStatus(inputs),
710
- request: options.request,
711
- inputs,
712
- ...(template ? { template } : {}),
713
- ...(baseImage ? { baseImage } : {}),
714
- diagnostics: inputs
715
- .filter((input) => input.status !== "ready")
716
- .map((input) => input.diagnostic),
717
- };
718
- }
719
- export async function getPharoLauncherInventory(runner = runLauncherCli, config = loadPharoLauncherConfig(), options = {}) {
720
- const diagnostics = [];
721
- const configReport = getPharoLauncherConfigReport(config);
722
- const activeProfile = getInventoryProfile(config);
723
- const profiles = {
724
- ...(activeProfile ? { active: activeProfile } : {}),
725
- available: activeProfile ? [activeProfile] : [],
726
- };
727
- addConfigurationDiagnostics(config, diagnostics);
728
- addProfileDiagnostics(config, diagnostics);
729
- const installedTemplates = readInstalledTemplates(config, diagnostics);
730
- const probes = {};
731
- let downloadableTemplates = [];
732
- let existingImages = [];
733
- let downloadableKnown = false;
734
- let existingKnown = false;
735
- if (!diagnostics.some((diagnostic) => diagnostic.severity === "error")) {
736
- try {
737
- const templateList = await runInventoryProbe("pharo_launcher_template_list", ["template", "list", "--ston"], runner, config, options.timeoutMs);
738
- const diagnostic = addCommandDiagnostic(diagnostics, "downloadable_template_probe_failed", "Downloadable template inventory", templateList);
739
- probes.templateList = probeSummary(templateList, diagnostic);
740
- downloadableKnown = templateList.ok;
741
- downloadableTemplates = templateList.ok
742
- ? templatesFromData(templateList.data)
743
- .map((template) => inventoryTemplate("downloadable", template))
744
- .filter((template) => template !== undefined)
745
- : [];
746
- }
747
- catch (error) {
748
- probes.templateList = {
749
- ok: false,
750
- args: ["template", "list", "--ston"],
751
- parserStatus: "skipped",
752
- durationMs: 0,
753
- exitCode: null,
754
- timedOut: false,
755
- diagnostic: addProbeErrorDiagnostic(diagnostics, "downloadable_template_probe_error", "Downloadable template inventory", error),
756
- };
757
- }
758
- try {
759
- const imageList = await runInventoryProbe("pharo_launcher_image_list", ["image", "list", "--ston"], runner, config, options.timeoutMs);
760
- const diagnostic = addCommandDiagnostic(diagnostics, "existing_image_probe_failed", "Existing image inventory", imageList);
761
- probes.imageList = probeSummary(imageList, diagnostic);
762
- existingKnown = imageList.ok;
763
- existingImages = imageList.ok
764
- ? imagesFromData(imageList.data)
765
- .map(inventoryImage)
766
- .filter((image) => image !== undefined)
767
- : [];
768
- }
769
- catch (error) {
770
- probes.imageList = {
771
- ok: false,
772
- args: ["image", "list", "--ston"],
773
- parserStatus: "skipped",
774
- durationMs: 0,
775
- exitCode: null,
776
- timedOut: false,
777
- diagnostic: addProbeErrorDiagnostic(diagnostics, "existing_image_probe_error", "Existing image inventory", error),
778
- };
779
- }
780
- }
781
- const allTemplates = [...installedTemplates, ...downloadableTemplates];
782
- if (downloadableKnown &&
783
- installedTemplates.length === 0 &&
784
- downloadableTemplates.length === 0) {
785
- addEmptyTemplateInventoryDiagnostic(diagnostics, config);
786
- }
787
- const readiness = options.templateCreateRequest
788
- ? templateCreateReadiness({
789
- config,
790
- request: options.templateCreateRequest,
791
- installedTemplates,
792
- downloadableTemplates,
793
- existingImages,
794
- existingKnown,
795
- })
796
- : undefined;
797
- return {
798
- ok: !diagnostics.some((diagnostic) => diagnostic.severity === "error"),
799
- service: "pharo-launcher-mcp",
800
- config: configReport,
801
- profiles,
802
- templates: {
803
- installed: installedTemplates,
804
- downloadable: downloadableTemplates,
805
- downloadableKnown,
806
- },
807
- versions: collectVersions(allTemplates, existingImages),
808
- images: {
809
- existing: existingImages,
810
- existingKnown,
811
- declared: [...(options.declaredImages ?? [])],
812
- },
813
- probes,
814
- ...(readiness ? { templateCreateReadiness: readiness } : {}),
815
- diagnostics,
816
- };
817
- }
818
90
  function isVersionTokenCharacter(char) {
819
91
  return ((char >= "0" && char <= "9") ||
820
92
  (char >= "A" && char <= "Z") ||