展示HN:Sigil – 一种用于人工智能代理的新编程语言

3作者: inerte7 天前原帖
我一直在开发一种新的编程语言,用于人工智能代理。我非常希望能听到你们对使编程语言适合人工智能代理的看法,尤其是在语法、编译器和工具方面,这些都可以帮助人工智能代理编写代码。 什么使得Sigil适合编写代理代码? 我尽可能地将约定转化为编译器规则。编译器拥有规范的打印器,每个抽象语法树(AST)都有一个被接受的文本表示。对于几乎每个语法特性,我都尽量节省标记。 顺序和命名约定是强制执行的。再也没有“我认为这个参数很重要,所以它应该放在第一位。”大多数内容都是按字母顺序排列的。声明被分类并按字母顺序排列;参数、效果和记录字段也都是按字母顺序排列。类型使用大驼峰命名法(UpperCamelCase),其他所有内容使用小驼峰命名法(lowerCamelCase),包括文件名。 没有空值(null)。没有未定义(undefined)。 双向类型检查。 没有变量遮蔽(shadowing)。 丰富的标准库(仍在进行中)。 `sigil debug`支持重放、单步调试、监视和断点。 `sigil inspect`允许编码代理直接查询编译器,包括证明表面。 支持求解器的细化和合约。不同的语言已经选择了不同的数值表面:字节(byte)、短整型(short)、小整型(smallint)、无符号整数等。Sigil更进一步:领域约束也可以定义类型。`where`允许命名类型携带谓词,而`requires`和`ensures`则允许函数在调用边界之间携带证明义务。 以下是来自roguelite的一个人为例子: ```sigil t InventoryCount=Int where value≥0 λspendArrow(arrows:InventoryCount)=>InventoryCount requires arrows>0 ensures result≥0 =arrows-1 ``` 在底层,这由Z3支持: [https://github.com/z3prover/z3](https://github.com/z3prover/z3) 但表面保持普通的Sigil语法。没有证明脚本,也没有面向用户的SMT语言。 没有导入,仅限根引用。在某些语言中,你可以导入代码并发生名称冲突,因此有许多方法来指定导入。Sigil通过仅使用根引用消除了所有这些。我认为这减少了代理的变动,因为当模型看到一行代码时,它不必去寻找导入语句。 服务依赖在`src/topology.lib.sigil`中声明,环境绑定则在`config/<env>.lib.sigil`中。 该语言有特殊的测试语法,测试是并行运行的。每个项目的`src/*.lib.sigil`函数必须经过测试,如果一个函数可以返回多个情况,测试应涵盖所有情况。“世界”是Sigil的效果模型。这就是模拟的工作原理:用一个效果替换另一个效果,并进行断言,而不需要实际调用外部系统。 编译器工具链是用Rust编写的,Sigil输出为TypeScript,并与Node.js有外部函数接口(Foreign Function Interface)。可以在这里查看一些小项目 [https://inerte.github.io/sigil/projects/](https://inerte.github.io/sigil/projects/) - Flashcards是了解Sigil特性的有用工具 [https://inerte.github.io/sigil/projects/sigil-flashcards/demo/](https://inerte.github.io/sigil/projects/sigil-flashcards/demo/)。 警告:我没有为编译器工具链编写一行代码。所有代码都是通过Claude Code和Codex生成的。我在运行这两个工具时,权限是危险地跳过的。这篇实际的帖子是我手动撰写的每一个字。 此外,还有一个用Sigil编写的玩具roguelite。它仍在进行中,但证明了Sigil可以支持非平凡的项目代码。你可以通过`pnpm sigil:run:roguelike`进行体验。 仓库:[https://github.com/inerte/sigil](https://github.com/inerte/sigil) 网站:[https://inerte.github.io/sigil/](https://inerte.github.io/sigil/) 我也希望你们能找到更多的方法来进一步限制大型语言模型(LLM)/用户程序。在Sigil中,应该只有一种方法来完成任何事情。
查看原文
I&#x27;ve been working on a new programming language for AI agents. I would love your input on what makes programming languages good for AI agents, especially syntax, compiler, and tooling that could help AI agents write code.<p>What makes Sigil good for coding agents?<p>I&#x27;ve turned conventions into compiler rules whenever possible. The compiler owns the canonical printer and every AST has one accepted textual representation. For almost every syntax feature I tried to save tokens.<p>Order and naming conventions are enforced. No more &quot;I think this argument is important so it should come first.&quot; Most things are alphabetical. Declarations are categorized and ordered alphabetically; parameters, effects, and record fields are alphabetical too. Types are UpperCamelCase. Everything else is lowerCamelCase, including file names.<p>No nulls. No undefined. Bidirectional type checking. No shadowing. Fat stdlib (still in progress). `sigil debug` supports replay, stepping, watches, and breakpoints. `sigil inspect` lets coding agents query the compiler directly, including proof surfaces.<p>Solver-backed refinements and contracts. Different languages already choose different numeric surfaces: byte, short, smallint, unsigned integers, etc. Sigil pushes that one step further: domain constraints can also define types. `where` lets a named type carry a predicate, and `requires` &#x2F; `ensures` let functions carry proof obligations across call boundaries.<p>Here is a contrived example from the roguelite:<p><pre><code> t InventoryCount=Int where value≥0 λspendArrow(arrows:InventoryCount)=&gt;InventoryCount requires arrows&gt;0 ensures result≥0 =arrows-1 </code></pre> Under the hood this is backed by Z3: <a href="https:&#x2F;&#x2F;github.com&#x2F;z3prover&#x2F;z3" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;z3prover&#x2F;z3</a> But the surface stays ordinary Sigil syntax. There are no proof scripts and no user-facing SMT language.<p>No imports, rooted references only. In some languages you can import code and have name clashes, so there are many ways to specify imports. Sigil eliminates all of that by only using rooted references. I think this reduces agent churn because when the model sees a line, it does not have to go hunt for an import statement.<p>Service dependencies are declared in `src&#x2F;topology.lib.sigil`, and environment bindings live in `config&#x2F;&lt;env&gt;.lib.sigil`.<p>The language has special syntax for tests and they are run in parallel. Every project `src&#x2F;*.lib.sigil` function must be tested, and if a function can return multiple cases, tests should exercise all of them. &quot;World&quot; is Sigil&#x27;s model for effects. That is how mocks work: swap one effect for another and make assertions without exercising real external systems.<p>The compiler toolchain is written in Rust, and Sigil outputs to TypeScript, with a Foreign Function Interface to Node.js. See some small projects here <a href="https:&#x2F;&#x2F;inerte.github.io&#x2F;sigil&#x2F;projects&#x2F;" rel="nofollow">https:&#x2F;&#x2F;inerte.github.io&#x2F;sigil&#x2F;projects&#x2F;</a> - the Flashcards is useful to learn about Sigil features <a href="https:&#x2F;&#x2F;inerte.github.io&#x2F;sigil&#x2F;projects&#x2F;sigil-flashcards&#x2F;demo&#x2F;" rel="nofollow">https:&#x2F;&#x2F;inerte.github.io&#x2F;sigil&#x2F;projects&#x2F;sigil-flashcards&#x2F;dem...</a><p>Caveat: I did NOT type a single line of code for the compiler toolchain. It was all generated with Claude Code and Codex. I run both with permissions dangerously skipped. This actual post I hand crafted every word.<p>There is also a toy roguelite written in Sigil. It is a work in progress, but it is proof that Sigil can support nontrivial project code. You can play with `pnpm sigil:run:roguelike`.<p>Repository: <a href="https:&#x2F;&#x2F;github.com&#x2F;inerte&#x2F;sigil" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;inerte&#x2F;sigil</a><p>Website: <a href="https:&#x2F;&#x2F;inerte.github.io&#x2F;sigil&#x2F;" rel="nofollow">https:&#x2F;&#x2F;inerte.github.io&#x2F;sigil&#x2F;</a><p>And I would love if you can find ways to lock down LLM &#x2F; user programs even more. In Sigil, there should be only one way to do anything.