Skip to content

Commit f4fa56d

Browse files
committed
fix(cli): keep session key truncation UTF-16 safe
1 parent 372b527 commit f4fa56d

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Sessions table tests cover shared fixed-width cell formatting.
2+
import { describe, expect, it } from "vitest";
3+
import { formatSessionKeyCell, SESSION_KEY_PAD } from "./sessions-table.js";
4+
5+
describe("formatSessionKeyCell", () => {
6+
it("keeps both truncation boundaries UTF-16 safe", () => {
7+
const key = `${"a".repeat(15)}😀middle😀${"z".repeat(5)}`;
8+
9+
const rendered = formatSessionKeyCell(key, false);
10+
11+
expect(rendered).toBe(`${"a".repeat(15)}...${"z".repeat(5)}`.padEnd(SESSION_KEY_PAD));
12+
expect(rendered).toHaveLength(SESSION_KEY_PAD);
13+
});
14+
});

src/commands/sessions-table.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Cleanup and listing commands use the same row shape and fixed-width cells so
55
* terminal output stays aligned across commands.
66
*/
7+
import { sliceUtf16Safe, truncateUtf16Safe } from "@openclaw/normalization-core/utf16-slice";
78
import { theme } from "../../packages/terminal-core/src/theme.js";
89
import type { SessionEntry } from "../config/sessions.js";
910
import { formatTimeAgo } from "../infra/format-time/format-relative.ts";
@@ -108,7 +109,7 @@ function truncateSessionKey(key: string): string {
108109
// Keep both the stable prefix and suffix; the tail often contains direct
109110
// recipient or runtime identifiers that distinguish otherwise similar keys.
110111
const head = Math.max(4, SESSION_KEY_PAD - 10);
111-
return `${key.slice(0, head)}...${key.slice(-6)}`;
112+
return `${truncateUtf16Safe(key, head)}...${sliceUtf16Safe(key, -6)}`;
112113
}
113114

114115
/** Formats a session key cell for table output. */

0 commit comments

Comments
 (0)