@evref-bl/pharo-agent 0.12.2 → 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/init.js +6 -3
- package/src/live.js +66 -4
- package/src/mcpServer.js +85 -13
- package/src/runtime.js +8 -1
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.
|
|
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/init.js
CHANGED
|
@@ -120,7 +120,9 @@ outside generated/copied files and outside the host guide's managed block.
|
|
|
120
120
|
Refreshing project files does not install a newer package or upgrade image tools.
|
|
121
121
|
|
|
122
122
|
\`plexus.json\` declares this project's images. A freshly initialized
|
|
123
|
-
project declares none; register one before the first
|
|
123
|
+
project declares none; register one before the first image start. With the
|
|
124
|
+
pharo-agent plugin enabled, that is \`image_templates\` and then \`image_add\`,
|
|
125
|
+
with no shell. Otherwise:
|
|
124
126
|
|
|
125
127
|
\`\`\`sh
|
|
126
128
|
pharo-agent image templates
|
|
@@ -142,8 +144,9 @@ installed the image's source is also projected under \`.pharo-agent/mounts\`
|
|
|
142
144
|
and can be edited as files; everywhere else the Pharo tools are the way in,
|
|
143
145
|
and \`image start\` says so.
|
|
144
146
|
|
|
145
|
-
With the pharo-agent plugin enabled for this project,
|
|
146
|
-
|
|
147
|
+
With the pharo-agent plugin enabled for this project, this is all MCP tools:
|
|
148
|
+
declare an image with \`image_add\`, start it with \`image_start\`, and call the
|
|
149
|
+
image's own tools by name. Without it,
|
|
147
150
|
call a tool with \`pharo-agent pharo <tool> [arguments-json]\`, and
|
|
148
151
|
\`pharo-agent mcp\` serves the same surface as a command-scoped stdio MCP
|
|
149
152
|
server.
|
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
|
@@ -11,8 +11,8 @@ import {
|
|
|
11
11
|
version,
|
|
12
12
|
withImageSelector,
|
|
13
13
|
} from "./gateway.js";
|
|
14
|
-
import { listImages } from "./images.js";
|
|
15
|
-
import { startAgentImage, stopAgentImage } from "./live.js";
|
|
14
|
+
import { addImage, listImages } from "./images.js";
|
|
15
|
+
import { listImageTemplates, startAgentImage, stopAgentImage } from "./live.js";
|
|
16
16
|
import { readRunningImage } from "./runtime.js";
|
|
17
17
|
|
|
18
18
|
// The host loads only tool names and these instructions at session start and
|
|
@@ -26,15 +26,57 @@ and projecting image source as files on disk.
|
|
|
26
26
|
Search these tools whenever the task involves Pharo, Smalltalk, a Tonel
|
|
27
27
|
package, or a .st file. Start an image with image_start before calling the
|
|
28
28
|
image's own tools, which are listed once an image answers; image_list says
|
|
29
|
-
what is already running.
|
|
29
|
+
what is already running. A project that declares no image yet needs
|
|
30
|
+
image_templates and image_add first.
|
|
30
31
|
|
|
31
32
|
The image advertises the common tools rather than all of it. Use tool_search
|
|
32
33
|
and tool_get to find the rest, then call one by name like any other.`;
|
|
33
34
|
|
|
34
|
-
//
|
|
35
|
-
//
|
|
36
|
-
// an
|
|
37
|
-
|
|
35
|
+
// This server's own tools, in the order a project meets them: declare an
|
|
36
|
+
// image, start it, and the image's tools join the list. Listed whether or not
|
|
37
|
+
// an image is running, so the list is never empty — a host that caches tools
|
|
38
|
+
// and ignores tools/list_changed would otherwise hold an empty list for the
|
|
39
|
+
// whole session and never learn that one had started.
|
|
40
|
+
const projectTools = [
|
|
41
|
+
{
|
|
42
|
+
name: "image_templates",
|
|
43
|
+
description:
|
|
44
|
+
"List the images Pharo Launcher can create, with the category of each. "
|
|
45
|
+
+ "A template name that two categories offer is flagged, and needs its "
|
|
46
|
+
+ "category when it is declared.",
|
|
47
|
+
inputSchema: { type: "object", properties: {} },
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: "image_add",
|
|
51
|
+
description:
|
|
52
|
+
"Declare an image in this project, from a template image_templates "
|
|
53
|
+
+ "names. Declaring does not create the image: the first image_start "
|
|
54
|
+
+ "does, from this template. The first image declared becomes the "
|
|
55
|
+
+ "project's default.",
|
|
56
|
+
inputSchema: {
|
|
57
|
+
type: "object",
|
|
58
|
+
properties: {
|
|
59
|
+
id: {
|
|
60
|
+
type: "string",
|
|
61
|
+
description: "Short id this project calls the image by, such as dev.",
|
|
62
|
+
},
|
|
63
|
+
template: {
|
|
64
|
+
type: "string",
|
|
65
|
+
description: "Template name, exactly as image_templates gives it.",
|
|
66
|
+
},
|
|
67
|
+
category: {
|
|
68
|
+
type: "string",
|
|
69
|
+
description:
|
|
70
|
+
"Template category. Needed only for a name two categories offer.",
|
|
71
|
+
},
|
|
72
|
+
profile: {
|
|
73
|
+
type: "string",
|
|
74
|
+
description: "Pharo Launcher profile to create the image under.",
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
required: ["id", "template"],
|
|
78
|
+
},
|
|
79
|
+
},
|
|
38
80
|
{
|
|
39
81
|
name: "image_start",
|
|
40
82
|
description:
|
|
@@ -56,7 +98,8 @@ const lifecycleTools = [
|
|
|
56
98
|
name: "image_list",
|
|
57
99
|
description:
|
|
58
100
|
"List this project's declared images, which are running, and the route "
|
|
59
|
-
+ "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.",
|
|
60
103
|
inputSchema: { type: "object", properties: {} },
|
|
61
104
|
},
|
|
62
105
|
{
|
|
@@ -91,8 +134,31 @@ async function runningImageTools(projectRoot, defaultImage) {
|
|
|
91
134
|
// contributes no tools yet and the lifecycle tools say how to change that.
|
|
92
135
|
return [];
|
|
93
136
|
}
|
|
94
|
-
|
|
95
|
-
|
|
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
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// A schema is a description, not a guard: nothing between the model and here
|
|
151
|
+
// enforces it, and a declaration missing its template would otherwise fail
|
|
152
|
+
// somewhere further in, naming a field the caller never saw.
|
|
153
|
+
function declarationFrom(argumentsValue) {
|
|
154
|
+
const { id, template, category, profile } = argumentsValue;
|
|
155
|
+
if (typeof id !== "string" || id === "") {
|
|
156
|
+
throw new Error("image_add needs the id this project will call the image by.");
|
|
157
|
+
}
|
|
158
|
+
if (typeof template !== "string" || template === "") {
|
|
159
|
+
throw new Error("image_add needs a template name, as image_templates gives it.");
|
|
160
|
+
}
|
|
161
|
+
return { id, template, category, profile };
|
|
96
162
|
}
|
|
97
163
|
|
|
98
164
|
export async function serveImagesMcp(resolveProjectRoot, defaultImage) {
|
|
@@ -108,10 +174,10 @@ export async function serveImagesMcp(resolveProjectRoot, defaultImage) {
|
|
|
108
174
|
} catch {
|
|
109
175
|
// No project here. The lifecycle tools are still listed rather than
|
|
110
176
|
// nothing, so the host has a server that works and a call can say why.
|
|
111
|
-
return { tools:
|
|
177
|
+
return { tools: projectTools };
|
|
112
178
|
}
|
|
113
179
|
return {
|
|
114
|
-
tools: [...
|
|
180
|
+
tools: [...projectTools, ...(await runningImageTools(projectRoot, defaultImage))],
|
|
115
181
|
};
|
|
116
182
|
});
|
|
117
183
|
|
|
@@ -121,9 +187,15 @@ export async function serveImagesMcp(resolveProjectRoot, defaultImage) {
|
|
|
121
187
|
// Throws when there is no project, which is the answer the caller needs.
|
|
122
188
|
const projectRoot = resolveProjectRoot();
|
|
123
189
|
|
|
124
|
-
// Matched before the image's catalogue: these
|
|
190
|
+
// Matched before the image's catalogue: these names belong to this
|
|
125
191
|
// server, and an image that happened to hold one must not decide what
|
|
126
192
|
// starting an image means.
|
|
193
|
+
if (request.params.name === "image_templates") {
|
|
194
|
+
return toolResult({ ok: true, ...(await listImageTemplates(projectRoot)) });
|
|
195
|
+
}
|
|
196
|
+
if (request.params.name === "image_add") {
|
|
197
|
+
return toolResult({ ok: true, ...addImage(projectRoot, declarationFrom(argumentsValue)) });
|
|
198
|
+
}
|
|
127
199
|
if (request.params.name === "image_start") {
|
|
128
200
|
const started = await startAgentImage(projectRoot, selected);
|
|
129
201
|
await server.sendToolListChanged();
|
package/src/runtime.js
CHANGED
|
@@ -23,11 +23,18 @@ export function configPath(projectRoot) {
|
|
|
23
23
|
return path.join(pluginDirectory(projectRoot), "config.json");
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
// A project can hold a plexus.json this plugin never initialized, and now that
|
|
27
|
+
// an image can be declared from a chat it is reached before `.pharo-agent`
|
|
28
|
+
// exists. An absent settings file is a project with no settings, not an error
|
|
29
|
+
// about a path the caller never named.
|
|
26
30
|
export function readConfig(projectRoot) {
|
|
27
|
-
|
|
31
|
+
const filePath = configPath(projectRoot);
|
|
32
|
+
if (!fs.existsSync(filePath)) return {};
|
|
33
|
+
return readJson(filePath);
|
|
28
34
|
}
|
|
29
35
|
|
|
30
36
|
export function writeConfig(projectRoot, config) {
|
|
37
|
+
fs.mkdirSync(pluginDirectory(projectRoot), { recursive: true });
|
|
31
38
|
fs.writeFileSync(configPath(projectRoot), `${JSON.stringify(config, null, 2)}\n`);
|
|
32
39
|
}
|
|
33
40
|
|