talkops-opscloud 0.3.0b1__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 (309) hide show
  1. opscloud/__init__.py +5 -0
  2. opscloud/__main__.py +6 -0
  3. opscloud/_constants.py +53 -0
  4. opscloud/_debug.py +145 -0
  5. opscloud/_debug_buffer.py +250 -0
  6. opscloud/_textual_patches.py +367 -0
  7. opscloud/_version.py +15 -0
  8. opscloud/agent/__init__.py +27 -0
  9. opscloud/agent/config.py +168 -0
  10. opscloud/agent/factory.py +1103 -0
  11. opscloud/approval_mode.py +44 -0
  12. opscloud/backend/__init__.py +49 -0
  13. opscloud/backend/composite.py +89 -0
  14. opscloud/backend/local.py +183 -0
  15. opscloud/backend/registry.py +79 -0
  16. opscloud/backend/sandbox_config.py +107 -0
  17. opscloud/backend/sandbox_factory.py +432 -0
  18. opscloud/built_in_skills/remember/SKILL.md +124 -0
  19. opscloud/built_in_skills/skill-creator/SKILL.md +348 -0
  20. opscloud/built_in_skills/skill-creator/scripts/init_skill.py +371 -0
  21. opscloud/built_in_skills/skill-creator/scripts/quick_validate.py +165 -0
  22. opscloud/cli/__init__.py +1 -0
  23. opscloud/cli/commands/__init__.py +15 -0
  24. opscloud/cli/commands/auth.py +45 -0
  25. opscloud/cli/commands/doctor.py +100 -0
  26. opscloud/cli/commands/mcp.py +137 -0
  27. opscloud/cli/commands/threads.py +51 -0
  28. opscloud/cli/interactive.py +154 -0
  29. opscloud/cli/main.py +903 -0
  30. opscloud/cli/non_interactive.py +425 -0
  31. opscloud/cli/server_manager.py +58 -0
  32. opscloud/commands/__init__.py +19 -0
  33. opscloud/commands/_base.py +110 -0
  34. opscloud/commands/_guards.py +52 -0
  35. opscloud/commands/_router.py +146 -0
  36. opscloud/commands/_types.py +36 -0
  37. opscloud/commands/core/__init__.py +47 -0
  38. opscloud/commands/core/auth.py +94 -0
  39. opscloud/commands/core/bug.py +46 -0
  40. opscloud/commands/core/clear.py +106 -0
  41. opscloud/commands/core/cloud.py +185 -0
  42. opscloud/commands/core/compact.py +128 -0
  43. opscloud/commands/core/config_cmd.py +120 -0
  44. opscloud/commands/core/context.py +220 -0
  45. opscloud/commands/core/cost.py +44 -0
  46. opscloud/commands/core/doctor.py +535 -0
  47. opscloud/commands/core/effort.py +108 -0
  48. opscloud/commands/core/exit_cmd.py +41 -0
  49. opscloud/commands/core/fast.py +148 -0
  50. opscloud/commands/core/help_cmd.py +94 -0
  51. opscloud/commands/core/mcp.py +134 -0
  52. opscloud/commands/core/model.py +109 -0
  53. opscloud/commands/core/permissions.py +196 -0
  54. opscloud/commands/core/plugins.py +92 -0
  55. opscloud/commands/core/pool.py +108 -0
  56. opscloud/commands/core/resume.py +97 -0
  57. opscloud/commands/core/skills.py +178 -0
  58. opscloud/commands/power/__init__.py +51 -0
  59. opscloud/commands/power/agents.py +98 -0
  60. opscloud/commands/power/btw.py +85 -0
  61. opscloud/commands/power/copy.py +97 -0
  62. opscloud/commands/power/goal.py +548 -0
  63. opscloud/commands/power/loop.py +295 -0
  64. opscloud/commands/power/memory.py +287 -0
  65. opscloud/commands/power/review.py +152 -0
  66. opscloud/commands/power/rubric.py +287 -0
  67. opscloud/commands/power/runtime.py +321 -0
  68. opscloud/commands/power/skill_creator.py +70 -0
  69. opscloud/commands/power/skill_invoke.py +165 -0
  70. opscloud/commands/power/tasks.py +209 -0
  71. opscloud/commands/power/trace.py +117 -0
  72. opscloud/commands/power/ui_toggles.py +135 -0
  73. opscloud/commands/power/version.py +52 -0
  74. opscloud/commands/registry.py +176 -0
  75. opscloud/config/__init__.py +114 -0
  76. opscloud/config/adapters/__init__.py +5 -0
  77. opscloud/config/adapters/postgres.py +776 -0
  78. opscloud/config/adapters/sqlite.py +769 -0
  79. opscloud/config/aws.py +248 -0
  80. opscloud/config/cloud_profiles.py +437 -0
  81. opscloud/config/env_vars.py +81 -0
  82. opscloud/config/langsmith.py +319 -0
  83. opscloud/config/manifest.py +817 -0
  84. opscloud/config/metadata.py +205 -0
  85. opscloud/config/paths.py +604 -0
  86. opscloud/config/plugins.py +130 -0
  87. opscloud/config/settings.py +834 -0
  88. opscloud/config/store.py +453 -0
  89. opscloud/config/store_factory.py +97 -0
  90. opscloud/config/toml_config.py +562 -0
  91. opscloud/editor.py +173 -0
  92. opscloud/exceptions.py +65 -0
  93. opscloud/file_ops.py +217 -0
  94. opscloud/hooks/__init__.py +139 -0
  95. opscloud/hooks/env.py +44 -0
  96. opscloud/hooks/interrupt.py +121 -0
  97. opscloud/hooks/models/__init__.py +109 -0
  98. opscloud/hooks/models/adapters.py +19 -0
  99. opscloud/hooks/models/config.py +79 -0
  100. opscloud/hooks/models/domain.py +434 -0
  101. opscloud/hooks/models/transport.py +37 -0
  102. opscloud/hooks/tools.py +231 -0
  103. opscloud/input.py +48 -0
  104. opscloud/integrations/__init__.py +80 -0
  105. opscloud/integrations/base.py +153 -0
  106. opscloud/integrations/content_filter.py +119 -0
  107. opscloud/integrations/event_bus.py +480 -0
  108. opscloud/integrations/hooks.py +238 -0
  109. opscloud/integrations/identity.py +181 -0
  110. opscloud/integrations/notifications.py +134 -0
  111. opscloud/integrations/stream_bridge.py +397 -0
  112. opscloud/integrations/thread_store.py +81 -0
  113. opscloud/json_types.py +20 -0
  114. opscloud/mcp/__init__.py +57 -0
  115. opscloud/mcp/config.py +203 -0
  116. opscloud/mcp/discovery.py +229 -0
  117. opscloud/mcp/mcp_info.py +109 -0
  118. opscloud/mcp/middleware.py +102 -0
  119. opscloud/mcp/preload.py +505 -0
  120. opscloud/mcp/raw_config.py +149 -0
  121. opscloud/mcp/semantic_profiler.py +305 -0
  122. opscloud/mcp/session_manager.py +727 -0
  123. opscloud/mcp/trust.py +105 -0
  124. opscloud/memory/__init__.py +27 -0
  125. opscloud/memory/branch.py +61 -0
  126. opscloud/memory/guard.py +19 -0
  127. opscloud/memory/onboarding.py +120 -0
  128. opscloud/memory/registry.py +134 -0
  129. opscloud/memory/store.py +223 -0
  130. opscloud/middleware/__init__.py +106 -0
  131. opscloud/middleware/_repository_bounds.py +459 -0
  132. opscloud/middleware/ask_user.py +152 -0
  133. opscloud/middleware/auto_mode.py +60 -0
  134. opscloud/middleware/auto_mode_hitl.py +2434 -0
  135. opscloud/middleware/compaction.py +566 -0
  136. opscloud/middleware/configurable_model.py +233 -0
  137. opscloud/middleware/cost_tracking.py +1021 -0
  138. opscloud/middleware/glm_stall_recovery.py +109 -0
  139. opscloud/middleware/goal_criteria.py +1234 -0
  140. opscloud/middleware/goal_state_notice.py +712 -0
  141. opscloud/middleware/goal_tools.py +407 -0
  142. opscloud/middleware/headless_mcp_guard.py +88 -0
  143. opscloud/middleware/jev_model_router.py +1018 -0
  144. opscloud/middleware/local_context.py +460 -0
  145. opscloud/middleware/mcp_context.py +151 -0
  146. opscloud/middleware/mcp_middleware.py +146 -0
  147. opscloud/middleware/memory_guard.py +393 -0
  148. opscloud/middleware/model_retry.py +205 -0
  149. opscloud/middleware/registry.py +137 -0
  150. opscloud/middleware/reliable_rubric.py +709 -0
  151. opscloud/middleware/resume_state.py +91 -0
  152. opscloud/middleware/server_hooks.py +1189 -0
  153. opscloud/middleware/shell_allow_list.py +90 -0
  154. opscloud/middleware/skills.py +382 -0
  155. opscloud/middleware/subagent_artifacts.py +84 -0
  156. opscloud/middleware/subagent_telemetry.py +261 -0
  157. opscloud/middleware/subagents.py +243 -0
  158. opscloud/middleware/tool_filter.py +384 -0
  159. opscloud/middleware/unified_system_message.py +62 -0
  160. opscloud/model/__init__.py +37 -0
  161. opscloud/model/config.py +2992 -0
  162. opscloud/model/factory.py +477 -0
  163. opscloud/model/pool.py +459 -0
  164. opscloud/model/reasoning.py +282 -0
  165. opscloud/offload.py +173 -0
  166. opscloud/output.py +64 -0
  167. opscloud/plugins/__init__.py +189 -0
  168. opscloud/plugins/_json.py +22 -0
  169. opscloud/plugins/adapters/__init__.py +13 -0
  170. opscloud/plugins/adapters/agents.py +112 -0
  171. opscloud/plugins/adapters/commands.py +190 -0
  172. opscloud/plugins/adapters/mcp.py +363 -0
  173. opscloud/plugins/adapters/skills.py +132 -0
  174. opscloud/plugins/commands_cli.py +541 -0
  175. opscloud/plugins/discovery.py +512 -0
  176. opscloud/plugins/manifest.py +335 -0
  177. opscloud/plugins/marketplace.py +893 -0
  178. opscloud/plugins/models.py +334 -0
  179. opscloud/plugins/project_plugins.py +317 -0
  180. opscloud/plugins/protocol.py +31 -0
  181. opscloud/plugins/store.py +905 -0
  182. opscloud/plugins/substitution.py +122 -0
  183. opscloud/project_utils.py +145 -0
  184. opscloud/prompts/__init__.py +37 -0
  185. opscloud/prompts/system.py +483 -0
  186. opscloud/prompts/templates/system_prompt.md +166 -0
  187. opscloud/prompts/types.py +54 -0
  188. opscloud/rubrics/__init__.py +42 -0
  189. opscloud/rubrics/evaluator.py +404 -0
  190. opscloud/rubrics/evidence_extractor.py +229 -0
  191. opscloud/rubrics/generator.py +239 -0
  192. opscloud/rubrics/jev_compiler.py +175 -0
  193. opscloud/rubrics/jev_grader.py +297 -0
  194. opscloud/rubrics/middleware.py +8 -0
  195. opscloud/schema/__init__.py +107 -0
  196. opscloud/schema/interrupts.py +981 -0
  197. opscloud/security/__init__.py +91 -0
  198. opscloud/security/approval_mode.py +528 -0
  199. opscloud/security/approval_mode_source.py +230 -0
  200. opscloud/security/cli_ast_evaluator.py +552 -0
  201. opscloud/security/jev_classifier.py +651 -0
  202. opscloud/security/shell_safety.py +340 -0
  203. opscloud/security/unicode_security.py +439 -0
  204. opscloud/security/url_validation.py +160 -0
  205. opscloud/server/__init__.py +13 -0
  206. opscloud/server/_server_config.py +158 -0
  207. opscloud/server/server.py +242 -0
  208. opscloud/server/server_graph.py +93 -0
  209. opscloud/skills/__init__.py +91 -0
  210. opscloud/skills/commands.py +1099 -0
  211. opscloud/skills/invocation.py +200 -0
  212. opscloud/skills/load.py +388 -0
  213. opscloud/skills/loader.py +23 -0
  214. opscloud/skills/merge.py +65 -0
  215. opscloud/skills/registry.py +263 -0
  216. opscloud/skills/sources.py +174 -0
  217. opscloud/skills/trust.py +417 -0
  218. opscloud/state/__init__.py +142 -0
  219. opscloud/state/base.py +154 -0
  220. opscloud/state/cloud_context.py +262 -0
  221. opscloud/state/goal_channels.py +124 -0
  222. opscloud/state/goal_state_limits.py +175 -0
  223. opscloud/state/resume_state.py +58 -0
  224. opscloud/state/service_context.py +281 -0
  225. opscloud/state/session.py +957 -0
  226. opscloud/state/state_migration.py +86 -0
  227. opscloud/subagents/__init__.py +30 -0
  228. opscloud/subagents/loader.py +331 -0
  229. opscloud/subagents/subagents_parser.py +117 -0
  230. opscloud/subagents/types.py +25 -0
  231. opscloud/tools/__init__.py +36 -0
  232. opscloud/tools/catalog.py +37 -0
  233. opscloud/tools/display.py +24 -0
  234. opscloud/tools/fetch_url.py +176 -0
  235. opscloud/tools/goal_tools.py +423 -0
  236. opscloud/tools/registry.py +105 -0
  237. opscloud/tools/thread.py +32 -0
  238. opscloud/tools/web_search.py +215 -0
  239. opscloud/ui/__init__.py +119 -0
  240. opscloud/ui/app.py +5400 -0
  241. opscloud/ui/app.tcss +479 -0
  242. opscloud/ui/clipboard.py +147 -0
  243. opscloud/ui/command_registry.py +482 -0
  244. opscloud/ui/message_store.py +152 -0
  245. opscloud/ui/permission_store.py +360 -0
  246. opscloud/ui/preferences.py +113 -0
  247. opscloud/ui/prompt_manager.py +96 -0
  248. opscloud/ui/remote_client.py +505 -0
  249. opscloud/ui/textual_adapter.py +1269 -0
  250. opscloud/ui/theme.py +728 -0
  251. opscloud/ui/ui_help.py +415 -0
  252. opscloud/ui/widgets/__init__.py +383 -0
  253. opscloud/ui/widgets/_ask_user_types.py +81 -0
  254. opscloud/ui/widgets/_copy_spans.py +52 -0
  255. opscloud/ui/widgets/_inline_prompt.py +290 -0
  256. opscloud/ui/widgets/_js_eval_display.py +139 -0
  257. opscloud/ui/widgets/_links.py +175 -0
  258. opscloud/ui/widgets/_tool_stream.py +308 -0
  259. opscloud/ui/widgets/agent_selector.py +297 -0
  260. opscloud/ui/widgets/approval.py +741 -0
  261. opscloud/ui/widgets/ask_user.py +539 -0
  262. opscloud/ui/widgets/auth.py +695 -0
  263. opscloud/ui/widgets/auth_manager.py +214 -0
  264. opscloud/ui/widgets/auto_mode_notice.py +146 -0
  265. opscloud/ui/widgets/autocomplete.py +709 -0
  266. opscloud/ui/widgets/chat_input.py +805 -0
  267. opscloud/ui/widgets/cloud_selector.py +528 -0
  268. opscloud/ui/widgets/config_manager.py +652 -0
  269. opscloud/ui/widgets/debug_console.py +1269 -0
  270. opscloud/ui/widgets/devops_renderers.py +184 -0
  271. opscloud/ui/widgets/diff.py +237 -0
  272. opscloud/ui/widgets/effort_selector.py +166 -0
  273. opscloud/ui/widgets/goal_review.py +612 -0
  274. opscloud/ui/widgets/goal_status.py +57 -0
  275. opscloud/ui/widgets/infra_panel.py +141 -0
  276. opscloud/ui/widgets/install_confirm.py +114 -0
  277. opscloud/ui/widgets/loading.py +170 -0
  278. opscloud/ui/widgets/mcp_viewer.py +1204 -0
  279. opscloud/ui/widgets/messages.py +4461 -0
  280. opscloud/ui/widgets/model_selector.py +863 -0
  281. opscloud/ui/widgets/notification_center.py +108 -0
  282. opscloud/ui/widgets/notification_settings.py +119 -0
  283. opscloud/ui/widgets/operation_card.py +106 -0
  284. opscloud/ui/widgets/permissions_manager.py +667 -0
  285. opscloud/ui/widgets/plugin_manager.py +1212 -0
  286. opscloud/ui/widgets/pool_selector.py +376 -0
  287. opscloud/ui/widgets/preamble.py +53 -0
  288. opscloud/ui/widgets/skills_viewer.py +432 -0
  289. opscloud/ui/widgets/status.py +1037 -0
  290. opscloud/ui/widgets/subagent_panel.py +927 -0
  291. opscloud/ui/widgets/theme_selector.py +232 -0
  292. opscloud/ui/widgets/thread_selector.py +358 -0
  293. opscloud/ui/widgets/toast.py +31 -0
  294. opscloud/ui/widgets/tool_display.py +325 -0
  295. opscloud/ui/widgets/tool_renderers.py +234 -0
  296. opscloud/ui/widgets/tool_widgets.py +278 -0
  297. opscloud/ui/widgets/welcome.py +421 -0
  298. opscloud/ui/widgets/welcome_popup.py +102 -0
  299. opscloud/utils/__init__.py +24 -0
  300. opscloud/utils/cost_estimation.py +169 -0
  301. opscloud/utils/git.py +390 -0
  302. opscloud/utils/logger.py +571 -0
  303. opscloud/utils/session_stats.py +115 -0
  304. opscloud/utils/startup_error.py +37 -0
  305. talkops_opscloud-0.3.0b1.dist-info/METADATA +449 -0
  306. talkops_opscloud-0.3.0b1.dist-info/RECORD +309 -0
  307. talkops_opscloud-0.3.0b1.dist-info/WHEEL +4 -0
  308. talkops_opscloud-0.3.0b1.dist-info/entry_points.txt +2 -0
  309. talkops_opscloud-0.3.0b1.dist-info/licenses/LICENSE +175 -0
opscloud/cli/main.py ADDED
@@ -0,0 +1,903 @@
1
+ """Main CLI entry point and argument parser for OpsCloud.
2
+
3
+ Routes between interactive TUI mode (default), subcommands (doctor, auth,
4
+ threads, mcp, plugin, skill), and non-interactive headless mode
5
+ (-p / -n / positional prompt / piped stdin).
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import argparse
11
+ import json
12
+ import os
13
+ import sys
14
+ from pathlib import Path
15
+ from typing import Any, overload
16
+
17
+ from opscloud._version import __version__
18
+ from opscloud.approval_mode import ApprovalMode
19
+ from opscloud.cli.commands import (
20
+ run_auth_command,
21
+ run_doctor_command,
22
+ run_mcp_command,
23
+ run_threads_command,
24
+ setup_mcp_parser,
25
+ )
26
+ from opscloud.cli.interactive import run_interactive
27
+ from opscloud.cli.non_interactive import run_non_interactive
28
+ from opscloud.output import OutputFormat, add_json_output_arg
29
+ from opscloud.state.goal_state_limits import validate_rubric
30
+ from opscloud.utils.logger import get_logger
31
+
32
+ logger = get_logger(__name__)
33
+
34
+
35
+ # ── Argument Types ───────────────────────────────────────
36
+
37
+
38
+ def positive_int(value: str) -> int:
39
+ """Validate positive integer arguments (> 0)."""
40
+ try:
41
+ ivalue = int(value)
42
+ except ValueError as exc:
43
+ raise argparse.ArgumentTypeError(f"{value!r} is not a valid integer") from exc
44
+ if ivalue <= 0:
45
+ raise argparse.ArgumentTypeError(f"{value!r} must be greater than 0")
46
+ return ivalue
47
+
48
+
49
+ def non_negative_int(value: str) -> int:
50
+ """Validate non-negative integer arguments (>= 0)."""
51
+ try:
52
+ ivalue = int(value)
53
+ except ValueError as exc:
54
+ raise argparse.ArgumentTypeError(f"{value!r} is not a valid integer") from exc
55
+ if ivalue < 0:
56
+ raise argparse.ArgumentTypeError(f"{value!r} must be non-negative")
57
+ return ivalue
58
+
59
+
60
+ def shell_allow_list_arg(value: str) -> list[str]:
61
+ """Parse comma-separated list of allowed shell commands."""
62
+ from opscloud.config.settings import parse_shell_allow_list
63
+
64
+ parsed = parse_shell_allow_list(value)
65
+ return parsed or []
66
+
67
+
68
+ # ── Rubric Resolution ────────────────────────────────────
69
+
70
+
71
+ @overload
72
+ def _resolve_rubric_text(rubric: None) -> None: ...
73
+
74
+
75
+ @overload
76
+ def _resolve_rubric_text(rubric: str) -> str: ...
77
+
78
+
79
+ def _resolve_rubric_text(rubric: str | None) -> str | None:
80
+ """Resolve the rubric from `--rubric` into one string.
81
+
82
+ `--rubric` accepts literal text, or `@path` to read a file. File paths
83
+ may be absolute, relative to the process working directory, or `~`-expanded.
84
+ """
85
+ if rubric is None:
86
+ return None
87
+
88
+ if rubric.startswith("@"):
89
+ path = rubric[1:]
90
+ try:
91
+ text = Path(path).expanduser().read_text(encoding="utf-8")
92
+ except (OSError, UnicodeError) as exc:
93
+ msg = f"Could not read rubric file {path!r}: {exc}."
94
+ raise ValueError(msg) from exc
95
+ if not text.strip():
96
+ msg = f"Rubric file {path!r} is empty."
97
+ raise ValueError(msg)
98
+ resolved = text.strip()
99
+ validate_rubric(resolved)
100
+ return resolved
101
+
102
+ if not rubric.strip():
103
+ msg = "--rubric must not be empty."
104
+ raise ValueError(msg)
105
+ resolved = rubric.strip()
106
+ validate_rubric(resolved)
107
+ return resolved
108
+
109
+
110
+ # ── Stdin detection & piping ─────────────────────────────
111
+
112
+
113
+ def _apply_stdin_pipe(args: argparse.Namespace) -> None:
114
+ """Read piped stdin and merge it into the parsed CLI arguments."""
115
+ explicit_stdin = getattr(args, "stdin", False)
116
+ if sys.stdin is None:
117
+ if explicit_stdin:
118
+ print("Error: --stdin was passed but stdin is not available.", file=sys.stderr)
119
+ sys.exit(1)
120
+ return
121
+
122
+ try:
123
+ is_tty = sys.stdin.isatty()
124
+ except (ValueError, OSError):
125
+ if explicit_stdin:
126
+ print("Error: --stdin was passed but stdin state could not be determined.", file=sys.stderr)
127
+ sys.exit(1)
128
+ return
129
+
130
+ if is_tty:
131
+ if explicit_stdin:
132
+ print(
133
+ "Error: --stdin was passed but stdin is a terminal. Pipe input or pass a prompt directly.",
134
+ file=sys.stderr,
135
+ )
136
+ sys.exit(1)
137
+ return
138
+
139
+ max_stdin_bytes = 10 * 1024 * 1024 # 10 MiB
140
+ try:
141
+ stdin_text = sys.stdin.read(max_stdin_bytes + 1)
142
+ except UnicodeDecodeError:
143
+ print("Error: Could not read piped input — ensure the input is valid text", file=sys.stderr)
144
+ sys.exit(1)
145
+ except (OSError, ValueError) as exc:
146
+ if not explicit_stdin or "pytest" in str(exc).lower():
147
+ return
148
+ print(f"Error: Failed to read piped input: {exc}", file=sys.stderr)
149
+ sys.exit(1)
150
+
151
+ if len(stdin_text) > max_stdin_bytes:
152
+ print(f"Error: Piped input exceeds {max_stdin_bytes // (1024 * 1024)} MiB limit.", file=sys.stderr)
153
+ sys.exit(1)
154
+
155
+ stdin_text = stdin_text.strip()
156
+ if not stdin_text:
157
+ return
158
+
159
+ if getattr(args, "prompt", None):
160
+ args.prompt = f"{stdin_text}\n\n{args.prompt}"
161
+ elif getattr(args, "initial_prompt", None) is not None:
162
+ if args.initial_prompt:
163
+ args.initial_prompt = f"{stdin_text}\n\n{args.initial_prompt}"
164
+ else:
165
+ args.initial_prompt = stdin_text
166
+ elif getattr(args, "initial_skill", None) and not explicit_stdin:
167
+ args.initial_prompt = stdin_text
168
+ else:
169
+ args.prompt = stdin_text
170
+
171
+ # Restore terminal fd for interactive mode if possible
172
+ try:
173
+ tty_fd = os.open("/dev/tty", os.O_RDONLY)
174
+ os.dup2(tty_fd, 0)
175
+ os.close(tty_fd)
176
+ except OSError:
177
+ pass
178
+
179
+
180
+ # ── Approval Mode Resolution ─────────────────────────────
181
+
182
+
183
+ def _resolve_approval_mode(args: argparse.Namespace) -> ApprovalMode:
184
+ """Resolve flags into typed ApprovalMode."""
185
+ if getattr(args, "smart", False):
186
+ return ApprovalMode.SMART
187
+ if getattr(args, "auto_approve", False):
188
+ return ApprovalMode.AUTO
189
+ raw = getattr(args, "approval_mode", None)
190
+ if raw:
191
+ if raw.lower() in ("smart", "s", "jev"):
192
+ return ApprovalMode.SMART
193
+ if raw.lower() in ("always", "manual"):
194
+ return ApprovalMode.MANUAL
195
+ if raw.lower() in ("auto", "a"):
196
+ return ApprovalMode.AUTO
197
+
198
+ # Non-interactive / headless execution (-p / --prompt) defaults to AUTO for autonomous execution,
199
+ # while interactive TUI defaults to MANUAL for human-in-the-loop safety.
200
+ if getattr(args, "prompt", None):
201
+ return ApprovalMode.AUTO
202
+ return ApprovalMode.MANUAL
203
+
204
+
205
+ # ── Parser Builder ───────────────────────────────────────
206
+
207
+
208
+ def build_parser() -> argparse.ArgumentParser:
209
+ """Build the comprehensive OpsCloud command-line argument parser."""
210
+ parser = argparse.ArgumentParser(
211
+ prog="opscloud",
212
+ description="OpsCloud — Autonomous Cloud Operations & DevOps Coding Agent.",
213
+ )
214
+ parser.add_argument(
215
+ "-v",
216
+ "--version",
217
+ action="version",
218
+ version=f"%(prog)s {__version__}",
219
+ )
220
+
221
+ # Prompt & Headless flags
222
+ parser.add_argument(
223
+ "-p",
224
+ "--prompt",
225
+ "-n",
226
+ "--non-interactive",
227
+ dest="prompt",
228
+ type=str,
229
+ default=None,
230
+ help="Run non-interactively (headless) with the given prompt.",
231
+ )
232
+
233
+ # Interactive Initial Prompts & Seeding
234
+ parser.add_argument(
235
+ "-m",
236
+ "--message",
237
+ "--initial-prompt",
238
+ dest="initial_prompt",
239
+ type=str,
240
+ default=None,
241
+ help="Initial prompt to auto-submit when interactive session starts.",
242
+ )
243
+ parser.add_argument(
244
+ "-s",
245
+ "--skill",
246
+ dest="initial_skill",
247
+ type=str,
248
+ default=None,
249
+ help="Invoke a skill when interactive or headless session starts.",
250
+ )
251
+ parser.add_argument(
252
+ "--startup-cmd",
253
+ dest="startup_cmd",
254
+ type=str,
255
+ default=None,
256
+ help="Shell command executed at startup before the first prompt.",
257
+ )
258
+
259
+ # Output formatting
260
+ parser.add_argument(
261
+ "-q",
262
+ "--quiet",
263
+ action="store_true",
264
+ default=False,
265
+ help="Clean output for piping stdout — only agent's final text goes to stdout. Requires headless mode.",
266
+ )
267
+ parser.add_argument(
268
+ "--no-stream",
269
+ dest="no_stream",
270
+ action="store_true",
271
+ default=False,
272
+ help="Buffer response and write to stdout at once instead of streaming chunks. Requires headless mode.",
273
+ )
274
+ add_json_output_arg(parser, default="text")
275
+
276
+ # CI/CD Execution Limits
277
+ parser.add_argument(
278
+ "--max-turns",
279
+ dest="max_turns",
280
+ type=positive_int,
281
+ default=None,
282
+ help="Maximum agentic turns before stopping (>= 1). Requires headless mode.",
283
+ )
284
+ parser.add_argument(
285
+ "--timeout",
286
+ dest="timeout",
287
+ type=positive_int,
288
+ default=None,
289
+ help="Hard wall-clock timeout in seconds (>= 1). Exits 124 on expiry. Requires headless mode.",
290
+ )
291
+ parser.add_argument(
292
+ "--recursion-limit",
293
+ dest="recursion_limit",
294
+ type=positive_int,
295
+ default=None,
296
+ help="Override main agent's LangGraph recursion_limit (graph step budget).",
297
+ )
298
+ parser.add_argument(
299
+ "--stdin",
300
+ action="store_true",
301
+ default=False,
302
+ help="Read input from stdin explicitly.",
303
+ )
304
+
305
+ # Cloud & Environment Overrides
306
+ parser.add_argument(
307
+ "--read-only",
308
+ "--dry-run",
309
+ dest="read_only",
310
+ action="store_true",
311
+ default=False,
312
+ help="Enforce read-only cloud operations safety mode (blocks all mutating AWS/K8s/Terraform calls).",
313
+ )
314
+ parser.add_argument(
315
+ "--aws-profile",
316
+ dest="aws_profile",
317
+ type=str,
318
+ default=None,
319
+ help="AWS profile override for this session (e.g. staging, prod).",
320
+ )
321
+ parser.add_argument(
322
+ "--aws-region",
323
+ dest="aws_region",
324
+ type=str,
325
+ default=None,
326
+ help="AWS region override for this session (e.g. us-east-1, eu-west-1).",
327
+ )
328
+ parser.add_argument(
329
+ "-S",
330
+ "--shell-allow-list",
331
+ dest="shell_allow_list",
332
+ type=shell_allow_list_arg,
333
+ default=None,
334
+ help="Comma-separated list of allowed shell commands ('recommended', 'all', or comma-separated names).",
335
+ )
336
+
337
+ # Model & Config
338
+ parser.add_argument(
339
+ "-M",
340
+ "--model",
341
+ dest="model",
342
+ type=str,
343
+ default=None,
344
+ help="Model specification to use (e.g. anthropic:claude-3-5-sonnet, openai:gpt-4o, bedrock:anthropic.claude-3-5-sonnet).",
345
+ )
346
+ parser.add_argument(
347
+ "--model-params",
348
+ dest="model_params",
349
+ type=str,
350
+ default=None,
351
+ help="Extra kwargs to pass to model as JSON string (e.g. '{\"temperature\": 0.0}').",
352
+ )
353
+ parser.add_argument(
354
+ "--profile-override",
355
+ dest="profile_override",
356
+ type=str,
357
+ default=None,
358
+ help="Override model profile fields as JSON string.",
359
+ )
360
+ parser.add_argument(
361
+ "--default-model",
362
+ dest="default_model",
363
+ nargs="?",
364
+ const="__SHOW__",
365
+ default=None,
366
+ help="Set or show the default model for future launches.",
367
+ )
368
+ parser.add_argument(
369
+ "--clear-default-model",
370
+ dest="clear_default_model",
371
+ action="store_true",
372
+ default=False,
373
+ help="Clear configured default model.",
374
+ )
375
+
376
+ # Approvals
377
+ approval_group = parser.add_mutually_exclusive_group()
378
+ approval_group.add_argument(
379
+ "--approval-mode",
380
+ dest="approval_mode",
381
+ type=str,
382
+ choices=["manual", "auto", "smart"],
383
+ default=None,
384
+ help="HITL tool approval mode: 'manual', 'auto', or 'smart' (TypeSafe AI Jev).",
385
+ )
386
+ approval_group.add_argument(
387
+ "-y",
388
+ "--auto-approve",
389
+ dest="auto_approve",
390
+ action="store_true",
391
+ default=False,
392
+ help="Enable classic classifier-backed Auto mode.",
393
+ )
394
+ approval_group.add_argument(
395
+ "--smart",
396
+ dest="smart",
397
+ action="store_true",
398
+ default=False,
399
+ help="Enable Jev-powered Smart approval mode (<100ms System One safety gate).",
400
+ )
401
+
402
+ # MCP
403
+ parser.add_argument(
404
+ "--mcp-config",
405
+ dest="mcp_config",
406
+ type=str,
407
+ default=None,
408
+ help="Path to MCP servers JSON configuration file.",
409
+ )
410
+ parser.add_argument(
411
+ "--no-mcp",
412
+ dest="no_mcp",
413
+ action="store_true",
414
+ default=False,
415
+ help="Disable all MCP tool loading.",
416
+ )
417
+ parser.add_argument(
418
+ "--trust-project-mcp",
419
+ dest="trust_project_mcp",
420
+ action="store_true",
421
+ default=False,
422
+ help="Skip interactive confirmation prompts for project-level MCP servers.",
423
+ )
424
+
425
+ # Session & State
426
+ parser.add_argument(
427
+ "-r",
428
+ "--resume",
429
+ "--resume-thread",
430
+ dest="resume_thread",
431
+ type=str,
432
+ default=None,
433
+ help="Resume an existing session thread ID.",
434
+ )
435
+ parser.add_argument(
436
+ "--cwd",
437
+ dest="cwd",
438
+ type=str,
439
+ default=None,
440
+ help="Working directory path for this execution.",
441
+ )
442
+ parser.add_argument(
443
+ "--goal",
444
+ type=str,
445
+ default=None,
446
+ help="Initial goal objective to establish (for interactive TUI mode).",
447
+ )
448
+ parser.add_argument(
449
+ "--rubric",
450
+ type=str,
451
+ default=None,
452
+ help="Acceptance criteria to grade against (literal text or @path); used with headless mode.",
453
+ )
454
+ parser.add_argument(
455
+ "--rubric-model",
456
+ type=str,
457
+ default=None,
458
+ help="Model specification for the rubric grader agent.",
459
+ )
460
+ parser.add_argument(
461
+ "--rubric-max-iterations",
462
+ type=positive_int,
463
+ default=None,
464
+ help="Maximum evaluation iterations for the rubric grader.",
465
+ )
466
+ parser.add_argument(
467
+ "--verbose",
468
+ action="store_true",
469
+ default=False,
470
+ help="Enable verbose logging.",
471
+ )
472
+ parser.add_argument(
473
+ "--log-level",
474
+ choices=["debug", "info", "warning", "error", "critical"],
475
+ type=str.lower,
476
+ default=None,
477
+ help="Set logging level (default: info, or debug with -v).",
478
+ )
479
+ parser.add_argument(
480
+ "--log-dir",
481
+ type=str,
482
+ default=None,
483
+ help="Directory for log files (default: /tmp/opscloud_logs).",
484
+ )
485
+ parser.add_argument(
486
+ "--log-file",
487
+ type=str,
488
+ default=None,
489
+ help="Log file path or filename (default: opscloud.log in log directory).",
490
+ )
491
+
492
+ # Subcommands
493
+ subparsers = parser.add_subparsers(dest="subcommand", help="Operational subcommands")
494
+ doctor_parser = subparsers.add_parser("doctor", help="Run system & cloud environment health checks.")
495
+ add_json_output_arg(doctor_parser)
496
+
497
+ auth_parser = subparsers.add_parser("auth", help="Show AWS STS authentication status.")
498
+ add_json_output_arg(auth_parser)
499
+
500
+ threads_parser = subparsers.add_parser("threads", help="Manage session threads.")
501
+ add_json_output_arg(threads_parser)
502
+ threads_sub = threads_parser.add_subparsers(dest="threads_command")
503
+ threads_list = threads_sub.add_parser("list", aliases=["ls"], help="List saved session threads.")
504
+ add_json_output_arg(threads_list)
505
+ threads_del = threads_sub.add_parser("delete", help="Delete a session thread.")
506
+ threads_del.add_argument("thread_id", help="Thread ID to delete.")
507
+ add_json_output_arg(threads_del)
508
+
509
+ setup_mcp_parser(subparsers)
510
+
511
+ from opscloud.plugins.commands_cli import setup_plugin_parser
512
+
513
+ setup_plugin_parser(subparsers)
514
+
515
+ from opscloud.skills import setup_skills_parser
516
+
517
+ setup_skills_parser(subparsers)
518
+
519
+ return parser
520
+
521
+
522
+ # ── Argument Validation ──────────────────────────────────
523
+
524
+
525
+ def _validate_args(args: argparse.Namespace) -> int | None:
526
+ """Validate argument compatibility and mutual exclusions."""
527
+ # Goal and rubric flag validations
528
+ if getattr(args, "goal", None) and getattr(args, "rubric", None):
529
+ print(
530
+ "Error: Cannot specify both --goal and --rubric. Use --goal for interactive sessions, or --rubric with -p for headless verification.",
531
+ file=sys.stderr,
532
+ )
533
+ return 1
534
+
535
+ if getattr(args, "goal", None) and getattr(args, "prompt", None):
536
+ print(
537
+ "Error: Cannot specify both --goal and --rubric/--prompt. Use --goal for interactive sessions, or --rubric with -p for headless verification.",
538
+ file=sys.stderr,
539
+ )
540
+ return 1
541
+
542
+ if getattr(args, "rubric", None) and not getattr(args, "prompt", None):
543
+ print("Error: --rubric requires -p/--prompt for headless verification.", file=sys.stderr)
544
+ return 1
545
+
546
+ if getattr(args, "rubric_model", None) and not getattr(args, "rubric", None):
547
+ print("Error: --rubric-model requires --rubric.", file=sys.stderr)
548
+ return 1
549
+
550
+ if getattr(args, "rubric_max_iterations", None) and not getattr(args, "rubric", None):
551
+ print("Error: --rubric-max-iterations requires --rubric.", file=sys.stderr)
552
+ return 1
553
+
554
+ if (getattr(args, "quiet", False) or getattr(args, "no_stream", False)) and not getattr(args, "prompt", None):
555
+ flags = []
556
+ if getattr(args, "quiet", False):
557
+ flags.append("--quiet")
558
+ if getattr(args, "no_stream", False):
559
+ flags.append("--no-stream")
560
+ flag = " and ".join(flags)
561
+ print(
562
+ f"Error: {flag} requires -p/--prompt, -n, positional prompt, or piped stdin.",
563
+ file=sys.stderr,
564
+ )
565
+ return 2
566
+
567
+ if getattr(args, "max_turns", None) is not None and not getattr(args, "prompt", None):
568
+ print(
569
+ "Error: --max-turns requires -p/--prompt, -n, positional prompt, or piped stdin.",
570
+ file=sys.stderr,
571
+ )
572
+ return 2
573
+
574
+ if getattr(args, "timeout", None) is not None and not getattr(args, "prompt", None):
575
+ print(
576
+ "Error: --timeout requires -p/--prompt, -n, positional prompt, or piped stdin.",
577
+ file=sys.stderr,
578
+ )
579
+ return 2
580
+
581
+ if getattr(args, "no_mcp", False) and getattr(args, "mcp_config", None):
582
+ print("Error: --no-mcp and --mcp-config are mutually exclusive.", file=sys.stderr)
583
+ return 2
584
+
585
+ return None
586
+
587
+
588
+ # ── Main Entrypoint ──────────────────────────────────────
589
+
590
+
591
+ def main(argv: list[str] | None = None) -> int:
592
+ """Main CLI entrypoint function."""
593
+ raw_args = list(sys.argv[1:]) if argv is None else list(argv)
594
+
595
+ # 1. Fast-path for --version
596
+ if len(raw_args) == 1 and raw_args[0] in {"-v", "--version"}:
597
+ print(f"opscloud {__version__}")
598
+ return 0
599
+
600
+ parser = build_parser()
601
+
602
+ known_subcommands = {
603
+ "doctor",
604
+ "auth",
605
+ "threads",
606
+ "mcp",
607
+ "plugin",
608
+ "plugins",
609
+ "skill",
610
+ "skills",
611
+ "help",
612
+ }
613
+
614
+ # Hoist global logging flags to the front so they work seamlessly
615
+ # across both root invocations and subcommands (e.g. opscloud doctor --verbose)
616
+ hoisted_args: list[str] = []
617
+ remaining_args: list[str] = []
618
+ it = iter(raw_args)
619
+ for arg in it:
620
+ if arg in {"-v", "--verbose"}:
621
+ hoisted_args.append(arg)
622
+ elif arg.startswith(("--log-level=", "--log-dir=", "--log-file=")):
623
+ hoisted_args.append(arg)
624
+ elif arg in {"--log-level", "--log-dir", "--log-file"}:
625
+ hoisted_args.append(arg)
626
+ val = next(it, None)
627
+ if val is not None:
628
+ hoisted_args.append(val)
629
+ else:
630
+ remaining_args.append(arg)
631
+ reordered_args = hoisted_args + remaining_args
632
+
633
+ # Identify flags with value arguments vs flags without
634
+ flags_with_values: set[str] = {
635
+ opt for act in parser._actions if act.nargs not in (0, "?") for opt in act.option_strings
636
+ }
637
+ optional_val_flags: set[str] = {
638
+ opt for act in parser._actions if act.nargs == "?" for opt in act.option_strings
639
+ }
640
+
641
+ # Find the first positional token to check if it's a subcommand or a prompt
642
+ first_pos = None
643
+ scan_it = iter(reordered_args)
644
+ for token in scan_it:
645
+ if token in flags_with_values:
646
+ next(scan_it, None)
647
+ elif token in optional_val_flags:
648
+ pass
649
+ elif not token.startswith("-"):
650
+ first_pos = token
651
+ break
652
+
653
+ is_subcommand = first_pos in known_subcommands
654
+ if is_subcommand:
655
+ args = parser.parse_args(reordered_args)
656
+ else:
657
+ # Preprocess positional prompt if -p/--prompt not already present
658
+ has_prompt_flag = any(a in {"-p", "--prompt", "-n", "--non-interactive"} for a in reordered_args)
659
+ if first_pos is not None and not has_prompt_flag:
660
+ processed_args: list[str] = []
661
+ prompt_injected = False
662
+ build_it = iter(reordered_args)
663
+ for token in build_it:
664
+ if token in flags_with_values:
665
+ processed_args.append(token)
666
+ val = next(build_it, None)
667
+ if val is not None:
668
+ processed_args.append(val)
669
+ elif token in optional_val_flags:
670
+ processed_args.append(token)
671
+ elif not token.startswith("-") and token == first_pos and not prompt_injected:
672
+ processed_args.extend(["-p", token])
673
+ prompt_injected = True
674
+ else:
675
+ processed_args.append(token)
676
+ args = parser.parse_args(processed_args)
677
+ else:
678
+ args = parser.parse_args(reordered_args)
679
+
680
+ # 2. Configure system logging based on CLI flags and environment
681
+ from opscloud.utils.logger import configure_logging
682
+
683
+ log_level = "DEBUG" if getattr(args, "verbose", False) else getattr(args, "log_level", None)
684
+ log_to_console = (
685
+ True
686
+ if getattr(args, "verbose", False)
687
+ else (False if getattr(args, "json_output", False) or getattr(args, "quiet", False) else None)
688
+ )
689
+
690
+ configure_logging(
691
+ level=log_level,
692
+ log_to_console=log_to_console,
693
+ log_dir=getattr(args, "log_dir", None),
694
+ log_file=getattr(args, "log_file", None),
695
+ )
696
+
697
+ # 3. Ingest piped stdin
698
+ _apply_stdin_pipe(args)
699
+
700
+ # 4. Handle subcommands
701
+ raw_fmt = getattr(args, "output_format", "text")
702
+ output_format: OutputFormat = "json" if raw_fmt == "json" else "text"
703
+
704
+ if args.subcommand == "doctor":
705
+ return run_doctor_command(output_format)
706
+ elif args.subcommand == "auth":
707
+ return run_auth_command(output_format)
708
+ elif args.subcommand == "threads":
709
+ subcmd = getattr(args, "threads_command", None)
710
+ if subcmd == "delete":
711
+ # Delete thread command
712
+ import asyncio
713
+ from opscloud.state.session import delete_thread
714
+
715
+ try:
716
+ deleted = asyncio.run(delete_thread(args.thread_id))
717
+ if output_format == "json":
718
+ from opscloud.output import write_json
719
+
720
+ write_json("threads delete", {"thread_id": args.thread_id, "deleted": deleted})
721
+ else:
722
+ if deleted:
723
+ print(f"Deleted thread: {args.thread_id}")
724
+ else:
725
+ print(f"Thread not found: {args.thread_id}", file=sys.stderr)
726
+ return 1
727
+ return 0
728
+ except Exception as e:
729
+ print(f"Error deleting thread {args.thread_id}: {e}", file=sys.stderr)
730
+ return 1
731
+ return run_threads_command(output_format)
732
+ elif args.subcommand == "mcp":
733
+ return run_mcp_command(args)
734
+ elif args.subcommand in {"plugin", "plugins"}:
735
+ from opscloud.plugins.commands_cli import execute_plugin_command
736
+
737
+ try:
738
+ execute_plugin_command(args)
739
+ return 0
740
+ except SystemExit as exc:
741
+ return exc.code if isinstance(exc.code, int) else 1
742
+ elif args.subcommand in {"skill", "skills"}:
743
+ from opscloud.skills import execute_skills_command
744
+
745
+ try:
746
+ execute_skills_command(args)
747
+ return 0
748
+ except SystemExit as exc:
749
+ return exc.code if isinstance(exc.code, int) else 1
750
+
751
+ # 4. Handle default model configuration
752
+ if getattr(args, "clear_default_model", False):
753
+ from opscloud.model.config import clear_default_model
754
+
755
+ if clear_default_model():
756
+ print("Default model cleared.")
757
+ return 0
758
+ else:
759
+ print("Error: Could not clear default model.", file=sys.stderr)
760
+ return 1
761
+
762
+ if getattr(args, "default_model", None) is not None:
763
+ from opscloud.model.config import load_default_model, save_default_model
764
+ from opscloud.model.factory import normalize_model_spec
765
+
766
+ if args.default_model == "__SHOW__":
767
+ curr = load_default_model()
768
+ if curr:
769
+ print(f"Default model: {curr}")
770
+ else:
771
+ print("No default model set.")
772
+ return 0
773
+
774
+ norm = normalize_model_spec(args.default_model)
775
+ if save_default_model(norm):
776
+ print(f"Default model set to {norm}")
777
+ return 0
778
+ else:
779
+ print("Error: Could not save default model.", file=sys.stderr)
780
+ return 1
781
+
782
+ # 5. Parse model kwargs and profile JSON if provided
783
+ model_params: dict[str, Any] | None = None
784
+ if getattr(args, "model_params", None):
785
+ try:
786
+ model_params = json.loads(args.model_params)
787
+ if not isinstance(model_params, dict):
788
+ print("Error: --model-params must be a JSON object.", file=sys.stderr)
789
+ return 1
790
+ except json.JSONDecodeError as exc:
791
+ print(f"Error: --model-params is not valid JSON: {exc}", file=sys.stderr)
792
+ return 1
793
+
794
+ profile_override: dict[str, Any] | None = None
795
+ if getattr(args, "profile_override", None):
796
+ try:
797
+ profile_override = json.loads(args.profile_override)
798
+ if not isinstance(profile_override, dict):
799
+ print("Error: --profile-override must be a JSON object.", file=sys.stderr)
800
+ return 1
801
+ except json.JSONDecodeError as exc:
802
+ print(f"Error: --profile-override is not valid JSON: {exc}", file=sys.stderr)
803
+ return 1
804
+
805
+ # 6. Validate argument combinations
806
+ val_err = _validate_args(args)
807
+ if val_err is not None:
808
+ return val_err
809
+
810
+ # 7. Resolve Rubric text if provided
811
+ resolved_rubric = None
812
+ if args.rubric:
813
+ try:
814
+ resolved_rubric = _resolve_rubric_text(args.rubric)
815
+ except ValueError as exc:
816
+ print(f"Error: {exc}", file=sys.stderr)
817
+ return 1
818
+
819
+ # 8. Resolve Approval Mode
820
+ approval_mode = _resolve_approval_mode(args)
821
+
822
+ # 9. Headless / Non-interactive execution mode
823
+ if args.prompt:
824
+ model = args.model
825
+ if not model:
826
+ try:
827
+ from opscloud.model.factory import _get_default_model_spec
828
+
829
+ model = _get_default_model_spec()
830
+ except Exception as e:
831
+ print(f"Error: {e}", file=sys.stderr)
832
+ return 1
833
+
834
+ json_out = getattr(args, "output_format", "text") == "json"
835
+
836
+ from opscloud.project_utils import ProjectContext
837
+
838
+ project_context = (
839
+ ProjectContext.from_user_cwd(Path(args.cwd))
840
+ if args.cwd
841
+ else ProjectContext.from_user_cwd(Path.cwd())
842
+ )
843
+ effective_cwd = str(project_context.user_cwd)
844
+ return run_non_interactive(
845
+ args.prompt,
846
+ model=model,
847
+ model_params=model_params,
848
+ profile_override=profile_override,
849
+ approval_mode=approval_mode,
850
+ shell_allow_list=args.shell_allow_list,
851
+ read_only=args.read_only,
852
+ aws_profile=args.aws_profile,
853
+ aws_region=args.aws_region,
854
+ quiet=args.quiet,
855
+ no_stream=args.no_stream,
856
+ json_output=json_out,
857
+ max_turns=args.max_turns,
858
+ timeout=float(args.timeout) if args.timeout is not None else None,
859
+ rubric=resolved_rubric,
860
+ rubric_model=args.rubric_model,
861
+ rubric_max_iterations=args.rubric_max_iterations,
862
+ recursion_limit=args.recursion_limit,
863
+ initial_skill=args.initial_skill,
864
+ startup_cmd=args.startup_cmd,
865
+ mcp_config_path=args.mcp_config,
866
+ no_mcp=args.no_mcp,
867
+ trust_project_mcp=args.trust_project_mcp,
868
+ thread_id=args.resume_thread,
869
+ cwd=effective_cwd,
870
+ )
871
+
872
+ # 10. Interactive TUI mode
873
+ from opscloud.project_utils import ProjectContext
874
+
875
+ project_context = (
876
+ ProjectContext.from_user_cwd(Path(args.cwd))
877
+ if args.cwd
878
+ else ProjectContext.from_user_cwd(Path.cwd())
879
+ )
880
+ effective_cwd = str(project_context.user_cwd)
881
+ return run_interactive(
882
+ model=args.model,
883
+ approval_mode=approval_mode,
884
+ resume_thread=args.resume_thread,
885
+ cwd=effective_cwd,
886
+ goal=args.goal,
887
+ initial_prompt=args.initial_prompt,
888
+ initial_skill=args.initial_skill,
889
+ startup_cmd=args.startup_cmd,
890
+ read_only=args.read_only,
891
+ aws_profile=args.aws_profile,
892
+ aws_region=args.aws_region,
893
+ shell_allow_list=args.shell_allow_list,
894
+ mcp_config_path=args.mcp_config,
895
+ no_mcp=args.no_mcp,
896
+ trust_project_mcp=args.trust_project_mcp,
897
+ )
898
+
899
+
900
+ cli_main = main
901
+
902
+ if __name__ == "__main__":
903
+ sys.exit(main())