mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-25 09:51:28 +00:00
* feat(terminal): extract hostnames from shell prompts * fix(ai): accept decorated two-line shell prompts * feat(tabs): add prompt-host title presentation * feat(session): track prompt-host transitions * feat(terminal): publish live prompt hostnames to tabs * fix(session): include prompt host action in publisher runtime * fix(ai): accept redrawn JumpServer shell prompts * fix(tabs): prefer live prompt host behind user labels * build(windows): normalize cross-built native modules * fix(build): avoid config lint global shadowing * fix(session): constrain live prompt hostname parsing * fix(tabs): refresh workspace labels from live prompt hosts * build(windows): validate cross-built native payloads * fix(session): cover strict zsh and jump host prompts * test(tabs): type live workspace prompt fixtures * build(windows): scan packed native modules safely * build(windows): add explicit cross-build script * build(windows): make cross packaging self-contained * fix(terminal): address review findings on JumpServer prompts and Windows cross-pack * fix(windows): preserve child-process detection in cross-built packages * fix(windows): require patched conpty.node during cross-packaging --------- Co-authored-by: zjio26 <zjao2026@outlook.com> Co-authored-by: bincxz <16399091+binaricat@users.noreply.github.com>
87 lines
2.6 KiB
TypeScript
87 lines
2.6 KiB
TypeScript
import type { TerminalSession } from '../../domain/models';
|
|
import {
|
|
extractTerminalPromptHostname,
|
|
isJumpServerMenuPrompt,
|
|
} from '../../domain/terminalPromptSecurity';
|
|
|
|
type PromptHostnameSessionSignalOptions = {
|
|
getSession: (sessionId: string) => Pick<TerminalSession, 'protocol' | 'hostname'> | undefined;
|
|
onChange: (sessionId: string, hostname: string | null) => void;
|
|
maxTailChars?: number;
|
|
};
|
|
|
|
const DEFAULT_MAX_TAIL_CHARS = 8_192;
|
|
|
|
function normalizedHostname(hostname: string): string {
|
|
return hostname.trim().toLocaleLowerCase().replace(/\.$/u, '');
|
|
}
|
|
|
|
export function createPromptHostnameSessionSignalController({
|
|
getSession,
|
|
onChange,
|
|
maxTailChars = DEFAULT_MAX_TAIL_CHARS,
|
|
}: PromptHostnameSessionSignalOptions) {
|
|
const tails = new Map<string, string>();
|
|
const baselines = new Map<string, string>();
|
|
const published = new Map<string, string>();
|
|
const tailLimit = Math.max(256, maxTailChars);
|
|
|
|
const forgetSession = (sessionId: string): void => {
|
|
tails.delete(sessionId);
|
|
baselines.delete(sessionId);
|
|
published.delete(sessionId);
|
|
};
|
|
|
|
return {
|
|
forgetSession,
|
|
pruneSessions(validSessionIds: ReadonlySet<string>): void {
|
|
for (const sessionId of [...tails.keys(), ...baselines.keys(), ...published.keys()]) {
|
|
if (!validSessionIds.has(sessionId)) {
|
|
forgetSession(sessionId);
|
|
}
|
|
}
|
|
},
|
|
handleTerminalOutput(sessionId: string, chunk: string): void {
|
|
const session = getSession(sessionId);
|
|
if (!session) {
|
|
forgetSession(sessionId);
|
|
return;
|
|
}
|
|
if ((session.protocol ?? 'ssh') !== 'ssh') return;
|
|
|
|
const combined = `${tails.get(sessionId) ?? ''}${chunk}`;
|
|
const tail = combined.slice(-tailLimit);
|
|
tails.set(sessionId, tail);
|
|
|
|
const detected = extractTerminalPromptHostname(tail);
|
|
if (!detected) {
|
|
if (isJumpServerMenuPrompt(tail) && published.has(sessionId)) {
|
|
published.delete(sessionId);
|
|
onChange(sessionId, null);
|
|
}
|
|
return;
|
|
}
|
|
|
|
const detectedKey = normalizedHostname(detected);
|
|
if (!detectedKey) return;
|
|
|
|
let baseline = baselines.get(sessionId);
|
|
if (baseline === undefined) {
|
|
baseline = normalizedHostname(session.hostname) || detectedKey;
|
|
baselines.set(sessionId, baseline);
|
|
}
|
|
|
|
if (detectedKey === baseline) {
|
|
if (!published.has(sessionId)) return;
|
|
published.delete(sessionId);
|
|
onChange(sessionId, null);
|
|
return;
|
|
}
|
|
|
|
if (published.get(sessionId) === detectedKey) return;
|
|
published.set(sessionId, detectedKey);
|
|
onChange(sessionId, detected);
|
|
},
|
|
};
|
|
}
|