pi-better-background-tasks 0.2.3 → 0.2.5
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/remote-task-preset.ts +17 -3
- package/src/tools.ts +4 -4
package/package.json
CHANGED
|
@@ -113,8 +113,14 @@ const REQUIRED_SSH_OPTIONS = new Set(["batchmode", "connecttimeout", "requesttty
|
|
|
113
113
|
const DIRECT_STOP_WARNING = "Direct SSH mode has weak stop semantics: stopping the local SSH client may leave the remote process running.";
|
|
114
114
|
const TMUX_STATUS_PREFIX = "__PI_BG_STATUS__=";
|
|
115
115
|
const TMUX_SIZE_PREFIX = "__PI_BG_SIZE__=";
|
|
116
|
+
const TMUX_PATH_PREFIX = "__PI_BG_TMUX_PATH__=";
|
|
117
|
+
const TMUX_VERSION_PREFIX = "__PI_BG_TMUX_VERSION__=";
|
|
116
118
|
const TMUX_CAPTURE_CHUNK_BYTES = 256 * 1024;
|
|
117
|
-
const TMUX_PROBE_COMMAND =
|
|
119
|
+
const TMUX_PROBE_COMMAND = [
|
|
120
|
+
"tmux_path=$(command -v tmux) || exit 127",
|
|
121
|
+
`printf '${TMUX_PATH_PREFIX}%s\\n' "$tmux_path"`,
|
|
122
|
+
`printf '${TMUX_VERSION_PREFIX}%s\\n' "$("$tmux_path" -V)"`,
|
|
123
|
+
].join("; ");
|
|
118
124
|
const TMUX_PACKAGE_MANAGERS: TmuxPackageManager[] = ["apt-get", "dnf", "yum", "apk", "pacman", "zypper", "brew"];
|
|
119
125
|
const TMUX_INSTALL_COMMANDS: Record<TmuxPackageManager, string> = {
|
|
120
126
|
"apt-get": "apt-get update && apt-get install -y tmux",
|
|
@@ -523,8 +529,16 @@ function resolveBootstrapTimeoutMs(timeoutMs: number | undefined): number {
|
|
|
523
529
|
}
|
|
524
530
|
|
|
525
531
|
function parseTmuxCapability(result: CommandResult): { tmuxPath: string; tmuxVersion: string } | undefined {
|
|
526
|
-
|
|
527
|
-
|
|
532
|
+
if (result.exitCode !== 0) return undefined;
|
|
533
|
+
let tmuxPath: string | undefined;
|
|
534
|
+
let tmuxVersion: string | undefined;
|
|
535
|
+
for (const line of result.stdout.split("\n")) {
|
|
536
|
+
if (line.startsWith(TMUX_PATH_PREFIX)) tmuxPath = line.slice(TMUX_PATH_PREFIX.length);
|
|
537
|
+
if (line.startsWith(TMUX_VERSION_PREFIX)) tmuxVersion = line.slice(TMUX_VERSION_PREFIX.length);
|
|
538
|
+
}
|
|
539
|
+
if (!tmuxPath || !tmuxVersion) return undefined;
|
|
540
|
+
if (!tmuxPath.startsWith("/") || /\s/.test(tmuxPath)) return undefined;
|
|
541
|
+
if (!/^tmux\b/i.test(tmuxVersion)) return undefined;
|
|
528
542
|
return { tmuxPath, tmuxVersion };
|
|
529
543
|
}
|
|
530
544
|
|
package/src/tools.ts
CHANGED
|
@@ -68,7 +68,7 @@ const ListParams = Type.Object({
|
|
|
68
68
|
});
|
|
69
69
|
const LogParams = Type.Object({
|
|
70
70
|
id: Type.String({ description: "Background task id." }),
|
|
71
|
-
tail_lines: Type.Optional(Type.Number({ description: "Number of trailing lines. Default
|
|
71
|
+
tail_lines: Type.Optional(Type.Number({ description: "Number of trailing lines. Default 5 for compact model ingestion. Set <=0 only when the full log is explicitly required." })),
|
|
72
72
|
});
|
|
73
73
|
|
|
74
74
|
const ActionParams = Type.Object({
|
|
@@ -168,7 +168,7 @@ export function registerTools(pi: ExtensionAPI): void {
|
|
|
168
168
|
pi.registerTool({
|
|
169
169
|
name: "bg_task_log",
|
|
170
170
|
label: "BG Log",
|
|
171
|
-
description: "Read a background task log. Default output is a compact
|
|
171
|
+
description: "Read a background task log. Default output is a compact 5-line terminal-aware tail for model ingestion. Pass tail_lines for a bounded tail; tail_lines:0 returns the retained raw log, capped at 512 KiB for safe recovery. Nonblocking.",
|
|
172
172
|
parameters: LogParams,
|
|
173
173
|
renderResult(result: unknown, options: unknown, theme: unknown) {
|
|
174
174
|
return renderBackgroundTaskLogDisplay(result, options, theme);
|
|
@@ -338,7 +338,7 @@ function formatCompactStatus(meta: BackgroundTaskMeta): string {
|
|
|
338
338
|
if (meta.lastState !== undefined) lines.push(`last state: ${oneLine(meta.lastState, 800)}`);
|
|
339
339
|
if (meta.logDiscardedBytes) lines.push(`log retention: ${meta.logDiscardedBytes} bytes discarded in ${meta.logRetentionEvents ?? 1} compaction(s).`);
|
|
340
340
|
lines.push(`log: ${meta.logPath}`);
|
|
341
|
-
lines.push(`For full metadata use bg_task_status id=${meta.id} verbose=true. For logs use bg_task_log id=${meta.id} tail_lines=
|
|
341
|
+
lines.push(`For full metadata use bg_task_status id=${meta.id} verbose=true. For logs use bg_task_log id=${meta.id} tail_lines=5, or tail_lines=0 for the retained raw log.`);
|
|
342
342
|
return lines.join("\n");
|
|
343
343
|
}
|
|
344
344
|
|
|
@@ -360,7 +360,7 @@ function oneLine(value: unknown, maxLength: number): string {
|
|
|
360
360
|
function formatLog(id: string, tailLines?: number): string {
|
|
361
361
|
const meta = readMeta(id);
|
|
362
362
|
if (!meta) return `No background task found for id ${id}.`;
|
|
363
|
-
const log = readLog(meta.logPath, tailLines ??
|
|
363
|
+
const log = readLog(meta.logPath, tailLines ?? 5);
|
|
364
364
|
const prefix = log.truncated ? `[showing tail of ${meta.logPath}]\n` : `[${meta.logPath}]\n`;
|
|
365
365
|
return prefix + (log.text || "(log is empty)");
|
|
366
366
|
}
|