@pify/shell-background 0.3.0 → 0.3.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/README.md +2 -0
- package/package.json +1 -1
- package/src/env.ts +37 -4
package/README.md
CHANGED
|
@@ -60,6 +60,8 @@ Put these in `.pi/shell-background.json` (project) or `<agentDir>/shell-backgrou
|
|
|
60
60
|
|
|
61
61
|
`autoBackgroundMs` is how long a foreground command may run before it auto-backgrounds; set it to `0` to disable auto-background (explicit `background: true` still works). `PIFY_SHELL_BG_MS` overrides it for one run or in CI. `tailBytes` bounds how much of a job's log a status result shows. `maxBackground` bounds how many jobs may be alive at once: over it, a `background: true` request is refused with a message naming the limit (the command can still run in the foreground), and a command that crosses the auto-background threshold simply stays in the foreground instead of moving — a command is never refused, only the decision to background it. Bad values fall back to the defaults with a warning rather than taking the tool down.
|
|
62
62
|
|
|
63
|
+
A backgrounded command runs with no one to answer it, so its environment says so: `GIT_TERMINAL_PROMPT=0` and `GIT_EDITOR`/`EDITOR`/`VISUAL=true` are forced (a `git commit` without `-m` fails with "empty message" instead of waiting on an editor that never comes, and an https `git fetch` fails instead of prompting for a password), and pagers default to `cat` unless you set them. `CI` and `TERM` are left alone on purpose — dev servers and watchers read them.
|
|
64
|
+
|
|
63
65
|
The tail a result carries is cleaned the way pi's own bash cleans what the model sees — ANSI escapes, control characters and carriage-return progress frames stripped — so a chatty build or dev server does not spend tokens on colour codes and thousands of overwritten progress lines. The log file on disk keeps every byte.
|
|
64
66
|
|
|
65
67
|
## Coexistence with @pify/pretty
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pify/shell-background",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Long-running bash goes async: background: true launches detached, and any command still running after 30s auto-backgrounds and delivers its result when it finishes",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
package/src/env.ts
CHANGED
|
@@ -17,6 +17,37 @@
|
|
|
17
17
|
*/
|
|
18
18
|
import { delimiter } from "node:path";
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Defaults that keep an unattended child from waiting on a human. FORCED —
|
|
22
|
+
* they win over the inherited value — because a background job has no one
|
|
23
|
+
* to answer: `git commit` without -m must not open $EDITOR, `git fetch` over
|
|
24
|
+
* https must not prompt for a password. With stdin ignored such a prompt
|
|
25
|
+
* either hangs forever or sits until the tree is killed, and while it waits
|
|
26
|
+
* it holds one of the maxBackground slots. (Set from oh-my-pi's
|
|
27
|
+
* non-interactive-env; the editor becomes `true`, which exits 0 with the
|
|
28
|
+
* message untouched, so git aborts with "empty commit message" instead.)
|
|
29
|
+
*/
|
|
30
|
+
export const NON_INTERACTIVE_FORCED: Readonly<Record<string, string>> = {
|
|
31
|
+
GIT_TERMINAL_PROMPT: "0",
|
|
32
|
+
GIT_EDITOR: "true",
|
|
33
|
+
EDITOR: "true",
|
|
34
|
+
VISUAL: "true",
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Formatting-only defaults, applied UNDER the inherited env so an explicit
|
|
39
|
+
* value still wins: a pager only ever changes how output is shown, and to a
|
|
40
|
+
* pipe it is dead weight. Deliberately NOT here: CI=true and TERM=dumb —
|
|
41
|
+
* this package also runs dev servers and watchers, and those flags make many
|
|
42
|
+
* of them drop watch mode, change ports or strip the output the user wants.
|
|
43
|
+
*/
|
|
44
|
+
export const NON_INTERACTIVE_DEFAULTS: Readonly<Record<string, string>> = {
|
|
45
|
+
PAGER: "cat",
|
|
46
|
+
GIT_PAGER: "cat",
|
|
47
|
+
GH_PAGER: "cat",
|
|
48
|
+
LESS: "FRX",
|
|
49
|
+
};
|
|
50
|
+
|
|
20
51
|
/** The slice of the pi ExtensionContext this needs, kept structural for tests. */
|
|
21
52
|
export interface EnvCtx {
|
|
22
53
|
sessionManager?: { getSessionId?(): string; getSessionFile?(): string | undefined };
|
|
@@ -25,16 +56,18 @@ export interface EnvCtx {
|
|
|
25
56
|
}
|
|
26
57
|
|
|
27
58
|
/**
|
|
28
|
-
* Copy `base`, prepend `binDir` to PATH when absent,
|
|
29
|
-
* variables from `ctx
|
|
30
|
-
*
|
|
59
|
+
* Copy `base`, prepend `binDir` to PATH when absent, set the PI_* session
|
|
60
|
+
* variables from `ctx`, and layer the non-interactive defaults (formatting
|
|
61
|
+
* ones under the base, the anti-hang ones over it). The ctx reads are
|
|
62
|
+
* wrapped so a stale ctx after a `/reload` degrades to plain env rather than
|
|
63
|
+
* failing the spawn.
|
|
31
64
|
*/
|
|
32
65
|
export function buildEnv(
|
|
33
66
|
ctx: EnvCtx,
|
|
34
67
|
binDir: string,
|
|
35
68
|
base: NodeJS.ProcessEnv = process.env,
|
|
36
69
|
): NodeJS.ProcessEnv {
|
|
37
|
-
const env: NodeJS.ProcessEnv = { ...base };
|
|
70
|
+
const env: NodeJS.ProcessEnv = { ...NON_INTERACTIVE_DEFAULTS, ...base, ...NON_INTERACTIVE_FORCED };
|
|
38
71
|
|
|
39
72
|
// PATH is case-insensitive on Windows; find the real key so we do not create a
|
|
40
73
|
// second, ignored "PATH" alongside an inherited "Path". Only prepend when the
|