Simplify filter-flatMap patterns to single flatMap operations (#23242)

- Replace .filter().flatMap() chains with .flatMap() using conditionals
- Use constructor parameter shorthand in PreflightHandler
- More concise conditional filtering across agent detection and tab rebasing
This commit is contained in:
Jinjing
2026-09-26 11:45:03 -07:00
committed by GitHub
parent 3990076fa3
commit a85057ef48
3 changed files with 13 additions and 14 deletions
@@ -70,7 +70,7 @@ function rebaseUnifiedTabs(
(tab) => tab.contentType !== 'terminal' || terminalUnifiedTabMatches(tab, terminalTabIds)
)
const representedTerminalIds = new Set(
result.filter((tab) => tab.contentType === 'terminal').flatMap((tab) => [tab.id, tab.entityId])
result.flatMap((tab) => (tab.contentType === 'terminal' ? [tab.id, tab.entityId] : []))
)
for (const tab of current) {
if (
+7 -10
View File
@@ -39,10 +39,7 @@ const CONSERVATIVE_SYSTEM_SHELL_DIRS = new Set(['/bin', '/usr/bin'])
const AGENT_PATH_PREFIX = '__ORCA_AGENT_PATH__'
export class PreflightHandler {
private dispatcher: RelayDispatcher
constructor(dispatcher: RelayDispatcher) {
this.dispatcher = dispatcher
constructor(private readonly dispatcher: RelayDispatcher) {
this.registerHandlers()
}
@@ -53,9 +50,7 @@ export class PreflightHandler {
)
}
// Why: the client sends the command list rather than importing TUI_AGENT_CONFIG
// on the relay side. This keeps the relay bundle minimal and makes the protocol
// self-describing — the relay doesn't need to know the agent catalog.
// Why: client-supplied commands keep the relay independent of the agent catalog.
private async detectAgents(params: Record<string, unknown>): Promise<{
agents: string[]
versions?: Record<string, string>
@@ -66,9 +61,11 @@ export class PreflightHandler {
}
const probeCommands = [
...new Set(
commands
.filter((command) => !isDetectionUnsupportedInRuntime(command, process.platform))
.flatMap((command) => [command.cmd, ...(command.requiredCommands ?? [])])
commands.flatMap((command) =>
isDetectionUnsupportedInRuntime(command, process.platform)
? []
: [command.cmd, ...(command.requiredCommands ?? [])]
)
)
]
+5 -3
View File
@@ -48,9 +48,11 @@ export function getTuiAgentDetectionProbeCommands(
): string[] {
return [
...new Set(
commands
.filter((command) => !isDetectionUnsupportedInRuntime(command, runtime))
.flatMap((command) => [command.cmd, ...(command.requiredCommands ?? [])])
commands.flatMap((command) =>
isDetectionUnsupportedInRuntime(command, runtime)
? []
: [command.cmd, ...(command.requiredCommands ?? [])]
)
)
]
}