Skip to content

Commit c88edae

Browse files
committed
Extract noisy JSX/statement IIFEs into helpers (CL-5351 slice C)
Behavior-preserving refactors only: hoist work/accept ordering and copy-mode windowing in app.tsx, PromptActionBar + renderInputLines in chat-input, re-auth hint boolean in agent-modal, plain manage_tasks parse block in use-stream, and shared persistWithMergeBase for the two provider-manager disk writes.
1 parent 2921e45 commit c88edae

5 files changed

Lines changed: 274 additions & 209 deletions

File tree

src/tui/app.tsx

Lines changed: 59 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,21 @@ export type AppProps = {
220220
onFirstUserMessage?: () => void;
221221
};
222222

223+
// Center a selection in a fixed-height window over a copy-target list.
224+
// Returns the visible slice and the absolute index of its first item so
225+
// the caller can mark the selected row without re-scanning the full list.
226+
function windowedCopyTargets(
227+
items: readonly CopyTarget[],
228+
selectedIndex: number,
229+
windowSize = 6,
230+
): { window: readonly CopyTarget[]; start: number } {
231+
const start = Math.max(
232+
0,
233+
Math.min(selectedIndex - Math.floor(windowSize / 2), Math.max(0, items.length - windowSize)),
234+
);
235+
return { window: items.slice(start, start + windowSize), start };
236+
}
237+
223238
export function App({
224239
eventEmitter,
225240
agent,
@@ -1037,6 +1052,40 @@ export function App({
10371052
);
10381053
}
10391054

1055+
// Work / Acceptance chrome: order flips by goal phase (implementing = Work on top).
1056+
const workBlock = hasActiveTasks(state.tasks) ? (
1057+
<Box flexDirection="column" marginTop={1} key="work">
1058+
<TaskView
1059+
tasks={state.tasks}
1060+
compact={!workExpanded}
1061+
title={goalActive ? "Work" : "Tasks"}
1062+
/>
1063+
</Box>
1064+
) : null;
1065+
const acceptBlock =
1066+
goalActive && goalSnapshot !== null ? (
1067+
<Box flexDirection="column" marginTop={1} key="accept">
1068+
<GoalView goal={goalSnapshot} compact={!showAcceptance} />
1069+
</Box>
1070+
) : null;
1071+
const workAcceptBlocks = workPrimary ? (
1072+
<>
1073+
{workBlock}
1074+
{acceptBlock}
1075+
</>
1076+
) : (
1077+
<>
1078+
{acceptBlock}
1079+
{workBlock}
1080+
</>
1081+
);
1082+
1083+
const copyModeSelection = copyModeIndex ?? 0;
1084+
const { window: copyModeWindow, start: copyModeWindowStart } = windowedCopyTargets(
1085+
copyTargetList,
1086+
copyModeSelection,
1087+
);
1088+
10401089
return (
10411090
<Box flexDirection="column" height={rows}>
10421091
<Box flexShrink={0} flexDirection="column">
@@ -1209,35 +1258,7 @@ export function App({
12091258
)}
12101259
{!taskFullScreenOpen && (
12111260
<Box flexShrink={0} flexDirection="column">
1212-
{(() => {
1213-
const workBlock = hasActiveTasks(state.tasks) ? (
1214-
<Box flexDirection="column" marginTop={1} key="work">
1215-
<TaskView
1216-
tasks={state.tasks}
1217-
compact={!workExpanded}
1218-
title={goalActive ? "Work" : "Tasks"}
1219-
/>
1220-
</Box>
1221-
) : null;
1222-
const acceptBlock =
1223-
goalActive && goalSnapshot !== null ? (
1224-
<Box flexDirection="column" marginTop={1} key="accept">
1225-
<GoalView goal={goalSnapshot} compact={!showAcceptance} />
1226-
</Box>
1227-
) : null;
1228-
// implementing: Work on top; planning/reviewing/completed: Acceptance on top
1229-
return workPrimary ? (
1230-
<>
1231-
{workBlock}
1232-
{acceptBlock}
1233-
</>
1234-
) : (
1235-
<>
1236-
{acceptBlock}
1237-
{workBlock}
1238-
</>
1239-
);
1240-
})()}
1261+
{workAcceptBlocks}
12411262
{agentsStripVisible ? (
12421263
<Box flexDirection="column" marginTop={1}>
12431264
<AgentsStrip
@@ -1270,20 +1291,15 @@ export function App({
12701291
{copyModeOpen && (
12711292
<Box flexDirection="column" marginTop={1} borderStyle="round" borderColor={color("brand")} paddingX={1}>
12721293
<Text color={color("brand")} bold>Copy — ↑/↓ select · y/⏎ copy · a copy all · esc cancel</Text>
1273-
{(() => {
1274-
const windowSize = 6;
1275-
const sel = copyModeIndex ?? 0;
1276-
const start = Math.max(0, Math.min(sel - Math.floor(windowSize / 2), Math.max(0, copyTargetList.length - windowSize)));
1277-
return copyTargetList.slice(start, start + windowSize).map((target, i) => {
1278-
const idx = start + i;
1279-
const selected = idx === sel;
1280-
return (
1281-
<Text key={target.id} color={selected ? color("text") : color("muted")} dimColor={!selected}>
1282-
{selected ? "› " : " "}{target.label}: {target.preview}
1283-
</Text>
1284-
);
1285-
});
1286-
})()}
1294+
{copyModeWindow.map((target, i) => {
1295+
const idx = copyModeWindowStart + i;
1296+
const selected = idx === copyModeSelection;
1297+
return (
1298+
<Text key={target.id} color={selected ? color("text") : color("muted")} dimColor={!selected}>
1299+
{selected ? "› " : " "}{target.label}: {target.preview}
1300+
</Text>
1301+
);
1302+
})}
12871303
</Box>
12881304
)}
12891305
{exitConfirmOpen ? (

src/tui/components/agent-modal.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,12 @@ export function AgentModal({
785785
setFormError(null);
786786
});
787787

788+
const selectedProviderRow = providers[providerIndex];
789+
const showReauthHint =
790+
selectedProviderRow !== undefined &&
791+
(selectedProviderRow.codexProfile !== undefined || selectedProviderRow.xaiProfile !== undefined) &&
792+
unauthedProviders?.has(selectedProviderRow.name) === true;
793+
788794
return (
789795
<Box
790796
flexDirection="column"
@@ -832,15 +838,11 @@ export function AgentModal({
832838
</Box>
833839
);
834840
})}
835-
{(() => {
836-
const p = providers[providerIndex];
837-
const isUnauthed = p !== undefined && (p.codexProfile !== undefined || p.xaiProfile !== undefined) && unauthedProviders?.has(p.name) === true;
838-
return isUnauthed ? (
839-
<Box marginTop={1}>
840-
<Text color="red">Enter to re-authenticate</Text>
841-
</Box>
842-
) : null;
843-
})()}
841+
{showReauthHint ? (
842+
<Box marginTop={1}>
843+
<Text color="red">Enter to re-authenticate</Text>
844+
</Box>
845+
) : null}
844846
</Box>
845847
)}
846848

0 commit comments

Comments
 (0)