bambu-printer-mcp 1.1.44 → 1.1.46

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/CONTRIBUTORS.md CHANGED
@@ -6,6 +6,7 @@ Thank you to everyone who builds, tests, reports problems, and shares real print
6
6
 
7
7
  | Contributor | Contribution |
8
8
  | --- | --- |
9
+ | [billh-hub](https://github.com/billh-hub) | Reports and isolates three official H2C time-lapse and filament-change command rejections in [#84](https://github.com/DMontgomery40/bambu-printer-mcp/issues/84), supplies emitted commands and multi-colour reproduction evidence, and distinguishes the unknown cooling parameter for source-backed investigation. The correction preserves independent safety checks; no maintainer physical printing is claimed. |
9
10
  | [Steve Pritchard (sjpritchard)](https://github.com/sjpritchard) | Reports and diagnoses H2C per-variant first-layer temperature rejection in [#81](https://github.com/DMontgomery40/bambu-printer-mcp/issues/81), supplies the exact official preset metadata and reproduction, and identifies the upstream variant-mapping contract. Verification uses synthetic slicing and offline regressions, not physical printing. |
10
11
  | [JackCA](https://github.com/JackCA) | Reports an X2D retaining `FAILED` with no active print/HMS error after cancellation, supplies read-only printer evidence for `fail_reason: 0300400C`, and contributes narrow canceled-task recovery, job-bound physical confirmation, a recheck of the job and error codes after connecting and before clearing hardware errors on any model, and regression coverage in [#76](https://github.com/DMontgomery40/bambu-printer-mcp/pull/76). Physical print delivery after the fix remains unverified. |
11
12
  | [ZombieLurker](https://github.com/ZombieLurker) | Reports and diagnoses the unused-nozzle preheat rejection for OrcaSlicer 2.4.2 single-filament H2D jobs in [#73](https://github.com/DMontgomery40/bambu-printer-mcp/issues/73), supplies the exact startup commands and environment, and verifies a local inspection fix. H2D Pro coverage is independently supported by its official profile; no physical printing is claimed by this release. |
@@ -26,7 +26,6 @@ interface BambuPrintOptionsInternal {
26
26
  amsSlots?: number[];
27
27
  md5?: string;
28
28
  }
29
- /** What the human confirmed in confirmPrintPreflight, checked again before dispatch. */
30
29
  export type PrintPreflight = {
31
30
  finishedJob?: string;
32
31
  serial: string;
@@ -1,5 +1,5 @@
1
1
  import { createHash } from "node:crypto";
2
- import { isCancelledX2DJob, readFreshPrinterStatus } from "../safety/printer-state.js";
2
+ import { isFinishedP1SJob, isCancelledX2DJob, readFreshPrinterStatus } from "../safety/printer-state.js";
3
3
  import fs from "node:fs/promises";
4
4
  import { readFileSync, existsSync } from "node:fs";
5
5
  import path from "node:path";
@@ -386,6 +386,10 @@ class BambuClientStore {
386
386
  this.initialReportResolvers.clear();
387
387
  }
388
388
  }
389
+ /** What the human confirmed in confirmPrintPreflight, checked again before dispatch. */
390
+ function printJobIdentity(raw) {
391
+ return JSON.stringify([raw.gcode_file, raw.subtask_name, raw.task_id, raw.subtask_id, raw.job_id]);
392
+ }
389
393
  /**
390
394
  * Split the A1/P1 camera stream on port 6000 into JPEG frames. Each frame is
391
395
  * a 16-byte header (payload size LE, itrack, flags, reserved) and the JPEG.
@@ -439,8 +443,8 @@ export class BambuImplementation {
439
443
  }
440
444
  finishedJobIdentity(status) {
441
445
  const raw = status.raw;
442
- return raw.gcode_state === "FINISH" || isCancelledX2DJob(raw, String(status.model ?? ""))
443
- ? JSON.stringify([raw.gcode_state, raw.gcode_file, raw.subtask_name, raw.task_id, raw.subtask_id, raw.job_id])
446
+ return raw.gcode_state === "FINISH" || (isCancelledX2DJob(raw, String(status.model ?? "")) || isFinishedP1SJob(raw, String(status.model ?? "")))
447
+ ? printJobIdentity(raw)
444
448
  : undefined;
445
449
  }
446
450
  /**
@@ -457,7 +461,9 @@ export class BambuImplementation {
457
461
  `Materials: ${inspection.materials.join(", ")}. Peak targets: nozzle ${inspection.maxNozzleTemperature}°C, bed ${inspection.maxBedTemperature}°C, chamber ${inspection.maxChamberTemperature}°C. ` +
458
462
  `File SHA-256: ${inspection.sha256}. Confirm the physical spool labels and that the build plate is clear.` +
459
463
  (finishedJob !== undefined ? (status.raw.gcode_state === "FAILED"
460
- ? " The previous X2D task was canceled (0300400C): remove every detached part, support and strand from the plate and nozzle before confirming. FAILED is the previous job's terminal state; no error-reset command is sent."
464
+ ? (isFinishedP1SJob(status.raw, inspection.model)
465
+ ? " The previous P1S job ended in FAILED and the printer now reports idle with no print or HMS errors. Remove the previous part and every detached part, support and strand from the plate and nozzle before confirming. No error-reset command is sent."
466
+ : " The previous X2D task was canceled (0300400C): remove every detached part, support and strand from the plate and nozzle before confirming. FAILED is the previous job's terminal state; no error-reset command is sent.")
461
467
  : " The printer reports FINISH: remove the previous part and debris before confirming.") : "") +
462
468
  (cleared ? ` Previously cleared hardware codes: ${cleared.map(describeHmsKey).join(", ")}. Confirm their physical causes have been resolved.` : "") +
463
469
  (notices.length ? ` The printer also reports ${notices.join(", ")}, which Bambu lists for this model without text and never shows as a fault; ` +
@@ -469,7 +475,8 @@ export class BambuImplementation {
469
475
  /** Stop a print whose confirmed situation changed: a newly finished job, or a hidden HMS notice the preflight did not name. */
470
476
  assertBedClearance(status, preflight) {
471
477
  const current = this.finishedJobIdentity(status);
472
- if (current !== undefined && current !== preflight.finishedJob) {
478
+ if ((preflight.finishedJob !== undefined && printJobIdentity(status.raw) !== preflight.finishedJob)
479
+ || (current !== undefined && preflight.finishedJob === undefined)) {
473
480
  throw new Error("Printer reports a newly finished job. Confirm that its part and debris have been removed before retrying the print.");
474
481
  }
475
482
  // An X2D raises its hidden camera notice about 15 seconds after boot, so it
@@ -482,12 +482,12 @@ export async function inspectPrintFile(filePath, options) {
482
482
  const argumentsText = line.slice(command[0].length).trim();
483
483
  commandCount++;
484
484
  if (code === 'M9711') {
485
- // Official X2D and H2D time-lapse capture (Bambu Studio and OrcaSlicer
485
+ // Official X2D, H2D and H2C time-lapse capture (Bambu Studio and OrcaSlicer
486
486
  // templates), emitted on every layer: M is the time-lapse mode and E the
487
487
  // physical extruder, not a second command; T is a duration, not a heater.
488
488
  // It sets no temperature. Positions stay inside the machine volume.
489
489
  const invalid = () => fail('unsupported M9711 time-lapse parameters');
490
- if (!['x2d', 'h2d'].includes(model))
490
+ if (!['x2d', 'h2d', 'h2c'].includes(model))
491
491
  invalid();
492
492
  let args;
493
493
  try {
@@ -500,7 +500,7 @@ export async function inspectPrintFile(filePath, options) {
500
500
  const position = ['X', 'Y', 'U', 'V'].filter(key => args.has(key)).join('');
501
501
  const limit = { X: width, U: width, Y: depth, V: depth };
502
502
  if ([...args.keys()].some(key => !'MEXYUVZSCOT'.includes(key)) ||
503
- // X2D and H2D have two physical extruders, whatever the file declares.
503
+ // These models have two physical extruders, whatever the file declares.
504
504
  ![0, 1].includes(args.get('M')) || !Number.isInteger(args.get('E')) || !inRange(args, 'E', 0, Math.min(nozzleDiameters.length, 2) - 1) ||
505
505
  args.get('S') !== 11 || args.get('C') !== 10 || args.get('O') !== 0 || !inRange(args, 'T', 0, 600000) ||
506
506
  !inRange(args, 'Z', 0, height) ||
@@ -643,9 +643,10 @@ export async function inspectPrintFile(filePath, options) {
643
643
  }
644
644
  else if (code === 'M620.14') {
645
645
  const args = parameters(argumentsText);
646
- // H2C tower coordinates include the rear wipe area outside object bounds.
647
- if (!h2cStartup(index) || args.size !== 2 || !['X', 'Y'].every(key => args.has(key) && Number.isFinite(args.get(key)) && args.get(key) >= 0 && args.get(key) <= 350))
648
- fail('unsupported H2C startup tower parameters');
646
+ // H2C uses these coordinates during startup and a selected filament change.
647
+ // The rear wipe area extends outside object bounds (official fallback Y336).
648
+ if (!(h2cStartup(index) || (model === 'h2c' && pending !== undefined)) || args.size !== 2 || !['X', 'Y'].every(key => args.has(key) && Number.isFinite(args.get(key)) && args.get(key) >= 0 && args.get(key) <= 350))
649
+ fail('unsupported H2C tower parameters');
649
650
  }
650
651
  else if (model === 'h2c' && ['G383', 'G383.3', 'G383.7'].includes(code) && /U/i.test(argumentsText)) {
651
652
  const args = parameters(argumentsText);
@@ -687,9 +688,12 @@ export async function inspectPrintFile(filePath, options) {
687
688
  // H2D change_filament_gcode supplies the incoming filament's cooling
688
689
  // temperature as C{new_filament_temp - filament_cooling_before_tower}.
689
690
  const args = parameters(argumentsText);
690
- if (args.size !== 1 || !args.has('C'))
691
+ // H2C also supplies P{filament_pre_cooling_temperature_nc[next_filament_id]}
692
+ // before switching hotends. P and C both constrain the incoming material.
693
+ const target = model === 'h2c' && args.has('P') ? 'P' : 'C';
694
+ if (args.size !== 1 || !args.has(target))
691
695
  fail('unsupported M620.15 cooling temperature parameters');
692
- heat('nozzle', args.get('C'), pending ?? active);
696
+ heat('nozzle', args.get(target), pending ?? active);
693
697
  }
694
698
  else if (code === 'M620.17') {
695
699
  const args = parameters(argumentsText);
@@ -49,6 +49,10 @@ export interface ValidatedPrinterState {
49
49
  * and print dispatch must obtain job-bound physical bed-clearance confirmation.
50
50
  */
51
51
  export declare function isCancelledX2DJob(raw: Record<string, any>, model: string): boolean;
52
+ /** Bambu Studio 2.8.2.61 marks FAILED as finished. Limit P1S recovery to
53
+ * a named prior job explicitly reporting idle, no print error and no HMS.
54
+ * Its bed still needs job-bound human clearance before every print. */
55
+ export declare function isFinishedP1SJob(raw: Record<string, any>, model: string): boolean;
52
56
  /** Nozzles whose reported diameter and type are configured settings rather than chip readings. */
53
57
  export declare function unchippedNozzles(raw: unknown): number[];
54
58
  /** The one key format for a reported entry, shared by the gate and clear_hms_errors. */
@@ -130,6 +130,14 @@ export function isCancelledX2DJob(raw, model) {
130
130
  finiteNumber(raw.print_error) === 0 && finiteNumber(raw.fail_reason) === 0x0300400c &&
131
131
  [raw.gcode_file, raw.subtask_name].some(value => typeof value === "string" && value.trim().length > 0);
132
132
  }
133
+ /** Bambu Studio 2.8.2.61 marks FAILED as finished. Limit P1S recovery to
134
+ * a named prior job explicitly reporting idle, no print error and no HMS.
135
+ * Its bed still needs job-bound human clearance before every print. */
136
+ export function isFinishedP1SJob(raw, model) {
137
+ return normalizeModel(model) === "p1s" && raw.gcode_state === "FAILED" && raw.print_type === "idle" &&
138
+ finiteNumber(raw.print_error) === 0 && Array.isArray(raw.hms) && raw.hms.length === 0 &&
139
+ [raw.gcode_file, raw.subtask_name].some(value => typeof value === "string" && value.trim().length > 0);
140
+ }
133
141
  const token = (value) => typeof value === "string" ? value.trim().toLowerCase().replace(/[\s_-]/g, "") : "";
134
142
  function nozzleTypeAndFlow(value) {
135
143
  const text = String(value ?? "");
@@ -310,10 +318,10 @@ function logHiddenNotices(raw, serial, model) {
310
318
  }
311
319
  function validateErrors(raw, requireIdle, serial, model) {
312
320
  const state = typeof raw.gcode_state === "string" ? raw.gcode_state.toUpperCase() : "UNKNOWN";
313
- const cancelled = isCancelledX2DJob(raw, model);
314
- if (requireIdle && !["IDLE", "FINISH"].includes(state) && !cancelled)
321
+ const terminal = isCancelledX2DJob(raw, model) || isFinishedP1SJob(raw, model);
322
+ if (requireIdle && !["IDLE", "FINISH"].includes(state) && !terminal)
315
323
  throw new Error(`Printer state ${state} is not safely idle.`);
316
- if (!requireIdle && !["IDLE", "FINISH", "RUNNING", "PAUSE"].includes(state) && !cancelled)
324
+ if (!requireIdle && !["IDLE", "FINISH", "RUNNING", "PAUSE"].includes(state) && !terminal)
317
325
  throw new Error(`Printer state ${state} is unknown or failed.`);
318
326
  if (finiteNumber(raw.print_error) !== 0)
319
327
  throw new Error("Printer reports a print error or did not report its error state.");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bambu-printer-mcp",
3
- "version": "1.1.44",
3
+ "version": "1.1.46",
4
4
  "description": "MCP server for Bambu Lab 3D printers with STL manipulation, slicing, and print management",
5
5
  "main": "dist/index.js",
6
6
  "repository": {
@@ -1,5 +1,5 @@
1
1
  import { createHash } from "node:crypto";
2
- import { isCancelledX2DJob, readFreshPrinterStatus } from "../safety/printer-state.js";
2
+ import { isFinishedP1SJob, isCancelledX2DJob, readFreshPrinterStatus } from "../safety/printer-state.js";
3
3
  import fs from "node:fs/promises";
4
4
  import { readFileSync, existsSync } from "node:fs";
5
5
  import path from "node:path";
@@ -472,6 +472,10 @@ class BambuClientStore {
472
472
  }
473
473
 
474
474
  /** What the human confirmed in confirmPrintPreflight, checked again before dispatch. */
475
+ function printJobIdentity(raw: Record<string, any>): string {
476
+ return JSON.stringify([raw.gcode_file, raw.subtask_name, raw.task_id, raw.subtask_id, raw.job_id]);
477
+ }
478
+
475
479
  export type PrintPreflight = { finishedJob?: string; serial: string; model: string; notices: string[] };
476
480
 
477
481
  /**
@@ -528,8 +532,8 @@ export class BambuImplementation {
528
532
 
529
533
  private finishedJobIdentity(status: any): string | undefined {
530
534
  const raw = status.raw;
531
- return raw.gcode_state === "FINISH" || isCancelledX2DJob(raw, String(status.model ?? ""))
532
- ? JSON.stringify([raw.gcode_state, raw.gcode_file, raw.subtask_name, raw.task_id, raw.subtask_id, raw.job_id])
535
+ return raw.gcode_state === "FINISH" || (isCancelledX2DJob(raw, String(status.model ?? "")) || isFinishedP1SJob(raw, String(status.model ?? "")))
536
+ ? printJobIdentity(raw)
533
537
  : undefined;
534
538
  }
535
539
 
@@ -548,7 +552,9 @@ export class BambuImplementation {
548
552
  `Materials: ${inspection.materials.join(", ")}. Peak targets: nozzle ${inspection.maxNozzleTemperature}°C, bed ${inspection.maxBedTemperature}°C, chamber ${inspection.maxChamberTemperature}°C. ` +
549
553
  `File SHA-256: ${inspection.sha256}. Confirm the physical spool labels and that the build plate is clear.` +
550
554
  (finishedJob !== undefined ? (status.raw.gcode_state === "FAILED"
551
- ? " The previous X2D task was canceled (0300400C): remove every detached part, support and strand from the plate and nozzle before confirming. FAILED is the previous job's terminal state; no error-reset command is sent."
555
+ ? (isFinishedP1SJob(status.raw, inspection.model)
556
+ ? " The previous P1S job ended in FAILED and the printer now reports idle with no print or HMS errors. Remove the previous part and every detached part, support and strand from the plate and nozzle before confirming. No error-reset command is sent."
557
+ : " The previous X2D task was canceled (0300400C): remove every detached part, support and strand from the plate and nozzle before confirming. FAILED is the previous job's terminal state; no error-reset command is sent.")
552
558
  : " The printer reports FINISH: remove the previous part and debris before confirming.") : "") +
553
559
  (cleared ? ` Previously cleared hardware codes: ${cleared.map(describeHmsKey).join(", ")}. Confirm their physical causes have been resolved.` : "") +
554
560
  (notices.length ? ` The printer also reports ${notices.join(", ")}, which Bambu lists for this model without text and never shows as a fault; ` +
@@ -563,7 +569,8 @@ export class BambuImplementation {
563
569
  /** Stop a print whose confirmed situation changed: a newly finished job, or a hidden HMS notice the preflight did not name. */
564
570
  assertBedClearance(status: any, preflight: PrintPreflight): void {
565
571
  const current = this.finishedJobIdentity(status);
566
- if (current !== undefined && current !== preflight.finishedJob) {
572
+ if ((preflight.finishedJob !== undefined && printJobIdentity(status.raw) !== preflight.finishedJob)
573
+ || (current !== undefined && preflight.finishedJob === undefined)) {
567
574
  throw new Error("Printer reports a newly finished job. Confirm that its part and debris have been removed before retrying the print.");
568
575
  }
569
576
  // An X2D raises its hidden camera notice about 15 seconds after boot, so it
@@ -374,19 +374,19 @@ export async function inspectPrintFile(filePath: string, options: {model:string;
374
374
  const [base,subcode]=command![2].split('.');
375
375
  const code=command![1].toUpperCase()+String(Number(base))+(subcode===undefined?'':'.'+subcode);const argumentsText=line.slice(command![0].length).trim();commandCount++;
376
376
  if(code==='M9711') {
377
- // Official X2D and H2D time-lapse capture (Bambu Studio and OrcaSlicer
377
+ // Official X2D, H2D and H2C time-lapse capture (Bambu Studio and OrcaSlicer
378
378
  // templates), emitted on every layer: M is the time-lapse mode and E the
379
379
  // physical extruder, not a second command; T is a duration, not a heater.
380
380
  // It sets no temperature. Positions stay inside the machine volume.
381
381
  const invalid=()=>fail('unsupported M9711 time-lapse parameters');
382
- if(!['x2d','h2d'].includes(model)) invalid();
382
+ if(!['x2d','h2d','h2c'].includes(model)) invalid();
383
383
  let args:Map<string,number>;
384
384
  try {args=parameters(argumentsText);} catch {return invalid();}
385
385
  const [width,depth,height]=MACHINE_LIMITS[model].volume;
386
386
  const position=['X','Y','U','V'].filter(key=>args.has(key)).join('');
387
387
  const limit:Record<string,number>={X:width,U:width,Y:depth,V:depth};
388
388
  if([...args.keys()].some(key=>!'MEXYUVZSCOT'.includes(key)) ||
389
- // X2D and H2D have two physical extruders, whatever the file declares.
389
+ // These models have two physical extruders, whatever the file declares.
390
390
  ![0,1].includes(args.get('M')!) || !Number.isInteger(args.get('E')) || !inRange(args,'E',0,Math.min(nozzleDiameters.length,2)-1) ||
391
391
  args.get('S')!==11 || args.get('C')!==10 || args.get('O')!==0 || !inRange(args,'T',0,600000) ||
392
392
  !inRange(args,'Z',0,height) ||
@@ -476,8 +476,9 @@ export async function inspectPrintFile(filePath: string, options: {model:string;
476
476
  fail(`unsupported thermal-affecting wipe command ${code}`);
477
477
  } else if(code==='M620.14') {
478
478
  const args=parameters(argumentsText);
479
- // H2C tower coordinates include the rear wipe area outside object bounds.
480
- if(!h2cStartup(index) || args.size!==2 || !['X','Y'].every(key=>args.has(key) && Number.isFinite(args.get(key)) && args.get(key)!>=0 && args.get(key)!<=350)) fail('unsupported H2C startup tower parameters');
479
+ // H2C uses these coordinates during startup and a selected filament change.
480
+ // The rear wipe area extends outside object bounds (official fallback Y336).
481
+ if(!(h2cStartup(index) || (model==='h2c' && pending!==undefined)) || args.size!==2 || !['X','Y'].every(key=>args.has(key) && Number.isFinite(args.get(key)) && args.get(key)!>=0 && args.get(key)!<=350)) fail('unsupported H2C tower parameters');
481
482
  } else if(model==='h2c' && ['G383','G383.3','G383.7'].includes(code) && /U/i.test(argumentsText)) {
482
483
  const args=parameters(argumentsText);
483
484
  const expected=code==='G383.7'?'UJ':code==='G383.3'?'UL':'OUL';
@@ -508,8 +509,11 @@ export async function inspectPrintFile(filePath: string, options: {model:string;
508
509
  // H2D change_filament_gcode supplies the incoming filament's cooling
509
510
  // temperature as C{new_filament_temp - filament_cooling_before_tower}.
510
511
  const args=parameters(argumentsText);
511
- if(args.size!==1 || !args.has('C')) fail('unsupported M620.15 cooling temperature parameters');
512
- heat('nozzle',args.get('C')!,pending ?? active);
512
+ // H2C also supplies P{filament_pre_cooling_temperature_nc[next_filament_id]}
513
+ // before switching hotends. P and C both constrain the incoming material.
514
+ const target=model==='h2c' && args.has('P')?'P':'C';
515
+ if(args.size!==1 || !args.has(target)) fail('unsupported M620.15 cooling temperature parameters');
516
+ heat('nozzle',args.get(target)!,pending ?? active);
513
517
  } else if(code==='M620.17') {
514
518
  const args=parameters(argumentsText);
515
519
  if(!args.has('S') || !args.has('L') || !args.has('T') || !Number.isInteger(args.get('T')) || args.get('T')!<0 || args.get('T')!>=nozzleDiameters.length) fail('unsupported M620.17 nozzle/material temperature mapping');
@@ -141,6 +141,14 @@ export function isCancelledX2DJob(raw: Record<string, any>, model: string): bool
141
141
  finiteNumber(raw.print_error) === 0 && finiteNumber(raw.fail_reason) === 0x0300400c &&
142
142
  [raw.gcode_file, raw.subtask_name].some(value => typeof value === "string" && value.trim().length > 0);
143
143
  }
144
+ /** Bambu Studio 2.8.2.61 marks FAILED as finished. Limit P1S recovery to
145
+ * a named prior job explicitly reporting idle, no print error and no HMS.
146
+ * Its bed still needs job-bound human clearance before every print. */
147
+ export function isFinishedP1SJob(raw: Record<string, any>, model: string): boolean {
148
+ return normalizeModel(model) === "p1s" && raw.gcode_state === "FAILED" && raw.print_type === "idle" &&
149
+ finiteNumber(raw.print_error) === 0 && Array.isArray(raw.hms) && raw.hms.length === 0 &&
150
+ [raw.gcode_file, raw.subtask_name].some(value => typeof value === "string" && value.trim().length > 0);
151
+ }
144
152
  const token = (value: unknown) => typeof value === "string" ? value.trim().toLowerCase().replace(/[\s_-]/g, "") : "";
145
153
  function nozzleTypeAndFlow(value: unknown): {type?: string; flow?: string} {
146
154
  const text = String(value ?? "");
@@ -319,9 +327,9 @@ function logHiddenNotices(raw: Record<string, any>, serial: string, model: strin
319
327
 
320
328
  function validateErrors(raw: Record<string,any>, requireIdle: boolean, serial: string, model: string) {
321
329
  const state = typeof raw.gcode_state === "string" ? raw.gcode_state.toUpperCase() : "UNKNOWN";
322
- const cancelled = isCancelledX2DJob(raw, model);
323
- if (requireIdle && !["IDLE","FINISH"].includes(state) && !cancelled) throw new Error(`Printer state ${state} is not safely idle.`);
324
- if (!requireIdle && !["IDLE","FINISH","RUNNING","PAUSE"].includes(state) && !cancelled) throw new Error(`Printer state ${state} is unknown or failed.`);
330
+ const terminal = isCancelledX2DJob(raw, model) || isFinishedP1SJob(raw, model);
331
+ if (requireIdle && !["IDLE","FINISH"].includes(state) && !terminal) throw new Error(`Printer state ${state} is not safely idle.`);
332
+ if (!requireIdle && !["IDLE","FINISH","RUNNING","PAUSE"].includes(state) && !terminal) throw new Error(`Printer state ${state} is unknown or failed.`);
325
333
  if (finiteNumber(raw.print_error) !== 0) throw new Error("Printer reports a print error or did not report its error state.");
326
334
  if (!Array.isArray(raw.hms)) throw new Error("Printer HMS error state is missing or malformed.");
327
335
  for (const reported of raw.hms) {