Core Package
The lampe.core package provides the foundational logic and constants for the SDK.
Data Models
lampe.core.data_models
Issue
Bases: BaseModel
Individual issue to be resolved.
PullRequest
Bases: BaseModel
Pull request information.
Repository
Bases: BaseModel
Repository information.
issue
Issue
Bases: BaseModel
Individual issue to be resolved.
pull_request
PullRequest
Bases: BaseModel
Pull request information.
repository
Repository
Bases: BaseModel
Repository information.
Parsers
lampe.core.parsers
MarkdownCodeBlockRemoverOutputParser
Bases: BaseOutputParser
Output parser that extracts and returns the content of markdown code blocks marked with 'md' or 'markdown'.
This parser is designed to process LLM outputs or other text that may contain markdown code blocks.
It specifically targets code blocks with the language tag 'md' or 'markdown', removing the code block
markers and returning only the inner content. If no such block is found, it falls back to extracting
a generic code block (```). If the result still contains any other code block (with a language tag),
it is preserved as-is. If no code block is found, the original text (stripped of leading/trailing whitespace)
is returned.
Edge Cases:
- If the input is an empty string, returns an empty string.
- If the input contains a code block with a language other than 'md' or 'markdown', it is preserved.
- If the input contains text before or after a markdown code block, only the content inside the block is returned.
- If the input contains an incomplete code block, returns the input with the trailing backticks removed if present.
Examples
Examples
>>> parser = MarkdownCodeBlockRemoverOutputParser()
>>> text = '''```md
... This is inside md block.
... ```'''
>>> parser.parse(text)
'This is inside md block.'
>>> text = '''```python
... Multiple lines
... are here.
... ```'''
>>> parser.parse(text)
'```python
Multiple lines are here. ```'
>>> text = 'No code block here.'
>>> parser.parse(text)
'No code block here.'
parse(output: str) -> str
Extracts and returns the content of a markdown code block marked with md ormarkdown from the input text.
If the input contains a markdown code block with language tag 'md' or 'markdown', the content inside that block is returned, with the code block markers removed. If no such block is found, but a generic code block (```) is present, its content is returned. If the result still contains any other code block (with a language tag), it is preserved as-is. If no code block is found, the original text (stripped of leading/trailing whitespace) is returned.
Source code in src/lampe/core/parsers/markdown_code_block_remover_output.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
YAMLPydanticOutputParser
Bases: PydanticOutputParser[Model], Generic[Model]
A parser that extracts and validates YAML content using Pydantic models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_cls
|
Pydantic output class used for validation |
required | |
excluded_schema_keys_from_format
|
Schema keys to exclude from format string, by default None |
required | |
pydantic_format_tmpl
|
Template for format string, by default PYDANTIC_FORMAT_TMPL |
required |
Notes
This parser extracts YAML content from markdown code blocks, validates the structure using a Pydantic model, and returns the validated data. It first looks for YAML-specific code blocks, then falls back to any code block if needed.
format_string: str
property
Get the format string that instructs the LLM how to output YAML.
This method will provide a format string that includes the Pydantic model's JSON schema converted to a YAML example, helping the LLM understand the expected output structure.
Returns:
| Type | Description |
|---|---|
str
|
Format string with YAML schema example |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
The method is not yet implemented |
parse(text: str) -> Model
Extract, parse and validate YAML content using the configured Pydantic model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Raw text containing YAML content in markdown code blocks |
required |
Returns:
| Type | Description |
|---|---|
Model
|
Validated data matching the Pydantic model structure |
Raises:
| Type | Description |
|---|---|
YAMLParsingError
|
If no valid YAML content is found in the text or if the YAML parsing fails due to syntax errors |
ValidationError
|
If the data does not match the Pydantic model schema |
Source code in src/lampe/core/parsers/yaml_pydantic_output.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |
markdown_code_block_remover_output
MarkdownCodeBlockRemoverOutputParser
Bases: BaseOutputParser
Output parser that extracts and returns the content of markdown code blocks marked with 'md' or 'markdown'.
This parser is designed to process LLM outputs or other text that may contain markdown code blocks.
It specifically targets code blocks with the language tag 'md' or 'markdown', removing the code block
markers and returning only the inner content. If no such block is found, it falls back to extracting
a generic code block (```). If the result still contains any other code block (with a language tag),
it is preserved as-is. If no code block is found, the original text (stripped of leading/trailing whitespace)
is returned.
Edge Cases:
- If the input is an empty string, returns an empty string.
- If the input contains a code block with a language other than 'md' or 'markdown', it is preserved.
- If the input contains text before or after a markdown code block, only the content inside the block is returned.
- If the input contains an incomplete code block, returns the input with the trailing backticks removed if present.
Examples
Examples
>>> parser = MarkdownCodeBlockRemoverOutputParser()
>>> text = '''```md
... This is inside md block.
... ```'''
>>> parser.parse(text)
'This is inside md block.'
>>> text = '''```python
... Multiple lines
... are here.
... ```'''
>>> parser.parse(text)
'```python
Multiple lines are here. ```'
>>> text = 'No code block here.'
>>> parser.parse(text)
'No code block here.'
parse(output: str) -> str
Extracts and returns the content of a markdown code block marked with md ormarkdown from the input text.
If the input contains a markdown code block with language tag 'md' or 'markdown', the content inside that block is returned, with the code block markers removed. If no such block is found, but a generic code block (```) is present, its content is returned. If the result still contains any other code block (with a language tag), it is preserved as-is. If no code block is found, the original text (stripped of leading/trailing whitespace) is returned.
Source code in src/lampe/core/parsers/markdown_code_block_remover_output.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
utils
extract_md_code_block(output: str, language: str = '', match_any_language: bool = False) -> str | None
Extract markdown code block content from a string, handling nested code blocks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
str
|
The string to extract code block content from. |
required |
language
|
str
|
The language identifier for the code block (e.g., 'yaml', 'python', 'json'). |
''
|
match_any_language
|
bool
|
If True, the language of the code block is optional and the function will return the first code block found. |
False
|
Returns:
| Type | Description |
|---|---|
str | None
|
The extracted code block content, or the entire input if no language is specified or no matching code block is found. |
Notes
This function extracts content between {language} tags, preserving any nested
code blocks within the content. The regex pattern handles:
- Optional text before the code block
- Nested code blocks (e.g.json, python, inside the main block)
- Proper indentation of nested content
- Case-insensitive language tag matching
Examples:
>>> text = '''
... Some text
... ```yaml
... key: value
... nested: |
... ```python
... print("Hello")
... ```
... ```
... '''
>>> result = extract_md_code_block(text, 'yaml')
>>> print(result)
key: value
nested: |
```python
print("Hello")
```
Source code in src/lampe/core/parsers/utils.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
yaml_pydantic_output
YAMLParsingError
Bases: Exception
Raised when YAML parsing or validation fails.
YAMLPydanticOutputParser
Bases: PydanticOutputParser[Model], Generic[Model]
A parser that extracts and validates YAML content using Pydantic models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_cls
|
Pydantic output class used for validation |
required | |
excluded_schema_keys_from_format
|
Schema keys to exclude from format string, by default None |
required | |
pydantic_format_tmpl
|
Template for format string, by default PYDANTIC_FORMAT_TMPL |
required |
Notes
This parser extracts YAML content from markdown code blocks, validates the structure using a Pydantic model, and returns the validated data. It first looks for YAML-specific code blocks, then falls back to any code block if needed.
format_string: str
property
Get the format string that instructs the LLM how to output YAML.
This method will provide a format string that includes the Pydantic model's JSON schema converted to a YAML example, helping the LLM understand the expected output structure.
Returns:
| Type | Description |
|---|---|
str
|
Format string with YAML schema example |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
The method is not yet implemented |
parse(text: str) -> Model
Extract, parse and validate YAML content using the configured Pydantic model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Raw text containing YAML content in markdown code blocks |
required |
Returns:
| Type | Description |
|---|---|
Model
|
Validated data matching the Pydantic model structure |
Raises:
| Type | Description |
|---|---|
YAMLParsingError
|
If no valid YAML content is found in the text or if the YAML parsing fails due to syntax errors |
ValidationError
|
If the data does not match the Pydantic model schema |
Source code in src/lampe/core/parsers/yaml_pydantic_output.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |
Tools
lampe.core.tools
TempGitRepository(repo_url: str, head_ref: str | None = None, base_ref: str | None = None, folder_name: str | None = None, sparse: bool = True, shallow: bool = True, blob_filter: bool = True, remove_existing: bool = True)
Context Manager for cloning and cleaning up a local clone of a repository
Uses partial clone optimizations including shallow clone, sparse checkout, and blob filtering to efficiently fetch only required content. Upon exit, will attempt to delete the cloned repository.
Attributes:
| Name | Type | Description |
|---|---|---|
repo_url |
Repository URL to clone |
|
head_ref |
Optional head ref to check out. |
|
folder_name |
Optional name prefix for temp directory |
|
sparse |
Enable sparse checkout mode to avoid populating all files initially. |
|
shallow |
Enable shallow clone (depth=1) to fetch only the target commit. |
|
blob_filter |
Enable blob filtering (--filter=blob:none) to fetch file contents on-demand |
|
remove_existing |
Remove existing directory if it exists |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If Git version check fails |
GitCommandError
|
If clone operation fails |
UnableToDeleteError
|
If unable to delete the cloned repository |
Source code in src/lampe/core/tools/repository/management.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
clone_repo(repo_url: str, head_ref: str | None = None, base_ref: str | None = None, folder_name: str | None = None, sparse: bool = True, shallow: bool = True, blob_filter: bool = True, remove_existing: bool = True) -> str
Clone a repository optimized for PR review.
Uses partial clone optimizations including shallow clone, sparse checkout, and blob filtering to efficiently fetch only required content.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_url
|
str
|
Repository URL to clone |
required |
head_ref
|
str | None
|
Head ref to checkout |
None
|
base_ref
|
str | None
|
Base ref to fetch for diff computation |
None
|
folder_name
|
str | None
|
Optional name prefix for temp directory |
None
|
sparse
|
bool
|
Enable sparse checkout mode to avoid populating all files initially |
True
|
shallow
|
bool
|
Enable shallow clone (depth=1) to fetch only the target commit |
True
|
blob_filter
|
bool
|
Enable blob filtering (--filter=blob:none) to fetch file contents on-demand |
True
|
remove_existing
|
bool
|
Remove existing directory if it exists |
True
|
Returns:
| Type | Description |
|---|---|
str
|
Path to the cloned repository |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If Git version check fails |
GitCommandError
|
If clone operation fails |
Source code in src/lampe/core/tools/repository/management.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
get_diff_between_commits(base_hash: str, head_hash: str = 'HEAD', files_exclude_patterns: list[str] | None = None, files_include_patterns: list[str] | None = None, files_reinclude_patterns: list[str] | None = None, batch_size: int = 50, repo_path: str = '/tmp/') -> str
Get the diff between two commits, optionally filtering files by glob patterns.
The filtering is done in a specific order to ensure correct pattern application: 1. First, if include patterns are provided, only files matching those patterns are kept 2. Then, exclude patterns are applied to filter out matching files 3. Finally, reinclude patterns can override the exclude patterns to bring back specific files
This order ensures that reinclude patterns only affect files that were actually excluded, preventing the reinclude of files that weren't matched by include patterns in the first place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_hash
|
str
|
Base commit hash to compare from |
required |
head_hash
|
str
|
Head commit hash to compare to. If not provided, uses HEAD |
'HEAD'
|
files_exclude_patterns
|
list[str] | None
|
List of glob patterns to exclude from the diff (relative to repo root). These patterns take precedence over include patterns. |
None
|
files_include_patterns
|
list[str] | None
|
List of glob patterns to include in the diff (relative to repo root). Note that exclude patterns will override these if there are conflicts. |
None
|
files_reinclude_patterns
|
list[str] | None
|
List of glob patterns to re-include files that were excluded by the exclude patterns. These patterns will only affect files that were previously excluded. |
None
|
repo_path
|
str
|
Path to the git repository |
'/tmp/'
|
batch_size
|
int
|
Number of files to process in each batch. |
50
|
Returns:
| Type | Description |
|---|---|
str
|
Diff as a string |
Raises:
| Type | Description |
|---|---|
DiffNotFoundError
|
If there is an unexpected git error |
Source code in src/lampe/core/tools/repository/diff.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
view_file(commit_hash: str, file_path: str, line_start: int | None = None, line_end: int | None = None, repo_path: str = '/tmp/') -> str
Get file content from a specific commit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
commit_hash
|
str
|
Commit reference (e.g., "main", commit hash) |
required |
file_path
|
str
|
Path to the file within the repository |
required |
line_start
|
int | None
|
Line range start index (0-based) of head_content to extract content from |
None
|
line_end
|
int | None
|
Line range end index (0-based) of head_content to extract content to |
None
|
repo_path
|
str
|
Path to the git repository, by default "/tmp/" |
'/tmp/'
|
Returns:
| Type | Description |
|---|---|
str
|
File content as a string, empty string if file doesn't exist or line range is invalid |
Raises:
| Type | Description |
|---|---|
GitCommandError
|
If the file doesn't exist or any other git error occurs |
Source code in src/lampe/core/tools/repository/content.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
repository
LocalCommitsAvailability(repo_path: str, commits: list[str])
Context manager to check if commits are available locally before git operations.
Checks if specified commits exist locally using git fsck --root and fetches
them if they're not present. This is useful for ensuring all required commits
are available before performing git operations that depend on them.
Attributes:
| Name | Type | Description |
|---|---|---|
repo_path |
Path to the git repository |
|
commits |
List of commit references to check and fetch if needed |
Source code in src/lampe/core/tools/repository/management.py
219 220 221 222 223 | |
TempGitRepository(repo_url: str, head_ref: str | None = None, base_ref: str | None = None, folder_name: str | None = None, sparse: bool = True, shallow: bool = True, blob_filter: bool = True, remove_existing: bool = True)
Context Manager for cloning and cleaning up a local clone of a repository
Uses partial clone optimizations including shallow clone, sparse checkout, and blob filtering to efficiently fetch only required content. Upon exit, will attempt to delete the cloned repository.
Attributes:
| Name | Type | Description |
|---|---|---|
repo_url |
Repository URL to clone |
|
head_ref |
Optional head ref to check out. |
|
folder_name |
Optional name prefix for temp directory |
|
sparse |
Enable sparse checkout mode to avoid populating all files initially. |
|
shallow |
Enable shallow clone (depth=1) to fetch only the target commit. |
|
blob_filter |
Enable blob filtering (--filter=blob:none) to fetch file contents on-demand |
|
remove_existing |
Remove existing directory if it exists |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If Git version check fails |
GitCommandError
|
If clone operation fails |
UnableToDeleteError
|
If unable to delete the cloned repository |
Source code in src/lampe/core/tools/repository/management.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
clone_repo(repo_url: str, head_ref: str | None = None, base_ref: str | None = None, folder_name: str | None = None, sparse: bool = True, shallow: bool = True, blob_filter: bool = True, remove_existing: bool = True) -> str
Clone a repository optimized for PR review.
Uses partial clone optimizations including shallow clone, sparse checkout, and blob filtering to efficiently fetch only required content.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_url
|
str
|
Repository URL to clone |
required |
head_ref
|
str | None
|
Head ref to checkout |
None
|
base_ref
|
str | None
|
Base ref to fetch for diff computation |
None
|
folder_name
|
str | None
|
Optional name prefix for temp directory |
None
|
sparse
|
bool
|
Enable sparse checkout mode to avoid populating all files initially |
True
|
shallow
|
bool
|
Enable shallow clone (depth=1) to fetch only the target commit |
True
|
blob_filter
|
bool
|
Enable blob filtering (--filter=blob:none) to fetch file contents on-demand |
True
|
remove_existing
|
bool
|
Remove existing directory if it exists |
True
|
Returns:
| Type | Description |
|---|---|
str
|
Path to the cloned repository |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If Git version check fails |
GitCommandError
|
If clone operation fails |
Source code in src/lampe/core/tools/repository/management.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
fetch_commit_ref(repo_path: str, commit_ref: str) -> None
Fetch a base reference from the remote repository.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_path
|
str
|
Path to the git repository |
required |
commit_ref
|
str
|
Commit reference to fetch (e.g., branch name, commit hash) |
required |
Raises:
| Type | Description |
|---|---|
GitCommandError
|
If the fetch operation fails |
Source code in src/lampe/core/tools/repository/management.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
find_files_by_pattern(pattern: str, repo_path: str = '/tmp/') -> str
Search for files using git ls-files and pattern matching.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern
|
str
|
Pattern to search for (e.g. ".py", "src//.md") |
required |
repo_path
|
str
|
Path to git repository |
'/tmp/'
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted string containing matching file paths |
Source code in src/lampe/core/tools/repository/search.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
get_diff_between_commits(base_hash: str, head_hash: str = 'HEAD', files_exclude_patterns: list[str] | None = None, files_include_patterns: list[str] | None = None, files_reinclude_patterns: list[str] | None = None, batch_size: int = 50, repo_path: str = '/tmp/') -> str
Get the diff between two commits, optionally filtering files by glob patterns.
The filtering is done in a specific order to ensure correct pattern application: 1. First, if include patterns are provided, only files matching those patterns are kept 2. Then, exclude patterns are applied to filter out matching files 3. Finally, reinclude patterns can override the exclude patterns to bring back specific files
This order ensures that reinclude patterns only affect files that were actually excluded, preventing the reinclude of files that weren't matched by include patterns in the first place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_hash
|
str
|
Base commit hash to compare from |
required |
head_hash
|
str
|
Head commit hash to compare to. If not provided, uses HEAD |
'HEAD'
|
files_exclude_patterns
|
list[str] | None
|
List of glob patterns to exclude from the diff (relative to repo root). These patterns take precedence over include patterns. |
None
|
files_include_patterns
|
list[str] | None
|
List of glob patterns to include in the diff (relative to repo root). Note that exclude patterns will override these if there are conflicts. |
None
|
files_reinclude_patterns
|
list[str] | None
|
List of glob patterns to re-include files that were excluded by the exclude patterns. These patterns will only affect files that were previously excluded. |
None
|
repo_path
|
str
|
Path to the git repository |
'/tmp/'
|
batch_size
|
int
|
Number of files to process in each batch. |
50
|
Returns:
| Type | Description |
|---|---|
str
|
Diff as a string |
Raises:
| Type | Description |
|---|---|
DiffNotFoundError
|
If there is an unexpected git error |
Source code in src/lampe/core/tools/repository/diff.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
get_diff_for_files(base_reference: str, file_paths: list[str] | None = None, head_reference: str = 'HEAD', repo_path: str = '/tmp/', batch_size: int = 50) -> str
Get the diff between two commits, optionally for specific files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_reference
|
str
|
Base commit reference (e.g., "main", commit hash) |
required |
file_paths
|
list[str] | None
|
List of file paths to get diff for |
None
|
head_reference
|
str
|
Head commit reference (e.g., "main", commit hash). Defaults to "HEAD" |
'HEAD'
|
repo_path
|
str
|
Path to git repository, by default "/tmp/" |
'/tmp/'
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted string containing diffs for specified files or all changed files |
Source code in src/lampe/core/tools/repository/diff.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
get_file_content_at_commit(commit_hash: str, file_path: str, line_start: int | None = None, line_end: int | None = None, repo_path: str = '/tmp/') -> str
Get file content from a specific commit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
commit_hash
|
str
|
Commit reference (e.g., "main", commit hash) |
required |
file_path
|
str
|
Path to the file within the repository |
required |
line_start
|
int | None
|
Line range start index (0-based) of head_content to extract content from |
None
|
line_end
|
int | None
|
Line range end index (0-based) of head_content to extract content to |
None
|
repo_path
|
str
|
Path to the git repository, by default "/tmp/" |
'/tmp/'
|
Returns:
| Type | Description |
|---|---|
str
|
File content as a string, empty string if file doesn't exist or line range is invalid |
Raises:
| Type | Description |
|---|---|
GitCommandError
|
If the file doesn't exist or any other git error occurs |
Source code in src/lampe/core/tools/repository/content.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
is_sparse_clone(repo_path: str) -> bool
Check if a repository is a sparse clone.
A sparse clone is detected by checking multiple indicators: 1. If core.sparseCheckout is enabled 2. If .git/info/sparse-checkout file exists and has content
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_path
|
str
|
Path to the git repository |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the repository appears to be a sparse clone, False otherwise |
Raises:
| Type | Description |
|---|---|
GitCommandError
|
If git commands fail |
Source code in src/lampe/core/tools/repository/management.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | |
list_changed_files(base_reference: str, head_reference: str = 'HEAD', repo_path: str = '/tmp/') -> str
List files changed between base reference and HEAD, with change stats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_reference
|
str
|
Git reference (commit hash, branch name, etc.) to compare against HEAD |
required |
head_reference
|
str
|
Git reference (commit hash, branch name, etc.) to compare against base reference. Defaults to "HEAD" |
'HEAD'
|
repo_path
|
str
|
Path to git repository, by default "/tmp/" |
'/tmp/'
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted string listing changed files with status, additions/deletions and size Format: "[STATUS] filepath | +additions -deletions | sizeKB" STATUS is one of: A (added), D (deleted), M (modified) |
Raises:
| Type | Description |
|---|---|
GitCommandError
|
If there is an error executing git commands |
Source code in src/lampe/core/tools/repository/diff.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
search_in_files(pattern: str, relative_dir_path: str, commit_reference: str, repo_path: str = '/tmp/') -> str
Search for a pattern in files within a directory at a specific commit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern
|
str
|
Pattern to search for |
required |
relative_dir_path
|
str
|
Directory path to search in |
required |
commit_reference
|
str
|
Commit reference to search at |
required |
repo_path
|
str
|
Path to the git repository, by default "/tmp/" |
'/tmp/'
|
Returns:
| Type | Description |
|---|---|
str
|
Search results as a string |
Source code in src/lampe/core/tools/repository/search.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
show_commit(commit_reference: str, repo_path: str = '/tmp/') -> str
Show the contents of a commit.
This function shows the contents of a commit, including the commit details and diffs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
commit_reference
|
str
|
Commit reference (e.g., "main", commit hash) |
required |
repo_path
|
str
|
Path to git repository, by default "/tmp/" |
'/tmp/'
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted string containing commit details and diffs |
Source code in src/lampe/core/tools/repository/history.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
content
file_exists(file_path: str, commit_hash: str = 'HEAD', repo_path: str = '/tmp/') -> bool
Check if a file exists in a specific commit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
Path to the file within the repository |
required |
commit_hash
|
str
|
Commit reference to check (e.g., commit hash, branch name, tag). Defaults to "HEAD" |
'HEAD'
|
repo_path
|
str
|
Path to git repository, by default "/tmp/" |
'/tmp/'
|
Returns:
| Type | Description |
|---|---|
bool
|
True if file exists in the commit, False otherwise |
Raises:
| Type | Description |
|---|---|
GitCommandError
|
If there is an unexpected git error |
Source code in src/lampe/core/tools/repository/content.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
get_file_content_at_commit(commit_hash: str, file_path: str, line_start: int | None = None, line_end: int | None = None, repo_path: str = '/tmp/') -> str
Get file content from a specific commit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
commit_hash
|
str
|
Commit reference (e.g., "main", commit hash) |
required |
file_path
|
str
|
Path to the file within the repository |
required |
line_start
|
int | None
|
Line range start index (0-based) of head_content to extract content from |
None
|
line_end
|
int | None
|
Line range end index (0-based) of head_content to extract content to |
None
|
repo_path
|
str
|
Path to the git repository, by default "/tmp/" |
'/tmp/'
|
Returns:
| Type | Description |
|---|---|
str
|
File content as a string, empty string if file doesn't exist or line range is invalid |
Raises:
| Type | Description |
|---|---|
GitCommandError
|
If the file doesn't exist or any other git error occurs |
Source code in src/lampe/core/tools/repository/content.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
get_file_size_at_commit(file_path: str, commit_hash: str = 'HEAD', repo_path: str = '/tmp/') -> int
Get the size of a file at a specific commit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
Path to the file within the repository |
required |
commit_hash
|
str
|
Commit reference (e.g., "main", commit hash). Defaults to "HEAD" |
'HEAD'
|
repo_path
|
str
|
Path to the git repository, by default "/tmp/" |
'/tmp/'
|
Returns:
| Type | Description |
|---|---|
int
|
Size of the file in bytes |
Source code in src/lampe/core/tools/repository/content.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
diff
get_diff_between_commits(base_hash: str, head_hash: str = 'HEAD', files_exclude_patterns: list[str] | None = None, files_include_patterns: list[str] | None = None, files_reinclude_patterns: list[str] | None = None, batch_size: int = 50, repo_path: str = '/tmp/') -> str
Get the diff between two commits, optionally filtering files by glob patterns.
The filtering is done in a specific order to ensure correct pattern application: 1. First, if include patterns are provided, only files matching those patterns are kept 2. Then, exclude patterns are applied to filter out matching files 3. Finally, reinclude patterns can override the exclude patterns to bring back specific files
This order ensures that reinclude patterns only affect files that were actually excluded, preventing the reinclude of files that weren't matched by include patterns in the first place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_hash
|
str
|
Base commit hash to compare from |
required |
head_hash
|
str
|
Head commit hash to compare to. If not provided, uses HEAD |
'HEAD'
|
files_exclude_patterns
|
list[str] | None
|
List of glob patterns to exclude from the diff (relative to repo root). These patterns take precedence over include patterns. |
None
|
files_include_patterns
|
list[str] | None
|
List of glob patterns to include in the diff (relative to repo root). Note that exclude patterns will override these if there are conflicts. |
None
|
files_reinclude_patterns
|
list[str] | None
|
List of glob patterns to re-include files that were excluded by the exclude patterns. These patterns will only affect files that were previously excluded. |
None
|
repo_path
|
str
|
Path to the git repository |
'/tmp/'
|
batch_size
|
int
|
Number of files to process in each batch. |
50
|
Returns:
| Type | Description |
|---|---|
str
|
Diff as a string |
Raises:
| Type | Description |
|---|---|
DiffNotFoundError
|
If there is an unexpected git error |
Source code in src/lampe/core/tools/repository/diff.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
get_diff_for_files(base_reference: str, file_paths: list[str] | None = None, head_reference: str = 'HEAD', repo_path: str = '/tmp/', batch_size: int = 50) -> str
Get the diff between two commits, optionally for specific files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_reference
|
str
|
Base commit reference (e.g., "main", commit hash) |
required |
file_paths
|
list[str] | None
|
List of file paths to get diff for |
None
|
head_reference
|
str
|
Head commit reference (e.g., "main", commit hash). Defaults to "HEAD" |
'HEAD'
|
repo_path
|
str
|
Path to git repository, by default "/tmp/" |
'/tmp/'
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted string containing diffs for specified files or all changed files |
Source code in src/lampe/core/tools/repository/diff.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
list_changed_files(base_reference: str, head_reference: str = 'HEAD', repo_path: str = '/tmp/') -> str
List files changed between base reference and HEAD, with change stats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_reference
|
str
|
Git reference (commit hash, branch name, etc.) to compare against HEAD |
required |
head_reference
|
str
|
Git reference (commit hash, branch name, etc.) to compare against base reference. Defaults to "HEAD" |
'HEAD'
|
repo_path
|
str
|
Path to git repository, by default "/tmp/" |
'/tmp/'
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted string listing changed files with status, additions/deletions and size Format: "[STATUS] filepath | +additions -deletions | sizeKB" STATUS is one of: A (added), D (deleted), M (modified) |
Raises:
| Type | Description |
|---|---|
GitCommandError
|
If there is an error executing git commands |
Source code in src/lampe/core/tools/repository/diff.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
history
get_commit_log(max_count: int, repo_path: str = '/tmp/') -> str
Get the log of commits for a repository.
This function gets the log of commits for a repository, including the commit details and the list of files path that were changed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_count
|
int
|
Maximum number of commits to return |
required |
repo_path
|
str
|
Path to git repository, by default "/tmp/" |
'/tmp/'
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted string containing commit details and list of files that were changed |
Source code in src/lampe/core/tools/repository/history.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
show_commit(commit_reference: str, repo_path: str = '/tmp/') -> str
Show the contents of a commit.
This function shows the contents of a commit, including the commit details and diffs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
commit_reference
|
str
|
Commit reference (e.g., "main", commit hash) |
required |
repo_path
|
str
|
Path to git repository, by default "/tmp/" |
'/tmp/'
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted string containing commit details and diffs |
Source code in src/lampe/core/tools/repository/history.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
management
LocalCommitsAvailability(repo_path: str, commits: list[str])
Context manager to check if commits are available locally before git operations.
Checks if specified commits exist locally using git fsck --root and fetches
them if they're not present. This is useful for ensuring all required commits
are available before performing git operations that depend on them.
Attributes:
| Name | Type | Description |
|---|---|---|
repo_path |
Path to the git repository |
|
commits |
List of commit references to check and fetch if needed |
Source code in src/lampe/core/tools/repository/management.py
219 220 221 222 223 | |
TempGitRepository(repo_url: str, head_ref: str | None = None, base_ref: str | None = None, folder_name: str | None = None, sparse: bool = True, shallow: bool = True, blob_filter: bool = True, remove_existing: bool = True)
Context Manager for cloning and cleaning up a local clone of a repository
Uses partial clone optimizations including shallow clone, sparse checkout, and blob filtering to efficiently fetch only required content. Upon exit, will attempt to delete the cloned repository.
Attributes:
| Name | Type | Description |
|---|---|---|
repo_url |
Repository URL to clone |
|
head_ref |
Optional head ref to check out. |
|
folder_name |
Optional name prefix for temp directory |
|
sparse |
Enable sparse checkout mode to avoid populating all files initially. |
|
shallow |
Enable shallow clone (depth=1) to fetch only the target commit. |
|
blob_filter |
Enable blob filtering (--filter=blob:none) to fetch file contents on-demand |
|
remove_existing |
Remove existing directory if it exists |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If Git version check fails |
GitCommandError
|
If clone operation fails |
UnableToDeleteError
|
If unable to delete the cloned repository |
Source code in src/lampe/core/tools/repository/management.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
clone_repo(repo_url: str, head_ref: str | None = None, base_ref: str | None = None, folder_name: str | None = None, sparse: bool = True, shallow: bool = True, blob_filter: bool = True, remove_existing: bool = True) -> str
Clone a repository optimized for PR review.
Uses partial clone optimizations including shallow clone, sparse checkout, and blob filtering to efficiently fetch only required content.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_url
|
str
|
Repository URL to clone |
required |
head_ref
|
str | None
|
Head ref to checkout |
None
|
base_ref
|
str | None
|
Base ref to fetch for diff computation |
None
|
folder_name
|
str | None
|
Optional name prefix for temp directory |
None
|
sparse
|
bool
|
Enable sparse checkout mode to avoid populating all files initially |
True
|
shallow
|
bool
|
Enable shallow clone (depth=1) to fetch only the target commit |
True
|
blob_filter
|
bool
|
Enable blob filtering (--filter=blob:none) to fetch file contents on-demand |
True
|
remove_existing
|
bool
|
Remove existing directory if it exists |
True
|
Returns:
| Type | Description |
|---|---|
str
|
Path to the cloned repository |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If Git version check fails |
GitCommandError
|
If clone operation fails |
Source code in src/lampe/core/tools/repository/management.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
fetch_commit_ref(repo_path: str, commit_ref: str) -> None
Fetch a base reference from the remote repository.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_path
|
str
|
Path to the git repository |
required |
commit_ref
|
str
|
Commit reference to fetch (e.g., branch name, commit hash) |
required |
Raises:
| Type | Description |
|---|---|
GitCommandError
|
If the fetch operation fails |
Source code in src/lampe/core/tools/repository/management.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
is_sparse_clone(repo_path: str) -> bool
Check if a repository is a sparse clone.
A sparse clone is detected by checking multiple indicators: 1. If core.sparseCheckout is enabled 2. If .git/info/sparse-checkout file exists and has content
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_path
|
str
|
Path to the git repository |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the repository appears to be a sparse clone, False otherwise |
Raises:
| Type | Description |
|---|---|
GitCommandError
|
If git commands fail |
Source code in src/lampe/core/tools/repository/management.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | |
search
find_files_by_pattern(pattern: str, repo_path: str = '/tmp/') -> str
Search for files using git ls-files and pattern matching.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern
|
str
|
Pattern to search for (e.g. ".py", "src//.md") |
required |
repo_path
|
str
|
Path to git repository |
'/tmp/'
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted string containing matching file paths |
Source code in src/lampe/core/tools/repository/search.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
search_in_files(pattern: str, relative_dir_path: str, commit_reference: str, repo_path: str = '/tmp/') -> str
Search for a pattern in files within a directory at a specific commit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern
|
str
|
Pattern to search for |
required |
relative_dir_path
|
str
|
Directory path to search in |
required |
commit_reference
|
str
|
Commit reference to search at |
required |
repo_path
|
str
|
Path to the git repository, by default "/tmp/" |
'/tmp/'
|
Returns:
| Type | Description |
|---|---|
str
|
Search results as a string |
Source code in src/lampe/core/tools/repository/search.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
Utilities
lampe.core.utils
truncate_to_token_limit(content: str, max_tokens: int) -> str
Truncate the content to the maximum number of tokens.
If the content is too long, truncate it to 200000 characters (3-4 characters per token)
before encoding for performance reasons.
We allow endoftext token to be encoded, since in the past we encountered issues with the tokenizer.
Args: content (str): The content to truncate. max_tokens (int): The maximum number of tokens to keep.
Returns: str: The truncated content.
Source code in src/lampe/core/utils/token.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
token
truncate_to_token_limit(content: str, max_tokens: int) -> str
Truncate the content to the maximum number of tokens.
If the content is too long, truncate it to 200000 characters (3-4 characters per token)
before encoding for performance reasons.
We allow endoftext token to be encoded, since in the past we encountered issues with the tokenizer.
Args: content (str): The content to truncate. max_tokens (int): The maximum number of tokens to keep.
Returns: str: The truncated content.
Source code in src/lampe/core/utils/token.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
Configuration
lampe.core.config
lampe.core.gitconfig
init_git()
Initialize Git configuration and check version requirements.
Source code in src/lampe/core/gitconfig.py
58 59 60 61 | |
valid_git_version_available() -> bool
Check if the installed Git version meets the minimum requirement.
Returns:
| Type | Description |
|---|---|
bool
|
True if Git version meets requirement, False otherwise |
Source code in src/lampe/core/gitconfig.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |