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

fix(cli): delete whole characters when editing patch instructions (#1549)

1232857ff886c2
diff --git a/sdk/typescript/src/patch-tui.tsx b/sdk/typescript/src/patch-tui.tsx
index 1b6d9d0a2..0ab2c1f06 100644
--- a/sdk/typescript/src/patch-tui.tsx
+++ b/sdk/typescript/src/patch-tui.tsx
@@ -17,6 +17,9 @@ type PatchSeverity = keyof typeof SEVERITY_COLORS;
const SEVERITIES = Object.keys(SEVERITY_COLORS) as PatchSeverity[];
const HEADING = /^[A-Z][A-Z ]+$/u;
const SOURCE_LINE = /^([› ]\s*\d* │ )(.*)$/u;
+const GRAPHEME_SEGMENTER = new Intl.Segmenter(undefined, {
+ granularity: "grapheme",
+});
const DETAIL_ORDER = [
"summary",
@@ -429,7 +432,12 @@ export function PatchTui({
});
setEditing(null);
} else if (key.backspace || key.delete) {
- setDraft((previous) => previous.slice(0, -1));
+ setDraft((previous) =>
+ previous.slice(
+ 0,
+ Array.from(GRAPHEME_SEGMENTER.segment(previous)).at(-1)?.index ?? 0,
+ ),
+ );
} else if (!key.ctrl && !key.meta && input.length > 0) {
setDraft((previous) => previous + input);
}
diff --git a/sdk/typescript/tests-ts/patch-tui.test.ts b/sdk/typescript/tests-ts/patch-tui.test.ts
index 15a7055b3..4f883eab2 100644
--- a/sdk/typescript/tests-ts/patch-tui.test.ts
+++ b/sdk/typescript/tests-ts/patch-tui.test.ts
@@ -359,6 +359,34 @@ describe("interactive patch finding browser", () => {
expect(selected).toEqual([{ severity: "high", occurrenceIds: ["occ_1"] }]);
});
+ test("deletes complete characters from finding instructions", async () => {
+ const selected: (PatchSelection | null)[] = [];
+ const app = render(
+ createElement(PatchTui, {
+ repository: "/work/example",
+ findings: findings(["high"]),
+ color: false,
+ onComplete: (value) => selected.push(value),
+ }),
+ );
+
+ await press(app, "i");
+ await press(app, "Ask 👩‍💻");
+ await press(app, "\u007F");
+ await press(app, "the owner 👍🏽");
+ await press(app, "\u007F");
+ await press(app, "\r");
+ await press(app, "\r");
+
+ expect(selected).toEqual([
+ {
+ severity: "high",
+ occurrenceIds: ["occ_1"],
+ instructions: { occ_1: "Ask the owner" },
+ },
+ ]);
+ });
+
test("allows selecting none and canceling without patching", async () => {
for (const input of ["q", "\r"]) {
const selected: (PatchSelection | null)[] = [];