@turingcode/cli 0.2.13 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/cli/create-cli.d.ts +10 -0
- package/dist/cli/create-cli.js +17 -4
- package/dist/cli/index.d.ts +9 -0
- package/dist/cli/index.js +5 -1
- package/dist/core/bound-error.d.ts +10 -0
- package/dist/core/date.d.ts +12 -0
- package/dist/core/exact/expression.d.ts +49 -0
- package/dist/core/exact/fraction.d.ts +85 -0
- package/dist/core/exact/fraction.js +2 -0
- package/dist/core/files.d.ts +44 -0
- package/dist/core/files.js +48 -3
- package/dist/core/json-shape.d.ts +45 -0
- package/dist/core/json-shape.js +1 -0
- package/dist/core/mcp.d.ts +92 -0
- package/dist/core/mcp.js +56 -15
- package/dist/core/query.d.ts +69 -0
- package/dist/core/query.js +2 -2
- package/dist/core/report.d.ts +11 -0
- package/dist/core/tables/csv.d.ts +29 -0
- package/dist/core/tables/csv.js +54 -25
- package/dist/core/tables/markdown.d.ts +22 -0
- package/dist/core/tables/markdown.js +8 -2
- package/dist/core/tables/types.d.ts +25 -0
- package/dist/features/contract/check.d.ts +30 -0
- package/dist/features/contract/command.d.ts +12 -0
- package/dist/features/contract/command.js +64 -64
- package/dist/features/contract/describe.d.ts +22 -0
- package/dist/features/contract/diagnostics.d.ts +111 -0
- package/dist/features/contract/diagnostics.js +7 -4
- package/dist/features/contract/load.d.ts +58 -0
- package/dist/features/contract/load.js +4 -4
- package/dist/features/contract/model.d.ts +67 -0
- package/dist/features/contract/rules.d.ts +149 -0
- package/dist/features/contract/rules.js +31 -4
- package/dist/features/debug/clear_breakpoint.d.ts +3 -0
- package/dist/features/debug/clear_breakpoint.js +24 -0
- package/dist/features/debug/command.d.ts +5 -0
- package/dist/features/debug/command.js +66 -0
- package/dist/features/debug/continue.d.ts +3 -0
- package/dist/features/debug/continue.js +22 -0
- package/dist/features/debug/debug_start.d.ts +3 -0
- package/dist/features/debug/debug_start.js +22 -0
- package/dist/features/debug/debug_stop.d.ts +3 -0
- package/dist/features/debug/debug_stop.js +11 -0
- package/dist/features/debug/evaluate.d.ts +3 -0
- package/dist/features/debug/evaluate.js +48 -0
- package/dist/features/debug/get_stack.d.ts +3 -0
- package/dist/features/debug/get_stack.js +14 -0
- package/dist/features/debug/get_variables.d.ts +3 -0
- package/dist/features/debug/get_variables.js +26 -0
- package/dist/features/debug/halt.d.ts +3 -0
- package/dist/features/debug/halt.js +16 -0
- package/dist/features/debug/set_breakpoint.d.ts +3 -0
- package/dist/features/debug/set_breakpoint.js +30 -0
- package/dist/features/debug/step.d.ts +3 -0
- package/dist/features/debug/step.js +23 -0
- package/dist/features/install-mods/command.d.ts +6 -0
- package/dist/features/install-mods/command.js +18 -0
- package/dist/features/install-mods/install.d.ts +23 -0
- package/dist/features/install-mods/install.js +49 -0
- package/dist/features/install-skills/command.d.ts +7 -0
- package/dist/features/install-skills/command.js +22 -0
- package/dist/features/install-skills/install.d.ts +14 -0
- package/dist/features/install-skills/install.js +29 -0
- package/dist/features/probe/command.d.ts +5 -0
- package/dist/features/probe/command.js +112 -0
- package/dist/features/probe/kill_all_debuggers.d.ts +3 -0
- package/dist/features/probe/kill_all_debuggers.js +50 -0
- package/dist/features/probe/list_probes.d.ts +3 -0
- package/dist/features/probe/list_probes.js +8 -0
- package/dist/features/probe/program_project.d.ts +3 -0
- package/dist/features/probe/program_project.js +29 -0
- package/dist/features/probe/read_fault_status.d.ts +3 -0
- package/dist/features/probe/read_fault_status.js +19 -0
- package/dist/features/probe/read_memory.d.ts +3 -0
- package/dist/features/probe/read_memory.js +36 -0
- package/dist/features/probe/read_peripheral.d.ts +3 -0
- package/dist/features/probe/read_peripheral.js +60 -0
- package/dist/features/probe/reset_probe_usb.d.ts +3 -0
- package/dist/features/probe/reset_probe_usb.js +17 -0
- package/dist/features/probe/reset_target.d.ts +3 -0
- package/dist/features/probe/reset_target.js +16 -0
- package/dist/features/probe/target_info.d.ts +3 -0
- package/dist/features/probe/target_info.js +34 -0
- package/dist/features/project/analysis_static.d.ts +3 -0
- package/dist/features/project/analysis_static.js +19 -0
- package/dist/features/project/analysis_syntax_check.d.ts +3 -0
- package/dist/features/project/analysis_syntax_check.js +21 -0
- package/dist/features/project/command.d.ts +5 -0
- package/dist/features/project/command.js +64 -0
- package/dist/features/project/project_build.d.ts +3 -0
- package/dist/features/project/project_build.js +22 -0
- package/dist/features/project/project_download_template.d.ts +3 -0
- package/dist/features/project/project_download_template.js +34 -0
- package/dist/features/project/project_regenerate.d.ts +2 -0
- package/dist/features/project/project_regenerate.js +20 -0
- package/dist/features/project/project_sync_from_server.d.ts +2 -0
- package/dist/features/project/project_sync_from_server.js +13 -0
- package/dist/features/project/project_sync_to_server.d.ts +2 -0
- package/dist/features/project/project_sync_to_server.js +51 -0
- package/dist/features/project/stm32_cubetools_download_drivers.d.ts +3 -0
- package/dist/features/project/stm32_cubetools_download_drivers.js +19 -0
- package/dist/features/status/command.d.ts +2 -0
- package/dist/features/status/command.js +6 -0
- package/dist/features/status/get_status.d.ts +3 -0
- package/dist/features/status/get_status.js +44 -0
- package/dist/features/table/check.d.ts +38 -0
- package/dist/features/table/check.js +5 -5
- package/dist/features/table/command.d.ts +3 -0
- package/dist/features/table/read.d.ts +28 -0
- package/dist/features/table/read.js +9 -9
- package/dist/features/tool/command.d.ts +35 -0
- package/dist/features/tool/command.js +95 -66
- package/dist/lib.d.ts +15 -0
- package/dist/lib.js +11 -0
- package/dist/stm32/actions/DebugAction.d.ts +65 -0
- package/dist/stm32/actions/DebugAction.js +106 -0
- package/dist/stm32/actions/DebugActionInfo.d.ts +11 -0
- package/dist/stm32/actions/DebugActionInfo.js +11 -0
- package/dist/stm32/actions/DebugActionListProbes.d.ts +10 -0
- package/dist/stm32/actions/DebugActionListProbes.js +10 -0
- package/dist/stm32/actions/DebugActionProgram.d.ts +34 -0
- package/dist/stm32/actions/DebugActionProgram.js +81 -0
- package/dist/stm32/actions/DebugActionRead.d.ts +39 -0
- package/dist/stm32/actions/DebugActionRead.js +61 -0
- package/dist/stm32/actions/DebugActionReset.d.ts +12 -0
- package/dist/stm32/actions/DebugActionReset.js +9 -0
- package/dist/stm32/actions/DebugActionServer.d.ts +11 -0
- package/dist/stm32/actions/DebugActionServer.js +11 -0
- package/dist/stm32/analysis.d.ts +20 -0
- package/dist/stm32/analysis.js +21 -0
- package/dist/stm32/build.d.ts +34 -0
- package/dist/stm32/build.js +79 -0
- package/dist/stm32/context.d.ts +23 -0
- package/dist/stm32/context.js +42 -0
- package/dist/stm32/daemon.d.ts +65 -0
- package/dist/stm32/daemon.js +209 -0
- package/dist/stm32/regen.d.ts +68 -0
- package/dist/stm32/regen.js +231 -0
- package/dist/stm32/session.d.ts +137 -0
- package/dist/stm32/session.js +375 -0
- package/dist/stm32/sync.d.ts +25 -0
- package/dist/stm32/sync.js +74 -0
- package/dist/stm32/tool.d.ts +45 -0
- package/dist/stm32/tool.js +20 -0
- package/dist/stm32/toolCommand.d.ts +50 -0
- package/dist/stm32/toolCommand.js +100 -0
- package/dist/stm32/utils/discover_tools.d.ts +25 -0
- package/dist/stm32/utils/discover_tools.js +121 -0
- package/dist/stm32/utils/downloadzip_utils.d.ts +57 -0
- package/dist/stm32/utils/downloadzip_utils.js +180 -0
- package/dist/stm32/utils/faultUtils.d.ts +15 -0
- package/dist/stm32/utils/faultUtils.js +69 -0
- package/dist/stm32/utils/findElf.d.ts +9 -0
- package/dist/stm32/utils/findElf.js +19 -0
- package/dist/stm32/utils/hash_utils.d.ts +19 -0
- package/dist/stm32/utils/hash_utils.js +28 -0
- package/dist/stm32/utils/listSyncFiles.d.ts +9 -0
- package/dist/stm32/utils/listSyncFiles.js +100 -0
- package/dist/stm32/utils/mcu_utils.d.ts +58 -0
- package/dist/stm32/utils/mcu_utils.js +100 -0
- package/dist/stm32/utils/project_utils.d.ts +54 -0
- package/dist/stm32/utils/project_utils.js +104 -0
- package/dist/stm32/utils/svdUtils.d.ts +31 -0
- package/dist/stm32/utils/svdUtils.js +30 -0
- package/dist/stm32/utils/truncate.d.ts +7 -0
- package/dist/stm32/utils/truncate.js +9 -0
- package/dist/stm32/utils/usb_utils.d.ts +5 -0
- package/dist/stm32/utils/usb_utils.js +23 -0
- package/dist/stm32/utils/user_code.d.ts +17 -0
- package/dist/stm32/utils/user_code.js +45 -0
- package/dist/stm32/utils/utils_mutex.d.ts +15 -0
- package/dist/stm32/utils/utils_mutex.js +113 -0
- package/dist/stm32/validate.d.ts +17 -0
- package/dist/stm32/validate.js +46 -0
- package/mods/claude/.claude-plugin/marketplace.json +8 -0
- package/mods/claude/turingcode-skills/.claude-plugin/plugin.json +5 -0
- package/mods/claude/turingcode-skills/skills/turingcode-cli/SKILL.md +44 -0
- package/mods/claude/turingcode-skills/skills/turingcode-firmware-code/SKILL.md +47 -0
- package/mods/claude/turingcode-skills/skills/turingcode-firmware-code/references/concurrency.md +42 -0
- package/mods/claude/turingcode-skills/skills/turingcode-firmware-code/references/init-and-timing.md +35 -0
- package/mods/claude/turingcode-skills/skills/turingcode-firmware-code/references/input-and-bounds.md +21 -0
- package/mods/claude/turingcode-skills/skills/turingcode-firmware-code/references/registers-and-units.md +35 -0
- package/package.json +11 -3
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { DEFAULT_URL } from "../../core/mcp.js";
|
|
2
|
+
import { cliVersion } from "../../stm32/context.js";
|
|
3
|
+
import { _defineTool } from "../../stm32/tool.js";
|
|
4
|
+
import { findElf } from "../../stm32/utils/findElf.js";
|
|
5
|
+
import { discover_system_tools } from "../../stm32/utils/discover_tools.js";
|
|
6
|
+
import { findProject, findStm32Project } from "../../stm32/utils/project_utils.js";
|
|
7
|
+
import { scanUserSections } from "../../stm32/utils/user_code.js";
|
|
8
|
+
import { readFile } from "node:fs/promises";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
/** Reports the CLI, server token, project, its newest built ELF, debug session and hardware tool state. */
|
|
11
|
+
export default _defineTool({
|
|
12
|
+
name: "get_status",
|
|
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).",
|
|
14
|
+
run: async (_args, ctx) => {
|
|
15
|
+
const p = await findProject(ctx.cwd);
|
|
16
|
+
const stm = await findStm32Project(ctx.cwd).catch((e) => e);
|
|
17
|
+
const stmText = stm instanceof Error ? `none (${stm.message})` : `${stm.name} (${stm.root})`;
|
|
18
|
+
const elf = stm instanceof Error ? undefined : await findElf(stm.root);
|
|
19
|
+
const build = elf ? `${elf.path} (${elf.mtime.toISOString()})` : "none";
|
|
20
|
+
const tools = await discover_system_tools(true);
|
|
21
|
+
const userCode = await Promise.all(["Core/Src/main.c", "Core/Inc/main.h"].map(async (f) => {
|
|
22
|
+
const text = stm instanceof Error ? undefined : await readFile(join(stm.root, f), "utf8").catch(() => undefined);
|
|
23
|
+
if (text === undefined)
|
|
24
|
+
return ` ${f}: not found`;
|
|
25
|
+
const { sections, errors } = scanUserSections(text);
|
|
26
|
+
if (!errors.length)
|
|
27
|
+
return ` ${f}: ${sections.length} sections, ok`;
|
|
28
|
+
return [` ${f}: ${errors.length} mismatch(es)`, ...errors.map((e) => ` ${e}`)].join("\n");
|
|
29
|
+
}));
|
|
30
|
+
return [
|
|
31
|
+
`turingcode ${cliVersion()}`,
|
|
32
|
+
`Server: ${process.env.TURINGCODE_URL || DEFAULT_URL}`,
|
|
33
|
+
`Token: ${process.env.TURINGCODE_TOKEN?.trim() ? "set" : "missing, set TURINGCODE_TOKEN"}`,
|
|
34
|
+
`Project: ${p.name} (${p.root})`,
|
|
35
|
+
`STM32 project: ${stmText}`,
|
|
36
|
+
`Last build: ${build}`,
|
|
37
|
+
`Debug session: ${ctx.debugActive() ? `active (probe owned by the debug daemon, ${ctx.socketPath})` : "none"}`,
|
|
38
|
+
"USER CODE sections:",
|
|
39
|
+
...userCode,
|
|
40
|
+
`Debug tools: ${tools.length ? "" : "none found (install probe-rs from https://probe.rs, or STM32CubeProgrammer)"}`,
|
|
41
|
+
...tools.map((t) => ` ${t.id}: ${t.path}`),
|
|
42
|
+
].join("\n");
|
|
43
|
+
},
|
|
44
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Diagnostic } from "../contract/diagnostics.js";
|
|
2
|
+
export interface TableCheckInput {
|
|
3
|
+
/** Contract file. */
|
|
4
|
+
contract: string;
|
|
5
|
+
/** Markdown file, folder of `<Table>.csv`, or one `<Table>.csv`. */
|
|
6
|
+
tables: string;
|
|
7
|
+
/** Dependency alias -> its tables file. */
|
|
8
|
+
deps?: Record<string, string>;
|
|
9
|
+
}
|
|
10
|
+
export interface TableCheckResult {
|
|
11
|
+
status: "PASS" | "FAIL" | "INVALID_CONTRACT" | "INVALID_INPUT" | "MISSING_DATA";
|
|
12
|
+
contract: string;
|
|
13
|
+
summary: {
|
|
14
|
+
tables: number;
|
|
15
|
+
rows: number;
|
|
16
|
+
fails: number;
|
|
17
|
+
warnings: number;
|
|
18
|
+
};
|
|
19
|
+
diagnostics: Diagnostic[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Checks tables against a contract: tables and columns, every cell's type,
|
|
23
|
+
* every column's `match`, then the rules.
|
|
24
|
+
*
|
|
25
|
+
* @param {TableCheckInput} input - Contract, tables and dependency tables.
|
|
26
|
+
* @returns {TableCheckResult} Status, summary and diagnostics.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* tableCheck({ contract: "orders.contract.json", tables: "orders.md" }).status; // "PASS"
|
|
30
|
+
*/
|
|
31
|
+
export declare function tableCheck(input: TableCheckInput): TableCheckResult;
|
|
32
|
+
/**
|
|
33
|
+
* Compact text for a table check result.
|
|
34
|
+
*
|
|
35
|
+
* @param {TableCheckResult} r - The result.
|
|
36
|
+
* @returns {string} Status line, then the diagnostics.
|
|
37
|
+
*/
|
|
38
|
+
export declare function formatTableCheck(r: TableCheckResult): string;
|
|
@@ -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,
|
|
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)) ||
|
|
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;
|
|
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));
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { TablesDoc } from "../../core/tables/types.js";
|
|
2
|
+
/** Most rows read from one table. */
|
|
3
|
+
export declare const MAX_TABLE_ROWS = 100000;
|
|
4
|
+
/** The files a format reads, for `expected`. */
|
|
5
|
+
export declare const FORMAT_FILES: {
|
|
6
|
+
readonly markdown: "a Markdown file";
|
|
7
|
+
readonly csv: "a .csv file or a folder of them";
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Why a path is in the wrong format for its contract, or null when it fits (or does not exist,
|
|
11
|
+
* which reading reports). Markdown parsing of CSV text finds no tables, so this must be checked
|
|
12
|
+
* first or a CSV dependency would silently look empty.
|
|
13
|
+
*
|
|
14
|
+
* @param {string} path - The file or folder.
|
|
15
|
+
* @param {"markdown" | "csv"} format - The contract's format.
|
|
16
|
+
* @returns {string | null} The problem, or null.
|
|
17
|
+
*/
|
|
18
|
+
export declare function formatMismatch(path: string, format: "markdown" | "csv"): string | null;
|
|
19
|
+
/**
|
|
20
|
+
* Reads tables in a contract's format: a Markdown file, a folder of
|
|
21
|
+
* `<Table>.csv` files, or one `<Table>.csv` file.
|
|
22
|
+
*
|
|
23
|
+
* @param {string} path - The file or folder.
|
|
24
|
+
* @param {"markdown" | "csv"} format - The contract's format.
|
|
25
|
+
* @returns {TablesDoc} The tables.
|
|
26
|
+
* @throws {Error} When the path cannot be read; BoundError when a table has too many rows.
|
|
27
|
+
*/
|
|
28
|
+
export declare function readTables(path: string, format: "markdown" | "csv"): TablesDoc;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
2
|
-
import { basename
|
|
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
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
malformed:
|
|
50
|
-
text: only ?
|
|
51
|
-
textOutside: names => (names.includes(name) ? "" :
|
|
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
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { CommandModule } from 'yargs';
|
|
2
|
+
import { ToolInfo } from '../../core/mcp.js';
|
|
3
|
+
/**
|
|
4
|
+
* Formats tools as one line each: name, then the first line of its description.
|
|
5
|
+
*
|
|
6
|
+
* @param {ToolInfo[]} tools - Tools from the gateway.
|
|
7
|
+
* @returns {string} The text, ending in a newline (empty for no tools).
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* formatToolSummaries([{ name: "read_file", description: "Reads a file.\nMore." }]); // "read_file Reads a file.\n"
|
|
11
|
+
*/
|
|
12
|
+
export declare function formatToolSummaries(tools: ToolInfo[]): string;
|
|
13
|
+
/**
|
|
14
|
+
* Formats tools with their full description and arguments, one `## <name>` section per tool.
|
|
15
|
+
*
|
|
16
|
+
* @param {ToolInfo[]} tools - Tools from the gateway.
|
|
17
|
+
* @returns {string} The text, ending in a newline (empty for no tools).
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* formatToolDetails([{ name: "read_file", description: "Reads a file.",
|
|
21
|
+
* inputSchema: { properties: { path: { type: "string" } }, required: ["path"] } }]);
|
|
22
|
+
* // "## read_file\n\nReads a file.\n\nArguments:\n- path (string, required)\n"
|
|
23
|
+
*/
|
|
24
|
+
export declare function formatToolDetails(tools: ToolInfo[]): string;
|
|
25
|
+
/**
|
|
26
|
+
* Picks the named tools, in the order given.
|
|
27
|
+
*
|
|
28
|
+
* @param {ToolInfo[]} tools - Tools from the gateway.
|
|
29
|
+
* @param {string[]} names - Tool names to pick.
|
|
30
|
+
* @returns {ToolInfo[]} The named tools.
|
|
31
|
+
* @throws {Error} When a name is not among the tools.
|
|
32
|
+
*/
|
|
33
|
+
export declare function pickTools(tools: ToolInfo[], names: string[]): ToolInfo[];
|
|
34
|
+
declare const command: CommandModule;
|
|
35
|
+
export default command;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { readJsonArg } from
|
|
2
|
-
import { getGatewayConfig, listTools, runServerTool, TOKEN_HELP } from
|
|
3
|
-
import { JSON_FLAG } from
|
|
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(
|
|
20
|
-
if (schema.type ===
|
|
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 ??
|
|
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
|
|
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
|
|
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 = [
|
|
53
|
-
|
|
54
|
-
|
|
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 [
|
|
57
|
-
.
|
|
58
|
-
|
|
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(
|
|
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:
|
|
77
|
-
describe:
|
|
78
|
-
builder: cli => cli
|
|
79
|
-
|
|
80
|
-
|
|
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(
|
|
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:
|
|
94
|
-
describe:
|
|
95
|
-
builder: cli => cli
|
|
96
|
-
.positional(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
-
|
|
102
|
-
|
|
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(
|
|
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) +
|
|
128
|
+
process.stdout.write(args.json ? JSON.stringify(tools) + '\n' : formatToolDetails(tools));
|
|
110
129
|
},
|
|
111
130
|
};
|
|
112
131
|
const call = {
|
|
113
|
-
command:
|
|
114
|
-
describe:
|
|
115
|
-
builder: cli => cli
|
|
116
|
-
.positional(
|
|
117
|
-
.options({
|
|
118
|
-
|
|
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 &&
|
|
121
|
-
|
|
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>"}'`,
|
|
126
|
-
.example(
|
|
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
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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
|
-
|
|
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(
|
|
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:
|
|
141
|
-
describe:
|
|
142
|
-
builder: cli => cli
|
|
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
|
-
|
|
145
|
-
|
|
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(
|
|
176
|
+
].join('\n')),
|
|
148
177
|
handler: () => { },
|
|
149
178
|
};
|
|
150
179
|
export default command;
|
package/dist/lib.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
*/
|
|
5
|
+
export { callTool, callToolText, listTools, DEFAULT_URL } from "./core/mcp.js";
|
|
6
|
+
export type { ToolInfo, ToolResult } from "./core/mcp.js";
|
|
7
|
+
export { syncProjectFromServer, syncProjectToServer } from "./stm32/sync.js";
|
|
8
|
+
export { recordBaseline, regenerateProject } from "./stm32/regen.js";
|
|
9
|
+
export type { ServerCall } from "./stm32/sync.js";
|
|
10
|
+
export { buildProject, BUILD_PRESETS } from "./stm32/build.js";
|
|
11
|
+
export { analyzeProject, syntaxCheckProject } from "./stm32/analysis.js";
|
|
12
|
+
export type { BuildResult } from "./stm32/build.js";
|
|
13
|
+
export { downloadAndUnzip, zipLink } from "./stm32/utils/downloadzip_utils.js";
|
|
14
|
+
export { findStm32Project, findStm32ProjectIn } from "./stm32/utils/project_utils.js";
|
|
15
|
+
export type { Project } from "./stm32/tool.js";
|
package/dist/lib.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
*/
|
|
5
|
+
export { callTool, callToolText, listTools, DEFAULT_URL } from "./core/mcp.js";
|
|
6
|
+
export { syncProjectFromServer, syncProjectToServer } from "./stm32/sync.js";
|
|
7
|
+
export { recordBaseline, regenerateProject } from "./stm32/regen.js";
|
|
8
|
+
export { buildProject, BUILD_PRESETS } from "./stm32/build.js";
|
|
9
|
+
export { analyzeProject, syntaxCheckProject } from "./stm32/analysis.js";
|
|
10
|
+
export { downloadAndUnzip, zipLink } from "./stm32/utils/downloadzip_utils.js";
|
|
11
|
+
export { findStm32Project, findStm32ProjectIn } from "./stm32/utils/project_utils.js";
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { DiscoveredSystemTool, SystemToolId } from '../utils/discover_tools.js';
|
|
2
|
+
/** Values for the {placeholders}; booleans switch optional argument groups on and off */
|
|
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 */
|
|
5
|
+
export type CommandArg = string | {
|
|
6
|
+
if: string;
|
|
7
|
+
args: string[];
|
|
8
|
+
};
|
|
9
|
+
export interface ToolOutput {
|
|
10
|
+
tool: SystemToolId;
|
|
11
|
+
stdout: string;
|
|
12
|
+
stderr: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A debug operation (program, read memory, reset, ...) and the command line of each tool that can do it.
|
|
16
|
+
* The first installed tool in `commands` order runs it, with the placeholders filled from the action params.
|
|
17
|
+
* Everything is static: subclasses set the fields and are used without an instance (DebugActionRead.run_action(...)).
|
|
18
|
+
*/
|
|
19
|
+
export declare abstract class DebugAction {
|
|
20
|
+
static readonly title: string; /** e.g. "Reading memory", for error messages */
|
|
21
|
+
static readonly commands: Partial<Record<SystemToolId, CommandArg[]>>;
|
|
22
|
+
static readonly timeout: number;
|
|
23
|
+
static readonly exclusive: boolean; /** the run opens the probe, so only one such run happens at a time */
|
|
24
|
+
/**
|
|
25
|
+
* Converts the action params to the placeholder values; override to add derived or formatted values.
|
|
26
|
+
* @param params action params
|
|
27
|
+
* @returns the placeholder values
|
|
28
|
+
*/
|
|
29
|
+
protected static values(params: ActionParams): ActionParams;
|
|
30
|
+
/**
|
|
31
|
+
* Picks the first installed tool that has a command line for this action.
|
|
32
|
+
* @returns the tool
|
|
33
|
+
*/
|
|
34
|
+
static pickSystemTool(): Promise<DiscoveredSystemTool>;
|
|
35
|
+
/**
|
|
36
|
+
* Builds the command line of a tool for this action.
|
|
37
|
+
* @param params action params
|
|
38
|
+
* @param tool tool to use, default the one pickSystemTool returns
|
|
39
|
+
* @returns the tool and its arguments
|
|
40
|
+
*/
|
|
41
|
+
static build_command(params: ActionParams, tool?: DiscoveredSystemTool): Promise<{
|
|
42
|
+
tool: DiscoveredSystemTool;
|
|
43
|
+
args: string[];
|
|
44
|
+
}>;
|
|
45
|
+
/**
|
|
46
|
+
* Runs the action's command line (no shell) and returns its full output.
|
|
47
|
+
* @param params action params
|
|
48
|
+
* @param tool tool to use, default the one pickSystemTool returns
|
|
49
|
+
* @returns the tool that ran and its stdout and stderr
|
|
50
|
+
*/
|
|
51
|
+
static run_action(params: ActionParams, tool?: DiscoveredSystemTool): Promise<ToolOutput>;
|
|
52
|
+
/**
|
|
53
|
+
* Runs the action and returns the tail of its output, for tool replies.
|
|
54
|
+
* @param params action params
|
|
55
|
+
* @param tool tool to use, default the one pickSystemTool returns
|
|
56
|
+
* @returns the last 1500 characters of stdout and stderr
|
|
57
|
+
*/
|
|
58
|
+
static run_action_get_tail(params: ActionParams, tool?: DiscoveredSystemTool): Promise<string>;
|
|
59
|
+
/**
|
|
60
|
+
* Returns the tail of a run's output, for tool replies.
|
|
61
|
+
* @param out output of exec
|
|
62
|
+
* @returns the last 1500 characters of stdout and stderr
|
|
63
|
+
*/
|
|
64
|
+
static tail(out: ToolOutput): string;
|
|
65
|
+
}
|