Jac Programming Language Documentation

repository·main·Indexed 20 days ago

https://github.com/jaseci-labs/jac

Jac is a high-level, synechic, and topokinetic programming language that compiles a single Python-like syntax into Python bytecode, JavaScript, and native machine code. It features the 'jac ninja' editor with a built-in coding agent, byLLM for Meaning Typed Programming (MTP) and AI integration, and the jac-mcp server for AI-assisted development. The ecosystem includes a wasm_rt runtime for self-contained WebAssembly modules and CEF client targets for native desktop applications.

Tokens
396.2K
Snippets
1.2K
Records
1.5K
Agent score
67%

What's inside Jac

  1. Overview of Jac language features

    main

    Jac is a programming language designed for humans and AI to build together. It uses a Python-like syntax and compiles to Python bytecode, JavaScript, and native machine code. Key features include:

    • Full-Stack Single Codebase: Frontend, backend, and data models are managed under one type checker.
    • Reduced Boilerplate: The compiler automatically generates API endpoints, route tables, ORM models, validation, serializers, and migrations.
    • Integrated AI: AI interactions are treated as typed function calls where the compiler builds prompts from function signatures and enforces return types.
    • Built-in Persistence: Objects persist automatically without requiring manual database setup, ORMs, or migrations.
    • Cloud Deployment: Use jac start --scale to build images and provision clusters (e.g., Kubernetes) without writing Dockerfiles or YAML.
  2. Overview of the jac single-binary launcher

    main

    The jac executable is a self-contained, single-binary launcher built with Zig. It consists of a tiny native launcher and a private CPython runtime appended as a payload.

    Key features:

    • Zero Dependencies: It requires no system Python, uv, or pip at install or runtime.
    • Runtime Loading: Instead of static linking, the launcher uses dlopen to load a bundled libpython at runtime. This allows the interpreter to load C extensions from the lib-dynload/ directory on demand.
    • Isolated Environment: The launcher configures the interpreter using PEP 741 init configuration (home / pythonpath_env) rather than relying on PYTHONHOME or PYTHONPATH environment variables, preventing accidental inheritance from the user's shell.
  3. Overview of Jac Language and Capabilities

    main

    The Jac technical reference is organized into several core domains:

    Language

    Covers syntax, types, variables, control flow, and advanced features like Object-Spatial Programming (OSP) (nodes, edges, walkers), Concurrency (async/await, flow/wait), and Gradual Borrow Checking (ownership/borrowing).

    Capabilities and Plugins

    • byLLM: Built-in capability for by llm(), model configuration, and agentic patterns.
    • Scale: Built-in production serving, storage, and Kubernetes support.
    • jac-client: Plugin for web/PWA/mobile targets, routing, and auth.
    • jac-desktop: Plugin for native desktop windows and sidecar bundling.

    Python Integration

    Jac supports high interoperability with Python, including importing Python packages, using Jac from pure Python via jaclang.lib or jac2py, and importing from PyPI or npm.

  4. Overview of the `jac` CLI

    main

    The jac command is the unified interface for the entire Jac development lifecycle. It replaces several specialized tools by combining the functionality of python, pip, pytest, black, and flask into a single binary.

    Key capabilities include:

    • Execution: Running programs and walkers (jac run).
    • Development: Type-checking (jac check), formatting (jac fmt), and linting (jac check --lint).
    • Dependency Management: Installing, removing, and updating packages (jac install, jac remove, jac update).
    • Deployment & Servers: Starting API servers (jac start) and deploying to Kubernetes via the scale subsystem (jac start --scale).
    • Build & Distribution: Compiling native binaries (jac nacompile) or building distributable artifacts like .jab, wheel, or npm packages (jac build).
    • AI Integration: Using the byLLM subsystem for local models (jac model) or interactive coding agents (jac ai).

    All commands feature built-in, colorful Rich-style output with themes, panels, and spinners.

  5. Overview of Jac language capabilities

    main

    Jac is a multi-target programming language designed for AI agents and modern distributed systems. Key features include:

    • Multi-Target Compilation: Compiles to Python bytecode, JavaScript, and native machine code (C-ABI compatible). This allows direct use of PyPI, npm, and native C libraries without interop wrappers.
    • AI-Native Constructs: Allows replacing code blocks with generative AI models directly within the language syntax, abstracting away prompt engineering.
    • Persistence and User Abstractions: Built-in reasoning for persistence and users as language-level constructs, allowing code to run seamlessly from local terminals to distributed cloud environments.
    • Modern Syntax: Includes modern operators, new comprehension forms, and a module organization that separates declarations from implementations.
  6. Overview of jac-mcp

    main

    jac-mcp is a Model Context Protocol (MCP) server designed for AI-assisted Jac development. It enables AI assistants to write, validate, format, and debug Jac code by exposing:

    • Grammar specifications
    • Documentation
    • Code examples
    • Compiler tools
    • Prompt templates

    The server implements JSON-RPC 2.0 over stdio, streamable-HTTP, and SSE using only the Python standard library, ensuring it has no third-party dependencies.

  7. Structure of a web-static Jac project

    main

    When creating a project with jac create myapp --kind web-static, the following directory structure is scaffolded:

    • main.jac: The entry point containing the client application.
    • jac.toml: The auto-generated project configuration.
    • components/: A directory for client components (e.g., Button.jac).
    • assets/: Directory for static assets.
    • README.md: Project documentation.
    • AGENTS.md: Documentation specifically for AI coding agents.
    • .gitignore: Git exclusion rules.
  8. Summary of Jac Concepts learned in the AI Day Planner Tutorial

    main

    The AI Day Planner tutorial covers a comprehensive range of Jac features categorized into Data & Types, Graph operations, Functions, Walkers, Frontend, Structure, and Auth. Use these concepts to build full-stack, AI-integrated, graph-based applications.

    Data & Types

    • node, edge, obj, enum: Core data structures.
    • has: Declares fields/properties within a type.
    • glob: Pattern matching/globbing.
    • sem: Semantic types for AI integration.
    • Type annotations and unions (e.g., str | None).

    Graph Operations

    • root: The entry point for per-user isolation.
    • ++>: Creates and connects a node.
    • +>: Edge :+>: Creates a typed edge.
    • [root-->]: Query syntax to traverse from root.
    • [?:Type]: Filter nodes by type.
    • jid(): Retrieves a node's unique identity.
    • del: Deletes a node or edge.

    Functions

    • def: Standard function declaration.
    • def:pub / def:priv: Visibility modifiers for public and private functions.
    • by llm(): Delegates function execution to a Large Language Model.
    • lambda: Anonymous functions.
    • async/await: Asynchronous execution.

    Walkers (Object-Spatial Programming)

    • walker: Defines a walker for graph traversal.
    • walker:priv: Private walker.
    • can with Type entry/exit: Defines abilities for a walker when entering or exiting a specific type.
    • visit, here, self, visitor: Keywords for managing traversal state and context.
    • report, disengage, spawn: Control flow for walkers.

    Frontend & Structure

    • JsxElement: UI component type.
    • import from: Automatically bridges server-side code into the client.
    • impl: Used for the declaration/implementation split.
    • reactive has: Enables reactive UI updates based on property changes.

    Authentication

    • jacSignup, jacLogin, jacLogout, jacIsLoggedIn: Built-in authentication primitives.
  9. Understand the Bundled Native Standard Library (`na_stdlib`)

    main

    The na_stdlib is a collection of pure-Jac (.jac) modules shipped with jaclang. It provides a Python-congruent standard library specifically for the native (na) compiler pathway.

    It operates via Mechanism B: these modules are ordinary Jac files that are compiled and linked exactly like user code, requiring no specialized backend work per module. This allows the native compiler to use the same cross-module machinery (binding population, extern forward-decl, and link_in) used by standard Jac code.

  10. Understand the Jac UI project structure

    main

    A standard Jac client-side application follows this directory layout:

    • jac.toml: Project configuration file.
    • main.jac: The main entry point for the application.
    • components/: Directory containing reusable .jac component files.
    • assets/: Directory for static assets like images and fonts.
    • build/: The directory where build outputs are generated.
  11. Build for multiple deployment targets with jac-client

    main

    The jac-client architecture allows you to build for various targets from a single codebase. Use the --client flag with jac build to specify your target.

    TargetCommandOutputSetup Required
    Web (default)jac build.jac/client/dist/No
    Desktop (native webview)jac build --client desktopSingle binary under .jac/client/desktop/No
    CEF (Chromium)jac build --client cefCEF bundle under .jac/client/cef/No
    Mobile (Capacitor)jac build --client mobile --platform androidAndroid APK / iOS build productsYes
    React Native (beta)jac build --client react-native --platform androidAndroid APK / iOS .app bundleYes
    PWAjac build --client pwaInstallable web appNo
    # Build for web (default)
    jac build
    
    # Build for desktop
    jac build --client desktop
    
    # Build for mobile (Capacitor)
    jac build --client mobile --platform android
    
    # Build for React Native
    jac build --client react-native --platform android
    
    # Build for PWA
    jac build --client pwa