summaryrefslogtreecommitdiff
path: root/docs/core
diff options
context:
space:
mode:
authorNiladri Das <[email protected]>2025-07-31 22:06:50 +0530
committerGitHub <[email protected]>2025-07-31 16:36:50 +0000
commit9a6422f331294ea2f56d67599ed142d09cc33320 (patch)
tree16f3e58fc1ce3b6de88082dd4bb194a6635bafac /docs/core
parentae86c7ba05567264ca2d115a7f96d887bc576457 (diff)
fix: CLAUDE.md compatibility for GEMINI.md '@' file import behavior (#2978)
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Allen Hutchison <[email protected]>
Diffstat (limited to 'docs/core')
-rw-r--r--docs/core/memport.md80
1 files changed, 60 insertions, 20 deletions
diff --git a/docs/core/memport.md b/docs/core/memport.md
index cc6404e0..cc96aad3 100644
--- a/docs/core/memport.md
+++ b/docs/core/memport.md
@@ -1,18 +1,14 @@
# Memory Import Processor
-The Memory Import Processor is a feature that allows you to modularize your GEMINI.md files by importing content from other markdown files using the `@file.md` syntax.
+The Memory Import Processor is a feature that allows you to modularize your GEMINI.md files by importing content from other files using the `@file.md` syntax.
## Overview
This feature enables you to break down large GEMINI.md files into smaller, more manageable components that can be reused across different contexts. The import processor supports both relative and absolute paths, with built-in safety features to prevent circular imports and ensure file access security.
-## Important Limitations
-
-**This feature only supports `.md` (markdown) files.** Attempting to import files with other extensions (like `.txt`, `.json`, etc.) will result in a warning and the import will fail.
-
## Syntax
-Use the `@` symbol followed by the path to the markdown file you want to import:
+Use the `@` symbol followed by the path to the file you want to import:
```markdown
# Main GEMINI.md file
@@ -96,31 +92,47 @@ The `validateImportPath` function ensures that imports are only allowed from spe
### Maximum Import Depth
-To prevent infinite recursion, there's a configurable maximum import depth (default: 10 levels).
+To prevent infinite recursion, there's a configurable maximum import depth (default: 5 levels).
## Error Handling
-### Non-MD File Attempts
+### Missing Files
+
+If a referenced file doesn't exist, the import will fail gracefully with an error comment in the output.
-If you try to import a non-markdown file, you'll see a warning:
+### File Access Errors
-```markdown
-@./instructions.txt <!-- This will show a warning and fail -->
-```
+Permission issues or other file system errors are handled gracefully with appropriate error messages.
+
+## Code Region Detection
+
+The import processor uses the `marked` library to detect code blocks and inline code spans, ensuring that `@` imports inside these regions are properly ignored. This provides robust handling of nested code blocks and complex Markdown structures.
+
+## Import Tree Structure
-Console output:
+The processor returns an import tree that shows the hierarchy of imported files, similar to Claude's `/memory` feature. This helps users debug problems with their GEMINI.md files by showing which files were read and their import relationships.
+
+Example tree structure:
```
-[WARN] [ImportProcessor] Import processor only supports .md files. Attempting to import non-md file: ./instructions.txt. This will fail.
+Memory Files
+ L project: GEMINI.md
+ L a.md
+ L b.md
+ L c.md
+ L d.md
+ L e.md
+ L f.md
+ L included.md
```
-### Missing Files
+The tree preserves the order that files were imported and shows the complete import chain for debugging purposes.
-If a referenced file doesn't exist, the import will fail gracefully with an error comment in the output.
+## Comparison to Claude Code's `/memory` (`claude.md`) Approach
-### File Access Errors
+Claude Code's `/memory` feature (as seen in `claude.md`) produces a flat, linear document by concatenating all included files, always marking file boundaries with clear comments and path names. It does not explicitly present the import hierarchy, but the LLM receives all file contents and paths, which is sufficient for reconstructing the hierarchy if needed.
-Permission issues or other file system errors are handled gracefully with appropriate error messages.
+Note: The import tree is mainly for clarity during development and has limited relevance to LLM consumption.
## API Reference
@@ -135,7 +147,25 @@ Processes import statements in GEMINI.md content.
- `debugMode` (boolean, optional): Whether to enable debug logging (default: false)
- `importState` (ImportState, optional): State tracking for circular import prevention
-**Returns:** Promise<string> - Processed content with imports resolved
+**Returns:** Promise<ProcessImportsResult> - Object containing processed content and import tree
+
+### `ProcessImportsResult`
+
+```typescript
+interface ProcessImportsResult {
+ content: string; // The processed content with imports resolved
+ importTree: MemoryFile; // Tree structure showing the import hierarchy
+}
+```
+
+### `MemoryFile`
+
+```typescript
+interface MemoryFile {
+ path: string; // The file path
+ imports?: MemoryFile[]; // Direct imports, in the order they were imported
+}
+```
### `validateImportPath(importPath, basePath, allowedDirectories)`
@@ -149,6 +179,16 @@ Validates import paths to ensure they are safe and within allowed directories.
**Returns:** boolean - Whether the import path is valid
+### `findProjectRoot(startDir)`
+
+Finds the project root by searching for a `.git` directory upwards from the given start directory. Implemented as an **async** function using non-blocking file system APIs to avoid blocking the Node.js event loop.
+
+**Parameters:**
+
+- `startDir` (string): The directory to start searching from
+
+**Returns:** Promise<string> - The project root directory (or the start directory if no `.git` is found)
+
## Best Practices
1. **Use descriptive file names** for imported components
@@ -161,7 +201,7 @@ Validates import paths to ensure they are safe and within allowed directories.
### Common Issues
-1. **Import not working**: Check that the file exists and has a `.md` extension
+1. **Import not working**: Check that the file exists and the path is correct
2. **Circular import warnings**: Review your import structure for circular references
3. **Permission errors**: Ensure the files are readable and within allowed directories
4. **Path resolution issues**: Use absolute paths if relative paths aren't resolving correctly