Commit Graph
3 Commits
Author SHA1 Message Date
陈大猫 3998add458 perf(memory): Phase 3 deep business-code memory optimization across main, renderer, and active terminals
Completes exhaustive business-code memory optimization stacked on Phase 1-2 (#4476),
reaching the business-code floor before Electron-level optimization:

Round 1 - Renderer Cold Start & Preload Minification:
- Enable esbuild minification in scripts/build-preload.mjs (368 KB -> 103 KB, -72%)
- Remove eager requestIdleCallback TerminalLayer mount in AppMounts.tsx
- Add compact capability lookup maps to toolNameIndex.json so permissionGrants drops
  static cattyToolSpecs.json (126 KB) from startup
- Lazy-load pinyin-pro (447 KB) on first CJK text via usePinyinMatcherVersion hook
  (synchronous createRequire in Node/test mode, zero top-level await)

Round 2 & 3 - Main Process & terminalWorker Zero-Dead-Weight Startup:
- Lazy-load all third-party npm packages on startup (0 npm packages loaded at boot;
  require.cache 657 -> 234 modules, -64.4%; main heapTotal 54 -> 23.3 MiB):
  ajv/ajv-formats/plugin-contract schema, electron-updater, jsqr, ws, webmDurationPatch,
  terminalPerformanceDiagnostics, ssh2, ssh2-sftp-client, iconv-lite, zmodem.js,
  node-pty/serialport (Electron-gated so Node Module._load mocks stay 100% intact),
  11 AI SDK drivers, CodexAppServerRuntime, codebuddy, aiPrivacyService, re2js,
  external MCP setup, 17 capability modules, and 7 systemManager/*Ops modules
- Clean up windowManager readiness/unhealthy maps on BrowserWindow closed

Round 4 - Renderer Startup Bundle Decomposition:
- Lazy-load HostDetailsPanel (134 KB), GroupDetailsPanel (29 KB), KnownHostsManager,
  QuickConnectWizard, SerialConnectModal, Serial/LocalHostDetailsPanel,
  ImportVaultDialog, VaultImportProgressPanel, domain/vaultImport (55 KB),
  TerminalHostTreeSidebar (35 KB), ToolCall (26 KB), vaultAgentBridgeClient (47 KB)
- Tree-shake package.json in cloudSync (-32 KB from useUpdateCheck)
- Main App-*.js chunk: 1,550 KB -> 714.6 KB (-53.9%)

Round 5 - Active Multi-Terminal Memory Optimization:
- Remove unconditional requestIdleCallback preload of AIChatSidePanel (~1.5 MB JS /
  vendor-ai + globalAgentRuntime + tool specs) in TerminalLayerSupport.tsx
- Remove eager 67-spec Fig autocomplete preloading (1.25 MB raw JS imported into
  main-process ESM cache + renderer specCache) in useTerminalAutocomplete.ts; specs
  load on demand via completionEngine.ts loadSpec()

Verified Clean-VM Benchmarks (0-host idle, 3x median, vs Blank Electron 97.6 MiB PrivDirty):
- Total Private Dirty RAM: 324.8 -> 234.6 (Phase 1-2) -> 184.2 MiB (-43.3%, 61.9% of
  all Netcatty overhead above Blank Electron eliminated)
- Renderer v8/main/heap: 24.84 -> 9.35 MiB (-62.4%); jsHeapUsedMB: 35.98 -> 12.76 MiB
  (only +3.22 MiB above about:blank)
- Active 5 local terminals + 1,000-line ANSI burst: Peak PrivDirty -25.6 MiB
  (395.9 -> 370.3 MiB), main PrivDirty -11.3 MiB, renderer PrivDirty -14.2 MiB,
  zero xterm/canvas/listener/per-session heap leaks across 2x5 open/close cycles
2026-11-27 10:04:36 +00:00
陈大猫 38c0f5879a fix(memory): fix CI unit test compatibility for tray spellcheck, pty mocks, and sync toolNameIndex 2026-11-27 08:48:48 +00:00
陈大猫andCursor 9aed2c41d4 feat(ai): unify capability registry, harness tools, and agent runtime (#1685)
* feat(ai): unify capability registry, harness tools, and agent runtime

Centralize MCP/CLI/Catty tool surfaces in the capability catalog with codegen,
move Catty-only harness tools into catalog with local execution, converge
mcpServerBridge builtin dispatch via registry, and wire AgentRuntime with
vault bridge, permission grants, and Round 2 catalog parity.

Co-authored-by: Cursor <cursoragent@cursor.com>

* feat(ai): vault host tools, artifact cards, and external agent vault guidance

Unify vault host create/import with capability RPC routing, add chat artifact cards with Vault navigation, and align external MCP agents with Catty rules so host creation never falls back to Vault Notes.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(ai): address Bugbot findings for streaming, vault bridge, and grants

Clear Catty streaming by chat sessionId, read latest vault state via getters on agent mutations, and stack grant persisters so unmounting one AI panel does not break others.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(vault): clear pending openNoteId after chat navigation focus

NotesManager notifies VaultView once the one-shot openNoteId request is applied so the id does not stick for the rest of the session.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(vault): serialize vault agent IPC mutations to prevent lost writes

Queue vault agent bridge handlers so concurrent hosts.create or note.create tool calls cannot overwrite each other via stale read-modify-write snapshots.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(vault): keep synchronous vault snapshot for agent IPC reads

Mirror hosts, notes, and groups in a ref updated immediately on agent writes so serialized mutations see the latest state before React re-renders.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(ai): sync Catty MCP sessions and defer runtime cleanup on delete

Register terminal sessions with the main process before Catty tool calls, and clear ToolOutputStore only after stopping an active turn when deleting a chat session.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(ai): avoid deleting a newer abort controller on late stop

Only remove the session abort-controller entry when stop finishes if it still refers to the controller that was stopped.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(ai): sync vault snapshot on render and await active turn on stop

Refresh vault agent reads when React props change without clobbering in-flight agent writes, and wait for runTurn to finish before clearing ToolOutputStore on session delete.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(ai): reload permission grants from storage before auto-approve

Re-read persisted grant rules on each approval check so revocations in Settings take effect without requiring a chat hook remount.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(ai): sync permission grants to main process immediately on write

Push MCP permissionGrantsSnapshot as soon as Always allow persists a rule so the next tool call in the same agent turn sees the grant without waiting for useEffect.

Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-26 00:08:39 +08:00