名称: smalltalk
版本: 1.7.0
描述: 与活跃的 Smalltalk 镜像(Cuis 或 Squeak)交互。用于执行 Smalltalk 代码、浏览类、查看方法源码、定义类/方法、查询继承层次和分类。
元数据: {"clawdbot":{"emoji":"💎","requires":{"bins":["python3","xvfb-run"]}}}
通过 MCP 执行 Smalltalk 代码并浏览活跃的 Squeak/Cuis 镜像。
首先获取 ClaudeSmalltalk 仓库:
git clone https://github.com/CorporateSmalltalkConsultingLtd/ClaudeSmalltalk.git
此仓库包含:
- 用于 Squeak 的 MCP 服务器代码 (MCP-Server-Squeak.st)
- 设置文档 (SQUEAK-SETUP.md, CLAWDBOT-SETUP.md)
- 此 Clawdbot 技能 (clawdbot/)
# 检查设置
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
使用标准镜像,临时性。守护进程停止时,所有更改将被丢弃。
用户指令:"load Smalltalk skill" 或 "invoke Smalltalk" — 无需特殊标志。
# 启动沙盒守护进程
nohup python3 smalltalk-daemon.py start > /tmp/daemon.log 2>&1 &
用户提供自己的镜像/变更文件对。更改在会话间持久保存。
用户指令:"load Smalltalk skill in dev mode with ~/MyProject.image"
# 使用自定义镜像启动开发守护进程
nohup python3 smalltalk-daemon.py start --dev --image ~/MyProject.image > /tmp/daemon.log 2>&1 &
开发模式会设置 SMALLTALK_DEV_MODE=1,使 MCP 服务器保留 .changes 文件(而不是重定向到 /dev/null)。提供的镜像必须有一个匹配的 .changes 文件与其并存。
# 检查状态
python3 smalltalk.py --daemon-status
# 停止守护进程
python3 smalltalk-daemon.py stop
# 在开发模式下重启
python3 smalltalk-daemon.py restart --dev --image ~/MyProject.image
| 命令 | 描述 |
|---|---|
--check |
验证虚拟机/镜像路径和依赖项 |
--daemon-status |
检查守护进程是否正在运行 |
--debug |
调试挂起系统(发送 SIGUSR1,捕获堆栈跟踪) |
evaluate <code> |
执行 Smalltalk 代码并返回结果 |
browse <class> |
获取类元数据(超类、实例变量、实例方法和类方法) |
method-source <class> <selector> [--class-side] |
查看方法源码(支持 "Class class" 语法或 --class-side 标志) |
define-class <definition> |
创建或修改类 |
define-method <class> <source> |
添加或更新方法 |
delete-method <class> <selector> |
移除方法 |
delete-class <class> |
移除类 |
list-classes [prefix] |
列出类,可选名称前缀过滤 |
hierarchy <class> |
获取超类链 |
subclasses <class> |
获取直接子类 |
list-categories |
列出所有系统分类 |
classes-in-category <cat> |
列出指定分类中的类 |
explain <code> |
解释 Smalltalk 代码(需要 ANTHROPIC_API_KEY 或 OPENAI_API_KEY) |
explain-method <class> <sel> [--class-side] [--source <code>] |
从镜像获取方法并解释(或使用 --source/--source-file/--source-stdin 绕过守护进程) |
audit-comment <class> <sel> [--class-side] [--source <code>] |
审计方法注释与实现的一致性(或使用 --source/--source-file/--source-stdin 绕过守护进程) |
audit-class <class> |
审计类中的所有方法(实例端 + 类端) |
generate-sunit <targets> [--force] [--class-name <name>] |
为方法生成 SUnit 测试并直接存入镜像 |
| 变量 | 描述 |
|---|---|
SQUEAK_VM_PATH |
Squeak/Cuis 虚拟机可执行文件路径 |
SQUEAK_IMAGE_PATH |
包含 MCP 服务器的 Smalltalk 镜像路径 |
ANTHROPIC_API_KEY |
Anthropic Claude 的 API 密钥(LLM 工具首选) |
ANTHROPIC_MODEL |
Anthropic 模型(默认:claude-opus-4-20250514) |
OPENAI_API_KEY |
OpenAI 的 API 密钥(LLM 工具备用) |
OPENAI_MODEL |
OpenAI 模型(默认:gpt-4o) |
LLM_PROVIDER |
强制指定 LLM 提供商:anthropic 或 openai(未设置时自动检测) |
当 Claude Code 通过 MCP 连接到一个活跃的 Smalltalk 镜像时,explain-method 和 audit-comment 可以使用预获取的源码,而无需运行守护进程。使用 --source、--source-file 或 --source-stdin 直接传递方法源码:
# 内联源码(通过 MCP 获取,在命令行传递)
python3 smalltalk.py explain-method SmallInteger + --source "+ aNumber <primitive: 1> ^ 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
这三个源码标志是互斥的。当都未提供时,将像之前一样使用守护进程。
generate-sunit 命令使用 LLM 为 Smalltalk 方法生成 SUnit 测试用例,并直接存入正在运行的镜像:
# 为单个方法生成测试
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 使用标准的 SUnit 断言(assert:、assert:equals:、deny:、should:raise:),并存入 GeneratedSUnit-* 分类。
saveImage 功能--dev --image PATH 参数