@evref-bl/plexus 0.0.0-stage → 0.1.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 (122) hide show
  1. package/README.md +11 -2
  2. package/dist/cli.d.ts +3 -0
  3. package/dist/cli.d.ts.map +1 -0
  4. package/dist/cli.js +296 -0
  5. package/dist/cli.js.map +1 -0
  6. package/dist/config/config.d.ts +29 -0
  7. package/dist/config/config.d.ts.map +1 -0
  8. package/dist/config/config.js +111 -0
  9. package/dist/config/config.js.map +1 -0
  10. package/dist/config/plexusHome.d.ts +17 -0
  11. package/dist/config/plexusHome.d.ts.map +1 -0
  12. package/dist/config/plexusHome.js +30 -0
  13. package/dist/config/plexusHome.js.map +1 -0
  14. package/dist/config/projectConfig.d.ts +228 -0
  15. package/dist/config/projectConfig.d.ts.map +1 -0
  16. package/dist/config/projectConfig.js +1159 -0
  17. package/dist/config/projectConfig.js.map +1 -0
  18. package/dist/config/target.d.ts +19 -0
  19. package/dist/config/target.d.ts.map +1 -0
  20. package/dist/config/target.js +2 -0
  21. package/dist/config/target.js.map +1 -0
  22. package/dist/gateway/projectGateway.d.ts +80 -0
  23. package/dist/gateway/projectGateway.d.ts.map +1 -0
  24. package/dist/gateway/projectGateway.js +435 -0
  25. package/dist/gateway/projectGateway.js.map +1 -0
  26. package/dist/gateway/projectImageMcpEndpoint.d.ts +24 -0
  27. package/dist/gateway/projectImageMcpEndpoint.d.ts.map +1 -0
  28. package/dist/gateway/projectImageMcpEndpoint.js +79 -0
  29. package/dist/gateway/projectImageMcpEndpoint.js.map +1 -0
  30. package/dist/images/homeImageCache.d.ts +264 -0
  31. package/dist/images/homeImageCache.d.ts.map +1 -0
  32. package/dist/images/homeImageCache.js +930 -0
  33. package/dist/images/homeImageCache.js.map +1 -0
  34. package/dist/images/imageRescue.d.ts +155 -0
  35. package/dist/images/imageRescue.d.ts.map +1 -0
  36. package/dist/images/imageRescue.js +847 -0
  37. package/dist/images/imageRescue.js.map +1 -0
  38. package/dist/images/preparedImageCache.d.ts +90 -0
  39. package/dist/images/preparedImageCache.d.ts.map +1 -0
  40. package/dist/images/preparedImageCache.js +237 -0
  41. package/dist/images/preparedImageCache.js.map +1 -0
  42. package/dist/images/scopedTemplateCatalog.d.ts +32 -0
  43. package/dist/images/scopedTemplateCatalog.d.ts.map +1 -0
  44. package/dist/images/scopedTemplateCatalog.js +316 -0
  45. package/dist/images/scopedTemplateCatalog.js.map +1 -0
  46. package/dist/index.d.ts +22 -0
  47. package/dist/index.d.ts.map +1 -0
  48. package/dist/index.js +22 -0
  49. package/dist/index.js.map +1 -0
  50. package/dist/launcher/pharoLauncherMcpClient.d.ts +17 -0
  51. package/dist/launcher/pharoLauncherMcpClient.d.ts.map +1 -0
  52. package/dist/launcher/pharoLauncherMcpClient.js +78 -0
  53. package/dist/launcher/pharoLauncherMcpClient.js.map +1 -0
  54. package/dist/launcher/pharoLauncherProfile.d.ts +31 -0
  55. package/dist/launcher/pharoLauncherProfile.d.ts.map +1 -0
  56. package/dist/launcher/pharoLauncherProfile.js +122 -0
  57. package/dist/launcher/pharoLauncherProfile.js.map +1 -0
  58. package/dist/launcher/scopedPharoLauncherServer.d.ts +247 -0
  59. package/dist/launcher/scopedPharoLauncherServer.d.ts.map +1 -0
  60. package/dist/launcher/scopedPharoLauncherServer.js +1097 -0
  61. package/dist/launcher/scopedPharoLauncherServer.js.map +1 -0
  62. package/dist/lifecycle/projectCleanup.d.ts +59 -0
  63. package/dist/lifecycle/projectCleanup.d.ts.map +1 -0
  64. package/dist/lifecycle/projectCleanup.js +483 -0
  65. package/dist/lifecycle/projectCleanup.js.map +1 -0
  66. package/dist/lifecycle/projectClose.d.ts +35 -0
  67. package/dist/lifecycle/projectClose.d.ts.map +1 -0
  68. package/dist/lifecycle/projectClose.js +273 -0
  69. package/dist/lifecycle/projectClose.js.map +1 -0
  70. package/dist/lifecycle/projectLifecycle.d.ts +422 -0
  71. package/dist/lifecycle/projectLifecycle.d.ts.map +1 -0
  72. package/dist/lifecycle/projectLifecycle.js +2114 -0
  73. package/dist/lifecycle/projectLifecycle.js.map +1 -0
  74. package/dist/lifecycle/projectOpen.d.ts +68 -0
  75. package/dist/lifecycle/projectOpen.d.ts.map +1 -0
  76. package/dist/lifecycle/projectOpen.js +1471 -0
  77. package/dist/lifecycle/projectOpen.js.map +1 -0
  78. package/dist/mcp/pharoMcpHealth.d.ts +26 -0
  79. package/dist/mcp/pharoMcpHealth.d.ts.map +1 -0
  80. package/dist/mcp/pharoMcpHealth.js +97 -0
  81. package/dist/mcp/pharoMcpHealth.js.map +1 -0
  82. package/dist/mcp/server.d.ts +86 -0
  83. package/dist/mcp/server.d.ts.map +1 -0
  84. package/dist/mcp/server.js +357 -0
  85. package/dist/mcp/server.js.map +1 -0
  86. package/dist/ports/imagePortClaims.d.ts +41 -0
  87. package/dist/ports/imagePortClaims.d.ts.map +1 -0
  88. package/dist/ports/imagePortClaims.js +337 -0
  89. package/dist/ports/imagePortClaims.js.map +1 -0
  90. package/dist/ports/portClaims.d.ts +116 -0
  91. package/dist/ports/portClaims.d.ts.map +1 -0
  92. package/dist/ports/portClaims.js +393 -0
  93. package/dist/ports/portClaims.js.map +1 -0
  94. package/dist/support/pathStyle.d.ts +11 -0
  95. package/dist/support/pathStyle.d.ts.map +1 -0
  96. package/dist/support/pathStyle.js +61 -0
  97. package/dist/support/pathStyle.js.map +1 -0
  98. package/dist/support/runtimeIdentity.d.ts +13 -0
  99. package/dist/support/runtimeIdentity.d.ts.map +1 -0
  100. package/dist/support/runtimeIdentity.js +38 -0
  101. package/dist/support/runtimeIdentity.js.map +1 -0
  102. package/dist/support/toolResultFormatting.d.ts +8 -0
  103. package/dist/support/toolResultFormatting.d.ts.map +1 -0
  104. package/dist/support/toolResultFormatting.js +81 -0
  105. package/dist/support/toolResultFormatting.js.map +1 -0
  106. package/dist/workspace/projectRepositoryWorkspace.d.ts +74 -0
  107. package/dist/workspace/projectRepositoryWorkspace.d.ts.map +1 -0
  108. package/dist/workspace/projectRepositoryWorkspace.js +553 -0
  109. package/dist/workspace/projectRepositoryWorkspace.js.map +1 -0
  110. package/dist/workspace/projectStartupScript.d.ts +74 -0
  111. package/dist/workspace/projectStartupScript.d.ts.map +1 -0
  112. package/dist/workspace/projectStartupScript.js +748 -0
  113. package/dist/workspace/projectStartupScript.js.map +1 -0
  114. package/dist/workspace/projectState.d.ts +319 -0
  115. package/dist/workspace/projectState.d.ts.map +1 -0
  116. package/dist/workspace/projectState.js +399 -0
  117. package/dist/workspace/projectState.js.map +1 -0
  118. package/dist/workspace/scopedProjectContext.d.ts +169 -0
  119. package/dist/workspace/scopedProjectContext.d.ts.map +1 -0
  120. package/dist/workspace/scopedProjectContext.js +358 -0
  121. package/dist/workspace/scopedProjectContext.js.map +1 -0
  122. package/package.json +39 -4
@@ -0,0 +1,930 @@
1
+ import crypto from "node:crypto";
2
+ import fs from "node:fs";
3
+ import { defaultPharoMcpMetacelloRepository, } from "../workspace/projectStartupScript.js";
4
+ import { projectConfigId, projectMcpStartupMode, resolveProjectRuntimePolicy, } from "../config/projectConfig.js";
5
+ import { homeImageCacheDirectoryName, homeImageCacheEnabled, homeImageCacheNetworkPolicy, resolvePlexusHomePath, } from "../config/plexusHome.js";
6
+ import { dirnamePathLike, isAbsolutePathLike, joinPathLike, resolvePathLike, } from "../support/pathStyle.js";
7
+ import { pharoLauncherMcpProfileEnvironment, } from "../launcher/pharoLauncherProfile.js";
8
+ import { createStdioPharoLauncherMcpClient, } from "../launcher/pharoLauncherMcpClient.js";
9
+ export const homeImageCacheSchemaVersion = 1;
10
+ export { defaultPlexusHomePath, defaultPlexusHomeDirectoryName, homeDependencyIcebergDirectoryName, homeDependencyRepositoriesDirectoryName, homeDependencyRepositoryCachePath, homeDependencyRepositoryNetworkPolicy, homeImageCacheDirectoryName, homeImageCacheEnabled, homeImageCacheNetworkPolicy, plexusHomeEnvironmentKey, resolvePlexusHomePath, } from "../config/plexusHome.js";
11
+ export class HomeImageCacheError extends Error {
12
+ constructor(message) {
13
+ super(message);
14
+ this.name = "HomeImageCacheError";
15
+ }
16
+ }
17
+ function removeUndefined(value) {
18
+ if (Array.isArray(value)) {
19
+ return value.map(removeUndefined);
20
+ }
21
+ if (value && typeof value === "object") {
22
+ const entries = Object.entries(value)
23
+ .filter(([, entryValue]) => entryValue !== undefined)
24
+ .map(([key, entryValue]) => [key, removeUndefined(entryValue)])
25
+ .sort(([left], [right]) => left.localeCompare(right));
26
+ return Object.fromEntries(entries);
27
+ }
28
+ return value;
29
+ }
30
+ function stableJson(value) {
31
+ return JSON.stringify(removeUndefined(value));
32
+ }
33
+ function sha256Hex(value) {
34
+ return crypto.createHash("sha256").update(value).digest("hex");
35
+ }
36
+ function safeCacheKey(value) {
37
+ if (!/^[a-f0-9]{64}$/.test(value)) {
38
+ throw new HomeImageCacheError(`Invalid home image cache key: ${value}`);
39
+ }
40
+ return value;
41
+ }
42
+ function toMetacelloRepository(repository) {
43
+ return repository ?? defaultPharoMcpMetacelloRepository;
44
+ }
45
+ function resolveMcpLoadScriptPath(projectRoot, mcp) {
46
+ return isAbsolutePathLike(mcp.loadScript)
47
+ ? resolvePathLike(mcp.loadScript)
48
+ : resolvePathLike(projectRoot, mcp.loadScript);
49
+ }
50
+ function sourceFromProjectImage(config, imageConfig) {
51
+ if (imageConfig.preparedImage?.cacheId) {
52
+ const preparedImage = config.preparedImages?.find((candidate) => candidate.id === imageConfig.preparedImage?.cacheId);
53
+ if (!preparedImage) {
54
+ throw new HomeImageCacheError(`Project image ${imageConfig.id} references unknown prepared image cache: ${imageConfig.preparedImage.cacheId}`);
55
+ }
56
+ return {
57
+ source: preparedSource(preparedImage),
58
+ mcp: preparedImage.mcp,
59
+ };
60
+ }
61
+ if (imageConfig.create) {
62
+ return {
63
+ source: createSource(imageConfig.create),
64
+ mcp: imageConfig.mcp,
65
+ };
66
+ }
67
+ throw new HomeImageCacheError(`Project image ${imageConfig.id} has no template create or prepared image source`);
68
+ }
69
+ export function projectImageCanUseHomeImageCache(imageConfig) {
70
+ return Boolean(imageConfig.create || imageConfig.preparedImage?.cacheId);
71
+ }
72
+ function createSource(source) {
73
+ return {
74
+ kind: "template",
75
+ ...(source.profileId ? { profileId: source.profileId } : {}),
76
+ templateName: source.templateName,
77
+ ...(source.templateCategory
78
+ ? { templateCategory: source.templateCategory }
79
+ : {}),
80
+ };
81
+ }
82
+ function preparedSource(preparedImage) {
83
+ return preparedTemplateSource(preparedImage.source);
84
+ }
85
+ function preparedTemplateSource(source) {
86
+ return {
87
+ kind: "template",
88
+ ...(source.profileId ? { profileId: source.profileId } : {}),
89
+ templateName: source.templateName,
90
+ ...(source.templateCategory
91
+ ? { templateCategory: source.templateCategory }
92
+ : {}),
93
+ };
94
+ }
95
+ export function homeImageCacheRootPath(homePath) {
96
+ return joinPathLike(homePath, homeImageCacheDirectoryName);
97
+ }
98
+ export function homeImageCacheEntryDirectory(cacheRoot, key) {
99
+ return joinPathLike(cacheRoot, "entries", safeCacheKey(key));
100
+ }
101
+ export function homeImageCacheManifestPath(cacheRoot, key) {
102
+ return joinPathLike(homeImageCacheEntryDirectory(cacheRoot, key), "manifest.json");
103
+ }
104
+ export function homeImageCacheLockPath(cacheRoot, key) {
105
+ return joinPathLike(cacheRoot, "locks", safeCacheKey(key));
106
+ }
107
+ export function homeImageCachePreparationScriptPath(cacheRoot, key) {
108
+ return joinPathLike(homeImageCacheEntryDirectory(cacheRoot, key), "prepare.st");
109
+ }
110
+ export function homeImageCachePreparationStatusPath(cacheRoot, key) {
111
+ return joinPathLike(homeImageCacheEntryDirectory(cacheRoot, key), "preparation-status.properties");
112
+ }
113
+ export function homeImageCacheImageName(key) {
114
+ return `PlexusHomeCache-${safeCacheKey(key).slice(0, 24)}`;
115
+ }
116
+ export function homeImageCacheProfile(homePath) {
117
+ const stateRoot = joinPathLike(homePath, "profiles", "pharo-launcher-mcp", "image-cache");
118
+ return {
119
+ profileName: "plexus-home-image-cache",
120
+ stateRoot,
121
+ launcherImage: joinPathLike(stateRoot, "launcher", "PharoLauncher.image"),
122
+ imagesDir: joinPathLike(stateRoot, "images"),
123
+ vmsDir: joinPathLike(stateRoot, "vms"),
124
+ templateSourcesDir: joinPathLike(stateRoot, "templates"),
125
+ initScriptsDir: joinPathLike(stateRoot, "init-scripts"),
126
+ logsDir: joinPathLike(stateRoot, "logs"),
127
+ launcherConfiguration: joinPathLike(stateRoot, "launcher", "pharo-launcher-cli-config.ston"),
128
+ };
129
+ }
130
+ export function profileEnvironmentFromPaths(paths) {
131
+ return {
132
+ PHARO_LAUNCHER_MCP_PROFILE: paths.profileName,
133
+ PHARO_LAUNCHER_MCP_STATE_ROOT: paths.stateRoot,
134
+ PHARO_LAUNCHER_MCP_LAUNCHER_IMAGE: paths.launcherImage,
135
+ PHARO_LAUNCHER_MCP_IMAGES_DIR: paths.imagesDir,
136
+ PHARO_LAUNCHER_MCP_VMS_DIR: paths.vmsDir,
137
+ PHARO_LAUNCHER_MCP_TEMPLATE_SOURCES_DIR: paths.templateSourcesDir,
138
+ PHARO_LAUNCHER_MCP_INIT_SCRIPTS_DIR: paths.initScriptsDir,
139
+ PHARO_LAUNCHER_MCP_LOGS_DIR: paths.logsDir,
140
+ PHARO_LAUNCHER_MCP_LAUNCHER_CONFIGURATION: paths.launcherConfiguration,
141
+ };
142
+ }
143
+ export function profilePathsFromEnvironment(environment) {
144
+ if (!environment) {
145
+ return undefined;
146
+ }
147
+ const requiredKeys = [
148
+ "PHARO_LAUNCHER_MCP_PROFILE",
149
+ "PHARO_LAUNCHER_MCP_STATE_ROOT",
150
+ "PHARO_LAUNCHER_MCP_LAUNCHER_IMAGE",
151
+ "PHARO_LAUNCHER_MCP_IMAGES_DIR",
152
+ "PHARO_LAUNCHER_MCP_VMS_DIR",
153
+ "PHARO_LAUNCHER_MCP_TEMPLATE_SOURCES_DIR",
154
+ "PHARO_LAUNCHER_MCP_INIT_SCRIPTS_DIR",
155
+ "PHARO_LAUNCHER_MCP_LOGS_DIR",
156
+ "PHARO_LAUNCHER_MCP_LAUNCHER_CONFIGURATION",
157
+ ];
158
+ if (requiredKeys.some((key) => !environment[key])) {
159
+ return undefined;
160
+ }
161
+ return {
162
+ profileName: environment.PHARO_LAUNCHER_MCP_PROFILE,
163
+ stateRoot: environment.PHARO_LAUNCHER_MCP_STATE_ROOT,
164
+ launcherImage: environment.PHARO_LAUNCHER_MCP_LAUNCHER_IMAGE,
165
+ imagesDir: environment.PHARO_LAUNCHER_MCP_IMAGES_DIR,
166
+ vmsDir: environment.PHARO_LAUNCHER_MCP_VMS_DIR,
167
+ templateSourcesDir: environment.PHARO_LAUNCHER_MCP_TEMPLATE_SOURCES_DIR,
168
+ initScriptsDir: environment.PHARO_LAUNCHER_MCP_INIT_SCRIPTS_DIR,
169
+ logsDir: environment.PHARO_LAUNCHER_MCP_LOGS_DIR,
170
+ launcherConfiguration: environment.PHARO_LAUNCHER_MCP_LAUNCHER_CONFIGURATION,
171
+ };
172
+ }
173
+ export function inferPharoMajorVersionFromTemplateText(value) {
174
+ if (!value) {
175
+ return undefined;
176
+ }
177
+ const namedMatch = /\b(?:Pharo|Moose)\s*(\d{1,2})(?:\.\d+)?\b/i.exec(value);
178
+ if (namedMatch) {
179
+ return Number.parseInt(namedMatch[1], 10);
180
+ }
181
+ const numericMatch = /^(\d{1,2})(?:\.\d+)?$/.exec(value.trim());
182
+ if (numericMatch) {
183
+ return Number.parseInt(numericMatch[1], 10);
184
+ }
185
+ const launcherVersionMatch = /^(\d{2})0$/.exec(value.trim());
186
+ if (launcherVersionMatch) {
187
+ return Number.parseInt(launcherVersionMatch[1], 10);
188
+ }
189
+ return undefined;
190
+ }
191
+ export function classifyHomeImageCachePharoMcpSupport(options) {
192
+ const policy = resolveProjectRuntimePolicy(options.config).pharoMcp;
193
+ const majorVersion = inferPharoMajorVersionFromTemplateText(options.templateMetadata?.pharoVersion) ?? inferPharoMajorVersionFromTemplateText(options.source.templateName);
194
+ if (majorVersion === undefined) {
195
+ return {
196
+ status: "unknown",
197
+ metadataKey: policy.metadataKey,
198
+ supportedMajorVersions: [...policy.supportedMajorVersions],
199
+ reason: "PLexus could not infer the Pharo major version from launcher template metadata.",
200
+ };
201
+ }
202
+ const supported = policy.supportedMajorVersions.includes(majorVersion);
203
+ return {
204
+ status: supported ? "supported" : "unsupported",
205
+ metadataKey: policy.metadataKey,
206
+ actualMajorVersion: majorVersion,
207
+ supportedMajorVersions: [...policy.supportedMajorVersions],
208
+ reason: supported
209
+ ? `Pharo ${majorVersion} is supported for Pharo MCP preparation.`
210
+ : `Pharo ${majorVersion} is not supported for Pharo MCP preparation.`,
211
+ };
212
+ }
213
+ export function homeImageCacheKeyMaterial(options) {
214
+ const support = classifyHomeImageCachePharoMcpSupport({
215
+ config: options.config,
216
+ source: options.source,
217
+ templateMetadata: options.templateMetadata,
218
+ });
219
+ const startupMode = projectMcpStartupMode(options.mcp);
220
+ return {
221
+ schemaVersion: homeImageCacheSchemaVersion,
222
+ projectCachePolicy: {
223
+ pharoMcpPreparation: startupMode === "disabled" ? "disabled" : "load-when-supported",
224
+ pharoMcpStartupMode: startupMode,
225
+ },
226
+ source: options.source,
227
+ ...(options.templateMetadata ? { templateMetadata: options.templateMetadata } : {}),
228
+ pharoMcp: {
229
+ support,
230
+ },
231
+ ...(options.git ? { git: { transport: options.git.transport } } : {}),
232
+ };
233
+ }
234
+ export function deriveHomeImageCacheKey(material) {
235
+ return sha256Hex(stableJson(material));
236
+ }
237
+ export function readHomeImageCacheManifest(manifestPath) {
238
+ if (!fs.existsSync(manifestPath)) {
239
+ return { status: "missing", manifestPath };
240
+ }
241
+ try {
242
+ return {
243
+ status: "ok",
244
+ manifestPath,
245
+ manifest: JSON.parse(fs.readFileSync(manifestPath, "utf8")),
246
+ };
247
+ }
248
+ catch (error) {
249
+ return {
250
+ status: "corrupt",
251
+ manifestPath,
252
+ error: error instanceof Error ? error.message : String(error),
253
+ };
254
+ }
255
+ }
256
+ export function writeHomeImageCacheManifest(manifest) {
257
+ fs.mkdirSync(dirnamePathLike(manifest.paths.manifestPath), { recursive: true });
258
+ const temporaryPath = `${manifest.paths.manifestPath}.tmp-${process.pid}`;
259
+ fs.writeFileSync(temporaryPath, `${JSON.stringify(manifest, null, 2)}\n`, "utf8");
260
+ fs.renameSync(temporaryPath, manifest.paths.manifestPath);
261
+ }
262
+ export function readHomeImageCacheLock(lockPath) {
263
+ const lockFile = joinPathLike(lockPath, "lock.json");
264
+ if (!fs.existsSync(lockFile)) {
265
+ if (fs.existsSync(lockPath)) {
266
+ return {
267
+ status: "corrupt",
268
+ lockPath,
269
+ error: "Lock directory exists without lock.json",
270
+ };
271
+ }
272
+ return { status: "missing", lockPath };
273
+ }
274
+ try {
275
+ return {
276
+ status: "ok",
277
+ lockPath,
278
+ lock: JSON.parse(fs.readFileSync(lockFile, "utf8")),
279
+ };
280
+ }
281
+ catch (error) {
282
+ return {
283
+ status: "corrupt",
284
+ lockPath,
285
+ error: error instanceof Error ? error.message : String(error),
286
+ };
287
+ }
288
+ }
289
+ export function tryAcquireHomeImageCacheLock(options) {
290
+ fs.mkdirSync(dirnamePathLike(options.lockPath), { recursive: true });
291
+ try {
292
+ fs.mkdirSync(options.lockPath, { recursive: false });
293
+ }
294
+ catch {
295
+ return {
296
+ acquired: false,
297
+ current: readHomeImageCacheLock(options.lockPath),
298
+ };
299
+ }
300
+ const lock = {
301
+ key: options.key,
302
+ owner: options.owner,
303
+ acquiredAt: (options.now ?? (() => new Date()))().toISOString(),
304
+ };
305
+ fs.writeFileSync(joinPathLike(options.lockPath, "lock.json"), `${JSON.stringify(lock, null, 2)}\n`, "utf8");
306
+ return { acquired: true, lock };
307
+ }
308
+ export function releaseHomeImageCacheLock(lockPath) {
309
+ fs.rmSync(lockPath, { recursive: true, force: true });
310
+ }
311
+ export function listHomeImageCacheManifests(cacheRoot) {
312
+ const entriesRoot = joinPathLike(cacheRoot, "entries");
313
+ if (!fs.existsSync(entriesRoot)) {
314
+ return [];
315
+ }
316
+ return fs
317
+ .readdirSync(entriesRoot, { withFileTypes: true })
318
+ .filter((entry) => entry.isDirectory())
319
+ .map((entry) => readHomeImageCacheManifest(joinPathLike(entriesRoot, entry.name, "manifest.json")));
320
+ }
321
+ export function planHomeImageCacheFlush(options) {
322
+ const homePath = resolvePlexusHomePath(options);
323
+ const cacheRoot = homeImageCacheRootPath(homePath);
324
+ const keys = options.key
325
+ ? [safeCacheKey(options.key)]
326
+ : fs.existsSync(joinPathLike(cacheRoot, "entries"))
327
+ ? fs
328
+ .readdirSync(joinPathLike(cacheRoot, "entries"), {
329
+ withFileTypes: true,
330
+ })
331
+ .filter((entry) => entry.isDirectory())
332
+ .map((entry) => entry.name)
333
+ : [];
334
+ return {
335
+ homePath,
336
+ cacheRoot,
337
+ ...(options.key ? { key: options.key } : {}),
338
+ entries: keys.map((key) => {
339
+ const entryDirectory = homeImageCacheEntryDirectory(cacheRoot, key);
340
+ return {
341
+ key,
342
+ entryDirectory,
343
+ manifestPath: homeImageCacheManifestPath(cacheRoot, key),
344
+ lockPath: homeImageCacheLockPath(cacheRoot, key),
345
+ exists: fs.existsSync(entryDirectory),
346
+ };
347
+ }),
348
+ };
349
+ }
350
+ export function flushHomeImageCache(plan) {
351
+ for (const entry of plan.entries) {
352
+ fs.rmSync(entry.entryDirectory, { recursive: true, force: true });
353
+ fs.rmSync(entry.lockPath, { recursive: true, force: true });
354
+ }
355
+ }
356
+ function manifestPreparationStatus(support, mcp) {
357
+ return support.status === "supported" &&
358
+ projectMcpStartupMode(mcp) !== "disabled"
359
+ ? "pending"
360
+ : "skipped";
361
+ }
362
+ function planStatus(enabled, manifest, lock) {
363
+ if (!enabled) {
364
+ return "disabled";
365
+ }
366
+ if (manifest.status === "ok") {
367
+ return manifest.manifest.pharoMcp.preparationStatus === "failed"
368
+ ? "corrupt"
369
+ : "hit";
370
+ }
371
+ if (manifest.status === "corrupt") {
372
+ return "corrupt";
373
+ }
374
+ return lock.status === "ok" || lock.status === "corrupt"
375
+ ? "in-progress"
376
+ : "miss";
377
+ }
378
+ function resolvedLocalInputAvailability(options) {
379
+ return options.inputs?.[options.key] ?? options.inferred ?? "unknown";
380
+ }
381
+ function localOnlyReadiness(options) {
382
+ if (options.networkPolicy !== "local-only") {
383
+ return {
384
+ status: "not-required",
385
+ missingInputs: [],
386
+ diagnostics: [],
387
+ };
388
+ }
389
+ if (options.status === "hit") {
390
+ return {
391
+ status: "ready",
392
+ missingInputs: [],
393
+ diagnostics: [],
394
+ };
395
+ }
396
+ if (options.status !== "miss" && options.status !== "corrupt") {
397
+ return {
398
+ status: "not-required",
399
+ missingInputs: [],
400
+ diagnostics: [],
401
+ };
402
+ }
403
+ const diagnostics = [...(options.localInputs?.diagnostics ?? [])];
404
+ const missingInputs = [];
405
+ const requireInput = (key, label, inferred) => {
406
+ const availability = resolvedLocalInputAvailability({
407
+ key,
408
+ inputs: options.localInputs,
409
+ inferred,
410
+ });
411
+ if (availability === "available") {
412
+ return;
413
+ }
414
+ missingInputs.push(key);
415
+ diagnostics.push(availability === "missing"
416
+ ? `${label} is missing for local-only home image cache preparation.`
417
+ : `${label} has not been proven local for local-only home image cache preparation.`);
418
+ };
419
+ const loadScriptPath = resolveMcpLoadScriptPath(options.projectRoot, options.mcp);
420
+ const startupMode = projectMcpStartupMode(options.mcp);
421
+ requireInput("templateSource", "The selected home launcher template source", options.templateMetadata?.sourceFile ? "available" : undefined);
422
+ requireInput("baseImage", "The selected Pharo base image artifact");
423
+ requireInput("vm", "The selected Pharo VM");
424
+ if (options.support.status === "supported" && startupMode !== "disabled") {
425
+ requireInput("pharoMcpLoadScript", "The Pharo MCP load script", fs.existsSync(loadScriptPath) ? "available" : "missing");
426
+ requireInput("pharoMcpDependencies", "The Pharo MCP load script dependencies");
427
+ }
428
+ if (missingInputs.length === 0) {
429
+ diagnostics.push("PLexus home image cache is in local-only mode; template catalog refresh will be skipped.");
430
+ return {
431
+ status: "ready",
432
+ missingInputs,
433
+ diagnostics,
434
+ };
435
+ }
436
+ return {
437
+ status: "missing",
438
+ missingInputs,
439
+ diagnostics,
440
+ };
441
+ }
442
+ function preparationScriptSource(options) {
443
+ const repository = toMetacelloRepository("repository" in options.mcp ? options.mcp.repository : undefined);
444
+ const loadScriptPath = resolveMcpLoadScriptPath(options.projectRoot, options.mcp);
445
+ const quoted = (value) => `'${value.replaceAll("'", "''")}'`;
446
+ const pathString = (value) => quoted(value.replace(/\\/g, "/"));
447
+ const repositoryLabel = `github://${repository.githubUser}/${repository.project}:${repository.commitish}/${repository.path}`;
448
+ return `"Generated by PLexus. Do not edit."
449
+
450
+ | loadScript preparationStatusFile preparationStatusWriter preparationSource |
451
+
452
+ Smalltalk globals at: #PLexusHomeImageCacheKey put: ${quoted(options.cacheId)}.
453
+
454
+ preparationStatusFile := ${pathString(options.statusPath)} asFileReference.
455
+ preparationStatusFile exists ifTrue: [ preparationStatusFile delete ].
456
+ preparationSource := 'pending'.
457
+ preparationStatusWriter := [ :status :message |
458
+ preparationStatusFile parent ensureCreateDirectory.
459
+ preparationStatusFile writeStreamDo: [ :stream |
460
+ stream nextPutAll: 'status='; nextPutAll: status; cr.
461
+ stream nextPutAll: 'cacheKey='; nextPutAll: ${quoted(options.cacheId)}; cr.
462
+ stream
463
+ nextPutAll: 'source=';
464
+ nextPutAll: (preparationSource ifNil: [ 'unknown' ]);
465
+ cr.
466
+ stream nextPutAll: 'loadScript='; nextPutAll: ${pathString(loadScriptPath)}; cr.
467
+ stream nextPutAll: 'repository='; nextPutAll: ${quoted(repositoryLabel)}; cr.
468
+ stream nextPutAll: 'baseline='; nextPutAll: ${quoted(repository.baseline)}; cr.
469
+ message ifNotNil: [
470
+ stream nextPutAll: 'message='; nextPutAll: message asString; cr ] ] ].
471
+ [
472
+ loadScript := ${pathString(loadScriptPath)} asFileReference.
473
+ loadScript exists
474
+ ifTrue: [
475
+ preparationSource := 'loadScript'.
476
+ loadScript fileIn ]
477
+ ifFalse: [
478
+ preparationSource := 'metacello'.
479
+ Metacello new
480
+ githubUser: ${quoted(repository.githubUser)} project: ${quoted(repository.project)} commitish: ${quoted(repository.commitish)} path: ${quoted(repository.path)};
481
+ baseline: ${quoted(repository.baseline)};
482
+ load ].
483
+
484
+ (Smalltalk globals includesKey: #MCP)
485
+ ifFalse: [ Error signal: 'MCP class is not available after home image cache preparation.' ].
486
+ preparationStatusWriter value: 'loaded' value: nil
487
+ ] on: Error do: [ :error |
488
+ preparationStatusWriter value: 'failed' value: error description.
489
+ error pass ].
490
+
491
+ Smalltalk globals at: #PLexusHomeImageCachePreparedAt put: DateAndTime now asString.
492
+ Smalltalk snapshot: true andQuit: true.
493
+ `;
494
+ }
495
+ function buildHomeImageCacheDiagnostics(options) {
496
+ const diagnostics = [];
497
+ if (!options.enabled) {
498
+ diagnostics.push("PLexus home image cache is disabled by project config.");
499
+ }
500
+ if (options.manifest.status === "corrupt") {
501
+ diagnostics.push(`Home image cache manifest is unreadable: ${options.manifest.error}`);
502
+ }
503
+ if (options.lock.status === "ok") {
504
+ diagnostics.push(`Home image cache entry is already being prepared by ${options.lock.lock.owner}.`);
505
+ }
506
+ if (options.lock.status === "corrupt") {
507
+ diagnostics.push(`Home image cache lock is unreadable: ${options.lock.error}`);
508
+ }
509
+ if (options.imageState && !options.destinationProfile) {
510
+ diagnostics.push("Runtime copy from the home image cache requires an explicit destination launcher profile.");
511
+ }
512
+ diagnostics.push(...options.offlineReadiness.diagnostics);
513
+ return diagnostics;
514
+ }
515
+ function homeImageCacheCanPrepareEntry(options) {
516
+ const shouldPrepare = options.status === "miss" || options.status === "corrupt";
517
+ return (options.enabled &&
518
+ shouldPrepare &&
519
+ (options.networkPolicy === "online" ||
520
+ options.offlineReadiness.status === "ready"));
521
+ }
522
+ function buildHomeImageCachePlanOperations(options) {
523
+ const refreshTemplateCatalog = options.canPrepareCacheEntry && options.networkPolicy === "online"
524
+ ? {
525
+ toolName: "pharo_launcher_template_update",
526
+ profileEnvironment: profileEnvironmentFromPaths(options.homeProfile),
527
+ argumentsValue: {},
528
+ requiresApproval: true,
529
+ reason: "A fresh PLexus home image cache profile must have a launcher template catalog before creating a cache base.",
530
+ }
531
+ : undefined;
532
+ const createCacheImage = options.canPrepareCacheEntry
533
+ ? {
534
+ toolName: "pharo_launcher_image_create",
535
+ profileEnvironment: profileEnvironmentFromPaths(options.homeProfile),
536
+ argumentsValue: {
537
+ newImageName: options.cacheImageName,
538
+ templateName: options.source.templateName,
539
+ ...(options.source.templateCategory
540
+ ? { templateCategory: options.source.templateCategory }
541
+ : {}),
542
+ noLaunch: true,
543
+ },
544
+ requiresApproval: true,
545
+ reason: "Creating a PLexus home image cache base mutates the explicit home launcher profile.",
546
+ }
547
+ : undefined;
548
+ const prepareCacheImage = options.canPrepareCacheEntry &&
549
+ options.keyMaterial.pharoMcp.support.status === "supported" &&
550
+ projectMcpStartupMode(options.mcp) !== "disabled"
551
+ ? {
552
+ toolName: "pharo_launcher_image_launch",
553
+ profileEnvironment: profileEnvironmentFromPaths(options.homeProfile),
554
+ argumentsValue: {
555
+ imageName: options.cacheImageName,
556
+ detached: false,
557
+ displayMode: "headless",
558
+ script: options.preparationScriptPath,
559
+ },
560
+ requiresApproval: true,
561
+ reason: "Preparing a supported Pharo MCP cache image must run headlessly, snapshot, and quit.",
562
+ }
563
+ : undefined;
564
+ const runtimeCopy = options.enabled &&
565
+ options.imageState &&
566
+ options.destinationProfile &&
567
+ (options.status === "hit" || options.canPrepareCacheEntry)
568
+ ? {
569
+ toolName: "pharo_launcher_image_copy_between_profiles",
570
+ argumentsValue: {
571
+ sourceProfile: options.homeProfile,
572
+ destinationProfile: options.destinationProfile,
573
+ sourceImageName: options.cacheImageName,
574
+ destinationImageName: options.imageState.imageName,
575
+ },
576
+ requiresApproval: true,
577
+ reason: "Runtime images must be copies of home cache bases and must stay in the project launcher profile.",
578
+ }
579
+ : undefined;
580
+ return {
581
+ ...(refreshTemplateCatalog ? { refreshTemplateCatalog } : {}),
582
+ ...(createCacheImage ? { createCacheImage } : {}),
583
+ ...(prepareCacheImage ? { prepareCacheImage } : {}),
584
+ ...(runtimeCopy ? { runtimeCopy } : {}),
585
+ };
586
+ }
587
+ export function buildHomeImageCachePlan(options) {
588
+ const { source, mcp } = sourceFromProjectImage(options.config, options.imageConfig);
589
+ const homePath = resolvePlexusHomePath(options);
590
+ const cacheRoot = homeImageCacheRootPath(homePath);
591
+ const keyMaterial = homeImageCacheKeyMaterial({
592
+ config: options.config,
593
+ source,
594
+ mcp,
595
+ git: options.imageConfig.git,
596
+ templateMetadata: options.templateMetadata,
597
+ });
598
+ const key = deriveHomeImageCacheKey(keyMaterial);
599
+ const entryDirectory = homeImageCacheEntryDirectory(cacheRoot, key);
600
+ const manifestPath = homeImageCacheManifestPath(cacheRoot, key);
601
+ const lockPath = homeImageCacheLockPath(cacheRoot, key);
602
+ const preparationScriptPath = homeImageCachePreparationScriptPath(cacheRoot, key);
603
+ const preparationStatusPath = homeImageCachePreparationStatusPath(cacheRoot, key);
604
+ const cacheImageName = homeImageCacheImageName(key);
605
+ const homeProfile = homeImageCacheProfile(homePath);
606
+ const manifest = readHomeImageCacheManifest(manifestPath);
607
+ const lock = readHomeImageCacheLock(lockPath);
608
+ const enabled = homeImageCacheEnabled(options.config);
609
+ const networkPolicy = homeImageCacheNetworkPolicy(options.config);
610
+ const status = planStatus(enabled, manifest, lock);
611
+ const destinationProfile = profilePathsFromEnvironment(pharoLauncherMcpProfileEnvironment({
612
+ projectRoot: options.projectRoot,
613
+ config: options.config,
614
+ workspaceId: options.workspaceId ?? "default",
615
+ targetId: options.targetId ??
616
+ `${projectConfigId(options.config)}--${options.workspaceId ?? "default"}`,
617
+ stateRoot: options.stateRoot,
618
+ }));
619
+ const offlineReadiness = localOnlyReadiness({
620
+ networkPolicy,
621
+ status,
622
+ support: keyMaterial.pharoMcp.support,
623
+ projectRoot: options.projectRoot,
624
+ mcp,
625
+ templateMetadata: options.templateMetadata,
626
+ localInputs: options.localInputs,
627
+ });
628
+ const diagnostics = buildHomeImageCacheDiagnostics({
629
+ enabled,
630
+ manifest,
631
+ lock,
632
+ imageState: options.imageState,
633
+ destinationProfile,
634
+ offlineReadiness,
635
+ });
636
+ const now = options.now ?? (() => new Date());
637
+ const expectedManifest = {
638
+ schemaVersion: homeImageCacheSchemaVersion,
639
+ key,
640
+ createdAt: now().toISOString(),
641
+ updatedAt: now().toISOString(),
642
+ cacheImageName,
643
+ source,
644
+ ...(options.templateMetadata ? { templateMetadata: options.templateMetadata } : {}),
645
+ pharoMcp: {
646
+ support: keyMaterial.pharoMcp.support,
647
+ preparationStatus: manifestPreparationStatus(keyMaterial.pharoMcp.support, mcp),
648
+ diagnostics,
649
+ },
650
+ paths: {
651
+ entryDirectory,
652
+ manifestPath,
653
+ lockPath,
654
+ preparationScriptPath,
655
+ preparationStatusPath,
656
+ profileStateRoot: homeProfile.stateRoot,
657
+ },
658
+ };
659
+ const canPrepareCacheEntry = homeImageCacheCanPrepareEntry({
660
+ enabled,
661
+ status,
662
+ networkPolicy,
663
+ offlineReadiness,
664
+ });
665
+ const operations = buildHomeImageCachePlanOperations({
666
+ canPrepareCacheEntry,
667
+ networkPolicy,
668
+ homeProfile,
669
+ source,
670
+ cacheImageName,
671
+ keyMaterial,
672
+ mcp,
673
+ preparationScriptPath,
674
+ enabled,
675
+ imageState: options.imageState,
676
+ destinationProfile,
677
+ status,
678
+ });
679
+ return {
680
+ status,
681
+ networkPolicy,
682
+ offlineReadiness,
683
+ key,
684
+ projectRoot: options.projectRoot,
685
+ homePath,
686
+ cacheRoot,
687
+ entryDirectory,
688
+ manifestPath,
689
+ lockPath,
690
+ cacheImageName,
691
+ source,
692
+ mcp,
693
+ support: keyMaterial.pharoMcp.support,
694
+ manifest,
695
+ lock,
696
+ homeProfile,
697
+ keyMaterial,
698
+ expectedManifest,
699
+ ...operations,
700
+ diagnostics,
701
+ };
702
+ }
703
+ export function writeHomeImageCachePreparationScript(plan) {
704
+ const source = preparationScriptSource({
705
+ cacheId: plan.key,
706
+ projectRoot: plan.projectRoot,
707
+ source: plan.source,
708
+ mcp: plan.mcp,
709
+ statusPath: plan.expectedManifest.paths.preparationStatusPath,
710
+ });
711
+ fs.mkdirSync(dirnamePathLike(plan.expectedManifest.paths.preparationScriptPath), {
712
+ recursive: true,
713
+ });
714
+ fs.writeFileSync(plan.expectedManifest.paths.preparationScriptPath, source, "utf8");
715
+ return {
716
+ filePath: plan.expectedManifest.paths.preparationScriptPath,
717
+ source,
718
+ };
719
+ }
720
+ function assertLauncherOk(result, toolName) {
721
+ if (result && result.ok === false) {
722
+ throw new HomeImageCacheError(`${toolName} returned ok: false`);
723
+ }
724
+ }
725
+ function requireMutationApproval(approval, operation) {
726
+ if (!approval?.approved || approval.approvalId.length === 0) {
727
+ throw new HomeImageCacheError(`${operation} requires approved home image cache mutation`);
728
+ }
729
+ return approval;
730
+ }
731
+ async function callLauncherOperation(client, operation) {
732
+ const result = await client.callTool(operation.toolName, operation.argumentsValue);
733
+ assertLauncherOk(result, operation.toolName);
734
+ }
735
+ function finalizedManifest(options) {
736
+ const timestamp = (options.now ?? (() => new Date()))().toISOString();
737
+ const existingCreatedAt = options.plan.manifest.status === "ok"
738
+ ? options.plan.manifest.manifest.createdAt
739
+ : undefined;
740
+ return {
741
+ ...options.plan.expectedManifest,
742
+ createdAt: existingCreatedAt ?? timestamp,
743
+ updatedAt: timestamp,
744
+ pharoMcp: {
745
+ ...options.plan.expectedManifest.pharoMcp,
746
+ preparationStatus: options.preparationStatus,
747
+ diagnostics: [
748
+ ...options.plan.diagnostics,
749
+ ...(options.diagnostics ?? []),
750
+ ],
751
+ },
752
+ };
753
+ }
754
+ function preparationStatusProperties(filePath) {
755
+ if (!fs.existsSync(filePath)) {
756
+ return undefined;
757
+ }
758
+ return Object.fromEntries(fs
759
+ .readFileSync(filePath, "utf8")
760
+ .split(/\r\n|\n|\r/)
761
+ .map((line) => {
762
+ if (!line || line.startsWith("#")) {
763
+ return undefined;
764
+ }
765
+ const separator = line.indexOf("=");
766
+ if (separator <= 0) {
767
+ return undefined;
768
+ }
769
+ return [line.slice(0, separator), line.slice(separator + 1)];
770
+ })
771
+ .filter((entry) => entry !== undefined));
772
+ }
773
+ function preparationFailureDiagnostic(plan) {
774
+ const properties = preparationStatusProperties(plan.expectedManifest.paths.preparationStatusPath);
775
+ if (properties?.status !== "failed") {
776
+ return undefined;
777
+ }
778
+ const message = properties.message ??
779
+ "Pharo MCP preparation failed without a reported message.";
780
+ return `Home image cache Pharo MCP preparation failed: ${message}`;
781
+ }
782
+ async function prepareHomeImageCacheEntry(options) {
783
+ if (!options.plan.createCacheImage) {
784
+ return [];
785
+ }
786
+ const lock = tryAcquireHomeImageCacheLock({
787
+ lockPath: options.plan.lockPath,
788
+ key: options.plan.key,
789
+ owner: options.approval.approvalId,
790
+ now: options.now,
791
+ });
792
+ if (!lock.acquired) {
793
+ const detail = lock.current.status === "ok"
794
+ ? `current owner: ${lock.current.lock.owner}`
795
+ : lock.current.status === "corrupt"
796
+ ? lock.current.error
797
+ : "lock appeared before acquisition";
798
+ throw new HomeImageCacheError(`Home image cache entry ${options.plan.key} is already being prepared (${detail})`);
799
+ }
800
+ const operations = [];
801
+ try {
802
+ if (options.plan.prepareCacheImage) {
803
+ fs.rmSync(options.plan.expectedManifest.paths.preparationStatusPath, {
804
+ force: true,
805
+ });
806
+ writeHomeImageCachePreparationScript(options.plan);
807
+ }
808
+ if (options.plan.refreshTemplateCatalog) {
809
+ await callLauncherOperation(options.homeClient, options.plan.refreshTemplateCatalog);
810
+ operations.push(options.plan.refreshTemplateCatalog);
811
+ }
812
+ await callLauncherOperation(options.homeClient, options.plan.createCacheImage);
813
+ operations.push(options.plan.createCacheImage);
814
+ if (options.plan.prepareCacheImage) {
815
+ await callLauncherOperation(options.homeClient, options.plan.prepareCacheImage);
816
+ operations.push(options.plan.prepareCacheImage);
817
+ }
818
+ writeHomeImageCacheManifest(finalizedManifest({
819
+ plan: options.plan,
820
+ preparationStatus: options.plan.prepareCacheImage ? "prepared" : "skipped",
821
+ now: options.now,
822
+ }));
823
+ return operations;
824
+ }
825
+ catch (error) {
826
+ writeHomeImageCacheManifest(finalizedManifest({
827
+ plan: options.plan,
828
+ preparationStatus: "failed",
829
+ diagnostics: [
830
+ preparationFailureDiagnostic(options.plan) ??
831
+ (error instanceof Error ? error.message : String(error)),
832
+ ],
833
+ now: options.now,
834
+ }));
835
+ throw error;
836
+ }
837
+ finally {
838
+ releaseHomeImageCacheLock(options.plan.lockPath);
839
+ }
840
+ }
841
+ function ensureMaterializableHomeImageCachePlan(plan) {
842
+ if (plan.status === "disabled") {
843
+ return false;
844
+ }
845
+ if (plan.offlineReadiness.status === "missing") {
846
+ throw new HomeImageCacheError([
847
+ `Home image cache local-only preparation is missing required local inputs for entry ${plan.key}: ${plan.offlineReadiness.missingInputs.join(", ")}`,
848
+ ...plan.offlineReadiness.diagnostics,
849
+ ].join("\n"));
850
+ }
851
+ if (plan.status === "in-progress") {
852
+ const detail = plan.lock.status === "ok"
853
+ ? `current owner: ${plan.lock.lock.owner}`
854
+ : plan.lock.status === "corrupt"
855
+ ? plan.lock.error
856
+ : "lock is present";
857
+ throw new HomeImageCacheError(`Home image cache entry ${plan.key} is already being prepared (${detail})`);
858
+ }
859
+ return true;
860
+ }
861
+ function materializationNeedsHomeClient(plan) {
862
+ return plan.status === "miss" || plan.status === "corrupt";
863
+ }
864
+ async function runHomeCacheMaterializationOperations(options) {
865
+ const operations = [];
866
+ if (materializationNeedsHomeClient(options.plan)) {
867
+ if (!options.homeClient) {
868
+ throw new HomeImageCacheError("Home image cache preparation requires a home launcher client");
869
+ }
870
+ operations.push(...(await prepareHomeImageCacheEntry({
871
+ plan: options.plan,
872
+ homeClient: options.homeClient,
873
+ approval: options.approval,
874
+ now: options.now,
875
+ })));
876
+ }
877
+ if (options.plan.runtimeCopy) {
878
+ await callLauncherOperation(options.runtimeClient, options.plan.runtimeCopy);
879
+ operations.push(options.plan.runtimeCopy);
880
+ }
881
+ return operations;
882
+ }
883
+ export async function materializeProjectImageFromHomeCache(options) {
884
+ if (!projectImageCanUseHomeImageCache(options.imageConfig)) {
885
+ return undefined;
886
+ }
887
+ const plan = buildHomeImageCachePlan({
888
+ projectRoot: options.projectRoot,
889
+ config: options.config,
890
+ imageConfig: options.imageConfig,
891
+ imageState: options.imageState,
892
+ workspaceId: options.workspaceId,
893
+ targetId: options.targetId,
894
+ stateRoot: options.stateRoot,
895
+ env: options.env,
896
+ homeDirectory: options.homeDirectory,
897
+ now: options.now,
898
+ templateMetadata: options.templateMetadata,
899
+ localInputs: options.localInputs,
900
+ });
901
+ if (!ensureMaterializableHomeImageCachePlan(plan)) {
902
+ return undefined;
903
+ }
904
+ const approval = requireMutationApproval(options.approval, `Materializing image ${options.imageState.id} from the home image cache`);
905
+ const operations = [];
906
+ let homeClient = options.homeClient;
907
+ let ownsHomeClient = false;
908
+ try {
909
+ if (materializationNeedsHomeClient(plan) && !homeClient) {
910
+ homeClient = await createStdioPharoLauncherMcpClient(undefined, {
911
+ profileEnvironment: profileEnvironmentFromPaths(plan.homeProfile),
912
+ });
913
+ ownsHomeClient = true;
914
+ }
915
+ operations.push(...(await runHomeCacheMaterializationOperations({
916
+ plan,
917
+ approval,
918
+ now: options.now,
919
+ runtimeClient: options.runtimeClient,
920
+ homeClient,
921
+ })));
922
+ return { plan, operations };
923
+ }
924
+ finally {
925
+ if (ownsHomeClient) {
926
+ await homeClient?.close?.();
927
+ }
928
+ }
929
+ }
930
+ //# sourceMappingURL=homeImageCache.js.map