@yusukeshib/pi-babysit 0.6.27 → 0.6.29
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 +13 -6
- package/index.ts +104 -31
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -151,18 +151,25 @@ before local retention can collect their metadata.
|
|
|
151
151
|
| Command | What it does |
|
|
152
152
|
| ------- | ------------ |
|
|
153
153
|
| `/babysit` | Arrow-key picker over all sessions. Renders an **inline snapshot** (no tmux): running **process** → current rendered screen + recent output + a copy-paste `babysit attach` take-over hint (detach `Ctrl-\ Ctrl-\`); running **subagent** → read-only progress (RPC stdin stays untouchable); finished → summary. Re-run `/babysit` to refresh |
|
|
154
|
-
| `/babysit-log` | Pick any process or agent (running or finished) and put its shell-quoted `babysit log` command in Pi's input buffer for copying. Includes the local session namespace or remote host/worker ID. Does not execute the command or write to the clipboard |
|
|
155
154
|
| `/babysit gc [days]` | Preview and confirm deletion of old Pi-session roots (default 14 days). Active leases, live supervisor/child PIDs, unknown states, the current root, and recent roots are retained; old empty roots are eligible once their lease is gone. Deletion uses a GC lock and atomic rename |
|
|
156
155
|
|
|
157
|
-
The
|
|
156
|
+
The widget below the editor lists all running sessions, newest first,
|
|
158
157
|
including reusable idle agents. Summary counts use `RUNNING` / `IDLE`; rows show
|
|
159
158
|
`PROCESS RUNNING`, `AGENT RUNNING`, or `AGENT IDLE`, total session age, remote host
|
|
160
159
|
and unknown-status indicators when applicable, and a colored one-line description.
|
|
161
160
|
Older sessions fall back to their command or task. Rows truncate to terminal width
|
|
162
|
-
with
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
161
|
+
with `…`. In fullscreen mode, click the single `⧉` icon at the right edge of a row
|
|
162
|
+
to copy that session's shell-quoted `babysit log` command. It includes the local
|
|
163
|
+
`BABYSIT_DIR` or remote host/worker ID, without executing the command or changing
|
|
164
|
+
the input buffer. The icon changes in place: `…` while copying, `✓` on success,
|
|
165
|
+
or `!` on failure. The result stays visible for two seconds before returning to
|
|
166
|
+
`⧉`, including across list refreshes. Only the icon is clickable; rows never expand.
|
|
167
|
+
There is no paging, all/running toggle, keyboard handling, or log fetching. Very narrow widgets omit the icon.
|
|
168
|
+
Finished sessions disappear from the widget. Without mouse support, or for finished
|
|
169
|
+
sessions, use the keyboard picker `/babysit`; its snapshot includes the log command
|
|
170
|
+
for manual copying. The babysit tools also remain available to inspect output.
|
|
171
|
+
Transcript details from tool results, snapshots, and completion notifications still
|
|
172
|
+
use Pi's tool-output toggle (`Ctrl+O` by default).
|
|
166
173
|
|
|
167
174
|
## Logs without context flooding
|
|
168
175
|
|
package/index.ts
CHANGED
|
@@ -43,8 +43,8 @@ import type {
|
|
|
43
43
|
Theme,
|
|
44
44
|
ToolDefinition,
|
|
45
45
|
} from "@earendil-works/pi-coding-agent";
|
|
46
|
-
import { getMarkdownTheme } from "@earendil-works/pi-coding-agent";
|
|
47
|
-
import { Box, Markdown, Text, truncateToWidth } from "@earendil-works/pi-tui";
|
|
46
|
+
import { copyToClipboard, getMarkdownTheme } from "@earendil-works/pi-coding-agent";
|
|
47
|
+
import { Box, Markdown, Text, truncateToWidth, visibleWidth, type TuiMouseEvent } from "@earendil-works/pi-tui";
|
|
48
48
|
import { Type, type TSchema } from "typebox";
|
|
49
49
|
import { StringEnum } from "@earendil-works/pi-ai";
|
|
50
50
|
import { type AgentConfig, type AgentScope, discoverAgents } from "./agents";
|
|
@@ -2599,16 +2599,88 @@ export interface WidgetSessionDisplay {
|
|
|
2599
2599
|
description?: string;
|
|
2600
2600
|
}
|
|
2601
2601
|
|
|
2602
|
-
/**
|
|
2603
|
-
export function createWidgetComponent(
|
|
2602
|
+
/** Running-session list with an optional copy-log icon; never reads logs. */
|
|
2603
|
+
export function createWidgetComponent(
|
|
2604
|
+
summaryLines: string[],
|
|
2605
|
+
sessions: WidgetSessionDisplay[],
|
|
2606
|
+
onCopy?: (id: string) => void | Promise<void>,
|
|
2607
|
+
requestRender: () => void = () => {},
|
|
2608
|
+
) {
|
|
2609
|
+
let renderedWidth = 0;
|
|
2610
|
+
let disposed = false;
|
|
2611
|
+
const copyTargets = new Map<number, string>();
|
|
2612
|
+
const feedback = new Map<string, { icon: string; timer?: ReturnType<typeof setTimeout> }>();
|
|
2613
|
+
const clearFeedback = (id: string) => {
|
|
2614
|
+
clearTimeout(feedback.get(id)?.timer);
|
|
2615
|
+
feedback.delete(id);
|
|
2616
|
+
};
|
|
2617
|
+
const copy = (id: string) => {
|
|
2618
|
+
if (!onCopy || feedback.get(id)?.icon === "…") return;
|
|
2619
|
+
clearFeedback(id);
|
|
2620
|
+
const state: { icon: string; timer?: ReturnType<typeof setTimeout> } = { icon: "…" };
|
|
2621
|
+
feedback.set(id, state);
|
|
2622
|
+
requestRender();
|
|
2623
|
+
const finish = (icon: string) => {
|
|
2624
|
+
if (disposed || feedback.get(id) !== state) return;
|
|
2625
|
+
state.icon = icon;
|
|
2626
|
+
state.timer = setTimeout(() => {
|
|
2627
|
+
if (feedback.get(id) !== state) return;
|
|
2628
|
+
feedback.delete(id);
|
|
2629
|
+
requestRender();
|
|
2630
|
+
}, 2000);
|
|
2631
|
+
state.timer.unref?.();
|
|
2632
|
+
requestRender();
|
|
2633
|
+
};
|
|
2634
|
+
try {
|
|
2635
|
+
void Promise.resolve(onCopy(id)).then(() => finish("✓"), () => finish("!"));
|
|
2636
|
+
} catch {
|
|
2637
|
+
finish("!");
|
|
2638
|
+
}
|
|
2639
|
+
};
|
|
2604
2640
|
return {
|
|
2641
|
+
update(summary: string[], rows: WidgetSessionDisplay[]) {
|
|
2642
|
+
summaryLines = summary;
|
|
2643
|
+
sessions = rows;
|
|
2644
|
+
copyTargets.clear();
|
|
2645
|
+
const ids = new Set(rows.map((row) => row.id));
|
|
2646
|
+
for (const id of feedback.keys()) if (!ids.has(id)) clearFeedback(id);
|
|
2647
|
+
requestRender();
|
|
2648
|
+
},
|
|
2605
2649
|
render(width: number): string[] {
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2650
|
+
renderedWidth = Math.max(0, width);
|
|
2651
|
+
copyTargets.clear();
|
|
2652
|
+
const lines = summaryLines.map((line) => truncateToWidth(line, renderedWidth, "…"));
|
|
2653
|
+
for (const session of sessions) {
|
|
2654
|
+
const text = `${session.header}${session.description ? ` ${session.description}` : ""}`;
|
|
2655
|
+
if (onCopy && renderedWidth >= 3) {
|
|
2656
|
+
const content = truncateToWidth(text, renderedWidth - 2, "…");
|
|
2657
|
+
copyTargets.set(lines.length, session.id);
|
|
2658
|
+
lines.push(`${content}${" ".repeat(renderedWidth - 1 - visibleWidth(content))}${feedback.get(session.id)?.icon ?? "⧉"}`);
|
|
2659
|
+
} else {
|
|
2660
|
+
lines.push(truncateToWidth(text, renderedWidth, "…"));
|
|
2661
|
+
}
|
|
2662
|
+
}
|
|
2663
|
+
return lines;
|
|
2664
|
+
},
|
|
2665
|
+
handleMouse(event: TuiMouseEvent) {
|
|
2666
|
+
if (disposed || !onCopy || event.width !== renderedWidth || event.x !== renderedWidth - 1 ||
|
|
2667
|
+
event.button !== "left" || event.shift || event.alt || event.ctrl) return undefined;
|
|
2668
|
+
const id = copyTargets.get(event.y);
|
|
2669
|
+
if (!id) return undefined;
|
|
2670
|
+
if (event.type === "press") {
|
|
2671
|
+
copy(id);
|
|
2672
|
+
return { handled: true, render: true };
|
|
2673
|
+
}
|
|
2674
|
+
// Pi synthesizes a click after press/release; do not copy twice.
|
|
2675
|
+
if (event.type === "click" || event.type === "release") return { handled: true, render: false };
|
|
2676
|
+
return undefined;
|
|
2677
|
+
},
|
|
2678
|
+
invalidate() { copyTargets.clear(); },
|
|
2679
|
+
dispose() {
|
|
2680
|
+
disposed = true;
|
|
2681
|
+
copyTargets.clear();
|
|
2682
|
+
for (const id of feedback.keys()) clearFeedback(id);
|
|
2610
2683
|
},
|
|
2611
|
-
invalidate() {},
|
|
2612
2684
|
};
|
|
2613
2685
|
}
|
|
2614
2686
|
|
|
@@ -3511,6 +3583,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
3511
3583
|
}
|
|
3512
3584
|
}
|
|
3513
3585
|
|
|
3586
|
+
let sessionWidget: ReturnType<typeof createWidgetComponent> | undefined;
|
|
3514
3587
|
const refreshWidget = async (ctx: ExtensionContext, snapshot?: BsSession[]) => {
|
|
3515
3588
|
if (!ctx.hasUI) return;
|
|
3516
3589
|
const all = snapshot ?? (await listSessions()).sessions;
|
|
@@ -3544,10 +3617,22 @@ export default function (pi: ExtensionAPI) {
|
|
|
3544
3617
|
description: description ? theme.fg("warning", theme.bold(escapeCommandForDisplay(description))) : undefined,
|
|
3545
3618
|
};
|
|
3546
3619
|
});
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
3620
|
+
if (ctx.mode === "tui") {
|
|
3621
|
+
if (!sessionWidget) {
|
|
3622
|
+
ctx.ui.setWidget("pi-babysit", (tui) => {
|
|
3623
|
+
sessionWidget = createWidgetComponent(summaryLines, displays,
|
|
3624
|
+
(id) => copyToClipboard(sessionCliCommand(id, "log")),
|
|
3625
|
+
() => tui.requestRender());
|
|
3626
|
+
return sessionWidget;
|
|
3627
|
+
}, { placement: "belowEditor" });
|
|
3628
|
+
} else {
|
|
3629
|
+
sessionWidget.update(summaryLines, displays);
|
|
3630
|
+
}
|
|
3631
|
+
} else {
|
|
3632
|
+
ctx.ui.setWidget("pi-babysit", createWidgetComponent(summaryLines, displays).render(10_000), {
|
|
3633
|
+
placement: "belowEditor",
|
|
3634
|
+
});
|
|
3635
|
+
}
|
|
3551
3636
|
};
|
|
3552
3637
|
|
|
3553
3638
|
type DisplayStatus = "started" | "running" | "idle" | "success" | "failed" | "terminated";
|
|
@@ -3727,6 +3812,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
3727
3812
|
});
|
|
3728
3813
|
|
|
3729
3814
|
pi.on("session_shutdown", async (event) => {
|
|
3815
|
+
sessionWidget?.dispose();
|
|
3816
|
+
sessionWidget = undefined;
|
|
3730
3817
|
if (pollTimer) clearInterval(pollTimer);
|
|
3731
3818
|
pollTimer = undefined;
|
|
3732
3819
|
// Pi also emits session_shutdown while hot-reloading and switching sessions.
|
|
@@ -5069,22 +5156,6 @@ export default function (pi: ExtensionAPI) {
|
|
|
5069
5156
|
return sessions[labels.indexOf(choice)];
|
|
5070
5157
|
};
|
|
5071
5158
|
|
|
5072
|
-
pi.registerCommand("babysit-log", {
|
|
5073
|
-
description: "Pick a session and put its babysit log command in the input buffer (does not execute it)",
|
|
5074
|
-
handler: async (args, ctx) => {
|
|
5075
|
-
if (args.trim()) {
|
|
5076
|
-
ctx.ui.notify("Usage: /babysit-log", "error");
|
|
5077
|
-
return;
|
|
5078
|
-
}
|
|
5079
|
-
if (!ctx.hasUI) {
|
|
5080
|
-
ctx.ui.notify("/babysit-log requires an interactive UI.", "error");
|
|
5081
|
-
return;
|
|
5082
|
-
}
|
|
5083
|
-
const picked = await pickSession(ctx);
|
|
5084
|
-
if (picked) ctx.ui.setEditorText(sessionCliCommand(picked.id, "log"));
|
|
5085
|
-
},
|
|
5086
|
-
});
|
|
5087
|
-
|
|
5088
5159
|
// ----- /babysit -----------------------------------------------------------
|
|
5089
5160
|
// Arrow up/down picker over all sessions (like /stash). Renders an INLINE
|
|
5090
5161
|
// snapshot (no tmux): running process → current rendered screen + recent
|
|
@@ -5151,7 +5222,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
5151
5222
|
`(no structured output; full log: ${logPath(picked.id)})`) +
|
|
5152
5223
|
(picked.state === "running"
|
|
5153
5224
|
? "\n\n_Live subagent (read-only). Re-run `/babysit` to refresh this snapshot._"
|
|
5154
|
-
: "")
|
|
5225
|
+
: "") +
|
|
5226
|
+
`\n\n**Log command**\n\`\`\`sh\n${sessionCliCommand(picked.id, "log")}\n\`\`\``;
|
|
5155
5227
|
const title =
|
|
5156
5228
|
`${picked.id} ${picked.state}${elapsedSuffix}` +
|
|
5157
5229
|
(picked.exit_code != null ? ` (exit=${picked.exit_code})` : "") +
|
|
@@ -5198,7 +5270,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
5198
5270
|
: "(no output)") +
|
|
5199
5271
|
(running
|
|
5200
5272
|
? `\n\n_Take over in your own terminal:_ \`${attachCmd(picked.id)}\` _(detach: Ctrl-\\ Ctrl-\\)._ Re-run \`/babysit\` to refresh this snapshot.`
|
|
5201
|
-
: "")
|
|
5273
|
+
: "") +
|
|
5274
|
+
`\n\n**Log command**\n\`\`\`sh\n${sessionCliCommand(picked.id, "log")}\n\`\`\``;
|
|
5202
5275
|
const status: DisplayStatus = running
|
|
5203
5276
|
? "running"
|
|
5204
5277
|
: picked.exit_code === 0
|