@turingcode/cli 0.2.13 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. package/README.md +2 -0
  2. package/dist/cli/create-cli.d.ts +10 -0
  3. package/dist/cli/create-cli.js +12 -1
  4. package/dist/cli/index.d.ts +9 -0
  5. package/dist/cli/index.js +5 -1
  6. package/dist/core/bound-error.d.ts +10 -0
  7. package/dist/core/date.d.ts +12 -0
  8. package/dist/core/exact/expression.d.ts +49 -0
  9. package/dist/core/exact/fraction.d.ts +85 -0
  10. package/dist/core/files.d.ts +44 -0
  11. package/dist/core/files.js +46 -1
  12. package/dist/core/json-shape.d.ts +45 -0
  13. package/dist/core/mcp.d.ts +92 -0
  14. package/dist/core/mcp.js +56 -15
  15. package/dist/core/query.d.ts +69 -0
  16. package/dist/core/report.d.ts +11 -0
  17. package/dist/core/tables/csv.d.ts +18 -0
  18. package/dist/core/tables/markdown.d.ts +22 -0
  19. package/dist/core/tables/types.d.ts +25 -0
  20. package/dist/features/contract/check.d.ts +30 -0
  21. package/dist/features/contract/command.d.ts +12 -0
  22. package/dist/features/contract/command.js +64 -64
  23. package/dist/features/contract/describe.d.ts +22 -0
  24. package/dist/features/contract/diagnostics.d.ts +108 -0
  25. package/dist/features/contract/load.d.ts +58 -0
  26. package/dist/features/contract/model.d.ts +67 -0
  27. package/dist/features/contract/rules.d.ts +137 -0
  28. package/dist/features/debug/clear_breakpoint.d.ts +2 -0
  29. package/dist/features/debug/clear_breakpoint.js +24 -0
  30. package/dist/features/debug/command.d.ts +5 -0
  31. package/dist/features/debug/command.js +66 -0
  32. package/dist/features/debug/continue.d.ts +2 -0
  33. package/dist/features/debug/continue.js +22 -0
  34. package/dist/features/debug/debug_start.d.ts +2 -0
  35. package/dist/features/debug/debug_start.js +22 -0
  36. package/dist/features/debug/debug_stop.d.ts +2 -0
  37. package/dist/features/debug/debug_stop.js +11 -0
  38. package/dist/features/debug/evaluate.d.ts +2 -0
  39. package/dist/features/debug/evaluate.js +48 -0
  40. package/dist/features/debug/get_stack.d.ts +2 -0
  41. package/dist/features/debug/get_stack.js +14 -0
  42. package/dist/features/debug/get_variables.d.ts +2 -0
  43. package/dist/features/debug/get_variables.js +26 -0
  44. package/dist/features/debug/halt.d.ts +2 -0
  45. package/dist/features/debug/halt.js +16 -0
  46. package/dist/features/debug/set_breakpoint.d.ts +2 -0
  47. package/dist/features/debug/set_breakpoint.js +30 -0
  48. package/dist/features/debug/step.d.ts +2 -0
  49. package/dist/features/debug/step.js +23 -0
  50. package/dist/features/install-mods/command.d.ts +6 -0
  51. package/dist/features/install-mods/command.js +18 -0
  52. package/dist/features/install-mods/install.d.ts +23 -0
  53. package/dist/features/install-mods/install.js +48 -0
  54. package/dist/features/install-skills/command.d.ts +7 -0
  55. package/dist/features/install-skills/command.js +22 -0
  56. package/dist/features/install-skills/install.d.ts +13 -0
  57. package/dist/features/install-skills/install.js +29 -0
  58. package/dist/features/probe/command.d.ts +5 -0
  59. package/dist/features/probe/command.js +44 -0
  60. package/dist/features/probe/kill_all_debuggers.d.ts +2 -0
  61. package/dist/features/probe/kill_all_debuggers.js +50 -0
  62. package/dist/features/probe/list_probes.d.ts +2 -0
  63. package/dist/features/probe/list_probes.js +8 -0
  64. package/dist/features/probe/program_project.d.ts +2 -0
  65. package/dist/features/probe/program_project.js +29 -0
  66. package/dist/features/probe/read_fault_status.d.ts +2 -0
  67. package/dist/features/probe/read_fault_status.js +19 -0
  68. package/dist/features/probe/read_memory.d.ts +2 -0
  69. package/dist/features/probe/read_memory.js +36 -0
  70. package/dist/features/probe/read_peripheral.d.ts +2 -0
  71. package/dist/features/probe/read_peripheral.js +58 -0
  72. package/dist/features/probe/reset_probe_usb.d.ts +2 -0
  73. package/dist/features/probe/reset_probe_usb.js +17 -0
  74. package/dist/features/probe/reset_target.d.ts +2 -0
  75. package/dist/features/probe/reset_target.js +16 -0
  76. package/dist/features/probe/target_info.d.ts +2 -0
  77. package/dist/features/probe/target_info.js +34 -0
  78. package/dist/features/project/analysis_static.d.ts +2 -0
  79. package/dist/features/project/analysis_static.js +19 -0
  80. package/dist/features/project/analysis_syntax_check.d.ts +2 -0
  81. package/dist/features/project/analysis_syntax_check.js +21 -0
  82. package/dist/features/project/command.d.ts +5 -0
  83. package/dist/features/project/command.js +64 -0
  84. package/dist/features/project/project_build.d.ts +2 -0
  85. package/dist/features/project/project_build.js +22 -0
  86. package/dist/features/project/project_download_template.d.ts +2 -0
  87. package/dist/features/project/project_download_template.js +34 -0
  88. package/dist/features/project/project_regenerate.d.ts +2 -0
  89. package/dist/features/project/project_regenerate.js +20 -0
  90. package/dist/features/project/project_sync_from_server.d.ts +2 -0
  91. package/dist/features/project/project_sync_from_server.js +13 -0
  92. package/dist/features/project/project_sync_to_server.d.ts +2 -0
  93. package/dist/features/project/project_sync_to_server.js +51 -0
  94. package/dist/features/project/stm32_cubetools_download_drivers.d.ts +2 -0
  95. package/dist/features/project/stm32_cubetools_download_drivers.js +19 -0
  96. package/dist/features/status/command.d.ts +2 -0
  97. package/dist/features/status/command.js +6 -0
  98. package/dist/features/status/get_status.d.ts +2 -0
  99. package/dist/features/status/get_status.js +44 -0
  100. package/dist/features/table/check.d.ts +38 -0
  101. package/dist/features/table/command.d.ts +3 -0
  102. package/dist/features/table/read.d.ts +28 -0
  103. package/dist/features/tool/command.d.ts +35 -0
  104. package/dist/lib.d.ts +11 -0
  105. package/dist/lib.js +9 -0
  106. package/dist/stm32/actions/DebugAction.d.ts +63 -0
  107. package/dist/stm32/actions/DebugAction.js +105 -0
  108. package/dist/stm32/actions/DebugActionInfo.d.ts +7 -0
  109. package/dist/stm32/actions/DebugActionInfo.js +9 -0
  110. package/dist/stm32/actions/DebugActionListProbes.d.ts +9 -0
  111. package/dist/stm32/actions/DebugActionListProbes.js +10 -0
  112. package/dist/stm32/actions/DebugActionProgram.d.ts +28 -0
  113. package/dist/stm32/actions/DebugActionProgram.js +79 -0
  114. package/dist/stm32/actions/DebugActionRead.d.ts +38 -0
  115. package/dist/stm32/actions/DebugActionRead.js +59 -0
  116. package/dist/stm32/actions/DebugActionReset.d.ts +11 -0
  117. package/dist/stm32/actions/DebugActionReset.js +9 -0
  118. package/dist/stm32/actions/DebugActionServer.d.ts +7 -0
  119. package/dist/stm32/actions/DebugActionServer.js +9 -0
  120. package/dist/stm32/analysis.d.ts +19 -0
  121. package/dist/stm32/analysis.js +21 -0
  122. package/dist/stm32/build.d.ts +34 -0
  123. package/dist/stm32/build.js +79 -0
  124. package/dist/stm32/context.d.ts +23 -0
  125. package/dist/stm32/context.js +42 -0
  126. package/dist/stm32/daemon.d.ts +63 -0
  127. package/dist/stm32/daemon.js +202 -0
  128. package/dist/stm32/regen.d.ts +68 -0
  129. package/dist/stm32/regen.js +225 -0
  130. package/dist/stm32/session.d.ts +134 -0
  131. package/dist/stm32/session.js +374 -0
  132. package/dist/stm32/sync.d.ts +24 -0
  133. package/dist/stm32/sync.js +72 -0
  134. package/dist/stm32/tool.d.ts +43 -0
  135. package/dist/stm32/tool.js +20 -0
  136. package/dist/stm32/toolCommand.d.ts +50 -0
  137. package/dist/stm32/toolCommand.js +102 -0
  138. package/dist/stm32/utils/discover_tools.d.ts +24 -0
  139. package/dist/stm32/utils/discover_tools.js +121 -0
  140. package/dist/stm32/utils/downloadzip_utils.d.ts +57 -0
  141. package/dist/stm32/utils/downloadzip_utils.js +180 -0
  142. package/dist/stm32/utils/faultUtils.d.ts +14 -0
  143. package/dist/stm32/utils/faultUtils.js +69 -0
  144. package/dist/stm32/utils/findElf.d.ts +9 -0
  145. package/dist/stm32/utils/findElf.js +19 -0
  146. package/dist/stm32/utils/hash_utils.d.ts +19 -0
  147. package/dist/stm32/utils/hash_utils.js +28 -0
  148. package/dist/stm32/utils/listSyncFiles.d.ts +9 -0
  149. package/dist/stm32/utils/listSyncFiles.js +98 -0
  150. package/dist/stm32/utils/mcu_utils.d.ts +59 -0
  151. package/dist/stm32/utils/mcu_utils.js +99 -0
  152. package/dist/stm32/utils/project_utils.d.ts +54 -0
  153. package/dist/stm32/utils/project_utils.js +102 -0
  154. package/dist/stm32/utils/svdUtils.d.ts +31 -0
  155. package/dist/stm32/utils/svdUtils.js +30 -0
  156. package/dist/stm32/utils/truncate.d.ts +7 -0
  157. package/dist/stm32/utils/truncate.js +9 -0
  158. package/dist/stm32/utils/usb_utils.d.ts +5 -0
  159. package/dist/stm32/utils/usb_utils.js +23 -0
  160. package/dist/stm32/utils/user_code.d.ts +14 -0
  161. package/dist/stm32/utils/user_code.js +43 -0
  162. package/dist/stm32/utils/utils_mutex.d.ts +15 -0
  163. package/dist/stm32/utils/utils_mutex.js +93 -0
  164. package/dist/stm32/validate.d.ts +16 -0
  165. package/dist/stm32/validate.js +46 -0
  166. package/mods/claude/.claude-plugin/marketplace.json +8 -0
  167. package/mods/claude/turingcode-skills/.claude-plugin/plugin.json +5 -0
  168. package/mods/claude/turingcode-skills/skills/turingcode-cli/SKILL.md +50 -0
  169. package/mods/claude/turingcode-skills/skills/turingcode-cli/references/board-and-debug.md +22 -0
  170. package/mods/claude/turingcode-skills/skills/turingcode-cli/references/build-and-check.md +19 -0
  171. package/mods/claude/turingcode-skills/skills/turingcode-cli/references/new-project.md +9 -0
  172. package/mods/claude/turingcode-skills/skills/turingcode-firmware-code/SKILL.md +43 -0
  173. package/mods/claude/turingcode-skills/skills/turingcode-firmware-code/references/concurrency.md +42 -0
  174. package/mods/claude/turingcode-skills/skills/turingcode-firmware-code/references/init-and-timing.md +35 -0
  175. package/mods/claude/turingcode-skills/skills/turingcode-firmware-code/references/input-and-bounds.md +34 -0
  176. package/mods/claude/turingcode-skills/skills/turingcode-firmware-code/references/registers-and-units.md +35 -0
  177. package/package.json +11 -3
@@ -0,0 +1,225 @@
1
+ // Safe CubeMX regeneration: CubeMX keeps only the code inside USER CODE sections, so before a regen this compares each
2
+ // file that has USER CODE markers with the version CubeMX generated last time (the baseline in .turingcode/generated/)
3
+ // and shows, as a diff, the code that regen would remove. Used by `turingcode project regen` and, as a library, by the
4
+ // VS Code extension.
5
+ import { copyFile, mkdir, readdir, readFile, rm, writeFile } from 'node:fs/promises';
6
+ import { dirname, join } from 'node:path';
7
+ import { scanUserSections } from './utils/user_code.js';
8
+ import { syncProjectFromServer, syncProjectToServer } from './sync.js';
9
+ import { formatPatch, structuredPatch } from 'diff';
10
+ import { extractZip } from './utils/downloadzip_utils.js';
11
+ import { listSyncFiles } from './utils/listSyncFiles.js';
12
+ const MARKER = /\/\*\s*USER CODE BEGIN/;
13
+ /**
14
+ * Builds a unified diff of two texts with jsdiff.
15
+ * @param a old text
16
+ * @param b new text
17
+ * @param nameA header label of a
18
+ * @param nameB header label of b
19
+ * @returns the diff without jsdiff's ==== line, or "" when the texts are equal
20
+ */
21
+ function unifiedDiff(a, b, nameA, nameB) {
22
+ const patch = structuredPatch(nameA, nameB, a, b, undefined, undefined, { context: 3 });
23
+ return patch.hunks.length ? formatPatch(patch).replace(/^=+\n/, '').trimEnd() : '';
24
+ }
25
+ /**
26
+ * Returns the folder holding the baseline: each generated file with its USER CODE section bodies emptied.
27
+ * @param root STM32 project root
28
+ * @returns the baseline folder
29
+ */
30
+ export function baselineDir(root) {
31
+ return join(root, '.turingcode', 'generated');
32
+ }
33
+ /**
34
+ * Replaces the body of every well-formed USER CODE section of a file.
35
+ * @param text file contents
36
+ * @param body gets the section name and current body, returns the new body
37
+ * @returns the new contents
38
+ */
39
+ export function mapUserSections(text, body) {
40
+ let out = '';
41
+ let at = 0;
42
+ for (const s of scanUserSections(text).sections) {
43
+ out += text.slice(at, s.start) + body(s.name, text.slice(s.start, s.end));
44
+ at = s.end;
45
+ }
46
+ return out + text.slice(at);
47
+ }
48
+ /**
49
+ * Reads the project's source files that have USER CODE markers (Drivers/ is skipped: CubeMX does not regenerate it).
50
+ * @param root STM32 project root
51
+ * @returns posix relative path -> contents with \n line endings
52
+ */
53
+ async function readMarkedFiles(root) {
54
+ const names = (await listSyncFiles(root)).filter((f) => /\.(c|h|cpp|hpp)$/.test(f) && !f.startsWith('Drivers/'));
55
+ const files = new Map();
56
+ for (const f of names) {
57
+ const text = (await readFile(join(root, f), 'utf8')).replace(/\r\n/g, '\n');
58
+ if (MARKER.test(text))
59
+ files.set(f, text);
60
+ }
61
+ return files;
62
+ }
63
+ /**
64
+ * Saves the baseline: every file with USER CODE markers, with its section bodies emptied, and the .ioc as it is (to
65
+ * tell later which side changed it). Call it right after CubeMX output reached the project (template, create, regen).
66
+ * shortcut: user-written files with markers are saved too, so later edits outside their sections are reported
67
+ * even though CubeMX leaves those files alone; skip files CubeMX does not generate if that gets noisy.
68
+ * @param root STM32 project root
69
+ * @returns the number of files with markers saved
70
+ */
71
+ export async function recordBaseline(root) {
72
+ const dir = baselineDir(root);
73
+ await rm(dir, { recursive: true, force: true });
74
+ await mkdir(dir, { recursive: true });
75
+ const files = await readMarkedFiles(root);
76
+ for (const [f, text] of files) {
77
+ await mkdir(dirname(join(dir, f)), { recursive: true });
78
+ await writeFile(join(dir, f), mapUserSections(text, () => ''));
79
+ }
80
+ for (const f of (await readdir(root)).filter((f) => f.endsWith('.ioc')))
81
+ await copyFile(join(root, f), join(dir, f));
82
+ return files.size;
83
+ }
84
+ /**
85
+ * Makes sure the regen uses the newest .ioc: the sync before it would otherwise overwrite an .ioc that a server
86
+ * tool (pins, clocks, set_params) changed. Takes the server's .ioc when only the server changed it since the baseline,
87
+ * keeps the local one (the sync sends it) when only it changed.
88
+ * @param call server tool caller
89
+ * @param project STM32 project root and name
90
+ * @returns a note per .ioc taken from the server
91
+ * @throws when both sides changed the .ioc, or it differs and there is no baseline to tell which side did
92
+ */
93
+ export async function takeServerIoc(call, project) {
94
+ const { root } = project;
95
+ const notes = [];
96
+ const tmp = join(root, '.turingcode', `ioc-${process.pid}`);
97
+ // A pull that is always cancelled: it only fetches the server's versions of the files that differ.
98
+ await syncProjectFromServer(call, project, async (files, zip) => {
99
+ const iocs = files.filter((f) => f.endsWith('.ioc'));
100
+ if (!iocs.length)
101
+ return false;
102
+ await extractZip(zip, tmp);
103
+ try {
104
+ for (const f of iocs) {
105
+ const mine = await readFile(join(root, f));
106
+ const theirs = await readFile(join(tmp, f));
107
+ const base = await readFile(join(baselineDir(root), f)).catch(() => undefined);
108
+ if (base?.equals(theirs))
109
+ continue;
110
+ if (!base?.equals(mine))
111
+ throw new Error(`${f} differs from the server's, and ${base ? 'both were changed since the last regen' : 'there is no baseline to tell which side changed it'}. ` +
112
+ 'Run `turingcode project pull` to take the server\'s version or `turingcode project sync` to keep yours, then regen.');
113
+ await writeFile(join(root, f), theirs);
114
+ notes.push(`Took the server's ${f}: it was changed there (e.g. by a pin or clock tool), not here.`);
115
+ }
116
+ }
117
+ finally {
118
+ await rm(tmp, { recursive: true, force: true });
119
+ }
120
+ return false;
121
+ });
122
+ return notes;
123
+ }
124
+ /**
125
+ * Finds the code a regen would remove from the local files, before running it: broken USER CODE markers, and code
126
+ * outside the sections that differs from the baseline.
127
+ * @param root STM32 project root
128
+ * @returns one diff or message per affected file (broken markers first), the broken-marker messages alone, the local
129
+ * marked files, and those without a baseline
130
+ */
131
+ export async function checkBeforeRegen(root) {
132
+ const local = await readMarkedFiles(root);
133
+ const findings = [];
134
+ const broken = [];
135
+ const unbaselined = new Set();
136
+ for (const [f, text] of local) {
137
+ const errors = scanUserSections(text).errors;
138
+ if (errors.length)
139
+ broken.push(`${f}: broken USER CODE markers, CubeMX may drop the code around them:\n${errors.join('\n')}`);
140
+ const base = await readFile(join(baselineDir(root), f), 'utf8').catch(() => undefined);
141
+ if (base === undefined) {
142
+ unbaselined.add(f);
143
+ continue;
144
+ }
145
+ const bodies = new Map(scanUserSections(text).sections.map((s) => [s.name, text.slice(s.start, s.end)]));
146
+ const expected = mapUserSections(base, (name, old) => bodies.get(name) ?? old);
147
+ const diff = unifiedDiff(text, expected, `${f} (yours)`, `${f} (as CubeMX generates it)`);
148
+ if (diff)
149
+ findings.push(diff);
150
+ }
151
+ return { findings: [...broken, ...findings], broken, local, unbaselined };
152
+ }
153
+ /**
154
+ * Finds the code a regen removed, comparing a local file with the regenerated one: USER CODE sections with code that
155
+ * no longer exist (e.g. a peripheral was removed), and, for files without a baseline, every change regen made.
156
+ * @param f posix relative path, for the headers
157
+ * @param local local contents
158
+ * @param regenerated contents after regen
159
+ * @param hasBaseline false: show the whole diff, since your code cannot be told apart from CubeMX's changes
160
+ * @returns the diff, or "" when nothing is removed
161
+ */
162
+ export function checkAfterRegen(f, local, regenerated, hasBaseline) {
163
+ regenerated = regenerated.replace(/\r\n/g, '\n');
164
+ if (!hasBaseline) {
165
+ const diff = unifiedDiff(local, regenerated, `${f} (yours)`, `${f} (after regen)`);
166
+ return diff && `${f} has no baseline, so this is every change regen makes, yours and CubeMX's:\n${diff}`;
167
+ }
168
+ const kept = new Set(scanUserSections(regenerated).sections.map((s) => s.name));
169
+ const gone = (name, body) => !kept.has(name) && body.trim() !== '';
170
+ const diff = unifiedDiff(local, mapUserSections(local, (n, b) => (gone(n, b) ? '' : b)), `${f} (yours)`, `${f} (after regen)`);
171
+ return diff && `${f}: regen removes these USER CODE sections:\n${diff}`;
172
+ }
173
+ /**
174
+ * Regenerates the project's code from its .ioc on the server and pulls the result, refusing to remove local code:
175
+ * checks the local files, takes the server's .ioc if only it changed, syncs the files up, regenerates, checks the
176
+ * regenerated files before overwriting local ones, pulls them and saves a new baseline.
177
+ * @param call server tool caller
178
+ * @param project STM32 project root and name
179
+ * @param force regenerate and pull even when code would be removed (the removed code is still shown)
180
+ * @returns the removed code (with force), then the sync, regen and pull summaries
181
+ * @throws with the code that would be removed when force is not set; nothing local changes then
182
+ */
183
+ export async function regenerateProject(call, project, force = false) {
184
+ const { root, name } = project;
185
+ const { findings, local, unbaselined } = await checkBeforeRegen(root);
186
+ const head = '# Code outside USER CODE sections that regen removes (- lines are yours)';
187
+ if (findings.length && !force)
188
+ throw new Error([head, ...findings, 'Regen stopped, nothing changed. Move this code into USER CODE sections, or run `turingcode project regen --force` to regenerate anyway.'].join('\n\n'));
189
+ const iocNotes = await takeServerIoc(call, project);
190
+ const synced = [...iocNotes, await syncProjectToServer(call, project)].join('\n');
191
+ const regen = await call('project_regenerate', { project_name: name }, 125_000);
192
+ // A failed regen comes back as plain text, not as a tool error; pulling then would save unregenerated files as the baseline.
193
+ if (!/^# Regenerated project /m.test(regen))
194
+ throw new Error(`${regen.trim()}\n\nRegen failed on the server; your local files and the baseline are unchanged. Run it again.`);
195
+ const removed = [];
196
+ const tmp = join(root, '.turingcode', `regen-${process.pid}`);
197
+ const pulled = await syncProjectFromServer(call, project, async (files, zip) => {
198
+ await extractZip(zip, tmp);
199
+ try {
200
+ for (const f of files.filter((x) => local.has(x))) {
201
+ const diff = checkAfterRegen(f, local.get(f), await readFile(join(tmp, f), 'utf8'), !unbaselined.has(f));
202
+ if (diff)
203
+ removed.push(diff);
204
+ }
205
+ }
206
+ finally {
207
+ await rm(tmp, { recursive: true, force: true });
208
+ }
209
+ return force || !removed.length;
210
+ });
211
+ if (removed.length && !force)
212
+ throw new Error([
213
+ '# Code that regen removes (- lines are yours)',
214
+ ...removed,
215
+ 'Regen ran on the server, but your local files are unchanged. `turingcode project sync` puts your version back on the server; `turingcode project regen --force` regenerates and pulls anyway.',
216
+ ].join('\n\n'));
217
+ const saved = await recordBaseline(root);
218
+ const warning = [...findings, ...removed];
219
+ return [
220
+ ...(warning.length ? [`# Code that regen removed (- lines are yours)\n\nRegenerated anyway (--force); this code is gone from the local files.`, ...warning] : []),
221
+ `# Sync\n${synced}`,
222
+ `# Regen\n${regen.trim()}`,
223
+ `# Pull\n${pulled}\nSaved the generated code of ${saved} files as the baseline in .turingcode/generated/.`,
224
+ ].join('\n\n');
225
+ }
@@ -0,0 +1,134 @@
1
+ import { ChildProcess } from 'node:child_process';
2
+ export interface Breakpoint {
3
+ line: number;
4
+ condition?: string;
5
+ }
6
+ export interface StartOptions {
7
+ root: string;
8
+ chip: string;
9
+ elf: string;
10
+ flash: boolean;
11
+ }
12
+ export declare class DebugSession {
13
+ readonly opts: StartOptions;
14
+ private proc;
15
+ readonly breakpoints: Map<string, Breakpoint[]>;
16
+ capabilities: any;
17
+ state: 'running' | 'halted';
18
+ stopReason: string;
19
+ threadId: number;
20
+ private seq;
21
+ private buf;
22
+ private pending;
23
+ private waiters;
24
+ private log;
25
+ private elfData?;
26
+ constructor(opts: StartOptions, proc: ChildProcess);
27
+ /**
28
+ * Sends a DAP request and waits for its response.
29
+ * @param command DAP command (e.g. stackTrace)
30
+ * @param args request arguments
31
+ * @param timeout milliseconds before the request fails
32
+ * @returns the response body
33
+ */
34
+ request(command: string, args?: object, timeout?: number): Promise<any>;
35
+ /**
36
+ * Waits for a DAP event.
37
+ * @param name event name (e.g. stopped)
38
+ * @param timeout milliseconds to wait
39
+ * @returns the event body, or undefined on timeout or when the session ends
40
+ */
41
+ waitEvent(name: string, timeout: number): Promise<any | undefined>;
42
+ /**
43
+ * Throws unless the target is halted.
44
+ */
45
+ requireHalted(): void;
46
+ /**
47
+ * Converts a project-relative file to the path the ELF's debug info uses. The firmware is built on the
48
+ * TuringCode server, so the ELF holds the server's folder; its prefix is found from the path strings in the ELF.
49
+ * @param rel project-relative path with forward slashes
50
+ * @returns the path to send in setBreakpoints
51
+ */
52
+ sourcePath(rel: string): Promise<string>;
53
+ /**
54
+ * Converts a path from the debug info to a project-relative one, by finding the longest tail of it that exists in the project.
55
+ * @param path source path from a stack frame
56
+ * @returns the project-relative path, or the path itself when no tail exists locally
57
+ */
58
+ projectPath(path: string | undefined): string;
59
+ /**
60
+ * Describes where the halted target is: function, file and line of the innermost frame.
61
+ * @returns e.g. "Halted (breakpoint) in main at Core/Src/main.c:42"
62
+ */
63
+ location(): Promise<string>;
64
+ /**
65
+ * Ends the session: disconnects (the target keeps running) and stops probe-rs.
66
+ */
67
+ stop(): Promise<void>;
68
+ /**
69
+ * Returns the last lines of probe-rs output, for error messages.
70
+ * @returns the output prefixed with a newline, or an empty string
71
+ */
72
+ logTail(): string;
73
+ /**
74
+ * Keeps the last probe-rs output lines.
75
+ * @param text output text
76
+ */
77
+ private addLog;
78
+ /**
79
+ * Splits the stdout stream into DAP messages (Content-Length framed JSON).
80
+ * @param chunk data read from probe-rs stdout
81
+ */
82
+ private onData;
83
+ /**
84
+ * Handles one DAP message: resolves its request, or tracks the target state from events.
85
+ * @param msg response or event
86
+ */
87
+ private onMessage;
88
+ /**
89
+ * Fails every open request and frees the probe once probe-rs is gone.
90
+ * @param reason message for the open requests
91
+ */
92
+ private onExit;
93
+ }
94
+ /**
95
+ * Tells whether a probe-rs debug session holds the probe.
96
+ * @returns true while a session is running
97
+ */
98
+ export declare function debugSessionActive(): boolean;
99
+ /**
100
+ * Returns the running debug session.
101
+ * @returns the session
102
+ */
103
+ export declare function getSession(): DebugSession;
104
+ /**
105
+ * Starts `probe-rs dap-server`, then attaches to the target (or flashes it and halts after reset).
106
+ * @param opts chip, ELF and project of the session
107
+ * @returns the started session
108
+ */
109
+ export declare function startSession(opts: StartOptions): Promise<DebugSession>;
110
+ /**
111
+ * Stops the debug session if one is running.
112
+ */
113
+ export declare function stopSession(): Promise<void>;
114
+ /**
115
+ * Resolves a project-relative path the agent passed and checks it stays inside the project.
116
+ * @param root project root
117
+ * @param file project-relative path
118
+ * @returns the path relative to the root, with forward slashes
119
+ */
120
+ export declare function projectFile(root: string, file: string): string;
121
+ /**
122
+ * Sends the breakpoints of one file to probe-rs (DAP replaces the whole list of a file on each call).
123
+ * @param s debug session
124
+ * @param rel project-relative file
125
+ * @returns the breakpoints as probe-rs placed them
126
+ */
127
+ export declare function syncBreakpoints(s: DebugSession, rel: string): Promise<any[]>;
128
+ /**
129
+ * Returns the DAP id of a stack frame of the halted target.
130
+ * @param s debug session
131
+ * @param frame frame index, 0 = innermost
132
+ * @returns the frame id
133
+ */
134
+ export declare function frameId(s: DebugSession, frame: number): Promise<number>;