返回资讯中心
外部精选
软件工程
#开发者实时流

Tov: A programming language for coding agents

A programming language for coding agents. Your agent already writes TypeScript, so it can already write Tov, and when it gets something wrong the compiler hands back the edit that fixes it. What it ships is a native bin…

Hacker News 最新thatxliner2026/10/14 · 23 天前14 分钟阅读

以下正文同步自 Hacker News 最新,版权归原站所有,已转换为易读排版。

A programming language for coding agents. Your agent already writes TypeScript, so it can already write Tov, and when it gets something wrong the compiler hands back the edit that fixes it. What it ships is a native binary that beats Rust's.

Copy the prompt for your agent Star on GitHub

$ curl -fsSL https://tov.sh/install.sh | shCopy

Web serverHTTP clientProgramCompileMemory

Requests a second, a JSON API on one core

binary_trees: millions of small objects made and freed

Tov is a compiler. It checks the TypeScript your agent wrote, writes it out as C and hands that to clang, so what you ship is one native binary with nothing to install next to it.

Tov reads TypeScript's syntax and types, with int and f64 for numbers, and Bun's and Node's APIs. It leaves out what makes a program hard to follow: any, null and ==.

type Shape = | { kind: "circle", r: f64 } | { kind: "rect", w: f64, h: f64 }

function area(s: Shape): f64 { switch (s.kind) { case "circle": return Math.PI * s.r * s.r case "rect": return s.w * s.h } }

Tov checks every line

The checker, written in Rust, catches what TypeScript lets through: a call that can fail without try, a value shared where it should be copied, a switch that misses a case. Each error has a code and, where the fix is clear, the edit that makes it, which tov check --json hands to your agent.

// without the "rect" case $ tov check shapes.tov error[F0301] shapes.tov:6:11: switch is not exhaustive: missing "rect" 6 | switch (s.kind) { fix: add case "rect"

It writes the program as C

The whole program becomes one C file. Records become structs and a union becomes a tagged union, so switch (s.kind) is a switch on an integer. Values are reference-counted, with the counting written into the C, so there's no garbage collector to pause the program.

struct Shape { uint32_t tag; union { Circle m0; Rect m1; } u; };

static double area(Shape s) { switch (s.tag) { case 0: return 3.141592653589793 * s.u.m0.r * s.u.m0.r; case 1: return s.u.m1.w * s.u.m1.h; } }

clang makes one binary

clang compiles that C with Tov's runtime, a C library with the event loop, the HTTP server and client, and Tov's strings, arrays and maps. The runtime is compiled once and cached, so most of a build is clang's. A program that imports an npm package also carries the package and JavaScriptCore, the engine Bun uses, to run it.

$ tov build shapes.tov --time check 0.3 ms, generate 0.2 ms, C compile 55 ms build: shapes $ ls -lh shapes 34K shapes $ ./shapes circle: 3.14 rect: 6.00

How an agent writes Tov

1Your agent writes TypeScript

// hello.tov Bun.serve({ port: 3000, fetch(req) { const url = new URL(req.url) return new Response(Hello from ${url.pathname}) }, })

2Tov hands back the fix

$ tov check --json { "code": "T0831", "message": "new URL can throw TypeError; mark the call try to pass the error on, or catch it", "fixes": [{ "applicability": "safe", "edits": [{ "line": 4, "col": 17, "text": "try " }] }] }

3You ship a native binary

// the agent applies the fix const url = try new URL(req.url)

$ tov build hello.tov build: hello $ ls -lh hello 152K hello $ ./hello & curl :3000/agents Hello from /agents

It's TypeScript

With the APIs your agent knows from Bun and Node. Bun.serve, fetch, node:fs, async/await and npm packages work as it expects.

There's no any, null or ==, and a call that can fail is marked try. If code looks like TypeScript it behaves like TypeScript, and if it can't, it doesn't compile.

--watch restarts the program on save, and tov test runs the tests that sit next to the code.

Tov compiles to C and counts references instead of collecting garbage, so there are no collector pauses and the binaries stay small.

3.0× faster than Rustbinary_trees: millions of small objects

1.6× faster than Rustsort: 3M floats, with a comparator

1.7× faster than Rustmap_insert: 2M string keys

2.1× faster than Rustdispatch: 50M virtual calls

1.6× faster than Ruststrings: format, join, split

7% faster than Rustfib: recursive calls, overflow-checked

12% faster than Rustweb server: JSON API, one core

2.8× less than Rustserver memory: serving that API

9% faster than Rustfetch(): 64 requests at once

2.3× faster than Rustcompile: a program to a binary

10.5× smaller than Rustbinary size: a program, stripped

Measured on an Apple M4 Max, and each program prints the same output in every language. Tov checks integer overflow by default; Rust's release builds don't. Method and every result.

Cap is our open-source screen recorder. We've tried two parts of its video pipeline on Tov: a new encoder written in Tov, and the media server Cap already has, compiled by Tov as it is. Neither runs in Cap's production yet.

Every Cap recording ends up as H.264 video. We wrote an encoder for it in Tov, tuned for what's on a screen, and compared it with x264 at the same picture quality. The encoder is on GitHub.

12 screen recordings at 1080p, on one thread, against x264's veryfast preset. Every result.

Cap's media server is a Bun app (Hono, zod and FFmpeg) that probes uploaded videos and pulls out their audio. Tov runs it without changing a line; the file below is the whole port. Cap still serves it with Bun.

// main.tov import server from "cap-media-server" import { serve } from "bun"

function main() { try serve(server) }

105 msto start (Bun: 120)

27% lessCPU for each video it reads

129 MBof memory at its peak under load (Bun: 143)

Against Bun 1.4 on an Apple M4 Max. Method and every result.

Paste this into your agent. It installs Tov, reads llms.txt, and from then on checks its own work with tov check --json.

正文由 探How 从来源站点 RSS 同步,内容未经改写;遇到排版缺失或需要图片、视频时请以原文为准。

打开原文
去社区讨论 →