@softspark/ai-toolkit 1.0.0
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.
- package/AGENTS.md +412 -0
- package/CHANGELOG.md +68 -0
- package/LICENSE +21 -0
- package/README.md +632 -0
- package/action.yml +53 -0
- package/app/.claude-plugin/plugin.json +44 -0
- package/app/ARCHITECTURE.md +306 -0
- package/app/CLAUDE.md.template +23 -0
- package/app/agents/ai-engineer.md +128 -0
- package/app/agents/backend-specialist.md +193 -0
- package/app/agents/business-intelligence.md +54 -0
- package/app/agents/chaos-monkey.md +67 -0
- package/app/agents/chief-of-staff.md +51 -0
- package/app/agents/code-archaeologist.md +127 -0
- package/app/agents/code-reviewer.md +184 -0
- package/app/agents/command-expert.md +131 -0
- package/app/agents/data-analyst.md +205 -0
- package/app/agents/data-scientist.md +151 -0
- package/app/agents/database-architect.md +317 -0
- package/app/agents/debugger.md +238 -0
- package/app/agents/devops-implementer.md +194 -0
- package/app/agents/documenter.md +364 -0
- package/app/agents/explorer-agent.md +145 -0
- package/app/agents/fact-checker.md +172 -0
- package/app/agents/frontend-specialist.md +209 -0
- package/app/agents/game-developer.md +216 -0
- package/app/agents/incident-responder.md +226 -0
- package/app/agents/infrastructure-architect.md +127 -0
- package/app/agents/infrastructure-validator.md +247 -0
- package/app/agents/llm-ops-engineer.md +237 -0
- package/app/agents/mcp-expert.md +228 -0
- package/app/agents/mcp-server-architect.md +195 -0
- package/app/agents/mcp-testing-engineer.md +292 -0
- package/app/agents/meta-architect.md +58 -0
- package/app/agents/ml-engineer.md +136 -0
- package/app/agents/mobile-developer.md +190 -0
- package/app/agents/night-watchman.md +55 -0
- package/app/agents/nlp-engineer.md +154 -0
- package/app/agents/orchestrator.md +437 -0
- package/app/agents/performance-optimizer.md +254 -0
- package/app/agents/predictive-analyst.md +57 -0
- package/app/agents/product-manager.md +194 -0
- package/app/agents/project-planner.md +287 -0
- package/app/agents/prompt-engineer.md +103 -0
- package/app/agents/qa-automation-engineer.md +182 -0
- package/app/agents/rag-engineer.md +201 -0
- package/app/agents/research-synthesizer.md +138 -0
- package/app/agents/search-specialist.md +101 -0
- package/app/agents/security-architect.md +62 -0
- package/app/agents/security-auditor.md +293 -0
- package/app/agents/seo-specialist.md +111 -0
- package/app/agents/system-governor.md +57 -0
- package/app/agents/tech-lead.md +62 -0
- package/app/agents/technical-researcher.md +103 -0
- package/app/agents/test-engineer.md +264 -0
- package/app/constitution.md +38 -0
- package/app/hooks/_profile-check.sh +11 -0
- package/app/hooks/guard-destructive.sh +74 -0
- package/app/hooks/guard-path.sh +73 -0
- package/app/hooks/post-tool-use.sh +35 -0
- package/app/hooks/pre-compact.sh +31 -0
- package/app/hooks/quality-check.sh +22 -0
- package/app/hooks/quality-gate.sh +49 -0
- package/app/hooks/save-session.sh +24 -0
- package/app/hooks/session-end.sh +37 -0
- package/app/hooks/session-start.sh +29 -0
- package/app/hooks/subagent-start.sh +16 -0
- package/app/hooks/subagent-stop.sh +16 -0
- package/app/hooks/track-usage.sh +50 -0
- package/app/hooks/user-prompt-submit.sh +25 -0
- package/app/hooks.json +178 -0
- package/app/mcp-defaults.json +23 -0
- package/app/output-styles/golden-rules.md +43 -0
- package/app/plugins/README.md +19 -0
- package/app/plugins/csharp-pack/README.md +11 -0
- package/app/plugins/csharp-pack/plugin.json +18 -0
- package/app/plugins/enterprise-pack/README.md +16 -0
- package/app/plugins/enterprise-pack/hooks/output-style.sh +6 -0
- package/app/plugins/enterprise-pack/hooks/status-line.sh +8 -0
- package/app/plugins/enterprise-pack/plugin.json +24 -0
- package/app/plugins/frontend-pack/README.md +14 -0
- package/app/plugins/frontend-pack/plugin.json +22 -0
- package/app/plugins/java-pack/README.md +11 -0
- package/app/plugins/java-pack/plugin.json +18 -0
- package/app/plugins/kotlin-pack/README.md +11 -0
- package/app/plugins/kotlin-pack/plugin.json +18 -0
- package/app/plugins/memory-pack/README.md +24 -0
- package/app/plugins/memory-pack/hooks/observation-capture.sh +67 -0
- package/app/plugins/memory-pack/hooks/session-summary.sh +71 -0
- package/app/plugins/memory-pack/plugin.json +22 -0
- package/app/plugins/memory-pack/scripts/init_db.py +81 -0
- package/app/plugins/memory-pack/scripts/strip_private.py +22 -0
- package/app/plugins/memory-pack/skills/mem-search/SKILL.md +70 -0
- package/app/plugins/research-pack/README.md +14 -0
- package/app/plugins/research-pack/plugin.json +22 -0
- package/app/plugins/ruby-pack/README.md +11 -0
- package/app/plugins/ruby-pack/plugin.json +18 -0
- package/app/plugins/rust-pack/README.md +11 -0
- package/app/plugins/rust-pack/plugin.json +18 -0
- package/app/plugins/security-pack/README.md +15 -0
- package/app/plugins/security-pack/plugin.json +23 -0
- package/app/plugins/swift-pack/README.md +11 -0
- package/app/plugins/swift-pack/plugin.json +18 -0
- package/app/rules/claude-toolkit-rules.md +21 -0
- package/app/rules/git-conventions.md +5 -0
- package/app/rules/quality-gates.md +10 -0
- package/app/skills/_lib/__init__.py +1 -0
- package/app/skills/_lib/detect_utils.py +150 -0
- package/app/skills/agent-creator/SKILL.md +82 -0
- package/app/skills/analyze/SKILL.md +92 -0
- package/app/skills/analyze/scripts/complexity.py +165 -0
- package/app/skills/api-patterns/SKILL.md +305 -0
- package/app/skills/app-builder/SKILL.md +187 -0
- package/app/skills/architecture-audit/SKILL.md +141 -0
- package/app/skills/architecture-decision/SKILL.md +55 -0
- package/app/skills/architecture-decision/templates/adr-template.md +36 -0
- package/app/skills/biz-scan/SKILL.md +30 -0
- package/app/skills/briefing/SKILL.md +27 -0
- package/app/skills/build/SKILL.md +97 -0
- package/app/skills/build/scripts/detect-build.py +151 -0
- package/app/skills/chaos/SKILL.md +32 -0
- package/app/skills/ci/SKILL.md +77 -0
- package/app/skills/ci/scripts/ci-detect.py +135 -0
- package/app/skills/ci/templates/github-actions-node.yml +38 -0
- package/app/skills/ci/templates/github-actions-python.yml +42 -0
- package/app/skills/ci-cd-patterns/SKILL.md +299 -0
- package/app/skills/clean-code/SKILL.md +110 -0
- package/app/skills/clean-code/reference/dart.md +18 -0
- package/app/skills/clean-code/reference/go.md +23 -0
- package/app/skills/clean-code/reference/php.md +32 -0
- package/app/skills/clean-code/reference/python.md +180 -0
- package/app/skills/clean-code/reference/typescript.md +26 -0
- package/app/skills/command-creator/SKILL.md +83 -0
- package/app/skills/commit/SKILL.md +98 -0
- package/app/skills/commit/scripts/pre-commit-check.py +87 -0
- package/app/skills/commit/templates/conventional-commit.md +52 -0
- package/app/skills/csharp-patterns/SKILL.md +450 -0
- package/app/skills/database-patterns/SKILL.md +297 -0
- package/app/skills/debug/SKILL.md +154 -0
- package/app/skills/debug/scripts/error-parser.py +187 -0
- package/app/skills/debugging-tactics/SKILL.md +136 -0
- package/app/skills/deploy/SKILL.md +130 -0
- package/app/skills/deploy/scripts/pre_deploy_check.py +171 -0
- package/app/skills/deploy/templates/deployment-checklist.md +31 -0
- package/app/skills/design-an-interface/SKILL.md +105 -0
- package/app/skills/design-engineering/SKILL.md +260 -0
- package/app/skills/docker-devops/SKILL.md +303 -0
- package/app/skills/docs/SKILL.md +145 -0
- package/app/skills/docs/scripts/doc-inventory.py +176 -0
- package/app/skills/docs/templates/adr-template.md +36 -0
- package/app/skills/docs/templates/readme-template.md +67 -0
- package/app/skills/documentation-standards/SKILL.md +191 -0
- package/app/skills/ecommerce-patterns/SKILL.md +209 -0
- package/app/skills/evaluate/SKILL.md +132 -0
- package/app/skills/evolve/SKILL.md +27 -0
- package/app/skills/explain/SKILL.md +54 -0
- package/app/skills/explain/scripts/dependency-graph.py +215 -0
- package/app/skills/explore/SKILL.md +112 -0
- package/app/skills/explore/scripts/visualize.py +117 -0
- package/app/skills/fix/SKILL.md +78 -0
- package/app/skills/fix/scripts/error-classifier.py +191 -0
- package/app/skills/flutter-patterns/SKILL.md +254 -0
- package/app/skills/git-mastery/SKILL.md +70 -0
- package/app/skills/grill-me/SKILL.md +38 -0
- package/app/skills/health/SKILL.md +91 -0
- package/app/skills/health/scripts/health_check.py +162 -0
- package/app/skills/hive-mind/SKILL.md +56 -0
- package/app/skills/hook-creator/SKILL.md +107 -0
- package/app/skills/index/SKILL.md +74 -0
- package/app/skills/instinct-review/SKILL.md +77 -0
- package/app/skills/java-patterns/SKILL.md +442 -0
- package/app/skills/kotlin-patterns/SKILL.md +446 -0
- package/app/skills/lint/SKILL.md +103 -0
- package/app/skills/lint/scripts/detect-linters.py +112 -0
- package/app/skills/mcp-patterns/SKILL.md +270 -0
- package/app/skills/mem-search/SKILL.md +70 -0
- package/app/skills/migrate/SKILL.md +90 -0
- package/app/skills/migrate/scripts/migration-status.py +195 -0
- package/app/skills/migration-patterns/SKILL.md +260 -0
- package/app/skills/night-watch/SKILL.md +28 -0
- package/app/skills/observability-patterns/SKILL.md +203 -0
- package/app/skills/onboard/SKILL.md +76 -0
- package/app/skills/orchestrate/SKILL.md +86 -0
- package/app/skills/panic/SKILL.md +30 -0
- package/app/skills/performance-profiling/SKILL.md +59 -0
- package/app/skills/plan/SKILL.md +110 -0
- package/app/skills/plan/templates/plan-template.md +40 -0
- package/app/skills/plan-writing/SKILL.md +201 -0
- package/app/skills/plugin-creator/SKILL.md +78 -0
- package/app/skills/pr/SKILL.md +129 -0
- package/app/skills/pr/scripts/pr-summary.py +175 -0
- package/app/skills/prd-to-issues/SKILL.md +108 -0
- package/app/skills/prd-to-plan/SKILL.md +120 -0
- package/app/skills/predict/SKILL.md +30 -0
- package/app/skills/qa-session/SKILL.md +110 -0
- package/app/skills/rag-patterns/SKILL.md +203 -0
- package/app/skills/refactor/SKILL.md +124 -0
- package/app/skills/refactor/scripts/refactor-scan.py +210 -0
- package/app/skills/refactor-plan/SKILL.md +112 -0
- package/app/skills/repeat/SKILL.md +149 -0
- package/app/skills/research-mastery/SKILL.md +56 -0
- package/app/skills/review/SKILL.md +141 -0
- package/app/skills/review/scripts/diff-analyzer.py +170 -0
- package/app/skills/rollback/SKILL.md +87 -0
- package/app/skills/rollback/scripts/rollback_info.py +149 -0
- package/app/skills/ruby-patterns/SKILL.md +454 -0
- package/app/skills/rust-patterns/SKILL.md +446 -0
- package/app/skills/search/SKILL.md +64 -0
- package/app/skills/security-patterns/SKILL.md +91 -0
- package/app/skills/security-patterns/reference/authentication.md +37 -0
- package/app/skills/security-patterns/reference/authorization.md +22 -0
- package/app/skills/security-patterns/reference/input-validation.md +30 -0
- package/app/skills/security-patterns/reference/oauth-csrf-audit.md +131 -0
- package/app/skills/skill-creator/SKILL.md +154 -0
- package/app/skills/skill-creator/templates/dashboard/index.html +130 -0
- package/app/skills/skill-creator/templates/reasoning-engine/assets/example.json +12 -0
- package/app/skills/skill-creator/templates/reasoning-engine/search.py +110 -0
- package/app/skills/subagent-development/SKILL.md +225 -0
- package/app/skills/subagent-development/reference/code-quality-reviewer-prompt.md +145 -0
- package/app/skills/subagent-development/reference/implementer-prompt.md +118 -0
- package/app/skills/subagent-development/reference/spec-reviewer-prompt.md +100 -0
- package/app/skills/swarm/SKILL.md +81 -0
- package/app/skills/swift-patterns/SKILL.md +500 -0
- package/app/skills/tdd/SKILL.md +174 -0
- package/app/skills/tdd/reference/deep-modules.md +32 -0
- package/app/skills/tdd/reference/interface-design.md +32 -0
- package/app/skills/tdd/reference/mocking.md +52 -0
- package/app/skills/tdd/reference/refactoring.md +10 -0
- package/app/skills/tdd/reference/tests.md +59 -0
- package/app/skills/teams/SKILL.md +101 -0
- package/app/skills/test/SKILL.md +107 -0
- package/app/skills/test/scripts/detect-runner.py +113 -0
- package/app/skills/testing-patterns/SKILL.md +73 -0
- package/app/skills/testing-patterns/reference/flutter-testing.md +33 -0
- package/app/skills/testing-patterns/reference/go-testing.md +52 -0
- package/app/skills/testing-patterns/reference/php-phpunit.md +39 -0
- package/app/skills/testing-patterns/reference/python-pytest.md +228 -0
- package/app/skills/testing-patterns/reference/typescript-vitest.md +50 -0
- package/app/skills/triage-issue/SKILL.md +120 -0
- package/app/skills/typescript-patterns/SKILL.md +256 -0
- package/app/skills/ubiquitous-language/SKILL.md +74 -0
- package/app/skills/verification-before-completion/SKILL.md +108 -0
- package/app/skills/workflow/SKILL.md +250 -0
- package/app/skills/write-a-prd/SKILL.md +129 -0
- package/app/skills/write-a-prd/reference/visual-companion.md +78 -0
- package/app/skills/write-a-prd/scripts/frame-template.html +111 -0
- package/app/skills/write-a-prd/scripts/visual-server.cjs +79 -0
- package/app/templates/skill/generator/SKILL.md.template +40 -0
- package/app/templates/skill/knowledge/SKILL.md.template +52 -0
- package/app/templates/skill/linter/SKILL.md.template +34 -0
- package/app/templates/skill/reviewer/SKILL.md.template +51 -0
- package/app/templates/skill/workflow/SKILL.md.template +49 -0
- package/benchmarks/README.md +111 -0
- package/benchmarks/ecosystem-dashboard.json +148 -0
- package/benchmarks/ecosystem-harvest.json +148 -0
- package/benchmarks/results.json +38 -0
- package/benchmarks/run.py +351 -0
- package/bin/ai-toolkit.js +345 -0
- package/kb/best-practices/README.md +11 -0
- package/kb/howto/README.md +11 -0
- package/kb/procedures/maintenance-sop.md +306 -0
- package/kb/reference/agents-catalog.md +124 -0
- package/kb/reference/anti-pattern-registry-format.md +221 -0
- package/kb/reference/architecture-overview.md +232 -0
- package/kb/reference/benchmark-config.md +62 -0
- package/kb/reference/ci-integration.md +66 -0
- package/kb/reference/claude-ecosystem-benchmark-snapshot.md +80 -0
- package/kb/reference/claude-ecosystem-expansion-foundations.md +102 -0
- package/kb/reference/commands-catalog.md +21 -0
- package/kb/reference/distribution-model.md +63 -0
- package/kb/reference/global-install-model.md +56 -0
- package/kb/reference/hierarchical-override-pattern.md +200 -0
- package/kb/reference/hooks-catalog.md +306 -0
- package/kb/reference/integrations.md +88 -0
- package/kb/reference/language-packs.md +52 -0
- package/kb/reference/merge-friendly-install-model.md +58 -0
- package/kb/reference/plugin-pack-conventions.md +151 -0
- package/kb/reference/quick-wins-implementation-summary.md +70 -0
- package/kb/reference/skill-templates.md +50 -0
- package/kb/reference/skills-catalog.md +215 -0
- package/kb/reference/skills-unification.md +57 -0
- package/kb/reference/stats.md +69 -0
- package/kb/reference/sync.md +76 -0
- package/kb/troubleshooting/README.md +11 -0
- package/llms-full.txt +3068 -0
- package/llms.txt +39 -0
- package/package.json +75 -0
- package/scripts/_common.py +160 -0
- package/scripts/add_rule.py +50 -0
- package/scripts/benchmark_config.py +127 -0
- package/scripts/benchmark_ecosystem.py +288 -0
- package/scripts/check_deps.py +260 -0
- package/scripts/create_skill.py +118 -0
- package/scripts/doctor.py +504 -0
- package/scripts/eject.py +113 -0
- package/scripts/emission.py +256 -0
- package/scripts/evaluate_skills.py +260 -0
- package/scripts/frontmatter.py +58 -0
- package/scripts/generate_agents_md.py +91 -0
- package/scripts/generate_aider_conf.py +51 -0
- package/scripts/generate_cline.py +35 -0
- package/scripts/generate_copilot.py +30 -0
- package/scripts/generate_cursor_rules.py +35 -0
- package/scripts/generate_gemini.py +28 -0
- package/scripts/generate_llms_txt.py +164 -0
- package/scripts/generate_roo_modes.py +80 -0
- package/scripts/generate_windsurf.py +35 -0
- package/scripts/generator_base.py +140 -0
- package/scripts/harvest_ecosystem.py +50 -0
- package/scripts/inject_rule_cli.py +101 -0
- package/scripts/inject_section_cli.py +47 -0
- package/scripts/injection.py +180 -0
- package/scripts/install.py +236 -0
- package/scripts/install_git_hooks.py +71 -0
- package/scripts/install_steps/__init__.py +5 -0
- package/scripts/install_steps/ai_tools.py +261 -0
- package/scripts/install_steps/hooks.py +90 -0
- package/scripts/install_steps/markers.py +79 -0
- package/scripts/install_steps/symlinks.py +87 -0
- package/scripts/merge-hooks.py +192 -0
- package/scripts/plugin.py +642 -0
- package/scripts/plugin_schema.py +138 -0
- package/scripts/remove_rule.py +58 -0
- package/scripts/stats.py +81 -0
- package/scripts/sync.py +215 -0
- package/scripts/uninstall.py +292 -0
- package/scripts/validate.py +700 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: evaluate
|
|
3
|
+
description: "Evaluate skill quality and RAG retrieval accuracy"
|
|
4
|
+
effort: medium
|
|
5
|
+
disable-model-invocation: true
|
|
6
|
+
argument-hint: "[--threshold N]"
|
|
7
|
+
allowed-tools: Bash, Read
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# RAG Evaluation
|
|
11
|
+
|
|
12
|
+
Evaluate RAG quality using LLM-as-a-Judge methodology.
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
/evaluate [--threshold 0.7]
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Execution
|
|
21
|
+
|
|
22
|
+
### Direct Execution (recommended for most projects)
|
|
23
|
+
```bash
|
|
24
|
+
# Run RAG evaluation
|
|
25
|
+
python3 scripts/evaluate_rag.py
|
|
26
|
+
|
|
27
|
+
# With custom thresholds
|
|
28
|
+
python3 scripts/evaluate_rag.py \
|
|
29
|
+
--faithfulness 0.7 \
|
|
30
|
+
--relevancy 0.7 \
|
|
31
|
+
--context 0.6
|
|
32
|
+
|
|
33
|
+
# Detect knowledge gaps
|
|
34
|
+
python3 scripts/knowledge_gaps.py --detect
|
|
35
|
+
|
|
36
|
+
# Generate gap report
|
|
37
|
+
python3 scripts/knowledge_gaps.py --report
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Docker Execution (containerized projects)
|
|
41
|
+
```bash
|
|
42
|
+
# Replace {api-container} with your API server container name
|
|
43
|
+
docker exec {api-container} python3 scripts/evaluate_rag.py
|
|
44
|
+
|
|
45
|
+
# With custom thresholds
|
|
46
|
+
docker exec {api-container} python3 scripts/evaluate_rag.py \
|
|
47
|
+
--faithfulness 0.7 \
|
|
48
|
+
--relevancy 0.7 \
|
|
49
|
+
--context 0.6
|
|
50
|
+
|
|
51
|
+
# Detect knowledge gaps
|
|
52
|
+
docker exec {api-container} python3 scripts/knowledge_gaps.py --detect
|
|
53
|
+
|
|
54
|
+
# Generate gap report
|
|
55
|
+
docker exec {api-container} python3 scripts/knowledge_gaps.py --report
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Metrics
|
|
59
|
+
|
|
60
|
+
| Metric | Description | Target |
|
|
61
|
+
|--------|-------------|--------|
|
|
62
|
+
| **Faithfulness** | Is answer based on context? | >70% |
|
|
63
|
+
| **Relevancy** | Does answer address question? | >70% |
|
|
64
|
+
| **Context Precision** | Is found context accurate? | >60% |
|
|
65
|
+
|
|
66
|
+
## Evaluation Process
|
|
67
|
+
|
|
68
|
+
1. **Generate test queries** from golden dataset
|
|
69
|
+
2. **Execute RAG pipeline** for each query
|
|
70
|
+
3. **LLM judges** each response on metrics
|
|
71
|
+
4. **Report** aggregate scores
|
|
72
|
+
|
|
73
|
+
## Golden Dataset
|
|
74
|
+
|
|
75
|
+
Located at: `scripts/golden_dataset.json` (or project-specific path)
|
|
76
|
+
|
|
77
|
+
```json
|
|
78
|
+
{
|
|
79
|
+
"queries": [
|
|
80
|
+
{
|
|
81
|
+
"query": "How to configure rate limiting?",
|
|
82
|
+
"expected_topics": ["nginx", "rate-limiting"],
|
|
83
|
+
"expected_sources": ["kb/nginx/howto/rate-limiting.md"]
|
|
84
|
+
}
|
|
85
|
+
]
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Output Example
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
RAG Evaluation Results
|
|
93
|
+
======================
|
|
94
|
+
Total Queries: 50
|
|
95
|
+
Average Faithfulness: 0.82
|
|
96
|
+
Average Relevancy: 0.78
|
|
97
|
+
Average Context Precision: 0.71
|
|
98
|
+
|
|
99
|
+
Quality: GOOD
|
|
100
|
+
|
|
101
|
+
Failed Queries (faithfulness < 0.7):
|
|
102
|
+
- Query: "How to backup PostgreSQL?"
|
|
103
|
+
Score: 0.45
|
|
104
|
+
Issue: No relevant documents found
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Knowledge Gaps
|
|
108
|
+
|
|
109
|
+
After evaluation, check for gaps:
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
# Direct execution
|
|
113
|
+
python3 scripts/knowledge_gaps.py --detect
|
|
114
|
+
|
|
115
|
+
# Docker execution
|
|
116
|
+
docker exec {api-container} python3 scripts/knowledge_gaps.py --detect
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Output:
|
|
120
|
+
```
|
|
121
|
+
Knowledge Gaps Detected:
|
|
122
|
+
1. PostgreSQL backup procedures (5 failed queries)
|
|
123
|
+
2. Redis caching configuration (3 failed queries)
|
|
124
|
+
3. Ollama model selection (2 failed queries)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Quality Gates
|
|
128
|
+
|
|
129
|
+
- [ ] Faithfulness >70%
|
|
130
|
+
- [ ] Relevancy >70%
|
|
131
|
+
- [ ] Context Precision >60%
|
|
132
|
+
- [ ] No critical knowledge gaps
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: evolve
|
|
3
|
+
description: "Evolve agent definitions via meta-architect"
|
|
4
|
+
effort: medium
|
|
5
|
+
disable-model-invocation: true
|
|
6
|
+
context: fork
|
|
7
|
+
agent: meta-architect
|
|
8
|
+
allowed-tools: Read, Edit, Grep, Glob
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# Evolve Command
|
|
12
|
+
|
|
13
|
+
Triggers the Meta-Architect to improve the system.
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
/evolve [source]
|
|
19
|
+
# Example: /evolve learnings (Analyze kb/learnings)
|
|
20
|
+
# Example: /evolve last-failure (Analyze last error log)
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Protocol
|
|
24
|
+
1. **Analyze**: Read input source for patterns of failure/inefficiency.
|
|
25
|
+
2. **Design**: Draft changes to `.claude/agents/` or `.claude/skills/`.
|
|
26
|
+
3. **Implement**: Apply changes.
|
|
27
|
+
4. **Report**: Document what evolved.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: explain
|
|
3
|
+
description: "Explain code, architecture, or concepts with diagrams"
|
|
4
|
+
user-invocable: true
|
|
5
|
+
effort: medium
|
|
6
|
+
argument-hint: "[file or module path]"
|
|
7
|
+
agent: code-archaeologist
|
|
8
|
+
context: fork
|
|
9
|
+
allowed-tools: Read, Grep, Glob
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# Explain
|
|
13
|
+
|
|
14
|
+
$ARGUMENTS
|
|
15
|
+
|
|
16
|
+
Generates visual architecture explanations.
|
|
17
|
+
|
|
18
|
+
## Output Format
|
|
19
|
+
|
|
20
|
+
### 1. High-Level Role
|
|
21
|
+
"This module handles [Responsibility]. It interacts with [Dependencies]."
|
|
22
|
+
|
|
23
|
+
### 2. Dependency Graph (Mermaid)
|
|
24
|
+
Generate a graph showing imports/exports.
|
|
25
|
+
```mermaid
|
|
26
|
+
graph TD
|
|
27
|
+
A[AuthService] -->|uses| B[UserRepo]
|
|
28
|
+
A -->|validates| C[Schema]
|
|
29
|
+
D[Controller] -->|calls| A
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### 3. Key Flows (Sequence)
|
|
33
|
+
If logical flows are detected:
|
|
34
|
+
```mermaid
|
|
35
|
+
sequenceDiagram
|
|
36
|
+
User->>Controller: Login
|
|
37
|
+
Controller->>Service: Validate
|
|
38
|
+
Service->>DB: Check Creds
|
|
39
|
+
DB-->>Service: Result
|
|
40
|
+
Service-->>Controller: Token
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Protocol
|
|
44
|
+
1. **Scan**: Read file contents to identify classes and functions.
|
|
45
|
+
2. **Link**: Identify imports to find collaborators.
|
|
46
|
+
3. **Visualize**: Generate standard Mermaid syntax.
|
|
47
|
+
|
|
48
|
+
## Automated Dependency Graph
|
|
49
|
+
|
|
50
|
+
Run the bundled script to extract imports and generate a Mermaid diagram:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
python3 ${CLAUDE_SKILL_DIR}/scripts/dependency-graph.py src/auth.py
|
|
54
|
+
```
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Extract import graph from source files and generate Mermaid syntax."""
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
import os
|
|
6
|
+
import re
|
|
7
|
+
import sys
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
IGNORE_DIRS = {'.git', 'node_modules', '__pycache__', '.venv', 'venv', 'dist', 'build', '.next', 'vendor', '.cache'}
|
|
11
|
+
|
|
12
|
+
LANG_MAP = {
|
|
13
|
+
'.py': 'python',
|
|
14
|
+
'.js': 'javascript',
|
|
15
|
+
'.ts': 'typescript',
|
|
16
|
+
'.tsx': 'typescript',
|
|
17
|
+
'.jsx': 'javascript',
|
|
18
|
+
'.go': 'go',
|
|
19
|
+
'.php': 'php',
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
SOURCE_EXTS = set(LANG_MAP.keys())
|
|
23
|
+
|
|
24
|
+
IMPORT_PATTERNS = {
|
|
25
|
+
'python': [
|
|
26
|
+
re.compile(r'^\s*import\s+([\w.]+)'),
|
|
27
|
+
re.compile(r'^\s*from\s+([\w.]+)\s+import'),
|
|
28
|
+
],
|
|
29
|
+
'javascript': [
|
|
30
|
+
re.compile(r'''import\s+.*?from\s+['"]([^'"]+)['"]'''),
|
|
31
|
+
re.compile(r'''require\s*\(\s*['"]([^'"]+)['"]\s*\)'''),
|
|
32
|
+
],
|
|
33
|
+
'typescript': [
|
|
34
|
+
re.compile(r'''import\s+.*?from\s+['"]([^'"]+)['"]'''),
|
|
35
|
+
re.compile(r'''require\s*\(\s*['"]([^'"]+)['"]\s*\)'''),
|
|
36
|
+
],
|
|
37
|
+
'go': [
|
|
38
|
+
re.compile(r'^\s*"([^"]+)"'),
|
|
39
|
+
re.compile(r'^\s*import\s+"([^"]+)"'),
|
|
40
|
+
],
|
|
41
|
+
'php': [
|
|
42
|
+
re.compile(r'^\s*use\s+([\w\\]+)'),
|
|
43
|
+
],
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
FUNC_CLASS_PATTERNS = {
|
|
47
|
+
'python': {
|
|
48
|
+
'function': re.compile(r'^\s*def\s+(\w+)\s*\('),
|
|
49
|
+
'class': re.compile(r'^\s*class\s+(\w+)'),
|
|
50
|
+
},
|
|
51
|
+
'javascript': {
|
|
52
|
+
'function': re.compile(r'(?:^|\s)function\s+(\w+)|(?:const|let|var)\s+(\w+)\s*=\s*(?:async\s*)?\('),
|
|
53
|
+
'class': re.compile(r'^\s*class\s+(\w+)'),
|
|
54
|
+
},
|
|
55
|
+
'typescript': {
|
|
56
|
+
'function': re.compile(r'(?:^|\s)function\s+(\w+)|(?:const|let|var)\s+(\w+)\s*=\s*(?:async\s*)?\('),
|
|
57
|
+
'class': re.compile(r'^\s*(?:class|interface)\s+(\w+)'),
|
|
58
|
+
},
|
|
59
|
+
'go': {
|
|
60
|
+
'function': re.compile(r'^\s*func\s+(?:\([^)]*\)\s+)?(\w+)\s*\('),
|
|
61
|
+
'class': re.compile(r'^\s*type\s+(\w+)\s+(?:struct|interface)'),
|
|
62
|
+
},
|
|
63
|
+
'php': {
|
|
64
|
+
'function': re.compile(r'^\s*(?:public|private|protected|static|\s)*function\s+(\w+)'),
|
|
65
|
+
'class': re.compile(r'^\s*(?:abstract\s+)?class\s+(\w+)'),
|
|
66
|
+
},
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def detect_language(filepath: str) -> str:
|
|
71
|
+
ext = Path(filepath).suffix
|
|
72
|
+
return LANG_MAP.get(ext, '')
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def extract_imports(filepath: str, language: str) -> list:
|
|
76
|
+
patterns = IMPORT_PATTERNS.get(language, [])
|
|
77
|
+
imports = []
|
|
78
|
+
try:
|
|
79
|
+
with open(filepath, 'r', errors='replace') as f:
|
|
80
|
+
for line in f:
|
|
81
|
+
for pat in patterns:
|
|
82
|
+
m = pat.search(line)
|
|
83
|
+
if m:
|
|
84
|
+
# Use first non-None group
|
|
85
|
+
val = next((g for g in m.groups() if g is not None), None)
|
|
86
|
+
if val and val not in imports:
|
|
87
|
+
imports.append(val)
|
|
88
|
+
except OSError:
|
|
89
|
+
pass
|
|
90
|
+
return imports
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def extract_symbols(filepath: str, language: str) -> tuple:
|
|
94
|
+
patterns = FUNC_CLASS_PATTERNS.get(language, {})
|
|
95
|
+
functions, classes = [], []
|
|
96
|
+
try:
|
|
97
|
+
with open(filepath, 'r', errors='replace') as f:
|
|
98
|
+
for line in f:
|
|
99
|
+
fp = patterns.get('function')
|
|
100
|
+
if fp:
|
|
101
|
+
m = fp.search(line)
|
|
102
|
+
if m:
|
|
103
|
+
name = next((g for g in m.groups() if g is not None), None)
|
|
104
|
+
if name and name not in functions:
|
|
105
|
+
functions.append(name)
|
|
106
|
+
cp = patterns.get('class')
|
|
107
|
+
if cp:
|
|
108
|
+
m = cp.search(line)
|
|
109
|
+
if m:
|
|
110
|
+
name = next((g for g in m.groups() if g is not None), None)
|
|
111
|
+
if name and name not in classes:
|
|
112
|
+
classes.append(name)
|
|
113
|
+
except OSError:
|
|
114
|
+
pass
|
|
115
|
+
return functions, classes
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def find_source_files(root: str) -> list:
|
|
119
|
+
result = []
|
|
120
|
+
for dirpath, dirnames, filenames in os.walk(root):
|
|
121
|
+
dirnames[:] = [d for d in dirnames if d not in IGNORE_DIRS]
|
|
122
|
+
for fn in filenames:
|
|
123
|
+
if Path(fn).suffix in SOURCE_EXTS:
|
|
124
|
+
result.append(os.path.join(dirpath, fn))
|
|
125
|
+
return result
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def build_reverse_map(project_root: str, target_stem: str) -> list:
|
|
129
|
+
imported_by = []
|
|
130
|
+
for src in find_source_files(project_root):
|
|
131
|
+
lang = detect_language(src)
|
|
132
|
+
if not lang:
|
|
133
|
+
continue
|
|
134
|
+
imps = extract_imports(src, lang)
|
|
135
|
+
for imp in imps:
|
|
136
|
+
if target_stem in imp or Path(target_stem).stem in imp:
|
|
137
|
+
rel = os.path.relpath(src, project_root)
|
|
138
|
+
if rel not in imported_by:
|
|
139
|
+
imported_by.append(rel)
|
|
140
|
+
break
|
|
141
|
+
return imported_by
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def generate_mermaid(target_name: str, imports: list, imported_by: list) -> str:
|
|
145
|
+
lines = ['graph TD']
|
|
146
|
+
safe = re.sub(r'[^a-zA-Z0-9_]', '_', target_name)
|
|
147
|
+
lines.append(f' {safe}["{target_name}"]')
|
|
148
|
+
for imp in imports:
|
|
149
|
+
imp_safe = re.sub(r'[^a-zA-Z0-9_]', '_', imp)
|
|
150
|
+
lines.append(f' {safe} -->|imports| {imp_safe}["{imp}"]')
|
|
151
|
+
for dep in imported_by:
|
|
152
|
+
dep_safe = re.sub(r'[^a-zA-Z0-9_]', '_', dep)
|
|
153
|
+
lines.append(f' {dep_safe}["{dep}"] -->|imports| {safe}')
|
|
154
|
+
return '\n'.join(lines)
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def main():
|
|
158
|
+
if len(sys.argv) < 2:
|
|
159
|
+
print(json.dumps({"error": "Usage: dependency-graph.py <file_or_directory>"}))
|
|
160
|
+
sys.exit(1)
|
|
161
|
+
|
|
162
|
+
target = os.path.abspath(sys.argv[1])
|
|
163
|
+
if not os.path.exists(target):
|
|
164
|
+
print(json.dumps({"error": f"Path not found: {target}"}))
|
|
165
|
+
sys.exit(1)
|
|
166
|
+
|
|
167
|
+
# Determine project root (walk up to find .git or use parent)
|
|
168
|
+
project_root = target if os.path.isdir(target) else os.path.dirname(target)
|
|
169
|
+
check = project_root
|
|
170
|
+
for _ in range(10):
|
|
171
|
+
if os.path.isdir(os.path.join(check, '.git')):
|
|
172
|
+
project_root = check
|
|
173
|
+
break
|
|
174
|
+
parent = os.path.dirname(check)
|
|
175
|
+
if parent == check:
|
|
176
|
+
break
|
|
177
|
+
check = parent
|
|
178
|
+
|
|
179
|
+
files = [target] if os.path.isfile(target) else find_source_files(target)
|
|
180
|
+
|
|
181
|
+
all_imports, all_functions, all_classes = [], [], []
|
|
182
|
+
language = ''
|
|
183
|
+
|
|
184
|
+
for fp in files:
|
|
185
|
+
lang = detect_language(fp)
|
|
186
|
+
if not lang:
|
|
187
|
+
continue
|
|
188
|
+
if not language:
|
|
189
|
+
language = lang
|
|
190
|
+
imps = extract_imports(fp, lang)
|
|
191
|
+
all_imports.extend(i for i in imps if i not in all_imports)
|
|
192
|
+
funcs, clss = extract_symbols(fp, lang)
|
|
193
|
+
all_functions.extend(f for f in funcs if f not in all_functions)
|
|
194
|
+
all_classes.extend(c for c in clss if c not in all_classes)
|
|
195
|
+
|
|
196
|
+
target_name = os.path.relpath(target, project_root)
|
|
197
|
+
imported_by = build_reverse_map(project_root, target_name)
|
|
198
|
+
|
|
199
|
+
mermaid = generate_mermaid(target_name, all_imports, imported_by)
|
|
200
|
+
|
|
201
|
+
result = {
|
|
202
|
+
"target": target_name,
|
|
203
|
+
"language": language,
|
|
204
|
+
"imports": all_imports,
|
|
205
|
+
"imported_by": imported_by,
|
|
206
|
+
"functions": all_functions,
|
|
207
|
+
"classes": all_classes,
|
|
208
|
+
"mermaid": mermaid,
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
print(json.dumps(result, indent=2))
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
if __name__ == '__main__':
|
|
215
|
+
main()
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: explore
|
|
3
|
+
description: "Explore codebase structure, stack, and architecture"
|
|
4
|
+
user-invocable: true
|
|
5
|
+
effort: medium
|
|
6
|
+
argument-hint: "[path or question]"
|
|
7
|
+
allowed-tools: Read, Grep, Glob
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Codebase Exploration
|
|
11
|
+
|
|
12
|
+
$ARGUMENTS
|
|
13
|
+
|
|
14
|
+
Explore and understand a codebase structure.
|
|
15
|
+
|
|
16
|
+
## Project context
|
|
17
|
+
|
|
18
|
+
- Config files: !`find . -maxdepth 2 -type f -name "*.json" -o -name "*.toml" -o -name "*.yaml" -o -name "*.yml" 2>/dev/null | head -20`
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
/explore [path]
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## What This Command Does
|
|
27
|
+
|
|
28
|
+
1. **Maps** project structure
|
|
29
|
+
2. **Identifies** technology stack
|
|
30
|
+
3. **Finds** key files and patterns
|
|
31
|
+
4. **Reports** architecture overview
|
|
32
|
+
|
|
33
|
+
## Output Format
|
|
34
|
+
|
|
35
|
+
```markdown
|
|
36
|
+
## Codebase Analysis Report
|
|
37
|
+
|
|
38
|
+
### Project Type
|
|
39
|
+
- **Language**: [TypeScript/Python/PHP/etc.]
|
|
40
|
+
- **Framework**: [Next.js/FastAPI/Laravel/etc.]
|
|
41
|
+
- **Package Manager**: [npm/pnpm/pip/composer]
|
|
42
|
+
|
|
43
|
+
### Directory Structure
|
|
44
|
+
```
|
|
45
|
+
project/
|
|
46
|
+
├── src/ # Source code
|
|
47
|
+
├── tests/ # Test files
|
|
48
|
+
├── config/ # Configuration
|
|
49
|
+
└── ...
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Key Files
|
|
53
|
+
| File | Purpose |
|
|
54
|
+
|------|---------|
|
|
55
|
+
| `src/index.ts` | Entry point |
|
|
56
|
+
| `src/api/` | API routes |
|
|
57
|
+
|
|
58
|
+
### Dependencies
|
|
59
|
+
- **Runtime**: [list]
|
|
60
|
+
- **Dev**: [list]
|
|
61
|
+
|
|
62
|
+
### Patterns Detected
|
|
63
|
+
- [Pattern 1]
|
|
64
|
+
- [Pattern 2]
|
|
65
|
+
|
|
66
|
+
### Entry Points
|
|
67
|
+
- [Entry 1]
|
|
68
|
+
- [Entry 2]
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Technology Detection
|
|
72
|
+
|
|
73
|
+
| Marker | Technology |
|
|
74
|
+
|--------|------------|
|
|
75
|
+
| `package.json` | Node.js |
|
|
76
|
+
| `tsconfig.json` | TypeScript |
|
|
77
|
+
| `next.config.*` | Next.js |
|
|
78
|
+
| `nuxt.config.*` | Nuxt |
|
|
79
|
+
| `pyproject.toml` | Python |
|
|
80
|
+
| `composer.json` | PHP |
|
|
81
|
+
| `pubspec.yaml` | Flutter/Dart |
|
|
82
|
+
| `Cargo.toml` | Rust |
|
|
83
|
+
| `go.mod` | Go |
|
|
84
|
+
|
|
85
|
+
## When to Use
|
|
86
|
+
|
|
87
|
+
- Starting work on unfamiliar codebase
|
|
88
|
+
- Before planning major changes
|
|
89
|
+
- Understanding dependencies
|
|
90
|
+
- Finding specific code patterns
|
|
91
|
+
|
|
92
|
+
## READ-ONLY
|
|
93
|
+
|
|
94
|
+
This skill ONLY reads and analyzes.
|
|
95
|
+
It does NOT write or modify any files.
|
|
96
|
+
|
|
97
|
+
## Visual Output
|
|
98
|
+
|
|
99
|
+
For an interactive HTML tree visualization of the codebase:
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
python ${CLAUDE_SKILL_DIR}/scripts/visualize.py .
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
This generates `codebase-map.html` with collapsible directories, file sizes, and type-colored indicators.
|
|
106
|
+
|
|
107
|
+
## KB Integration
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
smart_query("codebase analysis: {technology}")
|
|
111
|
+
hybrid_search_kb("project structure {framework}")
|
|
112
|
+
```
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Generate an interactive collapsible tree visualization of a codebase.
|
|
3
|
+
|
|
4
|
+
Usage: python visualize.py [directory]
|
|
5
|
+
Output: codebase-map.html (opened in browser)
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import json
|
|
9
|
+
import sys
|
|
10
|
+
import webbrowser
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
from collections import Counter
|
|
13
|
+
|
|
14
|
+
IGNORE = {'.git', 'node_modules', '__pycache__', '.venv', 'venv', 'dist', 'build', '.next', '.nuxt', '.cache', 'vendor', '.dart_tool'}
|
|
15
|
+
|
|
16
|
+
def scan(path: Path, stats: dict) -> dict:
|
|
17
|
+
result = {"name": path.name, "children": [], "size": 0}
|
|
18
|
+
try:
|
|
19
|
+
for item in sorted(path.iterdir()):
|
|
20
|
+
if item.name in IGNORE or item.name.startswith('.'):
|
|
21
|
+
continue
|
|
22
|
+
if item.is_file():
|
|
23
|
+
size = item.stat().st_size
|
|
24
|
+
ext = item.suffix.lower() or '(no ext)'
|
|
25
|
+
result["children"].append({"name": item.name, "size": size, "ext": ext})
|
|
26
|
+
result["size"] += size
|
|
27
|
+
stats["files"] += 1
|
|
28
|
+
stats["extensions"][ext] += 1
|
|
29
|
+
stats["ext_sizes"][ext] += size
|
|
30
|
+
elif item.is_dir():
|
|
31
|
+
stats["dirs"] += 1
|
|
32
|
+
child = scan(item, stats)
|
|
33
|
+
if child["children"]:
|
|
34
|
+
result["children"].append(child)
|
|
35
|
+
result["size"] += child["size"]
|
|
36
|
+
except PermissionError:
|
|
37
|
+
pass
|
|
38
|
+
return result
|
|
39
|
+
|
|
40
|
+
def fmt(b):
|
|
41
|
+
if b < 1024: return f"{b} B"
|
|
42
|
+
if b < 1048576: return f"{b/1024:.1f} KB"
|
|
43
|
+
return f"{b/1048576:.1f} MB"
|
|
44
|
+
|
|
45
|
+
def generate_html(data: dict, stats: dict, output: Path) -> None:
|
|
46
|
+
ext_sizes = stats["ext_sizes"]
|
|
47
|
+
total_size = sum(ext_sizes.values()) or 1
|
|
48
|
+
sorted_exts = sorted(ext_sizes.items(), key=lambda x: -x[1])[:8]
|
|
49
|
+
colors = {
|
|
50
|
+
'.js': '#f7df1e', '.ts': '#3178c6', '.py': '#3776ab', '.go': '#00add8',
|
|
51
|
+
'.rs': '#dea584', '.rb': '#cc342d', '.css': '#264de4', '.html': '#e34c26',
|
|
52
|
+
'.json': '#6b7280', '.md': '#083fa1', '.yaml': '#cb171e', '.yml': '#cb171e',
|
|
53
|
+
'.tsx': '#3178c6', '.jsx': '#61dafb', '.sh': '#4eaa25', '.dart': '#0175c2',
|
|
54
|
+
'.php': '#777bb4', '.vue': '#42b883', '.svelte': '#ff3e00',
|
|
55
|
+
}
|
|
56
|
+
lang_bars = "".join(
|
|
57
|
+
f'<div class="bar-row"><span class="bar-label">{ext}</span>'
|
|
58
|
+
f'<div class="bar" style="width:{(size/total_size)*100}%;background:{colors.get(ext,"#6b7280")}"></div>'
|
|
59
|
+
f'<span class="bar-pct">{(size/total_size)*100:.1f}%</span></div>'
|
|
60
|
+
for ext, size in sorted_exts
|
|
61
|
+
)
|
|
62
|
+
html = f'''<!DOCTYPE html>
|
|
63
|
+
<html><head><meta charset="utf-8"><title>Codebase Explorer</title>
|
|
64
|
+
<style>
|
|
65
|
+
body {{ font: 14px/1.5 system-ui, sans-serif; margin: 0; background: #1a1a2e; color: #eee; }}
|
|
66
|
+
.container {{ display: flex; height: 100vh; }}
|
|
67
|
+
.sidebar {{ width: 280px; background: #252542; padding: 20px; border-right: 1px solid #3d3d5c; overflow-y: auto; flex-shrink: 0; }}
|
|
68
|
+
.main {{ flex: 1; padding: 20px; overflow-y: auto; }}
|
|
69
|
+
h1 {{ margin: 0 0 10px; font-size: 18px; }} h2 {{ margin: 20px 0 10px; font-size: 14px; color: #888; text-transform: uppercase; }}
|
|
70
|
+
.stat {{ display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid #3d3d5c; }}
|
|
71
|
+
.stat-value {{ font-weight: bold; }}
|
|
72
|
+
.bar-row {{ display: flex; align-items: center; margin: 6px 0; }}
|
|
73
|
+
.bar-label {{ width: 55px; font-size: 12px; color: #aaa; }}
|
|
74
|
+
.bar {{ height: 18px; border-radius: 3px; }} .bar-pct {{ margin-left: 8px; font-size: 12px; color: #666; }}
|
|
75
|
+
.tree {{ list-style: none; padding-left: 20px; }}
|
|
76
|
+
details {{ cursor: pointer; }} summary {{ padding: 4px 8px; border-radius: 4px; }}
|
|
77
|
+
summary:hover {{ background: #2d2d44; }} .folder {{ color: #ffd700; }}
|
|
78
|
+
.file {{ display: flex; align-items: center; padding: 4px 8px; border-radius: 4px; }}
|
|
79
|
+
.file:hover {{ background: #2d2d44; }} .size {{ color: #888; margin-left: auto; font-size: 12px; }}
|
|
80
|
+
.dot {{ width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; display: inline-block; }}
|
|
81
|
+
</style></head><body>
|
|
82
|
+
<div class="container">
|
|
83
|
+
<div class="sidebar">
|
|
84
|
+
<h1>Summary</h1>
|
|
85
|
+
<div class="stat"><span>Files</span><span class="stat-value">{stats["files"]:,}</span></div>
|
|
86
|
+
<div class="stat"><span>Directories</span><span class="stat-value">{stats["dirs"]:,}</span></div>
|
|
87
|
+
<div class="stat"><span>Total size</span><span class="stat-value">{fmt(data["size"])}</span></div>
|
|
88
|
+
<div class="stat"><span>File types</span><span class="stat-value">{len(stats["extensions"])}</span></div>
|
|
89
|
+
<h2>By file type</h2>{lang_bars}
|
|
90
|
+
</div>
|
|
91
|
+
<div class="main"><h1>{data["name"]}</h1><ul class="tree" id="root"></ul></div>
|
|
92
|
+
</div>
|
|
93
|
+
<script>
|
|
94
|
+
const data={json.dumps(data)};const colors={json.dumps(colors)};
|
|
95
|
+
function fmt(b){{if(b<1024)return b+' B';if(b<1048576)return(b/1024).toFixed(1)+' KB';return(b/1048576).toFixed(1)+' MB';}}
|
|
96
|
+
function render(n,p){{if(n.children){{const d=document.createElement('details');d.open=p===document.getElementById('root');
|
|
97
|
+
d.innerHTML=`<summary><span class="folder">${{n.name}}</span><span class="size">${{fmt(n.size)}}</span></summary>`;
|
|
98
|
+
const u=document.createElement('ul');u.className='tree';n.children.sort((a,b)=>(b.children?1:0)-(a.children?1:0)||a.name.localeCompare(b.name));
|
|
99
|
+
n.children.forEach(c=>render(c,u));d.appendChild(u);const l=document.createElement('li');l.appendChild(d);p.appendChild(l);
|
|
100
|
+
}}else{{const l=document.createElement('li');l.className='file';
|
|
101
|
+
l.innerHTML=`<span class="dot" style="background:${{colors[n.ext]||'#6b7280'}}"></span>${{n.name}}<span class="size">${{fmt(n.size)}}</span>`;
|
|
102
|
+
p.appendChild(l);}}}}
|
|
103
|
+
data.children.forEach(c=>render(c,document.getElementById('root')));
|
|
104
|
+
</script></body></html>'''
|
|
105
|
+
output.write_text(html)
|
|
106
|
+
|
|
107
|
+
if __name__ == '__main__':
|
|
108
|
+
target = Path(sys.argv[1] if len(sys.argv) > 1 else '.').resolve()
|
|
109
|
+
stats = {"files": 0, "dirs": 0, "extensions": Counter(), "ext_sizes": Counter()}
|
|
110
|
+
data = scan(target, stats)
|
|
111
|
+
out = Path('codebase-map.html')
|
|
112
|
+
generate_html(data, stats, out)
|
|
113
|
+
print(f'Generated {out.absolute()}')
|
|
114
|
+
try:
|
|
115
|
+
webbrowser.open(f'file://{out.absolute()}')
|
|
116
|
+
except Exception:
|
|
117
|
+
pass
|