@turingcode/cli 0.2.13 → 0.3.5

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 (185) hide show
  1. package/README.md +2 -0
  2. package/dist/cli/create-cli.d.ts +10 -0
  3. package/dist/cli/create-cli.js +17 -4
  4. package/dist/cli/index.d.ts +9 -0
  5. package/dist/cli/index.js +5 -1
  6. package/dist/core/bound-error.d.ts +10 -0
  7. package/dist/core/date.d.ts +12 -0
  8. package/dist/core/exact/expression.d.ts +49 -0
  9. package/dist/core/exact/fraction.d.ts +85 -0
  10. package/dist/core/exact/fraction.js +2 -0
  11. package/dist/core/files.d.ts +44 -0
  12. package/dist/core/files.js +48 -3
  13. package/dist/core/json-shape.d.ts +45 -0
  14. package/dist/core/json-shape.js +1 -0
  15. package/dist/core/mcp.d.ts +92 -0
  16. package/dist/core/mcp.js +56 -15
  17. package/dist/core/query.d.ts +69 -0
  18. package/dist/core/query.js +2 -2
  19. package/dist/core/report.d.ts +11 -0
  20. package/dist/core/tables/csv.d.ts +29 -0
  21. package/dist/core/tables/csv.js +54 -25
  22. package/dist/core/tables/markdown.d.ts +22 -0
  23. package/dist/core/tables/markdown.js +8 -2
  24. package/dist/core/tables/types.d.ts +25 -0
  25. package/dist/features/contract/check.d.ts +30 -0
  26. package/dist/features/contract/command.d.ts +12 -0
  27. package/dist/features/contract/command.js +64 -64
  28. package/dist/features/contract/describe.d.ts +22 -0
  29. package/dist/features/contract/diagnostics.d.ts +111 -0
  30. package/dist/features/contract/diagnostics.js +7 -4
  31. package/dist/features/contract/load.d.ts +58 -0
  32. package/dist/features/contract/load.js +4 -4
  33. package/dist/features/contract/model.d.ts +67 -0
  34. package/dist/features/contract/rules.d.ts +149 -0
  35. package/dist/features/contract/rules.js +31 -4
  36. package/dist/features/debug/clear_breakpoint.d.ts +3 -0
  37. package/dist/features/debug/clear_breakpoint.js +24 -0
  38. package/dist/features/debug/command.d.ts +5 -0
  39. package/dist/features/debug/command.js +66 -0
  40. package/dist/features/debug/continue.d.ts +3 -0
  41. package/dist/features/debug/continue.js +22 -0
  42. package/dist/features/debug/debug_start.d.ts +3 -0
  43. package/dist/features/debug/debug_start.js +22 -0
  44. package/dist/features/debug/debug_stop.d.ts +3 -0
  45. package/dist/features/debug/debug_stop.js +11 -0
  46. package/dist/features/debug/evaluate.d.ts +3 -0
  47. package/dist/features/debug/evaluate.js +48 -0
  48. package/dist/features/debug/get_stack.d.ts +3 -0
  49. package/dist/features/debug/get_stack.js +14 -0
  50. package/dist/features/debug/get_variables.d.ts +3 -0
  51. package/dist/features/debug/get_variables.js +26 -0
  52. package/dist/features/debug/halt.d.ts +3 -0
  53. package/dist/features/debug/halt.js +16 -0
  54. package/dist/features/debug/set_breakpoint.d.ts +3 -0
  55. package/dist/features/debug/set_breakpoint.js +30 -0
  56. package/dist/features/debug/step.d.ts +3 -0
  57. package/dist/features/debug/step.js +23 -0
  58. package/dist/features/install-mods/command.d.ts +6 -0
  59. package/dist/features/install-mods/command.js +18 -0
  60. package/dist/features/install-mods/install.d.ts +23 -0
  61. package/dist/features/install-mods/install.js +49 -0
  62. package/dist/features/install-skills/command.d.ts +7 -0
  63. package/dist/features/install-skills/command.js +22 -0
  64. package/dist/features/install-skills/install.d.ts +14 -0
  65. package/dist/features/install-skills/install.js +29 -0
  66. package/dist/features/probe/command.d.ts +5 -0
  67. package/dist/features/probe/command.js +112 -0
  68. package/dist/features/probe/kill_all_debuggers.d.ts +3 -0
  69. package/dist/features/probe/kill_all_debuggers.js +50 -0
  70. package/dist/features/probe/list_probes.d.ts +3 -0
  71. package/dist/features/probe/list_probes.js +8 -0
  72. package/dist/features/probe/program_project.d.ts +3 -0
  73. package/dist/features/probe/program_project.js +29 -0
  74. package/dist/features/probe/read_fault_status.d.ts +3 -0
  75. package/dist/features/probe/read_fault_status.js +19 -0
  76. package/dist/features/probe/read_memory.d.ts +3 -0
  77. package/dist/features/probe/read_memory.js +36 -0
  78. package/dist/features/probe/read_peripheral.d.ts +3 -0
  79. package/dist/features/probe/read_peripheral.js +60 -0
  80. package/dist/features/probe/reset_probe_usb.d.ts +3 -0
  81. package/dist/features/probe/reset_probe_usb.js +17 -0
  82. package/dist/features/probe/reset_target.d.ts +3 -0
  83. package/dist/features/probe/reset_target.js +16 -0
  84. package/dist/features/probe/target_info.d.ts +3 -0
  85. package/dist/features/probe/target_info.js +34 -0
  86. package/dist/features/project/analysis_static.d.ts +3 -0
  87. package/dist/features/project/analysis_static.js +19 -0
  88. package/dist/features/project/analysis_syntax_check.d.ts +3 -0
  89. package/dist/features/project/analysis_syntax_check.js +21 -0
  90. package/dist/features/project/command.d.ts +5 -0
  91. package/dist/features/project/command.js +64 -0
  92. package/dist/features/project/project_build.d.ts +3 -0
  93. package/dist/features/project/project_build.js +22 -0
  94. package/dist/features/project/project_download_template.d.ts +3 -0
  95. package/dist/features/project/project_download_template.js +34 -0
  96. package/dist/features/project/project_regenerate.d.ts +2 -0
  97. package/dist/features/project/project_regenerate.js +20 -0
  98. package/dist/features/project/project_sync_from_server.d.ts +2 -0
  99. package/dist/features/project/project_sync_from_server.js +13 -0
  100. package/dist/features/project/project_sync_to_server.d.ts +2 -0
  101. package/dist/features/project/project_sync_to_server.js +51 -0
  102. package/dist/features/project/stm32_cubetools_download_drivers.d.ts +3 -0
  103. package/dist/features/project/stm32_cubetools_download_drivers.js +19 -0
  104. package/dist/features/status/command.d.ts +2 -0
  105. package/dist/features/status/command.js +6 -0
  106. package/dist/features/status/get_status.d.ts +3 -0
  107. package/dist/features/status/get_status.js +44 -0
  108. package/dist/features/table/check.d.ts +38 -0
  109. package/dist/features/table/check.js +5 -5
  110. package/dist/features/table/command.d.ts +3 -0
  111. package/dist/features/table/read.d.ts +28 -0
  112. package/dist/features/table/read.js +9 -9
  113. package/dist/features/tool/command.d.ts +35 -0
  114. package/dist/features/tool/command.js +95 -66
  115. package/dist/lib.d.ts +15 -0
  116. package/dist/lib.js +11 -0
  117. package/dist/stm32/actions/DebugAction.d.ts +65 -0
  118. package/dist/stm32/actions/DebugAction.js +106 -0
  119. package/dist/stm32/actions/DebugActionInfo.d.ts +11 -0
  120. package/dist/stm32/actions/DebugActionInfo.js +11 -0
  121. package/dist/stm32/actions/DebugActionListProbes.d.ts +10 -0
  122. package/dist/stm32/actions/DebugActionListProbes.js +10 -0
  123. package/dist/stm32/actions/DebugActionProgram.d.ts +34 -0
  124. package/dist/stm32/actions/DebugActionProgram.js +81 -0
  125. package/dist/stm32/actions/DebugActionRead.d.ts +39 -0
  126. package/dist/stm32/actions/DebugActionRead.js +61 -0
  127. package/dist/stm32/actions/DebugActionReset.d.ts +12 -0
  128. package/dist/stm32/actions/DebugActionReset.js +9 -0
  129. package/dist/stm32/actions/DebugActionServer.d.ts +11 -0
  130. package/dist/stm32/actions/DebugActionServer.js +11 -0
  131. package/dist/stm32/analysis.d.ts +20 -0
  132. package/dist/stm32/analysis.js +21 -0
  133. package/dist/stm32/build.d.ts +34 -0
  134. package/dist/stm32/build.js +79 -0
  135. package/dist/stm32/context.d.ts +23 -0
  136. package/dist/stm32/context.js +42 -0
  137. package/dist/stm32/daemon.d.ts +65 -0
  138. package/dist/stm32/daemon.js +209 -0
  139. package/dist/stm32/regen.d.ts +68 -0
  140. package/dist/stm32/regen.js +231 -0
  141. package/dist/stm32/session.d.ts +137 -0
  142. package/dist/stm32/session.js +375 -0
  143. package/dist/stm32/sync.d.ts +25 -0
  144. package/dist/stm32/sync.js +74 -0
  145. package/dist/stm32/tool.d.ts +45 -0
  146. package/dist/stm32/tool.js +20 -0
  147. package/dist/stm32/toolCommand.d.ts +50 -0
  148. package/dist/stm32/toolCommand.js +100 -0
  149. package/dist/stm32/utils/discover_tools.d.ts +25 -0
  150. package/dist/stm32/utils/discover_tools.js +121 -0
  151. package/dist/stm32/utils/downloadzip_utils.d.ts +57 -0
  152. package/dist/stm32/utils/downloadzip_utils.js +180 -0
  153. package/dist/stm32/utils/faultUtils.d.ts +15 -0
  154. package/dist/stm32/utils/faultUtils.js +69 -0
  155. package/dist/stm32/utils/findElf.d.ts +9 -0
  156. package/dist/stm32/utils/findElf.js +19 -0
  157. package/dist/stm32/utils/hash_utils.d.ts +19 -0
  158. package/dist/stm32/utils/hash_utils.js +28 -0
  159. package/dist/stm32/utils/listSyncFiles.d.ts +9 -0
  160. package/dist/stm32/utils/listSyncFiles.js +100 -0
  161. package/dist/stm32/utils/mcu_utils.d.ts +58 -0
  162. package/dist/stm32/utils/mcu_utils.js +100 -0
  163. package/dist/stm32/utils/project_utils.d.ts +54 -0
  164. package/dist/stm32/utils/project_utils.js +104 -0
  165. package/dist/stm32/utils/svdUtils.d.ts +31 -0
  166. package/dist/stm32/utils/svdUtils.js +30 -0
  167. package/dist/stm32/utils/truncate.d.ts +7 -0
  168. package/dist/stm32/utils/truncate.js +9 -0
  169. package/dist/stm32/utils/usb_utils.d.ts +5 -0
  170. package/dist/stm32/utils/usb_utils.js +23 -0
  171. package/dist/stm32/utils/user_code.d.ts +17 -0
  172. package/dist/stm32/utils/user_code.js +45 -0
  173. package/dist/stm32/utils/utils_mutex.d.ts +15 -0
  174. package/dist/stm32/utils/utils_mutex.js +113 -0
  175. package/dist/stm32/validate.d.ts +17 -0
  176. package/dist/stm32/validate.js +46 -0
  177. package/mods/claude/.claude-plugin/marketplace.json +8 -0
  178. package/mods/claude/turingcode-skills/.claude-plugin/plugin.json +5 -0
  179. package/mods/claude/turingcode-skills/skills/turingcode-cli/SKILL.md +44 -0
  180. package/mods/claude/turingcode-skills/skills/turingcode-firmware-code/SKILL.md +47 -0
  181. package/mods/claude/turingcode-skills/skills/turingcode-firmware-code/references/concurrency.md +42 -0
  182. package/mods/claude/turingcode-skills/skills/turingcode-firmware-code/references/init-and-timing.md +35 -0
  183. package/mods/claude/turingcode-skills/skills/turingcode-firmware-code/references/input-and-bounds.md +21 -0
  184. package/mods/claude/turingcode-skills/skills/turingcode-firmware-code/references/registers-and-units.md +35 -0
  185. package/package.json +11 -3
@@ -0,0 +1,29 @@
1
+ import { _defineTool } from '../../stm32/tool.js';
2
+ import { findStm32Project } from '../../stm32/utils/project_utils.js';
3
+ import { getMcuFromIoc } from '../../stm32/utils/mcu_utils.js';
4
+ import { findElf } from '../../stm32/utils/findElf.js';
5
+ import { DebugActionProgram } from '../../stm32/actions/DebugActionProgram.js';
6
+ /** Flashes the newest ELF in the project's build/ folder. */
7
+ export default _defineTool({
8
+ name: 'program_project',
9
+ description: "Flash the newest .elf in the project's build/ folder \
10
+ (downloaded by `turingcode project build`) to the board over SWD with the installed programmer (probe-rs or STM32_Programmer_CLI), \
11
+ verify it and reset the target.",
12
+ needsProbe: true,
13
+ run: async (_args, ctx) => {
14
+ const project = await findStm32Project();
15
+ const elf = await findElf(project.root);
16
+ if (!elf)
17
+ throw new Error("No .elf in the project's build/ folder: run `turingcode project build` first");
18
+ const chip = await getMcuFromIoc(project.root);
19
+ const program_result = await DebugActionProgram.run_action_get_tail({
20
+ elf: elf.path,
21
+ chip,
22
+ }).catch((e) => {
23
+ throw new Error(`${e?.message ?? e}\n\nIf the probe does not answer \
24
+ (USB sleep, DEV_USB_COMM_ERR, probe not found), \
25
+ run \`turingcode probe reset-usb\` and try again once.`);
26
+ });
27
+ return `Programmed ${elf.path} (${chip})\n\n${program_result}`;
28
+ },
29
+ });
@@ -0,0 +1,3 @@
1
+ /** Reads and decodes the SCB fault status registers. */
2
+ declare const _default: import("../../stm32/tool.js").ToolDef;
3
+ export default _default;
@@ -0,0 +1,19 @@
1
+ import { _defineTool } from '../../stm32/tool.js';
2
+ import { findStm32Project } from '../../stm32/utils/project_utils.js';
3
+ import { DebugActionRead } from '../../stm32/actions/DebugActionRead.js';
4
+ import { FAULT_REGS_ADDRESS, decodeFaultStatus } from '../../stm32/utils/faultUtils.js';
5
+ import { getMcuFromIoc, isArmv6m } from '../../stm32/utils/mcu_utils.js';
6
+ /** Reads and decodes the SCB fault status registers. */
7
+ export default _defineTool({
8
+ name: 'read_fault_status',
9
+ description: 'Read and decode the Cortex-M fault status registers (CFSR, HFSR, DFSR, MMFAR, BFAR, AFSR) over SWD (probe-rs or STM32_Programmer_CLI), without halting the core. Use it after the board hangs in HardFault_Handler.',
10
+ needsProbe: true,
11
+ run: async (_args, ctx) => {
12
+ const project = await findStm32Project();
13
+ const chip = await getMcuFromIoc(project.root);
14
+ if (isArmv6m(chip))
15
+ return `${chip} has a Cortex-M0/M0+ core, which has no fault status registers: every fault is a plain HardFault.`;
16
+ const { words: regs } = await DebugActionRead.run_action({ chip, address: FAULT_REGS_ADDRESS, width: 32, count: 6 });
17
+ return `Fault status of ${chip}\n\n${decodeFaultStatus(regs)}`;
18
+ },
19
+ });
@@ -0,0 +1,3 @@
1
+ /** Reads target memory while the core keeps running. */
2
+ declare const _default: import("../../stm32/tool.js").ToolDef;
3
+ export default _default;
@@ -0,0 +1,36 @@
1
+ import { _defineTool } from '../../stm32/tool.js';
2
+ import { findStm32Project } from '../../stm32/utils/project_utils.js';
3
+ import { getMcuFromIoc } from '../../stm32/utils/mcu_utils.js';
4
+ import { hex } from '../../stm32/utils/faultUtils.js';
5
+ import { DebugActionRead } from '../../stm32/actions/DebugActionRead.js';
6
+ /** Reads target memory while the core keeps running. */
7
+ export default _defineTool({
8
+ name: 'read_memory',
9
+ description: "Read target memory over SWD (probe-rs or STM32_Programmer_CLI) without halting the core, at most 4096 bytes per call. Width defaults to the widest one the address and length allow; use 32 for peripheral registers.",
10
+ properties: {
11
+ address: { type: 'string', pattern: '^0x[0-9A-Fa-f]{1,8}$' },
12
+ length: { type: 'integer', minimum: 1, maximum: 4096, description: 'Bytes to read' },
13
+ width: { type: 'string', enum: ['8', '16', '32'], description: 'Access width in bits' },
14
+ },
15
+ required: ['address', 'length'],
16
+ needsProbe: true,
17
+ run: async (args, ctx) => {
18
+ const address = parseInt(args.address, 16);
19
+ const length = args.length;
20
+ const fits = (bytes) => address % bytes === 0 && length % bytes === 0;
21
+ const width = (args.width ? Number(args.width) : fits(4) ? 32 : fits(2) ? 16 : 8);
22
+ if (!fits(width / 8))
23
+ throw new Error(`address and length must be multiples of ${width / 8} bytes for ${width}-bit reads`);
24
+ const project = await findStm32Project();
25
+ const chip = await getMcuFromIoc(project.root);
26
+ const { words } = await DebugActionRead.run_action({ chip, address, width, count: length / (width / 8) });
27
+ /** 16 bytes per line, each line prefixed with its address */
28
+ const perLine = 128 / width;
29
+ const lines = [];
30
+ for (let i = 0; i < words.length; i += perLine) {
31
+ const row = words.slice(i, i + perLine).map((w) => w.toString(16).toUpperCase().padStart(width / 4, '0'));
32
+ lines.push(`${hex(address + i * (width / 8))}: ${row.join(' ')}`);
33
+ }
34
+ return `${length} bytes from ${hex(address)} (${width}-bit, ${chip})\n\n${lines.join('\n')}`;
35
+ },
36
+ });
@@ -0,0 +1,3 @@
1
+ /** Reads a peripheral's registers and decodes them with the MCU's SVD data from the TuringCode server. */
2
+ declare const _default: import("../../stm32/tool.js").ToolDef;
3
+ export default _default;
@@ -0,0 +1,60 @@
1
+ import { callServer } from '../../stm32/context.js';
2
+ import { _defineTool } from '../../stm32/tool.js';
3
+ import { findStm32Project } from '../../stm32/utils/project_utils.js';
4
+ import { DebugActionRead } from '../../stm32/actions/DebugActionRead.js';
5
+ import { hex } from '../../stm32/utils/faultUtils.js';
6
+ import { getMcuFromIoc } from '../../stm32/utils/mcu_utils.js';
7
+ import { loadPeripheral } from '../../stm32/utils/svdUtils.js';
8
+ /** Reads a peripheral's registers and decodes them with the MCU's SVD data from the TuringCode server. */
9
+ export default _defineTool({
10
+ name: 'read_peripheral',
11
+ description: "Read and decode a peripheral's registers (e.g. GPIOA, USART2, TIM1, RCC) over SWD (probe-rs or STM32_Programmer_CLI), using the MCU's SVD data from the TuringCode server (needs TURINGCODE_TOKEN the first time per peripheral, then cached in .turingcode/svd/ and works offline). Does not halt the core. Data/FIFO registers whose read has side effects are skipped. Lists non-zero fields only.",
12
+ properties: { name: { type: 'string', pattern: '^[A-Za-z0-9_]{1,32}$' } },
13
+ required: ['name'],
14
+ needsProbe: true,
15
+ run: async (args) => {
16
+ const project = await findStm32Project();
17
+ const chip = await getMcuFromIoc(project.root);
18
+ /** The server sorts registers by offset and flags those not safe to read; cached after the first download */
19
+ const { peripheral: p } = await loadPeripheral(project.root, chip, args.name, callServer);
20
+ const regs = p.registers.filter((r) => r.safeToRead);
21
+ const skipped = p.registers.filter((r) => !r.safeToRead).map((r) => r.name);
22
+ /**
23
+ * Group registers into runs with gaps of at most 0x40 bytes, so each run is one memory read.
24
+ * A register not safe to read ends the run, so no read spans it.
25
+ */
26
+ const runs = [];
27
+ let open = false;
28
+ for (const r of p.registers) {
29
+ if (!r.safeToRead) {
30
+ open = false;
31
+ continue;
32
+ }
33
+ const last = runs.at(-1);
34
+ if (open && last && r.addressOffsetInt - last[last.length - 1].addressOffsetInt <= 0x40)
35
+ last.push(r);
36
+ else
37
+ runs.push([r]);
38
+ open = true;
39
+ }
40
+ const values = new Map();
41
+ for (const run of runs) {
42
+ /** Read whole words; a 16-bit register at offset 2 is the upper half of its word */
43
+ const start = run[0].addressOffsetInt & ~3;
44
+ const { words } = await DebugActionRead.run_action({ chip, address: p.baseAddressInt + start, width: 32, count: ((run[run.length - 1].addressOffsetInt - start) >> 2) + 1 });
45
+ for (const r of run)
46
+ values.set(r, words[(r.addressOffsetInt - start) >> 2] >>> ((r.addressOffsetInt & 3) * 8));
47
+ }
48
+ const lines = regs.map((r) => {
49
+ const v = values.get(r);
50
+ const fields = r.fields
51
+ .map((f) => ({ ...f, value: f.bitWidth >= 32 ? v : (v >>> f.bitOffset) & ((1 << f.bitWidth) - 1) }))
52
+ .filter((f) => f.value && !(r.fields.length === 1 && f.name === r.name))
53
+ .map((f) => `${f.name}=${f.bitWidth === 1 ? f.value : hex(f.value, 1)}`);
54
+ return `${r.name.padEnd(10)} ${hex(p.baseAddressInt + r.addressOffsetInt)} = ${hex(v)}${fields.length ? ` ${fields.join(' ')}` : ''}`;
55
+ });
56
+ if (skipped.length)
57
+ lines.push('', `Not read: ${skipped.join(', ')} (write-only or reading has side effects)`);
58
+ return `${p.name} @ ${hex(p.baseAddressInt)} (${chip}, ${p.svd})\n\n${lines.join('\n')}`;
59
+ },
60
+ });
@@ -0,0 +1,3 @@
1
+ /** Wakes an ST-LINK whose USB link went to sleep, which makes programming fail. */
2
+ declare const _default: import("../../stm32/tool.js").ToolDef;
3
+ export default _default;
@@ -0,0 +1,17 @@
1
+ import { _defineTool } from '../../stm32/tool.js';
2
+ import { claimProbe, releaseProbe } from '../../stm32/utils/utils_mutex.js';
3
+ import { resetStlinkUsb } from '../../stm32/utils/usb_utils.js';
4
+ /** Wakes an ST-LINK whose USB link went to sleep, which makes programming fail. */
5
+ export default _defineTool({
6
+ name: 'reset_probe_usb',
7
+ description: 'Restart the USB connection of every connected ST-LINK probe (Windows, pnputil). Use when programming or debugging fails \
8
+ because the probe does not answer (e.g. it is in USB sleep, DEV_USB_COMM_ERR, "probe not found"). Needs administrator rights.',
9
+ needsProbe: true,
10
+ run: async () => {
11
+ claimProbe('reset_probe_usb');
12
+ const restarted = await resetStlinkUsb().finally(releaseProbe);
13
+ return restarted.length
14
+ ? `Restarted: ${restarted.join(', ')}`
15
+ : 'No ST-LINK USB device is connected';
16
+ },
17
+ });
@@ -0,0 +1,3 @@
1
+ /** Resets the board over SWD; the chip comes from the project's .ioc. */
2
+ declare const _default: import("../../stm32/tool.js").ToolDef;
3
+ export default _default;
@@ -0,0 +1,16 @@
1
+ import { _defineTool } from '../../stm32/tool.js';
2
+ import { findStm32Project } from '../../stm32/utils/project_utils.js';
3
+ import { getMcuFromIoc } from '../../stm32/utils/mcu_utils.js';
4
+ import { DebugActionReset } from '../../stm32/actions/DebugActionReset.js';
5
+ /** Resets the board over SWD; the chip comes from the project's .ioc. */
6
+ export default _defineTool({
7
+ name: 'reset_target',
8
+ description: "Hardware reset of the project's target board over SWD (probe-rs or STM32_Programmer_CLI).",
9
+ needsProbe: true,
10
+ run: async (_args, ctx) => {
11
+ const project = await findStm32Project();
12
+ const chip = await getMcuFromIoc(project.root);
13
+ const reset_result = await DebugActionReset.run_action_get_tail({ chip });
14
+ return `Reset ${chip}\n\n${reset_result}`;
15
+ },
16
+ });
@@ -0,0 +1,3 @@
1
+ /** Identifies the connected chip and lists the CubeMX names that fit it, for `project template --mcu`. */
2
+ declare const _default: import("../../stm32/tool.js").ToolDef;
3
+ export default _default;
@@ -0,0 +1,34 @@
1
+ import { DebugActionInfo } from '../../stm32/actions/DebugActionInfo.js';
2
+ import { callServer } from '../../stm32/context.js';
3
+ import { _defineTool } from '../../stm32/tool.js';
4
+ import { deviceLines, lineFamily, matchMcuNames, parseTargetInfo } from '../../stm32/utils/mcu_utils.js';
5
+ /** Identifies the connected chip and lists the CubeMX names that fit it, for `project template --mcu`. */
6
+ export default _defineTool({
7
+ name: 'target_info',
8
+ description: 'Identify the chip connected to the debug probe (STM32_Programmer_CLI, without resetting it): device ID, name, flash size, core and voltage, ' +
9
+ 'and the CubeMX MCU names that match it for `turingcode project template --mcu` (needs TURINGCODE_TOKEN; the package and pin count cannot be read over SWD). Needs no project.',
10
+ needsProbe: true,
11
+ run: async () => {
12
+ const out = await DebugActionInfo.run_action({});
13
+ const info = parseTargetInfo(out.stdout + out.stderr);
14
+ if (!info.name)
15
+ throw new Error(`No target found: ${DebugActionInfo.tail(out)}`);
16
+ const lines = [
17
+ `Device: ${info.name} (ID ${info.deviceId ?? '?'})`,
18
+ `Flash: ${info.flashKb ?? '?'} KB, CPU: ${info.cpu ?? '?'}, voltage: ${info.voltage ?? '?'}`,
19
+ ];
20
+ const families = [...new Set(deviceLines(info.name).map(lineFamily))];
21
+ try {
22
+ const names = (await Promise.all(families.map((family) => callServer('list_mcu_names', { family }))))
23
+ .flatMap((text) => text.split('\n').map((l) => l.trim()).filter((l) => /^STM32\w+$/.test(l)));
24
+ const matches = matchMcuNames(names, info);
25
+ lines.push(matches.length
26
+ ? `MCU names for \`project template --mcu\` (pick the package; it can't be read over SWD): ${matches.join(', ')}`
27
+ : `No CubeMX MCU name matches; list them with \`turingcode tool call list_mcu_names --args '{"family":"${families[0]}"}'\``);
28
+ }
29
+ catch (e) {
30
+ lines.push(`MCU names not listed: ${e.message.split('\n')[0]}`);
31
+ }
32
+ return lines.join('\n');
33
+ },
34
+ });
@@ -0,0 +1,3 @@
1
+ /** Static analysis of the server copy of the project's own sources (never Drivers/). */
2
+ declare const _default: import("../../stm32/tool.js").ToolDef;
3
+ export default _default;
@@ -0,0 +1,19 @@
1
+ import { analyzeProject } from '../../stm32/analysis.js';
2
+ import { callServer } from '../../stm32/context.js';
3
+ import { _defineTool } from '../../stm32/tool.js';
4
+ import { findStm32Project } from '../../stm32/utils/project_utils.js';
5
+ /** Static analysis of the server copy of the project's own sources (never Drivers/). */
6
+ export default _defineTool({
7
+ name: 'analysis_static',
8
+ description: 'Static analysis of your stm32 project on the TuringCode server (its own sources, never Drivers/HAL/CMSIS; \
9
+ run `turingcode project sync` first to include local changes). Profiles: quick (cppcheck), full (cppcheck + clang-tidy) \
10
+ or misra (cppcheck MISRA C:2012). Returns `file:line:col: severity: message [check id]` lines.',
11
+ properties: {
12
+ profile: { type: 'string', enum: ['quick', 'full', 'misra'], description: 'default: quick' },
13
+ paths: { type: 'string', description: 'Comma-separated files, globs or folders to limit the check to (default: whole project)' },
14
+ },
15
+ run: async (args) => {
16
+ const project = await findStm32Project();
17
+ return analyzeProject(callServer, project, args.profile, args.paths);
18
+ },
19
+ });
@@ -0,0 +1,3 @@
1
+ /** Syntax-checks files of the server copy; local project-relative paths are mapped to projects/<name>/. */
2
+ declare const _default: import("../../stm32/tool.js").ToolDef;
3
+ export default _default;
@@ -0,0 +1,21 @@
1
+ import { syntaxCheckProject } from '../../stm32/analysis.js';
2
+ import { callServer } from '../../stm32/context.js';
3
+ import { _defineTool } from '../../stm32/tool.js';
4
+ import { findStm32Project } from '../../stm32/utils/project_utils.js';
5
+ /** Syntax-checks files of the server copy; local project-relative paths are mapped to projects/<name>/. */
6
+ export default _defineTool({
7
+ name: 'analysis_syntax_check',
8
+ description: 'Check .c/.h/.cpp/.hpp files of your stm32 project for syntax errors on the TuringCode server \
9
+ (run `turingcode project sync` first to include local changes). Returns `file:line:col: severity: message` lines.',
10
+ properties: {
11
+ files: {
12
+ type: 'string',
13
+ description: 'Comma-separated project-relative files, globs or folders, e.g. Core/Src/main.c (default: Core,App)',
14
+ },
15
+ },
16
+ run: async (args) => {
17
+ const project = await findStm32Project();
18
+ const files = (args.files || 'Core,App').split(',').map(f => f.trim()).filter(Boolean);
19
+ return syntaxCheckProject(callServer, project, files);
20
+ },
21
+ });
@@ -0,0 +1,5 @@
1
+ import { CommandModule } from "yargs";
2
+ /** How the commands find the project; shown in the help of every STM32 command group. */
3
+ export declare const PROJECT_HELP: string;
4
+ declare const command: CommandModule;
5
+ export default command;
@@ -0,0 +1,64 @@
1
+ import { TOKEN_HELP } from "../../core/mcp.js";
2
+ import { toolCommand } from "../../stm32/toolCommand.js";
3
+ import analysisStatic from "./analysis_static.js";
4
+ import analysisSyntaxCheck from "./analysis_syntax_check.js";
5
+ import projectBuild from "./project_build.js";
6
+ import projectDownloadTemplate from "./project_download_template.js";
7
+ import projectRegenerate from "./project_regenerate.js";
8
+ import projectSyncFromServer from "./project_sync_from_server.js";
9
+ import projectSyncToServer from "./project_sync_to_server.js";
10
+ import downloadDrivers from "./stm32_cubetools_download_drivers.js";
11
+ /** How the commands find the project; shown in the help of every STM32 command group. */
12
+ export const PROJECT_HELP = [
13
+ "Project: the nearest folder at or above the working directory that holds .turingcode/ (made by the",
14
+ "VS Code extension and the debug daemon; not the home folder's) or a .ioc or .mxproject file, else the",
15
+ "working directory. The STM32 project is that folder or the one subfolder holding a .ioc or .mxproject file.",
16
+ ].join("\n");
17
+ const subcommands = [
18
+ toolCommand({ command: "sync", tool: projectSyncToServer, mode: "local", server: true, aliases: { build: "b", analyse: "a" }, examples: [
19
+ ["$0 project sync", "upload the files the server lacks or has a different version of"],
20
+ ["$0 project sync -b", "sync, then build with the Debug preset"],
21
+ ["$0 project sync -b Release -a misra", "sync, build Release, then MISRA static analysis"],
22
+ ] }),
23
+ toolCommand({ command: "pull", tool: projectSyncFromServer, mode: "local", server: true, examples: [
24
+ ["$0 project pull", "download the files that changed on the server, overwriting local copies"],
25
+ ] }),
26
+ toolCommand({ command: "build", tool: projectBuild, mode: "local", server: true, examples: [
27
+ ["$0 project build", "build the Debug preset and download the .elf into build/Debug/"],
28
+ ["$0 project build --preset Release", "build another preset"],
29
+ ] }),
30
+ toolCommand({ command: "check", tool: analysisSyntaxCheck, mode: "local", server: true, examples: [
31
+ ["$0 project check", "syntax-check Core/ and App/ of the synced project"],
32
+ ["$0 project check --files Core/Src/main.c", "one file"],
33
+ ] }),
34
+ toolCommand({ command: "analyze", tool: analysisStatic, mode: "local", server: true, examples: [
35
+ ["$0 project analyze", "quick static analysis (cppcheck) of the synced project"],
36
+ ["$0 project analyze --profile misra --paths Core/Src", "MISRA C:2012 check of one folder"],
37
+ ] }),
38
+ toolCommand({ command: "regen", tool: projectRegenerate, mode: "local", server: true, examples: [
39
+ ["$0 project regen", "sync, regenerate from the .ioc and pull; stops with a diff if code outside USER CODE sections would be removed"],
40
+ ["$0 project regen --force", "regenerate anyway, still showing the diff of the removed code"],
41
+ ] }),
42
+ toolCommand({ command: "template", tool: projectDownloadTemplate, mode: "local", server: true, examples: [
43
+ ["$0 project template --mcu STM32G474RETx", "download a barebone project into ./STM32G474RETx/"],
44
+ ] }),
45
+ toolCommand({ command: "drivers", tool: downloadDrivers, mode: "local", server: true, examples: [
46
+ ["$0 project drivers", "restore missing Drivers/ files for the .ioc's MCU"],
47
+ ] }),
48
+ ];
49
+ const command = {
50
+ command: "project",
51
+ describe: "Sync, build and edit the local STM32 project with the Turing Code server",
52
+ builder: cli => subcommands.reduce((c, s) => c.command(s), cli)
53
+ .demandCommand(1, "project needs a subcommand: sync, pull, build, check, analyze, regen, template or drivers")
54
+ .epilogue([
55
+ "Typical use: edit files, `project sync` (or `project sync -b -a` to also build and analyse), `project build`,",
56
+ "then `probe program`. `project check` (syntax) and `project analyze` (cppcheck, clang-tidy, MISRA) check the synced code.",
57
+ "Other server tools (pins, clocks, .ioc edits) go through `tool call`; after one that",
58
+ "changes the server copy, `project pull` brings the changes back, and `project regen` regenerates the code.",
59
+ PROJECT_HELP,
60
+ TOKEN_HELP,
61
+ ].join("\n")),
62
+ handler: () => { },
63
+ };
64
+ export default command;
@@ -0,0 +1,3 @@
1
+ /** Builds the server copy and downloads the resulting ELF into the local build/<preset>/ folder. */
2
+ declare const _default: import("../../stm32/tool.js").ToolDef;
3
+ export default _default;
@@ -0,0 +1,22 @@
1
+ import { runBuild } from '../../stm32/context.js';
2
+ import { _defineTool } from '../../stm32/tool.js';
3
+ import { findStm32Project } from '../../stm32/utils/project_utils.js';
4
+ /** Builds the server copy and downloads the resulting ELF into the local build/<preset>/ folder. */
5
+ export default _defineTool({
6
+ name: 'project_build',
7
+ description: 'Build the project on the TuringCode server \
8
+ (run `turingcode project sync` first to include local changes), then download the .elf ' +
9
+ 'into the local build/<preset>/ folder for `turingcode probe program`. \
10
+ Prints the result, warnings in the project code, sizes and the clock audit summary (`--verbose` for the full reply).',
11
+ properties: {
12
+ preset: {
13
+ type: 'string',
14
+ enum: ['Debug', 'Release', 'RelWithDebInfo', 'MinSizeRel'],
15
+ },
16
+ verbose: {
17
+ type: 'boolean',
18
+ description: 'Print the full build reply (compiler, Drivers/ warnings, map file, stack usage, build log, clock tables); a failed build always prints it',
19
+ },
20
+ },
21
+ run: async (args) => runBuild(await findStm32Project(), args.preset ?? 'Debug', !!args.verbose),
22
+ });
@@ -0,0 +1,3 @@
1
+ /** Downloads the server's barebone project for an MCU into the agent's working directory (which must be inside the project folder). */
2
+ declare const _default: import("../../stm32/tool.js").ToolDef;
3
+ export default _default;
@@ -0,0 +1,34 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { callServer } from '../../stm32/context.js';
4
+ import { recordBaseline } from '../../stm32/regen.js';
5
+ import { downloadAndUnzip, zipLink } from '../../stm32/utils/downloadzip_utils.js';
6
+ import { _defineTool } from '../../stm32/tool.js';
7
+ import { getMcuFromText } from '../../stm32/utils/mcu_utils.js';
8
+ /** Downloads the server's barebone project for an MCU into the agent's working directory (which must be inside the project folder). */
9
+ export default _defineTool({
10
+ name: 'project_download_template',
11
+ description: 'Download a barebone STM32 project template (CMake)' +
12
+ ' for an MCU into the current working directory, as a <MCU>/ folder. ' +
13
+ ' only use when user asked to create a new project.',
14
+ properties: {
15
+ mcu: {
16
+ type: 'string',
17
+ pattern: '^[A-Za-z0-9_-]{4,40}$',
18
+ description: 'CubeMX part number, e.g. STM32G474RETx',
19
+ },
20
+ },
21
+ required: ['mcu'],
22
+ run: async (args, ctx) => {
23
+ const text = await callServer('project_template', { mcu: args.mcu }, 125_000);
24
+ const mcu = getMcuFromText(text);
25
+ if (!mcu)
26
+ throw new Error(text); /** e.g. unknown or ambiguous MCU, with the server's choices */
27
+ const dest = join(ctx.cwd, mcu); /** the zip holds one <MCU>/ folder */
28
+ if (existsSync(dest))
29
+ throw new Error(`${dest} already exists; move or delete it first`);
30
+ await downloadAndUnzip(zipLink(text), ctx.cwd);
31
+ await recordBaseline(dest); /** what CubeMX generated, for `project regen`'s check */
32
+ return `Template for ${mcu} downloaded to ${dest}`;
33
+ },
34
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: import("../../stm32/tool.js").ToolDef;
2
+ export default _default;
@@ -0,0 +1,20 @@
1
+ import { callServer } from '../../stm32/context.js';
2
+ import { regenerateProject } from '../../stm32/regen.js';
3
+ import { _defineTool } from '../../stm32/tool.js';
4
+ import { findStm32Project } from '../../stm32/utils/project_utils.js';
5
+ export default _defineTool({
6
+ name: 'project_regenerate',
7
+ description: 'Regenerate the project code from its .ioc file with CubeMX on the TuringCode server, then pull the result ' +
8
+ '(run after pin, clock or peripheral edits). CubeMX keeps only the code inside USER CODE sections, so it first ' +
9
+ 'compares each file with USER CODE markers with the code CubeMX generated last time (.turingcode/generated/) and ' +
10
+ 'stops with a diff of the code that would be removed; force regenerates anyway and still shows that diff. ' +
11
+ 'Local changes are synced to the server first. ' +
12
+ 'The project is the folder with a .ioc or .mxproject file inside the project folder (the nearest folder holding .turingcode/ or a .ioc file, else the working directory); fails if there are several.',
13
+ properties: {
14
+ force: {
15
+ type: 'boolean',
16
+ description: 'Regenerate and pull even when code outside USER CODE sections would be removed',
17
+ },
18
+ },
19
+ run: async (args) => regenerateProject(callServer, await findStm32Project(), !!args.force),
20
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: import("../../stm32/tool.js").ToolDef;
2
+ export default _default;
@@ -0,0 +1,13 @@
1
+ import { callServer } from "../../stm32/context.js";
2
+ import { syncProjectFromServer } from "../../stm32/sync.js";
3
+ import { _defineTool } from "../../stm32/tool.js";
4
+ import { findStm32Project } from "../../stm32/utils/project_utils.js";
5
+ export default _defineTool({
6
+ name: "project_sync_from_server",
7
+ description: "Download the files of your stm32 project that changed on the TuringCode server (e.g. after project_regenerate " +
8
+ "or stm32_cubetools_* edits) and overwrite the local copies; local files absent on the server are kept. " +
9
+ "build/ and git-ignored files (except Drivers/) are skipped. Local edits not yet synced to the server are lost, " +
10
+ "so run `turingcode project sync` first if you have any. " +
11
+ "The project is the folder with a .ioc or .mxproject file inside the project folder (the nearest folder holding .turingcode/ or a .ioc file, else the working directory); fails if there are several.",
12
+ run: async () => syncProjectFromServer(callServer, await findStm32Project()),
13
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: import("../../stm32/tool.js").ToolDef;
2
+ export default _default;
@@ -0,0 +1,51 @@
1
+ import analysisStatic from './analysis_static.js';
2
+ import { callServer, runBuild } from '../../stm32/context.js';
3
+ import { checkBeforeRegen } from '../../stm32/regen.js';
4
+ import { syncProjectToServer } from '../../stm32/sync.js';
5
+ import { _defineTool } from '../../stm32/tool.js';
6
+ import { findStm32Project } from '../../stm32/utils/project_utils.js';
7
+ export default _defineTool({
8
+ name: 'project_sync_to_server',
9
+ description: 'Sync your local stm32 project files (except build/ and git-ignored files; Drivers/ is always sent) ' +
10
+ 'to the TuringCode server; only files the server lacks or has a different version of are uploaded. \
11
+ To restore deleted Drivers/ files use `turingcode project drivers`. \
12
+ Stops before uploading when a USER CODE BEGIN/END marker is unmatched, and warns about code outside USER CODE sections that `project regen` would remove. \
13
+ The project is the folder with a .ioc or .mxproject file inside the project folder (the nearest folder holding .turingcode/ or a .ioc file, else the working directory); fails if there are several.',
14
+ properties: {
15
+ force_full_sync: {
16
+ type: 'boolean',
17
+ description: 'Upload every file, skipping the check for which files the server already has (server files deleted locally are kept)',
18
+ },
19
+ build: {
20
+ type: 'string',
21
+ enum: ['', 'Debug', 'Release', 'RelWithDebInfo', 'MinSizeRel'],
22
+ description: 'After a successful sync, build with this preset like `turingcode project build`; empty = Debug',
23
+ },
24
+ analyse: {
25
+ type: 'string',
26
+ enum: ['', 'quick', 'full', 'misra'],
27
+ description: 'After a successful sync (and build), run static analysis with this profile like `turingcode project analyze`; empty = quick',
28
+ },
29
+ verbose: {
30
+ type: 'boolean',
31
+ description: 'Print the full build reply (compiler, Drivers/ warnings, map file, stack usage, build log, clock tables); a failed build always prints it',
32
+ },
33
+ },
34
+ run: async (args, ctx) => {
35
+ const project = await findStm32Project();
36
+ const { findings, broken } = await checkBeforeRegen(project.root);
37
+ if (broken.length)
38
+ throw new Error(`Sync stopped, nothing uploaded. Fix the USER CODE markers first:\n\n${broken.join('\n\n')}`);
39
+ const synced = await syncProjectToServer(callServer, project, !!args.force_full_sync);
40
+ /** warn, not stop: user-written files with markers are reported too (see recordBaseline) */
41
+ const outside = findings.length
42
+ ? `\n\nWarning: code outside USER CODE sections differs from what CubeMX generated; \`project regen\` would stop on it. Move it into a USER CODE section:\n\n${findings.join('\n\n')}`
43
+ : '';
44
+ const parts = [`# Sync\n${synced}${outside}`];
45
+ if (args.build !== undefined)
46
+ parts.push(`# Build\n${await runBuild(project, args.build || 'Debug', !!args.verbose)}`);
47
+ if (args.analyse !== undefined)
48
+ parts.push(`# Static analysis\n${await analysisStatic.run({ profile: args.analyse || 'quick' }, ctx)}`);
49
+ return parts.length > 1 ? parts.join('\n') : synced + outside;
50
+ },
51
+ });
@@ -0,0 +1,3 @@
1
+ /** Restores the project's Drivers/ files from the server's copy for the .ioc's MCU; existing files are kept. */
2
+ declare const _default: import("../../stm32/tool.js").ToolDef;
3
+ export default _default;
@@ -0,0 +1,19 @@
1
+ import { callServer } from '../../stm32/context.js';
2
+ import { downloadAndUnzip, zipLink } from '../../stm32/utils/downloadzip_utils.js';
3
+ import { _defineTool } from '../../stm32/tool.js';
4
+ import { findStm32Project } from '../../stm32/utils/project_utils.js';
5
+ import { getMcuFromIoc } from '../../stm32/utils/mcu_utils.js';
6
+ /** Restores the project's Drivers/ files from the server's copy for the .ioc's MCU; existing files are kept. */
7
+ export default _defineTool({
8
+ name: 'stm32_cubetools_download_drivers',
9
+ description: 'Restore missing Drivers/ files (CMSIS, HAL) of your local stm32 project: downloads the complete Drivers/ folder ' +
10
+ 'STM32CubeMX makes for the MCU in the .ioc and adds the files the project lacks; existing files are not overwritten. ' +
11
+ 'The project is the folder with a .ioc or .mxproject file inside the project folder (the nearest folder holding .turingcode/ or a .ioc file, else the working directory); fails if there are several.',
12
+ run: async () => {
13
+ const project = await findStm32Project();
14
+ const mcu = await getMcuFromIoc(project.root);
15
+ const text = await callServer('stm32_cubetools_download_drivers', { mcu }, 125_000);
16
+ await downloadAndUnzip(zipLink(text), project.root, false); /** throws with the server reply when it has no zip link */
17
+ return `Restored missing Drivers/ files for ${mcu} into ${project.root}`;
18
+ },
19
+ });
@@ -0,0 +1,2 @@
1
+ declare const command: import("yargs").CommandModule<{}, {}>;
2
+ export default command;
@@ -0,0 +1,6 @@
1
+ import { toolCommand } from "../../stm32/toolCommand.js";
2
+ import getStatus from "./get_status.js";
3
+ const command = toolCommand({ command: "status", tool: getStatus, mode: "local", examples: [
4
+ ["$0 status", "project, last build, debug session and installed debug tools"],
5
+ ] });
6
+ export default command;
@@ -0,0 +1,3 @@
1
+ /** Reports the CLI, server token, project, its newest built ELF, debug session and hardware tool state. */
2
+ declare const _default: import("../../stm32/tool.js").ToolDef;
3
+ export default _default;