SuperAPIAI Directory

terse

github.com · AI coding

Terse is an open-source "AI-native" code language for AI coding agents, using a machine-designed prefix intermediate representation (HIR) aimed at reducing syntax errors and repair iterations when AI generates code. It uses fixed-arity operations, a single spelling per construct, structured error codes, and claims to use fewer tokens than Python on benchmark tasks. The project is open-sourced under the Apache-2.0 license, and the repository also includes a GBNF constrained-decoding grammar, an MCP server, benchmarks, and a leaderboard.

Open website Alternatives
PricingOpen source开源项目(可免费自部署)

About this tool

Terse is an "AI-native" code language for AI coding agents, positioned as a machine-designed prefix intermediate representation (prefix HIR). The project holds that mainstream programming languages are designed for humans and suffer from infix operators and precedence tables, multiple spellings for the same construct, reliance on whitespace indentation, and human-oriented error messages—all of which become sources of failure when AI generates code. Terse attempts to remove decisions the model should not have to make.

Key design features:

  • Prefix notation: operators always come first, e.g. (add a (mul b c)); the structure is known after reading one token, there is no precedence table or associativity rules, and there is only one way to parenthesize.
  • Canonicalization: each construct has exactly one spelling, enforced by the parser; if is always prefix form, true/false/null are always lowercase, and a bare symbol is always a variable reference.
  • Compactness: the v0.2 syntax was designed based on cl100k_base measurements, using adjacent parentheses, head-position calls, n-ary if, and fused operations for hot patterns; the reference scheme measured 0.60–1.00× the Python token count across 8 benchmark tasks.
  • Fixed arity: checked at parse time, e.g. (add 1) fails with E103 arity-mismatch before running.
  • Structured errors: every failure is a TerseError with a stable error code (E100–E300), phase, operation, source location, expected/got, and a specific hint; err.to_dict() can be fed back to the model to support repair loops.
  • Constrained-decoding grammar: terse/grammar.gbnf provides a GBNF grammar for the full language; under constrained decoding, syntax errors cannot occur, and the remaining failures are semantic errors covered by the error protocol.

On language semantics: div is true division; and/or are n-ary and short-circuit; let is letrec to support closures, and def defines named (recursive) functions; put/push/inc are functional; print returns null; evaluation is limited by gas metering and reports E205 when exhausted. See SPEC.md for the full conventions.

Versions and tooling: v0.3 has 160 passing tests and adds fmt string interpolation, e.g. (fmt "hi {}" name), which is claimed to outperform cat in sentence scenarios; the -> threading macro was rejected after measurement. The v0.2 density ratioholds at 0.60–1.00× Python tokens across the 8-task benchmark, with all stdout matching. The MCP server (mcp/) exposes eval/transpile/token-count/parse as agent tools over stdio. The repository also includes the TTCP leaderboard (methodology, scoring tools, static pages), where models are compared on token efficiency relative to Python across 8 fixed benchmark tasks, verified by stdout; first-attempt validity and the live repair loop are defined as secondary metrics but have not yet been measured.

The project also plans or includes: a Terse↔Python paired training corpus for fine-tuning; fine-tuning open-source models on Terse to generate it directly; and more transpilation backends beyond Python. The project is under the Apache-2.0 license; see LICENSE for details.

Up/Down to navigate · Enter to open · ESC to closeBrowse all tools