@turingcode/cli 0.3.4 → 0.3.6

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 (140) hide show
  1. package/dist/cli/create-cli.js +6 -4
  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 +2 -2
  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 +2 -2
  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 +3 -3
  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/command.js +3 -8
  64. package/dist/features/project/project_download_template.d.ts +1 -0
  65. package/dist/features/project/project_download_template.js +4 -4
  66. package/dist/features/project/project_sync_to_server.js +2 -2
  67. package/dist/features/project/stm32_cubetools_download_drivers.d.ts +1 -0
  68. package/dist/features/project/stm32_cubetools_download_drivers.js +2 -2
  69. package/dist/features/status/get_status.d.ts +1 -0
  70. package/dist/features/status/get_status.js +1 -1
  71. package/dist/features/table/check.js +5 -5
  72. package/dist/features/table/read.js +9 -9
  73. package/dist/features/tool/command.d.ts +2 -2
  74. package/dist/features/tool/command.js +95 -66
  75. package/dist/lib.d.ts +4 -0
  76. package/dist/lib.js +4 -2
  77. package/dist/stm32/actions/DebugAction.d.ts +4 -2
  78. package/dist/stm32/actions/DebugAction.js +6 -5
  79. package/dist/stm32/actions/DebugActionInfo.d.ts +4 -0
  80. package/dist/stm32/actions/DebugActionInfo.js +4 -2
  81. package/dist/stm32/actions/DebugActionListProbes.d.ts +1 -0
  82. package/dist/stm32/actions/DebugActionListProbes.js +1 -1
  83. package/dist/stm32/actions/DebugActionProgram.d.ts +8 -2
  84. package/dist/stm32/actions/DebugActionProgram.js +9 -7
  85. package/dist/stm32/actions/DebugActionRead.d.ts +8 -7
  86. package/dist/stm32/actions/DebugActionRead.js +5 -3
  87. package/dist/stm32/actions/DebugActionReset.d.ts +2 -1
  88. package/dist/stm32/actions/DebugActionReset.js +1 -1
  89. package/dist/stm32/actions/DebugActionServer.d.ts +4 -0
  90. package/dist/stm32/actions/DebugActionServer.js +4 -2
  91. package/dist/stm32/analysis.d.ts +1 -0
  92. package/dist/stm32/build.d.ts +4 -4
  93. package/dist/stm32/build.js +1 -1
  94. package/dist/stm32/context.js +2 -2
  95. package/dist/stm32/daemon.d.ts +8 -6
  96. package/dist/stm32/daemon.js +25 -18
  97. package/dist/stm32/regen.js +14 -8
  98. package/dist/stm32/session.d.ts +9 -6
  99. package/dist/stm32/session.js +11 -10
  100. package/dist/stm32/sync.d.ts +1 -0
  101. package/dist/stm32/sync.js +5 -3
  102. package/dist/stm32/tool.d.ts +5 -3
  103. package/dist/stm32/toolCommand.d.ts +4 -4
  104. package/dist/stm32/toolCommand.js +1 -3
  105. package/dist/stm32/utils/discover_tools.d.ts +2 -1
  106. package/dist/stm32/utils/discover_tools.js +1 -1
  107. package/dist/stm32/utils/downloadzip_utils.js +4 -4
  108. package/dist/stm32/utils/faultUtils.d.ts +2 -1
  109. package/dist/stm32/utils/faultUtils.js +2 -2
  110. package/dist/stm32/utils/findElf.d.ts +1 -1
  111. package/dist/stm32/utils/findElf.js +1 -1
  112. package/dist/stm32/utils/listSyncFiles.js +12 -10
  113. package/dist/stm32/utils/mcu_utils.d.ts +5 -6
  114. package/dist/stm32/utils/mcu_utils.js +10 -9
  115. package/dist/stm32/utils/project_utils.d.ts +1 -1
  116. package/dist/stm32/utils/project_utils.js +5 -3
  117. package/dist/stm32/utils/usb_utils.js +2 -2
  118. package/dist/stm32/utils/user_code.d.ts +4 -1
  119. package/dist/stm32/utils/user_code.js +5 -3
  120. package/dist/stm32/utils/utils_mutex.js +34 -14
  121. package/dist/stm32/validate.d.ts +1 -0
  122. package/dist/stm32/validate.js +1 -1
  123. package/mods/claude/turingcode-skills/skills/turingcode-cli/SKILL.md +19 -23
  124. package/mods/claude/turingcode-skills/skills/turingcode-firmware-code/SKILL.md +71 -23
  125. package/mods/claude/turingcode-skills/skills/turingcode-firmware-code/references/M_StatusEnum.md +33 -0
  126. package/mods/claude/turingcode-skills/skills/turingcode-firmware-code/references/app-startup.md +49 -0
  127. package/mods/claude/turingcode-skills/skills/turingcode-firmware-code/references/driver.md +103 -0
  128. package/mods/claude/turingcode-skills/skills/turingcode-firmware-code/references/host-protocol.md +48 -0
  129. package/mods/claude/turingcode-skills/skills/turingcode-firmware-code/references/registers-and-units.md +24 -23
  130. package/mods/claude/turingcode-skills/skills/turingcode-firmware-code/references/storage.md +140 -0
  131. package/mods/claude/turingcode-skills/skills/turingcode-firmware-code/references/tasks-and-interrupts.md +66 -0
  132. package/package.json +4 -1
  133. package/dist/features/project/project_build.d.ts +0 -2
  134. package/dist/features/project/project_build.js +0 -22
  135. package/mods/claude/turingcode-skills/skills/turingcode-cli/references/board-and-debug.md +0 -22
  136. package/mods/claude/turingcode-skills/skills/turingcode-cli/references/build-and-check.md +0 -19
  137. package/mods/claude/turingcode-skills/skills/turingcode-cli/references/new-project.md +0 -9
  138. package/mods/claude/turingcode-skills/skills/turingcode-firmware-code/references/concurrency.md +0 -42
  139. package/mods/claude/turingcode-skills/skills/turingcode-firmware-code/references/init-and-timing.md +0 -35
  140. package/mods/claude/turingcode-skills/skills/turingcode-firmware-code/references/input-and-bounds.md +0 -34
@@ -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));
@@ -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
  /**