@kaynooo/cli-wait 0.0.0-stage → 0.5.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kaynooo <contact@kaynooo.fr>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,51 @@
1
- # Temporary Holding Version
1
+ # waitfor and slot
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ `slot` is documented after `waitfor`, below.
4
+
5
+ Waits for a background build or server for Claude Code, where a session would otherwise `sleep 30; tail -c 2000 build.log` or hand-write an `until` loop: `waitfor` returns as soon as the log line shows, the port listens or the URL answers, and stops early on an error line.
6
+
7
+ ```sh
8
+ bun install -g @kaynooo/cli-wait
9
+ waitfor --file server.log --until 'Listening on' --fail 'Error|FATAL' --timeout 2m
10
+ waitfor --port 5432
11
+ waitfor --url http://localhost:8000/health
12
+ waitfor --pid 4242
13
+ waitfor task b92stimuo
14
+ ```
15
+
16
+ ## Behaviour
17
+
18
+ - `--file` is read from its start, line by line as each is completed, colours stripped; it may not exist yet. A file that shrinks (rotated, truncated) is read again from its start.
19
+ - `--until <regex>` waits for a line of `--file` to match and prints it as `<file>:<line>: <text>`.
20
+ - `--fail <regex>` ends the wait on the first matching line of `--file`, printing the five lines on each side of it on stderr, as long as some condition is still unmet: a `--until` line before it in the same read wins.
21
+ - `--port <n>` waits for a TCP connection to `--host` (127.0.0.1) to be accepted, `--url <url>` for a 2xx answer, redirects followed. Each prints how long it took.
22
+ - `--pid <n>` waits for the process to exit, checked with signal 0, so it never matches its own shell the way a `while pgrep -f` loop does. A zombie counts as exited. A `--port` connection attempt is given up after 3 seconds and retried, so dropped packets do not hold a poll for minutes.
23
+ - `waitfor task <id | file>` waits for a Claude Code background Bash task to end, its id found under `$CLAUDE_CODE_TMPDIR` (or `$TMPDIR`, `/tmp`) in `claude-<uid>/*/*/tasks/<id>.output`, then prints its exit code, its last 20 lines (`-n`) and the `(fail)` and `error:` lines above them, the last 30. It exits 0 when the task exited 0, 1 on another code, 2 on a timeout with the last lines; a path that does not exist fails at once with 2, and a subagent's id is refused, its notification reporting its end. `--json` prints `{task, path, code, ms, failures, tail}`, each line as `{number, text}`.
24
+ - Every condition given must be met: `--port 8000 --file server.log --fail Error` waits for the port and gives up early when the log shows an error.
25
+ - `--timeout` takes `30s`, `5m`, `1h` or a bare number of seconds, 5 minutes by default. On a timeout stderr names what is still missing (the file absent, the connection error, the status answered) and the file's last 20 lines.
26
+ - Exit codes: 0 every condition met, 1 a `--fail` line, 2 a timeout or a usage error.
27
+ - Named `waitfor` so as not to shadow the shell's `wait`.
28
+
29
+ # slot
30
+
31
+ Heavy commands from parallel Claude Code sessions (phpunit, playwright, vue-tsc, eslint) queue behind a machine-wide set of slots instead of overloading the machine, and a named lock keeps two runs off one shared resource such as a test database.
32
+
33
+ ```sh
34
+ slot -- bunx vue-tsc
35
+ slot --lock booki-test-db -- vendor/bin/phpunit
36
+ slot -n 6 -t 10m -- bun test
37
+ slot ls
38
+ check --slot
39
+ ```
40
+
41
+ ## Behaviour
42
+
43
+ - `slot -- <cmd>` waits for a free slot, runs the command with the terminal's stdin, stdout and stderr and exits with its code (a signal's `128 + n`, 127 when it cannot start). The slots are shared by every session, worktree and shell of the user; there are half as many as CPUs by default, `-n` sets the count (every caller should use the same one).
44
+ - `--lock <name>` also holds a named lock, repeatable, across sessions and worktrees. The locks and the slot are taken all together or not at all: a command waiting for one gives back what it got, so it never occupies a slot while it waits for a lock, nor holds a lock while it waits for a slot. The price is no queue: a command wanting a lock and a slot can wait long behind a stream of short holders of either. `--no-slot` takes the locks alone.
45
+ - Slots and locks are `flock`s on files, called through `bun:ffi`: the kernel drops one with its holder, so a `slot` killed with SIGKILL frees what it held, and nothing is cleaned up by pid or timestamp. The command it started is not killed with it: it keeps running with its slot and lock already freed, so the lock no longer protects it.
46
+ - A `slot` inside a slotted command does not wait for another slot or for a lock the outer one holds (the `SLOT_HOLDING` variable lists them), so a script and the commands it runs may both be wrapped, and `check --slot` over a script calling `slot --lock` cannot deadlock against a session waiting for a slot while it holds that lock, since a waiter holds nothing.
47
+ - When it has to wait, stderr gets one line naming who holds what it needs: the session, the command and for how long. `--timeout` (`-t`, `30s`, `5m`, a bare number of seconds) gives up with exit 2; it waits forever by default.
48
+ - `slot ls` lists the holders (`slot 2`, `lock booki-test-db`) and the waiters with their session (found as `ft take` finds it, through `~/.claude/sessions`), command and age, `--json` as `{slots, busy, entries}`. A waiter that died is dropped from the list.
49
+ - `slot ls` is the listing even as a first word, `slot -- ls` being read as `slot ls` because Bun drops a leading `--`: write `slot -n 4 -- ls` for the command.
50
+ - State lives in `$XDG_RUNTIME_DIR/kaynooo-cli/slot` (`~/.cache/kaynooo-cli/slot` without it), only the user can enter it; `$SLOT_DIR` points elsewhere.
51
+ - Exit codes: the command's, 2 on a timeout or a usage error.