claude-mpm 5.1.9__py3-none-any.whl → 5.4.22__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.
- claude_mpm/VERSION +1 -1
- claude_mpm/__init__.py +4 -0
- claude_mpm/agents/CLAUDE_MPM_TEACHER_OUTPUT_STYLE.md +1 -1
- claude_mpm/agents/PM_INSTRUCTIONS.md +290 -34
- claude_mpm/agents/agent_loader.py +13 -44
- claude_mpm/agents/templates/circuit-breakers.md +138 -1
- claude_mpm/cli/__main__.py +4 -0
- claude_mpm/cli/chrome_devtools_installer.py +175 -0
- claude_mpm/cli/commands/agent_state_manager.py +8 -17
- claude_mpm/cli/commands/agents.py +0 -31
- claude_mpm/cli/commands/auto_configure.py +210 -25
- claude_mpm/cli/commands/config.py +88 -2
- claude_mpm/cli/commands/configure.py +1097 -158
- claude_mpm/cli/commands/configure_agent_display.py +15 -6
- claude_mpm/cli/commands/mpm_init/core.py +160 -46
- claude_mpm/cli/commands/mpm_init/knowledge_extractor.py +481 -0
- claude_mpm/cli/commands/mpm_init/prompts.py +280 -0
- claude_mpm/cli/commands/skills.py +214 -189
- claude_mpm/cli/commands/summarize.py +413 -0
- claude_mpm/cli/executor.py +11 -3
- claude_mpm/cli/parsers/agents_parser.py +0 -9
- claude_mpm/cli/parsers/auto_configure_parser.py +0 -138
- claude_mpm/cli/parsers/base_parser.py +5 -0
- claude_mpm/cli/parsers/config_parser.py +153 -83
- claude_mpm/cli/parsers/skills_parser.py +3 -2
- claude_mpm/cli/startup.py +550 -94
- claude_mpm/commands/mpm-config.md +265 -0
- claude_mpm/commands/mpm-help.md +14 -95
- claude_mpm/commands/mpm-organize.md +500 -0
- claude_mpm/config/agent_sources.py +27 -0
- claude_mpm/core/framework/formatters/content_formatter.py +3 -13
- claude_mpm/core/framework/loaders/agent_loader.py +8 -5
- claude_mpm/core/framework_loader.py +4 -2
- claude_mpm/core/logger.py +13 -0
- claude_mpm/core/socketio_pool.py +3 -3
- claude_mpm/core/unified_agent_registry.py +5 -15
- claude_mpm/hooks/claude_hooks/correlation_manager.py +60 -0
- claude_mpm/hooks/claude_hooks/event_handlers.py +211 -78
- claude_mpm/hooks/claude_hooks/hook_handler.py +6 -0
- claude_mpm/hooks/claude_hooks/installer.py +33 -10
- claude_mpm/hooks/claude_hooks/memory_integration.py +26 -9
- claude_mpm/hooks/claude_hooks/response_tracking.py +2 -3
- claude_mpm/hooks/claude_hooks/services/connection_manager.py +4 -0
- claude_mpm/hooks/memory_integration_hook.py +46 -1
- claude_mpm/init.py +0 -19
- claude_mpm/scripts/claude-hook-handler.sh +58 -18
- claude_mpm/scripts/launch_monitor.py +93 -13
- claude_mpm/scripts/start_activity_logging.py +0 -0
- claude_mpm/services/agents/agent_recommendation_service.py +278 -0
- claude_mpm/services/agents/agent_review_service.py +280 -0
- claude_mpm/services/agents/deployment/agent_discovery_service.py +2 -3
- claude_mpm/services/agents/deployment/agent_template_builder.py +4 -2
- claude_mpm/services/agents/deployment/multi_source_deployment_service.py +78 -9
- claude_mpm/services/agents/deployment/remote_agent_discovery_service.py +335 -53
- claude_mpm/services/agents/git_source_manager.py +34 -0
- claude_mpm/services/agents/loading/base_agent_manager.py +1 -13
- claude_mpm/services/agents/sources/git_source_sync_service.py +8 -1
- claude_mpm/services/agents/toolchain_detector.py +10 -6
- claude_mpm/services/analysis/__init__.py +11 -1
- claude_mpm/services/analysis/clone_detector.py +1030 -0
- claude_mpm/services/command_deployment_service.py +81 -10
- claude_mpm/services/event_bus/config.py +3 -1
- claude_mpm/services/git/git_operations_service.py +93 -8
- claude_mpm/services/monitor/daemon.py +9 -2
- claude_mpm/services/monitor/daemon_manager.py +39 -3
- claude_mpm/services/monitor/server.py +225 -19
- claude_mpm/services/self_upgrade_service.py +120 -12
- claude_mpm/services/skills/__init__.py +3 -0
- claude_mpm/services/skills/git_skill_source_manager.py +32 -2
- claude_mpm/services/skills/selective_skill_deployer.py +704 -0
- claude_mpm/services/skills/skill_to_agent_mapper.py +406 -0
- claude_mpm/services/skills_deployer.py +126 -9
- claude_mpm/services/socketio/event_normalizer.py +15 -1
- claude_mpm/services/socketio/server/core.py +160 -21
- claude_mpm/services/version_control/git_operations.py +103 -0
- claude_mpm/utils/agent_filters.py +17 -44
- {claude_mpm-5.1.9.dist-info → claude_mpm-5.4.22.dist-info}/METADATA +47 -84
- {claude_mpm-5.1.9.dist-info → claude_mpm-5.4.22.dist-info}/RECORD +82 -161
- claude_mpm-5.4.22.dist-info/entry_points.txt +5 -0
- claude_mpm-5.4.22.dist-info/licenses/LICENSE +94 -0
- claude_mpm-5.4.22.dist-info/licenses/LICENSE-FAQ.md +153 -0
- claude_mpm/agents/BASE_AGENT_TEMPLATE.md +0 -292
- claude_mpm/agents/BASE_DOCUMENTATION.md +0 -53
- claude_mpm/agents/BASE_ENGINEER.md +0 -658
- claude_mpm/agents/BASE_OPS.md +0 -219
- claude_mpm/agents/BASE_PM.md +0 -480
- claude_mpm/agents/BASE_PROMPT_ENGINEER.md +0 -787
- claude_mpm/agents/BASE_QA.md +0 -167
- claude_mpm/agents/BASE_RESEARCH.md +0 -53
- claude_mpm/agents/base_agent.json +0 -31
- claude_mpm/agents/base_agent_loader.py +0 -601
- claude_mpm/cli/commands/agents_detect.py +0 -380
- claude_mpm/cli/commands/agents_recommend.py +0 -309
- claude_mpm/cli/ticket_cli.py +0 -35
- claude_mpm/commands/mpm-agents-auto-configure.md +0 -278
- claude_mpm/commands/mpm-agents-detect.md +0 -177
- claude_mpm/commands/mpm-agents-list.md +0 -131
- claude_mpm/commands/mpm-agents-recommend.md +0 -223
- claude_mpm/commands/mpm-config-view.md +0 -150
- claude_mpm/commands/mpm-ticket-organize.md +0 -304
- claude_mpm/dashboard/analysis_runner.py +0 -455
- claude_mpm/dashboard/index.html +0 -13
- claude_mpm/dashboard/open_dashboard.py +0 -66
- claude_mpm/dashboard/static/css/activity.css +0 -1958
- claude_mpm/dashboard/static/css/connection-status.css +0 -370
- claude_mpm/dashboard/static/css/dashboard.css +0 -4701
- claude_mpm/dashboard/static/js/components/activity-tree.js +0 -1871
- claude_mpm/dashboard/static/js/components/agent-hierarchy.js +0 -777
- claude_mpm/dashboard/static/js/components/agent-inference.js +0 -956
- claude_mpm/dashboard/static/js/components/build-tracker.js +0 -333
- claude_mpm/dashboard/static/js/components/code-simple.js +0 -857
- claude_mpm/dashboard/static/js/components/connection-debug.js +0 -654
- claude_mpm/dashboard/static/js/components/diff-viewer.js +0 -891
- claude_mpm/dashboard/static/js/components/event-processor.js +0 -542
- claude_mpm/dashboard/static/js/components/event-viewer.js +0 -1155
- claude_mpm/dashboard/static/js/components/export-manager.js +0 -368
- claude_mpm/dashboard/static/js/components/file-change-tracker.js +0 -443
- claude_mpm/dashboard/static/js/components/file-change-viewer.js +0 -690
- claude_mpm/dashboard/static/js/components/file-tool-tracker.js +0 -724
- claude_mpm/dashboard/static/js/components/file-viewer.js +0 -580
- claude_mpm/dashboard/static/js/components/hud-library-loader.js +0 -211
- claude_mpm/dashboard/static/js/components/hud-manager.js +0 -671
- claude_mpm/dashboard/static/js/components/hud-visualizer.js +0 -1718
- claude_mpm/dashboard/static/js/components/module-viewer.js +0 -2764
- claude_mpm/dashboard/static/js/components/session-manager.js +0 -579
- claude_mpm/dashboard/static/js/components/socket-manager.js +0 -368
- claude_mpm/dashboard/static/js/components/ui-state-manager.js +0 -749
- claude_mpm/dashboard/static/js/components/unified-data-viewer.js +0 -1824
- claude_mpm/dashboard/static/js/components/working-directory.js +0 -920
- claude_mpm/dashboard/static/js/connection-manager.js +0 -536
- claude_mpm/dashboard/static/js/dashboard.js +0 -1914
- claude_mpm/dashboard/static/js/extension-error-handler.js +0 -164
- claude_mpm/dashboard/static/js/socket-client.js +0 -1474
- claude_mpm/dashboard/static/js/tab-isolation-fix.js +0 -185
- claude_mpm/dashboard/static/socket.io.min.js +0 -7
- claude_mpm/dashboard/static/socket.io.v4.8.1.backup.js +0 -7
- claude_mpm/dashboard/templates/code_simple.html +0 -153
- claude_mpm/dashboard/templates/index.html +0 -606
- claude_mpm/dashboard/test_dashboard.html +0 -372
- claude_mpm/scripts/mcp_server.py +0 -75
- claude_mpm/scripts/mcp_wrapper.py +0 -39
- claude_mpm/services/mcp_gateway/__init__.py +0 -159
- claude_mpm/services/mcp_gateway/auto_configure.py +0 -369
- claude_mpm/services/mcp_gateway/config/__init__.py +0 -17
- claude_mpm/services/mcp_gateway/config/config_loader.py +0 -296
- claude_mpm/services/mcp_gateway/config/config_schema.py +0 -243
- claude_mpm/services/mcp_gateway/config/configuration.py +0 -429
- claude_mpm/services/mcp_gateway/core/__init__.py +0 -43
- claude_mpm/services/mcp_gateway/core/base.py +0 -312
- claude_mpm/services/mcp_gateway/core/exceptions.py +0 -253
- claude_mpm/services/mcp_gateway/core/interfaces.py +0 -443
- claude_mpm/services/mcp_gateway/core/process_pool.py +0 -977
- claude_mpm/services/mcp_gateway/core/singleton_manager.py +0 -315
- claude_mpm/services/mcp_gateway/core/startup_verification.py +0 -316
- claude_mpm/services/mcp_gateway/main.py +0 -589
- claude_mpm/services/mcp_gateway/registry/__init__.py +0 -12
- claude_mpm/services/mcp_gateway/registry/service_registry.py +0 -412
- claude_mpm/services/mcp_gateway/registry/tool_registry.py +0 -489
- claude_mpm/services/mcp_gateway/server/__init__.py +0 -15
- claude_mpm/services/mcp_gateway/server/mcp_gateway.py +0 -414
- claude_mpm/services/mcp_gateway/server/stdio_handler.py +0 -372
- claude_mpm/services/mcp_gateway/server/stdio_server.py +0 -712
- claude_mpm/services/mcp_gateway/tools/__init__.py +0 -36
- claude_mpm/services/mcp_gateway/tools/base_adapter.py +0 -485
- claude_mpm/services/mcp_gateway/tools/document_summarizer.py +0 -789
- claude_mpm/services/mcp_gateway/tools/external_mcp_services.py +0 -654
- claude_mpm/services/mcp_gateway/tools/health_check_tool.py +0 -456
- claude_mpm/services/mcp_gateway/tools/hello_world.py +0 -551
- claude_mpm/services/mcp_gateway/tools/kuzu_memory_service.py +0 -555
- claude_mpm/services/mcp_gateway/utils/__init__.py +0 -14
- claude_mpm/services/mcp_gateway/utils/package_version_checker.py +0 -160
- claude_mpm/services/mcp_gateway/utils/update_preferences.py +0 -170
- claude_mpm-5.1.9.dist-info/entry_points.txt +0 -10
- claude_mpm-5.1.9.dist-info/licenses/LICENSE +0 -21
- {claude_mpm-5.1.9.dist-info → claude_mpm-5.4.22.dist-info}/WHEEL +0 -0
- {claude_mpm-5.1.9.dist-info → claude_mpm-5.4.22.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
|
-
]
|