@@ -38,11 +38,21 @@ function escapeInvisibles(text: string, options?: { preserveLineBreaks?: boolean
3838 ) ;
3939}
4040
41- function truncateForDisplay ( text : string ) : string {
41+ export type SanitizedExecApprovalDisplayText = {
42+ text : string ;
43+ truncated : boolean ;
44+ oversized : boolean ;
45+ } ;
46+
47+ function truncateForDisplay ( text : string ) : SanitizedExecApprovalDisplayText {
4248 if ( text . length <= EXEC_APPROVAL_MAX_OUTPUT ) {
43- return text ;
49+ return { text, truncated : false , oversized : false } ;
4450 }
45- return text . slice ( 0 , EXEC_APPROVAL_MAX_OUTPUT ) + EXEC_APPROVAL_TRUNCATION_MARKER ;
51+ return {
52+ text : text . slice ( 0 , EXEC_APPROVAL_MAX_OUTPUT ) + EXEC_APPROVAL_TRUNCATION_MARKER ,
53+ truncated : true ,
54+ oversized : false ,
55+ } ;
4656}
4757
4858// Build a boolean bitmap of positions in `text` that ANY redaction pattern would match.
@@ -92,11 +102,15 @@ function buildStrippedView(original: string): { stripped: string; strippedToOrig
92102function sanitizeExecApprovalDisplayTextInternal (
93103 commandText : string ,
94104 options ?: { preserveLineBreaks ?: boolean ; oversizedMarker ?: string } ,
95- ) : string {
105+ ) : SanitizedExecApprovalDisplayText {
96106 if ( commandText . length > EXEC_APPROVAL_MAX_INPUT ) {
97107 // Refuse to display inputs above the hard cap; anything larger must be approved through
98108 // another channel. Running redaction on a multi-megabyte payload would be a DoS vector.
99- return options ?. oversizedMarker ?? EXEC_APPROVAL_OVERSIZED_MARKER ;
109+ return {
110+ text : options ?. oversizedMarker ?? EXEC_APPROVAL_OVERSIZED_MARKER ,
111+ truncated : false ,
112+ oversized : true ,
113+ } ;
100114 }
101115 const rawRedacted = redactSensitiveText ( commandText , { mode : "tools" } ) ;
102116 const { stripped, strippedToOrig } = buildStrippedView ( commandText ) ;
@@ -167,14 +181,20 @@ function sanitizeExecApprovalDisplayTextInternal(
167181}
168182
169183export function sanitizeExecApprovalDisplayText ( commandText : string ) : string {
184+ return sanitizeExecApprovalDisplayTextInternal ( commandText ) . text ;
185+ }
186+
187+ export function sanitizeExecApprovalDisplayTextWithStatus (
188+ commandText : string ,
189+ ) : SanitizedExecApprovalDisplayText {
170190 return sanitizeExecApprovalDisplayTextInternal ( commandText ) ;
171191}
172192
173193export function sanitizeExecApprovalWarningText ( warningText : string ) : string {
174194 return sanitizeExecApprovalDisplayTextInternal ( normalizeDisplayLineBreaks ( warningText ) , {
175195 preserveLineBreaks : true ,
176196 oversizedMarker : EXEC_APPROVAL_WARNING_OVERSIZED_MARKER ,
177- } ) ;
197+ } ) . text ;
178198}
179199
180200function normalizePreview ( commandText : string , commandPreview ?: string | null ) : string | null {
0 commit comments