@turingcode/cli 0.3.4 → 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 (128) hide show
  1. package/dist/cli/create-cli.js +5 -3
  2. package/dist/cli/index.js +1 -1
  3. package/dist/core/exact/fraction.js +2 -0
  4. package/dist/core/files.js +2 -2
  5. package/dist/core/json-shape.js +1 -0
  6. package/dist/core/query.js +2 -2
  7. package/dist/core/tables/csv.d.ts +13 -2
  8. package/dist/core/tables/csv.js +54 -25
  9. package/dist/core/tables/markdown.js +8 -2
  10. package/dist/features/contract/diagnostics.d.ts +3 -0
  11. package/dist/features/contract/diagnostics.js +7 -4
  12. package/dist/features/contract/load.js +4 -4
  13. package/dist/features/contract/rules.d.ts +12 -0
  14. package/dist/features/contract/rules.js +31 -4
  15. package/dist/features/debug/clear_breakpoint.d.ts +1 -0
  16. package/dist/features/debug/clear_breakpoint.js +1 -1
  17. package/dist/features/debug/command.js +1 -1
  18. package/dist/features/debug/continue.d.ts +1 -0
  19. package/dist/features/debug/continue.js +2 -2
  20. package/dist/features/debug/debug_start.d.ts +1 -0
  21. package/dist/features/debug/debug_start.js +1 -1
  22. package/dist/features/debug/debug_stop.d.ts +1 -0
  23. package/dist/features/debug/debug_stop.js +1 -1
  24. package/dist/features/debug/evaluate.d.ts +1 -0
  25. package/dist/features/debug/evaluate.js +5 -5
  26. package/dist/features/debug/get_stack.d.ts +1 -0
  27. package/dist/features/debug/get_stack.js +1 -1
  28. package/dist/features/debug/get_variables.d.ts +1 -0
  29. package/dist/features/debug/get_variables.js +2 -2
  30. package/dist/features/debug/halt.d.ts +1 -0
  31. package/dist/features/debug/halt.js +1 -1
  32. package/dist/features/debug/set_breakpoint.d.ts +1 -0
  33. package/dist/features/debug/set_breakpoint.js +1 -1
  34. package/dist/features/debug/step.d.ts +1 -0
  35. package/dist/features/debug/step.js +2 -2
  36. package/dist/features/install-mods/install.js +4 -3
  37. package/dist/features/install-skills/install.d.ts +1 -0
  38. package/dist/features/install-skills/install.js +1 -1
  39. package/dist/features/probe/command.d.ts +1 -1
  40. package/dist/features/probe/command.js +103 -35
  41. package/dist/features/probe/kill_all_debuggers.d.ts +1 -0
  42. package/dist/features/probe/kill_all_debuggers.js +5 -5
  43. package/dist/features/probe/list_probes.d.ts +1 -0
  44. package/dist/features/probe/list_probes.js +1 -1
  45. package/dist/features/probe/program_project.d.ts +1 -0
  46. package/dist/features/probe/program_project.js +1 -1
  47. package/dist/features/probe/read_fault_status.d.ts +1 -0
  48. package/dist/features/probe/read_fault_status.js +1 -1
  49. package/dist/features/probe/read_memory.d.ts +1 -0
  50. package/dist/features/probe/read_memory.js +2 -2
  51. package/dist/features/probe/read_peripheral.d.ts +1 -0
  52. package/dist/features/probe/read_peripheral.js +7 -5
  53. package/dist/features/probe/reset_probe_usb.d.ts +1 -0
  54. package/dist/features/probe/reset_probe_usb.js +1 -1
  55. package/dist/features/probe/reset_target.d.ts +1 -0
  56. package/dist/features/probe/reset_target.js +1 -1
  57. package/dist/features/probe/target_info.d.ts +1 -0
  58. package/dist/features/probe/target_info.js +1 -1
  59. package/dist/features/project/analysis_static.d.ts +1 -0
  60. package/dist/features/project/analysis_static.js +1 -1
  61. package/dist/features/project/analysis_syntax_check.d.ts +1 -0
  62. package/dist/features/project/analysis_syntax_check.js +1 -1
  63. package/dist/features/project/project_build.d.ts +1 -0
  64. package/dist/features/project/project_build.js +1 -1
  65. package/dist/features/project/project_download_template.d.ts +1 -0
  66. package/dist/features/project/project_download_template.js +4 -4
  67. package/dist/features/project/project_sync_to_server.js +1 -1
  68. package/dist/features/project/stm32_cubetools_download_drivers.d.ts +1 -0
  69. package/dist/features/project/stm32_cubetools_download_drivers.js +2 -2
  70. package/dist/features/status/get_status.d.ts +1 -0
  71. package/dist/features/status/get_status.js +1 -1
  72. package/dist/features/table/check.js +5 -5
  73. package/dist/features/table/read.js +9 -9
  74. package/dist/features/tool/command.d.ts +2 -2
  75. package/dist/features/tool/command.js +95 -66
  76. package/dist/lib.d.ts +4 -0
  77. package/dist/lib.js +4 -2
  78. package/dist/stm32/actions/DebugAction.d.ts +4 -2
  79. package/dist/stm32/actions/DebugAction.js +6 -5
  80. package/dist/stm32/actions/DebugActionInfo.d.ts +4 -0
  81. package/dist/stm32/actions/DebugActionInfo.js +4 -2
  82. package/dist/stm32/actions/DebugActionListProbes.d.ts +1 -0
  83. package/dist/stm32/actions/DebugActionListProbes.js +1 -1
  84. package/dist/stm32/actions/DebugActionProgram.d.ts +8 -2
  85. package/dist/stm32/actions/DebugActionProgram.js +9 -7
  86. package/dist/stm32/actions/DebugActionRead.d.ts +8 -7
  87. package/dist/stm32/actions/DebugActionRead.js +5 -3
  88. package/dist/stm32/actions/DebugActionReset.d.ts +2 -1
  89. package/dist/stm32/actions/DebugActionReset.js +1 -1
  90. package/dist/stm32/actions/DebugActionServer.d.ts +4 -0
  91. package/dist/stm32/actions/DebugActionServer.js +4 -2
  92. package/dist/stm32/analysis.d.ts +1 -0
  93. package/dist/stm32/build.d.ts +4 -4
  94. package/dist/stm32/build.js +1 -1
  95. package/dist/stm32/context.js +2 -2
  96. package/dist/stm32/daemon.d.ts +8 -6
  97. package/dist/stm32/daemon.js +25 -18
  98. package/dist/stm32/regen.js +14 -8
  99. package/dist/stm32/session.d.ts +9 -6
  100. package/dist/stm32/session.js +11 -10
  101. package/dist/stm32/sync.d.ts +1 -0
  102. package/dist/stm32/sync.js +5 -3
  103. package/dist/stm32/tool.d.ts +5 -3
  104. package/dist/stm32/toolCommand.d.ts +4 -4
  105. package/dist/stm32/toolCommand.js +1 -3
  106. package/dist/stm32/utils/discover_tools.d.ts +2 -1
  107. package/dist/stm32/utils/discover_tools.js +1 -1
  108. package/dist/stm32/utils/downloadzip_utils.js +4 -4
  109. package/dist/stm32/utils/faultUtils.d.ts +2 -1
  110. package/dist/stm32/utils/faultUtils.js +2 -2
  111. package/dist/stm32/utils/listSyncFiles.js +12 -10
  112. package/dist/stm32/utils/mcu_utils.d.ts +5 -6
  113. package/dist/stm32/utils/mcu_utils.js +10 -9
  114. package/dist/stm32/utils/project_utils.d.ts +1 -1
  115. package/dist/stm32/utils/project_utils.js +5 -3
  116. package/dist/stm32/utils/usb_utils.js +2 -2
  117. package/dist/stm32/utils/user_code.d.ts +4 -1
  118. package/dist/stm32/utils/user_code.js +5 -3
  119. package/dist/stm32/utils/utils_mutex.js +34 -14
  120. package/dist/stm32/validate.d.ts +1 -0
  121. package/dist/stm32/validate.js +1 -1
  122. package/mods/claude/turingcode-skills/skills/turingcode-cli/SKILL.md +17 -23
  123. package/mods/claude/turingcode-skills/skills/turingcode-firmware-code/SKILL.md +4 -0
  124. package/mods/claude/turingcode-skills/skills/turingcode-firmware-code/references/input-and-bounds.md +0 -13
  125. package/package.json +1 -1
  126. package/mods/claude/turingcode-skills/skills/turingcode-cli/references/board-and-debug.md +0 -22
  127. package/mods/claude/turingcode-skills/skills/turingcode-cli/references/build-and-check.md +0 -19
  128. package/mods/claude/turingcode-skills/skills/turingcode-cli/references/new-project.md +0 -9
@@ -1,2 +1,3 @@
1
+ /** Adds a source breakpoint to the debug session. */
1
2
  declare const _default: import("../../stm32/tool.js").ToolDef;
2
3
  export default _default;
@@ -1,6 +1,6 @@
1
1
  import { _defineTool } from '../../stm32/tool.js';
2
2
  import { getSession, projectFile, syncBreakpoints } from '../../stm32/session.js';
3
- // Adds a source breakpoint to the debug session.
3
+ /** Adds a source breakpoint to the debug session. */
4
4
  export default _defineTool({
5
5
  name: 'set_breakpoint',
6
6
  description: 'Add a source breakpoint in the debug session. Code runs from flash, so these are hardware breakpoints: 4 on Cortex-M0/M0+, 6 on M3/M4/M33, 8 on M7. Remove unused ones with `turingcode debug clear`.',
@@ -1,2 +1,3 @@
1
+ /** Steps the halted target by one source line. */
1
2
  declare const _default: import("../../stm32/tool.js").ToolDef;
2
3
  export default _default;
@@ -1,7 +1,7 @@
1
1
  import { _defineTool } from '../../stm32/tool.js';
2
2
  import { getSession } from '../../stm32/session.js';
3
3
  const COMMANDS = { over: 'next', into: 'stepIn', out: 'stepOut' };
4
- // Steps the halted target by one source line.
4
+ /** Steps the halted target by one source line. */
5
5
  export default _defineTool({
6
6
  name: 'step',
7
7
  description: 'Step the halted target one source line (over, the default; into a call; or out of the function) and report where it stopped.',
@@ -10,7 +10,7 @@ export default _defineTool({
10
10
  const s = getSession();
11
11
  s.requireHalted();
12
12
  const stopped = s.waitEvent('stopped', 10_000);
13
- // Set before the request: the stopped event of a short run can arrive before its response
13
+ /** Set before the request: the stopped event of a short run can arrive before its response */
14
14
  s.state = 'running';
15
15
  await s.request(COMMANDS[args.kind ?? 'over'], { threadId: s.threadId }).catch((e) => {
16
16
  s.state = 'halted';
@@ -13,8 +13,9 @@ export const MARKETPLACE_DIR = join(packageRoot(), "mods", "claude");
13
13
  */
14
14
  export const runCommand = (cmd, args) => {
15
15
  const win = process.platform === "win32";
16
- // the shell joins arguments with spaces, so quote them (the marketplace path may contain spaces)
17
- const result = spawnSync(cmd, win ? args.map(a => `"${a}"`) : args, { stdio: "inherit", shell: win, windowsHide: true });
16
+ const options = { stdio: "inherit", windowsHide: true };
17
+ /** a shell with an args array is deprecated (DEP0190), so give it one command line, each argument quoted (the marketplace path may contain spaces) */
18
+ const result = win ? spawnSync(`${cmd} ${args.map(a => `"${a}"`).join(" ")}`, { ...options, shell: true }) : spawnSync(cmd, args, options);
18
19
  if (result.error)
19
20
  throw new Error(`${cmd} could not start (${result.error.message}); is Claude Code installed and on PATH?`);
20
21
  if (result.status !== 0)
@@ -40,7 +41,7 @@ export function installMods(only = [], run = runCommand, source = MARKETPLACE_DI
40
41
  run("claude", ["plugin", "marketplace", "add", source]);
41
42
  run("claude", ["plugin", "marketplace", "update", marketplace.name]);
42
43
  for (const name of names) {
43
- // install is a no-op for an installed plugin, so update brings it to the shipped version
44
+ /** install is a no-op for an installed plugin, so update brings it to the shipped version */
44
45
  run("claude", ["plugin", "install", `${name}@${marketplace.name}`]);
45
46
  run("claude", ["plugin", "update", `${name}@${marketplace.name}`]);
46
47
  }
@@ -1,3 +1,4 @@
1
+ /** Claude Code loads these skills from the turingcode-skills plugin (install-mods); this copy serves Codex and OpenCode. */
1
2
  export declare const SKILLS_DIR: string;
2
3
  export declare const DEFAULT_TARGET: string;
3
4
  /**
@@ -2,7 +2,7 @@ import { cpSync, readdirSync, rmSync } from "node:fs";
2
2
  import { homedir } from "node:os";
3
3
  import { join } from "node:path";
4
4
  import { packageRoot } from "../../core/files.js";
5
- // Claude Code loads these skills from the turingcode-skills plugin (install-mods); this copy serves Codex and OpenCode.
5
+ /** Claude Code loads these skills from the turingcode-skills plugin (install-mods); this copy serves Codex and OpenCode. */
6
6
  export const SKILLS_DIR = join(packageRoot(), "mods", "claude", "turingcode-skills", "skills");
7
7
  export const DEFAULT_TARGET = join(homedir(), ".agents", "skills");
8
8
  /**
@@ -1,4 +1,4 @@
1
- import { CommandModule } from "yargs";
1
+ import { CommandModule } from 'yargs';
2
2
  /** The probe tools, also served by the debug daemon. */
3
3
  export declare const PROBE_TOOLS: import("../../stm32/tool.js").ToolDef[];
4
4
  declare const command: CommandModule;
@@ -1,44 +1,112 @@
1
- import { toolCommand } from "../../stm32/toolCommand.js";
2
- import { PROJECT_HELP } from "../project/command.js";
3
- import killAllDebuggers from "./kill_all_debuggers.js";
4
- import listProbes from "./list_probes.js";
5
- import programProject from "./program_project.js";
6
- import readFaultStatus from "./read_fault_status.js";
7
- import readMemory from "./read_memory.js";
8
- import readPeripheral from "./read_peripheral.js";
9
- import resetProbeUsb from "./reset_probe_usb.js";
10
- import resetTarget from "./reset_target.js";
11
- import targetInfo from "./target_info.js";
1
+ import { toolCommand } from '../../stm32/toolCommand.js';
2
+ import { PROJECT_HELP } from '../project/command.js';
3
+ import killAllDebuggers from './kill_all_debuggers.js';
4
+ import listProbes from './list_probes.js';
5
+ import programProject from './program_project.js';
6
+ import readFaultStatus from './read_fault_status.js';
7
+ import readMemory from './read_memory.js';
8
+ import readPeripheral from './read_peripheral.js';
9
+ import resetProbeUsb from './reset_probe_usb.js';
10
+ import resetTarget from './reset_target.js';
11
+ import targetInfo from './target_info.js';
12
12
  /** The probe tools, also served by the debug daemon. */
13
- export const PROBE_TOOLS = [listProbes, targetInfo, readMemory, readPeripheral, readFaultStatus, programProject, resetTarget, resetProbeUsb, killAllDebuggers];
13
+ export const PROBE_TOOLS = [
14
+ listProbes,
15
+ targetInfo,
16
+ readMemory,
17
+ readPeripheral,
18
+ readFaultStatus,
19
+ programProject,
20
+ resetTarget,
21
+ resetProbeUsb,
22
+ killAllDebuggers,
23
+ ];
14
24
  const subcommands = [
15
- toolCommand({ command: "list", tool: listProbes, mode: "probe", examples: [["$0 probe list", "the connected probes"]] }),
16
- toolCommand({ command: "info", tool: targetInfo, mode: "probe", server: true, examples: [["$0 probe info", "which chip is connected, and its CubeMX names for project template"]] }),
17
- toolCommand({ command: "read", tool: readMemory, mode: "probe", examples: [
18
- ["$0 probe read --address 0xE0042000 --length 4", "one 32-bit word (here DBGMCU_IDCODE)"],
19
- ["$0 probe read --address 0x20000000 --length 64 --width 8", "64 bytes of RAM, byte by byte"],
20
- ] }),
21
- toolCommand({ command: "peripheral", tool: readPeripheral, mode: "probe", server: true, examples: [
22
- ["$0 probe peripheral --name GPIOA", "GPIOA's registers, decoded"],
23
- ] }),
24
- toolCommand({ command: "faults", tool: readFaultStatus, mode: "probe", examples: [["$0 probe faults", "decode CFSR, HFSR, ... after a HardFault"]] }),
25
- toolCommand({ command: "program", tool: programProject, mode: "probe", examples: [["$0 probe program", "flash the newest .elf in build/ and reset"]] }),
26
- toolCommand({ command: "reset", tool: resetTarget, mode: "probe", examples: [["$0 probe reset", "hardware reset of the target"]] }),
27
- toolCommand({ command: "reset-usb", tool: resetProbeUsb, mode: "probe", examples: [["$0 probe reset-usb", "restart the ST-LINK's USB connection (Windows, admin)"]] }),
28
- toolCommand({ command: "kill-debuggers", tool: killAllDebuggers, mode: "probe", examples: [["$0 probe kill-debuggers", "free a probe held by a stuck debugger"]] }),
25
+ toolCommand({
26
+ command: 'list',
27
+ tool: listProbes,
28
+ mode: 'probe',
29
+ examples: [['$0 probe list', 'the connected probes']],
30
+ }),
31
+ toolCommand({
32
+ command: 'info',
33
+ tool: targetInfo,
34
+ mode: 'probe',
35
+ server: true,
36
+ examples: [
37
+ [
38
+ '$0 probe info',
39
+ 'which chip is connected, and its CubeMX names for project template',
40
+ ],
41
+ ],
42
+ }),
43
+ toolCommand({
44
+ command: 'read',
45
+ tool: readMemory,
46
+ mode: 'probe',
47
+ examples: [
48
+ [
49
+ '$0 probe read --address 0xE0042000 --length 4',
50
+ 'one 32-bit word (here DBGMCU_IDCODE)',
51
+ ],
52
+ [
53
+ '$0 probe read --address 0x20000000 --length 64 --width 8',
54
+ '64 bytes of RAM, byte by byte',
55
+ ],
56
+ ],
57
+ }),
58
+ toolCommand({
59
+ command: 'peripheral',
60
+ tool: readPeripheral,
61
+ mode: 'probe',
62
+ server: true,
63
+ examples: [['$0 probe peripheral --name GPIOA', "GPIOA's registers, decoded"]],
64
+ }),
65
+ toolCommand({
66
+ command: 'faults',
67
+ tool: readFaultStatus,
68
+ mode: 'probe',
69
+ examples: [['$0 probe faults', 'decode CFSR, HFSR, ... after a HardFault']],
70
+ }),
71
+ toolCommand({
72
+ command: 'program',
73
+ tool: programProject,
74
+ mode: 'probe',
75
+ examples: [['$0 probe program', 'flash the newest .elf in build/ and reset']],
76
+ }),
77
+ toolCommand({
78
+ command: 'reset',
79
+ tool: resetTarget,
80
+ mode: 'probe',
81
+ examples: [['$0 probe reset', 'hardware reset of the target']],
82
+ }),
83
+ toolCommand({
84
+ command: 'reset-usb',
85
+ tool: resetProbeUsb,
86
+ mode: 'probe',
87
+ examples: [
88
+ ['$0 probe reset-usb', "restart the ST-LINK's USB connection (Windows, admin)"],
89
+ ],
90
+ }),
91
+ toolCommand({
92
+ command: 'kill-debuggers',
93
+ tool: killAllDebuggers,
94
+ mode: 'probe',
95
+ examples: [['$0 probe kill-debuggers', 'free a probe held by a stuck debugger']],
96
+ }),
29
97
  ];
30
98
  const command = {
31
- command: "probe",
32
- describe: "Program, reset and read the target board over the debug probe (SWD)",
33
- builder: cli => subcommands.reduce((c, s) => c.command(s), cli)
34
- .demandCommand(1, "probe needs a subcommand: list, info, read, peripheral, faults, program, reset, reset-usb or kill-debuggers")
99
+ command: 'probe',
100
+ describe: 'Program, reset and read the target board over the debug probe (SWD)',
101
+ builder: (cli) => subcommands
102
+ .reduce((c, s) => c.command(s), cli)
103
+ .demandCommand(1, 'probe needs a subcommand: list, info, read, peripheral, faults, program, reset, reset-usb or kill-debuggers')
35
104
  .epilogue([
36
- "Runs probe-rs, or STM32_Programmer_CLI when probe-rs is not installed (`status` shows what is found).",
37
- "The chip is the Mcu.UserName of the STM32 project's .ioc. One probe command runs at a time: the probe",
38
- "lock is .turingcode/probe.lock. While a debug session runs, these commands go to its daemon, and",
39
- "the ones that need the probe are refused until `debug stop`.",
105
+ 'One probe command runs at a time: the probe',
106
+ 'lock is .turingcode/probe.lock. While a debug session runs, these commands go to its daemon, and',
107
+ 'the ones that need the probe are refused until `debug stop`.',
40
108
  PROJECT_HELP,
41
- ].join("\n")),
109
+ ].join('\n')),
42
110
  handler: () => { },
43
111
  };
44
112
  export default command;
@@ -1,2 +1,3 @@
1
+ /** Frees a probe left held by a stuck debugger, including one from another app or a crashed session. */
1
2
  declare const _default: import("../../stm32/tool.js").ToolDef;
2
3
  export default _default;
@@ -3,7 +3,7 @@ import { promisify } from 'node:util';
3
3
  import { _defineTool } from '../../stm32/tool.js';
4
4
  import { releaseProbe } from '../../stm32/utils/utils_mutex.js';
5
5
  const run = promisify(execFile);
6
- // Programs that can hold an ST-LINK or other debug probe open.
6
+ /** Programs that can hold an ST-LINK or other debug probe open. */
7
7
  const DEBUGGERS = [
8
8
  'probe-rs',
9
9
  'STM32_Programmer_CLI',
@@ -22,16 +22,16 @@ async function killByName(name) {
22
22
  await run('taskkill', ['/F', '/T', '/IM', `${name}.exe`], { windowsHide: true });
23
23
  else if (process.platform === 'darwin')
24
24
  await run('killall', ['-9', name]);
25
- // Linux: killall is missing on minimal installs; pkill -x matches the process name, which the kernel cuts to 15 characters
25
+ /** Linux: killall is missing on minimal installs; pkill -x matches the process name, which the kernel cuts to 15 characters */
26
26
  else
27
27
  await run('pkill', ['-9', '-x', name.slice(0, 15)]);
28
28
  return true;
29
29
  }
30
30
  catch {
31
- return false; // not running (or not ours to kill)
31
+ return false; /** not running (or not ours to kill) */
32
32
  }
33
33
  }
34
- // Frees a probe left held by a stuck debugger, including one from another app or a crashed session.
34
+ /** Frees a probe left held by a stuck debugger, including one from another app or a crashed session. */
35
35
  export default _defineTool({
36
36
  name: 'kill_all_debuggers',
37
37
  description: `Force-kill every running debugger process on this machine (${DEBUGGERS.join(', ')}), \
@@ -42,7 +42,7 @@ export default _defineTool({
42
42
  for (const name of DEBUGGERS)
43
43
  if (await killByName(name))
44
44
  killed.push(name);
45
- releaseProbe(); // the killed runs may not have released it yet
45
+ releaseProbe(); /** the killed runs may not have released it yet */
46
46
  return killed.length
47
47
  ? `Killed: ${killed.join(', ')}`
48
48
  : 'No debugger processes were running';
@@ -1,2 +1,3 @@
1
+ /** Lists the connected debug probes with the installed debug tool. */
1
2
  declare const _default: import("../../stm32/tool.js").ToolDef;
2
3
  export default _default;
@@ -1,6 +1,6 @@
1
1
  import { _defineTool } from '../../stm32/tool.js';
2
2
  import { DebugActionListProbes } from '../../stm32/actions/DebugActionListProbes.js';
3
- // Lists the connected debug probes with the installed debug tool.
3
+ /** Lists the connected debug probes with the installed debug tool. */
4
4
  export default _defineTool({
5
5
  name: 'list_probes',
6
6
  description: 'List the debug probes (ST-LINK, J-Link, CMSIS-DAP, ...) connected to this machine (probe-rs list, or STM32_Programmer_CLI --list).',
@@ -1,2 +1,3 @@
1
+ /** Flashes the newest ELF in the project's build/ folder. */
1
2
  declare const _default: import("../../stm32/tool.js").ToolDef;
2
3
  export default _default;
@@ -3,7 +3,7 @@ import { findStm32Project } from '../../stm32/utils/project_utils.js';
3
3
  import { getMcuFromIoc } from '../../stm32/utils/mcu_utils.js';
4
4
  import { findElf } from '../../stm32/utils/findElf.js';
5
5
  import { DebugActionProgram } from '../../stm32/actions/DebugActionProgram.js';
6
- // Flashes the newest ELF in the project's build/ folder.
6
+ /** Flashes the newest ELF in the project's build/ folder. */
7
7
  export default _defineTool({
8
8
  name: 'program_project',
9
9
  description: "Flash the newest .elf in the project's build/ folder \
@@ -1,2 +1,3 @@
1
+ /** Reads and decodes the SCB fault status registers. */
1
2
  declare const _default: import("../../stm32/tool.js").ToolDef;
2
3
  export default _default;
@@ -3,7 +3,7 @@ import { findStm32Project } from '../../stm32/utils/project_utils.js';
3
3
  import { DebugActionRead } from '../../stm32/actions/DebugActionRead.js';
4
4
  import { FAULT_REGS_ADDRESS, decodeFaultStatus } from '../../stm32/utils/faultUtils.js';
5
5
  import { getMcuFromIoc, isArmv6m } from '../../stm32/utils/mcu_utils.js';
6
- // Reads and decodes the SCB fault status registers.
6
+ /** Reads and decodes the SCB fault status registers. */
7
7
  export default _defineTool({
8
8
  name: 'read_fault_status',
9
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.',
@@ -1,2 +1,3 @@
1
+ /** Reads target memory while the core keeps running. */
1
2
  declare const _default: import("../../stm32/tool.js").ToolDef;
2
3
  export default _default;
@@ -3,7 +3,7 @@ import { findStm32Project } from '../../stm32/utils/project_utils.js';
3
3
  import { getMcuFromIoc } from '../../stm32/utils/mcu_utils.js';
4
4
  import { hex } from '../../stm32/utils/faultUtils.js';
5
5
  import { DebugActionRead } from '../../stm32/actions/DebugActionRead.js';
6
- // Reads target memory while the core keeps running.
6
+ /** Reads target memory while the core keeps running. */
7
7
  export default _defineTool({
8
8
  name: 'read_memory',
9
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.",
@@ -24,7 +24,7 @@ export default _defineTool({
24
24
  const project = await findStm32Project();
25
25
  const chip = await getMcuFromIoc(project.root);
26
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
27
+ /** 16 bytes per line, each line prefixed with its address */
28
28
  const perLine = 128 / width;
29
29
  const lines = [];
30
30
  for (let i = 0; i < words.length; i += perLine) {
@@ -1,2 +1,3 @@
1
+ /** Reads a peripheral's registers and decodes them with the MCU's SVD data from the TuringCode server. */
1
2
  declare const _default: import("../../stm32/tool.js").ToolDef;
2
3
  export default _default;
@@ -5,7 +5,7 @@ import { DebugActionRead } from '../../stm32/actions/DebugActionRead.js';
5
5
  import { hex } from '../../stm32/utils/faultUtils.js';
6
6
  import { getMcuFromIoc } from '../../stm32/utils/mcu_utils.js';
7
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.
8
+ /** Reads a peripheral's registers and decodes them with the MCU's SVD data from the TuringCode server. */
9
9
  export default _defineTool({
10
10
  name: 'read_peripheral',
11
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.",
@@ -15,12 +15,14 @@ export default _defineTool({
15
15
  run: async (args) => {
16
16
  const project = await findStm32Project();
17
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
18
+ /** The server sorts registers by offset and flags those not safe to read; cached after the first download */
19
19
  const { peripheral: p } = await loadPeripheral(project.root, chip, args.name, callServer);
20
20
  const regs = p.registers.filter((r) => r.safeToRead);
21
21
  const skipped = p.registers.filter((r) => !r.safeToRead).map((r) => r.name);
22
- // Group registers into runs with gaps of at most 0x40 bytes, so each run is one memory read.
23
- // A register not safe to read ends the run, so no read spans it.
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
+ */
24
26
  const runs = [];
25
27
  let open = false;
26
28
  for (const r of p.registers) {
@@ -37,7 +39,7 @@ export default _defineTool({
37
39
  }
38
40
  const values = new Map();
39
41
  for (const run of runs) {
40
- // Read whole words; a 16-bit register at offset 2 is the upper half of its word
42
+ /** Read whole words; a 16-bit register at offset 2 is the upper half of its word */
41
43
  const start = run[0].addressOffsetInt & ~3;
42
44
  const { words } = await DebugActionRead.run_action({ chip, address: p.baseAddressInt + start, width: 32, count: ((run[run.length - 1].addressOffsetInt - start) >> 2) + 1 });
43
45
  for (const r of run)
@@ -1,2 +1,3 @@
1
+ /** Wakes an ST-LINK whose USB link went to sleep, which makes programming fail. */
1
2
  declare const _default: import("../../stm32/tool.js").ToolDef;
2
3
  export default _default;
@@ -1,7 +1,7 @@
1
1
  import { _defineTool } from '../../stm32/tool.js';
2
2
  import { claimProbe, releaseProbe } from '../../stm32/utils/utils_mutex.js';
3
3
  import { resetStlinkUsb } from '../../stm32/utils/usb_utils.js';
4
- // Wakes an ST-LINK whose USB link went to sleep, which makes programming fail.
4
+ /** Wakes an ST-LINK whose USB link went to sleep, which makes programming fail. */
5
5
  export default _defineTool({
6
6
  name: 'reset_probe_usb',
7
7
  description: 'Restart the USB connection of every connected ST-LINK probe (Windows, pnputil). Use when programming or debugging fails \
@@ -1,2 +1,3 @@
1
+ /** Resets the board over SWD; the chip comes from the project's .ioc. */
1
2
  declare const _default: import("../../stm32/tool.js").ToolDef;
2
3
  export default _default;
@@ -2,7 +2,7 @@ import { _defineTool } from '../../stm32/tool.js';
2
2
  import { findStm32Project } from '../../stm32/utils/project_utils.js';
3
3
  import { getMcuFromIoc } from '../../stm32/utils/mcu_utils.js';
4
4
  import { DebugActionReset } from '../../stm32/actions/DebugActionReset.js';
5
- // Resets the board over SWD; the chip comes from the project's .ioc.
5
+ /** Resets the board over SWD; the chip comes from the project's .ioc. */
6
6
  export default _defineTool({
7
7
  name: 'reset_target',
8
8
  description: "Hardware reset of the project's target board over SWD (probe-rs or STM32_Programmer_CLI).",
@@ -1,2 +1,3 @@
1
+ /** Identifies the connected chip and lists the CubeMX names that fit it, for `project template --mcu`. */
1
2
  declare const _default: import("../../stm32/tool.js").ToolDef;
2
3
  export default _default;
@@ -2,7 +2,7 @@ import { DebugActionInfo } from '../../stm32/actions/DebugActionInfo.js';
2
2
  import { callServer } from '../../stm32/context.js';
3
3
  import { _defineTool } from '../../stm32/tool.js';
4
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`.
5
+ /** Identifies the connected chip and lists the CubeMX names that fit it, for `project template --mcu`. */
6
6
  export default _defineTool({
7
7
  name: 'target_info',
8
8
  description: 'Identify the chip connected to the debug probe (STM32_Programmer_CLI, without resetting it): device ID, name, flash size, core and voltage, ' +
@@ -1,2 +1,3 @@
1
+ /** Static analysis of the server copy of the project's own sources (never Drivers/). */
1
2
  declare const _default: import("../../stm32/tool.js").ToolDef;
2
3
  export default _default;
@@ -2,7 +2,7 @@ import { analyzeProject } from '../../stm32/analysis.js';
2
2
  import { callServer } from '../../stm32/context.js';
3
3
  import { _defineTool } from '../../stm32/tool.js';
4
4
  import { findStm32Project } from '../../stm32/utils/project_utils.js';
5
- // Static analysis of the server copy of the project's own sources (never Drivers/).
5
+ /** Static analysis of the server copy of the project's own sources (never Drivers/). */
6
6
  export default _defineTool({
7
7
  name: 'analysis_static',
8
8
  description: 'Static analysis of your stm32 project on the TuringCode server (its own sources, never Drivers/HAL/CMSIS; \
@@ -1,2 +1,3 @@
1
+ /** Syntax-checks files of the server copy; local project-relative paths are mapped to projects/<name>/. */
1
2
  declare const _default: import("../../stm32/tool.js").ToolDef;
2
3
  export default _default;
@@ -2,7 +2,7 @@ import { syntaxCheckProject } from '../../stm32/analysis.js';
2
2
  import { callServer } from '../../stm32/context.js';
3
3
  import { _defineTool } from '../../stm32/tool.js';
4
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>/.
5
+ /** Syntax-checks files of the server copy; local project-relative paths are mapped to projects/<name>/. */
6
6
  export default _defineTool({
7
7
  name: 'analysis_syntax_check',
8
8
  description: 'Check .c/.h/.cpp/.hpp files of your stm32 project for syntax errors on the TuringCode server \
@@ -1,2 +1,3 @@
1
+ /** Builds the server copy and downloads the resulting ELF into the local build/<preset>/ folder. */
1
2
  declare const _default: import("../../stm32/tool.js").ToolDef;
2
3
  export default _default;
@@ -1,7 +1,7 @@
1
1
  import { runBuild } from '../../stm32/context.js';
2
2
  import { _defineTool } from '../../stm32/tool.js';
3
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.
4
+ /** Builds the server copy and downloads the resulting ELF into the local build/<preset>/ folder. */
5
5
  export default _defineTool({
6
6
  name: 'project_build',
7
7
  description: 'Build the project on the TuringCode server \
@@ -1,2 +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). */
1
2
  declare const _default: import("../../stm32/tool.js").ToolDef;
2
3
  export default _default;
@@ -5,7 +5,7 @@ import { recordBaseline } from '../../stm32/regen.js';
5
5
  import { downloadAndUnzip, zipLink } from '../../stm32/utils/downloadzip_utils.js';
6
6
  import { _defineTool } from '../../stm32/tool.js';
7
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).
8
+ /** Downloads the server's barebone project for an MCU into the agent's working directory (which must be inside the project folder). */
9
9
  export default _defineTool({
10
10
  name: 'project_download_template',
11
11
  description: 'Download a barebone STM32 project template (CMake)' +
@@ -23,12 +23,12 @@ export default _defineTool({
23
23
  const text = await callServer('project_template', { mcu: args.mcu }, 125_000);
24
24
  const mcu = getMcuFromText(text);
25
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
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
28
  if (existsSync(dest))
29
29
  throw new Error(`${dest} already exists; move or delete it first`);
30
30
  await downloadAndUnzip(zipLink(text), ctx.cwd);
31
- await recordBaseline(dest); // what CubeMX generated, for `project regen`'s check
31
+ await recordBaseline(dest); /** what CubeMX generated, for `project regen`'s check */
32
32
  return `Template for ${mcu} downloaded to ${dest}`;
33
33
  },
34
34
  });
@@ -37,7 +37,7 @@ export default _defineTool({
37
37
  if (broken.length)
38
38
  throw new Error(`Sync stopped, nothing uploaded. Fix the USER CODE markers first:\n\n${broken.join('\n\n')}`);
39
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)
40
+ /** warn, not stop: user-written files with markers are reported too (see recordBaseline) */
41
41
  const outside = findings.length
42
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
43
  : '';
@@ -1,2 +1,3 @@
1
+ /** Restores the project's Drivers/ files from the server's copy for the .ioc's MCU; existing files are kept. */
1
2
  declare const _default: import("../../stm32/tool.js").ToolDef;
2
3
  export default _default;
@@ -3,7 +3,7 @@ import { downloadAndUnzip, zipLink } from '../../stm32/utils/downloadzip_utils.j
3
3
  import { _defineTool } from '../../stm32/tool.js';
4
4
  import { findStm32Project } from '../../stm32/utils/project_utils.js';
5
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.
6
+ /** Restores the project's Drivers/ files from the server's copy for the .ioc's MCU; existing files are kept. */
7
7
  export default _defineTool({
8
8
  name: 'stm32_cubetools_download_drivers',
9
9
  description: 'Restore missing Drivers/ files (CMSIS, HAL) of your local stm32 project: downloads the complete Drivers/ folder ' +
@@ -13,7 +13,7 @@ export default _defineTool({
13
13
  const project = await findStm32Project();
14
14
  const mcu = await getMcuFromIoc(project.root);
15
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
16
+ await downloadAndUnzip(zipLink(text), project.root, false); /** throws with the server reply when it has no zip link */
17
17
  return `Restored missing Drivers/ files for ${mcu} into ${project.root}`;
18
18
  },
19
19
  });
@@ -1,2 +1,3 @@
1
+ /** Reports the CLI, server token, project, its newest built ELF, debug session and hardware tool state. */
1
2
  declare const _default: import("../../stm32/tool.js").ToolDef;
2
3
  export default _default;
@@ -7,7 +7,7 @@ import { findProject, findStm32Project } from "../../stm32/utils/project_utils.j
7
7
  import { scanUserSections } from "../../stm32/utils/user_code.js";
8
8
  import { readFile } from "node:fs/promises";
9
9
  import { join } from "node:path";
10
- // Reports the CLI, server token, project, its newest built ELF, debug session and hardware tool state.
10
+ /** Reports the CLI, server token, project, its newest built ELF, debug session and hardware tool state. */
11
11
  export default _defineTool({
12
12
  name: "get_status",
13
13
  description: "Check the server token, project and hardware tool setup: current project and STM32 project, its newest .elf in build/, debug session, USER CODE section mismatches in Core/Src/main.c and Core/Inc/main.h, and the installed debug tools (probe-rs, STM32_Programmer_CLI, STM32CubeIDE, STM32CubeMX).",
@@ -5,7 +5,7 @@ import { queryTester } from "../../core/query.js";
5
5
  import { diag, formatDiagnostics, sortDiagnostics } from "../contract/diagnostics.js";
6
6
  import { failedLoadStatus, loadContract, parseRef, parseTableRef } from "../contract/load.js";
7
7
  import { keyColumns } from "../contract/model.js";
8
- import { evaluateCalc, explain, listItems, mentions, numberColumns, parseCalc, renderCondition, splitQuery, } from "../contract/rules.js";
8
+ import { evaluateCalc, explain, listItems, mentionTester, numberColumns, parseCalc, renderCondition, splitQuery, } from "../contract/rules.js";
9
9
  import { FORMAT_FILES, formatMismatch, readTables } from "./read.js";
10
10
  /**
11
11
  * Why a value does not fit its column's type, or null when it fits.
@@ -175,12 +175,12 @@ export function tableCheck(input) {
175
175
  const textOf = (targets) => {
176
176
  const key = targets.join("\u0000");
177
177
  if (!texts.has(key)) {
178
- texts.set(key, targets.map(t => {
178
+ texts.set(key, mentionTester(targets.map(t => {
179
179
  if (t === "*")
180
180
  return text.textOutside(own ? [scope.name] : []);
181
181
  const r = refRows(t);
182
182
  return r ? r.rows.map(row => row.cells[r.column.name] ?? "").join("\n") : "";
183
- }).join("\n"));
183
+ }).join("\n")));
184
184
  }
185
185
  return texts.get(key);
186
186
  };
@@ -192,7 +192,7 @@ export function tableCheck(input) {
192
192
  known.set(ref, refValues(ref));
193
193
  return known.get(ref).has(v);
194
194
  },
195
- mentioned: (targets, v) => targets.some(t => t !== "*" && unread(t)) || mentions(textOf(targets), v),
195
+ mentioned: (targets, v) => targets.some(t => t !== "*" && unread(t)) || textOf(targets)(v),
196
196
  calc: (param, doc) => evaluateCalc(calc(param), doc, numbers)?.holds ?? true,
197
197
  calcValues: (param, doc) => evaluateCalc(calc(param), doc, numbers),
198
198
  };
@@ -237,7 +237,7 @@ export function tableCheck(input) {
237
237
  const scope = file?.contract.tables.find(t => t.name === on.table);
238
238
  const scopeRows = file?.rows.get(on.table);
239
239
  if (!scope || !scopeRows)
240
- return; // the table is missing: reported as MISSING_TABLE
240
+ return; /** the table is missing: reported as MISSING_TABLE */
241
241
  const hooks = hooksFor(scope, !on.alias);
242
242
  const when = queryTester(rule.when ?? {}, hooks);
243
243
  const matching = scopeRows.filter(r => when(r.doc));