feat(f6): BaselineStore — vscode-free per-doc baseline persistence (SLICE-1)

F6 §6.2/§6.3, INV-19. One JSON per docPath under VS Code workspace storage,
never the repo. Mirrors CoauthorStore; unit-tested round-trip/paths/overwrite.

Also lands the F6 implementation plan
(docs/superpowers/plans/2026-06-11-f6-diff-view-toggle.md).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Ben Stull
2026-06-11 07:11:42 -07:00
parent 19075f243b
commit 6f0b903596
3 changed files with 1204 additions and 0 deletions
+43
View File
@@ -0,0 +1,43 @@
/**
* BaselineStore — load/save one diff-view baseline JSON per document (F6 §6.3).
* The CoauthorStore shape (src/store.ts): vscode-free (Node fs only, unit-
* testable), one file per docPath. INV-19: the storage dir is VS Code's
* per-workspace extension storage, NEVER the repo — so the baseline can never
* be committed, merged, or read by another rung, and the sidecar / cross-rung
* contract (INV-14..17) are untouched by construction.
*/
import * as fs from "node:fs";
import * as path from "node:path";
export type BaselineReason = "opened" | "machine-landing" | "pinned";
export interface Baseline {
docPath: string;
/** full document text captured at the epoch (from the buffer, not disk — §6.3). */
text: string;
capturedAt: string;
reason: BaselineReason;
}
export class BaselineStore {
/** @param storageDir absolute VS Code workspace-storage dir (context.storageUri.fsPath). */
constructor(private readonly storageDir: string) {}
/** `<storageDir>/baselines/<repo-relative-docPath>.json` (§6.3). */
baselinePath(docPath: string): string {
return path.join(this.storageDir, "baselines", `${docPath}.json`);
}
load(docPath: string): Baseline | null {
const p = this.baselinePath(docPath);
if (!fs.existsSync(p)) return null;
return JSON.parse(fs.readFileSync(p, "utf8")) as Baseline;
}
/** Newest epoch wins — overwrite in place, no history (state-not-history, the F3/F4 precedent). */
save(docPath: string, baseline: Baseline): void {
const p = this.baselinePath(docPath);
fs.mkdirSync(path.dirname(p), { recursive: true });
fs.writeFileSync(p, JSON.stringify(baseline, null, 2) + "\n", "utf8");
}
}