Release ClosedBit library catalog

Libraries

Browse shipped Coding Suite libraries, inspect callable surfaces, and copy real `.cbp` library code.

Source browser

Open a library and copy the code.

Usage docs explain how to call libraries; this page shows the actual `.cbp` source files.

studio/CB-Action.cbp
library CB-Action;

fn CB-Action.ready(u256 frame, u256 cooldownFrames, u256 lastFrame) -> bool {
    return frame >= lastFrame + cooldownFrames;
}

fn CB-Action.force_passes(f64 incomingForce, f64 threshold) -> bool {
    return incomingForce >= threshold;
}

fn CB-Action.triggered(bool input, f64 incomingForce, f64 threshold, i256 health) -> bool {
    if (input) { return true; }
    if (incomingForce >= threshold) { return true; }
    return health <= 0;
}

Developer recipes

What a dev can reasonably build with these libraries.

Use these as starting points when choosing a library. Each recipe maps to source files and examples on this page.

Local tool API

Use `CB-Networking.API` to match `method + path`, verify a bearer token, and return structured ClosedBit responses for launchers, local tools, and test harnesses.

External service call

Use `CB-Networking.HTTP.get_or()` for a runtime-backed GET with an offline fallback, then inspect the response with string helpers before continuing.

Save and reload app state

Use `CB-Storage` for validated `.cb` saves and `CB-AssetLoader` for files the app ships with, keeping mutable save data separate from bundled assets.

Indexed AI retrieval

Use `CB-GenerationOptimized` with `CB-Parsing` and `CB-Understanding` when the app needs tagged retrieval instead of brute-force text scanning.

Source locations

Every Coding Studio library source file.

The website mirrors the same `.cbp` files installed with ClosedBit Coding Studio, so developers can inspect the callable surface before building.

Shipped library sources
Installed source browser: ClosedBit Studio > Docs > Libraries
Website mirror: /docs/libraries/source/studio/

Coding Suite libraries:
CB-Action.cbp
CB-AI.Heuristics.cbp
CB-AI.Pattern.cbp
CB-AI.Search.cbp
CB-AssetLoader.cbp
CB-Audio.cbp
CB-Bit.cbp
CB-Breakable.cbp
CB-Cache.Local.cbp
CB-Console.cbp
CB-Data.cbp
CB-Data.CSV.cbp
CB-Data.TOML.cbp
CB-Data.XML.cbp
CB-Data.YAML.cbp
CB-Database.Local.cbp
CB-FileSystem.Path.cbp
CB-FileSystem.Storage.cbp
CB-FileSystem.Watch.cbp
CB-Generation.cbp
CB-Generation.Image.cbp
CB-Generation.Response.cbp
CB-Generation.Text.cbp
CB-GenerationOptimized.cbp
CB-GPU.cbp
CB-Graphics.2D.cbp
CB-Graphics.3D.cbp
CB-Graphics.Font.cbp
CB-Library.Compression.cbp
CB-Library.Config.cbp
CB-Library.Cryptography.cbp
CB-Library.DataStructures.cbp
CB-Library.Logging.cbp
CB-Library.Serialization.cbp
CB-Library.Testing.cbp
CB-Library.Validation.cbp
CB-Math.Basic.cbp
CB-Math.cbp
CB-Math.Linear.cbp
CB-Math.Random.cbp
CB-Multimedia.Audio.cbp
CB-Multimedia.Image.cbp
CB-Multimedia.Video.cbp
CB-Network.cbp
CB-Networking.API.cbp
CB-Networking.DNS.cbp
CB-Networking.HTTP.cbp
CB-Networking.Socket.cbp
CB-Networking.WebSocket.cbp
CB-Parsing.cbp
CB-Pathfinding.cbp
CB-Physics.cbp
CB-Render.cbp
CB-Runtime.cbp
CB-Security.Auth.cbp
CB-Security.RateLimit.cbp
CB-Security.RBAC.cbp
CB-Shader.cbp
CB-Storage.cbp
CB-System.Env.cbp
CB-System.OS.cbp
CB-System.Timer.cbp
CB-TextToSpeech.cbp
CB-TextToSpeech.Voices.cbp
CB-Time.cbp
CB-Time.Scheduler.cbp
CB-UI.cbp
CB-Understanding.cbp
CB-Understanding.Image.cbp
CB-Understanding.Language.cbp
CB-Understanding.Logic.cbp

Examples

Copy-paste library examples. 93

These are real mirrored `.cbp` examples from the shipped example tree. Open the full examples index, or copy the starter blocks below into Studio.

Create a local API handler
library CB-Console;
library CB-Networking.API;
library CB-Networking.HTTP;

fn main() {
    string requestMethod = "GET";
    string requestPath = "/support/status";
    string expectedToken = "dev-token";
    string authHeader = CB-Networking.HTTP.bearer(expectedToken);

    bool routeOk = CB-Networking.API.match(requestMethod, requestPath, "GET", "/support/status");
    bool authOk = CB-Networking.API.require_token(authHeader, expectedToken);

    if (!routeOk) {
        println(CB-Networking.API.error(404, "route not found"));
        return;
    }

    if (!authOk) {
        println(CB-Networking.API.error(401, "missing or invalid token"));
        return;
    }

    string body = "support=online;queue=2;priority=normal";
    println("Route: " + CB-Networking.API.route(requestMethod, requestPath));
    println("Response: " + CB-Networking.API.ok(body));
}

Teaches: route matching, bearer-token checks, 404/401 fallbacks, and success responses for local API-style handlers.

Connect to an external API
library CB-Console;
library CB-Networking.HTTP;

fn main() {
    string base = "https://closedbit.com";
    string url = CB-Networking.HTTP.endpoint(base, "/sitemap.xml");
    string fallback = "offline=true;source=fallback";
    string response = CB-Networking.HTTP.get_or(url, fallback);

    println("Request: " + CB-Networking.HTTP.cache_key("GET", url));
    println("Header: " + CB-Networking.HTTP.accept("application/xml"));
    println("Characters: " + len(response));

    if (string.contains(response, "<urlset")) {
        println("Connected: sitemap loaded");
    } else {
        println("Fallback: " + response);
    }
}

Teaches: endpoint joining, a real runtime-backed GET, offline fallback handling, request labeling, and response inspection.

Validated .cb save and load
library CB-Console;
library CB-Storage;

fn main() {
    string path = "closedbit-player-save.cb";
    string initial = "player=Ada;score=1250;level=4";

    CB-Storage.write_text(path, initial);
    string loaded = CB-Storage.read_text(path);

    println("ClosedBit Storage Round Trip");
    println("Exists: " + CB-Storage.exists(path));
    println("Loaded: " + loaded);
}
AI indexed generation retrieval
library CB-Console;
library CB-GenerationOptimized;
library CB-Parsing;
library CB-Understanding;

fn main() {
    string dataset = "examples/ai/shared-mini-dataset.txt";
    string index = "build/ai/shared-mini-dataset.cbi";

    CB-GenerationOptimized.build_index(dataset, index);
    u256 indexed = CB-GenerationOptimized.warm(index);
    array batches = CB-GenerationOptimized.query_batch(dataset, index, ["ai,gpu", "game,gpu", "storage,index"], 3);
    array records = batches[0];
    string picked = CB-GenerationOptimized.pick(dataset, index, "game,gpu", 256);

    println("ClosedBit Native Indexed Retrieval");
    println("Retrieval backend: " + CB-GenerationOptimized.last_backend());
    println("Indexed records: " + indexed);
    println("Matches: " + records.length());
    println("Picked: " + CB-Parsing.normalize(picked));
    println("AI score: " + CB-Understanding.score(picked, "gpu"));
    println("Native mapping hits: " + CB-GenerationOptimized.cache_hits());
    println("Native mapping misses: " + CB-GenerationOptimized.cache_misses());
    println("Native records scanned: " + CB-GenerationOptimized.records_scanned());
}
Direct3D GPU status
library CB-Console;
library CB-GPU;

fn main() {
    println("ClosedBit temporary Direct3D 12 GPU status");
    println("Available: " + CB-GPU.available());
    println("Driver: " + CB-GPU.name());
    println("Backend: " + CB-GPU.backend());
    println("VRAM visible MB: " + CB-GPU.vram_total_mb());
    println("Policy cap MB: " + CB-GPU.budget_mb());
}
Runtime cleanup and paging
library CB-Library;
library CB-Library.Graphics;
library CB-Library.Threaded;
library CB-Render;
library CB-Runtime;

fn main() {
    init_window(960, 540, "ClosedBit Runtime Memory Cleanup");
    set_background_color(0x071019);
    CB-Render.starfield(8_000, 1, 0xD7F9FF);
    CB-Render.particles(2_500, 1, 0x48D1CC, 0xFFBE55);
    CB-Render.cube_field(64, 1, 0x83E8FF);
    CB-Render.flush();
    println("Renderer before cleanup: " + CB-Render.backend());
    cleanup();

    array memory = CB-Runtime.cleanup_memory();
    println("Working set bytes: " + memory[0] + " -> " + memory[1]);
    println("Pageable committed bytes: " + memory[2] + " -> " + memory[3]);
    println("Private bytes: " + memory[4] + " -> " + memory[5]);
    println("Cleanup page faults: " + (memory[7] - memory[6]));
    u256 reuse_faults_before = CB-Runtime.page_fault_count();
    CB-Runtime.raw_kernel(2_000_000, 256);
    println("Hot reuse page faults: " + (CB-Runtime.page_fault_count() - reuse_faults_before));
}

All mirrored examples

Every link below opens a real `.cbp` example file under `/docs/libraries/examples/`.

ai (7)
apps (15)
benchmarks (10)
cbp (16)
complete (21)
external-physics (1)
games (17)
public (4)