talkops-ai 0.3.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 (411) hide show
  1. talkops/__init__.py +35 -0
  2. talkops/__main__.py +20 -0
  3. talkops/_constants.py +70 -0
  4. talkops/_debug.py +159 -0
  5. talkops/_debug_buffer.py +264 -0
  6. talkops/_textual_patches.py +637 -0
  7. talkops/_version.py +30 -0
  8. talkops/addons/__init__.py +131 -0
  9. talkops/addons/builtin/__init__.py +52 -0
  10. talkops/addons/builtin/client_gateway.py +532 -0
  11. talkops/addons/builtin/core_auth.py +157 -0
  12. talkops/addons/builtin/webhooks.py +212 -0
  13. talkops/addons/commands_cli.py +476 -0
  14. talkops/addons/config.py +456 -0
  15. talkops/addons/discovery.py +499 -0
  16. talkops/addons/gateway.py +849 -0
  17. talkops/addons/manager.py +888 -0
  18. talkops/addons/manifest.py +353 -0
  19. talkops/addons/marketplace.py +558 -0
  20. talkops/addons/marketplace_models.py +224 -0
  21. talkops/addons/protocol.py +307 -0
  22. talkops/addons/store.py +377 -0
  23. talkops/agent/__init__.py +53 -0
  24. talkops/agent/config.py +382 -0
  25. talkops/agent/factory.py +1540 -0
  26. talkops/agent/profiles.py +131 -0
  27. talkops/approval_mode.py +68 -0
  28. talkops/auth/__init__.py +78 -0
  29. talkops/auth/models.py +184 -0
  30. talkops/auth/oauth_acquirer.py +682 -0
  31. talkops/auth/storage.py +609 -0
  32. talkops/backend/__init__.py +104 -0
  33. talkops/backend/composite.py +107 -0
  34. talkops/backend/local.py +474 -0
  35. talkops/backend/registry.py +94 -0
  36. talkops/backend/sandbox_config.py +288 -0
  37. talkops/backend/sandbox_factory.py +1131 -0
  38. talkops/backend/sandbox_provider.py +147 -0
  39. talkops/backend/sandbox_registry.py +338 -0
  40. talkops/built_in_skills/commit/SKILL.md +49 -0
  41. talkops/built_in_skills/remember/SKILL.md +132 -0
  42. talkops/built_in_skills/simplify/SKILL.md +68 -0
  43. talkops/built_in_skills/skill-creator/SKILL.md +351 -0
  44. talkops/built_in_skills/skill-creator/scripts/init_skill.py +385 -0
  45. talkops/built_in_skills/skill-creator/scripts/quick_validate.py +179 -0
  46. talkops/cli/__init__.py +15 -0
  47. talkops/cli/commands/__init__.py +32 -0
  48. talkops/cli/commands/agents.py +147 -0
  49. talkops/cli/commands/auth.py +967 -0
  50. talkops/cli/commands/doctor.py +123 -0
  51. talkops/cli/commands/mcp.py +212 -0
  52. talkops/cli/commands/serve.py +623 -0
  53. talkops/cli/commands/threads.py +80 -0
  54. talkops/cli/interactive.py +218 -0
  55. talkops/cli/main.py +1533 -0
  56. talkops/cli/non_interactive.py +661 -0
  57. talkops/cli/server_manager.py +382 -0
  58. talkops/commands/__init__.py +39 -0
  59. talkops/commands/_base.py +145 -0
  60. talkops/commands/_guards.py +66 -0
  61. talkops/commands/_router.py +309 -0
  62. talkops/commands/_types.py +73 -0
  63. talkops/commands/core/__init__.py +103 -0
  64. talkops/commands/core/auth.py +550 -0
  65. talkops/commands/core/bug.py +66 -0
  66. talkops/commands/core/clear.py +176 -0
  67. talkops/commands/core/cloud.py +513 -0
  68. talkops/commands/core/compact.py +271 -0
  69. talkops/commands/core/config_cmd.py +147 -0
  70. talkops/commands/core/context.py +239 -0
  71. talkops/commands/core/cost.py +64 -0
  72. talkops/commands/core/doctor.py +554 -0
  73. talkops/commands/core/effort.py +127 -0
  74. talkops/commands/core/exit_cmd.py +61 -0
  75. talkops/commands/core/fast.py +167 -0
  76. talkops/commands/core/fork.py +151 -0
  77. talkops/commands/core/help_cmd.py +114 -0
  78. talkops/commands/core/mcp.py +152 -0
  79. talkops/commands/core/model.py +136 -0
  80. talkops/commands/core/permissions.py +223 -0
  81. talkops/commands/core/plugins.py +118 -0
  82. talkops/commands/core/pool.py +177 -0
  83. talkops/commands/core/resume.py +119 -0
  84. talkops/commands/core/skills.py +198 -0
  85. talkops/commands/custom/__init__.py +113 -0
  86. talkops/commands/custom/expansion.py +537 -0
  87. talkops/commands/custom/frontmatter.py +418 -0
  88. talkops/commands/custom/handler.py +387 -0
  89. talkops/commands/custom/loader.py +614 -0
  90. talkops/commands/custom/models.py +235 -0
  91. talkops/commands/power/__init__.py +106 -0
  92. talkops/commands/power/agents.py +486 -0
  93. talkops/commands/power/btw.py +126 -0
  94. talkops/commands/power/copy.py +157 -0
  95. talkops/commands/power/goal.py +593 -0
  96. talkops/commands/power/loop.py +327 -0
  97. talkops/commands/power/memory.py +348 -0
  98. talkops/commands/power/review.py +180 -0
  99. talkops/commands/power/rubric.py +306 -0
  100. talkops/commands/power/runtime.py +388 -0
  101. talkops/commands/power/skill_creator.py +102 -0
  102. talkops/commands/power/skill_invoke.py +183 -0
  103. talkops/commands/power/tasks.py +388 -0
  104. talkops/commands/power/trace.py +137 -0
  105. talkops/commands/power/ui_toggles.py +301 -0
  106. talkops/commands/power/version.py +73 -0
  107. talkops/commands/registry.py +217 -0
  108. talkops/config/__init__.py +128 -0
  109. talkops/config/adapters/__init__.py +19 -0
  110. talkops/config/adapters/postgres.py +790 -0
  111. talkops/config/adapters/sqlite.py +783 -0
  112. talkops/config/addons.py +173 -0
  113. talkops/config/aws.py +288 -0
  114. talkops/config/cli_settings.py +1239 -0
  115. talkops/config/cloud_discovery.py +1220 -0
  116. talkops/config/cloud_profiles.py +910 -0
  117. talkops/config/credential_broker.py +767 -0
  118. talkops/config/env_vars.py +110 -0
  119. talkops/config/langsmith.py +333 -0
  120. talkops/config/manifest.py +1249 -0
  121. talkops/config/metadata.py +216 -0
  122. talkops/config/paths.py +796 -0
  123. talkops/config/plugins.py +144 -0
  124. talkops/config/settings.py +1212 -0
  125. talkops/config/store.py +468 -0
  126. talkops/config/store_factory.py +111 -0
  127. talkops/config/toml_config.py +904 -0
  128. talkops/editor.py +442 -0
  129. talkops/exceptions.py +82 -0
  130. talkops/file_ops.py +232 -0
  131. talkops/hooks/__init__.py +153 -0
  132. talkops/hooks/env.py +58 -0
  133. talkops/hooks/interrupt.py +135 -0
  134. talkops/hooks/models/__init__.py +123 -0
  135. talkops/hooks/models/adapters.py +33 -0
  136. talkops/hooks/models/config.py +93 -0
  137. talkops/hooks/models/domain.py +448 -0
  138. talkops/hooks/models/transport.py +51 -0
  139. talkops/hooks/tools.py +245 -0
  140. talkops/input.py +890 -0
  141. talkops/integrations/__init__.py +94 -0
  142. talkops/integrations/base.py +167 -0
  143. talkops/integrations/content_filter.py +133 -0
  144. talkops/integrations/event_bus.py +495 -0
  145. talkops/integrations/hooks.py +258 -0
  146. talkops/integrations/identity.py +195 -0
  147. talkops/integrations/notifications.py +148 -0
  148. talkops/integrations/stream_bridge.py +411 -0
  149. talkops/integrations/thread_store.py +326 -0
  150. talkops/json_types.py +35 -0
  151. talkops/mcp/__init__.py +111 -0
  152. talkops/mcp/config.py +257 -0
  153. talkops/mcp/discovery.py +253 -0
  154. talkops/mcp/mcp_info.py +141 -0
  155. talkops/mcp/middleware.py +116 -0
  156. talkops/mcp/preload.py +1275 -0
  157. talkops/mcp/raw_config.py +163 -0
  158. talkops/mcp/semantic_profiler.py +319 -0
  159. talkops/mcp/session_manager.py +1492 -0
  160. talkops/mcp/trust.py +119 -0
  161. talkops/media_utils.py +587 -0
  162. talkops/memory/__init__.py +41 -0
  163. talkops/memory/branch.py +79 -0
  164. talkops/memory/guard.py +33 -0
  165. talkops/memory/onboarding.py +134 -0
  166. talkops/memory/registry.py +148 -0
  167. talkops/memory/store.py +238 -0
  168. talkops/middleware/__init__.py +235 -0
  169. talkops/middleware/_repository_bounds.py +473 -0
  170. talkops/middleware/agent_session.py +647 -0
  171. talkops/middleware/ask_user.py +173 -0
  172. talkops/middleware/auto_mode.py +75 -0
  173. talkops/middleware/auto_mode_hitl.py +2471 -0
  174. talkops/middleware/background_commands.py +833 -0
  175. talkops/middleware/btw.py +173 -0
  176. talkops/middleware/compaction.py +2651 -0
  177. talkops/middleware/configurable_model.py +461 -0
  178. talkops/middleware/cost_tracking.py +1192 -0
  179. talkops/middleware/custom_commands.py +630 -0
  180. talkops/middleware/glm_stall_recovery.py +135 -0
  181. talkops/middleware/goal_criteria.py +1423 -0
  182. talkops/middleware/goal_state_notice.py +778 -0
  183. talkops/middleware/goal_tools.py +441 -0
  184. talkops/middleware/headless_mcp_guard.py +199 -0
  185. talkops/middleware/jev_model_router.py +1196 -0
  186. talkops/middleware/local_context.py +512 -0
  187. talkops/middleware/mcp_context.py +279 -0
  188. talkops/middleware/mcp_middleware.py +367 -0
  189. talkops/middleware/memory_guard.py +404 -0
  190. talkops/middleware/model_retry.py +222 -0
  191. talkops/middleware/registry.py +155 -0
  192. talkops/middleware/reliable_rubric.py +784 -0
  193. talkops/middleware/resume_state.py +187 -0
  194. talkops/middleware/server_hooks.py +1270 -0
  195. talkops/middleware/shell_allow_list.py +104 -0
  196. talkops/middleware/skills.py +537 -0
  197. talkops/middleware/subagent_artifacts.py +99 -0
  198. talkops/middleware/subagent_telemetry.py +288 -0
  199. talkops/middleware/subagents.py +280 -0
  200. talkops/middleware/tnr_safety.py +621 -0
  201. talkops/middleware/tool_filter.py +869 -0
  202. talkops/middleware/unified_system_message.py +353 -0
  203. talkops/middleware/webhook_sre.py +470 -0
  204. talkops/model/__init__.py +85 -0
  205. talkops/model/config.py +3653 -0
  206. talkops/model/factory.py +1295 -0
  207. talkops/model/pool.py +527 -0
  208. talkops/model/reasoning.py +294 -0
  209. talkops/offload.py +187 -0
  210. talkops/output.py +78 -0
  211. talkops/plugins/__init__.py +212 -0
  212. talkops/plugins/_json.py +38 -0
  213. talkops/plugins/adapters/__init__.py +27 -0
  214. talkops/plugins/adapters/agents.py +127 -0
  215. talkops/plugins/adapters/commands.py +212 -0
  216. talkops/plugins/adapters/mcp.py +537 -0
  217. talkops/plugins/adapters/skills.py +146 -0
  218. talkops/plugins/commands_cli.py +572 -0
  219. talkops/plugins/discovery.py +665 -0
  220. talkops/plugins/manifest.py +350 -0
  221. talkops/plugins/marketplace.py +907 -0
  222. talkops/plugins/models.py +359 -0
  223. talkops/plugins/project_plugins.py +330 -0
  224. talkops/plugins/protocol.py +45 -0
  225. talkops/plugins/store.py +1161 -0
  226. talkops/plugins/substitution.py +136 -0
  227. talkops/project_utils.py +167 -0
  228. talkops/prompts/__init__.py +55 -0
  229. talkops/prompts/custom_commands.py +195 -0
  230. talkops/prompts/system.py +777 -0
  231. talkops/prompts/templates/system_prompt.md +92 -0
  232. talkops/prompts/templates/webhook_sre_prompt.md +146 -0
  233. talkops/prompts/types.py +68 -0
  234. talkops/rubrics/__init__.py +92 -0
  235. talkops/rubrics/evaluator.py +424 -0
  236. talkops/rubrics/evidence_extractor.py +288 -0
  237. talkops/rubrics/generator.py +454 -0
  238. talkops/rubrics/jev_compiler.py +189 -0
  239. talkops/rubrics/jev_grader.py +311 -0
  240. talkops/rubrics/middleware.py +22 -0
  241. talkops/schema/__init__.py +121 -0
  242. talkops/schema/interrupts.py +995 -0
  243. talkops/security/__init__.py +105 -0
  244. talkops/security/approval_mode.py +610 -0
  245. talkops/security/approval_mode_source.py +258 -0
  246. talkops/security/cli_ast_evaluator.py +570 -0
  247. talkops/security/jev_classifier.py +702 -0
  248. talkops/security/shell_safety.py +354 -0
  249. talkops/security/unicode_security.py +465 -0
  250. talkops/security/url_validation.py +174 -0
  251. talkops/server/__init__.py +56 -0
  252. talkops/server/_server_config.py +344 -0
  253. talkops/server/asgi.py +80 -0
  254. talkops/server/auth.py +919 -0
  255. talkops/server/oidc_provider.py +202 -0
  256. talkops/server/server.py +881 -0
  257. talkops/server/server_graph.py +249 -0
  258. talkops/server/webhooks_app.py +641 -0
  259. talkops/skills/__init__.py +152 -0
  260. talkops/skills/commands.py +1120 -0
  261. talkops/skills/invocation.py +396 -0
  262. talkops/skills/load.py +406 -0
  263. talkops/skills/loader.py +37 -0
  264. talkops/skills/merge.py +79 -0
  265. talkops/skills/registry.py +277 -0
  266. talkops/skills/sources.py +189 -0
  267. talkops/skills/trust.py +435 -0
  268. talkops/state/__init__.py +298 -0
  269. talkops/state/agent_session_channels.py +131 -0
  270. talkops/state/background_task_channels.py +89 -0
  271. talkops/state/base.py +178 -0
  272. talkops/state/btw_channels.py +30 -0
  273. talkops/state/cloud_context.py +276 -0
  274. talkops/state/conversation_title.py +479 -0
  275. talkops/state/custom_command_channels.py +70 -0
  276. talkops/state/goal_channels.py +196 -0
  277. talkops/state/goal_state_limits.py +203 -0
  278. talkops/state/postgres_session.py +831 -0
  279. talkops/state/remote_session.py +890 -0
  280. talkops/state/resume_state.py +72 -0
  281. talkops/state/service_context.py +295 -0
  282. talkops/state/session.py +2514 -0
  283. talkops/state/state_migration.py +100 -0
  284. talkops/state/webhook_sre_channels.py +34 -0
  285. talkops/subagents/__init__.py +44 -0
  286. talkops/subagents/loader.py +378 -0
  287. talkops/subagents/subagents_parser.py +131 -0
  288. talkops/subagents/types.py +41 -0
  289. talkops/tasks/__init__.py +43 -0
  290. talkops/tasks/manager.py +885 -0
  291. talkops/tools/__init__.py +50 -0
  292. talkops/tools/catalog.py +61 -0
  293. talkops/tools/cloud_tools.py +188 -0
  294. talkops/tools/display.py +38 -0
  295. talkops/tools/fetch_url.py +190 -0
  296. talkops/tools/goal_tools.py +437 -0
  297. talkops/tools/registry.py +119 -0
  298. talkops/tools/thread.py +46 -0
  299. talkops/tools/web_search.py +231 -0
  300. talkops/ui/__init__.py +133 -0
  301. talkops/ui/app.py +3240 -0
  302. talkops/ui/app.tcss +529 -0
  303. talkops/ui/assets/talkops-icon.png +0 -0
  304. talkops/ui/clipboard.py +165 -0
  305. talkops/ui/command_registry.py +863 -0
  306. talkops/ui/context_detection.py +115 -0
  307. talkops/ui/controllers/__init__.py +41 -0
  308. talkops/ui/controllers/btw_controller.py +269 -0
  309. talkops/ui/controllers/goal_controller.py +830 -0
  310. talkops/ui/controllers/modal_controller.py +1526 -0
  311. talkops/ui/controllers/prompt_controller.py +649 -0
  312. talkops/ui/controllers/server_controller.py +1513 -0
  313. talkops/ui/controllers/shell_controller.py +190 -0
  314. talkops/ui/controllers/task_watcher_controller.py +321 -0
  315. talkops/ui/controllers/thread_controller.py +777 -0
  316. talkops/ui/message_store.py +168 -0
  317. talkops/ui/modal.tcss +176 -0
  318. talkops/ui/permission_store.py +423 -0
  319. talkops/ui/preferences.py +132 -0
  320. talkops/ui/prompt_manager.py +19 -0
  321. talkops/ui/remote_client.py +1202 -0
  322. talkops/ui/state/__init__.py +31 -0
  323. talkops/ui/state/ui_phase.py +210 -0
  324. talkops/ui/textual_adapter.py +1813 -0
  325. talkops/ui/theme.py +796 -0
  326. talkops/ui/tips.py +263 -0
  327. talkops/ui/ui_help.py +451 -0
  328. talkops/ui/widgets/__init__.py +559 -0
  329. talkops/ui/widgets/_ask_user_types.py +96 -0
  330. talkops/ui/widgets/_copy_spans.py +66 -0
  331. talkops/ui/widgets/_inline_prompt.py +305 -0
  332. talkops/ui/widgets/_js_eval_display.py +153 -0
  333. talkops/ui/widgets/_links.py +264 -0
  334. talkops/ui/widgets/_tool_stream.py +323 -0
  335. talkops/ui/widgets/agent_selector.py +367 -0
  336. talkops/ui/widgets/approval.py +1085 -0
  337. talkops/ui/widgets/ask_user.py +566 -0
  338. talkops/ui/widgets/auth.py +870 -0
  339. talkops/ui/widgets/auth_manager.py +335 -0
  340. talkops/ui/widgets/auto_mode_notice.py +153 -0
  341. talkops/ui/widgets/autocomplete.py +1151 -0
  342. talkops/ui/widgets/background_task_panel.py +446 -0
  343. talkops/ui/widgets/btw_card.py +151 -0
  344. talkops/ui/widgets/chat_input.py +2283 -0
  345. talkops/ui/widgets/chat_messages.py +960 -0
  346. talkops/ui/widgets/cloud_selector.py +1281 -0
  347. talkops/ui/widgets/config_manager.py +875 -0
  348. talkops/ui/widgets/debug_console.py +1269 -0
  349. talkops/ui/widgets/devops_renderers.py +415 -0
  350. talkops/ui/widgets/diff.py +450 -0
  351. talkops/ui/widgets/effort_selector.py +230 -0
  352. talkops/ui/widgets/goal_review.py +938 -0
  353. talkops/ui/widgets/goal_status.py +71 -0
  354. talkops/ui/widgets/infra_panel.py +181 -0
  355. talkops/ui/widgets/input_dock.py +121 -0
  356. talkops/ui/widgets/install_confirm.py +123 -0
  357. talkops/ui/widgets/loading.py +236 -0
  358. talkops/ui/widgets/logo_image.py +175 -0
  359. talkops/ui/widgets/mcp_viewer.py +1349 -0
  360. talkops/ui/widgets/message_list.py +724 -0
  361. talkops/ui/widgets/messages.py +185 -0
  362. talkops/ui/widgets/modal_base.py +661 -0
  363. talkops/ui/widgets/model_selector.py +1136 -0
  364. talkops/ui/widgets/notification_center.py +126 -0
  365. talkops/ui/widgets/notification_settings.py +135 -0
  366. talkops/ui/widgets/operation_card.py +123 -0
  367. talkops/ui/widgets/permissions_manager.py +724 -0
  368. talkops/ui/widgets/plugin_manager.py +1662 -0
  369. talkops/ui/widgets/pool_selector.py +597 -0
  370. talkops/ui/widgets/preamble.py +67 -0
  371. talkops/ui/widgets/skills_viewer.py +571 -0
  372. talkops/ui/widgets/status.py +1417 -0
  373. talkops/ui/widgets/status_messages.py +897 -0
  374. talkops/ui/widgets/subagent_panel.py +1005 -0
  375. talkops/ui/widgets/theme_selector.py +315 -0
  376. talkops/ui/widgets/thread_selector.py +530 -0
  377. talkops/ui/widgets/toast.py +46 -0
  378. talkops/ui/widgets/tool_call_message.py +2638 -0
  379. talkops/ui/widgets/tool_display.py +484 -0
  380. talkops/ui/widgets/tool_group.py +474 -0
  381. talkops/ui/widgets/tool_renderers.py +328 -0
  382. talkops/ui/widgets/tool_widgets.py +415 -0
  383. talkops/ui/widgets/welcome.py +1513 -0
  384. talkops/ui/widgets/welcome_popup.py +105 -0
  385. talkops/ui/widgets/workspace_trust.py +482 -0
  386. talkops/utils/__init__.py +48 -0
  387. talkops/utils/cost_estimation.py +183 -0
  388. talkops/utils/git.py +400 -0
  389. talkops/utils/logger.py +646 -0
  390. talkops/utils/session_stats.py +143 -0
  391. talkops/utils/startup_error.py +51 -0
  392. talkops/webhooks/__init__.py +87 -0
  393. talkops/webhooks/dispatcher.py +870 -0
  394. talkops/webhooks/formatting.py +2576 -0
  395. talkops/webhooks/models.py +469 -0
  396. talkops/webhooks/providers/__init__.py +69 -0
  397. talkops/webhooks/providers/alertmanager.py +148 -0
  398. talkops/webhooks/providers/base.py +104 -0
  399. talkops/webhooks/providers/cloudevents.py +134 -0
  400. talkops/webhooks/providers/github.py +196 -0
  401. talkops/webhooks/providers/jenkins.py +124 -0
  402. talkops/webhooks/providers/observability_itsm.py +275 -0
  403. talkops/webhooks/providers/pagerduty.py +213 -0
  404. talkops/webhooks/providers/sns.py +241 -0
  405. talkops/webhooks/security.py +204 -0
  406. talkops/webhooks/sinks.py +1137 -0
  407. talkops_ai-0.3.0.dist-info/METADATA +271 -0
  408. talkops_ai-0.3.0.dist-info/RECORD +411 -0
  409. talkops_ai-0.3.0.dist-info/WHEEL +4 -0
  410. talkops_ai-0.3.0.dist-info/entry_points.txt +3 -0
  411. talkops_ai-0.3.0.dist-info/licenses/LICENSE +175 -0
talkops/__init__.py ADDED
@@ -0,0 +1,35 @@
1
+ # Copyright talkops.ai
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """TalkOps — Autonomous CLI-first AI agent for AWS Infrastructure and Applications."""
16
+
17
+ import logging
18
+ import os
19
+
20
+ # Silence C++ gRPC / Abseil logs (e.g., ev_poll_posix.cc fork FD warnings from google-vertexai)
21
+ # that write directly to OS file descriptor 2 and corrupt the Textual TUI screen.
22
+ os.environ.setdefault("GRPC_VERBOSITY", "NONE")
23
+ os.environ.setdefault("GRPC_ENABLE_FORK_SUPPORT", "0")
24
+ os.environ.setdefault("ABSL_MIN_LOG_LEVEL", "3")
25
+ os.environ.setdefault("TF_CPP_MIN_LOG_LEVEL", "3")
26
+
27
+ from talkops._debug import configure_debug_logging
28
+ from talkops._debug_buffer import install_log_buffer
29
+ from talkops._version import __version__
30
+
31
+ _package_logger = logging.getLogger(__name__)
32
+ install_log_buffer(_package_logger)
33
+ configure_debug_logging(_package_logger)
34
+
35
+ __all__ = ["__version__"]
talkops/__main__.py ADDED
@@ -0,0 +1,20 @@
1
+ # Copyright talkops.ai
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """Entry point for python -m talkops."""
16
+
17
+ from talkops.cli.main import cli_main
18
+
19
+ if __name__ == "__main__":
20
+ cli_main()
talkops/_constants.py ADDED
@@ -0,0 +1,70 @@
1
+ # Copyright talkops.ai
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """Global constant definitions for talkops."""
16
+
17
+ from pathlib import Path
18
+
19
+ DEFAULT_AGENT_NAME = "talkops"
20
+ DEFAULT_ASSISTANT_ID = "talkops"
21
+
22
+ # App directories
23
+ USER_HOME = Path.home()
24
+ TALKOPS_HOME = USER_HOME / ".talkops"
25
+ STATE_DIR = TALKOPS_HOME / ".state"
26
+ SESSIONS_DB_NAME = "sessions.db"
27
+ SESSIONS_DB_PATH = STATE_DIR / SESSIONS_DB_NAME
28
+ SERVER_RUNTIME_DIR = STATE_DIR / "server"
29
+ CONFIG_FILE_PATH = TALKOPS_HOME / "config.toml"
30
+ PLUGINS_CACHE_DIR = TALKOPS_HOME / "plugins" / "cache"
31
+
32
+ # Environment variables prefixes
33
+ ENV_PREFIX = "TALKOPS_"
34
+ SERVER_ENV_PREFIX = "TALKOPS_SERVER_"
35
+
36
+ # Tooling and shell execution
37
+ SHELL_TIMEOUT_SECONDS = 60
38
+ DEFAULT_PORT = 0 # Ephemeral
39
+ DEFAULT_CONTROL_PLANE_URL = "https://console.talkops.ai"
40
+
41
+ # Large tool results prefix (used by rubrics and compaction)
42
+ LARGE_TOOL_RESULTS_PREFIX = "/large_tool_results/"
43
+ SYSTEM_MESSAGE_PREFIX = "[System Message]"
44
+
45
+ FS_TOOL_NAMES = frozenset(
46
+ {"ls", "read_file", "write_file", "edit_file", "delete", "glob", "grep", "execute", "run_command"}
47
+ )
48
+
49
+ READONLY_FS_TOOLS = frozenset(
50
+ {
51
+ "ls",
52
+ "read_file",
53
+ "glob",
54
+ "grep",
55
+ "view_file",
56
+ "list_dir",
57
+ "dir_list",
58
+ "grep_search",
59
+ "file_search",
60
+ "read_url_content",
61
+ "fetch_web_page",
62
+ "search_web",
63
+ "get_goal",
64
+ "get_rubric",
65
+ "update_goal",
66
+ "write_todos",
67
+ "cloud_list_contexts",
68
+ "cloud_get_status",
69
+ }
70
+ )
talkops/_debug.py ADDED
@@ -0,0 +1,159 @@
1
+ # Copyright talkops.ai
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """Shared debug-logging configuration for verbose file-based tracing.
16
+
17
+ When the `TALKOPS_DEBUG` environment variable is set, modules that handle
18
+ streaming or remote communication can enable detailed file-based logging. This
19
+ helper centralizes the setup so the env-var name, file path, and format are
20
+ defined in one place.
21
+ """
22
+
23
+ from __future__ import annotations
24
+
25
+ import logging
26
+ import os
27
+ import sys
28
+ from pathlib import Path
29
+
30
+ from talkops.config.env_vars import (
31
+ DEBUG,
32
+ DEBUG_FILE,
33
+ DEFAULT_DEBUG_FILE,
34
+ LOG_LEVEL,
35
+ is_env_truthy,
36
+ )
37
+ from talkops.utils.logger import get_logger
38
+
39
+ _DEBUG_HANDLER_ATTR = "_talkops_debug_handler"
40
+ LOG_LEVELS = {
41
+ "DEBUG": logging.DEBUG,
42
+ "INFO": logging.INFO,
43
+ "WARNING": logging.WARNING,
44
+ "ERROR": logging.ERROR,
45
+ "CRITICAL": logging.CRITICAL,
46
+ }
47
+ """Canonical level-name to `logging` level mapping.
48
+
49
+ The single source of truth for level names and their numeric values, shared with
50
+ the Debug Console's level filter so severity ordering is never re-derived from
51
+ hardcoded integers.
52
+ """
53
+
54
+ logger = get_logger(__name__)
55
+
56
+
57
+ def resolve_log_level(*, debug_enabled: bool | None = None) -> int:
58
+ """Resolve the configured runtime logging level.
59
+
60
+ Args:
61
+ debug_enabled: Whether `TALKOPS_DEBUG` is truthy. When omitted,
62
+ the current environment is checked.
63
+
64
+ Returns:
65
+ A standard `logging` level integer. Defaults to `DEBUG` when debug file
66
+ logging is enabled and `INFO` otherwise.
67
+ """
68
+ if debug_enabled is None:
69
+ debug_enabled = is_env_truthy(DEBUG)
70
+ fallback = logging.DEBUG if debug_enabled else logging.INFO
71
+ raw = os.environ.get(LOG_LEVEL)
72
+ if raw is None or not raw.strip():
73
+ return fallback
74
+ level = LOG_LEVELS.get(raw.strip().upper())
75
+ if level is not None:
76
+ return level
77
+ valid = ", ".join(LOG_LEVELS)
78
+ message = f"ignoring invalid {LOG_LEVEL}={raw!r}; expected one of {valid}"
79
+ # stderr for headless / pre-TUI visibility; the logger so it also lands in
80
+ # the always-on in-memory buffer and surfaces in the Debug Console.
81
+ print(f"Warning: {message}", file=sys.stderr) # noqa: T201
82
+ logger.warning("%s", message)
83
+ return fallback
84
+
85
+
86
+ def configure_debug_logging(target: logging.Logger) -> None:
87
+ """Attach a file handler to *target* when `TALKOPS_DEBUG` is set.
88
+
89
+ Intended to be called once on the `talkops` package logger; child
90
+ module loggers reach the same file via propagation, so individual modules do
91
+ not configure logging themselves.
92
+
93
+ The log file defaults to `DEFAULT_DEBUG_FILE` but can be overridden with
94
+ `TALKOPS_DEBUG_FILE`. The handler appends (`mode='a'`) so logs
95
+ are preserved across separate process runs. Calling this again with the same
96
+ resolved path is a no-op: the existing tagged handler is reused rather than
97
+ stacking duplicates. If the resolved path changes, the stale handler is
98
+ closed and replaced.
99
+
100
+ Does nothing when `TALKOPS_DEBUG` is not truthy (see `is_env_truthy`).
101
+
102
+ Args:
103
+ target: Logger to configure.
104
+ """
105
+ debug_enabled = is_env_truthy(DEBUG)
106
+ level = resolve_log_level(debug_enabled=debug_enabled)
107
+ target.setLevel(level)
108
+
109
+ if not debug_enabled:
110
+ return
111
+
112
+ debug_path = Path(os.environ.get(DEBUG_FILE, DEFAULT_DEBUG_FILE))
113
+ for existing in list(target.handlers):
114
+ if not (
115
+ isinstance(existing, logging.FileHandler)
116
+ and getattr(existing, _DEBUG_HANDLER_ATTR, False)
117
+ ):
118
+ continue
119
+ if Path(existing.baseFilename) == debug_path:
120
+ # Already configured for this path; reuse rather than duplicate.
121
+ existing.setLevel(level)
122
+ return
123
+ # The debug path changed; drop the stale handler before re-attaching so
124
+ # we don't leak its file descriptor or fan logs out to two files.
125
+ target.removeHandler(existing)
126
+ existing.close()
127
+
128
+ try:
129
+ handler = logging.FileHandler(str(debug_path), mode="a")
130
+ except OSError as exc:
131
+ print( # noqa: T201
132
+ f"Warning: could not open debug log file {debug_path}: {exc}",
133
+ file=sys.stderr,
134
+ )
135
+ return
136
+ setattr(handler, _DEBUG_HANDLER_ATTR, True)
137
+ handler.setLevel(level)
138
+ handler.setFormatter(logging.Formatter("%(asctime)s %(name)s %(message)s"))
139
+ target.addHandler(handler)
140
+
141
+
142
+ def installed_debug_log_path() -> Path | None:
143
+ """Return the path of the active debug log file, or `None` if not logging.
144
+
145
+ Reflects the file handler actually attached by `configure_debug_logging`,
146
+ not the current `TALKOPS_DEBUG` env value. The two diverge when the
147
+ variable is set after import — e.g. via a project/global `.env` loaded during
148
+ settings bootstrap — in which case the variable reads truthy but no handler
149
+ was installed and no log file exists. Callers that surface "full error in
150
+ <path>" hints must use this rather than the env var to avoid pointing users
151
+ at a file that was never created.
152
+ """
153
+ package_logger = logging.getLogger(__package__ or "talkops")
154
+ for handler in package_logger.handlers:
155
+ if isinstance(handler, logging.FileHandler) and getattr(
156
+ handler, _DEBUG_HANDLER_ATTR, False
157
+ ):
158
+ return Path(handler.baseFilename)
159
+ return None
@@ -0,0 +1,264 @@
1
+ # Copyright talkops.ai
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ r"""In-memory ring buffer of recent log records for the in-app Debug Console.
16
+
17
+ A lightweight `logging.Handler` keeps the most recent structured log records in
18
+ bounded per-level `deque`s so the Debug Console (`Ctrl+\`) can show a live tail
19
+ without requiring the opt-in file logging from `_debug.configure_debug_logging`.
20
+ Partitioning retention by level means a burst of `DEBUG` output cannot evict the
21
+ rarer `INFO`/`WARNING`/`ERROR` records the level filter needs. The handler is
22
+ installed once on the `talkops` package logger (see `__init__.py`); child
23
+ module loggers reach it via propagation.
24
+
25
+ Installation is negligible, and each emitted record only appends a structured
26
+ record to a bounded `deque`, so the buffer is cheap enough to keep always on.
27
+ """
28
+
29
+ from __future__ import annotations
30
+
31
+ import logging
32
+ import operator
33
+ import os
34
+ from collections import deque
35
+ from dataclasses import dataclass
36
+
37
+ from talkops._debug import LOG_LEVELS
38
+ from talkops.config.env_vars import LOG_LEVEL
39
+
40
+ DEFAULT_CAPACITY = 1000
41
+ """Maximum number of records retained per level in the ring buffer."""
42
+
43
+ _FALLBACK_LEVEL_BUCKET = "_other"
44
+ """Retention bucket for records whose level name is not in `LOG_LEVELS`.
45
+
46
+ Non-standard level names are retained here rather than discarded at
47
+ classification time, and sharing one bucket keeps the number of per-level deques
48
+ bounded no matter how many distinct custom names appear. Like every bucket, this
49
+ one is bounded to *capacity* and evicts oldest-first, so — unlike the standard
50
+ levels, which each get isolated retention — distinct custom levels compete for a
51
+ single budget and can evict one another."""
52
+
53
+ _DATE_FORMAT = "%H:%M:%S"
54
+ _FORMATTER = logging.Formatter(datefmt=_DATE_FORMAT)
55
+
56
+
57
+ def retention_bucket_for_level(level: str) -> str:
58
+ """Return the bounded retention bucket key for a log level name."""
59
+ return level if level in LOG_LEVELS else _FALLBACK_LEVEL_BUCKET
60
+
61
+
62
+ @dataclass(frozen=True, slots=True)
63
+ class InMemoryLogRecord:
64
+ """Structured log record retained by the in-memory debug buffer."""
65
+
66
+ timestamp: str
67
+ level: str
68
+ levelno: int
69
+ logger: str
70
+ message: str
71
+
72
+ @property
73
+ def plain_line(self) -> str:
74
+ """The record in the legacy plain-text debug-console format."""
75
+ return f"{self.timestamp} {self.level} {self.logger} {self.message}"
76
+
77
+
78
+ class InMemoryLogBuffer(logging.Handler):
79
+ """Logging handler retaining the most recent structured records in memory.
80
+
81
+ Retention is partitioned by level: each recognized level name (see
82
+ `LOG_LEVELS`) keeps its own bounded `deque` of *capacity* records, while
83
+ unrecognized names share the `_FALLBACK_LEVEL_BUCKET` deque. A burst of
84
+ high-volume records at one recognized level (typically `DEBUG`) therefore
85
+ cannot evict the rarer, higher-severity records at other recognized levels,
86
+ so the Debug Console's level filter can still surface them. Each retained
87
+ record is tagged with its monotonic emission sequence number so snapshots
88
+ stay chronologically ordered across levels.
89
+ """
90
+
91
+ def __init__(self, capacity: int = DEFAULT_CAPACITY) -> None:
92
+ """Create the handler with a bounded backing `deque` per level.
93
+
94
+ Args:
95
+ capacity: Maximum records to retain per level; oldest are dropped
96
+ first.
97
+
98
+ Raises:
99
+ ValueError: If *capacity* is less than 1. A zero-capacity buffer
100
+ would silently discard every record while `total_emitted` kept
101
+ climbing, so it is rejected at the boundary.
102
+ """
103
+ if capacity < 1:
104
+ msg = f"capacity must be >= 1, got {capacity}"
105
+ raise ValueError(msg)
106
+ super().__init__()
107
+ self._capacity = capacity
108
+ self._levels: dict[str, deque[tuple[int, InMemoryLogRecord]]] = {}
109
+ self._total = 0
110
+
111
+ def emit(self, record: logging.LogRecord) -> None:
112
+ """Append the structured *record* to its level's ring buffer."""
113
+ self.acquire()
114
+ try:
115
+ structured = self._make_record(record)
116
+ bucket = self._level_bucket(structured.level)
117
+ bucket.append((self._total, structured))
118
+ self._total += 1
119
+ except Exception: # noqa: BLE001 # never let logging crash the app
120
+ self.handleError(record)
121
+ finally:
122
+ self.release()
123
+
124
+ def _level_bucket(self, level: str) -> deque[tuple[int, InMemoryLogRecord]]:
125
+ """Return the retention deque for *level*, creating it on first use."""
126
+ key = retention_bucket_for_level(level)
127
+ bucket = self._levels.get(key)
128
+ if bucket is None:
129
+ bucket = deque(maxlen=self._capacity)
130
+ self._levels[key] = bucket
131
+ return bucket
132
+
133
+ @property
134
+ def total_emitted(self) -> int:
135
+ """Total records ever emitted (monotonic; survives buffer eviction)."""
136
+ self.acquire()
137
+ try:
138
+ return self._total
139
+ finally:
140
+ self.release()
141
+
142
+ def snapshot_records_since(self, index: int) -> tuple[list[InMemoryLogRecord], int]:
143
+ """Return retained structured records and the next absolute index.
144
+
145
+ Absolute indices are stable even as old records are evicted, so callers
146
+ can poll incrementally without re-reading records they already consumed.
147
+ Returning the records and the resume index together under the handler
148
+ lock prevents a concurrent append from being skipped between separate
149
+ reads.
150
+
151
+ Args:
152
+ index: Absolute emission index to start from.
153
+
154
+ Returns:
155
+ A tuple of the structured records from *index* onward that are still
156
+ retained, and the current total emitted count to resume from.
157
+ """
158
+ self.acquire()
159
+ try:
160
+ return self._records_since_unlocked(index), self._total
161
+ finally:
162
+ self.release()
163
+
164
+ def _records_since_unlocked(self, index: int) -> list[InMemoryLogRecord]:
165
+ """Return retained records from *index* while the handler lock is held.
166
+
167
+ Merges the per-level deques and restores chronological order using each
168
+ record's emission sequence number, so callers see one ordered tail even
169
+ though retention is partitioned by level.
170
+ """
171
+ tagged = [
172
+ entry
173
+ for bucket in self._levels.values()
174
+ for entry in bucket
175
+ if entry[0] >= index
176
+ ]
177
+ tagged.sort(key=operator.itemgetter(0))
178
+ return [record for _seq, record in tagged]
179
+
180
+ @staticmethod
181
+ def _make_record(record: logging.LogRecord) -> InMemoryLogRecord:
182
+ """Convert a standard logging record into a structured debug record.
183
+
184
+ Returns:
185
+ Structured record for display and filtering.
186
+ """
187
+ message = record.getMessage()
188
+ if record.exc_info:
189
+ if not record.exc_text:
190
+ record.exc_text = _FORMATTER.formatException(record.exc_info)
191
+ if record.exc_text:
192
+ message = f"{message}\n{record.exc_text}"
193
+ if record.stack_info:
194
+ message = f"{message}\n{_FORMATTER.formatStack(record.stack_info)}"
195
+ return InMemoryLogRecord(
196
+ timestamp=_FORMATTER.formatTime(record, _DATE_FORMAT),
197
+ level=record.levelname,
198
+ levelno=record.levelno,
199
+ logger=record.name,
200
+ message=message,
201
+ )
202
+
203
+
204
+ _buffer: InMemoryLogBuffer | None = None
205
+
206
+
207
+ def install_log_buffer(
208
+ target: logging.Logger, capacity: int = DEFAULT_CAPACITY
209
+ ) -> InMemoryLogBuffer:
210
+ """Attach the in-memory buffer handler to *target* (idempotent).
211
+
212
+ Lowers *target*'s level to at most `INFO` so the console shows a useful tail
213
+ even when `TALKOPS_DEBUG` is off; never raises the level. In
214
+ `__init__.py` this runs *before* `configure_debug_logging`, which then sets
215
+ the final level (honoring `TALKOPS_DEBUG` and
216
+ `TALKOPS_LOG_LEVEL`) over this `INFO` floor — so any startup warnings
217
+ `configure_debug_logging` emits are captured by the already-installed buffer.
218
+ On a fresh `NOTSET` logger the `NOTSET` branch forces `INFO` without
219
+ consulting `TALKOPS_LOG_LEVEL`; the `> INFO and no env` branch only
220
+ matters on reconfiguration (e.g. an `importlib.reload`), where it preserves
221
+ an explicit `TALKOPS_LOG_LEVEL` rather than clobbering it with `INFO`.
222
+
223
+ Lowering the level does not spill log output onto the terminal: because this
224
+ handler is present in the propagation chain, `Logger.callHandlers` finds a
225
+ handler (`found > 0`) and Python's `lastResort` stderr handler is never
226
+ consulted. The exception is an embedding process that attaches its own
227
+ `INFO`-or-lower handler to the root logger, which would then see the
228
+ propagated records.
229
+
230
+ Note: this runs as an import-time side effect (see `__init__.py`), so every
231
+ `import talkops` attaches the handler and may lower the package
232
+ logger's level to `INFO` for the lifetime of the process.
233
+
234
+ Args:
235
+ target: Logger to attach the buffer to (the package logger).
236
+ capacity: Maximum records to retain.
237
+
238
+ Returns:
239
+ The installed (or already-installed) buffer handler.
240
+ """
241
+ global _buffer # noqa: PLW0603 # module-level singleton accessor
242
+ for existing in target.handlers:
243
+ if isinstance(existing, InMemoryLogBuffer):
244
+ _buffer = existing
245
+ return existing
246
+
247
+ handler = InMemoryLogBuffer(capacity)
248
+ handler.setLevel(logging.DEBUG)
249
+ target.addHandler(handler)
250
+ if target.level == logging.NOTSET or (
251
+ target.level > logging.INFO and not os.environ.get(LOG_LEVEL)
252
+ ):
253
+ target.setLevel(logging.INFO)
254
+ _buffer = handler
255
+ return handler
256
+
257
+
258
+ def get_log_buffer() -> InMemoryLogBuffer | None:
259
+ """Return the installed buffer handler.
260
+
261
+ Returns:
262
+ The installed buffer handler, or `None` if not yet installed.
263
+ """
264
+ return _buffer