open-swe/ui/src/components/agents/ported/markdownLocation.ts
Johannes du Plessis 801f93b4de
feat: AI-sorted PR review view with diff grouping (#1544)
* feat: AI-sorted PR review view with diff grouping

Group a PR's changed files into a logical top-to-bottom walkthrough via a best-effort structured-output LLM pass, kicked off concurrently with the reviewer run (~0 added latency) and persisted on reviewer thread metadata. Results render in the review UI behind an AI sorted / file tree toggle that persists across PRs; the view falls back to the file tree when groups are absent or stale.

Adds a grouping-model team default (inherits the Reviewer subagent model when unset) and the admin RolePicker for it.

* feat(reviews): richer AI-sorted explanations + sidebar polish

Sidebar group rows get Devin-style spacing (dividers, padding), a per-group file list (click a file to jump to its diff), inline-code chips in titles, and an accent Read explanation link.

Group explanations are now rich markdown: the grouping prompt feeds per-hunk line ranges and asks for inline code, a short code block, and [path:line](#loc=...) references. The Markdown renderer turns those #loc= links into in-page buttons that scroll the diff to the hunk and highlight the range, reusing the existing selectedLines path.

* fix(reviews): drop stale diff groups from the AI-sorted view

When groups were generated for a previous head, a persisted "ai" view in localStorage still rendered the outdated walkthrough. groupedView now returns null on diff_groups_stale, so the file-tree fallback is used and the view toggle hides until fresh groups arrive.

---------

Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
2026-06-16 13:59:37 -07:00

35 lines
1.2 KiB
TypeScript

export interface MarkdownLocation {
file: string;
startLine: number;
endLine: number;
}
/**
* Parse a `#loc=<path>:<start>[-<end>]` sentinel href emitted by the reviewer
* diff-grouping pass into a file + line range. Tolerant of an origin prefix the
* markdown URL transform may prepend, and of percent-encoding. Returns null for
* any href that isn't a location link.
*/
export function parseLocationHref(href?: string): MarkdownLocation | null {
if (!href) return null;
const marker = href.indexOf("#loc=");
if (marker === -1) return null;
let raw = href.slice(marker + "#loc=".length);
try {
raw = decodeURIComponent(raw);
} catch {
// Keep raw as-is if it isn't valid percent-encoding.
}
const colon = raw.lastIndexOf(":");
if (colon <= 0) return null;
const file = raw.slice(0, colon);
const [startStr, endStr] = raw.slice(colon + 1).split("-");
const start = Number.parseInt(startStr ?? "", 10);
if (!Number.isFinite(start) || start <= 0) return null;
const end = endStr !== undefined ? Number.parseInt(endStr, 10) : start;
return {
file,
startLine: start,
endLine: Number.isFinite(end) && end >= start ? end : start,
};
}