diff --git a/hub/client/application/hub/learnings-contracts/index.ts b/hub/client/application/hub/learnings-contracts/index.ts index 866b3683..d77c9a07 100644 --- a/hub/client/application/hub/learnings-contracts/index.ts +++ b/hub/client/application/hub/learnings-contracts/index.ts @@ -125,6 +125,31 @@ export const appliedLearningsResponseSchema = z }) .strict() satisfies z.ZodType +const buildSchema = z + .object({ + prototypeId: recordIdentifierSchema, + prototypeName: z.string().min(1), + number: identifier, + }) + .strict() + +const learningOutcomeResponseSchema = z + .object({ + id: z.string().min(1), + source: z.enum(["automated", "reviewer_confirmed"]), + 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: buildSchema, + before: appliedScreenshotSchema.optional(), + after: appliedScreenshotSchema.optional(), + }) + .strict() + +const proposalId = z.string().regex(/^[a-z][a-z0-9]{1,15}_[A-Za-z0-9_-]{8,128}$/) + export const learningHistoryResponseSchema = z .object({ decisions: z.array( @@ -143,28 +168,30 @@ export const learningHistoryResponseSchema = z otherEvidenceCount: count, contradictions: z.array(learningEvidenceResponseSchema), otherContradictionsCount: count, - outcomes: z.array( + outcomes: z.array(learningOutcomeResponseSchema), + earlierGuidance: z.array( z .object({ - id: z.string().min(1), - source: z.enum(["automated", "reviewer_confirmed"]), - efficiency: z.number().int().min(1).max(4), - followed: z.enum(["followed", "not_followed", "unclear"]), + version: identifier, + title: z.string().nullable(), + content: z.string(), + outcomes: z.array(learningOutcomeResponseSchema), + }) + .strict(), + ), + updates: z.array( + z + .object({ + id: proposalId, + issue: z.string(), + title: z.string().nullable(), + content: z.string(), 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(), + support: z.array(buildSchema), }) .strict(), ), + updateNeedsMoreEvidence: z.boolean(), }) .strict() satisfies z.ZodType @@ -309,6 +336,22 @@ export const learningDecisionInputSchema = z.discriminatedUnion("decision", [ reason: z.string().trim().min(1).max(500), }) .strict(), + z + .object({ + decision: z.literal("apply_update"), + proposalId, + title: titleInput.optional(), + content: z.string().trim().min(1).max(2000).optional(), + reason: z.string().trim().min(1).max(500), + }) + .strict(), + z + .object({ + decision: z.literal("dismiss_update"), + proposalId, + reason: z.string().trim().min(1).max(500), + }) + .strict(), ]) satisfies z.ZodType export const learningShareInputSchema = z diff --git a/hub/client/application/hub/learnings-contracts/types.ts b/hub/client/application/hub/learnings-contracts/types.ts index 1574a0e4..699275c3 100644 --- a/hub/client/application/hub/learnings-contracts/types.ts +++ b/hub/client/application/hub/learnings-contracts/types.ts @@ -85,6 +85,28 @@ export interface LearningHistoryResponse { contradictions: LearningEvidenceResponse[] otherContradictionsCount: number outcomes: LearningOutcomeResponse[] + /** Wording agents were given before the current version, newest first. */ + earlierGuidance: Array<{ + version: number + title: string | null + content: string + outcomes: LearningOutcomeResponse[] + }> + /** Suggested new wording waiting for an administrator. */ + updates: LearningUpdateResponse[] + /** Whether the last check found too few scored uses to suggest new wording. */ + updateNeedsMoreEvidence: boolean +} + +/** Suggested new wording, drafted because scored uses kept showing the same issue. */ +export interface LearningUpdateResponse { + id: string + issue: string + title: string | null + content: string + reasoning: string + /** The Builds whose scores showed the issue. */ + support: LearningOutcomeResponse["build"][] } /** How one use of a learning was scored, with the Build it judged. */ @@ -174,6 +196,14 @@ export type LearningDecisionInput = | { decision: "retire"; reason: string } | { decision: "edit"; digest: string; title?: string; content?: string; reason: string } | { decision: "reinstate"; digest: string; reason: string } + | { + decision: "apply_update" + proposalId: string + title?: string + content?: string + reason: string + } + | { decision: "dismiss_update"; proposalId: string; reason: string } export interface LearningShareInput { shared: boolean diff --git a/hub/client/application/hub/routes/settings-learnings/index.tsx b/hub/client/application/hub/routes/settings-learnings/index.tsx index a51c9dcb..741a12f5 100644 --- a/hub/client/application/hub/routes/settings-learnings/index.tsx +++ b/hub/client/application/hub/routes/settings-learnings/index.tsx @@ -355,7 +355,17 @@ function submitDecision( } : decision === "reinstate" ? { decision, digest: form.get("digest"), reason: form.get("reason") } - : { decision } + : decision === "apply_update" + ? { + decision, + proposalId: form.get("proposalId"), + ...(typeof title === "string" && title.trim() ? { title } : {}), + content: form.get("content"), + reason: form.get("reason"), + } + : decision === "dismiss_update" + ? { decision, proposalId: form.get("proposalId"), reason: form.get("reason") } + : { decision } const parsed = learningDecisionInputSchema.safeParse(input) if (!parsed.success) { throw new Response(parsed.error.issues.map(({ message }) => message).join(" "), { status: 422 }) diff --git a/hub/client/application/hub/view-models/learnings-library/index.test.ts b/hub/client/application/hub/view-models/learnings-library/index.test.ts index 2822ec33..d507a791 100644 --- a/hub/client/application/hub/view-models/learnings-library/index.test.ts +++ b/hub/client/application/hub/view-models/learnings-library/index.test.ts @@ -107,6 +107,9 @@ describe("learningsLibrary()", () => { contradictions: [], otherContradictionsCount: 0, outcomes: [], + earlierGuidance: [], + updates: [], + updateNeedsMoreEvidence: false, }, ) @@ -223,6 +226,9 @@ describe("learningsLibrary()", () => { ], otherContradictionsCount: 1, outcomes: [], + earlierGuidance: [], + updates: [], + updateNeedsMoreEvidence: false, }, ) @@ -265,6 +271,9 @@ describe("learningsLibrary()", () => { otherEvidenceCount: 0, contradictions: [], otherContradictionsCount: 0, + earlierGuidance: [], + updates: [], + updateNeedsMoreEvidence: false, outcomes: [ { ...score, @@ -306,4 +315,64 @@ describe("learningsLibrary()", () => { afterScreenshotUrl: `/api/repositories/2001/learnings/screenshots/${"b".repeat(64)}`, }) }) + + it("links each Build that showed a suggested update's issue once", () => { + 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 result = learningsLibrary( + state, + { pathname, search: "?status=active&learning=mem_active" }, + { + decisions: [], + evidence: [], + otherEvidenceCount: 0, + contradictions: [], + otherContradictionsCount: 0, + earlierGuidance: [], + updateNeedsMoreEvidence: false, + // A reviewer's later score replaced these in the current list, but the + // suggestion still links the Builds it was drafted from. + outcomes: [], + updates: [ + { + id: "upd_1", + issue: "The rule did not say where the label goes.", + title: null, + content: "Show a label above every field, outside the input.", + reasoning: "Builds kept placing labels inside inputs.", + // Both scores of one Build supported it. + support: [ + { prototypeId: "17", prototypeName: "Checkout", number: 3 }, + { prototypeId: "17", prototypeName: "Checkout", number: 3 }, + ], + }, + ], + }, + ) + + expect(result.selected?.updates).toEqual([ + { + id: "upd_1", + issue: "The rule did not say where the label goes.", + title: null, + content: "Show a label above every field, outside the input.", + reasoning: "Builds kept placing labels inside inputs.", + support: [{ label: "Checkout, Build 3", path: "/repositories/2001/prototypes/17?build=3" }], + }, + ]) + }) }) diff --git a/hub/client/application/hub/view-models/learnings-library/index.ts b/hub/client/application/hub/view-models/learnings-library/index.ts index 30915bb3..40851494 100644 --- a/hub/client/application/hub/view-models/learnings-library/index.ts +++ b/hub/client/application/hub/view-models/learnings-library/index.ts @@ -80,6 +80,13 @@ 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 buildLink(build: LearningOutcomeResponse["build"], repositoryId: string) { + return { + label: `${build.prototypeName}, Build ${build.number}`, + path: `/repositories/${repositoryId}/prototypes/${build.prototypeId}?build=${build.number}`, + } +} + function outcomes(items: LearningOutcomeResponse[], repositoryId: string): LearningOutcome[] { function screenshot(value?: { sha256: string }) { return value ? `/api/repositories/${repositoryId}/learnings/screenshots/${value.sha256}` : null @@ -90,8 +97,8 @@ function outcomes(items: LearningOutcomeResponse[], repositoryId: string): Learn item.followed !== "followed" ? "inconclusive" : item.efficiency >= 3 ? "supports" : "concern", reviewerConfirmed: item.source === "reviewer_confirmed", summary: item.issue ?? item.reasoning, - buildLabel: `${item.build.prototypeName}, Build ${item.build.number}`, - buildPath: `/repositories/${repositoryId}/prototypes/${item.build.prototypeId}?build=${item.build.number}`, + buildLabel: buildLink(item.build, repositoryId).label, + buildPath: buildLink(item.build, repositoryId).path, evaluatedAt: item.scoredAt, beforeScreenshotUrl: screenshot(item.before), afterScreenshotUrl: screenshot(item.after), @@ -227,6 +234,7 @@ function detail( const repositoryId = state.repository.id const path = `/repositories/${repositoryId}/learnings/${encodeURIComponent(record.id)}/decision` const canDecide = state.permissions.decide + const current = outcomes(history?.outcomes ?? [], repositoryId) const common = { id: record.id, status: record.status, @@ -252,7 +260,15 @@ function detail( reason: entry.reason, })), // Only guidance agents get now can have later Builds to judge. - outcomes: record.status === "active" ? outcomes(history?.outcomes ?? [], repositoryId) : null, + outcomes: record.status === "active" ? current : null, + updates: [], + updateNeedsMoreEvidence: false, + earlierGuidance: (history?.earlierGuidance ?? []).map((guidance) => ({ + version: guidance.version, + title: guidance.title, + guidance: guidance.content, + outcomes: outcomes(guidance.outcomes, repositoryId), + })), source: record.source, share: null, } @@ -317,6 +333,23 @@ function detail( recallFact(accepted.status), ...(accepted.shared ? ["Shared across Hub"] : []), ], + updates: (history?.updates ?? []).map((update) => ({ + id: update.id, + issue: update.issue, + title: update.title, + content: update.content, + reasoning: update.reasoning, + // Both scores of one Build can support a suggestion, so each Build is linked once. + support: [ + ...new Map( + update.support.map((build) => { + const link = buildLink(build, repositoryId) + return [link.path, link] + }), + ).values(), + ], + })), + updateNeedsMoreEvidence: history?.updateNeedsMoreEvidence ?? false, decision: canDecide && accepted.digest && accepted.content !== null ? { diff --git a/hub/client/features/learnings-library/index.tsx b/hub/client/features/learnings-library/index.tsx index 26e36995..7b4fa372 100644 --- a/hub/client/features/learnings-library/index.tsx +++ b/hub/client/features/learnings-library/index.tsx @@ -36,6 +36,7 @@ import type { LearningEvidence, LearningOutcome, LearningStatus, + LearningUpdate, LearningsLibraryData, } from "./types" import "./styles.css" @@ -255,6 +256,16 @@ function LearningDetailView({ error: { error: string } | null }) { const [dialog, setDialog] = useState<"reject" | "edit" | "retire" | "reinstate" | null>(null) + const [openedUpdate, setUpdateDialog] = useState<{ + action: "apply" | "dismiss" + update: LearningUpdate + } | null>(null) + // A decided suggestion leaves the refreshed list, so its dialog has nothing to submit. + // A failed attempt keeps the suggestion, and with it the person's draft. + const updateDialog = + openedUpdate && learning.updates.some(({ id }) => id === openedUpdate.update.id) + ? openedUpdate + : null // An error from an earlier attempt does not belong to a dialog opened afterwards. const [staleError, setStaleError] = useState(error) const decision = learning.decision @@ -266,6 +277,11 @@ function LearningDetailView({ setDialog(next) } + function openUpdate(next: NonNullable) { + setStaleError(error) + setUpdateDialog(next) + } + return (
@@ -431,12 +447,94 @@ function LearningDetailView({ ) : null} + {learning.updates.map((update) => ( + +
+ + Issue: {update.issue} + + {update.title ? ( + + New title: {update.title} + + ) : null} + + {update.content} + +
+
+ {decision ? ( +
+ + +
+ ) : null} + + ))} + {learning.outcomes ? ( + {learning.updateNeedsMoreEvidence ? ( + + Not enough Builds show the same issue to suggest new wording yet. + + ) : null} + + ) : null} + + {learning.earlierGuidance.length ? ( + + {learning.earlierGuidance.map((guidance) => ( +
+
+ + Version {guidance.version} + {guidance.title ? ` · ${guidance.title}` : null} + + + {guidance.guidance} + +
+ +
+ ))}
) : null} @@ -528,6 +626,87 @@ function LearningDetailView({ ) : null} + + {decision && updateDialog ? ( + setUpdateDialog(null)} + > +

+ {updateDialog.action === "apply" + ? "Agents get this wording. You can change it before applying." + : "Copilot suggests it again only when new Builds show the issue."} +

+ {error && error !== staleError ? ( + + ) : null} + + {updateDialog.action === "apply" ? ( + <> + {/* A blank title would fall back to the suggested one, so a suggested + title must be kept or reworded rather than cleared. */} + + Title + + + + Guidance +