pi-better-background-tasks 0.13.0 → 0.13.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 +64 -4
- package/package.json +1 -1
- package/src/output.ts +22 -2
- package/src/process.ts +100 -1
- package/src/runtime.ts +179 -10
- package/src/shared-callback-batcher.ts +18 -1
- package/src/shared-failure-observations.ts +78 -24
- package/src/shared-log-utils.ts +277 -31
- package/src/stall.ts +4 -1
- package/src/tools.ts +14 -3
- package/src/types.ts +33 -1
package/src/tools.ts
CHANGED
|
@@ -91,7 +91,17 @@ const CommandFields = {
|
|
|
91
91
|
...IntentFields,
|
|
92
92
|
};
|
|
93
93
|
|
|
94
|
-
|
|
94
|
+
/**
|
|
95
|
+
* Opt-in step gate (#619). Chained shell commands report only the last command's
|
|
96
|
+
* status, so a failing test run followed by summary commands reads as success at
|
|
97
|
+
* the status surface. The gate runs the command under bash errexit so its first
|
|
98
|
+
* unhandled failing step decides the task's exit code.
|
|
99
|
+
*/
|
|
100
|
+
const StepGateField = Type.Optional(Type.Boolean({
|
|
101
|
+
description: "Spawn only: opt in to a step gate for a shell command. The command runs under bash errexit, so its first unhandled failing step ends the task with that step's exit code and a later command cannot mask it; status reports that exit with `(step gate)` and names the failing step. Handled failures (`|| true`, `if`/`while`/`until` conditions, `!`) are not gate failures. Not supported with shell:false or ssh. Default false (ordinary shell semantics).",
|
|
102
|
+
}));
|
|
103
|
+
|
|
104
|
+
const SpawnParams = Type.Object({ ...CommandFields, require_successful_steps: StepGateField });
|
|
95
105
|
|
|
96
106
|
const BlindChecksField = Type.Optional(Type.Integer({ minimum: 0, description: "Flag the watch as possibly blind after this many checks in a row exit 0, write stderr, and match neither success_when nor failure_when: one incident that needs action, with the latest stderr line. The watch keeps running; a check with no stderr or a matched condition recovers it. Default 3; 0 turns it off." }));
|
|
97
107
|
|
|
@@ -164,6 +174,7 @@ const ActionParams = Type.Object({
|
|
|
164
174
|
tail_lines: Type.Optional(Type.Number({ description: "Deprecated alias for lines." })),
|
|
165
175
|
verbose: Type.Optional(Type.Boolean()),
|
|
166
176
|
...CommandFields,
|
|
177
|
+
require_successful_steps: StepGateField,
|
|
167
178
|
interval_seconds: Type.Optional(Type.Number()),
|
|
168
179
|
success_when: Type.Optional(ConditionSchema),
|
|
169
180
|
failure_when: Type.Optional(ConditionSchema),
|
|
@@ -239,7 +250,7 @@ export function registerTools(pi: ExtensionAPI): void {
|
|
|
239
250
|
register({
|
|
240
251
|
name: "bg_task_spawn",
|
|
241
252
|
label: "BG Spawn",
|
|
242
|
-
description: "Start a long-running background process and return immediately with its task id. For remote work, prefer structured ssh: pass ssh:{host,user} and put the remote command in command; spawn defaults to a remote tmux session with durable local logs and real remote stop. For short synchronous remote commands that should return output now, use remote_bash from pi-better-ssh. If tmux is missing, the preset attempts to install tmux non-interactively and fails closed with operator guidance when setup cannot proceed. Explicit remote.session=direct skips tmux, but direct mode has weaker stop semantics and may leave the remote process running. Never wait or poll in the foreground.",
|
|
253
|
+
description: "Start a long-running background process and return immediately with its task id. For remote work, prefer structured ssh: pass ssh:{host,user} and put the remote command in command; spawn defaults to a remote tmux session with durable local logs and real remote stop. For short synchronous remote commands that should return output now, use remote_bash from pi-better-ssh. If tmux is missing, the preset attempts to install tmux non-interactively and fails closed with operator guidance when setup cannot proceed. Explicit remote.session=direct skips tmux, but direct mode has weaker stop semantics and may leave the remote process running. Pass require_successful_steps:true for a chained shell command whose earlier failing steps must not be masked by a later command's exit 0: it runs under bash errexit and ends at the first unhandled failing step. Never wait or poll in the foreground.",
|
|
243
254
|
promptGuidelines: BACKGROUND_ORCHESTRATION_GUIDELINES,
|
|
244
255
|
parameters: SpawnParams,
|
|
245
256
|
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
|
@@ -316,7 +327,7 @@ export function registerTools(pi: ExtensionAPI): void {
|
|
|
316
327
|
register({
|
|
317
328
|
name: "bg_task",
|
|
318
329
|
label: "BG Task",
|
|
319
|
-
description: "Action wrapper for background tasks: spawn, watch, list, status, log, stop, or clear. For remote work, prefer structured ssh: pass ssh:{host,user} and provide the remote command in command. For short synchronous remote commands that should return output now, use remote_bash from pi-better-ssh. SSH spawn defaults to durable tmux; SSH watches use direct one-shot polls without tmux installation; remote.session=direct is a weaker-stop spawn escape hatch. Spawn returns immediately; do not poll in foreground. For action:watch: " + WATCH_CHECK_GUIDANCE + " For action:status, default compact output and use verbose:true only for full metadata. For action:log, default compact tail and use lines:0 to page retained raw bytes. Standalone tools and these wrappers share the same output assembler. List/status/log default to the current session; pass all:true to override. Stop and clear change only current-session tasks: clear dismisses every owned terminal task, or one task with id (all:true allows another session's task by id).",
|
|
330
|
+
description: "Action wrapper for background tasks: spawn, watch, list, status, log, stop, or clear. For remote work, prefer structured ssh: pass ssh:{host,user} and provide the remote command in command. For action:spawn, require_successful_steps:true runs a chained shell command under bash errexit so it ends at its first unhandled failing step instead of only reporting its last command's exit. For short synchronous remote commands that should return output now, use remote_bash from pi-better-ssh. SSH spawn defaults to durable tmux; SSH watches use direct one-shot polls without tmux installation; remote.session=direct is a weaker-stop spawn escape hatch. Spawn returns immediately; do not poll in foreground. For action:watch: " + WATCH_CHECK_GUIDANCE + " For action:status, default compact output and use verbose:true only for full metadata. For action:log, default compact tail and use lines:0 to page retained raw bytes. Standalone tools and these wrappers share the same output assembler. List/status/log default to the current session; pass all:true to override. Stop and clear change only current-session tasks: clear dismisses every owned terminal task, or one task with id (all:true allows another session's task by id).",
|
|
320
331
|
promptGuidelines: BACKGROUND_ORCHESTRATION_GUIDELINES,
|
|
321
332
|
parameters: ActionParams,
|
|
322
333
|
renderResult(result: unknown, options: unknown, theme: unknown) {
|
package/src/types.ts
CHANGED
|
@@ -28,6 +28,19 @@ export interface CommandSpec {
|
|
|
28
28
|
env?: Record<string, string>;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Evidence from an opt-in step gate (#619): bash reported a failing step inside a
|
|
33
|
+
* chained shell command, so a later command's exit 0 could not mask it.
|
|
34
|
+
*/
|
|
35
|
+
export interface StepGateFailure {
|
|
36
|
+
/** Exit code of the first failing step bash reported. */
|
|
37
|
+
stepExitCode: number;
|
|
38
|
+
/** The shell's own final status, before the gate turned a masked 0 into a failure. */
|
|
39
|
+
shellExitCode: number | null;
|
|
40
|
+
/** The failing step as bash named it, bounded so task metadata stays small. */
|
|
41
|
+
command: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
31
44
|
export interface CommandResult {
|
|
32
45
|
exitCode: number | null;
|
|
33
46
|
signal: NodeJS.Signals | null;
|
|
@@ -100,8 +113,19 @@ export interface BackgroundTaskMeta {
|
|
|
100
113
|
deadlineAt?: number;
|
|
101
114
|
intervalMs?: number;
|
|
102
115
|
lastCheckedAt?: number;
|
|
103
|
-
/**
|
|
116
|
+
/**
|
|
117
|
+
* Latest meaningful progress. A process advances it on output; a watch only
|
|
118
|
+
* when its observed outcome changes state (never on the poll itself).
|
|
119
|
+
*/
|
|
104
120
|
lastProgressAt?: number;
|
|
121
|
+
/**
|
|
122
|
+
* Watch only: canonical fingerprint of the last observed poll outcome
|
|
123
|
+
* (stdout content, stderr content, exit code, signal, error). A poll that
|
|
124
|
+
* reports the same outcome is activity, not progress. Versioned; a value from
|
|
125
|
+
* another version, or a record without one, is adopted without moving the
|
|
126
|
+
* state clock so an upgrade or reload can never keep resetting silence.
|
|
127
|
+
*/
|
|
128
|
+
watchFingerprint?: string;
|
|
105
129
|
lastExitCode?: number | null;
|
|
106
130
|
lastSignal?: NodeJS.Signals | null;
|
|
107
131
|
lastState?: unknown;
|
|
@@ -155,6 +179,14 @@ export interface BackgroundTaskMeta {
|
|
|
155
179
|
spawnPid: number;
|
|
156
180
|
/** Opaque process-start token used to reject recycled supervisor PIDs. */
|
|
157
181
|
spawnPidStartTime?: string;
|
|
182
|
+
/**
|
|
183
|
+
* Launch intent (#619): this shell command runs with the step gate. A failure bash
|
|
184
|
+
* reports for one step is surfaced even when a later command exits 0. Absent means
|
|
185
|
+
* ordinary shell semantics: only the command's own exit status is reported.
|
|
186
|
+
*/
|
|
187
|
+
requireSuccessfulSteps?: boolean;
|
|
188
|
+
/** Observed step-gate evidence; absent when the gate is off or no step failed. */
|
|
189
|
+
stepGateFailure?: StepGateFailure;
|
|
158
190
|
successWhen?: Condition;
|
|
159
191
|
failureWhen?: Condition;
|
|
160
192
|
/**
|