Skip to content

Commit f5c9880

Browse files
Merge pull request #413 from claude-code-best/performance/20260505/memory-leak-fix
feat: 继续进行内存泄露修复及垃圾代码清理
2 parents 100e9d2 + 3f1c846 commit f5c9880

142 files changed

Lines changed: 303 additions & 463 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ const result = await Bun.build({
2121
outdir,
2222
target: 'bun',
2323
splitting: true,
24-
define: getMacroDefines(),
24+
define: {
25+
...getMacroDefines(),
26+
// React production mode — eliminates _debugStack Error objects
27+
// (6,889 objects × ~1.7KB = 12MB in development builds) and removes
28+
// prop-type / key warnings not useful in a production CLI tool.
29+
'process.env.NODE_ENV': JSON.stringify('production'),
30+
},
2531
features,
2632
})
2733

scripts/dev.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ const __dirname = dirname(__filename)
1414
const projectRoot = join(__dirname, '..')
1515
const cliPath = join(projectRoot, 'src/entrypoints/cli.tsx')
1616

17-
const defines = getMacroDefines()
17+
const defines = {
18+
...getMacroDefines(),
19+
// React production mode — prevents 6,889+ _debugStack Error objects
20+
// (12MB) from accumulating during long-running sessions.
21+
'process.env.NODE_ENV': JSON.stringify('production'),
22+
}
1823

1924
const defineArgs = Object.entries(defines).flatMap(([k, v]) => [
2025
'-d',

src/QueryEngine.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,7 @@ import { type Tools, type ToolUseContext, toolMatchesName } from './Tool.js'
4141
import type { AgentDefinition } from '@claude-code-best/builtin-tools/tools/AgentTool/loadAgentsDir.js'
4242
import { SYNTHETIC_OUTPUT_TOOL_NAME } from '@claude-code-best/builtin-tools/tools/SyntheticOutputTool/SyntheticOutputTool.js'
4343
import type { APIError } from '@anthropic-ai/sdk'
44-
import type {
45-
CompactMetadata,
46-
Message,
47-
SystemCompactBoundaryMessage,
48-
} from './types/message.js'
44+
import type { Message, SystemCompactBoundaryMessage } from './types/message.js'
4945
import type { OrphanedPermission } from './types/textInputTypes.js'
5046
import { createAbortController } from './utils/abortController.js'
5147
import type { AttributionState } from './utils/commitAttribution.js'

src/assistant/gate.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { feature } from 'bun:bundle'
2-
import { getKairosActive } from '../bootstrap/state.js'
32
import { getFeatureValue_CACHED_MAY_BE_STALE } from '../services/analytics/growthbook.js'
43

54
/**

src/bridge/bridgeMain.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
logEvent,
1212
logEventAsync,
1313
} from '../services/analytics/index.js'
14-
import { isInBundledMode } from '../utils/bundledMode.js'
1514
import { getBootstrapArgs, getScriptPath } from '../utils/cliLaunch.js'
1615
import { logForDebugging } from '../utils/debug.js'
1716
import { rcLog } from './rcDebugLog.js'

src/bridge/remoteBridgeCore.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ import type {
7272
SDKControlResponse,
7373
} from '../entrypoints/sdk/controlTypes.js'
7474
import type { StdoutMessage } from '../entrypoints/sdk/controlTypes.js'
75-
import type { SDKResultSuccess } from '../entrypoints/sdk/coreTypes.js'
7675
import type { PermissionMode } from '../utils/permissions/PermissionMode.js'
7776
import { setSessionMetadataChangedListener } from '../utils/sessionState.js'
7877

src/bridge/replBridge.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ import type {
5555
SDKControlResponse,
5656
} from '../entrypoints/sdk/controlTypes.js'
5757
import type { StdoutMessage } from '../entrypoints/sdk/controlTypes.js'
58-
import type { SDKResultSuccess } from '../entrypoints/sdk/coreTypes.js'
5958

6059
/**
6160
* StdoutMessage with optional session_id. The transport layer accepts

src/buddy/CompanionCard.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* Companion display card — shown by /buddy (no args).
33
* Mirrors official vc8 component: bordered box with sprite, stats, last reaction.
44
*/
5-
import React from 'react';
65
import { Box, Text } from '@anthropic/ink';
76
import { useInput } from '@anthropic/ink';
87
import { renderSprite } from './sprites.js';

src/cli/handlers/mcp.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import { stat } from 'fs/promises';
77
import pMap from 'p-map';
88
import { cwd } from 'process';
9-
import React from 'react';
109
import { MCPServerDesktopImportDialog } from '../../components/MCPServerDesktopImportDialog.js';
1110
import { wrappedRender as render } from '@anthropic/ink';
1211
import { KeybindingSetup } from '../../keybindings/KeybindingProviderSetup.js';

src/cli/print.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ import type {
112112
ModelInfo,
113113
SDKMessage,
114114
SDKUserMessage,
115-
SDKUserMessageReplay,
116115
PermissionResult,
117116
McpServerConfigForProcessTransport,
118117
McpServerStatus,
@@ -5477,7 +5476,7 @@ function getStructuredIO(
54775476
*/
54785477
export async function handleOrphanedPermissionResponse({
54795478
message,
5480-
setAppState,
5479+
setAppState: _setAppState,
54815480
onEnqueued,
54825481
handledToolUseIds,
54835482
}: {

0 commit comments

Comments
 (0)