claude-mpm 5.1.9__py3-none-any.whl → 5.4.48__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 (248) hide show
  1. claude_mpm/VERSION +1 -1
  2. claude_mpm/__init__.py +4 -0
  3. claude_mpm/agents/BASE_AGENT.md +164 -0
  4. claude_mpm/agents/CLAUDE_MPM_TEACHER_OUTPUT_STYLE.md +1 -1
  5. claude_mpm/agents/MEMORY.md +1 -1
  6. claude_mpm/agents/PM_INSTRUCTIONS.md +843 -900
  7. claude_mpm/agents/WORKFLOW.md +5 -254
  8. claude_mpm/agents/agent_loader.py +13 -44
  9. claude_mpm/agents/base_agent.json +1 -1
  10. claude_mpm/agents/frontmatter_validator.py +2 -2
  11. claude_mpm/agents/templates/circuit-breakers.md +138 -1
  12. claude_mpm/cli/__main__.py +4 -0
  13. claude_mpm/cli/chrome_devtools_installer.py +175 -0
  14. claude_mpm/cli/commands/agent_state_manager.py +18 -27
  15. claude_mpm/cli/commands/agents.py +9 -40
  16. claude_mpm/cli/commands/auto_configure.py +210 -25
  17. claude_mpm/cli/commands/config.py +88 -2
  18. claude_mpm/cli/commands/configure.py +1098 -159
  19. claude_mpm/cli/commands/configure_agent_display.py +25 -6
  20. claude_mpm/cli/commands/mpm_init/core.py +225 -46
  21. claude_mpm/cli/commands/mpm_init/knowledge_extractor.py +481 -0
  22. claude_mpm/cli/commands/mpm_init/prompts.py +280 -0
  23. claude_mpm/cli/commands/postmortem.py +1 -1
  24. claude_mpm/cli/commands/profile.py +277 -0
  25. claude_mpm/cli/commands/skills.py +218 -197
  26. claude_mpm/cli/commands/summarize.py +413 -0
  27. claude_mpm/cli/executor.py +21 -3
  28. claude_mpm/cli/interactive/agent_wizard.py +2 -2
  29. claude_mpm/cli/parsers/agents_parser.py +0 -9
  30. claude_mpm/cli/parsers/auto_configure_parser.py +0 -138
  31. claude_mpm/cli/parsers/base_parser.py +12 -0
  32. claude_mpm/cli/parsers/config_parser.py +153 -83
  33. claude_mpm/cli/parsers/profile_parser.py +148 -0
  34. claude_mpm/cli/parsers/skills_parser.py +0 -5
  35. claude_mpm/cli/startup.py +876 -149
  36. claude_mpm/commands/mpm-config.md +28 -0
  37. claude_mpm/commands/mpm-doctor.md +9 -22
  38. claude_mpm/commands/mpm-help.md +5 -287
  39. claude_mpm/commands/mpm-init.md +81 -507
  40. claude_mpm/commands/mpm-monitor.md +15 -402
  41. claude_mpm/commands/mpm-organize.md +120 -0
  42. claude_mpm/commands/mpm-postmortem.md +6 -108
  43. claude_mpm/commands/mpm-session-resume.md +12 -363
  44. claude_mpm/commands/mpm-status.md +5 -69
  45. claude_mpm/commands/mpm-ticket-view.md +52 -495
  46. claude_mpm/commands/mpm-version.md +5 -107
  47. claude_mpm/config/agent_sources.py +27 -0
  48. claude_mpm/core/config.py +2 -4
  49. claude_mpm/core/framework/formatters/content_formatter.py +3 -13
  50. claude_mpm/core/framework/loaders/agent_loader.py +8 -5
  51. claude_mpm/core/framework/loaders/instruction_loader.py +52 -11
  52. claude_mpm/core/framework_loader.py +4 -2
  53. claude_mpm/core/logger.py +13 -0
  54. claude_mpm/core/optimized_startup.py +59 -0
  55. claude_mpm/core/shared/config_loader.py +1 -1
  56. claude_mpm/core/socketio_pool.py +3 -3
  57. claude_mpm/core/unified_agent_registry.py +5 -15
  58. claude_mpm/dashboard/static/svelte-build/_app/env.js +1 -0
  59. claude_mpm/dashboard/static/svelte-build/_app/immutable/assets/0.B_FtCwCQ.css +1 -0
  60. claude_mpm/dashboard/static/svelte-build/_app/immutable/assets/2.Cl_eSA4x.css +1 -0
  61. claude_mpm/dashboard/static/svelte-build/_app/immutable/chunks/BgChzWQ1.js +1 -0
  62. claude_mpm/dashboard/static/svelte-build/_app/immutable/chunks/CIXEwuWe.js +1 -0
  63. claude_mpm/dashboard/static/svelte-build/_app/immutable/chunks/CWc5urbQ.js +1 -0
  64. claude_mpm/dashboard/static/svelte-build/_app/immutable/chunks/DMkZpdF2.js +2 -0
  65. claude_mpm/dashboard/static/svelte-build/_app/immutable/chunks/DjhvlsAc.js +1 -0
  66. claude_mpm/dashboard/static/svelte-build/_app/immutable/chunks/N4qtv3Hx.js +2 -0
  67. claude_mpm/dashboard/static/svelte-build/_app/immutable/chunks/uj46x2Wr.js +1 -0
  68. claude_mpm/dashboard/static/svelte-build/_app/immutable/entry/app.DTL5mJO-.js +2 -0
  69. claude_mpm/dashboard/static/svelte-build/_app/immutable/entry/start.DzuEhzqh.js +1 -0
  70. claude_mpm/dashboard/static/svelte-build/_app/immutable/nodes/0.CAGBuiOw.js +1 -0
  71. claude_mpm/dashboard/static/svelte-build/_app/immutable/nodes/1.DFLC8jdE.js +1 -0
  72. claude_mpm/dashboard/static/svelte-build/_app/immutable/nodes/2.DPvEihJJ.js +10 -0
  73. claude_mpm/dashboard/static/svelte-build/_app/version.json +1 -0
  74. claude_mpm/dashboard/static/svelte-build/favicon.svg +7 -0
  75. claude_mpm/dashboard/static/svelte-build/index.html +36 -0
  76. claude_mpm/hooks/claude_hooks/__pycache__/__init__.cpython-311.pyc +0 -0
  77. claude_mpm/hooks/claude_hooks/__pycache__/correlation_manager.cpython-311.pyc +0 -0
  78. claude_mpm/hooks/claude_hooks/__pycache__/event_handlers.cpython-311.pyc +0 -0
  79. claude_mpm/hooks/claude_hooks/__pycache__/hook_handler.cpython-311.pyc +0 -0
  80. claude_mpm/hooks/claude_hooks/__pycache__/installer.cpython-311.pyc +0 -0
  81. claude_mpm/hooks/claude_hooks/__pycache__/memory_integration.cpython-311.pyc +0 -0
  82. claude_mpm/hooks/claude_hooks/__pycache__/response_tracking.cpython-311.pyc +0 -0
  83. claude_mpm/hooks/claude_hooks/__pycache__/tool_analysis.cpython-311.pyc +0 -0
  84. claude_mpm/hooks/claude_hooks/correlation_manager.py +60 -0
  85. claude_mpm/hooks/claude_hooks/event_handlers.py +211 -78
  86. claude_mpm/hooks/claude_hooks/hook_handler.py +155 -1
  87. claude_mpm/hooks/claude_hooks/installer.py +33 -10
  88. claude_mpm/hooks/claude_hooks/memory_integration.py +26 -9
  89. claude_mpm/hooks/claude_hooks/response_tracking.py +2 -3
  90. claude_mpm/hooks/claude_hooks/services/__pycache__/__init__.cpython-311.pyc +0 -0
  91. claude_mpm/hooks/claude_hooks/services/__pycache__/connection_manager.cpython-311.pyc +0 -0
  92. claude_mpm/hooks/claude_hooks/services/__pycache__/connection_manager_http.cpython-311.pyc +0 -0
  93. claude_mpm/hooks/claude_hooks/services/__pycache__/duplicate_detector.cpython-311.pyc +0 -0
  94. claude_mpm/hooks/claude_hooks/services/__pycache__/state_manager.cpython-311.pyc +0 -0
  95. claude_mpm/hooks/claude_hooks/services/__pycache__/subagent_processor.cpython-311.pyc +0 -0
  96. claude_mpm/hooks/claude_hooks/services/connection_manager.py +30 -6
  97. claude_mpm/hooks/kuzu_memory_hook.py +5 -5
  98. claude_mpm/hooks/memory_integration_hook.py +46 -1
  99. claude_mpm/init.py +63 -19
  100. claude_mpm/models/git_repository.py +3 -3
  101. claude_mpm/scripts/claude-hook-handler.sh +58 -18
  102. claude_mpm/scripts/launch_monitor.py +93 -13
  103. claude_mpm/services/agents/agent_builder.py +3 -3
  104. claude_mpm/services/agents/agent_recommendation_service.py +278 -0
  105. claude_mpm/services/agents/agent_review_service.py +280 -0
  106. claude_mpm/services/agents/cache_git_manager.py +6 -6
  107. claude_mpm/services/agents/deployment/agent_deployment.py +29 -7
  108. claude_mpm/services/agents/deployment/agent_discovery_service.py +4 -5
  109. claude_mpm/services/agents/deployment/agent_format_converter.py +23 -13
  110. claude_mpm/services/agents/deployment/agent_template_builder.py +32 -20
  111. claude_mpm/services/agents/deployment/agents_directory_resolver.py +2 -2
  112. claude_mpm/services/agents/deployment/async_agent_deployment.py +31 -27
  113. claude_mpm/services/agents/deployment/local_template_deployment.py +3 -1
  114. claude_mpm/services/agents/deployment/multi_source_deployment_service.py +247 -35
  115. claude_mpm/services/agents/deployment/remote_agent_discovery_service.py +392 -87
  116. claude_mpm/services/agents/git_source_manager.py +53 -4
  117. claude_mpm/services/agents/loading/base_agent_manager.py +1 -13
  118. claude_mpm/services/agents/recommender.py +5 -3
  119. claude_mpm/services/agents/single_tier_deployment_service.py +2 -2
  120. claude_mpm/services/agents/sources/git_source_sync_service.py +120 -7
  121. claude_mpm/services/agents/startup_sync.py +22 -2
  122. claude_mpm/services/agents/toolchain_detector.py +10 -6
  123. claude_mpm/services/analysis/__init__.py +11 -1
  124. claude_mpm/services/analysis/clone_detector.py +1030 -0
  125. claude_mpm/services/command_deployment_service.py +81 -10
  126. claude_mpm/services/diagnostics/checks/agent_check.py +2 -2
  127. claude_mpm/services/diagnostics/checks/agent_sources_check.py +1 -1
  128. claude_mpm/services/event_bus/config.py +3 -1
  129. claude_mpm/services/git/git_operations_service.py +101 -16
  130. claude_mpm/services/monitor/daemon.py +9 -2
  131. claude_mpm/services/monitor/daemon_manager.py +39 -3
  132. claude_mpm/services/monitor/management/lifecycle.py +8 -1
  133. claude_mpm/services/monitor/server.py +698 -22
  134. claude_mpm/services/pm_skills_deployer.py +711 -0
  135. claude_mpm/services/profile_manager.py +331 -0
  136. claude_mpm/services/self_upgrade_service.py +120 -12
  137. claude_mpm/services/skills/__init__.py +3 -0
  138. claude_mpm/services/skills/git_skill_source_manager.py +130 -2
  139. claude_mpm/services/skills/selective_skill_deployer.py +704 -0
  140. claude_mpm/services/skills/skill_to_agent_mapper.py +406 -0
  141. claude_mpm/services/skills_deployer.py +127 -9
  142. claude_mpm/services/socketio/dashboard_server.py +1 -0
  143. claude_mpm/services/socketio/event_normalizer.py +51 -6
  144. claude_mpm/services/socketio/server/core.py +386 -108
  145. claude_mpm/services/version_control/git_operations.py +103 -0
  146. claude_mpm/skills/skill_manager.py +92 -3
  147. claude_mpm/utils/agent_dependency_loader.py +14 -2
  148. claude_mpm/utils/agent_filters.py +17 -44
  149. claude_mpm/utils/migration.py +4 -4
  150. claude_mpm/utils/robust_installer.py +47 -3
  151. {claude_mpm-5.1.9.dist-info → claude_mpm-5.4.48.dist-info}/METADATA +53 -87
  152. {claude_mpm-5.1.9.dist-info → claude_mpm-5.4.48.dist-info}/RECORD +157 -197
  153. claude_mpm-5.4.48.dist-info/entry_points.txt +5 -0
  154. claude_mpm-5.4.48.dist-info/licenses/LICENSE +94 -0
  155. claude_mpm-5.4.48.dist-info/licenses/LICENSE-FAQ.md +153 -0
  156. claude_mpm/agents/BASE_AGENT_TEMPLATE.md +0 -292
  157. claude_mpm/agents/BASE_DOCUMENTATION.md +0 -53
  158. claude_mpm/agents/BASE_OPS.md +0 -219
  159. claude_mpm/agents/BASE_PM.md +0 -480
  160. claude_mpm/agents/BASE_PROMPT_ENGINEER.md +0 -787
  161. claude_mpm/agents/BASE_QA.md +0 -167
  162. claude_mpm/agents/BASE_RESEARCH.md +0 -53
  163. claude_mpm/agents/base_agent_loader.py +0 -601
  164. claude_mpm/cli/commands/agents_detect.py +0 -380
  165. claude_mpm/cli/commands/agents_recommend.py +0 -309
  166. claude_mpm/cli/ticket_cli.py +0 -35
  167. claude_mpm/commands/mpm-agents-auto-configure.md +0 -278
  168. claude_mpm/commands/mpm-agents-detect.md +0 -177
  169. claude_mpm/commands/mpm-agents-list.md +0 -131
  170. claude_mpm/commands/mpm-agents-recommend.md +0 -223
  171. claude_mpm/commands/mpm-config-view.md +0 -150
  172. claude_mpm/commands/mpm-ticket-organize.md +0 -304
  173. claude_mpm/dashboard/analysis_runner.py +0 -455
  174. claude_mpm/dashboard/index.html +0 -13
  175. claude_mpm/dashboard/open_dashboard.py +0 -66
  176. claude_mpm/dashboard/static/css/activity.css +0 -1958
  177. claude_mpm/dashboard/static/css/connection-status.css +0 -370
  178. claude_mpm/dashboard/static/css/dashboard.css +0 -4701
  179. claude_mpm/dashboard/static/js/components/activity-tree.js +0 -1871
  180. claude_mpm/dashboard/static/js/components/agent-hierarchy.js +0 -777
  181. claude_mpm/dashboard/static/js/components/agent-inference.js +0 -956
  182. claude_mpm/dashboard/static/js/components/build-tracker.js +0 -333
  183. claude_mpm/dashboard/static/js/components/code-simple.js +0 -857
  184. claude_mpm/dashboard/static/js/components/connection-debug.js +0 -654
  185. claude_mpm/dashboard/static/js/components/diff-viewer.js +0 -891
  186. claude_mpm/dashboard/static/js/components/event-processor.js +0 -542
  187. claude_mpm/dashboard/static/js/components/event-viewer.js +0 -1155
  188. claude_mpm/dashboard/static/js/components/export-manager.js +0 -368
  189. claude_mpm/dashboard/static/js/components/file-change-tracker.js +0 -443
  190. claude_mpm/dashboard/static/js/components/file-change-viewer.js +0 -690
  191. claude_mpm/dashboard/static/js/components/file-tool-tracker.js +0 -724
  192. claude_mpm/dashboard/static/js/components/file-viewer.js +0 -580
  193. claude_mpm/dashboard/static/js/components/hud-library-loader.js +0 -211
  194. claude_mpm/dashboard/static/js/components/hud-manager.js +0 -671
  195. claude_mpm/dashboard/static/js/components/hud-visualizer.js +0 -1718
  196. claude_mpm/dashboard/static/js/components/module-viewer.js +0 -2764
  197. claude_mpm/dashboard/static/js/components/session-manager.js +0 -579
  198. claude_mpm/dashboard/static/js/components/socket-manager.js +0 -368
  199. claude_mpm/dashboard/static/js/components/ui-state-manager.js +0 -749
  200. claude_mpm/dashboard/static/js/components/unified-data-viewer.js +0 -1824
  201. claude_mpm/dashboard/static/js/components/working-directory.js +0 -920
  202. claude_mpm/dashboard/static/js/connection-manager.js +0 -536
  203. claude_mpm/dashboard/static/js/dashboard.js +0 -1914
  204. claude_mpm/dashboard/static/js/extension-error-handler.js +0 -164
  205. claude_mpm/dashboard/static/js/socket-client.js +0 -1474
  206. claude_mpm/dashboard/static/js/tab-isolation-fix.js +0 -185
  207. claude_mpm/dashboard/static/socket.io.min.js +0 -7
  208. claude_mpm/dashboard/static/socket.io.v4.8.1.backup.js +0 -7
  209. claude_mpm/dashboard/templates/code_simple.html +0 -153
  210. claude_mpm/dashboard/templates/index.html +0 -606
  211. claude_mpm/dashboard/test_dashboard.html +0 -372
  212. claude_mpm/scripts/mcp_server.py +0 -75
  213. claude_mpm/scripts/mcp_wrapper.py +0 -39
  214. claude_mpm/services/mcp_gateway/__init__.py +0 -159
  215. claude_mpm/services/mcp_gateway/auto_configure.py +0 -369
  216. claude_mpm/services/mcp_gateway/config/__init__.py +0 -17
  217. claude_mpm/services/mcp_gateway/config/config_loader.py +0 -296
  218. claude_mpm/services/mcp_gateway/config/config_schema.py +0 -243
  219. claude_mpm/services/mcp_gateway/config/configuration.py +0 -429
  220. claude_mpm/services/mcp_gateway/core/__init__.py +0 -43
  221. claude_mpm/services/mcp_gateway/core/base.py +0 -312
  222. claude_mpm/services/mcp_gateway/core/exceptions.py +0 -253
  223. claude_mpm/services/mcp_gateway/core/interfaces.py +0 -443
  224. claude_mpm/services/mcp_gateway/core/process_pool.py +0 -977
  225. claude_mpm/services/mcp_gateway/core/singleton_manager.py +0 -315
  226. claude_mpm/services/mcp_gateway/core/startup_verification.py +0 -316
  227. claude_mpm/services/mcp_gateway/main.py +0 -589
  228. claude_mpm/services/mcp_gateway/registry/__init__.py +0 -12
  229. claude_mpm/services/mcp_gateway/registry/service_registry.py +0 -412
  230. claude_mpm/services/mcp_gateway/registry/tool_registry.py +0 -489
  231. claude_mpm/services/mcp_gateway/server/__init__.py +0 -15
  232. claude_mpm/services/mcp_gateway/server/mcp_gateway.py +0 -414
  233. claude_mpm/services/mcp_gateway/server/stdio_handler.py +0 -372
  234. claude_mpm/services/mcp_gateway/server/stdio_server.py +0 -712
  235. claude_mpm/services/mcp_gateway/tools/__init__.py +0 -36
  236. claude_mpm/services/mcp_gateway/tools/base_adapter.py +0 -485
  237. claude_mpm/services/mcp_gateway/tools/document_summarizer.py +0 -789
  238. claude_mpm/services/mcp_gateway/tools/external_mcp_services.py +0 -654
  239. claude_mpm/services/mcp_gateway/tools/health_check_tool.py +0 -456
  240. claude_mpm/services/mcp_gateway/tools/hello_world.py +0 -551
  241. claude_mpm/services/mcp_gateway/tools/kuzu_memory_service.py +0 -555
  242. claude_mpm/services/mcp_gateway/utils/__init__.py +0 -14
  243. claude_mpm/services/mcp_gateway/utils/package_version_checker.py +0 -160
  244. claude_mpm/services/mcp_gateway/utils/update_preferences.py +0 -170
  245. claude_mpm-5.1.9.dist-info/entry_points.txt +0 -10
  246. claude_mpm-5.1.9.dist-info/licenses/LICENSE +0 -21
  247. {claude_mpm-5.1.9.dist-info → claude_mpm-5.4.48.dist-info}/WHEEL +0 -0
  248. {claude_mpm-5.1.9.dist-info → claude_mpm-5.4.48.dist-info}/top_level.txt +0 -0
@@ -1,601 +0,0 @@
1
- #!/usr/bin/env python3
2
- """
3
- Base Agent Loader Utility
4
- ========================
5
-
6
- Provides functionality to load and prepend base agent instructions to all agent prompts.
7
- Integrates with SharedPromptCache for performance optimization.
8
-
9
- Key Features:
10
- - Load base_agent.md content with caching
11
- - Prepend base instructions to agent prompts
12
- - Thread-safe operations
13
- - Error handling for missing base instructions
14
- - Integration with SharedPromptCache
15
- - Dynamic prompt templates based on task complexity
16
-
17
- Usage:
18
- from claude_mpm.agents.base_agent_loader import prepend_base_instructions
19
-
20
- # Get agent prompt with base instructions prepended
21
- full_prompt = prepend_base_instructions(get_agent_prompt("documentation-agent"))
22
- """
23
-
24
- import json
25
- import os
26
- from enum import Enum
27
- from pathlib import Path
28
- from typing import Dict, Optional
29
-
30
- # Module-level logger
31
- from claude_mpm.core.logging_utils import get_logger
32
- from claude_mpm.services.memory.cache.shared_prompt_cache import SharedPromptCache
33
-
34
- logger = get_logger(__name__)
35
-
36
- # Cache key for base agent instructions
37
- BASE_AGENT_CACHE_KEY = "base_agent:instructions"
38
-
39
-
40
- def _get_base_agent_file() -> Path:
41
- """Get the base agent file path with priority-based search.
42
-
43
- Priority order:
44
- 1. Environment variable override (CLAUDE_MPM_BASE_AGENT_PATH)
45
- 2. Current working directory (for local development)
46
- 3. Known development locations
47
- 4. User override location (~/.claude/agents/)
48
- 5. Package installation location (fallback)
49
- """
50
- # Priority 0: Check environment variable override
51
- env_path = os.environ.get("CLAUDE_MPM_BASE_AGENT_PATH")
52
- if env_path:
53
- env_base_agent = Path(env_path)
54
- if env_base_agent.exists():
55
- logger.debug(f"Using environment variable base_agent: {env_base_agent}")
56
- return env_base_agent
57
- logger.warning(
58
- f"CLAUDE_MPM_BASE_AGENT_PATH set but file doesn't exist: {env_base_agent}"
59
- )
60
-
61
- # Priority 1: Check current working directory for local development
62
- cwd = Path.cwd()
63
- cwd_base_agent = cwd / "src" / "claude_mpm" / "agents" / "base_agent.json"
64
- if cwd_base_agent.exists():
65
- logger.debug(f"Using local development base_agent from cwd: {cwd_base_agent}")
66
- return cwd_base_agent
67
-
68
- # Priority 2: Check known development locations
69
- known_dev_paths = [
70
- Path("/Users/masa/Projects/claude-mpm/src/claude_mpm/agents/base_agent.json"),
71
- Path.home()
72
- / "Projects"
73
- / "claude-mpm"
74
- / "src"
75
- / "claude_mpm"
76
- / "agents"
77
- / "base_agent.json",
78
- Path.home()
79
- / "projects"
80
- / "claude-mpm"
81
- / "src"
82
- / "claude_mpm"
83
- / "agents"
84
- / "base_agent.json",
85
- ]
86
-
87
- for dev_path in known_dev_paths:
88
- if dev_path.exists():
89
- logger.debug(f"Using development base_agent: {dev_path}")
90
- return dev_path
91
-
92
- # Priority 3: Check user override location
93
- user_base_agent = Path.home() / ".claude" / "agents" / "base_agent.json"
94
- if user_base_agent.exists():
95
- logger.debug(f"Using user override base_agent: {user_base_agent}")
96
- return user_base_agent
97
-
98
- # Priority 4: Check if we're running from a wheel installation
99
- try:
100
- import claude_mpm
101
-
102
- package_path = Path(claude_mpm.__file__).parent
103
- path_str = str(package_path.resolve())
104
-
105
- # For development/editable installs, check if there's a local src directory
106
- if "site-packages" in path_str or "dist-packages" in path_str:
107
- # Check if this is a pipx/pip installation
108
- if "pipx" in path_str:
109
- logger.debug(f"Detected pipx installation at {package_path}")
110
-
111
- # For wheel installations, check data directory
112
- data_base_agent = package_path / "data" / "agents" / "base_agent.json"
113
- if data_base_agent.exists():
114
- logger.debug(f"Using wheel installation base_agent: {data_base_agent}")
115
- return data_base_agent
116
-
117
- # Also check direct agents directory in package
118
- pkg_base_agent = package_path / "agents" / "base_agent.json"
119
- if pkg_base_agent.exists():
120
- logger.info(f"Using package base_agent: {pkg_base_agent}")
121
- return pkg_base_agent
122
- except Exception as e:
123
- logger.debug(f"Exception checking package path: {e}")
124
-
125
- # Final fallback: Use the base_agent.json relative to this file
126
- base_agent_path = Path(__file__).parent / "base_agent.json"
127
- if base_agent_path.exists():
128
- logger.info(f"Using fallback base_agent relative to module: {base_agent_path}")
129
- return base_agent_path
130
-
131
- # Error if no base agent found
132
- logger.error("Base agent template file not found in any location")
133
- logger.error("Searched locations:")
134
- logger.error(f" 1. CWD: {cwd_base_agent}")
135
- logger.error(f" 2. Dev paths: {known_dev_paths}")
136
- logger.error(f" 3. User: {user_base_agent}")
137
- logger.error(f" 4. Module: {base_agent_path}")
138
- raise FileNotFoundError("base_agent.json not found in any expected location")
139
-
140
-
141
- # Base agent file path (dynamically determined)
142
- BASE_AGENT_FILE = _get_base_agent_file()
143
-
144
-
145
- class PromptTemplate(Enum):
146
- """Dynamic prompt template levels."""
147
-
148
- MINIMAL = "MINIMAL" # Core instructions only (~300 chars)
149
- STANDARD = "STANDARD" # Core + context + basic integration (~700 chars)
150
- FULL = "FULL" # All sections including escalation (~1500 chars)
151
-
152
-
153
- # Template section definitions
154
- # Optimized to reduce STANDARD template size while maintaining essential guidance
155
- TEMPLATE_SECTIONS = {
156
- "core_principles": {
157
- "templates": ["MINIMAL", "STANDARD", "FULL"],
158
- "content": "Core Agent Principles",
159
- },
160
- "communication_standards": {
161
- "templates": ["MINIMAL", "STANDARD", "FULL"],
162
- "content": "Communication Standards",
163
- },
164
- "test_protocols": {
165
- "templates": ["FULL"], # Moved to FULL only - not needed for most tasks
166
- "content": "Test Response Protocol",
167
- },
168
- "reporting_requirements": {
169
- "templates": ["STANDARD", "FULL"],
170
- "content": "Reporting Requirements",
171
- },
172
- "error_handling": {"templates": ["STANDARD", "FULL"], "content": "Error Handling"},
173
- "security_awareness": {"templates": ["FULL"], "content": "Security Awareness"},
174
- "temporal_context": {
175
- "templates": ["FULL"], # Moved to FULL - not essential for STANDARD
176
- "content": "Temporal Context Integration",
177
- },
178
- "quality_standards": {"templates": ["FULL"], "content": "Quality Standards"},
179
- "tool_usage": {
180
- "templates": ["FULL"], # Moved to FULL - agent-specific guidance suffices
181
- "content": "Tool Usage Guidelines",
182
- },
183
- "collaboration_protocols": {
184
- "templates": ["STANDARD", "FULL"], # Keep for STANDARD - essential
185
- "content": "Collaboration Protocols",
186
- },
187
- "cross_agent_dependencies": {
188
- "templates": ["FULL"], # Only needed for complex multi-agent tasks
189
- "content": "Cross-Agent Dependencies",
190
- },
191
- "performance_optimization": {
192
- "templates": ["FULL"],
193
- "content": "Performance Optimization",
194
- },
195
- "escalation_triggers": {"templates": ["FULL"], "content": "Escalation Triggers"},
196
- "output_formatting": {
197
- "templates": ["FULL"], # Moved to FULL - basic formatting in STANDARD suffices
198
- "content": "Output Formatting Standards",
199
- },
200
- "framework_integration": {
201
- "templates": ["FULL"],
202
- "content": "Framework Integration",
203
- },
204
- "constraints": {
205
- "templates": ["MINIMAL", "STANDARD", "FULL"],
206
- "content": "Universal Constraints",
207
- },
208
- "success_criteria": {
209
- "templates": ["FULL"], # Moved to FULL - implicit for simpler tasks
210
- "content": "Success Criteria",
211
- },
212
- }
213
-
214
-
215
- def load_base_agent_instructions(force_reload: bool = False) -> Optional[str]:
216
- """
217
- Load base agent instructions from base_agent.json with caching.
218
- Conditionally includes test-mode instructions based on CLAUDE_PM_TEST_MODE.
219
-
220
- Args:
221
- force_reload: Force reload from file, bypassing cache
222
-
223
- Returns:
224
- str: Base agent instructions content, or None if file not found
225
- """
226
- try:
227
- # Check if we're in test mode
228
- test_mode = os.environ.get("CLAUDE_PM_TEST_MODE", "").lower() in [
229
- "true",
230
- "1",
231
- "yes",
232
- ]
233
-
234
- # Get cache instance
235
- cache = SharedPromptCache.get_instance()
236
-
237
- # Different cache keys for test mode vs normal mode
238
- cache_key = f"{BASE_AGENT_CACHE_KEY}:{'test' if test_mode else 'normal'}"
239
-
240
- # Check cache first (unless force reload)
241
- if not force_reload:
242
- cached_content = cache.get(cache_key)
243
- if cached_content is not None:
244
- logger.debug(
245
- f"Base agent instructions loaded from cache (test_mode={test_mode})"
246
- )
247
- return str(cached_content)
248
-
249
- # Get fresh base agent file path
250
- base_agent_file = _get_base_agent_file()
251
-
252
- # Load from file
253
- if not base_agent_file.exists():
254
- logger.warning(f"Base agent instructions file not found: {base_agent_file}")
255
- return None
256
-
257
- logger.debug(f"Loading base agent instructions from: {base_agent_file}")
258
-
259
- # Load JSON and extract instructions
260
- with Path(base_agent_file).open(
261
- encoding="utf-8",
262
- ) as f:
263
- base_agent_data = json.load(f)
264
-
265
- # Extract instructions from the JSON structure
266
- if (
267
- "narrative_fields" in base_agent_data
268
- and "instructions" in base_agent_data["narrative_fields"]
269
- ):
270
- content = base_agent_data["narrative_fields"]["instructions"]
271
- else:
272
- # Fallback for older format
273
- content = base_agent_data.get("instructions", "")
274
-
275
- if not content:
276
- logger.error("No instructions found in base agent JSON")
277
- return None
278
-
279
- # If NOT in test mode, remove test-specific instructions to save context
280
- if not test_mode:
281
- content = _remove_test_mode_instructions(content)
282
- logger.debug("Test-mode instructions removed (not in test mode)")
283
- else:
284
- logger.info(
285
- "Test-mode instructions included (CLAUDE_PM_TEST_MODE is enabled)"
286
- )
287
-
288
- # Cache the content with 1 hour TTL
289
- cache.set(cache_key, content, ttl=3600)
290
- logger.debug(
291
- f"Base agent instructions cached successfully (test_mode={test_mode})"
292
- )
293
-
294
- return content
295
-
296
- except Exception as e:
297
- logger.error(f"Error loading base agent instructions: {e}")
298
- return None
299
-
300
-
301
- def _remove_test_mode_instructions(content: str) -> str:
302
- """
303
- Remove test-mode specific instructions from base agent content.
304
-
305
- This removes the "Standard Test Response Protocol"
306
- sections to save context when not in test mode.
307
-
308
- Args:
309
- content: Full base agent instructions content
310
-
311
- Returns:
312
- str: Content with test-mode instructions removed
313
- """
314
- import re
315
-
316
- # Pattern matches from "## Standard Test Response Protocol"
317
- # until the next "##" (but not "###") or end of string
318
- # Uses negative lookahead to stop at ## but not ###
319
- pattern = r"## Standard Test Response Protocol\n.*?(?=\n##(?!#)|\Z)"
320
-
321
- # Remove the test section (DOTALL allows . to match newlines)
322
- result = re.sub(pattern, "", content, flags=re.DOTALL)
323
-
324
- # Clean up multiple consecutive newlines
325
- while "\n\n\n" in result:
326
- result = result.replace("\n\n\n", "\n\n")
327
-
328
- return result.strip()
329
-
330
-
331
- def _build_dynamic_prompt(content: str, template: PromptTemplate) -> str:
332
- """
333
- Build a dynamic prompt based on the template level.
334
-
335
- Args:
336
- content: Full base agent content
337
- template: Template level to use
338
-
339
- Returns:
340
- str: Filtered content based on template
341
- """
342
- if template == PromptTemplate.FULL:
343
- # Return full content for FULL template
344
- return content
345
-
346
- # Parse content into sections
347
- sections = _parse_content_sections(content)
348
-
349
- # Build prompt based on template sections
350
- filtered_lines = []
351
- filtered_lines.append("# Base Agent Instructions\n")
352
- filtered_lines.append("## 🤖 Agent Framework Context\n")
353
- filtered_lines.append(
354
- "You are operating as a specialized agent within the Claude PM Framework. You have been delegated a specific task by the PM Orchestrator and must complete it according to your specialized role and authority.\n"
355
- )
356
-
357
- # Add sections based on template
358
- template_name = template.value
359
- for _section_key, section_config in TEMPLATE_SECTIONS.items():
360
- if template_name in section_config["templates"]:
361
- section_name = section_config["content"]
362
- assert isinstance(section_name, str), "Section name must be string"
363
- if section_name in sections:
364
- filtered_lines.append(sections[section_name])
365
-
366
- # Clean up multiple newlines
367
- result = "\n".join(filtered_lines)
368
- while "\n\n\n" in result:
369
- result = result.replace("\n\n\n", "\n\n")
370
-
371
- return result.strip()
372
-
373
-
374
- def _parse_content_sections(content: str) -> Dict[str, str]:
375
- """
376
- Parse content into named sections.
377
-
378
- Args:
379
- content: Full content to parse
380
-
381
- Returns:
382
- Dict mapping section names to their content
383
- """
384
- sections = {}
385
- current_section = None
386
- current_content = []
387
-
388
- lines = content.split("\n")
389
-
390
- for line in lines:
391
- # Check if this is a section header
392
- if line.startswith("### "):
393
- # Save previous section if exists
394
- if current_section:
395
- sections[current_section] = "\n".join(current_content)
396
- current_content = []
397
-
398
- # Extract section name
399
- current_section = line[4:].strip()
400
- current_content.append(line)
401
-
402
- elif line.startswith("## ") and "Agent Framework Context" not in line:
403
- # Handle ## level sections (skip the main header)
404
- if current_section:
405
- sections[current_section] = "\n".join(current_content)
406
- current_content = []
407
-
408
- current_section = line[3:].strip()
409
- current_content.append(line)
410
-
411
- elif line.startswith("#### "):
412
- # Handle #### level subsections
413
- if current_section:
414
- # Check for PM Orchestrator Integration vs PM Workflow Integration
415
- subsection_name = line[5:].strip()
416
- if subsection_name in [
417
- "PM Orchestrator Integration",
418
- "PM Workflow Integration",
419
- ]:
420
- # Merge these redundant sections under "Collaboration Protocols"
421
- if current_section != "Collaboration Protocols":
422
- current_section = "PM Integration"
423
- current_content.append(line)
424
-
425
- elif current_section:
426
- current_content.append(line)
427
-
428
- # Save final section
429
- if current_section and current_content:
430
- sections[current_section] = "\n".join(current_content)
431
-
432
- # Merge redundant PM sections if both exist
433
- if (
434
- "PM Orchestrator Integration" in sections
435
- and "PM Workflow Integration" in sections
436
- ):
437
- # Combine into single PM Integration section
438
- sections["PM Integration"] = (
439
- "#### PM Integration\n"
440
- + sections["PM Orchestrator Integration"]
441
- .replace("#### PM Orchestrator Integration", "")
442
- .strip()
443
- + "\n\n"
444
- + sections["PM Workflow Integration"]
445
- .replace("#### PM Workflow Integration", "")
446
- .strip()
447
- )
448
- # Remove redundant sections
449
- del sections["PM Orchestrator Integration"]
450
- del sections["PM Workflow Integration"]
451
-
452
- return sections
453
-
454
-
455
- def prepend_base_instructions(
456
- agent_prompt: str,
457
- separator: str = "\n\n---\n\n",
458
- template: Optional[PromptTemplate] = None,
459
- complexity_score: Optional[int] = None,
460
- ) -> str:
461
- """
462
- Prepend base agent instructions to an agent-specific prompt.
463
-
464
- Args:
465
- agent_prompt: The agent-specific prompt to prepend to
466
- separator: String to separate base instructions from agent prompt
467
- template: Optional template level to use (auto-selected if not provided)
468
- complexity_score: Optional complexity score for template selection
469
-
470
- Returns:
471
- str: Combined prompt with base instructions prepended
472
- """
473
- # Auto-select template based on complexity if not provided
474
- if template is None:
475
- if complexity_score is not None:
476
- if complexity_score <= 30:
477
- template = PromptTemplate.MINIMAL
478
- elif complexity_score <= 70:
479
- template = PromptTemplate.STANDARD
480
- else:
481
- template = PromptTemplate.FULL
482
- else:
483
- # Default to STANDARD if no complexity info
484
- template = PromptTemplate.STANDARD
485
-
486
- # Check if we're in test mode - always use FULL template for tests
487
- test_mode = os.environ.get("CLAUDE_PM_TEST_MODE", "").lower() in [
488
- "true",
489
- "1",
490
- "yes",
491
- ]
492
- if test_mode:
493
- template = PromptTemplate.FULL
494
-
495
- # Get cache instance
496
- cache = SharedPromptCache.get_instance()
497
-
498
- # Different cache keys for different templates and test mode
499
- cache_key = (
500
- f"{BASE_AGENT_CACHE_KEY}:{template.value}:{'test' if test_mode else 'normal'}"
501
- )
502
-
503
- # Check cache first
504
- cached_content = cache.get(cache_key)
505
- if cached_content is not None:
506
- logger.debug(
507
- f"Base agent instructions loaded from cache (template={template.value}, test_mode={test_mode})"
508
- )
509
- base_instructions = cached_content
510
- else:
511
- # Load full content
512
- full_content = load_base_agent_instructions()
513
-
514
- # If no base instructions, return original prompt
515
- if not full_content:
516
- logger.warning("No base instructions available, returning original prompt")
517
- return agent_prompt
518
-
519
- # Build dynamic prompt based on template
520
- base_instructions = _build_dynamic_prompt(full_content, template)
521
-
522
- # Cache the filtered content
523
- cache.set(cache_key, base_instructions, ttl=3600)
524
- logger.debug(
525
- f"Dynamic base agent instructions cached (template={template.value})"
526
- )
527
-
528
- # Log template selection
529
- if complexity_score is not None:
530
- logger.info(
531
- f"Using {template.value} prompt template "
532
- f"(complexity_score={complexity_score}, size={len(base_instructions)} chars)"
533
- )
534
-
535
- # Combine base instructions with agent prompt
536
- return f"{base_instructions}{separator}{agent_prompt}"
537
-
538
-
539
- def clear_base_agent_cache() -> None:
540
- """Clear the cached base agent instructions for all templates and modes."""
541
- try:
542
- cache = SharedPromptCache.get_instance()
543
- # Clear caches for all template levels and modes
544
- for template in PromptTemplate:
545
- for mode in ["normal", "test"]:
546
- cache_key = f"{BASE_AGENT_CACHE_KEY}:{template.value}:{mode}"
547
- cache.invalidate(cache_key)
548
-
549
- # Also clear the old-style caches for backward compatibility
550
- cache.invalidate(f"{BASE_AGENT_CACHE_KEY}:normal")
551
- cache.invalidate(f"{BASE_AGENT_CACHE_KEY}:test")
552
-
553
- logger.debug("Base agent cache cleared (all templates and modes)")
554
- except Exception as e:
555
- logger.error(f"Error clearing base agent cache: {e}")
556
-
557
-
558
- def get_base_agent_path() -> Path:
559
- """Get the path to the base agent instructions file."""
560
- return BASE_AGENT_FILE
561
-
562
-
563
- def validate_base_agent_file() -> bool:
564
- """
565
- Validate that base agent file exists and is readable.
566
-
567
- Returns:
568
- bool: True if file exists and is readable, False otherwise
569
- """
570
- try:
571
- if not BASE_AGENT_FILE.exists():
572
- logger.error(f"Base agent file does not exist: {BASE_AGENT_FILE}")
573
- return False
574
-
575
- if not BASE_AGENT_FILE.is_file():
576
- logger.error(f"Base agent path is not a file: {BASE_AGENT_FILE}")
577
- return False
578
-
579
- # Try to read the file
580
- BASE_AGENT_FILE.read_text(encoding="utf-8")
581
- return True
582
-
583
- except Exception as e:
584
- logger.error(f"Base agent file validation failed: {e}")
585
- return False
586
-
587
-
588
- # Module initialization - validate base agent file on import
589
- if not validate_base_agent_file():
590
- logger.warning("Base agent file validation failed during module import")
591
-
592
- # Export key components
593
- __all__ = [
594
- "TEMPLATE_SECTIONS",
595
- "PromptTemplate",
596
- "clear_base_agent_cache",
597
- "get_base_agent_path",
598
- "load_base_agent_instructions",
599
- "prepend_base_instructions",
600
- "validate_base_agent_file",
601
- ]