Skip to content

Commit 8a9e8cf

Browse files
feat: initial tomllm crate — standalone polyglot release
Rust core + WASM + Python (pyo3) bindings for TOML+LLM comment conventions. CI: crates.io, PyPI (maturin), npm (wasm-pack) publish on main push. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
0 parents  commit 8a9e8cf

15 files changed

Lines changed: 1497 additions & 0 deletions

.github/workflows/python-ci.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Python CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: actions/setup-python@v5
15+
with:
16+
python-version: "3.11"
17+
- name: Build wheel
18+
uses: PyO3/maturin-action@v1
19+
with:
20+
command: build
21+
args: --features python --release --out dist
22+
manylinux: auto
23+
- name: Upload wheel artifact
24+
uses: actions/upload-artifact@v4
25+
with:
26+
name: wheels-linux
27+
path: dist/
28+
29+
publish-pypi:
30+
needs: build
31+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
32+
runs-on: ubuntu-latest
33+
steps:
34+
- uses: actions/download-artifact@v4
35+
with:
36+
name: wheels-linux
37+
path: dist/
38+
- name: Publish to PyPI
39+
uses: PyO3/maturin-action@v1
40+
with:
41+
command: upload
42+
args: --non-interactive --skip-existing dist/*
43+
env:
44+
MATURIN_PYPI_TOKEN: ${{ secrets.MATURIN_PYPI_TOKEN }}

.github/workflows/rust-ci.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Rust CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: actions-rs/toolchain@v1
15+
with:
16+
toolchain: stable
17+
override: true
18+
- run: cargo test --all-features
19+
20+
publish-crate:
21+
needs: test
22+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v4
26+
- uses: actions-rs/toolchain@v1
27+
with:
28+
toolchain: stable
29+
override: true
30+
- run: cargo publish --token ${{ secrets.CRATESIO_API_TOKEN }}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: TypeScript / WASM CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
wasm-build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: actions-rs/toolchain@v1
15+
with:
16+
toolchain: stable
17+
override: true
18+
target: wasm32-unknown-unknown
19+
- name: Install wasm-pack
20+
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
21+
- name: Build WASM (bundler)
22+
run: wasm-pack build --target bundler --features wasm --out-dir pkg
23+
- name: Build WASM (nodejs)
24+
run: wasm-pack build --target nodejs --features wasm --out-dir pkg-nodejs
25+
- name: Upload WASM artifacts
26+
uses: actions/upload-artifact@v4
27+
with:
28+
name: wasm-pkg
29+
path: pkg/
30+
31+
publish-npm:
32+
needs: wasm-build
33+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
34+
runs-on: ubuntu-latest
35+
steps:
36+
- uses: actions/checkout@v4
37+
- uses: actions/setup-node@v4
38+
with:
39+
node-version: "20"
40+
registry-url: "https://registry.npmjs.org"
41+
- uses: actions/download-artifact@v4
42+
with:
43+
name: wasm-pkg
44+
path: pkg/
45+
- name: Publish to npm
46+
run: npm publish --access public
47+
env:
48+
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/target/
2+
/dist/
3+
/pkg/
4+
/pkg-nodejs/
5+
**/*.rs.bk
6+
.env
7+
Cargo.lock

Cargo.toml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
[package]
2+
name = "tomllm"
3+
version = "0.1.0"
4+
edition = "2024"
5+
description = "TOML + LLM comment conventions: tribal knowledge in #comments, stripped for data pipelines"
6+
license = "MIT"
7+
repository = "https://github.com/PromptExecution/tomllm"
8+
keywords = ["toml", "llm", "agent", "config", "annotations"]
9+
categories = ["parsing", "config", "text-processing"]
10+
readme = "README.md"
11+
12+
[lib]
13+
name = "tomllm"
14+
crate-type = ["cdylib", "rlib"] # cdylib for WASM/Python, rlib for Rust consumers
15+
16+
[features]
17+
default = []
18+
# 🤓 wasm: enables wasm-bindgen exports for TypeScript/JS consumers
19+
wasm = ["wasm-bindgen", "serde-wasm-bindgen"]
20+
# 🤓 python: pyo3 extension-module bindings (maturin build --features python)
21+
python = ["pyo3/extension-module"]
22+
23+
[dependencies]
24+
serde = { version = "1", features = ["derive"] }
25+
serde_json = "1"
26+
toml = "0.9"
27+
regex = "1"
28+
thiserror = "2"
29+
30+
[dependencies.wasm-bindgen]
31+
version = "0.2"
32+
optional = true
33+
34+
[dependencies.serde-wasm-bindgen]
35+
version = "0.6"
36+
optional = true
37+
38+
[dependencies.pyo3]
39+
version = "0.23"
40+
optional = true
41+
features = ["extension-module"]
42+
43+
[dev-dependencies]
44+
tempfile = "3"

README.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# tomllm
2+
3+
TOML + LLM comment conventions: tribal knowledge in `#comments`, stripped for data pipelines.
4+
5+
## Overview
6+
7+
`.tomllm` files are **valid TOML** with enriched `#` comment semantics:
8+
9+
- Comments associate with the next key-value pair or section header
10+
- Special prefixes encode tribal knowledge: `# 🤓`, `# @tribal:`, `# @example:`, `# @requires:`
11+
- Tail-map block (last ≤10 lines): fast executive agent scanning without full context load
12+
- Comments are FOR agents reading the **source file** as documentation — strip them for downstream pipelines
13+
14+
## Cognitive Tiers
15+
16+
Each `.tomllm` file MAY declare its required cognitive tier in the tail-map:
17+
18+
| Tier | Models | Tasks |
19+
|------|--------|-------|
20+
| `sm0l` | qwen2.5-3B, haiku | classify, route, grep, format |
21+
| `ch0nky` | qwen3-coder (local) | implement, refactor, debug |
22+
| `frontier` | claude-opus/sonnet | architecture, security, novel design |
23+
24+
## Example
25+
26+
```toml
27+
# @tribal: always use uv pip, never pip install directly
28+
# @example: uv pip install requests
29+
package_manager = "uv"
30+
31+
# b00t:map v1
32+
# summary: Python toolchain config
33+
# tags: python, uv
34+
# tier: sm0l
35+
# complexity: 2
36+
```
37+
38+
## Usage
39+
40+
### Rust
41+
42+
```rust
43+
use tomllm::TomllmDoc;
44+
45+
let doc = TomllmDoc::parse(input)?;
46+
let clean_json = doc.strip_for_pipeline(); // stripped TOML as JSON
47+
let tier = doc.cognitive_tier(); // sm0l / ch0nky / frontier
48+
let map = doc.map_block; // Option<MapBlock>
49+
```
50+
51+
### Python (maturin)
52+
53+
```python
54+
from tomllm import TomllmDoc, MapBlock
55+
56+
doc = TomllmDoc.parse(text)
57+
print(doc.cognitive_tier()) # "sm0l"
58+
print(doc.strip_for_pipeline()) # JSON string
59+
60+
block = MapBlock.from_text(text)
61+
if block:
62+
print(block.summary, block.tier, block.tags)
63+
```
64+
65+
### TypeScript / WASM
66+
67+
```typescript
68+
import init, { TomllmDoc } from '@promptexecution/tomllm';
69+
70+
await init();
71+
const doc = TomllmDoc.parse(text);
72+
```
73+
74+
## Install
75+
76+
```bash
77+
# Rust
78+
cargo add tomllm
79+
80+
# Python
81+
pip install tomllm
82+
83+
# npm
84+
npm install @promptexecution/tomllm
85+
```
86+
87+
## Tail-map format
88+
89+
```toml
90+
# b00t:map v1
91+
# summary: one-line human+LLM description
92+
# tags: comma, separated, keywords
93+
# tier: sm0l|ch0nky|frontier
94+
# cmds: b00t hive activate inference-qwen3, b00t hive status
95+
# complexity: 1-10
96+
```
97+
98+
## License
99+
100+
MIT
101+
102+
<!-- b00t:map v1
103+
summary: tomllm — TOML + LLM comment conventions crate
104+
tags: toml, llm, agent, config, annotations, wasm, python
105+
tier: sm0l
106+
cmds: cargo test, maturin build --features python, wasm-pack build
107+
complexity: 3
108+
-->

package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "@promptexecution/tomllm",
3+
"version": "0.1.0",
4+
"description": "TOML + LLM comment conventions: tribal knowledge in #comments, stripped for data pipelines",
5+
"main": "pkg/tomllm.js",
6+
"types": "pkg/tomllm.d.ts",
7+
"files": ["pkg/"],
8+
"license": "MIT",
9+
"repository": {
10+
"type": "git",
11+
"url": "https://github.com/PromptExecution/tomllm"
12+
},
13+
"scripts": {
14+
"build": "wasm-pack build --target bundler --features wasm",
15+
"build:nodejs": "wasm-pack build --target nodejs --features wasm"
16+
}
17+
}

pyproject.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[build-system]
2+
requires = ["maturin>=1.4,<2.0"]
3+
build-backend = "maturin"
4+
5+
[project]
6+
name = "tomllm"
7+
requires-python = ">=3.9"
8+
description = "TOML + LLM comment conventions: tribal knowledge in #comments, stripped for data pipelines"
9+
license = { text = "MIT" }
10+
classifiers = [
11+
"Programming Language :: Rust",
12+
"Programming Language :: Python",
13+
"Topic :: Software Development :: Libraries",
14+
]
15+
16+
[tool.maturin]
17+
features = ["python"]
18+
module-name = "tomllm"

src/lib.rs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
//! # tomllm
2+
//!
3+
//! TOML + LLM comment conventions.
4+
//!
5+
//! `.tomllm` files are **valid TOML** with enriched `#` comment semantics:
6+
//! - Comments associate with the next key-value pair or section header
7+
//! - Special prefixes encode tribal knowledge: `# 🤓`, `# @tribal:`, `# @example:`, `# @requires:`
8+
//! - Tail-map block (last ≤10 lines): fast executive agent scanning without full context load
9+
//!
10+
//! ## Design principle
11+
//! Comments are FOR agents reading the **source file** as documentation.
12+
//! When passing data VALUES downstream (to pipelines or further LLMs), strip comments
13+
//! to minimize token usage. The recipient gets clean TOML; the source stays rich.
14+
//!
15+
//! ## Cognitive tier
16+
//! Each `.tomllm` file MAY declare its required cognitive tier in the tail-map:
17+
//! - `sm0l` — any small model can process this (classify, route, format)
18+
//! - `ch0nky` — requires code-generation capable model (implement, refactor)
19+
//! - `frontier` — requires frontier reasoning (architecture, security, compliance)
20+
//!
21+
//! ## Example
22+
//! ```toml
23+
//! # @tribal: always use uv pip, never pip install directly
24+
//! # @example: uv pip install requests
25+
//! package_manager = "uv"
26+
//!
27+
//! # b00t:map v1
28+
//! # summary: Python toolchain config
29+
//! # tags: python, uv
30+
//! # tier: sm0l
31+
//! ```
32+
33+
use std::collections::BTreeMap;
34+
use thiserror::Error;
35+
36+
#[cfg(feature = "wasm")]
37+
use wasm_bindgen::prelude::*;
38+
39+
pub mod loader;
40+
pub mod map_block;
41+
pub mod parser;
42+
pub mod registry;
43+
pub mod stripper;
44+
45+
#[cfg(feature = "python")]
46+
pub mod python;
47+
48+
pub use loader::{load_any_typed, load_first, load_typed, resolve_path};
49+
pub use map_block::{CognitiveTier, MapBlock};
50+
pub use parser::TomllmDoc;
51+
pub use registry::TomllmRegistry;
52+
// 🤓 define_typed_registry! is #[macro_export] — already at crate root; no pub use needed
53+
54+
#[cfg(feature = "python")]
55+
use pyo3::prelude::*;
56+
57+
/// Python module entry point — called by maturin-generated C extension
58+
#[cfg(feature = "python")]
59+
#[pymodule]
60+
fn tomllm_py(m: &Bound<'_, PyModule>) -> PyResult<()> {
61+
python::tomllm(m)
62+
}
63+
64+
#[derive(Debug, Error)]
65+
pub enum TomllmError {
66+
#[error("TOML parse error: {0}")]
67+
TomlParse(#[from] toml::de::Error),
68+
#[error("IO error: {0}")]
69+
Io(#[from] std::io::Error),
70+
#[error("Map block parse error: {0}")]
71+
MapBlock(String),
72+
}
73+
74+
pub type Result<T> = std::result::Result<T, TomllmError>;

0 commit comments

Comments
 (0)