Repository navigation
feat(cli): add version, update, status, stop and open commands (#1139) - #1154
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A run record outlives a crash or reboot, and its pid may then belong to an unrelated process: stop would SIGTERM it. A record now counts as running only while its URL answers over HTTP (any status); a live pid that does not answer is skipped, and its record kept until the pid dies. On Windows process.kill() ended the launcher alone and left Next.js serving the port, so stop ends the launcher's process tree with taskkill there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…in the agent dir - A recycled pid passed the old check whenever something answered on the record's port, so stop could SIGTERM an unrelated process. A record now counts only while its pid still is pi-web: the launcher's command line names pi-web, the server's is "next-server (vX)" (/proc on Linux, ps elsewhere, the node image name on Windows). When nothing can tell, the URL check decides as before. - A launcher killed with SIGKILL left Next.js serving the port while status said nothing ran. The record keeps nextPid; status lists such a server as "launcher gone", stop signals it directly and update refuses. - Records were keyed by port, so a second server on the same port with another hostname overwrote the first's. They are keyed by launcher pid now. - Records move from ~/.pi-web/run to <agentDir>/pi-web-run (default ~/.pi/agent/pi-web-run), where pi-web keeps its other state; pi-web wrote nothing under ~/.pi-web before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1139 (the subset we want; the other proposed commands are out of scope).
Commands
Bare
pi-web [options]is unchanged. A command is recognized only as the first argument.How it works
<agentDir>/pi-web-run/<launcher pid>.json({ pid, nextPid, port, hostname, url, version, startedAt }) atomically, and removes it when it exits. The agent dir is resolved as pi resolves it (PI_CODING_AGENT_DIR, else~/.pi/agent), next to pi-web's other state files; pi-web writes nothing under~/.pi-web. A failed write only warns. Port 0 gets no record. Keying by pid means two servers on one port with different hostnames keep a record each.pi-web, the Next.js server's readsnext-server (vX)(/procon Linux,pselsewhere; on Windows only the image name,node.exe). When neither tool is available, the URL check alone decides. A record none of whose processes is ours, or with unreadable JSON, is deleted.nextPidkeeps such a server visible:statuslists it as "launcher gone",stopsignals it directly,updaterefuses.stopsends SIGTERM to the launcher, which forwards it to Next.js. On Windows it runstaskkill /T /Fon the launcher's tree, becauseprocess.kill()there would end only the launcher and leave Next.js on the port. It waits up to 10 s for the server to exit. With several servers running and no--port,stopandopenlist them and exit 1.latestfrom the npm registry (the URL/api/app-updatealready uses) and compares stable versions (ported fromlib/app-update.ts).--checkonly reports.next startkeeps.next/open, and on Windows the loadednode-ptybinary is locked) and says to runpi-web stopfirst.<npm root -g>/@agegr/pi-webmust match the package dir. From the npx cache it says to runnpx @agegr/pi-web@latest; for any other layout (pnpm, bun, a checkout) it prints the manual command.npm-cli.jswith no shell, aslib/node-cli.tsdoes.bin/browser-opener.js.bin/pi-web.jswraps the start path instartServer(), so read that diff with-w.Checked
lib/pi-web-cli-commands.test.mjspluslib/pi-web-options.test.mjs: 33 pass. Fullnpm test(2868),tsc --noEmitand eslint pass.next startservers in a temp HOME and agent dir (macOS):-v,status,update --checkwork; records land in<agentDir>/pi-web-run/.stopwithout--portlists both and exits 1;stop --portends one and frees the port; Ctrl+C removes the record.sleep, while another server answers on its port: not listed,stopexits 1, thesleepsurvives.kill -9of a launcher:statusshows its Next.js as "launcher gone",updaterefuses,stopends it and frees the port.updatewith a lower installed version refuses while a server runs, and from a checkout prints the manual command.npm install -gupdate, and Windows.npm root -goutput, so a global root path containing a UUID is reported as "not a global npm install" (the manual command is printed).🤖 Generated with Claude Code