teamai-cli 0.25.0 → 0.26.0-beta.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/CHANGELOG.md +6 -0
- package/README.zh-CN.md +6 -0
- package/dist/index.js +5377 -2786
- package/package.json +4 -1
- package/skill-data/core/SKILL.md +114 -0
- package/skill-data/core/references/commands.md +339 -0
- package/{skills/teamai → skill-data/core}/references/contribute-member.md +13 -10
- package/{skills/teamai → skill-data/core}/references/troubleshooting.md +1 -1
- package/skill-data/setup/SKILL.md +76 -0
- package/{skills/teamai → skill-data/setup}/references/join-member.md +17 -14
- package/{skills/teamai → skill-data/setup}/references/manage-admin.md +8 -6
- package/{skills/teamai → skill-data/setup}/references/provider-tgit.md +9 -6
- package/{skills/teamai → skill-data/setup}/references/setup-admin.md +41 -35
- package/skill-data/share/SKILL.md +70 -0
- package/skill-data/share/references/doc-template.md +44 -0
- package/skill-data/wiki/SKILL.md +314 -0
- package/skill-data/wiki/references/agents/graph-rag-agent.md +344 -0
- package/skill-data/wiki/references/agents/kb-doc-generator.md +323 -0
- package/skill-data/wiki/references/methodology/phase0-collection.md +54 -0
- package/skill-data/wiki/references/methodology/phase1-reverse-engineering.md +89 -0
- package/skill-data/wiki/references/methodology/phase2-document-types.md +341 -0
- package/skill-data/wiki/references/methodology/phase3-ai-enhancement.md +164 -0
- package/skill-data/wiki/references/methodology/phase4-quality.md +232 -0
- package/skill-data/wiki/references/overview.md +124 -0
- package/skill-data/wiki/references/phases/k1-reverse-engineering.md +118 -0
- package/skill-data/wiki/references/phases/k2-documents.md +68 -0
- package/skill-data/wiki/references/phases/k3-ai-native.md +121 -0
- package/skill-data/wiki/references/phases/k4-quality.md +190 -0
- package/skill-data/wiki/references/phases/phase0-init.md +112 -0
- package/skill-data/wiki/references/templates/project-overview.md +148 -0
- package/{skills/team-wiki-codebase → skill-data/wiki}/scripts/scan_repo.py +52 -52
- package/{skills/team-wiki-codebase → skill-data/wiki}/scripts/validate_kb.py +68 -62
- package/skills/teamai/SKILL.md +28 -128
- package/skills/team-wiki-codebase/README.md +0 -121
- package/skills/team-wiki-codebase/SKILL.md +0 -905
- package/skills/team-wiki-codebase/references/agents/graph-rag-agent.md +0 -344
- package/skills/team-wiki-codebase/references/agents/kb-doc-generator.md +0 -323
- package/skills/team-wiki-codebase/references/methodology/phase0-collection.md +0 -54
- package/skills/team-wiki-codebase/references/methodology/phase1-reverse-engineering.md +0 -89
- package/skills/team-wiki-codebase/references/methodology/phase2-document-types.md +0 -341
- package/skills/team-wiki-codebase/references/methodology/phase3-ai-enhancement.md +0 -164
- package/skills/team-wiki-codebase/references/methodology/phase4-quality.md +0 -232
- package/skills/team-wiki-codebase/references/templates/project-overview.md +0 -148
- package/skills/teamai-share-learnings/SKILL.md +0 -87
- /package/{skills/teamai → skill-data/setup}/references/uninstall.md +0 -0
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
# Knowledge Base Document Generator Agent
|
|
2
|
+
|
|
3
|
+
## Responsibility
|
|
4
|
+
|
|
5
|
+
Generate knowledge base documents for the assigned batch of components/document types, strictly following the nine document type specifications, ensuring code traceability, complete AI Quick Reference tables, and a web of bidirectional links.
|
|
6
|
+
|
|
7
|
+
**This agent is started batch by batch by the main agent in Phase K2 and supports the parallel sub-agent dispatch mode.**
|
|
8
|
+
|
|
9
|
+
## Input package
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
component_list: list of component names or document types to generate in this batch
|
|
13
|
+
e.g. ["Aurora", "Frame", "CCDB", "Dispatcher"] or ["Type-1", "Type-2", "Type-3"]
|
|
14
|
+
architecture_map: full content of _review/k1-architecture-map.md
|
|
15
|
+
repos: repository list ([{name, path, language}]), replaces the old project_root
|
|
16
|
+
service_map: service name -> repository map (used to trace call chains across repositories)
|
|
17
|
+
output_dir: knowledge base output root directory
|
|
18
|
+
project_name: project name (used for document naming, e.g. "CVM")
|
|
19
|
+
product_docs_dir: product documentation directory (may be empty; if empty, skip product constraint extraction)
|
|
20
|
+
methodology_dir: {SKILL_DIR}/references/methodology/ directory path
|
|
21
|
+
completed_docs: list of already completed documents (skipped when resuming from checkpoint)
|
|
22
|
+
parallel_mode: true | false (default true; Type-4 component documents in parallel, Type-1~3/5~8 serially)
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Execution steps
|
|
26
|
+
|
|
27
|
+
### Step 0: Load the methodology
|
|
28
|
+
|
|
29
|
+
Read `{methodology_dir}/phase2-document-types.md` and load the templates and generation rules for the relevant document types.
|
|
30
|
+
|
|
31
|
+
### Step 1: Checkpoint check
|
|
32
|
+
|
|
33
|
+
Check the `completed_docs` list, remove completed items from `component_list`, and obtain `pending_list`.
|
|
34
|
+
|
|
35
|
+
If `pending_list` is empty, return an "all completed" summary immediately and perform no other action.
|
|
36
|
+
|
|
37
|
+
### Step 2: Dispatch strategy decision
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
IF component_list consists only of Type-4 component documents AND parallel_mode = true:
|
|
41
|
+
→ parallel mode (Step 2A)
|
|
42
|
+
ELSE (Type-1/2/3/5/6/7/8 or parallel_mode = false):
|
|
43
|
+
→ serial mode (Step 2B)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Step 2A: Parallel mode (Type-4 component documents)
|
|
47
|
+
|
|
48
|
+
**MANDATORY: you must use the Agent tool; processing components one by one in sequence is forbidden.**
|
|
49
|
+
|
|
50
|
+
**Step 2A-1: Chunking**
|
|
51
|
+
|
|
52
|
+
Split `pending_list` into chunks of **3~5 components** each (component documents are large; do not exceed 5 to avoid context overflow).
|
|
53
|
+
- Prefer placing components from the same architecture layer in the same chunk (reduces cross-layer code reading contention)
|
|
54
|
+
- Skip completed ones (resume from checkpoint)
|
|
55
|
+
|
|
56
|
+
**Step 2A-2: Start all sub-agents concurrently in a single message**
|
|
57
|
+
|
|
58
|
+
**Issue all Agent tool calls in the same reply**. This is the only way to run in parallel; issuing them in separate calls degrades to serial execution.
|
|
59
|
+
|
|
60
|
+
Example (3 chunks concurrently):
|
|
61
|
+
```
|
|
62
|
+
[Agent tool call 1: chunk ["Aurora", "Frame"], subagent_type="general-purpose"]
|
|
63
|
+
[Agent tool call 2: chunk ["CCDB", "VSResource"], subagent_type="general-purpose"]
|
|
64
|
+
[Agent tool call 3: chunk ["Dispatcher", "Compute"], subagent_type="general-purpose"]
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Each sub-agent receives the following prompt (replace CHUNK_COMPONENTS, CHUNK_NUM, TOTAL_CHUNKS):
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
You are the component document generation sub-agent of the wiki skill.
|
|
71
|
+
Generate knowledge base documents for the following components (chunk CHUNK_NUM / TOTAL_CHUNKS):
|
|
72
|
+
CHUNK_COMPONENTS
|
|
73
|
+
|
|
74
|
+
Architecture reference (condensed; only the components in this chunk and their direct upstream/downstream):
|
|
75
|
+
RELEVANT_COMPONENTS_TABLE
|
|
76
|
+
(format: | Component | Architecture layer | Repository | Language | Upstream | Downstream | Entry file |)
|
|
77
|
+
|
|
78
|
+
Service map (for cross-repository tracing):
|
|
79
|
+
SERVICE_MAP_RELEVANT_ENTRIES
|
|
80
|
+
|
|
81
|
+
Project information:
|
|
82
|
+
- repos: REPO_LIST (paths only, no details)
|
|
83
|
+
- output_dir: OUTPUT_DIR
|
|
84
|
+
- project_name: PROJECT_NAME
|
|
85
|
+
- product_docs_dir: PRODUCT_DOCS_DIR (if empty, skip product constraints)
|
|
86
|
+
|
|
87
|
+
Methodology path: METHODOLOGY_DIR/phase2-document-types.md
|
|
88
|
+
|
|
89
|
+
For each component:
|
|
90
|
+
1. Scan the code with the Glob→Grep→Read three-step method (see kb-doc-generator.md §Step 2: Code structure scanning rules)
|
|
91
|
+
2. Extract: core responsibility / architecture layer / upstream and downstream / code entry / core mechanisms / data flow / tech stack / data model / config items
|
|
92
|
+
3. Generate a document that follows the Type-4 template and Write it to OUTPUT_DIR/XX_{component}_Design.md
|
|
93
|
+
4. Self-check (see the Checklist below)
|
|
94
|
+
5. Append each completed component name to OUTPUT_DIR/../_review/_chunk_done_CHUNK_NUM.txt (one per line)
|
|
95
|
+
|
|
96
|
+
Self-check Checklist (after each document is generated):
|
|
97
|
+
- [ ] All 10 dimensions of the AI Quick Reference table filled in and specific (not generic descriptions)?
|
|
98
|
+
- [ ] "Code entry" precise to the function name (not just the file name)?
|
|
99
|
+
- [ ] search-anchor has 5~15 keywords?
|
|
100
|
+
- [ ] Contains a bidirectional link to the main architecture document?
|
|
101
|
+
- [ ] Content that cannot be traced is marked [UNVERIFIED]?
|
|
102
|
+
- [ ] No empty placeholder sections?
|
|
103
|
+
|
|
104
|
+
[UNVERIFIED] above 20% → add a ⚠️ low-confidence warning at the top of the document.
|
|
105
|
+
|
|
106
|
+
Write components that could not be generated to OUTPUT_DIR/../_review/_chunk_failed_CHUNK_NUM.txt with the reason.
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
**Step 2A-3: Wait and collect results**
|
|
110
|
+
|
|
111
|
+
After all sub-agents finish:
|
|
112
|
+
- Check the `_chunk_done_N.txt` files to confirm completion status
|
|
113
|
+
- If `_chunk_done_N.txt` is missing for a chunk, print a warning: `chunk N may not have completed; check whether the sub-agent ran as the general-purpose type`
|
|
114
|
+
- If more than half of the chunks failed, stop and tell the user to rerun
|
|
115
|
+
- Merge all completed components into `kb_progress.components_done` in `progress.json`
|
|
116
|
+
- Clean up temporary files: `rm -f _review/_chunk_done_*.txt _review/_chunk_failed_*.txt`
|
|
117
|
+
|
|
118
|
+
### Step 2B: Serial mode (Type-1~3/5~8)
|
|
119
|
+
|
|
120
|
+
For each document type in `pending_list`, execute **in sequence** (these document types depend on each other and must be serial):
|
|
121
|
+
|
|
122
|
+
#### 2B-1: Code structure scanning rules
|
|
123
|
+
|
|
124
|
+
Use the `Glob → Grep → Read` three-step method (**adapt to the language of the component's repository**):
|
|
125
|
+
|
|
126
|
+
```
|
|
127
|
+
1. Glob: find the entry files of the component's repository (choose the pattern by language)
|
|
128
|
+
Go: main.go / cmd/*/main.go
|
|
129
|
+
Python: main.py / app.py / manage.py / wsgi.py
|
|
130
|
+
Java: *Application.java / *Bootstrap.java / src/main/java/**/Main*.java
|
|
131
|
+
TypeScript: app.ts / index.ts / main.ts / server.ts
|
|
132
|
+
Rust: main.rs / src/main.rs
|
|
133
|
+
|
|
134
|
+
2. Grep: locate the core Handlers/Routers (choose the pattern by language + framework)
|
|
135
|
+
Go: grep -rn 'func.*Handler\|\.GET\|\.POST\|router\.\|@handler' <dir>
|
|
136
|
+
Python: grep -rn '@app\.\|@router\.\|def.*view\|APIRouter\|include_router' <dir>
|
|
137
|
+
Java: grep -rn '@RestController\|@Controller\|@Service\|@GetMapping\|@PostMapping\|@RequestMapping' <dir>
|
|
138
|
+
TypeScript: grep -rn 'app\.get\|app\.post\|router\.\|@Get\|@Post\|@Controller' <dir>
|
|
139
|
+
Rust: grep -rn '\.route\|\.get\|\.post\|#\[get\|#\[post\|async fn' <dir>
|
|
140
|
+
|
|
141
|
+
⚠️ Exclude test files: --exclude='*_test.*' --exclude='test_*' --exclude='*_mock.*'
|
|
142
|
+
|
|
143
|
+
3. Read: read the core files (by the directory value rating in architecture_map)
|
|
144
|
+
- ⭐⭐⭐ Must read: business logic layer, core config files, DDL
|
|
145
|
+
- ⭐⭐ Reference: service context initialisation, config files
|
|
146
|
+
- ⭐ Skippable: pure binding layers (usually just parameter pass-through)
|
|
147
|
+
- ✗ Forbidden: generated files (*.pb.go, *_gen.go, *_generated.*, node_modules/, target/, build/)
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Extract the following information (**everything must cite a code file:line, no inference**):
|
|
151
|
+
- Core responsibility (one sentence, <=30 words)
|
|
152
|
+
- Architecture layer and upstream/downstream components (communication method: RPC/MQ/DB)
|
|
153
|
+
- Code entry (file name -> core function name)
|
|
154
|
+
- Core mechanisms (the 1~2 most important technical mechanisms)
|
|
155
|
+
- Data flow (where from -> what it passes through -> where to)
|
|
156
|
+
- Tech stack (language + framework + middleware)
|
|
157
|
+
- Data model (tables involved + key DDL fields)
|
|
158
|
+
- Core flows (the steps needed for sequence diagrams)
|
|
159
|
+
- Config items (config key + default value + impact scope)
|
|
160
|
+
- Scheduled tasks (if any)
|
|
161
|
+
- Monitoring metrics (if any)
|
|
162
|
+
|
|
163
|
+
Mark content that cannot be found in the code as `[UNVERIFIED]`; do not infer.
|
|
164
|
+
|
|
165
|
+
#### 2B-2: Product documentation extraction (Type-5/6/7, or when product_docs_dir is set)
|
|
166
|
+
|
|
167
|
+
If `product_docs_dir` is not empty:
|
|
168
|
+
```
|
|
169
|
+
Scan dimensions (from phase2-document-types.md §Type-5 bridge document generation method):
|
|
170
|
+
├── Quantity limits (batch caps, quotas, maximums)
|
|
171
|
+
├── Type constraints (enum values, mutual exclusions)
|
|
172
|
+
├── State preconditions
|
|
173
|
+
├── Billing rules
|
|
174
|
+
├── Security constraints
|
|
175
|
+
└── Compatibility constraints
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Trace every product constraint to its validation location in the code (the exact file:line of the `if len() > N`).
|
|
179
|
+
|
|
180
|
+
#### 2B-3: Document generation
|
|
181
|
+
|
|
182
|
+
Generate documents following the template for the corresponding type in `phase2-document-types.md`.
|
|
183
|
+
|
|
184
|
+
**Type-4 component documents must contain (in order)**:
|
|
185
|
+
|
|
186
|
+
```markdown
|
|
187
|
+
# {component} Internal Design
|
|
188
|
+
<!-- search-anchor: {full name}, {short name}, {abbreviation}, {synonyms}, {common search terms} -->
|
|
189
|
+
> Project: {project_name} | Repository: {repo URL} | Architecture layer: {layer}
|
|
190
|
+
> Position in the overall architecture: [📘 {project_name} Technical Architecture - 4.X {component}](./{project_name} Technical Architecture.md#4x-component)
|
|
191
|
+
|
|
192
|
+
## 🤖 AI Quick Reference
|
|
193
|
+
| Dimension | Key information |
|
|
194
|
+
|------|---------|
|
|
195
|
+
| **Core responsibility** | {<=30 words, specific} |
|
|
196
|
+
| **Architecture layer** | {layer name} → {role} |
|
|
197
|
+
| **Upstream components** | {ComponentA(RPC)}, {ComponentB(MQ)} |
|
|
198
|
+
| **Downstream components** | {ComponentC(RPC)}, {ComponentD(DB)} |
|
|
199
|
+
| **Code entry** | `{file name}` → `{core function name}()` |
|
|
200
|
+
| **Core mechanisms** | {mechanism 1}; {mechanism 2} |
|
|
201
|
+
| **Mutual exclusion** | {concurrency control method, e.g. "distributed lock key: xx"} |
|
|
202
|
+
| **Data flow** | {source} → {processing} → {destination} |
|
|
203
|
+
| **Tech stack** | {language} + {framework} + {middleware} |
|
|
204
|
+
| **Scheduled tasks** | {N scheduled tasks, or "none"} |
|
|
205
|
+
|
|
206
|
+
## 📋 Project Overview
|
|
207
|
+
(numbered list of core responsibilities + ASCII architecture position diagram)
|
|
208
|
+
|
|
209
|
+
## 🏗️ Architecture Design
|
|
210
|
+
(ASCII architecture diagram + core sub-module descriptions + core function signatures)
|
|
211
|
+
|
|
212
|
+
## 📊 Data Model
|
|
213
|
+
(SQL DDL with comments + data flow diagram)
|
|
214
|
+
|
|
215
|
+
## 🔌 Interface Design
|
|
216
|
+
(external/internal interface tables + error code definitions)
|
|
217
|
+
|
|
218
|
+
## ⚙️ Core Flows
|
|
219
|
+
(mermaid sequence diagrams + step descriptions + exception handling)
|
|
220
|
+
|
|
221
|
+
## 🔧 Configuration
|
|
222
|
+
(config item / default value / description / impact scope)
|
|
223
|
+
|
|
224
|
+
## 📈 Monitoring and Alerting
|
|
225
|
+
|
|
226
|
+
## 🐛 Common Issues and Troubleshooting
|
|
227
|
+
|
|
228
|
+
## 📝 Document Change Log
|
|
229
|
+
### v1.0 ({date})
|
|
230
|
+
- ✅ **Added**: initial version
|
|
231
|
+
> Code baseline: {commit_sha} ({tag})
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
**Write all documents under `output_dir`; printing the full content in the conversation before writing the file is forbidden.**
|
|
235
|
+
|
|
236
|
+
### Step 3: Self-check (accuracy verification + interface reconciliation)
|
|
237
|
+
|
|
238
|
+
Run after each document is generated; **must not be skipped**:
|
|
239
|
+
|
|
240
|
+
**Structural completeness**:
|
|
241
|
+
- [ ] All 10 dimensions of the AI Quick Reference table filled in, each with specific information (not "see below")?
|
|
242
|
+
- [ ] "Code entry" precise to the function name (`file name:line → function()`)?
|
|
243
|
+
- [ ] search-anchor has 5~15 keywords, including full and short names and synonyms?
|
|
244
|
+
- [ ] Contains a bidirectional link to the main architecture document?
|
|
245
|
+
- [ ] No empty placeholder sections (delete sections with no content)?
|
|
246
|
+
|
|
247
|
+
**Interface reconciliation** (only for components whose interface verification type in architecture_map is not NONE):
|
|
248
|
+
|
|
249
|
+
Read the component's scanned baseline count `scanned` from `_review/interface-inventory.json` and count the interfaces actually recorded in the document as `documented`:
|
|
250
|
+
|
|
251
|
+
```
|
|
252
|
+
HTTP type: count the routes listed in the document's ## Interface Design section
|
|
253
|
+
MQ type: count the Topics/Queues/Exchanges explicitly recorded in the document
|
|
254
|
+
RPC type: count the RPC Methods listed in the document
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
Compute the difference: `gap = scanned - documented`
|
|
258
|
+
|
|
259
|
+
Handling rules:
|
|
260
|
+
- `gap = 0` → ✅ interface coverage complete
|
|
261
|
+
- `0 < gap <= 20%` → ⚠️ minor gap, append `<!-- INTERFACE_GAP: N interfaces possibly missing -->` at the end of the document
|
|
262
|
+
- `gap > 20%` → ❌ mark `[INTERFACE_GAP]`, note it in the summary, recommend supplementing and rerunning
|
|
263
|
+
|
|
264
|
+
Update the component's `interface_coverage.documented` field in `progress.json`.
|
|
265
|
+
|
|
266
|
+
**Accuracy statistics** (computed per document and returned to the main agent for aggregation):
|
|
267
|
+
```
|
|
268
|
+
Method:
|
|
269
|
+
total_claims = business rule count + core flow step count + interface description count + config item count
|
|
270
|
+
verified = those with a file:line reference
|
|
271
|
+
unverified = those marked [UNVERIFIED]
|
|
272
|
+
ratio = unverified / total_claims
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
Handling rules:
|
|
276
|
+
- `ratio > 20%` → add `⚠️ Low-confidence warning: {unverified}/{total_claims} items cannot be traced to code` at the top of the document
|
|
277
|
+
- `ratio > 40%` → mark **[HIGH_UNVERIFIED]** in the summary and recommend focused manual confirmation
|
|
278
|
+
|
|
279
|
+
### Step 4: Return summary
|
|
280
|
+
|
|
281
|
+
Return to the main agent (the main agent accumulates the data into `accuracy_stats` and `interface_coverage` in progress.json):
|
|
282
|
+
|
|
283
|
+
```
|
|
284
|
+
Batch completion summary:
|
|
285
|
+
Files read: {N} (estimated token usage: ~{N}k)
|
|
286
|
+
Documents generated: {N}
|
|
287
|
+
|
|
288
|
+
Accuracy statistics:
|
|
289
|
+
Total claims: {N} | Verified: {N} | [UNVERIFIED]: {N} ({X}%)
|
|
290
|
+
|
|
291
|
+
Interface reconciliation (components with interfaces only):
|
|
292
|
+
ComponentA [HTTP]: documented {M} / baseline {N} = {X}% ✅/⚠️/❌
|
|
293
|
+
ComponentB [MQ]: documented {M} / baseline {N} = {X}% ✅/⚠️/❌
|
|
294
|
+
|
|
295
|
+
Per-document details:
|
|
296
|
+
- {component}_Design.md: {N}KB, {N} claims, [UNVERIFIED] {N} ({X}%) [HIGH_UNVERIFIED/INTERFACE_GAP if applicable]
|
|
297
|
+
|
|
298
|
+
Skipped (already completed): {N}
|
|
299
|
+
Issues found: {issue description or "none"}
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
## Output
|
|
303
|
+
|
|
304
|
+
```
|
|
305
|
+
<output_dir>/XX_{component}_Design.md ← Type-4 component document
|
|
306
|
+
<output_dir>/{project_name} Technical Architecture.md ← Type-1 (if included in this batch)
|
|
307
|
+
<output_dir>/{project_name} Business Architecture.md ← Type-2
|
|
308
|
+
<output_dir>/{project_name} Deployment Architecture.md ← Type-3
|
|
309
|
+
<output_dir>/XX_{project_name}_Core_API_Product_Code_Mapping.md ← Type-5
|
|
310
|
+
<output_dir>/XX_{project_name}_Product_Rules_Cheat_Sheet.md ← Type-6
|
|
311
|
+
<output_dir>/XX_{project_name}_Business_Development_SOP.md ← Type-7
|
|
312
|
+
<output_dir>/{knowledge_enhancement_doc}.md ← Type-8
|
|
313
|
+
Returned summary string
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
## Constraints
|
|
317
|
+
|
|
318
|
+
- **Code is the truth**: every description must cite a code file; unverifiable content must be marked `[UNVERIFIED]`
|
|
319
|
+
- **Templates are mandatory**: read the template for the corresponding section before generating each file type
|
|
320
|
+
- **No empty documents**: do not create a file without substantive content
|
|
321
|
+
- **No redundant output**: Write files directly; do not print the full content in the conversation
|
|
322
|
+
- **Naming convention**: component documents use `XX_{component}_Design.md`; XX is assigned in dependency-chain order (lower-layer components get smaller numbers)
|
|
323
|
+
- **When no API is provided**: Type-5/6 may skip the product constraint mapping and mark constraint values as `[PRODUCT_DOC_MISSING]`
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Phase 0: Source Material Collection and Preprocessing
|
|
2
|
+
|
|
3
|
+
## Repository Discovery and Classification
|
|
4
|
+
|
|
5
|
+
Starting from the entry repository, recursively discover all related repositories:
|
|
6
|
+
|
|
7
|
+
1. **Dependency analysis**: parse project dependency files (such as `requirements.txt`, `package.json`, `pom.xml`, `Cargo.toml`, `go.mod`, chosen by the detected language)
|
|
8
|
+
2. **Configuration references**: parse module names referenced in workflow orchestration configs → repository mapping
|
|
9
|
+
3. **RPC service discovery**: extract service names from service registry configs → repository mapping
|
|
10
|
+
4. **Classify by architecture layer**: API access layer / workflow engine layer / service execution layer / resource scheduling layer / data adapter layer / base execution layer
|
|
11
|
+
5. **Mark core-ness**: compute priority from lines of code, number of dependents, and Handler count
|
|
12
|
+
|
|
13
|
+
## Key File Extraction Checklist
|
|
14
|
+
|
|
15
|
+
| File type | Match pattern | Extraction purpose |
|
|
16
|
+
|---------|---------|---------|
|
|
17
|
+
| **Entry files** | `main.py`, `main.go`, `cmd/*/main.go`, `app.ts` | Service startup and initialization flow |
|
|
18
|
+
| **Routes/Handlers** | `handler.*`, `router.*`, `controller.*` | API endpoints and message handling entry points |
|
|
19
|
+
| **Config files** | `*config*.*`, `conf/`, `*.yaml`, `*.toml` | Workflow orchestration, parameter configuration |
|
|
20
|
+
| **Proto/IDL** | `*.proto`, `*.thrift`, `*schema*` | RPC interface contracts and data structures |
|
|
21
|
+
| **Database operations** | `*db*.*`, `*dao*.*`, `*model*.*`, `*repository*.*` | Data models and table schemas |
|
|
22
|
+
| **Constants/error codes** | `*const*`, `*error*`, `*code*`, `*enum*` | Error code system and business constants |
|
|
23
|
+
| **Test files** | `*_test.*`, `test_*.*` | Expected behavior and edge conditions |
|
|
24
|
+
|
|
25
|
+
## Building the Code Knowledge Graph
|
|
26
|
+
|
|
27
|
+
Before generating documents, build a code knowledge graph as an intermediate representation:
|
|
28
|
+
|
|
29
|
+
**Node types**: `[Service]` / `[Handler]` / `[Config]` / `[Table]` / `[Queue]` / `[API]` / `[ErrorCode]`
|
|
30
|
+
|
|
31
|
+
**Edge types**: `[CALLS]` (synchronous RPC/HTTP) / `[PUBLISHES]` (asynchronous MQ) / `[CONSUMES]` (MQ consumption) / `[READS]` (DB read) / `[WRITES]` (DB write) / `[CONFIGURES]` (config-driven) / `[MAPS_TO]` (product → code)
|
|
32
|
+
|
|
33
|
+
**Construction methods** (ordered by availability):
|
|
34
|
+
1. **`teamai codebase --extract`**: Tree-sitter structural edges (**TS/JS/Python/Go** and more) + multi-language heuristic fact pages (writes `teamwiki/`)
|
|
35
|
+
2. Grep + Read (Agent K1/K2): supplement dynamic routes and config-driven calls
|
|
36
|
+
3. Parse orchestration configs → module → command mapping
|
|
37
|
+
4. Parse Proto/IDL/DDL → data structures and table relationships (structured files, can be parsed precisely)
|
|
38
|
+
5. MQ topology inference → Exchange/Topic/Queue/Routing Key
|
|
39
|
+
6. API mapping → external API name → internal Handler entry point
|
|
40
|
+
|
|
41
|
+
> `code-ast` can produce `DEPENDS_ON` edges for relative imports; package-level and dynamic calls may still be missed, mark them `[UNVERIFIED]` or `AMBIGUOUS`.
|
|
42
|
+
> AST results take precedence over heuristics. There is no separate capabilities doc in this package; use `teamai codebase --extract` output under `teamwiki/`.
|
|
43
|
+
|
|
44
|
+
## Input Source Priority
|
|
45
|
+
|
|
46
|
+
| Priority | Input source | Specific content | Output document types |
|
|
47
|
+
|--------|--------|---------|------------|
|
|
48
|
+
| **P0 required** | Code repositories | Directory structure, entry files, configs, Proto | Type-1,4 |
|
|
49
|
+
| **P0 required** | Workflow orchestration configs | workflow_config / state machines | Type-1,4,5 |
|
|
50
|
+
| **P0 required** | Product API docs | Interface parameters, error codes | Type-5,6 |
|
|
51
|
+
| **P1 important** | Database schema | DDL, table schemas | Type-4 |
|
|
52
|
+
| **P1 important** | Product usage docs | Usage limits, FAQ | Type-6,8a |
|
|
53
|
+
| **P2 enhancement** | Git history | Commit/MR records | Type-8b |
|
|
54
|
+
| **P2 enhancement** | Incident records | Incident reports | Type-8d |
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# Phase 1: Architecture Reverse-Engineering, From Code to Architectural Understanding
|
|
2
|
+
|
|
3
|
+
## 1. Bottom-Up Layering Method
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
Step 1: Identify "leaf nodes" that operate directly on infrastructure
|
|
7
|
+
├── Database operations (MySQL/PostgreSQL/Redis/MongoDB)
|
|
8
|
+
├── Message queue operations (RabbitMQ/Kafka/RocketMQ)
|
|
9
|
+
├── External system calls (third-party APIs / low-level drivers)
|
|
10
|
+
└── File/object storage operations (S3/OSS/COS)
|
|
11
|
+
|
|
12
|
+
Step 2: Identify "intermediate nodes" that orchestrate and route
|
|
13
|
+
├── Message routing frameworks (consumer routing and dispatch)
|
|
14
|
+
├── Task schedulers (cron jobs / delayed tasks)
|
|
15
|
+
├── Workflow orchestration engines (Workflow/Saga/state machines)
|
|
16
|
+
└── Resource schedulers (load balancing / resource allocation)
|
|
17
|
+
|
|
18
|
+
Step 3: Identify "root nodes", the external entry points
|
|
19
|
+
├── API gateway / HTTP Handler / gRPC Server
|
|
20
|
+
├── Scheduled task entry points (Cron/Scheduler)
|
|
21
|
+
└── Event listener entry points (Webhook/EventBus)
|
|
22
|
+
|
|
23
|
+
Step 4: Layer by call direction
|
|
24
|
+
External entry → workflow orchestration → service execution → resource scheduling → data operations → infrastructure
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Layer Assignment Rules
|
|
28
|
+
|
|
29
|
+
| Distinguishing feature | Layer | Typical code pattern |
|
|
30
|
+
|---------|---------|-------------|
|
|
31
|
+
| HTTP/gRPC Server startup | API access layer | `http.ListenAndServe()`, `grpc.NewServer()` |
|
|
32
|
+
| Parameter validation + auth + rate limiting | API access layer | `validate()`, `auth()`, `rateLimit()` |
|
|
33
|
+
| Workflow step configs and state machines | Workflow engine layer | `workflow_config`, `state_machine` |
|
|
34
|
+
| MQ consumption + Handler routing | Service execution layer | `channel.consume()`, `handler.dispatch()` |
|
|
35
|
+
| Scheduling algorithms (Filter/Score) | Resource scheduling layer | `filter()`, `score()`, `schedule()` |
|
|
36
|
+
| DB CRUD + cache operations | Data adapter layer | `db.query()`, `redis.get()` |
|
|
37
|
+
| Low-level system calls/drivers | Base execution layer | `exec()`, `syscall.*`, `driver.*` |
|
|
38
|
+
|
|
39
|
+
## 2. Three-Layer Penetration Tracing (Core Methodology)
|
|
40
|
+
|
|
41
|
+
For every user-visible API operation, complete a three-layer penetration trace:
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
Layer 1: API entry layer
|
|
45
|
+
├── Locate the Handler function
|
|
46
|
+
├── Extract parameter validation logic
|
|
47
|
+
├── Identify hard-coded defaults and whitelists
|
|
48
|
+
└── Determine the downstream call style (synchronous RPC / asynchronous MQ)
|
|
49
|
+
|
|
50
|
+
Layer 2: Workflow orchestration layer
|
|
51
|
+
├── Find the workflow config (workflow_config / saga_config)
|
|
52
|
+
├── Parse the step sequence (step name / execution module / rollback module / timeout / retry)
|
|
53
|
+
├── Annotate the execution module and rollback module of each step
|
|
54
|
+
└── Determine how data is passed between steps
|
|
55
|
+
|
|
56
|
+
Layer 3: Service execution layer
|
|
57
|
+
├── Trace the concrete Handler implementation of each step
|
|
58
|
+
├── Identify database operations and state changes
|
|
59
|
+
├── Annotate external system calls
|
|
60
|
+
└── Determine the callback path of the final execution result
|
|
61
|
+
|
|
62
|
+
Output: complete call chain sequence diagram + state transition diagram + data flow diagram
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Standard Format for Documenting Call Chains
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
[API name](code entry: {repo}/{path}/{file})
|
|
69
|
+
→ parameter validation + auth and rate limiting
|
|
70
|
+
→ [pre-checks]: {check content}
|
|
71
|
+
→ RPC/MQ → [orchestration layer] ({config file}: {operation name})
|
|
72
|
+
→ [service layer] ({config file}: {flow_name})
|
|
73
|
+
→ [{step 1 module}] {step 1 command} ({details})
|
|
74
|
+
→ [{step 2 module}] {step 2 command} ({details})
|
|
75
|
+
→ ...
|
|
76
|
+
→ callback to [orchestration layer]
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## 3. Component Relationship Matrix
|
|
80
|
+
|
|
81
|
+
Build an N×N relationship matrix annotated with the communication style:
|
|
82
|
+
|
|
83
|
+
| Caller ↓ / Callee → | ComponentA | ComponentB | ComponentC |
|
|
84
|
+
|---------------------|-------|-------|-------|
|
|
85
|
+
| **ComponentA** | — | RPC | MQ |
|
|
86
|
+
| **ComponentB** | — | — | DB |
|
|
87
|
+
| **ComponentC** | RPC | MQ | — |
|
|
88
|
+
|
|
89
|
+
Legend: `RPC` (synchronous) / `MQ` (asynchronous) / `DB` (shared database) / `—` (no direct communication)
|