dsh-stm32 0.1.2 → 0.1.4

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 (225) hide show
  1. package/README.md +92 -40
  2. package/README_EN.md +85 -36
  3. package/assets/README.md +85 -0
  4. package/assets/VERSION +1 -0
  5. package/assets/device/c0/chips.json +1108 -0
  6. package/assets/device/f0/chips.json +1570 -0
  7. package/assets/device/f1/chips.json +1238 -0
  8. package/assets/device/f1/svd/100.json +943 -0
  9. package/assets/device/f1/svd/101.json +901 -0
  10. package/assets/device/f1/svd/102.json +522 -0
  11. package/assets/device/f1/svd/103.json +1139 -0
  12. package/assets/device/f1/svd/105.json +1117 -0
  13. package/assets/device/f1/svd/107.json +1195 -0
  14. package/assets/device/f2/chips.json +674 -0
  15. package/assets/device/f3/chips.json +1318 -0
  16. package/assets/device/f4/chips.json +2942 -0
  17. package/assets/device/f7/chips.json +1710 -0
  18. package/assets/device/g0/chips.json +2102 -0
  19. package/assets/device/g4/chips.json +2494 -0
  20. package/assets/device/h5/chips.json +898 -0
  21. package/assets/device/h7/chips.json +1948 -0
  22. package/assets/device/l0/chips.json +2494 -0
  23. package/assets/device/l1/chips.json +1234 -0
  24. package/assets/device/l4/chips.json +2130 -0
  25. package/assets/device/l4+/chips.json +856 -0
  26. package/assets/device/l5/chips.json +226 -0
  27. package/assets/device/u0/chips.json +688 -0
  28. package/assets/device/u3/chips.json +310 -0
  29. package/assets/device/u5/chips.json +884 -0
  30. package/assets/device/wba/chips.json +506 -0
  31. package/assets/device/wl/chips.json +184 -0
  32. package/assets/headers/f1/stm32f100xb.h +5972 -0
  33. package/assets/headers/f1/stm32f100xe.h +6587 -0
  34. package/assets/headers/f1/stm32f101x6.h +5315 -0
  35. package/assets/headers/f1/stm32f101xb.h +5446 -0
  36. package/assets/headers/f1/stm32f101xe.h +6503 -0
  37. package/assets/headers/f1/stm32f101xg.h +6713 -0
  38. package/assets/headers/f1/stm32f102x6.h +6448 -0
  39. package/assets/headers/f1/stm32f102xb.h +6570 -0
  40. package/assets/headers/f1/stm32f103x6.h +10109 -0
  41. package/assets/headers/f1/stm32f103xb.h +10240 -0
  42. package/assets/headers/f1/stm32f103xe.h +11767 -0
  43. package/assets/headers/f1/stm32f103xg.h +11951 -0
  44. package/assets/headers/f1/stm32f105xc.h +14340 -0
  45. package/assets/headers/f1/stm32f107xc.h +15253 -0
  46. package/assets/headers/f1/stm32f1xx.h +273 -0
  47. package/assets/headers/f1/system_stm32f1xx.h +96 -0
  48. package/assets/ioc/family/C0.ioc +82 -0
  49. package/assets/ioc/family/F0.ioc +71 -0
  50. package/assets/ioc/family/F2.ioc +91 -0
  51. package/assets/ioc/family/F3.ioc +94 -0
  52. package/assets/ioc/family/F4.ioc +91 -0
  53. package/assets/ioc/family/F7.ioc +102 -0
  54. package/assets/ioc/family/G0.ioc +90 -0
  55. package/assets/ioc/family/G4.ioc +110 -0
  56. package/assets/ioc/family/H5.ioc +116 -0
  57. package/assets/ioc/family/H7.ioc +133 -0
  58. package/assets/ioc/family/L0.ioc +92 -0
  59. package/assets/ioc/family/L1.ioc +87 -0
  60. package/assets/ioc/family/L4+.ioc +92 -0
  61. package/assets/ioc/family/L4.ioc +93 -0
  62. package/assets/ioc/family/L5.ioc +91 -0
  63. package/assets/ioc/family/U0.ioc +103 -0
  64. package/assets/ioc/family/U3.ioc +113 -0
  65. package/assets/ioc/family/U5.ioc +102 -0
  66. package/assets/ioc/family/WBA.ioc +100 -0
  67. package/assets/ioc/family/WL.ioc +93 -0
  68. package/assets/ioc/minimal/STM32F100C8Tx.ioc +113 -0
  69. package/assets/ioc/minimal/STM32F100RCTx.ioc +113 -0
  70. package/assets/ioc/minimal/STM32F101C4Tx.ioc +113 -0
  71. package/assets/ioc/minimal/STM32F101C8Tx.ioc +113 -0
  72. package/assets/ioc/minimal/STM32F101RCTx.ioc +113 -0
  73. package/assets/ioc/minimal/STM32F101RFTx.ioc +113 -0
  74. package/assets/ioc/minimal/STM32F102C4Tx.ioc +113 -0
  75. package/assets/ioc/minimal/STM32F102C8Tx.ioc +113 -0
  76. package/assets/ioc/minimal/STM32F103C4Tx.ioc +113 -0
  77. package/assets/ioc/minimal/STM32F103C8Tx.ioc +113 -0
  78. package/assets/ioc/minimal/STM32F103RCTx.ioc +113 -0
  79. package/assets/ioc/minimal/STM32F103RFTx.ioc +113 -0
  80. package/assets/ioc/minimal/STM32F105RCTx.ioc +113 -0
  81. package/assets/ioc/minimal/STM32F107RCTx.ioc +113 -0
  82. package/assets/ld/f1/STM32F100C8Tx_FLASH.ld +249 -0
  83. package/assets/ld/f1/STM32F100RCTx_FLASH.ld +249 -0
  84. package/assets/ld/f1/STM32F101C4Tx_FLASH.ld +249 -0
  85. package/assets/ld/f1/STM32F101C8Tx_FLASH.ld +249 -0
  86. package/assets/ld/f1/STM32F101RCTx_FLASH.ld +249 -0
  87. package/assets/ld/f1/STM32F101RFTx_FLASH.ld +249 -0
  88. package/assets/ld/f1/STM32F102C4Tx_FLASH.ld +249 -0
  89. package/assets/ld/f1/STM32F102C8Tx_FLASH.ld +249 -0
  90. package/assets/ld/f1/STM32F103C4Tx_FLASH.ld +249 -0
  91. package/assets/ld/f1/STM32F103C8Tx_FLASH.ld +249 -0
  92. package/assets/ld/f1/STM32F103RCTx_FLASH.ld +249 -0
  93. package/assets/ld/f1/STM32F103RFTx_FLASH.ld +249 -0
  94. package/assets/ld/f1/STM32F105RCTx_FLASH.ld +249 -0
  95. package/assets/ld/f1/STM32F107RCTx_FLASH.ld +249 -0
  96. package/assets/manifest.json +1130 -0
  97. package/assets/startup/f1/startup_stm32f100xb.s +407 -0
  98. package/assets/startup/f1/startup_stm32f100xe.s +449 -0
  99. package/assets/startup/f1/startup_stm32f101x6.s +322 -0
  100. package/assets/startup/f1/startup_stm32f101xb.s +338 -0
  101. package/assets/startup/f1/startup_stm32f101xe.s +423 -0
  102. package/assets/startup/f1/startup_stm32f101xg.s +439 -0
  103. package/assets/startup/f1/startup_stm32f102x6.s +330 -0
  104. package/assets/startup/f1/startup_stm32f102xb.s +346 -0
  105. package/assets/startup/f1/startup_stm32f103x6.s +348 -0
  106. package/assets/startup/f1/startup_stm32f103xb.s +364 -0
  107. package/assets/startup/f1/startup_stm32f103xe.s +470 -0
  108. package/assets/startup/f1/startup_stm32f103xg.s +466 -0
  109. package/assets/startup/f1/startup_stm32f105xc.s +463 -0
  110. package/assets/startup/f1/startup_stm32f107xc.s +472 -0
  111. package/assets/templates/family/C0.ioc +82 -0
  112. package/assets/templates/family/F0.ioc +71 -0
  113. package/assets/templates/family/F2.ioc +91 -0
  114. package/assets/templates/family/F3.ioc +94 -0
  115. package/assets/templates/family/F4.ioc +91 -0
  116. package/assets/templates/family/F7.ioc +102 -0
  117. package/assets/templates/family/G0.ioc +90 -0
  118. package/assets/templates/family/G4.ioc +110 -0
  119. package/assets/templates/family/H5.ioc +116 -0
  120. package/assets/templates/family/H7.ioc +133 -0
  121. package/assets/templates/family/L0.ioc +92 -0
  122. package/assets/templates/family/L1.ioc +87 -0
  123. package/assets/templates/family/L4+.ioc +92 -0
  124. package/assets/templates/family/L4.ioc +93 -0
  125. package/assets/templates/family/L5.ioc +91 -0
  126. package/assets/templates/family/U0.ioc +103 -0
  127. package/assets/templates/family/U3.ioc +113 -0
  128. package/assets/templates/family/U5.ioc +102 -0
  129. package/assets/templates/family/WB.ioc +81 -0
  130. package/assets/templates/family/WBA.ioc +100 -0
  131. package/assets/templates/family/WL.ioc +93 -0
  132. package/docs/reading-guide.md +94 -71
  133. package/lib/data/chips.js +38 -51
  134. package/lib/data/clock-db.js +830 -0
  135. package/lib/data/clock-f1.js +12 -45
  136. package/lib/data/cmsis-sources.js +264 -17
  137. package/lib/data/db-presets.js +252 -0
  138. package/lib/data/device-facts.js +274 -0
  139. package/lib/data/family.js +515 -0
  140. package/lib/data/firmware-packages.js +562 -0
  141. package/lib/data/install-guides.js +2 -2
  142. package/lib/data/ioc-presets.js +248 -0
  143. package/lib/data/ioc-schema.js +1058 -0
  144. package/lib/data/rm-topics/stm32c0.json +227 -0
  145. package/lib/data/rm-topics.js +103 -0
  146. package/lib/data/search-roots.js +42 -1
  147. package/lib/data/stm32f1.js +95 -150
  148. package/lib/data/svd.js +643 -0
  149. package/lib/data/toolchain-config.js +0 -14
  150. package/lib/engine/assets.js +659 -0
  151. package/lib/engine/breakpoints.js +297 -0
  152. package/lib/engine/clock-derived.js +101 -0
  153. package/lib/engine/clock-direct.js +313 -0
  154. package/lib/engine/clock-plan.js +96 -52
  155. package/lib/engine/clock-pllmn.js +319 -0
  156. package/lib/engine/cmake-sources.js +67 -13
  157. package/lib/engine/cube-mx-guard.js +44 -0
  158. package/lib/engine/cube-programmer.js +137 -0
  159. package/lib/engine/cubemx-db.js +273 -0
  160. package/lib/engine/debug-session.js +576 -22
  161. package/lib/engine/debug.js +99 -46
  162. package/lib/engine/doctor.js +162 -19
  163. package/lib/engine/facts-acquire.js +416 -0
  164. package/lib/engine/facts.js +134 -0
  165. package/lib/engine/firmware-install.js +176 -5
  166. package/lib/engine/firmware-official.js +451 -0
  167. package/lib/engine/flash.js +317 -76
  168. package/lib/engine/gdb-mi.js +476 -0
  169. package/lib/engine/generate.js +9 -2
  170. package/lib/engine/hal-chip.js +124 -41
  171. package/lib/engine/ioc-plan.js +1247 -63
  172. package/lib/engine/ioc-rules.js +698 -0
  173. package/lib/engine/ioc-verify.js +706 -0
  174. package/lib/engine/ioc.js +43 -4
  175. package/lib/engine/msys2-install.js +4 -4
  176. package/lib/engine/probe-error.js +231 -0
  177. package/lib/engine/probe-session.js +347 -0
  178. package/lib/engine/probe.js +18 -3
  179. package/lib/engine/register-clock.js +41 -0
  180. package/lib/engine/register-gpio.js +115 -0
  181. package/lib/engine/register-linker.js +12 -7
  182. package/lib/engine/register-template.js +130 -45
  183. package/lib/engine/regs.js +43 -8
  184. package/lib/engine/rm-extract.js +144 -0
  185. package/lib/engine/rm-sources.js +360 -0
  186. package/lib/engine/rm-text.js +56 -0
  187. package/lib/engine/rtt.js +758 -0
  188. package/lib/engine/scaffold.js +185 -18
  189. package/lib/engine/toolchain-gate.js +0 -4
  190. package/lib/engine/watch.js +227 -0
  191. package/lib/index.js +12 -2
  192. package/lib/skill/stm32-workflow.js +2 -2
  193. package/lib/tools/assets.js +272 -0
  194. package/lib/tools/cache.js +8 -0
  195. package/lib/tools/debug-session.js +41 -6
  196. package/lib/tools/debug.js +41 -11
  197. package/lib/tools/doctor.js +65 -4
  198. package/lib/tools/firmware-install.js +31 -6
  199. package/lib/tools/flash.js +47 -10
  200. package/lib/tools/generate.js +25 -0
  201. package/lib/tools/ioc-apply.js +2 -0
  202. package/lib/tools/ioc-inspect.js +2 -0
  203. package/lib/tools/ioc-plan.js +59 -2
  204. package/lib/tools/ioc-verify.js +237 -0
  205. package/lib/tools/project-create.js +63 -3
  206. package/lib/tools/regs.js +453 -61
  207. package/lib/tools/route-plan.js +3 -0
  208. package/lib/tools/rtt.js +470 -0
  209. package/lib/tools/watch.js +256 -0
  210. package/package.json +5 -4
  211. package/templates/openocd/stm32c0x.cfg +83 -0
  212. package/templates/openocd/stm32u0x.cfg +64 -0
  213. package/templates/register/CMakeLists.txt +8 -2
  214. package/templates/register/Core/Inc/rtt.h +138 -0
  215. package/templates/register/Core/Src/main.c +42 -25
  216. package/templates/register/Core/Src/rtt.c +373 -0
  217. package/templates/scaffold/RTT.md +90 -0
  218. package/templates/scaffold/STM32F103XX_FLASH.ld +3 -0
  219. package/templates/scaffold/cmake/user/CMakeLists.txt +7 -0
  220. package/templates/scaffold/openocd.cfg +5 -3
  221. package/templates/scaffold/vscode/launch.json +8 -4
  222. package/docs/development-notes.md +0 -2116
  223. package/docs/dsh-stm32-plugin-/350/247/204/346/240/274.md +0 -673
  224. package/docs/logic-audit.md +0 -607
  225. package/lib/data/f1-ram.generated.js +0 -34
package/lib/tools/regs.js CHANGED
@@ -1,14 +1,39 @@
1
1
  /**
2
2
  * L3:stm32_regs_read —— 读物理地址上的寄存器(例如 GPIOC_ODR、AFIO_MAPR)。
3
3
  *
4
- * 只读不写、跑完 resume 让芯片原样继续跑、探针立刻释放。用来"自证"烧进去的固件真的在动,
5
- * 比看 LED 更可靠。
4
+ * 只读不写、跑完 resume 让芯片原样继续跑。
5
+ * B3 起走"会话复用快路径":先保证有一个调试会话(有就复用,没有就起一个、保留到租约到期),
6
+ * 再走 openocd 的 **Tcl RPC 口** halt → reg pc → mdw × N → resume,一次 TCP 往返几毫秒
7
+ * (原来每次 spawn 一个 openocd 要 1493 ms)。Tcl 端口解析不到 / RPC 失败时回退到会话里的 gdb 读。
8
+ * 端口被 VS Code 的调试会话占着时直接报 probe-busy,不抢探针。
9
+ *
10
+ * D2:接上内置资源里的 SVD(profile=full 才装)。addresses 的每一项可以是
11
+ * 物理地址(0x4001100C / 4001100C)、寄存器符号(GPIOC.ODR / GPIOC->ODR / RCC.CR),
12
+ * 或者只写外设名(GPIOC)=把该外设的寄存器整体 dump 一遍(最多 REG_DUMP_MAX 个)。
13
+ * 每条样本都会带上 ref(用户写法)、name(规范化名)与 fields(置位位域),报告 schema 同步。
14
+ * 没有 SVD 时自动退回"纯地址"模式,只是没有名字/位域解释(不报错,功能不退化)。
6
15
  */
7
- import { describeSample, runRegsRead } from "../engine/regs.js";
8
16
  import { debugSessions } from "../engine/debug-session.js";
17
+ import { ensureSession, readWordsViaSession } from "../engine/probe-session.js";
9
18
  import { ensureToolchain, gateReportNotes } from "../engine/toolchain-gate.js";
19
+ import { readIocCpn } from "../engine/breakpoints.js";
20
+ import { SVD_FULL_PROFILE_HINT, SVD_KNOWN_LINES, SvdError, decodeRegisterValue, describeAddress, formatAddress, loadSvd, parseAddressText, resolveRegisterRef, svdLineForChip, } from "../data/svd.js";
10
21
  import { resolveProjectDir, validateToolArgs } from "./project-dir.js";
11
22
  export const REGS_TOOL = "stm32_regs_read";
23
+ /** 只给外设名时一次最多 dump 多少个寄存器(GPIOC 这种寄存器少的根本到不了上限,RCC 也就几十个)。 */
24
+ export const REG_DUMP_MAX = 64;
25
+ /** 未知外设时列出多少个"可用外设"当建议。 */
26
+ export const REGS_SUGGEST_PERIPHERALS = 10;
27
+ const fieldSchema = {
28
+ type: "object",
29
+ additionalProperties: false,
30
+ properties: {
31
+ name: { type: "string", description: "位域名,例如 ODR2。" },
32
+ bits: { type: "string", description: "位域覆盖的位:单 bit 写 \"2\",多 bit 写 \"3:5\"(起点:终点,闭区间)。" },
33
+ value: { type: "number", description: "该位域移位后的值(置位才进列表,所以非 0)。" },
34
+ },
35
+ required: ["name", "bits", "value"],
36
+ };
12
37
  const sampleSchema = {
13
38
  type: "object",
14
39
  additionalProperties: false,
@@ -16,8 +41,11 @@ const sampleSchema = {
16
41
  address: { type: "string" },
17
42
  value: { type: "string" },
18
43
  ok: { type: "boolean" },
44
+ ref: { type: "string", description: "用户写的那个 ref(原样)。" },
45
+ name: { type: "string", description: "规范化名,例如 GPIOC.ODR;没有 SVD 时等于地址。" },
46
+ fields: { type: "array", items: fieldSchema, description: "值里置位(非 0)的位域。" },
19
47
  },
20
- required: ["address", "value", "ok"],
48
+ required: ["address", "value", "ok", "ref", "name", "fields"],
21
49
  };
22
50
  export const outputSchema = {
23
51
  type: "object",
@@ -29,6 +57,7 @@ export const outputSchema = {
29
57
  additionalProperties: false,
30
58
  properties: {
31
59
  ok: { type: "boolean" },
60
+ reusedSession: { type: "boolean" },
32
61
  projectDir: { type: "string" },
33
62
  configFile: { type: "string" },
34
63
  command: { type: "string" },
@@ -43,7 +72,7 @@ export const outputSchema = {
43
72
  notes: { type: "array", items: { type: "string" } },
44
73
  },
45
74
  required: [
46
- "ok", "projectDir", "configFile", "command", "script", "pc", "samples",
75
+ "ok", "reusedSession", "projectDir", "configFile", "command", "script", "pc", "samples",
47
76
  "durationMs", "errors", "message", "logTail", "notes",
48
77
  ],
49
78
  },
@@ -56,13 +85,316 @@ const ENV_CHECK_SCHEMA = {
56
85
  enum: ["block", "warn", "off"],
57
86
  description: "工具链检查:block 缺件就拒绝(默认)、warn 只警告、off 不检查",
58
87
  };
88
+ /* ------------------------------ SVD → line ------------------------------ */
89
+ function svdFailureText(failure) {
90
+ const suffix = failure.message.includes(SVD_FULL_PROFILE_HINT) ? "" : ";" + SVD_FULL_PROFILE_HINT;
91
+ return failure.message + suffix;
92
+ }
93
+ /**
94
+ * 工程 → SVD:先按型号查 device facts(chips.json 的 line),查不到再按型号里的三位数字兜底。
95
+ *
96
+ * 为什么要兜底:开发机上常把 DSH_STM32_ASSETS 直接指到资源脚本 scripts/assets/本体(未分版本、没有 install.json),
97
+ * 这时 device-facts 读不到,但 SVD 文件其实就在 <root>/device/f1/svd/<line>.json —— 兜底让本地开发可用。
98
+ */
99
+ export function resolveProjectSvd(projectDir, env = process.env) {
100
+ const cpn = readIocCpn(projectDir);
101
+ const degraded = (note) => ({
102
+ cpn, line: "", device: null, failure: null, source: "none", note,
103
+ });
104
+ if (cpn === "") {
105
+ return degraded("工程里没有 .ioc(取不到型号):这次只按物理地址读,符号名与位域解释不可用。");
106
+ }
107
+ let line = "";
108
+ let source = "none";
109
+ try {
110
+ line = svdLineForChip(cpn, env) ?? "";
111
+ }
112
+ catch {
113
+ line = "";
114
+ }
115
+ if (line !== "") {
116
+ source = "chips.json";
117
+ }
118
+ else {
119
+ // 兜底:STM32F103C8T6 → "103"。只认 SVD_KNOWN_LINES 里真有的 line,且文件必须能读出来。
120
+ const match = /^STM32F(\d{3})/u.exec(cpn.trim().toUpperCase());
121
+ const candidate = match === null ? "" : (match[1] ?? "");
122
+ if (candidate !== "" && SVD_KNOWN_LINES.includes(candidate)) {
123
+ line = candidate;
124
+ source = "cpn";
125
+ }
126
+ }
127
+ if (line === "") {
128
+ return degraded("型号 " + cpn + " 没能对上 SVD line(device facts 里没有它,或内置资源没装):这次只按物理地址读,符号名与位域解释不可用;" +
129
+ SVD_FULL_PROFILE_HINT + "。");
130
+ }
131
+ const loaded = loadSvd(line, env);
132
+ if (loaded.device === null) {
133
+ const failure = loaded.failure;
134
+ return {
135
+ cpn,
136
+ line,
137
+ device: null,
138
+ failure,
139
+ source,
140
+ note: "line=" + line + " 的 SVD 读不到(" + (failure === null ? "未知原因" : svdFailureText(failure)) +
141
+ "):这次只按物理地址读,符号名与位域解释都用不了。",
142
+ };
143
+ }
144
+ const device = loaded.device;
145
+ const pieces = [
146
+ "位域解释来自 SVD line=" + device.line + "(" + device.device + "," +
147
+ String(device.counts.peripherals) + " 个外设 / " + String(device.counts.registers) + " 个寄存器 / " +
148
+ String(device.counts.fields) + " 个位域" + (device.version === "" ? "" : ",内置资源 " + device.version) + ")",
149
+ source === "cpn"
150
+ ? "line 是按型号 " + cpn + " 的编号兜底推出来的(device facts 里没有这颗芯片)"
151
+ : "型号 " + cpn + " 来自 device facts",
152
+ ];
153
+ return { cpn, line, device, failure: null, source, note: pieces.join(";") };
154
+ }
155
+ /* ------------------------------ refs → 读目标 ------------------------------ */
156
+ /** 位域覆盖的位:单 bit 写 "2",多 bit 写 "3:5"(起点:终点,闭区间,跟手册的写法一致)。 */
157
+ export function formatBits(bitOffset, bitWidth) {
158
+ if (bitWidth <= 1)
159
+ return String(bitOffset);
160
+ return String(bitOffset) + ":" + String(bitOffset + bitWidth - 1);
161
+ }
162
+ function normalizeRefKey(ref) {
163
+ return ref.trim().replace(/\s+/gu, "").toUpperCase();
164
+ }
165
+ function lookupPeripheral(device, name) {
166
+ const exact = device.byName.get(name.trim());
167
+ if (exact !== undefined)
168
+ return exact;
169
+ const wanted = name.trim().toUpperCase();
170
+ if (wanted === "")
171
+ return null;
172
+ for (const peripheral of device.peripherals) {
173
+ if (peripheral.name.toUpperCase() === wanted)
174
+ return peripheral;
175
+ }
176
+ return null;
177
+ }
178
+ function suggestPeripheralNames(device, wanted) {
179
+ const upper = wanted.trim().toUpperCase();
180
+ const prefixHits = [];
181
+ const others = [];
182
+ for (const name of device.peripheralNames) {
183
+ const candidate = name.toUpperCase();
184
+ if (upper !== "" && (candidate.startsWith(upper) || upper.startsWith(candidate)))
185
+ prefixHits.push(name);
186
+ else
187
+ others.push(name);
188
+ }
189
+ return [...prefixHits, ...others].slice(0, REGS_SUGGEST_PERIPHERALS);
190
+ }
191
+ function describeAddressSafe(device, address, env) {
192
+ try {
193
+ return describeAddress(address, device.line, env);
194
+ }
195
+ catch {
196
+ // SVD 文件在两次调用之间被删/改坏:降级成"没有名字",不要让读值失败。
197
+ return null;
198
+ }
199
+ }
200
+ const SYMBOL_PATTERN = /^([A-Za-z_][A-Za-z0-9_]*)\s*(?:\.|->)\s*([A-Za-z_][A-Za-z0-9_]*)$/u;
201
+ const BARE_NAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/u;
202
+ /**
203
+ * 把 addresses 的每一项解析成"绝对地址 + 名字 + 位域"。
204
+ *
205
+ * 支持四种写法(与 svd.resolveRegisterRef 一致)+ 只给外设名时的 dump:
206
+ * GPIOC.ODR / GPIOC->ODR / RCC.CR / 0x4001100C / 4001100C / GPIOC
207
+ * 失败不抛:把结构化原因放进 errors(包含该 line 的可用外设清单),由工具层拼成一次失败的报告。
208
+ */
209
+ export function planRegReads(refs, device, env = process.env) {
210
+ const addresses = [];
211
+ const targets = [];
212
+ const errors = [];
213
+ const notes = [];
214
+ const seenRefs = new Set();
215
+ const byAddress = new Map();
216
+ let noSvdNoted = false;
217
+ const pushTarget = (target, quiet = false) => {
218
+ const existing = byAddress.get(target.address);
219
+ if (existing !== undefined) {
220
+ if (!quiet) {
221
+ notes.push("「" + target.ref + "」与「" + existing.ref + "」指向同一个地址 " + formatAddress(target.address) + ",只读一次");
222
+ }
223
+ return;
224
+ }
225
+ byAddress.set(target.address, target);
226
+ targets.push(target);
227
+ addresses.push(formatAddress(target.address));
228
+ };
229
+ const dumpPeripheral = (peripheral) => {
230
+ // 按偏移升序(= 手册顺序),前 REG_DUMP_MAX 个;同一个地址的别名寄存器只留第一个。
231
+ const registers = [...peripheral.registers].sort((left, right) => {
232
+ if (left.addressOffset !== right.addressOffset)
233
+ return left.addressOffset - right.addressOffset;
234
+ return left.name.localeCompare(right.name);
235
+ });
236
+ const kept = registers.slice(0, REG_DUMP_MAX);
237
+ for (const register of kept) {
238
+ pushTarget({
239
+ ref: peripheral.name,
240
+ kind: "peripheral",
241
+ name: peripheral.name + "." + register.name,
242
+ address: (peripheral.baseAddress + register.addressOffset) >>> 0,
243
+ peripheral: peripheral.name,
244
+ register: register.name,
245
+ size: register.size,
246
+ fields: register.fields,
247
+ }, true);
248
+ }
249
+ if (registers.length > kept.length) {
250
+ notes.push("外设 " + peripheral.name + " 有 " + String(registers.length) + " 个寄存器,只 dump 了地址最小的前 " +
251
+ String(REG_DUMP_MAX) + " 个(剩下的写 " + peripheral.name + ".寄存器名 单独读)");
252
+ }
253
+ notes.push("「" + peripheral.name + "」是外设名:dump 了它的 " + String(kept.length) + " 个寄存器(基址 " +
254
+ formatAddress(peripheral.baseAddress) + ")");
255
+ };
256
+ for (const raw of refs) {
257
+ const text = (raw ?? "").trim();
258
+ if (text === "") {
259
+ errors.push("addresses 里有一项是空字符串:写地址(0x4001100C)或符号名(GPIOC.ODR)都行。");
260
+ continue;
261
+ }
262
+ const key = normalizeRefKey(text);
263
+ if (seenRefs.has(key)) {
264
+ notes.push("「" + text + "」重复了,只读一次");
265
+ continue;
266
+ }
267
+ seenRefs.add(key);
268
+ const numeric = parseAddressText(text);
269
+ if (numeric !== null) {
270
+ const description = device === null ? null : describeAddressSafe(device, numeric, env);
271
+ if (device === null && !noSvdNoted) {
272
+ noSvdNoted = true;
273
+ notes.push("没有可用的 SVD:这次只给值,没有名字与位域解释(" + SVD_FULL_PROFILE_HINT + ")");
274
+ }
275
+ pushTarget({
276
+ ref: text,
277
+ kind: "address",
278
+ name: description === null ? formatAddress(numeric) : description.peripheral + "." + description.register,
279
+ address: numeric,
280
+ peripheral: description === null ? "" : description.peripheral,
281
+ register: description === null ? "" : description.register,
282
+ size: description === null ? 32 : description.size,
283
+ fields: description === null ? [] : description.fields,
284
+ });
285
+ if (description !== null && !description.exact) {
286
+ notes.push("地址 " + formatAddress(numeric) + " 落在 " + description.peripheral + "." + description.register +
287
+ "(起点 " + formatAddress(description.address) + ")内部第 " + String(description.offsetInRegister) +
288
+ " 个字节;位域解释按整个寄存器算");
289
+ }
290
+ continue;
291
+ }
292
+ if (device === null) {
293
+ errors.push("「" + text + "」不是物理地址;符号名/外设名要靠 SVD 才能解析:" + SVD_FULL_PROFILE_HINT +
294
+ "(或者直接写 0x 开头的地址)。");
295
+ continue;
296
+ }
297
+ if (SYMBOL_PATTERN.test(text)) {
298
+ try {
299
+ const resolved = resolveRegisterRef(text, device.line, env);
300
+ pushTarget({
301
+ ref: text,
302
+ kind: "register",
303
+ name: resolved.peripheral + "." + resolved.register,
304
+ address: resolved.address,
305
+ peripheral: resolved.peripheral,
306
+ register: resolved.register,
307
+ size: resolved.size,
308
+ fields: resolved.fields,
309
+ });
310
+ }
311
+ catch (error) {
312
+ if (error instanceof SvdError) {
313
+ const groups = SYMBOL_PATTERN.exec(text);
314
+ const wanted = groups === null || groups[1] === undefined ? text : groups[1];
315
+ // 外设写错是最常见的笔误:这里统一列出该 line 的前 N 个外设(不把 SVD 的内部文案直接甩给用户)。
316
+ errors.push(error.code === "peripheral-unknown"
317
+ ? "内置资源(line=" + device.line + ")里没有外设 " + wanted.toUpperCase() +
318
+ ";可用外设(前 " + String(REGS_SUGGEST_PERIPHERALS) + " 个):" +
319
+ suggestPeripheralNames(device, wanted).join("、") + "(共 " +
320
+ String(device.counts.peripherals) + " 个)"
321
+ : error.message);
322
+ continue;
323
+ }
324
+ throw error;
325
+ }
326
+ continue;
327
+ }
328
+ const peripheral = BARE_NAME_PATTERN.test(text) ? lookupPeripheral(device, text) : null;
329
+ if (peripheral !== null) {
330
+ dumpPeripheral(peripheral);
331
+ continue;
332
+ }
333
+ errors.push("内置资源(line=" + device.line + ")里没有外设 " + text.toUpperCase() +
334
+ ",也不像 GPIOC.ODR 这种寄存器写法;可用外设(前 " + String(REGS_SUGGEST_PERIPHERALS) + " 个):" +
335
+ suggestPeripheralNames(device, text).join("、") + "(共 " + String(device.counts.peripherals) + " 个)");
336
+ }
337
+ return { addresses, targets, errors, notes };
338
+ }
339
+ /* ------------------------------ 读回来的值 → 位域 ------------------------------ */
340
+ /**
341
+ * 把 engine 的原始样本配上 ref/name/fields。
342
+ *
343
+ * 为什么在工具层做而不是改 engine:readWordsViaSession / gdb 那条路只认地址(它们不该知道 SVD);
344
+ * 这里按绝对地址把 target 找回来,再拿 SVD 的位域拆值,两边互不侵入。
345
+ */
346
+ export function decorateSamples(rawSamples, targets) {
347
+ const byAddress = new Map();
348
+ for (const target of targets) {
349
+ if (!byAddress.has(target.address))
350
+ byAddress.set(target.address, target);
351
+ }
352
+ const samples = [];
353
+ for (const sample of rawSamples) {
354
+ const numeric = parseAddressText(sample.address);
355
+ // 地址统一成 8 位大写,跟 ref/name 和报告里的写法对齐(engine 那条路给的是小写)。
356
+ const address = numeric === null ? sample.address : formatAddress(numeric);
357
+ const target = numeric === null ? undefined : byAddress.get(numeric);
358
+ const fields = [];
359
+ if (sample.ok && target !== undefined && target.fields.length > 0) {
360
+ try {
361
+ const decoded = decodeRegisterValue({ name: target.register, addressOffset: 0, size: target.size, access: "", fields: target.fields }, sample.value);
362
+ for (const field of decoded.set) {
363
+ fields.push({ name: field.name, bits: formatBits(field.bitOffset, field.bitWidth), value: field.value });
364
+ }
365
+ }
366
+ catch {
367
+ // 值不是合法十六进制(openocd 偶尔给 "0x????????"):保留读值,只是不解释位域。
368
+ }
369
+ }
370
+ samples.push({
371
+ address,
372
+ value: sample.value,
373
+ ok: sample.ok,
374
+ ref: target === undefined ? address : target.ref,
375
+ name: target === undefined ? address : target.name,
376
+ fields,
377
+ });
378
+ }
379
+ return samples;
380
+ }
381
+ /** 一行人话:GPIOC.ODR (0x4001100C) = 0x00000004 → ODR2=1 */
382
+ export function describeRegSample(sample) {
383
+ const named = sample.name !== "" && sample.name.toUpperCase() !== sample.address.toUpperCase();
384
+ const head = (named ? sample.name + " (" + sample.address + ")" : sample.address) + " = " +
385
+ (sample.ok ? sample.value : "(读不到)");
386
+ if (sample.fields.length === 0)
387
+ return head;
388
+ return head + " → " + sample.fields.map((field) => field.name + "=" + String(field.value)).join(", ");
389
+ }
390
+ /* ------------------------------ 报告 ------------------------------ */
59
391
  function formatReport(report) {
60
392
  const lines = [];
61
393
  lines.push((report.ok ? "读取完成" : "读取失败") + ":" + report.message);
62
394
  if (report.pc !== "")
63
395
  lines.push("pc = " + report.pc);
64
396
  for (const sample of report.samples)
65
- lines.push(" " + describeSample(sample));
397
+ lines.push(" " + describeRegSample(sample));
66
398
  if (report.configFile !== "")
67
399
  lines.push("openocd 配置:" + report.configFile);
68
400
  for (const note of report.notes)
@@ -78,22 +410,27 @@ function formatReport(report) {
78
410
  }
79
411
  function failureReport(projectDir, message, errors) {
80
412
  return {
81
- ok: false, projectDir, configFile: "", command: "", script: "", pc: "",
413
+ ok: false, reusedSession: false, projectDir, configFile: "", command: "", script: "", pc: "",
82
414
  samples: [], durationMs: 0, errors, message, logTail: "", notes: [],
83
415
  };
84
416
  }
85
417
  export function registerRegsRead(ctx) {
86
418
  ctx.tools.register({
87
419
  name: REGS_TOOL,
88
- description: "读 STM32 内存映射寄存器(物理地址,如 GPIOC_ODR=0x4001100C、AFIO_MAPR=0x40010004):起 openocd → halt → mdw → resume → shutdown,不复位芯片、一次性拿值后立刻释放探针。用来自证固件在跑(例如看 ODR 位在翻转)。",
420
+ description: "读 STM32 内存映射寄存器:addresses 每项可以是物理地址(0x4001100C / GPIOC_ODR=0x4001100C 这种)、符号名(GPIOC.ODR / GPIOC->ODR / RCC.CR),或只给外设名(GPIOC = 把该外设的寄存器整体 dump 一遍,最多 " +
421
+ String(REG_DUMP_MAX) + " 个)。有 SVD(随插件内置,profile=full 也随包安装)时每条样本带规范化名 name 与置位位域 fields;没有 SVD 时自动退回纯地址读,只是没有名字/位域。复用常驻调试会话的 openocd(B3:Tcl RPC 直读,毫秒级;没有会话就先起一个并保留到租约到期),halt → mdw → resume 不复位芯片;Tcl 不可用时回退 gdb。用来自证固件在跑(例如看 ODR 位在翻转)。",
89
422
  parameters: {
90
423
  type: "object",
91
424
  additionalProperties: false,
92
425
  properties: {
93
- projectDir: { type: "string", description: "工程根目录(用于找 openocd.cfg);缺省为当前工作目录。" },
94
- addresses: { type: "array", items: { type: "string" }, description: "要读的物理地址,可带或不带 0x,例如 [\"0x4001100C\"]。" },
95
- configFile: { type: "string", description: "openocd 配置文件(相对工程目录)。" },
96
- adapterSpeed: { type: "number", description: "adapter speed(kHz)。" },
426
+ projectDir: { type: "string", description: "工程根目录(用于找 openocd.cfg 与 .ioc 里的型号);缺省为当前工作目录。" },
427
+ addresses: {
428
+ type: "array",
429
+ items: { type: "string" },
430
+ description: "要读的寄存器,每项可以是:物理地址(0x4001100C,可带或不带 0x)、符号名(GPIOC.ODR、GPIOC->ODR、RCC.CR),或外设名(GPIOC = dump 该外设全部寄存器)。",
431
+ },
432
+ configFile: { type: "string", description: "openocd 配置文件(相对工程目录;新起会话时生效)。" },
433
+ adapterSpeed: { type: "number", description: "adapter speed(kHz;新起会话时生效)。" },
97
434
  timeoutMs: { type: "number", description: "超时毫秒数,默认 30000。" },
98
435
  binDirs: { type: "array", items: { type: "string" }, description: "工具链目录候选。" },
99
436
  envCheck: ENV_CHECK_SCHEMA,
@@ -120,7 +457,21 @@ export function registerRegsRead(ctx) {
120
457
  return { message: invalid, report: failureReport(typeof args.projectDir === "string" ? args.projectDir : "", invalid, [invalid]) };
121
458
  }
122
459
  const resolution = await resolveProjectDir(ctx, args.projectDir, exec);
123
- // 门禁:读寄存器要 openocd(或已有会话里的那个)。放在借用会话之前判断,
460
+ // D2:先把符号名/外设名解析成地址(零成本、不占探针)。解析不了就直接失败——
461
+ // 没解析清楚就去借探针,等于白占一次硬件。
462
+ const svd = resolveProjectSvd(resolution.projectDir);
463
+ const plan = planRegReads(args.addresses, svd.device);
464
+ const planNotes = [svd.note, ...plan.notes];
465
+ const planErrors = plan.errors.length > 0
466
+ ? [...plan.errors]
467
+ : (plan.addresses.length === 0 ? ["addresses 里没有可读的项(都是空串/重复?)"] : []);
468
+ if (planErrors.length > 0) {
469
+ const message = "寄存器写法解析失败:" + (planErrors[0] ?? "");
470
+ const report = failureReport(resolution.projectDir, message, planErrors);
471
+ report.notes = planNotes;
472
+ return { message, report };
473
+ }
474
+ // 门禁:读寄存器要 openocd(或已有会话里的那个)。放在借会话之前判断,
124
475
  // 两种取词方式都不会在缺件时白跑一趟。
125
476
  const gate = await ensureToolchain(ctx, {
126
477
  capability: "debug",
@@ -128,68 +479,109 @@ export function registerRegsRead(ctx) {
128
479
  envCheck: args.envCheck,
129
480
  signal: exec.signal,
130
481
  });
482
+ const gateNotes = gate.ok ? [] : gateReportNotes(gate);
131
483
  if (!gate.ok && gate.mode === "block") {
132
484
  const blocked = failureReport(resolution.projectDir, gate.message, []);
133
- blocked.notes = gateReportNotes(gate);
485
+ blocked.notes = [...planNotes, ...gateNotes];
134
486
  return { message: blocked.message, report: blocked };
135
487
  }
136
- // 洞 D:有调试会话时不能再起一个 openocd —— 同一块 CMSIS-DAP 被两个进程抢会报
137
- // "CMSIS-DAP transfer count mismatch"。直接借会话的 gdb 读,halt → 读 → resume。
138
- if (debugSessions.isActive()) {
139
- const words = await debugSessions.readWords({
140
- addresses: args.addresses,
141
- ...(args.timeoutMs === undefined ? {} : { timeoutMs: args.timeoutMs }),
142
- signal: exec.signal,
143
- });
144
- const notes = gate.ok ? [] : [gate.message];
145
- notes.push("复用调试会话(端口 " + String(words.port) + ")的 openocd,没有另起一个");
146
- // A19:借用会话时 openocd 是会话里那个,这两个参数没法改,别让用户以为生效了。
147
- if ((args.configFile !== undefined && args.configFile !== "") || args.adapterSpeed !== undefined) {
148
- notes.push("这次借用了已有会话:configFile / adapterSpeed 不生效(openocd 是会话里那个,已按会话参数在跑)。" +
149
- "要按新参数读,先 stm32_debug_stop 再调 stm32_regs_read。");
150
- }
151
- if (resolution.note !== null)
152
- notes.push(resolution.note);
153
- if (words.projectDir !== "" && words.projectDir !== resolution.projectDir) {
154
- notes.push("会话的工程目录是 " + words.projectDir + ",与本次参数的 " + resolution.projectDir + " 不同(读值用的是会话里的那个)");
155
- }
156
- return {
157
- message: words.message,
158
- report: {
159
- ok: words.ok,
160
- projectDir: words.projectDir === "" ? resolution.projectDir : words.projectDir,
161
- configFile: "",
162
- command: words.command,
163
- script: "",
164
- pc: words.pc,
165
- samples: words.samples,
166
- durationMs: words.durationMs,
167
- errors: words.errors,
168
- message: words.message,
169
- logTail: words.output.split(/\r?\n/u).slice(-12).join("\n"),
170
- notes,
171
- },
172
- };
173
- }
174
488
  const subprocess = ctx.get("subprocess");
175
489
  if (subprocess === undefined) {
176
490
  const message = "宿主缺少 subprocess 服务,无法读寄存器";
177
491
  return { message, report: failureReport(resolution.projectDir, message, [message]) };
178
492
  }
179
- const report = await runRegsRead(subprocess, {
180
- projectDir: resolution.projectDir,
181
- addresses: args.addresses,
182
- ...(args.configFile === undefined ? {} : { configFile: args.configFile }),
493
+ // B3:有会话就复用(不重新起 openocd);没有就起一个,保留到租约到期(90 s 空闲 / turn 结束)。
494
+ const ensured = await ensureSession(resolution.projectDir, {
495
+ subprocess,
496
+ ...(args.binDirs === undefined ? {} : { binDirs: args.binDirs }),
497
+ ...(args.configFile === undefined || args.configFile === "" ? {} : { configFile: args.configFile }),
183
498
  ...(args.adapterSpeed === undefined ? {} : { adapterSpeed: args.adapterSpeed }),
499
+ ...(exec.agent?.id === undefined ? {} : { owner: exec.agent.id }),
500
+ });
501
+ if (!ensured.ok || ensured.session === null) {
502
+ // 端口被占(probe-busy)等:直接说清是哪一类,不让 openocd 顺延端口偷偷抢探针。
503
+ const evidence = ensured.probeError === null ? [] : ensured.probeError.evidence;
504
+ const report = failureReport(resolution.projectDir, ensured.message, evidence.length > 0 ? [...evidence] : [ensured.message]);
505
+ report.notes = [...planNotes, ...gateNotes, ...(resolution.note === null ? [] : [resolution.note])];
506
+ return { message: report.message, report };
507
+ }
508
+ const startedAt = Date.now();
509
+ const notes = [...planNotes, ...gateNotes];
510
+ // 快路径:Tcl RPC 直读(毫秒级)。
511
+ const fast = await readWordsViaSession({
512
+ addresses: plan.addresses,
184
513
  ...(args.timeoutMs === undefined ? {} : { timeoutMs: args.timeoutMs }),
185
- ...(args.binDirs === undefined ? {} : { binDirs: args.binDirs }),
186
514
  signal: exec.signal,
187
515
  });
188
- if (!gate.ok)
189
- report.notes.unshift(gate.message);
516
+ let ok = false;
517
+ let pc = "";
518
+ let rawSamples = [];
519
+ let command = "";
520
+ let output = "";
521
+ let errors = [];
522
+ let viaTcl = false;
523
+ if (fast.ok) {
524
+ ok = true;
525
+ viaTcl = true;
526
+ pc = fast.pc;
527
+ rawSamples = fast.samples;
528
+ command = fast.command;
529
+ output = fast.output;
530
+ }
531
+ else {
532
+ // 回退:会话里的 gdb -batch(慢一些,但不会挡探针、也不会撞上 openocd 的"转移计数不一致")。
533
+ const gdb = await debugSessions.readWords({
534
+ addresses: plan.addresses,
535
+ ...(args.timeoutMs === undefined ? {} : { timeoutMs: args.timeoutMs }),
536
+ signal: exec.signal,
537
+ });
538
+ ok = gdb.ok;
539
+ pc = gdb.pc;
540
+ rawSamples = gdb.samples;
541
+ command = gdb.command;
542
+ output = gdb.output;
543
+ errors = gdb.errors;
544
+ notes.push("Tcl 快路径没成(" + (fast.error ?? "未知原因") + "),回退到会话里的 gdb 读(慢一些)");
545
+ }
546
+ const durationMs = Date.now() - startedAt;
547
+ const samples = decorateSamples(rawSamples, plan.targets);
548
+ notes.push((ensured.reused ? "复用调试会话" : "新起调试会话") +
549
+ "(gdb 端口 " + String(ensured.session.port) + ",tcl 端口 " + String(ensured.session.tclPort) +
550
+ "),没有另起 openocd;这次走" + (viaTcl ? " Tcl RPC 直读" : "会话里的 gdb"));
551
+ // A19:借用会话时 openocd 是会话里那个,这两个参数没法改,别让用户以为生效了。
552
+ if (ensured.reused && ((args.configFile !== undefined && args.configFile !== "") || args.adapterSpeed !== undefined)) {
553
+ notes.push("这次借用了已有会话:configFile / adapterSpeed 不生效(openocd 是会话里那个,已按会话参数在跑)。" +
554
+ "要按新参数读,先 stm32_debug_stop 再调 " + REGS_TOOL + "。");
555
+ }
190
556
  if (resolution.note !== null)
191
- report.notes.push(resolution.note);
192
- return { message: report.message, report };
557
+ notes.push(resolution.note);
558
+ if (ensured.session.projectDir !== "" && ensured.session.projectDir !== resolution.projectDir) {
559
+ notes.push("会话的工程目录是 " + ensured.session.projectDir + ",与本次参数的 " + resolution.projectDir + " 不同(读值用的是会话里的那个)");
560
+ }
561
+ const readValues = samples.filter((sample) => sample.ok).length;
562
+ const unit = plan.targets.some((target) => target.kind !== "address") ? "个寄存器" : "个地址";
563
+ const clean = ok && errors.length === 0;
564
+ const message = clean
565
+ ? "读到 " + String(readValues) + " " + unit + "(pc=" + (pc === "" ? "未知" : pc) + "," + String(durationMs) + " ms" + (viaTcl ? ",复用会话 Tcl 直读" : "") + ")"
566
+ : "读寄存器失败:" + (errors[0] ?? fast.error ?? "未知原因");
567
+ return {
568
+ message,
569
+ report: {
570
+ ok: clean,
571
+ reusedSession: ensured.reused,
572
+ projectDir: ensured.session.projectDir === "" ? resolution.projectDir : ensured.session.projectDir,
573
+ configFile: ensured.session.configFile,
574
+ command,
575
+ script: "",
576
+ pc,
577
+ samples,
578
+ durationMs,
579
+ errors,
580
+ message,
581
+ logTail: output.split(/\r?\n/u).slice(-12).join("\n"),
582
+ notes,
583
+ },
584
+ };
193
585
  },
194
586
  });
195
587
  }
@@ -8,6 +8,9 @@
8
8
  * 输出是"每个外设的代价/风险 + 一条建议",外加工具链分流:
9
9
  * · pacman 能补的(gcc/gdb/openocd/cmake/ninja)→ 可代装,给 stm32_env_install 的路
10
10
  * · CubeMX / 固件包 → 只能人装,给 guides[](含离线整目录拷贝的做法)
11
+ *
12
+ * 不需要设备事实:评分只看 .ioc 与需求里的外设清单(芯片型号取自 .ioc 的 Mcu.CPN),
13
+ * 不查内置资源,所以不在这里 ensureAssets。
11
14
  */
12
15
  import { readFileSync } from "node:fs";
13
16
  import { resolveSearchConfig } from "../data/search-roots.js";