@evref-bl/pharo-agent 0.13.0 → 0.13.1
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/.claude-plugin/plugin.json +1 -1
- package/package.json +1 -1
- package/plugin.json +1 -1
- package/skills/pharo-setup/SKILL.md +1 -1
- package/src/help.js +2 -1
- package/src/images.js +15 -3
- package/src/live.js +66 -4
- package/src/mcpServer.js +13 -3
package/package.json
CHANGED
package/plugin.json
CHANGED
|
@@ -8,7 +8,7 @@ Run this only when the user asks to enable or refresh Pharo tooling in this proj
|
|
|
8
8
|
From the project root, run the released CLI that matches this plugin:
|
|
9
9
|
|
|
10
10
|
```sh
|
|
11
|
-
npx --yes @evref-bl/pharo-agent@0.13.
|
|
11
|
+
npx --yes @evref-bl/pharo-agent@0.13.1 init --host claude
|
|
12
12
|
```
|
|
13
13
|
|
|
14
14
|
Name the host this chat runs in: `--host claude` in Claude Code,
|
package/src/help.js
CHANGED
|
@@ -11,7 +11,8 @@ const commands = {
|
|
|
11
11
|
"image list": {
|
|
12
12
|
usage: "image list",
|
|
13
13
|
description: "List the project's declared images and the default one, with the mount and\n"
|
|
14
|
-
+ "projection port of each image this project has running."
|
|
14
|
+
+ "projection port of each image this project has running. An image this project\n"
|
|
15
|
+
+ "started that has since exited is listed as exited.",
|
|
15
16
|
example: "image list",
|
|
16
17
|
},
|
|
17
18
|
"image templates": {
|
package/src/images.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { declareProjectImage, removeProjectImage } from "@evref-bl/plexus";
|
|
2
2
|
import { configuredImages } from "./project.js";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
defaultImageId,
|
|
5
|
+
readConfig,
|
|
6
|
+
readRunningImages,
|
|
7
|
+
recordedImageIsRunning,
|
|
8
|
+
writeConfig,
|
|
9
|
+
} from "./runtime.js";
|
|
4
10
|
|
|
5
11
|
export const defaultLoadScript = "pharo/load-mcp.st";
|
|
6
12
|
|
|
@@ -26,14 +32,20 @@ export function listImages(projectRoot) {
|
|
|
26
32
|
return {
|
|
27
33
|
...(defaultImage ? { defaultImage } : {}),
|
|
28
34
|
images: configured.map((image) => {
|
|
35
|
+
const record = running[image.id];
|
|
36
|
+
// A record says this project started the image, not that it is still
|
|
37
|
+
// there. One that crashed or was closed keeps its record until it is
|
|
38
|
+
// started or stopped again, and its route and mount lead nowhere.
|
|
39
|
+
const alive = record !== undefined && recordedImageIsRunning(record);
|
|
29
40
|
// The record repeats the id it is keyed by; everything else in it is
|
|
30
41
|
// runtime detail this list carries when the image is running.
|
|
31
|
-
const { imageId: _keyed, ...runtime } =
|
|
42
|
+
const { imageId: _keyed, ...runtime } = alive ? record : {};
|
|
32
43
|
return {
|
|
33
44
|
id: image.id,
|
|
34
45
|
imageName: image.imageName,
|
|
35
46
|
isDefault: image.id === defaultImage,
|
|
36
|
-
running:
|
|
47
|
+
running: alive,
|
|
48
|
+
...(record !== undefined && !alive ? { exited: true } : {}),
|
|
37
49
|
...runtime,
|
|
38
50
|
templateName: image.create?.templateName,
|
|
39
51
|
templateCategory: image.create?.templateCategory,
|
package/src/live.js
CHANGED
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
writeRunningImages,
|
|
23
23
|
} from "./runtime.js";
|
|
24
24
|
|
|
25
|
-
export const pifsRelease = "v0.
|
|
25
|
+
export const pifsRelease = "v0.10.0";
|
|
26
26
|
|
|
27
27
|
// fuse-t ships as a macOS installer package, so it lands in /usr/local
|
|
28
28
|
// whatever Homebrew's prefix is. The unversioned symlink is what the daemon
|
|
@@ -86,6 +86,58 @@ export function pifsStopCode(projectionPort) {
|
|
|
86
86
|
return `(Smalltalk globals at: #PIFSServer) stopOn: ${projectionPort}`;
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
+
// `mount` prints one "<source> on <path> (<options>)" line per mount, with the
|
|
90
|
+
// path resolved, so a project under a symlink is looked for by its real path.
|
|
91
|
+
export function isMountedAt(mountPath, mountTable) {
|
|
92
|
+
let realPath = mountPath;
|
|
93
|
+
try {
|
|
94
|
+
realPath = path.join(fs.realpathSync(path.dirname(mountPath)), path.basename(mountPath));
|
|
95
|
+
} catch {
|
|
96
|
+
// No parent directory, so nothing can be mounted there either.
|
|
97
|
+
}
|
|
98
|
+
return mountTable
|
|
99
|
+
.split("\n")
|
|
100
|
+
.some((line) => line.includes(` on ${mountPath} (`) || line.includes(` on ${realPath} (`));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function currentMountTable() {
|
|
104
|
+
return spawnSync("mount", [], { encoding: "utf8" }).stdout ?? "";
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function unmount(mountPath) {
|
|
108
|
+
// What PIFSServer>>stopDaemon runs when it stops a projection itself.
|
|
109
|
+
if (spawnSync("umount", [mountPath], { stdio: "ignore" }).status !== 0) {
|
|
110
|
+
spawnSync("diskutil", ["unmount", mountPath], { stdio: "ignore" });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Unmount a projection whose image is gone.
|
|
116
|
+
*
|
|
117
|
+
* The mount is served by a PIFS daemon, a process of its own that reads the
|
|
118
|
+
* source over HTTP from the image. PIFS unmounts it from inside the image when
|
|
119
|
+
* it stops, which an image that crashed or was closed never does: the mount
|
|
120
|
+
* stays, every read in it fails with an I/O error, and it holds the path
|
|
121
|
+
* against the next projection. Unmounting is enough; the daemon exits with its
|
|
122
|
+
* mount.
|
|
123
|
+
*
|
|
124
|
+
* @param {string | undefined} mountPath
|
|
125
|
+
* @param {{ mountTable?: () => string, unmount?: (path: string) => void }} [host]
|
|
126
|
+
* @returns {boolean} whether something was unmounted
|
|
127
|
+
*/
|
|
128
|
+
export function releaseProjectionMount(mountPath, host = {}) {
|
|
129
|
+
const mountTable = host.mountTable ?? currentMountTable;
|
|
130
|
+
if (mountPath === undefined || !isMountedAt(mountPath, mountTable())) return false;
|
|
131
|
+
(host.unmount ?? unmount)(mountPath);
|
|
132
|
+
if (isMountedAt(mountPath, mountTable())) {
|
|
133
|
+
throw new Error(
|
|
134
|
+
`The source projection of an image that is gone is still mounted at ${mountPath},`
|
|
135
|
+
+ ` and could not be unmounted. Run umount ${JSON.stringify(mountPath)}, then try again.`,
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
|
|
89
141
|
function namedPrintString(value) {
|
|
90
142
|
// Structured results name the print string, somewhere under the envelope,
|
|
91
143
|
// and reach us either as an object or as JSON inside a text part.
|
|
@@ -208,6 +260,11 @@ export async function startAgentImage(projectRoot, imageId) {
|
|
|
208
260
|
restarted = true;
|
|
209
261
|
}
|
|
210
262
|
if (projectionAvailability().available) {
|
|
263
|
+
// This project has no live image at this mount path now: none was
|
|
264
|
+
// recorded, or the one recorded has exited. Whatever is still mounted
|
|
265
|
+
// there was left by an image that is gone, and would hold the path
|
|
266
|
+
// against the projection about to be mounted.
|
|
267
|
+
releaseProjectionMount(resolveMountPath(projectRoot, readConfig(projectRoot), resolved));
|
|
211
268
|
fetchPifsRelease(pifsCloneDirectory(projectRoot));
|
|
212
269
|
}
|
|
213
270
|
const launcher = new ScopedPharoLauncher({ projectRoot });
|
|
@@ -319,9 +376,14 @@ async function stopOneImage(projectRoot, runningImages, imageId) {
|
|
|
319
376
|
// ask over either.
|
|
320
377
|
if (record.projectionPort !== undefined) {
|
|
321
378
|
try {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
379
|
+
if (recordedImageIsRunning(record)) {
|
|
380
|
+
await callImageTool(projectRoot, record, "image_evaluate", {
|
|
381
|
+
code: pifsStopCode(record.projectionPort),
|
|
382
|
+
});
|
|
383
|
+
} else {
|
|
384
|
+
// PIFS stops a projection from inside its image, and this one is gone.
|
|
385
|
+
releaseProjectionMount(record.mountPath);
|
|
386
|
+
}
|
|
325
387
|
} catch (error) {
|
|
326
388
|
projectionError = error;
|
|
327
389
|
}
|
package/src/mcpServer.js
CHANGED
|
@@ -98,7 +98,8 @@ const projectTools = [
|
|
|
98
98
|
name: "image_list",
|
|
99
99
|
description:
|
|
100
100
|
"List this project's declared images, which are running, and the route "
|
|
101
|
-
+ "and mount of each running one."
|
|
101
|
+
+ "and mount of each running one. An image that was started and has "
|
|
102
|
+
+ "exited since is listed as exited; image_start starts it again.",
|
|
102
103
|
inputSchema: { type: "object", properties: {} },
|
|
103
104
|
},
|
|
104
105
|
{
|
|
@@ -133,8 +134,17 @@ async function runningImageTools(projectRoot, defaultImage) {
|
|
|
133
134
|
// contributes no tools yet and the lifecycle tools say how to change that.
|
|
134
135
|
return [];
|
|
135
136
|
}
|
|
136
|
-
|
|
137
|
-
|
|
137
|
+
try {
|
|
138
|
+
return (await listImageTools(projectRoot, running))
|
|
139
|
+
.map((tool) => withImageSelector(tool, running.imageId));
|
|
140
|
+
} catch (error) {
|
|
141
|
+
// A record says this project started the image, not that it still
|
|
142
|
+
// answers: it may have exited, or hung. Failing the whole list would take
|
|
143
|
+
// image_start with it, and with it the one way back. image_list says
|
|
144
|
+
// which image is gone; stderr reaches the host's log.
|
|
145
|
+
console.error(`pharo-agent: image ${running.imageId} listed no tools: ${error.message}`);
|
|
146
|
+
return [];
|
|
147
|
+
}
|
|
138
148
|
}
|
|
139
149
|
|
|
140
150
|
// A schema is a description, not a guard: nothing between the model and here
|