[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-111849":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":9,"language":10,"languages":9,"totalLinesOfCode":9,"stars":11,"forks":12,"watchers":12,"openIssues":12,"contributorsCount":13,"subscribersCount":13,"size":13,"stars1d":13,"stars7d":14,"stars30d":15,"stars90d":13,"forks30d":13,"starsTrendScore":13,"compositeScore":16,"rankGlobal":9,"rankLanguage":9,"license":17,"archived":18,"fork":18,"defaultBranch":19,"hasWiki":20,"hasPages":18,"topics":21,"createdAt":9,"pushedAt":32,"updatedAt":33,"readmeContent":34,"aiSummary":35,"trendingCount":13,"starSnapshotCount":13,"syncStatus":36,"lastSyncTime":37,"discoverSource":38},111849,"heavy","mokevnin\u002Fheavy","mokevnin","A machine-wide counting semaphore for heavy commands: N slots shared by every checkout and agent on one machine",null,"Rust",59,1,0,4,8,43.7,"Apache License 2.0",false,"main",true,[22,23,24,25,26,27,28,29,30,31],"cli","coding-agents","concurrency","developer-tools","flock","lock","queue","resource-management","rust","semaphore","2026-11-15 01:22:08","2026-11-20 10:51:25","# heavy\n\nA machine-wide counting semaphore for heavy commands.\n\nTen coding agents, a few checkouts and a CI-like `check` task all start `go test`, `tsc` and\n`golangci-lint` at once, and the machine stops answering. `heavy` gives every such command one of\na few **slots** shared by everything on the machine: a command that finds all slots busy waits for\none, so the heavy commands take turns instead of starving each other.\n\n```sh\nheavy -- go test .\u002F...\nheavy -- pnpm exec tsc --noEmit\nheavy --status\n```\n\n## Install\n\n```sh\nbrew install mokevnin\u002Ftap\u002Fheavy        # Homebrew\nmise use -g github:mokevnin\u002Fheavy      # mise\ncargo install heavy                    # from source\ncurl -LsSf https:\u002F\u002Fgithub.com\u002Fmokevnin\u002Fheavy\u002Freleases\u002Flatest\u002Fdownload\u002Fheavy-installer.sh | sh\n```\n\nThe binaries are built for macOS and Linux, on arm64 and x86_64.\n\n## Set up with a coding agent\n\nCopy this prompt into Claude Code, Codex, Cursor or another coding agent opened in your project.\nThe agent installs `heavy`, wraps the project's heavy commands where they are defined and tells\nthe project's agents to run them that way.\n\n```text\nSet up heavy (https:\u002F\u002Fgithub.com\u002Fmokevnin\u002Fheavy), a machine-wide counting semaphore for heavy commands, in this project. Read its README first.\n\n1. Install heavy the way this project installs its tools: a line in mise.toml if the project uses mise (\"github:mokevnin\u002Fheavy\" = \"latest\"), otherwise Homebrew or the installer from the README. Everyone who runs the project's tasks needs it, CI included (heavy runs the command at once when CI is set, but the binary must be there). If it cannot be installed for everyone, wrap only the git hooks and leave the shared tasks alone.\n2. Find the heavy commands: test suites, type checks, linters and builds, and the tasks, scripts and git hooks that run them (mise tasks, package.json scripts, a Makefile, hk or lefthook config).\n3. Wrap each heavy command where it is defined, so everyone who runs the task gets it: `heavy -- go test .\u002F...`. Wrap the command itself, not a task that only calls other tasks. Leave quick commands alone.\n4. In git hooks add `--timeout 300 --on-timeout run`, so a busy machine slows a hook down but never fails it.\n5. Add to the project's agent instructions (AGENTS.md, CLAUDE.md or whatever file the project already uses; create AGENTS.md if there is none): run tests, type checks, linters and builds through the project's tasks, or as `heavy -- \u003Ccommand>` when there is no task.\n6. Run each wrapped task once and report what you wrapped and where.\n```\n\n## How it behaves\n\n- **N slots.** `--slots N` or `HEAVY_SLOTS`; the default is a quarter of the cores, at least one.\n- **Shared by every process on the machine.** A slot is an exclusive `flock` on a file in\n  `$TMPDIR\u002Fheavy\u002F\u003Cpool>` (`--dir` or `HEAVY_DIR` moves it). Every checkout, every agent and every\n  tool that opens the same directory shares the slots.\n- **Released however the holder ends.** The operating system drops a `flock` when its holder dies,\n  `kill -9` included, so a crashed run never leaves a slot taken. The command does not inherit the\n  lock: a `heavy` that is killed outright frees its slot at once while its command, if still\n  running, is no longer counted.\n- **Waits and says who it waits for.** When every slot is busy it says so once, with who holds\n  each slot, and when it gets one, how long it waited:\n\n  ```\n  heavy: all 2 slots of pool 'default' are busy, waiting for one\n  heavy:   slot 0: held by pid 81234 for 252s: go test .\u002F...\n  heavy:   slot 1: held by pid 81302 for 40s: pnpm exec tsc --noEmit\n  heavy: got slot 1 after 37.2s\n  ```\n\n  A command that finds a free slot prints nothing.\n- **Waits as long as you let it.** `--timeout SECONDS` (`HEAVY_TIMEOUT`) stops waiting; then\n  `--on-timeout fail` (the default) exits with status 75 and `--on-timeout run`\n  (`HEAVY_ON_TIMEOUT`) runs the command anyway, without a slot, so a busy machine slows a check\n  down but never fails it.\n- **Logs every wait.** `--log FILE` (`HEAVY_LOG`) appends one JSON line per queued run, to see\n  how long commands wait and whether the number of slots is right:\n\n  ```json\n  {\"start\":1761510000,\"pool\":\"default\",\"command\":\"go test .\u002F...\",\"cwd\":\"\u002Fsrc\u002Fapp\",\"slot\":1,\"waited_ms\":37210,\"ran_ms\":81022,\"timed_out\":false,\"exit\":0}\n  ```\n\n  `slot` and `ran_ms` are `null` when the run timed out without running. Runs that skip the queue\n  (nested or on CI) are not logged.\n- **Nesting never deadlocks.** The command runs with `HEAVY_HELD=\u003Cpool>` and `HEAVY_SLOT=\u003Cn>`; a\n  `heavy` of the same pool started inside it runs its command at once. A task that calls another\n  heavy task is therefore safe.\n- **CI skips the queue.** A CI machine is its own; with `CI` set the command runs at once.\n  `--no-skip-ci` turns that off.\n- **Pools.** `--pool NAME` (`HEAVY_POOL`) keeps pools apart: they do not share slots.\n- **Exit status.** The command's own; `128 + n` when a signal `n` ended it; 127 when it does not\n  exist; 75 on a timeout (a command that exits 75 itself looks the same: a timeout is the one\n  that prints `gave up waiting` on stderr). `SIGINT`, `SIGTERM` and `SIGHUP` sent to `heavy` reach the command.\n- **`heavy --status`** shows who holds each slot (pid, how long, the command). The record is for\n  display only; the lock is the source of truth.\n\nThe queue is **not fair**: when a slot frees, the first waiter to look takes it (they look every\nquarter of a second, with jitter). The slot files must be on a local file system.\n\n## As a library\n\n```rust\nuse heavy::Pool;\n\nlet pool = Pool::open(\"\u002Ftmp\u002Fheavy\u002Fdefault\", 4)?;\nlet slot = pool.acquire(|| eprintln!(\"all slots are busy, waiting\"))?;\n\u002F\u002F run the heavy work; the slot is released when `slot` is dropped\ndrop(slot);\n```\n\n`Pool::try_acquire` takes a free slot or returns `None`, `Pool::acquire_timeout` gives up after a\nduration, `Pool::status` reports every slot. The library is synchronous and has no dependencies;\nbuild it without the command line with `default-features = false`.\n\n## Why not ...\n\n| | |\n| --- | --- |\n| a lock file in a script | N lock files are easy; the rest is the work: freeing a slot on `kill -9`, nesting without a deadlock, passing on signals and exit codes, saying who holds the slots and how long a command waited |\n| `flock(1)` | one lock, not N slots; not on macOS without Homebrew's util-linux |\n| GNU `parallel --semaphore` (`sem`) | needs Perl, and a nested call deadlocks |\n| the GNU make jobserver | a holder killed with `SIGKILL` loses its token, and only make, ninja and cargo speak it |\n| a daemon queue (`pueue`, `nq`) | a service to run and restart; `heavy` has no state beyond the lock files |\n\n## License\n\nApache-2.0.\n","heavy 是一个面向机器全局的计数信号量工具，用于限制高负载命令（如测试、类型检查、静态分析）的并发执行数量。它通过基于文件锁（flock）的跨进程共享槽位（slots）机制实现资源协调，支持动态配置槽位数、超时等待与自动释放，所有本地进程（包括多个代码仓库、开发代理和CI任务）共享同一组槽位。核心特点包括零依赖二进制分发、macOS\u002FLinux多架构支持、与开发工作流（mise、git hooks、package.json脚本等）无缝集成。适用于多代理协作、本地并行开发、CI\u002FCD资源受限环境下的命令节流与系统稳定性保障。",2,"2026-11-24 04:41:58","CREATED_QUERY"]