@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.
Files changed (53) hide show
  1. package/AGENTS.md +63 -0
  2. package/CHANGELOG.md +792 -0
  3. package/CONTRIBUTING.md +154 -0
  4. package/LICENSE +55 -0
  5. package/README.md +290 -2
  6. package/README.zh.md +449 -0
  7. package/cordis.patch.yml +7 -0
  8. package/docs/design-rules.md +254 -0
  9. package/docs/dsh-version-sweep.md +73 -0
  10. package/docs/pitfalls.md +99 -0
  11. package/docs/project-status.md +100 -0
  12. package/docs/release.md +215 -0
  13. package/docs/schematic-workflow.md +297 -0
  14. package/docs/tools.md +184 -0
  15. package/jlc-extension/api-bridge.js +879 -0
  16. package/jlc-extension/extension.json +104 -0
  17. package/lib/bridge.mjs +4179 -0
  18. package/lib/client.js +1605 -0
  19. package/lib/extension-digest.json +6 -0
  20. package/lib/index.js +1261 -0
  21. package/package.json +144 -4
  22. package/src/bridge/design-intake.ts +133 -0
  23. package/src/bridge/design-rules.ts +228 -0
  24. package/src/bridge/eda-launch.ts +267 -0
  25. package/src/bridge/extension-package.ts +35 -0
  26. package/src/bridge/index.ts +3576 -0
  27. package/src/bridge/netlist-erc.ts +305 -0
  28. package/src/bridge/schematic-audit.ts +131 -0
  29. package/src/bridge/workflow-guide.ts +65 -0
  30. package/src/bridge-diagnostics.ts +185 -0
  31. package/src/client/EdaMcpSettingsCard.tsx +571 -0
  32. package/src/client/index.ts +40 -0
  33. package/src/client/locales.ts +83 -0
  34. package/src/client/settings-scope.ts +160 -0
  35. package/src/config-values.ts +60 -0
  36. package/src/guidance.ts +35 -0
  37. package/src/index.ts +365 -0
  38. package/src/loopback.ts +48 -0
  39. package/src/node-runtime.ts +120 -0
  40. package/src/routes.ts +377 -0
  41. package/src/skills-content.ts +309 -0
  42. package/src/skills.ts +91 -0
  43. package/test/config-values.test.ts +60 -0
  44. package/test/design-intake.test.ts +40 -0
  45. package/test/design-rules.test.ts +72 -0
  46. package/test/eda-launch.test.ts +114 -0
  47. package/test/extension-package.test.ts +27 -0
  48. package/test/extension-routes.test.ts +116 -0
  49. package/test/netlist-erc.test.ts +90 -0
  50. package/test/node-runtime.test.ts +65 -0
  51. package/test/schematic-audit.test.ts +71 -0
  52. package/test/seams.test.ts +164 -0
  53. package/test/skills.test.ts +68 -0
@@ -0,0 +1,185 @@
1
+ import { spawn } from 'node:child_process'
2
+
3
+ /**
4
+ * Runtime record of how the bridge child is doing, so a failure is readable
5
+ * from the loopback routes instead of only from host logs that the desktop app
6
+ * does not write to disk.
7
+ */
8
+ export interface BridgeDiagnosticsSnapshot {
9
+ /** Whether the `tools` service became visible (the 0.2 mcp-client requires it). */
10
+ toolsServiceSeen: boolean
11
+ /** How many times the MCP client mount was attempted in this process. */
12
+ mountAttempts: number
13
+ /** Last mount/inject error, if any. */
14
+ mountError: string | null
15
+ /** Cordis fiber state of the mounted client, read live when diagnostics are requested. */
16
+ clientFiberState: number | null
17
+ /** Whether the client fiber's startup promise already settled. */
18
+ clientSettled: boolean
19
+ /** Startup failure of the client fiber, with its cause chain. */
20
+ clientStartupError: string | null
21
+ /** Last `/healthz` observation of the bridge. */
22
+ bridgeHealth: 'unknown' | 'ok' | 'unreachable'
23
+ /** Error text of the last failed probe. */
24
+ probeError: string | null
25
+ /** When the last probe ran (epoch ms). */
26
+ probedAt: number | null
27
+ }
28
+
29
+ /** Render an error together with its `cause` chain, which carries the real failure. */
30
+ export function describeError(error: unknown): string {
31
+ const parts: string[] = []
32
+ let current: unknown = error
33
+ for (let depth = 0; depth < 5 && current !== undefined && current !== null; depth += 1) {
34
+ if (current instanceof Error) {
35
+ parts.push(`${current.name}: ${current.message}`)
36
+ current = (current as { cause?: unknown }).cause
37
+ continue
38
+ }
39
+ parts.push(String(current))
40
+ break
41
+ }
42
+ return parts.join(' <- ')
43
+ }
44
+
45
+ /** One spawn attempt of the bridge script from THIS process. */
46
+ export interface BridgeSelfTestResult {
47
+ command: string
48
+ args: string[]
49
+ spawned: boolean
50
+ exited: boolean
51
+ exitCode: number | null
52
+ exitSignal: string | null
53
+ stderr: string
54
+ stdout: string
55
+ healthz: string
56
+ spawnError: string | null
57
+ pid: number | null
58
+ }
59
+
60
+ const BRIDGE_PORT = 39009
61
+
62
+ export class BridgeDiagnostics {
63
+ readonly snapshot: BridgeDiagnosticsSnapshot = {
64
+ toolsServiceSeen: false,
65
+ mountAttempts: 0,
66
+ mountError: null,
67
+ clientFiberState: null,
68
+ clientSettled: false,
69
+ clientStartupError: null,
70
+ bridgeHealth: 'unknown',
71
+ probeError: null,
72
+ probedAt: null,
73
+ }
74
+
75
+ /** The mounted client fiber, so its state can be read live. */
76
+ #clientFiber: { state?: number } | null = null
77
+
78
+ /** Forget per-mount facts before a fresh mount attempt. */
79
+ beginMount(): void {
80
+ this.snapshot.toolsServiceSeen = false
81
+ this.snapshot.mountError = null
82
+ this.snapshot.clientSettled = false
83
+ // A remount's outcome replaces the previous one, otherwise a startup remount
84
+ // race leaves a stale error next to a healthy connection.
85
+ this.snapshot.clientStartupError = null
86
+ this.snapshot.mountAttempts += 1
87
+ }
88
+
89
+ recordToolsServiceSeen(): void {
90
+ this.snapshot.toolsServiceSeen = true
91
+ }
92
+
93
+ recordError(error: unknown): void {
94
+ this.snapshot.mountError = describeError(error)
95
+ }
96
+
97
+ /** Record the client fiber and observe its startup settlement (a failure carries `cause`). */
98
+ observeClientFiber(fiber: unknown): void {
99
+ const record = fiber as { state?: number; then?: unknown }
100
+ this.#clientFiber = typeof record?.state === 'number' || record !== null ? record as { state?: number } : null
101
+ this.snapshot.clientFiberState = typeof record?.state === 'number' ? record.state : null
102
+ if (typeof record?.then !== 'function') return
103
+ void Promise.resolve(fiber).then(() => {
104
+ this.snapshot.clientSettled = true
105
+ }).catch((error: unknown) => {
106
+ this.snapshot.clientSettled = true
107
+ this.snapshot.clientStartupError = describeError(error)
108
+ })
109
+ }
110
+
111
+ /** Read the live fiber state now (mount-time snapshots are always "starting"). */
112
+ liveSnapshot(): BridgeDiagnosticsSnapshot {
113
+ const state = this.#clientFiber?.state
114
+ return { ...this.snapshot, clientFiberState: typeof state === 'number' ? state : this.snapshot.clientFiberState }
115
+ }
116
+
117
+ /** Ask the bridge's own health endpoint over loopback. */
118
+ async probe(): Promise<'ok' | 'unreachable'> {
119
+ this.snapshot.probedAt = Date.now()
120
+ try {
121
+ const response = await fetch(`http://127.0.0.1:${BRIDGE_PORT}/healthz`, { signal: AbortSignal.timeout(3000) })
122
+ if (!response.ok) {
123
+ this.snapshot.bridgeHealth = 'unreachable'
124
+ this.snapshot.probeError = `healthz responded ${response.status}`
125
+ return 'unreachable'
126
+ }
127
+ this.snapshot.bridgeHealth = 'ok'
128
+ this.snapshot.probeError = null
129
+ return 'ok'
130
+ } catch (error) {
131
+ this.snapshot.bridgeHealth = 'unreachable'
132
+ this.snapshot.probeError = error instanceof Error ? error.message : String(error)
133
+ return 'unreachable'
134
+ }
135
+ }
136
+
137
+ /**
138
+ * Spawn the bridge straight from the plugin host process, watch it for a
139
+ * moment, and report what happened. This separates "the host cannot start the
140
+ * bridge executable" from "the MCP client never got to start it".
141
+ */
142
+ async selfTest(command: string, args: string[], timeoutMs = 2500): Promise<BridgeSelfTestResult> {
143
+ const result: BridgeSelfTestResult = {
144
+ command, args, spawned: false, exited: false, exitCode: null, exitSignal: null,
145
+ stderr: '', stdout: '', healthz: 'n/a', spawnError: null, pid: null,
146
+ }
147
+ const child = spawn(command, args, { stdio: ['pipe', 'pipe', 'pipe'], windowsHide: true })
148
+ result.spawned = true
149
+ result.pid = child.pid ?? null
150
+ let settled = false
151
+ const finished = new Promise<void>((resolve) => {
152
+ child.once('error', (error) => {
153
+ result.spawnError = error instanceof Error ? `${error.name}: ${error.message}` : String(error)
154
+ settled = true
155
+ resolve()
156
+ })
157
+ child.once('exit', (code, signal) => {
158
+ result.exited = true
159
+ result.exitCode = code
160
+ result.exitSignal = signal ?? null
161
+ settled = true
162
+ resolve()
163
+ })
164
+ })
165
+ child.stdout?.on('data', (chunk) => { result.stdout = (result.stdout + String(chunk)).slice(-2000) })
166
+ child.stderr?.on('data', (chunk) => { result.stderr = (result.stderr + String(chunk)).slice(-2000) })
167
+
168
+ const deadline = Date.now() + timeoutMs
169
+ let health = 'unreachable'
170
+ while (Date.now() < deadline && !settled) {
171
+ await new Promise(resolve => setTimeout(resolve, 300))
172
+ try {
173
+ const response = await fetch(`http://127.0.0.1:${BRIDGE_PORT}/healthz`, { signal: AbortSignal.timeout(1000) })
174
+ health = `${response.status} ${await response.text()}`
175
+ break
176
+ } catch { /* not up yet */ }
177
+ }
178
+ result.healthz = health
179
+ if (!settled) {
180
+ try { child.kill() } catch { /* already gone */ }
181
+ await Promise.race([finished, new Promise(resolve => setTimeout(resolve, 1000))])
182
+ }
183
+ return result
184
+ }
185
+ }