fix(coding-agent): sort threaded sessions by latest activity in the subtree
This commit is contained in:
@@ -190,6 +190,7 @@ class SessionSelectorHeader implements Component {
|
||||
interface SessionTreeNode {
|
||||
session: SessionInfo;
|
||||
children: SessionTreeNode[];
|
||||
latestActivity: number;
|
||||
}
|
||||
|
||||
/** Flattened node for display with tree structure info */
|
||||
@@ -210,7 +211,7 @@ function buildSessionTree(sessions: SessionInfo[]): SessionTreeNode[] {
|
||||
|
||||
for (const session of sessions) {
|
||||
const sessionPath = canonicalizePath(session.path) ?? session.path;
|
||||
byPath.set(sessionPath, { session, children: [] });
|
||||
byPath.set(sessionPath, { session, children: [], latestActivity: session.modified.getTime() });
|
||||
}
|
||||
|
||||
const roots: SessionTreeNode[] = [];
|
||||
@@ -227,9 +228,22 @@ function buildSessionTree(sessions: SessionInfo[]): SessionTreeNode[] {
|
||||
}
|
||||
}
|
||||
|
||||
// Sort children and roots by modified date (descending)
|
||||
const updateLatestActivity = (node: SessionTreeNode): number => {
|
||||
let latestActivity = node.session.modified.getTime();
|
||||
for (const child of node.children) {
|
||||
latestActivity = Math.max(latestActivity, updateLatestActivity(child));
|
||||
}
|
||||
node.latestActivity = latestActivity;
|
||||
return latestActivity;
|
||||
};
|
||||
|
||||
for (const root of roots) {
|
||||
updateLatestActivity(root);
|
||||
}
|
||||
|
||||
// Sort children and roots by latest activity in each subtree (descending)
|
||||
const sortNodes = (nodes: SessionTreeNode[]): void => {
|
||||
nodes.sort((a, b) => b.session.modified.getTime() - a.session.modified.getTime());
|
||||
nodes.sort((a, b) => b.latestActivity - a.latestActivity);
|
||||
for (const node of nodes) {
|
||||
sortNodes(node.children);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user