Skip to content

🤖 refactor: auto-cleanup#3662

Merged
ThomasK33 merged 4 commits into
mainfrom
auto-cleanup
Jul 1, 2026
Merged

🤖 refactor: auto-cleanup#3662
ThomasK33 merged 4 commits into
mainfrom
auto-cleanup

Conversation

@mux-bot

@mux-bot mux-bot Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Summary

This is the long-lived auto-cleanup PR. Each run, the auto-cleanup agent reviews new commits merged to main, rebases onto the latest main, and applies at most one extremely low-risk, behavior-preserving cleanup. The branch accumulates a small stack of independent cleanups until it is merged.

This run extracts the duplicated model-string normalization chain (trimtoLowerCase → strip provider: prefix → strip namespace/ segment) that anthropicSupportsNativeXhigh (src/common/types/thinking.ts) and getExplicitThinkingPolicy (src/common/utils/thinking/policy.ts) each inlined verbatim into a shared stripModelProviderPrefixes helper. This area was just touched by #3664 (Claude Sonnet 5), which relies on anthropicSupportsNativeXhigh for capability detection. Behavior-preserving.

Included cleanups (diff vs main)

  1. refactor: extract shared stripAnsiControlChars helpersrc/node/services/bashMonitorWakeStore.ts and src/node/services/backgroundProcessManager.ts each defined a byte-for-byte identical ANSI_ESCAPE_PATTERN regex and inlined the same strip-ANSI + drop-control-chars expression (sanitizeBashMonitorWakeLine / sanitizeMonitorLine). Both now import the new stripAnsiControlChars from src/node/utils/ansi.ts.
  2. refactor: dedupe InstructionsTab formatBytes into shared helpersrc/browser/components/InstructionsTab/InstructionsTab.tsx defined a local formatBytes(n) that was byte-for-byte identical (only the parameter name differed) to the already-shared formatBytes in src/common/utils/formatBytes.ts (used by FileReadToolCall, WebFetchToolCall, AttachFileToolCall, AgentSkillReadFileToolCall, and the CLI tool formatters). The local copy is removed and the shared helper is imported.
  3. refactor: drop dead hasTrailingNewline ternary branches in getOutputsrc/node/services/backgroundProcessManager.ts had two hasTrailingNewline ? allLines.slice(0, -1) : allLines.slice(0, -1) ternaries inside getOutput whose two branches were identical, so the condition never affected the result. Both are replaced with the unconditional allLines.slice(0, -1). In the first occurrence the now-unused hasTrailingNewline local is also removed; in the second it is kept because it is still consulted when computing incompleteLineBuffer.
  4. refactor: extract shared stripModelProviderPrefixes helperanthropicSupportsNativeXhigh (src/common/types/thinking.ts) and getExplicitThinkingPolicy (src/common/utils/thinking/policy.ts) each inlined the identical trim → toLowerCase → strip 'provider:' → strip 'namespace/' chain to reduce a model string to its bare model id for capability matching. The chain moves into a new exported stripModelProviderPrefixes helper in thinking.ts; both call sites now use it. In getExplicitThinkingPolicy the two intermediate locals (normalized, withoutPrefix) collapse into the single withoutProviderNamespace the helper returns.

Background

These cleanups remove duplicated or dead logic that drifts silently.

  • Runs 1–2 deduped byte-identical helpers (stripAnsiControlChars, formatBytes) that had been copied across files.
  • Run 3 followed up 🤖 fix: stop background monitor from re-waking on already-shown output #3663, which simplified the hasTrailingNewline ? X : X pattern in processMonitorContent but left two identical instances in getOutput untouched.
  • Run 4 targets the model-string normalization that 🤖 feat: add support for Claude Sonnet 5 #3664 (Claude Sonnet 5) leaned on: getExplicitThinkingPolicy and anthropicSupportsNativeXhigh both need the bare model id and had copy-pasted the same normalization. Consolidating it keeps capability predicates consistent about how provider: prefixes and gateway namespace/ segments are stripped.

Implementation

  • stripAnsiControlChars (run 1): new src/node/utils/ansi.ts strips ANSI/VT escape sequences and drops non-printable control characters (keeping tab and any code point >= 0x20). The regex was copied verbatim from the prior inline definitions, so it is byte-identical.
  • formatBytes dedup (run 2): the local function in InstructionsTab.tsx is deleted and formatBytes is imported from @/common/utils/formatBytes; the shared helper is character-for-character equivalent, so the single call site renders identical output.
  • hasTrailingNewline dedup (run 3): the two dead ternaries in getOutput collapse to allLines.slice(0, -1). The polling-loop occurrence dropped its hasTrailingNewline declaration (it had no other use in that scope); the final-processing occurrence keeps the declaration since proc.incompleteLineBuffer still reads !hasTrailingNewline.
  • stripModelProviderPrefixes (run 4): the new exported helper runs the same two .replace() calls in the same order as the prior inline chains, so it is behavior-identical. getThinkingDisplayLabel in the same file is intentionally left alone — it only strips the provider: prefix and still inspects withoutPrefix.startsWith("openai/"), so it needs the un-stripped namespace and does not fit this helper.

Validation

  • bun test src/common/utils/thinking/policy.test.ts src/common/utils/ai/providerOptions.test.ts src/common/utils/ai/models.test.ts src/common/utils/tools/tools.test.ts (226 pass) exercises the normalization paths.
  • make static-check passes for these TS-only changes (ESLint, both TypeScript configs, and Prettier all green). The run's only failure is fmt-shell-check aborting because shfmt is not installed in this environment; the changes touch no shell/Docker files.

Risks

None. All four cleanups are behavior-preserving: the shared helpers reuse the verbatim prior logic, and collapsing a cond ? X : X ternary cannot change the result since both branches are identical.


Auto-cleanup checkpoint: e1169d7


Generated with mux • Model: anthropic:claude-opus-4-8 • Thinking: xhigh • Cost: $0.00

@mux-bot

mux-bot Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

To use Codex here, create a Codex account and connect to github.

@mux-bot mux-bot Bot force-pushed the auto-cleanup branch from e56f60c to c5b64f9 Compare June 30, 2026 00:31
@mux-bot

mux-bot Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

To use Codex here, create a Codex account and connect to github.

@mux-bot mux-bot Bot force-pushed the auto-cleanup branch from c5b64f9 to 7ce9a2a Compare June 30, 2026 12:41
mux-bot Bot added 4 commits July 1, 2026 00:27
bashMonitorWakeStore and backgroundProcessManager each inlined an identical
ANSI_ESCAPE_PATTERN regex plus the same strip-ANSI + drop-control-chars
expression. Single-source both in src/node/utils/ansi.ts so the escape pattern
can't drift between the two terminal-output sanitizers. Behavior-preserving.
InstructionsTab.tsx defined a local formatBytes that was byte-for-byte
identical (only the parameter name differed) to the shared
formatBytes in @/common/utils/formatBytes. Import the shared helper
instead of maintaining a second copy. Behavior-preserving.
anthropicSupportsNativeXhigh (src/common/types/thinking.ts) and getExplicitThinkingPolicy (src/common/utils/thinking/policy.ts) each inlined the identical trim -> lowercase -> strip 'provider:' -> strip 'namespace/' chain to derive the bare model id. Extract it into a shared stripModelProviderPrefixes helper and reuse it in both. Behavior-preserving: the helper runs the same two .replace() calls in the same order.
@mux-bot mux-bot Bot force-pushed the auto-cleanup branch from 7ce9a2a to 72dfd0b Compare July 1, 2026 00:35
@mux-bot

mux-bot Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

New cleanup on this run: extracted the duplicated model-string normalization chain (trim → toLowerCase → strip provider:→ stripnamespace/) shared by anthropicSupportsNativeXhighandgetExplicitThinkingPolicyinto a single exportedstripModelProviderPrefixeshelper. Behavior-preserving (same two.replace()calls, same order). Checkpoint advanced toe1169d7` (#3664 Claude Sonnet 5).

@chatgpt-codex-connector

Copy link
Copy Markdown

To use Codex here, create a Codex account and connect to github.

@ThomasK33 ThomasK33 added this pull request to the merge queue Jul 1, 2026
Merged via the queue into main with commit c008165 Jul 1, 2026
24 checks passed
@ThomasK33 ThomasK33 deleted the auto-cleanup branch July 1, 2026 07:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant