coding-client 1.21.2__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.
Files changed (109) hide show
  1. coding_client/__init__.py +1 -0
  2. coding_client/api/__init__.py +19 -0
  3. coding_client/api/exception_handlers.py +158 -0
  4. coding_client/api/logging_setup.py +44 -0
  5. coding_client/api/metrics.py +40 -0
  6. coding_client/api/openapi_config.py +124 -0
  7. coding_client/api/request_logging.py +60 -0
  8. coding_client/api/validation.py +150 -0
  9. coding_client/auth/__init__.py +78 -0
  10. coding_client/auth/_default_tenant.py +132 -0
  11. coding_client/auth/_header_trust.py +98 -0
  12. coding_client/auth/_onbehalf.py +315 -0
  13. coding_client/auth/_trusted_networks.py +94 -0
  14. coding_client/auth/dependencies.py +61 -0
  15. coding_client/auth/middleware.py +445 -0
  16. coding_client/auth/models.py +83 -0
  17. coding_client/auth/outbound.py +137 -0
  18. coding_client/auth/rbac.py +21 -0
  19. coding_client/auth/rbac_coding.py +5 -0
  20. coding_client/auth/tenant.py +650 -0
  21. coding_client/auth/websocket.py +148 -0
  22. coding_client/clients/__init__.py +24 -0
  23. coding_client/clients/base.py +131 -0
  24. coding_client/clients/coding_ai.py +33 -0
  25. coding_client/clients/coding_analysis.py +36 -0
  26. coding_client/clients/coding_containers.py +45 -0
  27. coding_client/clients/coding_github.py +127 -0
  28. coding_client/clients/coding_realtime.py +127 -0
  29. coding_client/clients/coding_security.py +51 -0
  30. coding_client/clients/coding_testing.py +31 -0
  31. coding_client/clients/coding_workspaces.py +265 -0
  32. coding_client/config/__init__.py +12 -0
  33. coding_client/config/base_settings.py +61 -0
  34. coding_client/config/yaml_config_loader.py +172 -0
  35. coding_client/db/__init__.py +42 -0
  36. coding_client/db/db_types.py +122 -0
  37. coding_client/db/exceptions.py +59 -0
  38. coding_client/db/postgres_connection.py +572 -0
  39. coding_client/db/tenant_query_helper.py +417 -0
  40. coding_client/db_init.py +49 -0
  41. coding_client/exceptions/__init__.py +67 -0
  42. coding_client/exceptions/api_exceptions.py +395 -0
  43. coding_client/exceptions/pydantic_ai_exceptions.py +533 -0
  44. coding_client/interfaces/__init__.py +22 -0
  45. coding_client/interfaces/cache_interface.py +179 -0
  46. coding_client/interfaces/container_interface.py +49 -0
  47. coding_client/interfaces/docker_interface.py +283 -0
  48. coding_client/interfaces/graph_interface.py +28 -0
  49. coding_client/interfaces/security_interface.py +72 -0
  50. coding_client/interfaces/webhook_interface.py +67 -0
  51. coding_client/llm/__init__.py +54 -0
  52. coding_client/llm/base_agent.py +195 -0
  53. coding_client/llm/context.py +121 -0
  54. coding_client/llm/responses.py +102 -0
  55. coding_client/llm/routing.py +82 -0
  56. coding_client/llm/settings.py +102 -0
  57. coding_client/models/__init__.py +62 -0
  58. coding_client/models/agent.py +38 -0
  59. coding_client/models/ai_test_failure.py +745 -0
  60. coding_client/models/analysis.py +330 -0
  61. coding_client/models/architecture.py +685 -0
  62. coding_client/models/bug.py +128 -0
  63. coding_client/models/code_graph.py +317 -0
  64. coding_client/models/container.py +241 -0
  65. coding_client/models/core.py +878 -0
  66. coding_client/models/docker_container.py +104 -0
  67. coding_client/models/github.py +293 -0
  68. coding_client/models/logging.py +29 -0
  69. coding_client/models/package_manager.py +257 -0
  70. coding_client/models/pr_validation.py +440 -0
  71. coding_client/models/pydantic_ai.py +395 -0
  72. coding_client/models/repo_scanner.py +249 -0
  73. coding_client/models/responses.py +431 -0
  74. coding_client/models/security.py +185 -0
  75. coding_client/models/static_analysis.py +508 -0
  76. coding_client/models/system.py +48 -0
  77. coding_client/models/test_executor.py +204 -0
  78. coding_client/models/testing.py +673 -0
  79. coding_client/models/testing_config.py +200 -0
  80. coding_client/models/validation.py +127 -0
  81. coding_client/models_init.py +272 -0
  82. coding_client/telemetry.py +195 -0
  83. coding_client/testing.py +180 -0
  84. coding_client/types/__init__.py +130 -0
  85. coding_client/types/constraint_types.py +276 -0
  86. coding_client/types/core_types.py +112 -0
  87. coding_client/types/state_machine.py +443 -0
  88. coding_client/utils/__init__.py +86 -0
  89. coding_client/utils/archive_utils.py +387 -0
  90. coding_client/utils/ast_debug.py +45 -0
  91. coding_client/utils/async_timeout.py +364 -0
  92. coding_client/utils/constants.py +518 -0
  93. coding_client/utils/content_processing.py +326 -0
  94. coding_client/utils/database.py +916 -0
  95. coding_client/utils/encoding_helper.py +222 -0
  96. coding_client/utils/enum_helpers.py +166 -0
  97. coding_client/utils/file_operations.py +177 -0
  98. coding_client/utils/filesystem_ops.py +528 -0
  99. coding_client/utils/http_client.py +562 -0
  100. coding_client/utils/path_utils.py +471 -0
  101. coding_client/utils/profiling.py +421 -0
  102. coding_client/utils/response_builder.py +240 -0
  103. coding_client/utils/retry_helper.py +712 -0
  104. coding_client/utils/security_validation.py +423 -0
  105. coding_client-1.21.2.dist-info/METADATA +234 -0
  106. coding_client-1.21.2.dist-info/RECORD +109 -0
  107. coding_client-1.21.2.dist-info/WHEEL +5 -0
  108. coding_client-1.21.2.dist-info/licenses/LICENSE +201 -0
  109. coding_client-1.21.2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,276 @@
1
+ """
2
+ Constraint types using Pydantic's Annotated types for validation.
3
+
4
+ These types provide runtime validation and constraints for various
5
+ data types used throughout the system.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import re
11
+ from datetime import UTC, datetime
12
+ from typing import Annotated
13
+
14
+ from pydantic import AfterValidator, Field
15
+
16
+
17
+ def validate_container_name(name: str) -> str:
18
+ """Validate Docker container naming constraints."""
19
+ if not re.match(r"^[a-zA-Z0-9][a-zA-Z0-9_.-]*$", name):
20
+ raise ValueError("Container name must match Docker naming rules")
21
+ if len(name) > 63:
22
+ raise ValueError("Container name too long (max 63 characters)")
23
+ return name
24
+
25
+
26
+ def validate_github_repo_url(url: str) -> str:
27
+ """Validate GitHub repository URL format."""
28
+ github_pattern = r"^https://github\.com/[a-zA-Z0-9\-_\.]+/[a-zA-Z0-9\-_\.]+(?:\.git)?/?$"
29
+ if not re.match(github_pattern, url):
30
+ raise ValueError("Invalid GitHub repository URL format")
31
+ return url
32
+
33
+
34
+ def validate_code_content(content: str) -> str:
35
+ """Validate code content size and format."""
36
+ if len(content) > 1024 * 1024: # 1MB limit
37
+ raise ValueError("Code content too large (max 1MB)")
38
+ if not content.strip():
39
+ raise ValueError("Code content cannot be empty")
40
+ return content
41
+
42
+
43
+ def validate_absolute_path(path: str) -> str:
44
+ """Validate absolute file path."""
45
+ if not path.startswith("/") and not (len(path) > 2 and path[1] == ":"):
46
+ raise ValueError("Path must be absolute")
47
+ return path
48
+
49
+
50
+ def validate_relative_path(path: str) -> str:
51
+ """Validate relative file path."""
52
+ if path.startswith("/") or (len(path) > 2 and path[1] == ":"):
53
+ raise ValueError("Path must be relative")
54
+ if ".." in path:
55
+ raise ValueError("Path cannot contain '..' segments")
56
+ return path
57
+
58
+
59
+ def validate_user_identifier(user_id: str) -> str:
60
+ """Validate user identifier format."""
61
+ if not re.match(r"^[a-zA-Z0-9_-]+$", user_id):
62
+ raise ValueError("User ID must contain only alphanumeric, underscore, and dash characters")
63
+ if len(user_id) < 3 or len(user_id) > 50:
64
+ raise ValueError("User ID must be between 3 and 50 characters")
65
+ return user_id
66
+
67
+
68
+ def validate_request_id(req_id: str) -> str:
69
+ """Validate request ID format."""
70
+ if not req_id.startswith("req_"):
71
+ raise ValueError("Request ID must start with 'req_'")
72
+ if len(req_id) > 100:
73
+ raise ValueError("Request ID too long (max 100 characters)")
74
+ return req_id
75
+
76
+
77
+ def validate_analysis_id(analysis_id: str) -> str:
78
+ """Validate analysis ID format."""
79
+ if not analysis_id.startswith("anal_"):
80
+ raise ValueError("Analysis ID must start with 'anal_'")
81
+ if len(analysis_id) > 100:
82
+ raise ValueError("Analysis ID too long (max 100 characters)")
83
+ return analysis_id
84
+
85
+
86
+ def validate_future_timestamp(timestamp: datetime) -> datetime:
87
+ """Validate that timestamp is in the future."""
88
+ if timestamp <= datetime.now(UTC):
89
+ raise ValueError("Timestamp must be in the future")
90
+ return timestamp
91
+
92
+
93
+ # Container naming constraint (Docker compatible)
94
+ ContainerName = Annotated[
95
+ str,
96
+ Field(min_length=1, max_length=63, pattern=r"^[a-zA-Z0-9][a-zA-Z0-9_.-]*$"),
97
+ AfterValidator(validate_container_name),
98
+ ]
99
+
100
+ # GitHub repository URL constraint
101
+ GitHubRepoUrl = Annotated[
102
+ str, Field(min_length=1, max_length=500), AfterValidator(validate_github_repo_url)
103
+ ]
104
+
105
+ # Code content constraint
106
+ CodeContent = Annotated[
107
+ str,
108
+ Field(min_length=1, max_length=1024 * 1024), # 1MB limit
109
+ AfterValidator(validate_code_content),
110
+ ]
111
+
112
+ # Memory constraints (in MB)
113
+ MemoryMB = Annotated[
114
+ int,
115
+ Field(ge=64, le=32768), # 64MB to 32GB
116
+ ]
117
+
118
+ # CPU constraints (in cores)
119
+ CPUCores = Annotated[
120
+ float,
121
+ Field(ge=0.1, le=16.0), # 0.1 to 16 cores
122
+ ]
123
+
124
+ # Timeout constraints (in seconds)
125
+ TimeoutSeconds = Annotated[
126
+ int,
127
+ Field(ge=1, le=3600), # 1 second to 1 hour
128
+ ]
129
+
130
+ # File path constraints
131
+ AbsolutePath = Annotated[
132
+ str, Field(min_length=1, max_length=4096), AfterValidator(validate_absolute_path)
133
+ ]
134
+
135
+ RelativePath = Annotated[
136
+ str, Field(min_length=1, max_length=4096), AfterValidator(validate_relative_path)
137
+ ]
138
+
139
+ # User identifier constraint
140
+ UserIdentifier = Annotated[
141
+ str,
142
+ Field(min_length=3, max_length=50, pattern=r"^[a-zA-Z0-9_-]+$"),
143
+ AfterValidator(validate_user_identifier),
144
+ ]
145
+
146
+ # Request ID constraint
147
+ RequestID = Annotated[
148
+ str,
149
+ Field(min_length=5, max_length=100, pattern=r"^req_.*"),
150
+ AfterValidator(validate_request_id),
151
+ ]
152
+
153
+ # Analysis ID constraint
154
+ AnalysisID = Annotated[
155
+ str,
156
+ Field(min_length=6, max_length=100, pattern=r"^anal_.*"),
157
+ AfterValidator(validate_analysis_id),
158
+ ]
159
+
160
+ # Code snippet constraint (smaller than full code)
161
+ CodeSnippet = Annotated[
162
+ str,
163
+ Field(min_length=1, max_length=10240), # 10KB limit for snippets
164
+ ]
165
+
166
+ # Port number constraint
167
+ PortNumber = Annotated[
168
+ int,
169
+ Field(ge=1, le=65535),
170
+ ]
171
+
172
+ # Percentage constraint
173
+ Percentage = Annotated[
174
+ float,
175
+ Field(ge=0.0, le=100.0),
176
+ ]
177
+
178
+ # Score constraint (0-10)
179
+ Score = Annotated[
180
+ float,
181
+ Field(ge=0.0, le=10.0),
182
+ ]
183
+
184
+ # Confidence constraint (0-1)
185
+ Confidence = Annotated[
186
+ float,
187
+ Field(ge=0.0, le=1.0),
188
+ ]
189
+
190
+ # Timestamp constraints
191
+ ValidTimestamp = Annotated[datetime, Field(description="Valid timestamp (past or present)")]
192
+
193
+ FutureTimestamp = Annotated[
194
+ datetime,
195
+ Field(description="Future timestamp"),
196
+ AfterValidator(validate_future_timestamp),
197
+ ]
198
+
199
+ # File size constraints
200
+ FileSizeBytes = Annotated[
201
+ int,
202
+ Field(ge=0, le=100 * 1024 * 1024), # 0 to 100MB
203
+ ]
204
+
205
+ # Line number constraint
206
+ LineNumber = Annotated[
207
+ int,
208
+ Field(ge=1, le=1000000), # Line 1 to 1 million
209
+ ]
210
+
211
+ # Column number constraint
212
+ ColumnNumber = Annotated[
213
+ int,
214
+ Field(ge=1, le=1000), # Column 1 to 1000
215
+ ]
216
+
217
+ # =============================================================================
218
+ # SafeString Types for Schemathesis Contract Test Compatibility
219
+ # =============================================================================
220
+ # These patterns block dangerous control characters while allowing:
221
+ # - All printable ASCII (0x20-0x7E)
222
+ # - Tab (0x09), Newline (0x0A), Carriage Return (0x0D)
223
+ # - All Unicode characters (0x80+)
224
+ #
225
+ # Blocked characters: NULL (0x00), 0x01-0x08, VT (0x0B), FF (0x0C), 0x0E-0x1F, DEL (0x7F)
226
+ # This matches the validation in src/app/middleware/input_validator.py
227
+ # =============================================================================
228
+
229
+ # Pattern that blocks dangerous control characters
230
+ SAFE_STRING_PATTERN = r"^[^\x00-\x08\x0B\x0C\x0E-\x1F\x7F]*$"
231
+
232
+ # Basic safe string - no length constraints
233
+ SafeString = Annotated[
234
+ str,
235
+ Field(pattern=SAFE_STRING_PATTERN),
236
+ ]
237
+
238
+ # Safe string for identifiers and short values (container names, IDs, etc.)
239
+ SafeStringShort = Annotated[
240
+ str,
241
+ Field(min_length=1, max_length=256, pattern=SAFE_STRING_PATTERN),
242
+ ]
243
+
244
+ # Safe string for medium-length content (messages, descriptions, titles)
245
+ SafeStringMedium = Annotated[
246
+ str,
247
+ Field(min_length=1, max_length=1000, pattern=SAFE_STRING_PATTERN),
248
+ ]
249
+
250
+ # Safe string for longer content (error messages, recommendations)
251
+ SafeStringLong = Annotated[
252
+ str,
253
+ Field(min_length=1, max_length=10000, pattern=SAFE_STRING_PATTERN),
254
+ ]
255
+
256
+ # Safe string for code content (file paths, code snippets, stdout/stderr)
257
+ SafeCodeString = Annotated[
258
+ str,
259
+ Field(max_length=50000, pattern=SAFE_STRING_PATTERN),
260
+ ]
261
+
262
+ # Optional safe string variants
263
+ SafeStringOptional = Annotated[
264
+ str,
265
+ Field(pattern=SAFE_STRING_PATTERN),
266
+ ]
267
+
268
+ SafeStringShortOptional = Annotated[
269
+ str,
270
+ Field(max_length=256, pattern=SAFE_STRING_PATTERN),
271
+ ]
272
+
273
+ SafeStringMediumOptional = Annotated[
274
+ str,
275
+ Field(max_length=1000, pattern=SAFE_STRING_PATTERN),
276
+ ]
@@ -0,0 +1,112 @@
1
+ """
2
+ Core Literal types for type safety in critical system paths.
3
+
4
+ These types provide compile-time and runtime type safety for key system
5
+ constants and enumerations, reducing runtime errors and improving code clarity.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from enum import StrEnum
11
+ from typing import Literal
12
+
13
+ # Language Support - based on subagent analysis
14
+ SupportedLanguage = Literal[
15
+ "python", "javascript", "typescript", "java", "rust", "go", "csharp", "cpp"
16
+ ]
17
+
18
+ # Execution Modes - based on timeout_manager.py analysis
19
+ ExecutionMode = Literal["validate", "execute", "test", "analyze", "quality_check", "security_scan"]
20
+
21
+ # Container States - based on test_orchestrator.py analysis
22
+ ContainerState = Literal[
23
+ "creating", "running", "stopped", "error", "removing", "paused", "restarting"
24
+ ]
25
+
26
+ # Analysis States - for analysis pipeline tracking
27
+ AnalysisState = Literal["queued", "processing", "completed", "failed", "cancelled", "timeout"]
28
+
29
+ # Response States - for API responses
30
+ ResponseState = Literal["success", "error", "pending", "timeout", "unauthorized", "forbidden"]
31
+
32
+ # Validation Results - for validation outcomes
33
+ ValidationResult = Literal["valid", "invalid", "warning", "error", "timeout", "pending"]
34
+
35
+ # Quality Levels - for quality assessment
36
+ QualityLevel = Literal["low", "medium", "high", "critical"]
37
+
38
+ # Health States - for system health monitoring
39
+ HealthState = Literal["healthy", "unhealthy", "unknown", "degraded", "critical", "maintenance"]
40
+
41
+ # Security Levels - for security classification
42
+ SecurityLevel = Literal["low", "medium", "high", "critical"]
43
+
44
+ # Test Types - for test execution
45
+ TestType = Literal["unit", "integration", "functional", "performance", "security", "coverage"]
46
+
47
+ # Test States - for test execution tracking
48
+ TestState = Literal["pending", "running", "passed", "failed", "skipped", "timeout", "error"]
49
+
50
+ # Error Categories - for error classification
51
+ ErrorCategory = Literal[
52
+ "timeout",
53
+ "execution_error",
54
+ "validation_error",
55
+ "type_error",
56
+ "permission_error",
57
+ "network_error",
58
+ "system_error",
59
+ ]
60
+
61
+ # Exit Codes - for process exit codes
62
+ ExitCode = Literal[0, 1, 124] # Success, Error, Timeout
63
+
64
+ # Database States - for database operations
65
+ DatabaseState = Literal["connected", "disconnected", "error", "readonly", "locked"]
66
+
67
+ # Transaction States - for transaction management
68
+ TransactionState = Literal["idle", "active", "committed", "rolled_back", "failed"]
69
+
70
+ # GitHub Event Types - for webhook handling
71
+ GitHubEventType = Literal[
72
+ "push",
73
+ "pull_request",
74
+ "issues",
75
+ "issue_comment",
76
+ "pull_request_review",
77
+ "pull_request_review_comment",
78
+ "create",
79
+ "delete",
80
+ "release",
81
+ ]
82
+
83
+
84
+ # GitHub Event Types as Enum - for webhook handler compatibility
85
+ class GitHubEventTypeEnum(StrEnum):
86
+ """GitHub webhook event types as enum for easier handling."""
87
+
88
+ PUSH = "push"
89
+ PULL_REQUEST = "pull_request"
90
+ ISSUES = "issues"
91
+ ISSUE_COMMENT = "issue_comment"
92
+ PULL_REQUEST_REVIEW = "pull_request_review"
93
+ PULL_REQUEST_REVIEW_COMMENT = "pull_request_review_comment"
94
+ CREATE = "create"
95
+ DELETE = "delete"
96
+ RELEASE = "release"
97
+
98
+
99
+ # PR States - for pull request management
100
+ PRState = Literal["open", "closed", "merged", "draft", "review_required"]
101
+
102
+ # Analysis Types - for code analysis
103
+ AnalysisType = Literal["syntax", "semantic", "security", "performance", "quality", "architecture"]
104
+
105
+ # File Operation Types
106
+ FileOperationType = Literal["read", "write", "append", "delete", "copy", "move", "create"]
107
+
108
+ # Network Operation Types
109
+ NetworkOperationType = Literal["get", "post", "put", "delete", "patch", "options", "head"]
110
+
111
+ # Cache Operation Types
112
+ CacheOperationType = Literal["get", "set", "delete", "clear", "expire", "exists"]