claude-mpm 5.4.96__py3-none-any.whl → 5.6.10__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.

Potentially problematic release.


This version of claude-mpm might be problematic. Click here for more details.

Files changed (191) hide show
  1. claude_mpm/VERSION +1 -1
  2. claude_mpm/agents/{CLAUDE_MPM_FOUNDERS_OUTPUT_STYLE.md → CLAUDE_MPM_RESEARCH_OUTPUT_STYLE.md} +14 -6
  3. claude_mpm/agents/PM_INSTRUCTIONS.md +44 -10
  4. claude_mpm/agents/WORKFLOW.md +2 -0
  5. claude_mpm/agents/templates/circuit-breakers.md +26 -17
  6. claude_mpm/cli/commands/autotodos.py +45 -5
  7. claude_mpm/cli/commands/commander.py +46 -0
  8. claude_mpm/cli/commands/hook_errors.py +60 -60
  9. claude_mpm/cli/commands/run.py +35 -3
  10. claude_mpm/cli/commands/skill_source.py +51 -2
  11. claude_mpm/cli/commands/skills.py +5 -3
  12. claude_mpm/cli/executor.py +32 -17
  13. claude_mpm/cli/parsers/base_parser.py +17 -0
  14. claude_mpm/cli/parsers/commander_parser.py +83 -0
  15. claude_mpm/cli/parsers/run_parser.py +10 -0
  16. claude_mpm/cli/parsers/skill_source_parser.py +4 -0
  17. claude_mpm/cli/parsers/skills_parser.py +5 -0
  18. claude_mpm/cli/startup.py +20 -2
  19. claude_mpm/cli/utils.py +7 -3
  20. claude_mpm/commander/__init__.py +72 -0
  21. claude_mpm/commander/adapters/__init__.py +31 -0
  22. claude_mpm/commander/adapters/base.py +191 -0
  23. claude_mpm/commander/adapters/claude_code.py +361 -0
  24. claude_mpm/commander/adapters/communication.py +366 -0
  25. claude_mpm/commander/api/__init__.py +16 -0
  26. claude_mpm/commander/api/app.py +105 -0
  27. claude_mpm/commander/api/errors.py +133 -0
  28. claude_mpm/commander/api/routes/__init__.py +8 -0
  29. claude_mpm/commander/api/routes/events.py +184 -0
  30. claude_mpm/commander/api/routes/inbox.py +171 -0
  31. claude_mpm/commander/api/routes/messages.py +148 -0
  32. claude_mpm/commander/api/routes/projects.py +271 -0
  33. claude_mpm/commander/api/routes/sessions.py +228 -0
  34. claude_mpm/commander/api/routes/work.py +260 -0
  35. claude_mpm/commander/api/schemas.py +182 -0
  36. claude_mpm/commander/chat/__init__.py +7 -0
  37. claude_mpm/commander/chat/cli.py +107 -0
  38. claude_mpm/commander/chat/commands.py +96 -0
  39. claude_mpm/commander/chat/repl.py +310 -0
  40. claude_mpm/commander/config.py +49 -0
  41. claude_mpm/commander/config_loader.py +115 -0
  42. claude_mpm/commander/daemon.py +398 -0
  43. claude_mpm/commander/events/__init__.py +26 -0
  44. claude_mpm/commander/events/manager.py +332 -0
  45. claude_mpm/commander/frameworks/__init__.py +12 -0
  46. claude_mpm/commander/frameworks/base.py +143 -0
  47. claude_mpm/commander/frameworks/claude_code.py +58 -0
  48. claude_mpm/commander/frameworks/mpm.py +62 -0
  49. claude_mpm/commander/inbox/__init__.py +16 -0
  50. claude_mpm/commander/inbox/dedup.py +128 -0
  51. claude_mpm/commander/inbox/inbox.py +224 -0
  52. claude_mpm/commander/inbox/models.py +70 -0
  53. claude_mpm/commander/instance_manager.py +337 -0
  54. claude_mpm/commander/llm/__init__.py +6 -0
  55. claude_mpm/commander/llm/openrouter_client.py +167 -0
  56. claude_mpm/commander/llm/summarizer.py +70 -0
  57. claude_mpm/commander/models/__init__.py +18 -0
  58. claude_mpm/commander/models/events.py +121 -0
  59. claude_mpm/commander/models/project.py +162 -0
  60. claude_mpm/commander/models/work.py +214 -0
  61. claude_mpm/commander/parsing/__init__.py +20 -0
  62. claude_mpm/commander/parsing/extractor.py +132 -0
  63. claude_mpm/commander/parsing/output_parser.py +270 -0
  64. claude_mpm/commander/parsing/patterns.py +100 -0
  65. claude_mpm/commander/persistence/__init__.py +11 -0
  66. claude_mpm/commander/persistence/event_store.py +274 -0
  67. claude_mpm/commander/persistence/state_store.py +309 -0
  68. claude_mpm/commander/persistence/work_store.py +164 -0
  69. claude_mpm/commander/polling/__init__.py +13 -0
  70. claude_mpm/commander/polling/event_detector.py +104 -0
  71. claude_mpm/commander/polling/output_buffer.py +49 -0
  72. claude_mpm/commander/polling/output_poller.py +153 -0
  73. claude_mpm/commander/project_session.py +268 -0
  74. claude_mpm/commander/proxy/__init__.py +12 -0
  75. claude_mpm/commander/proxy/formatter.py +89 -0
  76. claude_mpm/commander/proxy/output_handler.py +191 -0
  77. claude_mpm/commander/proxy/relay.py +155 -0
  78. claude_mpm/commander/registry.py +404 -0
  79. claude_mpm/commander/runtime/__init__.py +10 -0
  80. claude_mpm/commander/runtime/executor.py +191 -0
  81. claude_mpm/commander/runtime/monitor.py +316 -0
  82. claude_mpm/commander/session/__init__.py +6 -0
  83. claude_mpm/commander/session/context.py +81 -0
  84. claude_mpm/commander/session/manager.py +59 -0
  85. claude_mpm/commander/tmux_orchestrator.py +361 -0
  86. claude_mpm/commander/web/__init__.py +1 -0
  87. claude_mpm/commander/work/__init__.py +30 -0
  88. claude_mpm/commander/work/executor.py +189 -0
  89. claude_mpm/commander/work/queue.py +405 -0
  90. claude_mpm/commander/workflow/__init__.py +27 -0
  91. claude_mpm/commander/workflow/event_handler.py +219 -0
  92. claude_mpm/commander/workflow/notifier.py +146 -0
  93. claude_mpm/commands/mpm-config.md +8 -0
  94. claude_mpm/commands/mpm-doctor.md +8 -0
  95. claude_mpm/commands/mpm-help.md +8 -0
  96. claude_mpm/commands/mpm-init.md +8 -0
  97. claude_mpm/commands/mpm-monitor.md +8 -0
  98. claude_mpm/commands/mpm-organize.md +8 -0
  99. claude_mpm/commands/mpm-postmortem.md +8 -0
  100. claude_mpm/commands/mpm-session-resume.md +8 -0
  101. claude_mpm/commands/mpm-status.md +8 -0
  102. claude_mpm/commands/mpm-ticket-view.md +8 -0
  103. claude_mpm/commands/mpm-version.md +8 -0
  104. claude_mpm/commands/mpm.md +8 -0
  105. claude_mpm/config/agent_presets.py +8 -7
  106. claude_mpm/config/skill_sources.py +16 -0
  107. claude_mpm/core/config.py +32 -19
  108. claude_mpm/core/logger.py +26 -9
  109. claude_mpm/core/logging_utils.py +35 -11
  110. claude_mpm/core/output_style_manager.py +15 -5
  111. claude_mpm/core/unified_config.py +10 -6
  112. claude_mpm/core/unified_paths.py +68 -80
  113. claude_mpm/experimental/cli_enhancements.py +2 -1
  114. claude_mpm/hooks/claude_hooks/__pycache__/__init__.cpython-312.pyc +0 -0
  115. claude_mpm/hooks/claude_hooks/__pycache__/__init__.cpython-314.pyc +0 -0
  116. claude_mpm/hooks/claude_hooks/__pycache__/auto_pause_handler.cpython-311.pyc +0 -0
  117. claude_mpm/hooks/claude_hooks/__pycache__/auto_pause_handler.cpython-312.pyc +0 -0
  118. claude_mpm/hooks/claude_hooks/__pycache__/auto_pause_handler.cpython-314.pyc +0 -0
  119. claude_mpm/hooks/claude_hooks/__pycache__/event_handlers.cpython-311.pyc +0 -0
  120. claude_mpm/hooks/claude_hooks/__pycache__/event_handlers.cpython-312.pyc +0 -0
  121. claude_mpm/hooks/claude_hooks/__pycache__/event_handlers.cpython-314.pyc +0 -0
  122. claude_mpm/hooks/claude_hooks/__pycache__/hook_handler.cpython-311.pyc +0 -0
  123. claude_mpm/hooks/claude_hooks/__pycache__/hook_handler.cpython-312.pyc +0 -0
  124. claude_mpm/hooks/claude_hooks/__pycache__/hook_handler.cpython-314.pyc +0 -0
  125. claude_mpm/hooks/claude_hooks/__pycache__/installer.cpython-311.pyc +0 -0
  126. claude_mpm/hooks/claude_hooks/__pycache__/installer.cpython-314.pyc +0 -0
  127. claude_mpm/hooks/claude_hooks/__pycache__/memory_integration.cpython-311.pyc +0 -0
  128. claude_mpm/hooks/claude_hooks/__pycache__/memory_integration.cpython-312.pyc +0 -0
  129. claude_mpm/hooks/claude_hooks/__pycache__/memory_integration.cpython-314.pyc +0 -0
  130. claude_mpm/hooks/claude_hooks/__pycache__/response_tracking.cpython-311.pyc +0 -0
  131. claude_mpm/hooks/claude_hooks/__pycache__/response_tracking.cpython-312.pyc +0 -0
  132. claude_mpm/hooks/claude_hooks/__pycache__/response_tracking.cpython-314.pyc +0 -0
  133. claude_mpm/hooks/claude_hooks/__pycache__/tool_analysis.cpython-312.pyc +0 -0
  134. claude_mpm/hooks/claude_hooks/__pycache__/tool_analysis.cpython-314.pyc +0 -0
  135. claude_mpm/hooks/claude_hooks/auto_pause_handler.py +29 -30
  136. claude_mpm/hooks/claude_hooks/event_handlers.py +90 -99
  137. claude_mpm/hooks/claude_hooks/hook_handler.py +81 -88
  138. claude_mpm/hooks/claude_hooks/hook_wrapper.sh +6 -11
  139. claude_mpm/hooks/claude_hooks/installer.py +116 -8
  140. claude_mpm/hooks/claude_hooks/memory_integration.py +51 -31
  141. claude_mpm/hooks/claude_hooks/response_tracking.py +39 -58
  142. claude_mpm/hooks/claude_hooks/services/__pycache__/__init__.cpython-312.pyc +0 -0
  143. claude_mpm/hooks/claude_hooks/services/__pycache__/__init__.cpython-314.pyc +0 -0
  144. claude_mpm/hooks/claude_hooks/services/__pycache__/connection_manager_http.cpython-311.pyc +0 -0
  145. claude_mpm/hooks/claude_hooks/services/__pycache__/connection_manager_http.cpython-312.pyc +0 -0
  146. claude_mpm/hooks/claude_hooks/services/__pycache__/connection_manager_http.cpython-314.pyc +0 -0
  147. claude_mpm/hooks/claude_hooks/services/__pycache__/duplicate_detector.cpython-312.pyc +0 -0
  148. claude_mpm/hooks/claude_hooks/services/__pycache__/duplicate_detector.cpython-314.pyc +0 -0
  149. claude_mpm/hooks/claude_hooks/services/__pycache__/state_manager.cpython-311.pyc +0 -0
  150. claude_mpm/hooks/claude_hooks/services/__pycache__/state_manager.cpython-312.pyc +0 -0
  151. claude_mpm/hooks/claude_hooks/services/__pycache__/state_manager.cpython-314.pyc +0 -0
  152. claude_mpm/hooks/claude_hooks/services/__pycache__/subagent_processor.cpython-311.pyc +0 -0
  153. claude_mpm/hooks/claude_hooks/services/__pycache__/subagent_processor.cpython-312.pyc +0 -0
  154. claude_mpm/hooks/claude_hooks/services/__pycache__/subagent_processor.cpython-314.pyc +0 -0
  155. claude_mpm/hooks/claude_hooks/services/connection_manager.py +23 -28
  156. claude_mpm/hooks/claude_hooks/services/connection_manager_http.py +36 -103
  157. claude_mpm/hooks/claude_hooks/services/state_manager.py +23 -36
  158. claude_mpm/hooks/claude_hooks/services/subagent_processor.py +47 -73
  159. claude_mpm/hooks/session_resume_hook.py +22 -18
  160. claude_mpm/hooks/templates/pre_tool_use_template.py +10 -2
  161. claude_mpm/scripts/claude-hook-handler.sh +43 -16
  162. claude_mpm/services/agents/agent_recommendation_service.py +8 -8
  163. claude_mpm/services/agents/agent_selection_service.py +2 -2
  164. claude_mpm/services/agents/loading/framework_agent_loader.py +75 -2
  165. claude_mpm/services/agents/single_tier_deployment_service.py +4 -4
  166. claude_mpm/services/event_log.py +8 -0
  167. claude_mpm/services/pm_skills_deployer.py +84 -6
  168. claude_mpm/services/skills/git_skill_source_manager.py +130 -10
  169. claude_mpm/services/skills/selective_skill_deployer.py +28 -0
  170. claude_mpm/services/skills/skill_discovery_service.py +74 -4
  171. claude_mpm/services/skills_deployer.py +31 -5
  172. claude_mpm/skills/bundled/pm/mpm/SKILL.md +38 -0
  173. claude_mpm/skills/bundled/pm/mpm-config/SKILL.md +29 -0
  174. claude_mpm/skills/bundled/pm/mpm-doctor/SKILL.md +53 -0
  175. claude_mpm/skills/bundled/pm/mpm-help/SKILL.md +35 -0
  176. claude_mpm/skills/bundled/pm/mpm-init/SKILL.md +125 -0
  177. claude_mpm/skills/bundled/pm/mpm-monitor/SKILL.md +32 -0
  178. claude_mpm/skills/bundled/pm/mpm-organize/SKILL.md +121 -0
  179. claude_mpm/skills/bundled/pm/mpm-postmortem/SKILL.md +22 -0
  180. claude_mpm/skills/bundled/pm/mpm-session-resume/SKILL.md +31 -0
  181. claude_mpm/skills/bundled/pm/mpm-status/SKILL.md +37 -0
  182. claude_mpm/skills/bundled/pm/mpm-ticket-view/SKILL.md +110 -0
  183. claude_mpm/skills/bundled/pm/mpm-version/SKILL.md +21 -0
  184. {claude_mpm-5.4.96.dist-info → claude_mpm-5.6.10.dist-info}/METADATA +18 -4
  185. {claude_mpm-5.4.96.dist-info → claude_mpm-5.6.10.dist-info}/RECORD +190 -79
  186. claude_mpm/hooks/claude_hooks/services/__pycache__/connection_manager.cpython-311.pyc +0 -0
  187. {claude_mpm-5.4.96.dist-info → claude_mpm-5.6.10.dist-info}/WHEEL +0 -0
  188. {claude_mpm-5.4.96.dist-info → claude_mpm-5.6.10.dist-info}/entry_points.txt +0 -0
  189. {claude_mpm-5.4.96.dist-info → claude_mpm-5.6.10.dist-info}/licenses/LICENSE +0 -0
  190. {claude_mpm-5.4.96.dist-info → claude_mpm-5.6.10.dist-info}/licenses/LICENSE-FAQ.md +0 -0
  191. {claude_mpm-5.4.96.dist-info → claude_mpm-5.6.10.dist-info}/top_level.txt +0 -0
@@ -27,7 +27,9 @@ _CACHED_CLAUDE_VERSION: Optional[str] = None
27
27
  _VERSION_DETECTED: bool = False
28
28
 
29
29
  # Output style types
30
- OutputStyleType = Literal["professional", "teaching", "founders"]
30
+ OutputStyleType = Literal[
31
+ "professional", "teaching", "research", "founders"
32
+ ] # "founders" is deprecated, use "research"
31
33
 
32
34
 
33
35
  class StyleConfig(TypedDict):
@@ -44,7 +46,7 @@ class OutputStyleManager:
44
46
  Supports three output styles:
45
47
  - professional: Default Claude MPM style (claude-mpm.md)
46
48
  - teaching: Adaptive teaching mode (claude-mpm-teacher.md)
47
- - founders: Non-technical mode for startup founders (claude-mpm-founders.md)
49
+ - research: Codebase research mode for founders, PMs, and developers (claude-mpm-research.md)
48
50
  """
49
51
 
50
52
  def __init__(self) -> None:
@@ -72,12 +74,20 @@ class OutputStyleManager:
72
74
  target=self.output_style_dir / "claude-mpm-teacher.md",
73
75
  name="Claude MPM Teacher",
74
76
  ),
77
+ "research": StyleConfig(
78
+ source=Path(__file__).parent.parent
79
+ / "agents"
80
+ / "CLAUDE_MPM_RESEARCH_OUTPUT_STYLE.md",
81
+ target=self.output_style_dir / "claude-mpm-research.md",
82
+ name="Claude MPM Research",
83
+ ),
84
+ # Backward compatibility alias (deprecated)
75
85
  "founders": StyleConfig(
76
86
  source=Path(__file__).parent.parent
77
87
  / "agents"
78
- / "CLAUDE_MPM_FOUNDERS_OUTPUT_STYLE.md",
79
- target=self.output_style_dir / "claude-mpm-founders.md",
80
- name="Claude MPM Founders",
88
+ / "CLAUDE_MPM_RESEARCH_OUTPUT_STYLE.md",
89
+ target=self.output_style_dir / "claude-mpm-research.md",
90
+ name="Claude MPM Research",
81
91
  ),
82
92
  }
83
93
 
@@ -73,15 +73,19 @@ class AgentConfig(BaseModel):
73
73
  )
74
74
 
75
75
  # Required agents that are always deployed
76
+ # Standard 7 core agents for essential PM workflow functionality
77
+ # These are auto-deployed when no agents are specified in configuration
76
78
  required: List[str] = Field(
77
79
  default_factory=lambda: [
78
- "research",
79
- "mpm-skills-manager",
80
- "mpm-agent-manager",
81
- "memory-manager-agent", # Specific agent ID (not generic "memory-manager")
82
- "ticketing",
80
+ "engineer", # General-purpose implementation
81
+ "research", # Codebase exploration and analysis
82
+ "qa", # Testing and quality assurance
83
+ "web-qa", # Browser-based testing specialist
84
+ "documentation", # Documentation generation
85
+ "ops", # Basic deployment operations
86
+ "ticketing", # Ticket tracking (essential for PM workflow)
83
87
  ],
84
- description="Agents that are always deployed (core system agents)",
88
+ description="Agents that are always deployed (standard 7 core agents)",
85
89
  )
86
90
 
87
91
  include_universal: bool = Field(
@@ -76,6 +76,7 @@ class DeploymentContext(Enum):
76
76
  EDITABLE_INSTALL = "editable_install"
77
77
  PIP_INSTALL = "pip_install"
78
78
  PIPX_INSTALL = "pipx_install"
79
+ UV_TOOLS = "uv_tools"
79
80
  SYSTEM_PACKAGE = "system_package"
80
81
 
81
82
 
@@ -190,113 +191,100 @@ class PathContext:
190
191
 
191
192
  Priority order:
192
193
  1. Environment variable override (CLAUDE_MPM_DEV_MODE)
193
- 2. Current working directory is a claude-mpm development project
194
- 3. Editable installation detection
195
- 4. Path-based detection (development, pipx, system, pip)
194
+ 2. Package installation path (uv tools, pipx, site-packages, editable)
195
+ 3. Current working directory (opt-in with CLAUDE_MPM_PREFER_LOCAL_SOURCE)
196
+
197
+ This ensures installed packages use their installation paths rather than
198
+ accidentally picking up development paths from CWD.
196
199
  """
197
- # Check for environment variable override
200
+ # 1. Explicit environment variable override
198
201
  if os.environ.get("CLAUDE_MPM_DEV_MODE", "").lower() in ("1", "true", "yes"):
199
202
  logger.debug(
200
203
  "Development mode forced via CLAUDE_MPM_DEV_MODE environment variable"
201
204
  )
202
205
  return DeploymentContext.DEVELOPMENT
203
206
 
204
- # Check if current working directory is a claude-mpm development project
205
- # This handles the case where pipx claude-mpm is run from within the dev directory
206
- cwd = _safe_cwd()
207
- current = cwd
208
- for _ in range(5): # Check up to 5 levels up from current directory
209
- if (current / "pyproject.toml").exists() and (
210
- current / "src" / "claude_mpm"
211
- ).exists():
212
- # Check if this is the claude-mpm project
213
- try:
214
- pyproject_content = (current / "pyproject.toml").read_text()
215
- if (
216
- 'name = "claude-mpm"' in pyproject_content
217
- or '"claude-mpm"' in pyproject_content
218
- ):
219
- logger.debug(
220
- f"Detected claude-mpm development directory at {current}"
221
- )
222
- logger.debug(
223
- "Using development mode for local source preference"
224
- )
225
- return DeploymentContext.DEVELOPMENT
226
- except Exception: # nosec B110
227
- pass
228
- if current == current.parent:
229
- break
230
- current = current.parent
231
-
207
+ # 2. Check where the actual package is installed
232
208
  try:
233
209
  import claude_mpm
234
210
 
235
211
  module_path = Path(claude_mpm.__file__).parent
212
+ package_str = str(module_path)
236
213
 
237
- # First check if this is an editable install, regardless of path
238
- # This is important for cases where pipx points to a development installation
239
- if PathContext._is_editable_install():
240
- logger.debug("Detected editable/development installation")
241
- # Check if we should use development paths
242
- # This could be because we're in a src/ directory or running from dev directory
243
- if module_path.parent.name == "src":
244
- return DeploymentContext.DEVELOPMENT
245
- if "pipx" in str(module_path):
246
- # Running via pipx but from within a development directory
247
- # Use development mode to prefer local source over pipx installation
248
- cwd = _safe_cwd()
249
- current = cwd
250
- for _ in range(5):
251
- if (current / "src" / "claude_mpm").exists() and (
252
- current / "pyproject.toml"
253
- ).exists():
254
- logger.debug(
255
- "Running pipx from development directory, using development mode"
256
- )
257
- return DeploymentContext.DEVELOPMENT
258
- if current == current.parent:
259
- break
260
- current = current.parent
261
- return DeploymentContext.EDITABLE_INSTALL
262
- return DeploymentContext.EDITABLE_INSTALL
214
+ # UV tools installation (~/.local/share/uv/tools/)
215
+ if "/.local/share/uv/tools/" in package_str:
216
+ logger.debug(f"Detected uv tools installation at {module_path}")
217
+ return DeploymentContext.UV_TOOLS
263
218
 
264
- # Check for development mode based on directory structure
265
- # module_path is typically /path/to/project/src/claude_mpm
266
- if (
267
- module_path.parent.name == "src"
268
- and (module_path.parent.parent / "src" / "claude_mpm").exists()
269
- ):
219
+ # pipx installation (~/.local/pipx/venvs/)
220
+ if "/.local/pipx/venvs/" in package_str or "/pipx/" in package_str:
221
+ logger.debug(f"Detected pipx installation at {module_path}")
222
+ return DeploymentContext.PIPX_INSTALL
223
+
224
+ # site-packages (pip install) - but not editable
225
+ if "/site-packages/" in package_str and "/src/" not in package_str:
226
+ logger.debug(f"Detected pip installation at {module_path}")
227
+ return DeploymentContext.PIP_INSTALL
228
+
229
+ # Editable install (pip install -e) - module in src/
230
+ if module_path.parent.name == "src":
231
+ # Check if this is truly an editable install
232
+ if PathContext._is_editable_install():
233
+ logger.debug(f"Detected editable installation at {module_path}")
234
+ return DeploymentContext.EDITABLE_INSTALL
235
+ # Module in src/ but not editable - development mode
270
236
  logger.debug(
271
237
  f"Detected development mode via directory structure at {module_path}"
272
238
  )
273
239
  return DeploymentContext.DEVELOPMENT
274
240
 
275
- # Check for pipx install
276
- if "pipx" in str(module_path):
277
- logger.debug(f"Detected pipx installation at {module_path}")
278
- return DeploymentContext.PIPX_INSTALL
279
-
280
- # Check for system package
281
- if "dist-packages" in str(module_path):
241
+ # dist-packages (system package manager)
242
+ if "dist-packages" in package_str:
282
243
  logger.debug(f"Detected system package installation at {module_path}")
283
244
  return DeploymentContext.SYSTEM_PACKAGE
284
245
 
285
- # Check for site-packages (could be pip or editable)
286
- if "site-packages" in str(module_path):
287
- # Already checked for editable above, so this is a regular pip install
288
- logger.debug(f"Detected pip installation at {module_path}")
289
- return DeploymentContext.PIP_INSTALL
290
-
291
- # Default to pip install
246
+ # Default to pip install for any other installation
292
247
  logger.debug(f"Defaulting to pip installation for {module_path}")
293
248
  return DeploymentContext.PIP_INSTALL
294
249
 
295
250
  except ImportError:
296
251
  logger.debug(
297
- "ImportError during context detection, defaulting to development"
252
+ "ImportError during module path detection, checking CWD as fallback"
298
253
  )
299
- return DeploymentContext.DEVELOPMENT
254
+
255
+ # 3. CWD-based detection (OPT-IN ONLY for explicit development work)
256
+ # Only use CWD if explicitly requested or no package installation found
257
+ if os.environ.get("CLAUDE_MPM_PREFER_LOCAL_SOURCE", "").lower() in (
258
+ "1",
259
+ "true",
260
+ "yes",
261
+ ):
262
+ cwd = _safe_cwd()
263
+ current = cwd
264
+ for _ in range(5): # Check up to 5 levels up from current directory
265
+ if (current / "pyproject.toml").exists() and (
266
+ current / "src" / "claude_mpm"
267
+ ).exists():
268
+ # Check if this is the claude-mpm project
269
+ try:
270
+ pyproject_content = (current / "pyproject.toml").read_text()
271
+ if (
272
+ 'name = "claude-mpm"' in pyproject_content
273
+ or '"claude-mpm"' in pyproject_content
274
+ ):
275
+ logger.debug(
276
+ f"CLAUDE_MPM_PREFER_LOCAL_SOURCE: Using development directory at {current}"
277
+ )
278
+ return DeploymentContext.DEVELOPMENT
279
+ except Exception: # nosec B110
280
+ pass
281
+ if current == current.parent:
282
+ break
283
+ current = current.parent
284
+
285
+ # Final fallback: assume development mode
286
+ logger.debug("No installation detected, defaulting to development mode")
287
+ return DeploymentContext.DEVELOPMENT
300
288
 
301
289
 
302
290
  class UnifiedPathManager:
@@ -58,8 +58,9 @@ class CLIContext:
58
58
  else "%(message)s"
59
59
  )
60
60
 
61
+ # MUST use stderr to avoid corrupting hook JSON output
61
62
  logging.basicConfig(
62
- level=level, format=format_str, handlers=[logging.StreamHandler(sys.stdout)]
63
+ level=level, format=format_str, handlers=[logging.StreamHandler(sys.stderr)]
63
64
  )
64
65
  self.debug = debug
65
66
 
@@ -22,7 +22,7 @@ USAGE:
22
22
  threshold_crossed = auto_pause.on_usage_update(metadata["usage"])
23
23
  if threshold_crossed:
24
24
  warning = auto_pause.emit_threshold_warning(threshold_crossed)
25
- print(f"\n⚠️ {warning}", file=sys.stderr)
25
+ _log(f"\n⚠️ {warning}")
26
26
 
27
27
  # Record actions during pause mode
28
28
  if auto_pause.is_pause_active():
@@ -34,7 +34,6 @@ USAGE:
34
34
  """
35
35
 
36
36
  import os
37
- import sys
38
37
  from datetime import datetime, timezone
39
38
  from pathlib import Path
40
39
  from typing import Any, Dict, Optional
@@ -45,6 +44,15 @@ from claude_mpm.services.infrastructure.context_usage_tracker import (
45
44
  ContextUsageTracker,
46
45
  )
47
46
 
47
+ # Try to import _log from hook_handler, fall back to no-op
48
+ try:
49
+ from claude_mpm.hooks.claude_hooks.hook_handler import _log
50
+ except ImportError:
51
+
52
+ def _log(msg: str) -> None:
53
+ pass # Silent fallback
54
+
55
+
48
56
  logger = get_logger(__name__)
49
57
 
50
58
  # Debug mode
@@ -100,11 +108,10 @@ class AutoPauseHandler:
100
108
  self._previous_threshold = current_state.threshold_reached
101
109
 
102
110
  if DEBUG:
103
- print(
111
+ _log(
104
112
  f"AutoPauseHandler initialized: "
105
113
  f"{current_state.percentage_used:.1f}% context used, "
106
- f"threshold: {current_state.threshold_reached}",
107
- file=sys.stderr,
114
+ f"threshold: {current_state.threshold_reached}"
108
115
  )
109
116
  except Exception as e:
110
117
  logger.error(f"Failed to initialize AutoPauseHandler: {e}")
@@ -169,10 +176,9 @@ class AutoPauseHandler:
169
176
  self._previous_threshold = current_threshold
170
177
 
171
178
  if DEBUG:
172
- print(
179
+ _log(
173
180
  f"Context threshold crossed: {current_threshold} "
174
- f"({state.percentage_used:.1f}%)",
175
- file=sys.stderr,
181
+ f"({state.percentage_used:.1f}%)"
176
182
  )
177
183
 
178
184
  # Trigger auto-pause if threshold reached
@@ -184,7 +190,7 @@ class AutoPauseHandler:
184
190
  except Exception as e:
185
191
  logger.error(f"Failed to update usage: {e}")
186
192
  if DEBUG:
187
- print(f"❌ Usage update failed: {e}", file=sys.stderr)
193
+ _log(f"❌ Usage update failed: {e}")
188
194
  # Don't propagate error - auto-pause is optional
189
195
  return None
190
196
 
@@ -220,12 +226,12 @@ class AutoPauseHandler:
220
226
  )
221
227
 
222
228
  if DEBUG:
223
- print(f"Recorded tool call during pause: {tool_name}", file=sys.stderr)
229
+ _log(f"Recorded tool call during pause: {tool_name}")
224
230
 
225
231
  except Exception as e:
226
232
  logger.error(f"Failed to record tool call: {e}")
227
233
  if DEBUG:
228
- print(f"❌ Failed to record tool call: {e}", file=sys.stderr)
234
+ _log(f"❌ Failed to record tool call: {e}")
229
235
 
230
236
  def on_assistant_response(self, response_summary: str) -> None:
231
237
  """Record an assistant response if auto-pause is active.
@@ -257,15 +263,14 @@ class AutoPauseHandler:
257
263
  )
258
264
 
259
265
  if DEBUG:
260
- print(
261
- f"Recorded assistant response during pause (length: {len(summary)})",
262
- file=sys.stderr,
266
+ _log(
267
+ f"Recorded assistant response during pause (length: {len(summary)})"
263
268
  )
264
269
 
265
270
  except Exception as e:
266
271
  logger.error(f"Failed to record assistant response: {e}")
267
272
  if DEBUG:
268
- print(f"❌ Failed to record assistant response: {e}", file=sys.stderr)
273
+ _log(f"❌ Failed to record assistant response: {e}")
269
274
 
270
275
  def on_user_message(self, message_summary: str) -> None:
271
276
  """Record a user message if auto-pause is active.
@@ -297,15 +302,12 @@ class AutoPauseHandler:
297
302
  )
298
303
 
299
304
  if DEBUG:
300
- print(
301
- f"Recorded user message during pause (length: {len(summary)})",
302
- file=sys.stderr,
303
- )
305
+ _log(f"Recorded user message during pause (length: {len(summary)})")
304
306
 
305
307
  except Exception as e:
306
308
  logger.error(f"Failed to record user message: {e}")
307
309
  if DEBUG:
308
- print(f"❌ Failed to record user message: {e}", file=sys.stderr)
310
+ _log(f"❌ Failed to record user message: {e}")
309
311
 
310
312
  def on_session_end(self) -> Optional[Path]:
311
313
  """Called when session ends. Finalizes any active pause.
@@ -318,7 +320,7 @@ class AutoPauseHandler:
318
320
  """
319
321
  if not self.is_pause_active():
320
322
  if DEBUG:
321
- print("No active pause to finalize", file=sys.stderr)
323
+ _log("No active pause to finalize")
322
324
  return None
323
325
 
324
326
  try:
@@ -326,14 +328,14 @@ class AutoPauseHandler:
326
328
  session_path = self.pause_manager.finalize_pause(create_full_snapshot=True)
327
329
 
328
330
  if session_path and DEBUG:
329
- print(f"✅ Session finalized: {session_path.name}", file=sys.stderr)
331
+ _log(f"✅ Session finalized: {session_path.name}")
330
332
 
331
333
  return session_path
332
334
 
333
335
  except Exception as e:
334
336
  logger.error(f"Failed to finalize pause session: {e}")
335
337
  if DEBUG:
336
- print(f"❌ Failed to finalize pause: {e}", file=sys.stderr)
338
+ _log(f"❌ Failed to finalize pause: {e}")
337
339
  raise
338
340
 
339
341
  def is_pause_active(self) -> bool:
@@ -417,9 +419,7 @@ class AutoPauseHandler:
417
419
  # Check if pause is already active
418
420
  if self.is_pause_active():
419
421
  if DEBUG:
420
- print(
421
- "Auto-pause already active, skipping trigger", file=sys.stderr
422
- )
422
+ _log("Auto-pause already active, skipping trigger")
423
423
  return
424
424
 
425
425
  # Start incremental pause
@@ -429,16 +429,15 @@ class AutoPauseHandler:
429
429
  )
430
430
 
431
431
  if DEBUG:
432
- print(
432
+ _log(
433
433
  f"✅ Auto-pause triggered: {session_id} "
434
- f"({state.percentage_used:.1f}% context used)",
435
- file=sys.stderr,
434
+ f"({state.percentage_used:.1f}% context used)"
436
435
  )
437
436
 
438
437
  except Exception as e:
439
438
  logger.error(f"Failed to trigger auto-pause: {e}")
440
439
  if DEBUG:
441
- print(f"❌ Failed to trigger auto-pause: {e}", file=sys.stderr)
440
+ _log(f"❌ Failed to trigger auto-pause: {e}")
442
441
  # Don't propagate - auto-pause is optional
443
442
 
444
443
  def _summarize_dict(