Files
Netcatty/components/ai/sessionScopeMatch.ts
T
陈大猫 36295e63ed [codex] Fix Agent history persistence (#1534)
* fix agent history persistence

* Keep mismatched terminal history scoped out
2026-06-20 11:27:00 +08:00

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;
}