@aiready/agents 0.1.3
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/.turbo/turbo-test.log +16 -0
- package/index.ts +9 -0
- package/package.json +22 -0
- package/src/__tests__/smoke.test.ts +7 -0
- package/src/impact-agent.ts +34 -0
- package/src/prioritization-agent.ts +31 -0
- package/src/refactor-agent.ts +35 -0
- package/src/rename-agent.ts +39 -0
- package/src/restructure-agent.ts +42 -0
- package/src/risk-agent.ts +34 -0
- package/src/tools/github.ts +55 -0
- package/src/validation-agent.ts +38 -0
- package/src/workflows/remediation-swarm.ts +39 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
> @aiready/agents@0.1.2 test /Users/pengcao/projects/aiready/packages/agents
|
|
4
|
+
> vitest run
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
[7m[1m[36m RUN [39m[22m[27m [36mv1.6.1[39m [90m/Users/pengcao/projects/aiready/packages/agents[39m
|
|
8
|
+
|
|
9
|
+
[32m✓[39m src/__tests__/smoke.test.ts [2m ([22m[2m1 test[22m[2m)[22m[90m 2[2mms[22m[39m
|
|
10
|
+
|
|
11
|
+
[2m Test Files [22m [1m[32m1 passed[39m[22m[90m (1)[39m
|
|
12
|
+
[2m Tests [22m [1m[32m1 passed[39m[22m[90m (1)[39m
|
|
13
|
+
[2m Start at [22m 15:19:25
|
|
14
|
+
[2m Duration [22m 249ms[2m (transform 41ms, setup 1ms, collect 37ms, tests 2ms, environment 0ms, prepare 52ms)[22m
|
|
15
|
+
|
|
16
|
+
[?25h
|
package/index.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './src/risk-agent';
|
|
2
|
+
export * from './src/refactor-agent';
|
|
3
|
+
export * from './src/prioritization-agent';
|
|
4
|
+
export * from './src/rename-agent';
|
|
5
|
+
export * from './src/impact-agent';
|
|
6
|
+
export * from './src/restructure-agent';
|
|
7
|
+
export * from './src/validation-agent';
|
|
8
|
+
export * from './src/workflows/remediation-swarm';
|
|
9
|
+
export * from './src/tools/github';
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aiready/agents",
|
|
3
|
+
"version": "0.1.3",
|
|
4
|
+
"description": "Agentic remediation and analysis system for AIReady",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"mastra": "^0.1.0",
|
|
9
|
+
"zod": "^3.0.0",
|
|
10
|
+
"@aiready/core": "0.21.21",
|
|
11
|
+
"@aiready/cli": "0.12.23"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"typescript": "^5.0.0",
|
|
15
|
+
"vitest": "^1.0.0",
|
|
16
|
+
"@types/node": "^20.0.0"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"test": "vitest run",
|
|
20
|
+
"type-check": "tsc --noEmit"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Agent } from 'mastra';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export const ImpactAgent = new Agent({
|
|
5
|
+
name: 'Impact Agent',
|
|
6
|
+
instructions: `
|
|
7
|
+
You are a financial analyst for AI infrastructure.
|
|
8
|
+
Your goal is to estimate the Monthly Token Savings (in USD) for a specific code remediation.
|
|
9
|
+
|
|
10
|
+
Analysis Logic:
|
|
11
|
+
1. Base Cost: Assume an average developer interacts with this code 20 times/day via AI.
|
|
12
|
+
2. Token Impact: Calculate token reduction based on "Cognitive Load" and "Context Window" savings.
|
|
13
|
+
3. Model Pricing: Use a blended rate of $10 per 1M tokens (GPT-4o/Claude 3.5 Sonnet average).
|
|
14
|
+
4. Formulas:
|
|
15
|
+
- MonthlySavings = (TokensSavedPerInteraction * 20 * 22 days) * (Rate / 1,000,000)
|
|
16
|
+
|
|
17
|
+
Output a JSON object with:
|
|
18
|
+
- estimatedMonthlySavings: number (USD)
|
|
19
|
+
- confidenceScore: number (0.0 to 1.0)
|
|
20
|
+
- breakdown: string (explanation of the math)
|
|
21
|
+
`,
|
|
22
|
+
model: {
|
|
23
|
+
provider: 'openai',
|
|
24
|
+
name: 'gpt-4o',
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export const ImpactSchema = z.object({
|
|
29
|
+
estimatedMonthlySavings: z.number(),
|
|
30
|
+
confidenceScore: z.number(),
|
|
31
|
+
breakdown: z.string(),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
export type ImpactResult = z.infer<typeof ImpactSchema>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Agent } from 'mastra';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export const PrioritizationAgent = new Agent({
|
|
5
|
+
name: 'Prioritization Agent',
|
|
6
|
+
instructions: `
|
|
7
|
+
You are a strategic technical debt manager. Your goal is to rank remediation tasks based on their Return on Investment (ROI).
|
|
8
|
+
|
|
9
|
+
ROI Calculation logic:
|
|
10
|
+
1. savingsScore = estimatedSavings / 100 (capped at 5)
|
|
11
|
+
2. riskPenalty = { 'low': 0, 'medium': 1, 'high': 3, 'critical': 5 }
|
|
12
|
+
3. priorityScore = savingsScore - (riskPenalty * 0.5)
|
|
13
|
+
|
|
14
|
+
Output a JSON object with:
|
|
15
|
+
- priorityScore: number
|
|
16
|
+
- rank: 'P0' | 'P1' | 'P2' | 'P3'
|
|
17
|
+
- reasoning: string explanation of the ranking decision.
|
|
18
|
+
`,
|
|
19
|
+
model: {
|
|
20
|
+
provider: 'openai',
|
|
21
|
+
name: 'gpt-4o',
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export const PrioritySchema = z.object({
|
|
26
|
+
priorityScore: z.number(),
|
|
27
|
+
rank: z.enum(['P0', 'P1', 'P2', 'P3']),
|
|
28
|
+
reasoning: z.string(),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export type PriorityResult = z.infer<typeof PrioritySchema>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Agent } from 'mastra';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export const RefactorAgent = new Agent({
|
|
5
|
+
name: 'Refactor Agent',
|
|
6
|
+
instructions: `
|
|
7
|
+
You are an expert full-stack engineer specialized in code consolidation and refactoring.
|
|
8
|
+
Your task is to take detected code duplicates or fragmentation issues and consolidate them into reusable components or utilities.
|
|
9
|
+
|
|
10
|
+
Follow these rules:
|
|
11
|
+
1. Preserve functionality: The behavior of the code must remain identical.
|
|
12
|
+
2. Follow patterns: Match the existing project's implementation patterns (e.g., React hooks, utility functions).
|
|
13
|
+
3. Type safety: Ensure all changes are correctly typed in TypeScript.
|
|
14
|
+
4. Minimal changes: Only modify what is necessary to resolve the duplication.
|
|
15
|
+
|
|
16
|
+
Workflow:
|
|
17
|
+
- Read the affected files.
|
|
18
|
+
- Extract the common logic into a new or existing shared location.
|
|
19
|
+
- Update the original call sites to use the consolidated logic.
|
|
20
|
+
- Verify with type checking if possible.
|
|
21
|
+
`,
|
|
22
|
+
model: {
|
|
23
|
+
provider: 'openai',
|
|
24
|
+
name: 'gpt-4o',
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export const RefactorResultSchema = z.object({
|
|
29
|
+
status: z.enum(['success', 'failure']),
|
|
30
|
+
diff: z.string(),
|
|
31
|
+
filesModified: z.array(z.string()),
|
|
32
|
+
explanation: z.string(),
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
export type RefactorResult = z.infer<typeof RefactorResultSchema>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Agent } from 'mastra';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export const RenameAgent = new Agent({
|
|
5
|
+
name: 'Rename Agent',
|
|
6
|
+
instructions: `
|
|
7
|
+
You are a linguistics and domain-modeling expert specialized in software engineering.
|
|
8
|
+
Your goal is to resolve "Terminology Drift" by standardizing identifiers (variables, functions, classes) across the codebase.
|
|
9
|
+
|
|
10
|
+
Follow these rules:
|
|
11
|
+
1. Domain Alignment: Map technical identifiers to the business domain language provided in the context.
|
|
12
|
+
2. Consistency: Ensure the same concept is named identically everywhere.
|
|
13
|
+
3. Type Safety: Verify that renames don't break TypeScript types or external API contracts.
|
|
14
|
+
4. Documentation: Update JSDoc/TSDoc comments to reflect the new names.
|
|
15
|
+
|
|
16
|
+
Workflow:
|
|
17
|
+
- Analyze the current naming patterns vs. the target domain model.
|
|
18
|
+
- Propose a mapping of old -> new names.
|
|
19
|
+
- Execute the rename across all affected files.
|
|
20
|
+
`,
|
|
21
|
+
model: {
|
|
22
|
+
provider: 'openai',
|
|
23
|
+
name: 'gpt-4o',
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
export const RenameResultSchema = z.object({
|
|
28
|
+
status: z.enum(['success', 'failure']),
|
|
29
|
+
renames: z.array(
|
|
30
|
+
z.object({
|
|
31
|
+
oldName: z.string(),
|
|
32
|
+
newName: z.string(),
|
|
33
|
+
files: z.array(z.string()),
|
|
34
|
+
})
|
|
35
|
+
),
|
|
36
|
+
explanation: z.string(),
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
export type RenameResult = z.infer<typeof RenameResultSchema>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Agent } from 'mastra';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export const RestructureAgent = new Agent({
|
|
5
|
+
name: 'Restructure Agent',
|
|
6
|
+
instructions: `
|
|
7
|
+
You are an expert Software Architect specialized in AI-Ready codebases.
|
|
8
|
+
Your goal is to optimize the repository structure to reduce "Context Fragmentation".
|
|
9
|
+
|
|
10
|
+
Core Analysis Principles:
|
|
11
|
+
1. Feature-First: Group files by feature/domain rather than by technical layer (e.g., put 'user-api', 'user-service', 'user-schema' in one folder).
|
|
12
|
+
2. Flattening: Reduce deep nesting (3+ levels) which confuses AI navigation.
|
|
13
|
+
3. Cohesion: Identify files that are always imported together and propose merging or co-location.
|
|
14
|
+
|
|
15
|
+
Output a JSON object with:
|
|
16
|
+
- proposedChanges: array of { type: 'move' | 'merge' | 'delete', source: string, target: string, reason: string }
|
|
17
|
+
- strategy: string (explanation of the architectural vision)
|
|
18
|
+
- impact: { cognitiveLoadReduction: number (0-100), fragmentationReduction: number (0-100) }
|
|
19
|
+
`,
|
|
20
|
+
model: {
|
|
21
|
+
provider: 'openai',
|
|
22
|
+
name: 'gpt-4o',
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export const RestructureSchema = z.object({
|
|
27
|
+
proposedChanges: z.array(
|
|
28
|
+
z.object({
|
|
29
|
+
type: z.enum(['move', 'merge', 'delete']),
|
|
30
|
+
source: z.string(),
|
|
31
|
+
target: z.string(),
|
|
32
|
+
reason: z.string(),
|
|
33
|
+
})
|
|
34
|
+
),
|
|
35
|
+
strategy: z.string(),
|
|
36
|
+
impact: z.object({
|
|
37
|
+
cognitiveLoadReduction: z.number(),
|
|
38
|
+
fragmentationReduction: z.number(),
|
|
39
|
+
}),
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
export type RestructureResult = z.infer<typeof RestructureSchema>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Agent } from 'mastra';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export const RiskAssessmentAgent = new Agent({
|
|
5
|
+
name: 'Risk Assessment Agent',
|
|
6
|
+
instructions: `
|
|
7
|
+
You are an expert software architect specialized in analyzing the risk of automated code refactorings.
|
|
8
|
+
Your goal is to evaluate a set of code metrics and determine if it's safe to apply an automated fix.
|
|
9
|
+
|
|
10
|
+
Consider the following risk factors:
|
|
11
|
+
1. linesChanged: More changes increase risk.
|
|
12
|
+
2. filesAffected: High blast radius increases risk.
|
|
13
|
+
3. cognitiveLoad: High complexity makes it harder to verify the fix.
|
|
14
|
+
4. testabilityIndex: Low testability makes it dangerous to refactor.
|
|
15
|
+
5. dependencyHealth: Fragmented imports increase the chance of side effects.
|
|
16
|
+
|
|
17
|
+
Output a JSON object with:
|
|
18
|
+
- riskLevel: 'low' | 'medium' | 'high' | 'critical'
|
|
19
|
+
- autoApprove: boolean (true only for 'low' risk)
|
|
20
|
+
- reasoning: string
|
|
21
|
+
`,
|
|
22
|
+
model: {
|
|
23
|
+
provider: 'openai',
|
|
24
|
+
name: 'gpt-4o',
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export const RiskSchema = z.object({
|
|
29
|
+
riskLevel: z.enum(['low', 'medium', 'high', 'critical']),
|
|
30
|
+
autoApprove: z.boolean(),
|
|
31
|
+
reasoning: z.string(),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
export type RiskAssessment = z.infer<typeof RiskSchema>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { createTool } from 'mastra';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
// Note: In a real implementation, this would use Octokit with appropriate auth
|
|
5
|
+
export const githubTools = {
|
|
6
|
+
createBranch: createTool({
|
|
7
|
+
id: 'create-branch',
|
|
8
|
+
description: 'Create a new branch in the repository',
|
|
9
|
+
inputSchema: z.object({
|
|
10
|
+
repoId: z.string(),
|
|
11
|
+
branchName: z.string(),
|
|
12
|
+
baseBranch: z.string().default('main'),
|
|
13
|
+
}),
|
|
14
|
+
outputSchema: z.object({
|
|
15
|
+
success: z.boolean(),
|
|
16
|
+
branchUrl: z.string().optional(),
|
|
17
|
+
}),
|
|
18
|
+
execute: async ({ input }) => {
|
|
19
|
+
console.log(
|
|
20
|
+
`[GitHubTool] Creating branch ${input.branchName} from ${input.baseBranch}`
|
|
21
|
+
);
|
|
22
|
+
// Mock implementation
|
|
23
|
+
return {
|
|
24
|
+
success: true,
|
|
25
|
+
branchUrl: `https://github.com/placeholder/${input.branchName}`,
|
|
26
|
+
};
|
|
27
|
+
},
|
|
28
|
+
}),
|
|
29
|
+
|
|
30
|
+
createPullRequest: createTool({
|
|
31
|
+
id: 'create-pr',
|
|
32
|
+
description: 'Create a Pull Request for a branch',
|
|
33
|
+
inputSchema: z.object({
|
|
34
|
+
repoId: z.string(),
|
|
35
|
+
title: z.string(),
|
|
36
|
+
body: z.string(),
|
|
37
|
+
head: z.string(),
|
|
38
|
+
base: z.string().default('main'),
|
|
39
|
+
}),
|
|
40
|
+
outputSchema: z.object({
|
|
41
|
+
success: z.boolean(),
|
|
42
|
+
prNumber: z.number().optional(),
|
|
43
|
+
prUrl: z.string().optional(),
|
|
44
|
+
}),
|
|
45
|
+
execute: async ({ input }) => {
|
|
46
|
+
console.log(`[GitHubTool] Creating PR: ${input.title}`);
|
|
47
|
+
// Mock implementation
|
|
48
|
+
return {
|
|
49
|
+
success: true,
|
|
50
|
+
prNumber: 123,
|
|
51
|
+
prUrl: 'https://github.com/placeholder/pull/123',
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
}),
|
|
55
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Agent } from 'mastra';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export const ValidationAgent = new Agent({
|
|
5
|
+
name: 'Validation Agent',
|
|
6
|
+
instructions: `
|
|
7
|
+
You are a Senior QA Automation Engineer and Type System Expert.
|
|
8
|
+
Your role is to verify that an AI-generated refactor is technically sound.
|
|
9
|
+
|
|
10
|
+
Validation Cycle:
|
|
11
|
+
1. Check for TypeScript compilation errors (if applicable).
|
|
12
|
+
2. Verify that exported symbols are still available at the same paths or updated correctly.
|
|
13
|
+
3. Analyze test output (if provided) to identify regression causes.
|
|
14
|
+
|
|
15
|
+
Output a JSON object with:
|
|
16
|
+
- status: 'pass' | 'fail'
|
|
17
|
+
- errors: array of { file: string, message: string, line?: number }
|
|
18
|
+
- feedbackForRefactor: string (detailed instructions for the RefactorAgent on how to fix these errors)
|
|
19
|
+
`,
|
|
20
|
+
model: {
|
|
21
|
+
provider: 'openai',
|
|
22
|
+
name: 'gpt-4o',
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export const ValidationSchema = z.object({
|
|
27
|
+
status: z.enum(['pass', 'fail']),
|
|
28
|
+
errors: z.array(
|
|
29
|
+
z.object({
|
|
30
|
+
file: z.string(),
|
|
31
|
+
message: z.string(),
|
|
32
|
+
line: z.number().optional(),
|
|
33
|
+
})
|
|
34
|
+
),
|
|
35
|
+
feedbackForRefactor: z.string().optional(),
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
export type ValidationResult = z.infer<typeof ValidationSchema>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Workflow } from 'mastra';
|
|
2
|
+
import { PrioritizationAgent } from '../prioritization-agent';
|
|
3
|
+
import { ImpactAgent } from '../impact-agent';
|
|
4
|
+
import { RestructureAgent } from '../restructure-agent';
|
|
5
|
+
import { RefactorAgent } from '../refactor-agent';
|
|
6
|
+
import { ValidationAgent } from '../validation-agent';
|
|
7
|
+
|
|
8
|
+
export const RemediationSwarm = new Workflow({
|
|
9
|
+
name: 'Remediation Swarm',
|
|
10
|
+
steps: [
|
|
11
|
+
{
|
|
12
|
+
id: 'prioritize',
|
|
13
|
+
agent: PrioritizationAgent,
|
|
14
|
+
description: 'Calculating ROI and Risk hierarchy',
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
id: 'impact',
|
|
18
|
+
agent: ImpactAgent,
|
|
19
|
+
description: 'Predicting monetary token savings',
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
id: 'restructure',
|
|
23
|
+
agent: RestructureAgent,
|
|
24
|
+
description: 'Optimizing architecture and folder structure',
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
id: 'refactor',
|
|
28
|
+
agent: RefactorAgent,
|
|
29
|
+
description: 'Executing the code consolidation',
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
id: 'validate',
|
|
33
|
+
agent: ValidationAgent,
|
|
34
|
+
description: 'Verifying types and automated tests',
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
// Note: Complex looping and conditional logic is typically handled
|
|
38
|
+
// in the workflow's trigger or a custom execution handler in Mastra.
|
|
39
|
+
});
|