feat: classify feedback work-data signals
This commit is contained in:
parent
e59c4c60c7
commit
b920691540
|
|
@ -38,7 +38,7 @@ describe("feedback memory", () => {
|
||||||
const root = tmpRoot();
|
const root = tmpRoot();
|
||||||
const receipt = writeFeedbackReceipt(root, "performance", "users want receipts", "test", new Date("2026-06-18T00:00:00.000Z"));
|
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.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");
|
expect(fs.readFileSync(receipt.memoryPath, "utf-8")).toContain("users want receipts");
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import * as fs from "node:fs";
|
||||||
import * as path from "node:path";
|
import * as path from "node:path";
|
||||||
|
|
||||||
export type FeedbackMemoryType = "approved" | "rejected" | "performance";
|
export type FeedbackMemoryType = "approved" | "rejected" | "performance";
|
||||||
|
export type FeedbackSignal = "quality_bar" | "correction" | "performance";
|
||||||
|
|
||||||
export interface FeedbackMemoryEntry {
|
export interface FeedbackMemoryEntry {
|
||||||
type: FeedbackMemoryType;
|
type: FeedbackMemoryType;
|
||||||
|
|
@ -12,6 +13,7 @@ export interface FeedbackMemoryEntry {
|
||||||
export interface FeedbackReceipt extends FeedbackMemoryEntry {
|
export interface FeedbackReceipt extends FeedbackMemoryEntry {
|
||||||
schema: "fable.feedback.receipt.v1";
|
schema: "fable.feedback.receipt.v1";
|
||||||
source: string;
|
source: string;
|
||||||
|
signal: FeedbackSignal;
|
||||||
memoryPath: string;
|
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 {
|
export function writeFeedbackReceipt(repo: string, type: FeedbackMemoryType, text: string, source = "cli", now = new Date()): FeedbackReceipt {
|
||||||
const entry = appendFeedbackMemory(repo, type, text, now);
|
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");
|
const dir = path.join(repo, ".fable", "feedback");
|
||||||
fs.mkdirSync(dir, { recursive: true });
|
fs.mkdirSync(dir, { recursive: true });
|
||||||
fs.writeFileSync(path.join(dir, `${entry.createdAt.replace(/[:.]/g, "-")}-${type}.json`), `${JSON.stringify(receipt, null, 2)}\n`);
|
fs.writeFileSync(path.join(dir, `${entry.createdAt.replace(/[:.]/g, "-")}-${type}.json`), `${JSON.stringify(receipt, null, 2)}\n`);
|
||||||
return receipt;
|
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> {
|
export function feedbackMemoryStats(repo: string): Record<FeedbackMemoryType, number> {
|
||||||
return Object.fromEntries((Object.keys(FILES) as FeedbackMemoryType[]).map((type) => {
|
return Object.fromEntries((Object.keys(FILES) as FeedbackMemoryType[]).map((type) => {
|
||||||
const file = feedbackMemoryPath(repo, type);
|
const file = feedbackMemoryPath(repo, type);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue