agentinit 1.5.0 → 1.7.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/CHANGELOG.md +21 -0
- package/README.md +93 -10
- package/dist/agentinit-1.7.0.tgz +0 -0
- package/dist/agents/DroidAgent.d.ts +52 -0
- package/dist/agents/DroidAgent.d.ts.map +1 -0
- package/dist/agents/DroidAgent.js +228 -0
- package/dist/agents/DroidAgent.js.map +1 -0
- package/dist/cli.js +501 -48
- package/dist/commands/apply.d.ts.map +1 -1
- package/dist/commands/apply.js +2 -2
- package/dist/commands/apply.js.map +1 -1
- package/dist/commands/verifyMcp.d.ts.map +1 -1
- package/dist/commands/verifyMcp.js +26 -4
- package/dist/commands/verifyMcp.js.map +1 -1
- package/dist/constants/index.d.ts +1 -1
- package/dist/constants/index.d.ts.map +1 -1
- package/dist/constants/index.js +1 -1
- package/dist/constants/index.js.map +1 -1
- package/dist/constants/mcp.d.ts +1 -0
- package/dist/constants/mcp.d.ts.map +1 -1
- package/dist/constants/mcp.js +2 -0
- package/dist/constants/mcp.js.map +1 -1
- package/dist/core/agentManager.d.ts.map +1 -1
- package/dist/core/agentManager.js +3 -1
- package/dist/core/agentManager.js.map +1 -1
- package/dist/core/mcpClient.d.ts +124 -6
- package/dist/core/mcpClient.d.ts.map +1 -1
- package/dist/core/mcpClient.js +385 -39
- package/dist/core/mcpClient.js.map +1 -1
- package/dist/lib/utils/index.d.ts +3 -1
- package/dist/lib/utils/index.d.ts.map +1 -1
- package/dist/lib/utils/index.js +4 -1
- package/dist/lib/utils/index.js.map +1 -1
- package/dist/types/index.d.ts +10 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/jsonSchema.d.ts +31 -0
- package/dist/types/jsonSchema.d.ts.map +1 -0
- package/dist/types/jsonSchema.js +6 -0
- package/dist/types/jsonSchema.js.map +1 -0
- package/dist/utils/packageVersion.d.ts +105 -0
- package/dist/utils/packageVersion.d.ts.map +1 -0
- package/dist/utils/packageVersion.js +219 -0
- package/dist/utils/packageVersion.js.map +1 -0
- package/package.json +1 -1
- package/dist/agentinit-1.5.0.tgz +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
# [1.7.0](https://github.com/agentinit/agentinit/compare/v1.6.0...v1.7.0) (2025-10-17)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* resolve TypeScript errors in MCP verifier ([469f886](https://github.com/agentinit/agentinit/commit/469f886ad0b6517b2eb1622b84a6b24b39614f3f))
|
|
7
|
+
* **tests:** remove duplicate getServerVersion properties in mock objects ([26106a7](https://github.com/agentinit/agentinit/commit/26106a7ddaad77a6e3ef37802bf01c8e2e580839))
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
* add automatic MCP server version detection ([3980599](https://github.com/agentinit/agentinit/commit/3980599539b8175384f0377765a0373c0315535c))
|
|
13
|
+
* **verifier:** add advanced MCP verification options ([d89d5da](https://github.com/agentinit/agentinit/commit/d89d5da9fe177aee19a92f9e441f2dbeba60a1b1))
|
|
14
|
+
|
|
15
|
+
# [1.6.0](https://github.com/agentinit/agentinit/compare/v1.5.0...v1.6.0) (2025-10-10)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Features
|
|
19
|
+
|
|
20
|
+
* **agents:** add Droid (Factory AI) agent support ([73e5529](https://github.com/agentinit/agentinit/commit/73e5529703af36781c06e840faf38227d2ce79ac))
|
|
21
|
+
|
|
1
22
|
# [1.5.0](https://github.com/agentinit/agentinit/compare/v1.4.1...v1.5.0) (2025-10-01)
|
|
2
23
|
|
|
3
24
|
|
package/README.md
CHANGED
|
@@ -302,6 +302,8 @@ AgentInit includes a curated registry of popular MCPs:
|
|
|
302
302
|
|
|
303
303
|
AgentInit can be used as a library in your Node.js/TypeScript applications for programmatic MCP server verification and management.
|
|
304
304
|
|
|
305
|
+
> **📖 Full Documentation:** See [src/lib/verifier/README.md](src/lib/verifier/README.md) for complete API reference, examples, and advanced usage.
|
|
306
|
+
|
|
305
307
|
### Installation
|
|
306
308
|
|
|
307
309
|
```bash
|
|
@@ -315,7 +317,8 @@ bun add agentinit
|
|
|
315
317
|
### Basic Usage
|
|
316
318
|
|
|
317
319
|
```typescript
|
|
318
|
-
import { MCPVerifier
|
|
320
|
+
import { MCPVerifier } from 'agentinit/verifier';
|
|
321
|
+
import { MCPServerType } from 'agentinit/types';
|
|
319
322
|
|
|
320
323
|
const verifier = new MCPVerifier();
|
|
321
324
|
|
|
@@ -333,6 +336,34 @@ if (result.status === 'success') {
|
|
|
333
336
|
}
|
|
334
337
|
```
|
|
335
338
|
|
|
339
|
+
### Advanced Features
|
|
340
|
+
|
|
341
|
+
The verifier supports additional options for detailed inspection:
|
|
342
|
+
|
|
343
|
+
```typescript
|
|
344
|
+
// Fetch resource contents and prompt templates
|
|
345
|
+
const result = await verifier.verifyServer(
|
|
346
|
+
serverConfig,
|
|
347
|
+
{
|
|
348
|
+
timeout: 15000,
|
|
349
|
+
includeResourceContents: true, // Fetch actual resource data
|
|
350
|
+
includePromptDetails: true, // Fetch prompt templates
|
|
351
|
+
includeTokenCounts: true // Calculate token usage (default)
|
|
352
|
+
}
|
|
353
|
+
);
|
|
354
|
+
|
|
355
|
+
// Access detailed tool parameters
|
|
356
|
+
result.capabilities?.tools.forEach(tool => {
|
|
357
|
+
console.log(`\nTool: ${tool.name}`);
|
|
358
|
+
|
|
359
|
+
if (tool.inputSchema?.properties) {
|
|
360
|
+
Object.entries(tool.inputSchema.properties).forEach(([name, schema]) => {
|
|
361
|
+
console.log(` - ${name}: ${schema.type} ${schema.description || ''}`);
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
```
|
|
366
|
+
|
|
336
367
|
### Submodule Imports
|
|
337
368
|
|
|
338
369
|
For better tree-shaking, import from specific submodules:
|
|
@@ -341,7 +372,11 @@ For better tree-shaking, import from specific submodules:
|
|
|
341
372
|
// Import specific modules
|
|
342
373
|
import { MCPVerifier } from 'agentinit/verifier';
|
|
343
374
|
import { MCPServerType } from 'agentinit/types';
|
|
344
|
-
import type {
|
|
375
|
+
import type {
|
|
376
|
+
MCPServerConfig,
|
|
377
|
+
MCPVerificationResult,
|
|
378
|
+
MCPVerificationOptions
|
|
379
|
+
} from 'agentinit/types';
|
|
345
380
|
import { countTokens, MCPParser } from 'agentinit/utils';
|
|
346
381
|
```
|
|
347
382
|
|
|
@@ -391,7 +426,7 @@ const result = await verifier.verifyServer({
|
|
|
391
426
|
#### Verify Multiple Servers
|
|
392
427
|
|
|
393
428
|
```typescript
|
|
394
|
-
import { MCPVerifier, MCPServerType } from 'agentinit';
|
|
429
|
+
import { MCPVerifier, MCPServerType } from 'agentinit/verifier';
|
|
395
430
|
|
|
396
431
|
const servers = [
|
|
397
432
|
{
|
|
@@ -416,6 +451,17 @@ console.log(verifier.formatResults(results));
|
|
|
416
451
|
// Or process results programmatically
|
|
417
452
|
const successful = results.filter(r => r.status === 'success').length;
|
|
418
453
|
console.log(`${successful}/${results.length} servers verified`);
|
|
454
|
+
|
|
455
|
+
// Inspect tool parameters and token usage
|
|
456
|
+
results.forEach(result => {
|
|
457
|
+
if (result.status === 'success' && result.capabilities) {
|
|
458
|
+
console.log(`\n${result.server.name}:`);
|
|
459
|
+
result.capabilities.tools.forEach(tool => {
|
|
460
|
+
const tokens = result.capabilities?.toolTokenCounts?.get(tool.name) || 0;
|
|
461
|
+
console.log(` • ${tool.name} (${tokens} tokens)`);
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
});
|
|
419
465
|
```
|
|
420
466
|
|
|
421
467
|
#### Count Tokens
|
|
@@ -449,10 +495,20 @@ new MCPVerifier(defaultTimeout?: number)
|
|
|
449
495
|
```
|
|
450
496
|
|
|
451
497
|
**Methods**
|
|
452
|
-
- `verifyServer(config: MCPServerConfig,
|
|
453
|
-
- `verifyServers(configs: MCPServerConfig[],
|
|
498
|
+
- `verifyServer(config: MCPServerConfig, options?: MCPVerificationOptions): Promise<MCPVerificationResult>` - Verify a single MCP server
|
|
499
|
+
- `verifyServers(configs: MCPServerConfig[], options?: MCPVerificationOptions): Promise<MCPVerificationResult[]>` - Verify multiple servers in parallel
|
|
454
500
|
- `formatResults(results: MCPVerificationResult[]): string` - Format verification results for display
|
|
455
501
|
|
|
502
|
+
**MCPVerificationOptions**
|
|
503
|
+
```typescript
|
|
504
|
+
interface MCPVerificationOptions {
|
|
505
|
+
timeout?: number; // Connection timeout (ms)
|
|
506
|
+
includeResourceContents?: boolean; // Fetch resource data
|
|
507
|
+
includePromptDetails?: boolean; // Fetch prompt templates
|
|
508
|
+
includeTokenCounts?: boolean; // Calculate tokens (default: true)
|
|
509
|
+
}
|
|
510
|
+
```
|
|
511
|
+
|
|
456
512
|
#### Types
|
|
457
513
|
|
|
458
514
|
**MCPServerType**
|
|
@@ -495,18 +551,45 @@ interface MCPVerificationResult {
|
|
|
495
551
|
**MCPCapabilities**
|
|
496
552
|
```typescript
|
|
497
553
|
interface MCPCapabilities {
|
|
498
|
-
tools: MCPTool[];
|
|
499
|
-
resources: MCPResource[];
|
|
500
|
-
prompts: MCPPrompt[];
|
|
554
|
+
tools: MCPTool[]; // Available tools with input schemas
|
|
555
|
+
resources: MCPResource[]; // Available resources (with optional contents)
|
|
556
|
+
prompts: MCPPrompt[]; // Available prompts (with optional templates)
|
|
501
557
|
serverInfo?: {
|
|
502
558
|
name: string;
|
|
503
559
|
version: string;
|
|
504
560
|
};
|
|
505
|
-
totalToolTokens?: number;
|
|
506
|
-
toolTokenCounts?: Map<string, number>;
|
|
561
|
+
totalToolTokens?: number; // Total token usage for all tools
|
|
562
|
+
toolTokenCounts?: Map<string, number>; // Token count per tool
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
interface MCPTool {
|
|
566
|
+
name: string;
|
|
567
|
+
description?: string;
|
|
568
|
+
inputSchema?: any; // JSON Schema defining parameters
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
interface MCPResource {
|
|
572
|
+
uri: string;
|
|
573
|
+
name?: string;
|
|
574
|
+
description?: string;
|
|
575
|
+
mimeType?: string;
|
|
576
|
+
contents?: string | Uint8Array; // Only if includeResourceContents is true
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
interface MCPPrompt {
|
|
580
|
+
name: string;
|
|
581
|
+
description?: string;
|
|
582
|
+
arguments?: Array<{
|
|
583
|
+
name: string;
|
|
584
|
+
description?: string;
|
|
585
|
+
required?: boolean;
|
|
586
|
+
}>;
|
|
587
|
+
template?: string; // Only if includePromptDetails is true
|
|
507
588
|
}
|
|
508
589
|
```
|
|
509
590
|
|
|
591
|
+
> **📝 Note:** For detailed examples on working with tool parameters, resource contents, and prompt templates, see the [full library documentation](src/lib/verifier/README.md).
|
|
592
|
+
|
|
510
593
|
## 🛠️ Development
|
|
511
594
|
|
|
512
595
|
### Building from Source
|
|
Binary file
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Agent } from './Agent.js';
|
|
2
|
+
import type { MCPServerConfig } from '../types/index.js';
|
|
3
|
+
import type { AppliedRules, RuleSection } from '../types/rules.js';
|
|
4
|
+
/**
|
|
5
|
+
* Droid (Factory) agent implementation
|
|
6
|
+
* Supports stdio MCP servers
|
|
7
|
+
* Uses ~/.factory for global configuration
|
|
8
|
+
* MCP config: ~/.factory/mcp.json
|
|
9
|
+
* Rules: AGENTS.md in project root
|
|
10
|
+
*/
|
|
11
|
+
export declare class DroidAgent extends Agent {
|
|
12
|
+
constructor();
|
|
13
|
+
/**
|
|
14
|
+
* Apply MCP configuration to Droid's ~/.factory/mcp.json format
|
|
15
|
+
* Droid stores configs globally regardless of project-level or global flag
|
|
16
|
+
*/
|
|
17
|
+
applyMCPConfig(projectPath: string, servers: MCPServerConfig[]): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Apply MCP configuration to Droid's global ~/.factory/mcp.json format
|
|
20
|
+
*/
|
|
21
|
+
applyGlobalMCPConfig(servers: MCPServerConfig[]): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Filter out non-stdio servers since Droid only supports stdio
|
|
24
|
+
*/
|
|
25
|
+
filterMCPServers(servers: MCPServerConfig[]): MCPServerConfig[];
|
|
26
|
+
/**
|
|
27
|
+
* Droid doesn't need any transformations for stdio servers
|
|
28
|
+
*/
|
|
29
|
+
transformMCPServers(servers: MCPServerConfig[]): MCPServerConfig[];
|
|
30
|
+
/**
|
|
31
|
+
* Apply rules configuration to AGENTS.md
|
|
32
|
+
*/
|
|
33
|
+
applyRulesConfig(configPath: string, rules: AppliedRules, existingContent: string): Promise<string>;
|
|
34
|
+
/**
|
|
35
|
+
* Extract existing rule texts from AGENTS.md content
|
|
36
|
+
*/
|
|
37
|
+
extractExistingRules(content: string): string[];
|
|
38
|
+
/**
|
|
39
|
+
* Extract existing rule sections from AGENTS.md content using ## headers
|
|
40
|
+
*/
|
|
41
|
+
extractExistingSections(content: string): RuleSection[];
|
|
42
|
+
/**
|
|
43
|
+
* Generate rules content in AGENTS.md markdown format
|
|
44
|
+
*/
|
|
45
|
+
generateRulesContent(sections: RuleSection[]): string;
|
|
46
|
+
/**
|
|
47
|
+
* Get existing MCP servers from Droid's ~/.factory/mcp.json configuration
|
|
48
|
+
* Droid uses global configuration, so we read from the global path
|
|
49
|
+
*/
|
|
50
|
+
getMCPServers(projectPath: string): Promise<MCPServerConfig[]>;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=DroidAgent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DroidAgent.d.ts","sourceRoot":"","sources":["../../src/agents/DroidAgent.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,OAAO,KAAK,EAAE,eAAe,EAAkC,MAAM,mBAAmB,CAAC;AACzF,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEnE;;;;;;GAMG;AACH,qBAAa,UAAW,SAAQ,KAAK;;IAmCnC;;;OAGG;IACG,cAAc,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAKpF;;OAEG;IACG,oBAAoB,CAAC,OAAO,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAsDrE;;OAEG;IACH,gBAAgB,CAAC,OAAO,EAAE,eAAe,EAAE,GAAG,eAAe,EAAE;IAI/D;;OAEG;IACH,mBAAmB,CAAC,OAAO,EAAE,eAAe,EAAE,GAAG,eAAe,EAAE;IAIlE;;OAEG;IACG,gBAAgB,CACpB,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,YAAY,EACnB,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,MAAM,CAAC;IAiBlB;;OAEG;IACH,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE;IAM/C;;OAEG;IACH,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW,EAAE;IAmCvD;;OAEG;IACH,oBAAoB,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,MAAM;IAiBrD;;;OAGG;IACG,aAAa,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;CA4CrE"}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { Agent } from './Agent.js';
|
|
2
|
+
import { readFileIfExists, writeFile, ensureDirectoryExists } from '../utils/fs.js';
|
|
3
|
+
/**
|
|
4
|
+
* Droid (Factory) agent implementation
|
|
5
|
+
* Supports stdio MCP servers
|
|
6
|
+
* Uses ~/.factory for global configuration
|
|
7
|
+
* MCP config: ~/.factory/mcp.json
|
|
8
|
+
* Rules: AGENTS.md in project root
|
|
9
|
+
*/
|
|
10
|
+
export class DroidAgent extends Agent {
|
|
11
|
+
constructor() {
|
|
12
|
+
const definition = {
|
|
13
|
+
id: 'droid',
|
|
14
|
+
name: 'Droid (Factory)',
|
|
15
|
+
url: 'https://factory.ai',
|
|
16
|
+
capabilities: {
|
|
17
|
+
mcp: {
|
|
18
|
+
stdio: true,
|
|
19
|
+
http: false,
|
|
20
|
+
sse: false
|
|
21
|
+
},
|
|
22
|
+
rules: true,
|
|
23
|
+
hooks: false,
|
|
24
|
+
commands: false,
|
|
25
|
+
subagents: false,
|
|
26
|
+
statusline: false
|
|
27
|
+
},
|
|
28
|
+
configFiles: [
|
|
29
|
+
{
|
|
30
|
+
path: 'AGENTS.md',
|
|
31
|
+
purpose: 'rules',
|
|
32
|
+
format: 'markdown',
|
|
33
|
+
type: 'file',
|
|
34
|
+
optional: true,
|
|
35
|
+
description: 'Agent instructions and rules in markdown format'
|
|
36
|
+
}
|
|
37
|
+
],
|
|
38
|
+
nativeConfigPath: '.factory/mcp.json',
|
|
39
|
+
globalConfigPath: '~/.factory/mcp.json'
|
|
40
|
+
};
|
|
41
|
+
super(definition);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Apply MCP configuration to Droid's ~/.factory/mcp.json format
|
|
45
|
+
* Droid stores configs globally regardless of project-level or global flag
|
|
46
|
+
*/
|
|
47
|
+
async applyMCPConfig(projectPath, servers) {
|
|
48
|
+
// Delegate to global config application since Droid uses global config
|
|
49
|
+
await this.applyGlobalMCPConfig(servers);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Apply MCP configuration to Droid's global ~/.factory/mcp.json format
|
|
53
|
+
*/
|
|
54
|
+
async applyGlobalMCPConfig(servers) {
|
|
55
|
+
const globalPath = this.getGlobalMcpPath();
|
|
56
|
+
if (!globalPath) {
|
|
57
|
+
throw new Error(`Droid global configuration path could not be determined`);
|
|
58
|
+
}
|
|
59
|
+
// Ensure the directory exists
|
|
60
|
+
await ensureDirectoryExists(globalPath);
|
|
61
|
+
// Read existing configuration
|
|
62
|
+
const existingContent = await readFileIfExists(globalPath);
|
|
63
|
+
let existingConfig = { mcpServers: {} };
|
|
64
|
+
if (existingContent) {
|
|
65
|
+
try {
|
|
66
|
+
existingConfig = JSON.parse(existingContent);
|
|
67
|
+
if (!existingConfig.mcpServers) {
|
|
68
|
+
existingConfig.mcpServers = {};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
console.warn('Warning: Existing ~/.factory/mcp.json is invalid, creating new configuration');
|
|
73
|
+
existingConfig = { mcpServers: {} };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
// Convert our MCP server configs to Droid's format
|
|
77
|
+
for (const server of servers) {
|
|
78
|
+
const droidServer = {
|
|
79
|
+
type: 'stdio'
|
|
80
|
+
};
|
|
81
|
+
if (server.command) {
|
|
82
|
+
droidServer.command = server.command;
|
|
83
|
+
}
|
|
84
|
+
if (server.args && server.args.length > 0) {
|
|
85
|
+
droidServer.args = server.args;
|
|
86
|
+
}
|
|
87
|
+
if (server.env && Object.keys(server.env).length > 0) {
|
|
88
|
+
droidServer.env = server.env;
|
|
89
|
+
}
|
|
90
|
+
// Add disabled flag (default false)
|
|
91
|
+
droidServer.disabled = false;
|
|
92
|
+
// Add or update the server in the config
|
|
93
|
+
existingConfig.mcpServers[server.name] = droidServer;
|
|
94
|
+
}
|
|
95
|
+
// Write the updated configuration
|
|
96
|
+
const configJson = JSON.stringify(existingConfig, null, 2);
|
|
97
|
+
await writeFile(globalPath, configJson);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Filter out non-stdio servers since Droid only supports stdio
|
|
101
|
+
*/
|
|
102
|
+
filterMCPServers(servers) {
|
|
103
|
+
return servers.filter(server => server.type === 'stdio');
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Droid doesn't need any transformations for stdio servers
|
|
107
|
+
*/
|
|
108
|
+
transformMCPServers(servers) {
|
|
109
|
+
return servers;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Apply rules configuration to AGENTS.md
|
|
113
|
+
*/
|
|
114
|
+
async applyRulesConfig(configPath, rules, existingContent) {
|
|
115
|
+
const rulesSection = this.generateRulesContent(rules.sections);
|
|
116
|
+
let content = existingContent;
|
|
117
|
+
// For markdown, we'll append rules directly
|
|
118
|
+
if (content && !content.endsWith('\n')) {
|
|
119
|
+
content += '\n';
|
|
120
|
+
}
|
|
121
|
+
if (content) {
|
|
122
|
+
content += '\n';
|
|
123
|
+
}
|
|
124
|
+
content += rulesSection;
|
|
125
|
+
return content.trim() + '\n';
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Extract existing rule texts from AGENTS.md content
|
|
129
|
+
*/
|
|
130
|
+
extractExistingRules(content) {
|
|
131
|
+
// Extract rules from markdown format - look for lines starting with "- "
|
|
132
|
+
const ruleLines = content.split('\n').filter(line => line.trim().startsWith('- '));
|
|
133
|
+
return ruleLines.map(line => line.replace(/^- /, '').trim()).filter(rule => rule.length > 0);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Extract existing rule sections from AGENTS.md content using ## headers
|
|
137
|
+
*/
|
|
138
|
+
extractExistingSections(content) {
|
|
139
|
+
const lines = content.split('\n');
|
|
140
|
+
const sections = [];
|
|
141
|
+
let currentSection = null;
|
|
142
|
+
for (const line of lines) {
|
|
143
|
+
const trimmed = line.trim();
|
|
144
|
+
// Check if it's a section header
|
|
145
|
+
if (trimmed.startsWith('## ') && trimmed.includes(' ')) {
|
|
146
|
+
// Start new section
|
|
147
|
+
if (currentSection) {
|
|
148
|
+
sections.push(currentSection);
|
|
149
|
+
}
|
|
150
|
+
const sectionName = trimmed.replace(/^##\s*/, '');
|
|
151
|
+
currentSection = {
|
|
152
|
+
templateId: sectionName.toLowerCase().replace(/\s+/g, '_'),
|
|
153
|
+
templateName: sectionName,
|
|
154
|
+
rules: []
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
else if (currentSection && trimmed.startsWith('- ')) {
|
|
158
|
+
// Add rule to current section
|
|
159
|
+
const rule = trimmed.replace(/^- /, '');
|
|
160
|
+
currentSection.rules.push(rule);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
// Add the last section
|
|
164
|
+
if (currentSection) {
|
|
165
|
+
sections.push(currentSection);
|
|
166
|
+
}
|
|
167
|
+
return sections;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Generate rules content in AGENTS.md markdown format
|
|
171
|
+
*/
|
|
172
|
+
generateRulesContent(sections) {
|
|
173
|
+
let content = '';
|
|
174
|
+
if (sections && sections.length > 0) {
|
|
175
|
+
// Group rules by sections
|
|
176
|
+
for (const ruleSection of sections) {
|
|
177
|
+
content += `## ${ruleSection.templateName}\n\n`;
|
|
178
|
+
for (const rule of ruleSection.rules) {
|
|
179
|
+
content += `- ${rule}\n`;
|
|
180
|
+
}
|
|
181
|
+
content += '\n';
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return content;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Get existing MCP servers from Droid's ~/.factory/mcp.json configuration
|
|
188
|
+
* Droid uses global configuration, so we read from the global path
|
|
189
|
+
*/
|
|
190
|
+
async getMCPServers(projectPath) {
|
|
191
|
+
const globalPath = this.getGlobalMcpPath();
|
|
192
|
+
if (!globalPath) {
|
|
193
|
+
return [];
|
|
194
|
+
}
|
|
195
|
+
const configContent = await readFileIfExists(globalPath);
|
|
196
|
+
if (!configContent) {
|
|
197
|
+
return [];
|
|
198
|
+
}
|
|
199
|
+
try {
|
|
200
|
+
const config = JSON.parse(configContent);
|
|
201
|
+
const servers = [];
|
|
202
|
+
if (config.mcpServers) {
|
|
203
|
+
for (const [name, serverConfig] of Object.entries(config.mcpServers)) {
|
|
204
|
+
const server = {
|
|
205
|
+
name,
|
|
206
|
+
type: 'stdio',
|
|
207
|
+
};
|
|
208
|
+
if (serverConfig.command) {
|
|
209
|
+
server.command = serverConfig.command;
|
|
210
|
+
}
|
|
211
|
+
if (serverConfig.args) {
|
|
212
|
+
server.args = serverConfig.args;
|
|
213
|
+
}
|
|
214
|
+
if (serverConfig.env) {
|
|
215
|
+
server.env = serverConfig.env;
|
|
216
|
+
}
|
|
217
|
+
servers.push(server);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return servers;
|
|
221
|
+
}
|
|
222
|
+
catch (error) {
|
|
223
|
+
// Invalid JSON or missing mcpServers property
|
|
224
|
+
return [];
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
//# sourceMappingURL=DroidAgent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DroidAgent.js","sourceRoot":"","sources":["../../src/agents/DroidAgent.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAIpF;;;;;;GAMG;AACH,MAAM,OAAO,UAAW,SAAQ,KAAK;IACnC;QACE,MAAM,UAAU,GAAoB;YAClC,EAAE,EAAE,OAAO;YACX,IAAI,EAAE,iBAAiB;YACvB,GAAG,EAAE,oBAAoB;YACzB,YAAY,EAAE;gBACZ,GAAG,EAAE;oBACH,KAAK,EAAE,IAAI;oBACX,IAAI,EAAE,KAAK;oBACX,GAAG,EAAE,KAAK;iBACX;gBACD,KAAK,EAAE,IAAI;gBACX,KAAK,EAAE,KAAK;gBACZ,QAAQ,EAAE,KAAK;gBACf,SAAS,EAAE,KAAK;gBAChB,UAAU,EAAE,KAAK;aAClB;YACD,WAAW,EAAE;gBACX;oBACE,IAAI,EAAE,WAAW;oBACjB,OAAO,EAAE,OAAO;oBAChB,MAAM,EAAE,UAAU;oBAClB,IAAI,EAAE,MAAM;oBACZ,QAAQ,EAAE,IAAI;oBACd,WAAW,EAAE,iDAAiD;iBAC/D;aACF;YACD,gBAAgB,EAAE,mBAAmB;YACrC,gBAAgB,EAAE,qBAAqB;SACxC,CAAC;QA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