Part of Epic #1423: Fast/cheap LLM build-runner.
The terraphim-ai project uses an adaptive build system (build-runner-llm) that automatically detects CI configuration and transforms build commands using the DevOpsRunner knowledge graph.
Push Event → build-runner-llm → detect CI config → extract commands → transform via KG → validate → execute → post status
Key principle: KG-first architecture. Commands are matched via Aho-Corasick automata (0.1s latency) rather than LLM extraction, keeping costs below $0.01 per build.
The build-runner detects CI configuration in this priority order:
- GitHub Actions (
.github/workflows/*.yml) - Extractsrunsteps from all workflows that trigger on push/pull_request - BUILD.md - Project-specific build documentation with bash code blocks
- Cargo workspace (
Cargo.toml) - Standard Rust commands - Makefile - Runs
make - Earthfile - Extracts
RUNlines containing cargo/build/test - package.json - Node.js projects (bun install/build/test)
The build-runner automatically discovers and executes commands from all GitHub Actions workflows that trigger on push or pull_request events. This means your existing CI configuration is leveraged directly:
- No need to duplicate build commands
- Uses the same commands as GitHub Actions
- Extracts
runsteps from all jobs
Example: If .github/workflows/ci-pr.yml contains:
jobs:
build:
steps:
- run: cargo fmt --all -- --check
- run: cargo clippy --workspace -- -D warnings
- run: cargo test --workspaceThe build-runner will execute these exact commands locally.
When Cargo.toml is detected:
cargo fmt --all -- --check
cargo clippy --workspace --all-targets -- -D warnings
cargo build --workspace
cargo test --workspace --no-fail-fastThe DevOpsRunner knowledge graph (~/.config/terraphim/docs/src/kg/devops/) provides semantic command transformations:
| Original Command | Transformed Command | Context |
|---|---|---|
cargo build |
rch build |
Remote compilation |
npm install |
bun install |
Package manager |
npm run build |
bun run build |
Build step |
npm test |
bun test |
Test runner |
Transformations are applied via terraphim-agent replace --role DevOpsRunner.
Every build tracks costs automatically:
- KG lookup: $0.0001 per command transformation
- LLM call: $0.005 (only used for cold-start extraction)
- Warning threshold: $0.01
- Fail threshold: $0.05
Cost metrics are sent to Quickwit telemetry:
{
"timestamp": "2026-05-11T16:30:00Z",
"agent": "build-runner-llm",
"project": "terraphim-ai",
"sha": "abc123",
"cost_cents": 0.0001,
"kg_lookups": 4,
"llm_calls": 0,
"status": "success"
}All commands are validated against a whitelist before execution:
Allowed: cargo, make, npm, yarn, pnpm, bun, docker, yq, test, echo, cat, ls, cd, mkdir, rm, cp, mv, git, curl, wget, tar, unzip, zip, chmod, chown, source, export, eval
Rejected patterns:
sudocurl ... | shorwget ... | shrm -rf /- Direct device writes (
> /dev/sd*) - Disk formatting (
mkfs.*,dd if=...of=...)
Builds are triggered automatically on push events to Gitea:
- Developer pushes commit
- Gitea webhook fires
- ADF orchestrator receives push event
build-runneragent spawned withADF_PUSH_*environment variables- Build executes and posts
adf/buildcommit status
To manually trigger a build for testing:
export ADF_PUSH_SHA=<commit-sha>
export ADF_PUSH_REF=refs/heads/<branch>
export ADF_WORKING_DIR=/path/to/repo
export GITEA_OWNER=terraphim
export GITEA_REPO=terraphim-ai
export GITEA_TOKEN=<token>
export GITEA_URL=https://git.terraphim.cloud
bash scripts/build-runner-llm.shCheck build status via Gitea commit status API:
curl -H "Authorization: token $GITEA_TOKEN" \
"$GITEA_URL/api/v1/repos/terraphim/terraphim-ai/commits/<sha>/statuses"If the adaptive build-runner causes issues, restore the deterministic build-runner:
ssh bigbox
sudo systemctl stop adf-orchestrator
# Restore from git history
git -C /opt/ai-dark-factory/conf.d checkout HEAD -- terraphim.toml
sudo systemctl start adf-orchestratorTo add new build command transformations:
- Create a new file in
~/.config/terraphim/docs/src/kg/devops/ - Use the format:
# command name
Description of the command.
synonyms:: alt1, alt2, alt3
related:: other-command, another-command
transforms:: old-command → new-command
context:: build
cost:: low|medium|high- Reload terraphim-agent config:
terraphim-agent config reload - Test:
terraphim-agent search --role DevOpsRunner "your command"
scripts/build-runner-llm.sh- Build runner implementation~/.config/terraphim/docs/src/kg/devops/- Build ontology knowledge graphcrates/terraphim_orchestrator/tests/fixtures/conf.d/terraphim.toml- Agent definition
- Epic #1423: Fast/cheap LLM build-runner
- ADR-001: Build-runner architecture decisions
.docs/research-fast-cheap-build-runner.md.docs/design-build-runner-llm.md