Skip to content

Commit 104c0a2

Browse files
author
codegen-bot
committed
.
1 parent b871535 commit 104c0a2

File tree

4 files changed

+333
-0
lines changed

4 files changed

+333
-0
lines changed

docs/blog/act-via-code.mdx

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
---
2+
title: "Act via Code"
3+
icon: "code"
4+
iconType: "solid"
5+
description: "The path to advanced code manipulation agents"
6+
---
7+
8+
The future of AI-powered software development isn't just about understanding code—it's about manipulating it effectively. As AI models become increasingly sophisticated in comprehending codebases, we're discovering that the real bottleneck isn't their "intelligence," but rather their ability to make precise, reliable changes to code. This is where the concept of "acting via code" becomes crucial.
9+
10+
## The Current Landscape
11+
12+
Today's AI coding assistants typically operate through:
13+
14+
- Generating complete code snippets
15+
- Suggesting text-based changes
16+
- Producing diffs for review
17+
18+
While these approaches work for simple tasks, they break down when dealing with complex, multi-file changes or large-scale refactors. The fundamental issue? They're trying to manipulate code as text, rather than as the structured data it really is.
19+
20+
## Why Acting via Code Matters
21+
22+
Acting via code means providing AI agents with programmatic interfaces to manipulate codebases. Instead of generating text patches, agents can express transformations through code itself. This approach offers several key advantages:
23+
24+
1. **Precision and Reliability**
25+
26+
- Changes are expressed through well-defined operations
27+
- Dependencies and references are handled automatically
28+
- Transformations are composable and reusable
29+
30+
2. **Scale and Consistency**
31+
32+
- Changes can be applied across massive codebases
33+
- Transformations remain consistent across files
34+
- Complex refactors become tractable
35+
36+
3. **Verifiability and Safety**
37+
- Changes are expressed in a reviewable format
38+
- Transformations can be tested before application
39+
- Operations can be rolled back if needed
40+
41+
## Building Blocks for AI Agents
42+
43+
For AI agents to effectively manipulate code, they need:
44+
45+
1. **A Natural Mental Model**
46+
47+
- Operations that match how developers think about code changes
48+
- High-level abstractions for common patterns
49+
- Clear semantics for transformations
50+
51+
2. **Composable Primitives**
52+
53+
- Basic operations that can be combined
54+
- Tools for building higher-level abstractions
55+
- Ways to express complex transformations
56+
57+
3. **Rich Static Analysis**
58+
- Understanding of dependencies and references
59+
- Analysis of control flow and types
60+
- Knowledge of cross-file relationships
61+
62+
## The Path Forward
63+
64+
As we move toward more advanced AI coding agents, the ability to act via code becomes increasingly critical. Future AI systems will need to:
65+
66+
1. **Build Their Own Tools**
67+
68+
- Create custom abstractions for common patterns
69+
- Develop specialized transformation utilities
70+
- Maintain their own libraries of operations
71+
72+
2. **Reason About Changes**
73+
74+
- Understand the impact of transformations
75+
- Plan complex refactoring operations
76+
- Verify the correctness of changes
77+
78+
3. **Learn From Experience**
79+
- Improve transformation strategies over time
80+
- Develop better abstractions through use
81+
- Share knowledge across different contexts
82+
83+
## Conclusion
84+
85+
The path to advanced AI coding agents isn't just about better language models—it's about giving those models the right tools to manipulate code effectively. By enabling AI to "act via code," we create a foundation for more sophisticated, reliable, and scalable code transformation capabilities.
86+
87+
Just as self-driving cars need sophisticated controls to navigate the physical world, AI coding agents need powerful, precise interfaces to manipulate codebases. This programmatic approach creates a shared language that both humans and AI can use to express, verify, and apply code changes reliably at scale.
88+
89+
The future of AI-powered development lies not in generating better patches or diffs, but in enabling AI to work with code the way developers do: through code itself.

docs/blog/codemod-frameworks.mdx

Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
---
2+
title: "A Deep Dive into Codemod Frameworks"
3+
description: "Comparing popular tools for programmatic code transformation"
4+
icon: "code-compare"
5+
iconType: "solid"
6+
---
7+
8+
Code transformation tools have evolved significantly over the years, each offering unique approaches to programmatic code manipulation. Let's explore the strengths and limitations of major frameworks in this space.
9+
10+
## Python's AST Module
11+
12+
Python's built-in Abstract Syntax Tree (AST) module provides the foundation for Python code manipulation.
13+
14+
### Strengths
15+
16+
- Native Python implementation
17+
- No external dependencies
18+
- Full access to Python's syntax tree
19+
- Great for Python-specific transformations
20+
21+
### Limitations
22+
23+
- Python-only
24+
- Low-level API requiring deep AST knowledge
25+
- Manual handling of formatting and comments
26+
- No cross-file awareness
27+
28+
```python
29+
import ast
30+
31+
class NameTransformer(ast.NodeTransformer):
32+
def visit_Name(self, node):
33+
if node.id == 'old_name':
34+
return ast.Name(id='new_name', ctx=node.ctx)
35+
return node
36+
```
37+
38+
## LibCST
39+
40+
Meta's Concrete Syntax Tree library offers a more modern approach to Python code modification.
41+
42+
### Strengths
43+
44+
- Preserves formatting and comments
45+
- Type annotations support
46+
- Visitor pattern API
47+
- Excellent documentation
48+
- Supports codemods at scale
49+
50+
### Limitations
51+
52+
- Python-only
53+
- Steeper learning curve
54+
- Slower than raw AST manipulation
55+
- Memory-intensive for large codebases
56+
57+
```python
58+
import libcst as cst
59+
60+
class NameTransformer(cst.CSTTransformer):
61+
def leave_Name(self, original_node, updated_node):
62+
if original_node.value == "old_name":
63+
return updated_node.with_changes(value="new_name")
64+
return updated_node
65+
```
66+
67+
## jscodeshift
68+
69+
The pioneer of JavaScript codemods, jscodeshift remains a staple in the JS ecosystem.
70+
71+
### Strengths
72+
73+
- Robust JavaScript/TypeScript support
74+
- Rich ecosystem of transforms
75+
- Familiar jQuery-like API
76+
- Battle-tested at scale
77+
78+
### Limitations
79+
80+
- JavaScript/TypeScript only
81+
- Limited type information
82+
- Can be verbose for simple transforms
83+
- Documentation could be better
84+
85+
```javascript
86+
export default function transformer(file, api) {
87+
const j = api.jscodeshift;
88+
return j(file.source)
89+
.find(j.Identifier)
90+
.filter((path) => path.node.name === "old_name")
91+
.replaceWith((path) => j.identifier("new_name"))
92+
.toSource();
93+
}
94+
```
95+
96+
## ts-morph
97+
98+
A TypeScript-first transformation tool with rich type system integration.
99+
100+
### Strengths
101+
102+
- First-class TypeScript support
103+
- Excellent type information access
104+
- High-level, intuitive API
105+
- Great documentation
106+
- Project-wide analysis capabilities
107+
108+
### Limitations
109+
110+
- TypeScript/JavaScript only
111+
- Higher memory usage
112+
- Can be slower for large projects
113+
- More complex setup than alternatives
114+
115+
```typescript
116+
import { Project } from "ts-morph";
117+
118+
const project = new Project();
119+
project.addSourceFileAtPath("src/**/*.ts");
120+
project.getSourceFiles().forEach((sourceFile) => {
121+
sourceFile
122+
.getDescendantsOfKind(SyntaxKind.Identifier)
123+
.filter((node) => node.getText() === "old_name")
124+
.forEach((node) => node.replaceWithText("new_name"));
125+
});
126+
```
127+
128+
## ast-grep
129+
130+
A modern, language-agnostic code searching and rewriting tool.
131+
132+
### Strengths
133+
134+
- Multi-language support
135+
- Fast pattern matching
136+
- Simple YAML-based rules
137+
- Great for quick transformations
138+
- Excellent performance
139+
140+
### Limitations
141+
142+
- Limited complex transformation support
143+
- Newer, less battle-tested
144+
- Smaller ecosystem
145+
- Less granular control
146+
147+
```yaml
148+
rules:
149+
- pattern: old_name
150+
replace: new_name
151+
```
152+
153+
## tree-sitter
154+
155+
The foundation many modern tools build upon, offering lightning-fast parsing and analysis.
156+
157+
### Strengths
158+
159+
- Incredible performance
160+
- Multi-language support
161+
- Incremental parsing
162+
- Language-agnostic design
163+
- Growing ecosystem
164+
165+
### Limitations
166+
167+
- Lower-level API
168+
- Requires language-specific grammars
169+
- Manual handling of transformations
170+
- Steeper learning curve
171+
172+
```javascript
173+
const Parser = require("tree-sitter");
174+
const JavaScript = require("tree-sitter-javascript");
175+
176+
const parser = new Parser();
177+
parser.setLanguage(JavaScript);
178+
const tree = parser.parse('console.log("Hello")');
179+
```
180+
181+
## Choosing the Right Tool
182+
183+
The choice of codemod framework depends heavily on your specific needs:
184+
185+
- **Single Language Focus**: If you're working exclusively with one language, use its specialized tools:
186+
187+
- Python → LibCST
188+
- TypeScript → ts-morph
189+
- JavaScript → jscodeshift
190+
191+
- **Multi-Language Projects**: Consider:
192+
193+
- ast-grep for simple transformations
194+
- tree-sitter for building custom tools
195+
- A combination of specialized tools
196+
197+
- **Scale Considerations**:
198+
- Small projects → Any tool works
199+
- Medium scale → Language-specific tools
200+
- Large scale → Need proper tooling support (LibCST, ts-morph)
201+
202+
## The Future of Codemods
203+
204+
As codebases grow and AI becomes more prevalent, we're seeing a shift toward:
205+
206+
1. **More Intelligent Tools**
207+
208+
- Better type awareness
209+
- Improved cross-file analysis
210+
- AI-assisted transformations
211+
212+
2. **Universal Approaches**
213+
214+
- Language-agnostic frameworks
215+
- Unified transformation APIs
216+
- Better interoperability
217+
218+
3. **Enhanced Developer Experience**
219+
- Simpler APIs
220+
- Better debugging tools
221+
- Richer ecosystems
222+
223+
The ideal codemod framework of the future will likely combine the best aspects of current tools: the type awareness of ts-morph, the simplicity of ast-grep, the performance of tree-sitter, and the reliability of LibCST.

docs/blog/posts.mdx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
title: "All Posts"
3+
icon: "clock"
4+
iconType: "solid"
5+
---
6+
7+
<Update label="2024-01-24" description="A Deep Dive into Codemod Frameworks">
8+
Comparing popular tools for programmatic code transformation
9+
</Update>
10+
11+
<Update label="2024-01-24" description="Acting via Code">
12+
The path to advanced code manipulation agents
13+
</Update>

docs/mint.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@
4646
{
4747
"name": "Changelog",
4848
"url": "/changelog"
49+
},
50+
{
51+
"name": "Blog",
52+
"url": "/blog"
4953
}
5054
],
5155
"navigation": [
@@ -127,6 +131,10 @@
127131
"group": "Changelog",
128132
"pages": ["changelog/changelog"]
129133
},
134+
{
135+
"group": "Blog",
136+
"pages": ["blog/posts", "blog/act-via-code"]
137+
},
130138
{
131139
"group": "API Reference",
132140
"pages": [

0 commit comments

Comments
 (0)