empathy-framework 5.2.1__py3-none-any.whl → 5.4.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.
Files changed (480) hide show
  1. empathy_framework-5.4.0.dist-info/METADATA +47 -0
  2. empathy_framework-5.4.0.dist-info/RECORD +8 -0
  3. {empathy_framework-5.2.1.dist-info → empathy_framework-5.4.0.dist-info}/top_level.txt +0 -1
  4. empathy_healthcare_plugin/__init__.py +12 -11
  5. empathy_llm_toolkit/__init__.py +12 -26
  6. empathy_os/__init__.py +12 -356
  7. empathy_software_plugin/__init__.py +12 -11
  8. empathy_framework-5.2.1.dist-info/METADATA +0 -1002
  9. empathy_framework-5.2.1.dist-info/RECORD +0 -478
  10. empathy_framework-5.2.1.dist-info/entry_points.txt +0 -26
  11. empathy_framework-5.2.1.dist-info/licenses/LICENSE +0 -201
  12. empathy_framework-5.2.1.dist-info/licenses/LICENSE_CHANGE_ANNOUNCEMENT.md +0 -101
  13. empathy_healthcare_plugin/monitors/__init__.py +0 -9
  14. empathy_healthcare_plugin/monitors/clinical_protocol_monitor.py +0 -315
  15. empathy_healthcare_plugin/monitors/monitoring/__init__.py +0 -44
  16. empathy_healthcare_plugin/monitors/monitoring/protocol_checker.py +0 -300
  17. empathy_healthcare_plugin/monitors/monitoring/protocol_loader.py +0 -214
  18. empathy_healthcare_plugin/monitors/monitoring/sensor_parsers.py +0 -306
  19. empathy_healthcare_plugin/monitors/monitoring/trajectory_analyzer.py +0 -389
  20. empathy_healthcare_plugin/protocols/cardiac.json +0 -93
  21. empathy_healthcare_plugin/protocols/post_operative.json +0 -92
  22. empathy_healthcare_plugin/protocols/respiratory.json +0 -92
  23. empathy_healthcare_plugin/protocols/sepsis.json +0 -141
  24. empathy_llm_toolkit/README.md +0 -553
  25. empathy_llm_toolkit/agent_factory/__init__.py +0 -53
  26. empathy_llm_toolkit/agent_factory/adapters/__init__.py +0 -85
  27. empathy_llm_toolkit/agent_factory/adapters/autogen_adapter.py +0 -312
  28. empathy_llm_toolkit/agent_factory/adapters/crewai_adapter.py +0 -483
  29. empathy_llm_toolkit/agent_factory/adapters/haystack_adapter.py +0 -298
  30. empathy_llm_toolkit/agent_factory/adapters/langchain_adapter.py +0 -362
  31. empathy_llm_toolkit/agent_factory/adapters/langgraph_adapter.py +0 -333
  32. empathy_llm_toolkit/agent_factory/adapters/native.py +0 -228
  33. empathy_llm_toolkit/agent_factory/adapters/wizard_adapter.py +0 -423
  34. empathy_llm_toolkit/agent_factory/base.py +0 -305
  35. empathy_llm_toolkit/agent_factory/crews/__init__.py +0 -67
  36. empathy_llm_toolkit/agent_factory/crews/code_review.py +0 -1113
  37. empathy_llm_toolkit/agent_factory/crews/health_check.py +0 -1262
  38. empathy_llm_toolkit/agent_factory/crews/refactoring.py +0 -1128
  39. empathy_llm_toolkit/agent_factory/crews/security_audit.py +0 -1018
  40. empathy_llm_toolkit/agent_factory/decorators.py +0 -287
  41. empathy_llm_toolkit/agent_factory/factory.py +0 -558
  42. empathy_llm_toolkit/agent_factory/framework.py +0 -193
  43. empathy_llm_toolkit/agent_factory/memory_integration.py +0 -328
  44. empathy_llm_toolkit/agent_factory/resilient.py +0 -320
  45. empathy_llm_toolkit/agents_md/__init__.py +0 -22
  46. empathy_llm_toolkit/agents_md/loader.py +0 -218
  47. empathy_llm_toolkit/agents_md/parser.py +0 -271
  48. empathy_llm_toolkit/agents_md/registry.py +0 -307
  49. empathy_llm_toolkit/claude_memory.py +0 -466
  50. empathy_llm_toolkit/cli/__init__.py +0 -8
  51. empathy_llm_toolkit/cli/sync_claude.py +0 -487
  52. empathy_llm_toolkit/code_health.py +0 -1313
  53. empathy_llm_toolkit/commands/__init__.py +0 -51
  54. empathy_llm_toolkit/commands/context.py +0 -375
  55. empathy_llm_toolkit/commands/loader.py +0 -301
  56. empathy_llm_toolkit/commands/models.py +0 -231
  57. empathy_llm_toolkit/commands/parser.py +0 -371
  58. empathy_llm_toolkit/commands/registry.py +0 -429
  59. empathy_llm_toolkit/config/__init__.py +0 -29
  60. empathy_llm_toolkit/config/unified.py +0 -291
  61. empathy_llm_toolkit/context/__init__.py +0 -22
  62. empathy_llm_toolkit/context/compaction.py +0 -455
  63. empathy_llm_toolkit/context/manager.py +0 -434
  64. empathy_llm_toolkit/contextual_patterns.py +0 -361
  65. empathy_llm_toolkit/core.py +0 -907
  66. empathy_llm_toolkit/git_pattern_extractor.py +0 -435
  67. empathy_llm_toolkit/hooks/__init__.py +0 -24
  68. empathy_llm_toolkit/hooks/config.py +0 -306
  69. empathy_llm_toolkit/hooks/executor.py +0 -289
  70. empathy_llm_toolkit/hooks/registry.py +0 -302
  71. empathy_llm_toolkit/hooks/scripts/__init__.py +0 -39
  72. empathy_llm_toolkit/hooks/scripts/evaluate_session.py +0 -201
  73. empathy_llm_toolkit/hooks/scripts/first_time_init.py +0 -285
  74. empathy_llm_toolkit/hooks/scripts/pre_compact.py +0 -207
  75. empathy_llm_toolkit/hooks/scripts/session_end.py +0 -183
  76. empathy_llm_toolkit/hooks/scripts/session_start.py +0 -163
  77. empathy_llm_toolkit/hooks/scripts/suggest_compact.py +0 -225
  78. empathy_llm_toolkit/learning/__init__.py +0 -30
  79. empathy_llm_toolkit/learning/evaluator.py +0 -438
  80. empathy_llm_toolkit/learning/extractor.py +0 -514
  81. empathy_llm_toolkit/learning/storage.py +0 -560
  82. empathy_llm_toolkit/levels.py +0 -227
  83. empathy_llm_toolkit/pattern_confidence.py +0 -414
  84. empathy_llm_toolkit/pattern_resolver.py +0 -272
  85. empathy_llm_toolkit/pattern_summary.py +0 -350
  86. empathy_llm_toolkit/providers.py +0 -967
  87. empathy_llm_toolkit/routing/__init__.py +0 -32
  88. empathy_llm_toolkit/routing/model_router.py +0 -362
  89. empathy_llm_toolkit/security/IMPLEMENTATION_SUMMARY.md +0 -413
  90. empathy_llm_toolkit/security/PHASE2_COMPLETE.md +0 -384
  91. empathy_llm_toolkit/security/PHASE2_SECRETS_DETECTOR_COMPLETE.md +0 -271
  92. empathy_llm_toolkit/security/QUICK_REFERENCE.md +0 -316
  93. empathy_llm_toolkit/security/README.md +0 -262
  94. empathy_llm_toolkit/security/__init__.py +0 -62
  95. empathy_llm_toolkit/security/audit_logger.py +0 -929
  96. empathy_llm_toolkit/security/audit_logger_example.py +0 -152
  97. empathy_llm_toolkit/security/pii_scrubber.py +0 -640
  98. empathy_llm_toolkit/security/secrets_detector.py +0 -678
  99. empathy_llm_toolkit/security/secrets_detector_example.py +0 -304
  100. empathy_llm_toolkit/security/secure_memdocs.py +0 -1192
  101. empathy_llm_toolkit/security/secure_memdocs_example.py +0 -278
  102. empathy_llm_toolkit/session_status.py +0 -745
  103. empathy_llm_toolkit/state.py +0 -246
  104. empathy_llm_toolkit/utils/__init__.py +0 -5
  105. empathy_llm_toolkit/utils/tokens.py +0 -349
  106. empathy_os/adaptive/__init__.py +0 -13
  107. empathy_os/adaptive/task_complexity.py +0 -127
  108. empathy_os/agent_monitoring.py +0 -414
  109. empathy_os/cache/__init__.py +0 -117
  110. empathy_os/cache/base.py +0 -166
  111. empathy_os/cache/dependency_manager.py +0 -256
  112. empathy_os/cache/hash_only.py +0 -251
  113. empathy_os/cache/hybrid.py +0 -453
  114. empathy_os/cache/storage.py +0 -285
  115. empathy_os/cache_monitor.py +0 -356
  116. empathy_os/cache_stats.py +0 -298
  117. empathy_os/cli/__init__.py +0 -152
  118. empathy_os/cli/__main__.py +0 -12
  119. empathy_os/cli/commands/__init__.py +0 -1
  120. empathy_os/cli/commands/batch.py +0 -256
  121. empathy_os/cli/commands/cache.py +0 -248
  122. empathy_os/cli/commands/help.py +0 -331
  123. empathy_os/cli/commands/info.py +0 -140
  124. empathy_os/cli/commands/inspect.py +0 -436
  125. empathy_os/cli/commands/inspection.py +0 -57
  126. empathy_os/cli/commands/memory.py +0 -48
  127. empathy_os/cli/commands/metrics.py +0 -92
  128. empathy_os/cli/commands/orchestrate.py +0 -184
  129. empathy_os/cli/commands/patterns.py +0 -207
  130. empathy_os/cli/commands/profiling.py +0 -198
  131. empathy_os/cli/commands/provider.py +0 -98
  132. empathy_os/cli/commands/routing.py +0 -285
  133. empathy_os/cli/commands/setup.py +0 -96
  134. empathy_os/cli/commands/status.py +0 -235
  135. empathy_os/cli/commands/sync.py +0 -166
  136. empathy_os/cli/commands/tier.py +0 -121
  137. empathy_os/cli/commands/utilities.py +0 -114
  138. empathy_os/cli/commands/workflow.py +0 -575
  139. empathy_os/cli/core.py +0 -32
  140. empathy_os/cli/parsers/__init__.py +0 -68
  141. empathy_os/cli/parsers/batch.py +0 -118
  142. empathy_os/cli/parsers/cache 2.py +0 -65
  143. empathy_os/cli/parsers/cache.py +0 -65
  144. empathy_os/cli/parsers/help.py +0 -41
  145. empathy_os/cli/parsers/info.py +0 -26
  146. empathy_os/cli/parsers/inspect.py +0 -66
  147. empathy_os/cli/parsers/metrics.py +0 -42
  148. empathy_os/cli/parsers/orchestrate.py +0 -61
  149. empathy_os/cli/parsers/patterns.py +0 -54
  150. empathy_os/cli/parsers/provider.py +0 -40
  151. empathy_os/cli/parsers/routing.py +0 -110
  152. empathy_os/cli/parsers/setup.py +0 -42
  153. empathy_os/cli/parsers/status.py +0 -47
  154. empathy_os/cli/parsers/sync.py +0 -31
  155. empathy_os/cli/parsers/tier.py +0 -33
  156. empathy_os/cli/parsers/workflow.py +0 -77
  157. empathy_os/cli/utils/__init__.py +0 -1
  158. empathy_os/cli/utils/data.py +0 -242
  159. empathy_os/cli/utils/helpers.py +0 -68
  160. empathy_os/cli_legacy.py +0 -3957
  161. empathy_os/cli_minimal.py +0 -1159
  162. empathy_os/cli_router 2.py +0 -416
  163. empathy_os/cli_router.py +0 -437
  164. empathy_os/cli_unified.py +0 -814
  165. empathy_os/config/__init__.py +0 -66
  166. empathy_os/config/xml_config.py +0 -286
  167. empathy_os/config.py +0 -532
  168. empathy_os/coordination.py +0 -870
  169. empathy_os/core.py +0 -1511
  170. empathy_os/core_modules/__init__.py +0 -15
  171. empathy_os/cost_tracker.py +0 -626
  172. empathy_os/dashboard/__init__.py +0 -41
  173. empathy_os/dashboard/app 2.py +0 -512
  174. empathy_os/dashboard/app.py +0 -512
  175. empathy_os/dashboard/simple_server 2.py +0 -403
  176. empathy_os/dashboard/simple_server.py +0 -403
  177. empathy_os/dashboard/standalone_server 2.py +0 -536
  178. empathy_os/dashboard/standalone_server.py +0 -547
  179. empathy_os/discovery.py +0 -306
  180. empathy_os/emergence.py +0 -306
  181. empathy_os/exceptions.py +0 -123
  182. empathy_os/feedback_loops.py +0 -373
  183. empathy_os/hot_reload/README.md +0 -473
  184. empathy_os/hot_reload/__init__.py +0 -62
  185. empathy_os/hot_reload/config.py +0 -83
  186. empathy_os/hot_reload/integration.py +0 -229
  187. empathy_os/hot_reload/reloader.py +0 -298
  188. empathy_os/hot_reload/watcher.py +0 -183
  189. empathy_os/hot_reload/websocket.py +0 -177
  190. empathy_os/levels.py +0 -577
  191. empathy_os/leverage_points.py +0 -441
  192. empathy_os/logging_config.py +0 -261
  193. empathy_os/mcp/__init__.py +0 -10
  194. empathy_os/mcp/server.py +0 -506
  195. empathy_os/memory/__init__.py +0 -237
  196. empathy_os/memory/claude_memory.py +0 -469
  197. empathy_os/memory/config.py +0 -224
  198. empathy_os/memory/control_panel.py +0 -1290
  199. empathy_os/memory/control_panel_support.py +0 -145
  200. empathy_os/memory/cross_session.py +0 -845
  201. empathy_os/memory/edges.py +0 -179
  202. empathy_os/memory/encryption.py +0 -159
  203. empathy_os/memory/file_session.py +0 -770
  204. empathy_os/memory/graph.py +0 -570
  205. empathy_os/memory/long_term.py +0 -913
  206. empathy_os/memory/long_term_types.py +0 -99
  207. empathy_os/memory/mixins/__init__.py +0 -25
  208. empathy_os/memory/mixins/backend_init_mixin.py +0 -244
  209. empathy_os/memory/mixins/capabilities_mixin.py +0 -199
  210. empathy_os/memory/mixins/handoff_mixin.py +0 -208
  211. empathy_os/memory/mixins/lifecycle_mixin.py +0 -49
  212. empathy_os/memory/mixins/long_term_mixin.py +0 -352
  213. empathy_os/memory/mixins/promotion_mixin.py +0 -109
  214. empathy_os/memory/mixins/short_term_mixin.py +0 -182
  215. empathy_os/memory/nodes.py +0 -179
  216. empathy_os/memory/redis_bootstrap.py +0 -540
  217. empathy_os/memory/security/__init__.py +0 -31
  218. empathy_os/memory/security/audit_logger.py +0 -932
  219. empathy_os/memory/security/pii_scrubber.py +0 -640
  220. empathy_os/memory/security/secrets_detector.py +0 -678
  221. empathy_os/memory/short_term.py +0 -2150
  222. empathy_os/memory/simple_storage.py +0 -302
  223. empathy_os/memory/storage/__init__.py +0 -15
  224. empathy_os/memory/storage_backend.py +0 -167
  225. empathy_os/memory/summary_index.py +0 -583
  226. empathy_os/memory/types.py +0 -441
  227. empathy_os/memory/unified.py +0 -182
  228. empathy_os/meta_workflows/__init__.py +0 -74
  229. empathy_os/meta_workflows/agent_creator.py +0 -248
  230. empathy_os/meta_workflows/builtin_templates.py +0 -567
  231. empathy_os/meta_workflows/cli_commands/__init__.py +0 -56
  232. empathy_os/meta_workflows/cli_commands/agent_commands.py +0 -321
  233. empathy_os/meta_workflows/cli_commands/analytics_commands.py +0 -442
  234. empathy_os/meta_workflows/cli_commands/config_commands.py +0 -232
  235. empathy_os/meta_workflows/cli_commands/memory_commands.py +0 -182
  236. empathy_os/meta_workflows/cli_commands/template_commands.py +0 -354
  237. empathy_os/meta_workflows/cli_commands/workflow_commands.py +0 -382
  238. empathy_os/meta_workflows/cli_meta_workflows.py +0 -59
  239. empathy_os/meta_workflows/form_engine.py +0 -292
  240. empathy_os/meta_workflows/intent_detector.py +0 -409
  241. empathy_os/meta_workflows/models.py +0 -569
  242. empathy_os/meta_workflows/pattern_learner.py +0 -738
  243. empathy_os/meta_workflows/plan_generator.py +0 -384
  244. empathy_os/meta_workflows/session_context.py +0 -397
  245. empathy_os/meta_workflows/template_registry.py +0 -229
  246. empathy_os/meta_workflows/workflow.py +0 -984
  247. empathy_os/metrics/__init__.py +0 -12
  248. empathy_os/metrics/collector.py +0 -31
  249. empathy_os/metrics/prompt_metrics.py +0 -194
  250. empathy_os/models/__init__.py +0 -172
  251. empathy_os/models/__main__.py +0 -13
  252. empathy_os/models/adaptive_routing 2.py +0 -437
  253. empathy_os/models/adaptive_routing.py +0 -437
  254. empathy_os/models/auth_cli.py +0 -444
  255. empathy_os/models/auth_strategy.py +0 -450
  256. empathy_os/models/cli.py +0 -655
  257. empathy_os/models/empathy_executor.py +0 -354
  258. empathy_os/models/executor.py +0 -257
  259. empathy_os/models/fallback.py +0 -762
  260. empathy_os/models/provider_config.py +0 -282
  261. empathy_os/models/registry.py +0 -472
  262. empathy_os/models/tasks.py +0 -359
  263. empathy_os/models/telemetry/__init__.py +0 -71
  264. empathy_os/models/telemetry/analytics.py +0 -594
  265. empathy_os/models/telemetry/backend.py +0 -196
  266. empathy_os/models/telemetry/data_models.py +0 -431
  267. empathy_os/models/telemetry/storage.py +0 -489
  268. empathy_os/models/token_estimator.py +0 -420
  269. empathy_os/models/validation.py +0 -280
  270. empathy_os/monitoring/__init__.py +0 -52
  271. empathy_os/monitoring/alerts.py +0 -946
  272. empathy_os/monitoring/alerts_cli.py +0 -448
  273. empathy_os/monitoring/multi_backend.py +0 -271
  274. empathy_os/monitoring/otel_backend.py +0 -362
  275. empathy_os/optimization/__init__.py +0 -19
  276. empathy_os/optimization/context_optimizer.py +0 -272
  277. empathy_os/orchestration/__init__.py +0 -67
  278. empathy_os/orchestration/agent_templates.py +0 -707
  279. empathy_os/orchestration/config_store.py +0 -499
  280. empathy_os/orchestration/execution_strategies.py +0 -2111
  281. empathy_os/orchestration/meta_orchestrator.py +0 -1168
  282. empathy_os/orchestration/pattern_learner.py +0 -696
  283. empathy_os/orchestration/real_tools.py +0 -931
  284. empathy_os/pattern_cache.py +0 -187
  285. empathy_os/pattern_library.py +0 -542
  286. empathy_os/patterns/debugging/all_patterns.json +0 -81
  287. empathy_os/patterns/debugging/workflow_20260107_1770825e.json +0 -77
  288. empathy_os/patterns/refactoring_memory.json +0 -89
  289. empathy_os/persistence.py +0 -564
  290. empathy_os/platform_utils.py +0 -265
  291. empathy_os/plugins/__init__.py +0 -28
  292. empathy_os/plugins/base.py +0 -361
  293. empathy_os/plugins/registry.py +0 -268
  294. empathy_os/project_index/__init__.py +0 -32
  295. empathy_os/project_index/cli.py +0 -335
  296. empathy_os/project_index/index.py +0 -667
  297. empathy_os/project_index/models.py +0 -504
  298. empathy_os/project_index/reports.py +0 -474
  299. empathy_os/project_index/scanner.py +0 -777
  300. empathy_os/project_index/scanner_parallel 2.py +0 -291
  301. empathy_os/project_index/scanner_parallel.py +0 -291
  302. empathy_os/prompts/__init__.py +0 -61
  303. empathy_os/prompts/config.py +0 -77
  304. empathy_os/prompts/context.py +0 -177
  305. empathy_os/prompts/parser.py +0 -285
  306. empathy_os/prompts/registry.py +0 -313
  307. empathy_os/prompts/templates.py +0 -208
  308. empathy_os/redis_config.py +0 -302
  309. empathy_os/redis_memory.py +0 -799
  310. empathy_os/resilience/__init__.py +0 -56
  311. empathy_os/resilience/circuit_breaker.py +0 -256
  312. empathy_os/resilience/fallback.py +0 -179
  313. empathy_os/resilience/health.py +0 -300
  314. empathy_os/resilience/retry.py +0 -209
  315. empathy_os/resilience/timeout.py +0 -135
  316. empathy_os/routing/__init__.py +0 -43
  317. empathy_os/routing/chain_executor.py +0 -433
  318. empathy_os/routing/classifier.py +0 -217
  319. empathy_os/routing/smart_router.py +0 -234
  320. empathy_os/routing/workflow_registry.py +0 -343
  321. empathy_os/scaffolding/README.md +0 -589
  322. empathy_os/scaffolding/__init__.py +0 -35
  323. empathy_os/scaffolding/__main__.py +0 -14
  324. empathy_os/scaffolding/cli.py +0 -240
  325. empathy_os/socratic/__init__.py +0 -256
  326. empathy_os/socratic/ab_testing.py +0 -958
  327. empathy_os/socratic/blueprint.py +0 -533
  328. empathy_os/socratic/cli.py +0 -703
  329. empathy_os/socratic/collaboration.py +0 -1114
  330. empathy_os/socratic/domain_templates.py +0 -924
  331. empathy_os/socratic/embeddings.py +0 -738
  332. empathy_os/socratic/engine.py +0 -794
  333. empathy_os/socratic/explainer.py +0 -682
  334. empathy_os/socratic/feedback.py +0 -772
  335. empathy_os/socratic/forms.py +0 -629
  336. empathy_os/socratic/generator.py +0 -732
  337. empathy_os/socratic/llm_analyzer.py +0 -637
  338. empathy_os/socratic/mcp_server.py +0 -702
  339. empathy_os/socratic/session.py +0 -312
  340. empathy_os/socratic/storage.py +0 -667
  341. empathy_os/socratic/success.py +0 -730
  342. empathy_os/socratic/visual_editor.py +0 -860
  343. empathy_os/socratic/web_ui.py +0 -958
  344. empathy_os/telemetry/__init__.py +0 -39
  345. empathy_os/telemetry/agent_coordination 2.py +0 -478
  346. empathy_os/telemetry/agent_coordination.py +0 -476
  347. empathy_os/telemetry/agent_tracking 2.py +0 -350
  348. empathy_os/telemetry/agent_tracking.py +0 -348
  349. empathy_os/telemetry/approval_gates 2.py +0 -563
  350. empathy_os/telemetry/approval_gates.py +0 -551
  351. empathy_os/telemetry/cli.py +0 -1231
  352. empathy_os/telemetry/commands/__init__.py +0 -14
  353. empathy_os/telemetry/commands/dashboard_commands.py +0 -696
  354. empathy_os/telemetry/event_streaming 2.py +0 -405
  355. empathy_os/telemetry/event_streaming.py +0 -405
  356. empathy_os/telemetry/feedback_loop 2.py +0 -557
  357. empathy_os/telemetry/feedback_loop.py +0 -554
  358. empathy_os/telemetry/usage_tracker.py +0 -591
  359. empathy_os/templates.py +0 -754
  360. empathy_os/test_generator/__init__.py +0 -38
  361. empathy_os/test_generator/__main__.py +0 -14
  362. empathy_os/test_generator/cli.py +0 -234
  363. empathy_os/test_generator/generator.py +0 -355
  364. empathy_os/test_generator/risk_analyzer.py +0 -216
  365. empathy_os/tier_recommender.py +0 -384
  366. empathy_os/tools.py +0 -183
  367. empathy_os/trust/__init__.py +0 -28
  368. empathy_os/trust/circuit_breaker.py +0 -579
  369. empathy_os/trust_building.py +0 -527
  370. empathy_os/validation/__init__.py +0 -19
  371. empathy_os/validation/xml_validator.py +0 -281
  372. empathy_os/vscode_bridge 2.py +0 -173
  373. empathy_os/vscode_bridge.py +0 -173
  374. empathy_os/workflow_commands.py +0 -780
  375. empathy_os/workflow_patterns/__init__.py +0 -33
  376. empathy_os/workflow_patterns/behavior.py +0 -249
  377. empathy_os/workflow_patterns/core.py +0 -76
  378. empathy_os/workflow_patterns/output.py +0 -99
  379. empathy_os/workflow_patterns/registry.py +0 -255
  380. empathy_os/workflow_patterns/structural.py +0 -288
  381. empathy_os/workflows/__init__.py +0 -539
  382. empathy_os/workflows/autonomous_test_gen.py +0 -1268
  383. empathy_os/workflows/base.py +0 -2667
  384. empathy_os/workflows/batch_processing.py +0 -342
  385. empathy_os/workflows/bug_predict.py +0 -1084
  386. empathy_os/workflows/builder.py +0 -273
  387. empathy_os/workflows/caching.py +0 -253
  388. empathy_os/workflows/code_review.py +0 -1048
  389. empathy_os/workflows/code_review_adapters.py +0 -312
  390. empathy_os/workflows/code_review_pipeline.py +0 -722
  391. empathy_os/workflows/config.py +0 -645
  392. empathy_os/workflows/dependency_check.py +0 -644
  393. empathy_os/workflows/document_gen/__init__.py +0 -25
  394. empathy_os/workflows/document_gen/config.py +0 -30
  395. empathy_os/workflows/document_gen/report_formatter.py +0 -162
  396. empathy_os/workflows/document_gen/workflow.py +0 -1426
  397. empathy_os/workflows/document_gen.py +0 -29
  398. empathy_os/workflows/document_manager.py +0 -216
  399. empathy_os/workflows/document_manager_README.md +0 -134
  400. empathy_os/workflows/documentation_orchestrator.py +0 -1205
  401. empathy_os/workflows/history.py +0 -510
  402. empathy_os/workflows/keyboard_shortcuts/__init__.py +0 -39
  403. empathy_os/workflows/keyboard_shortcuts/generators.py +0 -391
  404. empathy_os/workflows/keyboard_shortcuts/parsers.py +0 -416
  405. empathy_os/workflows/keyboard_shortcuts/prompts.py +0 -295
  406. empathy_os/workflows/keyboard_shortcuts/schema.py +0 -193
  407. empathy_os/workflows/keyboard_shortcuts/workflow.py +0 -509
  408. empathy_os/workflows/llm_base.py +0 -363
  409. empathy_os/workflows/manage_docs.py +0 -87
  410. empathy_os/workflows/manage_docs_README.md +0 -134
  411. empathy_os/workflows/manage_documentation.py +0 -821
  412. empathy_os/workflows/new_sample_workflow1.py +0 -149
  413. empathy_os/workflows/new_sample_workflow1_README.md +0 -150
  414. empathy_os/workflows/orchestrated_health_check.py +0 -849
  415. empathy_os/workflows/orchestrated_release_prep.py +0 -600
  416. empathy_os/workflows/output.py +0 -410
  417. empathy_os/workflows/perf_audit.py +0 -863
  418. empathy_os/workflows/pr_review.py +0 -762
  419. empathy_os/workflows/progress.py +0 -779
  420. empathy_os/workflows/progress_server.py +0 -322
  421. empathy_os/workflows/progressive/README 2.md +0 -454
  422. empathy_os/workflows/progressive/README.md +0 -454
  423. empathy_os/workflows/progressive/__init__ 2.py +0 -92
  424. empathy_os/workflows/progressive/__init__.py +0 -82
  425. empathy_os/workflows/progressive/cli 2.py +0 -242
  426. empathy_os/workflows/progressive/cli.py +0 -219
  427. empathy_os/workflows/progressive/core 2.py +0 -488
  428. empathy_os/workflows/progressive/core.py +0 -488
  429. empathy_os/workflows/progressive/orchestrator 2.py +0 -701
  430. empathy_os/workflows/progressive/orchestrator.py +0 -723
  431. empathy_os/workflows/progressive/reports 2.py +0 -528
  432. empathy_os/workflows/progressive/reports.py +0 -520
  433. empathy_os/workflows/progressive/telemetry 2.py +0 -280
  434. empathy_os/workflows/progressive/telemetry.py +0 -274
  435. empathy_os/workflows/progressive/test_gen 2.py +0 -514
  436. empathy_os/workflows/progressive/test_gen.py +0 -495
  437. empathy_os/workflows/progressive/workflow 2.py +0 -628
  438. empathy_os/workflows/progressive/workflow.py +0 -589
  439. empathy_os/workflows/refactor_plan.py +0 -694
  440. empathy_os/workflows/release_prep.py +0 -895
  441. empathy_os/workflows/release_prep_crew.py +0 -969
  442. empathy_os/workflows/research_synthesis.py +0 -404
  443. empathy_os/workflows/routing.py +0 -168
  444. empathy_os/workflows/secure_release.py +0 -593
  445. empathy_os/workflows/security_adapters.py +0 -297
  446. empathy_os/workflows/security_audit.py +0 -1329
  447. empathy_os/workflows/security_audit_phase3.py +0 -355
  448. empathy_os/workflows/seo_optimization.py +0 -633
  449. empathy_os/workflows/step_config.py +0 -234
  450. empathy_os/workflows/telemetry_mixin.py +0 -269
  451. empathy_os/workflows/test5.py +0 -125
  452. empathy_os/workflows/test5_README.md +0 -158
  453. empathy_os/workflows/test_coverage_boost_crew.py +0 -849
  454. empathy_os/workflows/test_gen/__init__.py +0 -52
  455. empathy_os/workflows/test_gen/ast_analyzer.py +0 -249
  456. empathy_os/workflows/test_gen/config.py +0 -88
  457. empathy_os/workflows/test_gen/data_models.py +0 -38
  458. empathy_os/workflows/test_gen/report_formatter.py +0 -289
  459. empathy_os/workflows/test_gen/test_templates.py +0 -381
  460. empathy_os/workflows/test_gen/workflow.py +0 -655
  461. empathy_os/workflows/test_gen.py +0 -54
  462. empathy_os/workflows/test_gen_behavioral.py +0 -477
  463. empathy_os/workflows/test_gen_parallel.py +0 -341
  464. empathy_os/workflows/test_lifecycle.py +0 -526
  465. empathy_os/workflows/test_maintenance.py +0 -627
  466. empathy_os/workflows/test_maintenance_cli.py +0 -590
  467. empathy_os/workflows/test_maintenance_crew.py +0 -840
  468. empathy_os/workflows/test_runner.py +0 -622
  469. empathy_os/workflows/tier_tracking.py +0 -531
  470. empathy_os/workflows/xml_enhanced_crew.py +0 -285
  471. empathy_software_plugin/SOFTWARE_PLUGIN_README.md +0 -57
  472. empathy_software_plugin/cli/__init__.py +0 -120
  473. empathy_software_plugin/cli/inspect.py +0 -362
  474. empathy_software_plugin/cli.py +0 -574
  475. empathy_software_plugin/plugin.py +0 -188
  476. workflow_scaffolding/__init__.py +0 -11
  477. workflow_scaffolding/__main__.py +0 -12
  478. workflow_scaffolding/cli.py +0 -206
  479. workflow_scaffolding/generator.py +0 -265
  480. {empathy_framework-5.2.1.dist-info → empathy_framework-5.4.0.dist-info}/WHEEL +0 -0
@@ -1,777 +0,0 @@
1
- """Project Scanner - Scans codebase to build file index.
2
-
3
- Analyzes source files, matches them to tests, calculates metrics.
4
-
5
- Copyright 2025 Smart AI Memory, LLC
6
- Licensed under Fair Source 0.9
7
- """
8
-
9
- import ast
10
- import fnmatch
11
- import hashlib
12
- import heapq
13
- import os
14
- import re
15
- from datetime import datetime
16
- from functools import lru_cache
17
- from pathlib import Path
18
- from typing import Any
19
-
20
- from .models import FileCategory, FileRecord, IndexConfig, ProjectSummary, TestRequirement
21
-
22
-
23
- class ProjectScanner:
24
- """Scans a project directory and builds file metadata.
25
-
26
- Used by ProjectIndex to populate and update the index.
27
- """
28
-
29
- # Optimization: Use frozensets for O(1) membership testing (vs O(n) with lists)
30
- # These are used on every file during categorization (thousands of files)
31
- CONFIG_SUFFIXES = frozenset({".yml", ".yaml", ".toml", ".ini", ".cfg", ".json"})
32
- DOC_SUFFIXES = frozenset({".md", ".rst", ".txt"})
33
- DOC_NAMES = frozenset({"README", "CHANGELOG", "LICENSE"})
34
- ASSET_SUFFIXES = frozenset({".css", ".scss", ".html", ".svg", ".png", ".jpg", ".gif"})
35
- SOURCE_SUFFIXES = frozenset({".py", ".js", ".ts", ".tsx", ".jsx", ".go", ".rs", ".java"})
36
-
37
- def __init__(self, project_root: str, config: IndexConfig | None = None):
38
- self.project_root = Path(project_root)
39
- self.config = config or IndexConfig()
40
- self._test_file_map: dict[str, str] = {} # source -> test mapping
41
- # Pre-compile glob patterns for O(1) matching (vs recompiling on every call)
42
- # This optimization reduces _matches_glob_pattern() time by ~70%
43
- self._compiled_patterns: dict[str, tuple[re.Pattern, str | None]] = {}
44
- self._compile_glob_patterns()
45
-
46
- def _compile_glob_patterns(self) -> None:
47
- """Pre-compile glob patterns for faster matching.
48
-
49
- Called once at init to avoid recompiling patterns on every file check.
50
- Profiling showed fnmatch.fnmatch() called 823,433 times - this optimization
51
- reduces that overhead by ~70% by using pre-compiled regex patterns.
52
- """
53
- all_patterns = list(self.config.exclude_patterns) + list(self.config.no_test_patterns)
54
-
55
- for pattern in all_patterns:
56
- if pattern in self._compiled_patterns:
57
- continue
58
-
59
- # Extract directory name for ** patterns
60
- dir_name = None
61
- if "**" in pattern:
62
- if pattern.startswith("**/") and pattern.endswith("/**"):
63
- dir_name = pattern[3:-3] # e.g., "**/node_modules/**" -> "node_modules"
64
- elif pattern.endswith("/**"):
65
- dir_name = pattern.replace("**/", "").replace("/**", "")
66
-
67
- # Compile simple pattern (without **) for fnmatch-style matching
68
- simple_pattern = pattern.replace("**/", "")
69
- try:
70
- regex_pattern = fnmatch.translate(simple_pattern)
71
- compiled = re.compile(regex_pattern)
72
- except re.error:
73
- # Fallback for invalid patterns
74
- compiled = re.compile(re.escape(simple_pattern))
75
-
76
- self._compiled_patterns[pattern] = (compiled, dir_name)
77
-
78
- @staticmethod
79
- @lru_cache(maxsize=1000)
80
- def _hash_file(file_path: str) -> str:
81
- """Cache file content hashes for invalidation.
82
-
83
- Args:
84
- file_path: Path to file as string (for hashability)
85
-
86
- Returns:
87
- SHA256 hash of file contents
88
-
89
- Note:
90
- Uses LRU cache with 1000 entries (~64KB memory).
91
- Hit rate expected: 80%+ for incremental scans.
92
- """
93
- try:
94
- return hashlib.sha256(Path(file_path).read_bytes()).hexdigest()
95
- except OSError:
96
- # Return timestamp-based hash if file unreadable
97
- return str(Path(file_path).stat().st_mtime)
98
-
99
- @staticmethod
100
- @lru_cache(maxsize=2000)
101
- def _parse_python_cached(file_path: str, file_hash: str) -> ast.Module | None:
102
- """Cache AST parsing results (expensive CPU operation).
103
-
104
- Args:
105
- file_path: Path to Python file
106
- file_hash: Hash of file contents (for cache invalidation)
107
-
108
- Returns:
109
- Parsed AST or None if parsing fails
110
-
111
- Note:
112
- Uses LRU cache with 2000 entries (~20MB memory).
113
- Hit rate expected: 90%+ for incremental operations.
114
- Cache invalidates automatically when file_hash changes.
115
- """
116
- try:
117
- content = Path(file_path).read_text(encoding="utf-8", errors="ignore")
118
- return ast.parse(content)
119
- except (SyntaxError, ValueError, OSError):
120
- return None
121
-
122
- def scan(self, analyze_dependencies: bool = True) -> tuple[list[FileRecord], ProjectSummary]:
123
- """Scan the entire project and return file records and summary.
124
-
125
- Args:
126
- analyze_dependencies: Whether to analyze import dependencies.
127
- Set to False to skip expensive dependency graph analysis (saves ~2s).
128
- Default: True for backwards compatibility.
129
-
130
- Returns:
131
- Tuple of (list of FileRecords, ProjectSummary)
132
-
133
- """
134
- records: list[FileRecord] = []
135
-
136
- # First pass: discover all files
137
- all_files = self._discover_files()
138
-
139
- # Build test file mapping
140
- self._build_test_mapping(all_files)
141
-
142
- # Second pass: analyze each file
143
- for file_path in all_files:
144
- record = self._analyze_file(file_path)
145
- if record:
146
- records.append(record)
147
-
148
- # Third pass: build dependency graph (optional - saves ~2s when skipped)
149
- if analyze_dependencies:
150
- self._analyze_dependencies(records)
151
-
152
- # Calculate impact scores (depends on dependency graph)
153
- self._calculate_impact_scores(records)
154
-
155
- # Determine attention needs
156
- self._determine_attention_needs(records)
157
-
158
- # Build summary
159
- summary = self._build_summary(records)
160
-
161
- return records, summary
162
-
163
- def _discover_files(self) -> list[Path]:
164
- """Discover all relevant files in the project."""
165
- files = []
166
-
167
- for root, dirs, filenames in os.walk(self.project_root):
168
- # Filter out excluded directories
169
- dirs[:] = [d for d in dirs if not self._is_excluded(Path(root) / d)]
170
-
171
- for filename in filenames:
172
- file_path = Path(root) / filename
173
- rel_path = file_path.relative_to(self.project_root)
174
-
175
- if not self._is_excluded(rel_path):
176
- files.append(file_path)
177
-
178
- return files
179
-
180
- def _matches_glob_pattern(self, path: Path, pattern: str) -> bool:
181
- """Check if a path matches a glob pattern (handles ** patterns).
182
-
183
- Uses pre-compiled regex patterns for performance. This method is called
184
- ~800K+ times during a full scan, so caching the compiled patterns
185
- provides significant speedup.
186
- """
187
- rel_str = str(path)
188
- path_parts = path.parts
189
-
190
- # Get pre-compiled pattern (or compile on-demand if not cached)
191
- if pattern not in self._compiled_patterns:
192
- # Lazily compile patterns not seen at init time
193
- dir_name = None
194
- if "**" in pattern:
195
- if pattern.startswith("**/") and pattern.endswith("/**"):
196
- dir_name = pattern[3:-3]
197
- elif pattern.endswith("/**"):
198
- dir_name = pattern.replace("**/", "").replace("/**", "")
199
-
200
- simple_pattern = pattern.replace("**/", "")
201
- try:
202
- regex_pattern = fnmatch.translate(simple_pattern)
203
- compiled = re.compile(regex_pattern)
204
- except re.error:
205
- compiled = re.compile(re.escape(simple_pattern))
206
- self._compiled_patterns[pattern] = (compiled, dir_name)
207
-
208
- compiled_regex, dir_name = self._compiled_patterns[pattern]
209
-
210
- # Handle ** glob patterns
211
- if "**" in pattern:
212
- # Check if the pattern matches the path or filename using compiled regex
213
- if compiled_regex.match(rel_str):
214
- return True
215
- if compiled_regex.match(path.name):
216
- return True
217
-
218
- # Check directory-based exclusions (fast path check)
219
- if dir_name and dir_name in path_parts:
220
- return True
221
- else:
222
- # Use compiled regex instead of fnmatch.fnmatch()
223
- if compiled_regex.match(rel_str):
224
- return True
225
- if compiled_regex.match(path.name):
226
- return True
227
-
228
- return False
229
-
230
- def _is_excluded(self, path: Path) -> bool:
231
- """Check if a path should be excluded."""
232
- for pattern in self.config.exclude_patterns:
233
- if self._matches_glob_pattern(path, pattern):
234
- return True
235
- return False
236
-
237
- def _build_test_mapping(self, files: list[Path]) -> None:
238
- """Build mapping from source files to their test files.
239
-
240
- Optimized to use O(1) dict lookups instead of O(n) linear search.
241
- Previous implementation was O(n*m), now O(n+m).
242
- """
243
- # Build index of non-test files by stem name for O(1) lookups
244
- # This replaces the inner loop that searched all files
245
- source_files_by_stem: dict[str, list[Path]] = {}
246
- for f in files:
247
- if not self._is_test_file(f):
248
- stem = f.stem
249
- if stem not in source_files_by_stem:
250
- source_files_by_stem[stem] = []
251
- source_files_by_stem[stem].append(f)
252
-
253
- # Now match test files to source files with O(1) lookups
254
- for f in files:
255
- if not self._is_test_file(f):
256
- continue
257
-
258
- test_name = f.stem # e.g., "test_core"
259
-
260
- # Common patterns: test_foo.py -> foo.py
261
- if test_name.startswith("test_"):
262
- source_name = test_name[5:] # Remove "test_" prefix
263
- elif test_name.endswith("_test"):
264
- source_name = test_name[:-5] # Remove "_test" suffix
265
- else:
266
- continue
267
-
268
- # O(1) lookup instead of O(n) linear search
269
- matching_sources = source_files_by_stem.get(source_name, [])
270
- if matching_sources:
271
- # Use first match (typically there's only one)
272
- source_file = matching_sources[0]
273
- rel_source = str(source_file.relative_to(self.project_root))
274
- rel_test = str(f.relative_to(self.project_root))
275
- self._test_file_map[rel_source] = rel_test
276
-
277
- def _is_test_file(self, path: Path) -> bool:
278
- """Check if a file is a test file."""
279
- name = path.stem
280
- return (
281
- name.startswith("test_")
282
- or name.endswith("_test")
283
- or "tests" in path.parts
284
- or path.parent.name == "test"
285
- )
286
-
287
- def _analyze_file(self, file_path: Path) -> FileRecord | None:
288
- """Analyze a single file and create its record."""
289
- rel_path = str(file_path.relative_to(self.project_root))
290
-
291
- # Determine category
292
- category = self._determine_category(file_path)
293
-
294
- # Determine language
295
- language = self._determine_language(file_path)
296
-
297
- # Get file stats
298
- try:
299
- stat = file_path.stat()
300
- last_modified = datetime.fromtimestamp(stat.st_mtime)
301
- except OSError:
302
- last_modified = None
303
-
304
- # Determine test requirement
305
- test_requirement = self._determine_test_requirement(file_path, category)
306
-
307
- # Find associated test file
308
- test_file_path = self._test_file_map.get(rel_path)
309
- tests_exist = test_file_path is not None
310
-
311
- # Get test file modification time
312
- tests_last_modified = None
313
- if test_file_path:
314
- test_full_path = self.project_root / test_file_path
315
- if test_full_path.exists():
316
- try:
317
- tests_last_modified = datetime.fromtimestamp(test_full_path.stat().st_mtime)
318
- except OSError:
319
- pass
320
-
321
- # Calculate staleness
322
- staleness_days = 0
323
- is_stale = False
324
- if last_modified and tests_last_modified:
325
- if last_modified > tests_last_modified:
326
- staleness_days = (last_modified - tests_last_modified).days
327
- is_stale = staleness_days >= self.config.staleness_threshold_days
328
-
329
- # Analyze code metrics (skip expensive AST analysis for test files)
330
- metrics = self._analyze_code_metrics(file_path, language, category)
331
-
332
- return FileRecord(
333
- path=rel_path,
334
- name=file_path.name,
335
- category=category,
336
- language=language,
337
- test_requirement=test_requirement,
338
- test_file_path=test_file_path,
339
- tests_exist=tests_exist,
340
- test_count=metrics.get("test_count", 0),
341
- coverage_percent=0.0, # Will be populated from coverage data
342
- last_modified=last_modified,
343
- tests_last_modified=tests_last_modified,
344
- last_indexed=datetime.now(),
345
- staleness_days=staleness_days,
346
- is_stale=is_stale,
347
- lines_of_code=metrics.get("lines_of_code", 0),
348
- lines_of_test=metrics.get("lines_of_test", 0),
349
- complexity_score=metrics.get("complexity", 0.0),
350
- has_docstrings=metrics.get("has_docstrings", False),
351
- has_type_hints=metrics.get("has_type_hints", False),
352
- lint_issues=0, # Will be populated from linter
353
- imports=metrics.get("imports", []),
354
- imported_by=[], # Populated in dependency analysis
355
- import_count=len(metrics.get("imports", [])),
356
- imported_by_count=0,
357
- impact_score=0.0, # Calculated later
358
- metadata={},
359
- needs_attention=False,
360
- attention_reasons=[],
361
- )
362
-
363
- def _determine_category(self, path: Path) -> FileCategory:
364
- """Determine the category of a file."""
365
- if self._is_test_file(path):
366
- return FileCategory.TEST
367
-
368
- suffix = path.suffix.lower()
369
-
370
- # Optimization: Use frozensets for O(1) lookup (called for every file)
371
- if suffix in self.CONFIG_SUFFIXES:
372
- return FileCategory.CONFIG
373
-
374
- if suffix in self.DOC_SUFFIXES or path.name in self.DOC_NAMES:
375
- return FileCategory.DOCS
376
-
377
- if suffix in self.ASSET_SUFFIXES:
378
- return FileCategory.ASSET
379
-
380
- if suffix in self.SOURCE_SUFFIXES:
381
- return FileCategory.SOURCE
382
-
383
- return FileCategory.UNKNOWN
384
-
385
- def _determine_language(self, path: Path) -> str:
386
- """Determine the programming language of a file."""
387
- suffix_map = {
388
- ".py": "python",
389
- ".js": "javascript",
390
- ".ts": "typescript",
391
- ".tsx": "typescript",
392
- ".jsx": "javascript",
393
- ".go": "go",
394
- ".rs": "rust",
395
- ".java": "java",
396
- ".rb": "ruby",
397
- ".php": "php",
398
- ".cs": "csharp",
399
- ".cpp": "cpp",
400
- ".c": "c",
401
- ".h": "c",
402
- ".hpp": "cpp",
403
- }
404
- return suffix_map.get(path.suffix.lower(), "")
405
-
406
- def _determine_test_requirement(self, path: Path, category: FileCategory) -> TestRequirement:
407
- """Determine if a file requires tests."""
408
- rel_path = path.relative_to(self.project_root)
409
-
410
- # Test files don't need tests
411
- if category == FileCategory.TEST:
412
- return TestRequirement.NOT_APPLICABLE
413
-
414
- # Config, docs, assets don't need tests
415
- if category in [FileCategory.CONFIG, FileCategory.DOCS, FileCategory.ASSET]:
416
- return TestRequirement.NOT_APPLICABLE
417
-
418
- # Check exclusion patterns using glob matching
419
- for pattern in self.config.no_test_patterns:
420
- if self._matches_glob_pattern(rel_path, pattern):
421
- return TestRequirement.NOT_APPLICABLE
422
-
423
- # __init__.py files usually don't need tests unless they have logic
424
- if path.name == "__init__.py":
425
- try:
426
- content = path.read_text(encoding="utf-8", errors="ignore")
427
- # If it's just imports/exports, no tests needed
428
- if len(content.strip().split("\n")) < 20:
429
- return TestRequirement.OPTIONAL
430
- except OSError:
431
- pass
432
-
433
- return TestRequirement.REQUIRED
434
-
435
- def _analyze_code_metrics(
436
- self, path: Path, language: str, category: FileCategory = FileCategory.SOURCE
437
- ) -> dict[str, Any]:
438
- """Analyze code metrics for a file with caching.
439
-
440
- Uses cached AST parsing for Python files to avoid re-parsing
441
- unchanged files during incremental scans.
442
-
443
- Optimization: Skips expensive AST analysis for test files since they
444
- don't need complexity scoring (saves ~30% of AST traversal time).
445
-
446
- Args:
447
- path: Path to file to analyze
448
- language: Programming language of the file
449
- category: File category (SOURCE, TEST, etc.)
450
- """
451
- metrics: dict[str, Any] = {
452
- "lines_of_code": 0,
453
- "lines_of_test": 0,
454
- "complexity": 0.0,
455
- "has_docstrings": False,
456
- "has_type_hints": False,
457
- "imports": [],
458
- "test_count": 0,
459
- }
460
-
461
- if language != "python":
462
- # For now, just count lines for non-Python
463
- try:
464
- content = path.read_text(encoding="utf-8", errors="ignore")
465
- metrics["lines_of_code"] = len(content.split("\n"))
466
- except OSError:
467
- pass
468
- return metrics
469
-
470
- try:
471
- content = path.read_text(encoding="utf-8", errors="ignore")
472
- lines = content.split("\n")
473
- # Use generator expression for memory efficiency (no intermediate list)
474
- metrics["lines_of_code"] = sum(
475
- 1 for line in lines if line.strip() and not line.strip().startswith("#")
476
- )
477
-
478
- # Optimization: Skip expensive AST analysis for test files
479
- # Test files don't need complexity scoring, docstring/type hint checks
480
- # This saves ~30% of AST traversal time (1+ seconds on large codebases)
481
- if category == FileCategory.TEST:
482
- # For test files, just count test functions with simple regex
483
- import re
484
-
485
- test_func_pattern = re.compile(r"^\s*def\s+test_\w+\(")
486
- metrics["test_count"] = sum(
487
- 1 for line in lines if test_func_pattern.match(line)
488
- )
489
- # Mark as having test functions (for test file records)
490
- if metrics["test_count"] > 0:
491
- metrics["lines_of_test"] = metrics["lines_of_code"]
492
- else:
493
- # Use cached AST parsing for source files only
494
- file_path_str = str(path)
495
- file_hash = self._hash_file(file_path_str)
496
- tree = self._parse_python_cached(file_path_str, file_hash)
497
-
498
- if tree:
499
- metrics.update(self._analyze_python_ast(tree))
500
-
501
- except OSError:
502
- pass
503
-
504
- return metrics
505
-
506
- def _analyze_python_ast(self, tree: ast.AST) -> dict[str, Any]:
507
- """Analyze Python AST for metrics.
508
-
509
- Optimized to use single-pass traversal with NodeVisitor instead of
510
- nested ast.walk() calls. Previous implementation was O(n²) due to
511
- walking each function's subtree separately. This version is O(n).
512
- """
513
-
514
- # Use inner class to maintain state during traversal
515
- class MetricsVisitor(ast.NodeVisitor):
516
- def __init__(self) -> None:
517
- self.result: dict[str, Any] = {
518
- "has_docstrings": False,
519
- "has_type_hints": False,
520
- "imports": [],
521
- "test_count": 0,
522
- "complexity": 0.0,
523
- }
524
- self.function_depth = 0 # Track if we're inside a function
525
-
526
- def visit_Module(self, node: ast.Module) -> None:
527
- if ast.get_docstring(node):
528
- self.result["has_docstrings"] = True
529
- self.generic_visit(node)
530
-
531
- def visit_ClassDef(self, node: ast.ClassDef) -> None:
532
- if ast.get_docstring(node):
533
- self.result["has_docstrings"] = True
534
- self.generic_visit(node)
535
-
536
- def visit_FunctionDef(self, node: ast.FunctionDef) -> None:
537
- self._handle_function(node)
538
-
539
- def visit_AsyncFunctionDef(self, node: ast.AsyncFunctionDef) -> None:
540
- self._handle_function(node)
541
-
542
- def _handle_function(self, node: ast.FunctionDef | ast.AsyncFunctionDef) -> None:
543
- # Check for docstrings
544
- if ast.get_docstring(node):
545
- self.result["has_docstrings"] = True
546
-
547
- # Check for type hints
548
- if node.returns or any(arg.annotation for arg in node.args.args):
549
- self.result["has_type_hints"] = True
550
-
551
- # Count test functions
552
- if node.name.startswith("test_"):
553
- self.result["test_count"] += 1
554
-
555
- # Enter function scope for complexity counting
556
- self.function_depth += 1
557
- self.generic_visit(node)
558
- self.function_depth -= 1
559
-
560
- def visit_If(self, node: ast.If) -> None:
561
- if self.function_depth > 0:
562
- self.result["complexity"] += 1.0
563
- self.generic_visit(node)
564
-
565
- def visit_For(self, node: ast.For) -> None:
566
- if self.function_depth > 0:
567
- self.result["complexity"] += 1.0
568
- self.generic_visit(node)
569
-
570
- def visit_While(self, node: ast.While) -> None:
571
- if self.function_depth > 0:
572
- self.result["complexity"] += 1.0
573
- self.generic_visit(node)
574
-
575
- def visit_Try(self, node: ast.Try) -> None:
576
- if self.function_depth > 0:
577
- self.result["complexity"] += 1.0
578
- self.generic_visit(node)
579
-
580
- def visit_ExceptHandler(self, node: ast.ExceptHandler) -> None:
581
- if self.function_depth > 0:
582
- self.result["complexity"] += 1.0
583
- self.generic_visit(node)
584
-
585
- def visit_Import(self, node: ast.Import) -> None:
586
- for alias in node.names:
587
- self.result["imports"].append(alias.name)
588
- self.generic_visit(node)
589
-
590
- def visit_ImportFrom(self, node: ast.ImportFrom) -> None:
591
- if node.module:
592
- self.result["imports"].append(node.module)
593
- self.generic_visit(node)
594
-
595
- visitor = MetricsVisitor()
596
- visitor.visit(tree)
597
- return visitor.result
598
-
599
- def _analyze_dependencies(self, records: list[FileRecord]) -> None:
600
- """Build dependency graph between files.
601
-
602
- Optimized from O(n³) to O(n*m) where n=records, m=avg imports per file.
603
- Uses dict lookups instead of nested loops for finding modules and records.
604
- """
605
- # Build record lookup by path for O(1) access (eliminates innermost loop)
606
- records_by_path: dict[str, FileRecord] = {r.path: r for r in records}
607
-
608
- # Build multiple module indexes for flexible matching
609
- # Key: module name or suffix -> Value: path
610
- module_to_path: dict[str, str] = {}
611
- module_suffix_to_path: dict[str, str] = {} # For "endswith" matching
612
-
613
- for record in records:
614
- if record.language == "python":
615
- # Convert path to module name: src/empathy_os/core.py -> src.empathy_os.core
616
- module_name = record.path.replace("/", ".").replace("\\", ".")
617
- if module_name.endswith(".py"):
618
- module_name = module_name[:-3]
619
-
620
- module_to_path[module_name] = record.path
621
-
622
- # Also index by module suffix parts for partial matching
623
- # e.g., "empathy_os.core" and "core" for "src.empathy_os.core"
624
- parts = module_name.split(".")
625
- for i in range(len(parts)):
626
- suffix = ".".join(parts[i:])
627
- if suffix not in module_suffix_to_path:
628
- module_suffix_to_path[suffix] = record.path
629
-
630
- # Track which records have been updated (for imported_by deduplication)
631
- imported_by_sets: dict[str, set[str]] = {r.path: set() for r in records}
632
-
633
- # Update imported_by relationships with O(1) lookups
634
- for record in records:
635
- for imp in record.imports:
636
- # Try exact match first
637
- target_path = module_to_path.get(imp)
638
-
639
- # Try suffix match if no exact match
640
- if not target_path:
641
- target_path = module_suffix_to_path.get(imp)
642
-
643
- # Try partial suffix matching as fallback
644
- if not target_path:
645
- # Check if import is a suffix of any module
646
- for suffix, path in module_suffix_to_path.items():
647
- if suffix.endswith(imp) or imp in suffix:
648
- target_path = path
649
- break
650
-
651
- if target_path and target_path in records_by_path:
652
- # Use set for O(1) deduplication check
653
- if record.path not in imported_by_sets[target_path]:
654
- imported_by_sets[target_path].add(record.path)
655
- target_record = records_by_path[target_path]
656
- target_record.imported_by.append(record.path)
657
- target_record.imported_by_count = len(target_record.imported_by)
658
-
659
- def _calculate_impact_scores(self, records: list[FileRecord]) -> None:
660
- """Calculate impact score for each file."""
661
- for record in records:
662
- # Impact = imported_by_count * 2 + complexity * 0.5 + lines_of_code * 0.01
663
- record.impact_score = (
664
- record.imported_by_count * 2.0
665
- + record.complexity_score * 0.5
666
- + record.lines_of_code * 0.01
667
- )
668
-
669
- def _determine_attention_needs(self, records: list[FileRecord]) -> None:
670
- """Determine which files need attention."""
671
- for record in records:
672
- reasons = []
673
-
674
- # Stale tests
675
- if record.is_stale:
676
- reasons.append(f"Tests are {record.staleness_days} days stale")
677
-
678
- # No tests but required
679
- if record.test_requirement == TestRequirement.REQUIRED and not record.tests_exist:
680
- reasons.append("Missing tests")
681
-
682
- # Low coverage (if we have coverage data)
683
- if (
684
- record.coverage_percent > 0
685
- and record.coverage_percent < self.config.low_coverage_threshold
686
- ):
687
- reasons.append(f"Low coverage ({record.coverage_percent:.1f}%)")
688
-
689
- # High impact but no tests
690
- if record.impact_score >= self.config.high_impact_threshold:
691
- if not record.tests_exist and record.test_requirement == TestRequirement.REQUIRED:
692
- reasons.append(f"High impact ({record.impact_score:.1f}) without tests")
693
-
694
- record.attention_reasons = reasons
695
- record.needs_attention = len(reasons) > 0
696
-
697
- def _build_summary(self, records: list[FileRecord]) -> ProjectSummary:
698
- """Build project summary from records."""
699
- summary = ProjectSummary()
700
-
701
- summary.total_files = len(records)
702
- summary.source_files = sum(1 for r in records if r.category == FileCategory.SOURCE)
703
- summary.test_files = sum(1 for r in records if r.category == FileCategory.TEST)
704
- summary.config_files = sum(1 for r in records if r.category == FileCategory.CONFIG)
705
- summary.doc_files = sum(1 for r in records if r.category == FileCategory.DOCS)
706
-
707
- # Testing health
708
- requiring_tests = [r for r in records if r.test_requirement == TestRequirement.REQUIRED]
709
- summary.files_requiring_tests = len(requiring_tests)
710
- summary.files_with_tests = sum(1 for r in requiring_tests if r.tests_exist)
711
- summary.files_without_tests = summary.files_requiring_tests - summary.files_with_tests
712
- summary.total_test_count = sum(
713
- r.test_count for r in records if r.category == FileCategory.TEST
714
- )
715
-
716
- # Coverage average
717
- covered = [r for r in records if r.coverage_percent > 0]
718
- if covered:
719
- summary.test_coverage_avg = sum(r.coverage_percent for r in covered) / len(covered)
720
-
721
- # Staleness
722
- stale = [r for r in records if r.is_stale]
723
- summary.stale_file_count = len(stale)
724
- if stale:
725
- summary.avg_staleness_days = sum(r.staleness_days for r in stale) / len(stale)
726
- top_stale = heapq.nlargest(5, stale, key=lambda r: r.staleness_days)
727
- summary.most_stale_files = [r.path for r in top_stale]
728
-
729
- # Code metrics
730
- source_records = [r for r in records if r.category == FileCategory.SOURCE]
731
- summary.total_lines_of_code = sum(r.lines_of_code for r in source_records)
732
- summary.total_lines_of_test = sum(
733
- r.lines_of_code for r in records if r.category == FileCategory.TEST
734
- )
735
- if summary.total_lines_of_code > 0:
736
- summary.test_to_code_ratio = summary.total_lines_of_test / summary.total_lines_of_code
737
- if source_records:
738
- summary.avg_complexity = sum(r.complexity_score for r in source_records) / len(
739
- source_records,
740
- )
741
-
742
- # Quality
743
- if source_records:
744
- summary.files_with_docstrings_pct = (
745
- sum(1 for r in source_records if r.has_docstrings) / len(source_records) * 100
746
- )
747
- summary.files_with_type_hints_pct = (
748
- sum(1 for r in source_records if r.has_type_hints) / len(source_records) * 100
749
- )
750
- summary.total_lint_issues = sum(r.lint_issues for r in records)
751
-
752
- # High impact files
753
- high_impact = heapq.nlargest(10, records, key=lambda r: r.impact_score)
754
- summary.high_impact_files = [
755
- r.path for r in high_impact if r.impact_score >= self.config.high_impact_threshold
756
- ]
757
-
758
- # Critical untested files (high impact + no tests)
759
- critical = [
760
- r
761
- for r in records
762
- if r.impact_score >= self.config.high_impact_threshold
763
- and not r.tests_exist
764
- and r.test_requirement == TestRequirement.REQUIRED
765
- ]
766
- summary.critical_untested_files = [
767
- r.path for r in heapq.nlargest(10, critical, key=lambda r: r.impact_score)
768
- ]
769
-
770
- # Attention needed
771
- needing_attention = [r for r in records if r.needs_attention]
772
- summary.files_needing_attention = len(needing_attention)
773
- summary.top_attention_files = [
774
- r.path for r in heapq.nlargest(10, needing_attention, key=lambda r: r.impact_score)
775
- ]
776
-
777
- return summary