@proagentstore/cli 0.1.19 → 0.1.20

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.
@@ -57,3 +57,12 @@ const shutdown = async () => {
57
57
  };
58
58
  process.on("SIGINT", () => void shutdown());
59
59
  process.on("SIGTERM", () => void shutdown());
60
+ // Self-exit if our parent (the `runner connect` CLI) dies — otherwise we'd orphan
61
+ // and keep holding the port, making the NEXT `pags up` fail with EADDRINUSE / a 401
62
+ // against our stale token. When the parent dies we're reparented (ppid changes to
63
+ // launchd/init), so a changed ppid means it's gone.
64
+ const parentPid = process.ppid;
65
+ setInterval(() => {
66
+ if (process.ppid !== parentPid)
67
+ void shutdown();
68
+ }, 3000).unref();
package/dist/index.js CHANGED
@@ -618,8 +618,21 @@ import { chmod, mkdir, writeFile } from "fs/promises";
618
618
  import { gunzipSync } from "zlib";
619
619
  import { arch, homedir as homedir2, platform } from "os";
620
620
  import { resolve as resolve4 } from "path";
621
+ import { createServer as createServer2 } from "net";
621
622
  import { fileURLToPath as fileURLToPath2 } from "url";
622
623
  import { Command as Command6 } from "commander";
624
+ async function findFreePort2(start) {
625
+ for (let p = start; p < start + 25; p++) {
626
+ const free = await new Promise((res) => {
627
+ const s = createServer2();
628
+ s.once("error", () => res(false));
629
+ s.once("listening", () => s.close(() => res(true)));
630
+ s.listen(p, "127.0.0.1");
631
+ });
632
+ if (free) return p;
633
+ }
634
+ return start;
635
+ }
623
636
  var runnerCommand = createRunnerCommand();
624
637
  function runnerBaseUrl(url) {
625
638
  return (clean(url) || clean(process.env.PAGS_RUNNER_URL) || "http://127.0.0.1:49171").replace(/\/$/, "");
@@ -898,7 +911,7 @@ function createRunnerCommand() {
898
911
  command.command("connect <instanceId>").description("Start the local FAGS runtime, open a Cloudflare quick tunnel, and register it with PAGS").option("--host <host>", "Host to bind", "127.0.0.1").option("--port <port>", "Port to bind", "49171").option("--data-dir <path>", "Runner data directory").option("--token <token>", "Runner bearer token. Defaults to PAGS_RUNNER_TOKEN or a generated token").option("--headless", "Run Playwright headless").option("--api-base <url>", "PAGS API base URL").option("--pags-token <token>", "PAGS session token. Defaults to PAGS_TOKEN").option("--cloudflared <path>", "cloudflared executable").option("--runner-version <version>", "Runner version").option("--skip-probe", "Skip PAGS FAGS-runtime probe after registration").action(async (instanceId, opts) => {
899
912
  const runnerToken = clean(opts.token) || clean(process.env.PAGS_RUNNER_TOKEN) || `pags_runner_${randomUUID()}`;
900
913
  const host = clean(opts.host) || "127.0.0.1";
901
- const port = clean(opts.port) || "49171";
914
+ const port = clean(opts.port) || String(await findFreePort2(49171));
902
915
  const localUrl = `http://${host}:${port}`;
903
916
  const runnerOpts = {
904
917
  ...opts,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proagentstore/cli",
3
- "version": "0.1.19",
3
+ "version": "0.1.20",
4
4
  "description": "CLI for creating, publishing, and running ProAgentStore agents",
5
5
  "license": "MIT",
6
6
  "type": "module",