@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,111 @@
|
|
|
1
|
+
/** One finding of `contract check` or `table check`. */
|
|
2
|
+
export interface Diagnostic {
|
|
3
|
+
severity: "FAIL" | "WARN";
|
|
4
|
+
code: Code;
|
|
5
|
+
/** Table name, or "-" for document- or contract-level findings. */
|
|
6
|
+
table: string;
|
|
7
|
+
/** Row label (primary key or `#n`), or "-". */
|
|
8
|
+
row: string;
|
|
9
|
+
/** Column name or contract field path, or "-". */
|
|
10
|
+
column: string;
|
|
11
|
+
message: string;
|
|
12
|
+
found: string;
|
|
13
|
+
expected: string;
|
|
14
|
+
fix: string;
|
|
15
|
+
/** ID of the contract rule that failed, if a rule did. */
|
|
16
|
+
rule?: string;
|
|
17
|
+
/** For NONE_OF: why each `$or` branch failed, in order. */
|
|
18
|
+
alternatives?: Alternative[];
|
|
19
|
+
}
|
|
20
|
+
/** Why one branch of a failing `$or` failed. */
|
|
21
|
+
export interface Alternative {
|
|
22
|
+
code: Code;
|
|
23
|
+
message: string;
|
|
24
|
+
}
|
|
25
|
+
/** Every code, with its fix hint. */
|
|
26
|
+
declare const HINTS: {
|
|
27
|
+
/** Contract problems (contract check, and table check before it starts). */
|
|
28
|
+
readonly "CONTRACT.BAD_JSON": "Fix the JSON syntax of the contract file.";
|
|
29
|
+
readonly "CONTRACT.BAD_FIELD": "Give the field the type or value named in 'expected'; remove unknown fields.";
|
|
30
|
+
readonly "CONTRACT.BAD_REGEX": "Write a valid JavaScript regular expression.";
|
|
31
|
+
readonly "CONTRACT.BAD_EXPRESSION": "Write an arithmetic expression over this table's number columns.";
|
|
32
|
+
readonly "CONTRACT.UNKNOWN_TABLE": "Name a table the contract declares.";
|
|
33
|
+
readonly "CONTRACT.UNKNOWN_COLUMN": "Name a column the table declares.";
|
|
34
|
+
readonly "CONTRACT.UNKNOWN_DEPENDENCY": "Declare the alias in depends_on.";
|
|
35
|
+
readonly "CONTRACT.DUPLICATE": "Give each table, column and rule a unique name.";
|
|
36
|
+
readonly "CONTRACT.CONFLICT": "Make the settings agree (e.g. minimum <= maximum, constraint fits the type).";
|
|
37
|
+
readonly "CONTRACT.CYCLE": "Remove the circular depends_on.";
|
|
38
|
+
readonly "CONTRACT.MISSING_FILE": "Check the path; the file must exist and be readable.";
|
|
39
|
+
/** Problems in the tables (table check). */
|
|
40
|
+
readonly MISSING_TABLE: "Add the table under a '## <name>' heading (Markdown) or as <name>.csv.";
|
|
41
|
+
readonly EXTRA_TABLE: "Remove the table, or declare it in the contract.";
|
|
42
|
+
readonly DUPLICATE_TABLE: "Write each table once.";
|
|
43
|
+
readonly BAD_TABLE: "Write the table as a header row, a '|---|' separator row, then data rows.";
|
|
44
|
+
readonly MISSING_COLUMN: "Add the column to the header.";
|
|
45
|
+
readonly EXTRA_COLUMN: "Remove the column, or declare it in the contract.";
|
|
46
|
+
readonly DUPLICATE_COLUMN: "Name each column once.";
|
|
47
|
+
readonly COLUMN_ORDER: "Put the columns in the declared order.";
|
|
48
|
+
readonly ROW_SHAPE: "Give the row one cell per column; in Markdown write '\\|' for a '|' inside a cell.";
|
|
49
|
+
readonly MISSING_VALUE: "Fill the cell.";
|
|
50
|
+
readonly BAD_TYPE: "Write the value in the column's type.";
|
|
51
|
+
readonly BAD_VALUE: "Use one of the allowed values, spelled exactly.";
|
|
52
|
+
readonly PATTERN: "Write the value in the required format.";
|
|
53
|
+
readonly OUT_OF_RANGE: "Use a value within the allowed range.";
|
|
54
|
+
readonly BAD_LENGTH: "Use a value of the allowed length.";
|
|
55
|
+
readonly DUPLICATE_KEY: "Make the value unique in its table.";
|
|
56
|
+
readonly UNKNOWN_REF: "Use only values that exist in the referenced column.";
|
|
57
|
+
readonly REQUIRED_IF: "Fill the cell; the rule requires it for this row.";
|
|
58
|
+
readonly EMPTY_IF: "Leave the cell empty; the rule forbids a value for this row.";
|
|
59
|
+
readonly COMPARE: "Correct the values so the comparison holds.";
|
|
60
|
+
readonly UNIQUE_TOGETHER: "Make the combination of values unique.";
|
|
61
|
+
readonly ROW_COUNT: "Add or remove rows so the count fits.";
|
|
62
|
+
readonly NOT_MENTIONED: "Mention the value where the rule says.";
|
|
63
|
+
readonly MATCH: "Correct the row so it matches the rule's query (shown in 'expected').";
|
|
64
|
+
readonly NONE_OF: "Make the value meet one of the alternatives in 'expected'.";
|
|
65
|
+
/** Inputs. */
|
|
66
|
+
readonly MISSING_FILE: "Check the path; the file must exist and be readable.";
|
|
67
|
+
readonly MISSING_DEPENDENCY: "Pass the dependency's tables with --dep <alias>=<file>.";
|
|
68
|
+
readonly TOO_LARGE: "Split the table; it exceeds the row limit.";
|
|
69
|
+
readonly INVALID_INPUT: "Fix the command arguments named in the message.";
|
|
70
|
+
};
|
|
71
|
+
export type Code = keyof typeof HINTS;
|
|
72
|
+
/** Where a finding points. */
|
|
73
|
+
export interface Where {
|
|
74
|
+
table?: string;
|
|
75
|
+
row?: string;
|
|
76
|
+
column?: string;
|
|
77
|
+
rule?: string;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Builds a diagnostic with its fix hint.
|
|
81
|
+
*
|
|
82
|
+
* @param {Code} code - The code.
|
|
83
|
+
* @param {string} message - What is wrong.
|
|
84
|
+
* @param {Where} at - Table, row, column and rule.
|
|
85
|
+
* @param {string} found - Observed value.
|
|
86
|
+
* @param {string} expected - Required value.
|
|
87
|
+
* @param {"FAIL"|"WARN"} [severity="FAIL"] - Severity.
|
|
88
|
+
* @param {Alternative[]} [alternatives] - For NONE_OF: why each `$or` branch failed.
|
|
89
|
+
* @returns {Diagnostic} The diagnostic.
|
|
90
|
+
*/
|
|
91
|
+
export declare function diag(code: Code, message: string, at: Where, found: string, expected: string, severity?: "FAIL" | "WARN", alternatives?: Alternative[]): Diagnostic;
|
|
92
|
+
/**
|
|
93
|
+
* Sorts diagnostics deterministically: FAIL before WARN, then by table, row, column, code.
|
|
94
|
+
*
|
|
95
|
+
* @param {Diagnostic[]} list - Diagnostics.
|
|
96
|
+
* @returns {Diagnostic[]} A sorted copy.
|
|
97
|
+
*/
|
|
98
|
+
export declare function sortDiagnostics(list: Diagnostic[]): Diagnostic[];
|
|
99
|
+
/**
|
|
100
|
+
* Renders diagnostics as compact text: one line per finding, findings that
|
|
101
|
+
* differ only by row grouped onto one line, then each fix hint once per code.
|
|
102
|
+
*
|
|
103
|
+
* @param {Diagnostic[]} diags - Sorted diagnostics.
|
|
104
|
+
* @returns {string[]} The lines.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* formatDiagnostics(result.diagnostics);
|
|
108
|
+
* // ["FAIL BAD_VALUE Orders Status ×2: O-1=Open, O-4=Shipped; expected open, closed", "fix BAD_VALUE: ..."]
|
|
109
|
+
*/
|
|
110
|
+
export declare function formatDiagnostics(diags: Diagnostic[]): string[];
|
|
111
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** Every code, with its fix hint. */
|
|
2
2
|
const HINTS = {
|
|
3
|
-
|
|
3
|
+
/** Contract problems (contract check, and table check before it starts). */
|
|
4
4
|
"CONTRACT.BAD_JSON": "Fix the JSON syntax of the contract file.",
|
|
5
5
|
"CONTRACT.BAD_FIELD": "Give the field the type or value named in 'expected'; remove unknown fields.",
|
|
6
6
|
"CONTRACT.BAD_REGEX": "Write a valid JavaScript regular expression.",
|
|
@@ -12,7 +12,7 @@ const HINTS = {
|
|
|
12
12
|
"CONTRACT.CONFLICT": "Make the settings agree (e.g. minimum <= maximum, constraint fits the type).",
|
|
13
13
|
"CONTRACT.CYCLE": "Remove the circular depends_on.",
|
|
14
14
|
"CONTRACT.MISSING_FILE": "Check the path; the file must exist and be readable.",
|
|
15
|
-
|
|
15
|
+
/** Problems in the tables (table check). */
|
|
16
16
|
"MISSING_TABLE": "Add the table under a '## <name>' heading (Markdown) or as <name>.csv.",
|
|
17
17
|
"EXTRA_TABLE": "Remove the table, or declare it in the contract.",
|
|
18
18
|
"DUPLICATE_TABLE": "Write each table once.",
|
|
@@ -38,7 +38,7 @@ const HINTS = {
|
|
|
38
38
|
"NOT_MENTIONED": "Mention the value where the rule says.",
|
|
39
39
|
"MATCH": "Correct the row so it matches the rule's query (shown in 'expected').",
|
|
40
40
|
"NONE_OF": "Make the value meet one of the alternatives in 'expected'.",
|
|
41
|
-
|
|
41
|
+
/** Inputs. */
|
|
42
42
|
"MISSING_FILE": "Check the path; the file must exist and be readable.",
|
|
43
43
|
"MISSING_DEPENDENCY": "Pass the dependency's tables with --dep <alias>=<file>.",
|
|
44
44
|
"TOO_LARGE": "Split the table; it exceeds the row limit.",
|
|
@@ -94,7 +94,10 @@ export function formatDiagnostics(diags) {
|
|
|
94
94
|
const groups = new Map();
|
|
95
95
|
for (const d of diags) {
|
|
96
96
|
const key = [d.severity, d.code, d.table, d.column, d.expected, d.rule, branchCodes(d)].join("\u0000");
|
|
97
|
-
|
|
97
|
+
let g = groups.get(key);
|
|
98
|
+
if (!g)
|
|
99
|
+
groups.set(key, g = []);
|
|
100
|
+
g.push(d);
|
|
98
101
|
}
|
|
99
102
|
for (const [d, ...more] of groups.values()) {
|
|
100
103
|
const rule = d.rule ? ` [${d.rule}]` : "";
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Diagnostic } from "./diagnostics.js";
|
|
2
|
+
import { Contract } from "./model.js";
|
|
3
|
+
/** A contract file that was read, with its dependencies. */
|
|
4
|
+
export interface LoadedContract {
|
|
5
|
+
path: string;
|
|
6
|
+
/** `name@version`, `name`, or the file name: how findings refer to this contract. */
|
|
7
|
+
label: string;
|
|
8
|
+
/** The contract when it and all its dependencies are valid, else null. */
|
|
9
|
+
contract: Contract | null;
|
|
10
|
+
/** Dependencies by alias (each loaded, valid or not). */
|
|
11
|
+
deps: Map<string, LoadedContract>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Parses a table reference (a rule's `on`).
|
|
15
|
+
*
|
|
16
|
+
* @param {string} ref - `Table` or `alias:Table`.
|
|
17
|
+
* @returns {{alias: string|null, table: string}} Its parts.
|
|
18
|
+
*/
|
|
19
|
+
export declare function parseTableRef(ref: string): {
|
|
20
|
+
alias: string | null;
|
|
21
|
+
table: string;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Parses a column reference.
|
|
25
|
+
*
|
|
26
|
+
* @param {string} ref - `Column`, `Table.Column` or `alias:Table.Column`.
|
|
27
|
+
* @returns {{alias: string|null, table: string|null, column: string}} Its parts.
|
|
28
|
+
*/
|
|
29
|
+
export declare function parseRef(ref: string): {
|
|
30
|
+
alias: string | null;
|
|
31
|
+
table: string | null;
|
|
32
|
+
column: string;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* The status of a check whose contract did not load: MISSING_DATA when a contract file
|
|
36
|
+
* could not be read, else INVALID_CONTRACT.
|
|
37
|
+
*
|
|
38
|
+
* @param {Diagnostic[]} diags - The loading diagnostics.
|
|
39
|
+
* @returns {"MISSING_DATA" | "INVALID_CONTRACT"} The status.
|
|
40
|
+
*/
|
|
41
|
+
export declare const failedLoadStatus: (diags: Diagnostic[]) => "MISSING_DATA" | "INVALID_CONTRACT";
|
|
42
|
+
/**
|
|
43
|
+
* Validates one contract whose dependencies are already loaded.
|
|
44
|
+
*
|
|
45
|
+
* @param {unknown} data - Parsed contract JSON.
|
|
46
|
+
* @param {Map<string, LoadedContract>} deps - Its dependencies by alias.
|
|
47
|
+
* @returns {Diagnostic[]} Every problem; empty when valid.
|
|
48
|
+
*/
|
|
49
|
+
export declare function validateContract(data: unknown, deps: Map<string, LoadedContract>): Diagnostic[];
|
|
50
|
+
/**
|
|
51
|
+
* Reads and validates a contract and, recursively, the contracts it depends on.
|
|
52
|
+
*
|
|
53
|
+
* @param {string} path - Contract file.
|
|
54
|
+
* @param {Diagnostic[]} out - Receives every problem; a dependency's are prefixed with its label.
|
|
55
|
+
* @param {string[]} [stack=[]] - Files being loaded above this one (cycle detection).
|
|
56
|
+
* @returns {LoadedContract} The contract (null when it or a dependency is invalid).
|
|
57
|
+
*/
|
|
58
|
+
export declare function loadContract(path: string, out: Diagnostic[], stack?: string[]): LoadedContract;
|
|
@@ -60,7 +60,7 @@ export function validateContract(data, deps) {
|
|
|
60
60
|
if (shapeIssues.length)
|
|
61
61
|
return out;
|
|
62
62
|
const c = data;
|
|
63
|
-
|
|
63
|
+
/** Checked here, not by the shape: the "string" shape rejects "", the most common missing value. */
|
|
64
64
|
for (const v of c.missing_values ?? []) {
|
|
65
65
|
if (typeof v !== "string")
|
|
66
66
|
out.push(diag("CONTRACT.BAD_FIELD", "missing_values must be strings", { column: "missing_values" }, show(v), "a string"));
|
|
@@ -93,7 +93,7 @@ export function validateContract(data, deps) {
|
|
|
93
93
|
}
|
|
94
94
|
target = deps.get(alias)?.contract ?? null;
|
|
95
95
|
if (!target)
|
|
96
|
-
return null;
|
|
96
|
+
return null; /** the dependency's own problems are reported with it */
|
|
97
97
|
}
|
|
98
98
|
const table = target.tables.find(t => t.name === name);
|
|
99
99
|
if (table)
|
|
@@ -178,7 +178,7 @@ export function loadContract(path, out, stack = []) {
|
|
|
178
178
|
const full = resolve(path);
|
|
179
179
|
const loaded = { path, label: basename(path), contract: null, deps: new Map() };
|
|
180
180
|
const own = [];
|
|
181
|
-
|
|
181
|
+
/** Findings in a dependency name it; findings in the checked contract need no prefix. */
|
|
182
182
|
const publish = () => out.push(...(stack.length ? own.map(d => ({ ...d, message: `${loaded.label}: ${d.message}` })) : own));
|
|
183
183
|
const file = readJsonFile(path);
|
|
184
184
|
if (!file.ok) {
|
|
@@ -196,7 +196,7 @@ export function loadContract(path, out, stack = []) {
|
|
|
196
196
|
const dependsOn = data && typeof data === "object" && data.depends_on && typeof data.depends_on === "object" ? data.depends_on : {};
|
|
197
197
|
for (const [alias, rel] of Object.entries(dependsOn)) {
|
|
198
198
|
if (typeof rel !== "string")
|
|
199
|
-
continue;
|
|
199
|
+
continue; /** reported by the shape check */
|
|
200
200
|
const depPath = resolve(dirname(path), rel);
|
|
201
201
|
if ([...stack, full].includes(depPath)) {
|
|
202
202
|
own.push(diag("CONTRACT.CYCLE", `depends_on '${alias}' leads back to ${rel}`, { column: `depends_on.${alias}` }, rel, "no cycle"));
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { Shape } from "../../core/json-shape.js";
|
|
2
|
+
import type { Query } from "../../core/query.js";
|
|
3
|
+
export declare const COLUMN_TYPES: readonly ["string", "integer", "number", "boolean", "date", "list"];
|
|
4
|
+
export type ColumnType = (typeof COLUMN_TYPES)[number];
|
|
5
|
+
/** One declared column. Only `name` is required; every value constraint is in `match`. */
|
|
6
|
+
export interface Column {
|
|
7
|
+
name: string;
|
|
8
|
+
/** Default `string`. */
|
|
9
|
+
type?: ColumnType;
|
|
10
|
+
description?: string;
|
|
11
|
+
/** The cell must not be a missing value. Default false. */
|
|
12
|
+
required?: boolean;
|
|
13
|
+
/** Item separator for `list`. Default ",". */
|
|
14
|
+
separator?: string;
|
|
15
|
+
/** A MongoDB-style condition every filled cell must meet, e.g. `{"$in": ["a", "b"]}`. */
|
|
16
|
+
match?: Record<string, unknown>;
|
|
17
|
+
}
|
|
18
|
+
/** A rule: rows (of `on`, default this table) matching `when` must match `require`, or their number must match `count`. */
|
|
19
|
+
export interface Rule {
|
|
20
|
+
id?: string;
|
|
21
|
+
description?: string;
|
|
22
|
+
/** `Table` or `alias:Table` whose rows the rule tests. Default: the table the rule is in. */
|
|
23
|
+
on?: string;
|
|
24
|
+
/** Rows the rule applies to: a row query. */
|
|
25
|
+
when?: Query;
|
|
26
|
+
/** A row query every applicable row must match. */
|
|
27
|
+
require?: Query;
|
|
28
|
+
/** A condition on the number of applicable rows, e.g. `{"$gte": 1}`. */
|
|
29
|
+
count?: Record<string, unknown>;
|
|
30
|
+
/** `error` (default) fails the check, `warning` only reports. */
|
|
31
|
+
severity?: "error" | "warning";
|
|
32
|
+
}
|
|
33
|
+
export interface Table {
|
|
34
|
+
name: string;
|
|
35
|
+
description?: string;
|
|
36
|
+
/** The table must be present. Default true. */
|
|
37
|
+
required?: boolean;
|
|
38
|
+
/** Columns must appear in the declared order. Default false. */
|
|
39
|
+
ordered?: boolean;
|
|
40
|
+
/** Columns not declared are allowed. Default false. */
|
|
41
|
+
allow_extra_columns?: boolean;
|
|
42
|
+
/** Column (or columns) whose values identify a row: required and unique. */
|
|
43
|
+
primary_key?: string | string[];
|
|
44
|
+
columns: Column[];
|
|
45
|
+
rules?: Rule[];
|
|
46
|
+
}
|
|
47
|
+
/** A table contract. Only `tables` is required. */
|
|
48
|
+
export interface Contract {
|
|
49
|
+
name?: string;
|
|
50
|
+
version?: string;
|
|
51
|
+
description?: string;
|
|
52
|
+
/** `markdown` (default): one `## <Table>` section per table; `csv`: one `<Table>.csv` per table. */
|
|
53
|
+
format?: "markdown" | "csv";
|
|
54
|
+
/** Cell texts that count as missing. Default [""]. */
|
|
55
|
+
missing_values?: string[];
|
|
56
|
+
/** Tables not declared are allowed. Default false. */
|
|
57
|
+
allow_extra_tables?: boolean;
|
|
58
|
+
/** Other contracts this one references: alias -> contract file (relative to this one). */
|
|
59
|
+
depends_on?: Record<string, string>;
|
|
60
|
+
tables: Table[];
|
|
61
|
+
}
|
|
62
|
+
export declare const COLUMN_SHAPE: Shape;
|
|
63
|
+
/** A rule. */
|
|
64
|
+
export declare const RULE_SHAPE: Shape;
|
|
65
|
+
export declare const CONTRACT_SHAPE: Shape;
|
|
66
|
+
/** The primary key columns of a table (empty when none). */
|
|
67
|
+
export declare const keyColumns: (t: Table) => string[];
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import type { Node } from "../../core/exact/expression.js";
|
|
2
|
+
import { Fraction } from "../../core/exact/fraction.js";
|
|
3
|
+
import { Doc, Query, QueryHooks, Value } from "../../core/query.js";
|
|
4
|
+
import type { Alternative, Code } from "./diagnostics.js";
|
|
5
|
+
import type { Column, Contract, Table } from "./model.js";
|
|
6
|
+
declare const CALC_OPS: readonly ["<=", ">=", "==", "!=", "<", ">"];
|
|
7
|
+
type CalcOp = (typeof CALC_OPS)[number];
|
|
8
|
+
/** One table row: its label (primary key or `#n`), its cells by column name, and the cells as a query sees them. */
|
|
9
|
+
export interface Row {
|
|
10
|
+
label: string;
|
|
11
|
+
cells: Record<string, string>;
|
|
12
|
+
doc: Doc;
|
|
13
|
+
/** The row has the wrong number of cells (ROW_SHAPE): it counts and can be referenced, but its own cells are not checked. */
|
|
14
|
+
shapeError: boolean;
|
|
15
|
+
}
|
|
16
|
+
/** A resolved `Table.Column` or `alias:Table.Column` reference. */
|
|
17
|
+
export interface Ref {
|
|
18
|
+
alias: string | null;
|
|
19
|
+
table: Table;
|
|
20
|
+
column: Column;
|
|
21
|
+
}
|
|
22
|
+
/** What `contract check` gives a query to validate it. */
|
|
23
|
+
export interface ValidateContext {
|
|
24
|
+
contract: Contract;
|
|
25
|
+
/** The table whose rows the query tests. */
|
|
26
|
+
table: Table;
|
|
27
|
+
/** Reports a contract problem (`field` names the contract field). */
|
|
28
|
+
problem(code: Code, message: string, field: string, found: string, expected: string): void;
|
|
29
|
+
/** Reports UNKNOWN_COLUMN for names the table does not declare; returns whether all exist. */
|
|
30
|
+
requireColumns(names: string[], field: string): boolean;
|
|
31
|
+
/** Resolves `Table.Column` or `alias:Table.Column`, reporting what is unknown. */
|
|
32
|
+
resolve(ref: string, field: string): Ref | null;
|
|
33
|
+
}
|
|
34
|
+
/** A query's hooks plus `$calc`'s values, which explaining a COMPARE failure needs. */
|
|
35
|
+
export interface CheckHooks extends QueryHooks {
|
|
36
|
+
calcValues(param: unknown, doc: Doc): {
|
|
37
|
+
left: Fraction;
|
|
38
|
+
right: Fraction;
|
|
39
|
+
} | null;
|
|
40
|
+
}
|
|
41
|
+
/** A failing part of a query, ready to report. */
|
|
42
|
+
export interface Failure {
|
|
43
|
+
code: Code;
|
|
44
|
+
message: string;
|
|
45
|
+
column: string;
|
|
46
|
+
found: string;
|
|
47
|
+
expected: string;
|
|
48
|
+
/** For NONE_OF: why each `$or` branch failed. */
|
|
49
|
+
alternatives?: Alternative[];
|
|
50
|
+
}
|
|
51
|
+
/** Splits a list cell into trimmed, non-empty items. */
|
|
52
|
+
export declare const listItems: (cell: string, separator?: string) => string[];
|
|
53
|
+
/** A value as text: list items joined, missing as empty. */
|
|
54
|
+
export declare const valueText: (v: Value | undefined) => string;
|
|
55
|
+
/**
|
|
56
|
+
* Whether `word` occurs in `text` as a whole token (not inside a longer word or ID).
|
|
57
|
+
*
|
|
58
|
+
* @param {string} text - Text to search.
|
|
59
|
+
* @param {string} word - The value.
|
|
60
|
+
* @returns {boolean} True when mentioned.
|
|
61
|
+
*/
|
|
62
|
+
export declare function mentions(text: string, word: string): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Prepares `mentions` for many values over one text. A value of up to MAX_TOKEN_RUNS word runs
|
|
65
|
+
* joined by single `-` (e.g. `R-12`) is looked up in the text's tokens: every such sequence of runs
|
|
66
|
+
* in the text that is not followed by `-<digit>`. Anything else uses `mentions`.
|
|
67
|
+
*
|
|
68
|
+
* @param {string} text - Text to search.
|
|
69
|
+
* @returns {(word: string) => boolean} Whether a value is mentioned, as `mentions(text, word)`.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* mentionTester("see R-12-3")("12-3"); // true; ("R-12") is false
|
|
73
|
+
*/
|
|
74
|
+
export declare function mentionTester(text: string): (word: string) => boolean;
|
|
75
|
+
/** Number columns of a table: the names a `$calc` expression may use. */
|
|
76
|
+
export declare const numberColumns: (t: Table) => Set<string>;
|
|
77
|
+
/** A parsed `$calc`: `"Qty * Price == Total"` or `{"expr": "...", "tolerance": 0.01}`. */
|
|
78
|
+
interface Calc {
|
|
79
|
+
text: string;
|
|
80
|
+
left: Node;
|
|
81
|
+
op: CalcOp;
|
|
82
|
+
right: Node;
|
|
83
|
+
tolerance: Fraction;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Parses a `$calc` parameter over the given number columns.
|
|
87
|
+
*
|
|
88
|
+
* @param {unknown} param - The parameter.
|
|
89
|
+
* @param {Set<string>} allowed - Number columns the expression may use.
|
|
90
|
+
* @returns {Calc | string} The parsed comparison, or what is wrong with it.
|
|
91
|
+
*/
|
|
92
|
+
export declare function parseCalc(param: unknown, allowed: Set<string>): Calc | string;
|
|
93
|
+
/**
|
|
94
|
+
* Evaluates a `$calc` on a row.
|
|
95
|
+
*
|
|
96
|
+
* @param {Calc} c - The parsed comparison.
|
|
97
|
+
* @param {Doc} doc - The row.
|
|
98
|
+
* @param {Set<string>} numbers - The table's number columns.
|
|
99
|
+
* @returns {{left: Fraction, right: Fraction, holds: boolean} | null} The sides and the result; null when a
|
|
100
|
+
* value is missing or not a number, or the arithmetic fails (the column check reports those).
|
|
101
|
+
*/
|
|
102
|
+
export declare function evaluateCalc(c: Calc, doc: Doc, numbers: Set<string>): {
|
|
103
|
+
left: Fraction;
|
|
104
|
+
right: Fraction;
|
|
105
|
+
holds: boolean;
|
|
106
|
+
} | null;
|
|
107
|
+
/**
|
|
108
|
+
* Validates a query of the contract (`match`, `when`, `require`, `count`):
|
|
109
|
+
* operators, values, columns, `$ref`/`$mentioned` targets, `$calc` and `$regex`.
|
|
110
|
+
*
|
|
111
|
+
* @param {unknown} q - The query, as a row query.
|
|
112
|
+
* @param {string} field - Contract field, for the report.
|
|
113
|
+
* @param {ValidateContext} v - Validation context.
|
|
114
|
+
* @returns {void}
|
|
115
|
+
*/
|
|
116
|
+
export declare function checkQuery(q: unknown, field: string, v: ValidateContext): void;
|
|
117
|
+
/**
|
|
118
|
+
* Splits a row query into parts that are checked (and reported) one by one.
|
|
119
|
+
*
|
|
120
|
+
* @param {Query} q - The query.
|
|
121
|
+
* @returns {Query[]} One row query per column operator, logical operator, `$calc` or `$unique`.
|
|
122
|
+
*/
|
|
123
|
+
export declare function splitQuery(q: Query): Query[];
|
|
124
|
+
/**
|
|
125
|
+
* Explains why a row fails one part of a query.
|
|
126
|
+
*
|
|
127
|
+
* @param {Query} part - A part from `splitQuery`.
|
|
128
|
+
* @param {Doc} doc - The row.
|
|
129
|
+
* @param {CheckHooks} hooks - The hooks the query ran with.
|
|
130
|
+
* @returns {Failure} Code, message, column, found and expected.
|
|
131
|
+
*/
|
|
132
|
+
export declare function explain(part: Query, doc: Doc, hooks: CheckHooks): Failure;
|
|
133
|
+
/**
|
|
134
|
+
* One column condition in words, e.g. "one of `a`, `b`".
|
|
135
|
+
*
|
|
136
|
+
* @param {unknown} cond - The condition.
|
|
137
|
+
* @param {(v: unknown) => string} c - Formats a value (backticks for describe, String for diagnostics).
|
|
138
|
+
* @returns {string} The text.
|
|
139
|
+
*/
|
|
140
|
+
export declare function renderCondition(cond: unknown, c?: (v: unknown) => string): string;
|
|
141
|
+
/**
|
|
142
|
+
* A row query in words, e.g. "`Status` = `shipped` and `Tracking` filled".
|
|
143
|
+
*
|
|
144
|
+
* @param {unknown} q - The query.
|
|
145
|
+
* @param {(v: unknown) => string} c - Formats a value.
|
|
146
|
+
* @returns {string} The text.
|
|
147
|
+
*/
|
|
148
|
+
export declare function renderQuery(q: unknown, c?: (v: unknown) => string): string;
|
|
149
|
+
export {};
|
|
@@ -23,6 +23,33 @@ export function mentions(text, word) {
|
|
|
23
23
|
const escaped = word.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
24
24
|
return new RegExp(`(?<![A-Za-z0-9_])${escaped}(?![A-Za-z0-9_]|-\\d)`).test(text);
|
|
25
25
|
}
|
|
26
|
+
/** Most `-`-joined word runs a value may have to be answered from the token set. */
|
|
27
|
+
const MAX_TOKEN_RUNS = 8;
|
|
28
|
+
/**
|
|
29
|
+
* Prepares `mentions` for many values over one text. A value of up to MAX_TOKEN_RUNS word runs
|
|
30
|
+
* joined by single `-` (e.g. `R-12`) is looked up in the text's tokens: every such sequence of runs
|
|
31
|
+
* in the text that is not followed by `-<digit>`. Anything else uses `mentions`.
|
|
32
|
+
*
|
|
33
|
+
* @param {string} text - Text to search.
|
|
34
|
+
* @returns {(word: string) => boolean} Whether a value is mentioned, as `mentions(text, word)`.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* mentionTester("see R-12-3")("12-3"); // true; ("R-12") is false
|
|
38
|
+
*/
|
|
39
|
+
export function mentionTester(text) {
|
|
40
|
+
const tokens = new Set();
|
|
41
|
+
for (const chain of text.matchAll(/[A-Za-z0-9_]+(?:-[A-Za-z0-9_]+)*/g)) {
|
|
42
|
+
const runs = chain[0].split("-");
|
|
43
|
+
for (let i = 0; i < runs.length; i++) {
|
|
44
|
+
for (let j = i; j < Math.min(runs.length, i + MAX_TOKEN_RUNS); j++) {
|
|
45
|
+
if (!/^\d/.test(runs[j + 1] ?? ""))
|
|
46
|
+
tokens.add(runs.slice(i, j + 1).join("-"));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const token = new RegExp(`^[A-Za-z0-9_]+(?:-[A-Za-z0-9_]+){0,${MAX_TOKEN_RUNS - 1}}$`);
|
|
51
|
+
return word => (token.test(word) ? tokens.has(word) : mentions(text, word));
|
|
52
|
+
}
|
|
26
53
|
/** Number columns of a table: the names a `$calc` expression may use. */
|
|
27
54
|
export const numberColumns = (t) => new Set(t.columns.filter(c => c.type === "integer" || c.type === "number").map(c => c.name));
|
|
28
55
|
/**
|
|
@@ -48,7 +75,7 @@ export function parseCalc(param, allowed) {
|
|
|
48
75
|
if (!tolerance || tolerance.cmp(new Fraction(0n)) < 0)
|
|
49
76
|
return "tolerance must be a number >= 0";
|
|
50
77
|
try {
|
|
51
|
-
|
|
78
|
+
/** Parse with every identifier allowed, then say which ones are not number columns. */
|
|
52
79
|
const names = new Set(text.match(/[A-Za-z_][A-Za-z0-9_]*/g) ?? []);
|
|
53
80
|
const left = parseExpression(l, MAX_EXPRESSION_NODES, names);
|
|
54
81
|
const right = parseExpression(r, MAX_EXPRESSION_NODES, names);
|
|
@@ -87,7 +114,7 @@ export function evaluateCalc(c, doc, numbers) {
|
|
|
87
114
|
return { left, right, holds };
|
|
88
115
|
}
|
|
89
116
|
catch {
|
|
90
|
-
return null;
|
|
117
|
+
return null; /** e.g. division by zero with these values: nothing to compare */
|
|
91
118
|
}
|
|
92
119
|
}
|
|
93
120
|
/**
|
|
@@ -166,7 +193,7 @@ export function explain(part, doc, hooks) {
|
|
|
166
193
|
found: cols.map(c => valueText(doc[c])).join(" / "), expected: "a unique combination" };
|
|
167
194
|
}
|
|
168
195
|
if (key === "$or" || key === "$and") {
|
|
169
|
-
|
|
196
|
+
/** The first failing part of each branch: all of them for $or, the first failing branch for $and. */
|
|
170
197
|
const failures = arg.flatMap(branch => {
|
|
171
198
|
const failing = splitQuery(branch).find(p => !queryTester(p, hooks)(doc));
|
|
172
199
|
return failing ? [explain(failing, doc, hooks)] : [];
|
|
@@ -278,7 +305,7 @@ function explainCondition(column, cond, value, hooks) {
|
|
|
278
305
|
break;
|
|
279
306
|
}
|
|
280
307
|
case "$every": {
|
|
281
|
-
|
|
308
|
+
/** Explain with the first failing item, against the item condition. */
|
|
282
309
|
const inner = isObject(arg) && Object.keys(arg).length === 1 ? arg : null;
|
|
283
310
|
if (!inner)
|
|
284
311
|
break;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { _defineTool } from '../../stm32/tool.js';
|
|
2
|
+
import { getSession, projectFile, syncBreakpoints } from '../../stm32/session.js';
|
|
3
|
+
/** Removes source breakpoints from the debug session. */
|
|
4
|
+
export default _defineTool({
|
|
5
|
+
name: 'clear_breakpoint',
|
|
6
|
+
description: 'Remove a source breakpoint from the debug session. Without line, removes every breakpoint in the file; without file, removes all breakpoints.',
|
|
7
|
+
properties: {
|
|
8
|
+
file: { type: 'string', maxLength: 512, description: 'Project-relative path' },
|
|
9
|
+
line: { type: 'integer', minimum: 1 },
|
|
10
|
+
},
|
|
11
|
+
run: async (args) => {
|
|
12
|
+
const s = getSession();
|
|
13
|
+
const files = args.file ? [projectFile(s.opts.root, args.file)] : [...s.breakpoints.keys()];
|
|
14
|
+
for (const rel of files) {
|
|
15
|
+
const keep = args.line ? (s.breakpoints.get(rel) ?? []).filter((b) => b.line !== args.line) : [];
|
|
16
|
+
s.breakpoints.set(rel, keep);
|
|
17
|
+
await syncBreakpoints(s, rel);
|
|
18
|
+
if (!keep.length)
|
|
19
|
+
s.breakpoints.delete(rel);
|
|
20
|
+
}
|
|
21
|
+
const left = [...s.breakpoints].flatMap(([rel, list]) => list.map((b) => `${rel}:${b.line}`));
|
|
22
|
+
return `Breakpoints left: ${left.length ? left.join(', ') : 'none'}`;
|
|
23
|
+
},
|
|
24
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { runDaemon } from "../../stm32/daemon.js";
|
|
2
|
+
import { toolCommand } from "../../stm32/toolCommand.js";
|
|
3
|
+
import { findProject } from "../../stm32/utils/project_utils.js";
|
|
4
|
+
import { PROBE_TOOLS } from "../probe/command.js";
|
|
5
|
+
import { PROJECT_HELP } from "../project/command.js";
|
|
6
|
+
import clearBreakpoint from "./clear_breakpoint.js";
|
|
7
|
+
import continueTarget from "./continue.js";
|
|
8
|
+
import debugStart from "./debug_start.js";
|
|
9
|
+
import debugStop from "./debug_stop.js";
|
|
10
|
+
import evaluate from "./evaluate.js";
|
|
11
|
+
import getStack from "./get_stack.js";
|
|
12
|
+
import getVariables from "./get_variables.js";
|
|
13
|
+
import halt from "./halt.js";
|
|
14
|
+
import setBreakpoint from "./set_breakpoint.js";
|
|
15
|
+
import step from "./step.js";
|
|
16
|
+
/** The session tools, served by the debug daemon. */
|
|
17
|
+
export const DEBUG_TOOLS = [debugStart, debugStop, halt, continueTarget, step, setBreakpoint, clearBreakpoint, getStack, getVariables, evaluate];
|
|
18
|
+
const subcommands = [
|
|
19
|
+
toolCommand({ command: "start", tool: debugStart, mode: "start", examples: [
|
|
20
|
+
["$0 debug start", "attach to the running firmware (it must match the newest .elf in build/)"],
|
|
21
|
+
["$0 debug start --flash", "flash the .elf and halt after reset"],
|
|
22
|
+
] }),
|
|
23
|
+
toolCommand({ command: "stop", tool: debugStop, mode: "session", examples: [["$0 debug stop", "end the session; the target keeps running"]] }),
|
|
24
|
+
toolCommand({ command: "halt", tool: halt, mode: "session", examples: [["$0 debug halt", "pause and show where"]] }),
|
|
25
|
+
toolCommand({ command: "continue", tool: continueTarget, mode: "session", examples: [
|
|
26
|
+
["$0 debug continue", "resume"],
|
|
27
|
+
["$0 debug continue --wait 10", "resume and wait up to 10 s for a breakpoint"],
|
|
28
|
+
] }),
|
|
29
|
+
toolCommand({ command: "step", tool: step, mode: "session", examples: [
|
|
30
|
+
["$0 debug step", "step over one source line"],
|
|
31
|
+
["$0 debug step --kind into", "step into a call"],
|
|
32
|
+
] }),
|
|
33
|
+
toolCommand({ command: "break", tool: setBreakpoint, mode: "session", examples: [
|
|
34
|
+
["$0 debug break --file Core/Src/main.c --line 120", "breakpoint at a line"],
|
|
35
|
+
["$0 debug break --file Core/Src/main.c --line 120 --condition 'count > 3'", "conditional breakpoint"],
|
|
36
|
+
] }),
|
|
37
|
+
toolCommand({ command: "clear", tool: clearBreakpoint, mode: "session", examples: [
|
|
38
|
+
["$0 debug clear --file Core/Src/main.c --line 120", "remove one breakpoint"],
|
|
39
|
+
["$0 debug clear", "remove every breakpoint"],
|
|
40
|
+
] }),
|
|
41
|
+
toolCommand({ command: "stack", tool: getStack, mode: "session", examples: [["$0 debug stack", "call stack of the halted target"]] }),
|
|
42
|
+
toolCommand({ command: "vars", tool: getVariables, mode: "session", examples: [["$0 debug vars --frame 1", "locals of the caller's frame"]] }),
|
|
43
|
+
toolCommand({ command: "eval", tool: evaluate, mode: "session", examples: [["$0 debug eval --expr 'count, cfg.mode, buf[2]'", "several expressions"]] }),
|
|
44
|
+
];
|
|
45
|
+
/** Hidden: the background process `debug start` launches in the project folder. */
|
|
46
|
+
const daemon = {
|
|
47
|
+
command: "daemon",
|
|
48
|
+
describe: false,
|
|
49
|
+
builder: cli => cli.options({ root: { type: "string", describe: "Project root, as the CLI that launched it found it" } }),
|
|
50
|
+
handler: async (argv) => runDaemon(argv.root ?? (await findProject()).root, [...DEBUG_TOOLS, ...PROBE_TOOLS]),
|
|
51
|
+
};
|
|
52
|
+
const command = {
|
|
53
|
+
command: "debug",
|
|
54
|
+
describe: "Debug the firmware on the board: breakpoints, stepping, stack, variables (probe-rs)",
|
|
55
|
+
builder: cli => [...subcommands, daemon].reduce((c, s) => c.command(s), cli)
|
|
56
|
+
.demandCommand(1, "debug needs a subcommand: start, stop, halt, continue, step, break, clear, stack, vars or eval")
|
|
57
|
+
.epilogue([
|
|
58
|
+
"`debug start` launches a background daemon for the project that holds the probe-rs session; the other",
|
|
59
|
+
"debug commands talk to it, so the session lives across runs until `debug stop` (the daemon then exits).",
|
|
60
|
+
"Its files are in .turingcode/ (daemon.token, daemon.log, probe.lock). Needs probe-rs and a .elf in build/",
|
|
61
|
+
"(`project build`). Breakpoint files are project-relative paths, e.g. Core/Src/main.c.",
|
|
62
|
+
PROJECT_HELP,
|
|
63
|
+
].join("\n")),
|
|
64
|
+
handler: () => { },
|
|
65
|
+
};
|
|
66
|
+
export default command;
|