0

Kyn-ngôn ngữ mới cho AI Agents và sự tiện lợi

Kyn

Github:https://github.com/tranhuykhang31032013-koocbiet/Kyn

Zero-Docker Python-Ergonomic Sandbox Runtime for AI Agents & Edge Plugins — running natively on Node.js, Browsers, and WebAssembly with capability-based policies, @wasm hybrid JIT offload, execution tracing, and deterministic resource budgets.

Kyn CI CodeQL Deploy Kyn Playground npm version Version License: MPL 2.0

Live Playground (Zero-Install ESM + WASM): https://tranhuykhang31032013-koocbiet.github.io/Kyn/playground/
Docs: Language Spec · Embedding Guide · FAQ · Security · Contributing · Tiếng Việt


Why Kyn?

Most embeddable scripting languages force a trade-off between ergonomics, safety, and portability. Kyn is built from scratch in pure ESM JavaScript with:

  1. Hardened Sandboxed VM (--sandbox, --max-steps, --max-frames, --max-memory): Deterministic execution budgets prevent infinite loops, stack overflows, and OOM payloads (E_MEMORY_LIMIT) before crashing the host process.
  2. Zero-Dependency WebAssembly Compiler (kyn wasm / --target wasm): Compiles numeric (i32/f64), loop (for range with step, while), recursive, array-buffer, logical (and/or), ternary, and print workloads directly to .wasm binaries without LLVM or Emscripten.
  3. Rust/Elm-Style Multi-Line Diagnostics & Optimizer: Multi-line context code frames with caret spans, Levenshtein "did you mean" hints, automatic error-code tips, constant/comparison folding, null-coalescing folding, and peephole optimization (--opt).
  4. Polyglot Syntax & Bidirectional Translation (vi ↔ en): Write Python-ergonomic code in English or Vietnamese (Unicode NFC/NFD-safe) and translate source files cleanly while preserving comments, strings, and dot-attributes.
  5. Runs Everywhere with Zero Python Dependency: Execute on Node.js (npx kyn-engine), browsers, or .wasm. Need ML/Data Science? Install the optional kyn-lang Python & AI Bridge (pip install kyn-lang).

30-Second Quickstart

1. Standalone Engine (kyn-engine on Node.js >= 18, no Python required)

# Run directly via npx or global install
npm install -g kyn-engine
kyn init my-app
kyn my-app/main.kyn

# Or run from source
node engine/cli.mjs init my-app
node engine/cli.mjs my-app/main.kyn

# Compile to WebAssembly (.wasm)
node engine/cli.mjs wasm demo_samples/demo_independent_engine.kyn -o app.wasm

# Run untrusted code safely with `ky` shortcuts & readable units
ky s -W -O --mem 64m --steps 5m --time 500ms my-app/main.kyn

# Lint, format, test, and switch diagnostic locale (en default, or vi)
node engine/cli.mjs lint my-app/main.kyn
node engine/cli.mjs --lang vi --help

2. Optional Python & AI Bridge (kyn-lang)

pip install kyn-lang
kyn demo_samples/demo_ai_neural_net.kyn
kyn translate demo_samples/demo_modern_syntax.kyn --from vi --to en

3. VS Code Extension

Open editors/vscode/ in VS Code for bilingual TextMate syntax highlighting (source.kyn) and live JSON-RPC LSP integration (diagnostics, completion, hover, definition, references, semanticTokens).


Benchmarks

Measured with node scripts/bench/run_bench.mjs --json on Node.js v18.20.4 (linux x64, Intel(R) Xeon(R) Platinum 8481C) and Python 3.11.2, median of 7 runs after 3 warmups:

Workload Kyn WASM (kyn wasm) Kyn Hybrid (@wasm) Node.js V8 (JS) Python 3.11 Kyn Stack VM Peak RSS / Heap
fib(25) recursive 0.558 ms 4.542 ms 0.759 ms 8.72 ms 269.54 ms (5,462,673 steps) 78.2 MB / 6.3 MB
sum(range(900_000)) loop 0.306 ms 1.304 ms 0.607 ms 21.58 ms 498.93 ms (9,000,017 steps) 80.2 MB / 13.1 MB

Inline micro-benchmark (node engine/cli.mjs bench --json, sum(i*i for i in range(10000)) BigInt): 7.34 ms median.


Testing & Verification

npm run lint
npm test
python -m pytest -q
ruff check .
python scripts/build_single.py && python scripts/build_single.py --check
python scripts/build_single_ml.py && python scripts/build_single_ml.py --check
node scripts/bench/run_bench.mjs --json

All rights reserved

Viblo
Hãy đăng ký một tài khoản Viblo để nhận được nhiều bài viết thú vị hơn.
Đăng kí