# FastCi — Complete Technical & AI Authoring Reference (v0.3.0) > Single-file, authoritative documentation for writing high-performance, cache-sound CI/CD pipelines with FastCi. > Repository: https://github.com/seregonwar/FastCi > Web Docs: https://seregonwar.github.io/FastCi/ > JSON Schema: https://seregonwar.github.io/FastCi/schema/fastci.schema.json > License: GPL-3.0-only OR LicenseRef-FastCi-Commercial > Status: Early-stage (pre-v1.0.0) — benchmark and validate in staging before production rollouts. --- ## 1. What FastCi Does (and Does Not Do) FastCi is a single hardened C11 + Assembly binary (also compiled with memory-safe Fil-C + SaRCAsm on Linux) designed to slash CI wall-clock time and runner billing minutes (especially 2x Windows and 10x macOS runners) without forcing a migration off GitHub Actions, GitLab CI, CMake, Ninja, or Cargo. Three complementary acceleration layers: 1. **Compiler & Link Cache (`fastci wrap` / `fastci cc`)**: - Works directly as `CMAKE_C_COMPILER_LAUNCHER=fastci`, `CMAKE_CXX_COMPILER_LAUNCHER=fastci`, `CMAKE_C_LINKER_LAUNCHER=fastci`, `CMAKE_CXX_LINKER_LAUNCHER=fastci`, and `RUSTC_WRAPPER=fastci`. - Direct-mode include manifest cache (hashes transitive headers/imports directly without spawning the preprocessor on hits). - Opt-in preprocessor fallback cache (`FASTCI_PP_CACHE=1`) for computed `#include MACRO` directives. - Supports GCC, Clang, MinGW, MSVC `cl.exe`, `rustc`, `zig`, `swiftc`, `esbuild`, `@file.rsp` response files, and C/C++ link invocations (Linux/macOS/MinGW; MSVC `link.exe` passes through cleanly). 2. **Critical-Path DAG Runner (`fastci run fastci.json`)**: - Memory-aware, slot-aware critical-path scheduler (`cpu_slots`, `mem_mb`, `weight`). - Direct-spawn process execution (`CreateProcessA` on Windows, `posix_spawn` on Unix) when using `cmd` arrays. - Local Content-Addressable Storage (CAS) with `.slz` (LZ4 / store / Zstd) archives and NTFS/POSIX hardlink staging. - Statcache v4 (`statcache.bin`, `FCS2` format) with NTFS USN journal validation on Windows and 12 KiB CRC32C edge sampling (`verify_inputs: "sample"`). - SIMD-accelerated 10-language transitive dependency scanner (`scan_deps`). 3. **Remote CAS & Sandboxed Distributed Compilation**: - `fastci remote-serve`: multi-threaded HTTP/1.1 Keep-Alive CAS server with Bearer auth, disk quota LRU eviction, and `--read-only` mode. - `fastci dist-serve` + `fastci dist-worker`: distributed compilation coordinator + stateless workers supporting `preproc` mode (C/C++) and `archive` (`FCIA` v1) mode (C/C++/Rust/arbitrary builds), capability matching (`compiler_id`, `target_triple`, `sysroot_hash`, `toolchain_tag`, `toolchain_hash`), and strict sandboxing (`bwrap`, `setrlimit`, Windows Job Objects). --- ## 2. Verified GitHub Actions Integration (`seregonwar/FastCi@v0.3.0`) Exact inputs defined in `action.yml`: - `version`: release tag (`v0.3.0`, `latest`, or `source`). Default: `v0.3.0`. - `variant`: `auto` (native everywhere), `native`, or `filc` (memory-safe Fil-C bundle on Linux x86_64/aarch64; auto-falls back to `native` on macOS). Default: `auto`. - `cache-dir`: local CAS/statcache path. Default: `${{ runner.temp }}/fastci-cache`. - `cache-enable`: auto restore/save `cache-dir` via `actions/cache@v4`. Default: `true`. - `cache-key-prefix`: prefix for `actions/cache` key. Default: `fastci`. - `verify-inputs`: `fast` | `sample` | `strict`. Default: `sample`. - `remote-cache`: optional Remote CAS URL (`http://`, `https://`, `file://`). - `remote-token`: optional Bearer token (always pass via `${{ secrets.* }}`; masked automatically with `::add-mask::`). - `remote-read-only`: `true` | `false` | `""` (empty defaults to `true` on `pull_request` and `pull_request_target`!). - `enable-cmake-launcher`: exports `CMAKE_C/CXX_COMPILER_LAUNCHER` and `CMAKE_C/CXX_LINKER_LAUNCHER=fastci`. Default: `false`. - `enable-rustc-wrapper`: exports `RUSTC_WRAPPER=fastci`. Default: `false`. - `run-doctor`: runs `fastci doctor` after install. Default: `false`. Exact outputs: - `fastci-path`: absolute path to installed `fastci` binary. - `cache-dir`: resolved `FASTCI_CACHE_DIR`. - `cache-hit`: exact hit indicator from `actions/cache@v4`. ### Recommended GitHub Actions Recipe (C/C++ CMake + Ninja across Linux/macOS/Windows) ```yaml name: Build on: [push, pull_request] jobs: build: strategy: fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 - uses: seregonwar/FastCi@v0.3.0 with: enable-cmake-launcher: true verify-inputs: sample remote-cache: ${{ vars.FASTCI_REMOTE_CACHE }} remote-token: ${{ secrets.FASTCI_REMOTE_TOKEN }} - name: Configure & Build run: | cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release cmake --build build --parallel - name: Inspect Cache Efficiency if: always() run: fastci stats ``` ### Recommended GitHub Actions Recipe (Rust / Cargo) ```yaml - uses: seregonwar/FastCi@v0.3.0 with: enable-rustc-wrapper: true verify-inputs: sample - run: cargo test --release - if: always() run: fastci stats ``` --- ## 3. Exact `fastci.json` Manifest Specification Verified against `src/pipeline/manifest.c` and `include/fastci/types.h`. ### Top-Level Keys | Key | Type | Default | Limits / Notes | |---|---|---|---| | `$schema` | string | — | Optional (`https://seregonwar.github.io/FastCi/schema/fastci.schema.json`) | | `name` | string | filename | Pipeline display name | | `version` | string | `"1"` | Pipeline version label | | `cache_dir` | string | `.fastci-cache` | Local CAS & statcache path; overridden by `--cache-dir` or `FASTCI_CACHE_DIR` | | `verify_inputs` | `"fast" \| "sample" \| "strict"` | `"sample"` | Overridden by `--verify-inputs` or `FASTCI_VERIFY_INPUTS` | | `remote_cache` | string | none | Remote CAS URL (`http://`, `https://`, `file://`); overridden by `--remote-cache` / `FASTCI_REMOTE_CACHE` | | `remote_read_only` | boolean | `false` | Read-only Remote CAS; overridden by `--remote-read-only` / `FASTCI_REMOTE_READ_ONLY=1` | | `workers` | integer | logical CPUs | `1..256`; overridden by `-j` / `--jobs` / `FASTCI_JOBS` | | `max_ram_mb` | integer | host RAM | RAM budget in MiB; overridden by `--ram` | | `env` | `Record` | `{}` | Up to 128 global env vars (hashed into cache keys) | | `jobs` | `Job[]` | **required** | `1..1024` jobs after matrix expansion | ### Job Object Keys | Key | Type | Default | Limits / Notes | |---|---|---|---| | `id` | string | **required** | Unique ID; supports `${matrix.k}` | | `name` | string | `id` | Human-readable label | | `cwd` | string | workspace root | Working directory (path traversal outside workspace is rejected) | | `cmd` | `string[]` | — | **Preferred** direct argv (`1..512` args); mutually exclusive with `shell` | | `shell` | string | — | Shell command string; mutually exclusive with `cmd` (avoid on Windows!) | | `toolchain_cmd` | `string[]` | none | Runs once per pipeline to fingerprint toolchain stdout into the job cache key (e.g. `["rustc", "-vV"]`) | | `needs` | `string[]` | `[]` | Up to 64 upstream job IDs; cycle detection rejects cyclic graphs | | `inputs` | `string[]` | `[]` | Up to 128 relative paths/globs (`*`, `?`, `**`, `!exclude`) | | `critical_inputs` | `string[]` | `[]` | Up to 128 relative paths/globs ALWAYS verified with full strict BLAKE3-256 | | `outputs` | `string[]` | `[]` | Up to 64 relative file/directory paths archived into CAS and restored on hit | | `scan_deps` | `string[]` | `[]` | Up to 128 entry-point files/globs for SIMD transitive dep scan (alias: `scan_c_deps`) | | `lang` | string | `"auto"` | `auto \| c \| asm \| rust \| go \| zig \| python \| js \| java \| csharp \| swift` | | `include_dirs` | `string[]` | `[]` | Up to 128 search dirs for `scan_deps` (alias: `search_dirs`) | | `verify_inputs` | string | pipeline default | Per-job override: `fast \| sample \| strict` | | `env` | `Record` | `{}` | Up to 128 job env vars merged over pipeline `env` | | `cpu_slots` | integer | `1` | `1..256` scheduler CPU slots | | `mem_mb` | integer | `256` | `1..1048576` MiB scheduler RAM hint (alias: `ram_mb`) | | `retries` | integer | `0` | `0..10` retries on non-zero exit | | `timeout_ms` | integer | `0` | Milliseconds (`0` = unlimited) | | `weight` | integer | `10` | `1..1000000` critical-path priority weight | | `cache` | boolean | auto (`true` if any inputs/outputs/scan_deps) | Explicit cache toggle | | `allow_failure` | boolean | `false` | Record failure without failing the pipeline exit code | | `matrix` | `Record` | none | Cartesian expansion (up to 256 combinations per job) | ### Variable Expansion Tokens Available in `id`, `name`, `cwd`, `cmd`, `shell`, `toolchain_cmd`, `needs`, `inputs`, `critical_inputs`, `outputs`, `scan_deps`, `include_dirs`, `lang`, `env`: - `${workspace}` — canonical workspace root path - `${os}` — `"linux"`, `"macos"`, `"windows"`, or `"posix"` - `${arch}` — host architecture (e.g. `x86_64`, `aarch64`, `arm64`) - `${cpus}` — logical CPU count - `${matrix.}` — matrix dimension value - `${env.}` — environment variable lookup ### Glob Matching Semantics (`fci_glob_match` — Iterative O(P*S)) - `*` matches any sequence of characters within a single path segment (does NOT cross `/`). - `?` matches any single character except `/`. - `**` matches across path segments. - `**/` matches zero or more path segments ONLY at a segment boundary (start of path or immediately after `/`). For example, `src/**/*.c` matches both `src/main.c` and `src/a/b/main.c`, while `src**/*.c` does NOT collapse `**/`. - Leading `!` in `inputs` / `critical_inputs` excludes matching paths (e.g. `["src/**", "!src/**/*.tmp", "!**/build/**"]`). - Walked directory trees automatically skip common cache directories (`.git`, `.fastci-cache`, etc.) unless `FASTCI_WALK_CACHE_DIRS=1`. --- ## 4. High-Performance CI Engineering Rules ### Rule 1: Eliminate Shell Spawns (`cmd` over `shell`) - `cmd: ["cmake", "--build", "build", "--parallel"]` invokes `CreateProcessA` / `posix_spawn` directly. - `shell: "..."` pays `cmd.exe` / `/bin/sh` startup latency on every job (20-80 ms wasted per invocation on Windows) and risks platform-specific quoting breakage. ### Rule 2: Maximize DAG Width & Critical-Path Priority - Split monolithic "build-and-test" scripts into independent DAG nodes (`compile-lib`, `lint`, `codegen`, `test-unit`, `test-integration`). - Assign higher `weight` (e.g. `100` for heavy compile/LTO, `20` for unit tests, `10` for lint) so FastCi's critical-path scheduler starts long-pole jobs at `t = 0`. - Set accurate `cpu_slots` and `mem_mb` for heavy link/LTO/Rust steps (e.g. `"cpu_slots": 2, "mem_mb": 4096`) to prevent OOM thrashing while small jobs fill spare cores. ### Rule 3: Keep Cache Keys Tight & Sound - Never glob the entire repo (`["**"]`) as `inputs` — touching `README.md` or a docs file will invalidate every build artifact! - Always exclude build outputs and temp directories (`"!build/**"`, `"!target/**"`, `"!node_modules/**"`). - Put lockfiles (`Cargo.lock`, `package-lock.json`, `go.sum`, `CMakeLists.txt`, `cmake/**`) into `critical_inputs` so they are always hashed with full BLAKE3-256 regardless of `verify_inputs`. - Use `scan_deps` + `include_dirs` for C/C++/ASM/Rust/Go/Zig/Python/JS/Java/C#/Swift entry points so only transitively referenced files enter the cache key. - Always declare `toolchain_cmd` (e.g. `["gcc", "--version"]`, `["rustc", "-vV"]`, `["node", "--version"]`) on cached DAG jobs. - Avoid nondeterministic timestamps or absolute paths embedded in outputs: pass `-ffile-prefix-map=${workspace}=.` (GCC/Clang), `/Brepro` + `/experimental:deterministic` (MSVC), or `--remap-path-prefix` (Rust). ### Rule 4: Cut Windows (2x) and macOS (10x) Runner Costs - Use Ninja (`-G Ninja`) with CMake on Windows instead of MSBuild/Visual Studio generator to unlock full parallelism + `CMAKE_C/CXX_COMPILER_LAUNCHER=fastci`. - Point `FASTCI_CACHE_DIR` to a short local path on the same NTFS volume as the workspace (`C:\fc` or `%RUNNER_TEMP%\fastci-cache`) so FastCi uses zero-copy NTFS hardlinks and USN journal validation. - Keep `verify_inputs: "sample"` (default) for CI builds (12 KiB CRC32C edge sampling + USN/inode metadata check); switch to `"strict"` only for release signing/reproducibility audits. - On MSVC, avoid `/Zi` (shared `vc140.pdb` lock prevents per-TU compiler caching); prefer `/Z7` (embedded debug info) in CI builds so every `.obj` is 100% cacheable! - On macOS (10x GitHub Actions minute multiplier), enable Remote CAS (`fastci remote-serve`) + `enable-cmake-launcher: true` or `enable-rustc-wrapper: true` so PR builds hit warm cache in seconds. ### Rule 5: Inspect & Eliminate Cache Misses Scientifically - Run `fastci stats` (or `fastci cache stats --json`) at the end of CI jobs. It reports exact hit rate, direct-mode hits, preprocessor hits, remote hits, and itemized reasons why invocations were uncacheable (e.g. MSVC `/Zi`, computed `#include` without `FASTCI_PP_CACHE=1`, `-M` depfile mismatch, unsupported flag). - Generate a Chrome Trace (`fastci run fastci.json --trace trace.json`) and open it in `chrome://tracing` or https://ui.perfetto.dev to spot idle gaps, serial bottlenecks, and critical-path stragglers. - Run `fastci doctor --json` to check CPU SIMD features (AVX2/SSE4.2/NEON/ARM-CRC32), cache directory health, statcache version, and Remote CAS latency. ### Rule 6: Security & Cache Poisoning Prevention - NEVER give pull requests from forks write access to a shared Remote CAS. Always set `FASTCI_REMOTE_READ_ONLY=1` (or `remote-read-only: true`, which `seregonwar/FastCi@v0.3.0` sets automatically on `pull_request` / `pull_request_target`). - Always authenticate `fastci remote-serve` and `fastci dist-serve` with `--token` / `FASTCI_REMOTE_TOKEN` / `FASTCI_DIST_TOKEN` behind TLS (Caddy/Nginx reverse proxy). - Never enable `--unsafe-win-defender-exclude` on untrusted PR workflows. --- ## 5. Complete CLI Subcommand Reference (`src/main.c`) - `fastci run [-f fastci.json] [-j N] [--ram MB] [--target ID] [--cache-dir DIR] [--no-cache] [--no-stat-cache] [--verify-inputs fast|sample|strict] [--remote-cache URL] [--remote-read-only] [--remote-token TOK] [--keep-going] [--dry-run] [--report FILE] [--trace FILE] [--summary FILE] [-v]` - `fastci init [--dir DIR] [-o fastci.json] [--force]` — Auto-detects project build system and scaffolds `fastci.json`. - `fastci validate [-f fastci.json]` — Parses manifest, validates schema, checks DAG acyclicity. - `fastci plan [-f fastci.json]` — Prints topological critical-path execution plan (Rank, Job ID, Slots, RAM, CritWt, Cache, Needs). - `fastci wrap [--cache-dir DIR] [--remote-cache URL] [--remote-read-only] [--verify-inputs fast|sample|strict] [-v] -- ` — Compiler/linker cache wrapper (alias: `fastci cc`). Also works directly as `CMAKE_*_LAUNCHER` / `RUSTC_WRAPPER` without the `wrap` subcommand. - `fastci remote-serve --dir DIR [--host 127.0.0.1] [--port 8980] [--workers N] [--max-mb N] [--token SECRET] [--read-only] [--max-requests N]` - `fastci dist-serve --token SECRET [--host H] [--port N] [--max-jobs N] [--worker-ttl-ms N] [--job-ttl-ms N] [--state-file PATH] [--save-interval-ms N] [--max-pending-jobs N] [--max-running-jobs N] [--max-slots-per-worker N] [--max-jobs-per-worker N] [--quiet]` - `fastci dist-worker --scheduler URL --token TOK --cas URL --id ID --cc PATH [--slots N] [--work DIR] [--compiler-id HEX] [--cas-token TOK] [--toolchain-tag TAG] [--toolchain-hash] [--sandbox auto|off|rlimit|bwrap] [--bwrap PATH] [--sandbox-mem-mb N] [--sandbox-max-procs N]` - `fastci dist-info` — Prints compiled distributed support and env vars. - `fastci doctor [--cache-dir DIR] [--remote-cache URL] [--remote-token TOK] [--json]` - `fastci deps [--lang auto|c|asm|rust|go|zig|python|js|java|csharp|swift] [-I DIR]... [-w DIR] [--json] ` - `fastci hash ` — Hardware-accelerated BLAKE3-256 hash. - `fastci pack [--codec lz4|store|zstd] [-j N]` - `fastci unpack [-j N]` - `fastci cache [--cache-dir DIR] [--max-mb N] [--json]` (alias: `fastci stats`) - `fastci emit-gha [-f fastci.json] [-o .github/workflows/fastci.yml] [--unsafe-win-defender-exclude]` - `fastci bench [--iters N] [--json]` - `fastci version` --- ## 6. Environment Variables (`FASTCI_*`) ### Core & Cache - `FASTCI_CACHE_DIR`: Local CAS & Statcache directory. - `FASTCI_VERIFY_INPUTS`: `fast` | `sample` | `strict`. - `FASTCI_NO_CACHE=1`: Bypass DAG CAS lookup/store. - `FASTCI_STAT_CACHE=0`: Disable statcache. - `FASTCI_JOBS=N`: Default worker concurrency. - `FASTCI_CC_DISABLE=1`: Pass through compiler/linker invocations directly without caching. - `FASTCI_PP_CACHE=1`: Enable preprocessor fallback caching for computed `#include` macros. - `FASTCI_STATS=0`: Disable wrapper stats recording. - `FASTCI_STATS_MAX_BYTES`: Override stats log rotation limit. - `FASTCI_WALK_CACHE_DIRS=1`: Include cache directories during glob directory walks. ### Remote CAS - `FASTCI_REMOTE_CACHE`: Remote CAS base URL (`http://`, `https://`, `file://`). - `FASTCI_REMOTE_TOKEN`: Bearer token for Remote CAS. - `FASTCI_REMOTE_READ_ONLY=1`: Fetch-only mode (mandatory for untrusted PRs). ### Distributed Compilation - `FASTCI_DIST=0`: Disable distributed offload. - `FASTCI_DIST_URL`: Coordinator URL (`http://...` or `https://...`). - `FASTCI_DIST_TOKEN`: Bearer token for coordinator. - `FASTCI_DIST_CAS_URL`: CAS URL for distributed artifacts (defaults to `FASTCI_REMOTE_CACHE`). - `FASTCI_DIST_CAS_TOKEN`: Bearer token for distributed CAS (defaults to `FASTCI_REMOTE_TOKEN`). - `FASTCI_DIST_TIMEOUT_MS`: Per-job remote execution timeout. - `FASTCI_DIST_COMPILER_ID`: Explicit compiler fingerprint hex. - `FASTCI_DIST_TARGET_TRIPLE`: Target triple for worker capability matching (e.g. `x86_64-linux-gnu`). - `FASTCI_DIST_SYSROOT_HASH`: Sysroot hash for cross-compilation safety. - `FASTCI_DIST_TOOLCHAIN_TAG`: Logical toolchain tag (e.g. `gcc-14`, `rust-1.85`). - `FASTCI_DIST_TOOLCHAIN_HASH`: Exact toolchain hash. - `FASTCI_DIST_ARCHIVE=1`: Enable `FCIA` v1 archive transport mode (for multi-file/Rust/arbitrary remote jobs). - `FASTCI_DIST_ARCHIVE_ROOT`: Root directory for `FCIA` archive packaging. --- ## 7. Mandatory AI Agent Verification Workflow When an AI coding agent creates or edits a FastCi pipeline or CI workflow, it MUST execute this check sequence before finishing: 1. Validate schema & DAG acyclicity: `fastci validate -f fastci.json` 2. Inspect topological order, slots, RAM, and critical-path weights: `fastci plan -f fastci.json` 3. Verify execution plan without side effects: `fastci run -f fastci.json --dry-run` 4. Run and inspect machine-readable metrics: `fastci run -f fastci.json --report fastci-report.json --trace fastci-trace.json` 5. Verify compiler cache hit rate and eliminate uncacheable invocations: `fastci cache stats --json` 6. Check environment health and SIMD acceleration: `fastci doctor --json` ### Common AI Hallucinations to AVOID (Real vs Invalid Keys) - VALID: `"shell": "..."` — INVALID: `"shell_cmd"`, `"run"`, `"script"`. - VALID: `"cache": true` — INVALID: `"cacheable"`. - VALID: `"workers": 8` — INVALID: `"default_workers"`, `"concurrency"`. - VALID: `"needs": ["build"]` — INVALID: `"depends_on"`, `"deps"`, `"after"`. - VALID: `"scan_deps": ["src/main.c"]` — INVALID: `"auto_deps"`, `"headers"`. - VALID: `"lang": "c"` — INVALID: `"scan_deps_lang"`, `"language"`. - VALID: `"mem_mb": 2048` (or `"ram_mb"`) — INVALID: `"memory"`, `"memory_mb"`. - VALID: `"critical_inputs": [...]` — INVALID: `"strict_inputs"`, `"lockfiles"`.