@kaynooo/cli-wait 0.13.1 → 0.14.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/README.md CHANGED
@@ -8,7 +8,9 @@ Waits for a background build or server for Claude Code, where a session would ot
8
8
 
9
9
  ```sh
10
10
  waitfor --file server.log --until 'Listening on' --fail 'Error|FATAL' --timeout 2m
11
+ waitfor --file out.bin --idle 2s
11
12
  waitfor --port 5432
13
+ waitfor --port-free 8000
12
14
  waitfor --url http://localhost:8000/health
13
15
  waitfor --pid 4242
14
16
  waitfor --cmd 'curl -fs localhost:8000/health'
@@ -21,12 +23,13 @@ waitfor task b92stimuo
21
23
  - `--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.
22
24
  - `--until <regex>` waits for a line of `--file` to match and prints it as `<file>:<line>: <text>`.
23
25
  - `--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.
24
- - `--port <n>` waits for a TCP connection to `--host` (127.0.0.1 or ::1) to be accepted, `--url <url>` for a 2xx answer, redirects followed. Each prints how long it took.
25
- - `--port` and `--url` may be repeated: every one must be met (or the first with `--any`), each printed with how long it took, and `--json` adds `conditions: [{name, ms}]` for each one met. A timeout lists only the ones still pending.
26
+ - `--idle <duration>` waits until `--file` exists and its size and mtime stay unchanged for that duration (`500ms`, `2s`, …), without requiring `--until` or `--fail` (and may be combined with `--fail` or `--until`).
27
+ - `--port <n>` waits for a TCP connection to `--host` (127.0.0.1 or ::1) to be accepted, `--port-free <n>` waits until the port stops accepting connections (when `--host` is omitted, neither 127.0.0.1 nor ::1 may accept connections), and `--url <url>` waits for a 2xx answer, redirects followed. Each prints how long it took.
28
+ - `--port`, `--port-free` and `--url` may be repeated: every one must be met (or the first with `--any`), each printed with how long it took, and `--json` adds `conditions: [{name, ms}]` for each one met. A timeout lists only the ones still pending.
26
29
  - `--status <spec>` sets the status a `--url` must answer instead of any 2xx: `301`, `200-299`, `2xx` or a comma list (redirects are not followed when a 3xx is asked for). `--body <regex>` makes the first MiB of the body match too. With several `--url`, both apply to every one.
27
30
  - `--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.
28
31
  - `--cmd <command>` runs the command through `sh -c` and waits for it to exit 0, re-running it every `--interval` (1s, `-t` bounds each run to the time left, 30s at most); a timeout names its last exit code and last output line.
29
- - `--any` is met by the first condition that is, not all of them: it takes two or more of `--until`, `--port`, `--url`, `--pid` and `--cmd`, prints the one that was met, and a timeout says none was and lists them all. A `--fail` line still ends the wait with 1.
32
+ - `--any` is met by the first condition that is, not all of them: it takes two or more of `--until`, `--idle`, `--port`, `--port-free`, `--url`, `--healthy`, `--pid` and `--cmd`, prints the one that was met, and a timeout says none was and lists them all. A `--fail` line still ends the wait with 1.
30
33
  - `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}`.
31
34
  - `--json` prints `{met, ms, line}` once met, or on a `--fail` line with `met` false, `line` being the last `--until` line or the `--fail` one as `{number, text}`; the progress lines go to stderr. `--quiet` drops the live progress line, on `waitfor task` too.
32
35
  - 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.
package/dist/cli.js CHANGED
@@ -1,24 +1,24 @@
1
1
  #!/bin/sh
2
2
  // @bun 2>/dev/null; exec bun --no-env-file --config=/dev/null "$0" "$@"
3
3
  import{configuredNumber,paint,writeErr,problem,formatDuration,formatElapsed,truncate,printJson,wholeNumber,duration,jsonOption,fail,badUsage,parse,runCommand,liveRegion,runMain}from"./chunk-18nqpwfh.js";import{existsSync as existsSync3}from"fs";import process2 from"process";import{existsSync,statSync}from"fs";var TAIL=configuredNumber("wait","tail",20),AROUND=configuredNumber("wait","around",5),CARRIAGE_RETURN=/\r$/,SLICE_BYTES=1048576,MAX_LINE=1e4,PORT_TIMEOUT_MS=configuredNumber("wait","portTimeoutMs",3000);class FileWatch{path;until;failOn;offset=0;decoder=new TextDecoder;partial="";identity;number=0;recent=[];failure;matched=!1;constructor(path,until,failOn,fromEnd=!1){this.path=path;this.until=until;this.failOn=failOn;if(fromEnd&&existsSync(path)){let stats=statSync(path);if(stats.isDirectory())badUsage(`--file ${path} is a folder, not a log file`);this.offset=stats.size,this.identity={dev:stats.dev,ino:stats.ino}}}get done(){return this.until===void 0||this.matched}get failing(){return this.failure!==void 0}get failsFirst(){return this.failure?.isFirst===!0}get exists(){return existsSync(this.path)}async poll(){let events=[];for(let lines=await this.nextLines();lines!==void 0;lines=await this.nextLines())for(let line of lines){if(this.failure!==void 0){if(this.failure.after.length<AROUND)this.failure.after.push(line);continue}if(this.failOn?.test(line.text)===!0){this.failure={before:this.recent.slice(-AROUND),line,after:[],waited:!1,isFirst:!this.matched};continue}if(this.recent.push(line),this.recent.length>TAIL)this.recent.shift();if(!this.matched&&this.until?.test(line.text)===!0)this.matched=!0,events.push({kind:"until",line})}if(this.failure!==void 0&&!this.failure.waited&&this.failure.after.length<AROUND)this.failure.waited=!0;else if(this.failure!==void 0)events.push({kind:"fail",line:this.failure.line,excerpt:[...this.failure.before,this.failure.line,...this.failure.after]});return events}excerpt(){return this.recent}async nextLines(){if(!existsSync(this.path))return;let stats=statSync(this.path);if(stats.isDirectory())badUsage(`--file ${this.path} is a folder, not a log file`);let{size,dev,ino}=stats,replaced=this.identity!==void 0&&(this.identity.dev!==dev||this.identity.ino!==ino);if(this.identity={dev,ino},size<this.offset||replaced)this.offset=0,this.decoder=new TextDecoder,this.partial="",this.number=0,this.recent=[];if(size===this.offset)return;let end=Math.min(size,this.offset+SLICE_BYTES),chunk=this.decoder.decode(await this.slice(end),{stream:!0});this.offset=end;let pieces=(this.partial+chunk).split(`
4
- `);return this.partial=(pieces.pop()??"").slice(0,MAX_LINE),pieces.map((text)=>({number:++this.number,text:Bun.stripANSI(text.slice(0,MAX_LINE).replace(CARRIAGE_RETURN,""))}))}async slice(end){try{return await Bun.file(this.path).slice(this.offset,end).bytes()}catch(error){return badUsage(`--file ${this.path} cannot be read (${error.code??String(error)})`)}}}async function portProblem(host,port,timeoutMs=PORT_TIMEOUT_MS){let attempt=Bun.connect({hostname:host,port,socket:{data:(socket)=>void socket.end()}}),timer;try{let socket=await Promise.race([attempt,new Promise((resolve)=>{timer=setTimeout(resolve,timeoutMs,"timeout")})]);if(socket==="timeout")return closeWhenConnected(attempt),"ETIMEDOUT";socket.end();return}catch(error){return error instanceof Error?error.code??error.message:String(error)}finally{clearTimeout(timer)}}async function closeWhenConnected(attempt){try{(await attempt).end()}catch{}}var STATUS_CLASS=/^([1-5])xx$/i,STATUS_RANGE=/^(\d{3})(?:-(\d{3}))?$/,BODY_BYTES=1048576;function parseStatus(spec){let tests=[];for(let part of spec.split(",").map((item)=>item.trim())){let klass=STATUS_CLASS.exec(part),range=STATUS_RANGE.exec(part);if(klass!==null){let hundred=Number(klass[1]);tests.push((status)=>Math.floor(status/100)===hundred)}else if(range!==null){let low=Number(range[1]),high=Number(range[2]??range[1]);tests.push((status)=>status>=low&&status<=high)}else return}return(status)=>tests.some((test)=>test(status))}async function healthyProblem(service){if(Bun.which("docker")===null)return"docker is not installed";let compose=await runCommand(["docker","compose","ps","--format","json",service]);if(compose.code===0&&compose.stdout.trim()!==""){let rows=compose.stdout.trim().split(`
4
+ `);return this.partial=(pieces.pop()??"").slice(0,MAX_LINE),pieces.map((text)=>({number:++this.number,text:Bun.stripANSI(text.slice(0,MAX_LINE).replace(CARRIAGE_RETURN,""))}))}async slice(end){try{return await Bun.file(this.path).slice(this.offset,end).bytes()}catch(error){return badUsage(`--file ${this.path} cannot be read (${error.code??String(error)})`)}}}class IdleWatch{path;durationMs;last;stableSince;matched=!1;lastNow=Date.now();constructor(path,durationMs){this.path=path;this.durationMs=durationMs}get done(){return this.matched}get exists(){return this.last!==void 0}get stableFor(){return this.stableSince===void 0?0:Math.max(0,this.lastNow-this.stableSince)}poll(now=Date.now()){if(this.lastNow=now,this.matched)return!1;let stats;try{stats=statSync(this.path,{bigint:!0,throwIfNoEntry:!1})}catch(error){let code=error.code;if(code==="ENOTDIR")return this.last=void 0,this.stableSince=void 0,!1;badUsage(`--file ${this.path} cannot be stat'd (${code??String(error)})`)}if(stats===void 0)return this.last=void 0,this.stableSince=void 0,!1;if(stats.isDirectory())badUsage(`--file ${this.path} is a folder, not a file`);let current={size:stats.size,mtimeNs:stats.mtimeNs,dev:stats.dev,ino:stats.ino};if(this.last===void 0||this.last.size!==current.size||this.last.mtimeNs!==current.mtimeNs||this.last.dev!==current.dev||this.last.ino!==current.ino)return this.last=current,this.stableSince=now,!1;if(this.stableSince!==void 0&&now-this.stableSince>=this.durationMs)return this.matched=!0,!0;return!1}}async function portProblem(host,port,timeoutMs=PORT_TIMEOUT_MS){let attempt=Bun.connect({hostname:host,port,socket:{data:(socket)=>void socket.end()}}),timer;try{let socket=await Promise.race([attempt,new Promise((resolve)=>{timer=setTimeout(resolve,timeoutMs,"timeout")})]);if(socket==="timeout")return closeWhenConnected(attempt),"ETIMEDOUT";socket.end();return}catch(error){return error instanceof Error?error.code??error.message:String(error)}finally{clearTimeout(timer)}}async function portFreeHost(hosts,port,timeoutMs=PORT_TIMEOUT_MS){for(let host of hosts)if(await portProblem(host,port,timeoutMs)===void 0)return host;return}async function closeWhenConnected(attempt){try{(await attempt).end()}catch{}}var STATUS_CLASS=/^([1-5])xx$/i,STATUS_RANGE=/^(\d{3})(?:-(\d{3}))?$/,BODY_BYTES=1048576;function parseStatus(spec){let tests=[];for(let part of spec.split(",").map((item)=>item.trim())){let klass=STATUS_CLASS.exec(part),range=STATUS_RANGE.exec(part);if(klass!==null){let hundred=Number(klass[1]);tests.push((status)=>Math.floor(status/100)===hundred)}else if(range!==null){let low=Number(range[1]),high=Number(range[2]??range[1]);tests.push((status)=>status>=low&&status<=high)}else return}return(status)=>tests.some((test)=>test(status))}async function healthyProblem(service){if(Bun.which("docker")===null)return"docker is not installed";let compose=await runCommand(["docker","compose","ps","--format","json",service]);if(compose.code===0&&compose.stdout.trim()!==""){let rows=compose.stdout.trim().split(`
5
5
  `).flatMap((line)=>{try{let parsed=JSON.parse(line);return Array.isArray(parsed)?parsed:[parsed]}catch{return[]}});if(rows.length>0){let states=rows.map((row)=>String(row.Health??row.State??row.Status??"unknown").toLowerCase());return states.every((state)=>state==="healthy"||state.includes("(healthy)"))?void 0:states.join(", ")}}let inspected=await runCommand(["docker","inspect","--format","{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}",service]);if(inspected.code!==0)return"container not found";let status=inspected.stdout.trim().toLowerCase();return status==="healthy"?void 0:status||"unknown"}async function readBody(response){let reader=response.body?.getReader();if(reader===void 0)return"";let decoder=new TextDecoder,text="",bytes=0;while(bytes<BODY_BYTES){let{done,value}=await reader.read();if(done)break;bytes+=value?.length??0,text+=decoder.decode(value,{stream:!0})}return await reader.cancel(),text}async function urlCheck(url,timeout,expect={}){try{let wantsRedirect=expect.status!==void 0&&Array.from({length:100},(_,index)=>300+index).some(expect.status.test),init={signal:AbortSignal.timeout(timeout),redirect:wantsRedirect?"manual":"follow",...expect.headers===void 0?{}:{headers:expect.headers},...expect.insecure===!0?{tls:{rejectUnauthorized:!1}}:{}},response=await fetch(url,init);if(!(expect.status===void 0?response.ok:expect.status.test(response.status)))return await response.body?.cancel(),{problem:expect.status===void 0?`answered ${response.status}`:`answered ${response.status}, expected ${expect.status.spec}`};if(expect.body===void 0)return await response.body?.cancel(),{status:response.status};return expect.body.test(await readBody(response))?{status:response.status}:{problem:`answered ${response.status} but the body does not match ${expect.body}`}}catch(error){return{problem:error instanceof Error?error.message:String(error),isTimeout:error instanceof Error&&error.name==="TimeoutError"}}}import{existsSync as existsSync2,lstatSync,readFileSync,statSync as statSync2}from"fs";import{join}from"path";import process from"process";var EXITED=/(?:^|\n)\[exited with code (-?\d+)\]\n*$/,FAILURE=/\(fail\)|\berror:/i,TASK_ID=/^[\w-]+$/,TAIL_BYTES=256,LONGEST_FAILURES=30,CARRIAGE_RETURN2=/\r$/;function tasksRoot(env){return join(env.CLAUDE_CODE_TMPDIR??env.TMPDIR??"/tmp",`claude-${process.getuid?.()??0}`)}function taskFile(task,env=process.env){if(task.includes("/")||task.endsWith(".output"))return task;if(!TASK_ID.test(task))return;let root=tasksRoot(env),found=existsSync2(root)?[...new Bun.Glob(`*/*/tasks/${task}.output`).scanSync({cwd:root,onlyFiles:!1})]:[];return found.length===0?void 0:join(root,found[0]??"")}function isTranscript(path){return existsSync2(path)&&lstatSync(path).isSymbolicLink()&&path.endsWith(".output")}async function exitCode(path){if(!existsSync2(path))return;let size=statSync2(path).size,found=EXITED.exec(await Bun.file(path).slice(Math.max(0,size-TAIL_BYTES),size).text());return found===null?void 0:Number(found[1])}async function taskEnd(path,lines){if(!existsSync2(path))return{failures:[],tail:[]};let all=(await Bun.file(path).text()).replace(EXITED,"").split(`
6
- `).map((line,i)=>({number:i+1,text:Bun.stripANSI(line.replace(CARRIAGE_RETURN2,""))}));while(all.at(-1)?.text.trim()==="")all.pop();let tail=all.slice(-lines),first=tail[0]?.number??1/0;return{failures:all.filter((line)=>line.number<first&&FAILURE.test(line.text)).slice(-LONGEST_FAILURES),tail}}function pidAlive(pid){try{process.kill(pid,0)}catch(error){return error.code==="EPERM"}return!isZombie(pid)}function isZombie(pid){try{let stat=readFileSync(`/proc/${pid}/stat`,"utf8");return stat.slice(stat.lastIndexOf(")")+2,stat.lastIndexOf(")")+3)==="Z"}catch{return!1}}var USAGE=`waitfor [options]: waits until a file shows a line, a port listens, a URL answers 2xx, a Docker service is healthy, a process exits or a command exits 0
6
+ `).map((line,i)=>({number:i+1,text:Bun.stripANSI(line.replace(CARRIAGE_RETURN2,""))}));while(all.at(-1)?.text.trim()==="")all.pop();let tail=all.slice(-lines),first=tail[0]?.number??1/0;return{failures:all.filter((line)=>line.number<first&&FAILURE.test(line.text)).slice(-LONGEST_FAILURES),tail}}function pidAlive(pid){try{process.kill(pid,0)}catch(error){return error.code==="EPERM"}return!isZombie(pid)}function isZombie(pid){try{let stat=readFileSync(`/proc/${pid}/stat`,"utf8");return stat.slice(stat.lastIndexOf(")")+2,stat.lastIndexOf(")")+3)==="Z"}catch{return!1}}var USAGE=`waitfor [options]: waits until a file shows a line or goes idle, a port listens or frees up, a URL answers 2xx, a Docker service is healthy, a process exits or a command exits 0
7
7
  waitfor task <task id | file>: waits for a Claude Code background task to end (waitfor task --help)
8
8
 
9
- All conditions are polled in parallel every tick. Every condition given must be met, or with --any the first of them; --port, --url and --healthy may be repeated. A --fail line in --file or a --while-pid process exiting ends the wait immediately with exit 1.`,TASK_USAGE=`waitfor task [options] <task id | file>: waits for a Claude Code background task to end, then prints its exit code, its last lines and the (fail) and error: lines above them
9
+ All conditions are polled in parallel every tick. Every condition given must be met, or with --any the first of them; --port, --port-free, --url and --healthy may be repeated. A --fail line in --file or a --while-pid process exiting ends the wait immediately with exit 1.`,TASK_USAGE=`waitfor task [options] <task id | file>: waits for a Claude Code background task to end, then prints its exit code, its last lines and the (fail) and error: lines above them
10
10
 
11
11
  The task is the id a background Bash call returned, or the path of its .output file.
12
- --json prints {task, path, code, ms, failures, tail}, each line as {number, text}.`,TIMEOUT_EXIT=124,EXITS=[[0,"every condition was met"],[1,"a --fail line showed up or --while-pid exited"],[124,"it timed out"],[2,"a usage error"]],TASK_EXITS=[[0,"the task exited 0"],[1,"it exited with another code"],[124,"it timed out"],[2,"a usage error"]],TIMEOUT={type:"string",short:"t",description:"how long before giving up (5m): 30s, 5m, 1h, a bare number in seconds"},TASK_OPTIONS={lines:{type:"string",short:"n",description:"how many of its last lines to print (20)"},timeout:TIMEOUT,json:jsonOption(),quiet:{type:"boolean",short:"q",description:"no live progress line"}},OPTIONS={file:{type:"string",short:"f",description:"a log file to read, waiting for it to exist"},"from-end":{type:"boolean",description:"with --file, start reading from the current end of the file (ignore existing lines)"},until:{type:"string",short:"u",description:"a regular expression a line of --file must match"},fail:{type:"string",short:"e",description:"a regular expression whose first matching line of --file is a failure"},port:{type:"string",short:"p",multiple:!0,description:"a TCP port that must accept connections, repeatable"},host:{type:"string",description:"the host of --port (127.0.0.1 and ::1)"},url:{type:"string",multiple:!0,description:"a URL that must answer 2xx (or --status), repeatable"},header:{type:"string",short:"H",multiple:!0,description:'"Name: value" header sent with every --url request, repeatable'},insecure:{type:"boolean",short:"k",description:"with --url, ignore untrusted TLS certificates"},status:{type:"string",description:"the status a --url must answer instead of 2xx: 301, 200-299, 2xx or a comma list, for every --url"},body:{type:"string",description:"a regular expression the first MiB of a --url body must match, for every --url"},healthy:{type:"string",multiple:!0,description:"a Docker Compose service or container that must report healthy, repeatable"},pid:{type:"string",description:"a process id that must exit"},"while-pid":{type:"string",description:"abort immediately with exit 1 if this process exits before conditions are met"},cmd:{type:"string",short:"c",description:"a shell command that must exit 0, re-run every --interval"},interval:{type:"string",description:"how long between two runs of --cmd (1s)"},any:{type:"boolean",description:"met by the first condition that is, not all of them (needs two)"},timeout:TIMEOUT,json:jsonOption("{met, ms, line, conditions: [{name, ms}]}, line being the last --until line or the --fail one as {number, text}; the progress lines go to stderr"),quiet:{type:"boolean",short:"q",description:"no live progress line: only what was met and the failure"}},POLL=250,URL_TIMEOUT=5000,WIDTH=400,CMD_RUN_LIMIT=30000,LAST_LINE=/[^\n]+(?=\n*$)/,HEADER_LINE=/^[\w!#$%&'*+.^`|~-]+:/;function regex(source,name){if(source===void 0)return;try{return new RegExp(source)}catch(error){fail(`--${name} is no valid regular expression: ${error instanceof Error?error.message:String(error)}`)}}function numbered(lines,marked){let width=String(lines.at(-1)?.number??0).length;return lines.map((line)=>`${line===marked?">":" "} ${String(line.number).padStart(width)} ${truncate(line.text,WIDTH)}`).join(`
12
+ --json prints {task, path, code, ms, failures, tail}, each line as {number, text}.`,TIMEOUT_EXIT=124,EXITS=[[0,"every condition was met"],[1,"a --fail line showed up or --while-pid exited"],[124,"it timed out"],[2,"a usage error"]],TASK_EXITS=[[0,"the task exited 0"],[1,"it exited with another code"],[124,"it timed out"],[2,"a usage error"]],TIMEOUT={type:"string",short:"t",description:"how long before giving up (5m): 30s, 5m, 1h, a bare number in seconds"},TASK_OPTIONS={lines:{type:"string",short:"n",description:"how many of its last lines to print (20)"},timeout:TIMEOUT,json:jsonOption(),quiet:{type:"boolean",short:"q",description:"no live progress line"}},OPTIONS={file:{type:"string",short:"f",description:"a file to read or watch, waiting for it to exist"},"from-end":{type:"boolean",description:"with --file, start reading from the current end of the file (ignore existing lines)"},until:{type:"string",short:"u",description:"a regular expression a line of --file must match"},fail:{type:"string",short:"e",description:"a regular expression whose first matching line of --file is a failure"},idle:{type:"string",description:"with --file, wait until its size and mtime stay unchanged for this duration (e.g. 2s)"},port:{type:"string",short:"p",multiple:!0,description:"a TCP port that must accept connections, repeatable"},"port-free":{type:"string",multiple:!0,description:"a TCP port that must stop accepting connections, repeatable"},host:{type:"string",description:"the host of --port and --port-free (127.0.0.1 and ::1)"},url:{type:"string",multiple:!0,description:"a URL that must answer 2xx (or --status), repeatable"},header:{type:"string",short:"H",multiple:!0,description:'"Name: value" header sent with every --url request, repeatable'},insecure:{type:"boolean",short:"k",description:"with --url, ignore untrusted TLS certificates"},status:{type:"string",description:"the status a --url must answer instead of 2xx: 301, 200-299, 2xx or a comma list, for every --url"},body:{type:"string",description:"a regular expression the first MiB of a --url body must match, for every --url"},healthy:{type:"string",multiple:!0,description:"a Docker Compose service or container that must report healthy, repeatable"},pid:{type:"string",description:"a process id that must exit"},"while-pid":{type:"string",description:"abort immediately with exit 1 if this process exits before conditions are met"},cmd:{type:"string",short:"c",description:"a shell command that must exit 0, re-run every --interval"},interval:{type:"string",description:"how long between two runs of --cmd (1s)"},any:{type:"boolean",description:"met by the first condition that is, not all of them (needs two)"},timeout:TIMEOUT,json:jsonOption("{met, ms, line, conditions: [{name, ms}]}, line being the last --until line or the --fail one as {number, text}; the progress lines go to stderr"),quiet:{type:"boolean",short:"q",description:"no live progress line: only what was met and the failure"}},POLL=250,URL_TIMEOUT=5000,WIDTH=400,CMD_RUN_LIMIT=30000,LAST_LINE=/[^\n]+(?=\n*$)/,HEADER_LINE=/^[\w!#$%&'*+.^`|~-]+:/;function regex(source,name){if(source===void 0)return;try{return new RegExp(source)}catch(error){fail(`--${name} is no valid regular expression: ${error instanceof Error?error.message:String(error)}`)}}function numbered(lines,marked){let width=String(lines.at(-1)?.number??0).length;return lines.map((line)=>`${line===marked?">":" "} ${String(line.number).padStart(width)} ${truncate(line.text,WIDTH)}`).join(`
13
13
  `)}async function cmdProblem(command,timeoutMs){try{let ran=await runCommand(["sh","-c",command],{timeoutMs});if(ran.code===0&&!ran.timedOut)return;let last=LAST_LINE.exec(ran.text)?.[0];return`${ran.timedOut?"timed out":`exited ${ran.code}`}${last===void 0?"":` (${truncate(last,WIDTH)})`}`}catch(error){return`could not run: ${error instanceof Error?error.message:String(error)}`}}async function waitTask(args){let{values,positionals:[task]}=parse(args,TASK_USAGE,TASK_OPTIONS,{positionals:["<task>"],exits:TASK_EXITS}),path=taskFile(task);if(path===void 0)fail(`no background task ${task}: give the id a background Bash call returned, or the path of its .output file`);if(!existsSync3(path))fail(`no output file ${path}: ${task} is no background task of this machine`);if(isTranscript(path))fail(`${task} is a subagent, whose end its notification reports: waitfor task waits on a background Bash task`);let lines=wholeNumber(values.lines,"lines",20),timeout=duration(values.timeout,"timeout",300000),started=Date.now(),{dim}=paint(process2.stderr),region=values.quiet===!0?void 0:liveRegion((spinner)=>[`${spinner} task ${task}: still running ${dim(formatElapsed(Date.now()-started))}`]),code;try{for(;;){if(code=await exitCode(path),code!==void 0||Date.now()-started>=timeout)break;await Bun.sleep(POLL)}}finally{region?.stop()}let{failures,tail}=await taskEnd(path,lines),last=tail.length===0?"":`
14
14
  last lines of ${path}:
15
15
  ${numbered(tail)}`;if(code===void 0)fail(`gave up after ${formatDuration(timeout)}: task ${task} is still running${last}`,TIMEOUT_EXIT);if(values.json===!0)return printJson({task,path,code,ms:Date.now()-started,failures,tail}),code===0?0:1;let failed=failures.length===0?"":`
16
16
  (fail) and error: lines above them:
17
- ${numbered(failures)}`;return console.log(`task ${task} exited with code ${code}, waited ${formatDuration(Date.now()-started)}${failed}${last}`),code===0?0:1}async function main(args){if(args[0]==="task")return waitTask(args.slice(1));let parsed=parse(args,USAGE,OPTIONS,{exits:EXITS,replaces:"sleep loops, tail -f and until ! pgrep -f",examples:[['waitfor --file dev.log --from-end --until "ready in" --fail error',"a dev server up from new log lines, or its first error"],["waitfor --port 5432 --while-pid 1234 -t 2m","Postgres accepting connections while its launcher is alive"]]}),{values,positionals}=parsed;if(positionals.length>0)fail(`unexpected argument ${positionals[0]}
17
+ ${numbered(failures)}`;return console.log(`task ${task} exited with code ${code}, waited ${formatDuration(Date.now()-started)}${failed}${last}`),code===0?0:1}function hostPort(host,port){return`${host.includes(":")?`[${host}]`:host}:${port}`}async function main(args){if(args[0]==="task")return waitTask(args.slice(1));let parsed=parse(args,USAGE,OPTIONS,{exits:EXITS,replaces:"sleep loops, tail -f and until ! pgrep -f",examples:[['waitfor --file dev.log --from-end --until "ready in" --fail error',"a dev server up from new log lines, or its first error"],["waitfor --port 5432 --while-pid 1234 -t 2m","Postgres accepting connections while its launcher is alive"],["waitfor --port-free 8000","old server has released port 8000"],["waitfor --file out.bin --idle 2s","file finished writing and stayed unchanged for 2s"]]}),{values,positionals}=parsed;if(positionals.length>0)fail(`unexpected argument ${positionals[0]}
18
18
 
19
- ${USAGE}`);let portTexts=values.port??[],urlTexts=values.url??[],healthyTexts=values.healthy??[];if(values.until===void 0&&portTexts.length===0&&urlTexts.length===0&&healthyTexts.length===0&&values.pid===void 0&&values.cmd===void 0)fail(`give --until with --file, --port, --url, --healthy, --pid or --cmd
19
+ ${USAGE}`);let portTexts=values.port??[],portFreeTexts=values["port-free"]??[],urlTexts=values.url??[],healthyTexts=values.healthy??[];if(values.until===void 0&&values.idle===void 0&&portTexts.length===0&&portFreeTexts.length===0&&urlTexts.length===0&&healthyTexts.length===0&&values.pid===void 0&&values.cmd===void 0)fail(`give --until or --idle with --file, --port, --port-free, --url, --healthy, --pid or --cmd
20
20
 
21
- ${USAGE}`);if((values.until!==void 0||values.fail!==void 0)!==(values.file!==void 0))fail("--until and --fail read the --file lines, and --file needs one of them");if(values["from-end"]===!0&&values.file===void 0)fail("--from-end goes with --file");if(values.host!==void 0&&portTexts.length===0)fail("--host goes with --port");if((values.status!==void 0||values.body!==void 0||(values.header?.length??0)>0||values.insecure===!0)&&urlTexts.length===0)fail("--status, --body, --header and --insecure go with --url");let conditions=[values.until,...portTexts,...urlTexts,...healthyTexts,values.pid,values.cmd].filter((condition)=>condition!==void 0).length;if(values.any===!0&&conditions<2)fail("--any needs two or more of --until, --port, --url, --healthy, --pid and --cmd");if(values.interval!==void 0&&values.cmd===void 0)fail("--interval goes with --cmd");let ports=portTexts.map((text)=>{let port=wholeNumber(text,"port",0);if(port>65535)fail(`--port takes a port up to 65535, not ${port}`);return{name:String(port),port,left:"not checked yet"}});for(let url of urlTexts)if(!URL.canParse(url))fail(`--url ${url} is no URL`);let headers={};for(let entry of values.header??[]){if(!HEADER_LINE.test(entry))fail(`-H takes "Name: value", not ${entry}`);let at=entry.indexOf(":");headers[entry.slice(0,at).trim()]=entry.slice(at+1).trim()}let statusTest=values.status===void 0?void 0:parseStatus(values.status);if(values.status!==void 0&&statusTest===void 0)fail(`--status takes a code, a range or a class such as 301, 200-299 or 2xx, not ${values.status}`);let expect={...values.status!==void 0&&statusTest!==void 0?{status:{test:statusTest,spec:values.status}}:{},...Object.keys(headers).length===0?{}:{headers},...values.insecure===!0?{insecure:!0}:{}},body=regex(values.body,"body");if(body!==void 0)expect.body=body;let urls=urlTexts.map((url)=>({name:url,left:"not checked yet"})),services=healthyTexts.map((service)=>({name:service,left:"not checked yet"})),metAt=[],pid=values.pid===void 0?void 0:wholeNumber(values.pid,"pid",0),whilePid=values["while-pid"]===void 0?void 0:wholeNumber(values["while-pid"],"while-pid",0),hosts=values.host===void 0?["127.0.0.1","::1"]:[values.host],interval=duration(values.interval,"interval",1000),isAny=values.any===!0,timeout=duration(values.timeout,"timeout",300000),watch=values.file===void 0?void 0:new FileWatch(values.file,regex(values.until,"until"),regex(values.fail,"fail"),values["from-end"]===!0),started=Date.now(),json=values.json===!0,say=json?writeErr:console.log,matched,isPidLeft=pid!==void 0,cmdLeft=values.cmd===void 0?void 0:"not run yet",cmdRanAt=0,{dim}=paint(process2.stderr),region=values.quiet===!0?void 0:liveRegion((spinner)=>{let waited=dim(formatElapsed(Date.now()-started));return[watch===void 0||watch.done?void 0:`${watch.path}: ${watch.exists?"no --until line yet":"does not exist yet"}`,...ports.filter((probe)=>probe.left!==void 0).map((probe)=>`${hosts[0]}:${probe.port}: ${probe.left}`),...urls.filter((probe)=>probe.left!==void 0).map((probe)=>`${probe.name}: ${probe.left}`),...services.filter((probe)=>probe.left!==void 0).map((probe)=>`service ${probe.name}: ${probe.left}`),isPidLeft?`pid ${pid}: still running`:void 0,cmdLeft===void 0?void 0:`\`${values.cmd}\`: ${cmdLeft}`].filter((line)=>line!==void 0).map((line)=>`${spinner} ${line} ${waited}`)});try{for(;;){if(whilePid!==void 0&&!pidAlive(whilePid)){if(problem(`waitfor: --while-pid ${whilePid} exited after ${formatDuration(Date.now()-started)} before conditions were met`),json)printJson({met:!1,ms:Date.now()-started,reason:`pid ${whilePid} exited`,line:null,conditions:metAt});return 1}let[fileEvents]=await Promise.all([watch===void 0?Promise.resolve([]):watch.poll(),Promise.all(ports.filter((probe)=>probe.left!==void 0).map(async(probe)=>{for(let candidate of hosts){let prob=await portProblem(candidate,probe.port??0);if(candidate===hosts[0])probe.left=prob;if(prob===void 0){let name=`${candidate.includes(":")?`[${candidate}]`:candidate}:${probe.port}`;probe.left=void 0,probe.name=name,metAt.push({name,ms:Date.now()-started}),say(`${name} listening after ${formatDuration(Date.now()-started)}`);return}}})),Promise.all(urls.filter((probe)=>probe.left!==void 0).map(async(probe)=>{let budget=Math.max(1,Math.min(URL_TIMEOUT,started+timeout-Date.now())),check=await urlCheck(probe.name,budget,expect);if(!(("problem"in check)&&check.isTimeout===!0&&budget<URL_TIMEOUT&&probe.left!=="not checked yet"))probe.left="problem"in check?check.problem:void 0;if("status"in check)metAt.push({name:probe.name,ms:Date.now()-started}),say(`${probe.name} answered ${check.status} after ${formatDuration(Date.now()-started)}`)})),Promise.all(services.filter((probe)=>probe.left!==void 0).map(async(probe)=>{let prob=await healthyProblem(probe.name);if(probe.left=prob,prob===void 0)metAt.push({name:`healthy:${probe.name}`,ms:Date.now()-started}),say(`${probe.name} healthy after ${formatDuration(Date.now()-started)}`)})),(async()=>{if(values.cmd!==void 0&&cmdLeft!==void 0&&Date.now()-cmdRanAt>=interval){let budget=Math.max(1,Math.min(CMD_RUN_LIMIT,started+timeout-Date.now())),prob=await cmdProblem(values.cmd,budget);if(!(prob?.startsWith("timed out")===!0&&budget<CMD_RUN_LIMIT&&cmdLeft!=="not run yet"))cmdLeft=prob;if(cmdRanAt=Date.now(),cmdLeft===void 0)metAt.push({name:`\`${values.cmd}\``,ms:Date.now()-started}),say(`\`${values.cmd}\` exited 0 after ${formatDuration(Date.now()-started)}`)}})()]);for(let event of fileEvents){if(event.kind==="until"){say(`${watch.path}:${event.line.number}: ${truncate(event.line.text,WIDTH)}`),matched={number:event.line.number,text:event.line.text},metAt.push({name:`${watch.path} --until`,ms:Date.now()-started});continue}if(problem(`waitfor: ${watch.path}:${event.line.number} matched --fail after ${formatDuration(Date.now()-started)}
22
- ${numbered(event.excerpt,event.line)}`),json)printJson({met:!1,ms:Date.now()-started,line:{number:event.line.number,text:event.line.text}});return 1}if(pid!==void 0&&isPidLeft){if(isPidLeft=pidAlive(pid),!isPidLeft)metAt.push({name:`pid ${pid}`,ms:Date.now()-started}),say(`pid ${pid} exited after ${formatDuration(Date.now()-started)}`)}let isMet=[values.until!==void 0&&(watch?.done??!1),ports.some((probe)=>probe.left===void 0),urls.some((probe)=>probe.left===void 0),services.some((probe)=>probe.left===void 0),pid!==void 0&&!isPidLeft,values.cmd!==void 0&&cmdLeft===void 0],isAllMet=(watch?.done??!0)&&ports.every((probe)=>probe.left===void 0)&&urls.every((probe)=>probe.left===void 0)&&services.every((probe)=>probe.left===void 0)&&!isPidLeft&&cmdLeft===void 0;if((isAny?isMet.includes(!0):isAllMet)&&!(watch?.failsFirst??!1)){if(json)printJson({met:!0,ms:Date.now()-started,line:matched??null,conditions:metAt});return 0}if(Date.now()-started>=timeout&&!(watch?.failing??!1))break;await Bun.sleep(POLL)}}finally{region?.stop()}let missing=[];if(watch!==void 0&&!watch.done)missing.push(watch.exists?`no line of ${watch.path} matched --until`:`${watch.path} does not exist`);for(let probe of ports)if(probe.left!==void 0)missing.push(`${hosts[0]}:${probe.port} is not listening (${probe.left})`);for(let probe of urls)if(probe.left!==void 0)missing.push(`${probe.name} ${probe.left}`);for(let probe of services)if(probe.left!==void 0)missing.push(`service ${probe.name} is not healthy (${probe.left})`);if(isPidLeft)missing.push(`pid ${pid} is still running`);if(cmdLeft!==void 0)missing.push(`\`${values.cmd}\` ${cmdLeft}`);let lines=watch?.excerpt()??[];fail(`gave up after ${formatDuration(timeout)}${isAny?", none met":""}: ${missing.join(", ")}${lines.length===0?"":`
21
+ ${USAGE}`);if((values.until!==void 0||values.fail!==void 0||values.idle!==void 0)!==(values.file!==void 0))fail("--until, --fail and --idle work with --file, and --file needs one of them");if(values["from-end"]===!0&&values.file===void 0)fail("--from-end goes with --file");if(values.host!==void 0&&portTexts.length===0&&portFreeTexts.length===0)fail("--host goes with --port or --port-free");if((values.status!==void 0||values.body!==void 0||(values.header?.length??0)>0||values.insecure===!0)&&urlTexts.length===0)fail("--status, --body, --header and --insecure go with --url");let conditions=[values.until,values.idle,...portTexts,...portFreeTexts,...urlTexts,...healthyTexts,values.pid,values.cmd].filter((condition)=>condition!==void 0).length;if(values.any===!0&&conditions<2)fail("--any needs two or more of --until, --idle, --port, --port-free, --url, --healthy, --pid and --cmd");if(values.interval!==void 0&&values.cmd===void 0)fail("--interval goes with --cmd");let hosts=values.host===void 0?["127.0.0.1","::1"]:[values.host],ports=portTexts.map((text)=>{let port=wholeNumber(text,"port",0);if(port>65535)fail(`--port takes a port up to 65535, not ${port}`);return{name:String(port),port,left:"not checked yet"}}),freePorts=portFreeTexts.map((text)=>{let port=wholeNumber(text,"port-free",0);if(port>65535)fail(`--port-free takes a port up to 65535, not ${port}`);return{name:hostPort(hosts[0],port),port,left:"not checked yet"}});for(let url of urlTexts)if(!URL.canParse(url))fail(`--url ${url} is no URL`);let headers={};for(let entry of values.header??[]){if(!HEADER_LINE.test(entry))fail(`-H takes "Name: value", not ${entry}`);let at=entry.indexOf(":");headers[entry.slice(0,at).trim()]=entry.slice(at+1).trim()}let statusTest=values.status===void 0?void 0:parseStatus(values.status);if(values.status!==void 0&&statusTest===void 0)fail(`--status takes a code, a range or a class such as 301, 200-299 or 2xx, not ${values.status}`);let expect={...values.status!==void 0&&statusTest!==void 0?{status:{test:statusTest,spec:values.status}}:{},...Object.keys(headers).length===0?{}:{headers},...values.insecure===!0?{insecure:!0}:{}},body=regex(values.body,"body");if(body!==void 0)expect.body=body;let urls=urlTexts.map((url)=>({name:url,left:"not checked yet"})),services=healthyTexts.map((service)=>({name:service,left:"not checked yet"})),metAt=[],pid=values.pid===void 0?void 0:wholeNumber(values.pid,"pid",0),whilePid=values["while-pid"]===void 0?void 0:wholeNumber(values["while-pid"],"while-pid",0),idleMs=values.idle===void 0?void 0:duration(values.idle,"idle",0),interval=duration(values.interval,"interval",1000),isAny=values.any===!0,timeout=duration(values.timeout,"timeout",300000),watch=values.file!==void 0&&(values.until!==void 0||values.fail!==void 0)?new FileWatch(values.file,regex(values.until,"until"),regex(values.fail,"fail"),values["from-end"]===!0):void 0,idle=values.file!==void 0&&idleMs!==void 0?new IdleWatch(values.file,idleMs):void 0,started=Date.now(),json=values.json===!0,say=json?writeErr:console.log,matched,isPidLeft=pid!==void 0,cmdLeft=values.cmd===void 0?void 0:"not run yet",cmdRanAt=0,{dim}=paint(process2.stderr),region=values.quiet===!0?void 0:liveRegion((spinner)=>{let waited=dim(formatElapsed(Date.now()-started));return[watch===void 0||watch.done?void 0:`${watch.path}: ${watch.exists?"no --until line yet":"does not exist yet"}`,idle===void 0||idle.done?void 0:`${idle.path}: ${idle.exists?`idle ${formatDuration(idle.stableFor)} / ${formatDuration(idle.durationMs)}`:"does not exist yet"}`,...ports.filter((probe)=>probe.left!==void 0).map((probe)=>`${hostPort(hosts[0],probe.port??0)}: ${probe.left}`),...freePorts.filter((probe)=>probe.left!==void 0).map((probe)=>`${probe.name}: ${probe.left}`),...urls.filter((probe)=>probe.left!==void 0).map((probe)=>`${probe.name}: ${probe.left}`),...services.filter((probe)=>probe.left!==void 0).map((probe)=>`service ${probe.name}: ${probe.left}`),isPidLeft?`pid ${pid}: still running`:void 0,cmdLeft===void 0?void 0:`\`${values.cmd}\`: ${cmdLeft}`].filter((line)=>line!==void 0).map((line)=>`${spinner} ${line} ${waited}`)});try{for(;;){if(whilePid!==void 0&&!pidAlive(whilePid)){if(problem(`waitfor: --while-pid ${whilePid} exited after ${formatDuration(Date.now()-started)} before conditions were met`),json)printJson({met:!1,ms:Date.now()-started,reason:`pid ${whilePid} exited`,line:null,conditions:metAt});return 1}let[fileEvents]=await Promise.all([watch===void 0?Promise.resolve([]):watch.poll(),Promise.all(ports.filter((probe)=>probe.left!==void 0).map(async(probe)=>{for(let candidate of hosts){let prob=await portProblem(candidate,probe.port??0);if(candidate===hosts[0])probe.left=prob;if(prob===void 0){let name=hostPort(candidate,probe.port??0);probe.left=void 0,probe.name=name,metAt.push({name,ms:Date.now()-started}),say(`${name} listening after ${formatDuration(Date.now()-started)}`);return}}})),Promise.all(freePorts.filter((probe)=>probe.left!==void 0).map(async(probe)=>{let busy=await portFreeHost(hosts,probe.port??0);if(busy!==void 0){probe.name=hostPort(busy,probe.port??0),probe.left="still listening";return}let name=hostPort(hosts[0],probe.port??0);probe.left=void 0,probe.name=name,metAt.push({name:`port-free:${name}`,ms:Date.now()-started}),say(`${name} free after ${formatDuration(Date.now()-started)}`)})),Promise.all(urls.filter((probe)=>probe.left!==void 0).map(async(probe)=>{let budget=Math.max(1,Math.min(URL_TIMEOUT,started+timeout-Date.now())),check=await urlCheck(probe.name,budget,expect);if(!(("problem"in check)&&check.isTimeout===!0&&budget<URL_TIMEOUT&&probe.left!=="not checked yet"))probe.left="problem"in check?check.problem:void 0;if("status"in check)metAt.push({name:probe.name,ms:Date.now()-started}),say(`${probe.name} answered ${check.status} after ${formatDuration(Date.now()-started)}`)})),Promise.all(services.filter((probe)=>probe.left!==void 0).map(async(probe)=>{let prob=await healthyProblem(probe.name);if(probe.left=prob,prob===void 0)metAt.push({name:`healthy:${probe.name}`,ms:Date.now()-started}),say(`${probe.name} healthy after ${formatDuration(Date.now()-started)}`)})),(async()=>{if(values.cmd!==void 0&&cmdLeft!==void 0&&Date.now()-cmdRanAt>=interval){let budget=Math.max(1,Math.min(CMD_RUN_LIMIT,started+timeout-Date.now())),prob=await cmdProblem(values.cmd,budget);if(!(prob?.startsWith("timed out")===!0&&budget<CMD_RUN_LIMIT&&cmdLeft!=="not run yet"))cmdLeft=prob;if(cmdRanAt=Date.now(),cmdLeft===void 0)metAt.push({name:`\`${values.cmd}\``,ms:Date.now()-started}),say(`\`${values.cmd}\` exited 0 after ${formatDuration(Date.now()-started)}`)}})()]);for(let event of fileEvents){if(event.kind==="until"){say(`${watch.path}:${event.line.number}: ${truncate(event.line.text,WIDTH)}`),matched={number:event.line.number,text:event.line.text},metAt.push({name:`${watch.path} --until`,ms:Date.now()-started});continue}if(problem(`waitfor: ${watch.path}:${event.line.number} matched --fail after ${formatDuration(Date.now()-started)}
22
+ ${numbered(event.excerpt,event.line)}`),json)printJson({met:!1,ms:Date.now()-started,line:{number:event.line.number,text:event.line.text}});return 1}if(idle!==void 0&&!idle.done&&idle.poll())metAt.push({name:`${idle.path} --idle`,ms:Date.now()-started}),say(`${idle.path} idle for ${formatDuration(idle.durationMs)} after ${formatDuration(Date.now()-started)}`);if(pid!==void 0&&isPidLeft){if(isPidLeft=pidAlive(pid),!isPidLeft)metAt.push({name:`pid ${pid}`,ms:Date.now()-started}),say(`pid ${pid} exited after ${formatDuration(Date.now()-started)}`)}let isMet=[values.until!==void 0&&(watch?.done??!1),idle!==void 0&&idle.done,ports.some((probe)=>probe.left===void 0),freePorts.some((probe)=>probe.left===void 0),urls.some((probe)=>probe.left===void 0),services.some((probe)=>probe.left===void 0),pid!==void 0&&!isPidLeft,values.cmd!==void 0&&cmdLeft===void 0],isAllMet=(watch?.done??!0)&&(idle?.done??!0)&&ports.every((probe)=>probe.left===void 0)&&freePorts.every((probe)=>probe.left===void 0)&&urls.every((probe)=>probe.left===void 0)&&services.every((probe)=>probe.left===void 0)&&!isPidLeft&&cmdLeft===void 0;if((isAny?isMet.includes(!0):isAllMet)&&!(watch?.failsFirst??!1)){if(json)printJson({met:!0,ms:Date.now()-started,line:matched??null,conditions:metAt});return 0}if(Date.now()-started>=timeout&&!(watch?.failing??!1))break;await Bun.sleep(POLL)}}finally{region?.stop()}let missing=[];if(watch!==void 0&&!watch.done)missing.push(watch.exists?`no line of ${watch.path} matched --until`:`${watch.path} does not exist`);if(idle!==void 0&&!idle.done)if(!idle.exists){if(watch===void 0||watch.done||watch.exists)missing.push(`${idle.path} does not exist`)}else missing.push(`${idle.path} has not been idle for ${formatDuration(idle.durationMs)} (stable ${formatDuration(idle.stableFor)})`);for(let probe of ports)if(probe.left!==void 0)missing.push(`${hostPort(hosts[0],probe.port??0)} is not listening (${probe.left})`);for(let probe of freePorts)if(probe.left!==void 0)missing.push(probe.left==="still listening"?`${probe.name} is still listening`:`${probe.name} is not free (${probe.left})`);for(let probe of urls)if(probe.left!==void 0)missing.push(`${probe.name} ${probe.left}`);for(let probe of services)if(probe.left!==void 0)missing.push(`service ${probe.name} is not healthy (${probe.left})`);if(isPidLeft)missing.push(`pid ${pid} is still running`);if(cmdLeft!==void 0)missing.push(`\`${values.cmd}\` ${cmdLeft}`);let lines=watch?.excerpt()??[];fail(`gave up after ${formatDuration(timeout)}${isAny?", none met":""}: ${missing.join(", ")}${lines.length===0?"":`
23
23
  last lines of ${watch?.path}:
24
24
  ${numbered(lines)}`}`,TIMEOUT_EXIT)}process2.exitCode=await runMain({name:"waitfor",run:main});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-wait",
3
3
  "type": "module",
4
- "version": "0.13.1",
4
+ "version": "0.14.0",
5
5
  "description": "waitfor and slot: waits for a log line, a listening port or a URL answering, and queues heavy commands behind machine-wide slots and named locks, for Claude Code, instead of sleep and polling loops.",
6
6
  "author": "Kaynooo <contact@kaynooo.fr>",
7
7
  "license": "MIT",
@@ -35,6 +35,6 @@
35
35
  "waitfor": "$npm_execpath src/cli.ts"
36
36
  },
37
37
  "devDependencies": {
38
- "@kaynooo/cli-kit": "0.52.0"
38
+ "@kaynooo/cli-kit": "0.52.1"
39
39
  }
40
40
  }