From 95a8932fc2080e5edb7fe1590d3bdbebd5d42ec5 Mon Sep 17 00:00:00 2001 From: altrdev Date: Mon, 19 Oct 2026 21:00:53 +0200 Subject: [PATCH] docs: llms.txt, llms-full.txt and a skill for agents that use torchio Co-Authored-By: Claude Sonnet 5.5 --- .github/workflows/docs.yml | 9 ++++ AGENTS.md | 1 + CHANGELOG.md | 5 ++ book/llms.py | 93 ++++++++++++++++++++++++++++++++++++++ book/src/SUMMARY.md | 1 + book/src/agents.md | 29 ++++++++++++ book/src/development.md | 3 +- skills/torchio/SKILL.md | 72 +++++++++++++++++++++++++++++ 8 files changed, 212 insertions(+), 1 deletion(-) create mode 100644 book/llms.py create mode 100644 book/src/agents.md create mode 100644 skills/torchio/SKILL.md diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index edc6ec7..bd507a5 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -9,6 +9,7 @@ on: paths: - book/** - docs/** + - skills/** - examples/endpoints_reference.rs - src/endpoints.rs - src/config.rs @@ -69,6 +70,14 @@ jobs: head -n 1 install.sh | grep -q '^#!/bin/sh$' cp install.sh book/book/install + # for language models: the index of the pages and all of them in one file (llmstxt.org), and the skill + # that tells an agent how to run a test, which is also copied to a place that can be curled + - name: Publish llms.txt, llms-full.txt and the skill next to the pages + run: | + python3 book/llms.py book/book + cp skills/torchio/SKILL.md book/book/SKILL.md + grep -q '^name: torchio$' book/book/SKILL.md + - name: Every link between the pages has a target run: python3 book/check-links.py book/book diff --git a/AGENTS.md b/AGENTS.md index c07e320..ddcb09f 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -24,6 +24,7 @@ CI (`.github/workflows/ci.yml`) runs all of the above on Linux and macOS, so run - `assets/ui.html`: the control panel, a single self-contained page. - `tests/`: integration tests; shared helpers are in `tests/common`. - `book/`: documentation (mdBook), published at . `book/src/reference.md` is generated, do not edit it by hand: `cargo run --example endpoints_reference > book/src/reference.md`. `book/src/development.md` has the full module map. +- `skills/torchio/SKILL.md`: the skill for agents that *use* torchio (not for working on this repo). `book/llms.py` writes `llms.txt` and `llms-full.txt` from the book. Keep the skill in line with the endpoints when they change. - `deploy/`: Kubernetes manifest and Helm chart. ## Conventions diff --git a/CHANGELOG.md b/CHANGELOG.md index 6656ac7..967bd77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to this project are documented here. The GitHub release of each version uses the matching section. +## Unreleased + +### Documentation +- The site has `llms.txt` (an index of the pages) and `llms-full.txt` (all of them in one file) for language models, and a skill for agents that use torchio, at `/SKILL.md` and in `skills/torchio/`. The page *For AI agents* says how to install it. + ## 4.6.0 - 2026-10-19 ### Added diff --git a/book/llms.py b/book/llms.py new file mode 100644 index 0000000..0014330 --- /dev/null +++ b/book/llms.py @@ -0,0 +1,93 @@ +#!/usr/bin/env python3 +"""Writes llms.txt and llms-full.txt from the pages of the book, in the order of SUMMARY.md. +llms.txt is the index for a language model (llmstxt.org); llms-full.txt has every page in one file. +Usage: python3 book/llms.py book/book (after mdbook build book)""" +import os +import re +import sys + +out = sys.argv[1] +src = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'src') +site = 'https://' + open(os.path.join(src, 'CNAME')).read().strip() +version = open(os.path.join(src, 'version.md')).read().strip() if os.path.exists(os.path.join(src, 'version.md')) else 'dev' +description = re.search(r'^description = "(.*)"$', open(os.path.join(os.path.dirname(src), 'book.toml')).read(), re.M).group(1) +# the changelog is a long list of every release and is not what a model needs to use the tool +left_out = {'changelog.md'} + + +def read(page): + text = open(os.path.join(src, page)).read().replace('{{#include version.md}}', version) + # a link to a page of the book becomes the address of that page on the site + text = re.sub(r'\]\(([a-z0-9-]+)\.md(#[^)]*)?\)', lambda m: f']({site}/{m.group(1)}.html{m.group(2) or ""})', text) + # the images are of no use in text + return '\n'.join(line for line in text.split('\n') if not line.startswith('![')).strip() + '\n' + + +# what each page is about, in a line: a sentence taken from the page itself says too little. A page that is not here +# is listed with its title only. +about = { + 'introduction.md': 'What torchio is and what it is for', + 'install.md': 'Docker, Homebrew, the install script, release binaries, building from source', + 'getting-started.md': 'Start a server and watch it in 30 seconds', + 'what-you-can-test.md': 'Recipes: OOM kills, autoscaling, probes, timeouts, disk, leaks, readiness, restarts, descriptors', + 'endpoints.md': 'What each endpoint does, with examples and answers', + 'reference.md': 'Every endpoint with its parameters, defaults, limits and command, written from the same catalog as GET /help', + 'starting-a-test.md': 'The torchio commands that call the endpoints of a running server, including scenario and payload', + 'scenarios.md': 'POST /scenario: a list of steps (cpu, memory, disk, fd, connections, ready, block) run one after the other', + 'agents.md': 'How an agent can use torchio: /help, llms.txt and the skill', + 'shell-completion.md': 'Completion scripts for bash, zsh and fish', + 'watch.md': 'torchio watch: a terminal view of a running server that can also start tests', + 'control-panel.md': 'The page at /ui to watch a server and start tests with sliders', + 'configuration.md': 'Every environment variable, its default and its limit', + 'token.md': 'TOKEN: which endpoints need a bearer token', + 'logs.md': 'Plain text and JSON logs (LOG_FORMAT), the access log', + 'shutdown.md': 'What happens on SIGTERM and SIGINT, and the drain', + 'docker.md': 'The image, its tags, platforms, limits and health check', + 'examples.md': 'Kubernetes manifests, the Helm chart and Compose files', + 'how-it-works.md': 'Worker threads and the async runtime', + 'load-testing.md': 'Using torchio with hey and k6 to load several cores', + 'development.md': 'Source layout, tests, documentation site and releases', + 'security.md': 'Where it is safe to run it, and the license', +} + + +sections = [] # (heading, [(title, page)]) +for line in open(os.path.join(src, 'SUMMARY.md')): + heading = re.match(r'^# (.+)$', line) + entry = re.match(r'^\s*- \[([^\]]+)\]\(([^)]+\.md)\)', line) + if heading and heading.group(1) != 'Summary': + sections.append((heading.group(1), [])) + elif entry: + if not sections: + sections.append(('Start', [])) + sections[-1][1].append((entry.group(1), entry.group(2))) + elif line.startswith('[') and (m := re.match(r'^\[([^\]]+)\]\(([^)]+\.md)\)', line)): + sections.append(('About', [(m.group(1), m.group(2))])) + +index = [ + '# torchio', + '', + f'> {description}', + '', + f'torchio {version} is a single static binary written in Rust that burns CPU, holds memory, fills disk, answers slowly or ' + 'returns any HTTP status, on demand over HTTP. Use it to test autoscaling, resource limits, OOM kills, probes, timeouts and ' + 'retries. A running server describes its own endpoints, parameters and limits as JSON at `GET /help`, and what it holds right ' + 'now at `GET /info`; prefer those to guessing. Every endpoint that changes state is also a command: `torchio cpu 80 --hold 60`. ' + f'The whole documentation in one file is {site}/llms-full.txt.', + '', +] +full = [f'# torchio {version}: documentation', '', f'> {description}', ''] +for heading, pages in sections: + index += [f'## {heading}', ''] + for title, page in pages: + text = read(page) + said = about.get(page, '') + index.append(f'- [{title}]({site}/{page[:-3]}.html)' + (f': {said}' if said else '')) + if page not in left_out: + full += [text, '---', ''] + index.append('') +index += ['## Optional', '', f'- [Skill for agents]({site}/SKILL.md): how to run a test with torchio, as a skill file', ''] + +open(os.path.join(out, 'llms.txt'), 'w').write('\n'.join(index)) +open(os.path.join(out, 'llms-full.txt'), 'w').write('\n'.join(full)) +print(f'llms.txt: {len(index)} lines, llms-full.txt: {len(full)} lines') diff --git a/book/src/SUMMARY.md b/book/src/SUMMARY.md index aa2ccfc..f61a6d6 100644 --- a/book/src/SUMMARY.md +++ b/book/src/SUMMARY.md @@ -12,6 +12,7 @@ - [Starting a test](starting-a-test.md) - [Scenarios](scenarios.md) - [Shell completion](shell-completion.md) +- [For AI agents](agents.md) # Watch it diff --git a/book/src/agents.md b/book/src/agents.md new file mode 100644 index 0000000..870c32b --- /dev/null +++ b/book/src/agents.md @@ -0,0 +1,29 @@ +# For AI agents + +An agent that runs tests with torchio has three things to read, from the least to the most work. + +## The server describes itself + +`GET /help` lists every endpoint with its parameters, defaults and the limits of that instance, as JSON, and `GET /info` says what the server holds right now and what is left of each budget. They come from the same definitions the endpoints use, so they are right for the version and the settings that are running. See [`/help`](endpoints.md#help) and [`/info`](endpoints.md#info). + +## llms.txt + +The site follows the [llms.txt](https://llmstxt.org) convention: + +- is an index of the pages, each with a line about it. +- is the whole documentation in one file, without the changelog. + +Both are written from the pages of the book when the site is built, so they match the version that is published. + +## A skill + +`skills/torchio/SKILL.md` is a skill that tells an agent how to put an instance under pressure: look at `/help` and `/info` first, which tests take the instance away and need a yes (`/crash`, `/oom`, `/block`), the budgets and their `429`, scenarios, and how to watch the result. It is also at . + +To use it with Claude Code, put it in a folder of skills: + +``` +mkdir -p ~/.claude/skills/torchio +curl -fsSL https://torchio.altr.dev/SKILL.md -o ~/.claude/skills/torchio/SKILL.md +``` + +Use `.claude/skills/torchio/` inside a project to share it with the people who work on that project. Other agents that read `SKILL.md` files take it the same way, from the folder where they look for skills. diff --git a/book/src/development.md b/book/src/development.md index 4bb290e..1db9097 100644 --- a/book/src/development.md +++ b/book/src/development.md @@ -50,7 +50,8 @@ src/ assets/ui.html the control panel, a single static page tests/ integration tests, by area deploy/ Kubernetes manifests and the Helm chart -book/ this documentation, with mdBook (`SUMMARY.md` is the list of pages) +book/ this documentation, with mdBook (`SUMMARY.md` is the list of pages); `llms.py` writes llms.txt from it +skills/torchio/ the skill that tells an agent how to run a test, published at /SKILL.md examples/ the reference of the endpoints, written from the catalog Dockerfile builds the binary for both platforms with cargo-zigbuild, into an image of one file ``` diff --git a/skills/torchio/SKILL.md b/skills/torchio/SKILL.md new file mode 100644 index 0000000..27aa9c4 --- /dev/null +++ b/skills/torchio/SKILL.md @@ -0,0 +1,72 @@ +--- +name: torchio +description: Put a container or service under controlled pressure with torchio, a small Rust server that burns CPU, holds memory, fills disk, answers slowly or fails on demand over HTTP. Use it to test autoscaling, resource limits, OOM kills, probes, timeouts, retries and restarts, or when the user mentions torchio. +--- + +# torchio + +torchio is a server you run in the thing under test (a container, a pod, a VM). You ask it over HTTP, or with the `torchio` command, to consume a resource or to misbehave, and you watch how the platform reacts. Full documentation: https://torchio.altr.dev, all in one file at https://torchio.altr.dev/llms-full.txt. + +## Before you start + +- The server must be running where the test is meant to happen: `docker run -p 3000:3000 altrdev/torchio`, or `torchio serve`. The port is `3000` (`PORT`). +- Check what you are talking to: `curl -s localhost:3000/info` is what it holds right now and what is left of each budget, and `curl -s localhost:3000/help` lists every endpoint with its parameters, defaults and limits. Use these instead of remembering numbers: the limits come from the server's own settings (`MAX_MEMORY_MB`, `MAX_DISK_MB`, `MAX_HOLD_SECONDS`, ...). +- If `/info` says a token is needed, the endpoints that change state want `Authorization: Bearer ` (or `--token` / `TOKEN` with the command). Ask the user for it; never guess one. +- It consumes resources on purpose. Run it only in environments the user controls, never on a shared or production service unless they say so. + +## Ask before you run these + +`/crash` (ends the process), `/oom` (allocates until the kernel kills it, needs `ALLOW_OOM=1`), `/block` (freezes the whole server, `/info` included) and `/ready/off` on something real. They are the point of some tests, but they take the instance away. Say what will happen and wait for a yes. + +## The endpoints + +Each one that changes state is also a command: `torchio [parameters]`, same names as the query parameters, in the order of the reference. + +| To test | Request | Command | +|---|---|---| +| CPU load at a level (autoscaling) | `/cpu?percent=80&hold=300` | `torchio cpu 80 --hold 300` | +| CPU on concurrent requests | `/stress?number=40` (needs about one concurrent request per worker) | `torchio stress 40` | +| Memory, OOM kills | `/memory?mb=400&hold=60` | `torchio memory 400 --hold 60` | +| A memory leak | `/leak?rate=10&mb=400&hold=60` | `torchio leak --rate 10 --mb 400` | +| Full disk, volumes | `/disk?mb=500&hold=60` | `torchio disk 500 --hold 60` | +| Out of descriptors / connections | `/fd?count=500&hold=30`, `/connections?count=100` | `torchio fd 500` | +| Slow answers, timeouts | `/delay?ms=5000` | `torchio delay 5000` | +| Any status, retries, circuit breakers | `/status/503`, `/flaky?rate=30&code=503` | `torchio status 503` | +| Readiness | `/ready/off?seconds=60`, `/ready` | `torchio ready off 60` | +| Restarts and backoff | `/crash?code=1` | `torchio crash 1` | +| Liveness probe timing out | `/block?ms=10000` | `torchio block 10000` | +| Body size limits of proxies | `/payload?mb=100`, `POST /payload` | `torchio payload get 100` | +| Logging volume | `/log?lines=1000&rate=100` | `torchio log 1000` | + +Notes that save a wrong turn: + +- `hold` is in seconds; memory, disk, descriptors and connections go back when it ends. `hold=0` releases at once. +- The budgets are shared by everyone: a request that would go over gets `429` (memory, disk, fd, connections) or `507` (the disk write failed). That is the server's limit, not a bug. `/info` says what is left. +- For an OOM test the limit of the container must be below `MAX_MEMORY_MB`, whose default (`512`) is a safety cap. Raise `MAX_MEMORY_MB` on purpose, and set `--memory-swap` equal to `-m`. +- A CPU level only holds while it is asked: `/cpu?percent=0` stops it. + +## Several steps: a scenario + +For a test with more than one phase, write it once and let the server run it: + +``` +torchio scenario ramp.json --wait # exits 0 only if the scenario finished +``` + +where `ramp.json` is a list of steps, each with one action and `seconds`: + +``` +[{"cpu": 30, "seconds": 120}, {"cpu": 90, "seconds": 300}, {"cpu": 0, "seconds": 300}, {"memory": 400, "seconds": 60}, {"ready": "off", "seconds": 30}] +``` + +Actions: `cpu` (with optional `workers`), `memory`, `disk`, `fd`, `connections`, `ready` (`"off"`), `block` (takes no `seconds`), or none for a pause. The whole list is checked before it starts and a mistake is a `400` naming the step. One scenario runs at a time (`409`); `GET /scenario` shows where it is and `DELETE /scenario` stops it. + +## Watching the result + +- `torchio watch` (or `torchio watch --once` for one reading) shows workers, memory, disk, descriptors, what is held and the seconds left. +- `curl -s localhost:3000/info` for scripts; `/metrics` for Prometheus (`torchio_*`). +- The effect on the platform is what you are testing: look at it where it happens (`kubectl get pods -w`, `kubectl top`, `docker inspect -f '{{.State.OOMKilled}}'`, the autoscaler's events), not only in torchio. + +## When you are done + +Everything held is released by itself when its `hold` ends. To end earlier: `/cpu?percent=0`, `/ready/on`, `DELETE /scenario`, or stop the container.