diff --git a/web/public/bundles/artemis/journeys.json b/web/public/bundles/artemis/journeys.json new file mode 100644 index 00000000..757e076f --- /dev/null +++ b/web/public/bundles/artemis/journeys.json @@ -0,0 +1,769 @@ +{ + "lanes": [ + "Browser", + "Web entry", + "Feature services", + "Course core", + "Queues & workers" + ], + "journeys": [ + { + "id": "push", + "name": "A student pushes code for a programming exercise", + "summary": "8 stops · 4 modules · 1 queue · ends with a live score in the browser", + "stops": [ + { + "lane": 0, + "module": "client", + "label": "git push", + "caption": "The student pushes their solution with git. Artemis hosts the repository itself, so the push goes straight to the server.", + "file": "git client → /git/ARTEMIS101/artemis101-alice.git", + "method": "HTTP POST · git-receive-pack", + "via": null, + "findingRank": null, + "payload": { + "type": "GitPush", + "definedIn": "git smart HTTP", + "fields": [ + { + "key": "ref", + "value": "\"refs/heads/main\"" + }, + { + "key": "commit", + "value": "\"8f2c1e4\"" + }, + { + "key": "changedFiles", + "value": "3" + } + ] + } + }, + { + "lane": 1, + "module": "programming", + "label": "accept push", + "caption": "The git servlet checks that the student is allowed to push and finds which participation the repository belongs to.", + "file": "programming/service/localvc/LocalVCServletService.java:412", + "method": "processNewPush(commitHash, repository)", + "via": { + "kind": "call", + "label": "HTTP request" + }, + "findingRank": null, + "payload": { + "type": "PushContext", + "definedIn": "LocalVCServletService.java", + "fields": [ + { + "key": "commit", + "value": "\"8f2c1e4\"" + }, + { + "key": "participationId", + "value": "48213" + }, + { + "key": "exerciseId", + "value": "3071" + }, + { + "key": "branch", + "value": "\"main\"" + } + ] + } + }, + { + "lane": 2, + "module": "programming", + "label": "save submission", + "caption": "A submission record is saved for this commit, so the build result can be attached to it later.", + "file": "programming/service/ProgrammingSubmissionService.java:118", + "method": "processNewProgrammingSubmission(participation, commit)", + "via": { + "kind": "call", + "label": "method call" + }, + "findingRank": null, + "payload": { + "type": "ProgrammingSubmission", + "definedIn": "programming/domain/ProgrammingSubmission.java", + "fields": [ + { + "key": "id", + "value": "902114" + }, + { + "key": "commitHash", + "value": "\"8f2c1e4\"" + }, + { + "key": "participationId", + "value": "48213" + }, + { + "key": "type", + "value": "\"MANUAL\"" + }, + { + "key": "submissionDate", + "value": "\"2026-11-27T14:02:11Z\"" + } + ] + } + }, + { + "lane": 4, + "module": "programming", + "label": "queue build", + "caption": "Instead of building right away, the job goes onto a shared queue so that any free build agent can pick it up.", + "file": "programming/service/localci/LocalCITriggerService.java:96", + "method": "triggerBuild(participation, commitHash)", + "via": { + "kind": "queue", + "label": "Hazelcast queue buildJobQueue" + }, + "findingRank": null, + "payload": { + "type": "BuildJobQueueItem", + "definedIn": "buildagent/dto/BuildJobQueueItem.java", + "fields": [ + { + "key": "id", + "value": "\"bj-77a1\"" + }, + { + "key": "participationId", + "value": "48213" + }, + { + "key": "repositoryUri", + "value": "\"…/artemis101-alice.git\"" + }, + { + "key": "commitHash", + "value": "\"8f2c1e4\"" + }, + { + "key": "priority", + "value": "2" + }, + { + "key": "buildConfig", + "value": "{ dockerImage: \"ls1tum/artemis-maven\", timeoutSec: 120 }" + } + ] + } + }, + { + "lane": 4, + "module": "buildagent", + "label": "run tests", + "caption": "A build agent takes the job, runs the instructor's tests in a container, and reports which tests passed.", + "file": "buildagent/service/BuildJobExecutionService.java:201", + "method": "runBuildJob(buildJob, containerName)", + "via": { + "kind": "queue", + "label": "polled from buildJobQueue" + }, + "findingRank": null, + "payload": { + "type": "BuildResult", + "definedIn": "buildagent/dto/BuildResult.java", + "fields": [ + { + "key": "jobId", + "value": "\"bj-77a1\"" + }, + { + "key": "successful", + "value": "false" + }, + { + "key": "testResults", + "value": "[ 17 passed, 3 failed ]" + }, + { + "key": "buildLogs", + "value": "\"214 lines\"" + }, + { + "key": "durationMs", + "value": "38412" + } + ] + } + }, + { + "lane": 3, + "module": "assessment", + "label": "score result", + "caption": "The test results become a score with one piece of feedback per test, and it is stored against the submission.", + "file": "assessment/service/ResultService.java:233", + "method": "processNewProgrammingExerciseResult(participation, buildResult)", + "via": { + "kind": "queue", + "label": "Hazelcast result queue" + }, + "findingRank": null, + "payload": { + "type": "Result", + "definedIn": "assessment/domain/Result.java", + "fields": [ + { + "key": "id", + "value": "1500872" + }, + { + "key": "submissionId", + "value": "902114" + }, + { + "key": "score", + "value": "85.0" + }, + { + "key": "successful", + "value": "false" + }, + { + "key": "feedbacks", + "value": "[ 20 items ]" + }, + { + "key": "completionDate", + "value": "\"2026-11-27T14:02:52Z\"" + } + ] + } + }, + { + "lane": 1, + "module": "communication", + "label": "push to browser", + "caption": "The new result is sent over a websocket to the topic the student's browser is already listening on.", + "file": "communication/service/WebsocketMessagingService.java:58", + "method": "sendMessage(\"/topic/participation/48213/newResults\", result)", + "via": { + "kind": "call", + "label": "method call" + }, + "findingRank": null, + "payload": { + "type": "ResultDTO", + "definedIn": "assessment/dto/ResultDTO.java", + "fields": [ + { + "key": "topic", + "value": "\"/topic/participation/48213/newResults\"" + }, + { + "key": "score", + "value": "85.0" + }, + { + "key": "successful", + "value": "false" + }, + { + "key": "testCaseCount", + "value": "20" + }, + { + "key": "passedTestCaseCount", + "value": "17" + } + ] + } + }, + { + "lane": 0, + "module": "client", + "label": "show score", + "caption": "The exercise page updates without a reload and shows 85% with the three failing tests listed.", + "file": "webapp/app/programming/…/result.component.ts", + "method": "subscribe → onNewResult(result)", + "via": { + "kind": "ws", + "label": "websocket" + }, + "findingRank": null, + "payload": { + "type": "UI state", + "definedIn": "Angular component", + "fields": [ + { + "key": "badge", + "value": "\"85 %\"" + }, + { + "key": "passed", + "value": "\"17 of 20 tests\"" + }, + { + "key": "failing", + "value": "[\"testSortEmpty\", \"testSortNull\", \"testStable\"]" + } + ] + } + } + ] + }, + { + "id": "exam", + "name": "An instructor starts an exam for 412 students", + "summary": "7 stops · 3 modules · 1 step is a finding", + "stops": [ + { + "lane": 0, + "module": "client", + "label": "click Start", + "caption": "The instructor clicks Start exercises on the exam page.", + "file": "webapp/app/exam/manage/exam-checklist.component.ts", + "method": "POST /api/exam/courses/12/exams/77/student-exams/start-exercises", + "via": null, + "findingRank": null, + "payload": { + "type": "HTTP request", + "definedIn": "REST", + "fields": [ + { + "key": "courseId", + "value": "12" + }, + { + "key": "examId", + "value": "77" + } + ] + } + }, + { + "lane": 1, + "module": "exam", + "label": "exam endpoint", + "caption": "The exam endpoint checks the instructor's role and hands the work to the exam service.", + "file": "exam/web/StudentExamResource.java:340", + "method": "startExercises(courseId, examId)", + "via": { + "kind": "call", + "label": "HTTP request" + }, + "findingRank": null, + "payload": { + "type": "StartRequest", + "definedIn": "exam/web/StudentExamResource.java", + "fields": [ + { + "key": "courseId", + "value": "12" + }, + { + "key": "examId", + "value": "77" + }, + { + "key": "requestedBy", + "value": "\"instructor42\"" + } + ] + } + }, + { + "lane": 2, + "module": "exam", + "label": "plan participations", + "caption": "The service loads every student exam and works out which exercises each student gets.", + "file": "exam/service/StudentExamService.java:512", + "method": "startExercises(examId)", + "via": { + "kind": "call", + "label": "method call" + }, + "findingRank": null, + "payload": { + "type": "List", + "definedIn": "exam/domain/StudentExam.java", + "fields": [ + { + "key": "examId", + "value": "77" + }, + { + "key": "studentExams", + "value": "412" + }, + { + "key": "exercisesPerStudent", + "value": "5" + } + ] + } + }, + { + "lane": 4, + "module": "programming", + "label": "read repo table", + "caption": "Exam reads programming's repository class directly to load the exercise templates. That repository is used by 107 files and changed 30 times in 12 months, which is finding #22.", + "file": "exam/service/StudentExamService.java:548 → programming/repository/ProgrammingExerciseRepository.java", + "method": "findByIdWithTemplateAndSolutionParticipationElseThrow(id)", + "via": { + "kind": "find", + "label": "direct repository access" + }, + "findingRank": 22, + "payload": { + "type": "ProgrammingExercise", + "definedIn": "programming/domain/ProgrammingExercise.java", + "fields": [ + { + "key": "id", + "value": "3071" + }, + { + "key": "templateParticipation", + "value": "{ id: 901 }" + }, + { + "key": "solutionParticipation", + "value": "{ id: 902 }" + }, + { + "key": "buildConfig", + "value": "{ … }" + } + ] + } + }, + { + "lane": 2, + "module": "programming", + "label": "create participations", + "caption": "For each student, a personal repository is copied from the template and a participation is created.", + "file": "programming/service/ParticipationService.java:190", + "method": "startExercise(exercise, student)", + "via": { + "kind": "call", + "label": "method call" + }, + "findingRank": null, + "payload": { + "type": "StudentParticipation", + "definedIn": "exercise/domain/participation/StudentParticipation.java", + "fields": [ + { + "key": "created", + "value": "412" + }, + { + "key": "failed", + "value": "0" + }, + { + "key": "repositoriesCopied", + "value": "412" + } + ] + } + }, + { + "lane": 1, + "module": "communication", + "label": "report progress", + "caption": "Progress is pushed to the instructor's page while students are processed.", + "file": "exam/service/StudentExamService.java:603", + "method": "convertAndSend(\"/topic/exams/77/exercise-start-status\")", + "via": { + "kind": "call", + "label": "method call" + }, + "findingRank": null, + "payload": { + "type": "ExerciseStartStatus", + "definedIn": "exam/dto/ExamExerciseStartPreparationStatus.java", + "fields": [ + { + "key": "finished", + "value": "412" + }, + { + "key": "failed", + "value": "0" + }, + { + "key": "participationCount", + "value": "2060" + } + ] + } + }, + { + "lane": 0, + "module": "client", + "label": "show 100%", + "caption": "The progress bar reaches 412 of 412 and the exam can open.", + "file": "webapp/app/exam/manage/exam-checklist.component.ts", + "method": "subscribe → updateProgress(status)", + "via": { + "kind": "ws", + "label": "websocket" + }, + "findingRank": null, + "payload": { + "type": "UI state", + "definedIn": "Angular component", + "fields": [ + { + "key": "progress", + "value": "\"412 / 412\"" + }, + { + "key": "readyToOpen", + "value": "true" + } + ] + } + } + ] + }, + { + "id": "grade", + "name": "A tutor grades a text answer", + "summary": "7 stops · 4 modules · ends with a notification to the student", + "stops": [ + { + "lane": 0, + "module": "client", + "label": "submit grade", + "caption": "The tutor highlights parts of the answer, adds comments, and clicks Submit.", + "file": "webapp/app/text/manage/assess/text-submission-assessment.component.ts", + "method": "PUT /api/text/participations/5521/results/889/submit-text-assessment", + "via": null, + "findingRank": null, + "payload": { + "type": "HTTP body", + "definedIn": "REST", + "fields": [ + { + "key": "feedbacks", + "value": "[ 4 items ]" + }, + { + "key": "textBlocks", + "value": "[ 6 items ]" + } + ] + } + }, + { + "lane": 1, + "module": "text", + "label": "grading endpoint", + "caption": "The text endpoint checks that this tutor holds the lock on the submission.", + "file": "text/web/TextAssessmentResource.java:171", + "method": "submitTextAssessment(participationId, resultId, dto)", + "via": { + "kind": "call", + "label": "HTTP request" + }, + "findingRank": null, + "payload": { + "type": "TextAssessmentDTO", + "definedIn": "text/dto/TextAssessmentDTO.java", + "fields": [ + { + "key": "participationId", + "value": "5521" + }, + { + "key": "resultId", + "value": "889" + }, + { + "key": "feedbacks", + "value": "[ 4 items ]" + }, + { + "key": "textBlocks", + "value": "[ 6 items ]" + } + ] + } + }, + { + "lane": 2, + "module": "text", + "label": "store feedback", + "caption": "Each comment is tied to the highlighted text block so it can be shown in place later.", + "file": "text/service/TextAssessmentService.java:84", + "method": "saveFeedback(textBlocks, feedbacks)", + "via": { + "kind": "call", + "label": "method call" + }, + "findingRank": null, + "payload": { + "type": "List", + "definedIn": "assessment/domain/Feedback.java", + "fields": [ + { + "key": "resultId", + "value": "889" + }, + { + "key": "feedbacks", + "value": "[ 4 items ]" + }, + { + "key": "linkedBlocks", + "value": "4" + }, + { + "key": "totalCredits", + "value": "7.5" + } + ] + } + }, + { + "lane": 3, + "module": "assessment", + "label": "finalise result", + "caption": "The result is scored, marked as rated, and locked against further edits.", + "file": "assessment/service/ResultService.java:301", + "method": "submitManualAssessment(resultId)", + "via": { + "kind": "call", + "label": "method call" + }, + "findingRank": null, + "payload": { + "type": "Result", + "definedIn": "assessment/domain/Result.java", + "fields": [ + { + "key": "id", + "value": "889" + }, + { + "key": "score", + "value": "75.0" + }, + { + "key": "rated", + "value": "true" + }, + { + "key": "assessor", + "value": "\"tutor17\"" + }, + { + "key": "completionDate", + "value": "\"2026-11-27T16:40:03Z\"" + } + ] + } + }, + { + "lane": 2, + "module": "athena", + "label": "share for learning", + "caption": "If the course allows it, the graded feedback is sent to Athena so it can suggest feedback for similar answers.", + "file": "athena/service/AthenaFeedbackSendingService.java:72", + "method": "sendFeedback(exercise, submission, feedbacks)", + "via": { + "kind": "call", + "label": "method call (async)" + }, + "findingRank": null, + "payload": { + "type": "AthenaFeedbackDTO", + "definedIn": "athena/dto/TextFeedbackDTO.java", + "fields": [ + { + "key": "exerciseId", + "value": "2210" + }, + { + "key": "submissionId", + "value": "5521" + }, + { + "key": "feedbacks", + "value": "[ 4 items ]" + }, + { + "key": "module", + "value": "\"module_text_cofee\"" + } + ] + } + }, + { + "lane": 1, + "module": "communication", + "label": "notify student", + "caption": "The student gets a notification that their answer was graded.", + "file": "communication/service/notifications/SingleUserNotificationService.java:140", + "method": "notifyUserAboutAssessedExerciseSubmission(exercise, user)", + "via": { + "kind": "call", + "label": "method call" + }, + "findingRank": null, + "payload": { + "type": "SingleUserNotification", + "definedIn": "communication/domain/notification/SingleUserNotification.java", + "fields": [ + { + "key": "recipient", + "value": "\"alice\"" + }, + { + "key": "title", + "value": "\"Exercise assessed\"" + }, + { + "key": "exerciseId", + "value": "2210" + }, + { + "key": "score", + "value": "75.0" + } + ] + } + }, + { + "lane": 0, + "module": "client", + "label": "see feedback", + "caption": "The student opens the notification and sees each comment next to the sentence it is about.", + "file": "webapp/app/text/overview/text-result.component.ts", + "method": "subscribe → onNotification(n)", + "via": { + "kind": "ws", + "label": "websocket" + }, + "findingRank": null, + "payload": { + "type": "UI state", + "definedIn": "Angular component", + "fields": [ + { + "key": "score", + "value": "\"75 %\"" + }, + { + "key": "inlineComments", + "value": "4" + } + ] + } + } + ] + } + ] +} diff --git a/web/src/App.tsx b/web/src/App.tsx index 3aa764fb..655c2fb2 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -4,6 +4,7 @@ import { Change } from "./routes/Change"; import { Decisions } from "./routes/Decisions"; import { FindingDetail } from "./routes/FindingDetail"; import { Findings } from "./routes/Findings"; +import { Journeys } from "./routes/Journeys"; import { Landing } from "./routes/Landing"; import { MapPage } from "./routes/MapPage"; import { NotFound } from "./routes/NotFound"; @@ -20,6 +21,7 @@ export function App() { } /> }> } /> + } /> } /> } /> } /> diff --git a/web/src/components/cx/closeup.tsx b/web/src/components/cx/closeup.tsx index fe85b554..95d7615c 100644 --- a/web/src/components/cx/closeup.tsx +++ b/web/src/components/cx/closeup.tsx @@ -163,7 +163,7 @@ export function Closeup({ repo, finding }: { repo: RepoBundle; finding: Finding const ly = (sy + ey) / 2 + (off ? ny * 1.8 : (dx / len) * 8) + 3; return ( - {`${at.get(e.src)!.label} uses ${at.get(e.dst)!.label}: ${e.count} ${e.count === 1 ? "link" : "links"}, ${e.against ? "against" : "with"} the grain`} + {`${at.get(e.src)!.label} uses ${at.get(e.dst)!.label}: ${e.count} ${e.count === 1 ? "link" : "links"}, ${e.against ? "backward" : "forward"}`}
  • - with the grain + forward link
  • - against the grain + backward link
  • {partners && (
  • diff --git a/web/src/components/cx/journeys.tsx b/web/src/components/cx/journeys.tsx new file mode 100644 index 00000000..ec07f89f --- /dev/null +++ b/web/src/components/cx/journeys.tsx @@ -0,0 +1,584 @@ +// The journey player: one user action drawn as a line across the layers of the codebase. A dip +// means the request goes down into core code, a rise means the result comes back up. Plain SVG +// and CSS; the only animation is a small packet travelling along the edge being played. +import { ChevronLeft, ChevronRight, Pause, Play } from "lucide-react"; +import { useCallback, useEffect, useMemo, useRef, useState } from "react"; +import { Link } from "react-router"; +import { findingPath } from "../../cx/address"; +import { TYPE } from "../../cx/meta"; +import type { RepoBundle } from "../../cx/types"; +import type { Journey, JourneyBundle, JourneyStop } from "../../data/journeys"; +import { FOCUS, cn } from "./cn"; +import { allFindings } from "./finding-fix"; + +const W = 1000; +const X0 = 190; +const X1 = 950; +const LANE_H = 72; + +/** How long the packet takes along one edge, and how long a stop stays open while playing. */ +const TRAVEL_MS = 1000; +const DWELL_MS = 1900; + +const VIA_TEXT: Record = { + call: "method call", + queue: "queue, handled later", + ws: "pushed to the browser", + find: "step that is a ranked finding", +}; + +function reducedMotion(): boolean { + return ( + typeof window !== "undefined" && + !!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches + ); +} + +/** "A student pushes code for a programming exercise" → "Student pushes code". */ +function shortName(name: string): string { + const s = name.replace(/^(An?|The) /, "").replace(/ for .*$/, ""); + return s.charAt(0).toUpperCase() + s.slice(1); +} + +type Pt = { x: number; y: number }; + +function edgePath(a: Pt, b: Pt): string { + const mx = (a.x + b.x) / 2; + return `M${a.x},${a.y} C${mx},${a.y} ${mx},${b.y} ${b.x},${b.y}`; +} + +function edgeKind(s: JourneyStop): "call" | "queue" | "ws" | "find" { + if (s.findingRank) return "find"; + return s.via?.kind ?? "call"; +} + +const EDGE_STYLE: Record = + { + call: { stroke: "var(--grain)", width: 2.5 }, + queue: { stroke: "var(--foreground)", dash: "7 5", width: 2.5 }, + ws: { stroke: "var(--grain)", dash: "2 5", width: 2.5, cap: "round" }, + // A finding step is drawn heavier; vermilion only when the finding is code against a decision. + find: { stroke: "var(--foreground)", width: 4 }, + against: { stroke: "var(--against)", width: 4 }, + }; + +// ---- the wave --------------------------------------------------------------------------- + +function Wave({ + lanes, + journey, + idx, + travelling, + onPick, + against = new Set(), + compact = false, +}: { + lanes: string[]; + journey: Journey; + idx: number; + /** The edge the packet is on, or null. */ + travelling: number | null; + onPick?: (i: number) => void; + /** Ranks of findings that are code against a decision. */ + against?: Set; + compact?: boolean; +}) { + const stops = journey.stops; + const n = stops.length; + // The still preview packs the lanes closer so the drawing stays short on the report page. + const laneH = compact ? 50 : LANE_H; + const laneY = (i: number) => (compact ? 54 : 46) + i * laneH; + const pts = stops.map((s, i) => ({ + x: X0 + (i * (X1 - X0)) / Math.max(1, n - 1), + y: laneY(s.lane), + })); + const H = laneY(lanes.length - 1) + (compact ? 46 : 54); + const pathRefs = useRef<(SVGPathElement | null)[]>([]); + const packet = useRef(null); + + // Moves the packet along the edge being played. + useEffect(() => { + const g = packet.current; + if (!g) return; + if (travelling === null || reducedMotion()) { + g.style.opacity = "0"; + return; + } + const path = pathRefs.current[travelling]; + if (!path) return; + const len = path.getTotalLength(); + const start = performance.now(); + let raf = 0; + g.style.opacity = "1"; + const step = (now: number) => { + const k = Math.min(1, (now - start) / TRAVEL_MS); + const e = k < 0.5 ? 2 * k * k : 1 - Math.pow(-2 * k + 2, 2) / 2; + const p = path.getPointAtLength(len * e); + g.setAttribute("transform", `translate(${p.x},${p.y})`); + if (k < 1) raf = requestAnimationFrame(step); + else g.style.opacity = "0"; + }; + raf = requestAnimationFrame(step); + return () => cancelAnimationFrame(raf); + }, [travelling]); + + const label = travelling !== null ? (stops[travelling + 1]?.payload.type ?? "") : ""; + + return ( + + {lanes.map((l, i) => ( + + {i % 2 === 0 && ( + + )} + + + {l} + + + ))} + {pts.slice(1).map((b, i) => { + const next = stops[i + 1]; + const kind = next.findingRank && against.has(next.findingRank) ? "against" : edgeKind(next); + const st = EDGE_STYLE[kind]; + const future = i >= idx && travelling !== i; + return ( + { + pathRefs.current[i] = el; + }} + d={edgePath(pts[i], b)} + fill="none" + stroke={st.stroke} + strokeWidth={st.width} + strokeDasharray={st.dash} + strokeLinecap={st.cap} + className="transition-opacity duration-300" + opacity={future ? 0.2 : 1} + /> + ); + })} + {stops.map((s, i) => { + const p = pts[i]; + const up = i % 2 === 0; + const on = i === idx && travelling === null; + const future = i > idx; + const flag = !!s.findingRank; + const flagColor = + s.findingRank && against.has(s.findingRank) ? "var(--against)" : "var(--foreground)"; + return ( + onPick(i) : undefined} + onKeyDown={ + onPick + ? (e) => { + if (e.key === "Enter" || e.key === " ") { + e.preventDefault(); + onPick(i); + } + } + : undefined + } + className={cn("group outline-none", onPick && "cursor-pointer")} + opacity={future ? 0.45 : 1} + > + + + + {s.module} + + + {s.label} + + + ); + })} + + + + {label} + + + + + ); +} + +function Legend() { + return ( +
      + {Object.entries(VIA_TEXT).map(([k, text]) => { + const st = EDGE_STYLE[k]; + return ( +
    • + + + + {text} +
    • + ); + })} +
    + ); +} + +// ---- the stop detail -------------------------------------------------------------------- + +function Payload({ stop, prev }: { stop: JourneyStop; prev: JourneyStop | null }) { + const before = new Set((prev?.payload.fields ?? []).map((f) => f.key)); + return ( +
    +
    + {stop.payload.type} + + {stop.payload.definedIn} + +
    +
    +        {"{"}
    +        {stop.payload.fields.map((f) => {
    +          const added = prev !== null && !before.has(f.key);
    +          return (
    +            
    +              {"  "}
    +              {f.key}
    +              : 
    +              {f.value}
    +            
    +          );
    +        })}
    +        {"}"}
    +      
    +

    + {prev ? "Highlighted fields are new at this stop. " : ""}Values are an example request. +

    +
    + ); +} + +function StopDetail({ + repo, + lanes, + journey, + idx, +}: { + repo: RepoBundle; + lanes: string[]; + journey: Journey; + idx: number; +}) { + const s = journey.stops[idx]; + const prev = idx > 0 ? journey.stops[idx - 1] : null; + const finding = s.findingRank + ? allFindings(repo).find((f) => f.rank === s.findingRank) + : undefined; + return ( +
    +
    +

    + Stop {idx + 1} of {journey.stops.length} + / + {lanes[s.lane]} +

    +

    {s.caption}

    +
    + {s.file} + + {s.method} + +
    +

    + {s.via ? ( + <> + Arrived by {s.via.label} + {prev && ( + <> + {" "} + from {prev.module} + + )} + + ) : ( + "Start of the journey" + )} +

    + {finding && ( + + #{finding.rank} + + {finding.title} + + Open the finding, its graph and its code + + + + )} +
    +
    + +
    +
    + ); +} + +// ---- the player ------------------------------------------------------------------------- + +const ctlBase = + "inline-flex h-8 min-w-8 items-center justify-center gap-1.5 rounded-md border px-2.5 font-mono text-xs transition-colors disabled:opacity-40"; +const ctl = cn(ctlBase, "bg-card hover:bg-muted", FOCUS); +const ctlPrimary = cn( + ctlBase, + "border-foreground bg-foreground px-3 text-background hover:bg-foreground/85", + FOCUS, +); + +export function JourneyPlayer({ + repo, + bundle, + start, +}: { + repo: RepoBundle; + bundle: JourneyBundle; + /** The journey id and 0-based stop to open first, from the address. */ + start?: { journey: string | null; stop: number }; +}) { + const startJ = Math.max( + 0, + bundle.journeys.findIndex((j) => j.id === start?.journey), + ); + const [jIdx, setJIdx] = useState(startJ); + const [idx, setIdx] = useState(() => + Math.max(0, Math.min(bundle.journeys[startJ].stops.length - 1, start?.stop ?? 0)), + ); + const [playing, setPlaying] = useState(false); + const [travelling, setTravelling] = useState(null); + const journey = bundle.journeys[jIdx]; + const last = journey.stops.length - 1; + + const stop = useCallback(() => { + setPlaying(false); + setTravelling(null); + }, []); + const go = useCallback( + (i: number) => { + stop(); + setIdx(Math.max(0, Math.min(last, i))); + }, + [last, stop], + ); + + // While playing: travel one edge, open the stop it reaches, stay there a moment, repeat. + useEffect(() => { + if (!playing) return; + if (travelling === null) { + if (idx >= last) { + setPlaying(false); + return; + } + const t = window.setTimeout(() => setTravelling(idx), DWELL_MS); + return () => window.clearTimeout(t); + } + const t = window.setTimeout( + () => { + setTravelling(null); + setIdx(travelling + 1); + }, + reducedMotion() ? 0 : TRAVEL_MS, + ); + return () => window.clearTimeout(t); + }, [playing, travelling, idx, last]); + + const togglePlay = () => { + if (playing) return stop(); + const from = idx >= last ? 0 : idx; + setIdx(from); + setPlaying(true); + setTravelling(from); + }; + + const onKey = (e: React.KeyboardEvent) => { + if ((e.target as HTMLElement).tagName === "BUTTON" && e.key === " ") return; + if (e.key === "ArrowRight") go(idx + 1); + else if (e.key === "ArrowLeft") go(idx - 1); + }; + + const modules = useMemo(() => new Set(journey.stops.map((s) => s.module)).size, [journey]); + const findingSteps = journey.stops.filter((s) => + allFindings(repo).some((f) => f.rank === s.findingRank), + ).length; + const against = useMemo( + () => + new Set( + allFindings(repo) + .filter((f) => TYPE[f.type].group === "Decision exception") + .map((f) => f.rank), + ), + [repo], + ); + + return ( +
    +
    +
    + {bundle.journeys.map((j, i) => ( + + ))} +
    +
    + + + +
    +
    +
    +

    {journey.name}

    +

    + {journey.stops.length} stops through {modules} modules + {findingSteps > 0 && + `, ${findingSteps} ${findingSteps === 1 ? "step is a ranked finding" : "steps are ranked findings"}`} + . +

    +
    +
    + +
    +
    + +
    + +
    + ); +} + +/** A still drawing of one journey for the report page. */ +export function JourneyPreview({ bundle, journey }: { bundle: JourneyBundle; journey: Journey }) { + return ( + + ); +} diff --git a/web/src/components/cx/map-controls.tsx b/web/src/components/cx/map-controls.tsx index f006d717..474be24b 100644 --- a/web/src/components/cx/map-controls.tsx +++ b/web/src/components/cx/map-controls.tsx @@ -8,7 +8,7 @@ import type { Finding, RepoBundle, Yardstick } from "../../cx/types"; import { FOCUS, cn } from "./cn"; export const GRID_ORDER_NOTE = - "The grid keeps one module order for every view, so its cells below the diagonal can differ from the stored totals above it, which use each date's own order."; + "Every view keeps the same module order so squares line up between dates. The totals above use each date's own order, so they can differ slightly from the squares."; export function viewLabel(repo: RepoBundle, view: MapView): string { if (view === "before") return `Before · ${repo.beforeDate.slice(0, 7)}`; @@ -126,7 +126,7 @@ export function GridNumbers({ return (
    -
    loops in this simulation
    +
    module loops in this simulation
    {fmt(s.loopsBefore)} → {fmt(s.loopsAfter)}
    @@ -140,7 +140,7 @@ export function GridNumbers({ return (
    -
    loops, simulation's count
    +
    module loops, before and after the fixes
    {fmt(b.loopsBefore)} → {fmt(b.loopsAfter)}
    @@ -163,7 +163,7 @@ export function GridNumbers({ > {share !== null && (
    -
    against grain
    +
    backward links
    {pct(share)} {!small && links !== null && ( @@ -174,7 +174,7 @@ export function GridNumbers({ )} {pairs !== null && (
    -
    two-way pairs
    +
    two-way dependencies
    {fmt(pairs)}
    )} @@ -203,10 +203,10 @@ export function MapLegend({ )} >
  • - with the grain + forward link
  • - against the grain + backward link
  • diff --git a/web/src/components/cx/matrix.tsx b/web/src/components/cx/matrix.tsx index c747874f..57effd3c 100644 --- a/web/src/components/cx/matrix.tsx +++ b/web/src/components/cx/matrix.tsx @@ -89,7 +89,7 @@ export function cellName( const v = values[i]![j]!; const head = `${src.path}${only(src)} uses ${dst.path}${only(dst)}`; const body = - v === 0 ? `${head}, no links` : `${head} ${times(v)}, ${i > j ? "against" : "with"} the grain`; + v === 0 ? `${head}, no links` : `${head} ${times(v)}, ${i > j ? "backward" : "forward"}`; return change ? `${body}; ${fmt(change.before)} to ${fmt(change.after)} links ${changeSource}`.trim() : body; @@ -327,7 +327,7 @@ export function Matrix({
    {" · "} j ? "text-accent" : "text-primary"}> - {i > j ? "against the grain" : "with the grain"} + {i > j ? "backward link" : "forward link"} )} @@ -870,7 +870,7 @@ function Tip({ {v > 0 && ( j ? "text-accent" : "text-primary"}> {" · "} - {i > j ? "against the grain" : "with the grain"} + {i > j ? "backward link" : "forward link"} )} diff --git a/web/src/cx/address.ts b/web/src/cx/address.ts index 875c740a..abb0510a 100644 --- a/web/src/cx/address.ts +++ b/web/src/cx/address.ts @@ -1,7 +1,7 @@ // Every view has an address (spec.md §10.3). These build the paths after the "#" and read // and write the Map's search parameters, so reloading or sharing a link restores the view. -export type RepoTab = "decisions" | "findings" | "map" | "change" | "trust" | "size"; +export type RepoTab = "journeys" | "decisions" | "findings" | "map" | "change" | "trust" | "size"; const seg = (s: string) => encodeURIComponent(s); diff --git a/web/src/cx/meta.ts b/web/src/cx/meta.ts index 60e22225..bbe4c3a4 100644 --- a/web/src/cx/meta.ts +++ b/web/src/cx/meta.ts @@ -12,26 +12,36 @@ import type { // Okabe-Ito categorical palette (colour-blind safe), spec §10.5 export const STATUS: Record = { - broken: { label: "Broken", color: "#D55E00", order: 0, hint: "Conformance below 90%" }, + broken: { + label: "Broken", + color: "#D55E00", + order: 0, + hint: "Kept in less than 90% of the code it covers", + }, slipping: { - label: "Slipping", + label: "Getting worse", color: "#E69F00", order: 1, - hint: "Fell by more than 1 point over the last two snapshots", + hint: "Kept less often than before: down more than 1 point over the last two snapshots", }, spreading: { - label: "Spreading", + label: "Reaching more modules", color: "#CC79A7", order: 2, - hint: "The number of modules the rule covers is growing", + hint: "The rule now covers more modules than before, so there is more code that has to keep it", }, mostly_holding: { label: "Mostly holding", color: "#56B4E9", order: 3, - hint: "90% to 98%, stable", + hint: "Kept in 90% to 98% of the code it covers, and stable", + }, + holding: { + label: "Holding", + color: "#009E73", + order: 4, + hint: "Kept in at least 98% of the code it covers", }, - holding: { label: "Holding", color: "#009E73", order: 4, hint: "Conformance at least 98%" }, }; export const STATUS_ORDER: Status[] = [ @@ -143,7 +153,7 @@ export const NO_FIX_TEXT = "No improvement proposed."; /** Said next to the simulated batch's loop counts, which are not the yardstick's pairs. */ export const BATCH_LOOPS_NOTE = - "Loop counts here are the simulation's own, on its set of module links, so they differ from the two-way pairs yardstick."; + "Loop counts here are the simulation's own, on its set of module links, so they differ from the two-way dependencies count."; /** * A readable label for each stored fact key. The value is shown after it with the fact's diff --git a/web/src/data/journeys.ts b/web/src/data/journeys.ts new file mode 100644 index 00000000..9ed80a78 --- /dev/null +++ b/web/src/data/journeys.ts @@ -0,0 +1,62 @@ +// Journeys: one user action traced through the main modules, step by step. They sit next to a +// repository's bundle as `journeys.json`; a repository without that file has no journeys and +// the screens leave the Journeys tab out. +import { bundlesRoot } from "./bundle"; +import { loadRepoList } from "./repo"; + +export type JourneyVia = { kind: "call" | "queue" | "ws" | "find"; label: string } | null; + +export interface JourneyStop { + /** Index into the bundle's lanes. */ + lane: number; + module: string; + /** A short verb phrase shown on the node. */ + label: string; + /** One sentence for a newcomer. */ + caption: string; + /** "path:line" of the code that runs at this stop. */ + file: string; + method: string; + /** How the request reached this stop; null on the first stop. */ + via: JourneyVia; + /** Set when this step is a ranked finding. */ + findingRank: number | null; + payload: { type: string; definedIn: string; fields: { key: string; value: string }[] }; +} + +export interface Journey { + id: string; + name: string; + summary: string; + stops: JourneyStop[]; +} + +export interface JourneyBundle { + lanes: string[]; + journeys: Journey[]; +} + +const loaded = new Map>(); + +/** The repository's journeys, or null when its bundle folder holds none. */ +export function loadJourneys(repoId: string): Promise { + const hit = loaded.get(repoId); + if (hit) return hit; + const loading = (async () => { + const entry = (await loadRepoList()).find((b) => b.repo_id === repoId); + if (!entry) return null; + const folder = entry.path.includes("/") + ? entry.path.slice(0, entry.path.lastIndexOf("/") + 1) + : ""; + try { + const res = await fetch(`${bundlesRoot()}${folder}journeys.json`); + if (!res.ok) return null; + const data = (await res.json()) as JourneyBundle; + return Array.isArray(data.journeys) && data.journeys.length > 0 ? data : null; + } catch { + return null; + } + })(); + loaded.set(repoId, loading); + return loading; +} diff --git a/web/src/routes/Change.tsx b/web/src/routes/Change.tsx index 232283f5..09a19b7e 100644 --- a/web/src/routes/Change.tsx +++ b/web/src/routes/Change.tsx @@ -9,12 +9,13 @@ import { findingPath } from "../cx/address"; import { fmt, hostLink, pct } from "../cx/meta"; import type { RepoBundle, StructuralEvent } from "../cx/types"; import { Drift } from "./change/drift"; +import { Impact } from "./change/impact"; import { LabelChip, StructuralEvents, labelCounts } from "./change/events"; import { ShowMoreButton, useShowMore } from "./decisions/show-more"; import { useRepo } from "./RepoLayout"; /** Hotspots and new links shown before "Show all". */ -const FIRST = 8; +const FIRST = 5; const pathLinkCls = cn("rounded-sm hover:underline decoration-border underline-offset-2", FOCUS); @@ -34,6 +35,10 @@ export function Change() { return (
    +
    + + +
    @@ -59,10 +64,13 @@ function Header({ repo }: { repo: RepoBundle }) {

    Before and after {monthYear(compared)}

    +

    + Did the structure get better or worse once the team started using AI coding tools? +

    - This page describes what changed between the dates and attributes no change to AI tools: - changes with an explicit AI marker are a lower bound, and code without one is counted as - no AI signal. + This page shows what changed between the two dates. It does not blame any change on AI: + only commits with an explicit AI marker are counted as AI, so that share is a lower bound, + and everything else is no AI signal.

    @@ -121,22 +129,11 @@ function Hotspots({ repo }: { repo: RepoBundle }) { const maxZ = Math.max(...repo.hotspots.map((h) => h.z), 1); return (
    - -
    -

    - Rule: z = (recent − prior) ÷ √(prior + 1) of at least 3, with at least 2 changes per month - recently; new files and restructuring commits are left out. -

    -

    - recent: changes in the last 3 months.{" "} - prior: expected changes in 3 months, - from the months before. The bar is z. -

    -
    + +

    + Files that changed far more often in the last 3 months than their own history predicts. New + files and restructuring commits are left out. +

    {repo.hotspots.length === 0 ? (

    No file met the rule in this run.

    ) : ( @@ -160,10 +157,10 @@ function Hotspots({ repo }: { repo: RepoBundle }) { )} - prior {h.prior.toFixed(2)}{" "} - {" "} - recent{" "} - {fmt(h.recent)} + {fmt(h.recent)}{" "} + + changes, {h.prior.toFixed(1)} expected +
    {dir && ( @@ -178,15 +175,16 @@ function Hotspots({ repo }: { repo: RepoBundle }) { {h.moduleName ?? "no module"} - + - - z {h.z.toFixed(1)} -
  • ); @@ -226,16 +224,12 @@ function NewLinks({ repo }: { repo: RepoBundle }) { }; return (
    - +

    {fmt(added.length)} new {added.length === 1 ? "link" : "links"} between modules:{" "} - {fmt(c.planned)} planned, {fmt(c.none)} with no stated intent. Each one's evidence is - listed under structural events. + {fmt(c.planned)} planned, {fmt(c.none)} unexplained. Each one's evidence is listed under + "Show every change" above.

    {plan && (

    @@ -301,8 +295,7 @@ function AiRisk({ repo }: { repo: RepoBundle }) { {repo.aiRisk && (

    @@ -336,16 +329,12 @@ function AiRisk({ repo }: { repo: RepoBundle }) { )}
    - } - /> + } />

    - Each evidence line is credited to the last change that touched it, which is not always the - change that first wrote it. The marked share counts explicit AI markers only, so it is a - lower bound.{missing && ` ${missing}`} + For each top finding: how much of the code behind it changed after {sponsor}, and how much + of that carries an explicit AI marker. Each line counts toward the last change that + touched it. Only explicit markers count as AI, so the AI share is a lower bound. + {missing && ` ${missing}`}

    {repo.findings.length === 0 ? (

    No finding was ranked in this run.

    diff --git a/web/src/routes/FindingDetail.tsx b/web/src/routes/FindingDetail.tsx index af08b1e6..a04830b4 100644 --- a/web/src/routes/FindingDetail.tsx +++ b/web/src/routes/FindingDetail.tsx @@ -4,7 +4,7 @@ import { EvidencePane } from "../components/cx/code-block"; import { allFindings } from "../components/cx/finding-fix"; import { ComputedMark } from "../components/cx/badges"; import { FOCUS, cn } from "../components/cx/cn"; -import { Chip, Eyebrow, Prose } from "../components/cx/primitives"; +import { Chip, Prose } from "../components/cx/primitives"; import { useTitle } from "../components/cx/use-page"; import { findingPath, repoPath } from "../cx/address"; import { TYPE, fmt } from "../cx/meta"; @@ -13,7 +13,7 @@ import { ShowMoreButton, useShowMore } from "./decisions/show-more"; import { Reading } from "./finding/Reading"; import { CloseupPanel, DecisionCard, FactsPanel, PriorityPanel, TrendPanel } from "./finding/Rail"; import { NotFound } from "./NotFound"; -import { useRepo } from "./RepoLayout"; +import { useJourneys, useRepo } from "./RepoLayout"; /** One finding of one repository, found by its slug among the top 10 and the rest. */ export function FindingDetail() { @@ -37,6 +37,11 @@ function FindingPage({ repo, f }: { repo: RepoBundle; f: Finding }) { const byId = new Map(all.map((x) => [x.id, x])); const related = f.related.map((id) => byId.get(id)).filter((x): x is Finding => Boolean(x)); const inTop = repo.findings.includes(f); + const journeys = useJourneys(); + const seenIn = (journeys?.journeys ?? []).flatMap((journey) => { + const stop = journey.stops.findIndex((s) => s.findingRank === f.rank); + return stop >= 0 ? [{ journey, stop }] : []; + }); return (
    @@ -75,35 +80,39 @@ function FindingPage({ repo, f }: { repo: RepoBundle; f: Finding }) {
    -
    -
    - {String(f.rank).padStart(2, "0")} -
    -
    -
    - {TYPE[f.type].label} - - · - - {TYPE[f.type].group} - - rank {f.rank} of {all.length} - - {!inTop && below the top {repo.findings.length}} +
    +

    + #{f.rank} + of {fmt(all.length)} + / + {TYPE[f.type].label} + {!inTop && below the top {repo.findings.length}} +

    +

    + {f.title} +

    + {f.judgement && ( +
    + +
    -

    - {f.title} -

    - {f.judgement && ( -
    - - -
    - )} -
    + )} + {seenIn.length > 0 && ( +

    + Seen in{" "} + {seenIn.map((x, i) => ( + + {i > 0 && ", "} + + the journey "{x.journey.name}", stop {x.stop + 1} + + + ))} +

    + )}
    @@ -175,10 +184,7 @@ function Related({ repo, related }: { repo: RepoBundle; related: Finding[] }) { > #{r.rank} - - {TYPE[r.type].label} - {" "} - {r.title} + {TYPE[r.type].label}. {r.title}
  • diff --git a/web/src/routes/Journeys.tsx b/web/src/routes/Journeys.tsx new file mode 100644 index 00000000..a222a67a --- /dev/null +++ b/web/src/routes/Journeys.tsx @@ -0,0 +1,37 @@ +import { useSearchParams } from "react-router"; +import { JourneyPlayer } from "../components/cx/journeys"; +import { useTitle } from "../components/cx/use-page"; +import { NotFound } from "./NotFound"; +import { useJourneys, useRepo } from "./RepoLayout"; + +/** Journeys: follow one user action through the code, the quickest way into a new codebase. */ +export function Journeys() { + const repo = useRepo(); + const journeys = useJourneys(); + const [params] = useSearchParams(); + const start = { + journey: params.get("j"), + stop: Math.max(0, Number(params.get("s") ?? 1) - 1 || 0), + }; + useTitle(`Journeys · ${repo.name}`); + if (!journeys) return ; + return ( +
    +
    +

    + Follow one request through the code +

    +

    + Each journey starts with something a person does in the browser and follows it through the + modules that handle it. The height of the line is the layer: a dip goes down into core + code, a rise brings the result back up. Press Play or pick any stop. +

    +
    + +

    + These journeys are a hand-traced sample for {repo.name}, not yet produced by the pipeline. + File paths are shortened to the module folder. +

    +
    + ); +} diff --git a/web/src/routes/MapPage.tsx b/web/src/routes/MapPage.tsx index b369367b..62646cf7 100644 --- a/web/src/routes/MapPage.tsx +++ b/web/src/routes/MapPage.tsx @@ -18,15 +18,8 @@ import { topFindingCells, } from "../components/cx/map-model"; import { type Cell, Matrix } from "../components/cx/matrix"; -import { Eyebrow } from "../components/cx/primitives"; import { useTitle } from "../components/cx/use-page"; -import { - type MapState, - type MapView, - readMapState, - repoPath, - withMapState, -} from "../cx/address"; +import { type MapState, type MapView, readMapState, repoPath, withMapState } from "../cx/address"; import { fmt } from "../cx/meta"; import { useRepo } from "./RepoLayout"; import { CellPanel } from "./map/CellPanel"; @@ -112,19 +105,16 @@ export function MapPage() { return (
    - - Map · {fmt(present)} {present === 1 ? "module" : "modules"} - {listsBeforeOnly && - beforeOnly > 0 && - ` · ${fmt(beforeOnly)} more only at the before date`} -

    Which module uses which

    - Each row uses the columns it has links into, and cells below the diagonal point against - the main direction of dependencies (against the grain). Click a cell to list the code - links behind it. + Every square is one of the {fmt(present)} modules using another. Above the diagonal, blue + squares point the normal way, from features down to the shared code they build on. Below + it, orange squares point backwards. Click a square to see the code behind it. + {listsBeforeOnly && + beforeOnly > 0 && + ` ${fmt(beforeOnly)} more ${beforeOnly === 1 ? "module" : "modules"} existed only at the before date.`}

    } /> -

    {GRID_ORDER_NOTE}

    +

    + {GRID_ORDER_NOTE} +

    {picture.changes.length > 0 && ( - + - +
    ); @@ -132,18 +129,10 @@ function StatusBar({ counts, total }: { counts: Record; total: n ); } -/** The verdict, the decisions furthest from holding, then what holds. */ -function DecisionList({ repo, compareDate }: { repo: RepoBundle; compareDate: string }) { +/** The verdict and the status bar; the decisions themselves are one click away. */ +function DecisionList({ repo }: { repo: RepoBundle }) { const counts = statusCounts(repo.decisions); const total = repo.decisions.length; - const shown = [...repo.decisions] - .sort( - (a, b) => - STATUS[a.status].order - STATUS[b.status].order || - a.conformance - b.conformance || - (a.id < b.id ? -1 : a.id > b.id ? 1 : 0), - ) - .slice(0, DECISIONS_SHOWN); return (

    {total > 0 && } - {shown.length > 0 && ( -
      - {shown.map((d) => { - const values = d.series.map((s) => s.conformance); - const lo = Math.min(0.75, ...values); - return ( -
    • - - - -

      - {d.statement} -

      - - s.date), - compareDate, - )} - width={72} - height={20} - color={STATUS[d.status].color} - domain={[lo, 1]} - label={`Conformance at each snapshot for ${d.id}`} - /> - - - {pct(d.conformance)} - -
    • - ); - })} -
    - )} -
    ); } -function Healthy({ repo }: { repo: RepoBundle }) { - if (repo.healthy.length === 0) return null; - const shown = repo.healthy.slice(0, HEALTHY_SHOWN); +/** Understandability: the main modules, then one request followed through them. */ +function HowItFits({ repo, journeys }: { repo: RepoBundle; journeys: JourneyBundle | null }) { + const first = journeys?.journeys[0]; return ( -
    -
    -

    What holds

    - {repo.healthy.length > shown.length && ( - - All {repo.healthy.length} holding decisions +
    + + Open the full map - )} -
    -
      - {shown.map((h) => { - const d = repo.decisions.find((x) => x.id === h.decisionId); - return ( -
    • -
      - {d && } - {d && ( - - {pct(d.conformance)} - - )} -
      -

      {d?.statement ?? h.decisionId}

      -

      - {h.evidence} -

      -
    • - ); - })} -
    -
    + } + /> + + {journeys && first && ( +
    +
    +

    How they work together: {first.name.toLowerCase()}

    + + Play the {journeys.journeys.length} journeys{" "} + + +
    + + + +
    + )} + ); } diff --git a/web/src/routes/RepoLayout.tsx b/web/src/routes/RepoLayout.tsx index 101b2e23..5aa4bf22 100644 --- a/web/src/routes/RepoLayout.tsx +++ b/web/src/routes/RepoLayout.tsx @@ -6,11 +6,13 @@ import { FOCUS, cn } from "../components/cx/cn"; import { allFindings } from "../components/cx/finding-fix"; import { SiteFooter, SiteHeader } from "../components/cx/site-header"; import { useLoaded, useTitle } from "../components/cx/use-page"; +import { type JourneyBundle, loadJourneys } from "../data/journeys"; import { loadRepo, loadRepoList } from "../data/repo"; import { NotFound } from "./NotFound"; interface RepoContext { repo: RepoBundle; + journeys: JourneyBundle | null; } /** @@ -21,30 +23,38 @@ export function useRepo(): RepoBundle { return useOutletContext().repo; } +/** The repository's journeys, or null when its bundle folder holds none. */ +export function useJourneys(): JourneyBundle | null { + return useOutletContext().journeys; +} + /** * The tab row. `also` lists the screens that are reached from a tab's page rather than from * the row; while one of them is open, that tab is marked as current. */ const TABS: { tab?: RepoTab; label: string; also?: RepoTab[] }[] = [ { label: "Report", also: ["decisions"] }, + { tab: "journeys", label: "Journeys" }, { tab: "findings", label: "Findings" }, { tab: "map", label: "Map", also: ["size"] }, { tab: "change", label: "Before and after" }, { tab: "trust", label: "Approach" }, ]; -type Load = { state: "missing" } | { state: "found"; repo: RepoBundle }; +type Load = + { state: "missing" } | { state: "found"; repo: RepoBundle; journeys: JourneyBundle | null }; export function RepoLayout() { const id = useParams().repo ?? ""; const loaded = useLoaded(async () => { const list = await loadRepoList(); if (!list.some((b) => b.repo_id === id)) return { state: "missing" }; - return { state: "found", repo: await loadRepo(id) }; + const [repo, journeys] = await Promise.all([loadRepo(id), loadJourneys(id)]); + return { state: "found", repo, journeys }; }, id); - const repo = - loaded.state === "ready" && loaded.value.state === "found" ? loaded.value.repo : null; + const found = loaded.state === "ready" && loaded.value.state === "found" ? loaded.value : null; + const repo = found ? found.repo : null; // Once the repository is loaded, each screen sets its own title. useTitle( loaded.state === "ready" && loaded.value.state === "missing" @@ -87,12 +97,12 @@ export function RepoLayout() {
    )} - {repo && } + {found && } ); } -function RepoBody({ repo }: { repo: RepoBundle }) { +function RepoBody({ repo, journeys }: { repo: RepoBundle; journeys: JourneyBundle | null }) { const modules = repo.modules.filter((m) => m.presentAtEnd).length; // Two names and a count keep the line short; the full list is the line's tooltip. const langs = @@ -105,7 +115,7 @@ function RepoBody({ repo }: { repo: RepoBundle }) { `${fmt(repo.prodLoc)} production lines`, `${fmt(modules)} ${modules === 1 ? "module" : "modules"}`, ].filter(Boolean); - const context: RepoContext = { repo }; + const context: RepoContext = { repo, journeys }; return ( <>
    @@ -152,7 +162,11 @@ function RepoBody({ repo }: { repo: RepoBundle }) {

    )} - +
    @@ -167,7 +181,15 @@ function RepoBody({ repo }: { repo: RepoBundle }) { ); } -function RepoNav({ repoId, counts }: { repoId: string; counts: Partial> }) { +function RepoNav({ + repoId, + counts, + hide, +}: { + repoId: string; + counts: Partial>; + hide: RepoTab[]; +}) { const path = useLocation().pathname; const base = repoPath(repoId); const under = (tab: RepoTab) => { @@ -176,7 +198,7 @@ function RepoNav({ repoId, counts }: { repoId: string; counts: Partial - {TABS.map((t) => { + {TABS.filter((t) => !t.tab || !hide.includes(t.tab)).map((t) => { const href = repoPath(repoId, t.tab); const active = (t.tab ? under(t.tab) : path === base || path === `${base}/`) || diff --git a/web/src/routes/change/drift.tsx b/web/src/routes/change/drift.tsx index df91bcba..2d06eb1f 100644 --- a/web/src/routes/change/drift.tsx +++ b/web/src/routes/change/drift.tsx @@ -16,28 +16,18 @@ const YARDSTICKS: { }[] = [ { key: "againstGrainShare", - label: "Against-the-grain share", - hint: "Share of cross-module links that point against the main direction of dependencies.", - }, - { - key: "againstGrain", - label: "Against-the-grain links", - hint: "Cross-module links that point against the main direction.", + label: "Backward links", + hint: "Share of links between modules that point backwards, from shared code up to the features that use it.", }, { key: "twoWayPairs", - label: "Two-way module pairs", - hint: "Pairs of modules that use each other.", + label: "Two-way dependencies", + hint: "Pairs of modules that use each other, so neither can be changed or tested alone.", }, { key: "perKloc", - label: "Exceptions per 1,000 lines", - hint: "Decision exceptions per 1,000 lines of production code, for the decisions that apply.", - }, - { - key: "crossModule", - label: "Cross-module links", - hint: "File-to-file links that cross a module boundary.", + label: "Rule breaks per 1,000 lines", + hint: "Code that goes against a recorded decision, per 1,000 lines of production code.", }, ]; @@ -111,7 +101,7 @@ function YardstickCard({ } /** Decisions shown before "Show all". */ -const RULES_SHOWN = 8; +const RULES_SHOWN = 5; /** The stored check at the before date, or null when the rule was not checked then. */ const beforePoint = (repo: RepoBundle, d: Decision) => @@ -143,7 +133,7 @@ function DecisionDrift({ repo }: { repo: RepoBundle }) { return (
    - +
    - @@ -179,7 +164,6 @@ function DecisionDrift({ repo }: { repo: RepoBundle }) { - +
    Each decision's conformance and exceptions per 1,000 lines at {repo.beforeDate} and at the end snapshot @@ -157,17 +147,12 @@ function DecisionDrift({ repo }: { repo: RepoBundle }) { status now
    - conformance -
    - {repo.beforeDate} → now -
    - per 1,000 lines + code that keeps it
    {repo.beforeDate} → now
    - conformance at each snapshot + over time
    {d.statement} - {d.id} @@ -192,14 +176,7 @@ function DecisionDrift({ repo }: { repo: RepoBundle }) { )}{" "} → {pct(d.conformance)} - {before ? ( - before.perKloc.toFixed(3) - ) : ( - no check - )}{" "} - → {d.perKloc.toFixed(3)} - } /> @@ -254,7 +230,7 @@ export function Drift({ repo }: { repo: RepoBundle }) { /> ))} -

    Per decision

    +

    Each decision, then and now

    ); diff --git a/web/src/routes/change/events.tsx b/web/src/routes/change/events.tsx index 12c6fc46..9f8a76b3 100644 --- a/web/src/routes/change/events.tsx +++ b/web/src/routes/change/events.tsx @@ -10,7 +10,7 @@ import { EvidenceList } from "./evidence"; export const LABEL: Record = { planned: "planned", - no_stated_intent: "no stated intent", + no_stated_intent: "unexplained", }; export const BASIS: Record, string> = { @@ -102,7 +102,7 @@ function Group({

    {title} - {fmt(events.length)} · {fmt(c.planned)} planned · {fmt(c.none)} no stated intent + {fmt(events.length)} · {fmt(c.planned)} planned · {fmt(c.none)} unexplained

      @@ -132,45 +132,107 @@ export function StructuralEvents({ repo }: { repo: RepoBundle }) { ? [...list].sort((a, b) => byText(a.fromDate ?? "", b.fromDate ?? "") || byText(a.id, b.id)) : list; }; + const rows = GROUPS.map((g) => ({ ...g, events: byKind(g.kind) })).filter( + (g) => g.events.length > 0, + ); + const th = "px-4 py-2.5 text-right font-normal whitespace-nowrap"; return ( -
      +
      - {fmt(repo.events.length)} {repo.events.length === 1 ? "event" : "events"} ·{" "} - {fmt(c.planned)} planned · {fmt(c.none)} no stated intent + + {fmt(repo.events.length)} {repo.events.length === 1 ? "change" : "changes"} } /> -
        -
      • - planned: a basis was found -
      • -
      • - no stated intent: no basis was found, which does not make - it unintended -
      • -
      • - built from stored facts -
      • -
      • - written by an AI model, citations checked -
      • -
      +

      + Drift is not automatically bad. A change counts as planned when a restructuring commit, a + decision document or a pull request explains it. A change without one is not called a + mistake, only unexplained. +

      {repo.events.length === 0 ? (

      - No structural event was found between the two dates in this run. + No structural change was found between the two dates in this run.

      ) : ( - GROUPS.map((g) => { - const events = byKind(g.kind); - return events.length === 0 ? null : ( - - ); - }) + <> +
      + + + + + + + + + + + + {rows.map((g) => { + const k = labelCounts(g.events); + return ( + + + + + + + ); + })} + + + + + + + + + +
      Structural changes by kind and by stated intent
      + Kind of change + + Total + + + Planned + + + + Unexplained + +
      + {g.title} + + {fmt(g.events.length)} + {fmt(k.planned)} + {fmt(k.none)} +
      + All changes + + {fmt(repo.events.length)} + {fmt(c.planned)}{fmt(c.none)}
      +
      +
      + + Show every change with its evidence + +
      +
        +
      • + built from stored facts +
      • +
      • + written by an AI model, citations checked +
      • +
      + {rows.map((g) => ( + + ))} +
      +
      + )}
      ); diff --git a/web/src/routes/change/impact.tsx b/web/src/routes/change/impact.tsx new file mode 100644 index 00000000..133fff87 --- /dev/null +++ b/web/src/routes/change/impact.tsx @@ -0,0 +1,369 @@ +// The impact at a glance: each stored measure at the comparison date against now, drawn as two +// dots on one line, with whether that is better or worse and how fast it moved before and after. +// Every value is a stored series point; this file only compares two of them. +import { ComputedMark } from "../../components/cx/badges"; +import { cn } from "../../components/cx/cn"; +import { allFindings } from "../../components/cx/finding-fix"; +import { STATUS, fmt, pct } from "../../cx/meta"; +import type { Finding, RepoBundle, SeriesPoint } from "../../cx/types"; + +const WORSE = STATUS.slipping.color; +const BETTER = STATUS.holding.color; +/** A move smaller than this share of the old value reads as "about the same". */ +const SAME = 0.03; + +type Verdict = "worse" | "better" | "same"; + +interface Measure { + /** Stored yardstick name. */ + series: string; + label: string; + question: string; + lowerIsBetter: boolean; + format: (v: number) => string; + /** Formats a change per month. */ + pace: (v: number) => string; +} + +const sign = (v: number) => (v > 0 ? "+" : v < 0 ? "−" : "±"); + +const MEASURES: Measure[] = [ + { + series: "against_grain_share", + label: "Backward links", + question: "Does shared code reach back up into features?", + lowerIsBetter: true, + format: (v) => pct(v), + pace: (v) => `${sign(v)}${Math.abs(v * 100).toFixed(2)} pts`, + }, + { + series: "two_way_module_pairs", + label: "Two-way dependencies", + question: "Are modules more tangled with each other?", + lowerIsBetter: true, + format: (v) => fmt(Math.round(v)), + pace: (v) => `${sign(v)}${Math.abs(v).toFixed(1)}`, + }, + { + series: "exceptions_per_kloc", + label: "Rule breaks per 1,000 lines", + question: "Does new code break the recorded decisions more often?", + lowerIsBetter: true, + format: (v) => v.toFixed(2), + pace: (v) => `${sign(v)}${Math.abs(v).toFixed(3)}`, + }, + { + series: "decisions_holding", + label: "Decisions still holding", + question: "How many architecture decisions are still kept?", + lowerIsBetter: false, + format: (v) => fmt(Math.round(v)), + pace: (v) => `${sign(v)}${Math.abs(v).toFixed(2)}`, + }, +]; + +/** The stored point on the date, or the last one before it. */ +function pointAt(series: SeriesPoint[], date: string): SeriesPoint | null { + let hit: SeriesPoint | null = null; + for (const p of series) if (p.date <= date) hit = p; + return hit; +} + +/** Months between two ISO dates, at least a tenth of a month. */ +function months(a: string, b: string): number { + const d = (Date.parse(b) - Date.parse(a)) / (1000 * 60 * 60 * 24 * 30.44); + return Math.max(0.1, d); +} + +function verdictOf(m: Measure, before: number, now: number): Verdict { + const base = Math.max(Math.abs(before), 1e-9); + if (Math.abs(now - before) / base < SAME) return "same"; + const rose = now > before; + return rose === m.lowerIsBetter ? "worse" : "better"; +} + +interface Row { + m: Measure; + before: SeriesPoint; + now: SeriesPoint; + verdict: Verdict; + /** Change per month before the comparison date and after it; null without enough points. */ + paceBefore: number | null; + paceAfter: number; +} + +function rowsOf(repo: RepoBundle, compareDate: string): Row[] { + return MEASURES.flatMap((m) => { + const s = repo.yardstickSeries[m.series] ?? []; + const before = pointAt(s, compareDate); + const now = s.at(-1); + if (!before || !now || now === before) return []; + const first = s[0]; + const paceBefore = + first && first !== before + ? (before.value - first.value) / months(first.date, before.date) + : null; + const paceAfter = (now.value - before.value) / months(before.date, now.date); + return [ + { m, before, now, verdict: verdictOf(m, before.value, now.value), paceBefore, paceAfter }, + ]; + }); +} + +const VERDICT_TEXT: Record = { + worse: "Worse", + better: "Better", + same: "About the same", +}; + +function VerdictTag({ v }: { v: Verdict }) { + return ( + + + {VERDICT_TEXT[v]} + + ); +} + +/** Two dots on one line: hollow is then, filled is now. The line between them carries the verdict. */ +function Dumbbell({ row }: { row: Row }) { + const { before, now, verdict } = row; + const hi = Math.max(before.value, now.value) * 1.12 || 1; + const x = (v: number) => 8 + (v / hi) * 284; + const color = + verdict === "worse" ? WORSE : verdict === "better" ? BETTER : "var(--muted-foreground)"; + const a = x(before.value); + const b = x(now.value); + const dir = b >= a ? 1 : -1; + return ( + + + + + + + ); +} + +function paceText(row: Row): string | null { + const { paceBefore: pb, paceAfter: pa, m } = row; + if (pb === null) return null; + const word = (v: number) => (Math.abs(v) < 1e-9 ? "flat" : `${m.pace(v)} a month`); + return `Before: ${word(pb)}. After: ${word(pa)}.`; +} + +/** How the pace after the comparison date compares with the pace before it. */ +function momentum(row: Row): string | null { + const { paceBefore: pb, paceAfter: pa } = row; + if (pb === null || Math.abs(pa) < 1e-9) return null; + if (Math.abs(pb) < 1e-9) return pa > 0 ? "started rising" : "started falling"; + if (Math.sign(pb) !== Math.sign(pa)) return pa > 0 ? "turned upward" : "turned downward"; + const r = Math.abs(pa) / Math.abs(pb); + if (r >= 1.25) return "moving faster than before"; + if (r <= 0.8) return "moving slower than before"; + return "same pace as before"; +} + +function MeasureRow({ row, compact }: { row: Row; compact: boolean }) { + const { m, before, now, verdict } = row; + const pace = compact ? null : paceText(row); + return ( +
    1. +
      +

      {m.label}

      +

      + {m.question}{" "} + + ({m.lowerIsBetter ? "lower" : "higher"} is better) + +

      + {pace &&

      {pace}

      } +
      + + {m.format(before.value)} + +
      + + {m.format(before.value)} + + + + {m.format(now.value)} + +
      + + {m.format(now.value)} + + + + {!compact && momentum(row) && ( + {momentum(row)} + )} + +
    2. + ); +} + +const TREND_PARTS: { key: Finding["trend"]["status"]; label: string; color: string }[] = [ + { key: "new_since_2025_03", label: "new since March 2025", color: "var(--foreground)" }, + { key: "worse", label: "getting worse", color: WORSE }, + { key: "unchanged", label: "unchanged", color: "var(--border)" }, + { key: "better", label: "improving", color: BETTER }, +]; + +/** Every ranked problem, split by how it moved over the snapshots. */ +function ProblemTrend({ repo }: { repo: RepoBundle }) { + const all = allFindings(repo); + if (all.length === 0) return null; + const counts = TREND_PARTS.map((p) => ({ + ...p, + n: all.filter((f) => f.trend.status === p.key).length, + })); + return ( +
      +

      The {fmt(all.length)} problems found, by how they moved

      +
      `${c.n} ${c.label}`).join(", ")} + > + {counts.map( + (c) => + c.n > 0 && ( + + ), + )} +
      +
        + {counts.map((c) => ( +
      • + + {fmt(c.n)}{" "} + {c.label} +
      • + ))} +
      +
      + ); +} + +/** "3 measures got worse and 1 got better." */ +function Headline({ rows }: { rows: Row[] }) { + const n = (v: Verdict) => rows.filter((r) => r.verdict === v).length; + const parts: { v: Verdict; text: string }[] = []; + if (n("worse")) parts.push({ v: "worse", text: `${n("worse")} got worse` }); + if (n("better")) parts.push({ v: "better", text: `${n("better")} got better` }); + if (n("same")) parts.push({ v: "same", text: `${n("same")} stayed about the same` }); + return ( +

      + Of {rows.length} measures,{" "} + {parts.map((p, i) => ( + + {i > 0 && (i === parts.length - 1 ? " and " : ", ")} + + {p.text} + + + ))} + . +

      + ); +} + +export function Impact({ + repo, + compareDate, + compact = false, +}: { + repo: RepoBundle; + compareDate: string; + compact?: boolean; +}) { + const rows = rowsOf(repo, compareDate); + if (rows.length === 0) return null; + const nowDate = rows[0].now.date; + const size = repo.yardstickSeries.cross_module_links ?? []; + const sizeBefore = pointAt(size, compareDate); + const sizeNow = size.at(-1); + const grew = + sizeBefore && sizeNow && sizeBefore.value > 0 + ? (sizeNow.value - sizeBefore.value) / sizeBefore.value + : null; + return ( +
      + +
      +
      + measure + {compareDate} + + + + + then + + + + now + + {nowDate} + since then +
      +
        + {rows.map((r) => ( + + ))} +
      + {!compact && } +
      +

      + {grew !== null && grew > 0.05 && ( + <> + The code itself grew: links between modules went from {fmt(sizeBefore!.value)} to{" "} + {fmt(sizeNow!.value)} ({sign(grew)} + {Math.round(Math.abs(grew) * 100)}%). Backward links and rule breaks per 1,000 lines are + rates, so they already allow for that.{" "} + + )} + These are stored measurements at two dates. They show what changed, not that AI caused it.{" "} + +

      +
      + ); +} diff --git a/web/src/routes/finding/Reading.tsx b/web/src/routes/finding/Reading.tsx index 61d8e61d..452f763d 100644 --- a/web/src/routes/finding/Reading.tsx +++ b/web/src/routes/finding/Reading.tsx @@ -20,7 +20,7 @@ import type { Finding, RepoBundle } from "../../cx/types"; const GOOD = STATUS.holding.color; -const headCls = "font-mono text-[11px] tracking-[0.14em] text-muted-foreground uppercase"; +const headCls = "text-sm font-semibold text-foreground"; /** * The computed summary without the template's fix sentence when the fix is shown on its own @@ -133,7 +133,7 @@ function FixBlock({ to?: string | null; }) { return ( -
      +
      Proposed fix · {ACTION[fix.action]} {symbol && {symbol}} @@ -152,7 +152,7 @@ function FixBlock({ function NoFix({ note }: { note: string | null }) { return ( -
      +

      {NO_FIX_TEXT}

      {note && (
      diff --git a/web/src/routes/map/CellPanel.tsx b/web/src/routes/map/CellPanel.tsx index 6383dfd5..0c08b47d 100644 --- a/web/src/routes/map/CellPanel.tsx +++ b/web/src/routes/map/CellPanel.tsx @@ -72,7 +72,7 @@ export function CellPanel({ <> {" · "} - {against ? "against the grain" : "with the grain"} + {against ? "backward link" : "forward link"} )} diff --git a/web/src/routes/overview/BeforeAfter.tsx b/web/src/routes/overview/BeforeAfter.tsx index 6b133655..f09b80e7 100644 --- a/web/src/routes/overview/BeforeAfter.tsx +++ b/web/src/routes/overview/BeforeAfter.tsx @@ -1,12 +1,10 @@ import { ArrowRight } from "lucide-react"; import { Link } from "react-router"; -import { ComputedMark } from "../../components/cx/badges"; import { FOCUS, cn } from "../../components/cx/cn"; import { SectionHead } from "../../components/cx/primitives"; -import { Sparkline, markIndex } from "../../components/cx/sparkline"; import { repoPath } from "../../cx/address"; -import { STATUS, fmt, pct } from "../../cx/meta"; -import type { RepoBundle, Yardstick } from "../../cx/types"; +import type { RepoBundle } from "../../cx/types"; +import { Impact } from "../change/impact"; const MONTHS = [ "January", @@ -30,89 +28,8 @@ export function monthYear(date: string): string { return m && name ? `${name} ${m[1]}` : date; } -/** Formats a yardstick value; both values of one yardstick share the number of decimals. */ -function formatter(y: Yardstick): (v: number) => string { - if (y.unit === "share") return (v) => pct(v); - if (y.unit === "pairs" || y.unit === "links" || y.unit === "decisions") return (v) => fmt(v); - const values = [y.now, y.before].filter((v): v is number => v !== null); - const decimals = values.some((v) => v !== 0 && Math.abs(v) < 0.1) ? 3 : 2; - return (v) => v.toFixed(decimals); -} - -function YardstickCell({ - label, - hint, - y, - now, - compareDate, -}: { - label: string; - hint: string; - y: Yardstick; - now: number; - compareDate: string; -}) { - const f = formatter(y); - const change = - y.before === null ? null : now > y.before ? "up" : now < y.before ? "down" : "same"; - return ( -
      -
      {label}
      -
      - - {f(now)} - {y.before !== null && ( - - {change === "up" ? "▲ " : change === "down" ? "▼ " : ""} - {change === "same" ? "unchanged from" : "from"} {f(y.before)} - - )} - - p.value)} - mark={markIndex( - y.series.map((p) => p.date), - compareDate, - )} - width={84} - height={22} - color={change === "up" ? "var(--accent)" : "var(--primary)"} - label={`${label} at each snapshot, ${y.series[0]?.date ?? ""} to ${y.series.at(-1)?.date ?? ""}`} - /> -
      -

      {hint}

      -
      - ); -} - -/** The three yardsticks at the end snapshot against the comparison date. */ +/** The report's view of the bonus question: the impact panel, short form. */ export function BeforeAfter({ repo, compareDate }: { repo: RepoBundle; compareDate: string }) { - const y = repo.yardsticks; - const rows = [ - { - label: "Links against the grain", - hint: "Share of links between modules that point against the main direction of dependencies.", - y: y.againstGrainShare, - }, - { - label: "Module pairs using each other", - hint: "Two modules that depend on each other cannot be changed or tested alone.", - y: y.twoWayPairs, - }, - { - label: "Exceptions per 1,000 lines", - hint: "Decision exceptions per 1,000 lines of code, for the decisions that apply.", - y: y.perKloc, - }, - ].flatMap((r) => (r.y.now === null ? [] : [{ ...r, now: r.y.now }])); - return (
      } /> -

      - - {repo.adoptionDate ? ( - <> - The team adopted AI coding tools around{" "} - {repo.adoptionDate.slice(0, 7)} - .{" "} - - ) : ( - <>No adoption date of AI coding tools was detected in this run. - )} - Each value is at the end snapshot, with its value at{" "} - {compareDate.slice(0, 7)} below it. - - +

      + {repo.adoptionDate ? ( + <> + The team adopted AI coding tools around{" "} + {repo.adoptionDate.slice(0, 7)}. Here + is how the structure moved from {monthYear(compareDate)} to now. + + ) : ( + <>How the structure moved from {monthYear(compareDate)} to now. + )}

      - {rows.length > 0 && ( -
      - {rows.map((r) => ( - - ))} -
      - )} +
      ); } diff --git a/web/src/routes/overview/FixFirst.tsx b/web/src/routes/overview/FixFirst.tsx index b3815b07..ec097d05 100644 --- a/web/src/routes/overview/FixFirst.tsx +++ b/web/src/routes/overview/FixFirst.tsx @@ -1,109 +1,23 @@ import { ArrowRight, ArrowUpRight } from "lucide-react"; import { Link } from "react-router"; -import { AiBadge, ComputedMark } from "../../components/cx/badges"; +import { AiBadge } from "../../components/cx/badges"; import { FOCUS, cn } from "../../components/cx/cn"; -import { allFindings, fixOf } from "../../components/cx/finding-fix"; +import { allFindings } from "../../components/cx/finding-fix"; import { TREND } from "../../components/cx/finding-row"; import { SectionHead } from "../../components/cx/primitives"; import { Sparkline, markIndex } from "../../components/cx/sparkline"; -import { findingPath, mapPath, repoPath } from "../../cx/address"; -import { BATCH_LOOPS_NOTE, NO_FIX_TEXT, TYPE, VERDICT, fmt, pct } from "../../cx/meta"; -import type { Batch, Fact, Finding, RepoBundle } from "../../cx/types"; +import { findingPath, repoPath } from "../../cx/address"; +import { TYPE, VERDICT, fmt } from "../../cx/meta"; +import type { Finding, RepoBundle } from "../../cx/types"; /** How many findings the overview lists before linking to all of them. */ const SHOWN = 5; -/** How many stored facts one row shows. */ -const FACTS_SHOWN = 4; -/** Longer text facts (paths, function lists) are left to the finding page. */ -const SHORT_TEXT = 40; const linkCls = cn( "inline-flex items-center gap-1 rounded-sm text-foreground hover:underline", FOCUS, ); -/** Readable names for the stored fact keys; an unknown key falls back to its own words. */ -const FACT_LABEL: Record = { - direct_users: "Direct users", - changes_12m: "Changes in 12 months", - reach: "Reach", - pressure: "Change pressure", - weak_links: "Weak direction", - strong_links: "Strong direction", - symbol: "Symbol", - shared_commits: "Shared commits", - shared_share: "Changed together", - changes_a: "Changes, first file", - changes_b: "Changes, second file", - violating_links: "Links against the decision", - reverse_links: "Links the other way", - files: "Files", - lines: "Lines", - branches: "Branches", - score: "Changes × branches", - dependencies: "Project files used", - longest_functions: "Longest functions", - top_functions: "Most branched", - feature_links: "Links to features", - instability: "Instability", - modules_total: "Modules", - other_modules_in_area: "Other modules in its area", - user_modules: "Modules using it", - user_modules_in_area: "Users in its area", -}; - -/** Hover text for the facts whose short label needs a word more. */ -const FACT_HINT: Record = { - reach: "Files that use the affected code directly or at one remove", - pressure: "Changes to the affected code in the last 12 months", - instability: "Outgoing links divided by all links of the module", - shared_share: "Share of their changes made in the same commits", -}; - -/** Facts stored as a share between 0 and 1. */ -const SHARE_FACTS = new Set(["shared_share"]); - -function factLabel(key: string): string { - const known = FACT_LABEL[key]; - if (known) return known; - const words = key.replace(/_/g, " "); - return words.charAt(0).toUpperCase() + words.slice(1); -} - -function hasValue(x: Fact): boolean { - const v = x.value as unknown; - return v !== null && v !== undefined && !(typeof v === "string" && v.trim() === ""); -} - -/** - * Up to four stored facts for a list row: numbers first, in stored order, then short text. - * Change pressure is left out when it repeats the stored count of changes. - */ -function rowFacts(f: Finding): Fact[] { - const usable = f.facts.filter(hasValue); - const changes = usable.find((x) => x.key === "changes_12m"); - const kept = usable.filter( - (x) => !(x.key === "pressure" && changes !== undefined && changes.value === x.value), - ); - const numbers = kept.filter((x) => typeof x.value !== "string"); - const texts = kept.filter((x) => typeof x.value === "string" && x.value.length <= SHORT_TEXT); - return [...numbers, ...texts].slice(0, FACTS_SHOWN); -} - -/** The value as the row shows it, with the unit when the label does not already name it. */ -function factText(x: Fact): string { - const v = x.value; - if (typeof v === "boolean") return v ? "yes" : "no"; - if (typeof v === "string") return v; - if (SHARE_FACTS.has(x.key)) return pct(v, 0); - const num = Number.isInteger(v) ? fmt(v) : String(v); - const unit = x.unit; - if (!unit) return num; - const root = unit.replace(/s$/, "").toLowerCase(); - if (factLabel(x.key).toLowerCase().includes(root)) return num; - return `${num} ${v === 1 && unit.length > 1 && unit.endsWith("s") ? unit.slice(0, -1) : unit}`; -} - /** Vermilion is kept for code that goes against a decision; other findings use plain ink. */ function trendStyle(f: Finding): { className: string; color?: string; line: string } { const t = TREND[f.trend.status]; @@ -117,76 +31,40 @@ function trendStyle(f: Finding): { className: string; color?: string; line: stri }; } +/** One finding: rank, the stored headline, why it matters, and where it is heading. */ function Row({ repoId, f, compareDate }: { repoId: string; f: Finding; compareDate: string }) { const t = TREND[f.trend.status]; const ts = trendStyle(f); const series = f.trend.series; - const facts = rowFacts(f); - const fix = fixOf(f); return (
    3. - + {f.rank} -
      -

      - {TYPE[f.type].label} +

      +

      + {f.title} +

      +

      + {TYPE[f.type].label}. {TYPE[f.type].why} {f.judgement && ( - + {VERDICT[f.judgement.verdict]} )} - -

      -

      {f.title}

      - {facts.length > 0 && ( -
      - {facts.map((x) => ( -
      -
      {factLabel(x.key)}
      -
      - {factText(x)} -
      -
      - ))} -
      - )} -

      - {TYPE[f.type].why} -

      -

      - Fix - {fix ? ( - <> - - {fix.text} - - {fix.source === "ai" ? ( - - ) : ( - - )} - - ) : ( - {NO_FIX_TEXT} - )}

      -
      +
      p.value)} mark={markIndex( @@ -214,32 +92,7 @@ function Row({ repoId, f, compareDate }: { repoId: string; f: Finding; compareDa ); } -/** One line for the simulated fix batch, linking to the Map after the batch. */ -function BatchLine({ repoId, batch }: { repoId: string; batch: Batch }) { - const n = batch.fixesApplied; - const loops = - batch.loopsAfter === batch.loopsBefore - ? `module loops stay at ${fmt(batch.loopsBefore)}` - : `module loops go from ${fmt(batch.loopsBefore)} to ${fmt(batch.loopsAfter)}`; - const created = batch.newExceptions.length; - return ( -

      - - Simulated fix batch: with{" "} - {fmt(n)}{" "} - {n === 1 ? "fix" : "fixes"} applied together on a copy of the module map, {loops} - {created > 0 && - `, and ${fmt(created)} new ${created === 1 ? "exception" : "exceptions"} appear`} - . Nothing is applied to the code. - - - See it on the map - -

      - ); -} - -/** The top findings, each with its facts, why it matters and its proposed fix. */ +/** The top findings, ranked. Facts, evidence and the proposed fix are on each finding's page. */ export function FixFirst({ repo, compareDate }: { repo: RepoBundle; compareDate: string }) { const total = allFindings(repo).length; return ( @@ -265,7 +118,6 @@ export function FixFirst({ repo, compareDate }: { repo: RepoBundle; compareDate: ))}
    )} - {repo.batch && } ); } diff --git a/web/src/routes/overview/Structure.tsx b/web/src/routes/overview/Structure.tsx index 38a28477..f1cd2386 100644 --- a/web/src/routes/overview/Structure.tsx +++ b/web/src/routes/overview/Structure.tsx @@ -6,6 +6,8 @@ import type { ModuleInfo, RepoBundle } from "../../cx/types"; /** How many modules the structure list shows. */ const MODULES_SHOWN = 8; +/** How many the report's short list shows. */ +const MODULES_SHORT = 6; /** The module's number as the Map's axes show it. */ const pad = (i: number, n: number) => String(i + 1).padStart(n >= 100 ? 3 : 2, "0"); @@ -102,3 +104,36 @@ export function Structure({ repo }: { repo: RepoBundle }) { ); } + +/** The report's short list: the six largest modules, what each does, and how linked it is. */ +export function MainModules({ repo }: { repo: RepoBundle }) { + const all = mainModules(repo); + const shown = all.slice(0, MODULES_SHORT); + if (shown.length === 0) return null; + return ( +
      + {shown.map((m) => ( +
    1. +
      + + {m.name} + + + {m.loc !== null ? `${fmt(Math.round(m.loc / 1000))}k lines` : ""} + +
      + {m.description && ( +

      + {m.description.source === "ai" && } + {m.description.text} +

      + )} +

      + + +

      +
    2. + ))} +
    + ); +} diff --git a/web/src/routes/overview/TrustStrip.tsx b/web/src/routes/overview/TrustStrip.tsx index 99289ecd..1a57debe 100644 --- a/web/src/routes/overview/TrustStrip.tsx +++ b/web/src/routes/overview/TrustStrip.tsx @@ -3,81 +3,138 @@ import type { ReactNode } from "react"; import { Link } from "react-router"; import { ComputedMark } from "../../components/cx/badges"; import { FOCUS, cn } from "../../components/cx/cn"; +import { SectionHead } from "../../components/cx/primitives"; import { repoPath } from "../../cx/address"; import { fmt } from "../../cx/meta"; import type { RepoBundle } from "../../cx/types"; -/** Cost in US dollars, written as the Trust screen writes it. */ -const usd = (n: number) => `$${n.toFixed(3)}`; +/** The stored re-run tests, in the order a reader can follow them. */ +const TESTS: { test: string; label: string }[] = [ + { test: "identical_rerun", label: "Run again, same input" }, + { test: "fresh_ai_run", label: "Run again with fresh AI text" }, + { test: "commits_removed_5pct", label: "5% of commits left out" }, + { test: "weights_changed_20pct", label: "Ranking weights moved by 20%" }, + { test: "end_date_minus_1_month", label: "Snapshot one month earlier" }, +]; -function Fact({ label, children }: { label: string; children: ReactNode }) { +function Block({ + title, + lead, + children, +}: { + title: string; + lead: ReactNode; + children?: ReactNode; +}) { return ( -
    -
    {label}
    -
    - {children} -
    +
    +

    {title}

    +

    {lead}

    + {children}
    ); } -/** A slim row of stored facts the report rests on, with a link to the Approach tab. */ +/** Robustness and efficiency, the two judging points a reader cannot see in the findings. */ export function TrustStrip({ repo }: { repo: RepoBundle }) { - const rerun = repo.stability.find((s) => s.test === "identical_rerun") ?? null; + const byTest = new Map(repo.stability.map((s) => [s.test, s])); + const tests = TESTS.flatMap((t) => { + const s = byTest.get(t.test); + return s ? [{ ...t, kept: Math.round(s.top10 * 10) }] : []; + }); + const rerun = byTest.get("identical_rerun"); const files = repo.coverage.reduce((s, c) => s + c.files, 0); const unread = repo.coverage.reduce((s, c) => s + c.unread, 0); const calls = repo.usage.reduce((s, u) => s + u.calls, 0); const cost = repo.usage.reduce((s, u) => s + u.cost, 0); const limits = repo.blindSpots.length; - const muted = "text-muted-foreground"; return ( -
    -

    - What this report rests on -

    -
    - {rerun !== null && ( - - top 10: {Math.round(rerun.top10 * 10)} of 10{" "} - unchanged on an identical re-run - - )} - {repo.coverage.length > 0 && ( - - {fmt(files)}{" "} - · {fmt(unread)} with unread parts - - )} - - {repo.usage.length === 0 ? ( - no AI call logged · ranking uses no AI model - ) : ( - <> - - {fmt(calls)} {calls === 1 ? "call" : "calls"} · {usd(cost)} - {" "} - · ranking uses no AI model - +
    + + How it works + + } + /> +
    + + Run twice, the top 10 stays the same:{" "} + {Math.round(rerun.top10 * 10)} of 10. + + ) : ( + "No re-run was stored for this report." + ) + } + > + {tests.length > 1 && ( +
      + {tests.map((t) => ( +
    • + {t.label} + + {Array.from({ length: 10 }, (_, i) => ( + + ))} + + {t.kept} of 10 +
    • + ))} +
    )} - - - {fmt(limits)}{" "} - {limits === 1 ? "limit" : "limits"} stated - -
    - - Approach - +

    + How many of the top 10 findings stay in the top 10 under each change.{" "} + +

    + + Finding, counting and ranking use no AI model. AI only reads and writes text.} + > +
    +
    +
    AI calls for this report
    +
    + {repo.usage.length === 0 ? "none" : fmt(calls)} +
    +
    +
    +
    Total AI cost
    +
    ${cost.toFixed(2)}
    +
    + {repo.coverage.length > 0 && ( +
    +
    Files read
    +
    {fmt(files)}
    +
    {fmt(unread)} with unread parts
    +
    + )} +
    +
    Limits stated openly
    +
    {fmt(limits)}
    +
    +
    +
    +
    ); }