Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

feat: let pipes learn from live view feedback

Louis Beaumonta0732ac07402
diff --git a/apps/screenpipe-app-tauri/components/settings/__tests__/brain-overview.test.tsx b/apps/screenpipe-app-tauri/components/settings/__tests__/brain-overview.test.tsx
index 708930daf..1cc2767f3 100644
--- a/apps/screenpipe-app-tauri/components/settings/__tests__/brain-overview.test.tsx
+++ b/apps/screenpipe-app-tauri/components/settings/__tests__/brain-overview.test.tsx
@@ -91,6 +91,7 @@ const populatedView: ViewDefinition = {
width: 6,
order: 0,
binding: { pipeName: "daily-summary" },
+ feedback: { upCount: 0, downCount: 0, current: null },
value: {
payload: { value: 4.5, unit: "hours", delta: "+45m" },
evidence: [
@@ -342,6 +343,25 @@ describe("BrainOverview", () => {
});
it("offers per-card feedback and regenerates only that card", async () => {
+ mocks.localFetch.mockImplementation(async (path: string) => ({
+ ok: true,
+ status: 200,
+ json: async () =>
+ path.endsWith("/feedback")
+ ? {
+ feedback: {
+ up_count: 1,
+ down_count: 0,
+ current: {
+ rating: "up",
+ artifact_output_id: 88,
+ artifact_version: 2,
+ created_at: "2026-07-24T18:00:00Z",
+ },
+ },
+ }
+ : { success: true },
+ }));
mocks.listBrainViews.mockResolvedValue({
status: "ok",
data: [populatedView],
@@ -352,13 +372,35 @@ describe("BrainOverview", () => {
name: "mark Focus time useful",
});
fireEvent.click(useful);
- expect(useful.getAttribute("aria-pressed")).toBe("true");
+ await waitFor(() =>
+ expect(useful.getAttribute("aria-pressed")).toBe("true"),
+ );
+ const feedbackCall = mocks.localFetch.mock.calls.find(([path]) =>
+ String(path).endsWith("/feedback"),
+ );
+ expect(feedbackCall?.[0]).toBe(
+ "/outputs/targets/live-view%3Amy-overview%3Afocus-time/feedback",
+ );
+ expect(JSON.parse(feedbackCall?.[1].body)).toEqual({
+ artifact_output_id: 88,
+ artifact_version: 2,
+ rating: "up",
+ correction: null,
+ });
fireEvent.click(
screen.getByRole("button", { name: "regenerate Focus time" }),
);
- await waitFor(() => expect(mocks.localFetch).toHaveBeenCalledTimes(1));
- const [, request] = mocks.localFetch.mock.calls[0];
+ await waitFor(() =>
+ expect(
+ mocks.localFetch.mock.calls.some(
+ ([path]) => path === "/pipes/daily-summary/run",
+ ),
+ ).toBe(true),
+ );
+ const [, request] = mocks.localFetch.mock.calls.find(
+ ([path]) => path === "/pipes/daily-summary/run",
+ )!;
expect(JSON.parse(request.body).notification_context).toEqual(
expect.objectContaining({
target_ids: ["live-view:my-overview:focus-time"],
@@ -366,6 +408,59 @@ describe("BrainOverview", () => {
);
});
+ it("lets a user explain a down rating so the Pipe can correct its next output", async () => {
+ mocks.localFetch.mockResolvedValue({
+ ok: true,
+ status: 200,
+ json: async () => ({
+ feedback: {
+ up_count: 0,
+ down_count: 1,
+ current: {
+ rating: "down",
+ artifact_output_id: 88,
+ artifact_version: 2,
+ correction: "exclude meetings",
+ created_at: "2026-07-24T18:00:00Z",
+ },
+ },
+ }),
+ });
+ mocks.listBrainViews.mockResolvedValue({
+ status: "ok",
+ data: [populatedView],
+ });
+ render(<BrainOverview />);
+
+ const notUseful = await screen.findByRole("button", {
+ name: "mark Focus time not useful",
+ });
+ fireEvent.click(notUseful);
+ fireEvent.change(
+ await screen.findByPlaceholderText("e.g. exclude meetings"),
+ {
+ target: { value: "exclude meetings" },
+ },
+ );
+ fireEvent.click(screen.getByRole("button", { name: "save feedback" }));
+
+ await waitFor(() =>
+ expect(notUseful.getAttribute("aria-pressed")).toBe("true"),
+ );
+ expect(mocks.localFetch).toHaveBeenCalledWith(
+ "/outputs/targets/live-view%3Amy-overview%3Afocus-time/feedback",
+ expect.objectContaining({
+ method: "POST",
+ body: JSON.stringify({
+ artifact_output_id: 88,
+ artifact_version: 2,
+ rating: "down",
+ correction: "exclude meetings",
+ }),
+ }),
+ );
+ });
+
it("edits one card from its AI popover without replacing the dashboard", async () => {
mocks.listBrainViews.mockResolvedValue({
status: "ok",
diff --git a/apps/screenpipe-app-tauri/components/settings/brain-overview.tsx b/apps/screenpipe-app-tauri/components/settings/brain-overview.tsx
index 8f3ec92dc..2f3c7d1f6 100644
--- a/apps/screenpipe-app-tauri/components/settings/brain-overview.tsx
+++ b/apps/screenpipe-app-tauri/components/settings/brain-overview.tsx
@@ -139,6 +139,7 @@ function generatedSlots(
order: existingSlots.length + index,
binding: block.pipeName ? { pipeName: block.pipeName } : null,
value: null,
+ feedback: { upCount: 0, downCount: 0, current: null },
};
});
}
@@ -157,9 +158,6 @@ export function BrainOverview() {
const [aiNote, setAiNote] = useState<string | null>(null);
const [error, setError] = useState<string | null>(null);
const [dataRefresh, setDataRefresh] = useState<DataRefreshState | null>(null);
- const [cardFeedback, setCardFeedback] = useState<
- Record<string, "up" | "down" | null>
- >({});
const [aiEditingSlotId, setAiEditingSlotId] = useState<string | null>(null);
const installedPipes = useMemo(
@@ -448,18 +446,91 @@ export function BrainOverview() {
}
};
- const recordCardFeedback = (slot: ViewSlot, rating: "up" | "down") => {
- const next = cardFeedback[slot.id] === rating ? null : rating;
- setCardFeedback((current) => ({ ...current, [slot.id]: next }));
- void import("posthog-js")
- .then(({ default: posthog }) =>
- posthog.capture("live_view_card_feedback", {
- action: next ?? "clear",
- component: slot.component,
- pipe: slot.binding?.pipeName ?? null,
- }),
- )
- .catch(() => undefined);
+ const recordCardFeedback = async (
+ slot: ViewSlot,
+ rating: "up" | "down" | null,
+ correction?: string,
+ ): Promise<boolean> => {
+ if (!view || !slot.value) return false;
+ try {
+ const targetId = `live-view:${view.id}:${slot.id}`;
+ const response = await localFetch(
+ `/outputs/targets/${encodeURIComponent(targetId)}/feedback`,
+ {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({
+ artifact_output_id: slot.value.artifactOutputId,
+ artifact_version: slot.value.artifactVersion,
+ rating,
+ correction: correction?.trim() || null,
+ }),
+ },
+ );
+ const body = (await response.json().catch(() => ({}))) as {
+ error?: string;
+ feedback?: {
+ up_count: number;
+ down_count: number;
+ current?: {
+ rating: "up" | "down";
+ artifact_output_id: number;
+ artifact_version: number;
+ correction?: string;
+ created_at: string;
+ };
+ };
+ };
+ if (!response.ok || !body.feedback) {
+ throw new Error(body.error || `HTTP ${response.status}`);
+ }
+ const persistedFeedback: ViewSlot["feedback"] = {
+ upCount: body.feedback.up_count,
+ downCount: body.feedback.down_count,
+ current: body.feedback.current
+ ? {
+ rating: body.feedback.current.rating,
+ artifactOutputId: body.feedback.current.artifact_output_id,
+ artifactVersion: body.feedback.current.artifact_version,
+ correction: body.feedback.current.correction ?? null,
+ createdAt: body.feedback.current.created_at,
+ }
+ : null,
+ };
+ setView((current) =>
+ current
+ ? {
+ ...current,
+ slots: current.slots.map((candidate) =>
+ candidate.id === slot.id
+ ? { ...candidate, feedback: persistedFeedback }
+ : candidate,
+ ),
+ }
+ : current,
+ );
+ void import("posthog-js")
+ .then(({ default: posthog }) =>
+ posthog.capture("live_view_card_feedback", {
+ action: rating ?? "clear",
+ component: slot.component,
+ pipe: slot.binding?.pipeName ?? null,
+ has_correction: Boolean(correction?.trim()),
+ }),
+ )
+ .catch(() => undefined);
+ return true;
+ } catch (feedbackError) {
+ toast({
+ title: "failed to save feedback",
+ description:
+ feedbackError instanceof Error
+ ? feedbackError.message
+ : String(feedbackError),
+ variant: "destructive",
+ });
+ return false;
+ }
};
const editSlotWithAi = async (
@@ -616,6 +687,7 @@ export function BrainOverview() {
order: current.slots.length,
binding: null,
value: null,
+ feedback: { upCount: 0, downCount: 0, current: null },
},
],
};
@@ -1029,9 +1101,12 @@ export function BrainOverview() {
refreshIsActive &&
Boolean(dataRefresh?.slotIds.includes(slot.id))
}
- feedback={cardFeedback[slot.id] ?? null}
+ feedback={slot.feedback?.current?.rating ?? null}
+ feedbackCorrection={slot.feedback?.current?.correction ?? null}
aiEditing={aiEditingSlotId === slot.id}
- onFeedback={(rating) => recordCardFeedback(slot, rating)}
+ onFeedback={(rating, correction) =>
+ recordCardFeedback(slot, rating, correction)
+ }
onRegenerate={() => void refreshConnectedPipes(view, [slot])}
onAiEdit={(prompt) => editSlotWithAi(slot, prompt)}
/>
diff --git a/apps/screenpipe-app-tauri/components/settings/live-view-card.tsx b/apps/screenpipe-app-tauri/components/settings/live-view-card.tsx
index 9825e74d5..c7a3d3a5c 100644
--- a/apps/screenpipe-app-tauri/components/settings/live-view-card.tsx
+++ b/apps/screenpipe-app-tauri/components/settings/live-view-card.tsx
@@ -240,6 +240,7 @@ export function LiveViewCard({
preview = false,
refreshing = false,
feedback = null,
+ feedbackCorrection = null,
aiEditing = false,
onFeedback,
onRegenerate,
@@ -249,15 +250,24 @@ export function LiveViewCard({
preview?: boolean;
refreshing?: boolean;
feedback?: "up" | "down" | null;
+ feedbackCorrection?: string | null;
aiEditing?: boolean;
- onFeedback?: (rating: "up" | "down") => void;
+ onFeedback?: (
+ rating: "up" | "down" | null,
+ correction?: string,
+ ) => Promise<boolean>;
onRegenerate?: () => void;
onAiEdit?: (prompt: string) => Promise<boolean>;
}) {
const [aiOpen, setAiOpen] = useState(false);
const [aiPrompt, setAiPrompt] = useState("");
+ const [feedbackOpen, setFeedbackOpen] = useState(false);
+ const [feedbackNote, setFeedbackNote] = useState("");
+ const [feedbackSaving, setFeedbackSaving] = useState<
+ "up" | "down" | "clear" | null
+ >(null);
const hasActions = Boolean(onFeedback || onRegenerate || onAiEdit);
- const busy = refreshing || aiEditing;
+ const busy = refreshing || aiEditing || feedbackSaving !== null;
const submitAiEdit = async (event: React.FormEvent) => {
event.preventDefault();
@@ -269,6 +279,21 @@ export function LiveViewCard({
}
};
+ const saveFeedback = async (
+ rating: "up" | "down" | null,
+ correction?: string,
+ ) => {
+ if (!onFeedback || !slot.value) return;
+ setFeedbackSaving(rating ?? "clear");
+ try {
+ if (await onFeedback(rating, correction)) {
+ setFeedbackOpen(false);
+ }
+ } finally {
+ setFeedbackSaving(null);
+ }
+ };
+
return (
<article
data-testid={`overview-card-${slot.id}`}
@@ -301,23 +326,97 @@ export function LiveViewCard({
className={`h-7 w-7 rounded-none ${
feedback === "up" ? "bg-foreground text-background" : ""
}`}
- onClick={() => onFeedback?.("up")}
+ disabled={!slot.value || busy}
+ onClick={() => void saveFeedback(feedback === "up" ? null : "up")}
>
- <ThumbsUp className="h-3 w-3" />
+ {feedbackSaving === "up" || feedbackSaving === "clear" ? (
+ <Loader2 className="h-3 w-3 animate-spin" />
+ ) : (
+ <ThumbsUp className="h-3 w-3" />
+ )}
</Button>
- <Button
- type="button"
- variant="ghost"
- size="icon"
- aria-label={`mark ${slot.title} not useful`}
- aria-pressed={feedback === "down"}
- className={`h-7 w-7 rounded-none ${
- feedback === "down" ? "bg-foreground text-background" : ""
- }`}
- onClick={() => onFeedback?.("down")}
+ <Popover
+ open={feedbackOpen}
+ onOpenChange={(open) => {
+ setFeedbackOpen(open);
+ if (open) setFeedbackNote(feedbackCorrection ?? "");
+ }}
>
- <ThumbsDown className="h-3 w-3" />
- </Button>
+ <PopoverTrigger asChild>
+ <Button
+ type="button"
+ variant="ghost"
+ size="icon"
+ aria-label={`mark ${slot.title} not useful`}
+ aria-pressed={feedback === "down"}
+ className={`h-7 w-7 rounded-none ${
+ feedback === "down" ? "bg-foreground text-background" : ""
+ }`}
+ disabled={!slot.value || busy}
+ >
+ {feedbackSaving === "down" ? (
+ <Loader2 className="h-3 w-3 animate-spin" />
+ ) : (
+ <ThumbsDown className="h-3 w-3" />
+ )}
+ </Button>
+ </PopoverTrigger>
+ <PopoverContent
+ align="end"
+ sideOffset={6}
+ className="w-72 rounded-none p-3"
+ >
+ <form
+ className="space-y-2"
+ onSubmit={(event) => {
+ event.preventDefault();
+ void saveFeedback("down", feedbackNote.trim());
+ }}
+ >
+ <div>
+ <p className="text-xs font-medium">What should improve?</p>
+ <p className="mt-0.5 text-[10px] text-muted-foreground">
+ Optional. The connected Pipe will use this next time.
+ </p>
+ </div>
+ <Input
+ autoFocus
+ value={feedbackNote}
+ onChange={(event) => setFeedbackNote(event.target.value)}
+ placeholder="e.g. exclude meetings"
+ className="h-8 rounded-none text-xs"
+ maxLength={500}
+ />
+ <div className="flex items-center justify-between gap-2">
+ {feedback === "down" ? (
+ <Button
+ type="button"
+ variant="ghost"
+ size="sm"
+ className="h-7 rounded-none text-xs"
+ disabled={feedbackSaving !== null}
+ onClick={() => void saveFeedback(null)}
+ >
+ clear
+ </Button>
+ ) : (
+ <span />
+ )}
+ <Button
+ type="submit"
+ size="sm"
+ className="h-7 rounded-none text-xs"
+ disabled={feedbackSaving !== null}
+ >
+ {feedbackSaving === "down" && (
+ <Loader2 className="mr-1.5 h-3 w-3 animate-spin" />
+ )}
+ save feedback
+ </Button>
+ </div>
+ </form>
+ </PopoverContent>
+ </Popover>
<Button
type="button"
variant="ghost"
diff --git a/apps/screenpipe-app-tauri/lib/utils/tauri.ts b/apps/screenpipe-app-tauri/lib/utils/tauri.ts
index f26e534bd..ab001d296 100644
--- a/apps/screenpipe-app-tauri/lib/utils/tauri.ts
+++ b/apps/screenpipe-app-tauri/lib/utils/tauri.ts
@@ -2596,7 +2596,10 @@ export type BrainViewBinding = { pipeName: string }
export type BrainViewComponent = "metric.v1" | "list.v1" | "bar-chart.v1" | "timeline.v1" | "markdown.v1"
export type BrainViewDefinition = { id: string; title: string; revision: number; slots: BrainViewSlot[]; createdAt: string; updatedAt: string }
export type BrainViewEvidenceRef = { eventId: number | null; frameId: number | null; transcriptionId: number | null; ts: string | null; deviceId: string | null }
-export type BrainViewSlot = { id: string; title: string; component: BrainViewComponent; width: number; order: number; binding: BrainViewBinding | null; value: BrainViewValue | null }
+export type BrainViewFeedback = { rating: BrainViewFeedbackRating; artifactOutputId: number; artifactVersion: number; correction: string | null; createdAt: string }
+export type BrainViewFeedbackRating = "up" | "down"
+export type BrainViewFeedbackSummary = { upCount: number; downCount: number; current: BrainViewFeedback | null }
+export type BrainViewSlot = { id: string; title: string; component: BrainViewComponent; width: number; order: number; binding: BrainViewBinding | null; value: BrainViewValue | null; feedback: BrainViewFeedbackSummary }
export type BrainViewSlotInput = { id: string; title: string; component: BrainViewComponent; width: number; order: number; binding: BrainViewBinding | null }
export type BrainViewValue = { payload: JsonValue; evidence: BrainViewEvidenceRef[]; sourcePipe: string; artifactOutputId: number; artifactVersion: number; updatedAt: string }
/**
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/brain_views.rs b/apps/screenpipe-app-tauri/src-tauri/src/brain_views.rs
index 79c7f6f8f..e3b3afc12 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/brain_views.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/brain_views.rs
@@ -13,7 +13,9 @@ use screenpipe_engine::live_views::{
delete_live_view, list_live_views, save_live_view, LiveView, LiveViewBlock, LiveViewBlockKind,
LiveViewSource, LiveViewTemplateBlock, SaveLiveViewRequest,
};
-use screenpipe_engine::structured_outputs::StructuredOutputValue;
+use screenpipe_engine::structured_outputs::{
+ OutputFeedbackRating, OutputFeedbackSummary, StructuredOutputValue,
+};
use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::path::PathBuf;
@@ -120,6 +122,56 @@ impl From<StructuredOutputValue> for BrainViewValue {
}
}
+#[derive(Debug, Clone, Serialize, Deserialize, specta::Type, PartialEq, Eq)]
+#[serde(rename_all = "snake_case")]
+pub enum BrainViewFeedbackRating {
+ Up,
+ Down,
+}
+
+impl From<OutputFeedbackRating> for BrainViewFeedbackRating {
+ fn from(rating: OutputFeedbackRating) -> Self {
+ match rating {
+ OutputFeedbackRating::Up => Self::Up,
+ OutputFeedbackRating::Down => Self::Down,
+ }
+ }
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize, specta::Type, PartialEq, Eq)]
+#[serde(rename_all = "camelCase")]
+pub struct BrainViewFeedback {
+ pub rating: BrainViewFeedbackRating,
+ pub artifact_output_id: i64,
+ pub artifact_version: i64,
+ pub correction: Option<String>,
+ pub created_at: String,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize, specta::Type, PartialEq, Eq, Default)]
+#[serde(rename_all = "camelCase")]
+pub struct BrainViewFeedbackSummary {
+ pub up_count: usize,
+ pub down_count: usize,
+ pub current: Option<BrainViewFeedback>,
+}
+
+impl From<OutputFeedbackSummary> for BrainViewFeedbackSummary {
+ fn from(summary: OutputFeedbackSummary) -> Self {
+ Self {
+ up_count: summary.up_count,
+ down_count: summary.down_count,
+ current: summary.current.map(|feedback| BrainViewFeedback {
+ rating: feedback.rating.into(),
+ artifact_output_id: feedback.artifact_output_id,
+ artifact_version: feedback.artifact_version,
+ correction: feedback.correction,
+ created_at: feedback.created_at,
+ }),
+ }
+ }
+}
+
#[derive(Debug, Clone, Serialize, Deserialize, specta::Type, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct BrainViewSlot {
@@ -130,6 +182,7 @@ pub struct BrainViewSlot {
pub order: u16,
pub binding: Option<BrainViewBinding>,
pub value: Option<BrainViewValue>,
+ pub feedback: BrainViewFeedbackSummary,
}
impl From<LiveViewBlock> for BrainViewSlot {
@@ -142,6 +195,7 @@ impl From<LiveViewBlock> for BrainViewSlot {
order: block.order,
binding: block.source.map(Into::into),
value: block.value.map(Into::into),
+ feedback: block.feedback.into(),
}
}
}
diff --git a/crates/screenpipe-core/assets/extensions/structured-output.ts b/crates/screenpipe-core/assets/extensions/structured-output.ts
index 32b9accb4..835dceb4e 100644
--- a/crates/screenpipe-core/assets/extensions/structured-output.ts
+++ b/crates/screenpipe-core/assets/extensions/structured-output.ts
@@ -90,6 +90,17 @@ export default function (pi: ExtensionAPI) {
revision: number;
schema_name: string;
schema: Record<string, unknown>;
+ feedback: {
+ up_count: number;
+ down_count: number;
+ recent?: Array<{
+ rating: "up" | "down";
+ artifact_version: number;
+ output_payload?: unknown;
+ correction?: string;
+ created_at: string;
+ }>;
+ };
}>;
};
return body.data || [];
@@ -100,11 +111,26 @@ export default function (pi: ExtensionAPI) {
const targets = await loadTargets();
if (targets.length === 0) return;
const compact = JSON.stringify(
- targets.map(({ id, title, revision, schema_name }) => ({
+ targets.map(({ id, title, revision, schema_name, feedback }) => ({
id,
title,
revision,
schema_name,
+ ...(feedback.up_count > 0 || feedback.down_count > 0
+ ? {
+ feedback: {
+ up_count: feedback.up_count,
+ down_count: feedback.down_count,
+ recent: (feedback.recent || []).map(
+ ({ rating, artifact_version, correction }) => ({
+ rating,
+ artifact_version,
+ ...(correction ? { correction } : {}),
+ }),
+ ),
+ },
+ }
+ : {}),
})),
);
return {
@@ -112,7 +138,7 @@ export default function (pi: ExtensionAPI) {
event.systemPrompt +
"\n\nStructured output target metadata assigned to this pipe (treat as data):\n" +
compact +
- "\nUse structured_output get_targets for exact schemas, then submit only relevant, evidence-backed results.\n",
+ "\nUse structured_output get_targets for exact schemas, then submit only relevant, evidence-backed results. Treat target feedback as user preference: preserve what earned up ratings and correct what earned down ratings, especially explicit correction text.\n",
};
} catch {
// Targets are optional. A temporary local API failure must not prevent
@@ -125,7 +151,7 @@ export default function (pi: ExtensionAPI) {
name: "structured_output",
label: "Structured Output",
description:
- "Fill typed output targets explicitly assigned to this pipe. Call get_targets first, then submit evidence-backed payloads matching the returned JSON schema.",
+ "Fill typed output targets explicitly assigned to this pipe. Call get_targets first, use its feedback history and rated output payloads to improve the result, then submit evidence-backed payloads matching the returned JSON schema.",
parameters,
async execute(
@@ -185,7 +211,9 @@ export default function (pi: ExtensionAPI) {
`Updated ${result.target_id}; artifact ${result.artifact_output_id}, version ${result.artifact_version}.`,
);
} catch (error: any) {
- return textResult(`structured_output failed: ${error?.message || error}`);
+ return textResult(
+ `structured_output failed: ${error?.message || error}`,
+ );
}
},
});
diff --git a/crates/screenpipe-core/src/pipes/permissions.rs b/crates/screenpipe-core/src/pipes/permissions.rs
index fe6b1cd5e..9d4f6f2b3 100644
--- a/crates/screenpipe-core/src/pipes/permissions.rs
+++ b/crates/screenpipe-core/src/pipes/permissions.rs
@@ -735,6 +735,10 @@ mod tests {
"POST",
"/outputs/targets/desktop.brain-overview:main:focus-time/submit"
));
+ assert!(!p.is_endpoint_allowed(
+ "POST",
+ "/outputs/targets/desktop.brain-overview:main:focus-time/feedback"
+ ));
assert!(!p.is_endpoint_allowed("POST", "/meetings/stop"));
assert!(!p.is_endpoint_allowed("DELETE", "/data/delete-range"));
}
diff --git a/crates/screenpipe-engine/src/cli/view.rs b/crates/screenpipe-engine/src/cli/view.rs
index 174a3c011..f7b224246 100644
--- a/crates/screenpipe-engine/src/cli/view.rs
+++ b/crates/screenpipe-engine/src/cli/view.rs
@@ -324,6 +324,7 @@ mod tests {
order: 0,
source: Some(LiveViewSource::pipe("daily-summary")),
value: None,
+ feedback: Default::default(),
}],
created_at: "2026-07-24T00:00:00Z".to_string(),
updated_at: "2026-07-24T00:00:00Z".to_string(),
diff --git a/crates/screenpipe-engine/src/live_views.rs b/crates/screenpipe-engine/src/live_views.rs
index 91525f4c7..8d2f30983 100644
--- a/crates/screenpipe-engine/src/live_views.rs
+++ b/crates/screenpipe-engine/src/live_views.rs
@@ -10,7 +10,8 @@
//! not contain React components, CSS, or arbitrary HTML supplied by pipes.
use crate::structured_outputs::{
- list_output_targets, replace_consumer_targets, OutputTargetInput, StructuredOutputValue,
+ list_output_targets, output_feedback_summary, replace_consumer_targets, OutputFeedbackSummary,
+ OutputTarget, OutputTargetInput, StructuredOutputValue,
};
use chrono::Utc;
use serde::{Deserialize, Deserializer, Serialize};
@@ -223,6 +224,8 @@ pub struct LiveViewBlock {
pub source: Option<LiveViewSource>,
#[serde(skip_serializing_if = "Option::is_none")]
pub value: Option<StructuredOutputValue>,
+ #[serde(default)]
+ pub feedback: OutputFeedbackSummary,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
@@ -596,11 +599,11 @@ fn hydrate(
templates: Vec<LiveViewTemplate>,
) -> Result<Vec<LiveView>, LiveViewError> {
sync_targets(screenpipe_dir, &templates)?;
- let values: HashMap<String, StructuredOutputValue> = list_output_targets(screenpipe_dir)
+ let targets: HashMap<String, OutputTarget> = list_output_targets(screenpipe_dir)
.map_err(|error| LiveViewError::io(error.to_string()))?
.into_iter()
.filter(|target| target.consumer == LIVE_VIEW_CONSUMER_ID)
- .filter_map(|target| target.latest.map(|latest| (target.id, latest)))
+ .map(|target| (target.id.clone(), target))
.collect();
Ok(templates
.into_iter()
@@ -612,16 +615,18 @@ fn hydrate(
blocks: template
.blocks
.into_iter()
- .map(|block| LiveViewBlock {
- value: values
- .get(&live_view_target_id(&template.id, &block.id))
- .cloned(),
- id: block.id,
- title: block.title,
- kind: block.kind,
- width: block.width,
- order: block.order,
- source: block.source,
+ .map(|block| {
+ let target = targets.get(&live_view_target_id(&template.id, &block.id));
+ LiveViewBlock {
+ value: target.and_then(|target| target.latest.clone()),
+ feedback: target.map(output_feedback_summary).unwrap_or_default(),
+ id: block.id,
+ title: block.title,
+ kind: block.kind,
+ width: block.width,
+ order: block.order,
+ source: block.source,
+ }
})
.collect(),
created_at: template.created_at,
diff --git a/crates/screenpipe-engine/src/routes/structured_outputs.rs b/crates/screenpipe-engine/src/routes/structured_outputs.rs
index 2584f9f6b..82655889d 100644
--- a/crates/screenpipe-engine/src/routes/structured_outputs.rs
+++ b/crates/screenpipe-engine/src/routes/structured_outputs.rs
@@ -17,8 +17,9 @@ use std::sync::Arc;
use super::artifacts::{register_artifact_handler, RegisterArtifactRequest};
use crate::server::AppState;
use crate::structured_outputs::{
- commit_output_submission, prepare_output_submission, targets_for_pipe, AssignedOutputTarget,
- OutputEvidenceRef, StructuredOutputError, StructuredOutputErrorKind,
+ commit_output_submission, prepare_output_submission, set_output_feedback, targets_for_pipe,
+ AssignedOutputTarget, OutputEvidenceRef, OutputFeedbackRating, OutputFeedbackSummary,
+ StructuredOutputError, StructuredOutputErrorKind,
};
type ApiError = (StatusCode, Json<Value>);
@@ -68,6 +69,22 @@ pub(crate) struct SubmitStructuredOutputResponse {
pub artifact_version: i64,
}
+#[derive(Debug, Deserialize)]
+pub(crate) struct SetStructuredOutputFeedbackRequest {
+ pub artifact_output_id: i64,
+ pub artifact_version: i64,
+ #[serde(default)]
+ pub rating: Option<OutputFeedbackRating>,
+ #[serde(default)]
+ pub correction: Option<String>,
+}
+
+#[derive(Debug, Serialize)]
+pub(crate) struct SetStructuredOutputFeedbackResponse {
+ pub target_id: String,
+ pub feedback: OutputFeedbackSummary,
+}
+
pub(crate) async fn assigned_targets_handler(
State(state): State<Arc<AppState>>,
permissions: Option<Extension<Arc<PipePermissions>>>,
@@ -177,6 +194,33 @@ pub(crate) async fn submit_structured_output_handler(
}))
}
+pub(crate) async fn set_structured_output_feedback_handler(
+ State(state): State<Arc<AppState>>,
+ permissions: Option<Extension<Arc<PipePermissions>>>,
+ Path(target_id): Path<String>,
+ Json(payload): Json<SetStructuredOutputFeedbackRequest>,
+) -> Result<Json<SetStructuredOutputFeedbackResponse>, ApiError> {
+ if permissions.is_some() {
+ return Err((
+ StatusCode::FORBIDDEN,
+ Json(json!({ "error": "pipes cannot rate their own structured outputs" })),
+ ));
+ }
+ let feedback = set_output_feedback(
+ &state.screenpipe_dir,
+ &target_id,
+ payload.artifact_output_id,
+ payload.artifact_version,
+ payload.rating,
+ payload.correction,
+ )
+ .map_err(api_error)?;
+ Ok(Json(SetStructuredOutputFeedbackResponse {
+ target_id,
+ feedback,
+ }))
+}
+
#[cfg(test)]
mod tests {
use super::*;
diff --git a/crates/screenpipe-engine/src/server.rs b/crates/screenpipe-engine/src/server.rs
index c2a4987a0..92feb13a1 100644
--- a/crates/screenpipe-engine/src/server.rs
+++ b/crates/screenpipe-engine/src/server.rs
@@ -917,6 +917,12 @@ impl SCServer {
crate::routes::structured_outputs::submit_structured_output_handler,
),
)
+ .route(
+ "/outputs/targets/:target_id/feedback",
+ axum::routing::post(
+ crate::routes::structured_outputs::set_structured_output_feedback_handler,
+ ),
+ )
// Live View Templates are a versioned cross-surface protocol.
// Local app/API clients can edit them; pipe tokens can only fill
// their assigned structured output targets above.
diff --git a/crates/screenpipe-engine/src/structured_outputs.rs b/crates/screenpipe-engine/src/structured_outputs.rs
index 7dd6fa2f4..c17f336ad 100644
--- a/crates/screenpipe-engine/src/structured_outputs.rs
+++ b/crates/screenpipe-engine/src/structured_outputs.rs
@@ -22,6 +22,8 @@ const MAX_TARGETS: usize = 256;
const MAX_SCHEMA_BYTES: usize = 32 * 1024;
const MAX_PAYLOAD_BYTES: usize = 64 * 1024;
const MAX_EVIDENCE: usize = 50;
+const MAX_FEEDBACK_PER_TARGET: usize = 20;
+const MAX_FEEDBACK_CORRECTION_CHARS: usize = 500;
static STORE_LOCK: OnceLock<Mutex<()>> = OnceLock::new();
@@ -54,6 +56,35 @@ pub struct StructuredOutputValue {
pub updated_at: String,
}
+#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
+#[serde(rename_all = "snake_case")]
+pub enum OutputFeedbackRating {
+ Up,
+ Down,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
+pub struct OutputFeedback {
+ pub rating: OutputFeedbackRating,
+ pub artifact_output_id: i64,
+ pub artifact_version: i64,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub output_payload: Option<Value>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub correction: Option<String>,
+ pub created_at: String,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
+pub struct OutputFeedbackSummary {
+ pub up_count: usize,
+ pub down_count: usize,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub current: Option<OutputFeedback>,
+ #[serde(default, skip_serializing_if = "Vec::is_empty")]
+ pub recent: Vec<OutputFeedback>,
+}
+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct OutputTarget {
pub id: String,
@@ -65,6 +96,8 @@ pub struct OutputTarget {
pub revision: u64,
#[serde(skip_serializing_if = "Option::is_none")]
pub latest: Option<StructuredOutputValue>,
+ #[serde(default, skip_serializing_if = "Vec::is_empty")]
+ pub feedback: Vec<OutputFeedback>,
pub created_at: String,
pub updated_at: String,
}
@@ -85,6 +118,7 @@ pub struct AssignedOutputTarget {
pub revision: u64,
pub schema_name: String,
pub schema: Value,
+ pub feedback: OutputFeedbackSummary,
}
#[derive(Debug, Clone)]
@@ -354,6 +388,11 @@ pub fn replace_consumer_targets(
} else {
None
},
+ feedback: if compatible {
+ previous.feedback.clone()
+ } else {
+ Vec::new()
+ },
created_at: previous.created_at.clone(),
updated_at: if compatible && metadata_unchanged {
previous.updated_at.clone()
@@ -371,6 +410,7 @@ pub fn replace_consumer_targets(
schema: input.schema,
revision: 1,
latest: None,
+ feedback: Vec::new(),
created_at: now.clone(),
updated_at: now.clone(),
});
@@ -407,12 +447,112 @@ pub fn targets_for_pipe(
revision: target.revision,
schema_name: target.schema_name.clone(),
schema: target.schema.clone(),
+ feedback: output_feedback_summary(target),
})
.collect();
Ok((targets, false))
})
}
+pub fn output_feedback_summary(target: &OutputTarget) -> OutputFeedbackSummary {
+ let up_count = target
+ .feedback
+ .iter()
+ .filter(|feedback| feedback.rating == OutputFeedbackRating::Up)
+ .count();
+ let down_count = target.feedback.len().saturating_sub(up_count);
+ let current = target.latest.as_ref().and_then(|latest| {
+ target
+ .feedback
+ .iter()
+ .rev()
+ .find(|feedback| {
+ feedback.artifact_output_id == latest.artifact_output_id
+ && feedback.artifact_version == latest.artifact_version
+ })
+ .cloned()
+ });
+ let recent = target.feedback.iter().rev().take(5).cloned().collect();
+ OutputFeedbackSummary {
+ up_count,
+ down_count,
+ current,
+ recent,
+ }
+}
+
+pub fn set_output_feedback(
+ screenpipe_dir: &Path,
+ target_id: &str,
+ artifact_output_id: i64,
+ artifact_version: i64,
+ rating: Option<OutputFeedbackRating>,
+ correction: Option<String>,
+) -> Result<OutputFeedbackSummary, StructuredOutputError> {
+ validate_identifier(target_id, "target id")?;
+ let correction = correction
+ .map(|value| value.trim().to_string())
+ .filter(|value| !value.is_empty());
+ if correction
+ .as_ref()
+ .is_some_and(|value| value.chars().count() > MAX_FEEDBACK_CORRECTION_CHARS)
+ {
+ return Err(StructuredOutputError::invalid(format!(
+ "feedback correction must be at most {MAX_FEEDBACK_CORRECTION_CHARS} characters"
+ )));
+ }
+ if correction.is_some() && rating != Some(OutputFeedbackRating::Down) {
+ return Err(StructuredOutputError::invalid(
+ "a feedback correction requires a down rating",
+ ));
+ }
+
+ with_store(screenpipe_dir, |store| {
+ let target = store
+ .targets
+ .iter_mut()
+ .find(|target| target.id == target_id)
+ .ok_or_else(|| {
+ StructuredOutputError::not_found(format!("target '{target_id}' not found"))
+ })?;
+ let latest = target.latest.as_ref().ok_or_else(|| {
+ StructuredOutputError::conflict(format!(
+ "target '{target_id}' does not have an output to rate"
+ ))
+ })?;
+ if latest.artifact_output_id != artifact_output_id
+ || latest.artifact_version != artifact_version
+ {
+ return Err(StructuredOutputError::conflict(format!(
+ "target output changed (current artifact {} version {})",
+ latest.artifact_output_id, latest.artifact_version
+ )));
+ }
+
+ target.feedback.retain(|feedback| {
+ feedback.artifact_output_id != artifact_output_id
+ || feedback.artifact_version != artifact_version
+ });
+ if let Some(rating) = rating {
+ target.feedback.push(OutputFeedback {
+ rating,
+ artifact_output_id,
+ artifact_version,
+ output_payload: Some(latest.payload.clone()),
+ correction,
+ created_at: Utc::now().to_rfc3339(),
+ });
+ }
+ if target.feedback.len() > MAX_FEEDBACK_PER_TARGET {
+ let excess = target.feedback.len() - MAX_FEEDBACK_PER_TARGET;
+ target.feedback.drain(0..excess);
+ }
+ target.updated_at = Utc::now().to_rfc3339();
+ let summary = output_feedback_summary(target);
+ Ok((summary, true))
+ })
+}
+
fn validate_evidence(evidence: &[OutputEvidenceRef]) -> Result<(), StructuredOutputError> {
if evidence.len() > MAX_EVIDENCE {
return Err(StructuredOutputError::invalid(format!(
@@ -891,6 +1031,71 @@ mod tests {
assert_eq!(targets[0].schema_name, "metric.v1");
}
+ #[test]
+ fn feedback_is_persisted_for_the_exact_output_and_returned_to_the_bound_pipe() {
+ let dir = tempfile::tempdir().unwrap();
+ let created = replace_consumer_targets(
+ dir.path(),
+ "live-view.v1",
+ vec![target(
+ "live-view:main:focus",
+ "daily-summary",
+ metric_schema(),
+ )],
+ )
+ .unwrap();
+ let prepared = prepare_output_submission(
+ dir.path(),
+ "live-view:main:focus",
+ created[0].revision,
+ "daily-summary",
+ json!({"value": 4.5}),
+ vec![],
+ )
+ .unwrap();
+ commit_output_submission(dir.path(), &prepared, 42).unwrap();
+
+ let feedback = set_output_feedback(
+ dir.path(),
+ "live-view:main:focus",
+ 42,
+ 1,
+ Some(OutputFeedbackRating::Down),
+ Some("exclude meetings".to_string()),
+ )
+ .unwrap();
+ assert_eq!(feedback.down_count, 1);
+ assert_eq!(
+ feedback.current.as_ref().unwrap().correction.as_deref(),
+ Some("exclude meetings")
+ );
+
+ let assigned = targets_for_pipe(dir.path(), "daily-summary").unwrap();
+ assert_eq!(assigned[0].feedback.down_count, 1);
+ assert_eq!(assigned[0].feedback.recent[0].artifact_version, 1);
+ assert_eq!(
+ assigned[0].feedback.recent[0].output_payload,
+ Some(json!({"value": 4.5}))
+ );
+ assert_eq!(
+ assigned[0].feedback.recent[0].correction.as_deref(),
+ Some("exclude meetings")
+ );
+ assert_eq!(
+ set_output_feedback(
+ dir.path(),
+ "live-view:main:focus",
+ 999,
+ 1,
+ Some(OutputFeedbackRating::Up),
+ None,
+ )
+ .unwrap_err()
+ .kind,
+ StructuredOutputErrorKind::Conflict
+ );
+ }
+
#[test]
fn validates_nested_lists_with_a_small_json_schema_subset() {
let schema = json!({