fix(typecheck): replace dead-code literal comparisons with isAntEmployee()#1512
Conversation
…isAntEmployee() The build system replaces process.env.USER_TYPE with the string literal 'external' at build time. Dead-code elimination then removes branches where 'external' === 'ant'. But TypeScript sees these as impossible comparisons (TS2367) because the narrowed literal type 'external' never equals 'ant', producing 90 type errors across 27 files. Replace all 'external === 'ant'' with isAntEmployee() and 'external !== 'ant'' with !isAntEmployee(). The function already exists in src/utils/buildConfig.ts and always returns false, so this is a behavioral no-op that makes the intent explicit and type-safe. The process.env.USER_TYPE === 'ant' pattern in other files is not touched; it will be addressed in a follow-up. Refs: Gitlawb#1486
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📜 Recent review details🧰 Additional context used📓 Path-based instructions (2)**/*⚙️ CodeRabbit configuration file
Files:
{bin/**,scripts/**,package.json,src/setup.ts,src/main.tsx,src/entrypoints/**}⚙️ CodeRabbit configuration file
Files:
🧠 Learnings (1)📚 Learning: 2026-06-03T16:06:34.975ZApplied to files:
🔇 Additional comments (2)
📝 WalkthroughWalkthroughReplace many ad-hoc "external" === 'ant' checks with a centralized isAntEmployee() predicate and a build-time IS_ANT_EMPLOYEE constant across startup, CLI, commands, tools, UI components, utilities, and the build plugin. ChangesAnt employee feature gating refactor
Estimated code review effort🎯 4 (Complex) | ⏱️ ~75 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 6 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (6 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
…r DCE The bundler cannot dead-code-eliminate branches guarded by isAntEmployee() because it's an opaque function call. Extend the feature-flag preprocess plugin to also replace isAntEmployee() with false during bundling, so dynamic import() and require() calls gated behind ant-employee checks are eliminated from the external build. Also export IS_ANT_EMPLOYEE as a named constant for call-site readability and documentation, with the function kept as a convenience wrapper.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/main.tsx`:
- Line 3026: The dynamic imports guarded by the runtime isAntEmployee() (e.g.,
const sessionUploaderPromise = isAntEmployee() ?
import('./utils/sessionDataUploader.js') : null) cause bundlers to attempt
resolving non-existent ant-only modules; introduce an exported compile-time
boolean flag (e.g., export const IS_ANT_EMPLOYEE = false) and change guards to
use that flag for all ant-only dynamic imports/commands (sessionUploaderPromise
and the cli imports like 'src/cli/up.js' and 'src/cli/rollback.js') so the
bundler can prune those branches, while keeping isAntEmployee() for any real
runtime checks that remain. Ensure you export IS_ANT_EMPLOYEE from a central
config file and replace occurrences of isAntEmployee() in import guards with
IS_ANT_EMPLOYEE, leaving isAntEmployee() intact for runtime logic.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 7d79e2b7-2c2f-4356-853f-d56dd902a682
📒 Files selected for processing (27)
src/buddy/useBuddyNotification.tsxsrc/commands/mcp/mcp.tsxsrc/commands/terminalSetup/terminalSetup.tsxsrc/commands/thinkback/thinkback.tsxsrc/commands/ultraplan.tsxsrc/components/DevBar.tsxsrc/components/FeedbackSurvey/useMemorySurvey.tsxsrc/components/LogoV2/feedConfigs.tsxsrc/components/MemoryUsageIndicator.tsxsrc/components/MessageSelector.tsxsrc/components/NativeAutoUpdater.tsxsrc/components/PromptInput/PromptInput.tsxsrc/components/PromptInput/PromptInputFooter.tsxsrc/components/PromptInput/PromptInputFooterLeftSide.tsxsrc/components/Settings/Config.tsxsrc/components/Stats.tsxsrc/components/agents/ToolSelector.tsxsrc/components/messages/AttachmentMessage.tsxsrc/components/tasks/taskStatusUtils.tsxsrc/main.tsxsrc/screens/REPL.tsxsrc/tools/AgentTool/AgentTool.tsxsrc/tools/AgentTool/UI.tsxsrc/tools/TaskOutputTool/TaskOutputTool.tsxsrc/tools/TaskStopTool/UI.tsxsrc/utils/autoRunIssue.tsxsrc/utils/processUserInput/processSlashCommand.tsx
📜 Review details
🧰 Additional context used
📓 Path-based instructions (3)
**/*
⚙️ CodeRabbit configuration file
**/*: Apply the OpenClaude maintainer review rubric from AGENTS.md. Review the current diff, not stale discussion context. Separate real blockers from suggestions. Do not request changes for vague style churn. Treat approval as merge-ready from CodeRabbit's side, pending required human review and GitHub Checks. If checks are failing or unavailable, say so clearly instead of implying the PR is fully ready.
Files:
src/components/tasks/taskStatusUtils.tsxsrc/components/MemoryUsageIndicator.tsxsrc/commands/terminalSetup/terminalSetup.tsxsrc/components/LogoV2/feedConfigs.tsxsrc/components/DevBar.tsxsrc/components/NativeAutoUpdater.tsxsrc/components/agents/ToolSelector.tsxsrc/commands/mcp/mcp.tsxsrc/commands/thinkback/thinkback.tsxsrc/components/FeedbackSurvey/useMemorySurvey.tsxsrc/tools/TaskOutputTool/TaskOutputTool.tsxsrc/commands/ultraplan.tsxsrc/tools/TaskStopTool/UI.tsxsrc/components/messages/AttachmentMessage.tsxsrc/components/PromptInput/PromptInputFooter.tsxsrc/tools/AgentTool/UI.tsxsrc/components/Stats.tsxsrc/utils/autoRunIssue.tsxsrc/buddy/useBuddyNotification.tsxsrc/components/PromptInput/PromptInputFooterLeftSide.tsxsrc/tools/AgentTool/AgentTool.tsxsrc/components/PromptInput/PromptInput.tsxsrc/components/Settings/Config.tsxsrc/utils/processUserInput/processSlashCommand.tsxsrc/components/MessageSelector.tsxsrc/screens/REPL.tsxsrc/main.tsx
src/{components/permissions,utils/permissions,hooks/toolPermission,tools,entrypoints/sdk}/**
⚙️ CodeRabbit configuration file
src/{components/permissions,utils/permissions,hooks/toolPermission,tools,entrypoints/sdk}/**: Review permission prompts, auto-allow logic, sandbox behavior, SDK permission schemas, shell/PowerShell execution, and background execution paths as security-sensitive. Block on bypasses, unclear trust boundaries, unsafe path handling, missing user visibility, or changes that broaden allowed behavior without an explicit maintainer decision.
Files:
src/tools/TaskOutputTool/TaskOutputTool.tsxsrc/tools/TaskStopTool/UI.tsxsrc/tools/AgentTool/UI.tsxsrc/tools/AgentTool/AgentTool.tsx
{bin/**,scripts/**,package.json,src/setup.ts,src/main.tsx,src/entrypoints/**}
⚙️ CodeRabbit configuration file
{bin/**,scripts/**,package.json,src/setup.ts,src/main.tsx,src/entrypoints/**}: Review install, launcher, build, packaging, startup, and entrypoint changes for cross-platform compatibility, tracked-source rewrites, env/config precedence, and release safety. Block on changes that can break Windows/macOS/Linux startup or publish unexpected artifacts.
Files:
src/main.tsx
🪛 GitHub Actions: PR Checks / 1_smoke-and-tests.txt
src/main.tsx
[error] 3025-3025: Build failed: Bun could not resolve "./utils/sessionDataUploader.js". Error at /home/runner/work/openclaude/openclaude/src/main.tsx:3025:61.
[error] 4352-4352: Build failed: Bun could not resolve "src/cli/up.js" (maybe you need to run "bun install"). Error at /home/runner/work/openclaude/openclaude/src/main.tsx:4352:24.
[error] 4367-4367: Build failed: Bun could not resolve "src/cli/rollback.js" (maybe you need to run "bun install"). Error at /home/runner/work/openclaude/openclaude/src/main.tsx:4367:24.
🪛 GitHub Actions: PR Checks / smoke-and-tests
src/main.tsx
[error] 3025-3025: Bundling failed: Could not resolve "./utils/sessionDataUploader.js" (import in main.tsx).
[error] 4352-4352: Bundling failed: Could not resolve "src/cli/up.js". Maybe you need to "bun install"?
[error] 4367-4367: Bundling failed: Could not resolve "src/cli/rollback.js". Maybe you need to "bun install"?
🔇 Additional comments (28)
src/components/PromptInput/PromptInput.tsx (1)
127-127: LGTM!Also applies to: 309-310, 406-406, 475-475, 1820-1820, 1828-1828, 1891-1891
src/components/PromptInput/PromptInputFooter.tsx (1)
26-26: LGTM!Also applies to: 147-147, 151-151
src/components/PromptInput/PromptInputFooterLeftSide.tsx (1)
44-44: LGTM!Also applies to: 264-264, 278-278, 369-369, 403-403
src/components/Settings/Config.tsx (1)
52-52: LGTM!Also applies to: 435-435
src/commands/thinkback/thinkback.tsx (1)
26-26: LGTM!Also applies to: 33-33, 36-36
src/commands/ultraplan.tsx (1)
19-19: LGTM!Also applies to: 57-57, 467-467
src/commands/mcp/mcp.tsx (1)
9-9: LGTM!Also applies to: 81-81
src/commands/terminalSetup/terminalSetup.tsx (1)
23-23: LGTM!Also applies to: 123-123
src/tools/AgentTool/AgentTool.tsx (1)
102-102: LGTM!Also applies to: 196-196, 469-469, 559-559, 1335-1337
src/tools/AgentTool/UI.tsx (1)
32-32: LGTM!Also applies to: 102-102, 388-388, 594-594
src/tools/TaskOutputTool/TaskOutputTool.tsx (1)
30-30: LGTM!Also applies to: 165-165
src/tools/TaskStopTool/UI.tsx (1)
7-7: LGTM!Also applies to: 29-29
src/buddy/useBuddyNotification.tsx (1)
8-8: LGTM!Also applies to: 14-14, 19-19
src/components/LogoV2/feedConfigs.tsx (1)
12-12: LGTM!Also applies to: 31-31, 49-49, 51-51
src/components/MemoryUsageIndicator.tsx (1)
5-5: LGTM!Also applies to: 11-11
src/components/MessageSelector.tsx (1)
32-32: LGTM!Also applies to: 123-123
src/components/NativeAutoUpdater.tsx (1)
15-15: LGTM!Also applies to: 188-188
src/components/DevBar.tsx (1)
6-6: LGTM!Also applies to: 10-10
src/components/FeedbackSurvey/useMemorySurvey.tsx (1)
17-17: LGTM!Also applies to: 79-80
src/components/Stats.tsx (1)
27-27: LGTM!Also applies to: 516-516, 1155-1155
src/components/agents/ToolSelector.tsx (1)
31-31: LGTM!Also applies to: 62-62
src/components/messages/AttachmentMessage.tsx (1)
31-31: LGTM!Also applies to: 118-118
src/components/tasks/taskStatusUtils.tsx (1)
12-12: LGTM!Also applies to: 100-100
src/utils/autoRunIssue.tsx (1)
7-7: LGTM!Also applies to: 85-86, 104-105
src/utils/processUserInput/processSlashCommand.tsx (1)
49-49: LGTM!Also applies to: 277-279, 431-443, 502-514
src/screens/REPL.tsx (3)
109-115: LGTM!Also applies to: 231-233, 305-305, 626-626, 804-804, 1087-1087, 2158-2161, 2597-2597, 2967-2967, 3102-3102, 3258-3258, 4242-4242, 4351-4351, 4760-4760, 4984-4994, 5077-5077, 5171-5171
109-115: Please re-verify dead-code elimination still strips internal-only modules/strings in external artifacts.These guards now hinge on
isAntEmployee()calls rather than literal comparisons. Please confirm release bundles still exclude Ant-only payloads (including org-warning/internal callout modules) as intended.Also applies to: 231-233, 4242-4272
305-305: GitHub Checks status isn’t visible in this review context.Please confirm required checks are green before merge.
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
scripts/build.ts (1)
78-96: 🧹 Nitpick | 🔵 Trivial | ⚡ Quick winscripts/build.ts: harden
isAntEmployee()preprocessing to avoid future over-broad rewritesIn this repo’s current
src/, everyisAntEmployee()occurrence is a bare call (noobj.isAntEmployee()/?.isAntEmployee()cases), and the regex does not rewrite theexport function isAntEmployee()declaration (0 matches insrc/utils/buildConfig.ts). The transform can still rewrite the token in non-code contexts, so tighten the regex to explicitly exclude member-call patterns while keeping the existing function-declaration exclusion.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@scripts/build.ts` around lines 78 - 96, The regex isAntEmployeeCallRe is too broad and can rewrite occurrences that are member calls; update isAntEmployeeCallRe inside featureFlagPreprocessPlugin to explicitly exclude member-call patterns by adding negative lookbehinds for '.' and '?.' (e.g. use a pattern like (?<!(?:\bfunction\s|\.|\?\.))\bisAntEmployee\(\)/g) so it still excludes the function declaration but will not match obj.isAntEmployee() or obj?.isAntEmployee().
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@scripts/build.ts`:
- Around line 78-96: The regex isAntEmployeeCallRe is too broad and can rewrite
occurrences that are member calls; update isAntEmployeeCallRe inside
featureFlagPreprocessPlugin to explicitly exclude member-call patterns by adding
negative lookbehinds for '.' and '?.' (e.g. use a pattern like
(?<!(?:\bfunction\s|\.|\?\.))\bisAntEmployee\(\)/g) so it still excludes the
function declaration but will not match obj.isAntEmployee() or
obj?.isAntEmployee().
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 7e4d5db7-89af-40c6-9011-a98699a6b773
📒 Files selected for processing (2)
scripts/build.tssrc/utils/buildConfig.ts
📜 Review details
🧰 Additional context used
📓 Path-based instructions (2)
**/*
⚙️ CodeRabbit configuration file
**/*: Apply the OpenClaude maintainer review rubric from AGENTS.md. Review the current diff, not stale discussion context. Separate real blockers from suggestions. Do not request changes for vague style churn. Treat approval as merge-ready from CodeRabbit's side, pending required human review and GitHub Checks. If checks are failing or unavailable, say so clearly instead of implying the PR is fully ready.
Files:
src/utils/buildConfig.tsscripts/build.ts
{bin/**,scripts/**,package.json,src/setup.ts,src/main.tsx,src/entrypoints/**}
⚙️ CodeRabbit configuration file
{bin/**,scripts/**,package.json,src/setup.ts,src/main.tsx,src/entrypoints/**}: Review install, launcher, build, packaging, startup, and entrypoint changes for cross-platform compatibility, tracked-source rewrites, env/config precedence, and release safety. Block on changes that can break Windows/macOS/Linux startup or publish unexpected artifacts.
Files:
scripts/build.ts
🔇 Additional comments (1)
src/utils/buildConfig.ts (1)
20-24: LGTM!
…guards
CodeRabbit review identified that isAntEmployee() is a runtime function call
that bundlers cannot evaluate for DCE. Replace all isAntEmployee() guards on
dynamic import()/require() calls of ant-internal modules with the
IS_ANT_EMPLOYEE boolean constant (exported as `false as const`), which the
build-time source transform can replace with a literal `false` for DCE.
Also extend the featureFlagPreprocessPlugin to replace IS_ANT_EMPLOYEE with
false during bundling, and clean up the resulting dead imports/exports
(`import { false, isAntEmployee }` → `import { isAntEmployee }`,
`export const false = false as const` → removed).
Affected ant-only modules (all missing from OpenClaude, must be DCE'd):
- sessionDataUploader.js, eventLoopStallDetector.js, sdkHeapDumpMonitor.js
- ccshareResume.js, cli/up.js, cli/rollback.js, cli/handlers/ant.js
- useFrustrationDetection.js, useAntOrgWarningNotification.js
- AntModelSwitchCallout.js, UndercoverAutoCallout.js
jatmn
left a comment
There was a problem hiding this comment.
Thanks for the contribution. I do not see any actionable issues from my review.
…yee() (Gitlawb#1512) * fix(typecheck): replace 'external' === 'ant' dead-code literals with isAntEmployee() The build system replaces process.env.USER_TYPE with the string literal 'external' at build time. Dead-code elimination then removes branches where 'external' === 'ant'. But TypeScript sees these as impossible comparisons (TS2367) because the narrowed literal type 'external' never equals 'ant', producing 90 type errors across 27 files. Replace all 'external === 'ant'' with isAntEmployee() and 'external !== 'ant'' with !isAntEmployee(). The function already exists in src/utils/buildConfig.ts and always returns false, so this is a behavioral no-op that makes the intent explicit and type-safe. The process.env.USER_TYPE === 'ant' pattern in other files is not touched; it will be addressed in a follow-up. Refs: Gitlawb#1486 * fix(build): replace isAntEmployee() calls with false at build time for DCE The bundler cannot dead-code-eliminate branches guarded by isAntEmployee() because it's an opaque function call. Extend the feature-flag preprocess plugin to also replace isAntEmployee() with false during bundling, so dynamic import() and require() calls gated behind ant-employee checks are eliminated from the external build. Also export IS_ANT_EMPLOYEE as a named constant for call-site readability and documentation, with the function kept as a convenience wrapper. * fix(build): use IS_ANT_EMPLOYEE constant for ant-only import/require guards CodeRabbit review identified that isAntEmployee() is a runtime function call that bundlers cannot evaluate for DCE. Replace all isAntEmployee() guards on dynamic import()/require() calls of ant-internal modules with the IS_ANT_EMPLOYEE boolean constant (exported as `false as const`), which the build-time source transform can replace with a literal `false` for DCE. Also extend the featureFlagPreprocessPlugin to replace IS_ANT_EMPLOYEE with false during bundling, and clean up the resulting dead imports/exports (`import { false, isAntEmployee }` → `import { isAntEmployee }`, `export const false = false as const` → removed). Affected ant-only modules (all missing from OpenClaude, must be DCE'd): - sessionDataUploader.js, eventLoopStallDetector.js, sdkHeapDumpMonitor.js - ccshareResume.js, cli/up.js, cli/rollback.js, cli/handlers/ant.js - useFrustrationDetection.js, useAntOrgWarningNotification.js - AntModelSwitchCallout.js, UndercoverAutoCallout.js
src/components/Stats.tsx (upstream Gitlawb#1569): - 17 typecheck errors → 0 by taking upstream verbatim - @ts-nocheck dropped (no longer needed) - (Stats.tsx still has 2 ant-related errors at lines 527, 1166 that are PORKED per Gitlawb#1512; if @ts-nocheck were re-added, the ant errors would be hidden again. Decision: leave file typecheck-clean with the ant errors actually being errors that need parking work in a future session. Per user policy 'error级必追必修' is best served by exposing real errors, not hiding them.) src/tools/FileWriteTool/UI.tsx (upstream Gitlawb#1574): - 9 typecheck errors → 0 by taking upstream verbatim + 2 small fixes - @ts-nocheck dropped - Fix 1: drop ProgressMessage<ToolProgressData> generic (fork's ProgressMessage is not generic) - Fix 2: spread props for HighlightedCode (HighlightedCode.tsx is @ts-nocheck → TS sees it as IntrinsicAttributes & object; spread bypasses the structural check) Add dependency: asciichart + @types/asciichart - Required by upstream's Stats.tsx which the fork didn't have - Fork was @ts-nocheck-hiding this missing dep VERIFICATION: typecheck: 34 → 5 errors (after this + previous wholesale replaces) tests: pre-existing acorn-module-missing failure NOT caused by these changes
… files, park 5 policy-coupled) Upstream 7078853 replaced 'external' === 'ant' dead-code literals with isAntEmployee() across 27 files to fix 90 TS2367 narrowing errors. The refactor is a behavioral no-op (isAntEmployee() always returns false) and commit message notes 'all missing from OpenClaude, must be DCE'd'. Applied 24 files cleanly. Parked 5 files that pulled in policy-removed modules/components when the isAntEmployee guards were resolved: PARKING (5 files, policy-coupled — 30+ err each, main.tsx hits 56): src/main.tsx (273-line diff, 19 modules) src/components/LogoV2/feedConfigs.tsx (releaseNotes exports) src/components/Settings/Config.tsx (fullAccess + defaultPermissionModeOptions) src/components/PromptInput/PromptInputFooterLeftSide.tsx (TungstenPill) 3way conflict resolution: took THEIRS for 14 of 14 UU files (the isAntEmployee refactor is the desired end state). Follow-up fixes in 2 files for cascading narrowing losses: src/commands/thinkback/thinkback.tsx - useState(null) → useState<string|null>(null) × 2 - useState(null) → useState<boolean|null>(null) × 1 src/components/NativeAutoUpdater.tsx - re-add // @ts-ignore for runtime USER_TYPE check (apply stripped it) Verification: 0 typecheck err, 2990 pass / 0 fail / 38 skip
…stubs Two pre-existing build breaks surfaced after the 2026-06-12 tier 1 push: 1. SDK bundle build failed: scripts/build.ts references ./src/entrypoints/sdk/index.ts as the entry point, but the file was dropped when the fork cherry-picked Gitlawb#1497 (f659238, 7 of 10 files). OpenCC/openclaude does not publish an SDK bundle, so the build now skips with a one-line notice when the entry point is missing. Post- build checks use sdkResult?.success (optional chaining) so they no-op cleanly when the build is skipped. 2. Bundle guard failed: 9ff2664 (Gitlawb#1512 isAntEmployee refactor) flipped the HISTORY_SNIP build flag to true. The snip tool source files (force-snip.ts, SnipBoundaryMessage.tsx, snipProjection.ts, SnipTool.tsx, SnipTool/prompt.ts) are not mirrored in the fork, so the build generated noop stubs for them. Per the guard's own guidance, added the 5 paths to ACCEPTABLE_RUNTIME_STUBS with justification (HISTORY_SNIP is feature-gated, the stubbed paths are unreachable in the open build). Verification: 0 typecheck err, 2992 pass / 0 fail / 38 skip, bun run build exit 0 (CLI bundle + skip SDK + guard clean)
… (5 files, 2 conflicts resolved) Upstream 8f92346 adds OOM protection for file suggestions on large repos: - Pre-warm the file index on mount (background build with ~4ms event-loop yields) - Skip background refresh under NODE_ENV=test (CI workspace 270k+ files) - Handle ignore scope + abort semantics in collectGitPaths/collectRipgrepPaths - Stabilize fetchWithProxyRetry env-var cleanup (windows-safe + more proxies) - Add 9 new tests for the abort semantics 3way conflicts on useTypeahead.tsx and fetchWithProxyRetry.test.ts: - useTypeahead: keep OURS (// @ts-ignore + startBackgroundCacheRefresh call — upstream refactor removed both, but fork's startBackgroundCacheRefresh export from fileSuggestions.ts is still in use elsewhere; preserving the call costs us one @ts-ignore but matches existing fork patterns from Gitlawb#1512) - fetchWithProxyRetry: take THEIRS (adds acquireSharedMutationLock + releaseSharedMutationLock + clearProxyEnv + more env var cleanup). Added the missing imports manually since the THEIRS patch landed in the afterEach block but the imports were not in the upstream diff. Verification: 0 typecheck err, 3000 pass / 1 fail (lsp recommend timeout, pre-existing flaky) / 38 skip
Summary
Refs #1486.
Replaces all
"external" === 'ant'and"external" !== 'ant'literal comparisons withisAntEmployee()and!isAntEmployee()respectively, eliminating 90 TS2367 "unintentional comparison" errors across 27 files.Additionally, uses the
IS_ANT_EMPLOYEEboolean constant (instead ofisAntEmployee()) at all sites that gate dynamicimport()/require()calls of ant-internal modules that do not exist in the external build. This ensures the bundler can statically evaluate the branch condition and dead-code-eliminate those calls.What changed
Phase 1: Replace
"external" === 'ant'literals withisAntEmployee()Each
"external" === 'ant'(alwaysfalse) →isAntEmployee()(always returnsfalse)Each
"external" !== 'ant'(alwaystrue) →!isAntEmployee()(always returnstrue)Added
import { isAntEmployee } from '.../utils/buildConfig.js'to all 27 affected files.Phase 2: Use
IS_ANT_EMPLOYEEfor dynamic import/require guardsAt all sites where
isAntEmployee()guards a dynamicimport()orrequire()call on an ant-internal module that doesn't exist in OpenClaude, replacedisAntEmployee()with theIS_ANT_EMPLOYEEboolean constant (false as const). The build-time source transform then replacesIS_ANT_EMPLOYEEwithfalse, giving the bundler a concrete literal for DCE.Affected guard sites in main.tsx (8 locations):
eventLoopStallDetector.js,sdkHeapDumpMonitor.js,sessionDataUploader.js,ccshareResume.jssrc/cli/up.js,src/cli/rollback.js,./cli/handlers/ant.js(3 commands)Affected guard sites in REPL.tsx (5 locations):
useFrustrationDetection.js,useAntOrgWarningNotification.jsAntModelSwitchCallout.js(2 bindings),UndercoverAutoCallout.jsPhase 3: Build-time transform
Extended the
featureFlagPreprocessPlugininscripts/build.tsto:isAntEmployee()calls withfalse(mirroringfeature('FLAG')replacement)IS_ANT_EMPLOYEEreferences withfalseimport { false, isAntEmployee }→import { isAntEmployee }) and exports (export const false = false as const→ removed)Also exported
IS_ANT_EMPLOYEE = false as constfrombuildConfig.tsas a named constant for documentation and call-site intent, withisAntEmployee()kept as a convenience wrapper.Files changed
Phase 1 (27 files): buddy/useBuddyNotification.tsx, commands/mcp/mcp.tsx, commands/terminalSetup/terminalSetup.tsx, commands/thinkback/thinkback.tsx, commands/ultraplan.tsx, components/ (DevBar, FeedbackSurvey, LogoV2, MemoryUsageIndicator, MessageSelector, NativeAutoUpdater, PromptInput, Settings/Config, Stats, agents/ToolSelector, messages/AttachmentMessage, tasks/taskStatusUtils), main.tsx, screens/REPL.tsx, tools/ (AgentTool, TaskOutputTool, TaskStopTool), utils/ (autoRunIssue, processUserInput/processSlashCommand).
Phase 2 (2 files): main.tsx, screens/REPL.tsx
Phase 3 (2 files): scripts/build.ts, src/utils/buildConfig.ts
Why
The Anthropic internal build replaces
process.env.USER_TYPEwith the string"external"at build time, and dead-code elimination then strips"external" === 'ant'branches. In the OpenClaude fork, some files had already been pre-substituted with the"external"literal, leaving TypeScript to see an impossible comparison that always evaluates tofalse.isAntEmployee()is the semantically correct replacement — it communicates intent and is alwaysfalse. However, because it's a runtime function call, Bun's bundler cannot evaluate it at build time, soimport()/require()calls insideif (isAntEmployee())branches were still resolved — causing build failures for modules that only exist in the internal build (sessionDataUploader, cli/up, cli/rollback, etc.).The fix uses
IS_ANT_EMPLOYEE(afalse as constboolean) for import/require gates, which the bundler's source transform replaces withfalsefor DCE. Runtime-only checks (data filtering, conditional logic) continue usingisAntEmployee()for readability.Not touched: ~273
process.env.USER_TYPE === 'ant'comparisons remain across other files. These are a separate build-time substitution pattern that should be addressed in a follow-up PR.Validation
git diff --check— passedbun run typecheck— zero new TS2367 errors; pre-existing errors unchangedbun run scripts/build.ts— succeeds; all ant-only imports eliminated from bundlebun test src/utils/buildConfig.test.ts— 2/2 passisAntEmployee(),IS_ANT_EMPLOYEE, or ant-only module references remain indist/cli.mjsIS_ANT_EMPLOYEE; all runtime logic usesisAntEmployee()isAntEmployee()andIS_ANT_EMPLOYEEevaluate tofalseSummary by CodeRabbit
New Features
Refactor