dev-playbooks 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/LICENSE +21 -0
- package/README.md +463 -0
- package/bin/devbooks.js +986 -0
- package/package.json +41 -0
- package/skills/Skill-Development-Guide.md +249 -0
- package/skills/Skills-Usage-Guide.md +447 -0
- package/skills/_shared/context-detection-template.md +315 -0
- package/skills/_shared/mcp-enhancement-template.md +144 -0
- package/skills/_shared/references/universal-gating-protocol.md +114 -0
- package/skills/_template/config-discovery-template.md +126 -0
- package/skills/devbooks-brownfield-bootstrap/SKILL.md +168 -0
- package/skills/devbooks-brownfield-bootstrap/references/10-glossary-template.md +42 -0
- package/skills/devbooks-brownfield-bootstrap/references/brownfield-bootstrap-prompt.md +115 -0
- package/skills/devbooks-brownfield-bootstrap/references/brownfield-bootstrap.md +96 -0
- package/skills/devbooks-brownfield-bootstrap/references/code-navigation-strategy.md +203 -0
- package/skills/devbooks-brownfield-bootstrap/scripts/cod-update.sh +357 -0
- package/skills/devbooks-brownfield-bootstrap/templates/project-profile-template.md +172 -0
- package/skills/devbooks-c4-map/SKILL.md +151 -0
- package/skills/devbooks-c4-map/references/c4-architecture-map-prompt.md +33 -0
- package/skills/devbooks-c4-map/references/layered-constraint-checklist.md +185 -0
- package/skills/devbooks-code-review/SKILL.md +175 -0
- package/skills/devbooks-code-review/references/code-review-prompt.md +100 -0
- package/skills/devbooks-code-review/references/code-smell-cheatsheet.md +498 -0
- package/skills/devbooks-code-review/references/pr-template-and-guidelines.md +321 -0
- package/skills/devbooks-code-review/references/resource-management-review-checklist.md +311 -0
- package/skills/devbooks-coder/SKILL.md +219 -0
- package/skills/devbooks-coder/references/code-implementation-prompt.md +74 -0
- package/skills/devbooks-coder/references/coding-style-guidelines.md +351 -0
- package/skills/devbooks-coder/references/error-code-standard.md +463 -0
- package/skills/devbooks-coder/references/logging-standard.md +329 -0
- package/skills/devbooks-coder/references/low-risk-modification-techniques.md +275 -0
- package/skills/devbooks-delivery-workflow/SKILL.md +217 -0
- package/skills/devbooks-delivery-workflow/references/9-change-verification-traceability-template.md +133 -0
- package/skills/devbooks-delivery-workflow/references/delivery-acceptance-workflow.md +177 -0
- package/skills/devbooks-delivery-workflow/references/prototype-production-dual-track.md +169 -0
- package/skills/devbooks-delivery-workflow/scripts/ac-trace-check.sh +330 -0
- package/skills/devbooks-delivery-workflow/scripts/audit-scope.sh +262 -0
- package/skills/devbooks-delivery-workflow/scripts/change-check.sh +1039 -0
- package/skills/devbooks-delivery-workflow/scripts/change-codemod-scaffold.sh +135 -0
- package/skills/devbooks-delivery-workflow/scripts/change-evidence.sh +152 -0
- package/skills/devbooks-delivery-workflow/scripts/change-scaffold.sh +467 -0
- package/skills/devbooks-delivery-workflow/scripts/change-spec-delta-scaffold.sh +135 -0
- package/skills/devbooks-delivery-workflow/scripts/constitution-check.sh +237 -0
- package/skills/devbooks-delivery-workflow/scripts/env-match-check.sh +128 -0
- package/skills/devbooks-delivery-workflow/scripts/fitness-check.sh +365 -0
- package/skills/devbooks-delivery-workflow/scripts/guardrail-check.sh +516 -0
- package/skills/devbooks-delivery-workflow/scripts/handoff-check.sh +141 -0
- package/skills/devbooks-delivery-workflow/scripts/hygiene-check.sh +340 -0
- package/skills/devbooks-delivery-workflow/scripts/migrate-from-openspec.sh +385 -0
- package/skills/devbooks-delivery-workflow/scripts/migrate-to-v2-gates.sh +202 -0
- package/skills/devbooks-delivery-workflow/scripts/progress-dashboard.sh +319 -0
- package/skills/devbooks-delivery-workflow/scripts/prototype-promote.sh +341 -0
- package/skills/devbooks-delivery-workflow/scripts/spec-preview.sh +203 -0
- package/skills/devbooks-delivery-workflow/scripts/spec-promote.sh +118 -0
- package/skills/devbooks-delivery-workflow/scripts/spec-rollback.sh +124 -0
- package/skills/devbooks-delivery-workflow/scripts/spec-stage.sh +117 -0
- package/skills/devbooks-delivery-workflow/scripts/verify-all.sh +78 -0
- package/skills/devbooks-delivery-workflow/scripts/verify-npm-package.sh +123 -0
- package/skills/devbooks-delivery-workflow/scripts/verify-openspec-free.sh +81 -0
- package/skills/devbooks-delivery-workflow/scripts/verify-slash-commands.sh +146 -0
- package/skills/devbooks-delivery-workflow/templates/handoff.md +50 -0
- package/skills/devbooks-design-backport/SKILL.md +73 -0
- package/skills/devbooks-design-backport/references/design-backport-prompt.md +132 -0
- package/skills/devbooks-design-doc/SKILL.md +121 -0
- package/skills/devbooks-design-doc/references/design-doc-prompt.md +188 -0
- package/skills/devbooks-design-doc/references/microservice-design-checklist.md +149 -0
- package/skills/devbooks-design-doc/references/privacy-compliance-checklist.md +240 -0
- package/skills/devbooks-entropy-monitor/SKILL.md +188 -0
- package/skills/devbooks-entropy-monitor/references/entropy-metrics-methodology.md +218 -0
- package/skills/devbooks-entropy-monitor/scripts/entropy-measure.sh +449 -0
- package/skills/devbooks-entropy-monitor/scripts/entropy-report.sh +303 -0
- package/skills/devbooks-entropy-monitor/templates/thresholds.json +99 -0
- package/skills/devbooks-federation/SKILL.md +264 -0
- package/skills/devbooks-federation/scripts/federation-check.sh +144 -0
- package/skills/devbooks-federation/templates/federation.yaml +89 -0
- package/skills/devbooks-impact-analysis/SKILL.md +135 -0
- package/skills/devbooks-impact-analysis/references/impact-analysis-prompt.md +82 -0
- package/skills/devbooks-impact-analysis/scripts/graph-cache.sh +214 -0
- package/skills/devbooks-implementation-plan/SKILL.md +83 -0
- package/skills/devbooks-implementation-plan/references/implementation-plan-prompt.md +95 -0
- package/skills/devbooks-index-bootstrap/SKILL.md +240 -0
- package/skills/devbooks-proposal-author/SKILL.md +83 -0
- package/skills/devbooks-proposal-author/references/proposal-authoring-prompt.md +66 -0
- package/skills/devbooks-proposal-challenger/SKILL.md +86 -0
- package/skills/devbooks-proposal-challenger/references/ethics-and-compliance-checklist.md +176 -0
- package/skills/devbooks-proposal-challenger/references/proposal-challenge-prompt.md +57 -0
- package/skills/devbooks-proposal-debate-workflow/SKILL.md +78 -0
- package/skills/devbooks-proposal-debate-workflow/references/11-proposal-debate-template.md +35 -0
- package/skills/devbooks-proposal-debate-workflow/references/proposal-debate-workflow.md +24 -0
- package/skills/devbooks-proposal-debate-workflow/scripts/proposal-debate-check.sh +102 -0
- package/skills/devbooks-proposal-judge/SKILL.md +78 -0
- package/skills/devbooks-proposal-judge/references/proposal-judge-prompt.md +37 -0
- package/skills/devbooks-router/SKILL.md +346 -0
- package/skills/devbooks-spec-contract/SKILL.md +191 -0
- package/skills/devbooks-spec-contract/references/api-design-guide.md +349 -0
- package/skills/devbooks-spec-contract/references/contract-and-data-definition-prompt.md +85 -0
- package/skills/devbooks-spec-contract/references/implicit-change-detection-prompt.md +183 -0
- package/skills/devbooks-spec-contract/references/spec-change-prompt.md +63 -0
- package/skills/devbooks-spec-contract/scripts/implicit-change-detect.sh +378 -0
- package/skills/devbooks-spec-gardener/SKILL.md +73 -0
- package/skills/devbooks-spec-gardener/references/spec-gardener-prompt.md +41 -0
- package/skills/devbooks-test-owner/SKILL.md +173 -0
- package/skills/devbooks-test-owner/references/9-change-verification-traceability-template.md +133 -0
- package/skills/devbooks-test-owner/references/async-system-test-strategy.md +316 -0
- package/skills/devbooks-test-owner/references/decoupling-techniques-cheatsheet.md +269 -0
- package/skills/devbooks-test-owner/references/test-code-prompt.md +171 -0
- package/skills/devbooks-test-owner/references/test-driven-development.md +351 -0
- package/skills/devbooks-test-owner/references/test-layering-strategy.md +281 -0
- package/skills/devbooks-test-reviewer/SKILL.md +189 -0
- package/templates/.devbooks/config.yaml +88 -0
- package/templates/claude-commands/devbooks/apply.md +38 -0
- package/templates/claude-commands/devbooks/archive.md +33 -0
- package/templates/claude-commands/devbooks/backport.md +19 -0
- package/templates/claude-commands/devbooks/bootstrap.md +20 -0
- package/templates/claude-commands/devbooks/c4.md +20 -0
- package/templates/claude-commands/devbooks/challenger.md +19 -0
- package/templates/claude-commands/devbooks/code.md +20 -0
- package/templates/claude-commands/devbooks/debate.md +20 -0
- package/templates/claude-commands/devbooks/delivery.md +20 -0
- package/templates/claude-commands/devbooks/design.md +20 -0
- package/templates/claude-commands/devbooks/entropy.md +19 -0
- package/templates/claude-commands/devbooks/federation.md +19 -0
- package/templates/claude-commands/devbooks/gardener.md +19 -0
- package/templates/claude-commands/devbooks/impact.md +19 -0
- package/templates/claude-commands/devbooks/index.md +19 -0
- package/templates/claude-commands/devbooks/judge.md +19 -0
- package/templates/claude-commands/devbooks/plan.md +20 -0
- package/templates/claude-commands/devbooks/proposal.md +20 -0
- package/templates/claude-commands/devbooks/quick.md +43 -0
- package/templates/claude-commands/devbooks/review.md +20 -0
- package/templates/claude-commands/devbooks/router.md +19 -0
- package/templates/claude-commands/devbooks/spec.md +20 -0
- package/templates/claude-commands/devbooks/test-review.md +19 -0
- package/templates/claude-commands/devbooks/test.md +20 -0
- package/templates/dev-playbooks/changes/.gitkeep +1 -0
- package/templates/dev-playbooks/constitution.md +116 -0
- package/templates/dev-playbooks/project.md +96 -0
- package/templates/dev-playbooks/scripts/.gitkeep +1 -0
- package/templates/dev-playbooks/specs/_meta/anti-patterns/.gitkeep +2 -0
- package/templates/dev-playbooks/specs/_meta/glossary.md +48 -0
- package/templates/dev-playbooks/specs/_meta/project-profile.md +79 -0
- package/templates/dev-playbooks/specs/architecture/fitness-rules.md +95 -0
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: devbooks-entropy-monitor
|
|
3
|
+
description: devbooks-entropy-monitor: Periodically collect system entropy metrics (structural entropy/change entropy/test entropy/dependency entropy), generate quantitative reports, and recommend refactoring when thresholds are exceeded. Use when user mentions "entropy measurement/complexity trends/refactoring warnings/code health/technical debt measurement".
|
|
4
|
+
tools:
|
|
5
|
+
- Glob
|
|
6
|
+
- Grep
|
|
7
|
+
- Read
|
|
8
|
+
- Bash
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# DevBooks: System Entropy Measurement and Alerts (Entropy Monitor)
|
|
12
|
+
|
|
13
|
+
> Source: "The Mythical Man-Month" Chapter 16 "No Silver Bullet" — "The complexity of software entities is an essential property... controlling complexity is the key to software development"
|
|
14
|
+
|
|
15
|
+
## Prerequisites: Configuration Discovery (Protocol-Agnostic)
|
|
16
|
+
|
|
17
|
+
- `<truth-root>`: Current truth directory root
|
|
18
|
+
- `<change-root>`: Change package directory root
|
|
19
|
+
|
|
20
|
+
Before execution, **must** search for configuration in the following order (stop when found):
|
|
21
|
+
1. `.devbooks/config.yaml` (if exists) → Parse and use its mappings
|
|
22
|
+
2. `dev-playbooks/project.md` (if exists) → DevBooks 2.0 protocol, use default mappings
|
|
23
|
+
4. `project.md` (if exists) → Template protocol, use default mappings
|
|
24
|
+
5. If still unable to determine → **Stop and ask the user**
|
|
25
|
+
|
|
26
|
+
**Key Constraints**:
|
|
27
|
+
- If `agents_doc` (rules document) is specified in configuration, **must read that document first** before executing any operations
|
|
28
|
+
- Do not guess directory roots
|
|
29
|
+
- Do not skip reading the rules document
|
|
30
|
+
|
|
31
|
+
## Core Philosophy
|
|
32
|
+
|
|
33
|
+
**System Entropy** = Growth trend of code complexity over time
|
|
34
|
+
|
|
35
|
+
Goals of entropy measurement:
|
|
36
|
+
1. **Quantification**: All metrics are numerical values/ratios, enabling comparison
|
|
37
|
+
2. **Trend Visibility**: Historical data supports trend analysis
|
|
38
|
+
3. **Threshold Alerts**: Proactively recommend refactoring when thresholds are exceeded
|
|
39
|
+
4. **Periodic Execution**: Run as an independent task, not embedded in every code review
|
|
40
|
+
|
|
41
|
+
## Execution Method
|
|
42
|
+
|
|
43
|
+
1) First read and follow: `_shared/references/universal-gating-protocol.md` (verifiability + structural quality gating).
|
|
44
|
+
2) Strictly output according to the complete prompt: `references/entropy-measurement-methodology.md`.
|
|
45
|
+
|
|
46
|
+
## Scripts
|
|
47
|
+
|
|
48
|
+
| Script | Purpose | Example |
|
|
49
|
+
|--------|---------|---------|
|
|
50
|
+
| `entropy-measure.sh` | Collect entropy metrics | `entropy-measure.sh --project-root /path/to/repo` |
|
|
51
|
+
| `entropy-report.sh` | Generate report | `entropy-report.sh --output report.md` |
|
|
52
|
+
|
|
53
|
+
## Metrics System (Four Dimensions)
|
|
54
|
+
|
|
55
|
+
### A) Structural Entropy
|
|
56
|
+
|
|
57
|
+
| Metric | Collection Method | Healthy Threshold | Description |
|
|
58
|
+
|--------|------------------|-------------------|-------------|
|
|
59
|
+
| Average Cyclomatic Complexity | Static analysis | < 10 | Function-level average |
|
|
60
|
+
| Cyclomatic Complexity P95 | Static analysis | < 20 | 95th percentile |
|
|
61
|
+
| File Lines P95 | Line count | < 500 | Oversized file warning |
|
|
62
|
+
| Function Lines P95 | Static analysis | < 50 | Overly long function warning |
|
|
63
|
+
|
|
64
|
+
### B) Change Entropy
|
|
65
|
+
|
|
66
|
+
| Metric | Collection Method | Healthy Threshold | Description |
|
|
67
|
+
|--------|------------------|-------------------|-------------|
|
|
68
|
+
| Hotspot File Ratio | git log | < 0.1 | Ratio of frequently modified files |
|
|
69
|
+
| Coupled Change Rate | git log | < 0.3 | Ratio of file pairs frequently modified together |
|
|
70
|
+
| Code Churn Rate | git diff | < 0.5 | Ratio of new code deleted within 30 days |
|
|
71
|
+
|
|
72
|
+
### C) Test Entropy
|
|
73
|
+
|
|
74
|
+
| Metric | Collection Method | Healthy Threshold | Description |
|
|
75
|
+
|--------|------------------|-------------------|-------------|
|
|
76
|
+
| Flaky Test Ratio | CI logs | < 0.01 | Ratio of unstable tests |
|
|
77
|
+
| Test Coverage | Coverage tools | > 0.7 | Code coverage rate |
|
|
78
|
+
| Test/Code Ratio | Line count | > 0.5 | Ratio of test code to production code |
|
|
79
|
+
|
|
80
|
+
### D) Dependency Entropy
|
|
81
|
+
|
|
82
|
+
| Metric | Collection Method | Healthy Threshold | Description |
|
|
83
|
+
|--------|------------------|-------------------|-------------|
|
|
84
|
+
| Outdated Dependency Ratio | npm/pip audit | < 0.2 | Dependencies more than 2 major versions behind |
|
|
85
|
+
| Security Vulnerability Count | Security scan | = 0 | Number of high-risk vulnerabilities |
|
|
86
|
+
| Dependency Depth P95 | Dependency tree analysis | < 10 | Levels of transitive dependencies |
|
|
87
|
+
|
|
88
|
+
## Output Locations
|
|
89
|
+
|
|
90
|
+
| Output | Path | Description |
|
|
91
|
+
|--------|------|-------------|
|
|
92
|
+
| Entropy Report | `<truth-root>/_meta/entropy/entropy-report-YYYY-MM-DD.md` | Current collection report |
|
|
93
|
+
| Historical Data | `<truth-root>/_meta/entropy/history.json` | All historical metrics |
|
|
94
|
+
| Threshold Configuration | `<truth-root>/_meta/entropy/thresholds.json` | Configurable thresholds |
|
|
95
|
+
|
|
96
|
+
## Recommended Execution Frequency
|
|
97
|
+
|
|
98
|
+
| Project Size | Recommended Frequency | Trigger Method |
|
|
99
|
+
|--------------|----------------------|----------------|
|
|
100
|
+
| Small (< 10K LOC) | Weekly | Manual / CI scheduled |
|
|
101
|
+
| Medium (10K-100K LOC) | Daily | CI scheduled |
|
|
102
|
+
| Large (> 100K LOC) | Every merge | PR merge trigger |
|
|
103
|
+
|
|
104
|
+
## Relationship with Other Skills
|
|
105
|
+
|
|
106
|
+
| Skill | Relationship |
|
|
107
|
+
|-------|--------------|
|
|
108
|
+
| devbooks-code-review | Entropy measurement is **not** embedded in every review, runs as independent task |
|
|
109
|
+
| devbooks-proposal-author | Entropy reports can serve as data support for refactoring proposals |
|
|
110
|
+
| devbooks-impact-analysis | Changes in high-entropy areas require more careful impact analysis |
|
|
111
|
+
|
|
112
|
+
## Hard Constraints
|
|
113
|
+
|
|
114
|
+
1. **Quantification First**: All metrics must be numerical values/ratios, no subjective evaluations
|
|
115
|
+
2. **Configurable Thresholds**: All thresholds managed through `thresholds.json`, not hardcoded
|
|
116
|
+
3. **Historical Traceability**: Each collection result appended to `history.json`
|
|
117
|
+
4. **Independent Execution**: Not embedded in other workflows, runs as periodic independent task
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## Context Awareness
|
|
122
|
+
|
|
123
|
+
This Skill automatically detects context before execution to select appropriate collection scope.
|
|
124
|
+
|
|
125
|
+
Detection rules reference: `skills/_shared/context-detection-template.md`
|
|
126
|
+
|
|
127
|
+
### Detection Flow
|
|
128
|
+
|
|
129
|
+
1. Detect if historical data file exists
|
|
130
|
+
2. Detect last collection time
|
|
131
|
+
3. Detect if any metrics exceed thresholds
|
|
132
|
+
|
|
133
|
+
### Modes Supported by This Skill
|
|
134
|
+
|
|
135
|
+
| Mode | Trigger Condition | Behavior |
|
|
136
|
+
|------|-------------------|----------|
|
|
137
|
+
| **Initial Collection** | Historical data does not exist | Execute full collection and establish baseline |
|
|
138
|
+
| **Incremental Collection** | Interval since last collection exceeded | Collect new data and compare trends |
|
|
139
|
+
| **Alert Mode** | Metrics exceeding thresholds detected | Generate alert report and recommend refactoring |
|
|
140
|
+
|
|
141
|
+
### Detection Output Example
|
|
142
|
+
|
|
143
|
+
```
|
|
144
|
+
Detection Results:
|
|
145
|
+
- Historical data: Exists (15 records)
|
|
146
|
+
- Last collection: 2026-01-10
|
|
147
|
+
- Metrics exceeding thresholds: 2 (Cyclomatic Complexity P95, Hotspot File Ratio)
|
|
148
|
+
- Execution mode: Incremental Collection + Alert Mode
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## MCP Enhancement
|
|
154
|
+
|
|
155
|
+
This Skill supports MCP runtime enhancement, automatically detecting and enabling advanced features.
|
|
156
|
+
|
|
157
|
+
MCP enhancement rules reference: `skills/_shared/mcp-enhancement-template.md`
|
|
158
|
+
|
|
159
|
+
### Required MCP Services
|
|
160
|
+
|
|
161
|
+
| Service | Purpose | Timeout |
|
|
162
|
+
|---------|---------|---------|
|
|
163
|
+
| `mcp__ckb__getHotspots` | Get hotspot file analysis | 2s |
|
|
164
|
+
| `mcp__ckb__getStatus` | Detect CKB index availability | 2s |
|
|
165
|
+
|
|
166
|
+
### Detection Flow
|
|
167
|
+
|
|
168
|
+
1. Call `mcp__ckb__getStatus` (2s timeout)
|
|
169
|
+
2. If CKB available → Use `getHotspots` for precise hotspot analysis
|
|
170
|
+
3. If timeout or failure → Fall back to Git history statistics
|
|
171
|
+
|
|
172
|
+
### Enhanced Mode vs Basic Mode
|
|
173
|
+
|
|
174
|
+
| Feature | Enhanced Mode | Basic Mode |
|
|
175
|
+
|---------|---------------|------------|
|
|
176
|
+
| Hotspot Analysis | CKB real-time analysis (includes complexity) | Git log change frequency statistics |
|
|
177
|
+
| Coupling Detection | Call graph analysis | File co-change analysis |
|
|
178
|
+
| Trend Prediction | Based on complexity change rate | Based on change frequency |
|
|
179
|
+
|
|
180
|
+
### Fallback Notice
|
|
181
|
+
|
|
182
|
+
When MCP is unavailable, output the following notice:
|
|
183
|
+
|
|
184
|
+
```
|
|
185
|
+
Warning: CKB unavailable, using Git history for entropy measurement.
|
|
186
|
+
Hotspot analysis based on change frequency, does not include code complexity data.
|
|
187
|
+
```
|
|
188
|
+
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
# Entropy Metrics Methodology
|
|
2
|
+
|
|
3
|
+
> Source: *The Mythical Man-Month*, Ch. 16 “No Silver Bullet” — “the complexity of software is an essential property… controlling complexity is key”
|
|
4
|
+
|
|
5
|
+
Highest-priority instruction:
|
|
6
|
+
- Before executing this prompt, read `_shared/references/universal-gating-protocol.md` and follow all protocols in it.
|
|
7
|
+
|
|
8
|
+
You are the **Entropy Monitor**. Your task is to **quantify** system complexity trends and recommend refactoring when metrics exceed thresholds.
|
|
9
|
+
|
|
10
|
+
## Core idea
|
|
11
|
+
|
|
12
|
+
**Entropy** = a measure of system disorder.
|
|
13
|
+
|
|
14
|
+
In software systems:
|
|
15
|
+
- **Low entropy** = clear structure, controllable change, healthy tests, healthy dependencies
|
|
16
|
+
- **High entropy** = messy structure, frequent hotspots, fragile tests, dependency decay
|
|
17
|
+
|
|
18
|
+
Entropy growth is inevitable, but it can be reduced via **intentional refactoring**.
|
|
19
|
+
|
|
20
|
+
## Four-dimension metrics framework
|
|
21
|
+
|
|
22
|
+
### A) Structural entropy
|
|
23
|
+
|
|
24
|
+
Measures static code complexity.
|
|
25
|
+
|
|
26
|
+
| Metric | Collection | Healthy threshold | Signal |
|
|
27
|
+
|-------|------------|------------------|--------|
|
|
28
|
+
| Cyclomatic complexity mean | static analysis | < 10 | functions are too complex |
|
|
29
|
+
| Cyclomatic complexity P95 | static analysis | < 20 | extreme outlier functions exist |
|
|
30
|
+
| File LOC P95 | `wc -l` | < 500 | files too large; split |
|
|
31
|
+
| Function LOC P95 | static analysis | < 50 | functions too long; extract |
|
|
32
|
+
|
|
33
|
+
Suggested tools:
|
|
34
|
+
- JavaScript/TypeScript: `eslint --rule complexity`
|
|
35
|
+
- Python: `radon cc`
|
|
36
|
+
- Go: `gocyclo`
|
|
37
|
+
- Java: `PMD`, `Checkstyle`
|
|
38
|
+
|
|
39
|
+
### B) Change entropy
|
|
40
|
+
|
|
41
|
+
Measures dynamic change patterns.
|
|
42
|
+
|
|
43
|
+
| Metric | Collection | Healthy threshold | Signal |
|
|
44
|
+
|-------|------------|------------------|--------|
|
|
45
|
+
| Hotspot ratio | git log analysis | < 0.1 | a few files absorb too much change |
|
|
46
|
+
| Coupled-change ratio | git log analysis | < 0.3 | implicit coupling across files |
|
|
47
|
+
| Churn ratio | git diff analysis | < 0.5 | newly added code is quickly removed |
|
|
48
|
+
|
|
49
|
+
**Hotspot**: a file modified more than 5 times within the analysis window.
|
|
50
|
+
|
|
51
|
+
**Coupled change**: two files modified together in the same commit frequently.
|
|
52
|
+
|
|
53
|
+
### C) Test entropy
|
|
54
|
+
|
|
55
|
+
Measures test quality and stability.
|
|
56
|
+
|
|
57
|
+
| Metric | Collection | Healthy threshold | Signal |
|
|
58
|
+
|-------|------------|------------------|--------|
|
|
59
|
+
| Flaky ratio | CI log analysis | < 0.01 | unreliable tests |
|
|
60
|
+
| Coverage | coverage tooling | > 0.7 | critical paths untested |
|
|
61
|
+
| Test/code ratio | line counts | > 0.5 | insufficient test investment |
|
|
62
|
+
|
|
63
|
+
**Flaky test**: for the same code, repeated runs yield inconsistent results.
|
|
64
|
+
|
|
65
|
+
### D) Dependency entropy
|
|
66
|
+
|
|
67
|
+
Measures dependency health.
|
|
68
|
+
|
|
69
|
+
| Metric | Collection | Healthy threshold | Signal |
|
|
70
|
+
|-------|------------|------------------|--------|
|
|
71
|
+
| Outdated ratio | `npm outdated` / `pip-audit` | < 0.2 | tech debt accumulation |
|
|
72
|
+
| Vulnerabilities | security scans | = 0 | security risk |
|
|
73
|
+
| Dependency depth P95 | dependency tree analysis | < 10 | supply-chain complexity |
|
|
74
|
+
|
|
75
|
+
**Outdated dependency**: lags the latest by more than 2 major versions.
|
|
76
|
+
|
|
77
|
+
## Execution flow
|
|
78
|
+
|
|
79
|
+
### 1) Collect metrics
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
entropy-measure.sh --project-root /path/to/repo --days 30
|
|
83
|
+
|
|
84
|
+
# Output:
|
|
85
|
+
<truth-root>/_meta/entropy/metrics-YYYY-MM-DD.json
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### 2) Generate report
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
entropy-report.sh --output report.md
|
|
92
|
+
|
|
93
|
+
# Output:
|
|
94
|
+
<truth-root>/_meta/entropy/entropy-report-YYYY-MM-DD.md
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### 3) Trend analysis
|
|
98
|
+
|
|
99
|
+
Historical data lives at `<truth-root>/_meta/entropy/history.json` and can be used to:
|
|
100
|
+
- plot trends
|
|
101
|
+
- compute deltas period-over-period
|
|
102
|
+
- estimate entropy growth rate
|
|
103
|
+
|
|
104
|
+
### 4) Threshold alerts
|
|
105
|
+
|
|
106
|
+
If any metric exceeds threshold:
|
|
107
|
+
1. report shows đź”´ status
|
|
108
|
+
2. an alert entry is generated
|
|
109
|
+
3. a concrete action is recommended
|
|
110
|
+
|
|
111
|
+
## Threshold configuration
|
|
112
|
+
|
|
113
|
+
Thresholds live at `<truth-root>/_meta/entropy/thresholds.json`:
|
|
114
|
+
|
|
115
|
+
```json
|
|
116
|
+
{
|
|
117
|
+
"structural": {
|
|
118
|
+
"complexity_mean": 10,
|
|
119
|
+
"complexity_p95": 20,
|
|
120
|
+
"file_lines_p95": 500,
|
|
121
|
+
"function_lines_p95": 50
|
|
122
|
+
},
|
|
123
|
+
"change": {
|
|
124
|
+
"hotspot_ratio": 0.1,
|
|
125
|
+
"coupling_ratio": 0.3,
|
|
126
|
+
"churn_ratio": 0.5
|
|
127
|
+
},
|
|
128
|
+
"test": {
|
|
129
|
+
"flaky_ratio": 0.01,
|
|
130
|
+
"coverage_min": 0.7,
|
|
131
|
+
"test_code_ratio_min": 0.5
|
|
132
|
+
},
|
|
133
|
+
"dependency": {
|
|
134
|
+
"outdated_ratio": 0.2,
|
|
135
|
+
"vulnerabilities": 0
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Threshold tuning principles:
|
|
141
|
+
- tune based on your project reality
|
|
142
|
+
- tighten gradually; do not “one-shot” it
|
|
143
|
+
- record rationale and date for changes
|
|
144
|
+
|
|
145
|
+
## Connecting to refactoring proposals
|
|
146
|
+
|
|
147
|
+
When multiple entropy metrics are out of bounds:
|
|
148
|
+
|
|
149
|
+
1. Use `devbooks-proposal-author` to start a refactoring proposal
|
|
150
|
+
2. Cite entropy report data in the “Why” section of `proposal.md`
|
|
151
|
+
3. Set verifiable entropy-reduction targets
|
|
152
|
+
|
|
153
|
+
Example:
|
|
154
|
+
|
|
155
|
+
```markdown
|
|
156
|
+
## Why
|
|
157
|
+
|
|
158
|
+
Entropy report (2024-01-15) shows:
|
|
159
|
+
- hotspot ratio 0.15 (threshold 0.1)
|
|
160
|
+
- file LOC P95 = 800 (threshold 500)
|
|
161
|
+
|
|
162
|
+
Recommendation: split `src/core/engine.ts` (1200 LOC) into multiple modules.
|
|
163
|
+
|
|
164
|
+
## Validation
|
|
165
|
+
|
|
166
|
+
After refactor:
|
|
167
|
+
- hotspot ratio < 0.08
|
|
168
|
+
- file LOC P95 < 400
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## Recommended cadence
|
|
172
|
+
|
|
173
|
+
| Project size | Cadence | Execution |
|
|
174
|
+
|-------------|---------|-----------|
|
|
175
|
+
| Small (< 10K LOC) | weekly | manual run |
|
|
176
|
+
| Medium (10K–100K LOC) | daily | scheduled CI job |
|
|
177
|
+
| Large (> 100K LOC) | per merge | trigger after PR merge |
|
|
178
|
+
|
|
179
|
+
## CI integration example
|
|
180
|
+
|
|
181
|
+
### GitHub Actions
|
|
182
|
+
|
|
183
|
+
```yaml
|
|
184
|
+
name: Entropy Monitor
|
|
185
|
+
on:
|
|
186
|
+
schedule:
|
|
187
|
+
- cron: '0 2 * * *' # 2am daily
|
|
188
|
+
workflow_dispatch:
|
|
189
|
+
|
|
190
|
+
jobs:
|
|
191
|
+
measure:
|
|
192
|
+
runs-on: ubuntu-latest
|
|
193
|
+
steps:
|
|
194
|
+
- uses: actions/checkout@v4
|
|
195
|
+
with:
|
|
196
|
+
fetch-depth: 0 # full git history required
|
|
197
|
+
- name: Run entropy measurement
|
|
198
|
+
run: ./scripts/entropy-measure.sh
|
|
199
|
+
- name: Generate report
|
|
200
|
+
run: ./scripts/entropy-report.sh
|
|
201
|
+
- name: Upload artifacts
|
|
202
|
+
uses: actions/upload-artifact@v4
|
|
203
|
+
with:
|
|
204
|
+
name: entropy-report
|
|
205
|
+
path: specs/_meta/entropy/
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## Hard constraints
|
|
209
|
+
|
|
210
|
+
1. **Quantitative first**: all metrics must be numeric/ratios; no subjective “looks complex”
|
|
211
|
+
2. **Thresholds are configurable**: managed via config files, not hard-coded
|
|
212
|
+
3. **History is preserved**: append each run to history.json to enable trend analysis
|
|
213
|
+
4. **Runs independently**: not embedded in every code review; run periodically as a standalone task
|
|
214
|
+
5. **Action-oriented**: every threshold breach must have a concrete recommendation
|
|
215
|
+
|
|
216
|
+
## References
|
|
217
|
+
|
|
218
|
+
- *The Mythical Man-Month*, Ch. 16 “No Silver Bullet”
|