calmrun 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,45 @@ All notable changes to this project are documented here. The format follows
4
4
  [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses
5
5
  [Semantic Versioning](https://semver.org/).
6
6
 
7
+ ## [Unreleased]
8
+
9
+ ## [0.2.0] - 2026-11-23
10
+
11
+ ### Added
12
+
13
+ - Detection for builds and tests across ecosystems: C/C++ (make, cmake --build, ctest, ninja,
14
+ meson, bazel, buck2, scons, xmake, compilers), JVM (gradle, maven, mvnd, sbt, ant), .NET
15
+ (dotnet, msbuild), Go, Swift and xcodebuild, Flutter/Dart (incl. build_runner), Ruby,
16
+ PHP (incl. composer test, artisan test), Elixir/Erlang, Haskell, OCaml, Zig, monorepo
17
+ runners (turbo, nx, lerna, pnpm -r, rush, moon) and containers (podman, buildah).
18
+ - New kinds `monorepo` (cost 3), `typecheck` and `lint`; a single compiler call costs 1.
19
+ - Exclusive keys per project folder for these tools (Gradle settings root, `pom.xml`, `*.sln`,
20
+ `Package.swift`, `pubspec.yaml`, …), so two builds of one project never share its output.
21
+ - Worker hints sized to the job's share of the cores for tools that use every core by default:
22
+ `cmake --build --parallel`, `ninja -j`, `meson`, `bazel --jobs`, `buck2 -j`, `dotnet -m`,
23
+ `go -p`, `golangci-lint --concurrency`, `swift -j`, `xcodebuild -jobs`, `flutter/dart test
24
+ --concurrency`, `paratest --processes`, `mix test --max-cases`, `stack`/`cabal`/`dune`/`zig
25
+ -j`, `mvnd -T`, monorepo runner concurrency, `PARALLEL_WORKERS`, `PARALLEL_TEST_PROCESSORS`,
26
+ `MOON_CONCURRENCY`, `DENO_JOBS`, `NEXTEST_TEST_THREADS`, and `pytest -n auto` / `tox -p auto`
27
+ turned into a number. nx, turbo and pnpm are never raised above their own defaults. A flag
28
+ or variable you set yourself always wins. `calmrun doctor` lists them.
29
+ - Gradle `connected*` tasks also take the `emulator` resource.
30
+ - More watch modes refused with their one-shot form (`gradle --continuous`, `dotnet watch`,
31
+ `turbo watch`, `mix test.watch`, `parcel watch`, `sbt ~`, `cargo watch`, …), and more dev
32
+ servers and app runs started outside the queue (`turbo run dev`, `nx serve`, `make dev`,
33
+ `bootRun`, `spring-boot:run`, `rails server`, `zig build run`, …).
34
+ - Launchers `bundle exec`, `dotnet tool run` and `xcrun` are seen through.
35
+
36
+ ### Changed
37
+
38
+ - Releases publish the npm package from CI through npm trusted publishing (with provenance).
39
+ - Dev servers and other commands that run outside the queue keep their arguments unchanged,
40
+ and the Claude Code hook no longer wraps them.
41
+ - The Claude Code hook follows the runner's command rules: a watch mode gets its one-shot form
42
+ (`npx vitest` → `calmrun -- npx vitest run`, `docker compose up` → `… up -d`), and one
43
+ without such a form (`sbt shell`, `cargo watch`) is left alone instead of being sent to a
44
+ calmrun that refuses it.
45
+
7
46
  ## [0.1.0] - 2026-11-23
8
47
 
9
48
  ### Added
package/README.md CHANGED
@@ -1,36 +1,55 @@
1
1
  # calmrun
2
2
 
3
+ [![CI](https://github.com/vannt-dev/calmrun/actions/workflows/ci.yml/badge.svg)](https://github.com/vannt-dev/calmrun/actions/workflows/ci.yml)
4
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
5
+ [![Release](https://img.shields.io/github/v/release/vannt-dev/calmrun)](https://github.com/vannt-dev/calmrun/releases/latest)
6
+ [![crates.io](https://img.shields.io/crates/v/calmrun)](https://crates.io/crates/calmrun)
7
+ [![npm](https://img.shields.io/npm/v/calmrun)](https://www.npmjs.com/package/calmrun)
8
+
3
9
  A machine-wide queue for heavy commands, so several coding agents and terminals on one computer
4
- don't run `vitest`, `tsc`, builds, Playwright and `docker compose` all at once and freeze it.
10
+ don't run their builds and tests all at once and freeze it, in any stack: `vitest`, `pytest`,
11
+ `cargo`, `gradle`, `dotnet`, `go`, `cmake`, Playwright, `docker compose` and more.
5
12
 
6
13
  ```sh
7
14
  calmrun -- npx vitest run
8
15
  ```
9
16
 
10
- calmrun waits until the machine has room (budget points and free RAM), then runs the command
11
- at low CPU priority and passes its exit code back. There is no daemon: every `calmrun` process
12
- coordinates through a small state file guarded by an OS file lock.
17
+ calmrun waits until the machine has room (budget points, free RAM, free disk), then runs the
18
+ command at low CPU priority and passes its exit code back. There is no daemon: every `calmrun`
19
+ process coordinates through a small state file guarded by an OS file lock.
13
20
 
14
- Works on Windows, macOS and Linux (x64 and arm64).
21
+ <picture>
22
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/vannt-dev/calmrun/main/docs/diagrams/overview-dark.svg">
23
+ <img alt="Several agents and terminals on one machine send heavy commands to calmrun, either directly as calmrun -- cmd or through the MCP tool run_task; the Claude Code hook catches a heavy command started without calmrun and denies it with the wrapped form, or rewrites it. calmrun first applies its command rules: a watch mode is refused with exit 2 and the one-shot form to run instead, and a dev server or app run starts at once outside the queue. Any other command is detected for its kind and cost, its exclusive key and a worker hint, then waits in the machine-wide queue until all gates hold: free budget points, enough free RAM and disk, its exclusive key and any named resource. With --wait-timeout it gives up with exit 75 and keeps its place as a ticket. Once admitted it runs at low CPU priority under a process-tree memory ceiling, and its exit code is passed back and recorded in the history." src="https://raw.githubusercontent.com/vannt-dev/calmrun/main/docs/diagrams/overview-light.svg">
24
+ </picture>
15
25
 
16
- ## Why not just run the commands?
26
+ Works on Windows, macOS and Linux. Website: <https://vannt-dev.github.io/calmrun/>
17
27
 
18
- One test run is fine. Four agents each starting `vitest` with a worker per core, plus a `tsc`
19
- and a build, is not: the machine swaps, the editor stalls, and every run gets slower than if
20
- they had taken turns. calmrun makes them take turns:
28
+ **Contents:** [Why](#why) · [Install](#install) · [Quick start](#quick-start) ·
29
+ [How it decides](#how-it-decides) · [Commands](#commands) · [Config](#config) ·
30
+ [Coding agents](#coding-agents) · [Exit codes](#exit-codes) · [Platform notes](#platform-notes) ·
31
+ [Troubleshooting](#troubleshooting) · [Contributing](#contributing)
21
32
 
22
- | Without calmrun | With calmrun |
23
- | --- | --- |
24
- | Every agent starts its heavy command at once | Jobs start only while budget points are free |
25
- | Runs pile up until RAM runs out | A job waits when free RAM is below a threshold |
26
- | Two test runs share one `node_modules` / `target` and fight over caches | Same folder means one at a time |
27
- | Test runners spawn a worker per core | Direct vitest calls get a small `--maxWorkers` |
28
- | Commands compete with your editor at normal priority | Commands run at low CPU priority |
29
- | A killed terminal can leave orphaned workers | The command's process tree dies with calmrun |
33
+ ## Why
34
+
35
+ One test run is fine. Four agents each starting `vitest` with a worker per core, plus a `tsc`
36
+ and a build, is not: the machine swaps, the editor stalls, tests time out for reasons that have
37
+ nothing to do with the code, and every run gets slower than if they had taken turns. calmrun
38
+ makes them take turns:
39
+
40
+ - Jobs start only while budget points are free, and wait while free RAM or disk is low.
41
+ - Two test runs or builds on the same `node_modules`, Cargo `target` or project folder (Gradle,
42
+ Maven, .NET, CMake, Swift, Flutter, …) never run together.
43
+ - Direct calls of vitest, cargo, gradle, dotnet, go, cmake, ninja, bazel and other tools that
44
+ use every core get a worker count that fits their share of the machine.
45
+ - Commands run at low CPU priority, so your editor and the agents stay responsive.
46
+ - A job whose process tree grows past a memory ceiling is stopped instead of taking the machine.
47
+ - A killed terminal does not leave orphaned workers: the command's tree dies with calmrun.
30
48
 
31
49
  ## Install
32
50
 
33
- Prebuilt binaries are attached to each GitHub release, with installers:
51
+ Prebuilt binaries for x64 and arm64 are attached to each
52
+ [GitHub release](https://github.com/vannt-dev/calmrun/releases/latest).
34
53
 
35
54
  ```sh
36
55
  # macOS / Linux
@@ -42,14 +61,32 @@ curl --proto '=https' --tlsv1.2 -LsSf https://github.com/vannt-dev/calmrun/relea
42
61
  powershell -ExecutionPolicy Bypass -c "irm https://github.com/vannt-dev/calmrun/releases/latest/download/calmrun-installer.ps1 | iex"
43
62
  ```
44
63
 
64
+ The installers put `calmrun` in `$CARGO_HOME/bin` (by default `~/.cargo/bin`, or
65
+ `%USERPROFILE%\.cargo\bin` on Windows) and add that folder to `PATH`. Open a new terminal
66
+ afterwards.
67
+
45
68
  ```sh
46
- # npm (any OS)
69
+ # npm (any OS; downloads the matching binary)
47
70
  npm install -g calmrun
48
71
 
49
- # from source
50
- cargo install --git https://github.com/vannt-dev/calmrun --locked
72
+ # from crates.io (Rust 1.95 or newer)
73
+ cargo install calmrun --locked
51
74
  ```
52
75
 
76
+ **Manual download.** Each release has one archive per platform, each with a `.sha256` file:
77
+
78
+ | Platform | Archive |
79
+ | --- | --- |
80
+ | Windows x64 | `calmrun-x86_64-pc-windows-msvc.zip` |
81
+ | Windows arm64 | `calmrun-aarch64-pc-windows-msvc.zip` |
82
+ | macOS Intel | `calmrun-x86_64-apple-darwin.tar.xz` |
83
+ | macOS Apple silicon | `calmrun-aarch64-apple-darwin.tar.xz` |
84
+ | Linux x64 | `calmrun-x86_64-unknown-linux-gnu.tar.xz` |
85
+ | Linux arm64 | `calmrun-aarch64-unknown-linux-gnu.tar.xz` |
86
+
87
+ Unpack it and put `calmrun` (`calmrun.exe`) in a folder on `PATH`. Check with
88
+ `calmrun --version` and `calmrun doctor`.
89
+
53
90
  ## Quick start
54
91
 
55
92
  ```sh
@@ -62,6 +99,7 @@ calmrun status # what runs, what waits, and why
62
99
  calmrun stats --days 30 # how long jobs waited and ran
63
100
  calmrun bump e2e # move a waiting job to the front
64
101
  calmrun init # write a commented config file
102
+ calmrun setup --write --hook # tell your coding agents to use calmrun
65
103
  ```
66
104
 
67
105
  While waiting, calmrun prints one line to stderr, then one every 30 seconds:
@@ -71,169 +109,273 @@ calmrun: waiting — 4 of 6 points in use, 2nd in line (needs 2); running: npx v
71
109
  calmrun: waiting for RAM: 2.1 GB free, needs 3.0 GB; running: npx playwright in e2e (4m55s)
72
110
  ```
73
111
 
74
- ## CLI
112
+ ## How it decides
75
113
 
76
- ```
77
- calmrun [--kind K] [--cost N] [--prio high] [--label L] [--needs NAME,…] [--id QUEUE]
78
- [--wait-timeout SECS] [--ticket ID] -- <command...>
79
- calmrun status [--json] [--id QUEUE]
80
- calmrun stats [--days N] [--json]
81
- calmrun bump <label-substring> [--id QUEUE]
82
- calmrun doctor
83
- calmrun hook claude
84
- calmrun mcp
85
- calmrun guide
86
- calmrun setup [--write] [--remove] [--hook] [--agents claude,codex,gemini,opencode]
87
- calmrun init [--force]
88
- ```
114
+ ### Budget and kinds
89
115
 
90
- - Separate words (`calmrun -- npx vitest run`) run the program directly. On Windows calmrun
91
- looks the name up on `PATH` with `PATHEXT`, so `npm`, `npx` and other `.cmd` shims work, and
92
- arguments are escaped for `cmd.exe`. A bare name is never taken from the working directory
93
- (a repository's own `npm.cmd` cannot stand in for npm); `./gradlew` or `.\tool.cmd` with a
94
- path runs from the job's folder.
95
- - One string containing spaces (`calmrun "a && b"`) runs through the shell: `cmd /d /s /c` on
96
- Windows, `sh -c` on Unix. calmrun never rewrites such a string.
97
- - The exit code is the command's exit code (on Unix a signal `n` becomes `128 + n`). A missing
98
- command exits 127; a refused command exits 2.
99
- - Ctrl+C reaches the command; a job still waiting leaves the queue and exits 130.
100
- - `--wait-timeout SECS` caps the wait. If the job has not started by then, calmrun exits **75**
101
- (EX_TEMPFAIL) and keeps its place in line for 10 minutes. It prints the exact command that
102
- resumes that place, the same arguments with `--ticket <id>` in front:
103
-
104
- ```
105
- calmrun: not started within 120s (waiting — 6 of 6 points in use, 2nd in line (needs 2)); your place in line is kept for 10 min.
106
- calmrun: next: calmrun --ticket 17 --wait-timeout 120 -- npx vitest run
107
- ```
108
-
109
- While the owner is away, the kept place does not block anyone; when the ticket comes back
110
- it rejoins at its old position. An expired or unknown ticket joins the end of the line.
111
- - Messages meant for agents say what happened and what to run next (`calmrun: next: …`), for
112
- example after a refused `docker compose up` or a command that is not on `PATH`.
113
- `calmrun guide` prints short instructions to paste into an agent's context.
114
-
115
- | Exit code | Meaning |
116
- | --- | --- |
117
- | the command's | it ran |
118
- | 2 | refused (e.g. attached `docker compose up`) |
119
- | 75 | not started within `--wait-timeout`; place kept, see the `next:` line |
120
- | 124 | stopped by the MCP `timeout_s` |
121
- | 127 | command not found |
122
- | 130 | Ctrl+C |
123
- | 137 | stopped by the memory ceiling or the critical free-RAM floor |
124
-
125
- ## Rules
126
-
127
- **Budget.** The machine has `budget` points (default: logical cores − 2, capped at
128
- floor(RAM GB / 4), at least 2). Each job costs points by kind; `--cost` overrides, and a cost
129
- above the budget counts as the whole budget.
116
+ The machine has `budget` points (default: logical cores − 2, capped at floor(RAM GB / 4), at
117
+ least 2). Each job costs points by kind; `--cost` overrides, and a cost above the budget counts
118
+ as the whole budget.
130
119
 
131
120
  | Kind | Detected from | Default cost |
132
121
  | --- | --- | --- |
133
122
  | `vitest` | `vitest` | 2 |
134
123
  | `jest` | `jest` | 2 |
135
- | `tsc` | `tsc`, `vue-tsc`, `tsgo`, `npm run typecheck` | 2 |
136
- | `build` | `vite/next/ng build`, `webpack`, `rollup`, `esbuild`, `gradle(w)`, `mvn`, `cargo build/check/clippy`, `flutter build`, `dotnet build`, `go build`, `npm run build` | 2 |
124
+ | `tsc` | `tsc`, `vue-tsc`, `tsgo`, package scripts `typecheck` / `type-check` / `tsc` | 2 |
125
+ | `build` | `vite/next/ng build`, `webpack`, `rollup`, `esbuild`, package script `build`, and the build tools in the [table below](#build-tools) | 2 (1 for one compiler call: `gcc`, `clang`, `cl`, …) |
126
+ | `monorepo` | `turbo run`, `nx run-many/affected`, `lerna run`, `pnpm -r`, `rush build`, `moon run` | 3 |
137
127
  | `capture` | `playwright`, `puppeteer`, `cypress` | 2 |
138
- | `docker` | `docker compose up/build/run`, `docker-compose …`, `docker build/run` | 2 |
139
- | `eslint` | `eslint`, `oxlint`, `biome`, `npm run lint` | 1 |
140
- | `pytest` | `pytest`, `python -m pytest` | 1 |
141
- | `test` | `cargo test`, `go test`, `flutter test`, `dotnet test`, `npm test` | 1 |
128
+ | `docker` | `docker compose up/build/run/create`, `docker-compose …` (same subcommands), `docker build/run/buildx`; the same for `podman` and `podman-compose`; `buildah build`, `packer build` | 2 |
129
+ | `typecheck` | `mypy`, `pyright`, `deno check`, `phpstan`, `psalm` | 2 |
130
+ | `eslint` | `eslint`, `oxlint`, `biome`, package script `lint` | 1 |
131
+ | `lint` | `ruff`, `pylint`, `flake8`, `go vet`, `golangci-lint run`, `rubocop` | 1 |
132
+ | `pytest` | `pytest`, `py.test`, `python -m pytest` | 1 |
133
+ | `test` | `npm/pnpm/yarn/bun test`, package script `test`, `mocha`, `tox`, `nox`, and the test runners in the [table below](#build-tools) | 1 |
142
134
  | `other` | anything else | 1 |
143
135
 
144
- Detection looks at the command position only: the program name (basename, without
145
- `.cmd/.bat/.exe/.ps1/.js`) after `VAR=value` prefixes and launchers such as `npx`, `pnpx`,
146
- `bunx`, `pnpm exec`, `yarn exec`, `npm exec`, `uv run`, `python -m`. So
147
- `git commit -m "fix vitest"` is not a vitest run. `--kind` overrides detection.
148
-
149
- **Starting.** A job starts when its cost fits in the free points **and** free RAM is at least
150
- `min_free_gb` (default max(3, RAM / 8) GB; 0 disables). The RAM check is skipped when nothing
151
- is running, so a job never waits forever on an idle machine.
152
-
153
- **Disk.** A job also waits while the drive of its working directory has less than
154
- `min_free_disk_gb` free (default 5; `0` turns it off), and says so:
155
- `calmrun: waiting for disk space: 3.2 GB free on C:\, needs 5.0 GB`. When nothing else is
156
- running it starts anyway, with a warning, so it never waits for a drive it cannot clean up.
136
+ "Package script" means `npm run <name>` / `npm run-script <name>` (also `<name>:suffix`, such as
137
+ `test:unit`), and `pnpm|yarn|bun <name>` directly. Detection looks at the command position
138
+ only: the program name (basename, without `.cmd/.bat/.exe/.ps1/.js`) after `VAR=value` prefixes
139
+ and launchers such as `npx`, `pnpx`, `bunx`, `pnpm exec`, `yarn exec`, `npm exec`, `uv run`,
140
+ `python -m`, `bundle exec`, `dotnet tool run`, `xcrun`. So `git commit -m "fix vitest"` is not a vitest run. `--kind` overrides detection;
141
+ `[kinds.<name>]` in the config changes a cost or adds a kind with its own patterns.
142
+
143
+ <a id="build-tools"></a>**Build tools.** What calmrun knows per tool beyond JavaScript and
144
+ Python. *Key* is the marker file of the project folder the job takes an exclusive key on
145
+ (see [Gates](#gates-when-a-job-starts)). *Hint* is the worker count calmrun passes, N being
146
+ the job's share of the machine (logical cores × cost ÷ budget, at least 1); in brackets, what
147
+ makes it leave the count alone because you already chose one.
148
+
149
+ | Tools | Kind | Key | Hint |
150
+ | --- | --- | --- | --- |
151
+ | `make`, `gmake`, `mingw32-make`, `nmake` | build | `Makefile` | none (serial unless you pass `-j`) |
152
+ | `cmake --build` | build | `CMakeCache.txt`, `CMakeLists.txt` | `--parallel N` (`-j`, `--parallel`, `CMAKE_BUILD_PARALLEL_LEVEL`) |
153
+ | `ctest` | test | as cmake | none (serial unless you pass `-j`) |
154
+ | `ninja` | build | `build.ninja` | `-jN` (`-j`) |
155
+ | `meson compile` / `meson test` | build / test | `meson.build` | `-j N` / `--num-processes N` (`MESON_TESTTHREADS`) |
156
+ | `bazel`, `bazelisk` `build` / `test`, `coverage` | build / test | `MODULE.bazel`, `WORKSPACE` | `--jobs=N` (`--jobs`, `-j`) |
157
+ | `buck2`, `buck` `build` / `test` | build / test | `.buckconfig` | `-jN` (`-j`, `--num-threads`) |
158
+ | `scons`, `xmake` | build | `SConstruct`, `xmake.lua` | none, `-j N` for xmake |
159
+ | `gcc`, `g++`, `clang`, `clang++`, `cl`, `cc` | build, cost 1 | none | none |
160
+ | `gradle`, `gradlew` | test for `test*`/`check*`/`connected*` tasks (`connected*` also takes the `emulator` resource), else build | `settings.gradle(.kts)` | `--max-workers=N` (`--max-workers`, `-Dorg.gradle.workers.max`) |
161
+ | `mvn`, `mvnw` / `mvnd` | test for `test`/`verify`, else build | `pom.xml` | none / `-T N` for mvnd (`-T`) |
162
+ | `sbt`, `ant` | test for `sbt test`/`testOnly`, else build | `build.sbt`, `build.xml` | none |
163
+ | `dotnet build`, `publish`, `pack`, `msbuild`, `restore` / `dotnet test` | build / test | `*.sln`, `*.slnx`, `*.csproj`, `*.fsproj`, … | `-m:N` (`-m`, `-maxcpucount`) |
164
+ | `msbuild` | build | as dotnet | none (serial unless you pass `-m`) |
165
+ | `go build`, `install` / `test` / `vet` | build / test / lint | none | `-p N` after the subcommand (`-p`, `GOFLAGS=-p…`) |
166
+ | `golangci-lint run` | lint | none | `--concurrency N` (`--concurrency`, `-j`) |
167
+ | `cargo build`, `check`, `clippy`, `doc` / `test`, `bench`, `nextest` | build / test | `target` folder | `CARGO_BUILD_JOBS=N`, also `NEXTEST_TEST_THREADS=N` for nextest |
168
+ | `maturin build`, `develop` | build | `target` folder | `CARGO_BUILD_JOBS=N` |
169
+ | `swift build` / `test` | build / test | `Package.swift` | `-j N` (`-j`, `--jobs`) |
170
+ | `xcodebuild` (also through `xcrun`) | test for test actions, else build | `*.xcworkspace`, `*.xcodeproj` | `-jobs N` (`-jobs`) |
171
+ | `flutter build` | build | `pubspec.yaml` | none |
172
+ | `flutter test`, `dart test` | test | `pubspec.yaml` | `--concurrency=N` (`--concurrency`, `-j`) |
173
+ | `dart compile`, `dart run build_runner` | build | `pubspec.yaml` | none |
174
+ | `rspec`, `cucumber`, `rake test`, `rake spec` | test | none | none |
175
+ | `rails test` | test | none | `PARALLEL_WORKERS=N` |
176
+ | `parallel_rspec`, `parallel_test` | test | none | `PARALLEL_TEST_PROCESSORS=N` |
177
+ | `phpunit`, `pest`, `composer test`, `php artisan test` | test | none | none |
178
+ | `paratest` | test | none | `--processes=N` (`-p`, `--processes`) |
179
+ | `mix test` / `mix compile`, `release` | test / build | `mix.exs` | `--max-cases N` (`--max-cases`) / none |
180
+ | `rebar3 eunit`, `ct` / `compile`, `release` | test / build | `rebar.config` | none |
181
+ | `stack build`, `install`, `test` | build / test | `stack.yaml` | `-j N` (`-j`, `--jobs`) |
182
+ | `cabal build`, `install`, `test` | build / test | `cabal.project`, `*.cabal` | `-jN` (`-j`, `--jobs`) |
183
+ | `dune build` / `test` | build / test | `dune-project` | `-j N` (`-j`) |
184
+ | `zig build` | build | `build.zig` | `-jN` (`-j`) |
185
+ | `turbo run` | monorepo | `node_modules` | `--concurrency=N`, at most 10, turbo's default (`--concurrency`) |
186
+ | `nx run-many`, `nx affected` | monorepo | `node_modules` | `--parallel=N`, at most 3, nx's default (`--parallel`) |
187
+ | `lerna run`, `exec` | monorepo | `node_modules` | `--concurrency N` (`--concurrency`) |
188
+ | `pnpm -r` (not `install`, `add`, `update`, …) | monorepo | `node_modules` | `--workspace-concurrency=N`, at most 4, pnpm's default (`--workspace-concurrency`) |
189
+ | `rush build`, `rebuild`, `test` | monorepo | `node_modules` | `--parallelism N` (`-p`, `--parallelism`) |
190
+ | `moon run`, `ci`, `check` | monorepo | `node_modules` | `MOON_CONCURRENCY=N` |
191
+ | `pytest -n auto`, `tox -p auto` | pytest / test | none, `tox.ini` | `auto` becomes N |
192
+ | `deno test`, `bench` | test | none | `DENO_JOBS=N` |
193
+ | `docker`, `podman`, `buildah`, `packer` builds | docker | none | none |
194
+
195
+ A variable in the Hint column is set only when it is not set already, and an argument is
196
+ added only when the tool is started directly as words (also after `VAR=value`, `npx`,
197
+ `bundle exec`, `xcrun`, …), never to package scripts or shell strings. `calmrun doctor` prints
198
+ the numbers for this machine. Tools that run one job at a time unless asked (make, ctest,
199
+ scons, plain Maven, msbuild without `-m`) get no hint on purpose: turning parallelism on can
200
+ break a build that was never written for it. Pass the flag yourself (`make -j8`) and calmrun
201
+ leaves it alone.
202
+
203
+ ### Gates: when a job starts
204
+
205
+ A job starts when **all** of these hold:
206
+
207
+ - **Points.** Its cost fits in the free points of its queue.
208
+ - **RAM.** Free RAM is at least `min_free_gb` (default max(3, RAM / 8) GB; `0` disables). The
209
+ check is skipped when nothing is running, so a job never waits forever on an idle machine.
210
+ Waiters share one RAM reading per second, and memory is reserved for jobs that just started.
211
+ - **Disk.** The drive of its working directory has at least `min_free_disk_gb` free (default 5;
212
+ `0` turns it off): `calmrun: waiting for disk space: 3.2 GB free on C:\, needs 5.0 GB`. When
213
+ nothing else runs it starts anyway, with a warning.
214
+ - **Same folder, one at a time.** vitest, jest and JavaScript build jobs take an exclusive key
215
+ for their nearest `node_modules` folder; Cargo builds and tests take one for their `target`
216
+ folder (or `CARGO_TARGET_DIR`); other build tools take one for their project folder, the
217
+ nearest folder holding the marker file in the [build tools table](#build-tools) (two Gradle
218
+ runs in one build share `build/`, two `dotnet` runs share `obj/`). Two jobs with the same key
219
+ never run together.
220
+ - **Named resources.** `--needs db` also takes one slot of the resource `db`. Configure slots
221
+ with `[resources] db = 1` or `CALMRUN_RESOURCES="db=1,gpu=2"`; a resource that is not
222
+ configured has one slot. Use it for things that cannot be shared: one test database, one
223
+ emulator, one GPU. Waiters say who holds it:
224
+ `calmrun: waiting for resource "db" (1 of 1 slot(s) held by npm test), 2nd in line`.
225
+
226
+ Points, keys and resource slots are taken all-or-nothing.
227
+
228
+ ### Order and passing
229
+
230
+ `--prio high` first, then first come. A later job may pass earlier ones only if it fits right
231
+ now and no job ahead of it has waited longer than `pass_limit_min` (default 10; `0` = strict
232
+ order). Running jobs are never stopped to make room. `calmrun bump <label>` moves matching
233
+ waiting jobs to the front.
234
+
235
+ ### Separate queues
236
+
237
+ `--id QUEUE` uses its own queue with its own budget, like GNU `sem --id` (for example one queue
238
+ per project, or one for long e2e runs). `status --id QUEUE` and `bump … --id QUEUE` act on it.
239
+ The default queue and named queues do not see each other's points; history and config are
240
+ shared. A queue id uses letters, digits, `-`, `_` and `.` (not first).
241
+
242
+ ### Tickets: capped waits
243
+
244
+ `--wait-timeout SECS` caps the wait. If the job has not started by then, calmrun exits **75**
245
+ (EX_TEMPFAIL) and keeps its place in line for 10 minutes. It prints the exact command that
246
+ resumes that place, the same arguments with `--ticket <id>` in front:
157
247
 
158
- **Named resources.** `--needs db` makes a job also take one slot of the resource `db`.
159
- Configure slots with `[resources] db = 1` or `CALMRUN_RESOURCES="db=1,gpu=2"`; a resource
160
- that is not configured has one slot. Use it for things that cannot be shared: one test
161
- database, one emulator, one GPU. Waiters say who holds it:
162
- `calmrun: waiting for resource "db" (1 of 1 slot(s) held by npm test), 2nd in line`.
163
-
164
- **Separate queues.** `--id QUEUE` uses its own queue with its own budget, like GNU `sem --id`
165
- (for example one queue per project, or one for long e2e runs). `status --id QUEUE` and
166
- `bump … --id QUEUE` act on it. The default queue and named queues do not see each other's
167
- points; history and config are shared.
168
-
169
- **Order.** `--prio high` first, then first come. A later job may pass earlier ones only if it
170
- fits right now and no job ahead of it has waited longer than `pass_limit_min` (default 10;
171
- 0 = strict order). Running jobs are never stopped.
248
+ ```
249
+ calmrun: not started within 120s (waiting — 6 of 6 points in use, 2nd in line (needs 2)); your place in line is kept for 10 min.
250
+ calmrun: next: calmrun --ticket 17 --wait-timeout 120 -- npx vitest run
251
+ ```
172
252
 
173
- **Same folder, one at a time.** vitest, jest and build jobs take an exclusive key for their
174
- nearest `node_modules` folder; Cargo builds and tests take one for their `target` folder (or
175
- `CARGO_TARGET_DIR`). Two jobs with the same key never run together. Points and keys are taken
176
- all-or-nothing.
253
+ While the owner is away, the kept place does not block anyone; when the ticket comes back it
254
+ rejoins at its old position. An expired or unknown ticket joins the end of the line. `status`
255
+ shows places kept by a ticket.
177
256
 
178
- **Command rules.**
257
+ ### Command rules
179
258
 
180
- - Commands that never end would hold their points forever, so they are refused with the
181
- one-shot form to run instead (`calmrun: next: …`):
259
+ - **Endless commands are refused** (exit 2), because they would hold their points forever.
260
+ calmrun prints the one-shot form to run instead (`calmrun: next: …`):
182
261
  - `docker compose up` / `docker-compose up` without `-d`, `--detach` or `--wait` → add `-d`;
183
- - `tsc --watch` / `-w`, `jest --watch` / `--watchAll` → without the flag;
262
+ - `tsc --watch` / `-w` (also `vue-tsc`, `tsgo`), `jest --watch` / `--watchAll`,
263
+ `vitest --watch` / `-w` → without the flag;
184
264
  - `vitest watch` / `vitest dev`, and plain `vitest` when stdin is a terminal (it watches
185
265
  then) → `vitest run`;
186
- - `docker run -it` / `-i` / `-t` (interactive containers) → run it outside calmrun.
187
- - Dev servers (`vite`, `next dev`, `ng serve`, `npm run dev|start|serve|preview`, …) and
188
- commands that only print help or a version (`--help`, `-h`, `--version`, `-V`) run at once,
189
- outside the queue.
190
- - vitest started directly as separate words (`vitest …`, `npx|pnpx|bunx vitest …`,
191
- `pnpm|yarn exec vitest …`) gets `--maxWorkers=N` appended unless it already passes
192
- `--maxWorkers`, `--pool` or `--no-file-parallelism`. N is `vitest_workers` (default 1 for
193
- up to 4 cores, 2 below 12, else 3). `npm run …` scripts and shell strings are never changed.
194
- - gradle / gradlew started directly as words gets `--max-workers=N` unless it already sets
195
- `--max-workers` or `-Dorg.gradle.workers.max`.
196
- - Cargo commands get `CARGO_BUILD_JOBS=N` unless it is already set. If a cargo config
197
- (`.cargo/config.toml` up from the working directory, then `$CARGO_HOME/config.toml`) sets a
198
- lower `build.jobs`, that lower number is used.
199
- - For both, N is the job's share of the machine: logical cores × cost ÷ budget (at least 1).
200
-
201
- **Nesting.** calmrun sets `CALMRUN_HELD=<pid>` for the command. A calmrun started inside it
202
- (for example a script that calls calmrun again) runs at once instead of queuing behind its own
203
- parent.
204
-
205
- **Low priority.** The command runs below normal priority on Windows and with `nice +10` in its
206
- own process group on Unix. `CALMRUN_LOW_CPU=0` turns the priority change off.
207
-
208
- **Memory ceiling.** While a job runs, calmrun adds up the memory of its whole process tree
209
- (the command and every process below it, including nested calmrun runs) about once a second.
210
- If the tree goes above `ceiling_gb` (default half the RAM; `0` turns it off), or free RAM
211
- stays below `critical_free_gb` (default 5% of RAM, at most 1 GB) for 3 seconds and this job's
212
- tree is the single largest of the running jobs (on a tie, the newer one), calmrun stops the
213
- tree (gracefully, then forced) and exits **137**. A tree smaller than max(1 GB, 10% of RAM)
214
- is never stopped for low free RAM: calmrun warns once instead, since something outside the
215
- queue is using the memory. A ceiling stop looks like:
266
+ - `gradle --continuous` / `-t`, `webpack|rollup|esbuild|mocha --watch`,
267
+ `vite build --watch`, `deno|bun --watch`, `stack --file-watch`, `dune -w`,
268
+ `zig build --watch` → without the flag;
269
+ - `dotnet watch <cmd>` → `dotnet <cmd>`; `turbo watch` → `turbo run`; `mix test.watch` →
270
+ `mix test`; `parcel watch` → `parcel build`;
271
+ - `docker run` / `docker exec` (also `podman`) with `-i`, `-t`, `--interactive` or `--tty`,
272
+ bare `sbt` and `sbt shell|console`, `sbt ~task`, `cargo watch`, `nx watch`, `lerna watch`,
273
+ `dart run build_runner watch|serve`, and watchers (`ibazel`, `nodemon`, `watchexec`, `ptw`,
274
+ `bacon`, `air`, `guard`) → run it outside calmrun.
275
+ - **Light commands run at once**, outside the queue and with their arguments unchanged: dev
276
+ servers and app runs (`vite`, `vite dev|serve|preview`, `next|nuxt|astro dev|start|preview`,
277
+ `ng serve`, `webpack serve`, `npm run dev|start|serve|preview` and the pnpm/yarn/bun forms,
278
+ `parcel <entry>`, `turbo run dev`, `nx serve`, `make dev|run|serve|start|watch`, `cargo run`,
279
+ `go run`, `dotnet run`, `flutter run`, `swift run`, `zig build run`, `bazel run`, `sbt run`,
280
+ `gradle bootRun`, `mvn spring-boot:run`, `rails server`, `mix phx.server`,
281
+ `php artisan serve`, `symfony serve`, …), installs and infrastructure commands
282
+ (`pod install`, `composer install`, `terraform plan|apply`, `pulumi up`), and commands that
283
+ only print help, a version or project information (`--help`, `-h`, `--version`, `-V`,
284
+ `xcodebuild -list`). The Claude Code hook leaves them alone.
285
+ - **Worker counts.** vitest started directly as separate words (`vitest …`,
286
+ `npx|pnpx|bunx vitest …`, `pnpm|yarn exec vitest …`) gets `--maxWorkers=N` unless it already
287
+ passes `--maxWorkers`, `--pool` or `--no-file-parallelism`; N is `vitest_workers` (default 1
288
+ for up to 4 cores, 2 below 12, else 3). Build tools get the hint in the
289
+ [build tools table](#build-tools). Cargo gets `CARGO_BUILD_JOBS=N` unless it is already set;
290
+ a lower `build.jobs` in a cargo config (`.cargo/config.toml` up from the working directory,
291
+ then `$CARGO_HOME/config.toml`) wins. `npm run …` scripts and shell strings are never
292
+ changed.
293
+ - **Nesting.** calmrun sets `CALMRUN_HELD=<pid>` for the command. A calmrun started inside it
294
+ (for example a script that calls calmrun again) runs at once instead of queuing behind its
295
+ own parent.
296
+
297
+ ### While it runs
298
+
299
+ - **Low priority.** Below normal priority on Windows, `nice +10` in its own process group on
300
+ Unix. `CALMRUN_LOW_CPU=0` (or `false`, `no`, `off`) turns this off.
301
+ - **Memory ceiling.** About once a second calmrun adds up the memory of the job's whole process
302
+ tree (including nested calmrun runs). If the tree goes above `ceiling_gb` (default half the
303
+ RAM; `0` turns it off), or free RAM stays below `critical_free_gb` (default 5% of RAM, at most
304
+ 1 GB) for 3 seconds and this job's tree is the largest of the running jobs (on a tie, the
305
+ newer one), calmrun stops the tree (gracefully, then forced) and exits **137**. A tree smaller
306
+ than max(1 GB, 10% of RAM) is never stopped for low free RAM: calmrun warns once instead,
307
+ since something outside the queue is using the memory.
308
+
309
+ ```
310
+ calmrun: stopped npx vitest run: its processes used 9.1 GB, above the 8.0 GB ceiling
311
+ ```
312
+
313
+ - **Process tree.** When the command exits normally, processes it deliberately left running (a
314
+ Gradle or Kotlin daemon, a dev server started in the background) are left alone. When the run
315
+ ends abnormally (Ctrl+C, or calmrun itself being killed) the whole tree is ended.
316
+ - **History.** Each run appends one JSON line to `history.jsonl`: `at`, `label`, `kind`, `cost`,
317
+ `wait_ms`, `run_ms`, `status` (`ceiling` or `low-memory` for memory stops). The label is
318
+ `--label` or the tool and subcommand only (`npx vitest run`, `cargo build`), never the
319
+ arguments, which may contain secrets.
320
+
321
+ ## Commands
216
322
 
217
323
  ```
218
- calmrun: stopped npx vitest run: its processes used 9.1 GB, above the 8.0 GB ceiling
324
+ calmrun [--kind K] [--cost N] [--prio normal|high] [--label L] [--needs NAME,…] [--id QUEUE]
325
+ [--wait-timeout SECS] [--ticket ID] -- <command...>
326
+ calmrun status [--json] [--id QUEUE]
327
+ calmrun stats [--days N] [--json]
328
+ calmrun bump <label-substring> [--id QUEUE]
329
+ calmrun doctor
330
+ calmrun init [--force]
331
+ calmrun guide
332
+ calmrun setup [--write] [--remove] [--hook] [--agents claude,codex,gemini,opencode] [--home DIR]
333
+ calmrun hook claude
334
+ calmrun mcp
219
335
  ```
220
336
 
221
- The stop is recorded in `history.jsonl` (`"status": "ceiling"` or `"low-memory"`), and
222
- `status --json` shows each running job's `mem_bytes`.
337
+ ### Running a command
338
+
339
+ | Flag | Meaning |
340
+ | --- | --- |
341
+ | `--kind K` | Kind of job (a built-in kind or one from the config); detected when omitted |
342
+ | `--cost N` | Points this job takes (clamped to the budget) |
343
+ | `--prio normal\|high` | Queue priority; `high` goes before every `normal` job |
344
+ | `--label L` | Name in `status` and `stats` (default: tool + subcommand) |
345
+ | `--needs NAME` | Also take a slot of this named resource; repeat or comma-separate (`--needs db,gpu`) |
346
+ | `--id QUEUE` | Use a separate queue instead of the machine-wide one |
347
+ | `--wait-timeout SECS` | Give up waiting after this long: exit 75, place kept for 10 minutes |
348
+ | `--ticket ID` | Resume the place kept by an earlier `--wait-timeout` run |
349
+
350
+ - Separate words (`calmrun -- npx vitest run`) run the program directly. On Windows calmrun
351
+ looks the name up on `PATH` with `PATHEXT`, so `npm`, `npx` and other `.cmd` shims work, and
352
+ arguments are escaped for `cmd.exe`. A bare name is never taken from the working directory
353
+ (a repository's own `npm.cmd` cannot stand in for npm); `./gradlew` or `.\tool.cmd` with a
354
+ path runs from the job's folder.
355
+ - One string containing spaces (`calmrun "a && b"`) runs through the shell: `cmd /d /s /c` on
356
+ Windows, `sh -c` on Unix. calmrun never rewrites such a string.
357
+ - Ctrl+C reaches the command; a job still waiting leaves the queue and exits 130.
223
358
 
224
- **Process tree.** When the command exits normally, processes it deliberately left running
225
- (a Gradle or Kotlin daemon, a dev server started in the background) are left alone. When the
226
- run ends abnormally — Ctrl+C, or calmrun itself being killed — the whole tree is ended: on
227
- Windows the command runs in a Job Object that kills the tree when calmrun's handle closes; on
228
- Unix the command's process group is killed after Ctrl+C.
359
+ ### Subcommands
229
360
 
230
- **History.** Each run appends one JSON line to `history.jsonl`: `at`, `label`, `kind`, `cost`,
231
- `wait_ms`, `run_ms`, `status`. The label is `--label` or the tool and subcommand only
232
- (`npx vitest run`, `cargo build`), never the arguments, which may contain secrets.
361
+ | Command | What it does |
362
+ | --- | --- |
363
+ | `status [--json]` | Running and waiting jobs with the reason each one waits, the budget, free RAM and kept tickets. `--json` (with `mem_bytes` per running job) for tools. |
364
+ | `stats [--days N] [--json]` | Runs, failures, average and maximum wait, average run time per label and kind, over the last N days (default 7). |
365
+ | `bump <text>` | Move waiting jobs whose label contains the text (case-insensitive) to the front. |
366
+ | `doctor` | Cores, RAM, disk type, battery, the state directory and config file, the settings in effect and the suggested ones. |
367
+ | `init [--force]` | Write a commented `config.toml` with this machine's defaults and print its path; `--force` overwrites. |
368
+ | `guide` | Short instructions for coding agents, to paste into their context. |
369
+ | `setup` | Add or remove the calmrun block in agents' global instruction files; see [below](#calmrun-setup). |
370
+ | `hook claude` | The Claude Code PreToolUse hook; reads the hook JSON on stdin. |
371
+ | `mcp` | An MCP server on stdin/stdout with `run_task`, `queue_status` and `bump`. |
372
+
373
+ `--id QUEUE` is accepted by every subcommand; it matters for running, `status` and `bump`.
233
374
 
234
375
  ## Config
235
376
 
236
- `calmrun init` writes a commented `config.toml` and prints its path. Every key is optional.
377
+ `calmrun init` writes a commented `config.toml` and prints its path. Every key is optional;
378
+ environment variables override the file.
237
379
 
238
380
  ```toml
239
381
  budget = 6
@@ -256,22 +398,26 @@ cost = 2
256
398
  patterns = ["make", "bazel build"]
257
399
  ```
258
400
 
259
- ### Environment
260
-
261
- | Variable | Meaning |
262
- | --- | --- |
263
- | `CALMRUN_BUDGET` | Budget points (overrides `budget`) |
264
- | `CALMRUN_MIN_FREE_GB` | Free RAM needed to start while busy; `0` disables |
265
- | `CALMRUN_PASS_MIN` | Pass limit in minutes; `0` = strict order |
266
- | `CALMRUN_VITEST_WORKERS` | `--maxWorkers` value for vitest |
267
- | `CALMRUN_LOW_CPU` | `0` keeps normal priority |
268
- | `CALMRUN_RESOURCES` | Named resource slots, e.g. `db=1,gpu=2` (adds to `[resources]`) |
269
- | `CALMRUN_MIN_FREE_DISK_GB` | Free space needed on the cwd's drive; `0` = off |
270
- | `CALMRUN_CEILING_GB` | Memory ceiling for one job's process tree; `0` = off |
271
- | `CALMRUN_CRITICAL_FREE_GB` | Free-RAM floor that stops the biggest job; `0` = off |
272
- | `CALMRUN_HOME` | State directory |
273
- | `CALMRUN_CONFIG` | Config file path |
274
- | `CALMRUN_HOOK_MODE` | `rewrite` makes the Claude Code hook wrap commands itself |
401
+ | Key | Variable | Default | Meaning |
402
+ | --- | --- | --- | --- |
403
+ | `budget` | `CALMRUN_BUDGET` | cores − 2, capped at floor(RAM GB / 4), at least 2 | Points that may run at once |
404
+ | `min_free_gb` | `CALMRUN_MIN_FREE_GB` | max(3, RAM / 8) | Free RAM needed to start while something runs; `0` = off |
405
+ | `min_free_disk_gb` | `CALMRUN_MIN_FREE_DISK_GB` | 5 | Free space needed on the working directory's drive; `0` = off |
406
+ | `pass_limit_min` | `CALMRUN_PASS_MIN` | 10 | Minutes a waiter may be passed; `0` = strict order |
407
+ | `vitest_workers` | `CALMRUN_VITEST_WORKERS` | 1 (≤ 4 cores), 2 (< 12), else 3 | `--maxWorkers` for direct vitest calls |
408
+ | `ceiling_gb` | `CALMRUN_CEILING_GB` | half the RAM | Memory ceiling for one job's process tree; `0` = off |
409
+ | `critical_free_gb` | `CALMRUN_CRITICAL_FREE_GB` | 5% of RAM, at most 1 GB | Free-RAM floor that stops the biggest job; `0` = off |
410
+ | `[resources]` | `CALMRUN_RESOURCES` | none (1 slot each) | Named resource slots, e.g. `db=1,gpu=2`; the variable adds to the table |
411
+ | `[kinds.<name>]` | | built-in costs | `cost` and `patterns` (command's first words) |
412
+ | | `CALMRUN_LOW_CPU` | on | `0`, `false`, `no` or `off` keeps normal priority |
413
+ | | `CALMRUN_HOOK_MODE` | deny | `rewrite` makes the Claude Code hook wrap commands itself |
414
+ | | `CALMRUN_HOME` | see below | State directory |
415
+ | | `CALMRUN_CONFIG` | `<state dir>/config.toml` | Config file path |
416
+ | | `CALMRUN_HELD` | | Set by calmrun for the command it runs (nesting); do not set it yourself |
417
+
418
+ An unknown key or a syntax error makes calmrun ignore the whole file with a warning
419
+ (`calmrun: ignoring config file: …`) and use the defaults; `calmrun doctor` shows what is in
420
+ effect.
275
421
 
276
422
  ### Where state lives
277
423
 
@@ -281,32 +427,40 @@ patterns = ["make", "bazel build"]
281
427
  | macOS | `~/Library/Application Support/calmrun` |
282
428
  | Linux | `$XDG_STATE_HOME/calmrun` or `~/.local/state/calmrun` |
283
429
 
284
- It holds `state.json` (running and waiting jobs), `state.lock`, `history.jsonl` and
285
- `config.toml`. Entries of processes that died are removed automatically: calmrun checks the
286
- pid together with the process start time, so a reused pid is not mistaken for a live job.
430
+ It holds `state.json` (running and waiting jobs), `state.lock`, `history.jsonl`, `config.toml`
431
+ and `logs/` (MCP task output). Entries of processes that died are removed automatically:
432
+ calmrun checks the pid together with the process start time, so a reused pid is not mistaken for
433
+ a live job. A corrupt `state.json` is set aside; an unreadable one is an error.
287
434
 
288
435
  ## Coding agents
289
436
 
290
437
  ### Claude Code hook
291
438
 
292
- `calmrun hook claude` is a
293
- [PreToolUse hook](https://code.claude.com/docs/en/hooks). For the `Bash` and `PowerShell`
294
- tools it checks each part of the command (split on `&&`, `||`, `;`, `|`, `&` and new lines).
295
- If a part runs a heavy kind and is not already wrapped (`calmrun …`, `npx calmrun …`,
296
- `lane with …`), the hook denies the call and tells Claude the exact command to run instead,
297
- with each heavy part wrapped in place:
439
+ `calmrun hook claude` is a [PreToolUse hook](https://code.claude.com/docs/en/hooks). For the
440
+ `Bash` and `PowerShell` tools it checks each part of the command (split on `&&`, `||`, `;`, `|`,
441
+ `&` and new lines). If a part runs a heavy kind and is not already wrapped (`calmrun …`,
442
+ `npx calmrun …`, `lane with …`), the hook denies the call and tells Claude the exact command to
443
+ run instead, with each heavy part wrapped in place:
298
444
 
299
445
  ```
300
446
  cd web && npm ci && npx vitest run → cd web && npm ci && calmrun -- npx vitest run
301
447
  ```
302
448
 
303
449
  Light commands (`git`, `ls`, `cat`, `npm install`, …) are never blocked, heredoc bodies (for
304
- example a commit message written with `<<'EOF'`) are not treated as commands, and any input
305
- the hook does not understand is allowed (no output, exit 0). Wrappers such as `VAR=1`, `time`
306
- or `nice` stay in front: `time npx vitest` becomes `time calmrun -- npx vitest`.
450
+ example a commit message written with `<<'EOF'`) are not treated as commands, and any input the
451
+ hook does not understand is allowed (no output, exit 0). Wrappers such as `VAR=1`, `time` or
452
+ `nice` stay in front: `time npx vitest run` becomes `time calmrun -- npx vitest run`. When
453
+ `calmrun` is not on the agent's `PATH`, the suggestion uses calmrun's absolute path.
454
+
455
+ The hook follows the same [command rules](#command-rules) as `calmrun --`, so it never
456
+ suggests a command calmrun would refuse. A watch mode with a one-shot form gets that form
457
+ (`dotnet watch test` → `calmrun -- dotnet test`, `npx vitest` → `calmrun -- npx vitest run`,
458
+ `docker compose up` → `calmrun -- docker compose up -d`). A watch mode or interactive session
459
+ without one (`sbt shell`, `cargo watch`, `nx watch`, `docker run -it`), dev servers and app
460
+ runs are left alone.
307
461
 
308
462
  Add it to `.claude/settings.json` in a project, or to `~/.claude/settings.json` for every
309
- project:
463
+ project (or let `calmrun setup --write --hook` do it):
310
464
 
311
465
  ```json
312
466
  {
@@ -328,20 +482,28 @@ command runs unwrapped; the default deny mode does not have that gap.
328
482
 
329
483
  ### MCP server
330
484
 
331
- `calmrun mcp` is an [MCP](https://modelcontextprotocol.io) server over stdio. Agents that
332
- speak MCP can queue work without a shell wrapper. It offers three tools:
485
+ `calmrun mcp` is an [MCP](https://modelcontextprotocol.io) server over stdio. Agents that speak
486
+ MCP can queue work without a shell wrapper. It offers three tools:
333
487
 
334
- | Tool | What it does |
335
- | --- | --- |
336
- | `run_task` | `{command, cwd?, kind?, cost?, label?, timeout_s?, prio?, wait_timeout_s?, ticket?, needs?, queue?}`. Waits in the same queue as the CLI, runs the command at low priority and returns the exit code, wait and run time, the last 200 lines of output and the path of the full log (kept under `logs/` in the state directory; the newest 200 are kept). While it waits, the server sends progress notifications if the client passed a `progressToken`. `timeout_s` stops the command (exit 124). `wait_timeout_s` gives up waiting (exit 75) and returns a `ticket`; pass it back as `ticket` to resume the same place in line. Cancelling the request leaves the queue or stops the command. |
337
- | `queue_status` | The same data as `calmrun status --json`. |
338
- | `bump` | `{label}`: move matching waiting jobs to the front. |
339
-
340
- A `command` made of plain words runs the program directly (and gets the vitest
341
- `--maxWorkers` rule); leading `VAR=value` words become the command's environment, so
342
- `CI=1 npm test` works on Windows too. One that uses shell syntax (`&&`, pipes, redirects,
343
- `$VAR`, …) runs in `sh -c` on macOS/Linux and `cmd /d /s /c` on Windows. The output tail is in
344
- the text content and, for clients that show structured results, in `output_tail`.
488
+ | Tool | Arguments | What it does |
489
+ | --- | --- | --- |
490
+ | `run_task` | `command`, and optionally `cwd`, `kind`, `cost`, `label`, `timeout_s`, `prio`, `wait_timeout_s`, `ticket`, `needs`, `queue` | Waits in the same queue as the CLI, runs the command at low priority and returns the exit code, wait and run time, the last 200 lines of output and the path of the full log. |
491
+ | `queue_status` | `queue` | The same data as `calmrun status --json`. |
492
+ | `bump` | `label`, `queue` | Move matching waiting jobs to the front. |
493
+
494
+ - While a task waits, the server sends progress notifications if the client passed a
495
+ `progressToken`.
496
+ - `timeout_s` stops the command (exit 124). `wait_timeout_s` gives up waiting (exit 75) and
497
+ returns a `ticket`; pass it back as `ticket` to resume the same place in line.
498
+ - Cancelling the request (`notifications/cancelled`) leaves the queue or stops the command, and,
499
+ as the MCP spec asks, the cancelled request gets no response.
500
+ - Full logs are kept under `logs/` in the state directory; the newest 200 are kept.
501
+ - A `command` made of plain words runs the program directly (and gets the worker rules);
502
+ leading `VAR=value` words become the command's environment, so `CI=1 npm test` works on
503
+ Windows too. One that uses shell syntax (`&&`, pipes, redirects, `$VAR`, …) runs in `sh -c`
504
+ on macOS/Linux and `cmd /d /s /c` on Windows. The output tail is in the text content and, for
505
+ clients that show structured results, in `output_tail`.
506
+ - `calmrun mcp` stops its running tasks on Ctrl+C / SIGTERM and when its client closes stdin.
345
507
 
346
508
  Register it with your agent:
347
509
 
@@ -377,14 +539,12 @@ tool_timeout_sec = 3600 # tasks may wait in the queue and run for a while
377
539
  ```
378
540
 
379
541
  Long test runs can outlast a client's default tool timeout; raise it where the client allows.
380
- Cancelling a `run_task` request (`notifications/cancelled`) stops the command or leaves the
381
- queue, and, as the MCP spec asks, the cancelled request gets no response.
382
542
 
383
543
  ### `calmrun setup`
384
544
 
385
- `calmrun setup` adds a short calmrun section to each coding agent's **global** instruction
386
- file. It is a dry run by default: it prints what it would change and the exact block. Add
387
- `--write` to apply.
545
+ `calmrun setup` adds a short calmrun section to each coding agent's **global** instruction file.
546
+ It is a dry run by default: it prints what it would change and the exact block. Add `--write`
547
+ to apply.
388
548
 
389
549
  | Agent | File |
390
550
  | --- | --- |
@@ -401,66 +561,117 @@ calmrun setup --write --hook # also add the Claude Code hook to ~/.clau
401
561
  calmrun setup --write --remove --hook # take both out again
402
562
  ```
403
563
 
404
- The block sits between `<!-- calmrun:start … -->` and `<!-- calmrun:end -->`. Running setup
405
- again replaces the block in place instead of adding a second one, and `--remove` deletes it
406
- and leaves the rest of the file as it was. Every file setup rewrites is first copied to
407
- `<file>.calmrun.bak`; a file that cannot be read or is not UTF-8 text is left alone (exit 1).
408
- `--hook` merges the PreToolUse entry into `settings.json`, keeps every other setting, and
409
- leaves a file it cannot parse untouched.
564
+ - The block sits between `<!-- calmrun:start … -->` and `<!-- calmrun:end -->`. Running setup
565
+ again replaces the block in place instead of adding a second one, and `--remove` deletes it
566
+ and leaves the rest of the file as it was.
567
+ - Every file setup rewrites is first copied to `<file>.calmrun.bak`; a file that cannot be read
568
+ or is not UTF-8 text is left alone (exit 1).
569
+ - `--hook` merges the PreToolUse entry into `settings.json`, keeps every other setting, and
570
+ leaves a file it cannot parse untouched.
571
+ - When Codex has an `AGENTS.override.md`, Codex reads that file instead; setup says so, and you
572
+ copy the block there too.
573
+ - `--home DIR` uses another home directory (for tests, or another user's profile).
410
574
 
411
- ### Instructions for agents
575
+ ### `calmrun guide` and hand-written instructions
412
576
 
413
- To write the instructions by hand instead, add this to `CLAUDE.md`, `AGENTS.md` or your
414
- agent's instruction file:
577
+ `calmrun guide` prints short instructions to paste into an agent's context. To write them by
578
+ hand instead, add this to `CLAUDE.md`, `AGENTS.md` or your agent's instruction file:
415
579
 
416
580
  ```markdown
417
581
  ## Heavy commands
418
582
 
419
583
  This machine is shared by several agents. Run heavy commands through the calmrun queue:
420
584
  `calmrun -- <command>` (tests, type checks, linters, builds, Playwright, docker compose,
421
- pytest, cargo/gradle builds). Example: `calmrun -- npx vitest run`.
585
+ pytest, cargo/gradle/make/dotnet/go builds). Example: `calmrun -- npx vitest run`.
422
586
  Run anything that may take more than a minute or two in the background and check on it later.
423
587
  Use `calmrun status` to see what is running or waiting. Do not wrap light commands
424
588
  (git, ls, cat, package installs).
425
589
  ```
426
590
 
427
- ## Per-OS notes
428
-
429
- - **Windows.** `.cmd` and `.bat` programs run through `cmd.exe /d /s /c` with every argument
430
- quoted and caret-escaped for both cmd parses a batch shim performs, so arguments such as
431
- `a&b`, `100%` or `"quoted"` arrive unchanged. `.ps1` files run with
432
- `powershell -NoProfile -ExecutionPolicy Bypass -File`. Ctrl+C reaches the command through the
433
- shared console; calmrun turns Ctrl+C processing back on if its parent had it disabled. A
434
- command ended by Ctrl+C exits 130.
435
- - **macOS / Linux.** The command gets its own process group. When calmrun runs in the
436
- foreground of a terminal, that group becomes the terminal's foreground group (so the command
437
- can read input and gets Ctrl+C directly) and the terminal is handed back afterwards; SIGINT,
438
- SIGTERM and SIGHUP that calmrun receives are forwarded to the group as SIGINT. Ctrl+Z stops
439
- the command and calmrun together; `fg` continues both.
440
- - **When calmrun itself is killed hard.** On Windows the Job Object ends the command's tree
441
- even after `taskkill /F`. On Linux the command gets SIGTERM when calmrun dies, even by
442
- `kill -9` (parent-death signal). On macOS a small `calmrun __watchdog` process does the same
443
- within a second. `calmrun mcp` stops its running tasks on Ctrl+C / SIGTERM and when its
444
- client closes stdin, then exits.
591
+ Messages meant for agents say what happened and what to run next (`calmrun: next: …`), for
592
+ example after a refused `docker compose up` or a command that is not on `PATH`.
593
+
594
+ ## Exit codes
595
+
596
+ | Exit code | Meaning |
597
+ | --- | --- |
598
+ | the command's | It ran. On Unix a command ended by signal `n` gives `128 + n`. |
599
+ | 1 | calmrun itself failed (state directory, lock, a file `setup` could not change) |
600
+ | 2 | Refused (watch mode, attached `docker compose up`, interactive `docker run`), bad arguments, or an invalid `--id` |
601
+ | 75 | Not started within `--wait-timeout`; place kept, see the `next:` line |
602
+ | 124 | Stopped by the MCP `timeout_s` |
603
+ | 126 | The command was found but could not be started |
604
+ | 127 | Command not found |
605
+ | 130 | Ctrl+C (while waiting or running) |
606
+ | 137 | Stopped by the memory ceiling or the critical free-RAM floor |
607
+
608
+ ## Platform notes
609
+
610
+ - **Windows** is where calmrun is built and checked by hand, as well as in CI. `.cmd` and
611
+ `.bat` programs run through `cmd.exe /d /s /c` with every argument quoted and caret-escaped
612
+ for both cmd parses a batch shim performs, so arguments such as `a&b`, `100%` or `"quoted"`
613
+ arrive unchanged. `.ps1` files run with `powershell -NoProfile -ExecutionPolicy Bypass -File`.
614
+ The command runs in a Job Object, so its tree ends even after `taskkill /F` on calmrun.
615
+ Ctrl+C reaches the command through the shared console; calmrun turns Ctrl+C processing back
616
+ on if its parent had it disabled. A command ended by Ctrl+C exits 130.
617
+ - **macOS / Linux** are covered by the test suite in CI, not by hand yet. The command gets its
618
+ own process group. When calmrun runs in the foreground of a terminal, that group becomes the
619
+ terminal's foreground group (so the command can read input and gets Ctrl+C directly) and the
620
+ terminal is handed back afterwards; SIGINT, SIGTERM and SIGHUP that calmrun receives are
621
+ forwarded to the group as SIGINT. Ctrl+Z stops the command and calmrun together; `fg`
622
+ continues both. On Linux the command gets SIGTERM when calmrun dies, even by `kill -9`
623
+ (parent-death signal); on macOS a small `calmrun __watchdog` process does the same within a
624
+ second.
445
625
  - **Memory figures.** calmrun counts resident memory: the working set on Windows and the
446
- resident set size (RSS) on macOS and Linux. Shared pages count once per process, so the
447
- tree total can be higher than what the OS reports as used; the default ceiling leaves room.
448
- - **What CI covers.** The test suite runs on Windows, macOS and Linux (GitHub-hosted x64 and
449
- arm64 runners): queue rules, exit codes, Ctrl+C while running and while waiting, a SIGKILLed
450
- calmrun taking its command with it (Unix), SIGTERM to the MCP server (Unix), and daemons
451
- surviving a normal exit, and the memory ceiling stopping a nested tree. The critical
452
- free-RAM floor is covered by unit tests only (it depends on the machine). Ctrl+Z is not
453
- covered by CI (runners have no terminal).
454
- The MCP server, tickets, the disk gate, named resources, separate queues and `setup` run
455
- their integration tests on all three systems as well. Killing calmrun ending the tree is tested on Windows only. The
456
- terminal hand-over is not covered by CI (runners have no terminal).
626
+ resident set size (RSS) on macOS and Linux. Shared pages count once per process, so the tree
627
+ total can be higher than what the OS reports as used; the default ceiling leaves room.
628
+ - **What CI covers.** CI runs the whole suite on `windows-latest` (x64), `ubuntu-latest` (x64)
629
+ and `macos-latest` (arm64): queue rules, exit codes, Ctrl+C while running and while waiting,
630
+ a SIGKILLed calmrun taking its command with it (Unix), SIGTERM to the MCP server (Unix),
631
+ daemons surviving a normal exit, the memory ceiling stopping a nested tree, the MCP server,
632
+ tickets, the disk gate, named resources, separate queues and `setup`. Killing calmrun ending
633
+ the tree is tested on Windows only. The critical free-RAM floor is covered by unit tests only
634
+ (it depends on the machine). Ctrl+Z and the terminal hand-over are not covered (runners have
635
+ no terminal). Release binaries for Windows arm64, Linux arm64 and macOS x64 are built but not
636
+ tested.
457
637
  - **Battery.** `calmrun doctor` reports whether the machine runs on battery; consider a smaller
458
638
  budget then.
459
639
 
460
- ## Development
640
+ ## Troubleshooting
641
+
642
+ **`calmrun: command not found` after installing.** The installers put the binary in
643
+ `~/.cargo/bin` (`%USERPROFILE%\.cargo\bin` on Windows). Open a new terminal, or add that folder
644
+ to `PATH`. Coding agents started before the install need a restart too; the Claude Code hook
645
+ falls back to calmrun's absolute path in its suggestions.
646
+
647
+ **A job waits although nothing seems to run.** `calmrun status` says why each job waits. On a
648
+ busy machine the RAM gate is the usual reason (`waiting for RAM: … free, needs …`): lower
649
+ `min_free_gb`, or set it to `0`. Entries of dead processes are removed automatically.
650
+
651
+ **A job I need now is stuck behind others.** `calmrun bump <label>`, or run it with
652
+ `--prio high`.
653
+
654
+ **My agent's tool call timed out while waiting.** Use `--wait-timeout` (CLI) or
655
+ `wait_timeout_s` (MCP) and resume with the ticket, or raise the client's tool timeout (see the
656
+ MCP section).
657
+
658
+ **`refused: … is watch mode`.** Queued jobs must end. Run the `calmrun: next:` command it
659
+ prints, or run the watcher outside calmrun.
461
660
 
462
- [ARCHITECTURE.md](ARCHITECTURE.md) maps the modules and explains how to add a tool, a
463
- gate, an MCP tool or an agent.
661
+ **A job was stopped with exit 137.** Its process tree passed `ceiling_gb`, or free RAM stayed
662
+ below `critical_free_gb` and it was the biggest job. Raise or disable the limit
663
+ (`CALMRUN_CEILING_GB=0`), or give the job fewer workers.
664
+
665
+ **My config seems ignored.** An unknown key or a TOML error makes calmrun skip the whole file
666
+ with a warning on stderr. `calmrun doctor` shows the path it reads and the values in effect.
667
+
668
+ **I want a separate budget for one project.** Use `--id <name>` on its runs (and on `status` /
669
+ `bump`).
670
+
671
+ ## Contributing
672
+
673
+ [ARCHITECTURE.md](ARCHITECTURE.md) maps the modules and explains how to add a tool, a gate, an
674
+ MCP tool or an agent. Changes are listed in [CHANGELOG.md](CHANGELOG.md).
464
675
 
465
676
  ```sh
466
677
  cargo fmt --all --check
@@ -468,6 +679,9 @@ cargo clippy --all-targets -- -D warnings
468
679
  cargo test
469
680
  ```
470
681
 
682
+ Bug reports and pull requests are welcome at
683
+ <https://github.com/vannt-dev/calmrun/issues>.
684
+
471
685
  ## License
472
686
 
473
687
  [MIT](LICENSE)
@@ -19,7 +19,7 @@
19
19
  "hasInstallScript": true,
20
20
  "license": "MIT",
21
21
  "name": "calmrun",
22
- "version": "0.1.0"
22
+ "version": "0.2.0"
23
23
  },
24
24
  "node_modules/detect-libc": {
25
25
  "engines": {
@@ -48,5 +48,5 @@
48
48
  }
49
49
  },
50
50
  "requires": true,
51
- "version": "0.1.0"
51
+ "version": "0.2.0"
52
52
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "artifactDownloadUrls": [
3
- "https://github.com/vannt-dev/calmrun/releases/download/v0.1.0"
3
+ "https://github.com/vannt-dev/calmrun/releases/download/v0.2.0"
4
4
  ],
5
5
  "bin": {
6
6
  "calmrun": "run-calmrun.js"
@@ -97,7 +97,7 @@
97
97
  "zipExt": ".tar.xz"
98
98
  }
99
99
  },
100
- "version": "0.1.0",
100
+ "version": "0.2.0",
101
101
  "volta": {
102
102
  "node": "18.14.1",
103
103
  "npm": "9.5.0"