网淘吧来吧,欢迎您!

Smalltalk技能使用说明

2026-04-01 新闻来源:网淘吧 围观:14
电脑广告
手机广告

Smalltalk 技能

通过 MCP 执行 Smalltalk 代码并浏览实时的 Squeak/Cuis 镜像。

先决条件

首先获取 ClaudeSmalltalk 仓库:

Smalltalk

git clone https://github.com/CorporateSmalltalkConsultingLtd/ClaudeSmalltalk.git

此仓库包含:

  • 用于 Squeak 的 MCP 服务器代码 (MCP-Server-Squeak.st)
  • 设置文档 (SQUEAK-SETUP.mdCLAWDBOT-SETUP.md)
  • 此 Clawdbot 技能 (clawdbot/)

设置

  1. 设置带有 MCP 服务器的 Squeak— 参见SQUEAK-SETUP.md
  2. 配置 Clawdbot— 参见CLAWDBOT-SETUP.md

使用

# Check setup
python3 smalltalk.py --check

# Evaluate code
python3 smalltalk.py evaluate "3 factorial"
python3 smalltalk.py evaluate "Date today"

# Browse a class
python3 smalltalk.py browse OrderedCollection

# View method source (instance side)
python3 smalltalk.py method-source String asUppercase

# View method source (class side)
python3 smalltalk.py method-source "MCPServer class" version
python3 smalltalk.py method-source MCPServer version --class-side

# List classes (with optional prefix filter)
python3 smalltalk.py list-classes Collection

# Get class hierarchy
python3 smalltalk.py hierarchy OrderedCollection

# Get subclasses  
python3 smalltalk.py subclasses Collection

# List all categories
python3 smalltalk.py list-categories

# List classes in a category
python3 smalltalk.py classes-in-category "Collections-Sequenceable"

# Define a new class
python3 smalltalk.py define-class "Object subclass: #Counter instanceVariableNames: 'count' classVariableNames: '' poolDictionaries: '' category: 'MyApp'"

# Define a method
python3 smalltalk.py define-method Counter "increment
    count := (count ifNil: [0]) + 1.
    ^ count"

# Delete a method
python3 smalltalk.py delete-method Counter increment

# Delete a class
python3 smalltalk.py delete-class Counter

操作模式

游乐场(默认)

使用临时库存映像。守护进程停止时,更改将被丢弃。 用户说:"load Smalltalk skill" 或 "invoke Smalltalk" ——无需特殊标志。

# Start playground daemon
nohup python3 smalltalk-daemon.py start > /tmp/daemon.log 2>&1 &

开发模式

用户提供自己的映像/更改文件对。更改在不同会话间持久保存。 用户说:"load Smalltalk skill in dev mode with ~/MyProject.image"

# Start dev daemon with custom 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 文件。

常用命令

# Check status
python3 smalltalk.py --daemon-status

# Stop daemon
python3 smalltalk-daemon.py stop

# Restart in dev mode
python3 smalltalk-daemon.py restart --dev --image ~/MyProject.image

命令

命令描述
--check验证虚拟机/映像路径和依赖项
--daemon-status检查守护进程是否正在运行
--debug调试挂起的系统(发送 SIGUSR1,捕获堆栈跟踪)
evaluate <代码>执行 Smalltalk 代码,返回结果
浏览 <类名>获取类元数据(超类、实例变量、实例方法类方法
方法源码 <类名> <选择器> [--类侧]查看方法源代码(支持"类名 class"语法或--类侧标志)
定义类 <定义>创建或修改一个类
定义方法 <类名> <源代码>添加或更新一个方法
删除方法 <类名> <选择器>移除一个方法
删除类 <类名>移除一个类
列出类 [前缀]列出类,可选择过滤
层次结构 <类名>获取超类链
子类 <类名>获取直接子类
列出类别列出所有系统类别
类别中的类 <类别名>列出某个类别中的类
解释 <代码>解释 Smalltalk 代码 (需要ANTHROPIC_API_KEYOPENAI_API_KEY)
解释方法 <类名> <选择器> [--类端] [--源代码 <代码>]从镜像获取方法并解释它 (或使用--源代码/--源文件/--标准输入源来绕过守护进程)
审核注释 <类名> <选择器> [--类端] [--源代码 <代码>]审核方法注释与实现 (或使用--源代码/--源文件/--源标准输入(用于绕过守护进程)
audit-class <类名>审计类中的所有方法(实例侧 + 类侧)
generate-sunit <目标> [--force] [--class-name <名称>]为方法生成SUnit测试并保存到映像中

环境变量

变量描述
SQUEAK_VM_PATHSqueak/Cuis虚拟机可执行文件路径
SQUEAK_IMAGE_PATH包含MCP服务器的Smalltalk映像文件路径
ANTHROPIC_API_KEYAnthropic Claude的API密钥(LLM工具首选)
ANTHROPIC_MODELAnthropic模型(默认:claude-opus-4-20250514
OPENAI_API_KEYOpenAI API密钥(用于LLM工具备用)
OPENAI_MODELOpenAI模型(默认:gpt-4o
LLM_PROVIDER强制指定LLM提供商:anthropicopenai(未设置时自动检测)

与Claude Code配合使用(MCP模式)

当Claude Code通过MCP连接了活跃的Smalltalk镜像时,explain-methodaudit-comment可以使用预获取的源代码,而无需运行守护进程。可通过--source--source-file--source-stdin直接传递方法源代码:

# Inline source (fetched via MCP, passed on command line)
python3 smalltalk.py explain-method SmallInteger + --source "+ aNumber <primitive: 1> ^ super + aNumber"

# Source from a file
python3 smalltalk.py audit-comment Integer factorial --source-file /tmp/factorial.st

# Source piped via stdin
echo "printString ^ self printStringLimitedTo: 50000" | python3 smalltalk.py explain-method Object printString --source-stdin

三个源标志是互斥的。当没有提供任何标志时,守护进程会像以前一样被使用。

生成SUnit测试

generate-sunit命令使用LLM为Smalltalk方法生成SUnit测试用例,并直接将其归档到正在运行的映像中:

# Generate tests for a single method
python3 smalltalk.py generate-sunit "String>>asUppercase"

# Generate tests for multiple methods
python3 smalltalk.py generate-sunit "Random>>next" "Random>>nextInt:" "Random>>seed:"

# Generate tests for an entire class (all instance methods)
python3 smalltalk.py generate-sunit "OrderedCollection"

# Generate tests for class-side methods
python3 smalltalk.py generate-sunit "Date class>>today"

# Custom test class name
python3 smalltalk.py generate-sunit "String>>asUppercase" --class-name MyStringTests

# Overwrite existing test class
python3 smalltalk.py generate-sunit "String>>asUppercase" --force

# Run the generated tests
python3 smalltalk.py evaluate "StringGeneratedTest buildSuite run printString"

生成的TestCase使用标准的SUnit断言(assert:assert:equals:deny:should:raise:),并被归档到GeneratedSUnit-*类别中。

注意事项

  • 在Linux服务器上进行无头操作需要xvfb
  • 使用Squeak 6.0 MCP服务器(如果显示可用,GUI保持响应)
  • saveImage为安全起见,已特意排除
  • 需要MCPServer版本7+(v7版本增加了类端方法支持)
  • 游乐场模式:临时性,.changes文件指向/dev/null
  • 开发模式:持久性,保留.changes文件,需要--dev --image PATH参数

免责申明
部分文章来自各大搜索引擎,如有侵权,请与我联系删除。
打赏

文章底部电脑广告
手机广告位-内容正文底部

相关文章

您是本站第413451名访客 今日有0篇新文章/评论