@evref-bl/pharo-launcher-mcp 0.4.0 → 0.5.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 +29 -20
- package/dist/answers.d.ts +43 -0
- package/dist/answers.d.ts.map +1 -0
- package/dist/answers.js +744 -0
- package/dist/answers.js.map +1 -0
- package/dist/commandCatalog.d.ts +13 -1
- package/dist/commandCatalog.d.ts.map +1 -1
- package/dist/commandCatalog.js +65 -89
- package/dist/commandCatalog.js.map +1 -1
- package/dist/config.d.ts +5 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +3 -1
- package/dist/config.js.map +1 -1
- package/dist/crossProfileCopy.d.ts +37 -0
- package/dist/crossProfileCopy.d.ts.map +1 -1
- package/dist/crossProfileCopy.js +77 -16
- package/dist/crossProfileCopy.js.map +1 -1
- package/dist/discovery.d.ts +8 -0
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +10 -0
- package/dist/discovery.js.map +1 -1
- package/dist/imageStore.d.ts +139 -0
- package/dist/imageStore.d.ts.map +1 -0
- package/dist/imageStore.js +385 -0
- package/dist/imageStore.js.map +1 -0
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/launcher.d.ts +64 -17
- package/dist/launcher.d.ts.map +1 -1
- package/dist/launcher.js +206 -167
- package/dist/launcher.js.map +1 -1
- package/dist/launcherCli.d.ts +13 -0
- package/dist/launcherCli.d.ts.map +1 -1
- package/dist/launcherCli.js +85 -91
- package/dist/launcherCli.js.map +1 -1
- package/dist/models.d.ts +117 -6
- package/dist/models.d.ts.map +1 -1
- package/dist/parser.d.ts +20 -7
- package/dist/parser.d.ts.map +1 -1
- package/dist/parser.js +48 -207
- package/dist/parser.js.map +1 -1
- package/dist/platform.d.ts +6 -0
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +14 -0
- package/dist/platform.js.map +1 -1
- package/dist/probe.d.ts +16 -0
- package/dist/probe.d.ts.map +1 -0
- package/dist/probe.js +31 -0
- package/dist/probe.js.map +1 -0
- package/dist/processTools.d.ts +22 -8
- package/dist/processTools.d.ts.map +1 -1
- package/dist/processTools.js +75 -58
- package/dist/processTools.js.map +1 -1
- package/dist/resultNormalizer.d.ts +9 -0
- package/dist/resultNormalizer.d.ts.map +1 -1
- package/dist/resultNormalizer.js +36 -79
- package/dist/resultNormalizer.js.map +1 -1
- package/dist/server.d.ts +10 -9
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +56 -55
- package/dist/server.js.map +1 -1
- package/dist/ston.d.ts +22 -0
- package/dist/ston.d.ts.map +1 -0
- package/dist/ston.js +127 -0
- package/dist/ston.js.map +1 -0
- package/docs/cleanup-hook-boundary.md +11 -9
- package/docs/development.md +51 -38
- package/docs/reference/tools.md +100 -40
- package/docs/troubleshooting.md +32 -23
- package/docs/user/getting-started.md +4 -4
- package/docs/user/profile-mode.md +30 -21
- package/package.json +1 -1
package/dist/processTools.js
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { afterLeadingDigits, hasCaseInsensitiveSuffix, leadingDigits, quotedValues, whitespaceTokens, } from "./textTokens.js";
|
|
4
|
+
/** Every Pharo VM on the machine, an image named as its command line names it. */
|
|
5
|
+
export const machineWideProcessScope = {
|
|
6
|
+
select: (processes) => [...processes],
|
|
7
|
+
imageTargets: (processes, target) => processes.filter((process) => process.imageName === target || process.imagePath === target),
|
|
8
|
+
};
|
|
9
|
+
/** Whether a pid runs: signal 0 checks without killing, `ESRCH` is gone. */
|
|
10
|
+
export function isPidAlive(pid) {
|
|
11
|
+
try {
|
|
12
|
+
process.kill(pid, 0);
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
return error.code !== "ESRCH";
|
|
17
|
+
}
|
|
18
|
+
}
|
|
4
19
|
function duration(startTime) {
|
|
5
20
|
return Date.now() - startTime;
|
|
6
21
|
}
|
|
@@ -143,12 +158,6 @@ async function listPosixPharoProcesses(timeoutMs, runCommand) {
|
|
|
143
158
|
// way, so the kind is read back off the target: all digits is a pid, anything
|
|
144
159
|
// else is an image. Matching the command line as well used to make a pid kill
|
|
145
160
|
// reach every process whose command line merely contained those digits.
|
|
146
|
-
function matchesTarget(process, target) {
|
|
147
|
-
if (isPid(target)) {
|
|
148
|
-
return String(process.pid) === target;
|
|
149
|
-
}
|
|
150
|
-
return process.imageName === target || process.imagePath === target;
|
|
151
|
-
}
|
|
152
161
|
function isPid(target) {
|
|
153
162
|
return /^\d+$/.test(target);
|
|
154
163
|
}
|
|
@@ -171,7 +180,7 @@ export function nativeProcessToolCapability(platform = process.platform) {
|
|
|
171
180
|
platform,
|
|
172
181
|
backend: "unsupported",
|
|
173
182
|
supported: false,
|
|
174
|
-
reason: `
|
|
183
|
+
reason: `listing processes is not supported on ${platform}`,
|
|
175
184
|
};
|
|
176
185
|
}
|
|
177
186
|
export function shouldUseNativeProcessTool(platform = process.platform) {
|
|
@@ -184,28 +193,56 @@ async function listNativePharoProcesses(capability, timeoutMs, runCommand) {
|
|
|
184
193
|
if (capability.backend === "posix-ps") {
|
|
185
194
|
return listPosixPharoProcesses(timeoutMs, runCommand);
|
|
186
195
|
}
|
|
187
|
-
throw new Error(capability.reason ?? "
|
|
196
|
+
throw new Error(capability.reason ?? "listing processes is not supported");
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* The machine's Pharo processes: each line of the native list that names a
|
|
200
|
+
* `.image` and mentions pharo or squeak. Throws why it cannot list them.
|
|
201
|
+
*/
|
|
202
|
+
export async function listNativeProcesses(options = {}) {
|
|
203
|
+
return listNativePharoProcesses(nativeProcessToolCapability(options.platform), options.timeoutMs ?? 30_000, options.runCommand ?? runProcessCommand);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Kill every target, and say which kills failed. A pid gone meanwhile
|
|
207
|
+
* (`ESRCH`) is stopped, which is what the kill was for.
|
|
208
|
+
*/
|
|
209
|
+
function killEach(targets, killProcess) {
|
|
210
|
+
const killed = [];
|
|
211
|
+
const failures = [];
|
|
212
|
+
for (const { pid } of targets) {
|
|
213
|
+
try {
|
|
214
|
+
killProcess(pid);
|
|
215
|
+
killed.push(pid);
|
|
216
|
+
}
|
|
217
|
+
catch (error) {
|
|
218
|
+
if (error.code === "ESRCH") {
|
|
219
|
+
killed.push(pid);
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
failures.push({
|
|
223
|
+
pid,
|
|
224
|
+
message: error instanceof Error ? error.message : String(error),
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return { killed, failures };
|
|
188
230
|
}
|
|
189
|
-
export async function runNativeProcessTool(args, optionsOrTimeoutMs = 30_000) {
|
|
231
|
+
export async function runNativeProcessTool(args, optionsOrTimeoutMs = 30_000, scope = machineWideProcessScope) {
|
|
190
232
|
const options = typeof optionsOrTimeoutMs === "number"
|
|
191
233
|
? { timeoutMs: optionsOrTimeoutMs }
|
|
192
234
|
: optionsOrTimeoutMs;
|
|
193
|
-
const
|
|
194
|
-
const capability = nativeProcessToolCapability(options.platform);
|
|
195
|
-
const runCommand = options.runCommand ?? runProcessCommand;
|
|
196
|
-
const killProcess = options.killProcess ?? process.kill;
|
|
235
|
+
const killProcess = options.killProcess ?? ((pid) => process.kill(pid));
|
|
197
236
|
const startTime = Date.now();
|
|
237
|
+
const failed = (stderr) => ({
|
|
238
|
+
exitCode: 1,
|
|
239
|
+
stdout: "",
|
|
240
|
+
stderr,
|
|
241
|
+
durationMs: duration(startTime),
|
|
242
|
+
timedOut: false,
|
|
243
|
+
});
|
|
198
244
|
try {
|
|
199
|
-
|
|
200
|
-
return {
|
|
201
|
-
exitCode: 1,
|
|
202
|
-
stdout: "",
|
|
203
|
-
stderr: capability.reason ?? "Native process backend is not supported",
|
|
204
|
-
durationMs: duration(startTime),
|
|
205
|
-
timedOut: false,
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
const processes = await listNativePharoProcesses(capability, timeoutMs, runCommand);
|
|
245
|
+
const processes = scope.select(await listNativeProcesses(options));
|
|
209
246
|
if (args[0] === "process" && args[1] === "list") {
|
|
210
247
|
return {
|
|
211
248
|
exitCode: 0,
|
|
@@ -213,56 +250,36 @@ export async function runNativeProcessTool(args, optionsOrTimeoutMs = 30_000) {
|
|
|
213
250
|
stderr: "",
|
|
214
251
|
durationMs: duration(startTime),
|
|
215
252
|
timedOut: false,
|
|
253
|
+
processes,
|
|
216
254
|
};
|
|
217
255
|
}
|
|
218
256
|
if (args[0] === "process" && args[1] === "kill") {
|
|
219
257
|
const target = args[2];
|
|
220
258
|
if (!target) {
|
|
221
|
-
return
|
|
222
|
-
exitCode: 1,
|
|
223
|
-
stdout: "",
|
|
224
|
-
stderr: "process kill requires a PID or image name",
|
|
225
|
-
durationMs: duration(startTime),
|
|
226
|
-
timedOut: false,
|
|
227
|
-
};
|
|
259
|
+
return failed("process kill requires a PID or image name");
|
|
228
260
|
}
|
|
229
|
-
const targets =
|
|
261
|
+
const targets = isPid(target)
|
|
262
|
+
? processes.filter((process) => String(process.pid) === target)
|
|
263
|
+
: scope.imageTargets(processes, target);
|
|
230
264
|
if (targets.length === 0) {
|
|
231
|
-
return {
|
|
232
|
-
exitCode: 1,
|
|
233
|
-
stdout: "",
|
|
234
|
-
stderr: `No matching Pharo process found for ${target}`,
|
|
235
|
-
durationMs: duration(startTime),
|
|
236
|
-
timedOut: false,
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
for (const targetProcess of targets) {
|
|
240
|
-
killProcess(targetProcess.pid);
|
|
265
|
+
return failed(`No matching Pharo process found for ${target}`);
|
|
241
266
|
}
|
|
267
|
+
const { killed, failures } = killEach(targets, killProcess);
|
|
242
268
|
return {
|
|
243
|
-
exitCode: 0,
|
|
244
|
-
stdout:
|
|
245
|
-
stderr:
|
|
269
|
+
exitCode: failures.length === 0 ? 0 : 1,
|
|
270
|
+
stdout: killed.map((pid) => `Killed ${pid}`).join("\n"),
|
|
271
|
+
stderr: failures
|
|
272
|
+
.map(({ pid, message }) => `Could not kill pid ${pid}: ${message}`)
|
|
273
|
+
.join("\n"),
|
|
246
274
|
durationMs: duration(startTime),
|
|
247
275
|
timedOut: false,
|
|
276
|
+
processes: targets,
|
|
248
277
|
};
|
|
249
278
|
}
|
|
250
|
-
return {
|
|
251
|
-
exitCode: 1,
|
|
252
|
-
stdout: "",
|
|
253
|
-
stderr: `Unsupported native process tool args: ${args.join(" ")}`,
|
|
254
|
-
durationMs: duration(startTime),
|
|
255
|
-
timedOut: false,
|
|
256
|
-
};
|
|
279
|
+
return failed(`Unsupported native process tool args: ${args.join(" ")}`);
|
|
257
280
|
}
|
|
258
281
|
catch (error) {
|
|
259
|
-
return
|
|
260
|
-
exitCode: 1,
|
|
261
|
-
stdout: "",
|
|
262
|
-
stderr: error instanceof Error ? error.message : String(error),
|
|
263
|
-
durationMs: duration(startTime),
|
|
264
|
-
timedOut: false,
|
|
265
|
-
};
|
|
282
|
+
return failed(error instanceof Error ? error.message : String(error));
|
|
266
283
|
}
|
|
267
284
|
}
|
|
268
285
|
//# sourceMappingURL=processTools.js.map
|
package/dist/processTools.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processTools.js","sourceRoot":"","sources":["../src/processTools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,IAAI,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"processTools.js","sourceRoot":"","sources":["../src/processTools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,IAAI,MAAM,WAAW,CAAC;AAG7B,OAAO,EACL,kBAAkB,EAClB,wBAAwB,EACxB,aAAa,EACb,YAAY,EACZ,gBAAgB,GACjB,MAAM,iBAAiB,C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"}
|
|
@@ -4,5 +4,14 @@ export interface NormalizeLauncherResultOptions {
|
|
|
4
4
|
includeRaw?: boolean;
|
|
5
5
|
diagnosticTailLength?: number;
|
|
6
6
|
}
|
|
7
|
+
/** What a command wrote, trimmed, its middle left out when it is long. */
|
|
8
|
+
export declare function outputTail(source: string, maxLength?: number): string | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* A message put at the end of a sentence: no second period when it ends with
|
|
11
|
+
* one, and after a colon, its lines indented, when it has several.
|
|
12
|
+
*/
|
|
13
|
+
export declare function sentenceWithMessage(sentence: string, message: string): string;
|
|
14
|
+
/** What a Launcher command said when it failed. */
|
|
15
|
+
export declare function launcherMessage(result: LauncherCliResult): string;
|
|
7
16
|
export declare function normalizeLauncherResult(toolName: string, args: readonly string[], result: LauncherCliResult, options?: NormalizeLauncherResultOptions): LauncherCommandResult;
|
|
8
17
|
//# sourceMappingURL=resultNormalizer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resultNormalizer.d.ts","sourceRoot":"","sources":["../src/resultNormalizer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"resultNormalizer.d.ts","sourceRoot":"","sources":["../src/resultNormalizer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,KAAK,EAAE,qBAAqB,EAAwB,MAAM,aAAa,CAAC;AAG/E,MAAM,WAAW,8BAA8B;IAC7C,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAaD,0EAA0E;AAC1E,wBAAgB,UAAU,CACxB,MAAM,EAAE,MAAM,EACd,SAAS,SAA8B,GACtC,MAAM,GAAG,SAAS,CAgBpB;AAeD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAQ7E;AAED,mDAAmD;AACnD,wBAAgB,eAAe,CAAC,MAAM,EAAE,iBAAiB,GAAG,MAAM,CASjE;AAED,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,MAAM,EAAE,iBAAiB,EACzB,OAAO,GAAE,8BAAmC,GAC3C,qBAAqB,CAuDvB"}
|
package/dist/resultNormalizer.js
CHANGED
|
@@ -7,7 +7,8 @@ function trimmedMessage(source) {
|
|
|
7
7
|
const message = source.trim();
|
|
8
8
|
return message ? message : undefined;
|
|
9
9
|
}
|
|
10
|
-
|
|
10
|
+
/** What a command wrote, trimmed, its middle left out when it is long. */
|
|
11
|
+
export function outputTail(source, maxLength = defaultDiagnosticTailLength) {
|
|
11
12
|
const message = trimmedMessage(source);
|
|
12
13
|
if (!message) {
|
|
13
14
|
return undefined;
|
|
@@ -28,94 +29,45 @@ function failedOutputDiagnostic(result, maxLength) {
|
|
|
28
29
|
const stdout = outputTail(result.stdout, maxLength);
|
|
29
30
|
return stdout ? { diagnostic: stdout } : undefined;
|
|
30
31
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
function
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (toolName !== "pharo_launcher_template_list") {
|
|
40
|
-
return undefined;
|
|
41
|
-
}
|
|
42
|
-
const output = `${result.stdout}\n${result.stderr}`;
|
|
43
|
-
if (!/Image template category '.*' not found/i.test(output) ||
|
|
44
|
-
args.includes("--templateCategory")) {
|
|
45
|
-
return undefined;
|
|
46
|
-
}
|
|
47
|
-
return {
|
|
48
|
-
diagnostic: "Pharo Launcher could not list default templates because the active template source inventory is empty or not bootstrapped.",
|
|
49
|
-
action: "Verify PHARO_LAUNCHER_MCP_TEMPLATE_SOURCES_DIR, then refresh or seed the active profile template sources with pharo_launcher_template_update before planning image creation.",
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
function scopedImageLaunchVmStoreDiagnostic(toolName, result) {
|
|
53
|
-
if (toolName !== "pharo_launcher_image_start") {
|
|
54
|
-
return undefined;
|
|
55
|
-
}
|
|
56
|
-
if (result.stderr.includes("Refusing profile-scoped image launch")) {
|
|
57
|
-
return {
|
|
58
|
-
diagnostic: "Profile-scoped image launch was refused because Pharo Launcher can use the default VM store instead of the configured profile VM directory.",
|
|
59
|
-
action: "Launch from an explicit profile only after Pharo Launcher initializes PhLVirtualMachineManager from the CLI configuration, or after pharo-launcher-mcp has a verified launch path that keeps VM artifacts inside PHARO_LAUNCHER_MCP_VMS_DIR.",
|
|
60
|
-
};
|
|
32
|
+
/**
|
|
33
|
+
* A message put at the end of a sentence: no second period when it ends with
|
|
34
|
+
* one, and after a colon, its lines indented, when it has several.
|
|
35
|
+
*/
|
|
36
|
+
export function sentenceWithMessage(sentence, message) {
|
|
37
|
+
const lines = message.trim().split(/\r?\n/);
|
|
38
|
+
if (lines.length > 1) {
|
|
39
|
+
return `${sentence}:\n${lines.map((line) => (line ? ` ${line}` : "")).join("\n")}`;
|
|
61
40
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
return {
|
|
66
|
-
diagnostic: "Profile-scoped image launch could not prepare the profile-local image and VM paths needed for direct launch.",
|
|
67
|
-
action: "Inspect pharo_launcher_image_info, PHARO_LAUNCHER_MCP_IMAGES_DIR and PHARO_LAUNCHER_MCP_VMS_DIR before retrying the launch.",
|
|
68
|
-
};
|
|
41
|
+
const line = lines[0] ?? "";
|
|
42
|
+
return `${sentence}: ${line}${line.endsWith(".") ? "" : "."}`;
|
|
69
43
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
const item = value[0];
|
|
79
|
-
if (typeof item !== "object" || item === null || hasImageName(item)) {
|
|
80
|
-
return value;
|
|
81
|
-
}
|
|
82
|
-
return [{ ...item, name: imageName }];
|
|
83
|
-
}
|
|
84
|
-
if (typeof value === "object" && value !== null && !hasImageName(value)) {
|
|
85
|
-
return { ...value, name: imageName };
|
|
86
|
-
}
|
|
87
|
-
return value;
|
|
88
|
-
}
|
|
89
|
-
function commandContextData(toolName, args, data) {
|
|
90
|
-
switch (toolName) {
|
|
91
|
-
case "pharo_launcher_image_list":
|
|
92
|
-
return withImageName(data, optionValue(args, "--nameFilter"));
|
|
93
|
-
case "pharo_launcher_image_info":
|
|
94
|
-
return withImageName(data, args.at(-1));
|
|
95
|
-
default:
|
|
96
|
-
return data;
|
|
97
|
-
}
|
|
44
|
+
/** What a Launcher command said when it failed. */
|
|
45
|
+
export function launcherMessage(result) {
|
|
46
|
+
return (outputTail(result.stderr) ??
|
|
47
|
+
outputTail(result.stdout) ??
|
|
48
|
+
result.timeoutReason ??
|
|
49
|
+
(result.signal
|
|
50
|
+
? `it was killed by signal ${result.signal}`
|
|
51
|
+
: `it exited with ${result.exitCode ?? "no exit code"}`));
|
|
98
52
|
}
|
|
99
53
|
export function normalizeLauncherResult(toolName, args, result, options = {}) {
|
|
100
54
|
const ok = result.exitCode === 0 && !result.timedOut;
|
|
101
55
|
const format = outputFormat(args);
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
56
|
+
// A native process list hands over its records: nothing to parse back.
|
|
57
|
+
const parseResult = !ok
|
|
58
|
+
? { status: "skipped", format, message: "Command failed" }
|
|
59
|
+
: toolName === "pharo_launcher_process_list" && result.processes
|
|
60
|
+
? { status: "parsed", format, data: result.processes }
|
|
61
|
+
: parseLauncherOutput(toolName, format, result.stdout);
|
|
62
|
+
const data = parseResult.status === "parsed"
|
|
106
63
|
? parseResult.data
|
|
107
64
|
: ok && parseResult.status === "unsupported"
|
|
108
65
|
? { message: trimmedMessage(result.stdout) }
|
|
109
66
|
: undefined;
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const commandDiagnostic = diagnostic ??
|
|
115
|
-
scopedImageLaunchVmStoreDiagnostic(toolName, result) ??
|
|
116
|
-
(!ok
|
|
117
|
-
? failedOutputDiagnostic(result, options.diagnosticTailLength ?? defaultDiagnosticTailLength)
|
|
118
|
-
: undefined);
|
|
67
|
+
// A command's own output is its diagnostic: nothing here rewrites it.
|
|
68
|
+
const commandDiagnostic = !ok
|
|
69
|
+
? failedOutputDiagnostic(result, options.diagnosticTailLength ?? defaultDiagnosticTailLength)
|
|
70
|
+
: undefined;
|
|
119
71
|
const raw = {
|
|
120
72
|
stdout: result.stdout,
|
|
121
73
|
stderr: result.stderr,
|
|
@@ -135,11 +87,16 @@ export function normalizeLauncherResult(toolName, args, result, options = {}) {
|
|
|
135
87
|
args: [...args],
|
|
136
88
|
durationMs: result.durationMs,
|
|
137
89
|
exitCode: result.exitCode,
|
|
90
|
+
...(result.signal ? { signal: result.signal } : {}),
|
|
138
91
|
timedOut: result.timedOut,
|
|
139
92
|
...(result.timeoutReason
|
|
140
93
|
? { timeoutReason: result.timeoutReason }
|
|
141
94
|
: {}),
|
|
142
95
|
},
|
|
96
|
+
...(result.launch ? { launch: result.launch } : {}),
|
|
97
|
+
...(ok && parseResult.defaultCategory
|
|
98
|
+
? { defaultCategory: parseResult.defaultCategory }
|
|
99
|
+
: {}),
|
|
143
100
|
};
|
|
144
101
|
}
|
|
145
102
|
//# sourceMappingURL=resultNormalizer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resultNormalizer.js","sourceRoot":"","sources":["../src/resultNormalizer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"resultNormalizer.js","sourceRoot":"","sources":["../src/resultNormalizer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAoB,MAAM,aAAa,CAAC;AAOpE,MAAM,2BAA2B,GAAG,KAAK,CAAC;AAE1C,SAAS,YAAY,CAA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CAAC,iBAAiB,IAAI,EAAE,CAAC;QAC5B,MAAM,EAAE;YACN,MAAM,EAAE,WAAW,CAAC,MAAM;YAC1B,MAAM,EAAE,WAAW,CAAC,MAAM;YAC1B,GAAG,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,WAAW,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACjE;QACD,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACtC,OAAO,EAAE;YACP,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;YACf,UAAU,EAAE,MAAM,CAAC,UAAU;YAC7B,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACnD,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,GAAG,CAAC,MAAM,CAAC,aAAa;gBACtB,CAAC,CAAC,EAAE,aAAa,EAAE,MAAM,CAAC,aAAa,EAAE;gBACzC,CAAC,CAAC,EAAE,CAAC;SACR;QACD,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACnD,GAAG,CAAC,EAAE,IAAI,WAAW,CAAC,eAAe;YACnC,CAAC,CAAC,EAAE,eAAe,EAAE,WAAW,CAAC,eAAe,EAAE;YAClD,CAAC,CAAC,EAAE,CAAC;KACR,CAAC;AACJ,CAAC"}
|
package/dist/server.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
2
|
-
import { type
|
|
2
|
+
import { type ToolResult } from "./answers.js";
|
|
3
|
+
import { type CallToolOptions } from "./launcher.js";
|
|
3
4
|
/** What the server advertises, for whoever has to stay level with it. */
|
|
4
5
|
export declare const toolNames: readonly string[];
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export declare function callTool(name: string, argumentsValue: unknown, options?:
|
|
6
|
+
/**
|
|
7
|
+
* One tool call, answered in plain text. Each call opens the library on the
|
|
8
|
+
* server's scope, asking for what the Launcher wrote, and gives the function
|
|
9
|
+
* its tool maps to only the arguments that tool takes: an older caller's
|
|
10
|
+
* includeRaw, format, brief, rowMode, delimiter, force, confirm or noLaunch is
|
|
11
|
+
* dropped unread. The library's parser, command and raw never reach a model.
|
|
12
|
+
*/
|
|
13
|
+
export declare function callTool(name: string, argumentsValue: unknown, options?: CallToolOptions): Promise<ToolResult>;
|
|
13
14
|
export declare function createServer(): Server;
|
|
14
15
|
export declare function startStdioServer(): Promise<void>;
|
|
15
16
|
export * from "./launcher.js";
|
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAQnE,OAAO,EAML,KAAK,UAAU,EAChB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAqB,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AA8ExE,yEAAyE;AACzE,eAAO,MAAM,SAAS,EAAE,SAAS,MAAM,EAAmC,CAAC;AAM3E;;;;;;GAMG;AACH,wBAAsB,QAAQ,CAC5B,IAAI,EAAE,MAAM,EACZ,cAAc,EAAE,OAAO,EACvB,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,UAAU,CAAC,CA6BrB;AAED,wBAAgB,YAAY,IAAI,MAAM,CAsBrC;AAED,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAItD;AAED,cAAc,eAAe,CAAC"}
|
package/dist/server.js
CHANGED
|
@@ -2,10 +2,11 @@ import { createRequire } from "node:module";
|
|
|
2
2
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
3
3
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
4
|
import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
5
|
+
import { launcherCommandTools, ProfileTooDeepError, ToolInputError } from "./commandCatalog.js";
|
|
6
|
+
import { loadPharoLauncherConfig } from "./config.js";
|
|
7
|
+
import { failureResult, invalidArgumentsText, toolAnswers, toolArguments, unknownToolText, } from "./answers.js";
|
|
8
|
+
import { resolveImagesDirectory } from "./imageStore.js";
|
|
9
|
+
import { openPharoLauncher } from "./launcher.js";
|
|
9
10
|
// Read the version, do not keep a copy of it. The copy that used to live here
|
|
10
11
|
// said 0.1.1 while the package was 0.1.4, so every client was told the wrong
|
|
11
12
|
// version at initialize.
|
|
@@ -16,17 +17,30 @@ const emptyInputSchema = {
|
|
|
16
17
|
additionalProperties: false,
|
|
17
18
|
};
|
|
18
19
|
const stringSchema = { type: "string", minLength: 1 };
|
|
20
|
+
/** A path of a profile, where stateRoot puts it. */
|
|
21
|
+
function defaultsTo(place) {
|
|
22
|
+
return { ...stringSchema, description: `Defaults to <stateRoot>/${place}.` };
|
|
23
|
+
}
|
|
24
|
+
// Undescribed, every path reads as one to fill in, and a model guesses each.
|
|
19
25
|
const scopedProfileSchema = {
|
|
20
26
|
type: "object",
|
|
27
|
+
description: "A launcher profile, given by its stateRoot. Every other path defaults to its place " +
|
|
28
|
+
"inside stateRoot: give one only when the profile keeps it elsewhere.",
|
|
21
29
|
properties: {
|
|
22
|
-
stateRoot:
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
stateRoot: {
|
|
31
|
+
...stringSchema,
|
|
32
|
+
description: "Absolute path of the directory that holds the profile's images/ directory.",
|
|
33
|
+
},
|
|
34
|
+
launcherConfiguration: defaultsTo("launcher/pharo-launcher-cli-config.ston"),
|
|
35
|
+
imagesDir: defaultsTo("images"),
|
|
36
|
+
vmsDir: defaultsTo("vms"),
|
|
37
|
+
templateSourcesDir: defaultsTo("templates"),
|
|
38
|
+
initScriptsDir: defaultsTo("init-scripts"),
|
|
39
|
+
logsDir: defaultsTo("logs"),
|
|
40
|
+
profileName: {
|
|
41
|
+
...stringSchema,
|
|
42
|
+
description: "A label for the profile; the copy does not use it.",
|
|
43
|
+
},
|
|
30
44
|
},
|
|
31
45
|
additionalProperties: false,
|
|
32
46
|
};
|
|
@@ -49,67 +63,54 @@ const copyBetweenProfilesInputSchema = {
|
|
|
49
63
|
const tools = [
|
|
50
64
|
{
|
|
51
65
|
name: "pharo_launcher_config",
|
|
52
|
-
description: "
|
|
66
|
+
description: "Say which Pharo Launcher this server runs, and where its images are.",
|
|
53
67
|
inputSchema: emptyInputSchema,
|
|
54
68
|
},
|
|
55
69
|
{
|
|
56
70
|
name: "pharo_launcher_image_copy_between_profiles",
|
|
57
|
-
description: "Copy a launcher image from one
|
|
71
|
+
description: "Copy a launcher image from one launcher profile to another. A profile is given by its " +
|
|
72
|
+
"stateRoot, the directory that holds its images/ directory; pharo_launcher_config prints " +
|
|
73
|
+
"this server's own stateRoot. Every profile path must exist: the copy creates none.",
|
|
58
74
|
inputSchema: copyBetweenProfilesInputSchema,
|
|
59
75
|
},
|
|
60
76
|
...launcherCommandTools,
|
|
61
77
|
];
|
|
62
78
|
/** What the server advertises, for whoever has to stay level with it. */
|
|
63
79
|
export const toolNames = tools.map((tool) => tool.name);
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
80
|
+
const toolByName = new Map(tools.map((tool) => [tool.name, tool]));
|
|
81
|
+
/**
|
|
82
|
+
* One tool call, answered in plain text. Each call opens the library on the
|
|
83
|
+
* server's scope, asking for what the Launcher wrote, and gives the function
|
|
84
|
+
* its tool maps to only the arguments that tool takes: an older caller's
|
|
85
|
+
* includeRaw, format, brief, rowMode, delimiter, force, confirm or noLaunch is
|
|
86
|
+
* dropped unread. The library's parser, command and raw never reach a model.
|
|
87
|
+
*/
|
|
88
|
+
export async function callTool(name, argumentsValue, options = {}) {
|
|
89
|
+
const tool = toolByName.get(name);
|
|
90
|
+
const answer = toolAnswers[name];
|
|
91
|
+
if (!tool || !answer) {
|
|
92
|
+
return failureResult(unknownToolText(name));
|
|
93
|
+
}
|
|
74
94
|
try {
|
|
75
|
-
|
|
95
|
+
const config = options.config ?? loadPharoLauncherConfig();
|
|
96
|
+
return await answer({
|
|
97
|
+
launcher: openPharoLauncher({ ...options, config, includeRaw: true }),
|
|
98
|
+
config,
|
|
99
|
+
options: { ...options, config },
|
|
100
|
+
imagesDir: resolveImagesDirectory(config).path,
|
|
101
|
+
}, toolArguments(tool.inputSchema, argumentsValue));
|
|
76
102
|
}
|
|
77
103
|
catch (error) {
|
|
104
|
+
// Its message says what to do, as it is.
|
|
105
|
+
if (error instanceof ProfileTooDeepError) {
|
|
106
|
+
return failureResult(error.message);
|
|
107
|
+
}
|
|
78
108
|
if (error instanceof ToolInputError) {
|
|
79
|
-
return
|
|
109
|
+
return failureResult(invalidArgumentsText(name, tool.inputSchema, error));
|
|
80
110
|
}
|
|
81
111
|
throw error;
|
|
82
112
|
}
|
|
83
113
|
}
|
|
84
|
-
function profileImageCopyResult(argumentsValue) {
|
|
85
|
-
return withToolInputErrorResult(() => {
|
|
86
|
-
const result = copyImageBetweenProfiles(argumentsValue);
|
|
87
|
-
return jsonResult(result, !result.ok);
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
async function commandCatalogToolResult(name, argumentsValue, options) {
|
|
91
|
-
return withToolInputErrorResult(async () => {
|
|
92
|
-
const resultOptions = commandResultOptions(argumentsValue, options);
|
|
93
|
-
const commandArgs = buildLauncherCommandArgs(name, argumentsValue);
|
|
94
|
-
if (commandArgs) {
|
|
95
|
-
const commandResult = await runCommand(name, commandArgs, resultOptions);
|
|
96
|
-
return jsonResult(commandResult, !commandResult.ok);
|
|
97
|
-
}
|
|
98
|
-
return jsonResult({
|
|
99
|
-
error: `Unknown tool: ${name}`,
|
|
100
|
-
}, true);
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
export async function callTool(name, argumentsValue, options = {}) {
|
|
104
|
-
switch (name) {
|
|
105
|
-
case "pharo_launcher_config":
|
|
106
|
-
return jsonResult(getPharoLauncherConfigReport(options.config));
|
|
107
|
-
case "pharo_launcher_image_copy_between_profiles":
|
|
108
|
-
return profileImageCopyResult(argumentsValue);
|
|
109
|
-
default:
|
|
110
|
-
return commandCatalogToolResult(name, argumentsValue, options);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
114
|
export function createServer() {
|
|
114
115
|
const server = new Server({
|
|
115
116
|
name: "pharo-launcher-mcp",
|