repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

Remove tune legacy compatibility cruft

957fb4308e8b39945d4c6e0279096e84ee5d701e

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (7)

+11 / −81 text lines

Diff layout

.gitignore

Modified

+0 / −1 text lines

22**/node_modules/
33.demo/
44.pi/tune/
5.pi/autoresearch/
65*.tgz
76.DS_Store

CHANGELOG.md

Modified

+0 / −1 text lines

55- Rename `autoresearch` extension to `tune` and slash command to `/tune`
66- Move tune session state to `.pi/tune/`
77- Restyle tune dashboard with the Nugu diff-review palette, theme selector, cards, side drawer, chart, and live session.jsonl refresh
8- Keep legacy `.pi/autoresearch/` state and `autoresearch.json` shortcuts readable
109## 0.0.3

extensions/tune/CHANGELOG.md

Modified

+2 / −2 text lines

55Fork of [pi-autoresearch](https://github.com/davebcn87/pi-autoresearch) with breaking changes:
77- Extension slug/package renamed to `tune` / `@bugabinga/pi-ext-tune`
8- State dir moved to `.pi/tune/`; legacy `.pi/autoresearch/` is copied once
8- State dir moved to `.pi/tune/`
99- Scripts renamed: `benchmark.mjs` (was `autoresearch.sh`), `checks.mjs` (was `autoresearch.checks.sh`)
1010- Hooks are Node.js only (`.mjs`), no bash dependency
11- Command renamed to `/tune`; legacy `autoresearch.json` shortcuts still load
11- Command renamed to `/tune`; shortcuts config moved to `tune.json`
1212- `workingDir` config option removed (state always in `.pi/tune/`)
1313- Session files live under `.pi/tune/`: `session.jsonl`, `session.md`, `ideas.md`
1414- Adapted to `@earendil-works/pi-coding-agent` and `typebox` packages

extensions/tune/README.md

Modified

+0 / −2 text lines

2222Settings:
2323Keyboard shortcuts configurable in `<agent-dir>/extensions/tune.json`.
24If missing, legacy `<agent-dir>/extensions/autoresearch.json` is still read.
2625## Hooks
3433## State
3635All state lives in `.pi/tune/`.
37If `.pi/tune/` is missing and legacy `.pi/autoresearch/` exists, tune copies the legacy state once on session load/init; it does not delete the old directory.
3937| File | Purpose |
4038|---|---|

extensions/tune/__tests__/remaining.test.ts

Modified

+4 / −43 text lines

1import { afterEach, beforeAll, describe, expect, it } from "bun:test";
1import { beforeAll, describe, expect, it } from "bun:test";
22import * as fs from "node:fs";
33import * as path from "node:path";
44import {
1111import { __test } from "../index.ts";
1313const TESTDIR = "/tmp/pi-ext-20260530-164209-project";
14const MIGRATION_TESTDIR = "/tmp/pi-ext-tune-migration";
1514const TEST_JSONL = [
1615 '{"type":"config","name":"Optimize sqrt/sin loop","metricName":"total_ms","metricUnit":"ms","bestDirection":"lower"}',
1716 '{"run":1,"commit":"92d4b83","metric":7,"metrics":{},"status":"keep","description":"Baseline: unoptimized sqrt/sin loop","timestamp":1780152220658,"segment":0,"confidence":null,"asi":{"hypothesis":"Baseline measurement"}}',
2726 fs.writeFileSync(path.join(tuneDir, "session.jsonl"), TEST_JSONL);
2827});
30afterEach(() => {
31 fs.rmSync(MIGRATION_TESTDIR, { recursive: true, force: true });
32});
3429// ── 1. COMPACTION RESUME ────────────────────────────────────────────────
3631describe("compaction resume", () => {
10499 });
105100});
107// ── 3. STATE MIGRATION ─────────────────────────────────────────────────
109describe("state migration", () => {
110 it("copies legacy .pi/autoresearch state into .pi/tune once", () => {
111 const legacyDir = path.join(MIGRATION_TESTDIR, ".pi", "autoresearch");
112 const tuneDir = path.join(MIGRATION_TESTDIR, ".pi", "tune");
113 fs.mkdirSync(legacyDir, { recursive: true });
114 fs.writeFileSync(path.join(legacyDir, "session.jsonl"), TEST_JSONL);
115 fs.writeFileSync(path.join(legacyDir, "ideas.md"), "- keep this\n");
117 expect(__test.migrateLegacyTuneState(MIGRATION_TESTDIR)).toBe(true);
118 expect(fs.readFileSync(path.join(tuneDir, "session.jsonl"), "utf-8")).toBe(
119 TEST_JSONL,
120 );
121 expect(fs.readFileSync(path.join(tuneDir, "ideas.md"), "utf-8")).toBe(
122 "- keep this\n",
123 );
124 expect(fs.existsSync(path.join(legacyDir, "session.jsonl"))).toBe(true);
125 expect(__test.migrateLegacyTuneState(MIGRATION_TESTDIR)).toBe(false);
126 });
127});
129// ── 4. SHORTCUTS ──────────────────────────────────────────────────────
102// ── 3. SHORTCUTS ──────────────────────────────────────────────────────
131104describe("shortcuts", () => {
132105 it("returns defaults when no config file", () => {
134107 expect(s.toggleDashboard).toBe("ctrl+shift+t");
135108 expect(s.fullscreenDashboard).toBe("ctrl+shift+f");
136109 });
138 it("falls back to legacy autoresearch.json", () => {
139 const configDir = path.join(MIGRATION_TESTDIR, "extensions");
140 fs.mkdirSync(configDir, { recursive: true });
141 fs.writeFileSync(
142 path.join(configDir, "autoresearch.json"),
143 JSON.stringify({ shortcuts: { toggleDashboard: "ctrl+x" } }),
144 );
145 expect(resolveTuneShortcuts(path.join(configDir, "tune.json")).toggleDashboard).toBe(
146 "ctrl+x",
147 );
148 });
149110});
151// ── 5. HOOK PATHS ─────────────────────────────────────────────────────
112// ── 4. HOOK PATHS ─────────────────────────────────────────────────────
153114describe("hook paths", () => {
154115 it("resolves to .pi/tune/hooks/{stage}.mjs", () => {
161122 });
162123});
164// ── 6. EXPORT DASHBOARD ───────────────────────────────────────────────
125// ── 5. EXPORT DASHBOARD ───────────────────────────────────────────────
166127describe("export dashboard", () => {
167128 it("ships a dashboard template next to the tune extension", () => {

extensions/tune/index.ts

Modified

+3 / −24 text lines

5858const EXPERIMENT_MAX_BYTES = 4 * 1024;
6060const STATE_DIR = ".pi/tune";
61const LEGACY_STATE_DIR = ".pi/autoresearch";
6361const TUNE_SUBCOMMAND_COMPLETIONS: AutocompleteItem[] = [
6462 { value: "off", label: "off", description: "Turn tune mode off" },
6563 { value: "clear", label: "clear", description: "Delete session.jsonl and stop" },
343341// ── State path helpers ────────────────────────────────────────────────────
345343const stateDir = (dir: string) => path.join(dir, STATE_DIR);
346const legacyStateDir = (dir: string) => path.join(dir, LEGACY_STATE_DIR);
347344const tuneJsonlPath = (dir: string) => path.join(stateDir(dir), "session.jsonl");
348345const tuneMdPath = (dir: string) => path.join(stateDir(dir), "session.md");
349346const tuneIdeasPath = (dir: string) => path.join(stateDir(dir), "ideas.md");
351348const tuneScriptPath = (dir: string) => path.join(stateDir(dir), "benchmark.mjs");
352349const tuneConfigPath = (dir: string) => path.join(stateDir(dir), "config.json");
354function migrateLegacyTuneState(cwd: string): boolean {
355 const current = stateDir(cwd);
356 const legacy = legacyStateDir(cwd);
357 try {
358 if (fs.existsSync(current) || !fs.existsSync(legacy)) return false;
359 fs.cpSync(legacy, current, { recursive: true });
360 return true;
361 } catch {
362 return false;
363 }
364}
366351function findBaselineMetric(results: ExperimentResult[], segment: number): number | null {
367352 const cur = currentResults(results, segment);
368353 return cur.length > 0 ? cur[0].metric : null;
881866 dashboardTemplatePath,
882867 tuneArgumentCompletions,
883868 tuneCommandArgumentSuggestions,
884 migrateLegacyTuneState,
885869};
887871// ── Extension ─────────────────────────────────────────────────────────────
11221106 runtime.autoResumeTurns = 0;
11231107 runtime.state = createExperimentState();
1125 migrateLegacyTuneState(ctx.cwd);
11261109 const state = runtime.state;
11271110 const jsonlPath = tuneJsonlPath(ctx.cwd);
11281111 let loadedFromJsonl = false;
14931476 state.bestMetric = null;
14941477 state.secondaryMetrics = [];
14951478 state.confidence = null;
1496 migrateLegacyTuneState(ctx.cwd);
1497 state.maxExperiments = readMaxExperiments(ctx.cwd);
1479 state.maxExperiments = readMaxExperiments(ctx.cwd);
14991481 // Ensure state directory exists
15001482 const dir = stateDir(ctx.cwd);
26432625 async function exportDashboard(ctx: ExtensionContext): Promise<void> {
2644 migrateLegacyTuneState(ctx.cwd);
26452626 const jsonlPath = tuneJsonlPath(ctx.cwd);
26462627 if (!fs.existsSync(jsonlPath)) {
26472628 ctx.ui.notify("No session.jsonl found — run some experiments first", "error");
27722753 if (command === "clear") {
2773 migrateLegacyTuneState(ctx.cwd);
2774 const jsonlPath = tuneJsonlPath(ctx.cwd);
2754 const jsonlPath = tuneJsonlPath(ctx.cwd);
27752755 runtime.tuneMode = false;
27762756 runtime.dashboardExpanded = false;
27772757 runtime.autoResumeTurns = 0;
28082788 runtime.tuneMode = true;
28092789 runtime.autoResumeTurns = 0;
2810 migrateLegacyTuneState(ctx.cwd);
28122791 const rulesLoaded = hasTuneRules(ctx);
28132792 const kickoff = rulesLoaded
28142793 ? `Tune active. ${trimmedArgs} ${BENCHMARK_GUARDRAIL}`

extensions/tune/shortcuts.ts

Modified

+2 / −8 text lines

22 * Keyboard shortcut configuration for tune dashboard.
33 *
44 * Config file: <agent-dir>/extensions/tune.json
5 * Fallback: <agent-dir>/extensions/autoresearch.json
65 * Keys: shortcuts.toggleDashboard, shortcuts.fullscreenDashboard
76 */
98import { existsSync, readFileSync } from "node:fs";
10import { dirname, join } from "node:path";
9import { join } from "node:path";
1110import { getAgentDir } from "@earendil-works/pi-coding-agent";
1312// ── Constants ─────────────────────────────────────────────────────────────
1615export const DEFAULT_FULLSCREEN_DASHBOARD_SHORTCUT = "ctrl+shift+f";
1817const CONFIG_FILE_NAME = "tune.json";
19const LEGACY_CONFIG_FILE_NAME = "autoresearch.json";
2119// ── Types ─────────────────────────────────────────────────────────────────
7876export function resolveTuneShortcuts(
7977 configPath: string = tuneShortcutsConfigPath(),
8078): TuneShortcuts {
81 if (!existsSync(configPath)) {
82 const legacyPath = join(dirname(configPath), LEGACY_CONFIG_FILE_NAME);
83 if (!existsSync(legacyPath)) return defaultTuneShortcuts();
84 configPath = legacyPath;
85 }
79 if (!existsSync(configPath)) return defaultTuneShortcuts();
8781 let parsed: unknown;
8882 try {