repodna-engine 1.0.1__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 (173) hide show
  1. repodna/__init__.py +3 -0
  2. repodna/__main__.py +10 -0
  3. repodna/advisor/__init__.py +17 -0
  4. repodna/advisor/engine.py +502 -0
  5. repodna/advisor/models.py +101 -0
  6. repodna/agent/__init__.py +87 -0
  7. repodna/agent/context.py +558 -0
  8. repodna/agent/deltas.py +198 -0
  9. repodna/agent/evidence.py +134 -0
  10. repodna/agent/expansion.py +447 -0
  11. repodna/agent/localization.py +518 -0
  12. repodna/agent/models.py +695 -0
  13. repodna/agent/patch.py +378 -0
  14. repodna/agent/postflight.py +278 -0
  15. repodna/agent/preflight.py +336 -0
  16. repodna/agent/ranking.py +318 -0
  17. repodna/agent/repo_map.py +392 -0
  18. repodna/agent/safety.py +111 -0
  19. repodna/agent/service.py +574 -0
  20. repodna/agent/sessions.py +264 -0
  21. repodna/agent/task.py +660 -0
  22. repodna/agent/telemetry.py +101 -0
  23. repodna/agent/token_budget.py +231 -0
  24. repodna/api/__init__.py +1 -0
  25. repodna/api/agent_routes.py +248 -0
  26. repodna/api/app.py +2904 -0
  27. repodna/benchmarks/__init__.py +29 -0
  28. repodna/benchmarks/baselines.py +126 -0
  29. repodna/benchmarks/budget_bench.py +162 -0
  30. repodna/benchmarks/engine.py +418 -0
  31. repodna/benchmarks/evaluator.py +310 -0
  32. repodna/benchmarks/metrics.py +206 -0
  33. repodna/benchmarks/models.py +194 -0
  34. repodna/benchmarks/scalability.py +166 -0
  35. repodna/brain/__init__.py +46 -0
  36. repodna/brain/evidence.py +276 -0
  37. repodna/brain/extractor.py +1207 -0
  38. repodna/brain/indexer.py +766 -0
  39. repodna/brain/models.py +275 -0
  40. repodna/brain/multilang_extractors.py +889 -0
  41. repodna/brain/retrieval.py +469 -0
  42. repodna/brain/tracer.py +203 -0
  43. repodna/cli/__init__.py +1 -0
  44. repodna/cli/__main__.py +10 -0
  45. repodna/cli/agent_cmd.py +228 -0
  46. repodna/cli/installer.py +590 -0
  47. repodna/cli/main.py +2173 -0
  48. repodna/cli/plugin_cmd.py +130 -0
  49. repodna/cli/workspace_cmd.py +211 -0
  50. repodna/context/__init__.py +9 -0
  51. repodna/context/builder.py +379 -0
  52. repodna/context/models.py +133 -0
  53. repodna/contract/__init__.py +39 -0
  54. repodna/contract/evaluator.py +318 -0
  55. repodna/contract/loader.py +260 -0
  56. repodna/contract/models.py +185 -0
  57. repodna/core/__init__.py +1 -0
  58. repodna/core/analyzer.py +1424 -0
  59. repodna/diff/__init__.py +35 -0
  60. repodna/diff/engine.py +332 -0
  61. repodna/diff/models.py +117 -0
  62. repodna/diff/snapshot.py +248 -0
  63. repodna/ecosystem/__init__.py +27 -0
  64. repodna/ecosystem/contracts.py +129 -0
  65. repodna/ecosystem/doctor.py +253 -0
  66. repodna/git_insights/__init__.py +1 -0
  67. repodna/git_insights/analyzer.py +273 -0
  68. repodna/graph/__init__.py +1 -0
  69. repodna/graph/engine.py +562 -0
  70. repodna/guardian/__init__.py +17 -0
  71. repodna/guardian/engine.py +369 -0
  72. repodna/guardian/models.py +104 -0
  73. repodna/history/__init__.py +40 -0
  74. repodna/history/cache.py +240 -0
  75. repodna/history/diff.py +394 -0
  76. repodna/history/engine.py +557 -0
  77. repodna/history/evidence.py +160 -0
  78. repodna/history/models.py +258 -0
  79. repodna/history/timeline.py +164 -0
  80. repodna/intelligence/__init__.py +33 -0
  81. repodna/intelligence/models.py +165 -0
  82. repodna/intelligence/service.py +570 -0
  83. repodna/live/__init__.py +94 -0
  84. repodna/live/alerts.py +443 -0
  85. repodna/live/coordinator.py +351 -0
  86. repodna/live/diff.py +444 -0
  87. repodna/live/events.py +471 -0
  88. repodna/live/filtering.py +329 -0
  89. repodna/live/history.py +637 -0
  90. repodna/live/models.py +505 -0
  91. repodna/live/observer.py +653 -0
  92. repodna/live/reconciliation.py +253 -0
  93. repodna/live/session.py +1547 -0
  94. repodna/mcp/__init__.py +5 -0
  95. repodna/mcp/__main__.py +6 -0
  96. repodna/mcp/agent_tools.py +258 -0
  97. repodna/mcp/server.py +3283 -0
  98. repodna/mcp/workspace_tools.py +200 -0
  99. repodna/parsers/__init__.py +13 -0
  100. repodna/parsers/base.py +126 -0
  101. repodna/parsers/capabilities.py +361 -0
  102. repodna/parsers/project_metadata.py +232 -0
  103. repodna/parsers/resolver.py +621 -0
  104. repodna/parsers/treesitter_parser.py +830 -0
  105. repodna/passport/__init__.py +64 -0
  106. repodna/passport/generator.py +546 -0
  107. repodna/passport/migrator.py +139 -0
  108. repodna/passport/models.py +224 -0
  109. repodna/passport/validator.py +143 -0
  110. repodna/performance/__init__.py +89 -0
  111. repodna/performance/cache.py +1584 -0
  112. repodna/performance/identity.py +341 -0
  113. repodna/performance/incremental.py +317 -0
  114. repodna/performance/models.py +157 -0
  115. repodna/performance/parallel.py +291 -0
  116. repodna/plugins/__init__.py +47 -0
  117. repodna/plugins/evaluator.py +334 -0
  118. repodna/plugins/models.py +113 -0
  119. repodna/plugins/validator.py +256 -0
  120. repodna/quality/__init__.py +91 -0
  121. repodna/quality/complexity.py +352 -0
  122. repodna/quality/config.py +159 -0
  123. repodna/quality/debt.py +73 -0
  124. repodna/quality/duplicates.py +330 -0
  125. repodna/quality/engine.py +282 -0
  126. repodna/quality/impact.py +198 -0
  127. repodna/quality/models.py +427 -0
  128. repodna/quality/rules.py +364 -0
  129. repodna/quality/sarif.py +107 -0
  130. repodna/quality/security_signals.py +278 -0
  131. repodna/quality/test_mapping.py +271 -0
  132. repodna/quality/unused.py +201 -0
  133. repodna/reports/__init__.py +1 -0
  134. repodna/reports/exporter.py +374 -0
  135. repodna/rules/__init__.py +1 -0
  136. repodna/rules/health.py +436 -0
  137. repodna/schemas/__init__.py +1 -0
  138. repodna/schemas/models.py +348 -0
  139. repodna/security/__init__.py +1 -0
  140. repodna/security/safe_yaml.py +81 -0
  141. repodna/security/validators.py +583 -0
  142. repodna/skills/__init__.py +0 -0
  143. repodna/skills/repodna/SKILL.md +59 -0
  144. repodna/skills/repodna/__init__.py +0 -0
  145. repodna/skills/repodna/examples/workflows.md +85 -0
  146. repodna/skills/repodna/references/architecture-rules.md +26 -0
  147. repodna/storage/__init__.py +1 -0
  148. repodna/storage/workspace.py +199 -0
  149. repodna/webui/__init__.py +1 -0
  150. repodna/webui/assets/DependencyGraph-km_Qo-nG.js +43 -0
  151. repodna/webui/assets/HealthReportView-WVL39aNO.js +1 -0
  152. repodna/webui/assets/index-ByZ5e5pe.js +506 -0
  153. repodna/webui/assets/index-CDj3e8hw.css +1 -0
  154. repodna/webui/index.html +21 -0
  155. repodna/workspace/__init__.py +131 -0
  156. repodna/workspace/compatibility.py +317 -0
  157. repodna/workspace/context.py +175 -0
  158. repodna/workspace/contracts.py +369 -0
  159. repodna/workspace/federation.py +411 -0
  160. repodna/workspace/identity.py +202 -0
  161. repodna/workspace/impact.py +111 -0
  162. repodna/workspace/manifest.py +266 -0
  163. repodna/workspace/models.py +461 -0
  164. repodna/workspace/packages.py +494 -0
  165. repodna/workspace/policies.py +142 -0
  166. repodna/workspace/services.py +238 -0
  167. repodna/workspace/topology.py +316 -0
  168. repodna_engine-1.0.1.dist-info/METADATA +129 -0
  169. repodna_engine-1.0.1.dist-info/RECORD +173 -0
  170. repodna_engine-1.0.1.dist-info/WHEEL +5 -0
  171. repodna_engine-1.0.1.dist-info/entry_points.txt +2 -0
  172. repodna_engine-1.0.1.dist-info/licenses/LICENSE +21 -0
  173. repodna_engine-1.0.1.dist-info/top_level.txt +1 -0
repodna/live/models.py ADDED
@@ -0,0 +1,505 @@
1
+ """Live Architecture Engine domain models, lifecycle state machine, and typed schemas."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from datetime import UTC, datetime
6
+ from enum import StrEnum
7
+ from typing import Any
8
+
9
+ from pydantic import BaseModel, ConfigDict, Field
10
+
11
+ from repodna.schemas.models import ScanLimits, SeverityLevel
12
+
13
+ LIVE_EVENT_SCHEMA_VERSION = "1.0"
14
+ LIVE_STATE_SCHEMA_VERSION = 1
15
+
16
+
17
+ class LiveSessionState(StrEnum):
18
+ STARTING = "STARTING"
19
+ WATCHING = "WATCHING"
20
+ DEBOUNCING = "DEBOUNCING"
21
+ ANALYZING = "ANALYZING"
22
+ PAUSED = "PAUSED"
23
+ DEGRADED = "DEGRADED"
24
+ STOPPING = "STOPPING"
25
+ STOPPED = "STOPPED"
26
+ FAILED = "FAILED"
27
+
28
+
29
+ VALID_STATE_TRANSITIONS: dict[LiveSessionState, frozenset[LiveSessionState]] = {
30
+ LiveSessionState.STARTING: frozenset(
31
+ {
32
+ LiveSessionState.ANALYZING,
33
+ LiveSessionState.WATCHING,
34
+ LiveSessionState.DEGRADED,
35
+ LiveSessionState.STOPPING,
36
+ LiveSessionState.FAILED,
37
+ }
38
+ ),
39
+ LiveSessionState.WATCHING: frozenset(
40
+ {
41
+ LiveSessionState.DEBOUNCING,
42
+ LiveSessionState.ANALYZING,
43
+ LiveSessionState.PAUSED,
44
+ LiveSessionState.DEGRADED,
45
+ LiveSessionState.STOPPING,
46
+ LiveSessionState.FAILED,
47
+ }
48
+ ),
49
+ LiveSessionState.DEBOUNCING: frozenset(
50
+ {
51
+ LiveSessionState.ANALYZING,
52
+ LiveSessionState.WATCHING,
53
+ LiveSessionState.PAUSED,
54
+ LiveSessionState.DEGRADED,
55
+ LiveSessionState.STOPPING,
56
+ LiveSessionState.FAILED,
57
+ }
58
+ ),
59
+ LiveSessionState.ANALYZING: frozenset(
60
+ {
61
+ LiveSessionState.WATCHING,
62
+ LiveSessionState.DEBOUNCING,
63
+ LiveSessionState.PAUSED,
64
+ LiveSessionState.DEGRADED,
65
+ LiveSessionState.STOPPING,
66
+ LiveSessionState.FAILED,
67
+ }
68
+ ),
69
+ LiveSessionState.PAUSED: frozenset(
70
+ {
71
+ LiveSessionState.WATCHING,
72
+ LiveSessionState.ANALYZING,
73
+ LiveSessionState.DEGRADED,
74
+ LiveSessionState.STOPPING,
75
+ LiveSessionState.FAILED,
76
+ }
77
+ ),
78
+ LiveSessionState.DEGRADED: frozenset(
79
+ {
80
+ LiveSessionState.WATCHING,
81
+ LiveSessionState.DEBOUNCING,
82
+ LiveSessionState.ANALYZING,
83
+ LiveSessionState.PAUSED,
84
+ LiveSessionState.STOPPING,
85
+ LiveSessionState.FAILED,
86
+ }
87
+ ),
88
+ LiveSessionState.STOPPING: frozenset(
89
+ {
90
+ LiveSessionState.STOPPED,
91
+ LiveSessionState.FAILED,
92
+ }
93
+ ),
94
+ LiveSessionState.STOPPED: frozenset(),
95
+ LiveSessionState.FAILED: frozenset(
96
+ {
97
+ LiveSessionState.STOPPING,
98
+ LiveSessionState.STOPPED,
99
+ }
100
+ ),
101
+ }
102
+
103
+
104
+ class InvalidStateTransitionError(ValueError):
105
+ """Raised when an invalid live session lifecycle transition is attempted."""
106
+
107
+ def __init__(self, current: LiveSessionState, target: LiveSessionState) -> None:
108
+ super().__init__(f"Invalid live session state transition: {current.value} -> {target.value}")
109
+ self.current = current
110
+ self.target = target
111
+
112
+
113
+ def validate_state_transition(current: LiveSessionState, target: LiveSessionState) -> None:
114
+ """Validate that transitioning from `current` to `target` is permitted."""
115
+ if current == target:
116
+ return
117
+ allowed = VALID_STATE_TRANSITIONS.get(current, frozenset())
118
+ if target not in allowed:
119
+ raise InvalidStateTransitionError(current, target)
120
+
121
+
122
+ class FreshnessLevel(StrEnum):
123
+ VERIFIED_CURRENT = "VERIFIED_CURRENT"
124
+ CHANGE_PENDING = "CHANGE_PENDING"
125
+ ANALYZING = "ANALYZING"
126
+ STALE = "STALE"
127
+ UNKNOWN = "UNKNOWN"
128
+ DEGRADED = "DEGRADED"
129
+
130
+
131
+ class WatcherBackend(StrEnum):
132
+ NATIVE_WATCHFILES = "native_watchfiles"
133
+ POLLING_FALLBACK = "polling_fallback"
134
+ DISABLED = "disabled"
135
+
136
+
137
+ class NormalizedEventKind(StrEnum):
138
+ CREATED = "CREATED"
139
+ MODIFIED = "MODIFIED"
140
+ DELETED = "DELETED"
141
+ MOVED = "MOVED"
142
+ DIRECTORY_CHANGED = "DIRECTORY_CHANGED"
143
+ CONFIG_CHANGED = "CONFIG_CHANGED"
144
+ WATCH_OVERFLOW = "WATCH_OVERFLOW"
145
+ WATCH_ERROR = "WATCH_ERROR"
146
+ RECONCILIATION_REQUIRED = "RECONCILIATION_REQUIRED"
147
+
148
+
149
+ class LiveEventType(StrEnum):
150
+ SESSION_STARTED = "session_started"
151
+ SESSION_STATE_CHANGED = "session_state_changed"
152
+ FILESYSTEM_BATCH = "filesystem_batch"
153
+ ANALYSIS_STARTED = "analysis_started"
154
+ ANALYSIS_PROGRESS = "analysis_progress"
155
+ ANALYSIS_COMPLETED = "analysis_completed"
156
+ ANALYSIS_SUPERSEDED = "analysis_superseded"
157
+ ANALYSIS_FAILED = "analysis_failed"
158
+ ARCHITECTURE_DELTA = "architecture_delta"
159
+ ALERT_CREATED = "alert_created"
160
+ ALERT_RESOLVED = "alert_resolved"
161
+ SNAPSHOT_PUBLISHED = "snapshot_published"
162
+ QUALITY_UPDATED = "quality_updated"
163
+ FRESHNESS_CHANGED = "freshness_changed"
164
+ RECONCILIATION_REQUIRED = "reconciliation_required"
165
+ STREAM_RESET = "stream_reset"
166
+ SESSION_STOPPED = "session_stopped"
167
+
168
+
169
+ class AlertCategory(StrEnum):
170
+ NEW_CYCLE = "NEW_CYCLE"
171
+ CONTRACT_REGRESSION = "CONTRACT_REGRESSION"
172
+ COUPLING_INCREASE = "COUPLING_INCREASE"
173
+ COVERAGE_REGRESSION = "COVERAGE_REGRESSION"
174
+ RESOLVER_FAILURE = "RESOLVER_FAILURE"
175
+ STALE_ANALYSIS = "STALE_ANALYSIS"
176
+ WATCHER_DEGRADED = "WATCHER_DEGRADED"
177
+
178
+
179
+ class AlertStatus(StrEnum):
180
+ ACTIVE = "ACTIVE"
181
+ ACKNOWLEDGED = "ACKNOWLEDGED"
182
+ RESOLVED = "RESOLVED"
183
+ UNKNOWN = "UNKNOWN"
184
+
185
+
186
+ class LiveResourceLimits(BaseModel):
187
+ """Configurable bounded resource limits for a live architecture session."""
188
+
189
+ model_config = ConfigDict(extra="forbid")
190
+
191
+ debounce_ms: int = Field(default=350, ge=50, le=5000)
192
+ max_batch_wait_ms: int = Field(default=2000, ge=200, le=15000)
193
+ max_pending_events: int = Field(default=2000, ge=16, le=20000)
194
+ max_replay_events: int = Field(default=500, ge=16, le=5000)
195
+ max_subscriber_queue: int = Field(default=256, ge=8, le=2048)
196
+ max_history_entries: int = Field(default=200, ge=10, le=2000)
197
+ max_history_bytes: int = Field(default=8 * 1024 * 1024, ge=65536, le=64 * 1024 * 1024)
198
+ max_event_payload_bytes: int = Field(default=64 * 1024, ge=4096, le=512 * 1024)
199
+ reconcile_interval_seconds: float = Field(default=60.0, ge=2.0, le=3600.0)
200
+ poll_interval_ms: int = Field(default=500, ge=100, le=10000)
201
+ idle_timeout_seconds: float = Field(default=3600.0, ge=30.0, le=86400.0)
202
+ max_observer_restarts: int = Field(default=5, ge=1, le=20)
203
+ workers: int | None = Field(default=None, ge=1, le=32)
204
+
205
+
206
+ class LiveSessionCreateRequest(BaseModel):
207
+ """Explicit opt-in request to start monitoring a local workspace."""
208
+
209
+ model_config = ConfigDict(extra="forbid")
210
+
211
+ target: str = Field(min_length=1, max_length=1024, description="Local repository directory path.")
212
+ limits: ScanLimits = Field(default_factory=ScanLimits)
213
+ live_limits: LiveResourceLimits = Field(default_factory=LiveResourceLimits)
214
+ force_polling: bool = Field(default=False, description="Force pure-Python polling observer fallback.")
215
+ use_cache: bool = Field(default=True, description="Use v0.8.0 persistent SQLite WAL cache.")
216
+ persist_history: bool = Field(default=True, description="Persist bounded live timeline locally.")
217
+
218
+
219
+ class FilesystemEvent(BaseModel):
220
+ """Normalized, boundary-verified filesystem event."""
221
+
222
+ kind: NormalizedEventKind
223
+ rel_path: str = Field(default="", description="Normalized POSIX path relative to canonical repo root.")
224
+ dest_rel_path: str | None = Field(default=None, description="Destination POSIX path for MOVED events.")
225
+ is_directory: bool = False
226
+ is_config: bool = False
227
+ is_git_metadata: bool = False
228
+ observed_at_monotonic: float = Field(default=0.0)
229
+ detail: str | None = None
230
+
231
+
232
+ class CoalescedChangeBatch(BaseModel):
233
+ """Coalesced batch of normalized filesystem events ready for scheduling."""
234
+
235
+ batch_id: str
236
+ change_generation: int
237
+ raw_event_count: int
238
+ coalesced_paths: list[str] = Field(default_factory=list)
239
+ created_paths: list[str] = Field(default_factory=list)
240
+ modified_paths: list[str] = Field(default_factory=list)
241
+ deleted_paths: list[str] = Field(default_factory=list)
242
+ moved_paths: dict[str, str] = Field(default_factory=dict)
243
+ config_changed: bool = False
244
+ git_metadata_changed: bool = False
245
+ requires_reconciliation: bool = False
246
+ overflow_detected: bool = False
247
+ first_event_monotonic: float = 0.0
248
+ flushed_at_monotonic: float = 0.0
249
+ reason: str = "debounce"
250
+
251
+
252
+ class SymbolDeltaItem(BaseModel):
253
+ """Statically detected symbol addition, removal, or signature/kind change."""
254
+
255
+ file_id: str
256
+ symbol_name: str
257
+ kind: str
258
+ change_type: str # "added" | "removed" | "changed"
259
+ line_before: int | None = None
260
+ line_after: int | None = None
261
+
262
+
263
+ class EdgeChangeItem(BaseModel):
264
+ """Typed dependency edge change between verified snapshots."""
265
+
266
+ source: str
267
+ target: str
268
+ change_type: str # "added" | "removed" | "changed"
269
+ import_names_before: list[str] = Field(default_factory=list)
270
+ import_names_after: list[str] = Field(default_factory=list)
271
+ in_cycle: bool = False
272
+
273
+
274
+ class RenamedModuleDelta(BaseModel):
275
+ """Module rename detection with explicit confidence disclosure."""
276
+
277
+ old_path: str
278
+ new_path: str
279
+ confidence: float = Field(ge=0.0, le=1.0)
280
+ status: str # "verified" | "candidate"
281
+ reason: str
282
+
283
+
284
+ class CycleDeltaSummary(BaseModel):
285
+ id: str
286
+ nodes: list[str]
287
+ length: int
288
+ severity: SeverityLevel
289
+ description: str
290
+
291
+
292
+ class CouplingHotspotDelta(BaseModel):
293
+ file_id: str
294
+ fan_in_before: int
295
+ fan_in_after: int
296
+ fan_in_delta: int
297
+ fan_out_before: int
298
+ fan_out_after: int
299
+ fan_out_delta: int
300
+ instability_before: float
301
+ instability_after: float
302
+ instability_delta: float
303
+ is_new_hotspot: bool = False
304
+
305
+
306
+ class ContractDeltaItem(BaseModel):
307
+ rule_id: str
308
+ rule_title: str
309
+ severity: str
310
+ source_file: str
311
+ target_file: str
312
+ line: int
313
+ message: str
314
+
315
+
316
+ class LiveArchitectureDelta(BaseModel):
317
+ """Typed architectural delta between two verified working-tree snapshots."""
318
+
319
+ delta_id: str
320
+ before_snapshot_identity: str | None = None
321
+ after_snapshot_identity: str
322
+ computed_at: datetime = Field(default_factory=lambda: datetime.now(UTC))
323
+ has_architectural_changes: bool = False
324
+ confidence: str = "high" # "high" | "medium" | "low"
325
+ completeness: str = "complete" # "complete" | "partial" | "truncated"
326
+ caveats: list[str] = Field(default_factory=list)
327
+
328
+ added_modules: list[str] = Field(default_factory=list)
329
+ removed_modules: list[str] = Field(default_factory=list)
330
+ renamed_modules: list[RenamedModuleDelta] = Field(default_factory=list)
331
+
332
+ added_edges: list[EdgeChangeItem] = Field(default_factory=list)
333
+ removed_edges: list[EdgeChangeItem] = Field(default_factory=list)
334
+ changed_edges: list[EdgeChangeItem] = Field(default_factory=list)
335
+
336
+ new_cycles: list[CycleDeltaSummary] = Field(default_factory=list)
337
+ resolved_cycles: list[CycleDeltaSummary] = Field(default_factory=list)
338
+ persisting_cycles_count: int = 0
339
+
340
+ new_contract_violations: list[ContractDeltaItem] = Field(default_factory=list)
341
+ resolved_contract_violations: list[ContractDeltaItem] = Field(default_factory=list)
342
+
343
+ coupling_deltas: list[CouplingHotspotDelta] = Field(default_factory=list)
344
+ new_high_coupling_hotspots: list[str] = Field(default_factory=list)
345
+
346
+ symbol_changes: list[SymbolDeltaItem] = Field(default_factory=list)
347
+ public_interface_changes: list[SymbolDeltaItem] = Field(default_factory=list)
348
+
349
+ health_score_before: float | None = None
350
+ health_score_after: float | None = None
351
+ health_score_delta: float | None = None
352
+
353
+ ast_coverage_before_pct: float = 0.0
354
+ ast_coverage_after_pct: float = 0.0
355
+ coverage_delta_pct: float = 0.0
356
+ coverage_regressed: bool = False
357
+ coverage_recovered: bool = False
358
+ evidence_freshness_changed: bool = False
359
+ summary_text: str = ""
360
+
361
+
362
+ class LiveAlert(BaseModel):
363
+ """Deduplicated architectural or operational alert with honest lifecycle tracking."""
364
+
365
+ alert_id: str
366
+ category: AlertCategory
367
+ severity: SeverityLevel
368
+ confidence: str = "high" # "high" | "medium" | "low"
369
+ title: str
370
+ explanation: str
371
+ affected_modules: list[str] = Field(default_factory=list)
372
+ before_snapshot_identity: str | None = None
373
+ after_snapshot_identity: str | None = None
374
+ evidence_refs: list[str] = Field(default_factory=list)
375
+ first_observed_at: datetime = Field(default_factory=lambda: datetime.now(UTC))
376
+ last_observed_at: datetime = Field(default_factory=lambda: datetime.now(UTC))
377
+ resolved_at: datetime | None = None
378
+ acknowledged_at: datetime | None = None
379
+ status: AlertStatus = AlertStatus.ACTIVE
380
+ resolution_state: str = "unresolved" # "unresolved" | "resolved" | "unknown_coverage_drop"
381
+ is_underlying_issue_present: bool = True
382
+ occurrence_count: int = 1
383
+
384
+
385
+ class LiveHistoryEntry(BaseModel):
386
+ """Bounded working-tree live timeline entry (metadata + delta only, zero raw source)."""
387
+
388
+ entry_id: str
389
+ session_id: str
390
+ session_generation: int
391
+ event_kind: str # "initial_analysis" | "live_update" | "reconciliation" | "paused" | "resumed" | "degraded"
392
+ timestamp: datetime = Field(default_factory=lambda: datetime.now(UTC))
393
+ change_generation: int = 0
394
+ changed_file_count: int = 0
395
+ changed_paths_preview: list[str] = Field(default_factory=list)
396
+ analysis_duration_ms: int = 0
397
+ analysis_mode_executed: str | None = None
398
+ reused_files: int = 0
399
+ reparsed_files: int = 0
400
+ snapshot_identity: str | None = None
401
+ previous_snapshot_identity: str | None = None
402
+ snapshot_available: bool = True
403
+ freshness: FreshnessLevel = FreshnessLevel.VERIFIED_CURRENT
404
+ has_architectural_changes: bool = False
405
+ new_alert_ids: list[str] = Field(default_factory=list)
406
+ resolved_alert_ids: list[str] = Field(default_factory=list)
407
+ delta: LiveArchitectureDelta | None = None
408
+ summary: str = ""
409
+
410
+
411
+ class LiveHealthDiagnostics(BaseModel):
412
+ """Operational telemetry and queue/watcher health diagnostics."""
413
+
414
+ watcher_backend: WatcherBackend = WatcherBackend.NATIVE_WATCHFILES
415
+ watcher_alive: bool = False
416
+ watcher_restarts: int = 0
417
+ last_error: str | None = None
418
+ degraded_reason: str | None = None
419
+ pending_events_count: int = 0
420
+ queue_high_water_mark: int = 0
421
+ overflow_count: int = 0
422
+ total_raw_events: int = 0
423
+ total_batches_flushed: int = 0
424
+ total_analyses_completed: int = 0
425
+ total_analyses_superseded: int = 0
426
+ total_analyses_failed: int = 0
427
+ total_reconciliations: int = 0
428
+ active_subscribers: int = 0
429
+ slow_subscriber_resets: int = 0
430
+ last_analysis_duration_ms: int = 0
431
+ last_reused_files: int = 0
432
+ last_reparsed_files: int = 0
433
+ last_reconciliation_at: datetime | None = None
434
+ last_analysis_phase: str = "idle"
435
+ current_analysis_progress_pct: float = 0.0
436
+ history_entries_count: int = 0
437
+ history_estimated_bytes: int = 0
438
+
439
+
440
+ class LiveSessionInfo(BaseModel):
441
+ """Authoritative public state of a Live Architecture Engine session."""
442
+
443
+ session_id: str
444
+ workspace_identity: str
445
+ repo_name: str
446
+ canonical_root: str
447
+ session_generation: int = 1
448
+ state: LiveSessionState = LiveSessionState.STARTING
449
+ freshness: FreshnessLevel = FreshnessLevel.UNKNOWN
450
+ last_verified_snapshot_identity: str | None = None
451
+ last_analysis_id: str | None = None
452
+ quality_freshness: FreshnessLevel = FreshnessLevel.UNKNOWN
453
+ quality_findings_count: int = 0
454
+ quality_snapshot_identity: str | None = None
455
+ quality_ruleset_fingerprint: str | None = None
456
+ latest_observed_change_generation: int = 0
457
+ published_change_generation: int = 0
458
+ pending_changes_count: int = 0
459
+ pending_paths_preview: list[str] = Field(default_factory=list)
460
+ analysis_in_progress: bool = False
461
+ watcher_backend: WatcherBackend = WatcherBackend.NATIVE_WATCHFILES
462
+ health_status: str = "healthy" # "healthy" | "degraded" | "stopped" | "failed"
463
+ active_alerts_count: int = 0
464
+ limits: LiveResourceLimits = Field(default_factory=LiveResourceLimits)
465
+ diagnostics: LiveHealthDiagnostics = Field(default_factory=LiveHealthDiagnostics)
466
+ created_at: datetime = Field(default_factory=lambda: datetime.now(UTC))
467
+ last_active_at: datetime = Field(default_factory=lambda: datetime.now(UTC))
468
+ last_verified_at: datetime | None = None
469
+ owner_pid: int | None = None
470
+
471
+
472
+ class LiveEventEnvelope(BaseModel):
473
+ """Typed, schema-versioned SSE / CLI JSONL event envelope."""
474
+
475
+ schema_version: str = LIVE_EVENT_SCHEMA_VERSION
476
+ session_id: str
477
+ session_generation: int
478
+ event_id: str
479
+ sequence: int
480
+ event_type: LiveEventType
481
+ timestamp: datetime = Field(default_factory=lambda: datetime.now(UTC))
482
+ snapshot_identity: str | None = None
483
+ payload: dict[str, Any] = Field(default_factory=dict)
484
+
485
+
486
+ class LiveTimelineResponse(BaseModel):
487
+ """Response payload for GET /api/live/sessions/{session_id}/history."""
488
+
489
+ session_id: str
490
+ workspace_identity: str
491
+ total_entries: int
492
+ max_entries: int
493
+ entries: list[LiveHistoryEntry] = Field(default_factory=list)
494
+
495
+
496
+ class LiveAlertsResponse(BaseModel):
497
+ """Response payload for GET /api/live/sessions/{session_id}/alerts."""
498
+
499
+ session_id: str
500
+ workspace_identity: str
501
+ active_count: int
502
+ acknowledged_count: int
503
+ resolved_count: int
504
+ unknown_count: int
505
+ alerts: list[LiveAlert] = Field(default_factory=list)