TUI: honor explicit session key in global scope

This commit is contained in:
Vignesh Natarajan
2026-02-14 16:40:37 -08:00
parent b08146fad6
commit 56b38d2fbe
2 changed files with 64 additions and 18 deletions

View File

@@ -77,6 +77,31 @@ export function createEditorSubmitHandler(params: {
};
}
export function resolveTuiSessionKey(params: {
raw?: string;
sessionScope: SessionScope;
currentAgentId: string;
sessionMainKey: string;
}) {
const trimmed = (params.raw ?? "").trim();
if (!trimmed) {
if (params.sessionScope === "global") {
return "global";
}
return buildAgentMainSessionKey({
agentId: params.currentAgentId,
mainKey: params.sessionMainKey,
});
}
if (trimmed === "global" || trimmed === "unknown") {
return trimmed;
}
if (trimmed.startsWith("agent:")) {
return trimmed;
}
return `agent:${params.currentAgentId}:${trimmed}`;
}
export async function runTui(opts: TuiOptions) {
const config = loadConfig();
const initialSessionInput = (opts.session ?? "").trim();
@@ -298,23 +323,12 @@ export async function runTui(opts: TuiOptions) {
};
const resolveSessionKey = (raw?: string) => {
const trimmed = (raw ?? "").trim();
if (sessionScope === "global") {
return "global";
}
if (!trimmed) {
return buildAgentMainSessionKey({
agentId: currentAgentId,
mainKey: sessionMainKey,
});
}
if (trimmed === "global" || trimmed === "unknown") {
return trimmed;
}
if (trimmed.startsWith("agent:")) {
return trimmed;
}
return `agent:${currentAgentId}:${trimmed}`;
return resolveTuiSessionKey({
raw,
sessionScope,
currentAgentId,
sessionMainKey,
});
};
currentSessionKey = resolveSessionKey(initialSessionInput);