@causyne/agent 1.20.36 → 1.20.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/package.json +1 -1
- package/src/tools/sysRun.js +22 -6
- package/src/tools/sysRun.ts +23 -6
- package/src/tui/chatRenderer.js +5 -4
- package/src/tui/homeView.js +0 -1
- package/src/tui/homeView.ts +0 -1
- package/src/tui/markdownMath.js +250 -0
- package/src/tui/markdownMath.ts +263 -0
- package/src/tui/messageActionPlacement.js +79 -8
- package/src/tui/messageActionPlacement.ts +102 -9
- package/src/tui/messageInteraction.js +43 -9
- package/src/tui/messageInteraction.ts +51 -17
- package/src/tui/overlay.js +191 -192
- package/src/tui/overlay.ts +320 -0
- package/src/tui/prompt.js +4 -1
- package/src/tui/stageSurface.js +4 -1
- package/src/tui/text.js +204 -208
- package/src/tui/text.ts +360 -0
- package/src/tui/toolOutputNormalizer.js +3 -1
- package/src/tui/toolOutputNormalizer.ts +3 -1
- package/src/tui/turnRail.js +11 -1
- package/src/tui/turnRail.ts +11 -1
- package/src/tui/text.d.ts +0 -7
package/src/tui/text.js
CHANGED
|
@@ -9,24 +9,21 @@
|
|
|
9
9
|
// * Tool output was printed raw — see sanitize() below, which is a security
|
|
10
10
|
// fix, not a cosmetic one.
|
|
11
11
|
//
|
|
12
|
-
// Pure
|
|
13
|
-
|
|
14
|
-
import os from 'os';
|
|
15
|
-
|
|
12
|
+
// Pure TypeScript. No dependency, no shell.
|
|
13
|
+
import os from 'node:os';
|
|
16
14
|
// CSI sequences (colour, cursor movement, erase) and OSC sequences (window
|
|
17
15
|
// title, hyperlinks — terminated by BEL or ST).
|
|
18
16
|
const CSI_PATTERN = /\x1b\[[0-?]*[ -/]*[@-~]/g;
|
|
19
17
|
const OSC_PATTERN = /\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)/g;
|
|
20
18
|
const OTHER_ESCAPE_PATTERN = /\x1b[@-Z\\-_]/g;
|
|
21
|
-
|
|
19
|
+
const OSC8_SEQUENCE = /^\x1b\]8;[^;]*;([^\x07\x1b]*)(\x07|\x1b\\)/;
|
|
22
20
|
/** Everything that is an escape sequence rather than visible text. */
|
|
23
21
|
export function stripAnsi(text) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
return String(text == null ? '' : text)
|
|
23
|
+
.replace(OSC_PATTERN, '')
|
|
24
|
+
.replace(CSI_PATTERN, '')
|
|
25
|
+
.replace(OTHER_ESCAPE_PATTERN, '');
|
|
28
26
|
}
|
|
29
|
-
|
|
30
27
|
/**
|
|
31
28
|
* Does this code point occupy two terminal columns?
|
|
32
29
|
*
|
|
@@ -34,19 +31,16 @@ export function stripAnsi(text) {
|
|
|
34
31
|
* makes a table of Indonesian and Chinese filenames drift apart.
|
|
35
32
|
*/
|
|
36
33
|
function isWideCodePoint(code) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
(code >= 0x1f900 && code <= 0x1f9ff)
|
|
47
|
-
);
|
|
34
|
+
return ((code >= 0x1100 && code <= 0x115f) || // Hangul Jamo
|
|
35
|
+
(code >= 0x2e80 && code <= 0xa4cf) || // CJK radicals … Yi
|
|
36
|
+
(code >= 0xac00 && code <= 0xd7a3) || // Hangul syllables
|
|
37
|
+
(code >= 0xf900 && code <= 0xfaff) || // CJK compatibility ideographs
|
|
38
|
+
(code >= 0xfe30 && code <= 0xfe6f) || // CJK compatibility forms
|
|
39
|
+
(code >= 0xff00 && code <= 0xff60) || // Fullwidth forms
|
|
40
|
+
(code >= 0xffe0 && code <= 0xffe6) ||
|
|
41
|
+
(code >= 0x1f300 && code <= 0x1f64f) || // emoji
|
|
42
|
+
(code >= 0x1f900 && code <= 0x1f9ff));
|
|
48
43
|
}
|
|
49
|
-
|
|
50
44
|
/**
|
|
51
45
|
* The East Asian AMBIGUOUS class (UAX #11).
|
|
52
46
|
*
|
|
@@ -62,21 +56,19 @@ function isWideCodePoint(code) {
|
|
|
62
56
|
* that must not be wrong get the wide reading via the environment.
|
|
63
57
|
*/
|
|
64
58
|
function isAmbiguousCodePoint(code) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
);
|
|
59
|
+
return ((code >= 0x00a1 && code <= 0x00ff && code !== 0x00ad) ||
|
|
60
|
+
(code >= 0x2010 && code <= 0x2027) ||
|
|
61
|
+
code === 0x2022 || code === 0x2026 ||
|
|
62
|
+
(code >= 0x2190 && code <= 0x21ff) || // arrows
|
|
63
|
+
(code >= 0x2200 && code <= 0x22ff) || // mathematical operators
|
|
64
|
+
(code >= 0x2460 && code <= 0x24ff) || // enclosed alphanumerics
|
|
65
|
+
(code >= 0x2500 && code <= 0x257f) || // box drawing
|
|
66
|
+
(code >= 0x2580 && code <= 0x259f) || // block elements
|
|
67
|
+
(code >= 0x25a0 && code <= 0x25ff) || // geometric shapes
|
|
68
|
+
(code >= 0x2600 && code <= 0x26ff) || // miscellaneous symbols
|
|
69
|
+
(code >= 0x2700 && code <= 0x27bf) // dingbats (✓ ✕)
|
|
70
|
+
);
|
|
78
71
|
}
|
|
79
|
-
|
|
80
72
|
/**
|
|
81
73
|
* Should ambiguous-width code points be measured as two columns?
|
|
82
74
|
*
|
|
@@ -85,135 +77,141 @@ function isAmbiguousCodePoint(code) {
|
|
|
85
77
|
* renders these glyphs wide.
|
|
86
78
|
*/
|
|
87
79
|
function detectAmbiguousWide() {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
80
|
+
const explicit = process.env.CAUSYNE_AMBIGUOUS_WIDE;
|
|
81
|
+
if (explicit === '1')
|
|
82
|
+
return true;
|
|
83
|
+
if (explicit === '0')
|
|
84
|
+
return false;
|
|
85
|
+
const locale = String(process.env.LC_ALL || process.env.LC_CTYPE || process.env.LANG || '');
|
|
86
|
+
return /^(ja|ko|zh)([_.-]|$)/i.test(locale);
|
|
93
87
|
}
|
|
94
|
-
|
|
95
88
|
export const AMBIGUOUS_IS_WIDE = detectAmbiguousWide();
|
|
96
|
-
|
|
97
89
|
/** Columns one code point occupies, under the active ambiguous-width policy. */
|
|
98
90
|
function columnsFor(code) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
91
|
+
if (isWideCodePoint(code))
|
|
92
|
+
return 2;
|
|
93
|
+
if (AMBIGUOUS_IS_WIDE && isAmbiguousCodePoint(code))
|
|
94
|
+
return 2;
|
|
95
|
+
return 1;
|
|
102
96
|
}
|
|
103
|
-
|
|
104
97
|
/** Columns this string will occupy once printed. Escapes count for nothing. */
|
|
105
98
|
export function visibleWidth(text) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
99
|
+
const plain = stripAnsi(text);
|
|
100
|
+
let width = 0;
|
|
101
|
+
for (const character of plain) {
|
|
102
|
+
const code = character.codePointAt(0);
|
|
103
|
+
if (code === undefined)
|
|
104
|
+
continue;
|
|
105
|
+
if (code === 0x200d)
|
|
106
|
+
continue; // zero-width joiner
|
|
107
|
+
if (code >= 0xfe00 && code <= 0xfe0f)
|
|
108
|
+
continue; // variation selectors
|
|
109
|
+
width += columnsFor(code);
|
|
110
|
+
}
|
|
111
|
+
return width;
|
|
115
112
|
}
|
|
116
|
-
|
|
117
113
|
const RESET = '\x1b[0m';
|
|
118
|
-
|
|
119
114
|
/**
|
|
120
115
|
* Cut to `width` columns without ever splitting an escape sequence.
|
|
121
116
|
*
|
|
122
117
|
* Walks the string escape-aware rather than slicing by index, and closes any
|
|
123
|
-
* style that was still open at the cut so
|
|
124
|
-
*
|
|
118
|
+
* style or OSC 8 hyperlink that was still open at the cut so neither colour nor
|
|
119
|
+
* link underline bleeds into the rest of the row or subsequent rows.
|
|
125
120
|
*/
|
|
126
121
|
export function truncate(text, width, ellipsis = '…') {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
122
|
+
const source = String(text == null ? '' : text);
|
|
123
|
+
if (width <= 0)
|
|
124
|
+
return '';
|
|
125
|
+
if (visibleWidth(source) <= width)
|
|
126
|
+
return source;
|
|
127
|
+
const ellipsisWidth = visibleWidth(ellipsis);
|
|
128
|
+
const budget = Math.max(0, width - ellipsisWidth);
|
|
129
|
+
let out = '';
|
|
130
|
+
let used = 0;
|
|
131
|
+
let sawEscape = false;
|
|
132
|
+
let openOsc8Term = '';
|
|
133
|
+
let index = 0;
|
|
134
|
+
while (index < source.length) {
|
|
135
|
+
if (source[index] === '\x1b') {
|
|
136
|
+
// Copy the whole sequence verbatim; it costs no columns.
|
|
137
|
+
const rest = source.slice(index);
|
|
138
|
+
const match = rest.match(/^\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)/)
|
|
139
|
+
|| rest.match(/^\x1b\[[0-?]*[ -/]*[@-~]/)
|
|
140
|
+
|| rest.match(/^\x1b[@-Z\\-_]/);
|
|
141
|
+
if (match) {
|
|
142
|
+
const osc8 = OSC8_SEQUENCE.exec(match[0]);
|
|
143
|
+
if (osc8) {
|
|
144
|
+
const uri = osc8[1] ?? '';
|
|
145
|
+
const term = osc8[2] ?? '\x1b\\';
|
|
146
|
+
openOsc8Term = uri.length > 0 ? term : '';
|
|
147
|
+
}
|
|
148
|
+
out += match[0];
|
|
149
|
+
sawEscape = true;
|
|
150
|
+
index += match[0].length;
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
const code = source.codePointAt(index);
|
|
155
|
+
if (code === undefined)
|
|
156
|
+
break;
|
|
157
|
+
const character = String.fromCodePoint(code);
|
|
158
|
+
const charWidth = columnsFor(code);
|
|
159
|
+
if (used + charWidth > budget)
|
|
160
|
+
break;
|
|
161
|
+
out += character;
|
|
162
|
+
used += charWidth;
|
|
163
|
+
index += character.length;
|
|
152
164
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
const charWidth = columnsFor(source.codePointAt(index));
|
|
156
|
-
if (used + charWidth > budget) break;
|
|
157
|
-
|
|
158
|
-
out += character;
|
|
159
|
-
used += charWidth;
|
|
160
|
-
index += character.length;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
return out + (sawEscape ? RESET : '') + ellipsis;
|
|
165
|
+
const osc8Reset = openOsc8Term ? `\x1b]8;;${openOsc8Term}` : '';
|
|
166
|
+
return out + osc8Reset + (sawEscape ? RESET : '') + ellipsis;
|
|
164
167
|
}
|
|
165
|
-
|
|
166
168
|
/** Pad to an exact column count, measuring visible width rather than bytes. */
|
|
167
169
|
export function padEnd(text, width) {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
+
const gap = width - visibleWidth(text);
|
|
171
|
+
return gap > 0 ? String(text) + ' '.repeat(gap) : String(text);
|
|
170
172
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
lines.push(paragraph);
|
|
180
|
-
continue;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
let current = '';
|
|
184
|
-
for (const word of paragraph.split(' ')) {
|
|
185
|
-
const candidate = current ? `${current} ${word}` : word;
|
|
186
|
-
|
|
187
|
-
if (visibleWidth(candidate) <= width) {
|
|
188
|
-
current = candidate;
|
|
189
|
-
continue;
|
|
190
|
-
}
|
|
191
|
-
if (current) {
|
|
192
|
-
lines.push(current);
|
|
193
|
-
current = '';
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
let remainder = word;
|
|
197
|
-
while (visibleWidth(remainder) > width) {
|
|
198
|
-
lines.push(truncate(remainder, width, ''));
|
|
199
|
-
// truncate() gives us the head; drop the same number of characters.
|
|
200
|
-
let consumed = 0;
|
|
201
|
-
let cut = 0;
|
|
202
|
-
while (cut < remainder.length && consumed < width) {
|
|
203
|
-
const code = remainder.codePointAt(cut);
|
|
204
|
-
consumed += columnsFor(code);
|
|
205
|
-
cut += String.fromCodePoint(code).length;
|
|
173
|
+
export function wrap(text, width, _options) {
|
|
174
|
+
if (width <= 0)
|
|
175
|
+
return [String(text)];
|
|
176
|
+
const lines = [];
|
|
177
|
+
for (const paragraph of String(text == null ? '' : text).split('\n')) {
|
|
178
|
+
if (visibleWidth(paragraph) <= width) {
|
|
179
|
+
lines.push(paragraph);
|
|
180
|
+
continue;
|
|
206
181
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
182
|
+
let current = '';
|
|
183
|
+
for (const word of paragraph.split(' ')) {
|
|
184
|
+
const candidate = current ? `${current} ${word}` : word;
|
|
185
|
+
if (visibleWidth(candidate) <= width) {
|
|
186
|
+
current = candidate;
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
if (current) {
|
|
190
|
+
lines.push(current);
|
|
191
|
+
current = '';
|
|
192
|
+
}
|
|
193
|
+
let remainder = word;
|
|
194
|
+
while (visibleWidth(remainder) > width) {
|
|
195
|
+
lines.push(truncate(remainder, width, ''));
|
|
196
|
+
// truncate() gives us the head; drop the same number of characters.
|
|
197
|
+
let consumed = 0;
|
|
198
|
+
let cut = 0;
|
|
199
|
+
while (cut < remainder.length && consumed < width) {
|
|
200
|
+
const code = remainder.codePointAt(cut);
|
|
201
|
+
if (code === undefined)
|
|
202
|
+
break;
|
|
203
|
+
consumed += columnsFor(code);
|
|
204
|
+
cut += String.fromCodePoint(code).length;
|
|
205
|
+
}
|
|
206
|
+
remainder = remainder.slice(cut);
|
|
207
|
+
}
|
|
208
|
+
current = remainder;
|
|
209
|
+
}
|
|
210
|
+
if (current)
|
|
211
|
+
lines.push(current);
|
|
210
212
|
}
|
|
211
|
-
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
return lines;
|
|
213
|
+
return lines;
|
|
215
214
|
}
|
|
216
|
-
|
|
217
215
|
/**
|
|
218
216
|
* Word-wrap a block of text while preserving each line's own indentation.
|
|
219
217
|
*
|
|
@@ -226,23 +224,25 @@ export function wrap(text, width) {
|
|
|
226
224
|
* terminal broke it at the right edge, mid-word, at column 0.
|
|
227
225
|
*/
|
|
228
226
|
export function wrapBlock(text, width, { hang = 2 } = {}) {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
227
|
+
const rows = [];
|
|
228
|
+
for (const line of String(text == null ? '' : text).split('\n')) {
|
|
229
|
+
const indent = (line.match(/^[ \t]*/) || [''])[0];
|
|
230
|
+
const body = line.slice(indent.length);
|
|
231
|
+
if (!body) {
|
|
232
|
+
rows.push('');
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
const continuation = indent + ' '.repeat(hang);
|
|
236
|
+
// Wrap at the NARROWER of the two budgets so neither the first row nor a
|
|
237
|
+
// continuation row can exceed `width`.
|
|
238
|
+
const budget = Math.max(8, width - visibleWidth(continuation));
|
|
239
|
+
const parts = wrap(body, budget);
|
|
240
|
+
rows.push(indent + (parts[0] ?? ''));
|
|
241
|
+
for (const part of parts.slice(1))
|
|
242
|
+
rows.push(continuation + part);
|
|
243
|
+
}
|
|
244
|
+
return rows;
|
|
244
245
|
}
|
|
245
|
-
|
|
246
246
|
/**
|
|
247
247
|
* Make untrusted text safe to print.
|
|
248
248
|
*
|
|
@@ -257,7 +257,6 @@ export function wrapBlock(text, width, { hang = 2 } = {}) {
|
|
|
257
257
|
*/
|
|
258
258
|
/** Columns between terminal tab stops. Eight is the POSIX default everywhere. */
|
|
259
259
|
const TAB_WIDTH = 8;
|
|
260
|
-
|
|
261
260
|
/**
|
|
262
261
|
* Replace tabs with the spaces the terminal would have moved over.
|
|
263
262
|
*
|
|
@@ -283,66 +282,63 @@ const TAB_WIDTH = 8;
|
|
|
283
282
|
* columnar output actually lining up.
|
|
284
283
|
*/
|
|
285
284
|
export function expandTabs(text, tabWidth = TAB_WIDTH) {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
285
|
+
const source = String(text == null ? '' : text);
|
|
286
|
+
if (!source.includes('\t'))
|
|
287
|
+
return source;
|
|
288
|
+
let out = '';
|
|
289
|
+
let column = 0;
|
|
290
|
+
for (const char of source) {
|
|
291
|
+
if (char === '\t') {
|
|
292
|
+
const advance = tabWidth - (column % tabWidth);
|
|
293
|
+
out += ' '.repeat(advance);
|
|
294
|
+
column += advance;
|
|
295
|
+
}
|
|
296
|
+
else if (char === '\n') {
|
|
297
|
+
out += char;
|
|
298
|
+
column = 0;
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
out += char;
|
|
302
|
+
column += 1;
|
|
303
|
+
}
|
|
302
304
|
}
|
|
303
|
-
|
|
304
|
-
return out;
|
|
305
|
+
return out;
|
|
305
306
|
}
|
|
306
|
-
|
|
307
307
|
export function sanitize(text) {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
308
|
+
// Tabs are expanded rather than stripped: removing them would collapse
|
|
309
|
+
// columnar output into an unreadable run, and leaving them corrupts the
|
|
310
|
+
// frame. Expansion is the only option that preserves what the user meant to
|
|
311
|
+
// see. Everything else in this class is genuinely unwanted and is removed.
|
|
312
|
+
const normalized = String(text == null ? '' : text)
|
|
313
|
+
.replace(/\r\n/g, '\n')
|
|
314
|
+
.replace(/\r/g, '\n');
|
|
315
|
+
return expandTabs(stripAnsi(normalized))
|
|
316
|
+
// eslint-disable-next-line no-control-regex
|
|
317
|
+
.replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g, '');
|
|
318
318
|
}
|
|
319
|
-
|
|
320
319
|
/** `/Users/example/Projects/x` → `~/Projects/x`. Long paths dominate a tool row. */
|
|
321
320
|
export function shortenHome(value) {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
321
|
+
const home = os.homedir();
|
|
322
|
+
const text = String(value == null ? '' : value);
|
|
323
|
+
if (home && text.startsWith(home))
|
|
324
|
+
return '~' + text.slice(home.length);
|
|
325
|
+
return text;
|
|
326
326
|
}
|
|
327
|
-
|
|
328
|
-
|
|
329
327
|
const SECRET_PATTERNS = [
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
328
|
+
[/\b(sk|pk|rk)-[A-Za-z0-9_-]{12,}/g, (m) => `${m.slice(0, 5)}…${m.slice(-4)}`],
|
|
329
|
+
[/\b(gh[pousr]|xox[baprs])_[A-Za-z0-9]{12,}/g, (m) => `${m.slice(0, 7)}…`],
|
|
330
|
+
[/\b(Bearer|Basic)\s+[A-Za-z0-9._~+/=-]{12,}/gi, (m) => `${m.split(/\s+/)[0]} …`],
|
|
331
|
+
[/\b(api[_-]?key|token|secret|password|passwd)\s*[=:]\s*["']?[^\s"']{6,}/gi,
|
|
332
|
+
(m) => `${m.split(/[=:]/)[0]}=…`]
|
|
335
333
|
];
|
|
336
|
-
|
|
337
334
|
export function redactSecrets(text) {
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
335
|
+
let out = String(text == null ? '' : text);
|
|
336
|
+
for (const [pattern, replace] of SECRET_PATTERNS) {
|
|
337
|
+
out = out.replace(pattern, replace);
|
|
338
|
+
}
|
|
339
|
+
return out;
|
|
343
340
|
}
|
|
344
|
-
|
|
345
341
|
/** sanitize + redact — the pipeline every untrusted string goes through. */
|
|
346
342
|
export function safeDisplay(text) {
|
|
347
|
-
|
|
343
|
+
return redactSecrets(sanitize(text));
|
|
348
344
|
}
|