Skip to content

Wolfe-Jam/faf-wasm-sdk

Repository files navigation

FAF WASM SDK v2

The compiler is the spec. 322KB of WASM. No server. No API calls. No dependencies.

Compile, score, and inspect FAF context — in any browser, edge runtime, or Node.js process. The same Rust code that runs on the CLI runs in your browser tab, in a Cloudflare Worker, in Node, in Bun. One source of truth. No reimplementation. No drift.

v2 — The Definitive Edition

v1 proved the concept: compile YAML to binary, score it, ship it to the edge. But v1 had 11 hardcoded section types. That works for a solo project. It breaks the moment an enterprise with 680 engineers, 62 teams, and custom compliance chunks tries to describe their repo.

v2 is the format we always wanted to ship. The FAF creator fell in love with IFF in the 90s — working with the Interchange File Format that Commodore created for the Amiga across early computer graphics engines and apps. That chunked binary architecture influenced everything that came after. Microsoft literally riffed on it with RIFF. IFF got it right the first time.

FAFb v2 brings that same architecture into the AI era: a string table replacing the fixed enum, the same pattern ELF and IFF have used for decades. FAF creator realized every YAML key can just become a named section. No limits. No "Unknown" fallback. No artificial ceiling.

This is a significant upgrade and it's free — the SDK is MIT, the format is an IANA-registered open standard, and the binary spec is public. We're making the standard bulletproof so everyone can build on it.

What v2 adds

  • Unlimited section names — any YAML key becomes a binary section (up to 256 per file)
  • Chunk classification — every section is automatically tagged as DNA (core identity), Context (supplementary), or Pointer (documentation references)
  • Enterprise scoring — 33-slot Mk4 engine with monorepo, compliance, and team structure support
  • Deterministic output — same YAML in, same binary out, every time (CRC32 sealed)

What stays the same

  • 32-byte header, 16-byte section entries — same wire layout
  • Same 8 JavaScript exports, same function signatures
  • Same sub-2ms parse + score performance
  • Priority truncation for context window management
  • IANA-registered application/vnd.faf+yaml input format

Installation

npm install faf-wasm-sdk

API

8 pure functions. No classes. JSON in, JSON out.

import init, {
  sdk_version,
  score_faf,
  score_faf_enterprise,
  validate_faf,
  compile_fafb,
  decompile_fafb,
  score_fafb,
  fafb_info
} from 'faf-wasm-sdk';

await init();

Score YAML

const result = JSON.parse(score_faf(yamlContent));
// { score: 71, tier: "🟢", populated: 15, total: 21, ... }

// Enterprise orgs: 33-slot scoring
const enterprise = JSON.parse(score_faf_enterprise(yamlContent));
// { score: 45, tier: "🟡", populated: 15, total: 33, ... }

Compile to Binary

const bytes = compile_fafb(yamlContent);   // Uint8Array
const json = decompile_fafb(bytes);        // JSON string with all sections + content
const info = fafb_info(bytes);             // JSON string, metadata only (no content)
const score = score_fafb(bytes);           // JSON string, score from embedded meta

Validate

validate_faf(yamlContent);  // true if valid YAML mapping

Edge Runtime

export default {
  async fetch(request) {
    await init();
    const score = score_faf(yamlContent);
    return Response.json(JSON.parse(score));
  }
};

Scoring

Mk4 engine — the same scorer that runs in the Rust SDK and CLI. Slot-based: each YAML key is a slot, populated slots are counted, placeholders and empty values are rejected.

Score Tier
100% 🏆 Championship
99% 🥇 Gold
95% 🥈 Silver
85% 🥉 Bronze
70% 🟢 Green
55% 🟡 Yellow
<55% 🔴 Red

Base scores against 21 slots. Enterprise scores against 33 (adds monorepo, compliance, team structure, and more).

FAFb Binary Format

The compiled output. YAML is source code, FAFb is the compiled binary.

HEADER (32 bytes)
  Magic: "FAFB"
  Version, flags, section count, CRC32 checksum

SECTION DATA (variable)
  Each YAML key → one section, priority-ordered

STRING TABLE (appended)
  Section name index — unlimited names, O(1) lookup

SECTION TABLE (at end)
  16 bytes per entry: name index, priority, offset, length, token count, classification

Every section carries a classification:

  • DNA — core project identity (project, tech_stack, commands, faf_version, ...)
  • Context — supplementary chunks (compliance, security, agents, custom fields, ...)
  • Pointer — documentation references (docs)

Build

cargo install wasm-pack
wasm-pack build --target web --release

# Tests
cargo test

Tests

138 tests across 4 suites:

  • Unit tests (90) — scoring, compilation, decompilation, edge cases
  • Stress tests (27) — YAML bombs, Unicode, large payloads, binary fuzzing
  • WASM integration (21) — public API surface through wasm-bindgen

If faf-wasm-sdk has been useful, consider starring the repo — it helps others find it.

License

MIT

Links


Get the CLI

faf-cli — The original AI-Context CLI. A must-have for every builder.

npx faf-cli auto

Anthropic MCP #2759 · IANA Registered: application/vnd.faf+yaml · faf.one · npm

About

WASM scoring kernel for FAF — Mk4 Championship Engine, FAFb binary compile/decompile. 281KB. IANA registered: application/vnd.faf+yaml

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors