agentvcs 1.0.0__py3-none-any.whl

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.
agentvcs/__init__.py ADDED
@@ -0,0 +1,4 @@
1
+ """AgentVCS - The world's first agentic version control system."""
2
+
3
+ __version__ = "1.0.0"
4
+ __author__ = "live-by-unix"
@@ -0,0 +1,6 @@
1
+ """Agent framework for AgentVCS."""
2
+
3
+ from agentvcs.agents.base import BaseAgent, SecurityAgent, PerformanceAgent, ArchitectureAgent, RefactorAgent
4
+ from agentvcs.agents.registry import AgentRegistry
5
+
6
+ __all__ = ["BaseAgent", "SecurityAgent", "PerformanceAgent", "ArchitectureAgent", "RefactorAgent", "AgentRegistry"]
@@ -0,0 +1,254 @@
1
+ """Base agent class for AgentVCS."""
2
+
3
+ from abc import ABC, abstractmethod
4
+ from typing import Dict, Any, List
5
+ from agentvcs.models import AgentRole, Commit, Proposal
6
+
7
+
8
+ class BaseAgent(ABC):
9
+ """Base class for all AgentVCS agents."""
10
+
11
+ def __init__(self, role: AgentRole, name: str):
12
+ self.role = role
13
+ self.name = name
14
+
15
+ @abstractmethod
16
+ def review_commit(self, commit: Dict[str, Any]) -> Dict[str, Any]:
17
+ """Review a commit and return assessment."""
18
+ pass
19
+
20
+ @abstractmethod
21
+ def propose_change(self, context: Dict[str, Any]) -> Proposal:
22
+ """Propose a change based on context."""
23
+ pass
24
+
25
+ @abstractmethod
26
+ def analyze_risk(self, change: Dict[str, Any]) -> Dict[str, Any]:
27
+ """Analyze risk level of a change."""
28
+ pass
29
+
30
+
31
+ class SecurityAgent(BaseAgent):
32
+ """Security-focused agent for vulnerability detection."""
33
+
34
+ def __init__(self):
35
+ super().__init__(AgentRole.SECURITY, "security-agent")
36
+
37
+ def review_commit(self, commit: Dict[str, Any]) -> Dict[str, Any]:
38
+ """Review commit for security issues."""
39
+ findings = []
40
+ concerns = []
41
+
42
+ # Simulate security analysis
43
+ if "auth" in commit.get("subsystem", "").lower():
44
+ findings.append("Authentication changes detected - review token handling")
45
+
46
+ if commit.get("risk_level") == "critical":
47
+ concerns.append("Critical risk changes require additional security review")
48
+
49
+ score = 0.9 if not concerns else 0.6
50
+ approved = len(concerns) == 0
51
+
52
+ return {
53
+ "agent": self.name,
54
+ "role": self.role.value,
55
+ "approved": approved,
56
+ "findings": findings,
57
+ "concerns": concerns,
58
+ "suggestions": ["Consider adding security tests"],
59
+ "score": score
60
+ }
61
+
62
+ def propose_change(self, context: Dict[str, Any]) -> Proposal:
63
+ """Propose security-related changes."""
64
+ from agentvcs.models import Proposal, ChangeType, RiskLevel
65
+ import hashlib
66
+
67
+ proposal_id = hashlib.sha256(f"security-{context['target']}".encode()).hexdigest()[:12]
68
+
69
+ return Proposal(
70
+ id=proposal_id,
71
+ agent=self.name,
72
+ change_type=ChangeType.SECURITY,
73
+ target=context.get("target", "unknown"),
74
+ diff="# Security improvements\n# Add input validation\n# Update dependencies",
75
+ reasoning="Security analysis identified potential vulnerabilities",
76
+ risk_level=RiskLevel.HIGH,
77
+ estimated_impact="Improved security posture"
78
+ )
79
+
80
+ def analyze_risk(self, change: Dict[str, Any]) -> Dict[str, Any]:
81
+ """Analyze security risk."""
82
+ return {
83
+ "risk_level": "high" if "auth" in change.get("subsystem", "") else "medium",
84
+ "reasoning": "Security-sensitive component",
85
+ "mitigations": ["Add security tests", "Review access controls"]
86
+ }
87
+
88
+
89
+ class PerformanceAgent(BaseAgent):
90
+ """Performance-focused agent for optimization."""
91
+
92
+ def __init__(self):
93
+ super().__init__(AgentRole.PERFORMANCE, "performance-agent")
94
+
95
+ def review_commit(self, commit: Dict[str, Any]) -> Dict[str, Any]:
96
+ """Review commit for performance impact."""
97
+ findings = []
98
+ concerns = []
99
+
100
+ if commit.get("change_type") == "perf":
101
+ findings.append("Performance change detected - benchmark recommended")
102
+
103
+ if "database" in commit.get("subsystem", "").lower():
104
+ findings.append("Database changes - review query performance")
105
+
106
+ score = 0.85 if not concerns else 0.7
107
+ approved = len(concerns) == 0
108
+
109
+ return {
110
+ "agent": self.name,
111
+ "role": self.role.value,
112
+ "approved": approved,
113
+ "findings": findings,
114
+ "concerns": concerns,
115
+ "suggestions": ["Add performance benchmarks"],
116
+ "score": score
117
+ }
118
+
119
+ def propose_change(self, context: Dict[str, Any]) -> Proposal:
120
+ """Propose performance-related changes."""
121
+ from agentvcs.models import Proposal, ChangeType, RiskLevel
122
+ import hashlib
123
+
124
+ proposal_id = hashlib.sha256(f"perf-{context['target']}".encode()).hexdigest()[:12]
125
+
126
+ return Proposal(
127
+ id=proposal_id,
128
+ agent=self.name,
129
+ change_type=ChangeType.PERF,
130
+ target=context.get("target", "unknown"),
131
+ diff="# Performance optimizations\n# Add caching\n# Optimize queries",
132
+ reasoning="Performance analysis identified optimization opportunities",
133
+ risk_level=RiskLevel.MEDIUM,
134
+ estimated_impact="Improved response times"
135
+ )
136
+
137
+ def analyze_risk(self, change: Dict[str, Any]) -> Dict[str, Any]:
138
+ """Analyze performance risk."""
139
+ return {
140
+ "risk_level": "medium",
141
+ "reasoning": "Performance changes may affect system behavior",
142
+ "mitigations": ["Add benchmarks", "Monitor metrics"]
143
+ }
144
+
145
+
146
+ class ArchitectureAgent(BaseAgent):
147
+ """Architecture-focused agent for design review."""
148
+
149
+ def __init__(self):
150
+ super().__init__(AgentRole.ARCHITECTURE, "architecture-agent")
151
+
152
+ def review_commit(self, commit: Dict[str, Any]) -> Dict[str, Any]:
153
+ """Review commit for architectural impact."""
154
+ findings = []
155
+ concerns = []
156
+
157
+ if commit.get("change_type") == "refactor":
158
+ findings.append("Refactor detected - review architectural impact")
159
+
160
+ if len(commit.get("files", [])) > 5:
161
+ concerns.append("Large change spans many files - consider splitting")
162
+
163
+ score = 0.8 if not concerns else 0.65
164
+ approved = len(concerns) == 0
165
+
166
+ return {
167
+ "agent": self.name,
168
+ "role": self.role.value,
169
+ "approved": approved,
170
+ "findings": findings,
171
+ "concerns": concerns,
172
+ "suggestions": ["Update architecture documentation"],
173
+ "score": score
174
+ }
175
+
176
+ def propose_change(self, context: Dict[str, Any]) -> Proposal:
177
+ """Propose architecture-related changes."""
178
+ from agentvcs.models import Proposal, ChangeType, RiskLevel
179
+ import hashlib
180
+
181
+ proposal_id = hashlib.sha256(f"arch-{context['target']}".encode()).hexdigest()[:12]
182
+
183
+ return Proposal(
184
+ id=proposal_id,
185
+ agent=self.name,
186
+ change_type=ChangeType.REFACTOR,
187
+ target=context.get("target", "unknown"),
188
+ diff="# Architectural improvements\n# Decouple components\n# Improve modularity",
189
+ reasoning="Architecture analysis identified design improvements",
190
+ risk_level=RiskLevel.MEDIUM,
191
+ estimated_impact="Improved maintainability"
192
+ )
193
+
194
+ def analyze_risk(self, change: Dict[str, Any]) -> Dict[str, Any]:
195
+ """Analyze architectural risk."""
196
+ return {
197
+ "risk_level": "medium",
198
+ "reasoning": "Architectural changes affect system design",
199
+ "mitigations": ["Update docs", "Review dependencies"]
200
+ }
201
+
202
+
203
+ class RefactorAgent(BaseAgent):
204
+ """Refactor-focused agent for code improvements."""
205
+
206
+ def __init__(self):
207
+ super().__init__(AgentRole.REFACTOR, "refactor-agent")
208
+
209
+ def review_commit(self, commit: Dict[str, Any]) -> Dict[str, Any]:
210
+ """Review commit for refactoring quality."""
211
+ findings = []
212
+ concerns = []
213
+
214
+ if commit.get("change_type") == "refactor":
215
+ findings.append("Refactor change - verify behavior preservation")
216
+
217
+ score = 0.9 if not concerns else 0.75
218
+ approved = len(concerns) == 0
219
+
220
+ return {
221
+ "agent": self.name,
222
+ "role": self.role.value,
223
+ "approved": approved,
224
+ "findings": findings,
225
+ "concerns": concerns,
226
+ "suggestions": ["Add regression tests"],
227
+ "score": score
228
+ }
229
+
230
+ def propose_change(self, context: Dict[str, Any]) -> Proposal:
231
+ """Propose refactor-related changes."""
232
+ from agentvcs.models import Proposal, ChangeType, RiskLevel
233
+ import hashlib
234
+
235
+ proposal_id = hashlib.sha256(f"refactor-{context['target']}".encode()).hexdigest()[:12]
236
+
237
+ return Proposal(
238
+ id=proposal_id,
239
+ agent=self.name,
240
+ change_type=ChangeType.REFACTOR,
241
+ target=context.get("target", "unknown"),
242
+ diff="# Refactoring\n# Extract methods\n# Reduce complexity",
243
+ reasoning="Code analysis identified refactoring opportunities",
244
+ risk_level=RiskLevel.LOW,
245
+ estimated_impact="Improved code quality"
246
+ )
247
+
248
+ def analyze_risk(self, change: Dict[str, Any]) -> Dict[str, Any]:
249
+ """Analyze refactor risk."""
250
+ return {
251
+ "risk_level": "low",
252
+ "reasoning": "Refactoring maintains behavior",
253
+ "mitigations": ["Add tests", "Review carefully"]
254
+ }
@@ -0,0 +1,36 @@
1
+ """Agent registry for managing available agents."""
2
+
3
+ from typing import Dict, Optional
4
+ from agentvcs.models import AgentRole
5
+ from agentvcs.agents.base import (
6
+ BaseAgent, SecurityAgent, PerformanceAgent,
7
+ ArchitectureAgent, RefactorAgent
8
+ )
9
+
10
+
11
+ class AgentRegistry:
12
+ """Registry for managing available agents."""
13
+
14
+ def __init__(self):
15
+ self._agents: Dict[AgentRole, BaseAgent] = {
16
+ AgentRole.SECURITY: SecurityAgent(),
17
+ AgentRole.PERFORMANCE: PerformanceAgent(),
18
+ AgentRole.ARCHITECTURE: ArchitectureAgent(),
19
+ AgentRole.REFACTOR: RefactorAgent(),
20
+ }
21
+
22
+ def register_agent(self, role: AgentRole, agent: BaseAgent) -> None:
23
+ """Register a new agent."""
24
+ self._agents[role] = agent
25
+
26
+ def get_agent(self, role: AgentRole) -> Optional[BaseAgent]:
27
+ """Get an agent by role."""
28
+ return self._agents.get(role)
29
+
30
+ def list_agents(self) -> Dict[AgentRole, str]:
31
+ """List all registered agents."""
32
+ return {role: agent.name for role, agent in self._agents.items()}
33
+
34
+ def get_all_agents(self) -> Dict[AgentRole, BaseAgent]:
35
+ """Get all registered agents."""
36
+ return self._agents.copy()