Skip to content

Commit b2d9dc2

Browse files
committed
refactor(tui): drop dead notice field, dedupe helpers
1 parent e88fda1 commit b2d9dc2

7 files changed

Lines changed: 56 additions & 33 deletions

File tree

‎src/tui/components/at-mention/list.ts‎

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,18 @@ export async function listPathSuggestions(
3939
// prefix as filter (the `@` alone case, like `ls`).
4040
const lastSlash = rest.lastIndexOf("/");
4141
const hasSlash = lastSlash !== -1;
42-
const dir = endsWithSep ? rest || "." : hasSlash ? dirname(rest) : ".";
43-
const fragment = endsWithSep ? "" : hasSlash ? basename(rest) : rest;
42+
let dir: string;
43+
let fragment: string;
44+
if (endsWithSep) {
45+
dir = rest || ".";
46+
fragment = "";
47+
} else if (hasSlash) {
48+
dir = dirname(rest);
49+
fragment = basename(rest);
50+
} else {
51+
dir = ".";
52+
fragment = rest;
53+
}
4454
const realDir = await resolveDirectory(dir, base);
4555
if (realDir === null) return [];
4656

@@ -56,16 +66,22 @@ export async function listPathSuggestions(
5666
// Reconstruct the path the user would type: bare fragments are shown
5767
// relative to cwd (dirPrefix ""), and home-relative results keep the
5868
// `~/` form so the completion inserts text the submit path expands.
59-
const innerPrefix = endsWithSep
60-
? rest
61-
: hasSlash
62-
? rest.slice(0, rest.length - fragment.length)
63-
: "";
64-
const dirPrefix = homeRelative
65-
? `~/${innerPrefix}`
66-
: endsWithSep
67-
? prefix
68-
: innerPrefix;
69+
let innerPrefix: string;
70+
if (endsWithSep) {
71+
innerPrefix = rest;
72+
} else if (hasSlash) {
73+
innerPrefix = rest.slice(0, rest.length - fragment.length);
74+
} else {
75+
innerPrefix = "";
76+
}
77+
let dirPrefix: string;
78+
if (homeRelative) {
79+
dirPrefix = `~/${innerPrefix}`;
80+
} else if (endsWithSep) {
81+
dirPrefix = prefix;
82+
} else {
83+
dirPrefix = innerPrefix;
84+
}
6985
matched.push(dirPrefix + entry.name + (entry.isDirectory() ? "/" : ""));
7086
}
7187

‎src/tui/copy-path.ts‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import { diffPlainText } from "./diff.js";
88
import type { StreamRow } from "./stream.js";
9+
import { abbreviate } from "./tool-formatter.js";
910

1011
export type CopyKind = "message" | "tool" | "diff" | "system";
1112

@@ -72,11 +73,6 @@ export function createRecordingClipboard(): ClipboardPort & {
7273
};
7374
}
7475

75-
function oneLine(text: string, max = 56): string {
76-
const collapsed = text.replace(/\s+/g, " ").trim();
77-
return collapsed.length > max ? `${collapsed.slice(0, max - 1)}…` : collapsed;
78-
}
79-
8076
/**
8177
* Infer copy kind from a stream row.
8278
* Rows carrying a rendered edit diff win; otherwise assistant/tool rows whose
@@ -154,7 +150,7 @@ export function buildCopyTargets(log: readonly StreamRow[]): CopyTarget[] {
154150
targets.push({
155151
id: `row-${i}`,
156152
label: copyRowLabel(row),
157-
preview: oneLine(payload.text),
153+
preview: abbreviate(payload.text, 56),
158154
text: payload.text,
159155
});
160156
}

‎src/tui/markdown-parser.ts‎

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,20 @@ export interface MarkdownSplit {
782782
readonly gapRows: number;
783783
}
784784

785+
/** Build a split whose live tail starts at `firstContent`; one blank line
786+
* between the frozen boundary and the live tail collapses to a single gap row. */
787+
function settledSplit(
788+
frozen: string,
789+
rest: string[],
790+
firstContent: number,
791+
): MarkdownSplit {
792+
return {
793+
frozen,
794+
live: rest.slice(firstContent).join("\n"),
795+
gapRows: firstContent > 0 ? 1 : 0,
796+
};
797+
}
798+
785799
export function splitAtSettledHeading(text: string): MarkdownSplit | null {
786800
const lines = text.split("\n");
787801
const insideFence = fencedLineMask(lines);
@@ -797,11 +811,11 @@ export function splitAtSettledHeading(text: string): MarkdownSplit | null {
797811
const firstContent = rest.findIndex((line) => line.trim().length > 0);
798812
// Heading closed but nothing has started under it yet.
799813
if (firstContent === -1) return null;
800-
return {
801-
frozen: lines.slice(0, boundary + 1).join("\n"),
802-
live: rest.slice(firstContent).join("\n"),
803-
gapRows: firstContent > 0 ? 1 : 0,
804-
};
814+
return settledSplit(
815+
lines.slice(0, boundary + 1).join("\n"),
816+
rest,
817+
firstContent,
818+
);
805819
}
806820

807821
/**
@@ -870,11 +884,11 @@ export function splitAtSettledBlock(withheld: string): MarkdownSplit | null {
870884
const rest = lines.slice(boundary + 1);
871885
const firstContent = rest.findIndex((entry) => entry.trim().length > 0);
872886
if (firstContent === -1) continue;
873-
return {
874-
frozen: lines.slice(0, boundary + 1).join("\n"),
875-
live: rest.slice(firstContent).join("\n"),
876-
gapRows: firstContent > 0 ? 1 : 0,
877-
};
887+
return settledSplit(
888+
lines.slice(0, boundary + 1).join("\n"),
889+
rest,
890+
firstContent,
891+
);
878892
}
879893
return null;
880894
}

‎src/tui/notice-line.test.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88

99
const state = (over: Partial<NoticeState> = {}): NoticeState => ({
1010
waitingOn: null,
11-
interrupt: false,
1211
pinned: false,
1312
flash: null,
1413
attachments: 0,

‎src/tui/notice-line.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ export interface NoticeState {
2525
* Gated by `resolveWaitingOn`; this field only controls wording.
2626
*/
2727
readonly waitingOn: string | null;
28-
readonly interrupt: boolean;
2928
/** Transcript scrolled off the tail (non-default follow state). */
3029
readonly pinned: boolean;
3130
/** Transient feedback (copy result, attach failure, exit arming). */

‎src/tui/shell/chrome.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ export function noticeText(shell: AppShell): string {
136136
shell.inFlightTool,
137137
shell.lockupNowMs,
138138
),
139-
interrupt: shell.session.interruptFlash,
140139
pinned: !isTranscriptFollowing(shell),
141140
flash: shell.statusFlash,
142141
attachments: shell.pendingAttachments.length,

‎src/tui/tool-formatter.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ export function describeToolCall(
147147
const subject = description.length > 0 ? description : prompt;
148148
const first = agentName?.[0];
149149
const display =
150-
first != null && agentName !== undefined
151-
? first.toUpperCase() + agentName.slice(1)
150+
first != null
151+
? first.toUpperCase() + (agentName ?? "").slice(1)
152152
: "Worker";
153153
// Collapsed row uses the abbreviated subject; Alt+E expands to the full text.
154154
return {

0 commit comments

Comments
 (0)