Show line-by-line live G-code execution trace

This commit is contained in:
2026-08-29 07:51:44 +08:00
parent 43670525d6
commit 55627010c3
7 changed files with 63 additions and 33 deletions

View File

@@ -180,6 +180,7 @@ export class SimSession {
status: statePayload.status,
cycles: statePayload.cycles,
motion_trace: trace,
execution_trace: Array.isArray(statePayload.execution_trace) ? statePayload.execution_trace : [],
motion_sample: motionSample,
snapshot_mode: "motion_delta",
motion_authority: statePayload.motion_authority ?? this.motionAuthority,
@@ -1534,6 +1535,13 @@ export class SimSession {
return finish(this.error(input, "scheduler", String(error?.message ?? error)), "failed");
}
const program = this.xyzacProgram ? this.xyzacProgram.snapshot() : this.program.loaded ? this.program.snapshot() : null;
const execution_trace = program_steps
.map((step) => ({
line: step.line ?? step.program?.execution_line ?? null,
text: step.program?.execution_line_text ?? "",
program_status: step.program_status ?? step.program?.program_status ?? null,
}))
.filter((entry) => Number.isSafeInteger(entry.line) && entry.line > 0);
if (program) {
const status = this.xyzacProgram ? (program.status === 4 ? "completed" : program.status === 2 ? "running" : program.status === 3 ? "paused" : "loaded") : (program.program_status === "completed" ? "completed" : program.program_status === "running" ? "running" : program.program_status);
this.task.setProgram(status, this.xyzacProgram ? program.current_line : program.line);
@@ -1544,7 +1552,7 @@ export class SimSession {
const snapshot = this.timeline.checkpoint(input.seq, this.tick, snapshotState, this.timeline.snapshots.latest()?.snapshot_id ?? null);
const lightweightXyzac = Boolean(this.xyzacProgram);
return finish(this.envelope("COMMAND_RESULT", input, {
status: "verified", cycles, program_steps,
status: "verified", cycles, program_steps, execution_trace,
...(lightweightXyzac && cycles <= 32 && motion_trace.length ? { motion_trace } : {}),
motion_authority: this.motionAuthority,
task: this.task.export(), scheduler: this.scheduler.export(), authoritative: snapshotState.authoritative,