@kaynooo/cli-proc 0.7.5 → 0.8.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
@@ -1,6 +1,6 @@
1
1
  # proc
2
2
 
3
- Three process and port helpers for Linux (also reachable as `proc pid|ports|procs`), reading `/proc` directly instead of shelling out to `ps`, `ss` or `lsof`: `pid` inspects one process, `ports` tells who listens on what, `procs` finds leftover or heavy dev processes.
3
+ Three process and port helpers for Linux, reading `/proc` directly instead of shelling out to `ps`, `ss` or `lsof`: `proc pid` inspects one process, `proc ports` tells who listens on what, `proc procs` finds leftover or heavy dev processes.
4
4
 
5
5
  ```sh
6
6
  bun install -g @kaynooo/cli-proc
@@ -10,23 +10,23 @@ bun install -g @kaynooo/cli-proc
10
10
 
11
11
  | Command | What it does |
12
12
  | --- | --- |
13
- | `pid <pid>` | executable, working directory, command line, parent chain up to init, user, start time and age, memory, open files and limits, the TCP and UDP ports it listens on, cgroup; `--env` adds the environment with secrets masked, `--json` everything |
14
- | `ports [port]` | the listening sockets (TCP and UDP, IPv4 and IPv6) with port, protocol, bound address, pid, command and working directory; a port Docker publishes shows its compose project and service |
15
- | `ports <port> --kill` | stops the owner: SIGTERM, and with `--force` SIGKILL after `--grace` (5s); asks on a terminal unless `--yes` |
16
- | `procs` | leftover or heavy dev processes grouped by origin, with count, total RSS and oldest age |
17
- | `procs --kill` | a dry run naming what would be stopped; `--yes` sends SIGTERM, then SIGKILL after `--grace` |
13
+ | `proc pid <pid>` | executable, working directory, command line, parent chain up to init, user, start time and age, memory, open files and limits, the TCP and UDP ports it listens on, cgroup; `--env` adds the environment with secrets masked, `--json` everything |
14
+ | `proc ports [port]` | the listening sockets (TCP and UDP, IPv4 and IPv6) with port, protocol, bound address, pid, command and working directory; a port Docker publishes shows its compose project and service |
15
+ | `proc ports <port> --kill` | stops the owner: SIGTERM, and with `--force` SIGKILL after `--grace` (5s); asks on a terminal unless `--yes` |
16
+ | `proc procs` | leftover or heavy dev processes grouped by origin, with count, total RSS and oldest age |
17
+ | `proc procs --kill` | a dry run naming what would be stopped; `--yes` sends SIGTERM, then SIGKILL after `--grace` |
18
18
 
19
- ## pid
19
+ ## proc pid
20
20
 
21
21
  A missing pid exits 1. What the calling user cannot read of another user's process (executable, working directory, open files, limits, environment) is left out and named at the end. The environment is off unless `--env` is given: a name that looks like a secret (kit's rule, shared with `ev` and `redact`) has its whole value masked, and a URL password, a well known token format, a private key or a long opaque token is masked inside any value; the command line is masked the same way.
22
22
 
23
- ## ports
23
+ ## proc ports
24
24
 
25
25
  Sockets come from `/proc/net/{tcp,tcp6,udp,udp6}` and are mapped to their owner through the inode in `/proc/<pid>/fd`, so only the calling user's processes show an owner; the others show `-`. A socket without a readable owner, or held by `docker-proxy`, takes the container publishing its port when `docker ps` answers (skipped quietly when docker is missing or its daemon unreachable).
26
26
 
27
- `ports <port>` exits 1 when nothing listens there. `--kill` refuses a process of another user, pid 1, this command and its ancestors, and a container's port, for which it prints the `docker stop <container>` to run instead.
27
+ `proc ports <port>` exits 1 when nothing listens there. `--kill` refuses a process of another user, pid 1, this command and its ancestors, and a container's port, for which it prints the `docker stop <container>` to run instead.
28
28
 
29
- ## procs
29
+ ## proc procs
30
30
 
31
31
  A process is listed when it is a dev tool (bun, node, vite, nuxt, next, chromium and chrome, playwright and WebKit browsers and their helpers, language servers, test runners) of the calling user and either:
32
32
 
package/dist/proc-cli.js CHANGED
@@ -1332,30 +1332,6 @@ function commandPath(scope, argv) {
1332
1332
  }
1333
1333
  return path.length === 0 ? undefined : path.join(" ");
1334
1334
  }
1335
- async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
1336
- if (argv[0] === COMPLETE)
1337
- return printCandidates(leafCandidates(run, argv.slice(1)));
1338
- if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
1339
- return printCompletionScript(name, flagValue(argv));
1340
- if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
1341
- console.log(version ?? packageVersion());
1342
- return 0;
1343
- }
1344
- let code;
1345
- const started = performance.now();
1346
- try {
1347
- code = await run(argv);
1348
- } catch (error) {
1349
- code = reportThrown(name, error, redact, wantsJson(argv));
1350
- }
1351
- notifyEnd(name, code, performance.now() - started);
1352
- if (usage !== false) {
1353
- try {
1354
- recordUsage(usageEntry(name, undefined, argv, code));
1355
- } catch {}
1356
- }
1357
- return code;
1358
- }
1359
1335
  // ../kit/src/folders.ts
1360
1336
  var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
1361
1337
  // ../kit/src/secrets.ts
@@ -1758,7 +1734,7 @@ async function userName(uid) {
1758
1734
  }
1759
1735
 
1760
1736
  // src/pid.ts
1761
- var usage2 = `pid <pid>
1737
+ var usage2 = `proc pid <pid>
1762
1738
 
1763
1739
  Shows what a process is: its executable, working directory, command line, parent chain up to init, user, start time and age, memory, open files and limits, the TCP and UDP ports it listens on and its cgroup. Everything is read from /proc; what the calling user cannot read of another user's process is left out and named at the end.
1764
1740
  The environment is not shown unless --env is given, with every value that looks like a secret masked.`;
@@ -1868,9 +1844,9 @@ async function pid(args) {
1868
1844
  positionals: ["<pid>"],
1869
1845
  replaces: "cat /proc/<pid>/{cmdline,environ,limits}, readlink /proc/<pid>/{exe,cwd}, the fish pid function",
1870
1846
  examples: [
1871
- ["pid 4242", "executable, directory, command, parents, memory, limits and ports"],
1872
- ["pid 4242 --env", "with the environment, secrets masked"],
1873
- "pid 4242 --json"
1847
+ ["proc pid 4242", "executable, directory, command, parents, memory, limits and ports"],
1848
+ ["proc pid 4242 --env", "with the environment, secrets masked"],
1849
+ "proc pid 4242 --json"
1874
1850
  ]
1875
1851
  });
1876
1852
  const [given] = positionals;
@@ -2172,11 +2148,11 @@ async function terminate(pids, { escalate, graceMs, signaller = realSignaller })
2172
2148
  }
2173
2149
 
2174
2150
  // src/ports.ts
2175
- var usage3 = `ports [port]
2151
+ var usage3 = `proc ports [port]
2176
2152
 
2177
2153
  Lists what listens on this machine, TCP and UDP over IPv4 and IPv6, one row per port with its bound address, the owning process, its command and its working directory. A port Docker publishes is held by docker-proxy, and shows as its compose project and service when docker is installed; the owner of a socket of another user cannot be read and shows as -.
2178
- \`ports <port>\` keeps that port alone and exits 1 when nothing listens on it.
2179
- \`ports <port> --kill\` stops its owner with SIGTERM, and with --force SIGKILL once --grace has passed, after asking on a terminal unless --yes is given. It refuses processes of other users, pid 1, this command and its ancestors, and docker-proxy, for which it names the container to stop instead.`;
2154
+ \`proc ports <port>\` keeps that port alone and exits 1 when nothing listens on it.
2155
+ \`proc ports <port> --kill\` stops its owner with SIGTERM, and with --force SIGKILL once --grace has passed, after asking on a terminal unless --yes is given. It refuses processes of other users, pid 1, this command and its ancestors, and docker-proxy, for which it names the container to stop instead.`;
2180
2156
  var EXITS2 = [[0, "it listed or stopped"], [1, "nothing listens on the given port or the owner could not be stopped"], [2, "a usage error"]];
2181
2157
  var options2 = {
2182
2158
  json: jsonOption("[{ port, protocol, addresses, pid, command, cwd, container }]"),
@@ -2269,10 +2245,10 @@ async function ports(args) {
2269
2245
  positionals: ["[port]"],
2270
2246
  replaces: "ss -ltnp | grep, lsof -i, fuser -k and lookups of docker-proxy by hand",
2271
2247
  examples: [
2272
- ["ports", "every listening port with its owner"],
2273
- ["ports 3000", "who holds 3000, exit 1 when nobody does"],
2274
- ["ports 3000 --kill --yes", "stop it"],
2275
- "ports --json"
2248
+ ["proc ports", "every listening port with its owner"],
2249
+ ["proc ports 3000", "who holds 3000, exit 1 when nobody does"],
2250
+ ["proc ports 3000 --kill --yes", "stop it"],
2251
+ "proc ports --json"
2276
2252
  ]
2277
2253
  });
2278
2254
  if (values.watch !== undefined)
@@ -2282,7 +2258,7 @@ async function ports(args) {
2282
2258
  if (port !== undefined && port > 65535)
2283
2259
  badUsage(`<port> takes a whole number from 1 to 65535, not ${given}`);
2284
2260
  if (values.kill === true && port === undefined)
2285
- badUsage("--kill takes the port to free: ports <port> --kill");
2261
+ badUsage("--kill takes the port to free: proc ports <port> --kill");
2286
2262
  const [sockets, owners, procs] = await Promise.all([readSockets(), socketOwners(), snapshot("/proc", (uid) => uid === process20.getuid?.())]);
2287
2263
  const byPid = new Map(procs.map((proc) => [proc.pid, proc]));
2288
2264
  const wanted = sockets.filter((socket) => port === undefined || socket.port === port);
@@ -2427,7 +2403,7 @@ function selectGroups(procs, options) {
2427
2403
  }
2428
2404
 
2429
2405
  // src/procs.ts
2430
- var usage4 = `procs
2406
+ var usage4 = `proc procs
2431
2407
 
2432
2408
  Lists the leftover or heavy processes of the calling user that are worth cleaning, grouped by origin: the project folder their working directory is in, a browser profile for a chromium and its helpers, else their command. Each group shows its process count, total resident memory and oldest age.
2433
2409
  A process is listed when it is a dev tool (bun, node, vite, nuxt, next, chromium and chrome, playwright and webview browsers and their helpers, language servers, test runners) and either an orphan, reparented to init or to the user's systemd, or heavy (500M resident by default). The processes below a listed one, and those sharing a browser profile with it, are listed too, so a chromium whose main process was killed groups with its leftover helpers.
@@ -2476,10 +2452,10 @@ async function procs(args) {
2476
2452
  exits: EXITS3,
2477
2453
  replaces: "pkill -f and pgrep -f one-liners (which match their own shell), ps aux | grep for leftover chromium, bun or vite processes",
2478
2454
  examples: [
2479
- ["procs", "leftover and heavy dev processes, by origin"],
2480
- ["procs --min-mem 1G --older 1h", "only the big ones that have run a while"],
2481
- ["procs --kill", "dry run: what would be stopped"],
2482
- "procs --kill --yes"
2455
+ ["proc procs", "leftover and heavy dev processes, by origin"],
2456
+ ["proc procs --min-mem 1G --older 1h", "only the big ones that have run a while"],
2457
+ ["proc procs --kill", "dry run: what would be stopped"],
2458
+ "proc procs --kill --yes"
2483
2459
  ]
2484
2460
  });
2485
2461
  const minMem = values["min-mem"] === undefined ? undefined : parseSize(values["min-mem"], 1024 ** 2);
package/package.json CHANGED
@@ -1,24 +1,21 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-proc",
3
3
  "type": "module",
4
- "version": "0.7.5",
5
- "description": "pid, ports, procs: one process inspected, who listens on a port, and leftover or heavy dev processes cleaned, read straight from /proc (Linux).",
4
+ "version": "0.8.0",
5
+ "description": "proc: one process inspected, who listens on a port, and leftover or heavy dev processes cleaned, read straight from /proc (Linux).",
6
6
  "author": "Kaynooo <contact@kaynooo.fr>",
7
7
  "license": "MIT",
8
- "homepage": "https://git.kaynooo.fr/kaynooo/cli/src/branch/main/packages/proc#readme",
8
+ "homepage": "https://github.com/Kayno0o/cli/tree/main/packages/proc#readme",
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "git+https://git.kaynooo.fr/kaynooo/cli.git",
11
+ "url": "git+https://github.com/Kayno0o/cli.git",
12
12
  "directory": "packages/proc"
13
13
  },
14
- "bugs": "https://git.kaynooo.fr/kaynooo/cli/issues",
14
+ "bugs": "https://github.com/Kayno0o/cli/issues",
15
15
  "keywords": ["process", "port", "proc", "kill", "cli", "bun"],
16
16
  "os": ["linux"],
17
17
  "bin": {
18
- "proc": "./dist/proc-cli.js",
19
- "pid": "./dist/pid-cli.js",
20
- "ports": "./dist/ports-cli.js",
21
- "procs": "./dist/procs-cli.js"
18
+ "proc": "./dist/proc-cli.js"
22
19
  },
23
20
  "files": ["dist", "src"],
24
21
  "engines": {
@@ -28,13 +25,10 @@
28
25
  "registry": "https://git.kaynooo.fr/api/packages/kaynooo/npm/"
29
26
  },
30
27
  "scripts": {
31
- "build": "$npm_execpath build src/proc-cli.ts src/pid-cli.ts src/ports-cli.ts src/procs-cli.ts --target bun --outdir dist",
32
- "proc": "$npm_execpath src/proc-cli.ts",
33
- "pid": "$npm_execpath src/pid-cli.ts",
34
- "ports": "$npm_execpath src/ports-cli.ts",
35
- "procs": "$npm_execpath src/procs-cli.ts"
28
+ "build": "$npm_execpath build src/proc-cli.ts --target bun --outdir dist",
29
+ "proc": "$npm_execpath src/proc-cli.ts"
36
30
  },
37
31
  "devDependencies": {
38
- "@kaynooo/cli-kit": "0.41.0"
32
+ "@kaynooo/cli-kit": "0.41.1"
39
33
  }
40
34
  }
package/src/pid.ts CHANGED
@@ -7,7 +7,7 @@ import { maskArgs, maskEnviron } from './mask'
7
7
  import { parseCgroup, parseEnviron, parseLimits, parseStat, parseStatus, statusBytes } from './parse'
8
8
  import { bootMs, fdCount, readProc, readSockets, readText, socketsOf, userName } from './read'
9
9
 
10
- const usage = `pid <pid>
10
+ const usage = `proc pid <pid>
11
11
 
12
12
  Shows what a process is: its executable, working directory, command line, parent chain up to init, user, start time and age, memory, open files and limits, the TCP and UDP ports it listens on and its cgroup. Everything is read from /proc; what the calling user cannot read of another user's process is left out and named at the end.
13
13
  The environment is not shown unless --env is given, with every value that looks like a secret masked.`
@@ -170,9 +170,9 @@ export async function pid(args: string[]): Promise<number> {
170
170
  positionals: ['<pid>'],
171
171
  replaces: 'cat /proc/<pid>/{cmdline,environ,limits}, readlink /proc/<pid>/{exe,cwd}, the fish pid function',
172
172
  examples: [
173
- ['pid 4242', 'executable, directory, command, parents, memory, limits and ports'],
174
- ['pid 4242 --env', 'with the environment, secrets masked'],
175
- 'pid 4242 --json',
173
+ ['proc pid 4242', 'executable, directory, command, parents, memory, limits and ports'],
174
+ ['proc pid 4242 --env', 'with the environment, secrets masked'],
175
+ 'proc pid 4242 --json',
176
176
  ],
177
177
  })
178
178
  const [given] = positionals
package/src/ports.ts CHANGED
@@ -10,11 +10,11 @@ import { protectionOf, terminate } from './kill'
10
10
  import { maskArgs } from './mask'
11
11
  import { ancestry, readSockets, snapshot, socketOwners } from './read'
12
12
 
13
- const usage = `ports [port]
13
+ const usage = `proc ports [port]
14
14
 
15
15
  Lists what listens on this machine, TCP and UDP over IPv4 and IPv6, one row per port with its bound address, the owning process, its command and its working directory. A port Docker publishes is held by docker-proxy, and shows as its compose project and service when docker is installed; the owner of a socket of another user cannot be read and shows as -.
16
- \`ports <port>\` keeps that port alone and exits 1 when nothing listens on it.
17
- \`ports <port> --kill\` stops its owner with SIGTERM, and with --force SIGKILL once --grace has passed, after asking on a terminal unless --yes is given. It refuses processes of other users, pid 1, this command and its ancestors, and docker-proxy, for which it names the container to stop instead.`
16
+ \`proc ports <port>\` keeps that port alone and exits 1 when nothing listens on it.
17
+ \`proc ports <port> --kill\` stops its owner with SIGTERM, and with --force SIGKILL once --grace has passed, after asking on a terminal unless --yes is given. It refuses processes of other users, pid 1, this command and its ancestors, and docker-proxy, for which it names the container to stop instead.`
18
18
  const EXITS: ExitRow[] = [[0, 'it listed or stopped'], [1, 'nothing listens on the given port or the owner could not be stopped'], [2, 'a usage error']]
19
19
 
20
20
  const options = {
@@ -147,10 +147,10 @@ export async function ports(args: string[]): Promise<number> {
147
147
  positionals: ['[port]'],
148
148
  replaces: 'ss -ltnp | grep, lsof -i, fuser -k and lookups of docker-proxy by hand',
149
149
  examples: [
150
- ['ports', 'every listening port with its owner'],
151
- ['ports 3000', 'who holds 3000, exit 1 when nobody does'],
152
- ['ports 3000 --kill --yes', 'stop it'],
153
- 'ports --json',
150
+ ['proc ports', 'every listening port with its owner'],
151
+ ['proc ports 3000', 'who holds 3000, exit 1 when nobody does'],
152
+ ['proc ports 3000 --kill --yes', 'stop it'],
153
+ 'proc ports --json',
154
154
  ],
155
155
  })
156
156
 
@@ -164,7 +164,7 @@ export async function ports(args: string[]): Promise<number> {
164
164
  badUsage(`<port> takes a whole number from 1 to 65535, not ${given}`)
165
165
 
166
166
  if (values.kill === true && port === undefined)
167
- badUsage('--kill takes the port to free: ports <port> --kill')
167
+ badUsage('--kill takes the port to free: proc ports <port> --kill')
168
168
 
169
169
  const [sockets, owners, procs] = await Promise.all([readSockets(), socketOwners(), snapshot('/proc', uid => uid === process.getuid?.())])
170
170
  const byPid = new Map(procs.map(proc => [proc.pid, proc]))
package/src/procs.ts CHANGED
@@ -9,7 +9,7 @@ import { maskArgs } from './mask'
9
9
  import { ancestry, snapshot } from './read'
10
10
  import { selectGroups } from './select'
11
11
 
12
- const usage = `procs
12
+ const usage = `proc procs
13
13
 
14
14
  Lists the leftover or heavy processes of the calling user that are worth cleaning, grouped by origin: the project folder their working directory is in, a browser profile for a chromium and its helpers, else their command. Each group shows its process count, total resident memory and oldest age.
15
15
  A process is listed when it is a dev tool (bun, node, vite, nuxt, next, chromium and chrome, playwright and webview browsers and their helpers, language servers, test runners) and either an orphan, reparented to init or to the user's systemd, or heavy (500M resident by default). The processes below a listed one, and those sharing a browser profile with it, are listed too, so a chromium whose main process was killed groups with its leftover helpers.
@@ -65,10 +65,10 @@ export async function procs(args: string[]): Promise<number> {
65
65
  exits: EXITS,
66
66
  replaces: 'pkill -f and pgrep -f one-liners (which match their own shell), ps aux | grep for leftover chromium, bun or vite processes',
67
67
  examples: [
68
- ['procs', 'leftover and heavy dev processes, by origin'],
69
- ['procs --min-mem 1G --older 1h', 'only the big ones that have run a while'],
70
- ['procs --kill', 'dry run: what would be stopped'],
71
- 'procs --kill --yes',
68
+ ['proc procs', 'leftover and heavy dev processes, by origin'],
69
+ ['proc procs --min-mem 1G --older 1h', 'only the big ones that have run a while'],
70
+ ['proc procs --kill', 'dry run: what would be stopped'],
71
+ 'proc procs --kill --yes',
72
72
  ],
73
73
  })
74
74
  const minMem = values['min-mem'] === undefined ? undefined : parseSize(values['min-mem'], 1024 ** 2)