repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

fix(tune): gate tools and sticky dashboard header

658236d9134955fc154a044ba78d912da55668cf

Review <review@example.invalid> ·

unsigned

Browse filesCompare with HEAD

Changed files (5)

CHANGELOG.md

Modified
67 67 - Move tune session state to `.pi/tune/`
68 68 - Restyle tune dashboard with the Nugu diff-review palette, theme selector,
69 69 cards, side drawer, chart, and live session.jsonl refresh
70 +- Fix tune dashboard runs-table sticky header positioning with measured topbar
71 + height, overflow-visible table panels, and chart-only clipping so the header
72 + stays below the topbar while scrolling
70 73 - Add jj-native tune keep/discard flow and exclusive tune repo lock
71 74 - Render clamped `run_experiment` timeout values consistently with execution
72 75 semantics

extensions/tune/__tests__/remaining.test.ts

Modified
161 161 expect(template).toContain("Nugu dark palette");
162 162 expect(template).toContain("diff-review-theme");
165 + it("uses measured topbar height for sticky table header", () => {
166 + const template = fs.readFileSync(__test.dashboardTemplatePath(), "utf-8");
168 + expect(template).toContain("--topbar-height");
169 + expect(template).toContain("top: var(--topbar-height)");
170 + expect(template).toContain("syncTopbarHeight");
171 + expect(template).toContain("ResizeObserver");
172 + expect(template).not.toContain("top: 63px");
173 + expect(template).not.toContain(
174 + ".panel { margin-top: 14px; overflow: hidden; }",
175 + );
176 + });

extensions/tune/__tests__/unit.test.ts

Modified
15 15 reconstructJsonlState,
16 16 } from "../jsonl.ts";
18 +// ── Dashboard HTML ────────────────────────────────────────────────────────
20 +describe("dashboard template", () => {
21 + it("keeps the runs table header below the sticky topbar", () => {
22 + const html = fs.readFileSync(
23 + path.join(import.meta.dirname, "..", "assets", "template.html"),
24 + "utf8",
25 + );
27 + expect(html).toContain("th { position: sticky; top: var(--topbar-height);");
28 + expect(html).not.toContain("th { position: sticky; top: 63px;");
29 + });
30 +});
18 32 // ── Metric line parsing ───────────────────────────────────────────────────
20 34 describe("parseMetricLines", () => {
228 +// ── Tune tool activation ──────────────────────────────────────────
230 +describe("tune tool activation", () => {
231 + it("disables only tune tools", () => {
232 + let activeTools = ["read", "init_experiment", "bash", "log_experiment"];
233 + const pi = {
234 + getActiveTools: () => activeTools,
235 + setActiveTools: (names: string[]) => {
236 + activeTools = names;
237 + },
238 + } as never;
240 + __test.setTuneToolsActive(pi, false);
242 + expect(activeTools).toEqual(["read", "bash"]);
243 + });
245 + it("enables tune tools without dropping existing tools", () => {
246 + let activeTools = ["read", "bash"];
247 + const pi = {
248 + getActiveTools: () => activeTools,
249 + setActiveTools: (names: string[]) => {
250 + activeTools = names;
251 + },
252 + } as never;
254 + __test.setTuneToolsActive(pi, true);
255 + __test.setTuneToolsActive(pi, true);
257 + expect(activeTools).toEqual([
258 + "read",
259 + "bash",
260 + "init_experiment",
261 + "run_experiment",
262 + "log_experiment",
263 + ]);
264 + });
265 +});
214 267 // ── /tune autocomplete ────────────────────────────────────────────
216 269 describe("tune autocomplete", () => {

extensions/tune/assets/template.html

Modified
52 52 --border: color-mix(in srgb, var(--nugu-ui-normal) 14%, transparent);
53 53 --shadow: 0 18px 60px color-mix(in srgb, #000 45%, transparent);
54 54 --radius: 12px;
55 + --topbar-height: 0px;
55 56 font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
56 57 background: var(--bg);
57 58 color: var(--fg);
154 155 .value { margin-top: 7px; color: var(--nugu-content-important-global); font-size: 24px; font-weight: 850; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
155 156 .value.good { color: var(--nugu-info); }
156 157 .value.bad { color: var(--nugu-error); }
157 - .panel { margin-top: 14px; overflow: hidden; }
158 - .chart-wrap { height: 320px; padding: 12px; background: color-mix(in srgb, var(--panel-2) 38%, transparent); }
158 + .panel { margin-top: 14px; }
159 + .chart-wrap { height: 320px; padding: 12px; overflow: hidden; background: color-mix(in srgb, var(--panel-2) 38%, transparent); }
159 160 canvas { width: 100%; height: 100%; display: block; }
161 162 #drawer {
187 188 table { width: 100%; border-collapse: collapse; font-size: 12px; }
188 189 th, td { padding: 10px; border-bottom: 1px solid color-mix(in srgb, var(--border) 62%, transparent); text-align: left; vertical-align: top; }
189 - th { position: sticky; top: 63px; background: color-mix(in srgb, var(--bg) 92%, var(--panel)); color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; white-space: nowrap; z-index: 2; }
190 + th { position: sticky; top: var(--topbar-height); background: color-mix(in srgb, var(--bg) 92%, var(--panel)); color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; white-space: nowrap; z-index: 2; }
190 191 td { color: color-mix(in srgb, var(--fg) 88%, var(--muted)); }
191 192 .status { display: inline-block; padding: 2px 7px; border-radius: 999px; font-weight: 800; font-size: 11px; }
192 193 .status.keep { color: var(--nugu-info); background: color-mix(in srgb, var(--nugu-info) 14%, transparent); border: 1px solid color-mix(in srgb, var(--nugu-info) 28%, var(--border)); }
224 225 #app { grid-template-columns: 1fr; }
225 226 #drawer { border-width: 1px 0 0; }
226 227 .cards { grid-template-columns: 1fr 1fr; }
227 - th { top: 0; }
229 229 @media (max-width: 620px) {
230 230 #topbar { align-items: flex-start; flex-direction: column; }
303 303 start();
304 304 function start() {
305 305 wireTheme();
306 + wireTopbar();
306 307 refresh();
307 308 if (typeof EventSource !== "undefined") {
308 309 const events = new EventSource("/events");
309 310 events.addEventListener("jsonl-updated", refresh);
310 311 events.onerror = () => setStatus("Live update disconnected; waiting…", true);
312 - window.addEventListener("resize", drawChart);
313 + window.addEventListener("resize", () => { syncTopbarHeight(); drawChart(); });
316 + function wireTopbar() {
317 + syncTopbarHeight();
318 + const topbar = document.getElementById("topbar");
319 + if (typeof ResizeObserver !== "undefined") new ResizeObserver(syncTopbarHeight).observe(topbar);
321 + function syncTopbarHeight() {
322 + const topbar = document.getElementById("topbar");
323 + document.documentElement.style.setProperty("--topbar-height", `${topbar.offsetHeight}px`);
315 326 function wireTheme() {
375 386 function render() {
387 + syncTopbarHeight();
376 388 const baseline = state.runs[0]?.metric ?? null;
377 389 const best = bestRun();
378 390 document.title = state.config.name;

extensions/tune/index.ts

Modified
62 62 const EXPERIMENT_MAX_BYTES = 4 * 1024;
64 64 const STATE_DIR = ".pi/tune";
65 +const TUNE_TOOL_NAMES = [
66 + "init_experiment",
67 + "run_experiment",
68 + "log_experiment",
69 +] as const;
65 70 const TUNE_SUBCOMMAND_COMPLETIONS: AutocompleteItem[] = [
66 71 { value: "off", label: "off", description: "Turn tune mode off" },
1122 1127 return items ? { prefix, items } : null;
1130 +function setTuneToolsActive(pi: ExtensionAPI, active: boolean): void {
1131 + const names = pi.getActiveTools();
1132 + const tuneNames = new Set<string>(TUNE_TOOL_NAMES);
1133 + const next = active
1134 + ? [...names, ...TUNE_TOOL_NAMES.filter((name) => !names.includes(name))]
1135 + : names.filter((name) => !tuneNames.has(name));
1136 + if (
1137 + next.length === names.length &&
1138 + next.every((name, i) => name === names[i])
1140 + return;
1141 + pi.setActiveTools(next);
1125 1144 // ── Exported test helpers ─────────────────────────────────────────────────
1127 1146 export const __test = {
1131 1150 dashboardTemplatePath,
1132 1151 tuneArgumentCompletions,
1133 1152 tuneCommandArgumentSuggestions,
1153 + setTuneToolsActive,
1134 1154 acquireTuneLock,
1135 1155 ownsTuneLock,
1136 1156 releaseTuneLock,
1662 1682 // ── Lifecycle hooks ─────────────────────────────────────────────────
1664 - pi.on("session_start", async (_e, ctx) => reconstructState(ctx));
1684 + pi.on("session_start", async (_e, ctx) => {
1685 + reconstructState(ctx);
1686 + setTuneToolsActive(pi, getRuntime(ctx).tuneMode);
1687 + });
1665 1688 pi.on("session_start", async (_e, ctx) => {
1666 1689 if (typeof ctx.ui.addAutocompleteProvider !== "function") return;
1667 1690 ctx.ui.addAutocompleteProvider((current) => ({
1696 - pi.on("session_tree", async (_e, ctx) => reconstructState(ctx));
1719 + pi.on("session_tree", async (_e, ctx) => {
1720 + reconstructState(ctx);
1721 + setTuneToolsActive(pi, getRuntime(ctx).tuneMode);
1722 + });
1697 1723 pi.on("session_before_switch", async () => clearOverlay());
1698 1724 pi.on("session_shutdown", async (_e, ctx) => {
1725 + setTuneToolsActive(pi, false);
1699 1726 clearSessionUi(ctx);
1700 1727 cancelPendingResume(getRuntime(ctx));
1701 1728 releaseTuneLock(ctx.cwd, getSessionKey(ctx));
1802 1829 parameters: InitParams,
1804 1831 async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
1832 + const runtime = getRuntime(ctx);
1833 + if (!runtime.tuneMode) {
1834 + return {
1835 + content: [
1837 + type: "text",
1838 + text: "❌ Tune is not active. Start with /tune <goal>.",
1839 + },
1840 + ],
1841 + details: {},
1842 + };
1805 1844 const lock = acquireTuneLock(ctx.cwd, getSessionKey(ctx));
1806 1845 if (!lock.ok) {
1807 1846 return {
1814 1853 details: {},
1817 - const runtime = getRuntime(ctx);
1818 - runtime.tuneMode = true;
1819 1856 const state = runtime.state;
1820 1857 const isReinit = state.results.length > 0;
1928 1965 const runtime = getRuntime(ctx);
1929 1966 const state = runtime.state;
1930 1967 const cwd = ctx.cwd;
1931 - if (!ownsTuneLock(cwd, getSessionKey(ctx))) {
1968 + if (!runtime.tuneMode || !ownsTuneLock(cwd, getSessionKey(ctx))) {
1932 1969 return {
1933 1970 content: [
1934 1971 { type: "text", text: "❌ Tune is not active in this session." },
2439 2476 const runtime = getRuntime(ctx);
2440 2477 const state = runtime.state;
2441 2478 const cwd = ctx.cwd;
2442 - if (!ownsTuneLock(cwd, getSessionKey(ctx))) {
2479 + if (!runtime.tuneMode || !ownsTuneLock(cwd, getSessionKey(ctx))) {
2443 2480 return {
2444 2481 content: [
2445 2482 { type: "text", text: "❌ Tune is not active in this session." },
2670 2707 if (limitReached) {
2671 2708 text += `\n\n🛑 Maximum experiments reached (${state.maxExperiments}). STOP.`;
2672 2709 runtime.tuneMode = false;
2710 + setTuneToolsActive(pi, false);
2673 2711 releaseTuneLock(cwd, getSessionKey(ctx));
2674 2712 ctx.abort();
2675 2713 } else if (runtime.tuneMode) {
3149 3187 const wasRunning = !ctx.isIdle();
3150 3188 releaseTuneLock(ctx.cwd, getSessionKey(ctx));
3151 3189 runtime.tuneMode = false;
3190 + setTuneToolsActive(pi, false);
3152 3191 runtime.dashboardExpanded = false;
3153 3192 runtime.autoResumeTurns = 0;
3154 3193 runtime.experimentsThisSession = 0;
3175 3214 releaseTuneLock(ctx.cwd, getSessionKey(ctx));
3176 3215 const jsonlPath = tuneJsonlPath(ctx.cwd);
3177 3216 runtime.tuneMode = false;
3217 + setTuneToolsActive(pi, false);
3178 3218 runtime.dashboardExpanded = false;
3179 3219 runtime.autoResumeTurns = 0;
3180 3220 runtime.experimentsThisSession = 0;
3219 3259 runtime.tuneMode = true;
3260 + setTuneToolsActive(pi, true);
3220 3261 runtime.autoResumeTurns = 0;
3222 3263 const rulesLoaded = hasTuneRules(ctx);