@evref-bl/pharo-agent 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/plugins/marketplace.json +17 -0
- package/.claude-plugin/marketplace.json +12 -0
- package/.claude-plugin/plugin.json +14 -0
- package/LICENSE +7 -0
- package/README.md +45 -2
- package/bin/pharo-agent.js +7 -0
- package/package.json +37 -4
- package/plugin.json +20 -0
- package/skills/pharo-setup/SKILL.md +19 -0
- package/src/cli.js +112 -0
- package/src/gateway.js +53 -0
- package/src/init.js +138 -0
- package/src/live.js +88 -0
- package/src/project.js +39 -0
- package/src/runtime.js +67 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "evref-bl",
|
|
3
|
+
"interface": {
|
|
4
|
+
"displayName": "Evref-BL"
|
|
5
|
+
},
|
|
6
|
+
"plugins": [
|
|
7
|
+
{
|
|
8
|
+
"name": "pharo-agent",
|
|
9
|
+
"source": "./",
|
|
10
|
+
"policy": {
|
|
11
|
+
"installation": "AVAILABLE",
|
|
12
|
+
"authentication": "ON_INSTALL"
|
|
13
|
+
},
|
|
14
|
+
"category": "Developer Tools"
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "pharo-agent",
|
|
3
|
+
"displayName": "Pharo Agent",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"description": "Terminal-first Pharo image setup for coding agents.",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "Evref-BL",
|
|
8
|
+
"url": "https://github.com/Evref-BL"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/Evref-BL/pharo-agent-plugin",
|
|
11
|
+
"repository": "https://github.com/Evref-BL/pharo-agent-plugin",
|
|
12
|
+
"license": "Apache-2.0",
|
|
13
|
+
"keywords": ["pharo", "smalltalk", "mcp"]
|
|
14
|
+
}
|
package/LICENSE
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,46 @@
|
|
|
1
|
-
#
|
|
1
|
+
# pharo-agent
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`pharo-agent` is a terminal-first Pharo integration for Codex, Claude Code, and
|
|
4
|
+
OpenCode. It has one small setup skill; a project receives the full Pharo
|
|
5
|
+
guidance only after setup.
|
|
6
|
+
|
|
7
|
+
The project must already contain a `plexus.project.json` that declares one
|
|
8
|
+
agent-facing image. Initialize it for one selected agent host:
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
npx --yes @evref-bl/pharo-agent init --host codex
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
It writes a small conditional instruction block, `pharo.AGENTS.md`, and copies
|
|
15
|
+
on-demand Pharo workflow skills and references from the pinned MCP template
|
|
16
|
+
package. It does not install an agent-host MCP server.
|
|
17
|
+
|
|
18
|
+
`open` starts the project image through PLexus, loads PIFS, and mounts its
|
|
19
|
+
projection below `.pharo-agent/mounts`. `close` unmounts the projection and
|
|
20
|
+
closes the PLexus image. `pharo` calls any exposed MCP tool through the same
|
|
21
|
+
project route, while `mcp` exposes that tool surface as a command-scoped stdio
|
|
22
|
+
MCP server.
|
|
23
|
+
|
|
24
|
+
Pass `--mount-root <path>` to `init` to use a different projection root.
|
|
25
|
+
|
|
26
|
+
## Requirements
|
|
27
|
+
|
|
28
|
+
PIFS currently supports the macOS workflow and needs
|
|
29
|
+
[fuse-t](https://www.fuse-t.org/). Its matching daemon is downloaded by PIFS;
|
|
30
|
+
Go is not required at runtime.
|
|
31
|
+
|
|
32
|
+
The CLI pins released MCP and PLexus dependencies. PLexus, in turn, pins the
|
|
33
|
+
MCP release used to prepare the image; PIFS is loaded at its own exact release
|
|
34
|
+
from the image.
|
|
35
|
+
|
|
36
|
+
## Host setup
|
|
37
|
+
|
|
38
|
+
Codex and Claude Code can install the repository as a plugin. Its only global
|
|
39
|
+
skill initializes the current project; it does not add an MCP server or the
|
|
40
|
+
Pharo workflow catalogue to every chat. OpenCode uses the same CLI command
|
|
41
|
+
with `--host opencode`.
|
|
42
|
+
|
|
43
|
+
After initialization, the selected host guide says to read
|
|
44
|
+
`pharo.AGENTS.md` only for Pharo work. That guide points to local workflow
|
|
45
|
+
skills and references on demand. In the chat that runs setup, read that file
|
|
46
|
+
before beginning Pharo work; later chats load the conditional guidance normally.
|
package/package.json
CHANGED
|
@@ -1,6 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@evref-bl/pharo-agent",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "Terminal-first Pharo integration for coding agents.",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/Evref-BL/pharo-agent-plugin.git"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"bin": {
|
|
13
|
+
"pharo-agent": "bin/pharo-agent.js"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"bin",
|
|
17
|
+
"src",
|
|
18
|
+
"skills",
|
|
19
|
+
"plugin.json",
|
|
20
|
+
".agents",
|
|
21
|
+
".claude-plugin",
|
|
22
|
+
"README.md",
|
|
23
|
+
"LICENSE"
|
|
24
|
+
],
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=22.12.0"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"check": "node --check bin/pharo-agent.js && node --check src/*.js",
|
|
30
|
+
"package:check": "npm pack --dry-run",
|
|
31
|
+
"test": "node --test"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@evref-bl/pharo-mcp": "1.4.1",
|
|
35
|
+
"@evref-bl/plexus": "0.2.1",
|
|
36
|
+
"@evref-bl/plexus-gateway": "0.2.1",
|
|
37
|
+
"@modelcontextprotocol/sdk": "1.32.1"
|
|
38
|
+
}
|
|
39
|
+
}
|
package/plugin.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json",
|
|
3
|
+
"name": "pharo-agent",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"description": "Terminal-first Pharo image setup for coding agents.",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "Evref-BL",
|
|
8
|
+
"url": "https://github.com/Evref-BL"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/Evref-BL/pharo-agent-plugin",
|
|
11
|
+
"repository": "https://github.com/Evref-BL/pharo-agent-plugin",
|
|
12
|
+
"license": "Apache-2.0",
|
|
13
|
+
"keywords": ["pharo", "smalltalk", "mcp"],
|
|
14
|
+
"extensions": {
|
|
15
|
+
"com.openai": {
|
|
16
|
+
"requires_local_executor": true,
|
|
17
|
+
"onboardingSkill": "./skills/pharo-setup/SKILL.md"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: pharo-setup
|
|
3
|
+
description: Enable Pharo image tooling in the current PLexus project.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Run this only when the user asks to enable Pharo tooling in this project.
|
|
7
|
+
|
|
8
|
+
From the project root, run the released CLI that matches this plugin:
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
npx --yes @evref-bl/pharo-agent@0.1.0 init --host codex
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Use `--host claude` in Claude Code and `--host opencode` in OpenCode.
|
|
15
|
+
Do not configure an MCP server in the agent host. The command adds only a
|
|
16
|
+
conditional instruction block, so Pharo guidance stays out of unrelated work.
|
|
17
|
+
|
|
18
|
+
After setup, read `pharo.AGENTS.md` in this chat before doing Pharo work. A
|
|
19
|
+
new chat picks up the conditional project guidance automatically.
|
package/src/cli.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { initialize } from "./init.js";
|
|
2
|
+
import { callActiveTool, listActiveTools, serveActiveMcp } from "./gateway.js";
|
|
3
|
+
import { closeAgentImage, openAgentImage } from "./live.js";
|
|
4
|
+
import { findProjectRoot } from "./project.js";
|
|
5
|
+
import { readActive } from "./runtime.js";
|
|
6
|
+
|
|
7
|
+
function parseInit(args) {
|
|
8
|
+
let host;
|
|
9
|
+
let mountRoot;
|
|
10
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
11
|
+
const option = args[index];
|
|
12
|
+
if (option === "--host" || option === "--mount-root") {
|
|
13
|
+
const value = args[index + 1];
|
|
14
|
+
if (!value) {
|
|
15
|
+
throw new Error(`${option} requires a value`);
|
|
16
|
+
}
|
|
17
|
+
if (option === "--host") host = value;
|
|
18
|
+
else mountRoot = value;
|
|
19
|
+
index += 1;
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
throw new Error(`Unknown init option: ${option}`);
|
|
23
|
+
}
|
|
24
|
+
if (!host) throw new Error("init requires --host <codex|claude|opencode>");
|
|
25
|
+
return { host, mountRoot };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function usage() {
|
|
29
|
+
return [
|
|
30
|
+
"Usage:",
|
|
31
|
+
" pharo-agent init --host <codex|claude|opencode> [--mount-root <path>]",
|
|
32
|
+
" pharo-agent open",
|
|
33
|
+
" pharo-agent status",
|
|
34
|
+
" pharo-agent close",
|
|
35
|
+
" pharo-agent mcp",
|
|
36
|
+
" pharo-agent pharo list",
|
|
37
|
+
" pharo-agent pharo <tool> [arguments-json]",
|
|
38
|
+
].join("\n");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function requireNoArguments(command, args) {
|
|
42
|
+
if (args.length > 0) {
|
|
43
|
+
throw new Error(`${command} does not accept arguments`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function parseToolArguments(value) {
|
|
48
|
+
if (value === undefined) return {};
|
|
49
|
+
let parsed;
|
|
50
|
+
try {
|
|
51
|
+
parsed = JSON.parse(value);
|
|
52
|
+
} catch {
|
|
53
|
+
throw new Error("Tool arguments must be a JSON object.");
|
|
54
|
+
}
|
|
55
|
+
if (!parsed || Array.isArray(parsed) || typeof parsed !== "object") {
|
|
56
|
+
throw new Error("Tool arguments must be a JSON object.");
|
|
57
|
+
}
|
|
58
|
+
return parsed;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export async function main(args) {
|
|
62
|
+
const [command, ...rest] = args;
|
|
63
|
+
if (command === "init") {
|
|
64
|
+
const result = initialize(parseInit(rest));
|
|
65
|
+
console.log(JSON.stringify({ ok: true, ...result }, null, 2));
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (!command || command === "--help" || command === "help") {
|
|
69
|
+
console.log(usage());
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const projectRoot = findProjectRoot();
|
|
73
|
+
if (command === "open") {
|
|
74
|
+
requireNoArguments(command, rest);
|
|
75
|
+
console.log(JSON.stringify({ ok: true, ...(await openAgentImage(projectRoot)) }, null, 2));
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (command === "close") {
|
|
79
|
+
requireNoArguments(command, rest);
|
|
80
|
+
console.log(JSON.stringify({ ok: true, ...(await closeAgentImage(projectRoot)) }, null, 2));
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (command === "status") {
|
|
84
|
+
requireNoArguments(command, rest);
|
|
85
|
+
console.log(JSON.stringify({ ok: true, ...readActive(projectRoot) }, null, 2));
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (command === "mcp") {
|
|
89
|
+
requireNoArguments(command, rest);
|
|
90
|
+
await serveActiveMcp(projectRoot, readActive(projectRoot));
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (command === "pharo") {
|
|
94
|
+
const [toolName, argumentsJson, ...extra] = rest;
|
|
95
|
+
if (toolName === "list") {
|
|
96
|
+
if (argumentsJson || extra.length > 0) throw new Error("pharo list does not accept arguments");
|
|
97
|
+
console.log(JSON.stringify(await listActiveTools(projectRoot, readActive(projectRoot)), null, 2));
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (!toolName || extra.length > 0) {
|
|
101
|
+
throw new Error("pharo requires one tool name and an optional JSON object");
|
|
102
|
+
}
|
|
103
|
+
console.log(JSON.stringify(await callActiveTool(
|
|
104
|
+
projectRoot,
|
|
105
|
+
readActive(projectRoot),
|
|
106
|
+
toolName,
|
|
107
|
+
parseToolArguments(argumentsJson),
|
|
108
|
+
), null, 2));
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
throw new Error(`Unsupported command: ${command}\n${usage()}`);
|
|
112
|
+
}
|
package/src/gateway.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { PlexusGateway } from "@evref-bl/plexus-gateway";
|
|
2
|
+
import { createGatewayServerWithOptions } from "@evref-bl/plexus-gateway";
|
|
3
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
+
import { readJson, selectRunningImage } from "./runtime.js";
|
|
5
|
+
|
|
6
|
+
export async function activeGateway(projectRoot, active) {
|
|
7
|
+
const state = readJson(active.statePath);
|
|
8
|
+
const { image, mcpServerId } = selectRunningImage(state, active.imageId);
|
|
9
|
+
if (image.id !== active.imageId || mcpServerId !== active.mcpServerId) {
|
|
10
|
+
throw new Error("The active PLexus image changed; run pharo-agent open again.");
|
|
11
|
+
}
|
|
12
|
+
const gateway = new PlexusGateway({
|
|
13
|
+
pharoScope: {
|
|
14
|
+
projectId: state.projectId,
|
|
15
|
+
workspaceId: state.workspaceId,
|
|
16
|
+
targetId: state.targetId,
|
|
17
|
+
},
|
|
18
|
+
pharoToolSchemaMcpServerId: mcpServerId,
|
|
19
|
+
});
|
|
20
|
+
const registered = await gateway.registerProjectRoute({
|
|
21
|
+
projectRoot,
|
|
22
|
+
statePath: active.statePath,
|
|
23
|
+
state,
|
|
24
|
+
});
|
|
25
|
+
if (!registered.ok) {
|
|
26
|
+
throw new Error(registered.error ?? "Cannot register the PLexus route.");
|
|
27
|
+
}
|
|
28
|
+
return { gateway, mcpServerId };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export async function callActiveTool(projectRoot, active, toolName, argumentsValue) {
|
|
32
|
+
const { gateway, mcpServerId } = await activeGateway(projectRoot, active);
|
|
33
|
+
const result = await gateway.routeToImage({
|
|
34
|
+
mcpServerId,
|
|
35
|
+
toolName,
|
|
36
|
+
arguments: argumentsValue,
|
|
37
|
+
});
|
|
38
|
+
if (!result.ok) {
|
|
39
|
+
throw new Error(result.error ?? `Pharo tool ${toolName} failed.`);
|
|
40
|
+
}
|
|
41
|
+
return result.data;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export async function listActiveTools(projectRoot, active) {
|
|
45
|
+
const { gateway } = await activeGateway(projectRoot, active);
|
|
46
|
+
return gateway.refreshPharoTools();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export async function serveActiveMcp(projectRoot, active) {
|
|
50
|
+
const { gateway, mcpServerId } = await activeGateway(projectRoot, active);
|
|
51
|
+
const server = createGatewayServerWithOptions(gateway, { fixedMcpServerId: mcpServerId });
|
|
52
|
+
await server.connect(new StdioServerTransport());
|
|
53
|
+
}
|
package/src/init.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { templateDirectory as mcpTemplateDirectory } from "@evref-bl/pharo-mcp";
|
|
4
|
+
import { findProjectRoot, pluginDirectory } from "./project.js";
|
|
5
|
+
|
|
6
|
+
const managedStart = "<!-- pharo-agent:begin -->";
|
|
7
|
+
const managedEnd = "<!-- pharo-agent:end -->";
|
|
8
|
+
|
|
9
|
+
const hostGuide = {
|
|
10
|
+
claude: "CLAUDE.md",
|
|
11
|
+
codex: "AGENTS.md",
|
|
12
|
+
opencode: "AGENTS.md",
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
function copyDirectory(source, target) {
|
|
16
|
+
fs.mkdirSync(target, { recursive: true });
|
|
17
|
+
for (const entry of fs.readdirSync(source, { withFileTypes: true })) {
|
|
18
|
+
const sourcePath = path.join(source, entry.name);
|
|
19
|
+
const targetPath = path.join(target, entry.name);
|
|
20
|
+
if (entry.isDirectory()) {
|
|
21
|
+
copyDirectory(sourcePath, targetPath);
|
|
22
|
+
} else {
|
|
23
|
+
fs.copyFileSync(sourcePath, targetPath);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function assertManagedBlockCanBeUpdated(filePath) {
|
|
29
|
+
const current = fs.existsSync(filePath) ? fs.readFileSync(filePath, "utf8") : "";
|
|
30
|
+
const start = current.indexOf(managedStart);
|
|
31
|
+
const end = current.indexOf(managedEnd);
|
|
32
|
+
if ((start === -1) !== (end === -1) || (end !== -1 && end < start)) {
|
|
33
|
+
throw new Error(`Cannot update incomplete pharo-agent block in ${filePath}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function updateManagedBlock(filePath, content) {
|
|
38
|
+
assertManagedBlockCanBeUpdated(filePath);
|
|
39
|
+
const current = fs.existsSync(filePath) ? fs.readFileSync(filePath, "utf8") : "";
|
|
40
|
+
const start = current.indexOf(managedStart);
|
|
41
|
+
const end = current.indexOf(managedEnd);
|
|
42
|
+
|
|
43
|
+
const block = `${managedStart}\n${content}\n${managedEnd}\n`;
|
|
44
|
+
const updated = start === -1
|
|
45
|
+
? `${current}${current && !current.endsWith("\n") ? "\n" : ""}${block}`
|
|
46
|
+
: `${current.slice(0, start)}${block}${current.slice(end + managedEnd.length).replace(/^\n?/, "")}`;
|
|
47
|
+
fs.writeFileSync(filePath, updated);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function writeIfMissing(filePath, content) {
|
|
51
|
+
if (!fs.existsSync(filePath)) {
|
|
52
|
+
fs.writeFileSync(filePath, content);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function assertGeneratedGuideCanBeUpdated(filePath) {
|
|
57
|
+
if (!fs.existsSync(filePath)) return;
|
|
58
|
+
const content = fs.readFileSync(filePath, "utf8");
|
|
59
|
+
if (
|
|
60
|
+
content.trimEnd() !== pharoGuide().trimEnd()
|
|
61
|
+
&& (!content.includes(managedStart) || !content.includes(managedEnd))
|
|
62
|
+
) {
|
|
63
|
+
throw new Error(`Refusing to replace user-owned ${filePath}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function guidance() {
|
|
68
|
+
return `# Pharo work\n\nWhen the task uses Pharo, read \`pharo.AGENTS.md\` before acting.\n`;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function pharoGuide() {
|
|
72
|
+
return `# Pharo project guide
|
|
73
|
+
|
|
74
|
+
Use \`pharo-agent open\` before live-image work and edit projected source under
|
|
75
|
+
\`.pharo-agent/mounts\`. Use \`pharo-agent pharo list\` to inspect the complete
|
|
76
|
+
live MCP tool surface and \`pharo-agent pharo <tool> [arguments-json]\` to call
|
|
77
|
+
a tool. \`pharo-agent mcp\` exposes the image as a command-scoped stdio MCP
|
|
78
|
+
server.
|
|
79
|
+
|
|
80
|
+
Image, Tonel, Iceberg, disk Git, and host processes are separate states.
|
|
81
|
+
|
|
82
|
+
## Read first
|
|
83
|
+
|
|
84
|
+
- Before Pharo source changes, read the project guidance. If absent, read the
|
|
85
|
+
local [coding rules](.pharo-agent/references/pharo-coding-rules.md) and
|
|
86
|
+
[coding style](.pharo-agent/references/pharo-coding-style.md).
|
|
87
|
+
- Before loading a project, read
|
|
88
|
+
[.pharo-agent/skills/pharo-project-load/SKILL.md](.pharo-agent/skills/pharo-project-load/SKILL.md).
|
|
89
|
+
- Before cross-version work, read
|
|
90
|
+
[.pharo-agent/skills/pharo-version-compat/SKILL.md](.pharo-agent/skills/pharo-version-compat/SKILL.md).
|
|
91
|
+
- Before exporting image changes or changing Git state, read
|
|
92
|
+
[.pharo-agent/skills/pharo-image-git-handoff/SKILL.md](.pharo-agent/skills/pharo-image-git-handoff/SKILL.md).
|
|
93
|
+
- Before reproducing smalltalkCI or GitHub failures, read
|
|
94
|
+
[.pharo-agent/skills/pharo-ci-repro/SKILL.md](.pharo-agent/skills/pharo-ci-repro/SKILL.md).
|
|
95
|
+
- Before recovering a stopped standalone image, read
|
|
96
|
+
[.pharo-agent/skills/pharo-mcp-recovery/SKILL.md](.pharo-agent/skills/pharo-mcp-recovery/SKILL.md).
|
|
97
|
+
- Before debugger sessions or repairs, read the local
|
|
98
|
+
[debugging guide](.pharo-agent/references/debugging.md).
|
|
99
|
+
|
|
100
|
+
## Workflow
|
|
101
|
+
|
|
102
|
+
1. Inspect the tool schema before acting; do not rely on remembered names.
|
|
103
|
+
2. Prefer the least-mutating dedicated tool; use \`image_evaluate\` only when
|
|
104
|
+
no dedicated tool fits.
|
|
105
|
+
3. Verify identity before mutation, make the narrowest change, then run focused
|
|
106
|
+
tests.
|
|
107
|
+
4. Use the image-to-Git handoff skill before export or commit.
|
|
108
|
+
`;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function initialize({ host, mountRoot, cwd = process.cwd() }) {
|
|
112
|
+
const guideName = hostGuide[host];
|
|
113
|
+
if (!guideName) {
|
|
114
|
+
throw new Error("--host must be codex, claude, or opencode");
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const projectRoot = findProjectRoot(cwd);
|
|
118
|
+
const directory = pluginDirectory(projectRoot);
|
|
119
|
+
const configPath = path.join(directory, "config.json");
|
|
120
|
+
const pharoGuidePath = path.join(projectRoot, "pharo.AGENTS.md");
|
|
121
|
+
assertGeneratedGuideCanBeUpdated(pharoGuidePath);
|
|
122
|
+
assertManagedBlockCanBeUpdated(path.join(projectRoot, guideName));
|
|
123
|
+
fs.mkdirSync(directory, { recursive: true });
|
|
124
|
+
if (!fs.existsSync(configPath) || mountRoot !== undefined) {
|
|
125
|
+
fs.writeFileSync(
|
|
126
|
+
configPath,
|
|
127
|
+
`${JSON.stringify({ mountRoot: mountRoot ?? ".pharo-agent/mounts" }, null, 2)}\n`,
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
writeIfMissing(path.join(directory, ".gitignore"), "mounts/\nruntime/\n");
|
|
131
|
+
updateManagedBlock(pharoGuidePath, pharoGuide());
|
|
132
|
+
const templates = mcpTemplateDirectory();
|
|
133
|
+
copyDirectory(path.join(templates, "pharo-references"), path.join(directory, "references"));
|
|
134
|
+
copyDirectory(path.join(templates, "pharo-skills"), path.join(directory, "skills"));
|
|
135
|
+
updateManagedBlock(path.join(projectRoot, guideName), guidance());
|
|
136
|
+
|
|
137
|
+
return { projectRoot, guideName };
|
|
138
|
+
}
|
package/src/live.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { closeProject, openProject } from "@evref-bl/plexus";
|
|
4
|
+
import { callActiveTool } from "./gateway.js";
|
|
5
|
+
import { configuredActiveImageId } from "./project.js";
|
|
6
|
+
import {
|
|
7
|
+
activePath,
|
|
8
|
+
clearActive,
|
|
9
|
+
readActive,
|
|
10
|
+
readConfig,
|
|
11
|
+
resolveMountPath,
|
|
12
|
+
selectRunningImage,
|
|
13
|
+
smalltalkString,
|
|
14
|
+
writeActive,
|
|
15
|
+
} from "./runtime.js";
|
|
16
|
+
|
|
17
|
+
export const pifsRelease = "v0.4.0";
|
|
18
|
+
|
|
19
|
+
export function pifsStartCode(mountPath, imageName) {
|
|
20
|
+
return `Metacello new
|
|
21
|
+
baseline: 'PharoImageFS';
|
|
22
|
+
repository: 'github://Evref-BL/pharo-image-fs:${pifsRelease}/src';
|
|
23
|
+
load: 'Core'.
|
|
24
|
+
(PIFSServer
|
|
25
|
+
startOn: 0
|
|
26
|
+
mountAt: ${smalltalkString(mountPath)} asFileReference
|
|
27
|
+
named: ${smalltalkString(imageName)}) port`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function resultPrintString(result) {
|
|
31
|
+
if (!result || typeof result !== "object") return undefined;
|
|
32
|
+
if (typeof result.resultPrintString === "string") return result.resultPrintString;
|
|
33
|
+
for (const value of Object.values(result)) {
|
|
34
|
+
const found = resultPrintString(value);
|
|
35
|
+
if (found) return found;
|
|
36
|
+
}
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export async function openAgentImage(projectRoot) {
|
|
41
|
+
if (fs.existsSync(activePath(projectRoot))) {
|
|
42
|
+
return { alreadyOpen: true, ...readActive(projectRoot) };
|
|
43
|
+
}
|
|
44
|
+
const configuredImageId = configuredActiveImageId(projectRoot);
|
|
45
|
+
const opened = await openProject({ projectRoot, imageIds: [configuredImageId] });
|
|
46
|
+
if (!opened.ok || opened.failures.length > 0) {
|
|
47
|
+
throw new Error(opened.failures.map((failure) => failure.message).join("\n") || "PLexus could not open the project image.");
|
|
48
|
+
}
|
|
49
|
+
const { image, mcpServerId } = selectRunningImage(opened.state, configuredImageId);
|
|
50
|
+
const mountPath = resolveMountPath(projectRoot, readConfig(projectRoot), image.id);
|
|
51
|
+
fs.mkdirSync(path.dirname(mountPath), { recursive: true });
|
|
52
|
+
const active = {
|
|
53
|
+
statePath: opened.statePath,
|
|
54
|
+
imageId: image.id,
|
|
55
|
+
mcpServerId,
|
|
56
|
+
mountPath,
|
|
57
|
+
};
|
|
58
|
+
const result = await callActiveTool(projectRoot, active, "image_evaluate", {
|
|
59
|
+
code: pifsStartCode(mountPath, image.imageName),
|
|
60
|
+
});
|
|
61
|
+
const port = Number(resultPrintString(result));
|
|
62
|
+
if (!Number.isInteger(port) || port < 1) {
|
|
63
|
+
throw new Error("PIFS started but did not report its projection port.");
|
|
64
|
+
}
|
|
65
|
+
writeActive(projectRoot, { ...active, projectionPort: port });
|
|
66
|
+
return { imageId: image.id, mountPath, projectionPort: port };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export async function closeAgentImage(projectRoot) {
|
|
70
|
+
const active = readActive(projectRoot);
|
|
71
|
+
let projectionError;
|
|
72
|
+
try {
|
|
73
|
+
await callActiveTool(projectRoot, active, "image_evaluate", {
|
|
74
|
+
code: `PIFSServer stopOn: ${active.projectionPort}`,
|
|
75
|
+
});
|
|
76
|
+
} catch (error) {
|
|
77
|
+
projectionError = error;
|
|
78
|
+
}
|
|
79
|
+
const closed = await closeProject({ projectRoot, imageIds: [active.imageId] });
|
|
80
|
+
if (!closed.ok || closed.failures.length > 0) {
|
|
81
|
+
throw new Error(closed.failures.map((failure) => failure.message).join("\n") || "PLexus could not close the project image.");
|
|
82
|
+
}
|
|
83
|
+
clearActive(projectRoot);
|
|
84
|
+
if (projectionError) {
|
|
85
|
+
throw new Error(`Image closed, but PIFS cleanup failed: ${projectionError.message}`);
|
|
86
|
+
}
|
|
87
|
+
return { stoppedImages: closed.stoppedImages.map((image) => image.id) };
|
|
88
|
+
}
|
package/src/project.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
export function findProjectRoot(start = process.cwd()) {
|
|
5
|
+
let directory = path.resolve(start);
|
|
6
|
+
|
|
7
|
+
while (true) {
|
|
8
|
+
if (fs.existsSync(path.join(directory, "plexus.project.json"))) {
|
|
9
|
+
return directory;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const parent = path.dirname(directory);
|
|
13
|
+
if (parent === directory) {
|
|
14
|
+
throw new Error("No plexus.project.json found above the current directory");
|
|
15
|
+
}
|
|
16
|
+
directory = parent;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function pluginDirectory(projectRoot) {
|
|
21
|
+
return path.join(projectRoot, ".pharo-agent");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function configuredActiveImageId(projectRoot) {
|
|
25
|
+
const configPath = path.join(projectRoot, "plexus.project.json");
|
|
26
|
+
let config;
|
|
27
|
+
try {
|
|
28
|
+
config = JSON.parse(fs.readFileSync(configPath, "utf8"));
|
|
29
|
+
} catch (error) {
|
|
30
|
+
throw new Error(`Cannot read ${configPath}: ${error.message}`);
|
|
31
|
+
}
|
|
32
|
+
const images = Array.isArray(config.images) ? config.images.filter((image) => image?.active) : [];
|
|
33
|
+
if (images.length !== 1 || typeof images[0].id !== "string") {
|
|
34
|
+
throw new Error(
|
|
35
|
+
`pharo-agent needs exactly one active image in plexus.project.json; found ${images.length}.`,
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
return images[0].id;
|
|
39
|
+
}
|
package/src/runtime.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { pluginDirectory } from "./project.js";
|
|
4
|
+
|
|
5
|
+
export function runtimeDirectory(projectRoot) {
|
|
6
|
+
return path.join(pluginDirectory(projectRoot), "runtime");
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function activePath(projectRoot) {
|
|
10
|
+
return path.join(runtimeDirectory(projectRoot), "active.json");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function readJson(filePath) {
|
|
14
|
+
try {
|
|
15
|
+
return JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
16
|
+
} catch (error) {
|
|
17
|
+
throw new Error(`Cannot read ${filePath}: ${error.message}`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function readConfig(projectRoot) {
|
|
22
|
+
return readJson(path.join(pluginDirectory(projectRoot), "config.json"));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function readActive(projectRoot) {
|
|
26
|
+
const filePath = activePath(projectRoot);
|
|
27
|
+
if (!fs.existsSync(filePath)) {
|
|
28
|
+
throw new Error("No active pharo-agent image. Run pharo-agent open first.");
|
|
29
|
+
}
|
|
30
|
+
return readJson(filePath);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function writeActive(projectRoot, value) {
|
|
34
|
+
fs.mkdirSync(runtimeDirectory(projectRoot), { recursive: true });
|
|
35
|
+
fs.writeFileSync(activePath(projectRoot), `${JSON.stringify(value, null, 2)}\n`);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function clearActive(projectRoot) {
|
|
39
|
+
fs.rmSync(activePath(projectRoot), { force: true });
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function resolveMountPath(projectRoot, config, imageId) {
|
|
43
|
+
const root = config.mountRoot ?? ".pharo-agent/mounts";
|
|
44
|
+
return path.resolve(projectRoot, root, imageId);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function selectRunningImage(state, imageId) {
|
|
48
|
+
const images = (state.images ?? []).filter(
|
|
49
|
+
(image) => image.status === "running" && (imageId === undefined || image.id === imageId),
|
|
50
|
+
);
|
|
51
|
+
if (images.length !== 1) {
|
|
52
|
+
throw new Error(
|
|
53
|
+
`pharo-agent needs exactly one running image; PLexus reported ${images.length}.`,
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
const image = images[0];
|
|
57
|
+
if (!Array.isArray(image.mcpServers) || image.mcpServers.length !== 1) {
|
|
58
|
+
throw new Error(
|
|
59
|
+
`Image ${image.id} needs exactly one MCP endpoint; PLexus reported ${image.mcpServers?.length ?? 0}.`,
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
return { image, mcpServerId: image.mcpServers[0].id };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function smalltalkString(value) {
|
|
66
|
+
return `'${String(value).replaceAll("'", "''")}'`;
|
|
67
|
+
}
|