@evref-bl/plexus 0.0.0-stage → 0.1.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -2
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +298 -0
- package/dist/cli.js.map +1 -0
- package/dist/config/config.d.ts +29 -0
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/config.js +111 -0
- package/dist/config/config.js.map +1 -0
- package/dist/config/plexusHome.d.ts +17 -0
- package/dist/config/plexusHome.d.ts.map +1 -0
- package/dist/config/plexusHome.js +30 -0
- package/dist/config/plexusHome.js.map +1 -0
- package/dist/config/projectConfig.d.ts +233 -0
- package/dist/config/projectConfig.d.ts.map +1 -0
- package/dist/config/projectConfig.js +1181 -0
- package/dist/config/projectConfig.js.map +1 -0
- package/dist/config/target.d.ts +19 -0
- package/dist/config/target.d.ts.map +1 -0
- package/dist/config/target.js +2 -0
- package/dist/config/target.js.map +1 -0
- package/dist/config.d.ts +29 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +111 -0
- package/dist/config.js.map +1 -0
- package/dist/gateway/projectGateway.d.ts +80 -0
- package/dist/gateway/projectGateway.d.ts.map +1 -0
- package/dist/gateway/projectGateway.js +435 -0
- package/dist/gateway/projectGateway.js.map +1 -0
- package/dist/gateway/projectImageMcpEndpoint.d.ts +24 -0
- package/dist/gateway/projectImageMcpEndpoint.d.ts.map +1 -0
- package/dist/gateway/projectImageMcpEndpoint.js +79 -0
- package/dist/gateway/projectImageMcpEndpoint.js.map +1 -0
- package/dist/homeImageCache.d.ts +264 -0
- package/dist/homeImageCache.d.ts.map +1 -0
- package/dist/homeImageCache.js +930 -0
- package/dist/homeImageCache.js.map +1 -0
- package/dist/imagePortClaims.d.ts +41 -0
- package/dist/imagePortClaims.d.ts.map +1 -0
- package/dist/imagePortClaims.js +337 -0
- package/dist/imagePortClaims.js.map +1 -0
- package/dist/imageRescue.d.ts +155 -0
- package/dist/imageRescue.d.ts.map +1 -0
- package/dist/imageRescue.js +847 -0
- package/dist/imageRescue.js.map +1 -0
- package/dist/images/homeImageCache.d.ts +264 -0
- package/dist/images/homeImageCache.d.ts.map +1 -0
- package/dist/images/homeImageCache.js +930 -0
- package/dist/images/homeImageCache.js.map +1 -0
- package/dist/images/imageRescue.d.ts +155 -0
- package/dist/images/imageRescue.d.ts.map +1 -0
- package/dist/images/imageRescue.js +847 -0
- package/dist/images/imageRescue.js.map +1 -0
- package/dist/images/preparedImageCache.d.ts +90 -0
- package/dist/images/preparedImageCache.d.ts.map +1 -0
- package/dist/images/preparedImageCache.js +237 -0
- package/dist/images/preparedImageCache.js.map +1 -0
- package/dist/images/scopedTemplateCatalog.d.ts +32 -0
- package/dist/images/scopedTemplateCatalog.d.ts.map +1 -0
- package/dist/images/scopedTemplateCatalog.js +316 -0
- package/dist/images/scopedTemplateCatalog.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/launcher/pharoLauncherMcpClient.d.ts +17 -0
- package/dist/launcher/pharoLauncherMcpClient.d.ts.map +1 -0
- package/dist/launcher/pharoLauncherMcpClient.js +78 -0
- package/dist/launcher/pharoLauncherMcpClient.js.map +1 -0
- package/dist/launcher/pharoLauncherProfile.d.ts +31 -0
- package/dist/launcher/pharoLauncherProfile.d.ts.map +1 -0
- package/dist/launcher/pharoLauncherProfile.js +122 -0
- package/dist/launcher/pharoLauncherProfile.js.map +1 -0
- package/dist/launcher/scopedPharoLauncherServer.d.ts +247 -0
- package/dist/launcher/scopedPharoLauncherServer.d.ts.map +1 -0
- package/dist/launcher/scopedPharoLauncherServer.js +1112 -0
- package/dist/launcher/scopedPharoLauncherServer.js.map +1 -0
- package/dist/lifecycle/projectCleanup.d.ts +59 -0
- package/dist/lifecycle/projectCleanup.d.ts.map +1 -0
- package/dist/lifecycle/projectCleanup.js +483 -0
- package/dist/lifecycle/projectCleanup.js.map +1 -0
- package/dist/lifecycle/projectClose.d.ts +35 -0
- package/dist/lifecycle/projectClose.d.ts.map +1 -0
- package/dist/lifecycle/projectClose.js +273 -0
- package/dist/lifecycle/projectClose.js.map +1 -0
- package/dist/lifecycle/projectLifecycle.d.ts +429 -0
- package/dist/lifecycle/projectLifecycle.d.ts.map +1 -0
- package/dist/lifecycle/projectLifecycle.js +2150 -0
- package/dist/lifecycle/projectLifecycle.js.map +1 -0
- package/dist/lifecycle/projectOpen.d.ts +68 -0
- package/dist/lifecycle/projectOpen.d.ts.map +1 -0
- package/dist/lifecycle/projectOpen.js +1472 -0
- package/dist/lifecycle/projectOpen.js.map +1 -0
- package/dist/mcp/pharoMcpHealth.d.ts +26 -0
- package/dist/mcp/pharoMcpHealth.d.ts.map +1 -0
- package/dist/mcp/pharoMcpHealth.js +97 -0
- package/dist/mcp/pharoMcpHealth.js.map +1 -0
- package/dist/mcp/server.d.ts +86 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +357 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/pathStyle.d.ts +11 -0
- package/dist/pathStyle.d.ts.map +1 -0
- package/dist/pathStyle.js +61 -0
- package/dist/pathStyle.js.map +1 -0
- package/dist/pharoLauncherMcpClient.d.ts +17 -0
- package/dist/pharoLauncherMcpClient.d.ts.map +1 -0
- package/dist/pharoLauncherMcpClient.js +78 -0
- package/dist/pharoLauncherMcpClient.js.map +1 -0
- package/dist/pharoLauncherProfile.d.ts +31 -0
- package/dist/pharoLauncherProfile.d.ts.map +1 -0
- package/dist/pharoLauncherProfile.js +122 -0
- package/dist/pharoLauncherProfile.js.map +1 -0
- package/dist/pharoMcpHealth.d.ts +26 -0
- package/dist/pharoMcpHealth.d.ts.map +1 -0
- package/dist/pharoMcpHealth.js +97 -0
- package/dist/pharoMcpHealth.js.map +1 -0
- package/dist/plexusHome.d.ts +17 -0
- package/dist/plexusHome.d.ts.map +1 -0
- package/dist/plexusHome.js +30 -0
- package/dist/plexusHome.js.map +1 -0
- package/dist/portClaims.d.ts +116 -0
- package/dist/portClaims.d.ts.map +1 -0
- package/dist/portClaims.js +393 -0
- package/dist/portClaims.js.map +1 -0
- package/dist/ports/imagePortClaims.d.ts +41 -0
- package/dist/ports/imagePortClaims.d.ts.map +1 -0
- package/dist/ports/imagePortClaims.js +337 -0
- package/dist/ports/imagePortClaims.js.map +1 -0
- package/dist/ports/portClaims.d.ts +116 -0
- package/dist/ports/portClaims.d.ts.map +1 -0
- package/dist/ports/portClaims.js +393 -0
- package/dist/ports/portClaims.js.map +1 -0
- package/dist/preparedImageCache.d.ts +90 -0
- package/dist/preparedImageCache.d.ts.map +1 -0
- package/dist/preparedImageCache.js +237 -0
- package/dist/preparedImageCache.js.map +1 -0
- package/dist/projectCleanup.d.ts +59 -0
- package/dist/projectCleanup.d.ts.map +1 -0
- package/dist/projectCleanup.js +483 -0
- package/dist/projectCleanup.js.map +1 -0
- package/dist/projectClose.d.ts +35 -0
- package/dist/projectClose.d.ts.map +1 -0
- package/dist/projectClose.js +273 -0
- package/dist/projectClose.js.map +1 -0
- package/dist/projectConfig.d.ts +233 -0
- package/dist/projectConfig.d.ts.map +1 -0
- package/dist/projectConfig.js +1181 -0
- package/dist/projectConfig.js.map +1 -0
- package/dist/projectGateway.d.ts +80 -0
- package/dist/projectGateway.d.ts.map +1 -0
- package/dist/projectGateway.js +435 -0
- package/dist/projectGateway.js.map +1 -0
- package/dist/projectImageMcpEndpoint.d.ts +24 -0
- package/dist/projectImageMcpEndpoint.d.ts.map +1 -0
- package/dist/projectImageMcpEndpoint.js +79 -0
- package/dist/projectImageMcpEndpoint.js.map +1 -0
- package/dist/projectLifecycle.d.ts +428 -0
- package/dist/projectLifecycle.d.ts.map +1 -0
- package/dist/projectLifecycle.js +2147 -0
- package/dist/projectLifecycle.js.map +1 -0
- package/dist/projectOpen.d.ts +68 -0
- package/dist/projectOpen.d.ts.map +1 -0
- package/dist/projectOpen.js +1472 -0
- package/dist/projectOpen.js.map +1 -0
- package/dist/projectRepositoryWorkspace.d.ts +74 -0
- package/dist/projectRepositoryWorkspace.d.ts.map +1 -0
- package/dist/projectRepositoryWorkspace.js +553 -0
- package/dist/projectRepositoryWorkspace.js.map +1 -0
- package/dist/projectStartupScript.d.ts +74 -0
- package/dist/projectStartupScript.d.ts.map +1 -0
- package/dist/projectStartupScript.js +748 -0
- package/dist/projectStartupScript.js.map +1 -0
- package/dist/projectState.d.ts +315 -0
- package/dist/projectState.d.ts.map +1 -0
- package/dist/projectState.js +399 -0
- package/dist/projectState.js.map +1 -0
- package/dist/runtimeIdentity.d.ts +15 -0
- package/dist/runtimeIdentity.d.ts.map +1 -0
- package/dist/runtimeIdentity.js +25 -0
- package/dist/runtimeIdentity.js.map +1 -0
- package/dist/scopedPharoLauncherServer.d.ts +247 -0
- package/dist/scopedPharoLauncherServer.d.ts.map +1 -0
- package/dist/scopedPharoLauncherServer.js +1112 -0
- package/dist/scopedPharoLauncherServer.js.map +1 -0
- package/dist/scopedProjectContext.d.ts +169 -0
- package/dist/scopedProjectContext.d.ts.map +1 -0
- package/dist/scopedProjectContext.js +358 -0
- package/dist/scopedProjectContext.js.map +1 -0
- package/dist/scopedTemplateCatalog.d.ts +32 -0
- package/dist/scopedTemplateCatalog.d.ts.map +1 -0
- package/dist/scopedTemplateCatalog.js +316 -0
- package/dist/scopedTemplateCatalog.js.map +1 -0
- package/dist/server.d.ts +86 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +357 -0
- package/dist/server.js.map +1 -0
- package/dist/support/pathStyle.d.ts +11 -0
- package/dist/support/pathStyle.d.ts.map +1 -0
- package/dist/support/pathStyle.js +61 -0
- package/dist/support/pathStyle.js.map +1 -0
- package/dist/support/runtimeIdentity.d.ts +15 -0
- package/dist/support/runtimeIdentity.d.ts.map +1 -0
- package/dist/support/runtimeIdentity.js +40 -0
- package/dist/support/runtimeIdentity.js.map +1 -0
- package/dist/support/toolResultFormatting.d.ts +8 -0
- package/dist/support/toolResultFormatting.d.ts.map +1 -0
- package/dist/support/toolResultFormatting.js +81 -0
- package/dist/support/toolResultFormatting.js.map +1 -0
- package/dist/target.d.ts +19 -0
- package/dist/target.d.ts.map +1 -0
- package/dist/target.js +2 -0
- package/dist/target.js.map +1 -0
- package/dist/toolResultFormatting.d.ts +8 -0
- package/dist/toolResultFormatting.d.ts.map +1 -0
- package/dist/toolResultFormatting.js +81 -0
- package/dist/toolResultFormatting.js.map +1 -0
- package/dist/workspace/projectRepositoryWorkspace.d.ts +74 -0
- package/dist/workspace/projectRepositoryWorkspace.d.ts.map +1 -0
- package/dist/workspace/projectRepositoryWorkspace.js +553 -0
- package/dist/workspace/projectRepositoryWorkspace.js.map +1 -0
- package/dist/workspace/projectStartupScript.d.ts +74 -0
- package/dist/workspace/projectStartupScript.d.ts.map +1 -0
- package/dist/workspace/projectStartupScript.js +748 -0
- package/dist/workspace/projectStartupScript.js.map +1 -0
- package/dist/workspace/projectState.d.ts +320 -0
- package/dist/workspace/projectState.d.ts.map +1 -0
- package/dist/workspace/projectState.js +399 -0
- package/dist/workspace/projectState.js.map +1 -0
- package/dist/workspace/scopedProjectContext.d.ts +169 -0
- package/dist/workspace/scopedProjectContext.d.ts.map +1 -0
- package/dist/workspace/scopedProjectContext.js +358 -0
- package/dist/workspace/scopedProjectContext.js.map +1 -0
- package/dist/workspace/workspaceMcpConfig.d.ts +51 -0
- package/dist/workspace/workspaceMcpConfig.d.ts.map +1 -0
- package/dist/workspace/workspaceMcpConfig.js +98 -0
- package/dist/workspace/workspaceMcpConfig.js.map +1 -0
- package/dist/workspaceMcpConfig.d.ts +51 -0
- package/dist/workspaceMcpConfig.d.ts.map +1 -0
- package/dist/workspaceMcpConfig.js +98 -0
- package/dist/workspaceMcpConfig.js.map +1 -0
- package/package.json +39 -4
|
@@ -0,0 +1,748 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { projectConfigId, projectMcpLoadPolicy, projectMcpStartupMode, } from "./projectConfig.js";
|
|
3
|
+
import { homeDependencyRepositoryCachePath, homeDependencyRepositoryNetworkPolicy, resolvePlexusHomePath, } from "./plexusHome.js";
|
|
4
|
+
import { dirnamePathLike, isAbsolutePathLike, joinPathLike, resolvePathLike, sanitizePathSegment, } from "./pathStyle.js";
|
|
5
|
+
import { projectImageRepositoryWorkspaces, projectStateDirectoryPath, projectStateRootForConfig, } from "./projectState.js";
|
|
6
|
+
import { imageMcpEndpointHandoffPath } from "./projectImageMcpEndpoint.js";
|
|
7
|
+
export const projectScriptsDirectoryName = "scripts";
|
|
8
|
+
export const defaultPharoMcpMetacelloRepository = {
|
|
9
|
+
githubUser: "Evref-BL",
|
|
10
|
+
project: "MCP",
|
|
11
|
+
commitish: "main",
|
|
12
|
+
path: "src",
|
|
13
|
+
baseline: "MCP",
|
|
14
|
+
};
|
|
15
|
+
export class ProjectStartupScriptError extends Error {
|
|
16
|
+
constructor(message) {
|
|
17
|
+
super(message);
|
|
18
|
+
this.name = "ProjectStartupScriptError";
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export function projectScriptsDirectoryPath(options) {
|
|
22
|
+
return joinPathLike(projectStateDirectoryPath(options), projectScriptsDirectoryName);
|
|
23
|
+
}
|
|
24
|
+
export function imageStartupScriptFileName(imageId) {
|
|
25
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(imageId)) {
|
|
26
|
+
throw new ProjectStartupScriptError(`Image id must be file-safe to generate a startup script: ${imageId}`);
|
|
27
|
+
}
|
|
28
|
+
return `start-${imageId}.st`;
|
|
29
|
+
}
|
|
30
|
+
export function imageStartupScriptPath(options) {
|
|
31
|
+
return joinPathLike(projectScriptsDirectoryPath(options), imageStartupScriptFileName(options.imageId));
|
|
32
|
+
}
|
|
33
|
+
export function imageRepositoryWorkspaceLoadStatusPath(options) {
|
|
34
|
+
const imageScriptName = imageStartupScriptFileName(options.imageId)
|
|
35
|
+
.replace(/^start-/, "")
|
|
36
|
+
.replace(/\.st$/, ".properties");
|
|
37
|
+
const repositorySuffix = options.repositoryId
|
|
38
|
+
? `-${statusPathSegment(options.repositoryId)}`
|
|
39
|
+
: "";
|
|
40
|
+
return joinPathLike(projectScriptsDirectoryPath(options), `repository-workspace-load-${imageScriptName.replace(/\.properties$/, `${repositorySuffix}.properties`)}`);
|
|
41
|
+
}
|
|
42
|
+
function statusPathSegment(value) {
|
|
43
|
+
return sanitizePathSegment(value, "repo");
|
|
44
|
+
}
|
|
45
|
+
export function imagePharoMcpLoadStatusPath(options) {
|
|
46
|
+
const imageScriptName = imageStartupScriptFileName(options.imageId)
|
|
47
|
+
.replace(/^start-/, "")
|
|
48
|
+
.replace(/\.st$/, ".properties");
|
|
49
|
+
return joinPathLike(projectScriptsDirectoryPath(options), `pharo-mcp-load-${imageScriptName}`);
|
|
50
|
+
}
|
|
51
|
+
export function imageDependencyRepositoryDetachStatusPath(options) {
|
|
52
|
+
const imageScriptName = imageStartupScriptFileName(options.imageId)
|
|
53
|
+
.replace(/^start-/, "")
|
|
54
|
+
.replace(/\.st$/, ".properties");
|
|
55
|
+
return joinPathLike(projectScriptsDirectoryPath(options), `dependency-repository-detach-${imageScriptName}`);
|
|
56
|
+
}
|
|
57
|
+
function smalltalkString(value) {
|
|
58
|
+
return `'${value.replaceAll("'", "''")}'`;
|
|
59
|
+
}
|
|
60
|
+
function smalltalkComment(value) {
|
|
61
|
+
return `"${value.replaceAll("\"", "\"\"")}"`;
|
|
62
|
+
}
|
|
63
|
+
function smalltalkPath(value) {
|
|
64
|
+
return smalltalkString(value.replace(/\\/g, "/"));
|
|
65
|
+
}
|
|
66
|
+
function icebergRemoteTypeSelector(transport) {
|
|
67
|
+
switch (transport) {
|
|
68
|
+
case "http":
|
|
69
|
+
return "#httpUrl";
|
|
70
|
+
case "https":
|
|
71
|
+
return "#httpsUrl";
|
|
72
|
+
case "ssh":
|
|
73
|
+
return "#scpUrl";
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function sshUsername(ssh) {
|
|
77
|
+
return ssh?.username ?? "git";
|
|
78
|
+
}
|
|
79
|
+
function sshHasCustomKeys(ssh) {
|
|
80
|
+
return Boolean(ssh?.publicKey && ssh.privateKey);
|
|
81
|
+
}
|
|
82
|
+
function sshRemoteUrlPrefix(ssh) {
|
|
83
|
+
if (!ssh?.host) {
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
return `ssh://${sshUsername(ssh)}@${ssh.host}${ssh.port ? `:${ssh.port}` : ""}/`;
|
|
87
|
+
}
|
|
88
|
+
function generateGitHubSshRemoteScript(ssh) {
|
|
89
|
+
const remoteUrlPrefix = sshRemoteUrlPrefix(ssh);
|
|
90
|
+
if (!remoteUrlPrefix) {
|
|
91
|
+
return [];
|
|
92
|
+
}
|
|
93
|
+
const remoteTemplate = `${remoteUrlPrefix}{projectPath}.git`;
|
|
94
|
+
const methodSource = [
|
|
95
|
+
"scpUrl",
|
|
96
|
+
`\t^ ${smalltalkString(remoteUrlPrefix)}, projectPath, '.git'`,
|
|
97
|
+
].join("\n");
|
|
98
|
+
return [
|
|
99
|
+
`Smalltalk globals at: #PLexusGitSshRemoteTemplate put: ${smalltalkString(remoteTemplate)}.`,
|
|
100
|
+
`(Smalltalk globals includesKey: #MCGitHubRepository)`,
|
|
101
|
+
` ifTrue: [`,
|
|
102
|
+
` (Smalltalk globals at: #MCGitHubRepository)`,
|
|
103
|
+
` compile: ${smalltalkString(methodSource)}`,
|
|
104
|
+
` classified: 'accessing' ]`,
|
|
105
|
+
` ifFalse: [ Error signal: 'MCGitHubRepository class is not available for explicit SSH GitHub remote configuration.' ].`,
|
|
106
|
+
];
|
|
107
|
+
}
|
|
108
|
+
function generateGitConfigurationScript(imageConfig) {
|
|
109
|
+
if (!imageConfig.git) {
|
|
110
|
+
return "";
|
|
111
|
+
}
|
|
112
|
+
const git = imageConfig.git;
|
|
113
|
+
const hasCustomSshKeys = sshHasCustomKeys(git.ssh);
|
|
114
|
+
const requiresCredentialsProvider = Boolean(hasCustomSshKeys || git.plainCredentials);
|
|
115
|
+
const lines = [
|
|
116
|
+
`"Configure image-local Git transport and credentials."`,
|
|
117
|
+
`Smalltalk globals at: #PLexusGitTransport put: ${smalltalkString(git.transport)}.`,
|
|
118
|
+
`(Smalltalk globals includesKey: #Iceberg)`,
|
|
119
|
+
` ifTrue: [ (Smalltalk globals at: #Iceberg) remoteTypeSelector: ${icebergRemoteTypeSelector(git.transport)}. ]`,
|
|
120
|
+
` ifFalse: [ nil ].`,
|
|
121
|
+
...generateGitHubSshRemoteScript(git.transport === "ssh" ? git.ssh : undefined),
|
|
122
|
+
`(Smalltalk globals includesKey: #IceCredentialsProvider)`,
|
|
123
|
+
` ifTrue: [`,
|
|
124
|
+
` | credentialsProvider |`,
|
|
125
|
+
` credentialsProvider := Smalltalk globals at: #IceCredentialsProvider.`,
|
|
126
|
+
];
|
|
127
|
+
if (git.transport === "ssh") {
|
|
128
|
+
if (hasCustomSshKeys) {
|
|
129
|
+
lines.push(` credentialsProvider useCustomSsh: true.`, ` credentialsProvider sshCredentials`, ` username: ${smalltalkString(sshUsername(git.ssh))};`, ` publicKey: ${smalltalkPath(git.ssh.publicKey)};`, ` privateKey: ${smalltalkPath(git.ssh.privateKey)}.`);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
lines.push(` "Use the image or platform SSH agent/defaults unless explicit keys are configured."`, ` credentialsProvider useCustomSsh: false.`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
lines.push(` credentialsProvider useCustomSsh: false.`);
|
|
137
|
+
if (git.plainCredentials) {
|
|
138
|
+
lines.push(` (Smalltalk globals includesKey: #IcePlaintextCredentials)`, ` ifTrue: [`, ` credentialsProvider plaintextCredentials: ((Smalltalk globals at: #IcePlaintextCredentials) new`, ` username: ${smalltalkString(git.plainCredentials.username)};`, ` password: ${smalltalkString(git.plainCredentials.password)};`, ` yourself) ]`, ` ifFalse: [ Error signal: 'IcePlaintextCredentials class is not available.' ].`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
lines.push(`]`);
|
|
142
|
+
if (requiresCredentialsProvider) {
|
|
143
|
+
lines.push(` ifFalse: [ Error signal: 'IceCredentialsProvider class is not available.' ].`);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
lines.push(` ifFalse: [ nil ].`);
|
|
147
|
+
}
|
|
148
|
+
return lines.join("\n");
|
|
149
|
+
}
|
|
150
|
+
function resolveLoadScriptPath(projectRoot, sourcePath, imageConfig) {
|
|
151
|
+
return isAbsolutePathLike(imageConfig.mcp.loadScript)
|
|
152
|
+
? resolvePathLike(imageConfig.mcp.loadScript)
|
|
153
|
+
: resolvePathLike(sourcePath ?? projectRoot, imageConfig.mcp.loadScript);
|
|
154
|
+
}
|
|
155
|
+
function findProjectImageConfig(config, imageId) {
|
|
156
|
+
const imageConfig = config.images.find((image) => image.id === imageId);
|
|
157
|
+
if (!imageConfig) {
|
|
158
|
+
throw new ProjectStartupScriptError(`Project config does not define image id: ${imageId}`);
|
|
159
|
+
}
|
|
160
|
+
return imageConfig;
|
|
161
|
+
}
|
|
162
|
+
function generateEndpointHandoffStartupScript(options) {
|
|
163
|
+
const fallbackScript = options.assignedPort === undefined
|
|
164
|
+
? [
|
|
165
|
+
` Error signal: 'MCP endpoint handoff is required, but this image-side MCP does not support bindToLoopback/endpoint.'`,
|
|
166
|
+
]
|
|
167
|
+
: [
|
|
168
|
+
` mcp port: ${options.assignedPort}.`,
|
|
169
|
+
` mcp start.`,
|
|
170
|
+
];
|
|
171
|
+
return [
|
|
172
|
+
`"Configure and start the MCP server. Prefer endpoint auto-bind when the image-side MCP supports it."`,
|
|
173
|
+
`mcp := (Smalltalk globals at: #MCP) new.`,
|
|
174
|
+
`endpointFile := ${smalltalkPath(options.endpointHandoffPath)} asFileReference.`,
|
|
175
|
+
`endpointFile exists ifTrue: [ endpointFile delete ].`,
|
|
176
|
+
``,
|
|
177
|
+
`((mcp respondsTo: #bindToLoopback) and: [ mcp respondsTo: #endpoint ])`,
|
|
178
|
+
` ifTrue: [`,
|
|
179
|
+
` mcp bindToLoopback.`,
|
|
180
|
+
` mcp port: 0.`,
|
|
181
|
+
` mcp start.`,
|
|
182
|
+
` endpoint := mcp endpoint.`,
|
|
183
|
+
` endpointValue := [ :key :fallback |`,
|
|
184
|
+
` endpoint`,
|
|
185
|
+
` at: key`,
|
|
186
|
+
` ifAbsent: [ endpoint at: key asString ifAbsent: [ fallback ] ] ].`,
|
|
187
|
+
` endpointTransport := (endpointValue value: #transport value: 'http') asString.`,
|
|
188
|
+
` endpointHost := (endpointValue value: #host value: '127.0.0.1') asString.`,
|
|
189
|
+
` endpointPort := endpointValue value: #port value: nil.`,
|
|
190
|
+
` endpointPath := (endpointValue value: #path value: '/') asString.`,
|
|
191
|
+
` endpointFile parent ensureCreateDirectory.`,
|
|
192
|
+
` endpointFile writeStreamDo: [ :stream |`,
|
|
193
|
+
` stream nextPutAll: 'transport='; nextPutAll: endpointTransport; cr.`,
|
|
194
|
+
` stream nextPutAll: 'host='; nextPutAll: endpointHost; cr.`,
|
|
195
|
+
` stream nextPutAll: 'port='; nextPutAll: endpointPort asString; cr.`,
|
|
196
|
+
` stream nextPutAll: 'path='; nextPutAll: endpointPath; cr ] ]`,
|
|
197
|
+
` ifFalse: [`,
|
|
198
|
+
...fallbackScript,
|
|
199
|
+
` ].`,
|
|
200
|
+
].join("\n");
|
|
201
|
+
}
|
|
202
|
+
function generateRepositoryWorkspaceLoadScript(options) {
|
|
203
|
+
const workspaces = projectImageRepositoryWorkspaces(options.imageState);
|
|
204
|
+
if (workspaces.length === 0) {
|
|
205
|
+
return "";
|
|
206
|
+
}
|
|
207
|
+
return workspaces
|
|
208
|
+
.map((workspace) => {
|
|
209
|
+
const loadStatusPath = options.loadStatusPaths?.[workspace.repository.id] ??
|
|
210
|
+
(workspaces.length === 1 ? options.loadStatusPath : undefined);
|
|
211
|
+
if (!loadStatusPath) {
|
|
212
|
+
return "";
|
|
213
|
+
}
|
|
214
|
+
const sourcePath = joinPathLike(workspace.path, workspace.sourceDirectory);
|
|
215
|
+
const loadCommand = workspace.loadGroup
|
|
216
|
+
? ` load: (Array with: ${smalltalkString(workspace.loadGroup)})`
|
|
217
|
+
: ` load`;
|
|
218
|
+
const currentCommitLine = workspace.currentCommit
|
|
219
|
+
? [
|
|
220
|
+
` stream`,
|
|
221
|
+
` nextPutAll: 'currentCommit=';`,
|
|
222
|
+
` nextPutAll: ${smalltalkString(workspace.currentCommit)};`,
|
|
223
|
+
` cr.`,
|
|
224
|
+
].join("\n")
|
|
225
|
+
: "";
|
|
226
|
+
return `
|
|
227
|
+
"Load the configured Pharo project from the image-local repository workspace."
|
|
228
|
+
repositoryLoadStatusFile := ${smalltalkPath(loadStatusPath)} asFileReference.
|
|
229
|
+
repositorySourcePath := ${smalltalkPath(sourcePath)}.
|
|
230
|
+
repositoryLoadStatusFile exists ifTrue: [ repositoryLoadStatusFile delete ].
|
|
231
|
+
repositoryLoadStatusWriter := [ :status :message |
|
|
232
|
+
repositoryLoadStatusFile parent ensureCreateDirectory.
|
|
233
|
+
repositoryLoadStatusFile writeStreamDo: [ :stream |
|
|
234
|
+
stream
|
|
235
|
+
nextPutAll: 'status=';
|
|
236
|
+
nextPutAll: status;
|
|
237
|
+
cr.
|
|
238
|
+
stream
|
|
239
|
+
nextPutAll: 'repositoryId=';
|
|
240
|
+
nextPutAll: ${smalltalkString(workspace.repository.id)};
|
|
241
|
+
cr.
|
|
242
|
+
stream
|
|
243
|
+
nextPutAll: 'sourcePath=';
|
|
244
|
+
nextPutAll: repositorySourcePath;
|
|
245
|
+
cr.
|
|
246
|
+
stream
|
|
247
|
+
nextPutAll: 'sourceDirectory=';
|
|
248
|
+
nextPutAll: ${smalltalkString(workspace.sourceDirectory)};
|
|
249
|
+
cr.
|
|
250
|
+
stream
|
|
251
|
+
nextPutAll: 'baseline=';
|
|
252
|
+
nextPutAll: ${smalltalkString(workspace.baseline)};
|
|
253
|
+
cr.
|
|
254
|
+
${workspace.loadGroup
|
|
255
|
+
? ` stream
|
|
256
|
+
nextPutAll: 'loadGroup=';
|
|
257
|
+
nextPutAll: ${smalltalkString(workspace.loadGroup)};
|
|
258
|
+
cr.
|
|
259
|
+
`
|
|
260
|
+
: ""}${currentCommitLine ? `${currentCommitLine}\n` : ""} message ifNotNil: [
|
|
261
|
+
stream
|
|
262
|
+
nextPutAll: 'message=';
|
|
263
|
+
nextPutAll: message asString;
|
|
264
|
+
cr ] ] ].
|
|
265
|
+
[
|
|
266
|
+
repositorySourceDirectory := repositorySourcePath asFileReference.
|
|
267
|
+
repositorySourceDirectory exists
|
|
268
|
+
ifFalse: [ Error signal: 'Configured Pharo project source directory does not exist: ', repositorySourcePath ].
|
|
269
|
+
Metacello new
|
|
270
|
+
repository: 'tonel://', repositorySourceDirectory fullName;
|
|
271
|
+
baseline: ${smalltalkString(workspace.baseline)};
|
|
272
|
+
onConflictUseIncoming;
|
|
273
|
+
onUpgrade: [ :ex :loaded :incoming | ex useIncoming ];
|
|
274
|
+
${loadCommand}.
|
|
275
|
+
repositoryLoadStatusWriter value: 'loaded' value: nil
|
|
276
|
+
] on: Error do: [ :error |
|
|
277
|
+
repositoryLoadStatusWriter value: 'failed' value: error description.
|
|
278
|
+
error pass ].
|
|
279
|
+
`;
|
|
280
|
+
})
|
|
281
|
+
.filter((script) => script.length > 0)
|
|
282
|
+
.join("\n");
|
|
283
|
+
}
|
|
284
|
+
function generateDependencyRepositoryCacheSetupScript(options) {
|
|
285
|
+
if (!options.cachePath) {
|
|
286
|
+
return "";
|
|
287
|
+
}
|
|
288
|
+
const networkPolicy = options.networkPolicy ?? "online";
|
|
289
|
+
return `
|
|
290
|
+
"Configure the PLexus-owned dependency repository cache for Metacello/Iceberg."
|
|
291
|
+
plexusDependencyRepositoryCachePath := ${smalltalkPath(options.cachePath)}.
|
|
292
|
+
plexusDependencyRepositoryNetworkPolicy := ${smalltalkString(networkPolicy)}.
|
|
293
|
+
plexusDependencyRepositoryCachePath asFileReference ensureCreateDirectory.
|
|
294
|
+
Smalltalk globals
|
|
295
|
+
at: #PLexusDependencyRepositoryCachePath
|
|
296
|
+
put: plexusDependencyRepositoryCachePath.
|
|
297
|
+
Smalltalk globals
|
|
298
|
+
at: #PLexusDependencyRepositoryNetworkPolicy
|
|
299
|
+
put: plexusDependencyRepositoryNetworkPolicy.
|
|
300
|
+
[
|
|
301
|
+
Iceberg enableMetacelloIntegration: true.
|
|
302
|
+
IceLibgitRepository
|
|
303
|
+
shareRepositoriesBetweenImages: true;
|
|
304
|
+
sharedRepositoriesLocationString: plexusDependencyRepositoryCachePath
|
|
305
|
+
]
|
|
306
|
+
on: Error
|
|
307
|
+
do: [ :error |
|
|
308
|
+
Error signal:
|
|
309
|
+
'PLexus dependency repository cache setup failed: ', error description ].
|
|
310
|
+
`;
|
|
311
|
+
}
|
|
312
|
+
function generateDependencyRepositoryDetachScript(options) {
|
|
313
|
+
if (!options.cachePath || !options.statusPath) {
|
|
314
|
+
return "";
|
|
315
|
+
}
|
|
316
|
+
const editableRepositoryPaths = options.editableRepositoryPaths ?? [];
|
|
317
|
+
const editablePathsLiteral = editableRepositoryPaths.length === 0
|
|
318
|
+
? "#()"
|
|
319
|
+
: `{ ${editableRepositoryPaths
|
|
320
|
+
.map((repositoryPath) => smalltalkPath(repositoryPath))
|
|
321
|
+
.join(". ")} }`;
|
|
322
|
+
return `
|
|
323
|
+
"Detach shared dependency repositories that PLexus loaded from the home cache."
|
|
324
|
+
plexusDependencyRepositoryDetachStatusFile := ${smalltalkPath(options.statusPath)} asFileReference.
|
|
325
|
+
plexusDependencyRepositoryDetachStatusFile exists
|
|
326
|
+
ifTrue: [ plexusDependencyRepositoryDetachStatusFile delete ].
|
|
327
|
+
plexusDependencyRepositoryCachePath := ${smalltalkPath(options.cachePath)}.
|
|
328
|
+
plexusEditableRepositoryPaths := ${editablePathsLiteral}.
|
|
329
|
+
plexusNormalizePath := [ :path |
|
|
330
|
+
| normalized |
|
|
331
|
+
normalized := path ifNil: [ '' ] ifNotNil: [
|
|
332
|
+
path asString copyReplaceAll: '\\' with: '/' ].
|
|
333
|
+
[ normalized notEmpty and: [ normalized last = $/ ] ]
|
|
334
|
+
whileTrue: [ normalized := normalized allButLast ].
|
|
335
|
+
normalized ].
|
|
336
|
+
plexusRepositoryLocationString := [ :repository |
|
|
337
|
+
plexusNormalizePath value: ([
|
|
338
|
+
repository location fullName ]
|
|
339
|
+
on: Error
|
|
340
|
+
do: [ :ignored |
|
|
341
|
+
[ repository location asString ]
|
|
342
|
+
on: Error
|
|
343
|
+
do: [ :secondIgnored | '' ] ]) ].
|
|
344
|
+
plexusRepositoryNameString := [ :repository |
|
|
345
|
+
[ repository name asString ]
|
|
346
|
+
on: Error
|
|
347
|
+
do: [ :ignored | '' ] ].
|
|
348
|
+
plexusDependencyRepositoryDetachStatusWriter := [ :status :message :detachedRepositories |
|
|
349
|
+
plexusDependencyRepositoryDetachStatusFile parent ensureCreateDirectory.
|
|
350
|
+
plexusDependencyRepositoryDetachStatusFile writeStreamDo: [ :stream |
|
|
351
|
+
stream
|
|
352
|
+
nextPutAll: 'status=';
|
|
353
|
+
nextPutAll: status;
|
|
354
|
+
cr.
|
|
355
|
+
stream
|
|
356
|
+
nextPutAll: 'cachePath=';
|
|
357
|
+
nextPutAll: (plexusNormalizePath value: plexusDependencyRepositoryCachePath);
|
|
358
|
+
cr.
|
|
359
|
+
stream
|
|
360
|
+
nextPutAll: 'detachedCount=';
|
|
361
|
+
nextPutAll: detachedRepositories size asString;
|
|
362
|
+
cr.
|
|
363
|
+
message ifNotNil: [
|
|
364
|
+
stream
|
|
365
|
+
nextPutAll: 'message=';
|
|
366
|
+
nextPutAll: message asString;
|
|
367
|
+
cr ].
|
|
368
|
+
detachedRepositories withIndexDo: [ :repository :index |
|
|
369
|
+
stream
|
|
370
|
+
nextPutAll: 'repository.';
|
|
371
|
+
nextPutAll: index asString;
|
|
372
|
+
nextPutAll: '.name=';
|
|
373
|
+
nextPutAll: (plexusRepositoryNameString value: repository);
|
|
374
|
+
cr.
|
|
375
|
+
stream
|
|
376
|
+
nextPutAll: 'repository.';
|
|
377
|
+
nextPutAll: index asString;
|
|
378
|
+
nextPutAll: '.location=';
|
|
379
|
+
nextPutAll: (plexusRepositoryLocationString value: repository);
|
|
380
|
+
cr ] ] ].
|
|
381
|
+
(Smalltalk globals includesKey: #IceRepository)
|
|
382
|
+
ifTrue: [
|
|
383
|
+
[
|
|
384
|
+
| cachePath editablePaths repositoriesToDetach |
|
|
385
|
+
cachePath := plexusNormalizePath value: plexusDependencyRepositoryCachePath.
|
|
386
|
+
editablePaths := plexusEditableRepositoryPaths collect: [ :each |
|
|
387
|
+
plexusNormalizePath value: each ].
|
|
388
|
+
repositoriesToDetach := OrderedCollection new.
|
|
389
|
+
(Smalltalk globals at: #IceRepository) registry do: [ :repository |
|
|
390
|
+
| repositoryLocation isInCache isEditable |
|
|
391
|
+
repositoryLocation := plexusRepositoryLocationString value: repository.
|
|
392
|
+
isInCache := repositoryLocation = cachePath or: [
|
|
393
|
+
repositoryLocation beginsWith: cachePath , '/' ].
|
|
394
|
+
isEditable := editablePaths includes: repositoryLocation.
|
|
395
|
+
(isInCache and: [ isEditable not ])
|
|
396
|
+
ifTrue: [ repositoriesToDetach add: repository ] ].
|
|
397
|
+
repositoriesToDetach do: [ :repository |
|
|
398
|
+
(Smalltalk globals at: #IceRepository) registry
|
|
399
|
+
remove: repository
|
|
400
|
+
ifAbsent: [ ] ].
|
|
401
|
+
plexusDependencyRepositoryDetachStatusWriter
|
|
402
|
+
value: 'detached'
|
|
403
|
+
value: nil
|
|
404
|
+
value: repositoriesToDetach ]
|
|
405
|
+
on: Error
|
|
406
|
+
do: [ :error |
|
|
407
|
+
plexusDependencyRepositoryDetachStatusWriter
|
|
408
|
+
value: 'failed'
|
|
409
|
+
value: error description
|
|
410
|
+
value: #( ).
|
|
411
|
+
error pass ] ]
|
|
412
|
+
ifFalse: [
|
|
413
|
+
plexusDependencyRepositoryDetachStatusWriter
|
|
414
|
+
value: 'skipped'
|
|
415
|
+
value: 'IceRepository is not available.'
|
|
416
|
+
value: #( ) ].
|
|
417
|
+
`;
|
|
418
|
+
}
|
|
419
|
+
function generatePharoMcpLoadScript(options) {
|
|
420
|
+
const repositoryLabel = `github://${options.repository.githubUser}/${options.repository.project}:${options.repository.commitish}/${options.repository.path}`;
|
|
421
|
+
const shouldThrowOnFailure = options.failureBehavior !== "record";
|
|
422
|
+
const failureHandler = shouldThrowOnFailure
|
|
423
|
+
? ` error pass`
|
|
424
|
+
: ` "Optional Pharo MCP startup records the failure and leaves the image process alive."`;
|
|
425
|
+
const loadPolicy = options.loadPolicy ?? "ifMissing";
|
|
426
|
+
const loadScriptPath = options.loadScriptPath;
|
|
427
|
+
if (loadPolicy !== "never" && loadScriptPath === undefined) {
|
|
428
|
+
throw new ProjectStartupScriptError(`Project image ${options.imageId} requires mcp.loadScript unless mcp.loadPolicy is never`);
|
|
429
|
+
}
|
|
430
|
+
if (!options.statusPath) {
|
|
431
|
+
const loadScript = loadPolicy === "never"
|
|
432
|
+
? `"Use the Pharo MCP project already present in the image."
|
|
433
|
+
(Smalltalk globals includesKey: #MCP)
|
|
434
|
+
ifFalse: [ Error signal: 'MCP class is not available because mcp.loadPolicy is never.' ].`
|
|
435
|
+
: `"Load the Pharo MCP project if configured policy requires it."
|
|
436
|
+
pharoMcpLoadPolicy := ${smalltalkString(loadPolicy)}.
|
|
437
|
+
(pharoMcpLoadPolicy = 'always' or: [
|
|
438
|
+
(Smalltalk globals includesKey: #MCP) not ]) ifTrue: [
|
|
439
|
+
loadScript := ${smalltalkPath(loadScriptPath)} asFileReference.
|
|
440
|
+
loadScript exists
|
|
441
|
+
ifTrue: [ loadScript fileIn ]
|
|
442
|
+
ifFalse: [
|
|
443
|
+
Metacello new
|
|
444
|
+
githubUser: ${smalltalkString(options.repository.githubUser)} project: ${smalltalkString(options.repository.project)} commitish: ${smalltalkString(options.repository.commitish)} path: ${smalltalkString(options.repository.path)};
|
|
445
|
+
baseline: ${smalltalkString(options.repository.baseline)};
|
|
446
|
+
load ] ].
|
|
447
|
+
|
|
448
|
+
(Smalltalk globals includesKey: #MCP)
|
|
449
|
+
ifFalse: [ Error signal: 'MCP class is not available after loading.' ].`;
|
|
450
|
+
return shouldThrowOnFailure
|
|
451
|
+
? loadScript
|
|
452
|
+
: `[
|
|
453
|
+
${loadScript}
|
|
454
|
+
] on: Error do: [ :error |
|
|
455
|
+
"Optional Pharo MCP startup has no status path, so the failure is only kept in-image."
|
|
456
|
+
].`;
|
|
457
|
+
}
|
|
458
|
+
const loadScriptStatusLines = loadScriptPath === undefined
|
|
459
|
+
? ""
|
|
460
|
+
: ` stream
|
|
461
|
+
nextPutAll: 'loadScript=';
|
|
462
|
+
nextPutAll: ${smalltalkPath(loadScriptPath)};
|
|
463
|
+
cr.`;
|
|
464
|
+
const loadAction = loadPolicy === "never"
|
|
465
|
+
? ` pharoMcpLoadSource := 'provided'.
|
|
466
|
+
(Smalltalk globals includesKey: #MCP)
|
|
467
|
+
ifTrue: [ pharoMcpLoadStatusWriter value: 'provided' value: nil ]
|
|
468
|
+
ifFalse: [ Error signal: 'MCP class is not available because mcp.loadPolicy is never.' ]`
|
|
469
|
+
: ` (pharoMcpLoadPolicy = 'ifMissing' and: [ Smalltalk globals includesKey: #MCP ])
|
|
470
|
+
ifTrue: [
|
|
471
|
+
pharoMcpLoadSource := 'provided'.
|
|
472
|
+
pharoMcpLoadStatusWriter value: 'provided' value: nil ]
|
|
473
|
+
ifFalse: [
|
|
474
|
+
loadScript := ${smalltalkPath(loadScriptPath)} asFileReference.
|
|
475
|
+
loadScript exists
|
|
476
|
+
ifTrue: [
|
|
477
|
+
pharoMcpLoadSource := 'loadScript'.
|
|
478
|
+
loadScript fileIn ]
|
|
479
|
+
ifFalse: [
|
|
480
|
+
pharoMcpLoadSource := 'metacello'.
|
|
481
|
+
Metacello new
|
|
482
|
+
githubUser: ${smalltalkString(options.repository.githubUser)} project: ${smalltalkString(options.repository.project)} commitish: ${smalltalkString(options.repository.commitish)} path: ${smalltalkString(options.repository.path)};
|
|
483
|
+
baseline: ${smalltalkString(options.repository.baseline)};
|
|
484
|
+
load ].
|
|
485
|
+
(Smalltalk globals includesKey: #MCP)
|
|
486
|
+
ifFalse: [ Error signal: 'MCP class is not available after loading.' ].
|
|
487
|
+
pharoMcpLoadStatusWriter value: 'loaded' value: nil ]`;
|
|
488
|
+
return `"Load the Pharo MCP project according to mcp.loadPolicy."
|
|
489
|
+
pharoMcpLoadStatusFile := ${smalltalkPath(options.statusPath)} asFileReference.
|
|
490
|
+
pharoMcpLoadStatusFile exists ifTrue: [ pharoMcpLoadStatusFile delete ].
|
|
491
|
+
pharoMcpLoadPolicy := ${smalltalkString(loadPolicy)}.
|
|
492
|
+
pharoMcpLoadSource := 'pending'.
|
|
493
|
+
pharoMcpLoadStatusWriter := [ :status :message |
|
|
494
|
+
pharoMcpLoadStatusFile parent ensureCreateDirectory.
|
|
495
|
+
pharoMcpLoadStatusFile writeStreamDo: [ :stream |
|
|
496
|
+
stream
|
|
497
|
+
nextPutAll: 'status=';
|
|
498
|
+
nextPutAll: status;
|
|
499
|
+
cr.
|
|
500
|
+
stream
|
|
501
|
+
nextPutAll: 'imageId=';
|
|
502
|
+
nextPutAll: ${smalltalkString(options.imageId)};
|
|
503
|
+
cr.
|
|
504
|
+
stream
|
|
505
|
+
nextPutAll: 'source=';
|
|
506
|
+
nextPutAll: (pharoMcpLoadSource ifNil: [ 'unknown' ]);
|
|
507
|
+
cr.
|
|
508
|
+
${loadScriptStatusLines}
|
|
509
|
+
stream
|
|
510
|
+
nextPutAll: 'loadPolicy=';
|
|
511
|
+
nextPutAll: pharoMcpLoadPolicy;
|
|
512
|
+
cr.
|
|
513
|
+
pharoMcpLoadSource = 'metacello'
|
|
514
|
+
ifTrue: [
|
|
515
|
+
stream
|
|
516
|
+
nextPutAll: 'repository=';
|
|
517
|
+
nextPutAll: ${smalltalkString(repositoryLabel)};
|
|
518
|
+
cr ]
|
|
519
|
+
ifFalse: [
|
|
520
|
+
stream
|
|
521
|
+
nextPutAll: 'configuredRepositoryHint=';
|
|
522
|
+
nextPutAll: ${smalltalkString(repositoryLabel)};
|
|
523
|
+
cr ].
|
|
524
|
+
stream
|
|
525
|
+
nextPutAll: 'baseline=';
|
|
526
|
+
nextPutAll: ${smalltalkString(options.repository.baseline)};
|
|
527
|
+
cr.
|
|
528
|
+
message ifNotNil: [
|
|
529
|
+
stream
|
|
530
|
+
nextPutAll: 'message=';
|
|
531
|
+
nextPutAll: message asString;
|
|
532
|
+
cr ] ] ].
|
|
533
|
+
[
|
|
534
|
+
${loadAction}
|
|
535
|
+
]
|
|
536
|
+
on: Error do: [ :error |
|
|
537
|
+
pharoMcpLoadStatusWriter value: 'failed' value: error description.
|
|
538
|
+
${failureHandler} ].`;
|
|
539
|
+
}
|
|
540
|
+
export function generateImageStartupScript(options) {
|
|
541
|
+
const dependencyRepositoryCacheSetupScript = generateDependencyRepositoryCacheSetupScript({
|
|
542
|
+
cachePath: options.dependencyRepositoryCachePath,
|
|
543
|
+
networkPolicy: options.dependencyRepositoryNetworkPolicy,
|
|
544
|
+
});
|
|
545
|
+
const repositoryWorkspaceLoadScript = generateRepositoryWorkspaceLoadScript({
|
|
546
|
+
imageState: options.imageState,
|
|
547
|
+
loadStatusPath: options.repositoryWorkspaceLoadStatusPath,
|
|
548
|
+
loadStatusPaths: options.repositoryWorkspaceLoadStatusPaths,
|
|
549
|
+
});
|
|
550
|
+
const dependencyRepositoryDetachScript = generateDependencyRepositoryDetachScript({
|
|
551
|
+
cachePath: options.dependencyRepositoryCachePath,
|
|
552
|
+
statusPath: options.dependencyRepositoryDetachStatusPath,
|
|
553
|
+
editableRepositoryPaths: projectImageRepositoryWorkspaces(options.imageState).map((workspace) => workspace.path),
|
|
554
|
+
});
|
|
555
|
+
const startupMode = projectMcpStartupMode(options.imageConfig.mcp);
|
|
556
|
+
if (startupMode === "disabled" ||
|
|
557
|
+
options.imageState.pharoMcpContract?.status === "unsupported") {
|
|
558
|
+
const reason = startupMode === "disabled"
|
|
559
|
+
? "Project image mcp.startupMode is disabled."
|
|
560
|
+
: (options.imageState.pharoMcpContract?.reason ??
|
|
561
|
+
"This image Pharo version is outside the supported Pharo MCP range.");
|
|
562
|
+
return `"Generated by PLexus. Do not edit."
|
|
563
|
+
|
|
564
|
+
| plexusDependencyRepositoryCachePath plexusDependencyRepositoryNetworkPolicy plexusDependencyRepositoryDetachStatusFile plexusEditableRepositoryPaths plexusNormalizePath plexusRepositoryLocationString plexusRepositoryNameString plexusDependencyRepositoryDetachStatusWriter repositoryLoadStatusFile repositorySourcePath repositorySourceDirectory repositoryLoadStatusWriter |
|
|
565
|
+
|
|
566
|
+
${dependencyRepositoryCacheSetupScript}
|
|
567
|
+
${repositoryWorkspaceLoadScript}
|
|
568
|
+
${dependencyRepositoryDetachScript}
|
|
569
|
+
|
|
570
|
+
${smalltalkComment(`Pharo MCP startup is disabled: ${reason}`)}
|
|
571
|
+
${smalltalkComment("Keep the headless eval process alive for project lifecycle management only.")}
|
|
572
|
+
Semaphore new wait.
|
|
573
|
+
`;
|
|
574
|
+
}
|
|
575
|
+
const preferEndpointHandoff = options.endpointHandoffPath !== undefined &&
|
|
576
|
+
options.imageConfig.mcp.port === undefined;
|
|
577
|
+
if (options.imageState.assignedPort === undefined &&
|
|
578
|
+
!preferEndpointHandoff) {
|
|
579
|
+
throw new ProjectStartupScriptError(`Project image ${options.imageState.id} requires Pharo MCP startup but has no assigned MCP port`);
|
|
580
|
+
}
|
|
581
|
+
const repository = options.repository ?? defaultPharoMcpMetacelloRepository;
|
|
582
|
+
const loadPolicy = projectMcpLoadPolicy(options.imageConfig.mcp);
|
|
583
|
+
const loadScriptPath = loadPolicy === "never"
|
|
584
|
+
? undefined
|
|
585
|
+
: resolveLoadScriptPath(options.projectRoot, options.sourcePath, options.imageConfig);
|
|
586
|
+
const gitConfiguration = generateGitConfigurationScript(options.imageConfig);
|
|
587
|
+
const pharoMcpLoadScript = generatePharoMcpLoadScript({
|
|
588
|
+
imageId: options.imageState.id,
|
|
589
|
+
loadScriptPath,
|
|
590
|
+
repository,
|
|
591
|
+
statusPath: options.pharoMcpLoadStatusPath,
|
|
592
|
+
failureBehavior: startupMode === "optional" ? "record" : "throw",
|
|
593
|
+
loadPolicy,
|
|
594
|
+
});
|
|
595
|
+
const requiredMcpStartup = preferEndpointHandoff
|
|
596
|
+
? generateEndpointHandoffStartupScript({
|
|
597
|
+
assignedPort: options.imageState.assignedPort,
|
|
598
|
+
endpointHandoffPath: options.endpointHandoffPath,
|
|
599
|
+
})
|
|
600
|
+
: [
|
|
601
|
+
`"Configure and start the MCP server."`,
|
|
602
|
+
`mcp := (Smalltalk globals at: #MCP) new.`,
|
|
603
|
+
`mcp port: ${options.imageState.assignedPort}.`,
|
|
604
|
+
`mcp start.`,
|
|
605
|
+
].join("\n");
|
|
606
|
+
const mcpStartup = startupMode === "optional"
|
|
607
|
+
? [
|
|
608
|
+
`"Configure and start the MCP server when optional loading succeeded."`,
|
|
609
|
+
`(Smalltalk globals includesKey: #MCP)`,
|
|
610
|
+
` ifTrue: [`,
|
|
611
|
+
requiredMcpStartup
|
|
612
|
+
.split("\n")
|
|
613
|
+
.map((line) => ` ${line}`)
|
|
614
|
+
.join("\n"),
|
|
615
|
+
` Smalltalk globals at: #PLexusMCPServer put: mcp ]`,
|
|
616
|
+
` ifFalse: [`,
|
|
617
|
+
` ${smalltalkComment("Optional Pharo MCP startup did not provide MCP; keep the image process alive without a route.")} ].`,
|
|
618
|
+
].join("\n")
|
|
619
|
+
: `${requiredMcpStartup}\n\nSmalltalk globals at: #PLexusMCPServer put: mcp.`;
|
|
620
|
+
return `"Generated by PLexus. Do not edit."
|
|
621
|
+
|
|
622
|
+
| loadScript mcp endpointFile endpoint endpointValue endpointTransport endpointHost endpointPort endpointPath pharoMcpLoadStatusFile pharoMcpLoadStatusWriter pharoMcpLoadSource pharoMcpLoadPolicy plexusDependencyRepositoryCachePath plexusDependencyRepositoryNetworkPolicy plexusDependencyRepositoryDetachStatusFile plexusEditableRepositoryPaths plexusNormalizePath plexusRepositoryLocationString plexusRepositoryNameString plexusDependencyRepositoryDetachStatusWriter repositoryLoadStatusFile repositorySourcePath repositorySourceDirectory repositoryLoadStatusWriter |
|
|
623
|
+
|
|
624
|
+
${gitConfiguration}
|
|
625
|
+
|
|
626
|
+
${dependencyRepositoryCacheSetupScript}
|
|
627
|
+
${repositoryWorkspaceLoadScript}
|
|
628
|
+
|
|
629
|
+
${pharoMcpLoadScript}
|
|
630
|
+
|
|
631
|
+
${dependencyRepositoryDetachScript}
|
|
632
|
+
|
|
633
|
+
"Stop the previous server registered by PLexus before starting a new one."
|
|
634
|
+
(Smalltalk globals at: #PLexusMCPServer ifAbsent: [ nil ])
|
|
635
|
+
ifNotNil: [ :existingServer |
|
|
636
|
+
[ existingServer stop ] on: Error do: [ :error | nil ] ].
|
|
637
|
+
|
|
638
|
+
${mcpStartup}
|
|
639
|
+
|
|
640
|
+
"Keep the headless eval process alive while the MCP server accepts requests."
|
|
641
|
+
Semaphore new wait.
|
|
642
|
+
`;
|
|
643
|
+
}
|
|
644
|
+
export function writeImageStartupScript(options) {
|
|
645
|
+
const filePath = imageStartupScriptPath({
|
|
646
|
+
projectRoot: options.projectRoot,
|
|
647
|
+
projectId: options.projectId,
|
|
648
|
+
workspaceId: options.workspaceId,
|
|
649
|
+
imageId: options.imageConfig.id,
|
|
650
|
+
stateRoot: options.stateRoot,
|
|
651
|
+
});
|
|
652
|
+
const repositoryWorkspaces = projectImageRepositoryWorkspaces(options.imageState);
|
|
653
|
+
const repositoryWorkspaceLoadStatusPaths = repositoryWorkspaces.length > 0
|
|
654
|
+
? Object.fromEntries(repositoryWorkspaces.map((workspace) => {
|
|
655
|
+
const pathOptions = {
|
|
656
|
+
projectRoot: options.projectRoot,
|
|
657
|
+
projectId: options.projectId,
|
|
658
|
+
workspaceId: options.workspaceId,
|
|
659
|
+
imageId: options.imageConfig.id,
|
|
660
|
+
stateRoot: options.stateRoot,
|
|
661
|
+
};
|
|
662
|
+
return [
|
|
663
|
+
workspace.repository.id,
|
|
664
|
+
imageRepositoryWorkspaceLoadStatusPath(repositoryWorkspaces.length === 1
|
|
665
|
+
? pathOptions
|
|
666
|
+
: {
|
|
667
|
+
...pathOptions,
|
|
668
|
+
repositoryId: workspace.repository.id,
|
|
669
|
+
}),
|
|
670
|
+
];
|
|
671
|
+
}))
|
|
672
|
+
: undefined;
|
|
673
|
+
const repositoryWorkspaceLoadStatusPath = repositoryWorkspaces.length === 1
|
|
674
|
+
? repositoryWorkspaceLoadStatusPaths?.[repositoryWorkspaces[0].repository.id]
|
|
675
|
+
: undefined;
|
|
676
|
+
const pharoMcpLoadStatusPath = projectMcpStartupMode(options.imageConfig.mcp) === "disabled" ||
|
|
677
|
+
options.imageState.pharoMcpContract?.status === "unsupported"
|
|
678
|
+
? undefined
|
|
679
|
+
: imagePharoMcpLoadStatusPath({
|
|
680
|
+
projectRoot: options.projectRoot,
|
|
681
|
+
projectId: options.projectId,
|
|
682
|
+
workspaceId: options.workspaceId,
|
|
683
|
+
imageId: options.imageConfig.id,
|
|
684
|
+
stateRoot: options.stateRoot,
|
|
685
|
+
});
|
|
686
|
+
const dependencyRepositoryDetachStatusPath = options.dependencyRepositoryCachePath
|
|
687
|
+
? imageDependencyRepositoryDetachStatusPath({
|
|
688
|
+
projectRoot: options.projectRoot,
|
|
689
|
+
projectId: options.projectId,
|
|
690
|
+
workspaceId: options.workspaceId,
|
|
691
|
+
imageId: options.imageConfig.id,
|
|
692
|
+
stateRoot: options.stateRoot,
|
|
693
|
+
})
|
|
694
|
+
: undefined;
|
|
695
|
+
const source = generateImageStartupScript({
|
|
696
|
+
...options,
|
|
697
|
+
...(pharoMcpLoadStatusPath ? { pharoMcpLoadStatusPath } : {}),
|
|
698
|
+
...(repositoryWorkspaceLoadStatusPath
|
|
699
|
+
? { repositoryWorkspaceLoadStatusPath }
|
|
700
|
+
: {}),
|
|
701
|
+
...(repositoryWorkspaceLoadStatusPaths
|
|
702
|
+
? { repositoryWorkspaceLoadStatusPaths }
|
|
703
|
+
: {}),
|
|
704
|
+
...(dependencyRepositoryDetachStatusPath
|
|
705
|
+
? { dependencyRepositoryDetachStatusPath }
|
|
706
|
+
: {}),
|
|
707
|
+
});
|
|
708
|
+
fs.mkdirSync(dirnamePathLike(filePath), { recursive: true });
|
|
709
|
+
fs.writeFileSync(filePath, source, "utf8");
|
|
710
|
+
return {
|
|
711
|
+
filePath,
|
|
712
|
+
source,
|
|
713
|
+
...(pharoMcpLoadStatusPath ? { pharoMcpLoadStatusPath } : {}),
|
|
714
|
+
...(repositoryWorkspaceLoadStatusPath
|
|
715
|
+
? { repositoryWorkspaceLoadStatusPath }
|
|
716
|
+
: {}),
|
|
717
|
+
...(repositoryWorkspaceLoadStatusPaths
|
|
718
|
+
? { repositoryWorkspaceLoadStatusPaths }
|
|
719
|
+
: {}),
|
|
720
|
+
...(dependencyRepositoryDetachStatusPath
|
|
721
|
+
? { dependencyRepositoryDetachStatusPath }
|
|
722
|
+
: {}),
|
|
723
|
+
};
|
|
724
|
+
}
|
|
725
|
+
export function writeProjectImageStartupScript(options) {
|
|
726
|
+
const imageConfig = findProjectImageConfig(options.config, options.imageId);
|
|
727
|
+
const plexusHomePath = resolvePlexusHomePath({ config: options.config });
|
|
728
|
+
return writeImageStartupScript({
|
|
729
|
+
projectRoot: options.projectRoot,
|
|
730
|
+
sourcePath: options.sourcePath,
|
|
731
|
+
projectId: projectConfigId(options.config),
|
|
732
|
+
imageConfig,
|
|
733
|
+
imageState: options.imageState,
|
|
734
|
+
endpointHandoffPath: imageMcpEndpointHandoffPath({
|
|
735
|
+
projectRoot: options.projectRoot,
|
|
736
|
+
projectId: projectConfigId(options.config),
|
|
737
|
+
workspaceId: options.workspaceId,
|
|
738
|
+
imageId: options.imageId,
|
|
739
|
+
stateRoot: projectStateRootForConfig(options.config, options.stateRoot),
|
|
740
|
+
}),
|
|
741
|
+
workspaceId: options.workspaceId,
|
|
742
|
+
stateRoot: projectStateRootForConfig(options.config, options.stateRoot),
|
|
743
|
+
dependencyRepositoryCachePath: homeDependencyRepositoryCachePath(plexusHomePath),
|
|
744
|
+
dependencyRepositoryNetworkPolicy: homeDependencyRepositoryNetworkPolicy(options.config),
|
|
745
|
+
repository: options.repository,
|
|
746
|
+
});
|
|
747
|
+
}
|
|
748
|
+
//# sourceMappingURL=projectStartupScript.js.map
|