repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

Rename tune extension internal symbols from autoresearch to tune; verify tests and build

4bea83083bf008f1ce28952f66b28285f08ad2f4

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Result: {"status":"keep","wall_time":500,"tests_passed":44,"failures":0}

Changed files (7)

extensions/tune/__tests__/remaining.test.ts

Modified
2 2 import { beforeAll, describe, expect, it } from "bun:test";
3 3 import * as fs from "node:fs";
4 4 import * as path from "node:path";
5 5 import {
6 - buildAutoresearchCompactionSummary,
7 - autoresearchSummaryPathsFor,
6 + buildTuneCompactionSummary,
7 + tuneSummaryPathsFor,
8 8 } from "../compaction.ts";
9 9 import { reconstructJsonlState } from "../jsonl.ts";
10 10 import { hookScriptPath } from "../hooks.ts";
11 -import { resolveAutoresearchShortcuts } from "../shortcuts.ts";
11 +import { resolveTuneShortcuts } from "../shortcuts.ts";
12 12 import { __test } from "../index.ts";
14 14 const TESTDIR = "/tmp/pi-ext-20260530-164209-project";
31 31 describe("compaction resume", () => {
32 32 it("builds summary from live session.jsonl", () => {
33 - const paths = autoresearchSummaryPathsFor(TESTDIR);
34 - const summary = buildAutoresearchCompactionSummary(paths);
33 + const paths = tuneSummaryPathsFor(TESTDIR);
34 + const summary = buildTuneCompactionSummary(paths);
36 36 expect(summary).toContain("Tune Compaction Summary");
37 37 expect(summary).toContain("## Session");
48 48 it("includes run metrics and deltas", () => {
49 - const paths = autoresearchSummaryPathsFor(TESTDIR);
50 - const summary = buildAutoresearchCompactionSummary(paths);
49 + const paths = tuneSummaryPathsFor(TESTDIR);
50 + const summary = buildTuneCompactionSummary(paths);
52 52 // Run 1 baseline=7ms, run 3 best=1ms → should show delta
53 53 expect(summary).toContain("7");
57 57 it("reconstructs correct state for compaction", () => {
58 - const paths = autoresearchSummaryPathsFor(TESTDIR);
58 + const paths = tuneSummaryPathsFor(TESTDIR);
59 59 const jsonl = fs.readFileSync(paths.jsonlPath, "utf-8");
60 60 const state = reconstructJsonlState(jsonl);
69 69 it("confidence=2 for run 3 (real improvement)", () => {
70 - const paths = autoresearchSummaryPathsFor(TESTDIR);
70 + const paths = tuneSummaryPathsFor(TESTDIR);
71 71 const jsonl = fs.readFileSync(paths.jsonlPath, "utf-8");
72 72 const state = reconstructJsonlState(jsonl);
73 73 const run3 = state.results.find((r) => r.run === 3);
104 104 describe("shortcuts", () => {
105 105 it("returns defaults when no config file", () => {
106 - const s = resolveAutoresearchShortcuts("/nonexistent/path");
106 + const s = resolveTuneShortcuts("/nonexistent/path");
107 107 expect(s.toggleDashboard).toBe("ctrl+shift+t");
108 108 expect(s.fullscreenDashboard).toBe("ctrl+shift+f");

extensions/tune/__tests__/unit.test.ts

Modified
3 3 import { DEFAULT_MAX_LINES } from "@earendil-works/pi-coding-agent";
4 4 import { describe, expect, it } from "bun:test";
5 5 import { __test } from "../index.ts";
6 6 import {
7 7 parseJsonlEntry,
8 - isAutoresearchConfigEntry,
9 - isAutoresearchRunEntry,
8 + isTuneConfigEntry,
9 + isTuneRunEntry,
10 10 reconstructJsonlState,
11 - hasAutoresearchConfigHeader,
12 - extractAutoresearchSessionName,
11 + hasTuneConfigHeader,
12 + extractTuneSessionName,
13 13 } from "../jsonl.ts";
14 -import { buildAutoresearchCompactionSummary } from "../compaction.ts";
14 +import { buildTuneCompactionSummary } from "../compaction.ts";
15 15 import { hookScriptPath } from "../hooks.ts";
17 17 // ── Metric line parsing ───────────────────────────────────────────────────
148 -describe("isAutoresearchConfigEntry", () => {
148 +describe("isTuneConfigEntry", () => {
149 149 it("recognizes config entries", () => {
150 - expect(isAutoresearchConfigEntry({ type: "config" })).toBe(true);
150 + expect(isTuneConfigEntry({ type: "config" })).toBe(true);
153 153 it("rejects run entries", () => {
154 - expect(isAutoresearchConfigEntry({ type: "run", run: 1 })).toBe(false);
154 + expect(isTuneConfigEntry({ type: "run", run: 1 })).toBe(false);
158 -describe("isAutoresearchRunEntry", () => {
158 +describe("isTuneRunEntry", () => {
159 159 it("recognizes run entries", () => {
160 - expect(isAutoresearchRunEntry({ run: 1, metric: 42 })).toBe(true);
160 + expect(isTuneRunEntry({ run: 1, metric: 42 })).toBe(true);
163 163 it("rejects non-run entries", () => {
164 - expect(isAutoresearchRunEntry({ type: "config" })).toBe(false);
164 + expect(isTuneRunEntry({ type: "config" })).toBe(false);
168 -describe("hasAutoresearchConfigHeader", () => {
168 +describe("hasTuneConfigHeader", () => {
169 169 it("detects config header", () => {
170 170 const content = '{"type":"config","name":"test"}\n{"run":1}\n';
171 - expect(hasAutoresearchConfigHeader(content)).toBe(true);
171 + expect(hasTuneConfigHeader(content)).toBe(true);
174 174 it("returns false for no config", () => {
175 175 const content = '{"run":1}\n{"run":2}\n';
176 - expect(hasAutoresearchConfigHeader(content)).toBe(false);
176 + expect(hasTuneConfigHeader(content)).toBe(false);
180 -describe("extractAutoresearchSessionName", () => {
180 +describe("extractTuneSessionName", () => {
181 181 it("extracts name from config", () => {
182 182 const content = '{"type":"config","name":"Optimize tests"}\n';
183 - expect(extractAutoresearchSessionName(content)).toBe("Optimize tests");
183 + expect(extractTuneSessionName(content)).toBe("Optimize tests");
186 186 it("returns default when no config", () => {
187 - expect(extractAutoresearchSessionName('{"run":1}\n')).toBe("Tune");
187 + expect(extractTuneSessionName('{"run":1}\n')).toBe("Tune");
231 231 // ── Compaction summary ────────────────────────────────────────────────────
233 -describe("buildAutoresearchCompactionSummary", () => {
233 +describe("buildTuneCompactionSummary", () => {
234 234 it("produces a summary with no data", () => {
235 235 const paths = {
236 236 workDir: "/tmp/nonexistent",
238 238 mdPath: "/tmp/nonexistent/session.md",
239 239 ideasPath: "/tmp/nonexistent/ideas.md",
241 - const summary = buildAutoresearchCompactionSummary(paths);
241 + const summary = buildTuneCompactionSummary(paths);
242 242 expect(summary).toContain("Tune Compaction Summary");
243 243 expect(summary).toContain("Runs so far: 0");
244 244 expect(summary).toContain("Next Step");

extensions/tune/compaction.ts

Modified
24 24 type RunStatus = ReconstructedRun["status"];
25 25 type StatusCounts = Record<RunStatus, number>;
27 -export interface AutoresearchSummaryPaths {
27 +export interface TuneSummaryPaths {
28 28 workDir: string;
29 29 jsonlPath: string;
30 30 mdPath: string;
31 31 ideasPath: string;
34 -export function autoresearchSummaryPathsFor(workDir: string): AutoresearchSummaryPaths {
34 +export function tuneSummaryPathsFor(workDir: string): TuneSummaryPaths {
35 35 const base = path.join(workDir, ".pi", "tune");
36 36 return {
37 37 workDir,
44 44 // ── Public API ────────────────────────────────────────────────────────────
46 -export function buildAutoresearchCompactionSummary(paths: AutoresearchSummaryPaths): string {
46 +export function buildTuneCompactionSummary(paths: TuneSummaryPaths): string {
47 47 const state = loadState(paths.jsonlPath);
48 48 return [
49 49 headerSection(),

extensions/tune/hooks.ts

Modified
9 9 import * as fs from "node:fs";
10 10 import * as path from "node:path";
12 -import { hasAutoresearchConfigHeader } from "./jsonl.ts";
12 +import { hasTuneConfigHeader } from "./jsonl.ts";
14 14 // ── Constants ─────────────────────────────────────────────────────────────
180 180 function hasConfigHeader(jsonlPath: string): boolean {
181 181 if (!fs.existsSync(jsonlPath)) return false;
183 - return hasAutoresearchConfigHeader(fs.readFileSync(jsonlPath, "utf-8"));
183 + return hasTuneConfigHeader(fs.readFileSync(jsonlPath, "utf-8"));
184 184 } catch {
185 185 return false;

extensions/tune/index.ts

Modified
42 42 } from "./hooks.ts";
43 43 import {
44 44 parseJsonlEntry,
45 - isAutoresearchRunEntry,
46 - extractAutoresearchSessionName,
45 + isTuneRunEntry,
46 + extractTuneSessionName,
47 47 reconstructJsonlState,
48 48 } from "./jsonl.ts";
49 49 import {
50 - autoresearchSummaryPathsFor,
51 - buildAutoresearchCompactionSummary,
50 + tuneSummaryPathsFor,
51 + buildTuneCompactionSummary,
52 52 } from "./compaction.ts";
53 -import { resolveAutoresearchShortcuts } from "./shortcuts.ts";
53 +import { resolveTuneShortcuts } from "./shortcuts.ts";
55 55 // ── Constants ─────────────────────────────────────────────────────────────
125 125 wallClockSeconds: number | null;
128 -interface AutoresearchRuntime {
129 - autoresearchMode: boolean;
128 +interface TuneRuntime {
129 + tuneMode: boolean;
130 130 dashboardExpanded: boolean;
131 131 experimentsThisSession: number;
132 132 autoResumeTurns: number;
342 342 // ── State path helpers ────────────────────────────────────────────────────
344 344 const stateDir = (dir: string) => path.join(dir, STATE_DIR);
345 -const autoresearchJsonlPath = (dir: string) => path.join(stateDir(dir), "session.jsonl");
346 -const autoresearchMdPath = (dir: string) => path.join(stateDir(dir), "session.md");
347 -const autoresearchIdeasPath = (dir: string) => path.join(stateDir(dir), "ideas.md");
348 -const autoresearchChecksPath = (dir: string) => path.join(stateDir(dir), "checks.mjs");
349 -const autoresearchScriptPath = (dir: string) => path.join(stateDir(dir), "benchmark.mjs");
350 -const autoresearchConfigPath = (dir: string) => path.join(stateDir(dir), "config.json");
345 +const tuneJsonlPath = (dir: string) => path.join(stateDir(dir), "session.jsonl");
346 +const tuneMdPath = (dir: string) => path.join(stateDir(dir), "session.md");
347 +const tuneIdeasPath = (dir: string) => path.join(stateDir(dir), "ideas.md");
348 +const tuneChecksPath = (dir: string) => path.join(stateDir(dir), "checks.mjs");
349 +const tuneScriptPath = (dir: string) => path.join(stateDir(dir), "benchmark.mjs");
350 +const tuneConfigPath = (dir: string) => path.join(stateDir(dir), "config.json");
352 352 function findBaselineMetric(results: ExperimentResult[], segment: number): number | null {
353 353 const cur = currentResults(results, segment);
398 398 function readMaxExperiments(cwd: string): number | null {
400 - const configPath = autoresearchConfigPath(cwd);
400 + const configPath = tuneConfigPath(cwd);
401 401 if (!fs.existsSync(configPath)) return null;
402 402 const config = JSON.parse(fs.readFileSync(configPath, "utf-8"));
403 403 return typeof config.maxIterations === "number" && config.maxIterations > 0
439 -function createSessionRuntime(): AutoresearchRuntime {
439 +function createSessionRuntime(): TuneRuntime {
440 440 return {
441 - autoresearchMode: false,
441 + tuneMode: false,
442 442 dashboardExpanded: false,
443 443 experimentsThisSession: 0,
444 444 autoResumeTurns: 0,
454 454 function createRuntimeStore() {
455 - const runtimes = new Map<string, AutoresearchRuntime>();
455 + const runtimes = new Map<string, TuneRuntime>();
456 456 return {
457 - ensure(sessionKey: string): AutoresearchRuntime {
457 + ensure(sessionKey: string): TuneRuntime {
458 458 let runtime = runtimes.get(sessionKey);
459 459 if (!runtime) {
460 460 runtime = createSessionRuntime();
872 872 // ── Extension ─────────────────────────────────────────────────────────────
874 -export default function autoresearchExtension(pi: ExtensionAPI) {
874 +export default function tuneExtension(pi: ExtensionAPI) {
875 875 const MAX_AUTORESUME_TURNS = 20;
876 876 const BENCHMARK_GUARDRAIL =
877 877 "Be careful not to overfit to the benchmarks and do not cheat on the benchmarks.";
878 878 const SETTLED_WINDOW_MS = 800;
879 - const shortcuts = resolveAutoresearchShortcuts();
879 + const shortcuts = resolveTuneShortcuts();
881 881 const dashboardHintVariants = (toggleAction: "expand" | "collapse"): string[] => {
882 882 const toggle = shortcuts.toggleDashboard
898 898 const runtimeStore = createRuntimeStore();
899 899 const getSessionKey = (ctx: ExtensionContext) => ctx.sessionManager.getSessionId();
900 - const getRuntime = (ctx: ExtensionContext): AutoresearchRuntime =>
900 + const getRuntime = (ctx: ExtensionContext): TuneRuntime =>
901 901 runtimeStore.ensure(getSessionKey(ctx));
903 903 const isAgentSettled = (ctx: ExtensionContext): boolean =>
904 904 ctx.isIdle() && !ctx.hasPendingMessages();
906 - const hasPendingResume = (runtime: AutoresearchRuntime): boolean =>
906 + const hasPendingResume = (runtime: TuneRuntime): boolean =>
907 907 runtime.pendingResumeMessage !== null;
909 - const pausePendingResume = (runtime: AutoresearchRuntime): void => {
909 + const pausePendingResume = (runtime: TuneRuntime): void => {
910 910 if (!runtime.pendingResumeTimer) return;
911 911 clearTimeout(runtime.pendingResumeTimer);
912 912 runtime.pendingResumeTimer = null;
915 - const cancelPendingResume = (runtime: AutoresearchRuntime): void => {
915 + const cancelPendingResume = (runtime: TuneRuntime): void => {
916 916 pausePendingResume(runtime);
917 917 runtime.pendingResumeMessage = null;
920 - const markAutoResumeSent = (runtime: AutoresearchRuntime): void => {
920 + const markAutoResumeSent = (runtime: TuneRuntime): void => {
921 921 runtime.autoResumeTurns++;
924 924 const sendPendingResumeIfReady = (
925 925 ctx: ExtensionContext,
926 - runtime: AutoresearchRuntime,
926 + runtime: TuneRuntime,
927 927 ): void => {
928 928 const message = runtime.pendingResumeMessage;
929 929 if (!message) return;
930 - if (!runtime.autoresearchMode) {
930 + if (!runtime.tuneMode) {
931 931 cancelPendingResume(runtime);
932 932 return;
945 945 const schedulePendingResume = (
946 946 ctx: ExtensionContext,
947 - runtime: AutoresearchRuntime,
947 + runtime: TuneRuntime,
948 948 message: string,
949 949 ): void => {
950 950 pausePendingResume(runtime);
958 958 const reschedulePendingResume = (
959 959 ctx: ExtensionContext,
960 - runtime: AutoresearchRuntime,
960 + runtime: TuneRuntime,
961 961 ): void => {
962 962 if (!hasPendingResume(runtime)) return;
963 963 schedulePendingResume(ctx, runtime, runtime.pendingResumeMessage!);
966 - const hasRunExperimentsThisSession = (runtime: AutoresearchRuntime): boolean =>
966 + const hasRunExperimentsThisSession = (runtime: TuneRuntime): boolean =>
967 967 runtime.experimentsThisSession > 0;
969 - const shouldAutoResumeAfterTurn = (runtime: AutoresearchRuntime): boolean =>
970 - runtime.autoresearchMode && hasRunExperimentsThisSession(runtime);
969 + const shouldAutoResumeAfterTurn = (runtime: TuneRuntime): boolean =>
970 + runtime.tuneMode && hasRunExperimentsThisSession(runtime);
972 - const shouldAutoResumeAfterCompact = (runtime: AutoresearchRuntime): boolean =>
973 - runtime.autoresearchMode;
972 + const shouldAutoResumeAfterCompact = (runtime: TuneRuntime): boolean =>
973 + runtime.tuneMode;
975 - const hasReachedAutoResumeLimit = (runtime: AutoresearchRuntime): boolean =>
975 + const hasReachedAutoResumeLimit = (runtime: TuneRuntime): boolean =>
976 976 runtime.autoResumeTurns >= MAX_AUTORESUME_TURNS;
978 978 const notifyAutoResumeLimitReached = (ctx: ExtensionContext): void => {
999 999 ].join(" ");
1002 - const autoresearchCompactionFor = (
1002 + const tuneCompactionFor = (
1003 1003 ctx: ExtensionContext,
1004 1004 event: SessionBeforeCompactEvent,
1006 - if (!getRuntime(ctx).autoresearchMode) return undefined;
1006 + if (!getRuntime(ctx).tuneMode) return undefined;
1007 1007 return {
1008 1008 compaction: {
1009 - summary: buildAutoresearchCompactionSummary(
1010 - autoresearchSummaryPathsFor(ctx.cwd),
1009 + summary: buildTuneCompactionSummary(
1010 + tuneSummaryPathsFor(ctx.cwd),
1012 1012 firstKeptEntryId: event.preparation.firstKeptEntryId,
1013 1013 tokensBefore: event.preparation.tokensBefore,
1023 1023 pi.sendUserMessage(message, { deliverAs: "followUp" });
1026 - const hasAutoresearchRules = (ctx: ExtensionContext): boolean =>
1027 - fs.existsSync(autoresearchMdPath(ctx.cwd));
1026 + const hasTuneRules = (ctx: ExtensionContext): boolean =>
1027 + fs.existsSync(tuneMdPath(ctx.cwd));
1029 1029 const readJsonlLines = (cwd: string): string[] => {
1030 - const jsonlPath = autoresearchJsonlPath(cwd);
1030 + const jsonlPath = tuneJsonlPath(cwd);
1031 1031 if (!fs.existsSync(jsonlPath)) return [];
1032 1032 return fs.readFileSync(jsonlPath, "utf-8").split("\n").filter(Boolean);
1036 1036 const lines = readJsonlLines(cwd);
1037 1037 for (let i = lines.length - 1; i >= 0; i--) {
1038 1038 const entry = parseJsonlEntry(lines[i]);
1039 - if (isAutoresearchRunEntry(entry)) return entry;
1039 + if (isTuneRunEntry(entry)) return entry;
1041 1041 return null;
1054 1054 const fireHook = async (payload: HookPayload): Promise<string | null> => {
1055 1055 const result = await runHook(payload);
1056 1056 appendHookLogEntryIfConfigured(
1057 - autoresearchJsonlPath(payload.cwd),
1057 + tuneJsonlPath(payload.cwd),
1058 1058 payload.event,
1059 1059 result,
1079 1079 const clearSessionUi = (ctx: ExtensionContext) => {
1080 1080 clearOverlay();
1081 - if (ctx.hasUI) ctx.ui.setWidget("autoresearch", undefined);
1081 + if (ctx.hasUI) ctx.ui.setWidget("tune", undefined);
1084 - const autoresearchHelp = () =>
1084 + const tuneHelp = () =>
1086 1086 "Usage: /tune [off|clear|export|<text>]",
1108 1108 runtime.state = createExperimentState();
1110 1110 const state = runtime.state;
1111 - const jsonlPath = autoresearchJsonlPath(ctx.cwd);
1111 + const jsonlPath = tuneJsonlPath(ctx.cwd);
1112 1112 let loadedFromJsonl = false;
1114 1114 if (fs.existsSync(jsonlPath)) {
1169 1169 state.maxExperiments = readMaxExperiments(ctx.cwd);
1170 - runtime.autoresearchMode = fs.existsSync(jsonlPath);
1170 + runtime.tuneMode = fs.existsSync(jsonlPath);
1171 1171 updateWidget(ctx);
1179 1179 const state = runtime.state;
1181 1181 if (state.results.length === 0 && !runtime.runningExperiment) {
1182 - ctx.ui.setWidget("autoresearch", undefined);
1182 + ctx.ui.setWidget("tune", undefined);
1183 1183 return;
1186 1186 if (state.results.length === 0 && runtime.runningExperiment) {
1187 - ctx.ui.setWidget("autoresearch", (tui, theme) => ({
1187 + ctx.ui.setWidget("tune", (tui, theme) => ({
1188 1188 render(width: number): string[] {
1189 1189 const safeWidth = Math.max(1, width || getTuiSize(tui).width);
1190 1190 return [
1208 1208 if (runtime.dashboardExpanded) {
1209 - ctx.ui.setWidget("autoresearch", (tui, theme) => ({
1209 + ctx.ui.setWidget("tune", (tui, theme) => ({
1210 1210 render(width: number): string[] {
1211 1211 const safeWidth = Math.max(1, width || getTuiSize(tui).width);
1212 1212 const title = truncateDisplayText(
1236 1236 invalidate(): void {},
1238 1238 } else {
1239 - ctx.ui.setWidget("autoresearch", (tui, theme) => ({
1239 + ctx.ui.setWidget("tune", (tui, theme) => ({
1240 1240 render(width: number): string[] {
1241 1241 const safeWidth = Math.max(1, width || getTuiSize(tui).width);
1242 1242 const cur = currentResults(state.results, state.currentSegment);
1380 1380 const ensurePendingResume = (
1381 1381 ctx: ExtensionContext,
1382 - gate: (runtime: AutoresearchRuntime) => boolean,
1382 + gate: (runtime: TuneRuntime) => boolean,
1383 1383 composeMessage: (ctx: ExtensionContext) => string = composeResumeMessage,
1384 1384 ): void => {
1385 1385 const runtime = getRuntime(ctx);
1398 1398 pi.on("session_before_compact", async (event, ctx) => {
1399 1399 pausePendingResume(getRuntime(ctx));
1400 - return autoresearchCompactionFor(ctx, event);
1400 + return tuneCompactionFor(ctx, event);
1403 1403 pi.on("session_compact", async (_event, ctx) => {
1414 1414 pi.on("before_agent_start", async (event, ctx) => {
1415 1415 const runtime = getRuntime(ctx);
1416 - if (!runtime.autoresearchMode) return;
1416 + if (!runtime.tuneMode) return;
1418 - const mdPath = autoresearchMdPath(ctx.cwd);
1419 - const ideasPath = autoresearchIdeasPath(ctx.cwd);
1418 + const mdPath = tuneMdPath(ctx.cwd);
1419 + const ideasPath = tuneIdeasPath(ctx.cwd);
1420 1420 const hasIdeas = fs.existsSync(ideasPath);
1421 - const checksPath = autoresearchChecksPath(ctx.cwd);
1421 + const checksPath = tuneChecksPath(ctx.cwd);
1422 1422 const hasChecks = fs.existsSync(checksPath);
1424 1424 let extra =
1484 1484 fs.mkdirSync(dir, { recursive: true });
1487 - const jsonlPath = autoresearchJsonlPath(ctx.cwd);
1487 + const jsonlPath = tuneJsonlPath(ctx.cwd);
1488 1488 const config = JSON.stringify({
1489 1489 type: "config",
1490 1490 name: state.name,
1513 - const wasInactive = !runtime.autoresearchMode;
1514 - runtime.autoresearchMode = true;
1513 + const wasInactive = !runtime.tuneMode;
1514 + runtime.tuneMode = true;
1515 1515 updateWidget(ctx);
1517 1517 if (wasInactive) {
1596 1596 // Guard: if benchmark.mjs exists, only allow running it
1597 - const benchmarkPath = autoresearchScriptPath(cwd);
1597 + const benchmarkPath = tuneScriptPath(cwd);
1598 1598 if (fs.existsSync(benchmarkPath) && !isBenchmarkCommand(params.command)) {
1599 1599 return {
1600 1600 content: [
1778 1778 let checksOutput = "";
1779 1779 let checksDuration = 0;
1781 - const checksPath = autoresearchChecksPath(cwd);
1781 + const checksPath = tuneChecksPath(cwd);
1782 1782 if (benchmarkPassed && fs.existsSync(checksPath)) {
1783 1783 const checksTimeout = (params.checks_timeout_seconds ?? 300) * 1000;
1784 1784 const ct0 = Date.now();
2251 2251 if (!mergedASI) delete jsonlEntry.asi;
2253 - fs.appendFileSync(autoresearchJsonlPath(cwd), JSON.stringify(jsonlEntry) + "\n");
2253 + fs.appendFileSync(tuneJsonlPath(cwd), JSON.stringify(jsonlEntry) + "\n");
2254 2254 broadcastDashboardUpdate(cwd);
2255 2255 } catch (e) {
2256 2256 text += `\n⚠️ Failed to write session.jsonl: ${e instanceof Error ? e.message : String(e)}`;
2288 2288 state.maxExperiments !== null && segmentCount >= state.maxExperiments;
2289 2289 if (limitReached) {
2290 2290 text += `\n\n🛑 Maximum experiments reached (${state.maxExperiments}). STOP.`;
2291 - runtime.autoresearchMode = false;
2291 + runtime.tuneMode = false;
2292 2292 ctx.abort();
2293 - } else if (runtime.autoresearchMode) {
2293 + } else if (runtime.tuneMode) {
2294 2294 const beforeSteer = await fireHook({
2295 2295 event: "before",
2622 2622 async function exportDashboard(ctx: ExtensionContext): Promise<void> {
2623 - const jsonlPath = autoresearchJsonlPath(ctx.cwd);
2623 + const jsonlPath = tuneJsonlPath(ctx.cwd);
2624 2624 if (!fs.existsSync(jsonlPath)) {
2625 2625 ctx.ui.notify("No session.jsonl found — run some experiments first", "error");
2626 2626 return;
2636 2636 const jsonlContent = fs.readFileSync(jsonlPath, "utf-8").trim();
2637 - const sessionName = extractAutoresearchSessionName(jsonlContent);
2637 + const sessionName = extractTuneSessionName(jsonlContent);
2638 2638 const html = injectDataIntoTemplate(template, sessionName);
2639 2639 const exportDir = fs.mkdtempSync(path.join(tmpdir(), "pi-tune-dashboard-"));
2640 2640 const dest = path.join(exportDir, "index.html");
2710 2710 const command = trimmedArgs.toLowerCase();
2712 2712 if (!trimmedArgs) {
2713 - ctx.ui.notify(autoresearchHelp(), "info");
2713 + ctx.ui.notify(tuneHelp(), "info");
2714 2714 return;
2717 2717 if (command === "off") {
2718 2718 const wasRunning = !ctx.isIdle();
2719 - runtime.autoresearchMode = false;
2719 + runtime.tuneMode = false;
2720 2720 runtime.dashboardExpanded = false;
2721 2721 runtime.autoResumeTurns = 0;
2722 2722 runtime.experimentsThisSession = 0;
2744 2744 if (command === "clear") {
2745 - const jsonlPath = autoresearchJsonlPath(ctx.cwd);
2746 - runtime.autoresearchMode = false;
2745 + const jsonlPath = tuneJsonlPath(ctx.cwd);
2746 + runtime.tuneMode = false;
2747 2747 runtime.dashboardExpanded = false;
2748 2748 runtime.autoResumeTurns = 0;
2749 2749 runtime.experimentsThisSession = 0;
2770 2770 return;
2773 - if (runtime.autoresearchMode) {
2773 + if (runtime.tuneMode) {
2774 2774 ctx.ui.notify("Already active — use '/tune off' to stop", "info");
2775 2775 return;
2778 - runtime.autoresearchMode = true;
2778 + runtime.tuneMode = true;
2779 2779 runtime.autoResumeTurns = 0;
2781 - const rulesLoaded = hasAutoresearchRules(ctx);
2781 + const rulesLoaded = hasTuneRules(ctx);
2782 2782 const kickoff = rulesLoaded
2783 2783 ? `Tune active. ${trimmedArgs} ${BENCHMARK_GUARDRAIL}`
2784 2784 : `Start tune: ${trimmedArgs} ${BENCHMARK_GUARDRAIL}`;

extensions/tune/jsonl.ts

Modified
11 11 export type JsonlEntry = Record<string, unknown>;
13 -export interface AutoresearchConfigEntry extends JsonlEntry {
13 +export interface TuneConfigEntry extends JsonlEntry {
14 14 type: "config";
15 15 name?: string;
16 16 metricName?: string;
18 18 bestDirection?: "lower" | "higher";
21 -export interface AutoresearchRunEntry extends JsonlEntry {
21 +export interface TuneRunEntry extends JsonlEntry {
22 22 run: number;
114 -function updateConfig(state: ReconstructedJsonlState, entry: AutoresearchConfigEntry): void {
114 +function updateConfig(state: ReconstructedJsonlState, entry: TuneConfigEntry): void {
115 115 if (typeof entry.name === "string") state.name = entry.name;
116 116 if (typeof entry.metricName === "string") state.metricName = entry.metricName;
117 117 if (typeof entry.metricUnit === "string") state.metricUnit = entry.metricUnit;
124 124 return segment + 1;
127 -function runFrom(entry: AutoresearchRunEntry, segment: number): ReconstructedRun {
127 +function runFrom(entry: TuneRunEntry, segment: number): ReconstructedRun {
128 128 return {
129 129 run: typeof entry.run === "number" ? entry.run : 0,
130 130 commit: typeof entry.commit === "string" ? entry.commit : "",
163 -export function isAutoresearchConfigEntry(entry: unknown): entry is AutoresearchConfigEntry {
163 +export function isTuneConfigEntry(entry: unknown): entry is TuneConfigEntry {
164 164 return isObjectRecord(entry) && entry.type === "config";
167 -export function isAutoresearchRunEntry(entry: unknown): entry is AutoresearchRunEntry {
167 +export function isTuneRunEntry(entry: unknown): entry is TuneRunEntry {
168 168 return isObjectRecord(entry) && typeof entry.run === "number";
171 -function firstConfigEntry(jsonlContent: string): AutoresearchConfigEntry | null {
171 +function firstConfigEntry(jsonlContent: string): TuneConfigEntry | null {
172 172 for (const line of nonEmptyLines(jsonlContent)) {
173 173 const entry = parseJsonlEntry(line);
174 - if (isAutoresearchConfigEntry(entry)) return entry;
174 + if (isTuneConfigEntry(entry)) return entry;
176 176 return null;
179 -export function hasAutoresearchConfigHeader(jsonlContent: string): boolean {
179 +export function hasTuneConfigHeader(jsonlContent: string): boolean {
180 180 return firstConfigEntry(jsonlContent) !== null;
183 -export function extractAutoresearchSessionName(jsonlContent: string): string {
183 +export function extractTuneSessionName(jsonlContent: string): string {
184 184 return firstConfigEntry(jsonlContent)?.name || "Tune";
192 192 const entry = parseJsonlEntry(line);
193 193 if (!entry) continue;
195 - if (isAutoresearchConfigEntry(entry)) {
195 + if (isTuneConfigEntry(entry)) {
196 196 updateConfig(state, entry);
197 197 segment = nextSegment(state, segment);
198 198 state.currentSegment = segment;
199 199 continue;
202 - if (!isAutoresearchRunEntry(entry)) continue;
202 + if (!isTuneRunEntry(entry)) continue;
204 204 const run = runFrom(entry, segment);
205 205 state.results.push(run);

extensions/tune/shortcuts.ts

Modified
19 19 // ── Types ─────────────────────────────────────────────────────────────────
21 -export interface AutoresearchShortcuts {
21 +export interface TuneShortcuts {
22 22 toggleDashboard: string | null;
23 23 fullscreenDashboard: string | null;
26 -interface AutoresearchShortcutConfig {
26 +interface TuneShortcutConfig {
27 27 toggleDashboard?: unknown;
28 28 fullscreenDashboard?: unknown;
54 54 return typeof configured === "string" ? configured : fallback;
57 -function defaultAutoresearchShortcuts(): AutoresearchShortcuts {
57 +function defaultTuneShortcuts(): TuneShortcuts {
58 58 return {
59 59 toggleDashboard: DEFAULT_TOGGLE_DASHBOARD_SHORTCUT,
60 60 fullscreenDashboard: DEFAULT_FULLSCREEN_DASHBOARD_SHORTCUT,
70 70 // ── Public API ────────────────────────────────────────────────────────────
72 -export function autoresearchShortcutsConfigPath(agentDir: string = getAgentDir()): string {
72 +export function tuneShortcutsConfigPath(agentDir: string = getAgentDir()): string {
73 73 return join(agentDir, "extensions", CONFIG_FILE_NAME);
76 -export function resolveAutoresearchShortcuts(
77 - configPath: string = autoresearchShortcutsConfigPath(),
78 -): AutoresearchShortcuts {
79 - if (!existsSync(configPath)) return defaultAutoresearchShortcuts();
76 +export function resolveTuneShortcuts(
77 + configPath: string = tuneShortcutsConfigPath(),
78 +): TuneShortcuts {
79 + if (!existsSync(configPath)) return defaultTuneShortcuts();
81 81 let parsed: unknown;
82 82 try {
83 83 parsed = JSON.parse(readFileSync(configPath, "utf-8"));
84 84 } catch {
85 85 warnUsingDefaults("Could not read", configPath);
86 - return defaultAutoresearchShortcuts();
86 + return defaultTuneShortcuts();
89 89 const shortcuts = isRecord(parsed) ? parsed.shortcuts : undefined;
90 - if (shortcuts === undefined) return defaultAutoresearchShortcuts();
90 + if (shortcuts === undefined) return defaultTuneShortcuts();
92 92 if (!isRecord(shortcuts) || !hasValidShortcutValues(shortcuts)) {
93 93 warnUsingDefaults("Invalid", configPath);
94 - return defaultAutoresearchShortcuts();
94 + return defaultTuneShortcuts();
97 97 return {