feat: name forked and cloned sessions

This commit is contained in:
Federico Jaramillo Martinez
2026-05-22 15:36:24 +02:00
parent 23e82e1292
commit 3409b0acba
4 changed files with 159 additions and 0 deletions
+20
View File
@@ -204,6 +204,7 @@ export class PiSessionService {
this.publishStatus(session);
},
},
{ listSessionNames: (cwd) => this.listSessionNames(cwd) },
);
}
@@ -476,6 +477,20 @@ export class PiSessionService {
};
}
private async listSessionNames(cwd: string): Promise<string[]> {
const [sessions, archivedRecords] = await Promise.all([this.sessionManager.list(cwd), this.archiveStore.list()]);
const names = new Set<string>();
for (const session of sessions) addSessionName(names, session.name);
for (const record of archivedRecords) {
if (record.cwd === cwd) addSessionName(names, record.name);
}
for (const active of new Set(this.active.values())) {
const session = active.runtime.session;
if (session.sessionManager.getCwd() === cwd) addSessionName(names, session.sessionName);
}
return [...names];
}
private async closeActive(sessionId: string): Promise<void> {
const active = this.active.get(sessionId);
if (!active) return;
@@ -751,6 +766,11 @@ function clientSessionFromArchivedRecord(record: ArchivedSessionRecord, fallback
};
}
function addSessionName(names: Set<string>, name: string | undefined): void {
const trimmed = name?.replace(/\s+/g, " ").trim();
if (trimmed !== undefined && trimmed !== "") names.add(trimmed);
}
function compareArchivedRecords(a: ArchivedSessionRecord, b: ArchivedSessionRecord): number {
return archivedTimestamp(b) - archivedTimestamp(a);
}