🤖 refactor: auto-cleanup#3213
Conversation
708166d to
1312f5a
Compare
|
Failed job: Failures (both in
What I checked:
No fix pushed. A re-run of |
30461c6 to
07976fe
Compare
Replace the inline `theme === "light" || theme === "flexoki-light"` check in `getColorScheme` with the shared `isLightThemeMode` helper from `shiki-shared.ts`, so the `-light` suffix convention has a single source of truth and stays consistent with the syntax-highlighting call sites that already use it.
…stions The skill and model alias build callbacks in getSlashCommandSuggestions hardcode the trailing space, so the appendSpace: true property on those SuggestionDefinition literals is dead. Remove it and add a brief comment explaining why we don't propagate appendSpace through these paths so a future reader doesn't assume the field is consulted there.
The OpenAI service-tier literal union ('auto' | 'default' | 'flex' |
'priority') was duplicated in three places: the CLI options interface
(src/cli/run.ts), the providerModelFactory cast at the providers.jsonc
boundary, and a local OpenAIServiceTier alias in ProvidersSection.tsx.
ServiceTierSchema (src/common/config/schemas/providersConfig.ts)
already defines this enum as the runtime source of truth, so derive a
TypeScript ServiceTier alias via z.infer once and import it at each
site. Pure type-only refactor; the emitted JS and the schema remain
unchanged.
The shape `{ model: string; thinkingLevel?: ThinkingLevel }` (used
internally to read per-agent AI settings off partial workspace metadata)
was duplicated 7 times across the parameter and return types of
`resolveWorkspaceAISettings`, `resolveTaskAISettings`, and
`resolveParentAutoResumeOptions`. The new sub-agent defaults split
(#3215) made this duplication especially visible because it added a
third method copying the same inline shape.
Introduce a private `ResolvedWorkspaceAiSettings` interface at module
scope and use it everywhere. Pure type-level cleanup — emitted JS,
runtime behavior, and the schema-derived `WorkspaceAISettings` type
(where `thinkingLevel` is required) are all unchanged.
🤖 _Generated with `mux` • Model: `anthropic:claude-opus-4-7` • Thinking: `xhigh`_
In `src/node/services/tools/file_edit_insert.ts`, `GuardAnchors` was defined as `Pick<InsertContentOptions, "insert_before" | "insert_after">`, but `InsertContentOptions` itself is already `Pick<FileEditInsertToolArgs, "insert_before" | "insert_after">` after the `.nullish()` strict-mode refactor in #2250 stripped the `InsertContentOptions` interface down to those same two fields. The two aliases are now structurally identical, so `GuardAnchors` is dead. Drop the alias and use `InsertContentOptions` for the two callers (`insertWithGuards`, `resolveGuardAnchor`). Both names were file-local; no exports change. The function names (`insertWithGuards`, `resolveGuardAnchor`) already convey "guard" context, so the parameter type doesn't need to repeat it. Pure type-level cleanup — emitted JS, runtime behavior, and the public tool surface are all unchanged.
…ator Both stream-error rows in `buildDisplayedMessagesForMessage` (the existing `message.metadata?.error` branch and the new `finishReason === "length"` branch added in #3223) push structurally identical objects, differing only in `id` suffix, `error` string, and `errorType`. The shared parent-message-derived fields (`historyId`, `historySequence`, `model`, `routedThroughGateway`, `timestamp`) were duplicated across both pushes. Extract a local `pushStreamErrorRow` closure that captures the shared fields once. Each branch now reduces to a single call passing the three differing values. Pure refactor — emitted DisplayedMessage objects are identical.
…uilder The `isPlanHandoffAgent` boolean in `buildPlanInstructions` was extracted when the gate was `effectiveAgentId === "exec" || effectiveAgentId === "orchestrator"`. After #3224 ripped out the Orchestrator agent, the boolean collapsed to a single equality check (`effectiveAgentId === "exec"`), and the trailing `else if (isPlanHandoffAgent && chatHasStartHerePlanSummary)` redundantly re-evaluated the same gate just to log a debug line. Replace the flat `if/else if` with a nested `if (effectiveAgentId === "exec") { … }` that tests the Start Here summary inside, removing the duplicate gate re-check and the now-meaningless boolean. A short comment captures the rationale so a future reader doesn't reintroduce the alias. Pure refactor — emitted control flow, the debug log, and `planContentForTransition` assignments are identical, and the existing 8-test `streamContextBuilder.test.ts` suite passes unchanged (257 tests across the related taskService / modelMessageTransform / aiService suites also pass).
The second argument was named `_workspaceName` (underscore-prefixed = unused) since it was introduced in the original SSH runtime PR and has never been referenced by the function body. The /new simplification (#3230) made the noise especially visible: the new `createNewWorkspace` call site had to pass `options.workspaceName ?? "(auto-generated)"` purely to satisfy the signature, and added a comment claiming `parseRuntimeString only uses the name for error reporting context` — but the function never reads it. Drop the parameter from the signature, the placeholder + misleading comment at the only non-test caller, and the boilerplate `workspaceName` constant + 23 second-arguments in `chatCommands.test.ts`. Pure dead-parameter cleanup — emitted JS, error messages, and runtime behavior are all identical. Mobile already had the cleaner shape (`parseRuntimeStringForMobile(runtime?: string)`) so the desktop signature now matches it.
The early `dotParts.length < 2` return at the top of `parseBedrockModelName` already guarantees `dotParts.length >= 2` by the time we compute `secondPart`, so the `dotParts.length > 1 ? dotParts[1].toLowerCase() : ""` ternary's empty-string branch is unreachable. The Deepseek V4 commit (#3237) extended the surrounding logic but didn't introduce this asymmetry — `firstPart` on the line above already accesses `dotParts[0].toLowerCase()` without a guard, so the redundant ternary on `secondPart` was the odd one out. Inline to a direct `dotParts[1].toLowerCase()` access (matching `firstPart`'s shape) and capture the rationale in a one-line comment so a future reader doesn't reintroduce the guard. Pure dead-code cleanup — emitted JS, runtime behavior, and the existing 18-test `modelDisplay` suite (including the new DeepSeek + Bedrock cases) are all unchanged.
|
Failed job: Failing test: Why this looks flaky, not regression-caused:
No fix pushed — recommend re-running the failed job ( |
Summary
Long-lived auto-cleanup PR that accumulates low-risk, behavior-preserving refactors picked from recent
maincommits.Changes
Drop dead length guard in
parseBedrockModelNamesecondPartThe early
dotParts.length < 2return at the top ofparseBedrockModelName(insrc/common/utils/ai/modelDisplay.ts) already guaranteesdotParts.length >= 2by the timesecondPartis computed, which makes thedotParts.length > 1 ? dotParts[1].toLowerCase() : ""ternary's empty-string branch unreachable. The DeepSeek V4 commit (#3237) extended the surrounding formatter without touching this site, but the new DeepSeek branch made the asymmetry more obvious — the line directly above (firstPart) already accessesdotParts[0].toLowerCase()without a guard, so the ternary onsecondPartwas the odd one out.Inline to a direct
dotParts[1].toLowerCase()access (matchingfirstPart's shape) and capture the rationale in a one-line comment so a future reader doesn't reintroduce the guard. Pure dead-code cleanup — emitted JS, runtime behavior, and the existing 18-testmodelDisplaysuite (including the new DeepSeek + existing Bedrock cases) are all unchanged.Previous cleanups
Drop unused
workspaceNameparam fromparseRuntimeStringThe second argument to
parseRuntimeString(insrc/browser/utils/chatCommands.ts) was named_workspaceName(underscore-prefixed = unused) when it was introduced in the original SSH runtime PR, and has never been referenced by the function body — error messages are all generic and don't include any workspace-specific context.The
/new-mirrors-/forksimplification (#3230) made the noise especially visible: the newcreateNewWorkspacecall site had to passoptions.workspaceName ?? "(auto-generated)"purely to satisfy the signature, and added a comment claimingparseRuntimeString only uses the name for error reporting context— but the function never reads it. Mobile already had the cleaner shape (parseRuntimeStringForMobile(runtime?: string)).Drop the parameter from the signature, drop the placeholder + misleading comment at the only non-test caller (
createNewWorkspace), and drop theworkspaceName = "test-workspace"constant + 23 second-arguments inchatCommands.test.ts. Pure dead-parameter cleanup — emitted JS, error messages, and runtime behavior are all identical, and the desktop signature now matches mobile's.Drop redundant
isPlanHandoffAgentboolean instreamContextBuilderThe
isPlanHandoffAgentboolean inbuildPlanInstructionswas extracted when the gate waseffectiveAgentId === "exec" || effectiveAgentId === "orchestrator". After #3224 ripped out the Orchestrator agent, the boolean collapsed to a single equality check (effectiveAgentId === "exec"), and the trailingelse if (isPlanHandoffAgent && chatHasStartHerePlanSummary)redundantly re-evaluated the same gate just to log a debug line.Replace the flat
if/else ifwith a nestedif (effectiveAgentId === "exec") { … }that tests the Start Here summary inside, removing the duplicate gate re-check and the now-meaningless boolean. A short comment captures the rationale so a future reader doesn't reintroduce the alias.Pure refactor — emitted control flow, the debug log, and
planContentForTransitionassignments are identical.Extract
seedScrollDirectionBaselinehelper inuseAutoScrolluseAutoScroll(touched by #3226) seedslastScrollTopReffrom two call sites —jumpToBottomanddisableAutoScroll— to keephandleScroll's released-branch direction check (currentScrollTop > previousScrollTop) honest after a programmatic ownership transfer that may not produce a follow-up scroll event. Both sites repeated the same write (lastScrollTopRef.current = contentRef.current?.scrollTop ?? 0) and a multi-line block comment re-explaining the same shared rationale.Extract a
seedScrollDirectionBaselineuseCallbackwith the shared rationale captured once on the helper itself. Each call site reduces to a single call plus a one-line comment naming the site-specific reason it doesn't get a free scroll-event refresh (stickToBottomskips the write at max;disableAutoScrollnever fires a scroll event itself). The dependency arrays forjumpToBottomanddisableAutoScrolladd the new helper, which has empty deps (useCallback(..., [])) so its identity is stable across renders — no extra re-creations of the surrounding callbacks.This shrinks the surface area for future drift: a third path that needs to flip
autoScrollRef/programmaticDisableRefwithout a guaranteed scroll-event tail (e.g. the deferred workspace-switch hydration race called out in #3226's "Pains") can call the helper instead of duplicating the rationale a third time. Pure refactor — emitted writes, write order, and ref values are identical, and the existing 25-testuseAutoScrollsuite (including the 6 new regression tests added in #3226) passes unchanged.Extract
pushStreamErrorRowhelper inStreamingMessageAggregatorbuildDisplayedMessagesForMessagenow has two branches that synthesize astream-errorDisplayedMessage: the existingmessage.metadata?.errorpath and thefinishReason === "length"path added in #3223. Both pushes were structurally identical, differing only inidsuffix,errorstring, anderrorType— the parent-message-derived fields (historyId,historySequence,model,routedThroughGateway,timestamp) were duplicated across both call sites.Extract a local
pushStreamErrorRowclosure that captures the shared fields once. Each branch reduces to a single call passing the three differing values. Themodelaccess switches frommessage.metadata.model(which relied on the outerif (message.metadata?.error)narrowing) tomessage.metadata?.model, which is functionally identical whenmetadatais defined and falls through toundefinedotherwise — same emitted value either way.This shrinks the surface area for future drift: the next branch added (e.g. a different finish-reason synthesis) can't accidentally pass a stale
modelor forgetroutedThroughGateway. Pure refactor — emittedDisplayedMessageobjects are identical, and the existing 77-test SMA suite (including the 6 new max-tokens tests) passes unchanged.Drop redundant
GuardAnchorstype alias infile_edit_insertIn
src/node/services/tools/file_edit_insert.ts,GuardAnchorswas defined asPick<InsertContentOptions, "insert_before" | "insert_after">, butInsertContentOptionsitself is alreadyPick<FileEditInsertToolArgs, "insert_before" | "insert_after">after the.nullish()strict-mode refactor in #2250 stripped theInsertContentOptionsinterface down to those same two fields. The two aliases became structurally identical, soGuardAnchorsis dead.Drop the alias and use
InsertContentOptionsfor the two callers (insertWithGuards,resolveGuardAnchor). Both names were file-local; no exports change. The function names already convey "guard" context, so the parameter type doesn't need to repeat it. This noise was especially visible to the new guardless-empty-file path added in #3220 since it sits next toinsertContentwhich usesInsertContentOptions.Pure type-level cleanup — emitted JS, runtime behavior, and the public tool surface are all unchanged.
Extract
ResolvedWorkspaceAiSettingstype alias intaskServiceThe shape
{ model: string; thinkingLevel?: ThinkingLevel }(used internally to read per-agent AI settings off partial workspace metadata) was duplicated 7 times across the parameter and return types ofresolveWorkspaceAISettings,resolveTaskAISettings, andresolveParentAutoResumeOptionsinsrc/node/services/taskService.ts. The new sub-agent defaults split (#3215) made this duplication especially visible because it added a third method copying the same inline shape.A private
ResolvedWorkspaceAiSettingsinterface at module scope replaces all 7 inline occurrences. Pure type-level cleanup — emitted JS, runtime behavior, and the schema-derivedWorkspaceAISettingstype (wherethinkingLevelis required) are all unchanged. The new interface is intentionally local to this file (not exported) since it captures the looser internal-reader shape, distinct from the canonical schema-derived type.Extract shared
ServiceTiertype fromServiceTierSchemaThe OpenAI service-tier literal union (
"auto" | "default" | "flex" | "priority") was duplicated in three places: the CLI options interface (src/cli/run.ts), theproviderModelFactorycast at theproviders.jsoncboundary (src/node/services/providerModelFactory.ts), and a localOpenAIServiceTieralias inProvidersSection.tsx.ServiceTierSchema(src/common/config/schemas/providersConfig.ts) already defines the same enum as the runtime source of truth, so this change derives a TypeScriptServiceTieralias viaz.inferonce and imports it at each site.The Settings UI keeps its
OpenAIServiceTierlocal alias (used byOpenAIServiceTierSelectValueand theisOpenAIServiceTiertype guard) but it is nowtype OpenAIServiceTier = ServiceTier, so the disambiguating name and call sites stay intact.Drop unused
appendSpaceliterals on skill/model alias suggestionsIn
src/browser/utils/slashCommands/suggestions.ts, theSuggestionDefinitionliterals built for agent skills and model alias one-shots setappendSpace: true, but the build callbacks for those two paths hardcode the trailing space and never readdefinition.appendSpace. Only the top-level command and subcommand build callbacks consult the field. Remove the no-opappendSpace: truefrom the skill and model alias mappings and leave a short comment near each so a future reader doesn't assume the field is consulted on these paths.Behavior is preserved — the field is unread on these paths, and the existing
suggestions.test.ts/inlineSkillSuggestions.test.ts/suggestionMatching.test.tssuites all still pass.Route
ThemeContextcolor-scheme throughisLightThemeModeReplace the inline
theme === "light" || theme === "flexoki-light"check ingetColorScheme(insrc/browser/contexts/ThemeContext.tsx) with the sharedisLightThemeModehelper fromsrc/browser/utils/highlighting/shiki-shared.ts.The helper was just introduced as the single source of truth for the
-lightsuffix → light-theme mapping, and the highlighting call sites (MarkdownComponents,HighlightedCode,highlightDiffChunk) already use it. This change extends that convention toThemeContextso a future palette likesolarized-lightwould automatically map tocolorScheme: "light"without revisiting this site.Behavior is preserved: for the four valid
ThemeModevalues ("light","dark","flexoki-light","flexoki-dark"),isLightThemeModereturns the same result as the previous explicit comparison.Validation
bun test src/common/utils/ai/modelDisplay.test.ts— 18/18 pass (covers the touched Bedrock branch plus the new DeepSeek cases).make static-check— eslint, tsgo (×2), prettier all pass; onlyshfmtfails because the binary is unavailable in this environment, and no shell files are touched.Risks
Minimal — purely a dead-code cleanup. The
dotParts.length < 2early return above the touched line guaranteesdotParts[1]exists, so removing the ternary's unreachable empty-string fallback cannot change which model IDsparseBedrockModelNameaccepts or rejects. The change is also symmetrical with the pre-existing unguardedfirstPart = dotParts[0].toLowerCase()access on the line directly above.Auto-cleanup checkpoint: 9854990
Generated with
mux• Model:anthropic:claude-opus-4-7• Thinking:xhigh