Coverage for integrations / coding_agent / __init__.py: 100.0%
21 statements
« prev ^ index » next coverage.py v7.14.0, created at 2026-05-12 04:49 +0000
« prev ^ index » next coverage.py v7.14.0, created at 2026-05-12 04:49 +0000
1"""
2HevolveSocial - Distributed Coding Agent
4Orchestrates idle agents across the 3-tier hierarchy to collaboratively
5code in a target repository towards a common goal. Uses the existing
6CREATE/REUSE agent pipeline for all LLM work.
8ALSO drains the self_heal goal queue produced by error_advice +
9SelfHealingDispatcher — these are NOT optional collaborative work,
10they are the system's autonomous-fix loop for production failures.
11Per the 2026-05-04 audit (15 stale self_heal goals back to
122026-04-27, zero completed), the queue piles up indefinitely when
13the daemon isn't running.
15Enabled via HEVOLVE_CODING_AGENT_ENABLED (default: TRUE — flipped
162026-05-07 since the daemon is the consumer for self_heal goals
17that error_advice + #102 producers fill). Safety: the daemon's
18_tick() early-returns when there are no idle agent personas
19(IdleDetectionService.get_idle_agent_personas — the same canonical
20gate agent_daemon uses for local goal dispatch; previously
21get_idle_opted_in_agents, which silently returned [] on installs
22where no human had opted into distributed compute → daemon stalled
23with self_heal goals piling up. Live-evidence 2026-05-07: 42
24goals, 0 dispatched. Same root-cause + fix as agent_daemon's
252026-05-01 switch). Budget gate at line 110-117 blocks dispatches
26if platform isn't affordable. Server deployments that explicitly
27don't want the daemon set HEVOLVE_CODING_AGENT_ENABLED=false.
28"""
29import os
30import logging
32logger = logging.getLogger('hevolve_social')
34_coding_bp = None
37def get_coding_blueprint():
38 global _coding_bp
39 if _coding_bp is None:
40 from .api import coding_agent_bp as bp
41 _coding_bp = bp
42 return _coding_bp
45def init_coding_agent(app):
46 """Initialize the distributed coding agent module."""
47 if os.environ.get('HEVOLVE_CODING_AGENT_ENABLED', 'true').lower() != 'true':
48 logger.info("Distributed coding agent disabled (HEVOLVE_CODING_AGENT_ENABLED=false explicitly set)")
49 return
51 # Register API blueprint
52 try:
53 bp = get_coding_blueprint()
54 app.register_blueprint(bp)
55 logger.info("Distributed coding agent endpoints registered")
56 except Exception as e:
57 logger.warning(f"Coding agent blueprint registration failed: {e}")
58 return
60 # Start background daemon
61 try:
62 from .coding_daemon import coding_daemon
63 coding_daemon.start()
64 logger.info("Distributed coding agent daemon started")
65 except Exception as e:
66 logger.debug(f"Coding agent daemon start skipped: {e}")