AgentSkillsCN

knowledge

在编辑 project_knowledge.json、上下文文件,或管理知识缓存时加载。提供高效的项目上下文管理模式,可将 Token 使用量降低 90%。

SKILL.md
--- frontmatter
name: knowledge
description: Load when working with project_knowledge.json, context files, or managing knowledge cache. Provides patterns for efficient project context management with 90% token reduction.

Knowledge

Merged Skills

  • context-management: Project knowledge graph, entity lookup
  • caching: Hot cache, domain index, gotchas lookup

⚠️ Critical Gotchas

CategoryPatternSolution
Multiple queriesRunning --query 5 timesRead first 100 lines ONCE at START
Repeated readsReading knowledge file multiple timesKeep in memory for entire session
Wrong lookupSearching when data is cachedCheck hot_cache before file reads
Stale knowledgeEntity refs outdatedRun knowledge.py --update after sessions
Missing gotchasNew issues not documentedAdd to workflow log, will be merged

Rules

RulePattern
Load onceRead first 100 lines ONCE at session start
Memory-firstKeep loaded knowledge in context
Hot cache firstCheck hot_cache.entity_refs before file reads
Gotchas firstCheck gotchas.issues when debugging
Update at ENDRun knowledge.py --update in END phase

Avoid

❌ Bad✅ Good
Run --query 5 timesRead first 100 lines once
grep knowledge.jsonCheck loaded gotchas in memory
list_dir for pathsCheck domain_index
Search for entityCheck hot_cache first

⛔ MANDATORY: Load Once at START

bash
head -100 project_knowledge.json  # Do this ONCE

This gives you (in memory for entire session):

LineContentUse For
1HOT_CACHETop 20 entities + file paths
2DOMAIN_INDEX81 backend, 71 frontend paths
3CHANGE_TRACKINGFile modification hashes
4GOTCHAS38 known issues + solutions
5INTERCONNECTIONSEntity chains
6SESSION_PATTERNSPreload hints
7-12Layer entitiesGraph structure
13-93Layer relationsLookup paths

Patterns

bash
# Pattern 1: Session start - load knowledge
head -100 project_knowledge.json

# Pattern 2: Query specific entity (rare, only if cache miss)
python .github/scripts/knowledge.py --query "entity_name"

# Pattern 3: Update knowledge after session
python .github/scripts/knowledge.py --update
python
# Pattern 4: Using knowledge programmatically
import json

with open('project_knowledge.json') as f:
    for i, line in enumerate(f):
        if i >= 100:
            break
        data = json.loads(line)
        if data.get('type') == 'hot_cache':
            entity_refs = data['entity_refs']
        elif data.get('type') == 'gotchas':
            issues = data['issues']

Query Order (Using In-Memory Knowledge)

StepCheckIf Miss
1hot_cache.top_entities→ Step 2
2gotchas.issues→ Step 3
3domain_index.backend/frontend→ Step 4
4layer relations→ Step 5
5Use --query CLI→ Step 6
6Read file directlyLast resort

File Structure

LinesContent
1-6Headers (ALL lookup data)
7-12Layer entities (KNOWLEDGE_GRAPH, HOT_CACHE, ...)
13-93Layer relations (caches → entity, indexes → file)
94+Code entities (sorted by weight)
300+Code relations (imports, calls)

Commands

TaskCommand
Load knowledgehead -100 project_knowledge.json
Query entitypython .github/scripts/knowledge.py --query "name"
Update knowledgepython .github/scripts/knowledge.py --update
Suggest updatespython .github/scripts/knowledge.py --suggest

Stats (v4.2)

  • First 100 lines: ~15KB (fits in context)
  • Contains: 100% of lookup data
  • File reads saved: 76.8%
  • Queries saved: 90%+ (vs multiple --query calls)