docs: add AGENTS.md documentation files
Add comprehensive AGENTS.md documentation files across the project structure to document the agent architecture and capabilities. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
95
VBA/AGENTS.md
Normal file
95
VBA/AGENTS.md
Normal file
@@ -0,0 +1,95 @@
|
||||
# VBA Module Knowledge Base
|
||||
|
||||
**Scope:** `VBA/` directory - Core automation logic
|
||||
|
||||
## OVERVIEW
|
||||
|
||||
VBA modules for BOM extraction: ClassModules (domain logic), Modules (workflows), DocumentModules (sheet events).
|
||||
|
||||
## STRUCTURE
|
||||
|
||||
```
|
||||
VBA/
|
||||
├── ClassModules/ # 4 classes: BomExtractor, BomItem, ProductModelParser, ConditionEvaluator
|
||||
├── Modules/ # 4 modules: MainModule, BIPUploadModule, ComponentInventoryCheckModule, TestModule
|
||||
├── DocumentModules/ # Sheet9.cls (event handlers)
|
||||
└── vba_metadata.json # Module metadata
|
||||
```
|
||||
|
||||
## WHERE TO LOOK
|
||||
|
||||
| Task | Location | Notes |
|
||||
|------|----------|-------|
|
||||
| Main entry point | `Modules/MainModule.bas` | `ProcessProductModels()` |
|
||||
| BOM extraction | `ClassModules/BomExtractor.cls` | `ExtractBom()` with assembly logic |
|
||||
| Model parsing | `ClassModules/ProductModelParser.cls` | `Parse()` extracts 6 conditions |
|
||||
| Condition logic | `ClassModules/ConditionEvaluator.cls` | Expression evaluation |
|
||||
| BIP upload | `Modules/BIPUploadModule.bas` | Upload to BIP system |
|
||||
| Inventory check | `Modules/ComponentInventoryCheckModule.bas` | Component verification |
|
||||
|
||||
## CODE MAP
|
||||
|
||||
| Symbol | Type | Location | Role |
|
||||
|--------|------|----------|------|
|
||||
| `ProcessProductModels()` | Sub | `MainModule.bas` | Main entry point |
|
||||
| `ExtractBom()` | Function | `BomExtractor.cls` | Core matching logic |
|
||||
| `Parse()` | Function | `ProductModelParser.cls` | Model string parser |
|
||||
| `Evaluate()` | Function | `ConditionEvaluator.cls` | Condition evaluator |
|
||||
| `LoadFromRow()` | Sub | `BomItem.cls` | Row data loader |
|
||||
|
||||
## CONVENTIONS
|
||||
|
||||
### Module Organization
|
||||
- **ClassModules**: `*.cls` files with `Option Explicit`, public methods, private state
|
||||
- **Modules**: `*.bas` files with public subs, helper functions
|
||||
- **DocumentModules**: Sheet-specific event handlers (e.g., `Sheet9.cls`)
|
||||
|
||||
### Error Handling Pattern
|
||||
```vba
|
||||
On Error GoTo ErrorHandler
|
||||
' ... logic ...
|
||||
Exit Sub
|
||||
ErrorHandler:
|
||||
' Handle error
|
||||
```
|
||||
|
||||
### Data Loading
|
||||
- `BomExtractor.LoadBomData()` starts at row 4 (row 3 is header)
|
||||
- `BomItem.LoadFromRow()` uses `On Error Resume Next` for type conversions
|
||||
|
||||
## ANTI-PATTERNS (THIS PROJECT)
|
||||
|
||||
- **NEVER** change row indexing in `LoadBomData()` — hardcoded to start at row 4
|
||||
- **NEVER** reorder `BomItem` fields — column mapping is hardcoded (11 fields)
|
||||
- **NEVER** remove `On Error Resume Next` in `LoadFromRow()` — handles type conversion
|
||||
- **NEVER** bypass `ApplyAssemblyLogic()` — parent/child override is critical
|
||||
- **NEVER** hardcode workbook names — always use `ThisWorkbook`
|
||||
|
||||
## UNIQUE STYLES
|
||||
|
||||
### Assembly Logic (总成逻辑)
|
||||
Parent category overrides children if:
|
||||
1. Parent matches exactly 1 item
|
||||
2. All children match at least 1 item
|
||||
3. Result: parent output, children hidden
|
||||
|
||||
### Batch Output Pattern
|
||||
```vba
|
||||
' Collect in Collection
|
||||
' Convert to 2D array
|
||||
' Single Range.Value write
|
||||
```
|
||||
|
||||
### Condition Syntax
|
||||
- Format: `"field=value|field2=value2"` (pipe = OR)
|
||||
- Example: `"azxs=M|azxs=L"` (vertical OR horizontal installation)
|
||||
|
||||
## NOTES
|
||||
|
||||
### Scripting.Dictionary Dependency
|
||||
All classes use `CreateObject("Scripting.Dictionary")` - Windows only, not Mac-compatible.
|
||||
|
||||
### Workbook Sheets Required
|
||||
- `产品订单` - Input orders
|
||||
- `平台配置清单` - BOM configuration (starts at row 4)
|
||||
- `BOM 提取结果` - Auto-created output
|
||||
148
VBA/ClassModules/AGENTS.md
Normal file
148
VBA/ClassModules/AGENTS.md
Normal file
@@ -0,0 +1,148 @@
|
||||
# ClassModules Knowledge Base
|
||||
|
||||
**Scope:** `VBA/ClassModules/` - Domain logic classes
|
||||
|
||||
## OVERVIEW
|
||||
|
||||
4 classes: `ProductModelParser` (parse model strings), `BomItem` (data model), `ConditionEvaluator` (evaluate conditions), `BomExtractor` (core matching logic).
|
||||
|
||||
## STRUCTURE
|
||||
|
||||
```
|
||||
ClassModules/
|
||||
├── ProductModelParser.cls # Parse model strings → extract 6 conditions
|
||||
├── BomItem.cls # BOM data model (11 fields)
|
||||
├── ConditionEvaluator.cls # Evaluate condition expressions
|
||||
└── BomExtractor.cls # Core matching + assembly logic
|
||||
```
|
||||
|
||||
## WHERE TO LOOK
|
||||
|
||||
| Task | Location | Notes |
|
||||
|------|----------|-------|
|
||||
| Parse model string | `ProductModelParser.cls` | `Parse()` method |
|
||||
| Extract conditions | `ProductModelParser.cls` | Returns `azxs`, `bkxs`, `gclj`, `jycz`, `lcfw`, `fjgn` |
|
||||
| Load BOM row | `BomItem.cls` | `LoadFromRow()` with type conversion |
|
||||
| Evaluate condition | `ConditionEvaluator.cls` | `Evaluate(condition, conditions)` |
|
||||
| Match BOM items | `BomExtractor.cls` | `ExtractBom()` with 4-step process |
|
||||
| Assembly logic | `BomExtractor.cls` | `ApplyAssemblyLogic()` parent/child override |
|
||||
|
||||
## CODE MAP
|
||||
|
||||
### ProductModelParser
|
||||
| Method | Role |
|
||||
|--------|------|
|
||||
| `Parse(modelString)` | Entry point, validates format |
|
||||
| `ParseHeader()` | Splits model string by `-` and `.` |
|
||||
| `ExtractConnectionAndMaterial()` | Separates `gclj` and `jycz` from code |
|
||||
| `ExtractAdditionalFeatures()` | Removes oil-fill type (Y+digit) from `fjgn` |
|
||||
|
||||
### BomItem
|
||||
| Property | Type | Column |
|
||||
|----------|------|--------|
|
||||
| `RowNumber` | Long | A |
|
||||
| `Module` | String | B |
|
||||
| `code` | String | C |
|
||||
| `Name` | String | D |
|
||||
| `quantity` | Double | E |
|
||||
| `SelectCondition` | String | F |
|
||||
| `Remark` | String | G |
|
||||
| `category` | String | H |
|
||||
| `ParentCategory` | String | I |
|
||||
| `CategoryCondition` | String | J |
|
||||
| `Code66` | String | K |
|
||||
|
||||
### BomExtractor
|
||||
| Method | Role |
|
||||
|--------|------|
|
||||
| `LoadBomData()` | Loads from row 4 (header row 3) |
|
||||
| `ExtractBom(conditions)` | 4-step: determine categories → match → apply assembly → validate |
|
||||
| `ApplyAssemblyLogic()` | Parent overrides children if all match |
|
||||
| `ValidateResult()` |双向覆盖检查 (parent/child coverage) |
|
||||
|
||||
## CONVENTIONS
|
||||
|
||||
### Class Structure
|
||||
```vba
|
||||
Option Explicit
|
||||
|
||||
' Private state
|
||||
Private pPropertyName As Type
|
||||
|
||||
' Initialize
|
||||
Private Sub Class_Initialize()
|
||||
Set pProperty = New Collection
|
||||
End Sub
|
||||
|
||||
' Public methods
|
||||
Public Function MethodName() As ReturnType
|
||||
On Error GoTo ErrorHandler
|
||||
' Logic
|
||||
Exit Function
|
||||
ErrorHandler:
|
||||
' Handle
|
||||
End Function
|
||||
```
|
||||
|
||||
### Condition Dictionary
|
||||
All condition methods accept `Scripting.Dictionary` with keys: `azxs`, `bkxs`, `gclj`, `jycz`, `lcfw`, `fjgn`.
|
||||
|
||||
### Error Collection Pattern
|
||||
```vba
|
||||
Private pErrorMessages As Collection
|
||||
Public Function GetErrorSummary() As String
|
||||
' Join all errors with "; "
|
||||
End Function
|
||||
```
|
||||
|
||||
## ANTI-PATTERNS (THIS PROJECT)
|
||||
|
||||
- **NEVER** change `BomItem.LoadFromRow()` column indices — hardcoded to match platform configuration sheet
|
||||
- **NEVER** remove `On Error Resume Next` in `LoadFromRow()` — type conversions fail gracefully
|
||||
- **NEVER** skip validation in `ValidateResult()` —双向覆盖检查 prevents false negatives
|
||||
- **DO NOT** modify `BomExtractor.LoadBomData()` row start — must be row 4 (row 3 is header)
|
||||
|
||||
## UNIQUE STYLES
|
||||
|
||||
### Assembly Logic Algorithm
|
||||
```vba
|
||||
' 1. Build parent→child map from CategoryHierarchy
|
||||
' 2. Count matches per category
|
||||
' 3. If parent=1 AND all children≥1 → parent covers children
|
||||
' 4. Output parent only, hide children
|
||||
```
|
||||
|
||||
### Model String Format
|
||||
```
|
||||
[Header]-[Spec1].[Spec2].[Spec3].[Spec4].[Spec5]|[Detail1]|[Detail2]
|
||||
Example: Y-100-M203.316SS.L100.N2
|
||||
|
||||
Parsed conditions:
|
||||
- azxs (安装形式): M (vertical)
|
||||
- bkxs (表壳形式): 3
|
||||
- gclj (过程连接): M20
|
||||
- jycz (接液材质): 3 (316SS)
|
||||
- lcfw (量程范围): 0.L100
|
||||
- fjgn (附加功能): N2 (from .316SS.L100.N2)
|
||||
```
|
||||
|
||||
### Condition Expression Syntax
|
||||
```vba
|
||||
' Single: "field=value"
|
||||
' OR: "field1=value1|field2=value2"
|
||||
' Example: "azxs=M|azxs=L" → vertical OR horizontal
|
||||
```
|
||||
|
||||
## NOTES
|
||||
|
||||
### Category Hierarchy
|
||||
Built from `ParentCategory` field (column I). Example:
|
||||
- "接头" → "部件"
|
||||
- "弹性元件" → "部件"
|
||||
- Result: if "部件" matches AND both children match → output "部件" only
|
||||
|
||||
### Type Conversion
|
||||
`BomItem.LoadFromRow()` uses `CLng()`, `CStr()`, `CDbl()` with `On Error Resume Next` — invalid conversions become 0 or empty string.
|
||||
|
||||
### Scripting.Dictionary
|
||||
Windows-only. All dictionary usage via `CreateObject("Scripting.Dictionary")`.
|
||||
142
VBA/Modules/AGENTS.md
Normal file
142
VBA/Modules/AGENTS.md
Normal file
@@ -0,0 +1,142 @@
|
||||
# Modules Knowledge Base
|
||||
|
||||
**Scope:** `VBA/Modules/` - Procedural workflows and entry points
|
||||
|
||||
## OVERVIEW
|
||||
|
||||
4 modules: `MainModule` (main workflow), `BIPUploadModule` (upload results), `ComponentInventoryCheckModule` (inventory check), `TestModule` (testing utilities).
|
||||
|
||||
## STRUCTURE
|
||||
|
||||
```
|
||||
Modules/
|
||||
├── MainModule.bas # Main entry point + orchestration
|
||||
├── BIPUploadModule.bas # Upload to BIP system
|
||||
├── ComponentInventoryCheckModule.bas # Component inventory verification
|
||||
└── TestModule.bas # Testing utilities
|
||||
```
|
||||
|
||||
## WHERE TO LOOK
|
||||
|
||||
| Task | Location | Notes |
|
||||
|------|----------|-------|
|
||||
| Run BOM extraction | `MainModule.bas` | `ProcessProductModels()` |
|
||||
| Upload results | `BIPUploadModule.bas` | BIP system integration |
|
||||
| Check inventory | `ComponentInventoryCheckModule.bas` | Component count verification |
|
||||
| Test parsing | `TestModule.bas` | Unit test utilities |
|
||||
|
||||
## CODE MAP
|
||||
|
||||
### MainModule
|
||||
| Function | Role |
|
||||
|----------|------|
|
||||
| `ProcessProductModels()` | Main entry point, orchestrates workflow |
|
||||
| `ProcessSingleModel()` | Process one model, collect output |
|
||||
| `CreateOutputRowArray()` | Build row data array |
|
||||
| `WriteBatchData()` | Bulk write to worksheet |
|
||||
| `GetInputSheet()` | Get `产品订单` sheet |
|
||||
| `GetBomSheet()` | Get `平台配置清单` sheet |
|
||||
| `CreateOutputSheet()` | Create/reset `BOM 提取结果` |
|
||||
|
||||
### BIPUploadModule
|
||||
| Function | Role |
|
||||
|----------|------|
|
||||
| `UploadToBIP()` | Upload BOM results to BIP system |
|
||||
|
||||
### ComponentInventoryCheckModule
|
||||
| Function | Role |
|
||||
|----------|------|
|
||||
| `CheckComponentInventory()` | Verify component counts match |
|
||||
|
||||
## CONVENTIONS
|
||||
|
||||
### Module Structure
|
||||
```vba
|
||||
Option Explicit
|
||||
|
||||
' Constants
|
||||
Private Const CONDITION_CONFIG = "azxs,安装形式|bkxs,表壳形式|..."
|
||||
|
||||
' Public entry points
|
||||
Public Sub MainEntryPoint()
|
||||
On Error GoTo ErrorHandler
|
||||
' Orchestration
|
||||
Exit Sub
|
||||
ErrorHandler:
|
||||
MsgBox "Error: " & Err.Description
|
||||
End Sub
|
||||
|
||||
' Private helpers
|
||||
Private Sub HelperFunction()
|
||||
' Implementation
|
||||
End Sub
|
||||
```
|
||||
|
||||
### Workflow Pattern
|
||||
1. Get input sheet (`产品订单`)
|
||||
2. Get BOM sheet (`平台配置清单`)
|
||||
3. Create output sheet (`BOM 提取结果`)
|
||||
4. Initialize `BomExtractor`, load data
|
||||
5. Loop through models, call `ProcessSingleModel()`
|
||||
6. Batch write results
|
||||
7. Format output, show message
|
||||
|
||||
### Batch Output Pattern
|
||||
```vba
|
||||
' Collect in Collection
|
||||
Dim outputData As Collection
|
||||
Set outputData = New Collection
|
||||
|
||||
' Add arrays
|
||||
outputData.Add CreateOutputRowArray(...)
|
||||
|
||||
' Convert to 2D array
|
||||
ReDim resultData(1 To rowCount, 1 To colCount)
|
||||
' Fill array...
|
||||
|
||||
' Single write
|
||||
ws.Range("A2").Resize(rowCount, colCount).Value = resultData
|
||||
```
|
||||
|
||||
## ANTI-PATTERNS (THIS PROJECT)
|
||||
|
||||
- **NEVER** hardcode sheet names — use `GetInputSheet()`, `GetBomSheet()` helpers
|
||||
- **NEVER** write row-by-row — always batch write via 2D array
|
||||
- **NEVER** skip error handling — all public subs use `On Error GoTo ErrorHandler`
|
||||
- **DO NOT** change output column order — must match header definition in `WriteOutputHeader()`
|
||||
|
||||
## UNIQUE STYLES
|
||||
|
||||
### Condition Config Constant
|
||||
```vba
|
||||
Private Const CONDITION_CONFIG = "azxs,安装形式|bkxs,表壳形式|gclj,过程连接|jycz,接液材质|lcfw,量程范围|fjgn,附加功能"
|
||||
```
|
||||
Format: `code,label|code,label|...` — parsed dynamically for header generation.
|
||||
|
||||
### Component Priority Flag
|
||||
From column E of input sheet:
|
||||
- "是" (or "1", "TRUE") → include all categories
|
||||
- "否" (or "0", "FALSE") → exclude "部件" (components) category
|
||||
|
||||
### Output Row Structure
|
||||
```
|
||||
Column 1: 生产订单号 (order number)
|
||||
Column 2: 产品型号 (full model)
|
||||
Columns 3-8: 6 conditions (azxs, bkxs, gclj, jycz, lcfw, fjgn)
|
||||
Columns 9-16: BOM fields (行号,模块,代号,名称,数量,类别,66 代码,备注)
|
||||
```
|
||||
|
||||
## NOTES
|
||||
|
||||
### Output Sheet Formatting
|
||||
- Row 1: Bold, gray background (RGB 217,217,217), centered
|
||||
- Data starts at row 2
|
||||
- AutoFit columns (commented out in current code)
|
||||
|
||||
### Error Messages
|
||||
- Parse failure: `"解析失败:" + error`
|
||||
- No match: `"未匹配到任何物料"`
|
||||
- Multi-match: `"类别[X] 匹配到多条物料(N 条)"` — outputs all but flags
|
||||
|
||||
### Performance
|
||||
Batch write via `Range.Value = resultData` is 10-100x faster than cell-by-cell writes for large datasets.
|
||||
Reference in New Issue
Block a user