feat(coding-agent): add label timestamps to the session tree (#2691)

This commit is contained in:
warren
2026-03-30 15:56:37 +02:00
committed by GitHub
parent 21863d4ec7
commit 84d2b51a2e
8 changed files with 146 additions and 28 deletions

View File

@@ -32,6 +32,8 @@ export interface AppKeybindings {
"app.session.resume": true;
"app.tree.foldOrUp": true;
"app.tree.unfoldOrDown": true;
"app.tree.editLabel": true;
"app.tree.toggleLabelTimestamp": true;
"app.session.togglePath": true;
"app.session.toggleSort": true;
"app.session.rename": true;
@@ -101,6 +103,14 @@ export const KEYBINDINGS = {
defaultKeys: ["ctrl+right", "alt+right"],
description: "Unfold tree branch or move down",
},
"app.tree.editLabel": {
defaultKeys: "shift+l",
description: "Edit tree label",
},
"app.tree.toggleLabelTimestamp": {
defaultKeys: "shift+t",
description: "Toggle tree label timestamps",
},
"app.session.togglePath": {
defaultKeys: "ctrl+p",
description: "Toggle session path display",
@@ -176,6 +186,8 @@ const KEYBINDING_NAME_MIGRATIONS = {
resume: "app.session.resume",
treeFoldOrUp: "app.tree.foldOrUp",
treeUnfoldOrDown: "app.tree.unfoldOrDown",
treeEditLabel: "app.tree.editLabel",
treeToggleLabelTimestamp: "app.tree.toggleLabelTimestamp",
toggleSessionPath: "app.session.togglePath",
toggleSessionSort: "app.session.toggleSort",
renameSession: "app.session.rename",

View File

@@ -154,6 +154,8 @@ export interface SessionTreeNode {
children: SessionTreeNode[];
/** Resolved label for this entry, if any */
label?: string;
/** Timestamp of the latest label change for this entry, if any */
labelTimestamp?: string;
}
export interface SessionContext {
@@ -669,6 +671,7 @@ export class SessionManager {
private fileEntries: FileEntry[] = [];
private byId: Map<string, SessionEntry> = new Map();
private labelsById: Map<string, string> = new Map();
private labelTimestampsById: Map<string, string> = new Map();
private leafId: string | null = null;
private constructor(cwd: string, sessionDir: string, sessionFile: string | undefined, persist: boolean) {
@@ -746,6 +749,7 @@ export class SessionManager {
private _buildIndex(): void {
this.byId.clear();
this.labelsById.clear();
this.labelTimestampsById.clear();
this.leafId = null;
for (const entry of this.fileEntries) {
if (entry.type === "session") continue;
@@ -754,8 +758,10 @@ export class SessionManager {
if (entry.type === "label") {
if (entry.label) {
this.labelsById.set(entry.targetId, entry.label);
this.labelTimestampsById.set(entry.targetId, entry.timestamp);
} else {
this.labelsById.delete(entry.targetId);
this.labelTimestampsById.delete(entry.targetId);
}
}
}
@@ -1007,8 +1013,10 @@ export class SessionManager {
this._appendEntry(entry);
if (label) {
this.labelsById.set(targetId, label);
this.labelTimestampsById.set(targetId, entry.timestamp);
} else {
this.labelsById.delete(targetId);
this.labelTimestampsById.delete(targetId);
}
return entry.id;
}
@@ -1067,7 +1075,8 @@ export class SessionManager {
// Create nodes with resolved labels
for (const entry of entries) {
const label = this.labelsById.get(entry.id);
nodeMap.set(entry.id, { entry, children: [], label });
const labelTimestamp = this.labelTimestampsById.get(entry.id);
nodeMap.set(entry.id, { entry, children: [], label, labelTimestamp });
}
// Build tree
@@ -1179,10 +1188,10 @@ export class SessionManager {
// Collect labels for entries in the path
const pathEntryIds = new Set(pathWithoutLabels.map((e) => e.id));
const labelsToWrite: Array<{ targetId: string; label: string }> = [];
const labelsToWrite: Array<{ targetId: string; label: string; timestamp: string }> = [];
for (const [targetId, label] of this.labelsById) {
if (pathEntryIds.has(targetId)) {
labelsToWrite.push({ targetId, label });
labelsToWrite.push({ targetId, label, timestamp: this.labelTimestampsById.get(targetId)! });
}
}
@@ -1191,12 +1200,12 @@ export class SessionManager {
const lastEntryId = pathWithoutLabels[pathWithoutLabels.length - 1]?.id || null;
let parentId = lastEntryId;
const labelEntries: LabelEntry[] = [];
for (const { targetId, label } of labelsToWrite) {
for (const { targetId, label, timestamp: labelTimestamp } of labelsToWrite) {
const labelEntry: LabelEntry = {
type: "label",
id: generateId(new Set(pathEntryIds)),
parentId,
timestamp: new Date().toISOString(),
timestamp: labelTimestamp,
targetId,
label,
};
@@ -1229,12 +1238,12 @@ export class SessionManager {
// In-memory mode: replace current session with the path + labels
const labelEntries: LabelEntry[] = [];
let parentId = pathWithoutLabels[pathWithoutLabels.length - 1]?.id || null;
for (const { targetId, label } of labelsToWrite) {
for (const { targetId, label, timestamp: labelTimestamp } of labelsToWrite) {
const labelEntry: LabelEntry = {
type: "label",
id: generateId(new Set([...pathEntryIds, ...labelEntries.map((e) => e.id)])),
parentId,
timestamp: new Date().toISOString(),
timestamp: labelTimestamp,
targetId,
label,
};

View File

@@ -13,7 +13,7 @@ import {
import type { SessionTreeNode } from "../../../core/session-manager.js";
import { theme } from "../theme/theme.js";
import { DynamicBorder } from "./dynamic-border.js";
import { keyHint } from "./keybinding-hints.js";
import { keyHint, keyText } from "./keybinding-hints.js";
/** Gutter info: position (displayIndent where connector was) and whether to show │ */
interface GutterInfo {
@@ -58,6 +58,7 @@ class TreeList implements Component {
private searchQuery = "";
private toolCallMap: Map<string, ToolCallInfo> = new Map();
private multipleRoots = false;
private showLabelTimestamps = false;
private activePathIds: Set<string> = new Set();
private visibleParentMap: Map<string, string | null> = new Map();
private visibleChildrenMap: Map<string | null, string[]> = new Map();
@@ -567,28 +568,36 @@ class TreeList implements Component {
return this.filteredNodes[this.selectedIndex]?.node;
}
updateNodeLabel(entryId: string, label: string | undefined): void {
updateNodeLabel(entryId: string, label: string | undefined, labelTimestamp?: string): void {
for (const flatNode of this.flatNodes) {
if (flatNode.node.entry.id === entryId) {
flatNode.node.label = label;
flatNode.node.labelTimestamp = label ? (labelTimestamp ?? new Date().toISOString()) : undefined;
break;
}
}
}
private getFilterLabel(): string {
private getStatusLabels(): string {
let labels = "";
switch (this.filterMode) {
case "no-tools":
return " [no-tools]";
labels += " [no-tools]";
break;
case "user-only":
return " [user]";
labels += " [user]";
break;
case "labeled-only":
return " [labeled]";
labels += " [labeled]";
break;
case "all":
return " [all]";
default:
return "";
labels += " [all]";
break;
}
if (this.showLabelTimestamps) {
labels += " [+label time]";
}
return labels;
}
render(width: number): string[] {
@@ -596,7 +605,7 @@ class TreeList implements Component {
if (this.filteredNodes.length === 0) {
lines.push(truncateToWidth(theme.fg("muted", " No entries found"), width));
lines.push(truncateToWidth(theme.fg("muted", ` (0/0)${this.getFilterLabel()}`), width));
lines.push(truncateToWidth(theme.fg("muted", ` (0/0)${this.getStatusLabels()}`), width));
return lines;
}
@@ -667,9 +676,13 @@ class TreeList implements Component {
const pathMarker = isOnActivePath ? theme.fg("accent", "• ") : "";
const label = flatNode.node.label ? theme.fg("warning", `[${flatNode.node.label}] `) : "";
const labelTimestamp =
this.showLabelTimestamps && flatNode.node.label && flatNode.node.labelTimestamp
? theme.fg("muted", `${this.formatLabelTimestamp(flatNode.node.labelTimestamp)} `)
: "";
const content = this.getEntryDisplayText(flatNode.node, isSelected);
let line = cursor + theme.fg("dim", prefix) + foldMarker + pathMarker + label + content;
let line = cursor + theme.fg("dim", prefix) + foldMarker + pathMarker + label + labelTimestamp + content;
if (isSelected) {
line = theme.bg("selectedBg", line);
}
@@ -678,7 +691,7 @@ class TreeList implements Component {
lines.push(
truncateToWidth(
theme.fg("muted", ` (${this.selectedIndex + 1}/${this.filteredNodes.length})${this.getFilterLabel()}`),
theme.fg("muted", ` (${this.selectedIndex + 1}/${this.filteredNodes.length})${this.getStatusLabels()}`),
width,
),
);
@@ -772,6 +785,31 @@ class TreeList implements Component {
return isSelected ? theme.bold(result) : result;
}
private formatLabelTimestamp(timestamp: string): string {
const date = new Date(timestamp);
const now = new Date();
const hours = date.getHours().toString().padStart(2, "0");
const minutes = date.getMinutes().toString().padStart(2, "0");
const time = `${hours}:${minutes}`;
if (
date.getFullYear() === now.getFullYear() &&
date.getMonth() === now.getMonth() &&
date.getDate() === now.getDate()
) {
return time;
}
const month = date.getMonth() + 1;
const day = date.getDate();
if (date.getFullYear() === now.getFullYear()) {
return `${month}/${day} ${time}`;
}
const year = date.getFullYear().toString().slice(-2);
return `${year}/${month}/${day} ${time}`;
}
private extractContent(content: unknown): string {
const maxLen = 200;
if (typeof content === "string") return content.slice(0, maxLen);
@@ -945,11 +983,13 @@ class TreeList implements Component {
this.foldedNodes.clear();
this.applyFilter();
}
} else if (matchesKey(keyData, "shift+l")) {
} else if (kb.matches(keyData, "app.tree.editLabel")) {
const selected = this.filteredNodes[this.selectedIndex];
if (selected && this.onLabelEdit) {
this.onLabelEdit(selected.node.entry.id, selected.node.label);
}
} else if (kb.matches(keyData, "app.tree.toggleLabelTimestamp")) {
this.showLabelTimestamps = !this.showLabelTimestamps;
} else {
const hasControlChars = [...keyData].some((ch) => {
const code = ch.charCodeAt(0);
@@ -1140,8 +1180,10 @@ export class TreeSelectorComponent extends Container implements Focusable {
this.addChild(new Text(theme.bold(" Session Tree"), 1, 0));
this.addChild(
new TruncatedText(
theme.fg("muted", " ↑/↓: move. ←/→: page. ^←/^→ or Alt+←/Alt+→: fold/branch. Shift+L: label. ") +
theme.fg("muted", "^D/^T/^U/^L/^A: filters (^O/⇧^O cycle)"),
theme.fg(
"muted",
` ↑/↓: move. ←/→: page. ^←/^→ or Alt+←/Alt+→: fold/branch. ${keyText("app.tree.editLabel")}: label. ^D/^T/^U/^L/^A: filters (^O/⇧^O cycle). ${keyText("app.tree.toggleLabelTimestamp")}: label time`,
),
0,
0,
),