@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,22 @@
|
|
|
1
|
+
import { _defineTool } from '../../stm32/tool.js';
|
|
2
|
+
import { getSession } from '../../stm32/session.js';
|
|
3
|
+
/** Resumes the target, optionally waiting for it to stop again. */
|
|
4
|
+
export default _defineTool({
|
|
5
|
+
name: 'continue',
|
|
6
|
+
description: 'Resume the target in the debug session. With wait > 0, waits up to that many seconds for it to stop (e.g. at a breakpoint) and reports where.',
|
|
7
|
+
properties: { wait: { type: 'integer', minimum: 0, maximum: 60, description: 'Seconds to wait for a stop (default 0)' } },
|
|
8
|
+
run: async (args) => {
|
|
9
|
+
const s = getSession();
|
|
10
|
+
s.requireHalted();
|
|
11
|
+
const stopped = s.waitEvent('stopped', (args.wait ?? 0) * 1000);
|
|
12
|
+
/** Set before the request: the stopped event of a short run can arrive before its response */
|
|
13
|
+
s.state = 'running';
|
|
14
|
+
await s.request('continue', { threadId: s.threadId }).catch((e) => {
|
|
15
|
+
s.state = 'halted';
|
|
16
|
+
throw e;
|
|
17
|
+
});
|
|
18
|
+
if (!args.wait)
|
|
19
|
+
return 'Running';
|
|
20
|
+
return (await stopped) ? s.location() : `Still running after ${args.wait} s`;
|
|
21
|
+
},
|
|
22
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { _defineTool } from '../../stm32/tool.js';
|
|
2
|
+
import { findStm32Project } from '../../stm32/utils/project_utils.js';
|
|
3
|
+
import { startSession } from '../../stm32/session.js';
|
|
4
|
+
import { findElf } from '../../stm32/utils/findElf.js';
|
|
5
|
+
import { getMcuFromIoc } from '../../stm32/utils/mcu_utils.js';
|
|
6
|
+
/** Starts a probe-rs debug session on the project's board. */
|
|
7
|
+
export default _defineTool({
|
|
8
|
+
name: 'debug_start',
|
|
9
|
+
description: "Start a probe-rs debug session on the project's board using the newest .elf in build/. By default it attaches to the running firmware (which must match that .elf); with flash=true it flashes the .elf first and halts after reset, so breakpoints can be set before continue. Takes ownership of the probe until `turingcode debug stop`.",
|
|
10
|
+
properties: { flash: { type: 'boolean', description: 'Flash the .elf and halt after reset (default false: attach)' } },
|
|
11
|
+
needsProbe: true,
|
|
12
|
+
run: async (args, ctx) => {
|
|
13
|
+
const project = await findStm32Project();
|
|
14
|
+
const elf = await findElf(project.root);
|
|
15
|
+
if (!elf)
|
|
16
|
+
throw new Error("No .elf in the project's build/ folder: run `turingcode project build` first");
|
|
17
|
+
const chip = await getMcuFromIoc(project.root);
|
|
18
|
+
const flash = args.flash === true;
|
|
19
|
+
const s = await startSession({ root: project.root, chip, elf: elf.path, flash });
|
|
20
|
+
return `Debug session started (${flash ? 'flashed' : 'attached'}, ${chip}, ${elf.path})\n${await s.location()}`;
|
|
21
|
+
},
|
|
22
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { _defineTool } from '../../stm32/tool.js';
|
|
2
|
+
import { getSession } from '../../stm32/session.js';
|
|
3
|
+
/** Ends the probe-rs debug session; the target keeps running. */
|
|
4
|
+
export default _defineTool({
|
|
5
|
+
name: 'debug_stop',
|
|
6
|
+
description: 'Stop the debug session and release the probe. Breakpoints are removed and the target keeps running.',
|
|
7
|
+
run: async () => {
|
|
8
|
+
await getSession().stop();
|
|
9
|
+
return 'Debug session stopped, probe released';
|
|
10
|
+
},
|
|
11
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { _defineTool } from '../../stm32/tool.js';
|
|
2
|
+
import { frameId, getSession } from '../../stm32/session.js';
|
|
3
|
+
/** Assignments, increments and calls could change the target; comparisons (==, !=, <=, >=) are allowed. */
|
|
4
|
+
const SIDE_EFFECTS = /=|\+\+|--|[A-Za-z_]\w*\s*\(|[;{}]/;
|
|
5
|
+
/** Checked before comparisons are removed: removing the "<=" of "<<=" would leave no "=". */
|
|
6
|
+
const SHIFT_ASSIGN = /<<=|>>=/;
|
|
7
|
+
/** Evaluates one or more comma-separated expressions in a frame of the halted target. */
|
|
8
|
+
export default _defineTool({
|
|
9
|
+
name: 'evaluate',
|
|
10
|
+
description: 'Evaluate side-effect-free expressions (variable, member, element; no assignments or calls) ' +
|
|
11
|
+
'in a frame of the halted target (0 = innermost). Separate several expressions with commas, e.g. "a, s.x, buf[2]".',
|
|
12
|
+
properties: {
|
|
13
|
+
expr: { type: 'string', maxLength: 1000 },
|
|
14
|
+
frame: { type: 'integer', minimum: 0, maximum: 64 },
|
|
15
|
+
},
|
|
16
|
+
required: ['expr'],
|
|
17
|
+
run: async (args) => {
|
|
18
|
+
/** Splitting on commas is safe: in C they only appear as the comma operator or in calls, and calls are refused. */
|
|
19
|
+
const exprs = args.expr
|
|
20
|
+
.split(',')
|
|
21
|
+
.map((e) => e.trim())
|
|
22
|
+
.filter(Boolean);
|
|
23
|
+
if (!exprs.length)
|
|
24
|
+
throw new Error('No expression given');
|
|
25
|
+
if (exprs.some((e) => SHIFT_ASSIGN.test(e) || SIDE_EFFECTS.test(e.replace(/[=!<>]=/g, ''))))
|
|
26
|
+
throw new Error('Only side-effect-free expressions are allowed: no assignments, ++/-- or function calls');
|
|
27
|
+
const s = getSession();
|
|
28
|
+
const id = await frameId(s, args.frame ?? 0);
|
|
29
|
+
const lines = [];
|
|
30
|
+
for (const e of exprs) {
|
|
31
|
+
try {
|
|
32
|
+
const r = await s.request('evaluate', {
|
|
33
|
+
expression: e,
|
|
34
|
+
frameId: id,
|
|
35
|
+
context: 'watch',
|
|
36
|
+
});
|
|
37
|
+
lines.push(`${e} = ${r.result}${r.type ? ` (${r.type})` : ''}`);
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
/** One bad expression should not hide the others' values. */
|
|
41
|
+
if (exprs.length === 1)
|
|
42
|
+
throw err;
|
|
43
|
+
lines.push(`${e}: ${err instanceof Error ? err.message : err}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return lines.join('\n');
|
|
47
|
+
},
|
|
48
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { _defineTool } from '../../stm32/tool.js';
|
|
2
|
+
import { getSession } from '../../stm32/session.js';
|
|
3
|
+
/** Lists the call stack of the halted target. */
|
|
4
|
+
export default _defineTool({
|
|
5
|
+
name: 'get_stack',
|
|
6
|
+
description: 'Call stack of the halted target in the debug session (frame 0 = innermost), with source file and line.',
|
|
7
|
+
run: async () => {
|
|
8
|
+
const s = getSession();
|
|
9
|
+
s.requireHalted();
|
|
10
|
+
const { stackFrames = [] } = await s.request('stackTrace', { threadId: s.threadId, levels: 32 });
|
|
11
|
+
const lines = stackFrames.map((f, i) => `#${i} ${f.name} at ${s.projectPath(f.source?.path)}:${f.line}${f.instructionPointerReference ? ` (${f.instructionPointerReference})` : ''}`);
|
|
12
|
+
return `${await s.location()}\n\n${lines.join('\n') || 'No stack frames'}`;
|
|
13
|
+
},
|
|
14
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { _defineTool } from '../../stm32/tool.js';
|
|
2
|
+
import { frameId, getSession } from '../../stm32/session.js';
|
|
3
|
+
/** Statics, globals and registers are left out: they are large; use evaluate or read_memory for those. */
|
|
4
|
+
const SKIPPED_SCOPES = /static|global|register/i;
|
|
5
|
+
const MAX_VARIABLES = 200;
|
|
6
|
+
/** Lists the local variables of a stack frame. */
|
|
7
|
+
export default _defineTool({
|
|
8
|
+
name: 'get_variables',
|
|
9
|
+
description: 'Local variables of a stack frame of the halted target (0 = innermost), with values and types. Structs and arrays show their summary; use `turingcode debug eval` for a member or element.',
|
|
10
|
+
properties: { frame: { type: 'integer', minimum: 0, maximum: 64 } },
|
|
11
|
+
run: async (args) => {
|
|
12
|
+
const s = getSession();
|
|
13
|
+
const id = await frameId(s, args.frame ?? 0);
|
|
14
|
+
const { scopes = [] } = await s.request('scopes', { frameId: id });
|
|
15
|
+
const lines = [];
|
|
16
|
+
for (const scope of scopes.filter((sc) => !SKIPPED_SCOPES.test(sc.name))) {
|
|
17
|
+
const { variables = [] } = await s.request('variables', { variablesReference: scope.variablesReference });
|
|
18
|
+
lines.push(`${scope.name}:`);
|
|
19
|
+
for (const v of variables.slice(0, MAX_VARIABLES))
|
|
20
|
+
lines.push(` ${v.name} = ${v.value}${v.type ? ` (${v.type})` : ''}`);
|
|
21
|
+
if (variables.length > MAX_VARIABLES)
|
|
22
|
+
lines.push(` ... ${variables.length - MAX_VARIABLES} more`);
|
|
23
|
+
}
|
|
24
|
+
return lines.join('\n') || 'No local variables in this frame';
|
|
25
|
+
},
|
|
26
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { _defineTool } from '../../stm32/tool.js';
|
|
2
|
+
import { getSession } from '../../stm32/session.js';
|
|
3
|
+
/** Pauses the target in the debug session. */
|
|
4
|
+
export default _defineTool({
|
|
5
|
+
name: 'halt',
|
|
6
|
+
description: 'Pause the target in the debug session and report where it stopped.',
|
|
7
|
+
run: async () => {
|
|
8
|
+
const s = getSession();
|
|
9
|
+
if (s.state === 'halted')
|
|
10
|
+
return `Already halted\n${await s.location()}`;
|
|
11
|
+
const stopped = s.waitEvent('stopped', 5000);
|
|
12
|
+
await s.request('pause', { threadId: s.threadId });
|
|
13
|
+
await stopped;
|
|
14
|
+
return s.location();
|
|
15
|
+
},
|
|
16
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { _defineTool } from '../../stm32/tool.js';
|
|
2
|
+
import { getSession, projectFile, syncBreakpoints } from '../../stm32/session.js';
|
|
3
|
+
/** Adds a source breakpoint to the debug session. */
|
|
4
|
+
export default _defineTool({
|
|
5
|
+
name: 'set_breakpoint',
|
|
6
|
+
description: 'Add a source breakpoint in the debug session. Code runs from flash, so these are hardware breakpoints: 4 on Cortex-M0/M0+, 6 on M3/M4/M33, 8 on M7. Remove unused ones with `turingcode debug clear`.',
|
|
7
|
+
properties: {
|
|
8
|
+
file: { type: 'string', maxLength: 512, description: 'Project-relative path' },
|
|
9
|
+
line: { type: 'integer', minimum: 1 },
|
|
10
|
+
condition: { type: 'string', maxLength: 200 },
|
|
11
|
+
},
|
|
12
|
+
required: ['file', 'line'],
|
|
13
|
+
run: async (args) => {
|
|
14
|
+
const s = getSession();
|
|
15
|
+
if (args.condition && !s.capabilities.supportsConditionalBreakpoints)
|
|
16
|
+
throw new Error('This probe-rs version does not support conditional breakpoints');
|
|
17
|
+
const rel = projectFile(s.opts.root, args.file);
|
|
18
|
+
const list = (s.breakpoints.get(rel) ?? []).filter((b) => b.line !== args.line);
|
|
19
|
+
s.breakpoints.set(rel, [...list, { line: args.line, condition: args.condition }]);
|
|
20
|
+
const placed = await syncBreakpoints(s, rel);
|
|
21
|
+
const bp = placed[placed.length - 1];
|
|
22
|
+
if (!bp?.verified) {
|
|
23
|
+
s.breakpoints.set(rel, list);
|
|
24
|
+
await syncBreakpoints(s, rel).catch(() => undefined);
|
|
25
|
+
throw new Error(`Breakpoint not set at ${rel}:${args.line}: ${bp?.message ?? 'no code at that line'}`);
|
|
26
|
+
}
|
|
27
|
+
const moved = bp.line && bp.line !== args.line ? ` (moved to line ${bp.line})` : '';
|
|
28
|
+
return `Breakpoint set at ${rel}:${args.line}${moved}`;
|
|
29
|
+
},
|
|
30
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { _defineTool } from '../../stm32/tool.js';
|
|
2
|
+
import { getSession } from '../../stm32/session.js';
|
|
3
|
+
const COMMANDS = { over: 'next', into: 'stepIn', out: 'stepOut' };
|
|
4
|
+
/** Steps the halted target by one source line. */
|
|
5
|
+
export default _defineTool({
|
|
6
|
+
name: 'step',
|
|
7
|
+
description: 'Step the halted target one source line (over, the default; into a call; or out of the function) and report where it stopped.',
|
|
8
|
+
properties: { kind: { type: 'string', enum: ['over', 'into', 'out'] } },
|
|
9
|
+
run: async (args) => {
|
|
10
|
+
const s = getSession();
|
|
11
|
+
s.requireHalted();
|
|
12
|
+
const stopped = s.waitEvent('stopped', 10_000);
|
|
13
|
+
/** Set before the request: the stopped event of a short run can arrive before its response */
|
|
14
|
+
s.state = 'running';
|
|
15
|
+
await s.request(COMMANDS[args.kind ?? 'over'], { threadId: s.threadId }).catch((e) => {
|
|
16
|
+
s.state = 'halted';
|
|
17
|
+
throw e;
|
|
18
|
+
});
|
|
19
|
+
if (!(await stopped))
|
|
20
|
+
return 'Still running after 10 s (the step did not finish)';
|
|
21
|
+
return s.location();
|
|
22
|
+
},
|
|
23
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { installMods } from "./install.js";
|
|
2
|
+
const command = {
|
|
3
|
+
command: "install-mods [names..]",
|
|
4
|
+
describe: "Install the Claude Code plugins shipped with turingcode (e.g. turingcode-skills)",
|
|
5
|
+
builder: cli => cli
|
|
6
|
+
.positional("names", { type: "string", array: true, describe: "Only install these mods (default: all)" })
|
|
7
|
+
.example("$0 install-mods", "add the turingcode marketplace to Claude Code and install every plugin")
|
|
8
|
+
.epilogue([
|
|
9
|
+
"Runs `claude plugin marketplace add|update` and `claude plugin install|update`; needs Claude Code on PATH.",
|
|
10
|
+
"Prints one `Installed mod: <name>` line per plugin; restart Claude Code to load them.",
|
|
11
|
+
"Exit: 0 installed, 1 a claude command failed, 2 unknown mod name.",
|
|
12
|
+
].join("\n")),
|
|
13
|
+
handler: args => {
|
|
14
|
+
const names = installMods(args.names?.map(String));
|
|
15
|
+
console.log(names.map(name => `Installed mod: ${name}`).join("\n") + "\nRestart Claude Code to load them.");
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
export default command;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare const MARKETPLACE_DIR: string;
|
|
2
|
+
/** Runs one command and throws when it fails. */
|
|
3
|
+
export type Runner = (cmd: string, args: string[]) => void;
|
|
4
|
+
/**
|
|
5
|
+
* Runs a command with inherited output; on Windows through the shell so `claude.cmd` resolves.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} cmd - Program name.
|
|
8
|
+
* @param {string[]} args - Its arguments.
|
|
9
|
+
* @returns {void}
|
|
10
|
+
* @throws {Error} When it cannot start or exits non-zero.
|
|
11
|
+
*/
|
|
12
|
+
export declare const runCommand: Runner;
|
|
13
|
+
/**
|
|
14
|
+
* Adds the CLI's Claude Code marketplace (mods/claude) and installs and updates its plugins.
|
|
15
|
+
* Every step is idempotent.
|
|
16
|
+
*
|
|
17
|
+
* @param {string[]} [only=[]] - Only install these mods (empty: all).
|
|
18
|
+
* @param {Runner} [run=runCommand] - Runs the `claude` commands.
|
|
19
|
+
* @param {string} [source=MARKETPLACE_DIR] - The marketplace folder, holding .claude-plugin/marketplace.json.
|
|
20
|
+
* @returns {string[]} The installed mod names.
|
|
21
|
+
* @throws {Error} When a name in `only` is not in the marketplace (`exitCode` 2), or a `claude` command fails.
|
|
22
|
+
*/
|
|
23
|
+
export declare function installMods(only?: string[], run?: Runner, source?: string): string[];
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { packageRoot } from "../../core/files.js";
|
|
5
|
+
export const MARKETPLACE_DIR = join(packageRoot(), "mods", "claude");
|
|
6
|
+
/**
|
|
7
|
+
* Runs a command with inherited output; on Windows through the shell so `claude.cmd` resolves.
|
|
8
|
+
*
|
|
9
|
+
* @param {string} cmd - Program name.
|
|
10
|
+
* @param {string[]} args - Its arguments.
|
|
11
|
+
* @returns {void}
|
|
12
|
+
* @throws {Error} When it cannot start or exits non-zero.
|
|
13
|
+
*/
|
|
14
|
+
export const runCommand = (cmd, args) => {
|
|
15
|
+
const win = process.platform === "win32";
|
|
16
|
+
const options = { stdio: "inherit", windowsHide: true };
|
|
17
|
+
/** a shell with an args array is deprecated (DEP0190), so give it one command line, each argument quoted (the marketplace path may contain spaces) */
|
|
18
|
+
const result = win ? spawnSync(`${cmd} ${args.map(a => `"${a}"`).join(" ")}`, { ...options, shell: true }) : spawnSync(cmd, args, options);
|
|
19
|
+
if (result.error)
|
|
20
|
+
throw new Error(`${cmd} could not start (${result.error.message}); is Claude Code installed and on PATH?`);
|
|
21
|
+
if (result.status !== 0)
|
|
22
|
+
throw new Error(`${cmd} ${args.join(" ")} exited with ${result.status}`);
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Adds the CLI's Claude Code marketplace (mods/claude) and installs and updates its plugins.
|
|
26
|
+
* Every step is idempotent.
|
|
27
|
+
*
|
|
28
|
+
* @param {string[]} [only=[]] - Only install these mods (empty: all).
|
|
29
|
+
* @param {Runner} [run=runCommand] - Runs the `claude` commands.
|
|
30
|
+
* @param {string} [source=MARKETPLACE_DIR] - The marketplace folder, holding .claude-plugin/marketplace.json.
|
|
31
|
+
* @returns {string[]} The installed mod names.
|
|
32
|
+
* @throws {Error} When a name in `only` is not in the marketplace (`exitCode` 2), or a `claude` command fails.
|
|
33
|
+
*/
|
|
34
|
+
export function installMods(only = [], run = runCommand, source = MARKETPLACE_DIR) {
|
|
35
|
+
const marketplace = JSON.parse(readFileSync(join(source, ".claude-plugin", "marketplace.json"), "utf8"));
|
|
36
|
+
const available = marketplace.plugins.map(p => p.name);
|
|
37
|
+
const unknown = only.filter(name => !available.includes(name));
|
|
38
|
+
if (unknown.length)
|
|
39
|
+
throw Object.assign(new Error(`Unknown mod: ${unknown.join(", ")}. Available: ${available.join(", ")}`), { exitCode: 2 });
|
|
40
|
+
const names = only.length ? [...new Set(only)] : available;
|
|
41
|
+
run("claude", ["plugin", "marketplace", "add", source]);
|
|
42
|
+
run("claude", ["plugin", "marketplace", "update", marketplace.name]);
|
|
43
|
+
for (const name of names) {
|
|
44
|
+
/** install is a no-op for an installed plugin, so update brings it to the shipped version */
|
|
45
|
+
run("claude", ["plugin", "install", `${name}@${marketplace.name}`]);
|
|
46
|
+
run("claude", ["plugin", "update", `${name}@${marketplace.name}`]);
|
|
47
|
+
}
|
|
48
|
+
return names;
|
|
49
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { join, resolve } from "node:path";
|
|
2
|
+
import { DEFAULT_TARGET, installSkills } from "./install.js";
|
|
3
|
+
const command = {
|
|
4
|
+
command: "install-skills [names..]",
|
|
5
|
+
describe: "Copy the agent skills shipped with turingcode into ~/.agents/skills (Codex, OpenCode)",
|
|
6
|
+
builder: cli => cli
|
|
7
|
+
.positional("names", { type: "string", array: true, describe: "Only install these skills (default: all)" })
|
|
8
|
+
.option("target", { type: "string", describe: "Skills directory", default: DEFAULT_TARGET })
|
|
9
|
+
.example("$0 install-skills", "install every shipped skill")
|
|
10
|
+
.example("$0 install-skills <name> --target .agents/skills", "one skill, into a project folder")
|
|
11
|
+
.epilogue([
|
|
12
|
+
"Claude Code gets the same skills from the turingcode-skills plugin: `$0 install-mods`.",
|
|
13
|
+
"Prints one `Installed skill: <path>` line per skill.",
|
|
14
|
+
"Exit: 0 installed, 1 copy failed, 2 unknown skill name or bad flag.",
|
|
15
|
+
].join("\n")),
|
|
16
|
+
handler: args => {
|
|
17
|
+
const target = resolve(args.target ?? DEFAULT_TARGET);
|
|
18
|
+
const names = installSkills(target, args.names?.map(String));
|
|
19
|
+
console.log(names.map(name => `Installed skill: ${join(target, name)}`).join("\n"));
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
export default command;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Claude Code loads these skills from the turingcode-skills plugin (install-mods); this copy serves Codex and OpenCode. */
|
|
2
|
+
export declare const SKILLS_DIR: string;
|
|
3
|
+
export declare const DEFAULT_TARGET: string;
|
|
4
|
+
/**
|
|
5
|
+
* Copies the skill folders shipped with the CLI (all, or only `only`) into a skills directory,
|
|
6
|
+
* replacing older copies so files removed from a skill do not linger.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} [target=DEFAULT_TARGET] - Skills directory to install into.
|
|
9
|
+
* @param {string[]} [only=[]] - Only install these skills (empty: all).
|
|
10
|
+
* @param {string} [source=SKILLS_DIR] - Folder holding one folder per skill.
|
|
11
|
+
* @returns {string[]} The installed skill names.
|
|
12
|
+
* @throws {Error} When a name in `only` is not shipped (`exitCode` 2).
|
|
13
|
+
*/
|
|
14
|
+
export declare function installSkills(target?: string, only?: string[], source?: string): string[];
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { cpSync, readdirSync, rmSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { packageRoot } from "../../core/files.js";
|
|
5
|
+
/** Claude Code loads these skills from the turingcode-skills plugin (install-mods); this copy serves Codex and OpenCode. */
|
|
6
|
+
export const SKILLS_DIR = join(packageRoot(), "mods", "claude", "turingcode-skills", "skills");
|
|
7
|
+
export const DEFAULT_TARGET = join(homedir(), ".agents", "skills");
|
|
8
|
+
/**
|
|
9
|
+
* Copies the skill folders shipped with the CLI (all, or only `only`) into a skills directory,
|
|
10
|
+
* replacing older copies so files removed from a skill do not linger.
|
|
11
|
+
*
|
|
12
|
+
* @param {string} [target=DEFAULT_TARGET] - Skills directory to install into.
|
|
13
|
+
* @param {string[]} [only=[]] - Only install these skills (empty: all).
|
|
14
|
+
* @param {string} [source=SKILLS_DIR] - Folder holding one folder per skill.
|
|
15
|
+
* @returns {string[]} The installed skill names.
|
|
16
|
+
* @throws {Error} When a name in `only` is not shipped (`exitCode` 2).
|
|
17
|
+
*/
|
|
18
|
+
export function installSkills(target = DEFAULT_TARGET, only = [], source = SKILLS_DIR) {
|
|
19
|
+
const available = readdirSync(source, { withFileTypes: true }).filter(e => e.isDirectory()).map(e => e.name);
|
|
20
|
+
const unknown = only.filter(name => !available.includes(name));
|
|
21
|
+
if (unknown.length)
|
|
22
|
+
throw Object.assign(new Error(`Unknown skill: ${unknown.join(", ")}. Available: ${available.join(", ")}`), { exitCode: 2 });
|
|
23
|
+
const names = only.length ? [...new Set(only)] : available;
|
|
24
|
+
for (const name of names) {
|
|
25
|
+
rmSync(join(target, name), { recursive: true, force: true });
|
|
26
|
+
cpSync(join(source, name), join(target, name), { recursive: true });
|
|
27
|
+
}
|
|
28
|
+
return names;
|
|
29
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { toolCommand } from '../../stm32/toolCommand.js';
|
|
2
|
+
import { PROJECT_HELP } from '../project/command.js';
|
|
3
|
+
import killAllDebuggers from './kill_all_debuggers.js';
|
|
4
|
+
import listProbes from './list_probes.js';
|
|
5
|
+
import programProject from './program_project.js';
|
|
6
|
+
import readFaultStatus from './read_fault_status.js';
|
|
7
|
+
import readMemory from './read_memory.js';
|
|
8
|
+
import readPeripheral from './read_peripheral.js';
|
|
9
|
+
import resetProbeUsb from './reset_probe_usb.js';
|
|
10
|
+
import resetTarget from './reset_target.js';
|
|
11
|
+
import targetInfo from './target_info.js';
|
|
12
|
+
/** The probe tools, also served by the debug daemon. */
|
|
13
|
+
export const PROBE_TOOLS = [
|
|
14
|
+
listProbes,
|
|
15
|
+
targetInfo,
|
|
16
|
+
readMemory,
|
|
17
|
+
readPeripheral,
|
|
18
|
+
readFaultStatus,
|
|
19
|
+
programProject,
|
|
20
|
+
resetTarget,
|
|
21
|
+
resetProbeUsb,
|
|
22
|
+
killAllDebuggers,
|
|
23
|
+
];
|
|
24
|
+
const subcommands = [
|
|
25
|
+
toolCommand({
|
|
26
|
+
command: 'list',
|
|
27
|
+
tool: listProbes,
|
|
28
|
+
mode: 'probe',
|
|
29
|
+
examples: [['$0 probe list', 'the connected probes']],
|
|
30
|
+
}),
|
|
31
|
+
toolCommand({
|
|
32
|
+
command: 'info',
|
|
33
|
+
tool: targetInfo,
|
|
34
|
+
mode: 'probe',
|
|
35
|
+
server: true,
|
|
36
|
+
examples: [
|
|
37
|
+
[
|
|
38
|
+
'$0 probe info',
|
|
39
|
+
'which chip is connected, and its CubeMX names for project template',
|
|
40
|
+
],
|
|
41
|
+
],
|
|
42
|
+
}),
|
|
43
|
+
toolCommand({
|
|
44
|
+
command: 'read',
|
|
45
|
+
tool: readMemory,
|
|
46
|
+
mode: 'probe',
|
|
47
|
+
examples: [
|
|
48
|
+
[
|
|
49
|
+
'$0 probe read --address 0xE0042000 --length 4',
|
|
50
|
+
'one 32-bit word (here DBGMCU_IDCODE)',
|
|
51
|
+
],
|
|
52
|
+
[
|
|
53
|
+
'$0 probe read --address 0x20000000 --length 64 --width 8',
|
|
54
|
+
'64 bytes of RAM, byte by byte',
|
|
55
|
+
],
|
|
56
|
+
],
|
|
57
|
+
}),
|
|
58
|
+
toolCommand({
|
|
59
|
+
command: 'peripheral',
|
|
60
|
+
tool: readPeripheral,
|
|
61
|
+
mode: 'probe',
|
|
62
|
+
server: true,
|
|
63
|
+
examples: [['$0 probe peripheral --name GPIOA', "GPIOA's registers, decoded"]],
|
|
64
|
+
}),
|
|
65
|
+
toolCommand({
|
|
66
|
+
command: 'faults',
|
|
67
|
+
tool: readFaultStatus,
|
|
68
|
+
mode: 'probe',
|
|
69
|
+
examples: [['$0 probe faults', 'decode CFSR, HFSR, ... after a HardFault']],
|
|
70
|
+
}),
|
|
71
|
+
toolCommand({
|
|
72
|
+
command: 'program',
|
|
73
|
+
tool: programProject,
|
|
74
|
+
mode: 'probe',
|
|
75
|
+
examples: [['$0 probe program', 'flash the newest .elf in build/ and reset']],
|
|
76
|
+
}),
|
|
77
|
+
toolCommand({
|
|
78
|
+
command: 'reset',
|
|
79
|
+
tool: resetTarget,
|
|
80
|
+
mode: 'probe',
|
|
81
|
+
examples: [['$0 probe reset', 'hardware reset of the target']],
|
|
82
|
+
}),
|
|
83
|
+
toolCommand({
|
|
84
|
+
command: 'reset-usb',
|
|
85
|
+
tool: resetProbeUsb,
|
|
86
|
+
mode: 'probe',
|
|
87
|
+
examples: [
|
|
88
|
+
['$0 probe reset-usb', "restart the ST-LINK's USB connection (Windows, admin)"],
|
|
89
|
+
],
|
|
90
|
+
}),
|
|
91
|
+
toolCommand({
|
|
92
|
+
command: 'kill-debuggers',
|
|
93
|
+
tool: killAllDebuggers,
|
|
94
|
+
mode: 'probe',
|
|
95
|
+
examples: [['$0 probe kill-debuggers', 'free a probe held by a stuck debugger']],
|
|
96
|
+
}),
|
|
97
|
+
];
|
|
98
|
+
const command = {
|
|
99
|
+
command: 'probe',
|
|
100
|
+
describe: 'Program, reset and read the target board over the debug probe (SWD)',
|
|
101
|
+
builder: (cli) => subcommands
|
|
102
|
+
.reduce((c, s) => c.command(s), cli)
|
|
103
|
+
.demandCommand(1, 'probe needs a subcommand: list, info, read, peripheral, faults, program, reset, reset-usb or kill-debuggers')
|
|
104
|
+
.epilogue([
|
|
105
|
+
'One probe command runs at a time: the probe',
|
|
106
|
+
'lock is .turingcode/probe.lock. While a debug session runs, these commands go to its daemon, and',
|
|
107
|
+
'the ones that need the probe are refused until `debug stop`.',
|
|
108
|
+
PROJECT_HELP,
|
|
109
|
+
].join('\n')),
|
|
110
|
+
handler: () => { },
|
|
111
|
+
};
|
|
112
|
+
export default command;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { promisify } from 'node:util';
|
|
3
|
+
import { _defineTool } from '../../stm32/tool.js';
|
|
4
|
+
import { releaseProbe } from '../../stm32/utils/utils_mutex.js';
|
|
5
|
+
const run = promisify(execFile);
|
|
6
|
+
/** Programs that can hold an ST-LINK or other debug probe open. */
|
|
7
|
+
const DEBUGGERS = [
|
|
8
|
+
'probe-rs',
|
|
9
|
+
'STM32_Programmer_CLI',
|
|
10
|
+
'openocd',
|
|
11
|
+
'ST-LINK_gdbserver',
|
|
12
|
+
'stlinkserver',
|
|
13
|
+
];
|
|
14
|
+
/**
|
|
15
|
+
* Force-kills every running process with the given program name.
|
|
16
|
+
* @param name program name without extension
|
|
17
|
+
* @returns true if a process was killed, false if none was running
|
|
18
|
+
*/
|
|
19
|
+
async function killByName(name) {
|
|
20
|
+
try {
|
|
21
|
+
if (process.platform === 'win32')
|
|
22
|
+
await run('taskkill', ['/F', '/T', '/IM', `${name}.exe`], { windowsHide: true });
|
|
23
|
+
else if (process.platform === 'darwin')
|
|
24
|
+
await run('killall', ['-9', name]);
|
|
25
|
+
/** Linux: killall is missing on minimal installs; pkill -x matches the process name, which the kernel cuts to 15 characters */
|
|
26
|
+
else
|
|
27
|
+
await run('pkill', ['-9', '-x', name.slice(0, 15)]);
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return false; /** not running (or not ours to kill) */
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/** Frees a probe left held by a stuck debugger, including one from another app or a crashed session. */
|
|
35
|
+
export default _defineTool({
|
|
36
|
+
name: 'kill_all_debuggers',
|
|
37
|
+
description: `Force-kill every running debugger process on this machine (${DEBUGGERS.join(', ')}), \
|
|
38
|
+
including ones started by other apps such as STM32CubeIDE. Use when programming or debugging fails because the probe is held \
|
|
39
|
+
(e.g. DEV_USB_COMM_ERR, "Failed to open the debug probe"). Ends any running debug session.`,
|
|
40
|
+
run: async () => {
|
|
41
|
+
const killed = [];
|
|
42
|
+
for (const name of DEBUGGERS)
|
|
43
|
+
if (await killByName(name))
|
|
44
|
+
killed.push(name);
|
|
45
|
+
releaseProbe(); /** the killed runs may not have released it yet */
|
|
46
|
+
return killed.length
|
|
47
|
+
? `Killed: ${killed.join(', ')}`
|
|
48
|
+
: 'No debugger processes were running';
|
|
49
|
+
},
|
|
50
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { _defineTool } from '../../stm32/tool.js';
|
|
2
|
+
import { DebugActionListProbes } from '../../stm32/actions/DebugActionListProbes.js';
|
|
3
|
+
/** Lists the connected debug probes with the installed debug tool. */
|
|
4
|
+
export default _defineTool({
|
|
5
|
+
name: 'list_probes',
|
|
6
|
+
description: 'List the debug probes (ST-LINK, J-Link, CMSIS-DAP, ...) connected to this machine (probe-rs list, or STM32_Programmer_CLI --list).',
|
|
7
|
+
run: async () => DebugActionListProbes.run_action_get_tail({}),
|
|
8
|
+
});
|