typesafe-computer-use README

项目的 README,来自 github.com/awlevin/typesafe-computer-use。合并为一个 markdown 文件:README.md。

typesafe-computer-use

CI MIT license Python 3.12+ macOS, Windows experimental TypeSafe Ruff

typesafe-computer-use (jev for short) drives a Mac toward a goal you type in plain English, for about a fiftieth of a cent per step. It reads the screen deterministically, asks a small classifier which action comes next, and only calls a writing model when a text field genuinely needs free text or the classifier has stopped and the screen needs reading.

One idea runs through it: the classifier picks, code decides facts, and the writer only writes free text. Anything a model would have to work out (a date, whether a field is focused, whether a URL is clean) is computed in code and handed over as state. VISION.md says what it is for in a dozen lines.

clicker "go to techcrunch and take me to the checkout page for the cheapest tickets to their next upcoming event" --act

Beta. This is under heavy development. Expect rough edges, and expect settings and behavior to change between 0.x releases. It drives your real mouse and keyboard, so start with a dry run.

Why a classifier

Frontier-model computer use is capable and expensive: every step ships a screenshot and waits several seconds for a plan. Most steps do not need a plan. They need one choice from a short list, made quickly and cheaply, with a confidence number you can gate on.

TypeSafe sells exactly that: a decision model that answers a Choice over up to 255 options with a full probability distribution and a calibrated confidence, in a few hundred milliseconds, with free output tokens. This project is a computer-use loop built around it.

Measured on the same screenshot and goal, one decision each:

typesafe (jev) Claude Opus 5, bare screenshot multiplier
input tokens 4,882 4,785 same
cost per decision $0.0002 $0.032 155x cheaper
cost per decision, realistic loop with history $0.0002 $0.035 to $0.08 170x to 390x cheaper
cost per 12-step task $0.003 $0.40 to $0.90 130x to 300x cheaper
model latency 0.13 to 0.38 s 5.2 s 14x to 40x faster
end-to-end step, with capture and OCR about 1.5 s about 5.5 s 3.7x faster

The honest caveat: the big model read the event dates off the pixels and compared them unaided. The classifier needed the date parsing described in how a step works. Every piece of reasoning the frontier model does for free has to be rebuilt here as deterministic state.

Install

macOS 14 or newer, Python 3.12 or newer, uv. Windows 10 and 11 are experimental; see Windows.

git clone https://github.com/awlevin/typesafe-computer-use
cd typesafe-computer-use
uv sync
cp .env.example .env     # fill in the keys
variable required purpose
TYPESAFE_API_KEY yes every decision
ANTHROPIC_API_KEY no type_text, writer-proposed URLs, and the final answer
CLICKER_EMAIL no enables the type_email action
CLICKER_BROWSER no defaults to Google Chrome

.env lives at the repo root and is read by every entry point (clicker, clicker-inspect). To run the writer on another model or endpoint (LM Studio, Ollama, any OpenAI-compatible server), see writer endpoints.

Grant your terminal Screen Recording and Accessibility in System Settings > Privacy & Security. Without the first, captures are wallpaper. Without the second, synthetic clicks are silently dropped, and --act refuses to start.

First run

uv run clicker "open the Playground"                 # dry run: one step, prints what it would do
uv run clicker "open the Playground" --act           # drives the machine, up to 100 steps
uv run clicker "log in" --act --steps 20 --delay 3   # longer and slower
uv run clicker "log in" --act --handoffs 0           # the classifier alone: its first stop ends the run
uv run clicker-inspect "any goal"                    # 3-2-1, capture, open the annotated screen + payload

Clear the terminal first. It is on screen, so its text is OCR input.

To stop a live run, press Ctrl-C in the terminal or slam the mouse into the top-left corner of the screen. The loop also stops itself on done, low confidence, a stall, or the step limit, and the writer then reads the screen and prints the answer. Every run writes runs/<timestamp>/, so a stall can be replayed offline.

How a step works

  1. The screen is read deterministically: Vision OCR on a crop of the frontmost window, plus the labelled controls from the accessibility tree, which sees the icons OCR cannot.
  2. Code adds the facts: the date on any block and how far off it is, the row of a repeated label, the focused field, the app and URL, and the actions already tried on this screen.
  3. One TypeSafe request answers three Choices: which kind of action, which item, which site.
  4. The action runs deterministically, the loop waits, and the next capture is the only witness of what it did.
  5. When the classifier stops, the writer reads the screen and answers, or hands the run back with a focus (one move) or a question for you. It never picks an action.

The full walk, with the OCR cost, the tree walk, the action space, and the stop rules, is in how a step works.

Benchmark

jev runs as an agent in OSWorld, a benchmark of real desktop tasks, beside OSWorld's own GPT agent on the same task. scripts/osworld setup fetches OSWorld and installs jev beside it; scripts/osworld run-jev chrome/<task id> --ocr rapidocr runs one task. It needs a Linux host with KVM; see OSWorld for that and for a one-command machine in Google Cloud.

Read more

Contributing

Bug reports with a run folder attached are the most useful thing you can send. Before a pull request, uv run ruff check . && uv run ruff format --check . and uv run pytest -q must pass. The ground rules, and how to write a scenario for a task the loop cannot do, are in CONTRIBUTING.md.

License

MIT

typesafe-computer-use (awlevin/typesafe-computer-use)

正在搜索数据库…

这是干什么的?一个 Python 代理,你用普通英语输入一个目标,它就会操控你的 Mac 去完成:它对屏幕做 OCR 识别,由一个便宜的分类器决定每一步动作,然后执行点击——每步大约只花 0.0002 美元。
这是一个 Mac 应用,还是我要在终端里运行的东西?是一个终端工具,不是图形界面应用:你通过 uv 运行 clicker、clicker-inspect 之类的入口命令,它能看到并操控你屏幕上的任何内容。
我怎么把它跑起来?需要 macOS 14+、Python 3.12+ 和 uv。把你的 TYPESAFEAPIKEY 放进 .env,给终端授予屏幕录制和辅助功能权限,然后先用试运行模式试一下——因为它会真实操控你的鼠标和键盘。
我需要 Anthropic 的 API 密钥吗?只有 TYPESAFEAPIKEY 是必需的,每一步决策都要用它。Anthropic 密钥是可选的(它负责输入自由文本并给出最终回答),writer 也可以改用 Ollama、LM Studio、vLLM 或 DeepSeek。
Windows 版本真的能用吗?勉强算吧——它带了一个 Windows 适配器,但没经过测试,预计会出问题:OCR 只支持英语且没有置信度分数,而且只能捕获主显示器。
它会读取我的屏幕,那会不会连密码也抓走?不会:在浏览器后端下,输入框的值永远不会被采集,而且循环会拒绝往密码框或银行卡号框里输入,所以凭据不会到达分类器、writer,也不会写入磁盘。
比起用前沿大模型操控电脑,它为什么能便宜这么多?大多数步骤只需要从一个短列表里选一项,所以一个小型的 TypeSafe 分类器在 0.13-0.38 秒内就能做出决定,花费 0.0002 美元,而不是把整张截图发给大模型花掉约 0.032 美元——每次决策便宜 155 倍。代价是:大模型顺手完成的推理,必须重新构建成确定性的状态逻辑。
TypeSafe 是什么?整个循环所围绕的决策模型:给它一个最多带 255 个选项的 Choice,它会在几百毫秒内返回完整的概率分布和一个经过校准的置信度,而且输出 token 免费。
它能不用 OCR 就读取网页吗?可以——有一个可选开启的浏览器后端,通过 Chrome DevTools Protocol 直接读取 DOM,而不是看像素:比截图 OCR 快 62 到 221 倍,而截图 OCR 对真实页面标签的还原率还不到 10%,而且这个后端不需要屏幕录制权限。
如果运行过程失控了,我怎么停下来?在终端获得焦点时按 Ctrl-C,或者把鼠标猛甩到屏幕左上角——每次动作执行前和输入字符之间都会检测这个角落。此外,置信度低于 --min-confidence 0.4、出现停滞、或到达 --steps 步数上限时,它也会自己停下。
作者
awlevin
大小
0.9 MB
星标
1.3K
更新
提交Sep 29
时长
2个月
提交 · 90 天