The best way to control Claude Code, Codex and more from any computer or phone
perf(shared): strip plan prefixes in linear time (#28537)
Hieu Le committed
Nov 1, 2026 at 22:54 UTC
6879da849a0c89255aa54a2afdf43496e45cd9af
1 file changed
+8
-8
packages/shared/src/proposedPlanText.ts
+8
-8
@@ -5,16 +5,16 @@ export function proposedPlanTitle(planMarkdown: string): string | null {
5
6
export function stripDisplayedPlanMarkdown(planMarkdown: string): string {
7
const lines = planMarkdown.trimEnd().split(/\r?\n/);
8
- const sourceLines = lines[0] && /^\s{0,3}#{1,6}\s+/.test(lines[0]) ? lines.slice(1) : [...lines];
9
- while (sourceLines[0]?.trim().length === 0) {
10
- sourceLines.shift();
8
+ let start = lines[0] && /^\s{0,3}#{1,6}\s+/.test(lines[0]) ? 1 : 0;
9
+ while (lines[start]?.trim().length === 0) {
10
+ start += 1;
11
}
12
- const firstHeadingMatch = sourceLines[0]?.match(/^\s{0,3}#{1,6}\s+(.+)$/);
12
+ const firstHeadingMatch = lines[start]?.match(/^\s{0,3}#{1,6}\s+(.+)$/);
13
if (firstHeadingMatch?.[1]?.trim().toLowerCase() === "summary") {
14
- sourceLines.shift();
15
- while (sourceLines[0]?.trim().length === 0) {
16
- sourceLines.shift();
14
+ start += 1;
15
+ while (lines[start]?.trim().length === 0) {
16
+ start += 1;
17
}
18
}
19
- return sourceLines.join("\n");
19
+ return lines.slice(start).join("\n");
20
}