mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-10-09 15:58:34 +00:00
36295e63ed
* fix agent history persistence * Keep mismatched terminal history scoped out
29 lines
971 B
TypeScript
29 lines
971 B
TypeScript
import type { AISession } from "../../infrastructure/ai/types";
|
|
|
|
export function getSessionScopeMatchRank(
|
|
session: AISession,
|
|
scopeType: "terminal" | "workspace",
|
|
scopeTargetId?: string,
|
|
scopeHostIds?: string[],
|
|
/**
|
|
* Session ids currently displayed by other terminal scopes. Tracked by
|
|
* session id rather than `scope.targetId` so that a host-matched session
|
|
* resumed from a different terminal is still recognised as in-use and
|
|
* not offered (or cleaned) as if it were orphaned.
|
|
*/
|
|
activeTerminalSessionIds?: Set<string>,
|
|
): number {
|
|
if (session.scope.type !== scopeType) return 0;
|
|
if (session.scope.targetId === scopeTargetId) return 3;
|
|
|
|
if (scopeType === "terminal" && activeTerminalSessionIds?.has(session.id)) {
|
|
return 0;
|
|
}
|
|
|
|
if (scopeType === "terminal" && scopeHostIds?.length && session.scope.hostIds?.length) {
|
|
return session.scope.hostIds.some((hostId) => scopeHostIds.includes(hostId)) ? 2 : 0;
|
|
}
|
|
|
|
return 1;
|
|
}
|