Smalltalk Skill
Execute Smalltalk code and browse live Squeak/Cuis images via MCP.
Prerequisites
Get the ClaudeSmalltalk repo first:
CODEBLOCK0
This repo contains:
- - MCP server code for Squeak (
MCP-Server-Squeak.st) - Setup documentation (
SQUEAK-SETUP.md, CLAWDBOT-SETUP.md) - This Clawdbot skill (
clawdbot/)
Setup
- 1. Set up Squeak with MCP server — see SQUEAK-SETUP.md
- Configure Clawdbot — see CLAWDBOT-SETUP.md
Usage
CODEBLOCK1
Operating Modes
Playground (Default)
Stock image, ephemeral. Changes are discarded when daemon stops.
User says: "load Smalltalk skill" or "invoke Smalltalk" — no special flags.
CODEBLOCK2
Dev Mode
User supplies their own image/changes pair. Changes persist across sessions.
User says: "load Smalltalk skill in dev mode with ~/MyProject.image"
CODEBLOCK3
Dev mode sets SMALLTALK_DEV_MODE=1 so the MCP server keeps the .changes file
(instead of redirecting to /dev/null). The supplied image must have a matching
.changes file alongside it.
Common Commands
CODEBLOCK4
Commands
| Command | Description |
|---|
| INLINECODE5 | Verify VM/image paths and dependencies |
| INLINECODE6 |
Check if daemon is running |
|
--debug | Debug hung system (sends SIGUSR1, captures stack trace) |
|
evaluate <code> | Execute Smalltalk code, return result |
|
browse <class> | Get class metadata (superclass, ivars, instance
methods and
classMethods) |
|
method-source <class> <selector> [--class-side] | View method source code (supports
"Class class" syntax or
--class-side flag) |
|
define-class <definition> | Create or modify a class |
|
define-method <class> <source> | Add or update a method |
|
delete-method <class> <selector> | Remove a method |
|
delete-class <class> | Remove a class |
|
list-classes [prefix] | List classes, optionally filtered |
|
hierarchy <class> | Get superclass chain |
|
subclasses <class> | Get immediate subclasses |
|
list-categories | List all system categories |
|
classes-in-category <cat> | List classes in a category |
|
explain <code> | Explain Smalltalk code (requires
ANTHROPIC_API_KEY or
OPENAI_API_KEY) |
|
explain-method <class> <sel> [--class-side] [--source <code>] | Fetch method from image and explain it (or use
--source/
--source-file/
--source-stdin to bypass daemon) |
|
audit-comment <class> <sel> [--class-side] [--source <code>] | Audit method comment vs implementation (or use
--source/
--source-file/
--source-stdin to bypass daemon) |
|
audit-class <class> | Audit all methods in a class (instance + class side) |
|
generate-sunit <targets> [--force] [--class-name <name>] | Generate SUnit tests for methods and file into image |
Environment Variables
| Variable | Description |
|---|
| INLINECODE37 | Path to Squeak/Cuis VM executable |
| INLINECODE38 |
Path to Smalltalk image with MCP server |
|
ANTHROPIC_API_KEY | API key for Anthropic Claude (preferred for LLM tools) |
|
ANTHROPIC_MODEL | Anthropic model (default:
claude-opus-4-20250514) |
|
OPENAI_API_KEY | API key for OpenAI (fallback for LLM tools) |
|
OPENAI_MODEL | OpenAI model (default:
gpt-4o) |
|
LLM_PROVIDER | Force LLM provider:
anthropic or
openai (auto-detected if not set) |
Using with Claude Code (MCP mode)
When Claude Code has a live Smalltalk image connected via MCP, explain-method and audit-comment can use pre-fetched source code instead of requiring a running daemon. Use --source, --source-file, or --source-stdin to pass the method source directly:
CODEBLOCK5
The three source flags are mutually exclusive. When none is provided, the daemon is used as before.
Generating SUnit Tests
The generate-sunit command uses an LLM to generate SUnit test cases for Smalltalk methods and files them directly into the running image:
CODEBLOCK6
The generated TestCase uses standard SUnit assertions (assert:, assert:equals:, deny:, should:raise:) and is filed into a GeneratedSUnit-* category.
Notes
- - Requires xvfb for headless operation on Linux servers
- Uses Squeak 6.0 MCP server (GUI stays responsive if display available)
- INLINECODE59 intentionally excluded for safety
- MCPServer version 7+ required (v7 adds class-side method support)
- Playground mode: ephemeral, .changes → /dev/null
- Dev mode: persistent, .changes kept, requires INLINECODE60
Smalltalk 技能
通过 MCP 执行 Smalltalk 代码并浏览实时 Squeak/Cuis 镜像。
前置条件
首先获取 ClaudeSmalltalk 仓库:
bash
git clone https://github.com/CorporateSmalltalkConsultingLtd/ClaudeSmalltalk.git
该仓库包含:
- - Squeak 的 MCP 服务器代码(MCP-Server-Squeak.st)
- 设置文档(SQUEAK-SETUP.md、CLAWDBOT-SETUP.md)
- 本 Clawdbot 技能(clawdbot/)
设置
- 1. 设置带有 MCP 服务器的 Squeak — 参见 SQUEAK-SETUP.md
- 配置 Clawdbot — 参见 CLAWDBOT-SETUP.md
用法
bash
检查设置
python3 smalltalk.py --check
评估代码
python3 smalltalk.py evaluate 3 factorial
python3 smalltalk.py evaluate Date today
浏览类
python3 smalltalk.py browse OrderedCollection
查看方法源码(实例侧)
python3 smalltalk.py method-source String asUppercase
查看方法源码(类侧)
python3 smalltalk.py method-source MCPServer class version
python3 smalltalk.py method-source MCPServer version --class-side
列出类(可选前缀过滤)
python3 smalltalk.py list-classes Collection
获取类层次结构
python3 smalltalk.py hierarchy OrderedCollection
获取子类
python3 smalltalk.py subclasses Collection
列出所有类别
python3 smalltalk.py list-categories
列出某个类别中的类
python3 smalltalk.py classes-in-category Collections-Sequenceable
定义新类
python3 smalltalk.py define-class Object subclass: #Counter instanceVariableNames: count classVariableNames: poolDictionaries: category: MyApp
定义方法
python3 smalltalk.py define-method Counter increment
count := (count ifNil: [0]) + 1.
^ count
删除方法
python3 smalltalk.py delete-method Counter increment
删除类
python3 smalltalk.py delete-class Counter
运行模式
游乐场模式(默认)
使用原始镜像,临时性。守护进程停止时更改将被丢弃。
用户说:加载 Smalltalk 技能或调用 Smalltalk——无需特殊标志。
bash
启动游乐场守护进程
nohup python3 smalltalk-daemon.py start > /tmp/daemon.log 2>&1 &
开发模式
用户提供自己的镜像/更改文件对。更改在会话间持久保存。
用户说:以开发模式加载 Smalltalk 技能,使用 ~/MyProject.image
bash
使用自定义镜像启动开发守护进程
nohup python3 smalltalk-daemon.py start --dev --image ~/MyProject.image > /tmp/daemon.log 2>&1 &
开发模式设置 SMALLTALKDEVMODE=1,使 MCP 服务器保留 .changes 文件
(而不是重定向到 /dev/null)。提供的镜像必须在其旁边有匹配的
.changes 文件。
常用命令
bash
检查状态
python3 smalltalk.py --daemon-status
停止守护进程
python3 smalltalk-daemon.py stop
以开发模式重启
python3 smalltalk-daemon.py restart --dev --image ~/MyProject.image
命令
| 命令 | 描述 |
|---|
| --check | 验证 VM/镜像路径和依赖项 |
| --daemon-status |
检查守护进程是否在运行 |
| --debug | 调试挂起系统(发送 SIGUSR1,捕获堆栈跟踪) |
| evaluate <代码> | 执行 Smalltalk 代码,返回结果 |
| browse <类> | 获取类元数据(超类、实例变量、实例方法和类方法) |
| method-source <类> <选择器> [--class-side] | 查看方法源码(支持类 class语法或--class-side标志) |
| define-class <定义> | 创建或修改类 |
| define-method <类> <源码> | 添加或更新方法 |
| delete-method <类> <选择器> | 删除方法 |
| delete-class <类> | 删除类 |
| list-classes [前缀] | 列出类,可选过滤 |
| hierarchy <类> | 获取超类链 |
| subclasses <类> | 获取直接子类 |
| list-categories | 列出所有系统类别 |
| classes-in-category <类别> | 列出某个类别中的类 |
| explain <代码> | 解释 Smalltalk 代码(需要ANTHROPIC
APIKEY或OPENAI
APIKEY) |
| explain-method <类> <选择器> [--class-side] [--source <代码>] | 从镜像中获取方法并解释(或使用--source/--source-file/--source-stdin绕过守护进程) |
| audit-comment <类> <选择器> [--class-side] [--source <代码>] | 审计方法注释与实现(或使用--source/--source-file/--source-stdin绕过守护进程) |
| audit-class <类> | 审计类中的所有方法(实例侧 + 类侧) |
| generate-sunit <目标> [--force] [--class-name <名称>] | 为方法生成 SUnit 测试并归档到镜像中 |
环境变量
| 变量 | 描述 |
|---|
| SQUEAKVMPATH | Squeak/Cuis VM 可执行文件路径 |
| SQUEAKIMAGEPATH |
带有 MCP 服务器的 Smalltalk 镜像路径 |
| ANTHROPIC
APIKEY | Anthropic Claude 的 API 密钥(LLM 工具首选) |
| ANTHROPIC_MODEL | Anthropic 模型(默认:claude-opus-4-20250514) |
| OPENAI
APIKEY | OpenAI 的 API 密钥(LLM 工具备用) |
| OPENAI_MODEL | OpenAI 模型(默认:gpt-4o) |
| LLM_PROVIDER | 强制指定 LLM 提供商:anthropic 或 openai(未设置时自动检测) |
与 Claude Code 配合使用(MCP 模式)
当 Claude Code 通过 MCP 连接到实时 Smalltalk 镜像时,explain-method 和 audit-comment 可以使用预获取的源代码,而无需运行中的守护进程。使用 --source、--source-file 或 --source-stdin 直接传递方法源码:
bash
内联源码(通过 MCP 获取,在命令行传递)
python3 smalltalk.py explain-method SmallInteger + --source + aNumber
^ super + aNumber
从文件读取源码
python3 smalltalk.py audit-comment Integer factorial --source-file /tmp/factorial.st
通过标准输入传递源码
echo printString ^ self printStringLimitedTo: 50000 | python3 smalltalk.py explain-method Object printString --source-stdin
这三个源码标志互斥。当未提供任何标志时,将像以前一样使用守护进程。
生成 SUnit 测试
generate-sunit 命令使用 LLM 为 Smalltalk 方法生成 SUnit 测试用例,并将其直接归档到运行中的镜像:
bash
为单个方法生成测试
python3 smalltalk.py generate-sunit String>>asUppercase
为多个方法生成测试
python3 smalltalk.py generate-sunit Random>>next Random>>nextInt: Random>>seed:
为整个类生成测试(所有实例方法)
python3 smalltalk.py generate-sunit OrderedCollection
为类侧方法生成测试
python3 smalltalk.py generate-sunit Date class>>today
自定义测试类名称
python3 smalltalk.py generate-sunit String>>asUppercase --class-name MyStringTests
覆盖现有测试类
python3 smalltalk.py generate-sunit String>>asUppercase --force
运行生成的测试
python3 smalltalk.py evaluate StringGeneratedTest buildSuite run printString
生成的 TestCase