mirror of
https://github.com/openai/codex.git
synced 2026-05-05 22:01:37 +03:00
agentydragon(tasks): implement command snippet truncation in session approval labels
This commit is contained in:
@@ -6,6 +6,7 @@ import { ReviewDecision } from "../../utils/agent/review";
|
||||
import { Select } from "../vendor/ink-select/select";
|
||||
import TextInput from "../vendor/ink-text-input";
|
||||
import { Box, Text, useInput } from "ink";
|
||||
import { sessionScopedApprovalLabel } from "../../utils/string-utils";
|
||||
import React from "react";
|
||||
|
||||
// default deny‑reason:
|
||||
@@ -86,10 +87,17 @@ export function TerminalChatCommandReview({
|
||||
];
|
||||
|
||||
if (showAlwaysApprove) {
|
||||
opts.push({
|
||||
label: "Always allow this command for the remainder of the session (a)",
|
||||
value: ReviewDecision.ALWAYS,
|
||||
});
|
||||
let label: string;
|
||||
if (
|
||||
React.isValidElement(confirmationPrompt) &&
|
||||
typeof (confirmationPrompt as any).props?.commandForDisplay === "string"
|
||||
) {
|
||||
const cmd: string = (confirmationPrompt as any).props.commandForDisplay;
|
||||
label = sessionScopedApprovalLabel(cmd, 30);
|
||||
} else {
|
||||
label = "Always allow this command for the remainder of the session (a)";
|
||||
}
|
||||
opts.push({ label, value: ReviewDecision.ALWAYS });
|
||||
}
|
||||
|
||||
opts.push(
|
||||
@@ -117,7 +125,7 @@ export function TerminalChatCommandReview({
|
||||
);
|
||||
|
||||
return opts;
|
||||
}, [showAlwaysApprove]);
|
||||
}, [showAlwaysApprove, confirmationPrompt]);
|
||||
|
||||
useInput(
|
||||
(input, key) => {
|
||||
|
||||
27
codex-cli/src/utils/string-utils.ts
Normal file
27
codex-cli/src/utils/string-utils.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Truncate a string in the middle to ensure its length does not exceed maxLength.
|
||||
* If the input is longer than maxLength, replaces the middle with a single-character ellipsis '…'.
|
||||
*/
|
||||
export function truncateMiddle(text: string, maxLength: number): string {
|
||||
if (text.length <= maxLength) {
|
||||
return text;
|
||||
}
|
||||
const ellipsis = '…';
|
||||
const trimLength = maxLength - ellipsis.length;
|
||||
const startLength = Math.ceil(trimLength / 2);
|
||||
const endLength = Math.floor(trimLength / 2);
|
||||
return text.slice(0, startLength) + ellipsis + text.slice(text.length - endLength);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a session-scoped approval label for a given command.
|
||||
* Embeds a truncated snippet of the first line of commandForDisplay.
|
||||
*/
|
||||
export function sessionScopedApprovalLabel(
|
||||
commandForDisplay: string,
|
||||
maxLength: number,
|
||||
): string {
|
||||
const firstLine = commandForDisplay.split('\n')[0].trim();
|
||||
const snippet = truncateMiddle(firstLine, maxLength);
|
||||
return `Yes, always allow running \`${snippet}\` for this session (a)`;
|
||||
}
|
||||
Reference in New Issue
Block a user