@pify/shell-background 0.5.1 → 0.6.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
@@ -55,11 +55,12 @@ Put these in `.pi/shell-background.json` (project) or `<agentDir>/shell-backgrou
55
55
  "autoBackgroundMs": 30000,
56
56
  "tailBytes": 65536,
57
57
  "tailLines": 200,
58
- "maxBackground": 8
58
+ "maxBackground": 8,
59
+ "deliverResults": true
59
60
  }
60
61
  ```
61
62
 
62
- `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 reads; `tailLines` bounds how many lines of it the model is shown (0 disables the line shrink). `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.
63
+ `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 reads; `tailLines` bounds how many lines of it the model is shown (0 disables the line shrink). `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. `deliverResults` (boolean, default `true`): when a background job finishes, its result is pushed into the conversation and wakes the agent for a new turn. Set it to `false` to turn that off — the widget still updates and `shell_status {id}` still collects the result, but nothing is injected and the agent is not woken. Bad values fall back to the defaults with a warning rather than taking the tool down.
63
64
 
64
65
  Since pi 0.99 the bash tool also returns a machine-readable result — `structuredContent` — which codemode scripts and tools calling `ctx.executeTool("bash", …)` receive instead of the text. This package keeps pi's shape so such a script reads either tool unchanged: `output` (the whole log, up to 1 MiB, head and tail around an omission marker), `truncated`, `full_output_path`, `exit_code`, `wall_time_seconds` — plus `status` and `job_id`, because a command here can still be running when the tool returns; then `exit_code` is absent and `shell_status {id}` collects it, with the same structured result.
65
66
 
@@ -218,6 +218,7 @@ export default function shellBackground(pi: ExtensionAPI) {
218
218
  /** Push a finished job's result into the conversation through the live pi. */
219
219
  function deliver(job: Job): void {
220
220
  renderWidget();
221
+ if (!settings.deliverResults) return;
221
222
  pi.sendMessage(
222
223
  {
223
224
  customType: DELIVERY_TYPE,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pify/shell-background",
3
- "version": "0.5.1",
3
+ "version": "0.6.0",
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/config.ts CHANGED
@@ -29,6 +29,13 @@ export interface ShellBgSettings {
29
29
  * — a command itself is never refused.
30
30
  */
31
31
  maxBackground: number;
32
+ /**
33
+ * Whether a finished background job pushes its result into the conversation
34
+ * (and triggers a new agent turn that explains it). false: the job still
35
+ * finishes, the widget updates, and shell_status collects the result, but
36
+ * nothing is injected and the agent is not woken.
37
+ */
38
+ deliverResults: boolean;
32
39
  }
33
40
 
34
41
  export const DEFAULT_SETTINGS: ShellBgSettings = {
@@ -36,9 +43,12 @@ export const DEFAULT_SETTINGS: ShellBgSettings = {
36
43
  tailBytes: 64 * 1024,
37
44
  tailLines: 200,
38
45
  maxBackground: 8,
46
+ deliverResults: true,
39
47
  };
40
48
 
41
- const LIMITS: Record<keyof ShellBgSettings, { min: number; max: number }> = {
49
+ type NumericKey = Exclude<keyof ShellBgSettings, "deliverResults">;
50
+
51
+ const LIMITS: Record<NumericKey, { min: number; max: number }> = {
42
52
  // 0 is allowed (disable); otherwise at least 1s so a typo of "30" (=30ms)
43
53
  // does not make every command look long-running.
44
54
  autoBackgroundMs: { min: 0, max: 3_600_000 },
@@ -63,7 +73,12 @@ export function resolveSettings(
63
73
  warnings.push(`unknown setting "${key}"`);
64
74
  continue;
65
75
  }
66
- const name = key as keyof ShellBgSettings;
76
+ if (key === "deliverResults") {
77
+ if (typeof value === "boolean") settings.deliverResults = value;
78
+ else warnings.push(`"deliverResults" must be true or false — using ${DEFAULT_SETTINGS.deliverResults}`);
79
+ continue;
80
+ }
81
+ const name = key as NumericKey;
67
82
  if (typeof value !== "number" || !Number.isFinite(value)) {
68
83
  warnings.push(`"${key}" must be a number — using ${DEFAULT_SETTINGS[name]}`);
69
84
  continue;
@@ -83,7 +98,7 @@ export function resolveSettings(
83
98
  return { settings, warnings };
84
99
  }
85
100
 
86
- function clamp(name: keyof ShellBgSettings, value: number, warnings: string[]): number {
101
+ function clamp(name: NumericKey, value: number, warnings: string[]): number {
87
102
  const { min, max } = LIMITS[name];
88
103
  const c = Math.round(Math.min(max, Math.max(min, value)));
89
104
  if (c !== value) warnings.push(`"${name}" clamped to ${c} (allowed ${min}–${max})`);