Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions hub/client/application/hub/learnings-contracts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,27 @@ export const learningHistoryResponseSchema = z
otherEvidenceCount: count,
contradictions: z.array(learningEvidenceResponseSchema),
otherContradictionsCount: count,
outcomes: z.array(
z
.object({
id: z.string().min(1),
efficiency: z.number().int().min(1).max(4),
followed: z.enum(["followed", "not_followed", "unclear"]),
reasoning: z.string(),
issue: z.string().nullable(),
scoredAt: timestamp,
build: z
.object({
prototypeId: recordIdentifierSchema,
prototypeName: z.string().min(1),
number: identifier,
})
.strict(),
before: appliedScreenshotSchema.optional(),
after: appliedScreenshotSchema.optional(),
})
.strict(),
),
})
.strict() satisfies z.ZodType<LearningHistoryResponse>

Expand Down
15 changes: 15 additions & 0 deletions hub/client/application/hub/learnings-contracts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,21 @@ export interface LearningHistoryResponse {
otherEvidenceCount: number
contradictions: LearningEvidenceResponse[]
otherContradictionsCount: number
outcomes: LearningOutcomeResponse[]
}

/** How one use of a learning was scored, with the Build it judged. */
export interface LearningOutcomeResponse {
id: string
/** 4 is best. 1 and 2 come with an issue. */
efficiency: number
followed: "followed" | "not_followed" | "unclear"
reasoning: string
issue: string | null
scoredAt: string
build: { prototypeId: string; prototypeName: string; number: number }
before?: { sha256: string; route: string }
after?: { sha256: string; route: string }
}

/** A day's learning runs, kept for a year after the runs themselves are deleted. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ describe("learningsLibrary()", () => {
otherEvidenceCount: 2,
contradictions: [],
otherContradictionsCount: 0,
outcomes: [],
},
)

Expand Down Expand Up @@ -221,6 +222,7 @@ describe("learningsLibrary()", () => {
},
],
otherContradictionsCount: 1,
outcomes: [],
},
)

Expand All @@ -230,4 +232,75 @@ describe("learningsLibrary()", () => {
"1 more opposing comment that Hub cannot show here",
)
})

it("reads each score as a result, newest first", () => {
const state = emptyLearnings()
state.learnings = [
{
id: "mem_active",
title: "Keep labels visible",
content: "Show a label above every field.",
digest,
acceptedBy: "hubot",
acceptedAt: "2026-10-09T15:00:00Z",
edited: false,
lastDecision: "accepted",
status: "recalled",
shared: false,
},
]
const score = {
reasoning: "The form kept its labels.",
issue: null,
build: { prototypeId: "17", prototypeName: "Checkout", number: 3 },
}

const result = learningsLibrary(
state,
{ pathname, search: "?status=active&learning=mem_active" },
{
decisions: [],
evidence: [],
otherEvidenceCount: 0,
contradictions: [],
otherContradictionsCount: 0,
outcomes: [
{
...score,
id: "score_not_followed",
efficiency: 4,
followed: "not_followed",
scoredAt: "2026-10-10T00:00:00Z",
},
{
...score,
id: "score_concern",
efficiency: 2,
followed: "followed",
issue: "The rule did not say where the label goes.",
scoredAt: "2026-10-11T00:00:00Z",
},
{
...score,
id: "score_supports",
efficiency: 3,
followed: "followed",
scoredAt: "2026-10-12T00:00:00Z",
after: { sha256: "b".repeat(64), route: "/checkout" },
},
],
},
)

expect(result.selected?.outcomes?.map((outcome) => [outcome.result, outcome.summary])).toEqual([
["supports", "The form kept its labels."],
["concern", "The rule did not say where the label goes."],
["inconclusive", "The form kept its labels."],
])
expect(result.selected?.outcomes?.[0]).toMatchObject({
buildPath: "/repositories/2001/prototypes/17?build=3",
beforeScreenshotUrl: null,
afterScreenshotUrl: `/api/repositories/2001/learnings/screenshots/${"b".repeat(64)}`,
})
})
})
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import type {
LearningDetail,
LearningEvidence,
LearningOutcome,
LearningStatus,
LearningsLibraryData,
LibraryLearning,
} from "@features/learnings-library/types"
import type {
LearningEvidenceResponse,
LearningHistoryResponse,
LearningOutcomeResponse,
LearningsResponse,
} from "@application/hub/learnings-contracts/types"

Expand Down Expand Up @@ -74,6 +76,27 @@ function evidence(items: LearningEvidenceResponse[], repositoryId: string): Lear
}))
}

/**
* Reads a score as a plain result. A score only says something about the guidance when
* the agent followed it, and 3 or 4 means the work went well.
*/
function outcomes(items: LearningOutcomeResponse[], repositoryId: string): LearningOutcome[] {
function screenshot(value?: { sha256: string }) {
return value ? `/api/repositories/${repositoryId}/learnings/screenshots/${value.sha256}` : null
}
return items.toReversed().map((item) => ({
id: item.id,
result:
item.followed !== "followed" ? "inconclusive" : item.efficiency >= 3 ? "supports" : "concern",
summary: item.issue ?? item.reasoning,
buildLabel: `${item.build.prototypeName}, Build ${item.build.number}`,
buildPath: `/repositories/${repositoryId}/prototypes/${item.build.prototypeId}?build=${item.build.number}`,
evaluatedAt: item.scoredAt,
beforeScreenshotUrl: screenshot(item.before),
afterScreenshotUrl: screenshot(item.after),
}))
}

function parseStatus(value: string | null): LearningStatus | null {
return value === "suggested" || value === "active" || value === "rejected" ? value : null
}
Expand Down Expand Up @@ -227,6 +250,8 @@ function detail(
by: entry.by?.includes(":") ? null : entry.by,
reason: entry.reason,
})),
// Only guidance agents get now can have later Builds to judge.
outcomes: record.status === "active" ? outcomes(history?.outcomes ?? [], repositoryId) : null,
source: record.source,
share: null,
}
Expand Down
79 changes: 79 additions & 0 deletions hub/client/features/learnings-library/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { useEffect, useRef, useState, type ReactNode } from "react"
import {
AlertIcon,
ArrowLeftIcon,
CheckCircleIcon,
CircleIcon,
LightBulbIcon,
SearchIcon,
XCircleIcon,
Expand Down Expand Up @@ -32,6 +34,7 @@ import { ReviewRelativeTime } from "@features/review-relative-time"
import type {
LearningDetail,
LearningEvidence,
LearningOutcome,
LearningStatus,
LearningsLibraryData,
} from "./types"
Expand Down Expand Up @@ -65,6 +68,19 @@ const emptyMessages: Record<LearningStatus, string> = {
rejected: "Learnings you reject or stop using stay here so you can accept them again.",
}

const outcomeLabels: Record<LearningOutcome["result"], string> = {
supports: "Supports the guidance",
concern: "Possible concern",
inconclusive: "Inconclusive",
}

// A result icon sets outcomes apart from review comments, which lead with an avatar.
const outcomeIcons: Record<LearningOutcome["result"], Icon> = {
supports: CheckCircleIcon,
concern: AlertIcon,
inconclusive: CircleIcon,
}

/** Renders a learning's state icon; Brand labels need an element, not a component. */
function StatusIcon({ status, className }: { status: LearningStatus; className?: string }) {
const Glyph = statusIcons[status]
Expand Down Expand Up @@ -415,6 +431,15 @@ function LearningDetailView({
</DetailSection>
) : null}

{learning.outcomes ? (
<DetailSection
heading="Observed outcomes"
description="How later Builds did with this guidance."
>
<OutcomeList outcomes={learning.outcomes} />
</DetailSection>
) : null}

{decision && dialog ? (
<CanvasDialog
title={
Expand Down Expand Up @@ -529,6 +554,60 @@ function DetailSection({
)
}

function OutcomeList({ outcomes }: { outcomes: LearningOutcome[] }) {
if (!outcomes.length) {
return (
<Text as="p" size="200" variant="muted">
Not evaluated yet.
</Text>
)
}
return (
<ul className="learning-library__evidence-list">
{outcomes.map((outcome) => {
const ResultIcon = outcomeIcons[outcome.result]
return (
<li className="learning-library__evidence-item" key={outcome.id}>
<div className="learning-library__evidence-meta">
<span
className={`learning-library__outcome-result learning-library__outcome-result--${outcome.result}`}
>
<ResultIcon size={16} />
<strong>{outcomeLabels[outcome.result]}</strong>
</span>
<span aria-hidden="true">·</span>
<span>Automated assessment</span>
<span aria-hidden="true">·</span>
<a href={outcome.buildPath}>{outcome.buildLabel}</a>
<span aria-hidden="true">·</span>
<ReviewRelativeTime value={outcome.evaluatedAt} />
</div>
{outcome.summary ? (
<Text as="p" size="200">
{outcome.summary}
</Text>
) : null}
{outcome.beforeScreenshotUrl || outcome.afterScreenshotUrl ? (
<div className="learning-library__evidence-meta">
{outcome.beforeScreenshotUrl ? (
<a href={outcome.beforeScreenshotUrl} target="_blank" rel="noreferrer">
Before screenshot
</a>
) : null}
{outcome.afterScreenshotUrl ? (
<a href={outcome.afterScreenshotUrl} target="_blank" rel="noreferrer">
After screenshot
</a>
) : null}
</div>
) : null}
</li>
)
})}
</ul>
)
}

function EvidenceList({ evidence, other }: { evidence: LearningEvidence[]; other: string | null }) {
return (
<>
Expand Down
15 changes: 15 additions & 0 deletions hub/client/features/learnings-library/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,21 @@
color: var(--hub-fg-link);
}

.learning-library__outcome-result {
display: inline-flex;
align-items: center;
gap: 0.25rem;
color: var(--hub-fg-default);
}

.learning-library__outcome-result--supports svg {
color: var(--hub-fg-success);
}

.learning-library__outcome-result--concern svg {
color: var(--hub-attention);
}

@container (max-width: 40rem) {
.learning-library__toolbar {
align-items: stretch;
Expand Down
14 changes: 14 additions & 0 deletions hub/client/features/learnings-library/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ export interface LearningHistoryEntry {
}

/** Everything the detail view shows for the selected learning. */
/** How one later Build did with a learning's guidance. */
export interface LearningOutcome {
id: string
result: "supports" | "concern" | "inconclusive"
summary: string
buildLabel: string
buildPath: string
evaluatedAt: string
beforeScreenshotUrl: string | null
afterScreenshotUrl: string | null
}

export interface LearningDetail {
id: string
status: LearningStatus
Expand All @@ -50,6 +62,8 @@ export interface LearningDetail {
contradictions: LearningEvidence[]
otherContradictions: string | null
history: LearningHistoryEntry[]
/** How later Builds did with the current wording. Null when agents don't get it. */
outcomes: LearningOutcome[] | null
/**
* Present only when the viewer can decide and the stored version is intact. The
* title and content are the stored wording, which the edit form starts from.
Expand Down
Loading
Loading