KSB — Kernel Script for Bots
Ultra-dense scripting language for AI agents. Fewer tokens than Python for tool scripts. Compiles to Python 3.
@ max(a:i,b:i)->i {
? a>b { ^a } { ^b }
}
@ main()->i { ^ max(3,7) }
Dense form:
@max(a:i,b:i)->i{?a>b{^a}{^b}}
@main()->i{^max(3,7)}
Why KSB?
| Problem for agents | KSB |
|---|---|
| Long keywords burn tokens | @ ^ ? * # |
| Huge stdlib surface | Small agent runtime |
| Style noise | ksb fmt + rigid grammar |
| Silent type mistakes | ksb check optional types |
Paste KSB.md into an agent system prompt (~400 tokens).
Install
From PyPI (after first publish):
pip install ksb
ksb -V
From source:
git clone https://github.com/semihbalan/ksb.git
cd ksb
pip install -e ".[dev]"
ksb -V
CLI
ksb run examples/hello.ksb
ksb run examples/match.ksb
ksb run examples/use_mod.ksb
ksb run examples/agent_kit.ksb
ksb build app.ksb -o app.py
ksb fmt app.ksb # pretty-print to stdout
ksb fmt app.ksb -w # write back
ksb check app.ksb # typecheck
ksb parse app.ksb
ksb lex app.ksb
Language (cheat sheet)
| Syntax | Meaning |
|---|---|
@ f(a:i)->i { ... } |
function |
^ e |
return |
= x e |
bind |
? c {t} {f} |
if / else |
* c { ... } |
while |
* x:xs { ... } |
for-each |
# e { p => v; _ => v } |
match |
a | f |
pipe → f(a) |
~ fs / ~ "lib/mathx" |
import runtime or local .ksb |
T F N |
true / false / null |
Patterns: _ · literals · bind n · [h,*t] · {ok:T, msg:m}
Types (optional): i f s b l m a
Runtime modules
| Module | Highlights |
|---|---|
fs |
read, write, exists, list, mkdir, remove, copy, cwd |
http |
get, post, put, delete, get_json, post_json |
json |
parse, dump |
sh |
run |
env |
get, set |
log |
info, err |
time |
now, ms, sleep, iso |
path |
join, dirname, basename, abs, ext |
cli |
args, argc, arg |
str |
split, join, trim, replace, contains, lower, upper |
tool |
ok, err, wrap — agent result shapes |
Local modules
// lib/mathx.ksb
@ add(a:i,b:i)->i { ^ a+b }
// app.ksb
~ "lib/mathx"
@ main()->i { ^ add(1,2) }
Functions from imported .ksb files are inlined at compile time (no main import).
Architecture
.ksb → lex → parse → [bundle local mods] → [typecheck] → codegen → Python 3
↓
ksb.runtime (agent stdlib)
Development
pip install -e ".[dev]"
pytest -q
CI runs on every push (Python 3.10–3.13). See CONTRIBUTING.md and docs/publishing.md for release / PyPI.
Topics
ai · agents · compiler · language · llm · python · transpiler
License
MIT — free for humans and agents.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ksb-0.2.0.tar.gz.
File metadata
- Download URL: ksb-0.2.0.tar.gz
- Upload date:
- Size: 28.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
392fc337e8b0ac0cb98c6f99108a4359f2417b6a24abcec84926eed2514e42e7
|
|
| MD5 |
0681e82e2ac2b2cc119fac28495e1d52
|
|
| BLAKE2b-256 |
38ea19d88c626409f3531fb75b429ab3e6f23df5c598a6f99a67d62694f2a68b
|
Provenance
The following attestation bundles were made for ksb-0.2.0.tar.gz:
Publisher:
publish.yml on semihbalan/ksb
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ksb-0.2.0.tar.gz -
Subject digest:
392fc337e8b0ac0cb98c6f99108a4359f2417b6a24abcec84926eed2514e42e7 - Sigstore transparency entry: 2399795955
- Sigstore integration time:
-
Permalink:
semihbalan/ksb@538fa572bea1195d71fe9268788ad06baaa66b99 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/semihbalan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@538fa572bea1195d71fe9268788ad06baaa66b99 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file ksb-0.2.0-py3-none-any.whl.
File metadata
- Download URL: ksb-0.2.0-py3-none-any.whl
- Upload date:
- Size: 28.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ea5c6640f849951faf498eb7e7d8a042d6906e35ae552282e5f4e3909463637
|
|
| MD5 |
0c1d000c3d18627341a0e32d574e9af4
|
|
| BLAKE2b-256 |
312f7f2cc8bd5ab63d5f76bd4c7db76a551a8de75e31956901228f073b4954c8
|
Provenance
The following attestation bundles were made for ksb-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on semihbalan/ksb
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ksb-0.2.0-py3-none-any.whl -
Subject digest:
6ea5c6640f849951faf498eb7e7d8a042d6906e35ae552282e5f4e3909463637 - Sigstore transparency entry: 2399796060
- Sigstore integration time:
-
Permalink:
semihbalan/ksb@538fa572bea1195d71fe9268788ad06baaa66b99 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/semihbalan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@538fa572bea1195d71fe9268788ad06baaa66b99 -
Trigger Event:
workflow_dispatch
-
Statement type: