### Zero Program Execution Output Example Source: https://context7.com/vercel-labs/zero/llms.txt Example of the expected output when running the `examples/add.0` program. ```text math works ``` -------------------------------- ### Full Example of std.io Usage Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/modules/io.md This example demonstrates creating a buffered reader, copying data, and checking reader capacity. It verifies that the copied byte count and reader capacity match expected values. ```zero pub fun main(world: World) -> Void raises { let mut copy_dst: [4]u8 = [0, 0, 0, 0] let mut reader_buf: [8]u8 = [0, 0, 0, 0, 0, 0, 0, 0] let reader = std.io.bufferedReader(reader_buf) let copied = std.io.copy(copy_dst, std.mem.span("abcd")) if std.io.readerCapacity(&reader) == 8 && copied == 4 { check world.out.write("io ok\n") } } ``` -------------------------------- ### Install Zero Compiler Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/install.md Installs the latest Zero release using a curl script and adds it to your PATH. Verify the installation with `zero --version`. ```sh curl -fsSL https://zerolang.ai/install.sh | bash export PATH="$HOME/.zero/bin:$PATH" zero --version ``` -------------------------------- ### Configure Web Target in zero.json Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/learn-zero.md Example of a `zero.json` configuration file specifying a web target with its runtime and route directory. This setup is necessary for deploying web applications. ```json { "targets": { "web": { "kind": "web", "runtime": "wasm32-web", "routes": "src/routes" } } } ``` -------------------------------- ### Check Multiple Zero Example Files Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/getting-started.md Runs the Zero checker on a series of example files to demonstrate various language features. ```sh zero check examples/hello.0 zero check examples/hello-let.0 zero check examples/functions.0 zero check examples/branch.0 zero check examples/point.0 zero check examples/result-choice.0 ``` -------------------------------- ### Quick Command Loop Examples Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/building-from-source.md Demonstrates a quick loop of checking, building, and running a Zero program. This is useful for rapid iteration during development. ```sh bin/zero check examples/hello.0 bin/zero build --emit exe --target linux-musl-x64 examples/add.0 --out .zero/out/add ./.zero/out/add ``` -------------------------------- ### Zero Package Manifest Example Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/getting-started.md An example of a 'zero.json' manifest file used to configure a Zero project, specifying package details and build targets. ```json { "package": { "name": "systems-package", "version": "0.1.0" }, "targets": { "cli": { "kind": "exe", "main": "src/main.0" } } } ``` -------------------------------- ### Zero Parse Module Example Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/modules/parse.md Demonstrates the usage of various parsing functions from the std.parse module, including checking for digits, identifier start characters, scanning digits, and parsing unsigned 16-bit integers. This example verifies the correct functionality of these primitives. ```zero use std.parse pub fun main(world: World) -> Void raises { let digit = std.parse.isAsciiDigit("7") let ident = std.parse.isIdentifierStart("_") let scanned = std.parse.scanDigits("123abc") let parsed = std.parse.parseU16("8080") if digit && ident && scanned == 3 && parsed.has && parsed.value == 8080 { check world.out.write("parse primitives ok\n") } } ``` -------------------------------- ### Create, Write, and Manage a File Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/modules/fs.md Demonstrates creating a file, writing content to it, checking its length, renaming it, and finally removing it. This example uses `createOrRaise`, `writeAllOrRaise`, `fileLenOrRaise`, `rename`, and `remove` from the `std.fs` module. Ensure the necessary capabilities are available. ```zero pub fun main(world: World) -> Void raises { NotFound, TooLarge, Io } { let fs = std.fs.host() let mut file: owned = check std.fs.createOrRaise(fs, ".zero/out/example.txt") check std.fs.writeAllOrRaise(&mut file, std.mem.span("hello\n")) let len = check std.fs.fileLenOrRaise(&mut file) std.fs.close(&mut file) if len == 6 && std.fs.exists(".zero/out/example.txt") { if std.fs.rename(".zero/out/example.txt", ".zero/out/example-renamed.txt") { if std.fs.remove(".zero/out/example-renamed.txt") { check world.out.write("fs ok\n") } } } } ``` -------------------------------- ### Import standard library modules Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/learn-zero.md Use the `use` keyword to import modules from the standard library. This example imports `std.codec` to use its functions for encoding and checksum calculation. ```zero use std.codec pub fun main(world: World) -> Void raises { let len = std.codec.encodedVarintLen(300) let checksum = std.codec.crc32("zero") if len == 2 && checksum > 0 { check world.out.write("codec primitives ok\n") } } ``` -------------------------------- ### Full HTTP Module Example Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/modules/http.md Demonstrates the usage of various std.http functions including client, server, parseMethod, and bodyLen within a main function. Requires a net-capable target. ```zero pub fun main(world: World) -> Void raises { let net = std.net.host() let addr = std.net.address("localhost", 8080_u16) let _client = std.http.client(net) let _server = std.http.server(net, addr) let method = std.http.parseMethod("GET") if method == std.http.parseMethod("GET") && std.http.bodyLen(std.mem.span("body")) == 4 { check world.out.write("http ok\n") } } ``` -------------------------------- ### Install Zero Extension for Cursor Source: https://github.com/vercel-labs/zero/blob/main/extensions/vscode/README.md Use this command to install the Zero language extension directly into your Cursor IDE from the repository root. ```sh npm run extension:install:cursor ``` -------------------------------- ### Create a Web Handler with GET Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/learn-zero.md Defines a simple web handler for GET requests that returns a text response. This is the basic structure for creating web services in Zero. ```zero pub fun GET(req: Request) -> Response { return Response.text("hello from zero web\n") } ``` -------------------------------- ### Standard Library Imports in Zero Source: https://github.com/vercel-labs/zero/blob/main/skill-data/zero-packages.md Examples of importing modules from the standard library using the `use` keyword. These follow the same pattern as package-local imports. ```zero use std.mem use std.parse ``` -------------------------------- ### List and Get Bundled Agent Skills with `zero skills` Source: https://context7.com/vercel-labs/zero/llms.txt Manage bundled agent skills using `zero skills`. Commands include `list`, `get`, `path`, and their JSON variants. Use `--full` for detailed skill information. ```sh zero skills list ``` ```sh zero skills get zero ``` ```sh zero skills get zero --full ``` ```sh zero skills path zero ``` ```sh zero skills list --json ``` -------------------------------- ### Zero Memory Span Example Source: https://github.com/vercel-labs/zero/blob/main/skill-data/zero-stdlib.md Demonstrates creating a memory span from a string and checking its length. Ensure the length matches expectations before proceeding. ```zero use std.mem pub fun main(world: World) -> Void raises { let bytes: Span = std.mem.span("zero") if std.mem.len(bytes) == 4 { check world.out.write("memory ok\n") } } ``` -------------------------------- ### Run Zero Project in Development Mode Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/cli-reference.md Start the Zero project in development mode. Use --json for machine-readable output, --trace for detailed tracing, and --target to specify a build target. ```sh zero dev [--json] [--trace] [--target ] ``` -------------------------------- ### Build Compiler from Local Checkout Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/install.md Installs dependencies and builds the Zero compiler from a local repository checkout using npm and make. Verify the build with `bin/zero --version`. ```sh npm install make -C native/zero-c bin/zero --version ``` -------------------------------- ### Check Web Response Source: https://github.com/vercel-labs/zero/blob/main/examples/README.md Demonstrates a single-file web-style GET handler. ```sh bin/zero check examples/web-response.0 ``` -------------------------------- ### Zero Fixed Buffer Allocator Example Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/modules/mem.md Illustrates the usage of a fixed-size buffer allocator for allocating memory from a pre-defined storage area. ```zero pub fun main(world: World) -> Void raises { let mut storage: [8]u8 = [0, 0, 0, 0, 0, 0, 0, 0] let mut alloc: FixedBufAlloc = std.mem.fixedBufAlloc(storage) let bytes = std.mem.allocBytes(alloc, 4) if bytes.has { bytes.value[0] = 90 check world.out.write("fixed buffer allocated\n") } } ``` -------------------------------- ### Check and Run Zero Packages Source: https://github.com/vercel-labs/zero/blob/main/skill-data/zero-packages.md Commands to check the validity of a package or its manifest, and to run examples within a package. You can specify either the package directory or the manifest file. ```sh zero check . zero check zero.json zero run examples/systems-package ``` -------------------------------- ### Expected output for zero-hash Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/examples.md The expected output when running the `zero-hash` example. ```text zero-hash ok ``` -------------------------------- ### Run native test for zero-hash Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/examples.md Executes the native test for the `zero-hash` example. ```sh npm run native:test ``` -------------------------------- ### Zero Memory Operations Example Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/modules/mem.md Demonstrates basic memory operations like creating spans, copying data, and comparing memory contents using Zero's memory module. ```zero shape SliceView { bytes: Span, values: Span, } pub fun main(world: World) -> Void raises { let bytes: Span = std.mem.span("zero-memory") let same = std.mem.span("zero-memory") let mut scratch: [11]u8 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] let copied = std.mem.copy(scratch, bytes) let mut ints: [3]i32 = [1, 2, 3] let intSpan: MutSpan = ints intSpan[1] = 20 let view = SliceView { bytes: bytes, values: intSpan } if copied == 11 && std.mem.len(view.bytes) == 11 && std.mem.eqlBytes(view.bytes, same) && std.mem.len(view.values) == 3 && std.mem.eqlBytes(view.values, intSpan) { check world.out.write("memory type forms runnable\n") } } ``` -------------------------------- ### Run Zero Program Source: https://github.com/vercel-labs/zero/blob/main/README.md Executes a small Zero program. The output 'math works' is expected for the 'add.0' example. ```bash zero run examples/add.0 ``` -------------------------------- ### Build zero-hash WASM module Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/examples.md Builds the `zero-hash` example as a WASM module for wasm32-wasi target. ```sh bin/zero build --emit wasm --target wasm32-wasi examples/zero-hash --out .zero/out/zero-hash ``` -------------------------------- ### Zero Writable Buffer Example Source: https://github.com/vercel-labs/zero/blob/main/skill-data/zero-stdlib.md Shows how to use a caller-owned fixed array and `MutSpan` for writable buffers. The `std.mem.copy` function can then be used to populate this buffer. ```zero let mut storage: [8]u8 = [0, 0, 0, 0, 0, 0, 0, 0] let writable: MutSpan = storage let copied = std.mem.copy(writable, std.mem.span("zero")) ``` -------------------------------- ### Zero CLI Commands for C ABI and Graph Source: https://context7.com/vercel-labs/zero/llms.txt Examples of using Zero CLI commands to check conformance, dump C ABI information in JSON format, and generate a graph for a specific target. ```sh zero check conformance/native/pass/c-abi-export.0 ``` ```sh zero abi dump --json conformance/native/pass/c-abi-export.0 ``` ```sh zero graph --json --target wasm32-web conformance/check/pass/c-header-import.0 ``` -------------------------------- ### Package main function with multiple imports Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/learn-zero.md An example of a package's main function that imports several standard library modules (`std.codec`, `std.parse`, `std.time`) and uses their functionalities. It also demonstrates deferred cleanup. ```zero use std.codec use std.parse use std.time pub fun main(world: World) -> Void raises { defer cleanup() let current: Status = status() let result: Result = Result.ok let word = std.codec.readU32("abcd") let digits = std.parse.scanDigits("123abc") let duration = std.time.add(std.time.ms(5), std.time.seconds(1)) if digits == 3 && word > 0 && std.time.asMsFloor(duration) > 0 { check world.out.write("systems package\n") } } ``` -------------------------------- ### Zero CLI Commands with JSON Output Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/cli-reference.md Examples of using the `--json` flag with various Zero CLI commands for machine-readable output. This is useful for integrating with other tools and CI systems. ```sh zero check --json ``` ```sh zero graph --json ``` ```sh zero dev --json ``` ```sh zero dev --json --trace ``` ```sh zero time --json ``` ```sh zero build --json ``` ```sh zero size --json ``` ```sh zero ship --json ``` ```sh zero doctor --json ``` -------------------------------- ### Inspect Web Routes with zero routes CLI Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/learn-zero.md Command-line instruction to inspect web routes and generate a JSON manifest for a given example directory. This helps in understanding the web application's structure and dependencies. ```sh zero routes --json examples/web/hello ``` -------------------------------- ### Serve Docs with npm Source: https://github.com/vercel-labs/zero/blob/main/examples/README.md Command to serve the Zero project documentation site locally. ```sh npm run docs:serve ``` -------------------------------- ### Standard Library Symbol Metadata Example Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/standard-library.md Example of metadata provided for a standard library symbol, detailing its effects, allocation behavior, target support, error behavior, ownership notes, and example usage. ```text symbol: std.fs.readAllOrRaise effects: fs allocation behavior: caller allocator target support: host error behavior: raises { NotFound, TooLarge, Io } ownership notes: returns owned example: examples/readall-cli/ ``` -------------------------------- ### Zero Package Manifest (zero.json) Configuration Source: https://context7.com/vercel-labs/zero/llms.txt Example of a `zero.json` file defining package metadata, targets, dependencies, and build profiles. It also shows how package-local imports resolve from the `src/` directory. ```json { "package": { "name": "systems-package", "version": "0.1.0", "license": "MIT" }, "targets": { "cli": { "kind": "exe", "main": "src/main.0" } }, "dependencies": { "local-tools": { "path": "../local-tools", "version": "0.1.0" } }, "profiles": { "dev": { "inherits": "dev" }, "release-small": { "inherits": "release-small" } } } ``` ```zero use helpers // resolves src/helpers.0 use config.parser // resolves src/config/parser.0 ``` -------------------------------- ### Check Systems Package Source: https://github.com/vercel-labs/zero/blob/main/examples/README.md Demonstrates zero.json, multiple source files, defer, and std helpers. ```sh bin/zero check examples/systems-package ``` -------------------------------- ### Create and Connect with std.net Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/modules/net.md Demonstrates creating a network host, an address with a timeout, and attempting to establish a connection. It checks if the connection is successful and verifies the DNS name of the address. ```zero pub fun main(world: World) -> Void raises { let net = std.net.host() let addr = std.net.withTimeout(std.net.address("localhost", 8080_u16), std.time.ms(250)) let conn = std.net.connect(net, addr) if conn.has && std.mem.eql(std.net.dnsName(addr), "localhost") { check world.out.write("net ok\n") } } ``` -------------------------------- ### Prepare Release with Make and bin/zero Source: https://github.com/vercel-labs/zero/blob/main/AGENTS.md Commands to run during the release preparation process, including building the native compiler, checking the Zero version, running tests, and validating command contracts. ```sh make -C native/zero-c bin/zero --version --json npm run test:zero npm run command-contracts:local npm run docs:test ``` -------------------------------- ### Write and Check a Basic Zero Program Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/getting-started.md Creates a simple 'hello world' program in a file named 'hello.0' and checks its syntax and structure using the Zero checker. ```zero pub fun main(world: World) -> Void raises { check world.out.write("hello from zero\n") } ``` ```sh zero check hello.0 ``` -------------------------------- ### Get Explanations and Repair Plans with `zero explain` and `zero fix` Source: https://context7.com/vercel-labs/zero/llms.txt Use `zero explain` for diagnostic code explanations and `zero fix --plan --json` to get typed repair plans. Specify targets for cross-compilation checks. ```sh zero explain NAM003 ``` ```sh zero explain --json TAR002 ``` ```sh zero fix --plan --json conformance/check/fail/unknown-name.0 ``` ```sh zero fix --plan --json --target linux-musl-x64 conformance/native/fail/std-fs-target-unsupported.0 ``` -------------------------------- ### Importing Standard Library Modules in Zero Source: https://context7.com/vercel-labs/zero/llms.txt Demonstrates how to import and use modules from the Zero standard library for various functionalities like encoding, parsing, and time operations. Imports are pay-as-used. ```zero use std.codec use std.parse use std.time pub fun main(world: World) -> Void raises { let len = std.codec.encodedVarintLen(300) // -> usize let crc = std.codec.crc32("zero") // -> u32 let word = std.codec.readU32("abcd") // -> u32 let isDigit = std.parse.isAsciiDigit("7") // -> Bool let digits = std.parse.scanDigits("123abc") // -> usize let dur = std.time.add(std.time.ms(5), std.time.seconds(1)) if len == 2 && crc > 0 && std.time.asMsFloor(dur) > 0 { check world.out.write("stdlib ok\n") } } ``` -------------------------------- ### Build and Run an Executable Zero Program Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/getting-started.md Creates a program 'add.0' that performs a simple calculation and prints the result. It then runs the program using the Zero runtime. ```zero fun answer() -> i32 { return 40 + 2 } pub fun main(world: World) -> Void raises { let value = answer() if value == 42 { check world.out.write("math works\n") } else { check world.out.write("math broke\n") } } ``` ```sh zero run add.0 ``` -------------------------------- ### Build Profiles for Debug, Fast, and Small Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/examples.md Shows how to build Zero programs with different optimization profiles (debug, fast, small) and analyze their size. The JSON output provides detailed build semantics and size breakdowns. ```sh bin/zero build --json --profile debug --target linux-musl-x64 examples/hello.0 --out .zero/out/hello-debug ``` ```sh bin/zero build --json --profile fast --target linux-musl-x64 examples/hello.0 --out .zero/out/hello-fast ``` ```sh bin/zero build --json --profile small --target linux-musl-x64 examples/hello.0 --out .zero/out/hello-small ``` ```sh bin/zero size --json --profile tiny --target linux-musl-x64 examples/fixed-vec.0 ``` -------------------------------- ### Check cross-target status for zero-hash Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/examples.md Checks the cross-target status of the `zero-hash` example for wasm32-web. ```sh bin/zero check --json --target wasm32-web examples/zero-hash ``` -------------------------------- ### Inspect zero-hash graph metadata Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/examples.md Inspects the dependency graph metadata for the `zero-hash` example. ```sh bin/zero graph --json examples/zero-hash ``` -------------------------------- ### Basic Zero Commands Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/examples.md Demonstrates fundamental Zero commands for checking and building Zero programs. Use these for initial verification and compilation to various targets. ```sh bin/zero check examples/hello.0 ``` ```sh bin/zero build --emit exe --target linux-musl-x64 examples/add.0 --out .zero/out/add ``` ```sh ./.zero/out/add ``` ```sh bin/zero build --emit wasm --target wasm32-wasi examples/direct-wasm-add.0 --out .zero/out/direct-wasm-add.wasm ``` -------------------------------- ### Defining and calling functions in Zero Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/learn-zero.md Define helper functions with 'fun' and call them from 'main'. Function signatures specify parameters and return types. ```zero fun answer() -> i32 { return 40 + 2 } pub fun main(world: World) -> Void raises { let value = answer() if value == 42 { check world.out.write("math works\n") } else { check world.out.write("math broke\n") } } ``` -------------------------------- ### Explain Diagnostic Source: https://github.com/vercel-labs/zero/blob/main/examples/agent-repair-demo/README.md Use this command to get a JSON explanation for a given diagnostic code. ```sh bin/zero explain --json TYP009 ``` -------------------------------- ### Check Resource CLI Source: https://github.com/vercel-labs/zero/blob/main/examples/README.md Demonstrates args/env fallback, path joins, std.mem.copy/fill, and named-error owned-file resources. ```sh bin/zero check examples/resource-cli ``` -------------------------------- ### Get zero-hash size report Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/examples.md Generates a JSON size report for the `zero-hash` WASM module. ```sh bin/zero size --json --target wasm32-wasi examples/zero-hash --out .zero/out/zero-hash-size.json ``` -------------------------------- ### Character literal examples in Zero Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/learn-zero.md Use 'char' for single-quoted byte literals. Characters do not cast to or from integers. ```zero let letter: char = 'A' let newline: char = '\n' let same = letter == '\x41' ``` -------------------------------- ### Integer type examples in Zero Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/learn-zero.md Zero supports explicit integer widths. Literals can be specified with suffixes and separators. ```zero let count: u32 = 0x12c_u32 let byte: u8 = count as u8 ``` -------------------------------- ### Get Specific Zero Skill Information Source: https://github.com/vercel-labs/zero/blob/main/skill-data/zero-agent.md Retrieves detailed information about a specific Zero skill, such as 'zero-language' or 'zero-diagnostics'. ```sh zero skills get zero-language ``` ```sh zero skills get zero-diagnostics ``` -------------------------------- ### Run Zero Project Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/cli-reference.md Execute the Zero project with specified arguments. Use --target to specify a build target, --profile for build profile, and --out to specify an output file. ```sh zero run [--target ] [--profile dev|release] [--out ] [-- args...] ``` -------------------------------- ### Get HTTP Body Length Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/modules/http.md Reports the byte length of an HTTP body without allocation. This is an infallible helper. ```zero std.http.bodyLen(std.mem.span("body")) ``` -------------------------------- ### Get HTTP TLS Boundary Name Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/modules/http.md Returns the platform or C-library TLS boundary name as a String. This is an infallible helper. ```zero std.http.tlsBoundary() ``` -------------------------------- ### Float literal examples in Zero Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/learn-zero.md Zero supports 'f32' and 'f64' for decimal literals. Untyped float literals default to 'f64'. ```zero let ratio: f64 = 1.0e-3 let small: f32 = 0.5 let total = ratio + 2.0 ``` -------------------------------- ### Filesystem Operations with std.fs in Zero Source: https://context7.com/vercel-labs/zero/llms.txt Demonstrates hosted filesystem operations using `std.fs`, including file creation, writing, checking length, renaming, and removal. This module is host-target only. ```zero use std.fs pub fun main(world: World) -> Void raises { let fs = std.fs.host() let mut file: owned = check std.fs.createOrRaise(fs, ".zero/out/example.txt") check std.fs.writeAllOrRaise(&mut file, std.mem.span("hello\n")) let len = check std.fs.fileLenOrRaise(&mut file) std.fs.close(&mut file) if len == 6 && std.fs.exists(".zero/out/example.txt") { _ = std.fs.rename(".zero/out/example.txt", ".zero/out/renamed.txt") _ = std.fs.remove(".zero/out/renamed.txt") check world.out.write("fs ok\n") } } ``` -------------------------------- ### Ship Zero Project Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/cli-reference.md Prepare the Zero project for shipping. Use --json for machine-readable output, --target for build target, --profile for specific release profiles, and --out for output file. ```sh zero ship [--json] [--target ] [--profile release-small|tiny|audit] [--out ] ``` -------------------------------- ### std.net.host() Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/modules/net.md Creates the hosted network capability. ```APIDOC ## std.net.host() ### Description Creates the hosted network capability. ### Return `Net` - The hosted network capability. ### Notes Requires a net-capable target. ``` -------------------------------- ### Get Zero CLI Version Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/cli-reference.md Display the current version of the Zero CLI. Use the --json flag for machine-readable output. ```sh zero --version [--json] ``` -------------------------------- ### Develop Zero Documentation Locally Source: https://github.com/vercel-labs/zero/blob/main/README.md Runs the Zero documentation site locally using npm. This command is useful for developers contributing to the documentation. ```bash npm run docs:dev ``` -------------------------------- ### Manage Zero Skills Source: https://github.com/vercel-labs/zero/blob/main/skills/zero/SKILL.md Commands to list, get, and retrieve full details of Zero skills. Use these to manage version-matched workflows for your agent. ```sh zero skills list ``` ```sh zero skills get zero ``` ```sh zero skills get zero --full ``` -------------------------------- ### Generate Documentation Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/cli-reference.md Generate documentation for the Zero project. Use --json for machine-readable output and --target to specify a build target. ```sh zero doc [--json] [--target ] ``` -------------------------------- ### Zero Hosted File Resource Management Source: https://github.com/vercel-labs/zero/blob/main/skill-data/zero-stdlib.md Demonstrates creating and writing to a file using hosted filesystem APIs. It uses explicit file handles and `owned` for deterministic resource management. Ensure to use `check` for operations that can fail. ```zero let fs = std.fs.host() let mut file: owned = check std.fs.createOrRaise(fs, ".zero/out/log.txt") check std.fs.writeAllOrRaise(&mut file, std.mem.span("hello\n")) ``` -------------------------------- ### Check Zero CLI Health Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/cli-reference.md Run diagnostics to check the health of the Zero CLI installation. Use the --json flag for machine-readable output. ```sh zero doctor [--json] ``` -------------------------------- ### Build Zero Programs with Profiles Source: https://github.com/vercel-labs/zero/blob/main/skill-data/zero-builds.md Build Zero programs with specific profiles like `debug`, `release-fast`, or `release-small`. Use `zero size --json` to analyze the program's size breakdown. ```sh zero build --profile release-small examples/hello.0 ``` ```sh zero size --json --profile tiny examples/hello.0 ``` -------------------------------- ### Inspect Zero Program Capabilities Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/standard-library.md Use the CLI to inspect required capabilities and imported helpers for a Zero program. ```bash zero graph --json ``` ```bash zero size --json ``` ```bash zero mem --json ``` -------------------------------- ### Local Path Dependencies in Zero Source: https://github.com/vercel-labs/zero/blob/main/skill-data/zero-packages.md Example of defining a local path dependency within a `zero.json` manifest. The `path` should point to a directory containing its own `zero.json`. ```json { "dependencies": { "local-tools": { "path": "../local-tools", "version": "0.1.0" } } } ``` -------------------------------- ### Access command-line arguments and file system Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/learn-zero.md This snippet demonstrates how to access command-line arguments using `std.args.get` and write to a file using `std.fs.write`. It handles cases where arguments might not exist. ```zero pub fun main(world: World) -> Void raises { let first = std.args.get(1) if first.has { let written = std.fs.write(".zero/out/name.txt", first.value) if written > 0 { check world.out.write("wrote argument\n") } } } ``` -------------------------------- ### Explain a Diagnostic Code Source: https://github.com/vercel-labs/zero/blob/main/skill-data/zero-diagnostics.md Use `zero explain` to get human-readable explanations for diagnostic codes. For agent consumption, use the `--json` flag. ```sh zero explain ``` ```sh zero explain --json ``` -------------------------------- ### Explain Diagnostic Code Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/diagnostics.md Use `zero explain` to get a human-readable explanation for a diagnostic code. For machine-readable output, use the `--json` flag. ```sh zero explain TAR002 ``` ```sh zero explain --json TYP009 ``` -------------------------------- ### Running Zero Programs with Arguments Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/cli-reference.md Demonstrates how to pass arguments to a Zero program when using the `zero run` command. Arguments for the Zero program are specified after the `--` separator. ```sh zero run examples/cli-file.0 -- input.txt ``` -------------------------------- ### Explain Diagnostic Code Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/target-capabilities.md Use `zero explain` to get human-readable or JSON explanations for diagnostic codes. This helps in understanding errors and potential repairs. ```sh zero explain TAR002 ``` ```sh zero explain --json TAR002 ``` -------------------------------- ### Create a New Zero Project Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/getting-started.md Initializes a new Zero project named 'cli' and performs standard project checks and build operations. ```sh zero new cli hello cd hello zero check . zero test . zero run . zero build --target linux-musl-x64 --out .zero/out/hello . ``` -------------------------------- ### Direct Executable Return Status Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/examples.md Builds a tiny native executable that returns a deterministic exit status. This example is useful for testing command-line applications and scripts. ```sh bin/zero build --emit exe --target linux-musl-x64 examples/direct-exe-return.0 --out .zero/out/direct-exe-return ``` -------------------------------- ### Inspect Route Metadata with JSON Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/cross-compilation.md Retrieve route maps, local-runtime facts, explicit imports, and capability restrictions for web examples using JSON output. ```sh bin/zero routes --json examples/web/hello ``` -------------------------------- ### Cross-Compilation for Linux and Windows Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/examples.md Demonstrates cross-compiling a Zero program for different targets (linux-musl-x64 and win32-x64.exe) using the 'tiny' release profile. Includes size analysis for the generated artifacts. ```sh bin/zero build --release tiny --target linux-musl-x64 examples/hello.0 --out .zero/out/hello-linux-musl ``` ```sh bin/zero build --release tiny --target win32-x64.exe examples/hello.0 --out .zero/out/hello-win32 ``` ```sh bin/zero size --json --release tiny --target linux-musl-x64 --out .zero/out/hello-linux-musl examples/hello.0 ``` -------------------------------- ### Import and use parse primitives Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/learn-zero.md Imports the `std.parse` module to utilize functions for checking character types, such as determining if a character is an ASCII digit or the start of an identifier. ```zero use std.parse pub fun main(world: World) -> Void raises { let digit = std.parse.isAsciiDigit("7") let ident = std.parse.isIdentifierStart("_") if digit && ident { check world.out.write("parse primitives ok\n") } } ``` -------------------------------- ### std.net.listen(net, address) Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/modules/net.md Returns a bootstrap listener handle when available. ```APIDOC ## std.net.listen(net, address) ### Description Returns a bootstrap listener handle when available. ### Parameters #### Path Parameters - **net** (Net) - The hosted network capability. - **address** (Address) - The address to listen on. ### Return `Maybe` - A bootstrap listener handle if available, otherwise `Nothing`. ### Notes Requires a net-capable target. Connection helpers return `Maybe`. ``` -------------------------------- ### Tiny Profile Builds and Size Analysis Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/examples.md Illustrates building and analyzing the size of artifacts using the 'tiny' profile. This is useful for creating minimal binaries. ```sh bin/zero build --release tiny --target linux-musl-x64 examples/hello.0 --out .zero/out/hello-tiny ``` ```sh bin/zero size --json --release tiny --target linux-musl-x64 --out .zero/out/hello-tiny examples/hello.0 ``` -------------------------------- ### Run Scripted Demo Source: https://github.com/vercel-labs/zero/blob/main/examples/agent-repair-demo/README.md Execute the scripted demo using Node.js. ```sh node scripts/agent-repair-demo.mjs ``` -------------------------------- ### Basic 'main' function in Zero Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/learn-zero.md The entry point of a Zero program must be a 'main' function. It receives a 'World' capability and can optionally fail. ```zero pub fun main(world: World) -> Void raises { check world.out.write("hello from zero\n") } ``` -------------------------------- ### Zero Codec Primitives Example Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/modules/codec.md Demonstrates the usage of `encodedVarintLen` for calculating varint byte length and `crc32` for string checksums. Also shows `crc32Bytes` for byte span checksums. ```zero use std.codec use std.mem pub fun main(world: World) -> Void raises { let len = std.codec.encodedVarintLen(300) let checksum = std.codec.crc32("zero") let bytes = std.mem.span("zero") let byte_checksum = std.codec.crc32Bytes(bytes) if len == 2 && checksum == byte_checksum { check world.out.write("codec primitives ok\n") } } ``` -------------------------------- ### std.net.connect(net, address) Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/modules/net.md Returns a bootstrap connection handle when available. ```APIDOC ## std.net.connect(net, address) ### Description Returns a bootstrap connection handle when available. ### Parameters #### Path Parameters - **net** (Net) - The hosted network capability. - **address** (Address) - The address to connect to. ### Return `Maybe` - A bootstrap connection handle if available, otherwise `Nothing`. ### Notes Requires a net-capable target. Connection helpers return `Maybe`. ``` -------------------------------- ### Check and Inspect a Zero Package Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/getting-started.md Checks the syntax of a Zero package located at 'examples/systems-package' and visualizes its module graph in JSON format. ```sh zero check examples/systems-package ``` ```sh zero graph --json examples/systems-package ``` -------------------------------- ### Construct and match a choice payload Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/learn-zero.md Demonstrates how to construct a `choice` with a payload and use a `match` statement to handle its different cases. Ensure all cases are handled exhaustively. Use `=> name` to bind the payload within a match arm. ```zero let result: Result = Result.ok(42) match result { .ok => value { if value == 42 { check world.out.write("choice ok\n") } } .err => message { check world.out.write("choice err\n") } } ``` -------------------------------- ### Writing to World Output in Zero Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/primitives.md Demonstrates basic output writing using the `World` capability. Ensure the `World` capability is available in your scope. ```zero pub fun main(world: World) -> Void raises { check world.out.write("hello\n") } ``` -------------------------------- ### Check Local Environment with Zero Doctor Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/install.md Use `zero doctor` to diagnose your local environment setup. The `--json` flag provides a detailed readiness matrix for target toolchains. ```sh zero doctor ``` ```sh zero doctor --json ``` -------------------------------- ### Create New Zero Project Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/cli-reference.md Scaffold a new Zero project of type cli, lib, or package at the specified path. ```sh zero new cli|lib|package ``` -------------------------------- ### Build Zero Project Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/cli-reference.md Compile the Zero project. Specify emit type (exe, obj, wasm), build target, profile, and output file. ```sh zero build [--emit exe|obj|wasm] [--target ] [--profile dev|release] [--out ] ``` -------------------------------- ### Run Zero Check with JSON Output Source: https://github.com/vercel-labs/zero/blob/main/skill-data/zero-diagnostics.md Use the `--json` flag with `zero check` to get structured diagnostic output for parsing and typechecking errors. This is intended for programmatic consumption by agents. ```sh zero check --json ``` -------------------------------- ### Get Zero Project Size Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/cli-reference.md Analyze the size of the Zero project artifacts. Use --json for machine-readable output, --target for build target, and --out to specify an artifact file. ```sh zero size [--json] [--target ] [--out ] ``` -------------------------------- ### Run Benchmark Suite Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/benchmarks.md Execute the benchmark suite locally to assess Zero's performance. The report is generated in `.zero/bench/latest.json`. ```sh npm run bench ``` -------------------------------- ### Example Error Diagnostic Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/diagnostics.md A typical error diagnostic shows the error code, message, source location, code excerpt, and detailed explanations for the rule, expected, and actual outcomes, along with a suggested fix. ```text error[NAM003]: Unknown identifier unknown identifier 'message' examples/hello.0:2:27 2 | check world.out.write(message) | ^^^^^^^ rule: Names must be declared before use in the current lexical scope. expected: local binding, parameter, function, builtin value actual: no visible symbol named 'message' fix: Introduce a local binding before this use (local-edit) explain: zero explain NAM003 ``` -------------------------------- ### Create New Zero Packages Source: https://github.com/vercel-labs/zero/blob/main/skill-data/zero-packages.md Use these commands to create new Zero packages of different types: CLI, library, or general application package. Check generated files before modifying the project structure. ```sh zero new cli hello zero new lib math-tools zero new package app ``` -------------------------------- ### Check Command for Tools with JSON Output Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/diagnostics.md Use the `--json` flag with the `zero check` command to get structured JSON output. This is ideal for integration with agents, CI systems, editors, and other tools. ```sh zero check --json examples/hello.0 ``` -------------------------------- ### Zero Skills Management Commands Source: https://github.com/vercel-labs/zero/blob/main/docs-site/articles/cli-reference.md Commands for managing Zero skills, including listing available skills, getting skill details, and specifying the path to skill content. Add `--json` for automation. ```sh zero skills list ``` ```sh zero skills get zero ``` ```sh zero skills get zero --full ``` ```sh zero skills path zero ```