Tommy 用於迫使 AI 按嚴格架構生成程式碼的語言 tommylang
I got tired of AI writing 500 lines of C# boilerplate, so I built a language that forces it to generate strict architecture
開發者創建 AI 原生 DSL tommylang,讓 AI 先編譯嚴格的架構藍圖,再生成程式碼。其 CLI 將藍圖傳送至 GPT-4o,可生成架構計劃、UML 圖及 C#、Rust 或 Python 程式碼;項目目前處於早期 Alpha 階段。
We all use ChatGPT, Claude, or Copilot to write code. It's great for simple scripts. But the moment you ask for a real Enterprise microservice (with Kafka, Redis, and Saga patterns), the AI gives you a massive wall of text.
You spend hours reviewing it, fixing missing dependencies, wiring up DI, and realizing it wrote an insecure SQL query.
I got so frustrated with this that I started asking a different question: What if I don't ask the AI to write code, but ask it to compile a strict architectural blueprint?
That's how tommylang was born.
🏛 What is tommylang?
It's an AI-native DSL with a custom file extension (.ty). You don't write public class UserService or async Task. You write pure intent.
Here is an example of a payment endpoint in Tommy:
[Saga]
[Outbox]
[Idempotent(key = 'order_id')]
[REST('/api/payments')]
[Auth(oauth2 = 'client_credentials')]
create_payment (@order_dto order) {
? order.amount <== 0.0 {
<= bad_request('Amount must be greater than zero')
}
@db.query('INSERT INTO payments ...', { id = order.id })
[Event('payment_created')].publish({ id = order.id })
<= created('Payment processed')
}
When you run our CLI (tommycli), it sends this to GPT-4o with a strict System Prompt. The AI doesn't just write code; it generates a <pre-flight> architecture plan, UML diagrams, and idiomatic C#, Rust, or Python.
🚀 The Coolest Features
Here is what makes tommylang different from "just a prompt":
1. Semantic Typography (TommyColor)
We designed a custom VS Code theme where color represents architecture, not just syntax. Purple is for logic (if, return), Green is for Classes/Interfaces, Blue is for Functions, and White is for Variables. Code reviews become 10x faster.
2. Built-in Enterprise Patterns
You don't need to explain to the AI what a Saga or Circuit Breaker is. You just use [Saga] or [CircuitBreaker]. The prompt forces the AI to generate the exact framework implementations (e.g., MassTransit for C#, or Polly).
3. Polyglot by Design
Write once, compile anywhere. Tommy targets C#, Python, Rust, Go, PHP, and TypeScript. Because the blueprint is abstract, the AI doesn't carry over C#-specific boilerplate into Rust.
4. OS-Level & AI-Agents
It's not just for web dev. We have annotations for [Ring(0)] (bare-metal Rust #![no_std]) and [Agent] (LangChain / CrewAI integration).
🧠 How it works under the hood
Tommy uses the "prompt-as-compiler" approach. The entire logic lives in a single System Prompt (COMPILER_PROMPT.md).
It enforces strict rules: snake_case for functions, = for all data, and : only for logic. If the AI hallucinates, the prompt forces it to fail the AST dry-run.
🛠 Try it out
The project is in early Alpha, but you can test the VS Code theme and the CLI right now.
- VS Code Theme: TommyColor
- GitHub Repo: tommylang
I'd love to hear your thoughts. Is this something you would use for your next microservice, or is it overengineering? Let me know in the comments!
來源:DEV Community · dev.to