Skip to content

Commit a9bcdd4

Browse files
authored
Merge pull request #64 from drivecore/feature/refactor-tool-agent
Refactor toolAgent.ts into modular components
2 parents 82f9759 + ba7774d commit a9bcdd4

39 files changed

+965
-825
lines changed

.changeset/convert-to-zod.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'mycoder-agent': minor
3+
'mycoder': minor
4+
---
5+
6+
Convert from JsonSchema7Type to ZodSchema for tool parameters and returns, required for Vercel AI SDK integration.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'mycoder-agent': patch
3+
---
4+
5+
Re-implemented token caching for Vercel AI SDK usage with Anthropic provider to reduce token consumption during repeated API calls.

.changeset/refactor-tool-agent.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'mycoder-agent': minor
3+
---
4+
5+
Refactored toolAgent.ts into modular components for improved maintainability and testability. Split into config.ts, messageUtils.ts, toolExecutor.ts, tokenTracking.ts, and types.ts modules.

.changeset/temp-changeset-message.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

CONTRIBUTING.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,19 @@ This project and everyone participating in it is governed by our Code of Conduct
8080
5. Push to your fork and create a Pull Request
8181

8282
6. Pre-commit Hooks:
83-
83+
8484
We use [husky](https://typicode.github.io/husky/) and [lint-staged](https://github.com/okonet/lint-staged) to automatically run linting and formatting on staged files before each commit. This helps maintain code quality and consistency.
8585

8686
The pre-commit hooks are configured to run:
87-
- `pnpm lint`: Lints the staged files using ESLint
87+
88+
- `pnpm lint`: Lints the staged files using ESLint
8889
- `pnpm format`: Formats the staged files using Prettier
8990

9091
If either of these commands fails due to linting errors or formatting issues, the commit will be aborted. Please fix the reported issues and try committing again.
9192

9293
You can also run the lint and format commands manually at any time:
93-
```bash
94+
95+
```bash
9496
pnpm lint # Lint all files
9597
pnpm format # Format all files
9698
```

docs/LargeCodeBase_Plan.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,19 @@ This document presents research findings on how leading AI coding tools handle l
1111
While detailed technical documentation on Claude Code's internal architecture is limited in public sources, we can infer several approaches from Anthropic's general AI architecture and Claude Code's capabilities:
1212

1313
1. **Chunking and Retrieval Augmentation**:
14+
1415
- Claude Code likely employs retrieval-augmented generation (RAG) to handle large codebases
1516
- Files are likely chunked into manageable segments with semantic understanding
1617
- Relevant code chunks are retrieved based on query relevance
1718

1819
2. **Hierarchical Code Understanding**:
20+
1921
- Builds a hierarchical representation of code (project → modules → files → functions)
2022
- Maintains a graph of relationships between code components
2123
- Prioritizes context based on relevance to the current task
2224

2325
3. **Incremental Context Management**:
26+
2427
- Dynamically adjusts the context window to include only relevant code
2528
- Maintains a "working memory" of recently accessed or modified files
2629
- Uses sliding context windows to process large files sequentially
@@ -35,16 +38,19 @@ While detailed technical documentation on Claude Code's internal architecture is
3538
Aider's approach to handling large codebases can be inferred from its open-source codebase and documentation:
3639

3740
1. **Git Integration**:
41+
3842
- Leverages Git to track file changes and understand repository structure
3943
- Uses Git history to prioritize recently modified files
4044
- Employs Git's diff capabilities to minimize context needed for changes
4145

4246
2. **Selective File Context**:
47+
4348
- Only includes relevant files in the context rather than the entire codebase
4449
- Uses heuristics to identify related files based on imports, references, and naming patterns
4550
- Implements a "map-reduce" approach where it first analyzes the codebase structure, then selectively processes relevant files
4651

4752
3. **Prompt Engineering and Chunking**:
53+
4854
- Designs prompts that can work with limited context by focusing on specific tasks
4955
- Chunks large files and processes them incrementally
5056
- Uses summarization to compress information about non-focal code parts
@@ -90,6 +96,7 @@ Based on the research findings, we recommend the following enhancements to MyCod
9096
```
9197

9298
**Implementation Details:**
99+
93100
- Create a lightweight indexer that runs during project initialization
94101
- Generate embeddings for code files, focusing on API definitions, function signatures, and documentation
95102
- Build a graph of relationships between files based on imports/exports and references
@@ -120,6 +127,7 @@ Based on the research findings, we recommend the following enhancements to MyCod
120127
```
121128

122129
**Implementation Details:**
130+
123131
- Develop a working set manager that tracks currently relevant files
124132
- Implement a relevance scoring algorithm that considers:
125133
- Semantic similarity to the current task
@@ -148,6 +156,7 @@ Based on the research findings, we recommend the following enhancements to MyCod
148156
```
149157

150158
**Implementation Details:**
159+
151160
- Chunk files at meaningful boundaries (functions, classes, modules)
152161
- Implement overlapping chunks to maintain context across boundaries
153162
- Develop a progressive loading strategy:
@@ -181,6 +190,7 @@ Based on the research findings, we recommend the following enhancements to MyCod
181190
```
182191

183192
**Implementation Details:**
193+
184194
- Implement a multi-level caching system:
185195
- Token cache: Store tokenized representations of files to avoid re-tokenization
186196
- Embedding cache: Store vector embeddings for semantic search
@@ -209,6 +219,7 @@ Based on the research findings, we recommend the following enhancements to MyCod
209219
```
210220

211221
**Implementation Details:**
222+
212223
- Improve task decomposition to identify parallelizable sub-tasks
213224
- Implement smart context distribution to sub-agents:
214225
- Provide each sub-agent with only the context it needs
@@ -222,16 +233,19 @@ Based on the research findings, we recommend the following enhancements to MyCod
222233
## Implementation Roadmap
223234

224235
### Phase 1: Foundation (1-2 months)
236+
225237
- Develop the basic indexing system for project structure and file metadata
226238
- Implement a simple relevance-based context selection mechanism
227239
- Create a basic chunking strategy for large files
228240

229241
### Phase 2: Advanced Features (2-3 months)
242+
230243
- Implement the semantic indexing system with code embeddings
231244
- Develop the full context management system with working sets
232245
- Create the multi-level caching system
233246

234247
### Phase 3: Optimization and Integration (1-2 months)
248+
235249
- Enhance sub-agent coordination for parallel processing
236250
- Optimize performance with better caching and context management
237251
- Integrate all components into a cohesive system

docs/SentryIntegration.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ npm install @sentry/node --save
1717
## Configuration
1818

1919
By default, Sentry is:
20+
2021
- Enabled in production environments
2122
- Disabled in development environments (unless explicitly enabled)
2223
- Configured to capture 100% of transactions
@@ -56,7 +57,9 @@ Sentry.init({
5657
tracesSampleRate: 1.0,
5758
environment: process.env.NODE_ENV || 'development',
5859
release: `mycoder@${packageVersion}`,
59-
enabled: process.env.NODE_ENV !== 'development' || process.env.ENABLE_SENTRY === 'true',
60+
enabled:
61+
process.env.NODE_ENV !== 'development' ||
62+
process.env.ENABLE_SENTRY === 'true',
6063
});
6164

6265
// Capture errors
@@ -76,6 +79,7 @@ mycoder test-sentry
7679
```
7780

7881
This command will:
82+
7983
1. Generate a test error that includes the package version
8084
2. Report it to Sentry.io
8185
3. Output the result to the console
@@ -85,6 +89,7 @@ Note: In development environments, you may need to set `ENABLE_SENTRY=true` for
8589
## Privacy
8690

8791
Error reports sent to Sentry include:
92+
8893
- Stack traces
8994
- Error messages
9095
- Environment information

packages/agent/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,16 @@
4444
"author": "Ben Houston",
4545
"license": "MIT",
4646
"dependencies": {
47-
"@anthropic-ai/sdk": "^0.37",
47+
"@ai-sdk/anthropic": "^1.1.13",
48+
"@ai-sdk/openai": "^1.2.0",
4849
"@mozilla/readability": "^0.5.0",
4950
"@playwright/test": "^1.50.1",
5051
"@vitest/browser": "^3.0.5",
52+
"ai": "^4.1.50",
5153
"chalk": "^5.4.1",
5254
"dotenv": "^16",
5355
"jsdom": "^26.0.0",
56+
"ollama-ai-provider": "^1.2.0",
5457
"playwright": "^1.50.1",
5558
"uuid": "^11",
5659
"zod": "^3.24.2",

packages/agent/src/core/tokens.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Anthropic from '@anthropic-ai/sdk';
1+
//import Anthropic from '@anthropic-ai/sdk';
22

33
import { LogLevel } from '../utils/logger.js';
44

@@ -34,14 +34,15 @@ export class TokenUsage {
3434
return usage;
3535
}
3636

37+
/*
3738
static fromMessage(message: Anthropic.Message) {
3839
const usage = new TokenUsage();
3940
usage.input = message.usage.input_tokens;
4041
usage.cacheWrites = message.usage.cache_creation_input_tokens ?? 0;
4142
usage.cacheReads = message.usage.cache_read_input_tokens ?? 0;
4243
usage.output = message.usage.output_tokens;
4344
return usage;
44-
}
45+
}*/
4546

4647
static sum(usages: TokenUsage[]) {
4748
const usage = new TokenUsage();

packages/agent/src/core/toolAgent.respawn.test.ts

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

0 commit comments

Comments
 (0)