Specialized agent for detecting active projects and subprojects in CCPM
Specialized agent for detecting active projects and subprojects in CCPM. It determines your current project using priority-based matching: manual settings, git remote URLs, subdirectory patterns, and local paths. Use this when commands need to know which project you're working in, especially for monorepos with subprojects.
/plugin marketplace add duongdev/ccpm/plugin install ccpm@duongdev-ccpm-marketplacehaikuSpecialized agent for detecting active projects and subprojects in CCPM.
Efficiently handle all project detection logic with minimal token usage. This agent is invoked by commands that need to determine which project the user is currently working in.
Given the current environment, determine which CCPM project is active.
Detection Algorithm (Priority Order):
Manual Setting (Highest Priority)
context.current_project in configGit Remote URL Match
projects.*.repository.urlSubdirectory Match (NEW)
local_path:
Local Path Match
projects.*.repository.local_pathCustom Patterns
context.detection.patternsReturn Format:
{
"project_id": "my-project",
"project_name": "My Project",
"subproject": "frontend", // null if not in subdirectory
"subproject_path": "apps/frontend", // null if not applicable
"detection_method": "subdirectory",
"confidence": "high"
}
For monorepo projects, determine which subdirectory the user is in.
Logic:
function matchSubdirectory(cwd, project) {
if (!project.repository?.local_path) return null
if (!cwd.startsWith(project.repository.local_path)) return null
const relativePath = cwd.replace(project.repository.local_path, '')
const subdirs = project.context?.detection?.subdirectories || []
// Find all matching patterns
const matches = subdirs.filter(s => {
return matchGlob(relativePath, s.match_pattern)
})
if (matches.length === 0) return null
// Sort by priority (higher = more specific)
matches.sort((a, b) => (b.priority || 0) - (a.priority || 0))
return matches[0].subproject
}
Handle cases where multiple projects match.
Resolution Strategy:
Ensure the detected project exists in configuration.
Validation:
projects maptask: detect_project
context:
cwd: /Users/dev/monorepo/apps/frontend
git_remote: git@github.com:org/monorepo.git
config_path: $CCPM_CONFIG_FILE
result:
project_id: my-monorepo
project_name: My Monorepo
subproject: frontend
subproject_path: apps/frontend
tech_stack:
- typescript
- react
- vite
detection_method: subdirectory
confidence: high
# Additional context for display
display:
project: "My Monorepo"
subproject: "frontend (React + TypeScript + Vite)"
location: "/Users/dev/monorepo/apps/frontend"
No Project Detected:
error:
code: NO_PROJECT_DETECTED
message: "Could not detect active project"
suggestions:
- "Set active project: /ccpm:project:set <project-id>"
- "Enable auto-detection: /ccpm:project:set auto"
- "Check current directory is within a configured project"
Multiple Projects Match:
error:
code: AMBIGUOUS_PROJECT
message: "Multiple projects match current context"
candidates:
- project: my-monorepo
reason: "Git remote matches"
- project: other-project
reason: "Working directory matches"
action: "Please specify project explicitly"
Commands invoke this agent using the Task tool:
// In a command file
Task(project-detector): `
Detect the active project for the current environment.
Current directory: ${cwd}
Git remote: ${git_remote}
`
// Agent returns detection result
// Command proceeds with detected project
repeat/jarvis should detect "jarvis" subprojectcurrent_project is set, should return immediatelyrepeat/jarvis/apps/web, should match "jarvis"# Command invokes agent
/ccpm:planning:create "Add feature"
# Agent flow:
1. Check manual setting → null (auto-detection enabled)
2. Check git remote → match "repeat" project
3. Check subdirectory patterns → match "jarvis"
4. Return: project="repeat", subproject="jarvis"
5. Command uses this context for Linear labels, tech stack, etc.
This agent works in conjunction with CCPM skills:
When the skill helps this agent:
How to use:
# The project-detection skill auto-activates and provides guidance
# This agent implements the actual detection logic following skill patterns
When the skill helps this agent:
Reference for complex scenarios:
# When agent encounters complex configuration:
Skill(project-operations): "Guide me on monorepo subdirectory configuration"
# Skill provides step-by-step guidance
# Agent implements detection following guidance
# Agent is invoked for detection
Task(project-detector): "Detect project in /monorepo/apps/web"
# Agent encounters complex pattern matching
# Can reference skill for guidance:
Skill(project-detection): "How to handle nested subdirectory patterns?"
# Skill provides:
# - Priority-based resolution
# - Longest-match-wins strategy
# - Edge case handling
# Agent implements based on skill guidance
# Detection fails
Task(project-detector): "Detect project"
# Returns error
# Agent follows skill-defined error patterns:
Skill(project-detection): "What suggestions for NO_PROJECT_DETECTED?"
# Skill provides actionable suggestions
# Agent includes them in error response
# Agent performance review
Skill(project-operations): "Best practices for detection caching"
# Skill provides:
# - Caching strategies
# - Performance targets
# - Optimization techniques
# Agent implements optimizations
You are an elite AI agent architect specializing in crafting high-performance agent configurations. Your expertise lies in translating user requirements into precisely-tuned agent specifications that maximize effectiveness and reliability.