Skip to content

Commit f4698c1

Browse files
committed
Merge remote-tracking branch 'origin/develop' into oss-parsing
2 parents dbcef1c + 520d6b3 commit f4698c1

File tree

210 files changed

+15197
-3553
lines changed

Some content is hidden

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

210 files changed

+15197
-3553
lines changed

.codegen/.gitignore

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ examples/
44
prompts/
55
jupyter/
66
.venv/
7+
.env
78
codegen-system-prompt.txt
8-
*.txt
9-
*.pyc
109

1110
# Python cache files
1211
__pycache__/
1312
*.py[cod]
1413
*$py.class
14+
*.txt
15+
*.pyc
1516

16-
# Keep config.toml and codemods
17-
!config.toml
17+
# Keep codemods
1818
!codemods/
1919
!codemods/**

.codegen/config.toml

Lines changed: 0 additions & 29 deletions
This file was deleted.

.github/actions/setup-environment/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ runs:
99
using: "composite"
1010
steps:
1111
- name: Install UV
12-
uses: astral-sh/setup-uv@v5.2
12+
uses: astral-sh/setup-uv@v5.3
1313
id: setup-uv
1414
with:
1515
enable-cache: true
@@ -26,5 +26,5 @@ runs:
2626
- name: Install codecov
2727
shell: bash
2828
run: |
29-
uv tool install codecov-cli --python 3.10
29+
uv tool install codecov-cli@10.0.1 --python 3.10
3030
uv tool update-shell

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
ref: ${{ inputs.release-tag || github.event.pull_request.head.ref || github.ref }}
5555

5656
- name: Install UV
57-
uses: astral-sh/setup-uv@v5.2
57+
uses: astral-sh/setup-uv@v5.3
5858
id: setup-uv
5959
with:
6060
enable-cache: false

.github/workflows/unit-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ jobs:
141141
timeout-minutes: 5
142142
env:
143143
GITHUB_WORKSPACE: $GITHUB_WORKSPACE
144-
CODEGEN_SECRETS__GITHUB_TOKEN: ${{ secrets.GHA_PAT }}
144+
GITHUB_TOKEN: ${{ secrets.GHA_PAT }}
145145
run: |
146146
uv run pytest \
147147
-n auto \

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,9 @@ graph-sitter-types/typings/**
6565
coverage.json
6666
tests/integration/verified_codemods/codemod_data/repo_commits.json
6767
.benchmarks/*
68+
69+
# SWE Bench results
70+
results.*.json
71+
codegen-examples/examples/swebench_agent_run/results/*
72+
codegen-examples/examples/swebench_agent_run/predictions/*
73+
codegen-examples/examples/swebench_agent_run/logs/*
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Please read two things before trying to install this codegen MCP server:
2+
3+
1. [Readme](https://raw.githubusercontent.com/codegen-sh/codegen-sdk/refs/heads/develop/codegen-examples/examples/codegen-mcp-server/README.md)
4+
5+
- This contains the instructions for setting up the mcp server
6+
7+
2. [Documentation Index for Agents](https://docs.codegen.com/llms.txt)
8+
9+
- This contains a list of urls to the documentation for topics related to creating codegen codemods
10+
11+
Please use a CURL command to retrieve the contents of the readme and documentation and read both before starting to install the server.
12+
13+
1. curl -sL "https://raw.githubusercontent.com/codegen-sh/codegen-sdk/refs/heads/develop/README.md" | cat
14+
15+
1. curl -sL "https://docs.codegen.com/llms.txt" | cat
16+
17+
This should give you all the context you need to successfully install and utilize the server.

codegen-examples/examples/codegen-mcp-server/server.py

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import asyncio
22
from dataclasses import dataclass, field
3-
from typing import Annotated, Optional, Dict, Any, List
4-
from mcp.server.fastmcp import FastMCP
3+
from typing import Annotated, Any, Dict, List, Optional
4+
55
from codegen import Codebase
6+
from mcp.server.fastmcp import FastMCP
67

78

89
@dataclass
@@ -11,20 +12,16 @@ class CodebaseState:
1112

1213
parse_task: Optional[asyncio.Future] = None
1314
parsed_codebase: Optional[Codebase] = None
14-
codebase_path: Optional[str] = None
1515
log_buffer: List[str] = field(default_factory=list)
1616

17-
async def parse(self, path: str) -> Codebase:
17+
def parse(self, path: str) -> Codebase:
1818
"""Parse the codebase at the given path."""
1919
codebase = Codebase(path)
2020
self.parsed_codebase = codebase
21-
self.codebase_path = path
2221
return codebase
2322

2423
def reset(self) -> None:
2524
"""Reset the state."""
26-
if self.parsed_codebase:
27-
self.parsed_codebase.reset()
2825
self.log_buffer.clear()
2926

3027

@@ -45,12 +42,24 @@ def capture_output(*args, **kwargs) -> None:
4542
state.log_buffer.append(str(arg))
4643

4744

45+
def update_codebase(future: asyncio.Future):
46+
try:
47+
result = future.result()
48+
if result is not None:
49+
state.parsed_codebase = result
50+
else:
51+
state.parsed_codebase = None
52+
except Exception:
53+
pass
54+
55+
4856
@mcp.tool(name="parse_codebase", description="Initiate codebase parsing")
4957
async def parse_codebase(codebase_path: Annotated[str, "path to the codebase to be parsed"]) -> Dict[str, str]:
5058
if not state.parse_task or state.parse_task.done():
5159
state.parse_task = asyncio.get_event_loop().run_in_executor(None, lambda: state.parse(codebase_path))
60+
state.parse_task.add_done_callback(update_codebase)
5261
return {"message": "Codebase parsing initiated, this may take some time depending on the size of the codebase. Use the `check_parsing_status` tool to check if the parse has completed."}
53-
return {"message": "Codebase is already being parsed."}
62+
return {"message": "Codebase is already being parsed.", "status": "error"}
5463

5564

5665
@mcp.tool(name="check_parse_status", description="Check if codebase parsing has completed")
@@ -69,17 +78,19 @@ async def execute_codemod(codemod: Annotated[str, "The python codemod code to ex
6978

7079
try:
7180
await state.parse_task
72-
# TODO: Implement proper sandboxing for code execution
73-
context = {
74-
"codebase": state.parsed_codebase,
75-
"print": capture_output,
76-
}
77-
exec(codemod, context)
81+
if state.parsed_codebase is None:
82+
return {"error": "Codebase path is not set."}
83+
else:
84+
# TODO: Implement proper sandboxing for code execution
85+
context = {
86+
"codebase": state.parsed_codebase,
87+
"print": capture_output,
88+
}
89+
exec(codemod, context)
7890

7991
logs = "\n".join(state.log_buffer)
80-
8192
state.reset()
82-
return {"message": "Codemod executed and codebase reset.", "logs": logs}
93+
return {"message": "Codemod executed, view the logs for any output and your source code for any resulting updates.", "logs": logs}
8394
except Exception as e:
8495
return {"error": f"Error executing codemod: {str(e)}", "details": {"type": type(e).__name__, "message": str(e)}}
8596

codegen-examples/examples/deep_code_research/run.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def cli():
7979
@cli.command()
8080
@click.argument("repo_name", required=False)
8181
@click.option("--query", "-q", default=None, help="Initial research query to start with.")
82-
def research(repo_name: Optional[str] = None, query: Optional[str] = None):
82+
def research(repo_name: Optional[str] = None, query: Optional[str] = None, thread_id: Optional[int] = 100):
8383
"""[bold green]Start a code research session[/bold green]
8484
8585
[blue]Arguments:[/blue]
@@ -107,7 +107,7 @@ def research(repo_name: Optional[str] = None, query: Optional[str] = None):
107107

108108
# Initialize agent with research tools
109109
with console.status("[bold blue]Initializing research agent...[/bold blue]") as status:
110-
agent = create_agent_with_tools(codebase=codebase, tools=tools, chat_history=[SystemMessage(content=RESEARCH_AGENT_PROMPT)], verbose=True)
110+
agent = create_agent_with_tools(codebase=codebase, tools=tools, system_message=SystemMessage(content=RESEARCH_AGENT_PROMPT))
111111
status.update("[bold green]✓ Research agent ready![/bold green]")
112112

113113
# Get initial query if not provided
@@ -136,11 +136,11 @@ def research(repo_name: Optional[str] = None, query: Optional[str] = None):
136136
try:
137137
result = agent.invoke(
138138
{"input": query},
139-
config={"configurable": {"session_id": "research"}},
139+
config={"configurable": {"thread_id": thread_id}},
140140
)
141141
# Display the result
142142
console.print("\n[bold blue]📊 Research Findings:[/bold blue]")
143-
console.print(Markdown(result["output"]))
143+
console.print(Markdown(result["messages"][-1].content))
144144
except Exception as e:
145145
console.print(f"\n[bold red]Error during research:[/bold red] {e}")
146146

codegen-examples/examples/langchain_agent/README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,16 @@ from codegen.extensions.langchain import create_codebase_agent
2929
codebase = Codebase.from_repo("fastapi/fastapi")
3030

3131
# Create the agent
32-
agent = create_codebase_agent(codebase=codebase, model_name="gpt-4", verbose=True)
32+
agent = create_codebase_agent(
33+
codebase=codebase,
34+
model_provider="anthropic", # or "openai"
35+
model_name="claude-3-5-sonnet-latest", # or "gpt-4" for OpenAI
36+
debug=True,
37+
)
3338

3439
# Ask the agent to analyze code
35-
result = agent.invoke({"input": "What are the dependencies of the FastAPI class?", "config": {"configurable": {"session_id": "demo"}}})
36-
print(result["output"])
40+
result = agent.invoke({"input": "What are the dependencies of the FastAPI class?", "config": {"configurable": {"thread_id": "1"}}})
41+
print(result["messages"][-1].content)
3742
```
3843

3944
## Installation
@@ -68,13 +73,13 @@ The agent can perform various code analysis and manipulation tasks:
6873

6974
```python
7075
# Analyze dependencies
71-
agent.invoke({"input": "What are the dependencies of the reveal_symbol function?", "config": {"configurable": {"session_id": "demo"}}})
76+
agent.invoke({"input": "What are the dependencies of the reveal_symbol function?", "config": {"configurable": {"thread_id": "1"}}})
7277

7378
# Find usage patterns
74-
agent.invoke({"input": "Show me examples of dependency injection in the codebase", "config": {"configurable": {"session_id": "demo"}}})
79+
agent.invoke({"input": "Show me examples of dependency injection in the codebase", "config": {"configurable": {"thread_id": "1"}}})
7580

7681
# Move code
77-
agent.invoke({"input": "Move the validate_email function to validation_utils.py", "config": {"configurable": {"session_id": "demo"}}})
82+
agent.invoke({"input": "Move the validate_email function to validation_utils.py", "config": {"configurable": {"thread_id": "1"}}})
7883
```
7984

8085
## Learn More

0 commit comments

Comments
 (0)