Skip to content

feat(memory): improve memory handling and regex performance across co…#198

Merged
matt1398 merged 1 commit into
mainfrom
feat/memory-viewer
May 13, 2026
Merged

feat(memory): improve memory handling and regex performance across co…#198
matt1398 merged 1 commit into
mainfrom
feat/memory-viewer

Conversation

@matt1398
Copy link
Copy Markdown
Owner

@matt1398 matt1398 commented May 13, 2026

…mponents

Summary by CodeRabbit

  • Bug Fixes

    • Improved memory file display consistency by adding fallback behavior when no file is selected
    • Fixed copy button label and icon toggling
    • Enhanced robustness of memory entry parsing to prevent performance issues on complex input
    • Improved list-row highlighting and toolbar rendering consistency
  • Documentation

    • Updated Antigravity opener detection notes

Review Change Stack

Copilot AI review requested due to automatic review settings May 13, 2026 08:35
@coderabbitai coderabbitai Bot added the feature request New feature or request label May 13, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request optimizes regex patterns for linear-time matching, refactors the MemoryView component to use derived state via useMemo instead of an effect, and improves type safety in the memory store by explicitly handling undefined values. It also updates the sorting logic for orphan files and refines the copy-to-clipboard UI. Feedback was provided regarding the mirroring of IPC channel constants in the main process, suggesting they be moved to a shared directory to maintain a single source of truth and reduce maintenance overhead.

Comment thread src/main/ipc/memory.ts
Comment on lines +21 to +26
const MEMORY_HAS_MEMORY = 'memory:hasMemory';
const MEMORY_GET_INDEX = 'memory:getIndex';
const MEMORY_READ_FILE = 'memory:readFile';
const MEMORY_LIST_OPENERS = 'memory:listAvailableOpeners';
const MEMORY_OPEN_IN = 'memory:openIn';
const MEMORY_COPY_PATH = 'memory:copyPath';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Mirroring IPC channel constants locally in the main process creates a maintenance burden and risks desynchronization with the preload script. While respecting module boundaries is important, the standard pattern in Electron is to place shared constants in a src/shared directory that can be imported by both main, renderer, and preload processes. This ensures a single source of truth for IPC channels.

@matt1398 matt1398 merged commit 16cc3c8 into main May 13, 2026
8 of 9 checks passed
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 13, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

The PR refactors the memory viewer's display logic to use a computed fallback selection (displayedFile) derived from user choice or the first row. State types are widened to allow undefined entries for distinguishing "not yet loaded" from loaded values. Regex patterns are hardened against backtracking, IPC constants are moved to local scope, and supporting documentation is clarified.

Changes

Memory Feature State and Display

Layer / File(s) Summary
Memory state type refinement
src/renderer/store/slices/memorySlice.ts
MemorySlice interface fields (hasMemoryByProjectId, indexByProjectId, expandedEntriesByProjectId, fileContents, memoryLoadingByProjectId) are widened to allow undefined entries so pending/not-yet-loaded states can be modeled distinctly. Cache invalidation type is updated accordingly.
Display file selection and UI synchronization
src/renderer/components/memory/MemoryView.tsx, src/renderer/components/sidebar/memory/OpenInMenu.tsx
MemoryView replaces selectedFile effect synchronization with a computed displayedFile that falls back to the first row when selection is invalid. Content loading, active row highlighting, toolbar copy button, and "Open in…" menu all switch to displayedFile for consistent rendering. OpenInMenu eslint suppression comment clarifies intentional closure-based dependency semantics.
Regex optimization for security and performance
src/renderer/components/memory/MemoryView.tsx, src/shared/utils/memoryIndex.ts
Wikilink preprocessing and entry-line parsing regexes are hardened using bounded negated character classes to avoid backtracking and ReDoS on adversarial input. File sorting switches to locale-aware localeCompare comparison.
IPC channel module boundary fix
src/main/ipc/memory.ts
Memory-related IPC channel name constants are defined locally instead of imported from the preload module, eliminating cross-boundary imports.
Documentation and explanation updates
src/main/utils/openInLauncher.ts
Comment for the antigravity opener is updated to explain detection strategy (probing PATH and /Applications for bundle identifier and CLI).

Suggested labels

feature request

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves the Memory feature’s parsing/performance characteristics and clarifies “not loaded yet” state handling across renderer components, while also tightening some implementation details (regexes, sorting, and IPC channel constant ownership).

Changes:

  • Replaced potentially backtracking regex patterns with bounded/negated character classes for linear-time matching (memory index entries + wikilinks).
  • Updated the memory Zustand slice caches to use undefined for “not loaded yet” to distinguish from loaded falsy values.
  • Refactored MemoryView to compute the displayed file during render (instead of effect-driven state syncing) and adjusted copy UI state handling.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/shared/utils/memoryIndex.ts Hardens entry parsing regex for linear-time behavior and adjusts orphan sorting comparator.
src/renderer/store/slices/memorySlice.ts Changes cache record value types to include undefined to represent “not loaded yet”; updates refresh invalidation typing.
src/renderer/components/sidebar/memory/OpenInMenu.tsx Expands rationale on a hooks lint-disable comment.
src/renderer/components/memory/MemoryView.tsx Uses a precompiled wikilink regex and refactors selection/display logic + copy button state rendering.
src/main/utils/openInLauncher.ts Improves inline documentation for the Antigravity opener detection behavior.
src/main/ipc/memory.ts Replaces preload import of IPC channel constants with locally defined channel strings and documents the module boundary rationale.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +25 to +29
hasMemoryByProjectId: Record<string, boolean | undefined>;
indexByProjectId: Record<string, MemoryIndex | null | undefined>;
expandedEntriesByProjectId: Record<string, string[] | undefined>;
fileContents: Record<string, string | undefined>;
memoryLoadingByProjectId: Record<string, boolean | undefined>;
Comment thread src/main/ipc/memory.ts
Comment on lines +19 to 29
// Channel constants (mirrored from preload/constants/ipcChannels.ts to respect
// module boundaries — main process cannot import from preload).
const MEMORY_HAS_MEMORY = 'memory:hasMemory';
const MEMORY_GET_INDEX = 'memory:getIndex';
const MEMORY_READ_FILE = 'memory:readFile';
const MEMORY_LIST_OPENERS = 'memory:listAvailableOpeners';
const MEMORY_OPEN_IN = 'memory:openIn';
const MEMORY_COPY_PATH = 'memory:copyPath';

import { validateProjectId } from './guards';

Comment thread src/main/ipc/memory.ts
Comment on lines +19 to +26
// Channel constants (mirrored from preload/constants/ipcChannels.ts to respect
// module boundaries — main process cannot import from preload).
const MEMORY_HAS_MEMORY = 'memory:hasMemory';
const MEMORY_GET_INDEX = 'memory:getIndex';
const MEMORY_READ_FILE = 'memory:readFile';
const MEMORY_LIST_OPENERS = 'memory:listAvailableOpeners';
const MEMORY_OPEN_IN = 'memory:openIn';
const MEMORY_COPY_PATH = 'memory:copyPath';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature request New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants