Skip to content

OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security

feat(serve): make dashboard tables sortable (#958)

mluck-openai8fb0cde9e0cd
diff --git a/plugins/codex-security/scripts/workbench_dashboard.py b/plugins/codex-security/scripts/workbench_dashboard.py
index 1c6e2e6b2..50c13f333 100644
--- a/plugins/codex-security/scripts/workbench_dashboard.py
+++ b/plugins/codex-security/scripts/workbench_dashboard.py
@@ -40,10 +40,24 @@ RECORDS = {
"groups": GROUP_RECORDS,
}
+SORT_COLUMNS = {
+ "activity": "updatedAt",
+ "newest": "createdAt",
+ "title": "casefold(title)",
+ "repository": "casefold(repository_label(repositoryIds))",
+ "severity": "CASE severity WHEN 'informational' THEN 0 WHEN 'low' THEN 1 "
+ "WHEN 'medium' THEN 2 WHEN 'high' THEN 3 WHEN 'critical' THEN 4 END",
+ "members": "memberCount",
+}
+
+
+def repository_ids(value: str) -> list[str]:
+ return sorted(json.loads(value), key=lambda name: (name.casefold(), name))
+
def item(row: sqlite3.Row) -> dict[str, Any]:
result = dict(row)
- result["repositoryIds"] = json.loads(result["repositoryIds"])
+ result["repositoryIds"] = repository_ids(result["repositoryIds"])
return result
@@ -77,10 +91,13 @@ def dashboard(connection: sqlite3.Connection, query: dict[str, Any]) -> dict[str
"""One snapshot, no artifact reads, model calls, or writes."""
view = query["view"]
records = RECORDS[view]
+ connection.create_function("casefold", 1, str.casefold, deterministic=True)
+ connection.create_function(
+ "repository_label", 1, lambda value: ", ".join(repository_ids(value)), deterministic=True
+ )
clauses: list[str] = []
values: list[Any] = []
if query.get("query"):
- connection.create_function("casefold", 1, str.casefold, deterministic=True)
columns = ["id", "title", "repositoryIds"]
clauses.append(
"("
@@ -92,7 +109,11 @@ def dashboard(connection: sqlite3.Connection, query: dict[str, Any]) -> dict[str
clauses.append("EXISTS (SELECT 1 FROM json_each(repositoryIds) WHERE value = ?)")
values.append(query["repository"])
where = " WHERE " + " AND ".join(clauses) if clauses else ""
- order = "createdAt DESC, id" if query["sort"] == "newest" else "updatedAt DESC, id"
+ direction = {"asc": "ASC", "desc": "DESC"}[query.get("direction", "desc")]
+ order = f"{SORT_COLUMNS[query['sort']]} {direction}"
+ if view == "findings" and query["sort"] == "activity":
+ order += f", {SORT_COLUMNS['severity']} DESC"
+ order += ", id"
connection.execute("BEGIN")
with connection:
repositories = connection.execute("""
diff --git a/sdk/typescript/README.md b/sdk/typescript/README.md
index 8b2726180..703add6be 100644
--- a/sdk/typescript/README.md
+++ b/sdk/typescript/README.md
@@ -1793,6 +1793,12 @@ cancels, resumes, publishes, edits, or deduplicates anything.
The dashboard opens on Findings, followed by Duplicate groups. Both views
support search, repository filtering, sorting, pagination, and record details.
+Click any column header to sort all matching records; click it again to reverse
+the order. The arrow marks the active column and direction. Changing the sort
+returns to the first page, and automatic refreshes keep the selected order.
+By default, findings sort by last update descending, then severity descending,
+then ID ascending to break ties. Groups sort by last update descending and ID
+ascending.
Findings show stored content and links to their duplicate groups. Groups link
back to their member findings, preserving separate overlapping groups and the
original finding records.
@@ -1809,7 +1815,10 @@ repository choices, a page of records, and optional selected-record details:
- `view`: `findings` (default) or `groups`.
- `query`, `repository`: optional search text and exact repository ID.
-- `sort`: `activity` (default; most recently updated first) or `newest`.
+- `sort`: `activity` (default; last update), `newest` (created), `title`,
+ `repository`, `severity` (findings only), or `members` (groups only).
+- `direction`: `asc` or `desc` (default). Text sorts alphabetically without
+ case sensitivity, severity by level, and member counts numerically.
- `limit`, `offset`: existing pagination conventions, defaulting to 50 and 0.
- `id`: optional exact record ID to include in `detail`; unknown IDs return
`detail: null` without hiding the list.
diff --git a/sdk/typescript/dashboard/App.tsx b/sdk/typescript/dashboard/App.tsx
index e44dcd884..ff1090bd0 100644
--- a/sdk/typescript/dashboard/App.tsx
+++ b/sdk/typescript/dashboard/App.tsx
@@ -7,6 +7,8 @@ import type {
DashboardDetail,
DashboardItem,
DashboardSnapshot,
+ DashboardSort,
+ DashboardSortDirection,
DashboardView,
} from "../src/server/dashboard-types.js";
import { pollDashboard } from "./polling.js";
@@ -185,13 +187,28 @@ function Results({
selected,
navigate,
now,
+ sort,
+ onSort,
+ emptyState,
}: {
view: DashboardView;
items: DashboardItem[];
selected: string;
navigate: Navigate;
now: number;
+ sort: { column: DashboardSort; direction: DashboardSortDirection };
+ onSort: (column: DashboardSort) => void;
+ emptyState: ReactNode;
}) {
+ const columns: { sort: DashboardSort; label: string }[] = [
+ { sort: "title", label: view === "findings" ? "Finding" : "Group" },
+ { sort: "repository", label: "Repository" },
+ view === "findings"
+ ? { sort: "severity", label: "Severity" }
+ : { sort: "members", label: "Members" },
+ { sort: "newest", label: "Created" },
+ { sort: "activity", label: "Last update" },
+ ];
return (
<div className="table-scroll">
<table>
@@ -200,15 +217,42 @@ function Results({
</caption>
<thead>
<tr>
- <th scope="col">{view === "findings" ? "Finding" : "Group"}</th>
- <th scope="col">Repository</th>
- {view === "findings" && <th scope="col">Severity</th>}
- {view === "groups" && <th scope="col">Members</th>}
- <th scope="col">Created</th>
- <th scope="col">Last update</th>
+ {columns.map((column) => (
+ <th
+ key={column.sort}
+ scope="col"
+ aria-sort={
+ sort.column === column.sort
+ ? sort.direction === "asc"
+ ? "ascending"
+ : "descending"
+ : undefined
+ }
+ >
+ <button
+ type="button"
+ className="column-sort"
+ onClick={() => onSort(column.sort)}
+ >
+ {column.label}
+ <span aria-hidden="true">
+ {sort.column === column.sort
+ ? sort.direction === "asc"
+ ? "↑"
+ : "↓"
+ : "↕"}
+ </span>
+ </button>
+ </th>
+ ))}
</tr>
</thead>
<tbody>
+ {items.length === 0 && (
+ <tr>
+ <td colSpan={columns.length}>{emptyState}</td>
+ </tr>
+ )}
{items.map((item) => (
<tr key={item.id} data-selected={selected === item.id || undefined}>
<th scope="row">
@@ -266,7 +310,10 @@ export function App() {
const [view, setView] = useState<DashboardView>("findings");
const [query, setQuery] = useState("");
const [repository, setRepository] = useState("");
- const [sort, setSort] = useState("activity");
+ const [sort, setSort] = useState<{
+ column: DashboardSort;
+ direction: DashboardSortDirection;
+ }>({ column: "activity", direction: "desc" });
const [offset, setOffset] = useState(0);
const [selected, setSelected] = useState("");
const inspectorHeading = useRef<HTMLHeadingElement>(null);
@@ -285,7 +332,8 @@ export function App() {
view,
query,
repository,
- sort,
+ sort: sort.column,
+ direction: sort.direction,
offset: String(offset),
});
if (selected) parameters.set("id", selected);
@@ -329,6 +377,9 @@ export function App() {
setQuery("");
setRepository("");
setOffset(0);
+ if (sort.column === "severity" || sort.column === "members") {
+ setSort({ column: "activity", direction: "desc" });
+ }
}
setSelected(id ?? "");
}
@@ -336,6 +387,20 @@ export function App() {
setter(value);
setOffset(0);
}
+ function changeSort(column: DashboardSort) {
+ setSort({
+ column,
+ direction:
+ sort.column === column
+ ? sort.direction === "asc"
+ ? "desc"
+ : "asc"
+ : column === "title" || column === "repository"
+ ? "asc"
+ : "desc",
+ });
+ setOffset(0);
+ }
const counts: Record<DashboardView, number | undefined> = {
findings: overview?.findings,
groups: overview?.groups,
@@ -446,23 +511,6 @@ export function App() {
/>
</span>
</label>
- <label>
- <span>Sort</span>
- <span className="select-field">
- <select
- value={sort}
- onChange={(event) => filter(setSort, event.target.value)}
- >
- <option value="activity">Recent activity</option>
- <option value="newest">Newest first</option>
- </select>
- <ChevronDownVector
- className="select-caret"
- aria-hidden="true"
- focusable="false"
- />
- </span>
- </label>
</div>
{failure && (
<div role="alert" className="error-message">
@@ -488,38 +536,41 @@ export function App() {
tabIndex={-1}
aria-busy={!data && !failure}
>
- {!data ? (
- <div className="empty-state">
- <h2>
- {failure
- ? "Data unavailable"
- : `Loading ${current.label.toLowerCase()}…`}
- </h2>
- </div>
- ) : data.items.length ? (
- <Results
- view={view}
- items={data.items}
- selected={selected}
- navigate={navigate}
- now={now}
- />
- ) : (
- <div className="empty-state">
- <h2>
- {query || repository
- ? "No matching records"
- : `No ${current.label.toLowerCase()} yet`}
- </h2>
- <p>
- {query || repository
- ? "Try another search or filter."
- : view === "findings"
- ? "Published or imported findings will appear here."
- : "Accepted duplicate groups will appear here after they are saved."}
- </p>
- </div>
- )}
+ <Results
+ view={view}
+ items={data?.items ?? []}
+ selected={selected}
+ navigate={navigate}
+ now={now}
+ sort={sort}
+ onSort={changeSort}
+ emptyState={
+ !data ? (
+ <div className="empty-state">
+ <h2>
+ {failure
+ ? "Data unavailable"
+ : `Loading ${current.label.toLowerCase()}…`}
+ </h2>
+ </div>
+ ) : (
+ <div className="empty-state">
+ <h2>
+ {query || repository
+ ? "No matching records"
+ : `No ${current.label.toLowerCase()} yet`}
+ </h2>
+ <p>
+ {query || repository
+ ? "Try another search or filter."
+ : view === "findings"
+ ? "Published or imported findings will appear here."
+ : "Accepted duplicate groups will appear here after they are saved."}
+ </p>
+ </div>
+ )
+ }
+ />
{data && (
<footer className="pagination">
<span>
diff --git a/sdk/typescript/dashboard/styles.css b/sdk/typescript/dashboard/styles.css
index 8b809c4e3..77c00e026 100644
--- a/sdk/typescript/dashboard/styles.css
+++ b/sdk/typescript/dashboard/styles.css
@@ -235,6 +235,23 @@ thead th {
color: var(--color-text-secondary);
white-space: nowrap;
}
+.column-sort {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ width: 100%;
+ text-align: left;
+ cursor: pointer;
+}
+.column-sort:hover,
+th[aria-sort] .column-sort {
+ color: var(--color-text);
+}
+.column-sort:focus-visible {
+ outline: 2px solid var(--color-text);
+ outline-offset: 4px;
+ border-radius: var(--radius-sm);
+}
tbody th {
font-weight: 400;
min-width: 220px;
diff --git a/sdk/typescript/src/server/dashboard-types.ts b/sdk/typescript/src/server/dashboard-types.ts
index 4a5206046..239cf7c66 100644
--- a/sdk/typescript/src/server/dashboard-types.ts
+++ b/sdk/typescript/src/server/dashboard-types.ts
@@ -2,6 +2,9 @@ import type { Finding } from "../models.js";
import type { FindingDedupeGroup } from "../finding-dedupe-groups.js";
export type DashboardView = "findings" | "groups";
+export type DashboardSort =
+ "activity" | "newest" | "title" | "repository" | "severity" | "members";
+export type DashboardSortDirection = "asc" | "desc";
export interface DashboardQuery {
view: DashboardView;
@@ -9,7 +12,8 @@ export interface DashboardQuery {
offset: number;
query: string;
repository: string;
- sort: "activity" | "newest";
+ sort: DashboardSort;
+ direction: DashboardSortDirection;
id?: string;
}
diff --git a/sdk/typescript/src/server/dashboard.ts b/sdk/typescript/src/server/dashboard.ts
index a49565a13..bbef8aa3d 100644
--- a/sdk/typescript/src/server/dashboard.ts
+++ b/sdk/typescript/src/server/dashboard.ts
@@ -1,6 +1,11 @@
import { readFile } from "node:fs/promises";
import type { ServerResponse } from "node:http";
-import type { DashboardQuery, DashboardView } from "./dashboard-types.js";
+import type {
+ DashboardQuery,
+ DashboardSort,
+ DashboardSortDirection,
+ DashboardView,
+} from "./dashboard-types.js";
import { FindingsError } from "./errors.js";
import { pagination } from "./validation.js";
@@ -39,19 +44,43 @@ export async function serveDashboard(
export function dashboardQuery(parameters: URLSearchParams): DashboardQuery {
const view = parameters.get("view") ?? "findings";
const sort = parameters.get("sort") ?? "activity";
+ const direction = parameters.get("direction") ?? "desc";
if (!["findings", "groups"].includes(view))
throw new FindingsError("invalid_request", "Unknown dashboard view.");
- if (sort !== "activity" && sort !== "newest")
+ if (
+ ![
+ "activity",
+ "newest",
+ "title",
+ "repository",
+ "severity",
+ "members",
+ ].includes(sort)
+ )
throw new FindingsError(
"invalid_request",
- "sort must be activity or newest.",
+ "sort must be activity, newest, title, repository, severity, or members.",
+ );
+ if (
+ (view === "findings" && sort === "members") ||
+ (view === "groups" && sort === "severity")
+ )
+ throw new FindingsError(
+ "invalid_request",
+ `Cannot sort ${view} by ${sort}.`,
+ );
+ if (direction !== "asc" && direction !== "desc")
+ throw new FindingsError(
+ "invalid_request",
+ "direction must be asc or desc.",
);
return {
view: view as DashboardView,
...pagination(parameters),
query: parameters.get("query") ?? "",
repository: parameters.get("repository") ?? "",
- sort,
+ sort: sort as DashboardSort,
+ direction: direction as DashboardSortDirection,
...(parameters.has("id") ? { id: parameters.get("id")! } : {}),
};
}
diff --git a/sdk/typescript/tests-ts/findings-server.test.ts b/sdk/typescript/tests-ts/findings-server.test.ts
index 644478c61..bf2e17431 100644
--- a/sdk/typescript/tests-ts/findings-server.test.ts
+++ b/sdk/typescript/tests-ts/findings-server.test.ts
@@ -159,6 +159,10 @@ test("dashboard serves only findings and groups, and never calls an embedding pr
"view=scans",
"view=workflows",
"sort=unknown",
+ "direction=unknown",
+ "direction=ASC",
+ "view=findings&sort=members",
+ "view=groups&sort=severity",
"offset=-1",
"limit=0",
]) {
@@ -175,6 +179,179 @@ test("dashboard serves only findings and groups, and never calls an embedding pr
);
});
+test("dashboard sorts findings across pages with stable ties and filters", async () => {
+ const { store, environment } = await fixture();
+ const base = await start(store);
+ const titles = [
+ "Zulu",
+ "alpha",
+ "Bravo",
+ "ALPHA",
+ "Éclair",
+ "éCLAIR",
+ "alpha",
+ ];
+ const severities: Finding["severity"]["level"][] = [
+ "low",
+ "critical",
+ "high",
+ "medium",
+ "informational",
+ "critical",
+ "critical",
+ ];
+ const repositories = [
+ ["zeta"],
+ ["zeta", "Alpha"],
+ ["beta"],
+ ["beta", "Alpha"],
+ ["équipe"],
+ ["ÉQUIPE"],
+ ["Alpha", "beta"],
+ ];
+ const findings = titles.map((title, index) => {
+ const value = finding(index + 1);
+ value.title = title;
+ value.severity.level = severities[index]!;
+ return value;
+ });
+ for (const [index, value] of findings.entries()) {
+ for (const repository of repositories[index]!) {
+ await store.insert(
+ [{ ...embedded(index + 1), finding: value }],
+ repository,
+ );
+ }
+ }
+ await database(
+ environment,
+ `with db:
+ db.executemany("UPDATE findings SET created_at = ?, updated_at = ? WHERE id = ?", json.load(sys.stdin))
+print("null")`,
+ findings.map((value, index) => [
+ `2026-01-0${[3, 1, 2, 1, 4, 4, 1][index]}T00:00:00Z`,
+ `2026-02-0${[1, 2, 2, 2, 3, 2, 2][index]}T00:00:00Z`,
+ value.findingId,
+ ]),
+ );
+ const ids = (indices: number[]) =>
+ indices.map((index) => findings[index - 1]!.findingId);
+ const orders = {
+ activity: { asc: [1, 2, 6, 7, 3, 4, 5], desc: [5, 2, 6, 7, 3, 4, 1] },
+ newest: { asc: [2, 4, 7, 3, 1, 5, 6], desc: [5, 6, 1, 3, 2, 4, 7] },
+ title: { asc: [2, 4, 7, 3, 1, 5, 6], desc: [5, 6, 1, 3, 2, 4, 7] },
+ repository: { asc: [4, 7, 2, 3, 1, 5, 6], desc: [5, 6, 1, 3, 2, 4, 7] },
+ severity: { asc: [5, 1, 4, 3, 2, 6, 7], desc: [2, 6, 7, 3, 4, 1, 5] },
+ };
+ for (const [sort, directions] of Object.entries(orders)) {
+ for (const [direction, indices] of Object.entries(directions)) {
+ const result = await dashboard(base, { sort, direction });
+ expect(result.items.map((item) => item.id)).toEqual(ids(indices));
+ const page = await dashboard(base, {
+ sort,
+ direction,
+ limit: "2",
+ offset: "2",
+ });
+ expect(page.items).toEqual(result.items.slice(2, 4));
+ expect(page.total).toBe(7);
+ expect(page.nextOffset).toBe(4);
+ }
+ }
+ for (const sort of ["activity", "newest"] as const) {
+ const result = await dashboard(base, { sort });
+ expect(result.items.map((item) => item.id)).toEqual(ids(orders[sort].desc));
+ }
+ const result = await dashboard(base);
+ expect(result.items.map((item) => item.id)).toEqual(
+ ids(orders.activity.desc),
+ );
+ expect(
+ result.items.find((item) => item.id === findings[1]!.findingId)!
+ .repositoryIds,
+ ).toEqual(["Alpha", "zeta"]);
+ const filtered = await dashboard(base, {
+ sort: "severity",
+ direction: "desc",
+ query: "ALPHA",
+ repository: "Alpha",
+ limit: "1",
+ offset: "1",
+ });
+ expect(filtered.items.map((item) => item.id)).toEqual(ids([7]));
+ expect(filtered.total).toBe(3);
+ expect(filtered.nextOffset).toBe(2);
+});
+
+test("dashboard sorts group columns by numeric members and displayed repositories", async () => {
+ const { store, environment } = await fixture();
+ const base = await start(store);
+ const entries = Array.from({ length: 12 }, (_, index) => embedded(index + 1));
+ await store.insert(entries, "zeta");
+ await store.insert([entries[0]!], "Alpha");
+ await store.insert([entries[1]!], "beta");
+ const groups = await store.storeDedupeGroups([
+ [entries[0]!, entries[2]!].map((entry) => entry.finding.findingId),
+ [entries[1]!, entries[2]!, entries[3]!].map(
+ (entry) => entry.finding.findingId,
+ ),
+ entries.slice(2).map((entry) => entry.finding.findingId),
+ [entries[0]!, entries[3]!].map((entry) => entry.finding.findingId),
+ ]);
+ await database(
+ environment,
+ `with db:
+ db.executemany("UPDATE finding_dedupe_groups SET created_at = ? WHERE id = ?", json.load(sys.stdin))
+print("null")`,
+ groups.map((group, index) => [
+ `2026-01-0${[2, 1, 3, 2][index]}T00:00:00Z`,
+ group.groupId,
+ ]),
+ );
+ const [first, second, third, fourth] = groups.map(
+ (group) => group.groupId,
+ ) as [string, string, string, string];
+ const tied = [first, fourth].sort();
+ const titles = groups.map((group) => group.groupId).sort();
+ const orders = {
+ activity: { asc: [second, ...tied, third], desc: [third, ...tied, second] },
+ newest: { asc: [second, ...tied, third], desc: [third, ...tied, second] },
+ title: { asc: titles, desc: [...titles].reverse() },
+ repository: {
+ asc: [...tied, second, third],
+ desc: [third, second, ...tied],
+ },
+ members: { asc: [...tied, second, third], desc: [third, second, ...tied] },
+ };
+ for (const [sort, directions] of Object.entries(orders)) {
+ for (const [direction, ids] of Object.entries(directions)) {
+ const result = await dashboard(base, { view: "groups", sort, direction });
+ expect(result.items.map((item) => item.id)).toEqual(ids);
+ const page = await dashboard(base, {
+ view: "groups",
+ sort,
+ direction,
+ limit: "2",
+ offset: "1",
+ });
+ expect(page.items).toEqual(result.items.slice(1, 3));
+ expect(page.nextOffset).toBe(3);
+ }
+ }
+ const filtered = await dashboard(base, {
+ view: "groups",
+ sort: "members",
+ direction: "desc",
+ repository: "Alpha",
+ limit: "1",
+ offset: "1",
+ });
+ expect(filtered.items.map((item) => item.id)).toEqual(tied.slice(1));
+ expect(filtered.items[0]!.repositoryIds).toEqual(["Alpha", "zeta"]);
+ expect(filtered.total).toBe(2);
+ expect(filtered.nextOffset).toBeNull();
+});
+
test("dashboard browses imported findings and overlapping groups without local runs", async () => {
const { store, environment } = await fixture();
const base = await start(store);