refactor(coding-agent): add runtime host for session switching closes #2024

This commit is contained in:
Mario Zechner
2026-03-31 13:49:57 +02:00
parent a3bf1eb399
commit d86122cbd3
32 changed files with 1328 additions and 692 deletions

View File

@@ -33,10 +33,6 @@ export default function (pi: ExtensionAPI) {
applyLabel(ctx);
});
pi.on("session_switch", async (_event, ctx) => {
applyLabel(ctx);
});
pi.registerCommand("thinking-label", {
description: "Set the hidden thinking label. Use without args to reset.",
handler: async (args, ctx) => {

View File

@@ -13,7 +13,7 @@
* - notify() - after each dialog completes
* - setStatus() - on turn_start/turn_end
* - setWidget() - on session_start
* - setTitle() - on session_start and session_switch
* - setTitle() - on session_start
* - setEditorText() - via /rpc-prefill command
*/
@@ -24,18 +24,12 @@ export default function (pi: ExtensionAPI) {
// -- setTitle, setWidget, setStatus on session lifecycle --
pi.on("session_start", async (_event, ctx) => {
ctx.ui.setTitle("pi RPC Demo");
pi.on("session_start", async (event, ctx) => {
ctx.ui.setTitle(event.reason === "new" ? "pi RPC Demo (new session)" : "pi RPC Demo");
ctx.ui.setWidget("rpc-demo", ["--- RPC Extension UI Demo ---", "Loaded and ready."]);
ctx.ui.setStatus("rpc-demo", `Turns: ${turnCount}`);
});
pi.on("session_switch", async (_event, ctx) => {
turnCount = 0;
ctx.ui.setTitle("pi RPC Demo (new session)");
ctx.ui.setStatus("rpc-demo", `Turns: ${turnCount}`);
});
// -- setStatus on turn lifecycle --
pi.on("turn_start", async (_event, ctx) => {

View File

@@ -29,12 +29,4 @@ export default function (pi: ExtensionAPI) {
const text = theme.fg("dim", ` Turn ${turnCount} complete`);
ctx.ui.setStatus("status-demo", check + text);
});
pi.on("session_switch", async (event, ctx) => {
if (event.reason === "new") {
turnCount = 0;
const theme = ctx.ui.theme;
ctx.ui.setStatus("status-demo", theme.fg("dim", "Ready"));
}
});
}

View File

@@ -130,8 +130,6 @@ export default function (pi: ExtensionAPI) {
// Reconstruct state on session events
pi.on("session_start", async (_event, ctx) => reconstructState(ctx));
pi.on("session_switch", async (_event, ctx) => reconstructState(ctx));
pi.on("session_fork", async (_event, ctx) => reconstructState(ctx));
pi.on("session_tree", async (_event, ctx) => reconstructState(ctx));
// Register the todo tool for the LLM

View File

@@ -138,9 +138,4 @@ export default function toolsExtension(pi: ExtensionAPI) {
pi.on("session_tree", async (_event, ctx) => {
restoreFromBranch(ctx);
});
// Restore state after forking
pi.on("session_fork", async (_event, ctx) => {
restoreFromBranch(ctx);
});
}

View File

@@ -1,17 +1,9 @@
import type { ExtensionAPI, ExtensionContext } from "@mariozechner/pi-coding-agent";
const applyWidgets = (ctx: ExtensionContext) => {
if (!ctx.hasUI) return;
ctx.ui.setWidget("widget-above", ["Above editor widget"]);
ctx.ui.setWidget("widget-below", ["Below editor widget"], { placement: "belowEditor" });
};
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
export default function widgetPlacementExtension(pi: ExtensionAPI) {
pi.on("session_start", (_event, ctx) => {
applyWidgets(ctx);
});
pi.on("session_switch", (_event, ctx) => {
applyWidgets(ctx);
if (!ctx.hasUI) return;
ctx.ui.setWidget("widget-above", ["Above editor widget"]);
ctx.ui.setWidget("widget-below", ["Below editor widget"], { placement: "belowEditor" });
});
}