Agent quickstart (learn X07 from scratch)
This page is a single entry point for LLM agents. Use the published agent portal endpoints as the canonical source of schemas/skills/examples (see Agent contracts).
If you want a single copy/paste prompt to bootstrap a new project, use: Agent initial prompt.
If you find a documentation gap, check the toolchain source directly in GitHub:
0) The mental model
- X07 source is x07AST JSON (
*.x07.json), not text. - The toolchain is JSON-first: diagnostics, patches, and reports are structured.
- Programs run in worlds (fixture or OS); OS worlds are
run-osandrun-os-sandboxed. - If you prefer authoring text, use the lossless x07text projection: write x07text, convert with
x07 ast from-text --in mod.x07t --out mod.x07.json(output is canonicalx07 fmtbytes), and render any module readable withx07 ast to-text. See x07text.
High-level primitives to learn early (the “one whole system”):
- Streaming pipes:
std.stream.pipe_v1(deterministic, budgeted streaming composition) - Branded bytes:
bytes@B+std.brand.*(typed boundary encodings) - Structured concurrency:
task.scope_v1(no orphan tasks; slots/select) - Record/replay:
std.rr+ rr scopes (OS → deterministic cassette) - Budget scopes:
budget.scope_v1(localize cost contracts; arch-driven budgets) - Contracts tooling:
x07 arch check,x07 schema derive,x07 sm gen(pinned contracts → deterministic checks/generation) - Property-based testing:
x07 test --pbt+x07 fix --from-pbt(counterexample → deterministic regression) - Function contracts + verification:
requires/ensures/invariant+x07 verify --prove|--coverage(proof artifacts plus explicit support posture) - Certificate-first review:
x07 prove check,x07 trust certify,x07 review diff,x07 trust report
0.5) Version + compat + migration (do this early)
New projects pin a compatibility mode in x07.json (project.compat, default "0.5"). If you open older projects or older package code, prefer mechanical migration over relying on legacy behavior:
x07 migrate --to 0.5 --check --input src/main.x07.json
x07 migrate --to 0.5 --write --input src/main.x07.json
For one-off debugging, you can override compatibility at the command level:
x07 run --compat 0.5
See: Compatibility contract and x07 migrate in Toolchain CLI.
0.6) Canonical patterns (loops, bytes/view, errors)
- Loops: use
forfor counted loops andwhilefor scanning loops; reserve recursion for contract/verified code.foris strict-form x07AST; see AST authoring best practices (X07-FOR-0001). - Bytes/view: call-argument coercion exists, but prefer explicit
bytes.viewat library boundaries.bytes.viewrequires an identifier owner; for literals preferbytes.view_lit(X07-BORROW-0001+ auto-fix viax07 fix). - Owned byte params: helper calls that take
bytesconsume the value. If a public byte param is reused across loops, helper calls, or postconditions, bind["bytes.view","param"]once and pass["view.to_bytes","param_v"]to owned-byte helpers. - Dependency roots: when imports fail, check
x07.json.module_roots+x07.lock.jsonand inspect closure withx07 pkg tree. - Error propagation:
- typed results (
result_i32,result_bytes) usetry - doc envelopes use
try_doc(see Doc envelope)
- typed results (
0.7) Agent pitfalls (common failure modes)
- Loop forms (
for): valid form is["for","i",<start:i32>,<end:i32>,<body:any>](X07-FOR-0001). Wrap multi-statement bodies inbegin. bytes.viewliterals/temporaries:bytes.viewrequires an identifier owner; usebytes.view_litfor literals andlet tmp = <expr>for temporaries (X07-BORROW-0001, often auto-fixable viax07 fix).- Owned
bytesreuse: passing abytesparam to a helper that expects ownedbytescan move it. In composed library code, keep abytes_viewlocal and passview.to_bytescopies into repeated helper calls. - Borrow-union returns: returning
bytes_viewfromif/option/result branches that borrow from different owners is usually rejected; return ownedbytes(copy) instead. - XTAL brands: when a public byte boundary is branded in
src/*.x07.json, the correspondingspec/*.x07spec.jsonoperation signature must also carry the samebrand/result_brandids (and generated property wrappers will inherit them). Seedocs/toolchain/xtal.mdanddocs/examples/agent-gate/xtal/workflow-graph/. - Dependency roots: module-not-found errors are usually missing
module_rootsor missing/stale locks; usex07 pkg tree/x07 pkg providesand re-runx07 pkg lock --check --offline. setis an expression:["set", x, e]evaluates to the assigned value, so statement-shaped["if", c, ["set", x, e], 0]fails branch unification whenxis noti32. Use["set0", x, e](returns0asi32) for statement assignments.std.hash_mapis fixed capacity: the slot table never grows; inserting a new key into a full map traps withmap_u32 full. Create maps withstd.hash_map.with_capacity_u32(expected)instead of guessing acap_pow2.vec_u8is accumulate-then-freeze: build withstd.vec.push/std.vec.extend_bytes(rebinding the move-only handle each call), then freeze once withstd.vec.as_bytes. No random reads while growing — for read-while-grow state keep abytesarena and read it withstd.codec.read_u32_le.- Two
concats: the builtinbytes.concattakes owned(bytes, bytes)and consumes both;std.bytes.concattakes views. Preferstd.vec.extend_bytesorstd.bytes.concatto avoid accidental moves. - Generics need explicit instantiation: generic stdlib calls (
std.heap,std.btree_map,std.deque, ...) require explicittapp/tystype arguments; there is no inference. - Integer literals are
i32:0xFFFFFFFFoverflows the literal range; write all-ones sentinels as-1.
1) Install and verify the toolchain
- Install with
x07up(recommended).
Prerequisites (macOS / Linux):
sh+tarcurlorwget(used for downloads)- a sha256 tool (
sha256sum,shasum, oropenssl) for installer verification - for OS worlds / native deps (for example
ext-curl-c): a C toolchain and libcurl headers (x07 doctorreports missing deps)
macOS / Linux (CI-safe, no profile edits, JSON report):
curl -fsSL https://x07lang.org/install.sh | sh -s -- \
--yes \
--channel stable \
--no-modify-path \
--json
export PATH="$HOME/.x07/bin:$PATH"
If you are not in CI, you can omit --no-modify-path and the installer will attempt to persist the PATH change.
Verify:
x07 --help
x07 run --help
x07up show --json
x07 --cli-specrows
If you plan to use OS worlds (run-os*) with native deps (for example ext-net / ext-curl-c / ext-sockets-c), run:
x07 doctor
See also: Install.
MCP: install the official X07 MCP server (optional)
If your agent runtime supports MCP (Model Context Protocol), install the official X07 MCP server: io.x07/x07lang-mcp. It lets an MCP client drive the local X07 toolchain via token-efficient core tools plus capability-gated ecosystem tools (x07.ecosystem.status_v1, x07.pkg.provides_v1, x07.doc_v1, x07.wasm.core_v1, safe patching, etc). The active surface is core editing, packages, and WASM.
Download the published bundle from GitHub releases:
- Repo: https://github.com/x07lang/x07-mcp
- Release tag pattern:
x07lang-mcp-v<MAJOR.MINOR.PATCH>(download the latest published release on the releases page) - Files:
x07lang-mcp.mcpbandx07lang-mcp.mcpb.sha256.txt
Verify (macOS / Linux):
expected="$(cat x07lang-mcp.mcpb.sha256.txt)"
got="$(shasum -a 256 x07lang-mcp.mcpb | awk '{print $1}')"
test "$got" = "$expected"
Configure your MCP client:
-
If your client supports
.mcpb, install the bundle. -
If your client requires a
command/argsserver definition, extract the bundle and run the router from the bundle root:unzip -q x07lang-mcp.mcpb -d x07lang-mcp.bundleUse:
command:.../x07lang-mcp.bundle/server/x07lang-mcpcwd:.../x07lang-mcp.bundle(soconfig/mcp.server.json+out/mcp-workerresolve)- env (recommended):
X07_MCP_X07_EXE=/absolute/path/to/x07(command -v x07)
Before optional wasm actions, call x07.ecosystem.status_v1 so the client sees which packs are actually enabled on the current machine.
If you are creating a new HTTP/SSE MCP server project that needs long-running tool calls or task polling, start from:
mkdir ./my-mcp-http-tasks
cd ./my-mcp-http-tasks
x07 init --template mcp-server-http-tasks
That scaffold still comes from x07-mcp; x07 only owns the delegation path and the surrounding project bootstrap.
2) Create a project (canonical starting point)
mkdir myapp
cd myapp
x07 init
x07 init creates both the project skeleton and the agent kit:
x07.json(withosandsandboxprofiles)x07.lock.jsonx07-toolchain.toml(pinsstableand declaresdocs+skills)AGENT.md(self-recovery guide + canonical commands).agent/docs/(offline docs; copied from the toolchain when init ran).agent/skills/(skills pack; copied from the toolchain when init ran)src/(a minimal program)tests/tests.json+tests/smoke.x07.json(a harness smoke test)
Templates (agentic starting points)
Use templates when the shape matches your project: they include pinned local deps + lockfiles, so you can iterate offline without guessing.
- Typed CLI (
ext-cli+ specrows):x07 init --template cli - File I/O with explicit caps (
run-os-sandboxed):x07 init --template fs-tool(defaults to thesandboxprofile) - JSON reporting (DataModel → canonical JSON):
x07 init --template json-report(see JSON reporting) - Spec-first pure XTAL starter:
x07 init --template xtal-pure - Certifiable pure XTAL starter:
x07 init --template xtal-verified
Offline sanity check (for dependency hydration):
x07 run --offline
x07 pkg lock --check --offline
x07.json notes (common failure mode)
- The root
worldfield is required (it’s used as a fallback when no run profile is selected). - For multi-profile projects, set the root
worldto the solve-* world you want for deterministic lint/repair (for examplesolve-pure), and run OS worlds via profiles (run-os*). - If the project will be certified, set
project.operational_entry_symbolon the current manifest line (x07.project@0.5.0). Strong trust profiles certify that operational entry and reject proof-only surrogate entries.
Contracts-by-example (copy/paste)
If your project uses pinned rr policies, archive policies, DB migrations, or arch-driven budgets, start from a schema-valid example arch/ tree:
docs/examples/contracts_project/(copy itsarch/into your project root)
If you are creating a publishable package repo (for x07 pkg publish), use x07 init --package instead of x07 init.
If you want the smallest certificate-first pure project instead of the default app skeleton, start from:
x07 init --template verified-core-pure
That template wires arch/, smoke/PBT tests, and verified_core_pure_v1 so you can go straight to x07 trust profile check and x07 trust certify.
If you want the sandboxed certificate-backed line instead, use:
x07 init --template trusted-sandbox-program
For a capsule-only starting point, use:
x07 init --template certified-capsule
See also: Available skills.
3) The core loop: run → test (auto-repair)
Run:
x07 run
x07 run runs the canonical auto-repair loop by default (format → lint → quickfix, repeatable). Use --repair=off when debugging, or --repair=memory to stage repairs without editing source files.
See: Running programs.
Diagnostics tip: many compiler errors include ptr=/... (a JSON Pointer into your x07AST) and sometimes moved_ptr=/... for ownership errors. Use x07 ast get --in src/main.x07.json --ptr /... to extract the failing node without manually counting indexes. Unknown-symbol errors include did-you-mean suggestions, and x07 run failure reports embed the structured diagnostics — parse the report instead of scraping stderr.
If you hit a compiler budget error (for example Budget: max locals exceeded or Budget: AST too large), see: Compiler limits.
Dependency tip: when compilation fails due to a missing module and prints hint: x07 pkg add ... --sync, x07 run can apply the hinted package add automatically and retry.
Run report tip: in run-os, the rr_* counters in x07 run --report ... are record/replay adapter stats and are not a count of real OS network requests.
If your program expects CLI arguments via argv_v1, pass them after -- and x07 run will encode them into input bytes:
x07 run -- tool --help
Run the deterministic harness (repo-defined suites):
x07 test --manifest tests/tests.json
For non-mutating, whole-project validation (full import graph + typecheck + backend-check, no emit), run:
x07 check --project x07.json
By default, the test harness runs non-PBT tests. If the suite includes property-based tests, run the full suite with:
x07 test --all --manifest tests/tests.json
To run only property-based tests, use x07 test --pbt --manifest tests/tests.json.
If PBT finds a counterexample, convert it into a committable regression test:
x07 fix --from-pbt target/x07test/pbt/<...>/repro.json --write
See: Property-based testing and PBT repro → regression test.
4) Repairs: quickfixes and patches
Two canonical repair mechanisms:
- Quickfixes:
x07 fixapplies the tool-providedquickfixJSON patches deterministically. - Explicit patches:
x07 ast apply-patchapplies RFC 6902 JSON Patch. - Multi-file patchsets:
x07 patch apply --in <patchset.json> --repo-root . --writeapplies anx07.patchset@0.1.0across specs, source modules, and manifests.
Note: x07 run, x07 build, and x07 bundle apply quickfixes automatically by default (--repair=...). Use the explicit loop below when you want raw diagnostics or tighter control.
Example loop:
x07 lint --input src/main.x07.json
x07 fix --input src/main.x07.json --write
x07 lint --input src/main.x07.json
See: Repair loop.
If you need a human-reviewable artifact for an agent patchset, use:
x07 review diff(semantic diff; HTML)x07 trust report(budgets/worlds/nondeterminism summary)x07 trust certify(certificate bundle with proof inventory, assumptions, and runtime/boundary evidence)
See: Review & trust artifacts.
5) Learn the language
- Start here: Language overview
- Read the concrete syntax model: Syntax & x07AST
Key x07AST shapes:
- expression call:
["head", arg1, arg2, ...] - identifier:
"std.bytes.len"
6) Packages (external dependencies)
Discover packages and versions:
- Registry UI: https://x07.io/packages
- Index catalog: https://registry.x07.io/index/catalog.json
Add a dependency:
# Add the latest non-yanked version from the index:
x07 pkg add NAME --sync
# Or pin explicitly:
x07 pkg versions NAME
x07 pkg add NAME@VERSION --sync
# Remove a dependency:
x07 pkg remove NAME --sync
Local path deps (offline-first):
# Add a dependency, but keep it as a local path (no registry fetch needed):
x07 pkg add ext-cli@VERSION --path .x07/deps/ext-cli/VERSION --sync
# Forbid any network during lock checks / hydration:
x07 pkg lock --check --offline
Notes:
x07 pkg addeditsx07.json. With--sync, it also updatesx07.lock.json.- Canonical project manifests use
x07.project@0.5.0.x07.project@0.2.0,x07.project@0.3.0, andx07.project@0.4.0are accepted for legacy manifests, and certification surfaces use thex07.project@0.4.0fields such asproject.operational_entry_symbol(still present inx07.project@0.5.0). - To migrate a legacy manifest to the current schema line, run
x07 project migrate --write --project x07.json. x07 pkg add NAME@VERSIONis safe to re-run: if the same dep+version already exists, it succeeds as a no-op. If the dep exists at a different version, pick a version explicitly and update the project deps.- If a module import fails and you don’t know which package provides it, use
x07 pkg provides <module-id>. - If you’ve added a package but don’t know which modules it exports, use
x07 doc <package-name>(example:x07 doc ext-net). - For builtin
std.*modules (file:<builtin>), usex07 doc std.<module>(example:x07 doc std.bytes). - For package-provided
std.*modules, runx07 doc <module-id> --project x07.jsonafter adding the package (example: afterx07 pkg add ext-net --sync, runx07 doc std.net.tcp --project x07.json). - For builtin forms (example:
bytes.len,task.scope_v1,budget.scope_v1), usex07 doc <name>(or force builtin resolution withx07 doc --builtin <name>). For the full reference (including syntax forms), usex07 guide. See: Prelude & names. - For structured encodings, prefer branded bytes + validators over ad-hoc parsing (see
std.brand.cast_view_v1/std.brand.cast_view_copy_v1inx07 guideandmeta.brands_v1in schema-derived modules). - For streaming transforms, prefer
std.stream.pipe_v1andstd.io.bufreadover manual loops (more predictable allocations; fewer borrow/ownership hazards). x07 pkg lockdefaults to the official registry index when fetching is required; override with--registry <URL>(alias:--index <URL>), or set a default in.x07/config.json/x07.config.json. Forbid network with--offline.- In CI, run
x07 pkg lock --project x07.json --check. - When the index can be consulted,
x07 pkg lock --checkalso fails on yanked dependencies and active advisories unless explicitly allowed (--allow-yanked/--allow-advisories). - After upgrading the toolchain, if old locks reference incompatible package versions, use
x07 pkg repair --toolchain current. - If you must force a transitive dependency version, use
project.patchinx07.jsonon the currentx07.project@0.5.0manifest line. - Some packages may declare required helper packages via
meta.requires_packages. When present,x07 pkg lockcan add and fetch these transitive deps, but agents should treat the capability map + templates as canonical so the dependency set is explicit. Requirements are exact versions (base@0.1.5) or SemVer ranges (base@>=0.1.5 <0.2.0); ranges resolve to the highest satisfying version at lock time and the lockfile freezes the choice. - Examples of transitive helpers:
ext-netpullsext-curl-c/ext-sockets-c/ext-url-rs, andext-db-sqlitepullsext-db-core(which pullsext-data-model).
If you hit a dependency version conflict, the canonical repair loop is:
x07 pkg versions NAME
x07 pkg remove NAME --sync
x07 pkg add NAME@VERSION --sync
See also: Packages & projects.
7) World selection (OS worlds)
run-os: real OS adapters (disk/network/time/env/process)run-os-sandboxed: policy-gated OS adapters (defaults to a VM boundary; still not a hardened sandbox if you mount secrets or enable networking)
For run-os-sandboxed, start from a schema-valid policy template instead of hand-writing JSON:
x07 policy init --template worker --out policy/sandbox.base.json --mkdir-out
Prefer profiles (x07.json.default_profile + x07.json.profiles) so agents usually run:
x07 run(project default)x07 run --profile os/x07 run --profile sandbox(explicit intent)
See: OS worlds.
8) Machine-first discovery surfaces
- CLI surface:
x07 --cli-specrows - Schemas:
spec/*.schema.json(and the synced copies on x07lang.org under/agent/.../schemas/) - External packages index:
GET /agent/latest/packages/index.jsonon x07lang.org - Offline docs:
x07up docs path --json - Local module inspection:
x07 doc <module-or-symbol>(example:x07 doc std.bytes). Stdlib exports include behavioral summaries (what the function does, not just its signature), and lookup is fuzzy — near-miss names resolve with suggestions. - Local package inspection (project deps):
x07 doc <package-name>(example:x07 doc ext-net) - Built-in reference guide:
x07 guide
9) Known-good reference projects (copy/paste)
The x07 repo ships CI-gated example projects under docs/examples/agent-gate/:
cli-newline(pure CLI payload parsing)cli-ext-cli(CLI args viaext-cli+argv_v1)json-report(typed CLI → DataModel → canonical JSON report)archive-safe-extract/zip-hello(safe ZIP extraction; hardened defaults)archive-extract-to-fs/zip-hello(streamed extraction to filesystem)web-crawler-local(sandboxed OS networking +--allow-host, against a local fixture site)
For the canonical package-focused set (examples + scenarios), see: Agent workflow.
See also: Patch-based recipes.
10) By-example tutorials (long-form)
- Sandbox policy walkthrough (progressive policy +
--allow-host) - Publishing by example (author → test → pack → publish → consume)
- Porting by example (
x07import-cliRust/C → x07 package) - Testing by example (
x07 test+ fixtures)