@sayknow-cli/coding-agent 0.7.19 → 0.7.21
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/CHANGELOG.md +1 -1
- package/dist/types/modes/controllers/ssh-command-controller.d.ts +5 -0
- package/dist/types/sdk/host/control/operations.d.ts +2 -0
- package/dist/types/sdk/host/external-permissions.d.ts +47 -0
- package/dist/types/session/client-bridge.d.ts +1 -0
- package/dist/types/tui/file-list.d.ts +0 -3
- package/dist/types/tui/status-line.d.ts +9 -0
- package/package.json +9 -8
- package/src/modes/acp/acp-event-mapper.ts +143 -5
- package/src/modes/components/ttsr-notification.ts +7 -4
- package/src/modes/controllers/ssh-command-controller.ts +20 -9
- package/src/modes/controllers/todo-command-controller.ts +13 -7
- package/src/modes/utils/tools-markdown.ts +12 -5
- package/src/prompts/system/subagent-system-prompt.md +1 -0
- package/src/prompts/system/system-prompt.md +6 -0
- package/src/prompts/tools/ask.md +5 -4
- package/src/sdk/host/control/operations.ts +2 -0
- package/src/sdk/host/external-permissions.ts +330 -0
- package/src/session/agent-session.ts +7 -1
- package/src/session/client-bridge.ts +1 -1
- package/src/skc-runtime/state-renderer.ts +41 -25
- package/src/skill-state/workflow-mutation-guard.ts +18 -8
- package/src/tools/gh-renderer.ts +44 -25
- package/src/tools/ssh.ts +2 -1
- package/src/tui/code-cell.ts +16 -2
- package/src/tui/file-list.ts +14 -3
- package/src/tui/status-line.ts +145 -4
package/src/tools/gh-renderer.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type Component, padding, Text, truncateToWidth, visibleWidth } from "@sayknow-cli/tui";
|
|
2
|
+
import { sanitizeDisplayLine, sanitizeText } from "@sayknow-cli/utils";
|
|
2
3
|
import type { RenderResultOptions } from "../extensibility/custom-tools/types";
|
|
3
4
|
import type { Theme, ThemeColor } from "../modes/theme/theme";
|
|
4
5
|
import { renderStatusLine } from "../tui";
|
|
@@ -37,6 +38,16 @@ const RUNNING_STATUSES = new Set(["in_progress"]);
|
|
|
37
38
|
const PENDING_STATUSES = new Set(["queued", "requested", "waiting", "pending"]);
|
|
38
39
|
const FALLBACK_WIDTH = 80;
|
|
39
40
|
|
|
41
|
+
// Strip terminal controls before tab expansion or width clipping. Theme color
|
|
42
|
+
// codes are applied only after this, so they are not removed with the payload.
|
|
43
|
+
function displayLine(value: string): string {
|
|
44
|
+
return replaceTabs(sanitizeDisplayLine(value));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function displayBlock(value: string): string {
|
|
48
|
+
return replaceTabs(sanitizeText(value));
|
|
49
|
+
}
|
|
50
|
+
|
|
40
51
|
const OP_TITLES: Record<string, string> = {
|
|
41
52
|
repo_view: "GitHub Repo",
|
|
42
53
|
pr_checkout: "GitHub PR Checkout",
|
|
@@ -61,7 +72,7 @@ function extractIssueId(value: string | undefined): string | undefined {
|
|
|
61
72
|
if (/^\d+$/.test(trimmed)) return `#${trimmed}`;
|
|
62
73
|
const match = trimmed.match(/\/(?:issues|pull)\/(\d+)/);
|
|
63
74
|
if (match) return `#${match[1]}`;
|
|
64
|
-
return truncateVisualWidth(trimmed, TRUNCATE_LENGTHS.SHORT);
|
|
75
|
+
return truncateVisualWidth(displayLine(trimmed), TRUNCATE_LENGTHS.SHORT);
|
|
65
76
|
}
|
|
66
77
|
|
|
67
78
|
function formatPrIdentifier(pr: string | string[] | undefined): string | undefined {
|
|
@@ -85,31 +96,31 @@ function buildOpMeta(args: GithubToolRenderArgs): string[] {
|
|
|
85
96
|
case "pr_push": {
|
|
86
97
|
const id = formatPrIdentifier(args.pr);
|
|
87
98
|
if (id) meta.push(id);
|
|
88
|
-
else if (args.branch) meta.push(args.branch);
|
|
89
|
-
if (args.repo) meta.push(args.repo);
|
|
99
|
+
else if (args.branch) meta.push(displayLine(args.branch));
|
|
100
|
+
if (args.repo) meta.push(displayLine(args.repo));
|
|
90
101
|
break;
|
|
91
102
|
}
|
|
92
103
|
case "search_issues":
|
|
93
104
|
case "search_prs":
|
|
94
105
|
case "search_code":
|
|
95
106
|
case "search_commits": {
|
|
96
|
-
if (args.query) meta.push(truncateVisualWidth(args.query, TRUNCATE_LENGTHS.CONTENT));
|
|
97
|
-
if (args.repo) meta.push(args.repo);
|
|
107
|
+
if (args.query) meta.push(truncateVisualWidth(displayLine(args.query), TRUNCATE_LENGTHS.CONTENT));
|
|
108
|
+
if (args.repo) meta.push(displayLine(args.repo));
|
|
98
109
|
break;
|
|
99
110
|
}
|
|
100
111
|
case "search_repos": {
|
|
101
|
-
if (args.query) meta.push(truncateVisualWidth(args.query, TRUNCATE_LENGTHS.CONTENT));
|
|
112
|
+
if (args.query) meta.push(truncateVisualWidth(displayLine(args.query), TRUNCATE_LENGTHS.CONTENT));
|
|
102
113
|
break;
|
|
103
114
|
}
|
|
104
115
|
case "repo_view": {
|
|
105
|
-
if (args.repo) meta.push(args.repo);
|
|
106
|
-
if (args.branch) meta.push(args.branch);
|
|
116
|
+
if (args.repo) meta.push(displayLine(args.repo));
|
|
117
|
+
if (args.branch) meta.push(displayLine(args.branch));
|
|
107
118
|
break;
|
|
108
119
|
}
|
|
109
120
|
case "run_watch":
|
|
110
121
|
break;
|
|
111
122
|
default: {
|
|
112
|
-
if (args.repo) meta.push(args.repo);
|
|
123
|
+
if (args.repo) meta.push(displayLine(args.repo));
|
|
113
124
|
break;
|
|
114
125
|
}
|
|
115
126
|
}
|
|
@@ -117,32 +128,34 @@ function buildOpMeta(args: GithubToolRenderArgs): string[] {
|
|
|
117
128
|
}
|
|
118
129
|
|
|
119
130
|
function getWatchHeader(watch: GhRunWatchViewDetails): string {
|
|
131
|
+
const repo = displayLine(watch.repo);
|
|
120
132
|
if (watch.mode === "run" && watch.run) {
|
|
121
133
|
if (watch.state === "watching") {
|
|
122
|
-
return `watching run #${watch.run.id} on ${
|
|
134
|
+
return `watching run #${watch.run.id} on ${repo}`;
|
|
123
135
|
}
|
|
124
136
|
|
|
125
|
-
return `run #${watch.run.id} on ${
|
|
137
|
+
return `run #${watch.run.id} on ${repo}`;
|
|
126
138
|
}
|
|
127
139
|
|
|
128
|
-
const shortSha = formatShortSha(watch.headSha) ?? "this commit";
|
|
140
|
+
const shortSha = formatShortSha(displayLine(watch.headSha ?? "")) ?? "this commit";
|
|
129
141
|
if (watch.state === "watching") {
|
|
130
|
-
return `watching ${shortSha} on ${
|
|
142
|
+
return `watching ${shortSha} on ${repo}`;
|
|
131
143
|
}
|
|
132
144
|
|
|
133
|
-
return `workflow runs for ${shortSha} on ${
|
|
145
|
+
return `workflow runs for ${shortSha} on ${repo}`;
|
|
134
146
|
}
|
|
135
147
|
|
|
136
148
|
function getRunLabel(run: GhRunWatchRunDetails): string {
|
|
137
|
-
return
|
|
149
|
+
return displayLine(run.workflowName ?? run.displayTitle ?? "GitHub Actions");
|
|
138
150
|
}
|
|
139
151
|
|
|
140
152
|
function getRunMeta(run: GhRunWatchRunDetails): string[] {
|
|
141
153
|
const parts: string[] = [];
|
|
142
154
|
if (run.branch) {
|
|
143
|
-
parts.push(
|
|
155
|
+
parts.push(displayLine(run.branch));
|
|
144
156
|
} else if (run.headSha) {
|
|
145
|
-
|
|
157
|
+
const shortSha = formatShortSha(displayLine(run.headSha));
|
|
158
|
+
if (shortSha) parts.push(shortSha);
|
|
146
159
|
}
|
|
147
160
|
parts.push(`#${run.id}`);
|
|
148
161
|
return parts;
|
|
@@ -207,7 +220,7 @@ function renderJobLine(job: GhRunWatchJobDetails, width: number, theme: Theme):
|
|
|
207
220
|
const styledDuration = durationLabel ? theme.fg(visual.textColor, durationLabel) : undefined;
|
|
208
221
|
const reservedWidth = visibleWidth(prefix) + (styledDuration ? 1 + visibleWidth(styledDuration) : 0);
|
|
209
222
|
const nameWidth = Math.max(8, width - reservedWidth);
|
|
210
|
-
const jobName = theme.fg(visual.textColor, truncateVisualWidth(
|
|
223
|
+
const jobName = theme.fg(visual.textColor, truncateVisualWidth(displayLine(job.name), nameWidth));
|
|
211
224
|
let line = `${prefix}${jobName}`;
|
|
212
225
|
if (styledDuration) {
|
|
213
226
|
line += padding(Math.max(1, width - visibleWidth(line) - visibleWidth(styledDuration)));
|
|
@@ -241,9 +254,10 @@ function renderFailedLogs(
|
|
|
241
254
|
|
|
242
255
|
const lines = ["", theme.fg("error", "failed logs")];
|
|
243
256
|
for (const entry of failedLogs) {
|
|
244
|
-
const
|
|
257
|
+
const workflowName = entry.workflowName ? displayLine(entry.workflowName) : "";
|
|
258
|
+
const context = workflowName ? `${workflowName} #${entry.runId}` : `run #${entry.runId}`;
|
|
245
259
|
lines.push(
|
|
246
|
-
theme.fg("error", `${theme.status.error} ${
|
|
260
|
+
theme.fg("error", `${theme.status.error} ${displayLine(entry.jobName)} ${theme.fg("muted", context)}`),
|
|
247
261
|
);
|
|
248
262
|
|
|
249
263
|
if (!entry.available || !entry.tail) {
|
|
@@ -251,8 +265,9 @@ function renderFailedLogs(
|
|
|
251
265
|
continue;
|
|
252
266
|
}
|
|
253
267
|
|
|
254
|
-
const tailLines =
|
|
268
|
+
const tailLines = displayBlock(entry.tail)
|
|
255
269
|
.split("\n")
|
|
270
|
+
.map(line => displayLine(line))
|
|
256
271
|
.filter(line => line.length > 0);
|
|
257
272
|
const previewLimit = expanded ? tailLines.length : Math.min(PREVIEW_LIMITS.OUTPUT_COLLAPSED, tailLines.length);
|
|
258
273
|
for (const line of tailLines.slice(-previewLimit)) {
|
|
@@ -277,7 +292,7 @@ function buildWatchLines(
|
|
|
277
292
|
const lines = [theme.fg("muted", getWatchHeader(watch))];
|
|
278
293
|
|
|
279
294
|
if (watch.note) {
|
|
280
|
-
lines.push(theme.fg("dim",
|
|
295
|
+
lines.push(theme.fg("dim", displayLine(watch.note)));
|
|
281
296
|
}
|
|
282
297
|
|
|
283
298
|
if (watch.mode === "run" && watch.run) {
|
|
@@ -334,7 +349,9 @@ function renderFallbackComponent(
|
|
|
334
349
|
return new Text(`${header}\n${theme.fg("dim", empty)}`, 0, 0);
|
|
335
350
|
}
|
|
336
351
|
|
|
337
|
-
const allLines =
|
|
352
|
+
const allLines = displayBlock(text)
|
|
353
|
+
.split("\n")
|
|
354
|
+
.map(line => displayLine(line));
|
|
338
355
|
|
|
339
356
|
return {
|
|
340
357
|
render(width: number): string[] {
|
|
@@ -366,8 +383,10 @@ function renderWatchCall(args: GithubToolRenderArgs, options: RenderResultOption
|
|
|
366
383
|
? formatStatusIcon("running", theme, options.spinnerFrame)
|
|
367
384
|
: formatStatusIcon("pending", theme);
|
|
368
385
|
|
|
369
|
-
const
|
|
370
|
-
const
|
|
386
|
+
const runRaw = typeof args.run === "string" ? args.run.trim() : "";
|
|
387
|
+
const branchRaw = typeof args.branch === "string" ? args.branch.trim() : "";
|
|
388
|
+
const runId = displayLine(runRaw).trim();
|
|
389
|
+
const branch = displayLine(branchRaw).trim();
|
|
371
390
|
|
|
372
391
|
const titleText = theme.fg("accent", "GitHub Run Watch");
|
|
373
392
|
let metaText: string;
|
package/src/tools/ssh.ts
CHANGED
|
@@ -79,7 +79,8 @@ async function formatDescription(hosts: SSHHost[]): Promise<string> {
|
|
|
79
79
|
return baseDescription;
|
|
80
80
|
}
|
|
81
81
|
const hostList = (await Promise.all(hosts.map(formatHostEntry))).join("\n");
|
|
82
|
-
|
|
82
|
+
// Encode each entry first. Frame the finished list; this text is not truncated.
|
|
83
|
+
return `${baseDescription}\n\nAvailable hosts:\n${wrapUntrustedContent(hostList)}`;
|
|
83
84
|
}
|
|
84
85
|
|
|
85
86
|
function quoteRemotePath(value: string): string {
|
package/src/tui/code-cell.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Render a code or markdown cell with optional output section.
|
|
3
3
|
*/
|
|
4
4
|
import { Markdown } from "@sayknow-cli/tui";
|
|
5
|
+
import { sanitizeText } from "@sayknow-cli/utils";
|
|
5
6
|
import { getMarkdownTheme, highlightCode, type Theme } from "../modes/theme/theme";
|
|
6
7
|
import {
|
|
7
8
|
formatDuration,
|
|
@@ -92,13 +93,20 @@ function collapseCarriageReturns(line: string): string {
|
|
|
92
93
|
const idx = line.lastIndexOf("\r");
|
|
93
94
|
return idx < 0 ? line : line.slice(idx + 1);
|
|
94
95
|
}
|
|
96
|
+
|
|
97
|
+
// Source bytes are untrusted. Collapse CR first: sanitizeText drops CR, which
|
|
98
|
+
// would concatenate both sides of a progress-bar overwrite. Strip before the
|
|
99
|
+
// line cap and the highlighter so a clipped line cannot keep a control.
|
|
100
|
+
function sanitizeCodeLines(text: string): string[] {
|
|
101
|
+
return sanitizeTerminalLines(text).map(line => sanitizeText(line));
|
|
102
|
+
}
|
|
95
103
|
export function renderCodeCell(options: CodeCellOptions, theme: Theme): string[] {
|
|
96
104
|
const { code, language, output, expanded = false, outputMaxLines = 6, codeMaxLines = 12, width } = options;
|
|
97
105
|
const { title, meta } = formatHeader(options, theme);
|
|
98
106
|
const state = getState(options.status);
|
|
99
107
|
|
|
100
108
|
const normalizedCode = replaceTabs(code ?? "");
|
|
101
|
-
const rawCodeLines =
|
|
109
|
+
const rawCodeLines = sanitizeCodeLines(normalizedCode);
|
|
102
110
|
const maxCodeLines = expanded ? rawCodeLines.length : Math.min(rawCodeLines.length, codeMaxLines);
|
|
103
111
|
const visibleCode = rawCodeLines.slice(0, maxCodeLines).join("\n");
|
|
104
112
|
const codeLines = highlightCode(visibleCode, language);
|
|
@@ -166,7 +174,13 @@ export function renderMarkdownCell(options: MarkdownCellOptions, theme: Theme):
|
|
|
166
174
|
// Markdown component manages its own wrapping at the inner content width.
|
|
167
175
|
// `renderOutputBlock` adds a `│ ` prefix + `│` suffix → 3 visible columns.
|
|
168
176
|
const innerWidth = Math.max(20, width - 3);
|
|
169
|
-
|
|
177
|
+
// Repository markdown is untrusted. The Markdown component writes text as-is
|
|
178
|
+
// and only later adds its own hyperlink sequences, so strip terminal controls
|
|
179
|
+
// from the source before that render.
|
|
180
|
+
const markdownSource = sanitizeText(content);
|
|
181
|
+
const allLines = markdownSource.trim()
|
|
182
|
+
? new Markdown(markdownSource, 0, 0, getMarkdownTheme()).render(innerWidth)
|
|
183
|
+
: [];
|
|
170
184
|
const maxContentLines = expanded ? allLines.length : Math.min(allLines.length, contentMaxLines);
|
|
171
185
|
const contentLines = allLines.slice(0, maxContentLines);
|
|
172
186
|
const hiddenContentLines = allLines.length - maxContentLines;
|
package/src/tui/file-list.ts
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Render file listings with optional icons and metadata.
|
|
3
3
|
*/
|
|
4
|
+
import { sanitizeText } from "@sayknow-cli/utils";
|
|
4
5
|
import type { Theme } from "../modes/theme/theme";
|
|
5
6
|
import { getLanguageFromPath } from "../modes/theme/theme";
|
|
6
7
|
import { renderTreeList } from "./tree-list";
|
|
7
8
|
|
|
9
|
+
// One label. Flatten line breaks, then strip C0/C1 and ANSI. Directional
|
|
10
|
+
// marks stay: they are part of a name, not a terminal command.
|
|
11
|
+
function sanitizeFileLabel(text: string): string {
|
|
12
|
+
return sanitizeText(text.replace(/[\r\n\u2028\u2029]+/gu, " "));
|
|
13
|
+
}
|
|
14
|
+
|
|
8
15
|
export interface FileEntry {
|
|
9
16
|
path: string;
|
|
10
17
|
/** Absolute filesystem path. When provided together with {@link FileListOptions.hyperlinkFn}, the
|
|
@@ -34,8 +41,11 @@ export function renderFileList(options: FileListOptions, theme: Theme): string[]
|
|
|
34
41
|
maxCollapsed,
|
|
35
42
|
itemType: "file",
|
|
36
43
|
renderItem: entry => {
|
|
37
|
-
|
|
38
|
-
|
|
44
|
+
// Names are repository-controlled. Strip controls before theme
|
|
45
|
+
// styling: the caller clips the styled line, and a zero-width
|
|
46
|
+
// sequence would survive that clip.
|
|
47
|
+
const displayPath = sanitizeFileLabel(entry.path);
|
|
48
|
+
const isDirectory = entry.isDirectory ?? displayPath.endsWith("/");
|
|
39
49
|
const lang = isDirectory ? undefined : getLanguageFromPath(displayPath);
|
|
40
50
|
const icon = !showIcons
|
|
41
51
|
? ""
|
|
@@ -43,7 +53,8 @@ export function renderFileList(options: FileListOptions, theme: Theme): string[]
|
|
|
43
53
|
? theme.fg("accent", theme.icon.folder)
|
|
44
54
|
: theme.fg("muted", theme.getLangIcon(lang));
|
|
45
55
|
const labelColor = isDirectory ? "accent" : "toolOutput";
|
|
46
|
-
const
|
|
56
|
+
const safeMeta = entry.meta ? sanitizeFileLabel(entry.meta) : "";
|
|
57
|
+
const meta = safeMeta ? ` ${theme.fg("dim", safeMeta)}` : "";
|
|
47
58
|
const iconPrefix = icon ? `${icon} ` : "";
|
|
48
59
|
const pathStr = theme.fg(labelColor, displayPath);
|
|
49
60
|
const linkedPath = entry.absPath && hyperlinkFn ? hyperlinkFn(entry.absPath, pathStr) : pathStr;
|
package/src/tui/status-line.ts
CHANGED
|
@@ -15,22 +15,163 @@ export interface StatusLineOptions {
|
|
|
15
15
|
meta?: string[];
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
const WELL_FORMED_FILE_OSC8_RE = /^\x1b\]8;[^\x1b\x07;]*;file:\/\/[^\x1b\x07\s]*(?:\x1b\\|\x07)$/;
|
|
19
|
+
const WELL_FORMED_OSC8_CLOSURE_RE = /^\x1b\]8;;(?:\x1b\\|\x07)$/;
|
|
20
|
+
const BIDI_CONTROL_RE = /[\u061C\u200E\u200F\u202A-\u202E\u2066-\u2069]/gu;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Sanitize untrusted text embedded in status lines while preserving caller-provided
|
|
24
|
+
* SGR color/style sequences (e.g. `theme.fg`) and intentional OSC 8 file hyperlinks.
|
|
25
|
+
*
|
|
26
|
+
* Uses a linear-time 1-pass scanner to avoid quadratic backtracking on repeated
|
|
27
|
+
* unterminated control introducers, stripping arbitrary OSC, DCS, non-SGR CSI,
|
|
28
|
+
* C0/C1 controls, and directional overrides, while flattening newlines and tabs to single spaces.
|
|
29
|
+
*/
|
|
30
|
+
export function sanitizeStatusLineText(text: string): string {
|
|
31
|
+
const normalized = text.replace(/[\r\n\t]+/gu, " ").replace(BIDI_CONTROL_RE, "");
|
|
32
|
+
let result = "";
|
|
33
|
+
const length = normalized.length;
|
|
34
|
+
let index = 0;
|
|
35
|
+
|
|
36
|
+
while (index < length) {
|
|
37
|
+
const char = normalized[index]!;
|
|
38
|
+
const code = char.charCodeAt(0);
|
|
39
|
+
|
|
40
|
+
if (char === "\x1b") {
|
|
41
|
+
if (index + 1 >= length) {
|
|
42
|
+
index++;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
const next = normalized[index + 1];
|
|
46
|
+
|
|
47
|
+
if (next === "[") {
|
|
48
|
+
let cursor = index + 2;
|
|
49
|
+
while (
|
|
50
|
+
cursor < length &&
|
|
51
|
+
((normalized.charCodeAt(cursor) >= 48 && normalized.charCodeAt(cursor) <= 57) ||
|
|
52
|
+
normalized[cursor] === ";" ||
|
|
53
|
+
normalized[cursor] === ":")
|
|
54
|
+
) {
|
|
55
|
+
cursor++;
|
|
56
|
+
}
|
|
57
|
+
if (cursor < length && normalized[cursor] === "m") {
|
|
58
|
+
result += normalized.slice(index, cursor + 1);
|
|
59
|
+
index = cursor + 1;
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
while (cursor < length && normalized.charCodeAt(cursor) < 0x40) {
|
|
63
|
+
cursor++;
|
|
64
|
+
}
|
|
65
|
+
if (cursor < length && normalized.charCodeAt(cursor) >= 0x40 && normalized.charCodeAt(cursor) <= 0x7e) {
|
|
66
|
+
cursor++;
|
|
67
|
+
}
|
|
68
|
+
index = cursor;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (next === "]") {
|
|
73
|
+
let cursor = index + 2;
|
|
74
|
+
while (cursor < length) {
|
|
75
|
+
if (normalized[cursor] === "\x07") {
|
|
76
|
+
cursor++;
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
if (normalized[cursor] === "\x1b" && cursor + 1 < length && normalized[cursor + 1] === "\\") {
|
|
80
|
+
cursor += 2;
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
if (normalized[cursor] === "\x1b") {
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
cursor++;
|
|
87
|
+
}
|
|
88
|
+
const seq = normalized.slice(index, cursor);
|
|
89
|
+
if (WELL_FORMED_FILE_OSC8_RE.test(seq) || WELL_FORMED_OSC8_CLOSURE_RE.test(seq)) {
|
|
90
|
+
result += seq;
|
|
91
|
+
} else if (!(seq.endsWith("\x07") || seq.endsWith("\x1b\\"))) {
|
|
92
|
+
index++;
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
index = cursor;
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (next === "P") {
|
|
100
|
+
let cursor = index + 2;
|
|
101
|
+
while (cursor < length) {
|
|
102
|
+
if (normalized[cursor] === "\x07") {
|
|
103
|
+
cursor++;
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
if (normalized[cursor] === "\x1b" && cursor + 1 < length && normalized[cursor + 1] === "\\") {
|
|
107
|
+
cursor += 2;
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
if (normalized[cursor] === "\x1b") {
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
cursor++;
|
|
114
|
+
}
|
|
115
|
+
index = cursor;
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
index++;
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (code < 0x20 || code === 0x7f) {
|
|
124
|
+
index++;
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (code >= 0x80 && code <= 0x9f) {
|
|
129
|
+
if (code === 0x9d || code === 0x90) {
|
|
130
|
+
index++;
|
|
131
|
+
while (
|
|
132
|
+
index < length &&
|
|
133
|
+
normalized.charCodeAt(index) !== 0x9c &&
|
|
134
|
+
normalized[index] !== "\x07" &&
|
|
135
|
+
!(normalized[index] === "\x1b" && index + 1 < length && normalized[index + 1] === "\\")
|
|
136
|
+
) {
|
|
137
|
+
index++;
|
|
138
|
+
}
|
|
139
|
+
if (index < length) {
|
|
140
|
+
if (normalized[index] === "\x1b" && index + 1 < length && normalized[index + 1] === "\\") {
|
|
141
|
+
index += 2;
|
|
142
|
+
} else {
|
|
143
|
+
index++;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
index++;
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
result += char;
|
|
153
|
+
index++;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return result;
|
|
157
|
+
}
|
|
158
|
+
|
|
18
159
|
export function renderStatusLine(options: StatusLineOptions, theme: Theme): string {
|
|
19
160
|
const icon = options.icon ? formatStatusIcon(options.icon, theme, options.spinnerFrame) : "";
|
|
20
161
|
const titleColor = options.titleColor ?? "accent";
|
|
21
|
-
const title = theme.fg(titleColor, options.title);
|
|
162
|
+
const title = theme.fg(titleColor, sanitizeStatusLineText(options.title));
|
|
22
163
|
let line = icon ? `${icon} ${title}` : title;
|
|
23
164
|
|
|
24
165
|
if (options.description) {
|
|
25
|
-
line += `: ${theme.fg("muted", options.description)}`;
|
|
166
|
+
line += `: ${theme.fg("muted", sanitizeStatusLineText(options.description))}`;
|
|
26
167
|
}
|
|
27
168
|
|
|
28
169
|
if (options.badge) {
|
|
29
170
|
const { label, color } = options.badge;
|
|
30
|
-
line += ` ${theme.fg(color, `${theme.format.bracketLeft}${label}${theme.format.bracketRight}`)}`;
|
|
171
|
+
line += ` ${theme.fg(color, `${theme.format.bracketLeft}${sanitizeStatusLineText(label)}${theme.format.bracketRight}`)}`;
|
|
31
172
|
}
|
|
32
173
|
|
|
33
|
-
const meta = options.meta?.filter(value => value.trim().length > 0) ?? [];
|
|
174
|
+
const meta = options.meta?.map(sanitizeStatusLineText).filter(value => value.trim().length > 0) ?? [];
|
|
34
175
|
if (meta.length > 0) {
|
|
35
176
|
line += ` ${theme.fg("dim", meta.join(theme.sep.dot))}`;
|
|
36
177
|
}
|