@qmingjun/dsh-eda-mcp 0.0.0-stage → 1.1.12
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/AGENTS.md +63 -0
- package/CHANGELOG.md +792 -0
- package/CONTRIBUTING.md +154 -0
- package/LICENSE +55 -0
- package/README.md +290 -2
- package/README.zh.md +449 -0
- package/cordis.patch.yml +7 -0
- package/docs/design-rules.md +254 -0
- package/docs/dsh-version-sweep.md +73 -0
- package/docs/pitfalls.md +99 -0
- package/docs/project-status.md +100 -0
- package/docs/release.md +215 -0
- package/docs/schematic-workflow.md +297 -0
- package/docs/tools.md +184 -0
- package/jlc-extension/api-bridge.js +879 -0
- package/jlc-extension/extension.json +104 -0
- package/lib/bridge.mjs +4179 -0
- package/lib/client.js +1605 -0
- package/lib/extension-digest.json +6 -0
- package/lib/index.js +1261 -0
- package/package.json +144 -4
- package/src/bridge/design-intake.ts +133 -0
- package/src/bridge/design-rules.ts +228 -0
- package/src/bridge/eda-launch.ts +267 -0
- package/src/bridge/extension-package.ts +35 -0
- package/src/bridge/index.ts +3576 -0
- package/src/bridge/netlist-erc.ts +305 -0
- package/src/bridge/schematic-audit.ts +131 -0
- package/src/bridge/workflow-guide.ts +65 -0
- package/src/bridge-diagnostics.ts +185 -0
- package/src/client/EdaMcpSettingsCard.tsx +571 -0
- package/src/client/index.ts +40 -0
- package/src/client/locales.ts +83 -0
- package/src/client/settings-scope.ts +160 -0
- package/src/config-values.ts +60 -0
- package/src/guidance.ts +35 -0
- package/src/index.ts +365 -0
- package/src/loopback.ts +48 -0
- package/src/node-runtime.ts +120 -0
- package/src/routes.ts +377 -0
- package/src/skills-content.ts +309 -0
- package/src/skills.ts +91 -0
- package/test/config-values.test.ts +60 -0
- package/test/design-intake.test.ts +40 -0
- package/test/design-rules.test.ts +72 -0
- package/test/eda-launch.test.ts +114 -0
- package/test/extension-package.test.ts +27 -0
- package/test/extension-routes.test.ts +116 -0
- package/test/netlist-erc.test.ts +90 -0
- package/test/node-runtime.test.ts +65 -0
- package/test/schematic-audit.test.ts +71 -0
- package/test/seams.test.ts +164 -0
- package/test/skills.test.ts +68 -0
package/package.json
CHANGED
|
@@ -1,6 +1,146 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qmingjun/dsh-eda-mcp",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.1.12",
|
|
4
|
+
"description": "dsh-eda-mcp 的自家维护版:扩展升级到 0.4.11(+pcb_Layer.modifyLayer),桥接版本随之对齐",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "DSH-EDA-MCP contributors"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/MCviseron/dsh-eda-mcp.git"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/MCviseron/dsh-eda-mcp#readme",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/MCviseron/dsh-eda-mcp/issues"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"dsh",
|
|
19
|
+
"dsh-plugin",
|
|
20
|
+
"deepseek-harness",
|
|
21
|
+
"plugin",
|
|
22
|
+
"mcp",
|
|
23
|
+
"eda",
|
|
24
|
+
"jlc",
|
|
25
|
+
"jlceda",
|
|
26
|
+
"easyeda",
|
|
27
|
+
"schematic"
|
|
28
|
+
],
|
|
29
|
+
"packageManager": "pnpm@10.6.3",
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": "^22.19.0 || >=24"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public",
|
|
35
|
+
"registry": "https://registry.npmjs.org"
|
|
36
|
+
},
|
|
37
|
+
"type": "module",
|
|
38
|
+
"main": "lib/index.js",
|
|
39
|
+
"exports": {
|
|
40
|
+
".": "./lib/index.js",
|
|
41
|
+
"./client": "./lib/client.js",
|
|
42
|
+
"./bridge": "./lib/bridge.mjs",
|
|
43
|
+
"./cordis.patch.yml": "./cordis.patch.yml",
|
|
44
|
+
"./package.json": "./package.json"
|
|
45
|
+
},
|
|
46
|
+
"files": [
|
|
47
|
+
"lib",
|
|
48
|
+
"src",
|
|
49
|
+
"test",
|
|
50
|
+
"docs",
|
|
51
|
+
"jlc-extension",
|
|
52
|
+
"cordis.patch.yml",
|
|
53
|
+
"CHANGELOG.md",
|
|
54
|
+
"CONTRIBUTING.md",
|
|
55
|
+
"LICENSE",
|
|
56
|
+
"README.md",
|
|
57
|
+
"README.zh.md",
|
|
58
|
+
"AGENTS.md"
|
|
59
|
+
],
|
|
60
|
+
"dsh": {
|
|
61
|
+
"bundle": {
|
|
62
|
+
"patch": "./cordis.patch.yml"
|
|
63
|
+
},
|
|
64
|
+
"client": {
|
|
65
|
+
"inject": [
|
|
66
|
+
"@deepseek-ai/dsh-client-ui-settings",
|
|
67
|
+
"@deepseek-ai/dsh-client-locale"
|
|
68
|
+
],
|
|
69
|
+
"platform": "web"
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
"scripts": {
|
|
73
|
+
"build": "node build.mjs",
|
|
74
|
+
"typecheck": "tsc --noEmit",
|
|
75
|
+
"test": "node --experimental-strip-types test/node-runtime.test.ts && node --experimental-strip-types test/config-values.test.ts && node --experimental-strip-types test/design-rules.test.ts && node --experimental-strip-types test/seams.test.ts && node --experimental-strip-types test/eda-launch.test.ts && node --experimental-strip-types test/schematic-audit.test.ts && node --experimental-strip-types test/design-intake.test.ts && node --experimental-strip-types test/extension-package.test.ts && node --experimental-strip-types test/extension-routes.test.ts && node --experimental-strip-types test/netlist-erc.test.ts && node --experimental-strip-types test/skills.test.ts",
|
|
76
|
+
"seam-check": "node scripts/seam-check.mjs",
|
|
77
|
+
"version-sweep": "node scripts/version-sweep.mjs",
|
|
78
|
+
"contract-check": "node scripts/contract-check.mjs",
|
|
79
|
+
"guard:bundle": "node scripts/guard-bundle-paths.mjs",
|
|
80
|
+
"check": "pnpm typecheck && pnpm test && pnpm contract-check && pnpm build && pnpm guard:bundle",
|
|
81
|
+
"docs": "node scripts/gen-tools-doc.mjs && node scripts/gen-skill-doc.mjs"
|
|
82
|
+
},
|
|
83
|
+
"dependencies": {
|
|
84
|
+
"@deepseek-ai/dsh-mcp-client": "^0.2.1-rc.5 || ^0.2.2-rc.1 || ^0.2.3-alpha.1",
|
|
85
|
+
"@deepseek-ai/dsh-settings": "^0.2.1-rc.5 || ^0.2.2-rc.1 || ^0.2.3-alpha.1",
|
|
86
|
+
"@deepseek-ai/schemastery": "^3.18.4"
|
|
87
|
+
},
|
|
88
|
+
"peerDependencies": {
|
|
89
|
+
"@deepseek-ai/cordis": "^4.0.1",
|
|
90
|
+
"@deepseek-ai/dsh-client-connection": "^0.1.1-rc.2 || ^0.1.5-rc.2 || ^0.2.0-rc.2 || ^0.2.1-rc.2 || ^0.2.2-rc.1 || ^0.2.3-alpha.1",
|
|
91
|
+
"@deepseek-ai/dsh-client-locale": "^0.1.1-rc.2 || ^0.1.5-rc.2 || ^0.2.0-rc.2 || ^0.2.1-rc.2 || ^0.2.2-rc.1 || ^0.2.3-alpha.1",
|
|
92
|
+
"@deepseek-ai/dsh-client-ui-settings": "^0.1.1-rc.2 || ^0.1.5-rc.2 || ^0.2.0-rc.2 || ^0.2.1-rc.2 || ^0.2.2-rc.1 || ^0.2.3-alpha.1",
|
|
93
|
+
"@deepseek-ai/dsh-client-ui-primitives": "^0.1.1-rc.2 || ^0.1.5-rc.2 || ^0.2.0-rc.2 || ^0.2.1-rc.2 || ^0.2.2-rc.1 || ^0.2.3-alpha.1",
|
|
94
|
+
"@deepseek-ai/dsh-client-ui-slots": "^0.1.1-rc.2 || ^0.1.5-rc.2 || ^0.2.0-rc.2 || ^0.2.1-rc.2 || ^0.2.2-rc.1 || ^0.2.3-alpha.1",
|
|
95
|
+
"react": "^18.2.0",
|
|
96
|
+
"react-dom": "^18.2.0"
|
|
97
|
+
},
|
|
98
|
+
"peerDependenciesMeta": {
|
|
99
|
+
"@deepseek-ai/cordis": {
|
|
100
|
+
"optional": true
|
|
101
|
+
},
|
|
102
|
+
"@deepseek-ai/dsh-client-connection": {
|
|
103
|
+
"optional": true
|
|
104
|
+
},
|
|
105
|
+
"@deepseek-ai/dsh-client-locale": {
|
|
106
|
+
"optional": true
|
|
107
|
+
},
|
|
108
|
+
"@deepseek-ai/dsh-client-ui-settings": {
|
|
109
|
+
"optional": true
|
|
110
|
+
},
|
|
111
|
+
"@deepseek-ai/dsh-client-ui-primitives": {
|
|
112
|
+
"optional": true
|
|
113
|
+
},
|
|
114
|
+
"@deepseek-ai/dsh-client-ui-slots": {
|
|
115
|
+
"optional": true
|
|
116
|
+
},
|
|
117
|
+
"react": {
|
|
118
|
+
"optional": true
|
|
119
|
+
},
|
|
120
|
+
"react-dom": {
|
|
121
|
+
"optional": true
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
"devDependencies": {
|
|
125
|
+
"@deepseek-ai/cordis": "^4.0.2",
|
|
126
|
+
"@deepseek-ai/dsh-client-connection": "^0.1.5-rc.2",
|
|
127
|
+
"@deepseek-ai/dsh-client-locale": "^0.1.5-rc.2",
|
|
128
|
+
"@deepseek-ai/dsh-client-store": "^0.1.5-rc.2",
|
|
129
|
+
"@deepseek-ai/dsh-client-ui-primitives": "0.1.5-rc.2",
|
|
130
|
+
"@deepseek-ai/dsh-client-ui-renderer": "^0.1.5-rc.2",
|
|
131
|
+
"@deepseek-ai/dsh-client-ui-settings": "^0.1.5-rc.2",
|
|
132
|
+
"@deepseek-ai/dsh-client-ui-slots": "^0.1.5-rc.2",
|
|
133
|
+
"@deepseek-ai/dsh-host-webserver": "^0.1.5-rc.2",
|
|
134
|
+
"@deepseek-ai/dsh-settings": "^0.1.5-rc.2",
|
|
135
|
+
"@deepseek-ai/dsh-system-prompt": "^0.1.5-rc.2",
|
|
136
|
+
"@types/node": "^22.20.0",
|
|
137
|
+
"@types/react": "~18.3.1",
|
|
138
|
+
"@types/react-dom": "^18.3.5",
|
|
139
|
+
"esbuild": "^0.24.0",
|
|
140
|
+
"immer": "10.2.0",
|
|
141
|
+
"react": "^18.3.1",
|
|
142
|
+
"react-dom": "^18.3.1",
|
|
143
|
+
"typescript": "~5.7.2",
|
|
144
|
+
"zustand": "4.4.7"
|
|
145
|
+
}
|
|
146
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Requirement intake for a new board.
|
|
3
|
+
*
|
|
4
|
+
* "Draw me an X board" is not a specification. Guessing the supply, the connector
|
|
5
|
+
* orientation, the layer count or the fabrication process produces a board that is
|
|
6
|
+
* electrically fine and practically wrong, so the parameters that actually change the
|
|
7
|
+
* drawing are listed here and must be confirmed with the user before placement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export interface IntakeQuestion {
|
|
11
|
+
id: string
|
|
12
|
+
question: string
|
|
13
|
+
why: string
|
|
14
|
+
critical: boolean
|
|
15
|
+
options?: string[]
|
|
16
|
+
fallback?: string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface IntakeSection {
|
|
20
|
+
id: string
|
|
21
|
+
title: string
|
|
22
|
+
questions: IntakeQuestion[]
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const INTAKE_SECTIONS: IntakeSection[] = [
|
|
26
|
+
{
|
|
27
|
+
id: 'power',
|
|
28
|
+
title: '供电与电流',
|
|
29
|
+
questions: [
|
|
30
|
+
{ id: 'powerSource', question: '板子怎么供电?(USB-C / USB-A / DC 座 / 电池 / 外部端子)', why: '决定接口器件、连接器朝向和 ESD 保护', critical: true, options: ['USB-C', 'USB-A', 'DC 座', '锂电池', '外部端子', '多种'] },
|
|
31
|
+
{ id: 'inputVoltage', question: '输入电压范围与最大电流是多少?', why: '决定稳压方案、线宽、铜厚与散热', critical: true, fallback: '5 V / < 500 mA' },
|
|
32
|
+
{ id: 'railNeeds', question: '需要哪些电源轨(3V3 / 5V / 1V8 / 模拟轨)?各自负载多大?', why: '决定 LDO 还是 DC-DC、去耦数量', critical: true },
|
|
33
|
+
{ id: 'battery', question: '是否需要电池充电/切换?', why: '充电 IC 与路径管理会改变布局', critical: false, fallback: '不需要' },
|
|
34
|
+
],
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
id: 'core',
|
|
38
|
+
title: '主控与固件约束',
|
|
39
|
+
questions: [
|
|
40
|
+
{ id: 'mcu', question: '主控型号(或必须兼容的系列)?', why: '引脚、时钟、封装决定布局与走线', critical: true },
|
|
41
|
+
{ id: 'clock', question: '时钟来源:内部 RC / 外部晶振(频率)?', why: '晶振要贴脚、负载电容要配、下方禁铺铜', critical: true, options: ['内部 RC', '8 MHz 晶振', '16 MHz 晶振', '32.768 kHz', '其它'] },
|
|
42
|
+
{ id: 'programming', question: '烧写/调试接口(SWD / JTAG / USB DFU / 串口)?', why: '决定排针与 USB 数据线', critical: true, options: ['SWD 4 线', 'SWD 2 线', 'JTAG', 'USB DFU', '串口 ISP', '不需要'] },
|
|
43
|
+
{ id: 'boot', question: '启动方式是否需要可切换(BOOT0 跳线/按键)?', why: '决定下拉电阻与跳线排针', critical: false, fallback: '固定从 Flash 启动,BOOT0 下拉' },
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
id: 'io',
|
|
48
|
+
title: '接口与外设',
|
|
49
|
+
questions: [
|
|
50
|
+
{ id: 'interfaces', question: '需要哪些对外接口?(USB / UART / I2C / SPI / CAN / 以太网 / 显示屏 / 传感器)', why: '每一种都带连接器、保护器件和布线约束', critical: true },
|
|
51
|
+
{ id: 'isolation', question: '是否有隔离/高压/强电部分?安全距离要求?', why: '需要爬电间距、开槽、隔离器件', critical: true, options: ['无', '有低压隔离', '有市电/高压'] },
|
|
52
|
+
{ id: 'esd', question: '对外接口是否要 ESD/浪涌保护?', why: 'USBLC6 之类器件的地必须单独回流', critical: false, fallback: '对外接口都加 ESD' },
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
id: 'mechanical',
|
|
57
|
+
title: '机械与结构',
|
|
58
|
+
questions: [
|
|
59
|
+
{ id: 'size', question: '板框尺寸限制(长×宽 mm)与形状(矩形/带缺口/圆角半径)?', why: '决定布局密度与连接器位置', critical: true },
|
|
60
|
+
{ id: 'mounting', question: '定位孔数量、孔径、位置?', why: '非金属化孔要避开走线与器件', critical: true, fallback: '4 个 φ3.2 mm,四角内缩 3 mm' },
|
|
61
|
+
{ id: 'connectorFacing', question: '各连接器的朝向/位置(USB 朝板边哪一侧)?', why: '插口必须朝板外,否则装不进外壳', critical: true },
|
|
62
|
+
{ id: 'enclosure', question: '是否有外壳/装配限制(高度、干涉区)?', why: '限制器件高度与摆放', critical: false, fallback: '无外壳,仅裸板' },
|
|
63
|
+
],
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
id: 'process',
|
|
67
|
+
title: '工艺与制造',
|
|
68
|
+
questions: [
|
|
69
|
+
{ id: 'layers', question: '层数(2 层 / 4 层)?', why: '决定地平面、阻抗与布线策略', critical: true, options: ['2 层', '4 层'] },
|
|
70
|
+
{ id: 'copper', question: '铜厚(1 oz / 2 oz)?', why: '影响载流与最小线宽', critical: false, fallback: '1 oz' },
|
|
71
|
+
{ id: 'assembly', question: '贴片还是手焊?双面贴片?', why: '决定封装选型、丝印标注与焊盘外扩', critical: true, options: ['单面贴片', '双面贴片', '手工焊接'] },
|
|
72
|
+
{ id: 'quantity', question: '打样数量与预算区间?', why: '影响工艺选择(拼板、阻抗、沉金)', critical: false, fallback: '5 片打样' },
|
|
73
|
+
],
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
id: 'delivery',
|
|
77
|
+
title: '交付与验证',
|
|
78
|
+
questions: [
|
|
79
|
+
{ id: 'deliverable', question: '要交付到什么程度?(原理图 / PCB / Gerber+BOM+坐标 / 全流程可下单)', why: '决定验证深度与文档量', critical: true, options: ['仅原理图', '原理图+PCB', '可下单(Gerber+BOM+坐标)'] },
|
|
80
|
+
{ id: 'validation', question: '要哪些验证?(DRC / 网表 ERC / 设计审计 / 实机点亮)', why: '决定交付前必须跑的检查', critical: false, fallback: 'DRC + 网表 ERC + 设计审计' },
|
|
81
|
+
{ id: 'constraints', question: '还有其它硬约束(禁用的器件、必须复用已有工程、认证要求)?', why: '避免返工', critical: false },
|
|
82
|
+
],
|
|
83
|
+
},
|
|
84
|
+
]
|
|
85
|
+
|
|
86
|
+
export interface IntakeReport {
|
|
87
|
+
sections: IntakeSection[]
|
|
88
|
+
questionCount: number
|
|
89
|
+
criticalCount: number
|
|
90
|
+
answered: string[]
|
|
91
|
+
missingCritical: string[]
|
|
92
|
+
unknownAnswerKeys: string[]
|
|
93
|
+
ready: boolean
|
|
94
|
+
brief: Record<string, string>
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Answers are keyed by question id; unknown ids are reported instead of dropped. */
|
|
98
|
+
export function buildIntake(answers?: Record<string, unknown> | null): IntakeReport {
|
|
99
|
+
const provided = answers !== null && typeof answers === 'object' ? answers : {}
|
|
100
|
+
const known = new Set<string>()
|
|
101
|
+
for (const section of INTAKE_SECTIONS) for (const question of section.questions) known.add(question.id)
|
|
102
|
+
const brief: Record<string, string> = {}
|
|
103
|
+
const answered: string[] = []
|
|
104
|
+
const unknownAnswerKeys: string[] = []
|
|
105
|
+
for (const [key, value] of Object.entries(provided)) {
|
|
106
|
+
if (!known.has(key)) { unknownAnswerKeys.push(key); continue }
|
|
107
|
+
const text = String(value ?? '').trim()
|
|
108
|
+
if (text === '') continue
|
|
109
|
+
brief[key] = text
|
|
110
|
+
answered.push(key)
|
|
111
|
+
}
|
|
112
|
+
const missingCritical: string[] = []
|
|
113
|
+
let criticalCount = 0
|
|
114
|
+
let questionCount = 0
|
|
115
|
+
for (const section of INTAKE_SECTIONS) {
|
|
116
|
+
for (const question of section.questions) {
|
|
117
|
+
questionCount += 1
|
|
118
|
+
if (!question.critical) continue
|
|
119
|
+
criticalCount += 1
|
|
120
|
+
if (brief[question.id] === undefined) missingCritical.push(question.id)
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
sections: INTAKE_SECTIONS,
|
|
125
|
+
questionCount,
|
|
126
|
+
criticalCount,
|
|
127
|
+
answered,
|
|
128
|
+
missingCritical,
|
|
129
|
+
unknownAnswerKeys,
|
|
130
|
+
ready: missingCritical.length === 0,
|
|
131
|
+
brief,
|
|
132
|
+
}
|
|
133
|
+
}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JLCEDA / 嘉立创 design rules that this plugin can actually enforce.
|
|
3
|
+
*
|
|
4
|
+
* Normative text and rationale: `docs/design-rules.md`. Everything here is a
|
|
5
|
+
* *default* the tools apply plus a check they report, never a silent rewrite:
|
|
6
|
+
* a caller that really needs an off-rule value passes `force: true` and gets a
|
|
7
|
+
* warning back.
|
|
8
|
+
*
|
|
9
|
+
* Units: PCB coordinates and sizes are **mil** (JLCEDA Pro), 1 mm = 39.3701 mil.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export const MIL_PER_MM = 39.37007874015748
|
|
13
|
+
|
|
14
|
+
/** Convert millimetres to mil. */
|
|
15
|
+
export function mmToMil(mm: number): number {
|
|
16
|
+
return mm * MIL_PER_MM
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Convert mil to millimetres. */
|
|
20
|
+
export function milToMm(mil: number): number {
|
|
21
|
+
return mil / MIL_PER_MM
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Round a mil value to the nearest 0.05 mm step, as the rule set recommends. */
|
|
25
|
+
export function roundToFiveHundredthsMm(mil: number): number {
|
|
26
|
+
const mm = milToMm(mil)
|
|
27
|
+
return Math.round(mm / 0.05) * 0.05 * MIL_PER_MM
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface RuleCheck {
|
|
31
|
+
/** False only for values that would fail manufacturing / free prototyping. */
|
|
32
|
+
ok: boolean
|
|
33
|
+
errors: string[]
|
|
34
|
+
warnings: string[]
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function result(errors: string[], warnings: string[]): RuleCheck {
|
|
38
|
+
return { ok: errors.length === 0, errors, warnings }
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// ---------------------------------------------------------------------------
|
|
42
|
+
// Net naming (section 2.1: the backend matches net names as exact strings)
|
|
43
|
+
// ---------------------------------------------------------------------------
|
|
44
|
+
|
|
45
|
+
/** Hard limit from the JLCEDA backend. */
|
|
46
|
+
export const NET_NAME_MAX_LENGTH = 255
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Characters that survive the backend's parser. Space, `/`, `\`, brackets,
|
|
50
|
+
* comma, semicolon and non-ASCII (Chinese) names can split a net or drop it.
|
|
51
|
+
*/
|
|
52
|
+
const NET_NAME_ALLOWED = /^[A-Za-z0-9_.+-]+$/
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Check a net name against the naming rules.
|
|
56
|
+
*
|
|
57
|
+
* Rejects what the backend cannot parse; warns about the "practical" advice
|
|
58
|
+
* (uppercase + underscore only) because existing projects legitimately use
|
|
59
|
+
* names such as `P0.1`.
|
|
60
|
+
*/
|
|
61
|
+
export function checkNetName(net: string): RuleCheck & { net: string } {
|
|
62
|
+
const errors: string[] = []
|
|
63
|
+
const warnings: string[] = []
|
|
64
|
+
if (net === '') errors.push('net name is empty')
|
|
65
|
+
if (net.length > NET_NAME_MAX_LENGTH) errors.push(`net name is longer than ${NET_NAME_MAX_LENGTH} characters`)
|
|
66
|
+
// EDA generates hidden power nets such as $1N6954 itself (measured on the official
|
|
67
|
+
// example board); flagging the application's own names was a false positive.
|
|
68
|
+
const autoGenerated = /^\$?\d+N\d+$/.test(net) || /^\$/.test(net)
|
|
69
|
+
if (net !== '' && !NET_NAME_ALLOWED.test(net) && !autoGenerated) {
|
|
70
|
+
errors.push(`net name "${net}" contains characters the JLCEDA backend cannot parse (allowed: letters, digits, "_", ".", "+", "-")`)
|
|
71
|
+
}
|
|
72
|
+
if (/[a-z]/.test(net)) warnings.push(`net name "${net}" is not uppercase; the official advice is uppercase letters, digits and "_" only`)
|
|
73
|
+
return { ...result(errors, warnings), net }
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Throw on an unusable net name, so every net-taking tool fails identically. */
|
|
77
|
+
export function assertNetName(net: string, tool: string): void {
|
|
78
|
+
const check = checkNetName(net)
|
|
79
|
+
if (!check.ok) throw new Error(`${tool}: ${check.errors.join('; ')} (see docs/design-rules.md §2.1)`)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// ---------------------------------------------------------------------------
|
|
83
|
+
// Net roles and track width (section 5.1)
|
|
84
|
+
// ---------------------------------------------------------------------------
|
|
85
|
+
|
|
86
|
+
export type NetRole = 'ground' | 'power' | 'signal'
|
|
87
|
+
|
|
88
|
+
/** Track widths in mil for the four roles the rule set names. */
|
|
89
|
+
export const TRACK_WIDTH_MIL = {
|
|
90
|
+
/** 0.15 mm — ordinary signals, also the free-prototyping lower bound. */
|
|
91
|
+
signal: 6,
|
|
92
|
+
/** 0.25 mm — device-to-decoupling branch power. */
|
|
93
|
+
branchPower: 10,
|
|
94
|
+
/** 0.4 mm — main power trunk. */
|
|
95
|
+
mainPower: 16,
|
|
96
|
+
/** 0.5 mm — more than ~500 mA. */
|
|
97
|
+
highCurrent: 20,
|
|
98
|
+
} as const
|
|
99
|
+
|
|
100
|
+
/** Hard lower bound for a routed track (0.15 mm). */
|
|
101
|
+
export const MIN_TRACK_WIDTH_MIL = TRACK_WIDTH_MIL.signal
|
|
102
|
+
|
|
103
|
+
const GROUND_PATTERN = /^(?:A|D|P)?GND[A-Z0-9_]*$|^(?:VSS|EARTH|0V)/i
|
|
104
|
+
const POWER_PATTERN = /^(?:VCC|VDD|VEE|VBAT|VIN|VOUT|VBUS|PWR|VSYS|VCORE|AVDD|DVDD|3V3|5V|12V|24V|1V8|1V2|2V5)/i
|
|
105
|
+
|
|
106
|
+
/** Classify a net by name, for the default track width and the audit. */
|
|
107
|
+
export function classifyNet(net: string): NetRole {
|
|
108
|
+
if (GROUND_PATTERN.test(net)) return 'ground'
|
|
109
|
+
if (POWER_PATTERN.test(net)) return 'power'
|
|
110
|
+
return 'signal'
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Default track width (mil) for one net, following section 5.1. */
|
|
114
|
+
export function suggestTrackWidthMil(net: string): number {
|
|
115
|
+
const role = classifyNet(net)
|
|
116
|
+
if (role === 'ground') return TRACK_WIDTH_MIL.mainPower // routed GND: main-power class, pour preferred
|
|
117
|
+
if (role === 'power') return TRACK_WIDTH_MIL.mainPower
|
|
118
|
+
return TRACK_WIDTH_MIL.signal
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Validate a track width for a net.
|
|
123
|
+
*
|
|
124
|
+
* `lineWidth` undefined means "use the suggestion", which is what the drawing
|
|
125
|
+
* tools do; a provided value below the hard bound is an error unless `force`.
|
|
126
|
+
*/
|
|
127
|
+
export function checkTrackWidth(net: string, lineWidth: number | undefined, force = false): RuleCheck & { widthMil: number; role: NetRole; suggestedMil: number } {
|
|
128
|
+
const errors: string[] = []
|
|
129
|
+
const warnings: string[] = []
|
|
130
|
+
const role = classifyNet(net)
|
|
131
|
+
const suggestedMil = suggestTrackWidthMil(net)
|
|
132
|
+
const widthMil = lineWidth === undefined ? suggestedMil : lineWidth
|
|
133
|
+
|
|
134
|
+
if (!Number.isFinite(widthMil) || widthMil <= 0) {
|
|
135
|
+
errors.push(`track width must be a positive number of mil (got ${String(lineWidth)})`)
|
|
136
|
+
} else if (widthMil < MIN_TRACK_WIDTH_MIL && !force) {
|
|
137
|
+
errors.push(`track width ${widthMil} mil is below the ${MIN_TRACK_WIDTH_MIL} mil (0.15 mm) design minimum; pass force:true to override`)
|
|
138
|
+
}
|
|
139
|
+
if (widthMil > 0 && widthMil < suggestedMil && Number.isFinite(widthMil) && !force) {
|
|
140
|
+
warnings.push(`track width ${widthMil} mil is below the ${suggestedMil} mil suggested for ${role} net "${net}"`)
|
|
141
|
+
}
|
|
142
|
+
// The tier values (6/10/16/20 mil) are the practical mil targets, so they are
|
|
143
|
+
// exempt from the "round to a 0.05 mm step" advice.
|
|
144
|
+
// 15/25 mil are what the official example board actually uses, so they are not
|
|
145
|
+
// "off-step" mistakes even though they miss the 0.05 mm grid advice.
|
|
146
|
+
const isTierValue = (Object.values(TRACK_WIDTH_MIL) as number[]).includes(widthMil) || widthMil === 15 || widthMil === 25 || widthMil === 12
|
|
147
|
+
// Tolerance matters: 9.81 mil is 0.2492 mm, i.e. the 0.25 mm step within rounding,
|
|
148
|
+
// and the strict modulo used to flag it on a real board.
|
|
149
|
+
const stepRemainder = (() => {
|
|
150
|
+
const mm = milToMm(widthMil)
|
|
151
|
+
if (mm <= 0) return 0
|
|
152
|
+
const nearest = Math.round(mm / 0.05) * 0.05
|
|
153
|
+
return Math.abs(mm - nearest)
|
|
154
|
+
})()
|
|
155
|
+
if (widthMil > 0 && !isTierValue && stepRemainder > 0.01) {
|
|
156
|
+
warnings.push(`track width ${Math.round(widthMil * 100) / 100} mil (${milToMm(widthMil).toFixed(3)} mm) is not on a 0.05 mm step; ${Math.round(roundToFiveHundredthsMm(widthMil) * 100) / 100} mil aligns better with JLC parameters`)
|
|
157
|
+
}
|
|
158
|
+
return { ...result(errors, warnings), widthMil, role, suggestedMil }
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// ---------------------------------------------------------------------------
|
|
162
|
+
// Vias (section 5.2)
|
|
163
|
+
// ---------------------------------------------------------------------------
|
|
164
|
+
|
|
165
|
+
/** Standard drill/pad pairs in mm — prefer these over custom sizes. */
|
|
166
|
+
export const VIA_SIZES_MM = [
|
|
167
|
+
{ hole: 0.2, pad: 0.4, role: 'signal' },
|
|
168
|
+
{ hole: 0.3, pad: 0.6, role: 'power' },
|
|
169
|
+
{ hole: 0.4, pad: 0.8, role: 'highCurrent' },
|
|
170
|
+
] as const
|
|
171
|
+
|
|
172
|
+
/** Free-prototyping common lower bound for the drill diameter. */
|
|
173
|
+
export const VIA_HOLE_MIN_MM = 0.3
|
|
174
|
+
/** Below this the drill is not manufacturable at the standard process at all. */
|
|
175
|
+
export const VIA_HOLE_ABSOLUTE_MIN_MM = 0.2
|
|
176
|
+
/** Minimum annular ring: pad diameter minus hole diameter (the rule's 0.20 mm). */
|
|
177
|
+
export const ANNULUS_MIN_MM = 0.2
|
|
178
|
+
|
|
179
|
+
/** Validate via geometry (mil in, mm rules). */
|
|
180
|
+
export function checkVia(net: string, holeDiameterMil: number, diameterMil: number, force = false): RuleCheck & { holeMm: number; padMm: number; annulusMm: number; ringMm: number; suggestedMm: { hole: number; pad: number } } {
|
|
181
|
+
const errors: string[] = []
|
|
182
|
+
const warnings: string[] = []
|
|
183
|
+
const holeMm = milToMm(holeDiameterMil)
|
|
184
|
+
const padMm = milToMm(diameterMil)
|
|
185
|
+
// The rule's "焊环 ≥0.20mm" is the radial ring measured across the pad, i.e.
|
|
186
|
+
// pad minus hole; the standard pairs (0.2/0.4, 0.3/0.6, 0.4/0.8) all satisfy it.
|
|
187
|
+
const ringMm = padMm - holeMm
|
|
188
|
+
const annulusMm = ringMm / 2
|
|
189
|
+
const role = classifyNet(net)
|
|
190
|
+
const suggestedMm = role === 'signal' ? { hole: 0.2, pad: 0.4 } : { hole: 0.3, pad: 0.6 }
|
|
191
|
+
|
|
192
|
+
if (!Number.isFinite(holeMm) || !Number.isFinite(padMm) || holeMm <= 0 || padMm <= 0) {
|
|
193
|
+
errors.push('via hole and pad must be positive numbers of mil')
|
|
194
|
+
} else {
|
|
195
|
+
if (holeMm < VIA_HOLE_ABSOLUTE_MIN_MM) {
|
|
196
|
+
errors.push(`via hole ${holeMm.toFixed(2)} mm is below the ${VIA_HOLE_ABSOLUTE_MIN_MM} mm manufacturable minimum`)
|
|
197
|
+
} else if (holeMm < VIA_HOLE_MIN_MM) {
|
|
198
|
+
warnings.push(`via hole ${holeMm.toFixed(2)} mm is below the ${VIA_HOLE_MIN_MM} mm free-prototyping lower bound; confirm the capability on the order page`)
|
|
199
|
+
}
|
|
200
|
+
if (ringMm < ANNULUS_MIN_MM - 0.001) {
|
|
201
|
+
errors.push(`via annular ring ${ringMm.toFixed(2)} mm (pad ${padMm.toFixed(2)} - hole ${holeMm.toFixed(2)}) is below the ${ANNULUS_MIN_MM} mm minimum`)
|
|
202
|
+
}
|
|
203
|
+
const standard = VIA_SIZES_MM.find(size => Math.abs(size.hole - holeMm) < 0.01 && Math.abs(size.pad - padMm) < 0.01)
|
|
204
|
+
if (standard === undefined) {
|
|
205
|
+
warnings.push(`via ${holeMm.toFixed(2)}/${padMm.toFixed(2)} mm is not one of the standard sizes (0.2/0.4, 0.3/0.6, 0.4/0.8 mm)`)
|
|
206
|
+
}
|
|
207
|
+
if (role !== 'signal' && holeMm < 0.3 && !force) {
|
|
208
|
+
warnings.push(`power/ground net "${net}" uses a ${holeMm.toFixed(2)} mm hole; 0.3/0.6 mm is recommended for current-carrying vias`)
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return { ...result(errors, warnings), holeMm, padMm, annulusMm, ringMm, suggestedMm }
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// ---------------------------------------------------------------------------
|
|
215
|
+
// Copper pour (section 5.4) and board outline (section 7.2)
|
|
216
|
+
// ---------------------------------------------------------------------------
|
|
217
|
+
|
|
218
|
+
/** Minimum clearance the fabricator requires between a pour and other nets. */
|
|
219
|
+
export const POUR_CLEARANCE_MIN_MIL = 6
|
|
220
|
+
/** Recommended clearance for real designs (0.254 mm). */
|
|
221
|
+
export const POUR_CLEARANCE_RECOMMENDED_MIL = 10
|
|
222
|
+
|
|
223
|
+
/** Default board-outline line width (10 mil), as the rule set specifies. */
|
|
224
|
+
export const BOARD_OUTLINE_WIDTH_MIL = 10
|
|
225
|
+
|
|
226
|
+
/** Silkscreen lower bounds (documented; the API cannot set them per primitive). */
|
|
227
|
+
export const SILKSCREEN_HEIGHT_MIN_MM = 1.0
|
|
228
|
+
export const SILKSCREEN_WIDTH_MIN_MM = 0.15
|