pi-better-background-tasks 0.2.11 → 0.2.13
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/package.json +1 -1
- package/src/shared-navigator.ts +19 -7
- package/src/tools.ts +9 -0
package/package.json
CHANGED
package/src/shared-navigator.ts
CHANGED
|
@@ -918,7 +918,7 @@ function createOverlayComponent(
|
|
|
918
918
|
width,
|
|
919
919
|
deps.truncate,
|
|
920
920
|
fg,
|
|
921
|
-
{ minRows: detailRows, bottomFooter: false, logTailRows },
|
|
921
|
+
{ minRows: detailRows, maxRows: detailRows, bottomFooter: false, logTailRows },
|
|
922
922
|
);
|
|
923
923
|
} else {
|
|
924
924
|
transcriptDetail = null;
|
|
@@ -1003,21 +1003,33 @@ function buildTranscriptDetailLines(
|
|
|
1003
1003
|
width: number,
|
|
1004
1004
|
truncate: (s: string, width: number) => string,
|
|
1005
1005
|
fg: (color: string, value: string) => string,
|
|
1006
|
-
options: { minRows?: number; bottomFooter?: boolean; logTailRows?: number } = {},
|
|
1006
|
+
options: { minRows?: number; maxRows?: number; bottomFooter?: boolean; logTailRows?: number } = {},
|
|
1007
1007
|
): string[] {
|
|
1008
1008
|
const actions = [...(detail.footerActions ?? ["x close"]), "Esc close"].join(" · ");
|
|
1009
1009
|
const tailRows = options.logTailRows ?? DEFAULT_LOG_TAIL_ROWS;
|
|
1010
|
-
|
|
1010
|
+
let shownTranscriptLines = transcriptLines.length ? transcriptLines.slice(-tailRows) : [" (no transcript yet)"];
|
|
1011
1011
|
const lines: string[] = [
|
|
1012
1012
|
fg("accent", rule(detail.title, width)),
|
|
1013
1013
|
dim(` ← main · ${actions}`, fg),
|
|
1014
1014
|
"",
|
|
1015
1015
|
` status ${fg(toneColor(detail.statusTone, detail.status), detail.status)}`,
|
|
1016
1016
|
];
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1017
|
+
const optionalMetadata = [
|
|
1018
|
+
...(detail.subtitle ? [` summary ${detail.subtitle}`] : []),
|
|
1019
|
+
...detail.metadata.map((item) => ` ${item.label.padEnd(8, " ").slice(0, 8)} ${item.value}`),
|
|
1020
|
+
];
|
|
1021
|
+
const transcriptHeader = ["", dim(section(`transcript · latest ${tailRows} rows`, width), fg)];
|
|
1022
|
+
if (detail.transcriptDiagnostic) transcriptHeader.push(` ${dim(detail.transcriptDiagnostic, fg)}`);
|
|
1023
|
+
if (options.maxRows !== undefined) {
|
|
1024
|
+
const fixedRows = lines.length + transcriptHeader.length + 1;
|
|
1025
|
+
const transcriptBudget = Math.max(1, options.maxRows - fixedRows);
|
|
1026
|
+
shownTranscriptLines = shownTranscriptLines.slice(-transcriptBudget);
|
|
1027
|
+
const metadataBudget = Math.max(0, options.maxRows - fixedRows - shownTranscriptLines.length);
|
|
1028
|
+
lines.push(...optionalMetadata.slice(0, metadataBudget));
|
|
1029
|
+
} else {
|
|
1030
|
+
lines.push(...optionalMetadata);
|
|
1031
|
+
}
|
|
1032
|
+
lines.push(...transcriptHeader);
|
|
1021
1033
|
lines.push(...shownTranscriptLines);
|
|
1022
1034
|
lines.push("");
|
|
1023
1035
|
if (options.bottomFooter === false) return lines.map((line) => safeTruncate(line, width, truncate));
|
package/src/tools.ts
CHANGED
|
@@ -103,6 +103,12 @@ const StatusActionParams = Type.Object({
|
|
|
103
103
|
verbose: Type.Optional(Type.Boolean()),
|
|
104
104
|
});
|
|
105
105
|
|
|
106
|
+
const BACKGROUND_ORCHESTRATION_GUIDELINES = [
|
|
107
|
+
"Use background tasks for genuinely long-running processes or repeated checks. Run short commands in the foreground.",
|
|
108
|
+
"When a structured plan is active, keep it as the coordinator ledger: launch relevant background work early, continue unblocked foreground work without polling, and update the plan after inspecting each terminal result or failure.",
|
|
109
|
+
"Do not treat launch as completion of the parent milestone; relevant background work must be terminal, inspected, and integrated before verification or completion.",
|
|
110
|
+
];
|
|
111
|
+
|
|
106
112
|
export function registerTools(pi: ExtensionAPI): void {
|
|
107
113
|
let activeSession: BackgroundTaskCallbackOrigin | undefined;
|
|
108
114
|
const getActiveSession = () => activeSession;
|
|
@@ -125,6 +131,7 @@ export function registerTools(pi: ExtensionAPI): void {
|
|
|
125
131
|
name: "bg_task_spawn",
|
|
126
132
|
label: "BG Spawn",
|
|
127
133
|
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.",
|
|
134
|
+
promptGuidelines: BACKGROUND_ORCHESTRATION_GUIDELINES,
|
|
128
135
|
parameters: SpawnParams,
|
|
129
136
|
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
|
130
137
|
activeSession = getCallbackOrigin(ctx);
|
|
@@ -138,6 +145,7 @@ export function registerTools(pi: ExtensionAPI): void {
|
|
|
138
145
|
name: "bg_task_watch",
|
|
139
146
|
label: "BG Watch",
|
|
140
147
|
description: "Poll a command in the background until success_when, failure_when, or timeout matches. For remote work, prefer structured ssh: pass ssh:{host,user} and provide the remote command in command; each interval opens a direct one-shot SSH poll without tmux installation. For short synchronous remote commands that should return output now, use remote_bash from pi-better-ssh. Returns immediately with its task id. Default timeout 900 seconds; pass timeout_seconds:0 to disable.",
|
|
148
|
+
promptGuidelines: BACKGROUND_ORCHESTRATION_GUIDELINES,
|
|
141
149
|
parameters: WatchParams,
|
|
142
150
|
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
|
143
151
|
activeSession = getCallbackOrigin(ctx);
|
|
@@ -198,6 +206,7 @@ export function registerTools(pi: ExtensionAPI): void {
|
|
|
198
206
|
name: "bg_task",
|
|
199
207
|
label: "BG Task",
|
|
200
208
|
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/watch return immediately; do not poll in foreground. For action:status, default compact output and use verbose:true only for full metadata. For action:log, default compact tail and use tail_lines:0 only for explicit full logs.",
|
|
209
|
+
promptGuidelines: BACKGROUND_ORCHESTRATION_GUIDELINES,
|
|
201
210
|
parameters: ActionParams,
|
|
202
211
|
renderResult(result: unknown, options: unknown, theme: unknown) {
|
|
203
212
|
return renderBackgroundTaskLogDisplay(result, options, theme);
|