feat: classify feedback work-data signals

This commit is contained in:
artale 2026-06-27 14:31:10 +02:00
parent e59c4c60c7
commit b920691540
2 changed files with 10 additions and 2 deletions

View File

@ -38,7 +38,7 @@ describe("feedback memory", () => {
const root = tmpRoot();
const receipt = writeFeedbackReceipt(root, "performance", "users want receipts", "test", new Date("2026-06-18T00:00:00.000Z"));
expect(receipt).toMatchObject({ schema: "fable.feedback.receipt.v1", source: "test", type: "performance" });
expect(receipt).toMatchObject({ schema: "fable.feedback.receipt.v1", source: "test", type: "performance", signal: "performance" });
expect(fs.existsSync(path.join(root, ".fable", "feedback", "2026-06-18T00-00-00-000Z-performance.json"))).toBe(true);
expect(fs.readFileSync(receipt.memoryPath, "utf-8")).toContain("users want receipts");
});

View File

@ -2,6 +2,7 @@ import * as fs from "node:fs";
import * as path from "node:path";
export type FeedbackMemoryType = "approved" | "rejected" | "performance";
export type FeedbackSignal = "quality_bar" | "correction" | "performance";
export interface FeedbackMemoryEntry {
type: FeedbackMemoryType;
@ -12,6 +13,7 @@ export interface FeedbackMemoryEntry {
export interface FeedbackReceipt extends FeedbackMemoryEntry {
schema: "fable.feedback.receipt.v1";
source: string;
signal: FeedbackSignal;
memoryPath: string;
}
@ -36,13 +38,19 @@ export function appendFeedbackMemory(repo: string, type: FeedbackMemoryType, tex
export function writeFeedbackReceipt(repo: string, type: FeedbackMemoryType, text: string, source = "cli", now = new Date()): FeedbackReceipt {
const entry = appendFeedbackMemory(repo, type, text, now);
const receipt: FeedbackReceipt = { schema: "fable.feedback.receipt.v1", ...entry, source, memoryPath: feedbackMemoryPath(repo, type) };
const receipt: FeedbackReceipt = { schema: "fable.feedback.receipt.v1", ...entry, source, signal: feedbackSignal(type), memoryPath: feedbackMemoryPath(repo, type) };
const dir = path.join(repo, ".fable", "feedback");
fs.mkdirSync(dir, { recursive: true });
fs.writeFileSync(path.join(dir, `${entry.createdAt.replace(/[:.]/g, "-")}-${type}.json`), `${JSON.stringify(receipt, null, 2)}\n`);
return receipt;
}
function feedbackSignal(type: FeedbackMemoryType): FeedbackSignal {
if (type === "approved") return "quality_bar";
if (type === "rejected") return "correction";
return "performance";
}
export function feedbackMemoryStats(repo: string): Record<FeedbackMemoryType, number> {
return Object.fromEntries((Object.keys(FILES) as FeedbackMemoryType[]).map((type) => {
const file = feedbackMemoryPath(repo, type);