claude-mpm 5.6.10__py3-none-any.whl → 5.6.33__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 (117) hide show
  1. claude_mpm/VERSION +1 -1
  2. claude_mpm/cli/commands/commander.py +174 -4
  3. claude_mpm/cli/parsers/commander_parser.py +43 -10
  4. claude_mpm/cli/startup.py +140 -20
  5. claude_mpm/cli/startup_display.py +2 -1
  6. claude_mpm/commander/__init__.py +6 -0
  7. claude_mpm/commander/adapters/__init__.py +32 -3
  8. claude_mpm/commander/adapters/auggie.py +260 -0
  9. claude_mpm/commander/adapters/base.py +98 -1
  10. claude_mpm/commander/adapters/claude_code.py +32 -1
  11. claude_mpm/commander/adapters/codex.py +237 -0
  12. claude_mpm/commander/adapters/example_usage.py +310 -0
  13. claude_mpm/commander/adapters/mpm.py +389 -0
  14. claude_mpm/commander/adapters/registry.py +204 -0
  15. claude_mpm/commander/api/app.py +32 -16
  16. claude_mpm/commander/api/routes/messages.py +11 -11
  17. claude_mpm/commander/api/routes/projects.py +20 -20
  18. claude_mpm/commander/api/routes/sessions.py +19 -21
  19. claude_mpm/commander/api/routes/work.py +86 -50
  20. claude_mpm/commander/api/schemas.py +4 -0
  21. claude_mpm/commander/chat/cli.py +42 -3
  22. claude_mpm/commander/config.py +5 -3
  23. claude_mpm/commander/core/__init__.py +10 -0
  24. claude_mpm/commander/core/block_manager.py +325 -0
  25. claude_mpm/commander/core/response_manager.py +323 -0
  26. claude_mpm/commander/daemon.py +215 -10
  27. claude_mpm/commander/env_loader.py +59 -0
  28. claude_mpm/commander/frameworks/base.py +4 -1
  29. claude_mpm/commander/instance_manager.py +124 -11
  30. claude_mpm/commander/memory/__init__.py +45 -0
  31. claude_mpm/commander/memory/compression.py +347 -0
  32. claude_mpm/commander/memory/embeddings.py +230 -0
  33. claude_mpm/commander/memory/entities.py +310 -0
  34. claude_mpm/commander/memory/example_usage.py +290 -0
  35. claude_mpm/commander/memory/integration.py +325 -0
  36. claude_mpm/commander/memory/search.py +381 -0
  37. claude_mpm/commander/memory/store.py +657 -0
  38. claude_mpm/commander/registry.py +10 -4
  39. claude_mpm/commander/runtime/monitor.py +32 -2
  40. claude_mpm/commander/work/executor.py +38 -20
  41. claude_mpm/commander/workflow/event_handler.py +25 -3
  42. claude_mpm/core/claude_runner.py +152 -0
  43. claude_mpm/core/config.py +3 -3
  44. claude_mpm/core/config_constants.py +74 -9
  45. claude_mpm/core/constants.py +56 -12
  46. claude_mpm/core/interactive_session.py +5 -4
  47. claude_mpm/core/logging_utils.py +4 -2
  48. claude_mpm/core/network_config.py +148 -0
  49. claude_mpm/core/oneshot_session.py +7 -6
  50. claude_mpm/core/output_style_manager.py +37 -7
  51. claude_mpm/core/socketio_pool.py +13 -5
  52. claude_mpm/hooks/claude_hooks/__pycache__/auto_pause_handler.cpython-311.pyc +0 -0
  53. claude_mpm/hooks/claude_hooks/__pycache__/event_handlers.cpython-311.pyc +0 -0
  54. claude_mpm/hooks/claude_hooks/__pycache__/hook_handler.cpython-311.pyc +0 -0
  55. claude_mpm/hooks/claude_hooks/__pycache__/memory_integration.cpython-311.pyc +0 -0
  56. claude_mpm/hooks/claude_hooks/__pycache__/response_tracking.cpython-311.pyc +0 -0
  57. claude_mpm/hooks/claude_hooks/auto_pause_handler.py +1 -1
  58. claude_mpm/hooks/claude_hooks/event_handlers.py +284 -89
  59. claude_mpm/hooks/claude_hooks/hook_handler.py +81 -32
  60. claude_mpm/hooks/claude_hooks/installer.py +90 -28
  61. claude_mpm/hooks/claude_hooks/memory_integration.py +1 -1
  62. claude_mpm/hooks/claude_hooks/response_tracking.py +1 -1
  63. claude_mpm/hooks/claude_hooks/services/__init__.py +21 -0
  64. claude_mpm/hooks/claude_hooks/services/__pycache__/__init__.cpython-311.pyc +0 -0
  65. claude_mpm/hooks/claude_hooks/services/__pycache__/connection_manager_http.cpython-311.pyc +0 -0
  66. claude_mpm/hooks/claude_hooks/services/__pycache__/container.cpython-311.pyc +0 -0
  67. claude_mpm/hooks/claude_hooks/services/__pycache__/protocols.cpython-311.pyc +0 -0
  68. claude_mpm/hooks/claude_hooks/services/__pycache__/state_manager.cpython-311.pyc +0 -0
  69. claude_mpm/hooks/claude_hooks/services/__pycache__/subagent_processor.cpython-311.pyc +0 -0
  70. claude_mpm/hooks/claude_hooks/services/connection_manager.py +2 -2
  71. claude_mpm/hooks/claude_hooks/services/connection_manager_http.py +2 -2
  72. claude_mpm/hooks/claude_hooks/services/container.py +310 -0
  73. claude_mpm/hooks/claude_hooks/services/protocols.py +328 -0
  74. claude_mpm/hooks/claude_hooks/services/state_manager.py +2 -2
  75. claude_mpm/hooks/claude_hooks/services/subagent_processor.py +2 -2
  76. claude_mpm/hooks/templates/pre_tool_use_simple.py +6 -6
  77. claude_mpm/hooks/templates/pre_tool_use_template.py +6 -6
  78. claude_mpm/scripts/claude-hook-handler.sh +3 -3
  79. claude_mpm/services/command_deployment_service.py +44 -26
  80. claude_mpm/services/hook_installer_service.py +77 -8
  81. claude_mpm/services/pm_skills_deployer.py +3 -2
  82. claude_mpm/skills/__init__.py +2 -1
  83. claude_mpm/skills/bundled/pm/mpm-session-pause/SKILL.md +170 -0
  84. claude_mpm/skills/registry.py +295 -90
  85. {claude_mpm-5.6.10.dist-info → claude_mpm-5.6.33.dist-info}/METADATA +5 -3
  86. {claude_mpm-5.6.10.dist-info → claude_mpm-5.6.33.dist-info}/RECORD +91 -94
  87. claude_mpm/hooks/claude_hooks/__pycache__/__init__.cpython-312.pyc +0 -0
  88. claude_mpm/hooks/claude_hooks/__pycache__/__init__.cpython-314.pyc +0 -0
  89. claude_mpm/hooks/claude_hooks/__pycache__/auto_pause_handler.cpython-312.pyc +0 -0
  90. claude_mpm/hooks/claude_hooks/__pycache__/auto_pause_handler.cpython-314.pyc +0 -0
  91. claude_mpm/hooks/claude_hooks/__pycache__/event_handlers.cpython-312.pyc +0 -0
  92. claude_mpm/hooks/claude_hooks/__pycache__/event_handlers.cpython-314.pyc +0 -0
  93. claude_mpm/hooks/claude_hooks/__pycache__/hook_handler.cpython-312.pyc +0 -0
  94. claude_mpm/hooks/claude_hooks/__pycache__/hook_handler.cpython-314.pyc +0 -0
  95. claude_mpm/hooks/claude_hooks/__pycache__/installer.cpython-311.pyc +0 -0
  96. claude_mpm/hooks/claude_hooks/__pycache__/installer.cpython-314.pyc +0 -0
  97. claude_mpm/hooks/claude_hooks/__pycache__/memory_integration.cpython-312.pyc +0 -0
  98. claude_mpm/hooks/claude_hooks/__pycache__/memory_integration.cpython-314.pyc +0 -0
  99. claude_mpm/hooks/claude_hooks/__pycache__/response_tracking.cpython-312.pyc +0 -0
  100. claude_mpm/hooks/claude_hooks/__pycache__/response_tracking.cpython-314.pyc +0 -0
  101. claude_mpm/hooks/claude_hooks/__pycache__/tool_analysis.cpython-312.pyc +0 -0
  102. claude_mpm/hooks/claude_hooks/__pycache__/tool_analysis.cpython-314.pyc +0 -0
  103. claude_mpm/hooks/claude_hooks/services/__pycache__/__init__.cpython-312.pyc +0 -0
  104. claude_mpm/hooks/claude_hooks/services/__pycache__/__init__.cpython-314.pyc +0 -0
  105. claude_mpm/hooks/claude_hooks/services/__pycache__/connection_manager_http.cpython-312.pyc +0 -0
  106. claude_mpm/hooks/claude_hooks/services/__pycache__/connection_manager_http.cpython-314.pyc +0 -0
  107. claude_mpm/hooks/claude_hooks/services/__pycache__/duplicate_detector.cpython-312.pyc +0 -0
  108. claude_mpm/hooks/claude_hooks/services/__pycache__/duplicate_detector.cpython-314.pyc +0 -0
  109. claude_mpm/hooks/claude_hooks/services/__pycache__/state_manager.cpython-312.pyc +0 -0
  110. claude_mpm/hooks/claude_hooks/services/__pycache__/state_manager.cpython-314.pyc +0 -0
  111. claude_mpm/hooks/claude_hooks/services/__pycache__/subagent_processor.cpython-312.pyc +0 -0
  112. claude_mpm/hooks/claude_hooks/services/__pycache__/subagent_processor.cpython-314.pyc +0 -0
  113. {claude_mpm-5.6.10.dist-info → claude_mpm-5.6.33.dist-info}/WHEEL +0 -0
  114. {claude_mpm-5.6.10.dist-info → claude_mpm-5.6.33.dist-info}/entry_points.txt +0 -0
  115. {claude_mpm-5.6.10.dist-info → claude_mpm-5.6.33.dist-info}/licenses/LICENSE +0 -0
  116. {claude_mpm-5.6.10.dist-info → claude_mpm-5.6.33.dist-info}/licenses/LICENSE-FAQ.md +0 -0
  117. {claude_mpm-5.6.10.dist-info → claude_mpm-5.6.33.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,260 @@
1
+ """Auggie CLI runtime adapter.
2
+
3
+ This module implements the RuntimeAdapter interface for Auggie,
4
+ an AI coding assistant with MCP (Model Context Protocol) support.
5
+ """
6
+
7
+ import logging
8
+ import re
9
+ import shlex
10
+ from typing import List, Optional, Set
11
+
12
+ from .base import (
13
+ Capability,
14
+ ParsedResponse,
15
+ RuntimeAdapter,
16
+ RuntimeCapability,
17
+ RuntimeInfo,
18
+ )
19
+
20
+ logger = logging.getLogger(__name__)
21
+
22
+
23
+ class AuggieAdapter(RuntimeAdapter):
24
+ """Adapter for Auggie CLI.
25
+
26
+ Auggie is an AI coding assistant with support for MCP servers,
27
+ custom instructions, and various tool capabilities.
28
+
29
+ Example:
30
+ >>> adapter = AuggieAdapter()
31
+ >>> cmd = adapter.build_launch_command("/home/user/project")
32
+ >>> print(cmd)
33
+ cd '/home/user/project' && auggie
34
+ """
35
+
36
+ # Idle detection patterns
37
+ IDLE_PATTERNS = [
38
+ r"^>\s*$", # Simple prompt
39
+ r"auggie>\s*$", # Named prompt
40
+ r"Ready for input",
41
+ r"What would you like",
42
+ r"How can I assist",
43
+ ]
44
+
45
+ # Error patterns
46
+ ERROR_PATTERNS = [
47
+ r"Error:",
48
+ r"Failed:",
49
+ r"Exception:",
50
+ r"Permission denied",
51
+ r"not found",
52
+ r"Traceback \(most recent call last\)",
53
+ r"FATAL:",
54
+ r"command not found",
55
+ r"cannot access",
56
+ ]
57
+
58
+ # Question patterns
59
+ QUESTION_PATTERNS = [
60
+ r"Which option",
61
+ r"Should I proceed",
62
+ r"Please choose",
63
+ r"\(y/n\)\?",
64
+ r"Are you sure",
65
+ r"Do you want",
66
+ r"\[Y/n\]",
67
+ r"\[yes/no\]",
68
+ ]
69
+
70
+ # ANSI escape code pattern
71
+ ANSI_ESCAPE = re.compile(r"\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])")
72
+
73
+ @property
74
+ def name(self) -> str:
75
+ """Return the runtime identifier."""
76
+ return "auggie"
77
+
78
+ @property
79
+ def capabilities(self) -> Set[Capability]:
80
+ """Return the set of capabilities supported by Auggie."""
81
+ return {
82
+ Capability.TOOL_USE,
83
+ Capability.FILE_EDIT,
84
+ Capability.FILE_CREATE,
85
+ Capability.GIT_OPERATIONS,
86
+ Capability.SHELL_COMMANDS,
87
+ Capability.COMPLEX_REASONING,
88
+ }
89
+
90
+ @property
91
+ def runtime_info(self) -> RuntimeInfo:
92
+ """Return detailed runtime information."""
93
+ return RuntimeInfo(
94
+ name="auggie",
95
+ version=None, # Version detection could be added
96
+ capabilities={
97
+ RuntimeCapability.FILE_READ,
98
+ RuntimeCapability.FILE_EDIT,
99
+ RuntimeCapability.FILE_CREATE,
100
+ RuntimeCapability.BASH_EXECUTION,
101
+ RuntimeCapability.GIT_OPERATIONS,
102
+ RuntimeCapability.TOOL_USE,
103
+ RuntimeCapability.MCP_TOOLS, # Auggie supports MCP
104
+ RuntimeCapability.INSTRUCTIONS,
105
+ RuntimeCapability.COMPLEX_REASONING,
106
+ RuntimeCapability.AGENT_DELEGATION, # Auggie now supports agents
107
+ },
108
+ command="auggie",
109
+ supports_agents=True, # Auggie now supports agent delegation
110
+ instruction_file=".augment/instructions.md",
111
+ )
112
+
113
+ def build_launch_command(
114
+ self, project_path: str, agent_prompt: Optional[str] = None
115
+ ) -> str:
116
+ """Generate shell command to start Auggie.
117
+
118
+ Args:
119
+ project_path: Absolute path to the project directory
120
+ agent_prompt: Optional system prompt to configure Auggie
121
+
122
+ Returns:
123
+ Shell command string ready to execute
124
+
125
+ Example:
126
+ >>> adapter = AuggieAdapter()
127
+ >>> adapter.build_launch_command("/home/user/project")
128
+ "cd '/home/user/project' && auggie"
129
+ """
130
+ quoted_path = shlex.quote(project_path)
131
+ cmd = f"cd {quoted_path} && auggie"
132
+
133
+ if agent_prompt:
134
+ # Auggie may support --prompt or similar flag
135
+ # Adjust based on actual Auggie CLI options
136
+ quoted_prompt = shlex.quote(agent_prompt)
137
+ cmd += f" --prompt {quoted_prompt}"
138
+
139
+ logger.debug(f"Built Auggie launch command: {cmd}")
140
+ return cmd
141
+
142
+ def format_input(self, message: str) -> str:
143
+ """Prepare message for Auggie's input format."""
144
+ formatted = message.strip()
145
+ logger.debug(f"Formatted input: {formatted[:100]}...")
146
+ return formatted
147
+
148
+ def strip_ansi(self, text: str) -> str:
149
+ """Remove ANSI escape codes from text."""
150
+ return self.ANSI_ESCAPE.sub("", text)
151
+
152
+ def detect_idle(self, output: str) -> bool:
153
+ """Recognize when Auggie is waiting for input."""
154
+ if not output:
155
+ return False
156
+
157
+ clean = self.strip_ansi(output)
158
+ lines = clean.strip().split("\n")
159
+
160
+ if not lines:
161
+ return False
162
+
163
+ last_line = lines[-1].strip()
164
+
165
+ for pattern in self.IDLE_PATTERNS:
166
+ if re.search(pattern, last_line):
167
+ logger.debug(f"Detected idle state with pattern: {pattern}")
168
+ return True
169
+
170
+ return False
171
+
172
+ def detect_error(self, output: str) -> Optional[str]:
173
+ """Recognize error states and extract error message."""
174
+ clean = self.strip_ansi(output)
175
+
176
+ for pattern in self.ERROR_PATTERNS:
177
+ match = re.search(pattern, clean, re.IGNORECASE)
178
+ if match:
179
+ for line in clean.split("\n"):
180
+ if re.search(pattern, line, re.IGNORECASE):
181
+ error_msg = line.strip()
182
+ logger.warning(f"Detected error: {error_msg}")
183
+ return error_msg
184
+
185
+ return None
186
+
187
+ def detect_question(
188
+ self, output: str
189
+ ) -> tuple[bool, Optional[str], Optional[List[str]]]:
190
+ """Detect if Auggie is asking a question."""
191
+ clean = self.strip_ansi(output)
192
+
193
+ for pattern in self.QUESTION_PATTERNS:
194
+ if re.search(pattern, clean, re.IGNORECASE):
195
+ lines = clean.strip().split("\n")
196
+ question = None
197
+ options = []
198
+
199
+ for line in lines:
200
+ if re.search(pattern, line, re.IGNORECASE):
201
+ question = line.strip()
202
+
203
+ # Look for numbered options
204
+ opt_match = re.match(r"^\s*(\d+)[.):]\s*(.+)$", line)
205
+ if opt_match:
206
+ options.append(opt_match.group(2).strip())
207
+
208
+ logger.debug(
209
+ f"Detected question: {question}, options: {options if options else 'none'}"
210
+ )
211
+ return True, question, options if options else None
212
+
213
+ return False, None, None
214
+
215
+ def parse_response(self, output: str) -> ParsedResponse:
216
+ """Extract meaningful content from Auggie output."""
217
+ if not output:
218
+ return ParsedResponse(
219
+ content="",
220
+ is_complete=False,
221
+ is_error=False,
222
+ is_question=False,
223
+ )
224
+
225
+ clean = self.strip_ansi(output)
226
+ error_msg = self.detect_error(output)
227
+ is_question, question_text, options = self.detect_question(output)
228
+ is_complete = self.detect_idle(output)
229
+
230
+ response = ParsedResponse(
231
+ content=clean,
232
+ is_complete=is_complete,
233
+ is_error=error_msg is not None,
234
+ error_message=error_msg,
235
+ is_question=is_question,
236
+ question_text=question_text,
237
+ options=options,
238
+ )
239
+
240
+ logger.debug(
241
+ f"Parsed response: complete={is_complete}, error={error_msg is not None}, "
242
+ f"question={is_question}"
243
+ )
244
+
245
+ return response
246
+
247
+ def inject_instructions(self, instructions: str) -> Optional[str]:
248
+ """Return command to inject custom instructions.
249
+
250
+ Auggie supports .augment/instructions.md file for custom instructions.
251
+
252
+ Args:
253
+ instructions: Instructions text to inject
254
+
255
+ Returns:
256
+ Command to write instructions file
257
+ """
258
+ # Write to .augment/instructions.md
259
+ escaped = instructions.replace("'", "'\\''")
260
+ return f"mkdir -p .augment && echo '{escaped}' > .augment/instructions.md"
@@ -6,7 +6,7 @@ between the TmuxOrchestrator and various AI coding tools (Claude Code, Cursor, e
6
6
 
7
7
  from abc import ABC, abstractmethod
8
8
  from dataclasses import dataclass
9
- from enum import Enum
9
+ from enum import Enum, auto
10
10
  from typing import List, Optional, Set
11
11
 
12
12
 
@@ -22,6 +22,56 @@ class Capability(Enum):
22
22
  COMPLEX_REASONING = "complex_reasoning"
23
23
 
24
24
 
25
+ class RuntimeCapability(Enum):
26
+ """Extended capabilities a runtime may support (MPM-specific features)."""
27
+
28
+ FILE_READ = auto()
29
+ FILE_EDIT = auto()
30
+ FILE_CREATE = auto()
31
+ BASH_EXECUTION = auto()
32
+ GIT_OPERATIONS = auto()
33
+ TOOL_USE = auto()
34
+ AGENT_DELEGATION = auto() # Sub-agent spawning
35
+ HOOKS = auto() # Lifecycle hooks
36
+ INSTRUCTIONS = auto() # Custom instructions file
37
+ MCP_TOOLS = auto() # MCP server integration
38
+ SKILLS = auto() # Loadable skills
39
+ MONITOR = auto() # Real-time monitoring
40
+ WEB_SEARCH = auto()
41
+ COMPLEX_REASONING = auto()
42
+
43
+
44
+ @dataclass
45
+ class RuntimeInfo:
46
+ """Information about a runtime environment.
47
+
48
+ Attributes:
49
+ name: Runtime identifier (e.g., "claude-code", "auggie")
50
+ version: Optional version string
51
+ capabilities: Set of RuntimeCapability enums
52
+ command: CLI command to invoke runtime
53
+ supports_agents: Whether runtime supports agent delegation
54
+ instruction_file: Path to instructions file (e.g., "CLAUDE.md")
55
+
56
+ Example:
57
+ >>> info = RuntimeInfo(
58
+ ... name="claude-code",
59
+ ... version="1.0.0",
60
+ ... capabilities={RuntimeCapability.FILE_EDIT, RuntimeCapability.TOOL_USE},
61
+ ... command="claude",
62
+ ... supports_agents=False,
63
+ ... instruction_file="CLAUDE.md"
64
+ ... )
65
+ """
66
+
67
+ name: str
68
+ version: Optional[str]
69
+ capabilities: Set[RuntimeCapability]
70
+ command: str
71
+ supports_agents: bool = False
72
+ instruction_file: Optional[str] = None
73
+
74
+
25
75
  @dataclass
26
76
  class ParsedResponse:
27
77
  """Parsed output from a runtime tool.
@@ -189,3 +239,50 @@ class RuntimeAdapter(ABC):
189
239
  >>> adapter.name
190
240
  'claude-code'
191
241
  """
242
+
243
+ @property
244
+ def runtime_info(self) -> Optional[RuntimeInfo]:
245
+ """Return detailed runtime information.
246
+
247
+ Returns:
248
+ RuntimeInfo with capabilities and configuration, or None if not implemented
249
+
250
+ Example:
251
+ >>> info = adapter.runtime_info
252
+ >>> if info and RuntimeCapability.AGENT_DELEGATION in info.capabilities:
253
+ ... print("Supports agent delegation")
254
+ """
255
+ return None
256
+
257
+ def inject_instructions(self, instructions: str) -> Optional[str]:
258
+ """Return command/method to inject custom instructions.
259
+
260
+ Args:
261
+ instructions: Instructions text to inject
262
+
263
+ Returns:
264
+ Command string to inject instructions, or None if not supported
265
+
266
+ Example:
267
+ >>> cmd = adapter.inject_instructions("You are a Python expert")
268
+ >>> if cmd:
269
+ ... # Execute command to inject instructions
270
+ """
271
+ return None
272
+
273
+ def inject_agent_context(self, agent_id: str, context: dict) -> Optional[str]:
274
+ """Return command to inject agent context.
275
+
276
+ Args:
277
+ agent_id: Unique identifier for agent
278
+ context: Context dictionary with agent metadata
279
+
280
+ Returns:
281
+ Command string to inject context, or None if not supported
282
+
283
+ Example:
284
+ >>> cmd = adapter.inject_agent_context("eng-001", {"role": "Engineer"})
285
+ >>> if cmd:
286
+ ... # Execute command to inject context
287
+ """
288
+ return None
@@ -9,7 +9,13 @@ import re
9
9
  import shlex
10
10
  from typing import List, Optional, Set
11
11
 
12
- from .base import Capability, ParsedResponse, RuntimeAdapter
12
+ from .base import (
13
+ Capability,
14
+ ParsedResponse,
15
+ RuntimeAdapter,
16
+ RuntimeCapability,
17
+ RuntimeInfo,
18
+ )
13
19
 
14
20
  logger = logging.getLogger(__name__)
15
21
 
@@ -96,6 +102,31 @@ class ClaudeCodeAdapter(RuntimeAdapter):
96
102
  Capability.COMPLEX_REASONING,
97
103
  }
98
104
 
105
+ @property
106
+ def runtime_info(self) -> RuntimeInfo:
107
+ """Return detailed runtime information."""
108
+ return RuntimeInfo(
109
+ name="claude-code",
110
+ version=None, # Version detection could be added
111
+ capabilities={
112
+ RuntimeCapability.FILE_READ,
113
+ RuntimeCapability.FILE_EDIT,
114
+ RuntimeCapability.FILE_CREATE,
115
+ RuntimeCapability.BASH_EXECUTION,
116
+ RuntimeCapability.GIT_OPERATIONS,
117
+ RuntimeCapability.TOOL_USE,
118
+ RuntimeCapability.WEB_SEARCH,
119
+ RuntimeCapability.COMPLEX_REASONING,
120
+ RuntimeCapability.AGENT_DELEGATION, # Claude Code supports Task tool
121
+ RuntimeCapability.HOOKS, # Claude Code supports hooks
122
+ RuntimeCapability.SKILLS, # Claude Code can load skills
123
+ RuntimeCapability.MONITOR, # Can be monitored
124
+ },
125
+ command="claude",
126
+ supports_agents=True, # Claude Code supports agent delegation
127
+ instruction_file="CLAUDE.md",
128
+ )
129
+
99
130
  def build_launch_command(
100
131
  self, project_path: str, agent_prompt: Optional[str] = None
101
132
  ) -> str:
@@ -0,0 +1,237 @@
1
+ """Codex CLI runtime adapter.
2
+
3
+ This module implements the RuntimeAdapter interface for Codex,
4
+ an AI coding assistant (limited support currently).
5
+ """
6
+
7
+ import logging
8
+ import re
9
+ import shlex
10
+ from typing import List, Optional, Set
11
+
12
+ from .base import (
13
+ Capability,
14
+ ParsedResponse,
15
+ RuntimeAdapter,
16
+ RuntimeCapability,
17
+ RuntimeInfo,
18
+ )
19
+
20
+ logger = logging.getLogger(__name__)
21
+
22
+
23
+ class CodexAdapter(RuntimeAdapter):
24
+ """Adapter for Codex CLI.
25
+
26
+ Codex is an AI coding assistant. This adapter provides basic support,
27
+ with limited capabilities compared to Claude Code or MPM.
28
+
29
+ Note:
30
+ Agent delegation and advanced features not yet supported.
31
+
32
+ Example:
33
+ >>> adapter = CodexAdapter()
34
+ >>> cmd = adapter.build_launch_command("/home/user/project")
35
+ >>> print(cmd)
36
+ cd '/home/user/project' && codex
37
+ """
38
+
39
+ # Idle detection patterns
40
+ IDLE_PATTERNS = [
41
+ r"^>\s*$", # Simple prompt
42
+ r"codex>\s*$", # Named prompt
43
+ r"Ready",
44
+ r"Waiting for input",
45
+ ]
46
+
47
+ # Error patterns
48
+ ERROR_PATTERNS = [
49
+ r"Error:",
50
+ r"Failed:",
51
+ r"Exception:",
52
+ r"Permission denied",
53
+ r"not found",
54
+ r"Traceback",
55
+ r"FATAL:",
56
+ ]
57
+
58
+ # Question patterns
59
+ QUESTION_PATTERNS = [
60
+ r"Which option",
61
+ r"Should I proceed",
62
+ r"Please choose",
63
+ r"\(y/n\)\?",
64
+ r"Are you sure",
65
+ r"\[Y/n\]",
66
+ ]
67
+
68
+ # ANSI escape code pattern
69
+ ANSI_ESCAPE = re.compile(r"\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])")
70
+
71
+ @property
72
+ def name(self) -> str:
73
+ """Return the runtime identifier."""
74
+ return "codex"
75
+
76
+ @property
77
+ def capabilities(self) -> Set[Capability]:
78
+ """Return the set of capabilities supported by Codex."""
79
+ return {
80
+ Capability.TOOL_USE,
81
+ Capability.FILE_EDIT,
82
+ Capability.FILE_CREATE,
83
+ Capability.SHELL_COMMANDS,
84
+ Capability.COMPLEX_REASONING,
85
+ }
86
+
87
+ @property
88
+ def runtime_info(self) -> RuntimeInfo:
89
+ """Return detailed runtime information."""
90
+ return RuntimeInfo(
91
+ name="codex",
92
+ version=None, # Version detection could be added
93
+ capabilities={
94
+ RuntimeCapability.FILE_READ,
95
+ RuntimeCapability.FILE_EDIT,
96
+ RuntimeCapability.FILE_CREATE,
97
+ RuntimeCapability.BASH_EXECUTION,
98
+ RuntimeCapability.TOOL_USE,
99
+ RuntimeCapability.COMPLEX_REASONING,
100
+ },
101
+ command="codex",
102
+ supports_agents=False, # No agent support
103
+ instruction_file=None, # No custom instructions support
104
+ )
105
+
106
+ def build_launch_command(
107
+ self, project_path: str, agent_prompt: Optional[str] = None
108
+ ) -> str:
109
+ """Generate shell command to start Codex.
110
+
111
+ Args:
112
+ project_path: Absolute path to the project directory
113
+ agent_prompt: Optional system prompt (may not be supported)
114
+
115
+ Returns:
116
+ Shell command string ready to execute
117
+
118
+ Example:
119
+ >>> adapter = CodexAdapter()
120
+ >>> adapter.build_launch_command("/home/user/project")
121
+ "cd '/home/user/project' && codex"
122
+ """
123
+ quoted_path = shlex.quote(project_path)
124
+ cmd = f"cd {quoted_path} && codex"
125
+
126
+ # Note: Codex may not support custom prompts
127
+ # Adjust based on actual Codex CLI capabilities
128
+ if agent_prompt:
129
+ logger.warning("Codex may not support custom prompts")
130
+
131
+ logger.debug(f"Built Codex launch command: {cmd}")
132
+ return cmd
133
+
134
+ def format_input(self, message: str) -> str:
135
+ """Prepare message for Codex's input format."""
136
+ formatted = message.strip()
137
+ logger.debug(f"Formatted input: {formatted[:100]}...")
138
+ return formatted
139
+
140
+ def strip_ansi(self, text: str) -> str:
141
+ """Remove ANSI escape codes from text."""
142
+ return self.ANSI_ESCAPE.sub("", text)
143
+
144
+ def detect_idle(self, output: str) -> bool:
145
+ """Recognize when Codex is waiting for input."""
146
+ if not output:
147
+ return False
148
+
149
+ clean = self.strip_ansi(output)
150
+ lines = clean.strip().split("\n")
151
+
152
+ if not lines:
153
+ return False
154
+
155
+ last_line = lines[-1].strip()
156
+
157
+ for pattern in self.IDLE_PATTERNS:
158
+ if re.search(pattern, last_line):
159
+ logger.debug(f"Detected idle state with pattern: {pattern}")
160
+ return True
161
+
162
+ return False
163
+
164
+ def detect_error(self, output: str) -> Optional[str]:
165
+ """Recognize error states and extract error message."""
166
+ clean = self.strip_ansi(output)
167
+
168
+ for pattern in self.ERROR_PATTERNS:
169
+ match = re.search(pattern, clean, re.IGNORECASE)
170
+ if match:
171
+ for line in clean.split("\n"):
172
+ if re.search(pattern, line, re.IGNORECASE):
173
+ error_msg = line.strip()
174
+ logger.warning(f"Detected error: {error_msg}")
175
+ return error_msg
176
+
177
+ return None
178
+
179
+ def detect_question(
180
+ self, output: str
181
+ ) -> tuple[bool, Optional[str], Optional[List[str]]]:
182
+ """Detect if Codex is asking a question."""
183
+ clean = self.strip_ansi(output)
184
+
185
+ for pattern in self.QUESTION_PATTERNS:
186
+ if re.search(pattern, clean, re.IGNORECASE):
187
+ lines = clean.strip().split("\n")
188
+ question = None
189
+ options = []
190
+
191
+ for line in lines:
192
+ if re.search(pattern, line, re.IGNORECASE):
193
+ question = line.strip()
194
+
195
+ # Look for numbered options
196
+ opt_match = re.match(r"^\s*(\d+)[.):]\s*(.+)$", line)
197
+ if opt_match:
198
+ options.append(opt_match.group(2).strip())
199
+
200
+ logger.debug(
201
+ f"Detected question: {question}, options: {options if options else 'none'}"
202
+ )
203
+ return True, question, options if options else None
204
+
205
+ return False, None, None
206
+
207
+ def parse_response(self, output: str) -> ParsedResponse:
208
+ """Extract meaningful content from Codex output."""
209
+ if not output:
210
+ return ParsedResponse(
211
+ content="",
212
+ is_complete=False,
213
+ is_error=False,
214
+ is_question=False,
215
+ )
216
+
217
+ clean = self.strip_ansi(output)
218
+ error_msg = self.detect_error(output)
219
+ is_question, question_text, options = self.detect_question(output)
220
+ is_complete = self.detect_idle(output)
221
+
222
+ response = ParsedResponse(
223
+ content=clean,
224
+ is_complete=is_complete,
225
+ is_error=error_msg is not None,
226
+ error_message=error_msg,
227
+ is_question=is_question,
228
+ question_text=question_text,
229
+ options=options,
230
+ )
231
+
232
+ logger.debug(
233
+ f"Parsed response: complete={is_complete}, error={error_msg is not None}, "
234
+ f"question={is_question}"
235
+ )
236
+
237
+ return response