OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security
TypeScript ai-securityapplication-securityclicode-scanningcodexcodex-securitycybersecuritydevsecopsnodejsnpmopenaisdksecuritytypescriptvulnerability-scanning
fix(history): align Unicode repository columns (#2148)
Auster J. Wang517f4a77f7f2
diff --git a/sdk/typescript/scripts/package-dist-files.mjs b/sdk/typescript/scripts/package-dist-files.mjsindex 856975c69..23708ced6 100644--- a/sdk/typescript/scripts/package-dist-files.mjs+++ b/sdk/typescript/scripts/package-dist-files.mjs@@ -144,6 +144,7 @@ const distModules = ["server/sqlite-store","server/storage","targets",+ "terminal-columns","thread-source","timestamps","trusted-executable",diff --git a/sdk/typescript/src/scan-dashboard.ts b/sdk/typescript/src/scan-dashboard.tsindex f49363cf5..8f7de4141 100644--- a/sdk/typescript/src/scan-dashboard.ts+++ b/sdk/typescript/src/scan-dashboard.ts@@ -4,6 +4,7 @@ import { PassThrough } from "node:stream";import { pathToFileURL } from "node:url";import stripAnsi from "strip-ansi";import stringWidth from "string-width";+import { fitCell, fitLine, graphemes } from "./terminal-columns.js";import { isRecord } from "./record.js";import type { ScanAuthMode, ScanBudget } from "./api.js";import type { ScanModelConfiguration } from "./config.js";@@ -834,7 +835,7 @@ export class ScanDashboard {lines.map((line, index) => {const text = typeof line === "string" ? line : line.text;- const clean = fitLine(text, width);+ const clean = fitLine(terminalText(text), width);const colored =this.#options.color === true? styleLine(@@ -961,10 +962,6 @@ export class ScanDashboard {Math.max("Status".length, 35 - progressWidth, nameAndStatusWidth - 10),);const nameWidth = Math.max(10, nameAndStatusWidth - statusWidth);- const cell = (value: string, width: number): string => {- const text = fitLine(value, width);- return text + " ".repeat(width - stringWidth(text));- };const row = (marker: string,name: string,@@ -973,7 +970,7 @@ export class ScanDashboard {findings: string,cost: string,): string =>- ` ${marker} ${cell(name, nameWidth)} ${cell(status, statusWidth)} ${progress.padStart(progressWidth)} ${findings.padStart(8)}${this.#showCost ? ` ${cost.padStart(8)}` : ""}`;+ ` ${marker} ${fitCell(terminalText(name), nameWidth)} ${fitCell(terminalText(status), statusWidth)} ${progress.padStart(progressWidth)} ${findings.padStart(8)}${this.#showCost ? ` ${cost.padStart(8)}` : ""}`;const table = visible.map(({ receipt, dashboard, status, progress }, index) =>row(@@ -1496,7 +1493,7 @@ function formatLocalTime(timestamp: number): string {}function fitActivityPrefix(prefix: string, width: number): string {- return width <= 2 ? "" : fitLine(prefix, width - 2);+ return width <= 2 ? "" : fitLine(terminalText(prefix), width - 2);}function wrapActivity(prefix: string, value: string, width: number): string[] {@@ -1562,8 +1559,6 @@ function wrapActivity(prefix: string, value: string, width: number): string[] {return lines;}-const graphemes = new Intl.Segmenter();-function columnChunks(value: string,width: number,@@ -1698,16 +1693,3 @@ function budgetBar(cost: number, limit: number): string {function terminalText(value: string): string {return stripAnsi(value).replaceAll(/[\u0000-\u001F\u007F]/gu, " ");}--function fitLine(value: string, width: number): string {- const clean = terminalText(value);- if (stringWidth(clean) <= width) return clean;- let clipped = "";- let columns = 0;- for (const { segment } of graphemes.segment(clean)) {- columns += stringWidth(segment);- if (columns > width - 1) break;- clipped += segment;- }- return `${clipped}…`;-}diff --git a/sdk/typescript/src/scan-history-renderer.ts b/sdk/typescript/src/scan-history-renderer.tsindex e0560686d..d7aa74935 100644--- a/sdk/typescript/src/scan-history-renderer.ts+++ b/sdk/typescript/src/scan-history-renderer.ts@@ -1,5 +1,6 @@import { basename, relative } from "node:path";import stringWidth from "string-width";+import { fitCell, graphemes } from "./terminal-columns.js";import type { JsonObject } from "./config.js";import {formatCoverageScopeParts,@@ -18,9 +19,6 @@ type RendererOptions = {};const STALE_SCAN_MILLISECONDS = 24 * 60 * 60 * 1_000;-const GRAPHEME_SEGMENTER = new Intl.Segmenter(undefined, {- granularity: "grapheme",-});const STATUS_STYLES: Record<string, { color: number; icon: string }> = {resolved: { color: 32, icon: "✓" },@@ -106,7 +104,7 @@ export function renderScanHistory(line += " ";lineWidth += 1;}- for (const { segment } of GRAPHEME_SEGMENTER.segment(word)) {+ for (const { segment } of graphemes.segment(word)) {const segmentWidth = stringWidth(segment);if (lineWidth + segmentWidth > available) {lines.push(`${prefix || " ".repeat(indent)}${line}`);@@ -219,7 +217,7 @@ export function renderScanHistory(const multipleRepositories =options.repository === undefined &&new Set(scans.map((scan) => scan["targetPath"])).size > 1;- const wide = width >= (multipleRepositories ? 96 : 80);+ const wide = width >= (multipleRepositories ? 97 : 80);lines.push(` ${strong(clean(repository))} ${accent("·")} ${scans.length} ${scans.length === 1 ? "scan" : "scans"}${latest === undefined ? "" : ` ${accent("·")} latest: ${clean(latest)} findings`}`,"",@@ -242,13 +240,22 @@ export function renderScanHistory(const scanRepository = basename(clean(scan["targetPath"]));if (wide) {lines.push(- ` ${clean(scan["scanId"]).padEnd(36)} ${started.padEnd(10)} ${clean(scan["mode"]).padEnd(8)}${multipleRepositories ? ` ${scanRepository.slice(0, 18).padEnd(18)}` : ""} ${findings.padEnd(8)} ${statusLabel}`,+ ` ${clean(scan["scanId"]).padEnd(36)} ${started.padEnd(10)} ${clean(scan["mode"]).padEnd(8)}${multipleRepositories ? ` ${fitCell(scanRepository, 18, "")}` : ""} ${findings.padEnd(8)} ${statusLabel}`,);} else {- lines.push(- ` ${clean(scan["scanId"])}`,- ` ${started}${multipleRepositories ? ` ${accent("·")} ${clean(scanRepository)}` : ""} ${accent("·")} ${findings} findings ${accent("·")} ${statusLabel}`,- );+ lines.push(` ${clean(scan["scanId"])}`);+ const separator = ` ${accent("·")} `;+ const summary = `${findings} findings${separator}${statusLabel}`;+ const location = multipleRepositories+ ? `${scanRepository}${separator}`+ : "";+ const line = ` ${started}${separator}${location}${summary}`;+ if (multipleRepositories && stringWidth(line) > width) {+ lines.push(` ${started}${separator}${summary}`);+ wrap([scanRepository], 4);+ } else {+ lines.push(line);+ }}}} else if (command === "findings") {diff --git a/sdk/typescript/src/terminal-columns.ts b/sdk/typescript/src/terminal-columns.tsnew file mode 100644index 000000000..ea13d3a24--- /dev/null+++ b/sdk/typescript/src/terminal-columns.ts@@ -0,0 +1,27 @@+import stringWidth from "string-width";++export const graphemes = new Intl.Segmenter();++export function fitLine(+ text: string,+ width: number,+ overflowMarker: "" | "…" = "…",+): string {+ if (overflowMarker && stringWidth(text) <= width) return text;+ const available = width - overflowMarker.length;+ let columns = 0;+ for (const { segment, index } of graphemes.segment(text)) {+ columns += stringWidth(segment);+ if (columns > available) return text.slice(0, index) + overflowMarker;+ }+ return text;+}++export function fitCell(+ text: string,+ width: number,+ overflowMarker: "" | "…" = "…",+): string {+ const fitted = fitLine(text, width, overflowMarker);+ return fitted + " ".repeat(width - stringWidth(fitted));+}diff --git a/sdk/typescript/tests-ts/scan-history-renderer.test.ts b/sdk/typescript/tests-ts/scan-history-renderer.test.tsindex f97e9d931..926767a5c 100644--- a/sdk/typescript/tests-ts/scan-history-renderer.test.ts+++ b/sdk/typescript/tests-ts/scan-history-renderer.test.ts@@ -343,39 +343,47 @@ describe("scan history renderer", () => {expect(output).not.toContain("Resolved");});- test("keeps repositories visible at narrow and wide terminal widths", () => {- const scans = [+ test("fits repository names when multi-repository history switches to the wide table", () => {+ const combining = "e\u0301".repeat(17);+ const joined = "界".repeat(8) + "👩💻";+ const repositories = [+ { name: "service", cell: "service".padEnd(18) },+ { name: `${combining}🚀-tail`, cell: `${combining} ` },+ { name: `${joined}-tail`, cell: joined },+ { name: "中", cell: "中" + " ".repeat(16) },{- scanId: "11111111-1111-4111-8111-111111111111",- targetPath: "/demo/juice-shop",- mode: "standard",- progress: { status: "complete" },- findingCount: 8,- startedAt: "2026-07-24T12:00:00Z",- },- {- scanId: "22222222-2222-4222-8222-222222222222",- targetPath: "/demo/payment-service",- mode: "deep",- progress: { status: "complete" },- findingCount: 2,- startedAt: "2026-07-23T12:00:00Z",+ name: "界".repeat(45) + joined,+ cell: "界".repeat(9),+ compact: `7 findings · ✓ COMPLETE\n ${"界".repeat(45)}\n ${joined}`,},];-- for (const columns of [72, 100]) {- const output = stripVTControlCharacters(+ const scans = repositories.map(({ name }, index) => ({+ scanId: String(index + 1).repeat(36),+ targetPath: `/demo/${name}`,+ mode: "standard",+ progress: { status: "complete" },+ findingCount: 7,+ startedAt: "2026-07-24T12:00:00Z",+ }));+ const render = (columns: number) =>+ stripVTControlCharacters(renderScanHistory({ scans }, "list", {columns,scanRoot: "/demo/results",}),);- expect(output).toContain("results");- expect(output).toContain("juice-shop");- expect(output).toContain("payment-service");- expect(output).toContain(scans[0]!.scanId);- expect(output).toContain(scans[1]!.scanId);- if (columns >= 96) expect(output).toContain("REPOSITORY");+ const narrow = render(96);+ const wide = render(97);+ expect(narrow).toContain("results");+ expect(narrow).not.toContain("REPOSITORY");+ expect(wide).toContain("REPOSITORY FINDINGS STATUS");+ for (const [index, { name, cell, compact }] of repositories.entries()) {+ const id = scans[index]!.scanId;+ expect(narrow).toContain(id);+ expect(narrow).toContain(compact ?? name);+ expect(wide).toContain(+ `${id} 2026-07-24 standard ${cell} 7 ✓ COMPLETE`,+ );}});