agentic-flow 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +87 -12
- package/dist/agents/claudeAgent.js +96 -67
- package/dist/cli/claude-code-wrapper.js +23 -1
- package/dist/cli-proxy.js +71 -5
- package/dist/mcp/standalone-stdio.js +251 -2
- package/dist/proxy/anthropic-to-requesty.js +707 -0
- package/dist/utils/cli.js +6 -0
- package/dist/utils/modelCapabilities.js +22 -0
- package/docs/plans/agent-booster/00-INDEX.md +230 -0
- package/docs/plans/agent-booster/00-OVERVIEW.md +454 -0
- package/docs/plans/agent-booster/01-ARCHITECTURE.md +699 -0
- package/docs/plans/agent-booster/02-INTEGRATION.md +771 -0
- package/docs/plans/agent-booster/03-BENCHMARKS.md +616 -0
- package/docs/plans/agent-booster/04-NPM-SDK.md +673 -0
- package/docs/plans/agent-booster/GITHUB-ISSUE.md +523 -0
- package/docs/plans/agent-booster/README.md +576 -0
- package/docs/plans/requesty/00-overview.md +176 -0
- package/docs/plans/requesty/01-api-research.md +573 -0
- package/docs/plans/requesty/02-architecture.md +1076 -0
- package/docs/plans/requesty/03-implementation-phases.md +1129 -0
- package/docs/plans/requesty/04-testing-strategy.md +905 -0
- package/docs/plans/requesty/05-migration-guide.md +576 -0
- package/docs/plans/requesty/README.md +290 -0
- package/package.json +1 -1
|
@@ -0,0 +1,673 @@
|
|
|
1
|
+
# Agent Booster: NPM SDK & CLI Design
|
|
2
|
+
|
|
3
|
+
## 📦 NPM Package Structure
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
npm/
|
|
7
|
+
├── agent-booster/ # Main SDK package
|
|
8
|
+
│ ├── package.json
|
|
9
|
+
│ ├── index.js # Auto-detection loader
|
|
10
|
+
│ ├── index.d.ts # TypeScript definitions
|
|
11
|
+
│ ├── native/ # Native addon binaries
|
|
12
|
+
│ │ ├── index.node # Auto-selected by platform
|
|
13
|
+
│ │ ├── linux-x64.node
|
|
14
|
+
│ │ ├── darwin-x64.node
|
|
15
|
+
│ │ ├── darwin-arm64.node
|
|
16
|
+
│ │ └── win32-x64.node
|
|
17
|
+
│ ├── wasm/ # WebAssembly fallback
|
|
18
|
+
│ │ ├── agent_booster_bg.wasm
|
|
19
|
+
│ │ └── agent_booster.js
|
|
20
|
+
│ └── README.md
|
|
21
|
+
│
|
|
22
|
+
└── agent-booster-cli/ # Standalone CLI
|
|
23
|
+
├── package.json
|
|
24
|
+
├── bin/
|
|
25
|
+
│ └── agent-booster.js # CLI entry point
|
|
26
|
+
├── commands/
|
|
27
|
+
│ ├── apply.js
|
|
28
|
+
│ ├── batch.js
|
|
29
|
+
│ ├── watch.js
|
|
30
|
+
│ ├── mcp.js
|
|
31
|
+
│ └── dashboard.js
|
|
32
|
+
└── README.md
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## 🎯 Main SDK Package
|
|
36
|
+
|
|
37
|
+
### package.json
|
|
38
|
+
|
|
39
|
+
```json
|
|
40
|
+
{
|
|
41
|
+
"name": "agent-booster",
|
|
42
|
+
"version": "0.1.0",
|
|
43
|
+
"description": "Ultra-fast code application engine for AI agents (200x faster than LLMs)",
|
|
44
|
+
"main": "index.js",
|
|
45
|
+
"types": "index.d.ts",
|
|
46
|
+
"keywords": [
|
|
47
|
+
"ai",
|
|
48
|
+
"code-editing",
|
|
49
|
+
"ast",
|
|
50
|
+
"semantic-merge",
|
|
51
|
+
"vector-embeddings",
|
|
52
|
+
"llm",
|
|
53
|
+
"morph-alternative",
|
|
54
|
+
"agentic-flow",
|
|
55
|
+
"mcp",
|
|
56
|
+
"rust",
|
|
57
|
+
"napi",
|
|
58
|
+
"wasm"
|
|
59
|
+
],
|
|
60
|
+
"author": "Your Name <your@email.com>",
|
|
61
|
+
"license": "MIT OR Apache-2.0",
|
|
62
|
+
"repository": {
|
|
63
|
+
"type": "git",
|
|
64
|
+
"url": "https://github.com/your-org/agent-booster.git"
|
|
65
|
+
},
|
|
66
|
+
"engines": {
|
|
67
|
+
"node": ">=16.0.0"
|
|
68
|
+
},
|
|
69
|
+
"os": ["linux", "darwin", "win32"],
|
|
70
|
+
"cpu": ["x64", "arm64"],
|
|
71
|
+
"files": [
|
|
72
|
+
"index.js",
|
|
73
|
+
"index.d.ts",
|
|
74
|
+
"native/",
|
|
75
|
+
"wasm/",
|
|
76
|
+
"README.md",
|
|
77
|
+
"LICENSE"
|
|
78
|
+
],
|
|
79
|
+
"optionalDependencies": {
|
|
80
|
+
"@agent-booster/linux-x64": "0.1.0",
|
|
81
|
+
"@agent-booster/darwin-x64": "0.1.0",
|
|
82
|
+
"@agent-booster/darwin-arm64": "0.1.0",
|
|
83
|
+
"@agent-booster/win32-x64": "0.1.0"
|
|
84
|
+
},
|
|
85
|
+
"dependencies": {
|
|
86
|
+
"detect-libc": "^2.0.2"
|
|
87
|
+
},
|
|
88
|
+
"devDependencies": {
|
|
89
|
+
"@types/node": "^20.0.0",
|
|
90
|
+
"typescript": "^5.0.0"
|
|
91
|
+
},
|
|
92
|
+
"scripts": {
|
|
93
|
+
"postinstall": "node scripts/download-model.js",
|
|
94
|
+
"test": "node test/index.js"
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### index.js (Auto-Detection Loader)
|
|
100
|
+
|
|
101
|
+
```javascript
|
|
102
|
+
// npm/agent-booster/index.js
|
|
103
|
+
|
|
104
|
+
const os = require('os');
|
|
105
|
+
const path = require('path');
|
|
106
|
+
|
|
107
|
+
let AgentBooster = null;
|
|
108
|
+
|
|
109
|
+
// Try to load native addon first (fastest)
|
|
110
|
+
function loadNative() {
|
|
111
|
+
try {
|
|
112
|
+
const platform = os.platform();
|
|
113
|
+
const arch = os.arch();
|
|
114
|
+
const nativeBinding = `${platform}-${arch}.node`;
|
|
115
|
+
|
|
116
|
+
// Try platform-specific package
|
|
117
|
+
try {
|
|
118
|
+
const platformPackage = `@agent-booster/${platform}-${arch}`;
|
|
119
|
+
AgentBooster = require(platformPackage).AgentBooster;
|
|
120
|
+
console.log(`[agent-booster] Using native addon (${platform}-${arch})`);
|
|
121
|
+
return true;
|
|
122
|
+
} catch (e) {
|
|
123
|
+
// Fall through to bundled native
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Try bundled native addon
|
|
127
|
+
const nativePath = path.join(__dirname, 'native', nativeBinding);
|
|
128
|
+
AgentBooster = require(nativePath).AgentBooster;
|
|
129
|
+
console.log(`[agent-booster] Using bundled native addon (${platform}-${arch})`);
|
|
130
|
+
return true;
|
|
131
|
+
} catch (error) {
|
|
132
|
+
console.warn('[agent-booster] Native addon not available:', error.message);
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Fallback to WASM
|
|
138
|
+
function loadWasm() {
|
|
139
|
+
try {
|
|
140
|
+
const wasmModule = require('./wasm/agent_booster.js');
|
|
141
|
+
AgentBooster = wasmModule.AgentBooster;
|
|
142
|
+
console.log('[agent-booster] Using WebAssembly');
|
|
143
|
+
return true;
|
|
144
|
+
} catch (error) {
|
|
145
|
+
console.error('[agent-booster] WASM not available:', error.message);
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Load in order of preference
|
|
151
|
+
if (!loadNative()) {
|
|
152
|
+
if (!loadWasm()) {
|
|
153
|
+
throw new Error(
|
|
154
|
+
'Failed to load Agent Booster. Neither native addon nor WASM are available.\n' +
|
|
155
|
+
'Please report this issue: https://github.com/your-org/agent-booster/issues'
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
module.exports = { AgentBooster };
|
|
161
|
+
module.exports.default = AgentBooster;
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### index.d.ts (TypeScript Definitions)
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
// npm/agent-booster/index.d.ts
|
|
168
|
+
|
|
169
|
+
export interface AgentBoosterConfig {
|
|
170
|
+
/** Embedding model to use */
|
|
171
|
+
model?: 'jina-code-v2' | 'all-MiniLM-L6-v2' | string;
|
|
172
|
+
|
|
173
|
+
/** Confidence threshold (0-1). Edits below this will fail or fallback. */
|
|
174
|
+
confidenceThreshold?: number;
|
|
175
|
+
|
|
176
|
+
/** Enable fallback to Morph LLM when confidence is low */
|
|
177
|
+
fallbackToMorph?: boolean;
|
|
178
|
+
|
|
179
|
+
/** Morph API key (required if fallbackToMorph is true) */
|
|
180
|
+
morphApiKey?: string;
|
|
181
|
+
|
|
182
|
+
/** Model cache directory */
|
|
183
|
+
cacheDir?: string;
|
|
184
|
+
|
|
185
|
+
/** Maximum number of chunks to extract per file */
|
|
186
|
+
maxChunks?: number;
|
|
187
|
+
|
|
188
|
+
/** Enable embedding caching */
|
|
189
|
+
cacheEmbeddings?: boolean;
|
|
190
|
+
|
|
191
|
+
/** Enable debug logging */
|
|
192
|
+
debug?: boolean;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export interface EditRequest {
|
|
196
|
+
/** Original code content */
|
|
197
|
+
originalCode: string;
|
|
198
|
+
|
|
199
|
+
/** Edit description or snippet to apply */
|
|
200
|
+
editSnippet: string;
|
|
201
|
+
|
|
202
|
+
/** Programming language */
|
|
203
|
+
language?: 'javascript' | 'typescript' | 'python' | 'rust' | 'go' | 'java' | string;
|
|
204
|
+
|
|
205
|
+
/** Optional edit options */
|
|
206
|
+
options?: EditOptions;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export interface EditOptions {
|
|
210
|
+
/** Preferred merge strategy (auto-detected if not specified) */
|
|
211
|
+
strategy?: 'exact' | 'fuzzy' | 'insert' | 'append';
|
|
212
|
+
|
|
213
|
+
/** Minimum confidence required */
|
|
214
|
+
minConfidence?: number;
|
|
215
|
+
|
|
216
|
+
/** Enable syntax validation */
|
|
217
|
+
validateSyntax?: boolean;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export interface EditResult {
|
|
221
|
+
/** Merged code */
|
|
222
|
+
mergedCode: string;
|
|
223
|
+
|
|
224
|
+
/** Confidence score (0-1) */
|
|
225
|
+
confidence: number;
|
|
226
|
+
|
|
227
|
+
/** Merge strategy used */
|
|
228
|
+
strategy: 'exact_replace' | 'insert_before' | 'insert_after' | 'append' | 'fuzzy_replace';
|
|
229
|
+
|
|
230
|
+
/** Additional metadata */
|
|
231
|
+
metadata: EditMetadata;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export interface EditMetadata {
|
|
235
|
+
/** Latency in milliseconds */
|
|
236
|
+
latency_ms: number;
|
|
237
|
+
|
|
238
|
+
/** Matched chunk information */
|
|
239
|
+
matched_chunk?: {
|
|
240
|
+
start_line: number;
|
|
241
|
+
end_line: number;
|
|
242
|
+
node_type: string;
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
/** Syntax validation result */
|
|
246
|
+
syntax_valid: boolean;
|
|
247
|
+
|
|
248
|
+
/** Method used (native/wasm) */
|
|
249
|
+
method: 'native' | 'wasm';
|
|
250
|
+
|
|
251
|
+
/** Model used */
|
|
252
|
+
model: string;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export class AgentBooster {
|
|
256
|
+
constructor(config?: AgentBoosterConfig);
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Apply a single code edit
|
|
260
|
+
*/
|
|
261
|
+
applyEdit(request: EditRequest): Promise<EditResult>;
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Apply multiple edits in parallel
|
|
265
|
+
*/
|
|
266
|
+
batchApply(requests: EditRequest[]): Promise<EditResult[]>;
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Get current configuration
|
|
270
|
+
*/
|
|
271
|
+
getConfig(): AgentBoosterConfig;
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Update configuration
|
|
275
|
+
*/
|
|
276
|
+
updateConfig(config: Partial<AgentBoosterConfig>): void;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export default AgentBooster;
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
## 🖥️ Standalone CLI Package
|
|
283
|
+
|
|
284
|
+
### package.json
|
|
285
|
+
|
|
286
|
+
```json
|
|
287
|
+
{
|
|
288
|
+
"name": "agent-booster-cli",
|
|
289
|
+
"version": "0.1.0",
|
|
290
|
+
"description": "CLI for Agent Booster - ultra-fast code editing",
|
|
291
|
+
"bin": {
|
|
292
|
+
"agent-booster": "./bin/agent-booster.js"
|
|
293
|
+
},
|
|
294
|
+
"keywords": ["cli", "code-editing", "ai", "agent-booster"],
|
|
295
|
+
"author": "Your Name <your@email.com>",
|
|
296
|
+
"license": "MIT OR Apache-2.0",
|
|
297
|
+
"engines": {
|
|
298
|
+
"node": ">=16.0.0"
|
|
299
|
+
},
|
|
300
|
+
"dependencies": {
|
|
301
|
+
"agent-booster": "^0.1.0",
|
|
302
|
+
"commander": "^11.0.0",
|
|
303
|
+
"chalk": "^5.0.0",
|
|
304
|
+
"ora": "^7.0.0",
|
|
305
|
+
"glob": "^10.0.0",
|
|
306
|
+
"chokidar": "^3.5.0"
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
### bin/agent-booster.js
|
|
312
|
+
|
|
313
|
+
```javascript
|
|
314
|
+
#!/usr/bin/env node
|
|
315
|
+
|
|
316
|
+
const { Command } = require('commander');
|
|
317
|
+
const chalk = require('chalk');
|
|
318
|
+
const packageJson = require('../package.json');
|
|
319
|
+
|
|
320
|
+
const program = new Command();
|
|
321
|
+
|
|
322
|
+
program
|
|
323
|
+
.name('agent-booster')
|
|
324
|
+
.description('Ultra-fast code application engine for AI agents')
|
|
325
|
+
.version(packageJson.version);
|
|
326
|
+
|
|
327
|
+
// Commands
|
|
328
|
+
program
|
|
329
|
+
.command('apply <file> <edit>')
|
|
330
|
+
.description('Apply a single code edit')
|
|
331
|
+
.option('-m, --model <model>', 'Embedding model', 'jina-code-v2')
|
|
332
|
+
.option('-t, --threshold <threshold>', 'Confidence threshold', '0.65')
|
|
333
|
+
.option('--dry-run', 'Show result without writing')
|
|
334
|
+
.option('--fallback', 'Fallback to Morph LLM if needed')
|
|
335
|
+
.action(require('../commands/apply'));
|
|
336
|
+
|
|
337
|
+
program
|
|
338
|
+
.command('batch <edits-file>')
|
|
339
|
+
.description('Apply multiple edits from JSON file')
|
|
340
|
+
.option('-m, --model <model>', 'Embedding model', 'jina-code-v2')
|
|
341
|
+
.option('-o, --output <dir>', 'Output directory')
|
|
342
|
+
.option('--parallel <n>', 'Parallel jobs', '4')
|
|
343
|
+
.action(require('../commands/batch'));
|
|
344
|
+
|
|
345
|
+
program
|
|
346
|
+
.command('watch <path>')
|
|
347
|
+
.description('Watch directory for changes and apply edits')
|
|
348
|
+
.option('-m, --model <model>', 'Embedding model', 'jina-code-v2')
|
|
349
|
+
.option('--ignore <patterns>', 'Ignore patterns (comma-separated)')
|
|
350
|
+
.action(require('../commands/watch'));
|
|
351
|
+
|
|
352
|
+
program
|
|
353
|
+
.command('mcp')
|
|
354
|
+
.description('Start Model Context Protocol server')
|
|
355
|
+
.option('--port <port>', 'HTTP port (default: stdio)', '')
|
|
356
|
+
.option('--config <file>', 'Config file')
|
|
357
|
+
.action(require('../commands/mcp'));
|
|
358
|
+
|
|
359
|
+
program
|
|
360
|
+
.command('dashboard')
|
|
361
|
+
.description('Start web dashboard for metrics')
|
|
362
|
+
.option('-p, --port <port>', 'Port', '8080')
|
|
363
|
+
.action(require('../commands/dashboard'));
|
|
364
|
+
|
|
365
|
+
program
|
|
366
|
+
.command('download-models')
|
|
367
|
+
.description('Download embedding models')
|
|
368
|
+
.option('-m, --model <models>', 'Models to download (comma-separated)', 'jina-code-v2')
|
|
369
|
+
.action(require('../commands/download-models'));
|
|
370
|
+
|
|
371
|
+
program.parse();
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
### commands/apply.js
|
|
375
|
+
|
|
376
|
+
```javascript
|
|
377
|
+
// npm/agent-booster-cli/commands/apply.js
|
|
378
|
+
|
|
379
|
+
const { AgentBooster } = require('agent-booster');
|
|
380
|
+
const { readFileSync, writeFileSync } = require('fs');
|
|
381
|
+
const chalk = require('chalk');
|
|
382
|
+
const ora = require('ora');
|
|
383
|
+
|
|
384
|
+
module.exports = async function apply(file, edit, options) {
|
|
385
|
+
const spinner = ora(`Applying edit to ${file}...`).start();
|
|
386
|
+
|
|
387
|
+
try {
|
|
388
|
+
// Initialize Agent Booster
|
|
389
|
+
const booster = new AgentBooster({
|
|
390
|
+
model: options.model,
|
|
391
|
+
confidenceThreshold: parseFloat(options.threshold),
|
|
392
|
+
fallbackToMorph: options.fallback,
|
|
393
|
+
morphApiKey: process.env.MORPH_API_KEY,
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
// Read file
|
|
397
|
+
const originalCode = readFileSync(file, 'utf-8');
|
|
398
|
+
|
|
399
|
+
// Apply edit
|
|
400
|
+
const startTime = Date.now();
|
|
401
|
+
const result = await booster.applyEdit({
|
|
402
|
+
originalCode,
|
|
403
|
+
editSnippet: edit,
|
|
404
|
+
language: detectLanguage(file),
|
|
405
|
+
});
|
|
406
|
+
const latency = Date.now() - startTime;
|
|
407
|
+
|
|
408
|
+
spinner.succeed('Edit applied successfully!');
|
|
409
|
+
|
|
410
|
+
// Display results
|
|
411
|
+
console.log('');
|
|
412
|
+
console.log(chalk.bold('Results:'));
|
|
413
|
+
console.log(` Strategy: ${chalk.cyan(result.strategy)}`);
|
|
414
|
+
console.log(` Confidence: ${formatConfidence(result.confidence)}`);
|
|
415
|
+
console.log(` Latency: ${chalk.green(latency + 'ms')}`);
|
|
416
|
+
console.log(` Cost: ${chalk.green('$0.00')}`);
|
|
417
|
+
console.log('');
|
|
418
|
+
|
|
419
|
+
if (result.confidence < parseFloat(options.threshold)) {
|
|
420
|
+
console.log(chalk.yellow('⚠️ Warning: Low confidence'));
|
|
421
|
+
console.log(chalk.yellow(` Consider using --fallback for better accuracy`));
|
|
422
|
+
console.log('');
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
// Write or preview
|
|
426
|
+
if (options.dryRun) {
|
|
427
|
+
console.log(chalk.bold('Dry run - no changes written'));
|
|
428
|
+
console.log('');
|
|
429
|
+
console.log(chalk.dim('─'.repeat(80)));
|
|
430
|
+
console.log(result.mergedCode);
|
|
431
|
+
console.log(chalk.dim('─'.repeat(80)));
|
|
432
|
+
} else {
|
|
433
|
+
writeFileSync(file, result.mergedCode, 'utf-8');
|
|
434
|
+
console.log(chalk.green(`✓ Saved to ${file}`));
|
|
435
|
+
}
|
|
436
|
+
} catch (error) {
|
|
437
|
+
spinner.fail('Edit failed');
|
|
438
|
+
console.error(chalk.red('Error:'), error.message);
|
|
439
|
+
process.exit(1);
|
|
440
|
+
}
|
|
441
|
+
};
|
|
442
|
+
|
|
443
|
+
function detectLanguage(filePath) {
|
|
444
|
+
const ext = filePath.split('.').pop();
|
|
445
|
+
const langMap = {
|
|
446
|
+
'js': 'javascript',
|
|
447
|
+
'jsx': 'javascript',
|
|
448
|
+
'ts': 'typescript',
|
|
449
|
+
'tsx': 'typescript',
|
|
450
|
+
'py': 'python',
|
|
451
|
+
'rs': 'rust',
|
|
452
|
+
};
|
|
453
|
+
return langMap[ext] || 'javascript';
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
function formatConfidence(confidence) {
|
|
457
|
+
const percentage = (confidence * 100).toFixed(1) + '%';
|
|
458
|
+
if (confidence >= 0.85) return chalk.green(percentage);
|
|
459
|
+
if (confidence >= 0.65) return chalk.yellow(percentage);
|
|
460
|
+
return chalk.red(percentage);
|
|
461
|
+
}
|
|
462
|
+
```
|
|
463
|
+
|
|
464
|
+
### commands/watch.js
|
|
465
|
+
|
|
466
|
+
```javascript
|
|
467
|
+
// npm/agent-booster-cli/commands/watch.js
|
|
468
|
+
|
|
469
|
+
const { AgentBooster } = require('agent-booster');
|
|
470
|
+
const chokidar = require('chokidar');
|
|
471
|
+
const chalk = require('chalk');
|
|
472
|
+
const path = require('path');
|
|
473
|
+
|
|
474
|
+
module.exports = async function watch(directory, options) {
|
|
475
|
+
console.log(chalk.bold(`\n📁 Watching ${directory} for changes...\n`));
|
|
476
|
+
|
|
477
|
+
const booster = new AgentBooster({
|
|
478
|
+
model: options.model,
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
const ignorePatterns = options.ignore
|
|
482
|
+
? options.ignore.split(',')
|
|
483
|
+
: ['node_modules/**', '.git/**', 'dist/**', 'build/**'];
|
|
484
|
+
|
|
485
|
+
const watcher = chokidar.watch(directory, {
|
|
486
|
+
ignored: ignorePatterns,
|
|
487
|
+
persistent: true,
|
|
488
|
+
ignoreInitial: true,
|
|
489
|
+
});
|
|
490
|
+
|
|
491
|
+
watcher
|
|
492
|
+
.on('change', async (filePath) => {
|
|
493
|
+
console.log(chalk.dim(`${new Date().toLocaleTimeString()} `), 'Changed:', filePath);
|
|
494
|
+
|
|
495
|
+
// Auto-apply formatting or linting fixes
|
|
496
|
+
// This is a placeholder - actual implementation would read
|
|
497
|
+
// from a .agent-booster.json config file
|
|
498
|
+
})
|
|
499
|
+
.on('error', (error) => {
|
|
500
|
+
console.error(chalk.red('Watcher error:'), error);
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
// Keep process alive
|
|
504
|
+
await new Promise(() => {});
|
|
505
|
+
};
|
|
506
|
+
```
|
|
507
|
+
|
|
508
|
+
## 📚 Usage Examples
|
|
509
|
+
|
|
510
|
+
### Example 1: Simple API Usage
|
|
511
|
+
|
|
512
|
+
```typescript
|
|
513
|
+
import { AgentBooster } from 'agent-booster';
|
|
514
|
+
import { readFileSync, writeFileSync } from 'fs';
|
|
515
|
+
|
|
516
|
+
const booster = new AgentBooster({
|
|
517
|
+
model: 'jina-code-v2',
|
|
518
|
+
confidenceThreshold: 0.65,
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
const result = await booster.applyEdit({
|
|
522
|
+
originalCode: readFileSync('src/utils/parser.ts', 'utf-8'),
|
|
523
|
+
editSnippet: 'add error handling to parseConfig function',
|
|
524
|
+
language: 'typescript',
|
|
525
|
+
});
|
|
526
|
+
|
|
527
|
+
if (result.confidence >= 0.65) {
|
|
528
|
+
writeFileSync('src/utils/parser.ts', result.mergedCode, 'utf-8');
|
|
529
|
+
console.log(`✓ Applied edit with ${(result.confidence * 100).toFixed(1)}% confidence`);
|
|
530
|
+
} else {
|
|
531
|
+
console.log(`✗ Confidence too low: ${(result.confidence * 100).toFixed(1)}%`);
|
|
532
|
+
}
|
|
533
|
+
```
|
|
534
|
+
|
|
535
|
+
### Example 2: Batch Processing
|
|
536
|
+
|
|
537
|
+
```typescript
|
|
538
|
+
const edits = [
|
|
539
|
+
{
|
|
540
|
+
originalCode: readFileSync('src/auth.ts', 'utf-8'),
|
|
541
|
+
editSnippet: 'add JWT token validation',
|
|
542
|
+
language: 'typescript',
|
|
543
|
+
},
|
|
544
|
+
{
|
|
545
|
+
originalCode: readFileSync('src/db.ts', 'utf-8'),
|
|
546
|
+
editSnippet: 'add connection pooling',
|
|
547
|
+
language: 'typescript',
|
|
548
|
+
},
|
|
549
|
+
{
|
|
550
|
+
originalCode: readFileSync('src/api.ts', 'utf-8'),
|
|
551
|
+
editSnippet: 'add rate limiting',
|
|
552
|
+
language: 'typescript',
|
|
553
|
+
},
|
|
554
|
+
];
|
|
555
|
+
|
|
556
|
+
const results = await booster.batchApply(edits);
|
|
557
|
+
|
|
558
|
+
console.log(`✓ Applied ${results.filter(r => r.confidence >= 0.65).length} of ${results.length} edits`);
|
|
559
|
+
```
|
|
560
|
+
|
|
561
|
+
### Example 3: CLI Usage
|
|
562
|
+
|
|
563
|
+
```bash
|
|
564
|
+
# Apply single edit
|
|
565
|
+
npx agent-booster apply src/main.ts "add error handling to parseConfig"
|
|
566
|
+
|
|
567
|
+
# Dry run (preview only)
|
|
568
|
+
npx agent-booster apply src/main.ts "add logging" --dry-run
|
|
569
|
+
|
|
570
|
+
# Batch edits from JSON file
|
|
571
|
+
cat > edits.json <<EOF
|
|
572
|
+
[
|
|
573
|
+
{
|
|
574
|
+
"file": "src/auth.ts",
|
|
575
|
+
"edit": "add JWT validation"
|
|
576
|
+
},
|
|
577
|
+
{
|
|
578
|
+
"file": "src/db.ts",
|
|
579
|
+
"edit": "add connection pooling"
|
|
580
|
+
}
|
|
581
|
+
]
|
|
582
|
+
EOF
|
|
583
|
+
|
|
584
|
+
npx agent-booster batch edits.json
|
|
585
|
+
|
|
586
|
+
# Watch mode
|
|
587
|
+
npx agent-booster watch src/ --model jina-code-v2
|
|
588
|
+
|
|
589
|
+
# Start MCP server
|
|
590
|
+
npx agent-booster mcp --port 3000
|
|
591
|
+
|
|
592
|
+
# Download models
|
|
593
|
+
npx agent-booster download-models --model jina-code-v2,all-MiniLM-L6-v2
|
|
594
|
+
```
|
|
595
|
+
|
|
596
|
+
## 🚀 Distribution Strategy
|
|
597
|
+
|
|
598
|
+
### Platform-Specific Packages
|
|
599
|
+
|
|
600
|
+
```json
|
|
601
|
+
// @agent-booster/linux-x64/package.json
|
|
602
|
+
{
|
|
603
|
+
"name": "@agent-booster/linux-x64",
|
|
604
|
+
"version": "0.1.0",
|
|
605
|
+
"os": ["linux"],
|
|
606
|
+
"cpu": ["x64"],
|
|
607
|
+
"main": "agent-booster.linux-x64.node"
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
// Similar for:
|
|
611
|
+
// - @agent-booster/darwin-x64
|
|
612
|
+
// - @agent-booster/darwin-arm64
|
|
613
|
+
// - @agent-booster/win32-x64
|
|
614
|
+
```
|
|
615
|
+
|
|
616
|
+
### Post-Install Script
|
|
617
|
+
|
|
618
|
+
```javascript
|
|
619
|
+
// scripts/download-model.js
|
|
620
|
+
|
|
621
|
+
const https = require('https');
|
|
622
|
+
const fs = require('fs');
|
|
623
|
+
const path = require('path');
|
|
624
|
+
const os = require('os');
|
|
625
|
+
|
|
626
|
+
const MODEL_URLS = {
|
|
627
|
+
'jina-code-v2': 'https://huggingface.co/jinaai/jina-embeddings-v2-base-code/resolve/main/onnx/model.onnx',
|
|
628
|
+
'all-MiniLM-L6-v2': 'https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2/resolve/main/onnx/model.onnx',
|
|
629
|
+
};
|
|
630
|
+
|
|
631
|
+
async function downloadModel(modelName) {
|
|
632
|
+
const cacheDir = path.join(os.homedir(), '.cache', 'agent-booster', 'models');
|
|
633
|
+
const modelPath = path.join(cacheDir, `${modelName}.onnx`);
|
|
634
|
+
|
|
635
|
+
if (fs.existsSync(modelPath)) {
|
|
636
|
+
console.log(`[agent-booster] Model ${modelName} already cached`);
|
|
637
|
+
return;
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
console.log(`[agent-booster] Downloading model ${modelName}...`);
|
|
641
|
+
|
|
642
|
+
// Create cache directory
|
|
643
|
+
fs.mkdirSync(cacheDir, { recursive: true });
|
|
644
|
+
|
|
645
|
+
// Download model
|
|
646
|
+
// (implementation omitted for brevity)
|
|
647
|
+
|
|
648
|
+
console.log(`[agent-booster] Model ${modelName} downloaded successfully`);
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
// Run on install
|
|
652
|
+
const defaultModel = process.env.AGENT_BOOSTER_MODEL || 'jina-code-v2';
|
|
653
|
+
downloadModel(defaultModel).catch(console.error);
|
|
654
|
+
```
|
|
655
|
+
|
|
656
|
+
## 📊 Bundle Size Analysis
|
|
657
|
+
|
|
658
|
+
```
|
|
659
|
+
agent-booster@0.1.0
|
|
660
|
+
├── Native addon (per platform): ~2-3 MB
|
|
661
|
+
├── WASM fallback: ~1.5 MB
|
|
662
|
+
├── JavaScript/TypeScript: ~50 KB
|
|
663
|
+
└── Total installed: ~5-8 MB
|
|
664
|
+
|
|
665
|
+
agent-booster-cli@0.1.0
|
|
666
|
+
├── Dependencies: ~2 MB
|
|
667
|
+
├── CLI code: ~100 KB
|
|
668
|
+
└── Total installed: ~2.1 MB
|
|
669
|
+
|
|
670
|
+
Models (downloaded on-demand):
|
|
671
|
+
├── jina-code-v2: ~150 MB (one-time)
|
|
672
|
+
└── all-MiniLM-L6-v2: ~90 MB (one-time)
|
|
673
|
+
```
|