engineering-intelligence 0.8.1 → 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.
Files changed (38) hide show
  1. package/dist/adapters/index.d.ts.map +1 -1
  2. package/dist/adapters/index.js +3 -0
  3. package/dist/adapters/index.js.map +1 -1
  4. package/dist/cli/index.js +20 -2
  5. package/dist/cli/index.js.map +1 -1
  6. package/dist/installer/index.d.ts.map +1 -1
  7. package/dist/installer/index.js +2 -10
  8. package/dist/installer/index.js.map +1 -1
  9. package/dist/manifest/index.d.ts +1 -1
  10. package/dist/manifest/index.js +1 -1
  11. package/dist/templates.d.ts +3 -2
  12. package/dist/templates.d.ts.map +1 -1
  13. package/dist/templates.js +24 -1
  14. package/dist/templates.js.map +1 -1
  15. package/dist/validation/index.d.ts.map +1 -1
  16. package/dist/validation/index.js +2 -11
  17. package/dist/validation/index.js.map +1 -1
  18. package/dist/visualizer/index.d.ts.map +1 -1
  19. package/dist/visualizer/index.js +100 -5
  20. package/dist/visualizer/index.js.map +1 -1
  21. package/package.json +1 -1
  22. package/templates/canonical/agents/engineering-orchestrator.md +21 -2
  23. package/templates/canonical/skills/codebase-discovery-engine/SKILL.md +428 -0
  24. package/templates/canonical/skills/convention-detector/SKILL.md +199 -0
  25. package/templates/canonical/skills/debugging-engine/SKILL.md +189 -0
  26. package/templates/canonical/skills/engineering-intelligence-skill/SKILL.md +4 -1
  27. package/templates/canonical/skills/git-intelligence-engine/SKILL.md +146 -0
  28. package/templates/canonical/skills/graph-engine/SKILL.md +30 -5
  29. package/templates/canonical/skills/greenfield-architect/SKILL.md +287 -0
  30. package/templates/canonical/skills/impact-analysis-engine/SKILL.md +12 -4
  31. package/templates/canonical/skills/incremental-sync-engine/SKILL.md +17 -0
  32. package/templates/canonical/skills/ongoing-learning-engine/SKILL.md +175 -0
  33. package/templates/canonical/skills/performance-analysis-engine/SKILL.md +156 -0
  34. package/templates/canonical/skills/pr-intelligence-engine/SKILL.md +127 -0
  35. package/templates/canonical/skills/security-audit-engine/SKILL.md +165 -0
  36. package/templates/canonical/skills/staleness-detector/SKILL.md +185 -0
  37. package/templates/canonical/workflows/create-project.md +63 -0
  38. package/templates/canonical/workflows/discover-codebase.md +60 -0
@@ -0,0 +1,156 @@
1
+ ---
2
+ name: performance-analysis-engine
3
+ description: Identifies performance issues through static analysis of database query patterns, frontend bundle size, render performance, API response patterns, and caching opportunities. Use during initialization, before releases, or when performance-sensitive changes are detected.
4
+ version: 3.0.0
5
+ ---
6
+
7
+ # Performance Analysis Engine
8
+
9
+ Identify performance risks and optimization opportunities through evidence-based static analysis of code patterns, queries, bundles, and caching strategies.
10
+
11
+ ## Inputs
12
+
13
+ - Repository root path
14
+ - Mode: `full` (comprehensive analysis) or `targeted` (specific area or post-change)
15
+ - Optional: scope constraints (specific modules, change diff)
16
+ - Optional: previous assessment (`knowledge-base/21-performance-assessment.md`) for delta comparison
17
+
18
+ ## Procedure
19
+
20
+ 1. **Database Query Pattern Analysis** — Scan data access layers for:
21
+
22
+ | Pattern | Risk | Detection Method |
23
+ |---|---|---|
24
+ | N+1 queries | High | Loop containing query calls, ORM eager/lazy loading misuse |
25
+ | Missing indexes | Medium | Queries filtering/sorting on non-indexed columns |
26
+ | Unbounded queries | High | SELECT without LIMIT, missing pagination |
27
+ | Full table scans | Medium | Queries without WHERE clauses on large tables |
28
+ | Unnecessary joins | Low | Joins fetching unused columns |
29
+ | Missing connection pooling | Medium | New connection per request pattern |
30
+
31
+ Cross-reference with schema definitions and ORM configuration.
32
+
33
+ 2. **Bundle Size Analysis** (frontend projects) — Assess:
34
+
35
+ | Check | Description |
36
+ |---|---|
37
+ | Bundle composition | Identify largest dependencies by size contribution |
38
+ | Tree-shaking gaps | Imports that prevent effective tree-shaking |
39
+ | Code splitting | Missing dynamic imports for route-level splitting |
40
+ | Duplicate dependencies | Same library bundled at multiple versions |
41
+ | Dead code | Exported modules never imported elsewhere |
42
+ | Asset optimization | Uncompressed images, unminified resources |
43
+
44
+ Read build configuration (webpack, vite, esbuild, etc.) to understand current optimization setup.
45
+
46
+ 3. **Render Performance Patterns** (frontend projects) — Identify:
47
+
48
+ | Pattern | Risk | Detection Method |
49
+ |---|---|---|
50
+ | Unnecessary re-renders | High | Components without memoization receiving stable props |
51
+ | Missing `useMemo`/`useCallback` | Medium | Expensive computations in render path |
52
+ | Large component trees | Medium | Deeply nested components without virtualization |
53
+ | Layout thrashing | High | DOM reads interleaved with writes |
54
+ | Missing virtualization | High | Lists rendering >100 items without windowing |
55
+ | Unoptimized images | Medium | Missing lazy loading, no responsive sizes |
56
+
57
+ 4. **API Response Time Patterns** — Analyze:
58
+
59
+ | Check | Description |
60
+ |---|---|
61
+ | Waterfall requests | Sequential API calls that could be parallelized |
62
+ | Over-fetching | Endpoints returning significantly more data than consumed |
63
+ | Under-fetching | Multiple requests needed where one could suffice |
64
+ | Missing pagination | List endpoints without page size limits |
65
+ | Synchronous heavy operations | Long-running tasks blocking request handlers |
66
+ | Missing timeouts | External API calls without timeout configuration |
67
+
68
+ 5. **Caching Opportunities** — Identify:
69
+
70
+ | Opportunity | Evidence |
71
+ |---|---|
72
+ | Repeated identical queries | Same query executed multiple times per request |
73
+ | Static data fetched dynamically | Configuration or reference data loaded on every request |
74
+ | Missing HTTP cache headers | Responses for stable resources without Cache-Control |
75
+ | Computation-heavy endpoints | Endpoints with expensive but deterministic calculations |
76
+ | Missing CDN utilization | Static assets served from application server |
77
+ | Session/user-level caching | Per-user data re-fetched on every request |
78
+
79
+ Review existing caching infrastructure (Redis, Memcached, in-memory, HTTP) and identify gaps.
80
+
81
+ 6. **Generate Assessment** — Write findings to `knowledge-base/21-performance-assessment.md`.
82
+
83
+ ## Output Format
84
+
85
+ Write `knowledge-base/21-performance-assessment.md`:
86
+
87
+ ```markdown
88
+ # Performance Assessment
89
+
90
+ ## Meta
91
+ - Generated: <ISO timestamp>
92
+ - Mode: full | targeted
93
+ - Scope: <what was examined>
94
+ - Overall risk: low | medium | high | critical
95
+
96
+ ## Database Query Patterns
97
+ | Issue | Location | Risk | Recommendation |
98
+ |---|---|---|---|
99
+ | N+1 query | src/users/service.ts:45 | High | Add eager loading for user.posts |
100
+
101
+ ## Bundle Analysis
102
+ | Metric | Value | Status |
103
+ |---|---|---|
104
+ | Total bundle size | 1.2 MB | concern |
105
+ | Largest dependency | moment.js (320 KB) | Replace with date-fns |
106
+
107
+ ## Render Performance
108
+ | Issue | Component | Risk | Recommendation |
109
+ |---|---|---|---|
110
+ | Missing memoization | UserList | Medium | Wrap with React.memo |
111
+
112
+ ## API Patterns
113
+ | Issue | Endpoint | Risk | Recommendation |
114
+ |---|---|---|---|
115
+ | Waterfall requests | /dashboard | High | Parallelize data fetching |
116
+
117
+ ## Caching Opportunities
118
+ | Opportunity | Location | Impact |
119
+ |---|---|---|
120
+ | Static config fetched per request | src/config/loader.ts | High |
121
+
122
+ ## Recommendations
123
+ 1. <prioritized optimization actions with estimated impact>
124
+
125
+ ## Evidence
126
+ - <file path citations for all findings>
127
+
128
+ ---
129
+ *This performance assessment did not modify product code.*
130
+ ```
131
+
132
+ ## Rules
133
+
134
+ - Every finding must cite a specific file path and line number or code pattern
135
+ - Risk assessment must consider actual usage patterns, not theoretical worst cases
136
+ - Bundle analysis findings must reference build configuration evidence
137
+ - Do not recommend premature optimization — prioritize by measured or evidenced impact
138
+ - This capability is analytical only — it must not modify product code
139
+
140
+ ## Quality Gates
141
+
142
+ - [ ] All findings cite specific file paths or code patterns
143
+ - [ ] Database query issues distinguish between ORM-generated and raw queries
144
+ - [ ] Bundle analysis references build configuration
145
+ - [ ] Render performance findings are framework-aware (React, Vue, Angular, etc.)
146
+ - [ ] Caching recommendations consider existing infrastructure
147
+ - [ ] Recommendations are prioritized by estimated impact
148
+ - [ ] Report ends with the "did not modify product code" statement
149
+
150
+ ## Cross-References
151
+
152
+ - Depends on: `deep-project-knowledge-extractor` (project structure and technology understanding)
153
+ - Used by: `engineering-intelligence-skill`, `impact-analysis-engine` (performance risk scoring)
154
+ - Updates: `knowledge-base/21-performance-assessment.md`
155
+
156
+ This capability is analytical only. It must not modify product code.
@@ -0,0 +1,127 @@
1
+ ---
2
+ name: pr-intelligence-engine
3
+ description: Generates intelligent PR descriptions, reviewer suggestions, impact summaries, and split recommendations from change records and git intelligence. Use before submitting or reviewing pull requests.
4
+ version: 3.0.0
5
+ ---
6
+
7
+ # PR Intelligence Engine
8
+
9
+ Produce evidence-backed PR artifacts that accelerate review cycles and improve change quality.
10
+
11
+ ## Inputs
12
+
13
+ - Change records from `.changes/CHG-XXX-*.md`
14
+ - Git diff or commit range for the PR
15
+ - Ownership mapping from `git-intelligence-engine` (`.engineering-intelligence/reports/GIT-intelligence.md`)
16
+ - Impact report from `impact-analysis-engine` (when available)
17
+ - Architecture decisions from `knowledge-base/`
18
+
19
+ ## Procedure
20
+
21
+ 1. **Analyze Change Scope** — Parse the diff or commit range to determine:
22
+ - Files modified, added, deleted
23
+ - Total lines changed (additions + deletions)
24
+ - Modules touched (distinct top-level directories or packages)
25
+ - Change classification (feature, bugfix, refactor, infrastructure, docs)
26
+
27
+ 2. **Generate PR Description** — From change records and diff, produce:
28
+
29
+ ```markdown
30
+ ## What
31
+ <concise summary of what changed and why>
32
+
33
+ ## Why
34
+ <link to change record CHG-XXX, issue/ticket if available>
35
+
36
+ ## How
37
+ <technical approach summary — key design decisions>
38
+
39
+ ## Impact
40
+ <blast radius summary from impact analysis>
41
+
42
+ ## Testing
43
+ <tests added/modified, validation performed>
44
+
45
+ ## Migration / Rollback
46
+ <if applicable — schema changes, feature flags, rollback steps>
47
+ ```
48
+
49
+ 3. **Suggest Reviewers** — Using ownership mapping from `git-intelligence-engine`:
50
+
51
+ | Priority | Criteria |
52
+ |---|---|
53
+ | Required | Primary owner of any modified module |
54
+ | Recommended | Secondary owner with recent activity in modified files |
55
+ | Optional | Contributors to change-coupled files not in the diff |
56
+ | Domain expert | Owner of upstream/downstream modules from impact analysis |
57
+
58
+ Flag when no active owner exists for a modified module (orphaned module risk).
59
+
60
+ 4. **Generate Impact Summary** — Produce a reviewer-focused impact digest:
61
+ - Risk level (from impact report or assessed from diff)
62
+ - Breaking changes (API contracts, schema migrations)
63
+ - Cross-service effects (if any)
64
+ - Intelligence artifacts that will need sync after merge
65
+
66
+ 5. **Evaluate PR Size and Suggest Split** — If the PR exceeds thresholds:
67
+
68
+ | Metric | Threshold | Action |
69
+ |---|---|---|
70
+ | Total lines changed | >500 | Suggest split |
71
+ | Modules touched | >3 | Suggest split |
72
+ | Mixed concerns | Feature + refactor | Suggest split |
73
+ | Schema + code | Migration + logic | Suggest split |
74
+
75
+ When suggesting split, propose concrete split boundaries:
76
+ - Group by module or concern
77
+ - Identify which changes can land independently
78
+ - Suggest merge order if dependencies exist between splits
79
+
80
+ 6. **Check Architecture Compliance** — Compare changes against:
81
+ - `knowledge-base/05-architecture-decisions.md` (ADRs)
82
+ - `knowledge-base/06-conventions-and-standards.md`
83
+ - Module boundary rules from `dependency-graph.json`
84
+
85
+ Flag violations with evidence:
86
+
87
+ | Violation Type | Example |
88
+ |---|---|
89
+ | Dependency direction | Service A importing from Service B's internals |
90
+ | Convention breach | Naming pattern, file structure deviation |
91
+ | ADR contradiction | Change conflicts with recorded architecture decision |
92
+ | Missing ADR | Architectural change without corresponding decision record |
93
+
94
+ ## Output Format
95
+
96
+ Generate the following artifacts (do not write to the repository — present to the user):
97
+
98
+ - **PR description** — Markdown ready to paste into PR body
99
+ - **Reviewer suggestions** — Ranked list with rationale
100
+ - **Impact summary** — Reviewer-focused digest
101
+ - **Split recommendations** — Only if thresholds are exceeded
102
+ - **Architecture flags** — Only if violations are detected
103
+
104
+ ## Rules
105
+
106
+ - PR descriptions must reference change records (CHG-XXX) when available
107
+ - Reviewer suggestions must cite ownership evidence, not guess from file paths
108
+ - Never suppress architecture violations — always surface them
109
+ - Split suggestions must include concrete boundaries, not vague advice
110
+ - This capability is analytical only — it must not modify product code
111
+
112
+ ## Quality Gates
113
+
114
+ - [ ] PR description covers what, why, how, impact, and testing
115
+ - [ ] Reviewer suggestions cite ownership data with evidence
116
+ - [ ] Impact summary includes risk level and blast radius
117
+ - [ ] Split recommendations (if any) propose concrete boundaries
118
+ - [ ] Architecture violations cite specific ADRs or conventions breached
119
+ - [ ] All claims reference change records, diffs, or intelligence artifacts
120
+
121
+ ## Cross-References
122
+
123
+ - Depends on: `git-intelligence-engine` (ownership mapping), `impact-analysis-engine` (impact reports), `change-detection-engine` (change records)
124
+ - Used by: `engineering-intelligence-skill`
125
+ - Consumed by: `engineering-change-review`
126
+
127
+ This capability is analytical only. It must not modify product code.
@@ -0,0 +1,165 @@
1
+ ---
2
+ name: security-audit-engine
3
+ description: Performs evidence-based security audits covering dependency vulnerabilities, auth/authz patterns, secrets detection, OWASP Top 10 compliance, and input validation. Use during initialization, before releases, or when security-sensitive changes are detected.
4
+ version: 3.0.0
5
+ ---
6
+
7
+ # Security Audit Engine
8
+
9
+ Identify security risks through systematic, evidence-backed analysis of dependencies, authentication patterns, secrets hygiene, and input handling.
10
+
11
+ ## Inputs
12
+
13
+ - Repository root path
14
+ - Mode: `full` (comprehensive audit) or `targeted` (specific area or post-change)
15
+ - Optional: scope constraints (specific modules, change diff)
16
+ - Optional: previous assessment (`knowledge-base/20-security-assessment.md`) for delta comparison
17
+
18
+ ## Procedure
19
+
20
+ 1. **Dependency Vulnerability Scanning** — Parse lock files and manifests:
21
+
22
+ | File | Ecosystem |
23
+ |---|---|
24
+ | `package-lock.json` / `yarn.lock` / `pnpm-lock.yaml` | npm |
25
+ | `Pipfile.lock` / `requirements.txt` | Python |
26
+ | `Cargo.lock` | Rust |
27
+ | `go.sum` | Go |
28
+ | `Gemfile.lock` | Ruby |
29
+ | `composer.lock` | PHP |
30
+
31
+ For each dependency:
32
+ - Check version against known CVE databases (cite CVE IDs)
33
+ - Flag dependencies with no updates in >12 months (abandonment risk)
34
+ - Identify transitive dependencies with known vulnerabilities
35
+ - Note severity: critical, high, medium, low
36
+
37
+ 2. **Auth/Authz Pattern Review** — Analyze authentication and authorization:
38
+
39
+ | Check | What to Look For |
40
+ |---|---|
41
+ | Auth mechanism | JWT, session, OAuth, API keys — identify which is used |
42
+ | Token handling | Storage (cookies, localStorage), expiration, refresh flow |
43
+ | Password handling | Hashing algorithm, salt usage, strength validation |
44
+ | Permission model | RBAC, ABAC, ACL — identify and assess |
45
+ | Route protection | Unprotected endpoints that should require auth |
46
+ | Privilege escalation | Missing authorization checks on sensitive operations |
47
+ | Session management | Fixation prevention, timeout, invalidation |
48
+
49
+ 3. **Secrets Detection** — Scan for exposed credentials:
50
+
51
+ | Pattern | Risk |
52
+ |---|---|
53
+ | Hardcoded API keys / tokens | Critical |
54
+ | Database connection strings with passwords | Critical |
55
+ | Private keys committed to repository | Critical |
56
+ | `.env` files without `.gitignore` coverage | High |
57
+ | Secrets in CI/CD configuration | High |
58
+ | Default/test credentials in non-test code | Medium |
59
+ | Comments containing sensitive URLs or tokens | Medium |
60
+
61
+ Check `.gitignore` for adequate secret file exclusions.
62
+
63
+ 4. **OWASP Top 10 Checklist** — Assess against current OWASP Top 10:
64
+
65
+ | # | Category | Assessment |
66
+ |---|---|---|
67
+ | A01 | Broken Access Control | Check route guards, CORS, directory traversal |
68
+ | A02 | Cryptographic Failures | Check TLS, hashing, encryption at rest |
69
+ | A03 | Injection | Check SQL, NoSQL, OS command, LDAP injection |
70
+ | A04 | Insecure Design | Check business logic flaws, missing rate limits |
71
+ | A05 | Security Misconfiguration | Check default configs, verbose errors, headers |
72
+ | A06 | Vulnerable Components | Cross-ref with dependency scan results |
73
+ | A07 | Auth Failures | Cross-ref with auth/authz review |
74
+ | A08 | Data Integrity Failures | Check deserialization, CI/CD pipeline integrity |
75
+ | A09 | Logging Failures | Check audit logging, sensitive data in logs |
76
+ | A10 | SSRF | Check URL handling, outbound request validation |
77
+
78
+ Rate each as: `pass`, `concern`, `fail`, or `not-applicable`.
79
+
80
+ 5. **Input Validation Pattern Review** — Assess input handling:
81
+
82
+ | Check | Description |
83
+ |---|---|
84
+ | Schema validation | Are API inputs validated against schemas? |
85
+ | Sanitization | Is user input sanitized before use? |
86
+ | File upload | Are uploads validated (type, size, content)? |
87
+ | Query parameters | Are query params validated and typed? |
88
+ | Output encoding | Is output encoded to prevent XSS? |
89
+ | Rate limiting | Are endpoints rate-limited? |
90
+
91
+ 6. **Generate Assessment** — Write findings to `knowledge-base/20-security-assessment.md`.
92
+
93
+ ## Output Format
94
+
95
+ Write `knowledge-base/20-security-assessment.md`:
96
+
97
+ ```markdown
98
+ # Security Assessment
99
+
100
+ ## Meta
101
+ - Generated: <ISO timestamp>
102
+ - Mode: full | targeted
103
+ - Scope: <what was examined>
104
+ - Overall risk: low | medium | high | critical
105
+
106
+ ## Dependency Vulnerabilities
107
+ | Dependency | Version | CVE | Severity | Fix Available |
108
+ |---|---|---|---|---|
109
+ | lodash | 4.17.15 | CVE-2020-8203 | High | Yes (4.17.21) |
110
+
111
+ ## Auth/Authz Assessment
112
+ - Mechanism: <description>
113
+ - Findings: <issues found>
114
+ - Risk: <level>
115
+
116
+ ## Secrets Scan
117
+ | Finding | File | Risk | Remediation |
118
+ |---|---|---|---|
119
+ | Hardcoded API key | src/config.ts:42 | Critical | Move to env variable |
120
+
121
+ ## OWASP Top 10
122
+ | # | Category | Status | Evidence |
123
+ |---|---|---|---|
124
+ | A01 | Broken Access Control | concern | <finding> |
125
+
126
+ ## Input Validation
127
+ | Area | Status | Evidence |
128
+ |---|---|---|
129
+ | API schema validation | pass | Uses Zod on all endpoints |
130
+
131
+ ## Recommendations
132
+ 1. <prioritized remediation actions>
133
+
134
+ ## Evidence
135
+ - <file path citations for all findings>
136
+
137
+ ---
138
+ *This security assessment did not modify product code.*
139
+ ```
140
+
141
+ ## Rules
142
+
143
+ - Never assume a vulnerability exists without evidence — cite file paths and line numbers
144
+ - Flag severity honestly — do not inflate or suppress findings
145
+ - Secrets detection must not log or expose the actual secret values in reports
146
+ - Mark `not-applicable` for OWASP categories genuinely irrelevant to the project
147
+ - This capability is analytical only — it must not modify product code
148
+
149
+ ## Quality Gates
150
+
151
+ - [ ] All dependency vulnerabilities cite CVE IDs and affected versions
152
+ - [ ] Auth/authz review covers both authentication and authorization
153
+ - [ ] Secrets scan does not expose actual secret values in the report
154
+ - [ ] OWASP Top 10 items each have a status with evidence or rationale
155
+ - [ ] Input validation assessment covers API boundaries
156
+ - [ ] Recommendations are prioritized by severity
157
+ - [ ] Report ends with the "did not modify product code" statement
158
+
159
+ ## Cross-References
160
+
161
+ - Depends on: `deep-project-knowledge-extractor` (project structure understanding)
162
+ - Used by: `engineering-intelligence-skill`, `impact-analysis-engine` (security risk scoring)
163
+ - Updates: `knowledge-base/20-security-assessment.md`
164
+
165
+ This capability is analytical only. It must not modify product code.
@@ -0,0 +1,185 @@
1
+ ---
2
+ name: staleness-detector
3
+ description: Compares knowledge-base document timestamps against related source file modification times, scores each document 0-100 for freshness, triggers incremental sync when freshness drops below threshold, and adds freshness metadata to document headers.
4
+ version: 3.0.0
5
+ ---
6
+
7
+ # Staleness Detector
8
+
9
+ Monitor the freshness of all engineering intelligence documents by comparing their last-updated timestamps against the modification times of the source files they describe. Produce a freshness report and trigger incremental sync for stale documents.
10
+
11
+ This capability does not modify product code.
12
+
13
+ ## Inputs
14
+
15
+ - Repository root path
16
+ - Knowledge base directory (`knowledge-base/`)
17
+ - Memory directory (`.engineering-intelligence/memory/`)
18
+ - Context directory (`.engineering-intelligence/context/`)
19
+ - Optional: specific document or module to check
20
+ - Optional: custom freshness threshold (default: 60)
21
+
22
+ ## Procedure
23
+
24
+ 1. **Inventory knowledge documents** — Enumerate all documents in:
25
+ - `knowledge-base/*.md` (00 through 16)
26
+ - `.engineering-intelligence/memory/*.md`
27
+ - `.engineering-intelligence/context/*.md`
28
+ - `.engineering-intelligence/graph/*.json`
29
+
30
+ For each document, extract:
31
+ - Document path
32
+ - Last modified timestamp (from filesystem or frontmatter `last_updated` field)
33
+ - Evidence citations within the document (file paths referenced)
34
+
35
+ 2. **Extract evidence dependencies** — For each knowledge document, parse all evidence citations to build a dependency map:
36
+
37
+ ```markdown
38
+ ## Document Dependencies
39
+
40
+ | Document | Depends On (Source Files) |
41
+ |---|---|
42
+ | `02-architecture.md` | `src/app/`, `src/server/`, `next.config.mjs` |
43
+ | `05-database.md` | `prisma/schema.prisma`, `src/db/`, `migrations/` |
44
+ | `06-authentication.md` | `src/auth/`, `auth.config.ts`, `middleware.ts` |
45
+ ```
46
+
47
+ 3. **Check source file modification times** — For each source file referenced by a knowledge document:
48
+ - Get the file's last modification time via `git log -1 --format=%cI -- <path>` (preferred) or filesystem mtime
49
+ - Compare against the knowledge document's last-updated timestamp
50
+ - Track files that no longer exist (deleted or moved)
51
+
52
+ 4. **Calculate freshness score** — Score each document 0–100 using this formula:
53
+
54
+ ```
55
+ base_score = 100
56
+
57
+ For each referenced source file:
58
+ days_since_doc_update = (now - document_last_updated).days
59
+ days_since_file_change = (now - file_last_modified).days
60
+
61
+ if file was modified AFTER document was last updated:
62
+ staleness_penalty = min(30, (file_modified - doc_updated).days * 3)
63
+ base_score -= staleness_penalty
64
+
65
+ if file no longer exists:
66
+ base_score -= 25 (major structural change)
67
+
68
+ if file was renamed/moved (detected via git):
69
+ base_score -= 15 (references are broken)
70
+
71
+ age_penalty = min(20, days_since_doc_update * 0.5)
72
+ base_score -= age_penalty
73
+
74
+ freshness_score = max(0, base_score)
75
+ ```
76
+
77
+ **Score interpretation:**
78
+
79
+ | Score | Status | Meaning |
80
+ |---|---|---|
81
+ | 80–100 | 🟢 Fresh | Document is current and reliable |
82
+ | 60–79 | 🟡 Aging | Document may have minor inaccuracies |
83
+ | 40–59 | 🟠 Stale | Document likely has outdated information |
84
+ | 20–39 | 🔴 Very Stale | Document is unreliable, needs re-generation |
85
+ | 0–19 | ⛔ Obsolete | Document may be misleading, urgent refresh needed |
86
+
87
+ 5. **Add freshness metadata** — Inject or update a frontmatter block at the top of each knowledge document:
88
+
89
+ ```markdown
90
+ <!-- freshness: score=75, status=aging, last_checked=2024-01-20T14:30:00Z -->
91
+ <!-- stale_sources: src/auth/middleware.ts (modified 5 days after doc update) -->
92
+ ```
93
+
94
+ Rules for metadata injection:
95
+ - If a `<!-- freshness: -->` comment already exists, update it in place
96
+ - If no freshness comment exists, add it after the document title (first `#` heading)
97
+ - Never modify document content — only metadata comments
98
+
99
+ 6. **Determine sync actions** — Based on freshness scores, determine required actions:
100
+
101
+ | Condition | Action |
102
+ |---|---|
103
+ | Score < threshold (default 60) | Queue for incremental sync via `incremental-sync-engine` |
104
+ | Score < 30 | Flag as critical in report, recommend full re-generation |
105
+ | Referenced file deleted | Flag structural change, recommend manual review |
106
+ | Referenced file moved | Update evidence citations, re-verify claims |
107
+ | Multiple documents stale for same module | Recommend module-level re-discovery |
108
+
109
+ 7. **Generate FRESHNESS-report.md** — Write to `.engineering-intelligence/reports/FRESHNESS-report.md`:
110
+
111
+ ```markdown
112
+ # Freshness Report
113
+
114
+ Generated: <timestamp>
115
+ Threshold: <score>
116
+ Documents scanned: <N>
117
+
118
+ ## Summary
119
+
120
+ | Status | Count | Percentage |
121
+ |---|---|---|
122
+ | 🟢 Fresh (80-100) | <N> | <N%> |
123
+ | 🟡 Aging (60-79) | <N> | <N%> |
124
+ | 🟠 Stale (40-59) | <N> | <N%> |
125
+ | 🔴 Very Stale (20-39) | <N> | <N%> |
126
+ | ⛔ Obsolete (0-19) | <N> | <N%> |
127
+
128
+ ## Document Scores
129
+
130
+ | Document | Score | Status | Stale Sources | Last Updated | Action Needed |
131
+ |---|---|---|---|---|---|
132
+ | `02-architecture.md` | 45 | 🟠 Stale | `src/app/layout.tsx` (+3d) | 2024-01-10 | Incremental sync |
133
+ | `05-database.md` | 90 | 🟢 Fresh | — | 2024-01-18 | None |
134
+ | ... | ... | ... | ... | ... | ... |
135
+
136
+ ## Structural Changes
137
+
138
+ | Type | File | Affected Documents |
139
+ |---|---|---|
140
+ | Deleted | `src/old-auth/handler.ts` | `06-authentication.md` |
141
+ | Moved | `src/utils.ts` → `src/lib/utils.ts` | `01-repository-structure.md` |
142
+
143
+ ## Recommended Actions
144
+
145
+ 1. **Critical** — Re-generate: <list of documents with score < 30>
146
+ 2. **High** — Incremental sync: <list of documents with score < 60>
147
+ 3. **Medium** — Review: <list of documents with score 60-79>
148
+ 4. **Structural** — Manual review needed: <list of deleted/moved file impacts>
149
+
150
+ ## Module-Level Freshness
151
+
152
+ | Module | Avg Document Score | Documents Below Threshold |
153
+ |---|---|---|
154
+ | auth | 42 | `06-authentication.md`, `context/critical-paths.md` |
155
+ | api | 88 | — |
156
+ | ... | ... | ... |
157
+ ```
158
+
159
+ 8. **Trigger incremental sync** — For documents below the threshold, invoke `incremental-sync-engine` with:
160
+ - The specific document to update
161
+ - The list of changed source files
162
+ - The staleness reason (file modified, file deleted, file moved, age)
163
+
164
+ ## Quality Gates
165
+
166
+ - [ ] All knowledge base, memory, and context documents are inventoried
167
+ - [ ] Evidence citations are parsed from every document
168
+ - [ ] Source file modification times are checked against document timestamps
169
+ - [ ] Freshness scores follow the defined calculation formula
170
+ - [ ] Score interpretation matches the defined status table
171
+ - [ ] Freshness metadata is injected without modifying document content
172
+ - [ ] FRESHNESS-report.md exists at `.engineering-intelligence/reports/FRESHNESS-report.md`
173
+ - [ ] Structural changes (deleted/moved files) are detected and reported
174
+ - [ ] Documents below threshold are queued for incremental sync
175
+ - [ ] Module-level aggregation is included in the report
176
+
177
+ ## Cross-References
178
+
179
+ - Used by: `ongoing-learning-engine` (for freshness monitoring)
180
+ - Uses: `incremental-sync-engine` (to refresh stale documents)
181
+ - Consumed by: `engineering-intelligence-skill`, `engineering-orchestrator`
182
+ - Feeds into: `.engineering-intelligence/reports/FRESHNESS-report.md`
183
+ - Related: `knowledge-base-validator` (validates content accuracy; staleness-detector validates currency)
184
+
185
+ This capability does not modify product code.