codex-autorunner 1.1.0__py3-none-any.whl → 1.2.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 (134) hide show
  1. codex_autorunner/agents/opencode/client.py +113 -4
  2. codex_autorunner/agents/opencode/supervisor.py +4 -0
  3. codex_autorunner/agents/registry.py +17 -7
  4. codex_autorunner/bootstrap.py +219 -1
  5. codex_autorunner/core/__init__.py +17 -1
  6. codex_autorunner/core/about_car.py +124 -11
  7. codex_autorunner/core/app_server_threads.py +6 -0
  8. codex_autorunner/core/config.py +238 -3
  9. codex_autorunner/core/context_awareness.py +39 -0
  10. codex_autorunner/core/docs.py +0 -122
  11. codex_autorunner/core/filebox.py +265 -0
  12. codex_autorunner/core/flows/controller.py +71 -1
  13. codex_autorunner/core/flows/reconciler.py +4 -1
  14. codex_autorunner/core/flows/runtime.py +22 -0
  15. codex_autorunner/core/flows/store.py +61 -9
  16. codex_autorunner/core/flows/transition.py +23 -16
  17. codex_autorunner/core/flows/ux_helpers.py +18 -3
  18. codex_autorunner/core/flows/worker_process.py +32 -6
  19. codex_autorunner/core/hub.py +198 -41
  20. codex_autorunner/core/lifecycle_events.py +253 -0
  21. codex_autorunner/core/path_utils.py +2 -1
  22. codex_autorunner/core/pma_audit.py +224 -0
  23. codex_autorunner/core/pma_context.py +683 -0
  24. codex_autorunner/core/pma_dispatch_interceptor.py +284 -0
  25. codex_autorunner/core/pma_lifecycle.py +527 -0
  26. codex_autorunner/core/pma_queue.py +367 -0
  27. codex_autorunner/core/pma_safety.py +221 -0
  28. codex_autorunner/core/pma_state.py +115 -0
  29. codex_autorunner/core/ports/agent_backend.py +2 -5
  30. codex_autorunner/core/ports/run_event.py +1 -4
  31. codex_autorunner/core/prompt.py +0 -80
  32. codex_autorunner/core/prompts.py +56 -172
  33. codex_autorunner/core/redaction.py +0 -4
  34. codex_autorunner/core/review_context.py +11 -9
  35. codex_autorunner/core/runner_controller.py +35 -33
  36. codex_autorunner/core/runner_state.py +147 -0
  37. codex_autorunner/core/runtime.py +829 -0
  38. codex_autorunner/core/sqlite_utils.py +13 -4
  39. codex_autorunner/core/state.py +7 -10
  40. codex_autorunner/core/state_roots.py +5 -0
  41. codex_autorunner/core/templates/__init__.py +39 -0
  42. codex_autorunner/core/templates/git_mirror.py +234 -0
  43. codex_autorunner/core/templates/provenance.py +56 -0
  44. codex_autorunner/core/templates/scan_cache.py +120 -0
  45. codex_autorunner/core/ticket_linter_cli.py +17 -0
  46. codex_autorunner/core/ticket_manager_cli.py +154 -92
  47. codex_autorunner/core/time_utils.py +11 -0
  48. codex_autorunner/core/types.py +18 -0
  49. codex_autorunner/core/utils.py +34 -6
  50. codex_autorunner/flows/review/service.py +23 -25
  51. codex_autorunner/flows/ticket_flow/definition.py +43 -1
  52. codex_autorunner/integrations/agents/__init__.py +2 -0
  53. codex_autorunner/integrations/agents/backend_orchestrator.py +18 -0
  54. codex_autorunner/integrations/agents/codex_backend.py +19 -8
  55. codex_autorunner/integrations/agents/runner.py +3 -8
  56. codex_autorunner/integrations/agents/wiring.py +8 -0
  57. codex_autorunner/integrations/telegram/adapter.py +1 -1
  58. codex_autorunner/integrations/telegram/config.py +1 -1
  59. codex_autorunner/integrations/telegram/doctor.py +228 -6
  60. codex_autorunner/integrations/telegram/handlers/commands/execution.py +236 -74
  61. codex_autorunner/integrations/telegram/handlers/commands/files.py +314 -75
  62. codex_autorunner/integrations/telegram/handlers/commands/flows.py +346 -58
  63. codex_autorunner/integrations/telegram/handlers/commands/workspace.py +498 -37
  64. codex_autorunner/integrations/telegram/handlers/commands_runtime.py +202 -45
  65. codex_autorunner/integrations/telegram/handlers/commands_spec.py +18 -7
  66. codex_autorunner/integrations/telegram/handlers/messages.py +34 -3
  67. codex_autorunner/integrations/telegram/helpers.py +1 -3
  68. codex_autorunner/integrations/telegram/runtime.py +9 -4
  69. codex_autorunner/integrations/telegram/service.py +30 -0
  70. codex_autorunner/integrations/telegram/state.py +38 -0
  71. codex_autorunner/integrations/telegram/ticket_flow_bridge.py +10 -4
  72. codex_autorunner/integrations/telegram/transport.py +10 -3
  73. codex_autorunner/integrations/templates/__init__.py +27 -0
  74. codex_autorunner/integrations/templates/scan_agent.py +312 -0
  75. codex_autorunner/server.py +2 -2
  76. codex_autorunner/static/agentControls.js +21 -5
  77. codex_autorunner/static/app.js +115 -11
  78. codex_autorunner/static/archive.js +274 -81
  79. codex_autorunner/static/archiveApi.js +21 -0
  80. codex_autorunner/static/chatUploads.js +137 -0
  81. codex_autorunner/static/constants.js +1 -1
  82. codex_autorunner/static/docChatCore.js +185 -13
  83. codex_autorunner/static/fileChat.js +68 -40
  84. codex_autorunner/static/fileboxUi.js +159 -0
  85. codex_autorunner/static/hub.js +46 -81
  86. codex_autorunner/static/index.html +303 -24
  87. codex_autorunner/static/messages.js +82 -4
  88. codex_autorunner/static/notifications.js +288 -0
  89. codex_autorunner/static/pma.js +1167 -0
  90. codex_autorunner/static/settings.js +3 -0
  91. codex_autorunner/static/streamUtils.js +57 -0
  92. codex_autorunner/static/styles.css +9141 -6742
  93. codex_autorunner/static/templateReposSettings.js +225 -0
  94. codex_autorunner/static/terminalManager.js +22 -3
  95. codex_autorunner/static/ticketChatActions.js +165 -3
  96. codex_autorunner/static/ticketChatStream.js +17 -119
  97. codex_autorunner/static/ticketEditor.js +41 -13
  98. codex_autorunner/static/ticketTemplates.js +798 -0
  99. codex_autorunner/static/tickets.js +69 -19
  100. codex_autorunner/static/turnEvents.js +27 -0
  101. codex_autorunner/static/turnResume.js +33 -0
  102. codex_autorunner/static/utils.js +28 -0
  103. codex_autorunner/static/workspace.js +258 -44
  104. codex_autorunner/static/workspaceFileBrowser.js +6 -4
  105. codex_autorunner/surfaces/cli/cli.py +1465 -155
  106. codex_autorunner/surfaces/cli/pma_cli.py +817 -0
  107. codex_autorunner/surfaces/web/app.py +253 -49
  108. codex_autorunner/surfaces/web/routes/__init__.py +4 -0
  109. codex_autorunner/surfaces/web/routes/analytics.py +29 -22
  110. codex_autorunner/surfaces/web/routes/archive.py +197 -0
  111. codex_autorunner/surfaces/web/routes/file_chat.py +297 -36
  112. codex_autorunner/surfaces/web/routes/filebox.py +227 -0
  113. codex_autorunner/surfaces/web/routes/flows.py +219 -29
  114. codex_autorunner/surfaces/web/routes/messages.py +70 -39
  115. codex_autorunner/surfaces/web/routes/pma.py +1652 -0
  116. codex_autorunner/surfaces/web/routes/repos.py +1 -1
  117. codex_autorunner/surfaces/web/routes/shared.py +0 -3
  118. codex_autorunner/surfaces/web/routes/templates.py +634 -0
  119. codex_autorunner/surfaces/web/runner_manager.py +2 -2
  120. codex_autorunner/surfaces/web/schemas.py +81 -18
  121. codex_autorunner/tickets/agent_pool.py +27 -0
  122. codex_autorunner/tickets/files.py +33 -16
  123. codex_autorunner/tickets/lint.py +50 -0
  124. codex_autorunner/tickets/models.py +3 -0
  125. codex_autorunner/tickets/outbox.py +41 -5
  126. codex_autorunner/tickets/runner.py +350 -69
  127. {codex_autorunner-1.1.0.dist-info → codex_autorunner-1.2.1.dist-info}/METADATA +15 -19
  128. {codex_autorunner-1.1.0.dist-info → codex_autorunner-1.2.1.dist-info}/RECORD +132 -101
  129. codex_autorunner/core/adapter_utils.py +0 -21
  130. codex_autorunner/core/engine.py +0 -3302
  131. {codex_autorunner-1.1.0.dist-info → codex_autorunner-1.2.1.dist-info}/WHEEL +0 -0
  132. {codex_autorunner-1.1.0.dist-info → codex_autorunner-1.2.1.dist-info}/entry_points.txt +0 -0
  133. {codex_autorunner-1.1.0.dist-info → codex_autorunner-1.2.1.dist-info}/licenses/LICENSE +0 -0
  134. {codex_autorunner-1.1.0.dist-info → codex_autorunner-1.2.1.dist-info}/top_level.txt +0 -0
@@ -1,47 +1,269 @@
1
1
  """Telegram integration doctor checks."""
2
2
 
3
+ import logging
4
+ import os
5
+ from datetime import datetime, timedelta, timezone
6
+ from pathlib import Path
3
7
  from typing import Any, Dict, Union
4
8
 
5
9
  from ...core.config import HubConfig, RepoConfig
6
- from ...core.engine import DoctorCheck
7
10
  from ...core.optional_dependencies import missing_optional_dependencies
11
+ from ...core.runtime import DoctorCheck
12
+
13
+ logger = logging.getLogger(__name__)
14
+
15
+ STUCK_TURN_THRESHOLD_MINUTES = 30
16
+ STATE_FILE_CHECK = ".codex-autorunner/telegram_state.sqlite3"
8
17
 
9
18
 
10
19
  def telegram_doctor_checks(
11
20
  config: Union[HubConfig, RepoConfig, Dict[str, Any]],
21
+ repo_root: Union[Path, None] = None,
12
22
  ) -> list[DoctorCheck]:
13
23
  """Run Telegram-specific doctor checks.
14
24
 
15
25
  Returns a list of DoctorCheck objects for Telegram integration.
16
26
  Works with HubConfig, RepoConfig, or raw dict.
27
+
28
+ Args:
29
+ config: HubConfig, RepoConfig, or raw dict
30
+ repo_root: Optional repo root path for state file checks
17
31
  """
18
32
  checks: list[DoctorCheck] = []
19
33
  telegram_cfg = None
20
34
 
21
35
  if isinstance(config, dict):
22
36
  telegram_cfg = config.get("telegram_bot")
37
+ if not telegram_cfg:
38
+ telegram_cfg = config.get("notifications", {}).get("telegram", {})
23
39
  elif isinstance(config.raw, dict):
24
40
  telegram_cfg = config.raw.get("telegram_bot")
41
+ if not telegram_cfg:
42
+ telegram_cfg = config.raw.get("notifications", {}).get("telegram", {})
25
43
 
26
- if isinstance(telegram_cfg, dict) and telegram_cfg.get("enabled") is True:
44
+ enabled = isinstance(telegram_cfg, dict) and telegram_cfg.get("enabled") is True
45
+
46
+ if enabled:
27
47
  missing_telegram = missing_optional_dependencies((("httpx", "httpx"),))
28
48
  if missing_telegram:
29
49
  deps_list = ", ".join(missing_telegram)
30
50
  checks.append(
31
51
  DoctorCheck(
32
- check_id="telegram.dependencies",
33
- status="error",
52
+ name="Telegram dependencies",
53
+ passed=False,
34
54
  message=f"Telegram is enabled but missing optional deps: {deps_list}",
55
+ check_id="telegram.dependencies",
35
56
  fix="Install with `pip install codex-autorunner[telegram]`.",
36
57
  )
37
58
  )
59
+ return checks
38
60
  else:
39
61
  checks.append(
40
62
  DoctorCheck(
41
- check_id="telegram.dependencies",
42
- status="ok",
63
+ name="Telegram dependencies",
64
+ passed=True,
43
65
  message="Telegram dependencies are installed.",
66
+ check_id="telegram.dependencies",
67
+ severity="info",
44
68
  )
45
69
  )
46
70
 
71
+ bot_token_env = telegram_cfg.get("bot_token_env", "CAR_TELEGRAM_BOT_TOKEN")
72
+ chat_id_env = telegram_cfg.get("chat_id_env", "CAR_TELEGRAM_CHAT_ID")
73
+
74
+ bot_token = os.environ.get(bot_token_env)
75
+ chat_id = os.environ.get(chat_id_env)
76
+
77
+ if not bot_token:
78
+ checks.append(
79
+ DoctorCheck(
80
+ name="Telegram bot token",
81
+ passed=False,
82
+ message=f"Telegram bot token not found in environment: {bot_token_env}",
83
+ check_id="telegram.bot_token",
84
+ fix=f"Set {bot_token_env} environment variable or disable Telegram.",
85
+ )
86
+ )
87
+ else:
88
+ checks.append(
89
+ DoctorCheck(
90
+ name="Telegram bot token",
91
+ passed=True,
92
+ message=f"Bot token configured (env: {bot_token_env}).",
93
+ check_id="telegram.bot_token",
94
+ severity="info",
95
+ )
96
+ )
97
+
98
+ if not chat_id:
99
+ checks.append(
100
+ DoctorCheck(
101
+ name="Telegram chat ID",
102
+ passed=False,
103
+ message=f"Telegram chat_id not found in environment: {chat_id_env}",
104
+ check_id="telegram.chat_id",
105
+ fix=f"Set {chat_id_env} environment variable for notifications.",
106
+ severity="warning",
107
+ )
108
+ )
109
+ else:
110
+ checks.append(
111
+ DoctorCheck(
112
+ name="Telegram chat ID",
113
+ passed=True,
114
+ message=f"Chat ID configured (env: {chat_id_env}).",
115
+ check_id="telegram.chat_id",
116
+ severity="info",
117
+ )
118
+ )
119
+
120
+ allowed_chats = telegram_cfg.get("allowed_chat_ids", [])
121
+ allowed_users = telegram_cfg.get("allowed_user_ids", [])
122
+ if not allowed_chats and not allowed_users:
123
+ checks.append(
124
+ DoctorCheck(
125
+ name="Telegram access control",
126
+ passed=False,
127
+ message="No allowed_chat_ids or allowed_user_ids configured",
128
+ check_id="telegram.access_control",
129
+ fix="Configure allowed_chat_ids or allowed_user_ids in telegram_bot config.",
130
+ severity="warning",
131
+ )
132
+ )
133
+ else:
134
+ checks.append(
135
+ DoctorCheck(
136
+ name="Telegram access control",
137
+ passed=True,
138
+ message=f"Access control configured: {len(allowed_chats)} chats, {len(allowed_users)} users.",
139
+ check_id="telegram.access_control",
140
+ severity="info",
141
+ )
142
+ )
143
+
144
+ state_file_path = None
145
+ if repo_root:
146
+ state_file_path = repo_root / STATE_FILE_CHECK
147
+ if not state_file_path.exists():
148
+ checks.append(
149
+ DoctorCheck(
150
+ name="Telegram state file",
151
+ passed=False,
152
+ message=f"Telegram state file not found: {state_file_path}",
153
+ check_id="telegram.state_file",
154
+ severity="warning",
155
+ fix="Run a Telegram command to initialize the state file.",
156
+ )
157
+ )
158
+ else:
159
+ checks.append(
160
+ DoctorCheck(
161
+ name="Telegram state file",
162
+ passed=True,
163
+ message=f"State file exists: {state_file_path}",
164
+ check_id="telegram.state_file",
165
+ severity="info",
166
+ )
167
+ )
168
+
169
+ _check_stuck_turns(checks, state_file_path)
170
+
171
+ mode = telegram_cfg.get("mode", "polling")
172
+ if mode not in ("polling", "webhook"):
173
+ checks.append(
174
+ DoctorCheck(
175
+ name="Telegram mode",
176
+ passed=False,
177
+ message=f"Invalid Telegram mode: {mode}",
178
+ check_id="telegram.mode",
179
+ fix="Set mode to 'polling' or 'webhook' in telegram_bot config.",
180
+ )
181
+ )
182
+ else:
183
+ checks.append(
184
+ DoctorCheck(
185
+ name="Telegram mode",
186
+ passed=True,
187
+ message=f"Telegram mode: {mode}",
188
+ check_id="telegram.mode",
189
+ severity="info",
190
+ )
191
+ )
192
+ else:
193
+ checks.append(
194
+ DoctorCheck(
195
+ name="Telegram enabled",
196
+ passed=True,
197
+ message="Telegram integration is disabled.",
198
+ check_id="telegram.enabled",
199
+ severity="info",
200
+ fix="Set telegram_bot.enabled=true in config to enable.",
201
+ )
202
+ )
203
+
47
204
  return checks
205
+
206
+
207
+ def _check_stuck_turns(checks: list[DoctorCheck], state_file_path: Path) -> None:
208
+ """Check for stuck turns in Telegram state."""
209
+ try:
210
+ from ...core.sqlite_utils import connect_sqlite
211
+
212
+ conn = connect_sqlite(state_file_path)
213
+ cursor = conn.cursor()
214
+
215
+ cursor.execute("PRAGMA table_info(turns)")
216
+ columns = {row[1] for row in cursor.fetchall()}
217
+
218
+ if "status" not in columns:
219
+ return
220
+
221
+ threshold = datetime.now(timezone.utc) - timedelta(
222
+ minutes=STUCK_TURN_THRESHOLD_MINUTES
223
+ )
224
+ cursor.execute(
225
+ """
226
+ SELECT topic_key, status, updated_at
227
+ FROM turns
228
+ WHERE status = 'running' AND updated_at < ?
229
+ ORDER BY updated_at ASC
230
+ LIMIT 5
231
+ """,
232
+ (threshold.isoformat(),),
233
+ )
234
+
235
+ stuck_turns = cursor.fetchall()
236
+ conn.close()
237
+
238
+ if stuck_turns:
239
+ topics = ", ".join([turn[0] for turn in stuck_turns])
240
+ checks.append(
241
+ DoctorCheck(
242
+ name="Telegram stuck turns",
243
+ passed=False,
244
+ message=f"Found {len(stuck_turns)} stuck turns (inactive > {STUCK_TURN_THRESHOLD_MINUTES}m): {topics}",
245
+ check_id="telegram.stuck_turns",
246
+ fix="Review logs and consider restarting the bot or clearing stuck turns.",
247
+ )
248
+ )
249
+ else:
250
+ checks.append(
251
+ DoctorCheck(
252
+ name="Telegram stuck turns",
253
+ passed=True,
254
+ message="No stuck turns detected.",
255
+ check_id="telegram.stuck_turns",
256
+ severity="info",
257
+ )
258
+ )
259
+ except Exception as exc:
260
+ logger.debug("Failed to check for stuck turns: %s", exc)
261
+ checks.append(
262
+ DoctorCheck(
263
+ name="Telegram stuck turns",
264
+ passed=True,
265
+ message=f"Could not check for stuck turns: {exc}",
266
+ check_id="telegram.stuck_turns",
267
+ severity="warning",
268
+ )
269
+ )