This document demonstrates the auto-discovery engine in action.
Let's create a monorepo with multiple projects:
# Create workspace structure
mkdir my-workspace
cd my-workspace
# Create frontend (Next.js)
mkdir frontend
cat > frontend/package.json <<EOF
{
"name": "frontend",
"version": "1.0.0",
"dependencies": {
"next": "14.0.0",
"react": "18.0.0",
"shared": "file:../shared"
}
}
EOF
touch frontend/next.config.js
mkdir frontend/pages
# Create backend (FastAPI)
mkdir backend
cat > backend/requirements.txt <<EOF
fastapi==0.104.0
uvicorn
-e ../shared
EOF
cat > backend/main.py <<EOF
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return {"message": "Hello World"}
EOF
# Create shared library
mkdir shared
cat > shared/package.json <<EOF
{
"name": "shared",
"version": "1.0.0"
}
EOF
cat > shared/setup.py <<EOF
from setuptools import setup
setup(name="shared")
EOF
# Create documentation
mkdir docs
cat > docs/mkdocs.yml <<EOF
site_name: My Project Docs
EOFcontext workspace discover . --name "My Application"π Scanning /path/to/my-workspace for projects...
β Found 4 project(s) (15 directories scanned in 0.12s)
ββββββββββββββββββββββββ Workspace Discovery βββββββββββββββββββββββββ
β My Application β
β Discovered 4 projects β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Discovered Projects
βββββ³βββββββββββ³ββββββββββββββββ³βββββββββββββ³βββββββββββ³βββββββββββββ³βββββββββββββββ
β # β ID β Type β Confidence β Frameworkβ Languages β Dependencies β
β‘βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ©
β 1 β frontend β web_frontend β 95% β next.js β javascript β shared β
β 2 β backend β api_server β 88% β fastapi β python β shared β
β 3 β shared β library β 100% β β β javascript β β β
β 4 β docs β documentation β 100% β mkdocs β β β β β
βββββ΄βββββββββββ΄ββββββββββββββββ΄βββββββββββββ΄βββββββββββ΄βββββββββββββ΄βββββββββββββββ
Relationships Detected: 2
β’ frontend β shared (dependency)
β’ backend β shared (dependency)
Save workspace configuration to .context-workspace.json? [Y/n]: y
β Workspace configuration saved to .context-workspace.json
Next Steps:
1. Review configuration: context workspace list --verbose
2. Adjust if needed: Edit .context-workspace.json
3. Index projects: context workspace index
4. Search workspace: context workspace search 'your query'
The auto-discovery engine generates a complete .context-workspace.json:
{
"version": "2.0.0",
"name": "My Application",
"projects": [
{
"id": "frontend",
"name": "Frontend",
"path": "frontend",
"type": "web_frontend",
"language": ["javascript", "typescript"],
"dependencies": ["shared"],
"indexing": {
"enabled": true,
"priority": "high",
"exclude": ["node_modules", "dist", ".next", "out"]
},
"metadata": {
"framework": "next.js",
"framework_version": "14.0.0",
"discovery_confidence": 0.95,
"auto_discovered": true
}
},
{
"id": "backend",
"name": "Backend",
"path": "backend",
"type": "api_server",
"language": ["python"],
"dependencies": ["shared"],
"indexing": {
"enabled": true,
"priority": "high",
"exclude": ["venv", "__pycache__", ".pytest_cache"]
},
"metadata": {
"framework": "fastapi",
"framework_version": "0.104.0",
"discovery_confidence": 0.88,
"auto_discovered": true
}
},
{
"id": "shared",
"name": "Shared",
"path": "shared",
"type": "library",
"language": ["javascript", "python"],
"dependencies": [],
"indexing": {
"enabled": true,
"priority": "medium",
"exclude": ["node_modules", "dist", "build"]
},
"metadata": {
"discovery_confidence": 1.0,
"auto_discovered": true
}
},
{
"id": "docs",
"name": "Docs",
"path": "docs",
"type": "documentation",
"language": [],
"dependencies": [],
"indexing": {
"enabled": true,
"priority": "low",
"exclude": ["_build", "site"]
},
"metadata": {
"framework": "mkdocs",
"discovery_confidence": 1.0,
"auto_discovered": true
}
}
],
"relationships": [
{
"from": "frontend",
"to": "shared",
"type": "dependency",
"description": "frontend depends on shared"
},
{
"from": "backend",
"to": "shared",
"type": "dependency",
"description": "backend depends on shared"
}
]
}The auto-discovery engine can detect:
- Next.js: Detects
next.config.js,pages/orapp/directories - React: Detects React in dependencies
- Vue: Detects
vue.config.jsor Vue in dependencies - Angular: Detects
angular.json - Svelte: Detects
svelte.config.js
- FastAPI: Detects FastAPI imports in Python files
- Django: Detects
manage.pyand Django imports - Flask: Detects Flask imports
- Express: Detects Express in dependencies
- NestJS: Detects
@nestjs/corein dependencies
- React Native: Detects
metro.config.js - Flutter: Detects
pubspec.yamlwith mobile directories
- MkDocs: Detects
mkdocs.yml - Sphinx: Detects
conf.py - Docusaurus: Detects
docusaurus.config.js
- Detects projects with
setup.pyandsrc/directory structure - Python packages with
pyproject.toml - Rust crates with
Cargo.toml - Go modules with
go.mod
# Basic usage
context workspace discover [PATH]
# Specify output file
context workspace discover --workspace my-workspace.json
# Custom workspace name
context workspace discover --name "My Custom Name"
# Adjust scan depth
context workspace discover --max-depth 15
# Non-interactive mode
context workspace discover --no-interactive
# JSON output for programmatic use
context workspace discover --jsonBased on test results:
- Scan Speed: 200+ files/second
- Small Workspace (5 projects): ~0.5 seconds
- Medium Workspace (50 projects): ~2 seconds
- Large Workspace (200+ projects): ~8 seconds
- Accuracy: 95%+ correct classification
- Framework config files present (e.g.,
next.config.js) - Framework dependencies in package files
- Multiple indicators align
- Single indicator present
- Heuristic-based classification
- Ambiguous project structure
- Fallback classification
- Minimal indicators
- Manual review recommended
# Increase scan depth
context workspace discover --max-depth 20
# Check for hidden directories
ls -laEdit .context-workspace.json and adjust:
{
"type": "correct_type",
"metadata": {
"auto_discovered": true,
"manually_corrected": true
}
}The analyzer detects:
- Local path references (
file:../,-e ./) - Workspace packages (monorepo)
- Similar project names
Add manual relationships in .context-workspace.json:
{
"relationships": [
{
"from": "project1",
"to": "project2",
"type": "api_client",
"description": "project1 calls project2 API"
}
]
}You can also use the auto-discovery engine programmatically:
from src.workspace.auto_discovery import (
ProjectScanner,
TypeClassifier,
DependencyAnalyzer,
ConfigGenerator,
)
# Step 1: Scan
scanner = ProjectScanner(max_depth=10)
discovered = scanner.scan("/path/to/workspace")
# Step 2: Classify
classifier = TypeClassifier()
for project in discovered:
classifier.classify(project)
# Step 3: Analyze dependencies
analyzer = DependencyAnalyzer()
discovered, relations = analyzer.analyze(discovered)
# Step 4: Generate configuration
generator = ConfigGenerator()
config = generator.generate(
projects=discovered,
relations=relations,
workspace_name="My Workspace",
base_path="/path/to/workspace"
)
# Step 5: Save configuration
config.save(".context-workspace.json")Auto-discovery can be integrated into CI/CD pipelines:
# .github/workflows/context.yml
name: Update Context Workspace
on:
push:
branches: [main]
jobs:
discover:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Context
run: pip install context-engine
- name: Auto-discover workspace
run: |
context workspace discover --no-interactive
- name: Commit updated configuration
run: |
git config --global user.name "Context Bot"
git config --global user.email "bot@context.dev"
git add .context-workspace.json
git commit -m "chore: update workspace configuration" || true
git push- Review Before Committing: Always review auto-generated configurations
- Add Metadata: Include project descriptions and owners
- Version Control: Commit
.context-workspace.jsonto git - Regular Updates: Re-run discovery when adding new projects
- Manual Overrides: Document manual changes in metadata
Planned features for v2.6+:
- ML-based classification (higher accuracy)
- Remote repository scanning (GitHub, GitLab)
- API endpoint detection (swagger/openapi)
- Import analysis (AST parsing)
- Team collaboration features
- Cloud storage integration