@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,6 +1,6 @@
1
1
  import { existsSync, readFileSync, statSync } from "node:fs";
2
- import { basename, dirname } from "node:path";
3
- import { parseCsvFolder } from "../../core/tables/csv.js";
2
+ import { basename } from "node:path";
3
+ import { parseCsvFolder, parseCsvTable } from "../../core/tables/csv.js";
4
4
  import { parseMarkdown } from "../../core/tables/markdown.js";
5
5
  /** Most rows read from one table. */
6
6
  export const MAX_TABLE_ROWS = 100_000;
@@ -40,14 +40,14 @@ export function readTables(path, format) {
40
40
  return parseMarkdown(readFileSync(path, "utf-8"), MAX_TABLE_ROWS);
41
41
  if (statSync(path).isDirectory())
42
42
  return parseCsvFolder(path, MAX_TABLE_ROWS);
43
- const doc = parseCsvFolder(dirname(path), MAX_TABLE_ROWS);
43
+ const text = readFileSync(path, "utf-8");
44
+ const only = parseCsvTable(basename(path), text, MAX_TABLE_ROWS);
44
45
  const name = basename(path).replace(/\.csv$/i, "");
45
- const only = doc.tables.get(name);
46
46
  return {
47
- ...doc,
48
- tables: only ? new Map([[name, only]]) : new Map(),
49
- malformed: doc.malformed.filter(([n]) => n === name),
50
- text: only ? readFileSync(path, "utf-8") : "",
51
- textOutside: names => (names.includes(name) ? "" : readFileSync(path, "utf-8")),
47
+ tables: typeof only === "string" ? new Map() : new Map([[name, only]]),
48
+ duplicates: [],
49
+ malformed: typeof only === "string" ? [[name, only]] : [],
50
+ text: typeof only === "string" ? "" : text,
51
+ textOutside: names => (names.includes(name) ? "" : text),
52
52
  };
53
53
  }
@@ -1,5 +1,5 @@
1
- import { CommandModule } from "yargs";
2
- import { ToolInfo } from "../../core/mcp.js";
1
+ import { CommandModule } from 'yargs';
2
+ import { ToolInfo } from '../../core/mcp.js';
3
3
  /**
4
4
  * Formats tools as one line each: name, then the first line of its description.
5
5
  *
@@ -1,6 +1,6 @@
1
- import { readJsonArg } from "../../core/files.js";
2
- import { getGatewayConfig, listTools, runServerTool, TOKEN_HELP } from "../../core/mcp.js";
3
- import { JSON_FLAG } from "../contract/command.js";
1
+ import { readJsonArg } from '../../core/files.js';
2
+ import { getGatewayConfig, listTools, runServerTool, TOKEN_HELP, } from '../../core/mcp.js';
3
+ import { JSON_FLAG } from '../contract/command.js';
4
4
  /**
5
5
  * Names a JSON schema's type compactly: `string`, `integer | null`, `list of string`, `"a" | "b"`, ...
6
6
  *
@@ -12,14 +12,14 @@ import { JSON_FLAG } from "../contract/command.js";
12
12
  */
13
13
  function schemaType(schema) {
14
14
  if (schema.enum)
15
- return schema.enum.map(v => JSON.stringify(v)).join(" | ");
15
+ return schema.enum.map((v) => JSON.stringify(v)).join(' | ');
16
16
  if (schema.anyOf)
17
- return schema.anyOf.map(schemaType).join(" | ");
17
+ return schema.anyOf.map(schemaType).join(' | ');
18
18
  if (schema.$ref)
19
- return schema.$ref.split("/").at(-1);
20
- if (schema.type === "array" && schema.items)
19
+ return schema.$ref.split('/').at(-1);
20
+ if (schema.type === 'array' && schema.items)
21
21
  return `list of ${schemaType(schema.items)}`;
22
- return [schema.type ?? "any"].flat().join(" | ");
22
+ return [schema.type ?? 'any'].flat().join(' | ');
23
23
  }
24
24
  /**
25
25
  * Formats tools as one line each: name, then the first line of its description.
@@ -31,8 +31,11 @@ function schemaType(schema) {
31
31
  * formatToolSummaries([{ name: "read_file", description: "Reads a file.\nMore." }]); // "read_file Reads a file.\n"
32
32
  */
33
33
  export function formatToolSummaries(tools) {
34
- const width = Math.max(0, ...tools.map(t => t.name.length));
35
- return tools.map(t => `${t.name.padEnd(width)} ${t.description?.trim().split("\n")[0] ?? ""}`.trimEnd() + "\n").join("");
34
+ const width = Math.max(0, ...tools.map((t) => t.name.length));
35
+ return tools
36
+ .map((t) => `${t.name.padEnd(width)} ${t.description?.trim().split('\n')[0] ?? ''}`.trimEnd() +
37
+ '\n')
38
+ .join('');
36
39
  }
37
40
  /**
38
41
  * Formats tools with their full description and arguments, one `## <name>` section per tool.
@@ -46,16 +49,28 @@ export function formatToolSummaries(tools) {
46
49
  * // "## read_file\n\nReads a file.\n\nArguments:\n- path (string, required)\n"
47
50
  */
48
51
  export function formatToolDetails(tools) {
49
- return tools.map(tool => {
52
+ return tools
53
+ .map((tool) => {
50
54
  const schema = (tool.inputSchema ?? {});
51
55
  const args = Object.entries(schema.properties ?? {}).map(([name, prop]) => {
52
- const facts = [schemaType(prop), schema.required?.includes(name) ? "required" : undefined,
53
- prop.default !== undefined ? `default ${JSON.stringify(prop.default)}` : undefined].filter(Boolean);
54
- return `- ${name} (${facts.join(", ")})${prop.description ? `: ${prop.description.trim()}` : ""}`;
56
+ const facts = [
57
+ schemaType(prop),
58
+ schema.required?.includes(name) ? 'required' : undefined,
59
+ prop.default !== undefined
60
+ ? `default ${JSON.stringify(prop.default)}`
61
+ : undefined,
62
+ ].filter(Boolean);
63
+ return `- ${name} (${facts.join(', ')})${prop.description ? `: ${prop.description.trim()}` : ''}`;
55
64
  });
56
- return [`## ${tool.name}`, tool.description?.trim(), args.length ? `Arguments:\n${args.join("\n")}` : "Arguments: none"]
57
- .filter(Boolean).join("\n\n") + "\n";
58
- }).join("\n");
65
+ return ([
66
+ `## ${tool.name}`,
67
+ tool.description?.trim(),
68
+ args.length ? `Arguments:\n${args.join('\n')}` : 'Arguments: none',
69
+ ]
70
+ .filter(Boolean)
71
+ .join('\n\n') + '\n');
72
+ })
73
+ .join('\n');
59
74
  }
60
75
  /**
61
76
  * Picks the named tools, in the order given.
@@ -66,85 +81,99 @@ export function formatToolDetails(tools) {
66
81
  * @throws {Error} When a name is not among the tools.
67
82
  */
68
83
  export function pickTools(tools, names) {
69
- const unknown = names.filter(name => !tools.some(t => t.name === name));
84
+ const unknown = names.filter((name) => !tools.some((t) => t.name === name));
70
85
  if (unknown.length) {
71
- throw new Error(`unknown tool ${unknown.map(n => `'${n}'`).join(", ")}; \`tool list\` shows the tools you can call`);
86
+ throw new Error(`unknown tool ${unknown.map((n) => `'${n}'`).join(', ')}; \`tool list\` shows the tools you can call`);
72
87
  }
73
- return names.map(name => tools.find(t => t.name === name));
88
+ return names.map((name) => tools.find((t) => t.name === name));
74
89
  }
75
90
  const list = {
76
- command: "list",
77
- describe: "List the server tools your gateway token can call, one line each",
78
- builder: cli => cli
79
- .example("$0 tool list", "each tool: name and the first line of its description")
80
- .epilogue([
81
- "Prints the tools of the Turing Code server that your token may call, one line each: the name",
82
- "and the first line of its description. The list comes from the server, so it is always current.",
83
- "`tool describe <name>` shows a tool's full description and arguments, before `tool call`.",
84
- "Exit: 0 ok, 1 failed request, 2 bad arguments.",
91
+ command: 'list',
92
+ describe: 'List the server tools your gateway token can call, one line each',
93
+ builder: (cli) => cli.epilogue([
94
+ 'Prints the tool list of the Turing Code server.',
95
+ "\n- `tool describe <name>` shows a tool's full description and arguments, use before `tool call`.",
85
96
  TOKEN_HELP,
86
- ].join("\n")),
97
+ ].join('\n')),
87
98
  handler: async () => {
88
99
  const { token, url } = getGatewayConfig();
89
100
  process.stdout.write(formatToolSummaries(await listTools(token, url)));
90
101
  },
91
102
  };
92
103
  const describe = {
93
- command: "describe <names..>",
94
- describe: "Show the full description and arguments of the named server tools",
95
- builder: cli => cli
96
- .positional("names", { type: "string", array: true, describe: "One or more tool names, from `tool list`" })
97
- .options({ json: { ...JSON_FLAG, describe: "Print the tools as one-line JSON, with the raw input schemas" } })
98
- .example("$0 tool describe <name>", "one tool")
99
- .example("$0 tool describe <name> <other name>", "several tools")
104
+ command: 'describe <names..>',
105
+ describe: 'Show the full description and arguments of the named server tools',
106
+ builder: (cli) => cli
107
+ .positional('names', {
108
+ type: 'string',
109
+ array: true,
110
+ describe: 'One or more tool names, from `tool list`',
111
+ })
112
+ .options({
113
+ json: {
114
+ ...JSON_FLAG,
115
+ describe: 'Print the tools as one-line JSON, with the raw input schemas',
116
+ },
117
+ })
118
+ .example('$0 tool describe <name>', 'one tool')
119
+ .example('$0 tool describe <name> <other name>', 'several tools')
100
120
  .epilogue([
101
- "Prints each named tool as a `## <name>` section: its full description and its arguments",
102
- "(type, required, default, description), which go in `tool call <name> --args`.",
103
- "Exit: 0 ok, 1 unknown tool name or failed request, 2 bad arguments.",
121
+ 'Prints each named tool and its full description and its arguments',
122
+ '(type, required, default, description), which go in `tool call <name> --args`.',
104
123
  TOKEN_HELP,
105
- ].join("\n")),
124
+ ].join('\n')),
106
125
  handler: async (args) => {
107
126
  const { token, url } = getGatewayConfig();
108
127
  const tools = pickTools(await listTools(token, url), args.names);
109
- process.stdout.write(args.json ? JSON.stringify(tools) + "\n" : formatToolDetails(tools));
128
+ process.stdout.write(args.json ? JSON.stringify(tools) + '\n' : formatToolDetails(tools));
110
129
  },
111
130
  };
112
131
  const call = {
113
- command: "call <name>",
114
- describe: "Call a server tool and print its text result (redirect it to save it in a file)",
115
- builder: cli => cli
116
- .positional("name", { type: "string", describe: "Tool name, from `tool list`" })
117
- .options({ args: { type: "string", coerce: readJsonArg, describe: "Tool arguments: inline JSON object or .json path" } })
118
- .check(argv => {
132
+ command: 'call <name>',
133
+ describe: 'Call a server tool and print its text result (redirect it to save it in a file)',
134
+ builder: (cli) => cli
135
+ .positional('name', { type: 'string', describe: 'Tool name, from `tool list`' })
136
+ .options({
137
+ args: {
138
+ type: 'string',
139
+ coerce: readJsonArg,
140
+ describe: 'Tool arguments: inline JSON object or .json path',
141
+ },
142
+ })
143
+ .check((argv) => {
119
144
  const value = argv.args;
120
- if (value !== undefined && (typeof value !== "object" || value === null || Array.isArray(value))) {
121
- throw new Error("--args must be a JSON object");
145
+ if (value !== undefined &&
146
+ (typeof value !== 'object' || value === null || Array.isArray(value))) {
147
+ throw new Error('--args must be a JSON object');
122
148
  }
123
149
  return true;
124
150
  })
125
- .example(`$0 tool call <name> --args '{"<arg>":"<value>"}'`, "inline arguments, result printed")
126
- .example("$0 tool call <name> --args args.json > result.md", "arguments from a file, result saved to a file")
151
+ .example(`$0 tool call <name> --args '{"<arg>":"<value>"}'`, 'inline arguments, result printed')
152
+ .example('$0 tool call <name> --args args.json > result.md', 'arguments from a file, result saved to a file')
127
153
  .epilogue([
128
- "Calls one tool of the Turing Code server. <name> comes from `tool list`, its arguments from",
129
- "`tool describe <name>`.",
130
- "--args is a JSON object, inline or a path to a .json file;",
131
- "leave it out for a tool without arguments.",
154
+ 'Calls one tool of the Turing Code server. <name> comes from `tool list`, its arguments from',
155
+ '`tool describe <name>`.',
156
+ '--args is a JSON object, inline or a path to a .json file;',
157
+ 'leave it out for a tool without arguments.',
132
158
  "The tool's text result goes to stdout: redirect it (`> file`) to save a large result without",
133
- "reading it. A tool error is printed to stderr.",
134
- "Exit: 0 ok, 1 tool error or failed request, 2 bad arguments (e.g. --args not a JSON object).",
159
+ 'reading it. A tool error is printed to stderr.',
135
160
  TOKEN_HELP,
136
- ].join("\n")),
137
- handler: args => runServerTool(args.name, (args.args ?? {})),
161
+ ].join('\n')),
162
+ handler: (args) => runServerTool(args.name, (args.args ?? {})),
138
163
  };
139
164
  const command = {
140
- command: "tool",
141
- describe: "List, describe or call tools on the Turing Code server",
142
- builder: cli => cli.command(list).command(describe).command(call).demandCommand(1, "tool needs a subcommand: list, describe or call")
165
+ command: 'tool',
166
+ describe: 'List, describe or call tools on the Turing Code server',
167
+ builder: (cli) => cli
168
+ .command(list)
169
+ .command(describe)
170
+ .command(call)
171
+ .demandCommand(1, 'tool needs a subcommand: list, describe or call')
143
172
  .epilogue([
144
- "Typical use: `tool list` to find a tool, `tool describe <name>` for its arguments, then",
145
- "`tool call <name> --args ... > file` to save its result.",
173
+ 'Typical use: `tool list` to find a tool, `tool describe <name>` for its arguments, then',
174
+ '`tool call <name> --args ... > file` to save its result.',
146
175
  TOKEN_HELP,
147
- ].join("\n")),
176
+ ].join('\n')),
148
177
  handler: () => { },
149
178
  };
150
179
  export default command;
package/dist/lib.d.ts CHANGED
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Library entry of @turingcode/cli, for the TuringCode VS Code extension: the server client and the STM32 project
3
+ * workflows the CLI commands run, without their command line parsing.
4
+ */
1
5
  export { callTool, callToolText, listTools, DEFAULT_URL } from "./core/mcp.js";
2
6
  export type { ToolInfo, ToolResult } from "./core/mcp.js";
3
7
  export { syncProjectFromServer, syncProjectToServer } from "./stm32/sync.js";
package/dist/lib.js CHANGED
@@ -1,5 +1,7 @@
1
- // Library entry of @turingcode/cli, for the TuringCode VS Code extension: the server client and the STM32 project
2
- // workflows the CLI commands run, without their command line parsing.
1
+ /**
2
+ * Library entry of @turingcode/cli, for the TuringCode VS Code extension: the server client and the STM32 project
3
+ * workflows the CLI commands run, without their command line parsing.
4
+ */
3
5
  export { callTool, callToolText, listTools, DEFAULT_URL } from "./core/mcp.js";
4
6
  export { syncProjectFromServer, syncProjectToServer } from "./stm32/sync.js";
5
7
  export { recordBaseline, regenerateProject } from "./stm32/regen.js";
@@ -1,5 +1,7 @@
1
1
  import { DiscoveredSystemTool, SystemToolId } from '../utils/discover_tools.js';
2
+ /** Values for the {placeholders}; booleans switch optional argument groups on and off */
2
3
  export type ActionParams = Record<string, string | number | boolean>;
4
+ /** A command line argument with {name} placeholders, or a group of them used only when the boolean param `if` is true */
3
5
  export type CommandArg = string | {
4
6
  if: string;
5
7
  args: string[];
@@ -15,10 +17,10 @@ export interface ToolOutput {
15
17
  * Everything is static: subclasses set the fields and are used without an instance (DebugActionRead.run_action(...)).
16
18
  */
17
19
  export declare abstract class DebugAction {
18
- static readonly title: string;
20
+ static readonly title: string; /** e.g. "Reading memory", for error messages */
19
21
  static readonly commands: Partial<Record<SystemToolId, CommandArg[]>>;
20
22
  static readonly timeout: number;
21
- static readonly exclusive: boolean;
23
+ static readonly exclusive: boolean; /** the run opens the probe, so only one such run happens at a time */
22
24
  /**
23
25
  * Converts the action params to the placeholder values; override to add derived or formatted values.
24
26
  * @param params action params
@@ -1,5 +1,6 @@
1
- // Base of the debug actions: each one knows the command line of every tool that can run it.
2
- //
1
+ /**
2
+ * Base of the debug actions: each one knows the command line of every tool that can run it.
3
+ */
3
4
  import { execFile } from 'node:child_process';
4
5
  import { promisify } from 'node:util';
5
6
  import { discover_system_tools, toolHint, } from '../utils/discover_tools.js';
@@ -11,10 +12,10 @@ const run = promisify(execFile);
11
12
  * Everything is static: subclasses set the fields and are used without an instance (DebugActionRead.run_action(...)).
12
13
  */
13
14
  export class DebugAction {
14
- static title; // e.g. "Reading memory", for error messages
15
+ static title; /** e.g. "Reading memory", for error messages */
15
16
  static commands;
16
17
  static timeout = 30_000;
17
- static exclusive = true; // the run opens the probe, so only one such run happens at a time
18
+ static exclusive = true; /** the run opens the probe, so only one such run happens at a time */
18
19
  /**
19
20
  * Converts the action params to the placeholder values; override to add derived or formatted values.
20
21
  * @param params action params
@@ -33,7 +34,7 @@ export class DebugAction {
33
34
  const installed = await discover_system_tools(refresh);
34
35
  return ids.map((id) => installed.find((t) => t.id === id)).find((t) => t);
35
36
  };
36
- // Look again before failing, in case a tool was installed after the cached discovery
37
+ /** Look again before failing, in case a tool was installed after the cached discovery */
37
38
  const tool = (await first(false)) ?? (await first(true));
38
39
  if (!tool)
39
40
  throw new Error(`${this.title} needs ${ids.map((id) => `${id} (${toolHint(id)})`).join(' or ')}`);
@@ -1,4 +1,8 @@
1
1
  import { DebugAction } from './DebugAction.js';
2
+ /**
3
+ * Connects to the target without resetting it and reports what STM32_Programmer_CLI identifies
4
+ * (device ID, name, flash size, core). probe-rs cannot name a chip it is not told, so it has no command here.
5
+ */
2
6
  export declare class DebugActionInfo extends DebugAction {
3
7
  static readonly title = "Identifying the target";
4
8
  static readonly commands: {
@@ -1,6 +1,8 @@
1
1
  import { DebugAction } from './DebugAction.js';
2
- // Connects to the target without resetting it and reports what STM32_Programmer_CLI identifies
3
- // (device ID, name, flash size, core). probe-rs cannot name a chip it is not told, so it has no command here.
2
+ /**
3
+ * Connects to the target without resetting it and reports what STM32_Programmer_CLI identifies
4
+ * (device ID, name, flash size, core). probe-rs cannot name a chip it is not told, so it has no command here.
5
+ */
4
6
  export class DebugActionInfo extends DebugAction {
5
7
  static title = 'Identifying the target';
6
8
  static commands = {
@@ -1,4 +1,5 @@
1
1
  import { DebugAction } from './DebugAction.js';
2
+ /** Lists the connected debug probes. Does not open a probe, so it skips the busy lock. */
2
3
  export declare class DebugActionListProbes extends DebugAction {
3
4
  static readonly title = "Listing probes";
4
5
  static readonly exclusive = false;
@@ -1,5 +1,5 @@
1
1
  import { DebugAction } from './DebugAction.js';
2
- // Lists the connected debug probes. Does not open a probe, so it skips the busy lock.
2
+ /** Lists the connected debug probes. Does not open a probe, so it skips the busy lock. */
3
3
  export class DebugActionListProbes extends DebugAction {
4
4
  static title = 'Listing probes';
5
5
  static exclusive = false;
@@ -1,9 +1,15 @@
1
1
  import { DebugAction, ToolOutput } from './DebugAction.js';
2
2
  import { DiscoveredSystemTool } from '../utils/discover_tools.js';
3
3
  export type ProgramParams = {
4
- chip: string;
5
- elf: string;
4
+ chip: string; /** probe-rs target name (e.g. STM32G474RETx) */
5
+ elf: string; /** path of the ELF to flash */
6
6
  };
7
+ /**
8
+ * Writes an ELF over SWD, verifies it and resets the target.
9
+ * ponytail: uses the only connected probe
10
+ * (probe-rs --non-interactive fails if there are several);
11
+ * pin the probe once the sidebar has a probe picker
12
+ */
7
13
  export declare class DebugActionProgram extends DebugAction {
8
14
  static readonly title = "Programming";
9
15
  static readonly timeout = 180000;
@@ -1,7 +1,7 @@
1
1
  import { DebugAction } from './DebugAction.js';
2
2
  import { DebugActionRead } from './DebugActionRead.js';
3
3
  import { hasSingleBankFlashAlgo } from '../utils/mcu_utils.js';
4
- // STM32G4 FLASH_OPTR and its DBANK bit (dual-bank mode, 2 KB pages, bank 2 at 0x08040000).
4
+ /** STM32G4 FLASH_OPTR and its DBANK bit (dual-bank mode, 2 KB pages, bank 2 at 0x08040000). */
5
5
  const G4_FLASH_OPTR = 0x40022020;
6
6
  const G4_OPTR_DBANK = 1 << 22;
7
7
  /**
@@ -21,10 +21,12 @@ async function needsChipErase(chip) {
21
21
  });
22
22
  return (optr & G4_OPTR_DBANK) !== 0;
23
23
  }
24
- // Writes an ELF over SWD, verifies it and resets the target.
25
- // ponytail: uses the only connected probe
26
- // (probe-rs --non-interactive fails if there are several);
27
- // pin the probe once the sidebar has a probe picker
24
+ /**
25
+ * Writes an ELF over SWD, verifies it and resets the target.
26
+ * ponytail: uses the only connected probe
27
+ * (probe-rs --non-interactive fails if there are several);
28
+ * pin the probe once the sidebar has a probe picker
29
+ */
28
30
  export class DebugActionProgram extends DebugAction {
29
31
  static title = 'Programming';
30
32
  static timeout = 180_000;
@@ -65,11 +67,11 @@ export class DebugActionProgram extends DebugAction {
65
67
  return await super.run_action({ ...p, chipErase: false }, tool);
66
68
  }
67
69
  catch (e) {
68
- // A failed OPTR read (e.g. probe unplugged) means no retry, and the programming error is the one to report
70
+ /** A failed OPTR read (e.g. probe unplugged) means no retry, and the programming error is the one to report */
69
71
  if (tool.id !== 'probe-rs' || !(await needsChipErase(p.chip).catch(() => false)))
70
72
  throw e;
71
73
  const out = await super.run_action({ ...p, chipErase: true }, tool);
72
- // appended to stderr so tail() keeps it
74
+ /** appended to stderr so tail() keeps it */
73
75
  return {
74
76
  ...out,
75
77
  stderr: `${out.stderr}\nDual-bank flash (DBANK=1): first attempt failed, erased the whole chip and programmed again. First error:\n${e.message.slice(-500)}`,
@@ -1,11 +1,12 @@
1
1
  import { DebugAction, ToolOutput } from './DebugAction.js';
2
2
  import { DiscoveredSystemTool } from '../utils/discover_tools.js';
3
3
  export type ReadParams = {
4
- chip: string;
5
- address: number;
6
- width: 8 | 16 | 32;
7
- count: number;
4
+ chip: string; /** probe-rs target name (e.g. STM32G474RETx) */
5
+ address: number; /** start address, aligned to the word width */
6
+ width: 8 | 16 | 32; /** word width in bits */
7
+ count: number; /** number of words to read */
8
8
  };
9
+ /** Reads target memory without halting the core. Never writes to the target. */
9
10
  export declare class DebugActionRead extends DebugAction {
10
11
  static readonly title = "Reading memory";
11
12
  static readonly commands: {
@@ -13,9 +14,9 @@ export declare class DebugActionRead extends DebugAction {
13
14
  STM32_Programmer_CLI: string[];
14
15
  };
15
16
  protected static values(p: ReadParams): {
16
- chip: string;
17
- width: 8 | 16 | 32;
18
- count: number;
17
+ chip: string; /** probe-rs target name (e.g. STM32G474RETx) */
18
+ width: 8 | 16 | 32; /** word width in bits */
19
+ count: number; /** number of words to read */
19
20
  address: string;
20
21
  bytes: number;
21
22
  };
@@ -1,5 +1,5 @@
1
1
  import { DebugAction } from './DebugAction.js';
2
- // Reads target memory without halting the core. Never writes to the target.
2
+ /** Reads target memory without halting the core. Never writes to the target. */
3
3
  export class DebugActionRead extends DebugAction {
4
4
  static title = 'Reading memory';
5
5
  static commands = {
@@ -34,8 +34,10 @@ export class DebugActionRead extends DebugAction {
34
34
  */
35
35
  static async run_action(p, tool) {
36
36
  const out = await super.run_action(p, tool);
37
- // probe-rs prints the words, newer versions after an "40022020: " address prefix;
38
- // STM32_Programmer_CLI prints "0x40022020 : FFEFF8AA ..." lines after its connection info
37
+ /**
38
+ * probe-rs prints the words, newer versions after an "40022020: " address prefix;
39
+ * STM32_Programmer_CLI prints "0x40022020 : FFEFF8AA ..." lines after its connection info
40
+ */
39
41
  const data = out.tool === 'probe-rs'
40
42
  ? out.stdout.replace(/^\s*(0x)?[0-9a-fA-F]+\s*:/gm, '')
41
43
  : [...out.stdout.matchAll(/^0x[0-9A-Fa-f]+\s*:(.*)$/gm)]
@@ -1,7 +1,8 @@
1
1
  import { DebugAction } from './DebugAction.js';
2
2
  export type ResetParams = {
3
- chip: string;
3
+ chip: string; /** probe-rs target name (e.g. STM32G474RETx) */
4
4
  };
5
+ /** Resets the target through the only connected probe. */
5
6
  export declare class DebugActionReset extends DebugAction {
6
7
  static readonly title = "Reset";
7
8
  static readonly commands: {
@@ -1,5 +1,5 @@
1
1
  import { DebugAction } from './DebugAction.js';
2
- // Resets the target through the only connected probe.
2
+ /** Resets the target through the only connected probe. */
3
3
  export class DebugActionReset extends DebugAction {
4
4
  static title = 'Reset';
5
5
  static commands = {
@@ -1,4 +1,8 @@
1
1
  import { DebugAction } from './DebugAction.js';
2
+ /**
3
+ * Debug adapter that speaks DAP over stdio; debug_utils spawns it and sends the session requests (breakpoints, step, ...).
4
+ * Only probe-rs has one; the launch config in debug_utils is probe-rs specific.
5
+ */
2
6
  export declare class DebugActionServer extends DebugAction {
3
7
  static readonly title = "Debug server";
4
8
  static readonly commands: {
@@ -1,6 +1,8 @@
1
1
  import { DebugAction } from './DebugAction.js';
2
- // Debug adapter that speaks DAP over stdio; debug_utils spawns it and sends the session requests (breakpoints, step, ...).
3
- // Only probe-rs has one; the launch config in debug_utils is probe-rs specific.
2
+ /**
3
+ * Debug adapter that speaks DAP over stdio; debug_utils spawns it and sends the session requests (breakpoints, step, ...).
4
+ * Only probe-rs has one; the launch config in debug_utils is probe-rs specific.
5
+ */
4
6
  export class DebugActionServer extends DebugAction {
5
7
  static title = 'Debug server';
6
8
  static commands = {
@@ -1,3 +1,4 @@
1
+ /** Server syntax check and static analysis of the STM32 project. Used by the project commands and the VS Code extension. */
1
2
  import { ServerCall } from './sync.js';
2
3
  import { Project } from './tool.js';
3
4
  /**
@@ -2,10 +2,10 @@ import { ServerCall } from './sync.js';
2
2
  import { Project } from './tool.js';
3
3
  export declare const BUILD_PRESETS: string[];
4
4
  export interface BuildResult {
5
- text: string;
6
- ok: boolean;
7
- elf?: string;
8
- note: string;
5
+ text: string; /** the server's build reply */
6
+ ok: boolean; /** the build succeeded */
7
+ elf?: string; /** local path of the downloaded ELF */
8
+ note: string; /** where the ELF went, or why it was not downloaded; empty for a failed build */
9
9
  }
10
10
  /**
11
11
  * Downloads the .elf next to the build reply's map file into the same path in the local project.
@@ -1,4 +1,4 @@
1
- // Server build of the STM32 project and download of its ELF. Used by the project commands and the VS Code extension.
1
+ /** Server build of the STM32 project and download of its ELF. Used by the project commands and the VS Code extension. */
2
2
  import { join } from 'node:path';
3
3
  import { replyBody } from '../core/mcp.js';
4
4
  import { downloadFile } from './utils/downloadzip_utils.js';
@@ -1,4 +1,4 @@
1
- // Server calls, builds and the CLI version for the STM32 tools, run in the CLI and in the debug daemon.
1
+ /** Server calls, builds and the CLI version for the STM32 tools, run in the CLI and in the debug daemon. */
2
2
  import { readFileSync } from 'node:fs';
3
3
  import { fileURLToPath } from 'node:url';
4
4
  import { callToolText, getGatewayConfig } from '../core/mcp.js';
@@ -36,7 +36,7 @@ export function callServer(name, args, timeoutMs) {
36
36
  */
37
37
  export async function runBuild(project, preset, verbose = false) {
38
38
  const r = await buildProject(callServer, project, preset);
39
- // a failed build keeps the full reply, so no error is hidden
39
+ /** a failed build keeps the full reply, so no error is hidden */
40
40
  const text = r.ok && !verbose ? compactBuildReply(r.text) : r.text;
41
41
  return r.note ? `${text}\n\n${r.note}` : text;
42
42
  }
@@ -1,15 +1,16 @@
1
1
  import { ToolDef } from './tool.js';
2
2
  export interface DaemonPaths {
3
- dir: string;
3
+ dir: string; /** <project>/.turingcode */
4
4
  token: string;
5
5
  socket: string;
6
- lock: string;
7
- log: string;
6
+ lock: string; /** probe lock file, see utils_mutex */
7
+ log: string; /** the daemon's stderr, for start failures */
8
8
  }
9
+ /** One request and one response per line, newline-delimited JSON. */
9
10
  export interface DaemonRequest {
10
11
  id: number;
11
12
  token: string;
12
- cwd: string;
13
+ cwd: string; /** the CLI's working directory */
13
14
  tool: string;
14
15
  args: Record<string, unknown>;
15
16
  }
@@ -22,7 +23,7 @@ export type DaemonResponse = {
22
23
  ok: false;
23
24
  error: string;
24
25
  };
25
- export declare const PING = "ping";
26
+ export declare const PING = "ping"; /** reserved tool: replies {"session": <true while a debug session runs>} */
26
27
  /**
27
28
  * Daemon files of one project, all inside <project>/.turingcode. Windows paths are lowercased so "c:" and "C:" give the same pipe.
28
29
  * shortcut: Unix socket paths are limited to ~104 chars, so a very deep project folder fails to listen; move the socket to a short dir if that bites.
@@ -36,7 +37,8 @@ export declare function daemonPaths(root: string): DaemonPaths;
36
37
  * @param tool tool name, or PING
37
38
  * @param args tool arguments
38
39
  * @param cwd the caller's working directory
39
- * @returns the daemon's response, or undefined when no daemon is running
40
+ * @returns the daemon's response, an error response when it closed the connection after the request was sent, or
41
+ * undefined when no daemon is running (the request was never sent)
40
42
  */
41
43
  export declare function forwardToDaemon(paths: DaemonPaths, tool: string, args: Record<string, unknown>, cwd: string): Promise<DaemonResponse | undefined>;
42
44
  /**