refactor: small cleanups from review of the Hermes UI commits
Three independent tidies, none behavioral: - The "fall back to the sole new-thread destination" logic existed twice with near-identical comments — in the palette's new-thread action and the sidebar's new-thread button. Extracted as `resolveSoleNewThreadProjectRef` next to `startNewThreadFromContext`, so the "only when there is exactly one target" rule cannot drift between the two call sites. - The notification-body heading demotion in index.css had the same specificity as the base `.chat-markdown h1` rules and matched the same element (both classes land on one root div), so it won purely by sitting later in the file — a reorder or cascade-layer change would silently undo it. The compound `.chat-markdown.chat-markdown-notification-body` selector out-specifies the base rules regardless of source order. - Dropped a useMemo wrapping `isHomeThreadId` in ChatComposer: a `.some()` over a handful of provider snapshots costs less than the memo bookkeeping. Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
1 parent
0790133072
commit
1d23dec384
5 files changed
+37
-28
No files matched your search
@@ -58,7 +58,11 @@ import { useAtomCommand } from "../state/use-atom-command";
|
||||
import { useAtomQueryRunner } from "../state/use-atom-query-runner";
|
||||
import { useEnvironments, usePrimaryEnvironmentId } from "../state/environments";
|
||||
import { useProjects, useThreadShells } from "../state/entities";
|
||||
import { resolveThreadActionProjectRef, startNewThreadFromContext } from "../lib/chatThreadActions";
|
||||
import {
|
||||
resolveSoleNewThreadProjectRef,
|
||||
resolveThreadActionProjectRef,
|
||||
startNewThreadFromContext,
|
||||
} from "../lib/chatThreadActions";
|
||||
import {
|
||||
appendBrowsePathSegment,
|
||||
canNavigateUp,
|
||||
@@ -1214,13 +1218,7 @@ function OpenCommandPaletteDialog(props: {
|
||||
const activeProjectTitle =
|
||||
projectPickerEntries.find((entry) => entry.isPreferred)?.group.displayName ??
|
||||
(currentProjectId ? (projectTitleById.get(currentProjectId) ?? null) : null);
|
||||
// Only meaningful when there is exactly one destination; with several,
|
||||
// an absent `defaultProjectRef` means "no obvious target" and the user
|
||||
// should pick from the submenu rather than have one chosen for them.
|
||||
const soleNewThreadProjectRef =
|
||||
newThreadProjectTargets.length === 1 && newThreadProjectTargets[0]
|
||||
? scopeProjectRef(newThreadProjectTargets[0].environmentId, newThreadProjectTargets[0].id)
|
||||
: null;
|
||||
const soleNewThreadProjectRef = resolveSoleNewThreadProjectRef(newThreadProjectTargets);
|
||||
|
||||
if (activeProjectTitle) {
|
||||
actionItems.push({
|
||||
|
||||
@@ -87,7 +87,10 @@ import { useThreadSelectionStore } from "../threadSelectionStore";
|
||||
import { useThreadActions } from "../hooks/useThreadActions";
|
||||
import { useHandleNewThread } from "../hooks/useHandleNewThread";
|
||||
import { openCommandPalette } from "../commandPaletteBus";
|
||||
import { startNewThreadFromContext } from "../lib/chatThreadActions";
|
||||
import {
|
||||
resolveSoleNewThreadProjectRef,
|
||||
startNewThreadFromContext,
|
||||
} from "../lib/chatThreadActions";
|
||||
import { useClientSettings, useUpdateClientSettings } from "../hooks/useSettings";
|
||||
import { useCopyToClipboard } from "../hooks/useCopyToClipboard";
|
||||
import { useNowMinute } from "../hooks/useNowMinute";
|
||||
@@ -2257,17 +2260,11 @@ export default function SidebarV2() {
|
||||
// One project: nothing to pick, create immediately.
|
||||
if (projectGroups.length <= 1) {
|
||||
if (isMobile) setOpenMobile(false);
|
||||
// `defaultProjectRef` deliberately resolves to workspaces only, so a
|
||||
// user whose sole project is an agent has none — without this fallback
|
||||
// `startNewThreadFromContext` returns false and the click does nothing.
|
||||
const onlyGroup = projectGroups[0];
|
||||
const fallbackProjectRef =
|
||||
newThreadContext.defaultProjectRef ??
|
||||
(onlyGroup ? scopeProjectRef(onlyGroup.environmentId, onlyGroup.id) : null);
|
||||
void startNewThreadFromContext({
|
||||
activeDraftThread: newThreadContext.activeDraftThread,
|
||||
activeThread: newThreadContext.activeThread ?? undefined,
|
||||
defaultProjectRef: fallbackProjectRef,
|
||||
defaultProjectRef:
|
||||
newThreadContext.defaultProjectRef ?? resolveSoleNewThreadProjectRef(projectGroups),
|
||||
handleNewThread: newThreadContext.handleNewThread,
|
||||
});
|
||||
return;
|
||||
|
||||
@@ -909,10 +909,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
// `thread.create` fixes both, and Hermes sets
|
||||
// `requiresNewThreadForModelChange`. A picker there would offer a choice
|
||||
// that cannot be taken, so the chip renders as a static label instead.
|
||||
const isHomeThread = useMemo(
|
||||
() => isHomeThreadId(providerStatuses, activeThread?.id),
|
||||
[activeThread?.id, providerStatuses],
|
||||
);
|
||||
const isHomeThread = isHomeThreadId(providerStatuses, activeThread?.id);
|
||||
|
||||
const { modelOptions: composerModelOptions, selectedModel } = useEffectiveComposerModelState({
|
||||
threadRef: composerDraftTarget,
|
||||
|
||||
+12
-7
@@ -1139,23 +1139,28 @@ label:has(> select#reasoning-effort) select {
|
||||
* while leaving the real heading the largest thing in the block. The first
|
||||
* heading also loses its top margin, since the header rule above it is
|
||||
* already the separation.
|
||||
*
|
||||
* The compound `.chat-markdown.…` selector out-specifies the base
|
||||
* `.chat-markdown h1` rules regardless of source order — both classes land on
|
||||
* the same root div, so a single-class selector would win or lose purely on
|
||||
* position in this file.
|
||||
*/
|
||||
.chat-markdown-notification-body h1 {
|
||||
.chat-markdown.chat-markdown-notification-body h1 {
|
||||
font-size: 1.0625rem;
|
||||
}
|
||||
|
||||
.chat-markdown-notification-body h2 {
|
||||
.chat-markdown.chat-markdown-notification-body h2 {
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.chat-markdown-notification-body h3,
|
||||
.chat-markdown-notification-body h4,
|
||||
.chat-markdown-notification-body h5,
|
||||
.chat-markdown-notification-body h6 {
|
||||
.chat-markdown.chat-markdown-notification-body h3,
|
||||
.chat-markdown.chat-markdown-notification-body h4,
|
||||
.chat-markdown.chat-markdown-notification-body h5,
|
||||
.chat-markdown.chat-markdown-notification-body h6 {
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.chat-markdown-notification-body > :first-child {
|
||||
.chat-markdown.chat-markdown-notification-body > :first-child {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,6 +48,18 @@ export function resolveThreadActionProjectRef(
|
||||
return context.defaultProjectRef;
|
||||
}
|
||||
|
||||
// `defaultProjectRef` resolves to workspaces only by design, so a user whose
|
||||
// sole project is an agent has none — and "new thread" would silently no-op.
|
||||
// The fallback applies only when there is exactly one destination: with
|
||||
// several, an absent default means "no obvious target" and the user should
|
||||
// pick rather than have one chosen for them.
|
||||
export function resolveSoleNewThreadProjectRef(
|
||||
targets: ReadonlyArray<{ environmentId: EnvironmentId; id: ProjectId }>,
|
||||
): ScopedProjectRef | null {
|
||||
const sole = targets.length === 1 ? targets[0] : undefined;
|
||||
return sole ? scopeProjectRef(sole.environmentId, sole.id) : null;
|
||||
}
|
||||
|
||||
// New threads inherit only the *project* from the current context. Branch,
|
||||
// worktree, and env mode always come from the user's configured defaults —
|
||||
// carrying them over from the viewed thread meant "new thread" silently
|
||||
|
||||
Reference in new issue
Block a user