bambu-printer-mcp 1.1.90 → 1.1.91

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 (42) hide show
  1. package/README.md +43 -0
  2. package/dist/counterpart/flight-record.d.ts +155 -0
  3. package/dist/counterpart/flight-record.js +831 -0
  4. package/dist/counterpart/flight-tools.d.ts +213 -0
  5. package/dist/counterpart/flight-tools.js +232 -0
  6. package/dist/counterpart/fresh-frame.d.ts +16 -0
  7. package/dist/counterpart/fresh-frame.js +26 -0
  8. package/dist/counterpart/make-3mf.js +1 -4
  9. package/dist/counterpart/physical-evidence.d.ts +70 -0
  10. package/dist/counterpart/physical-evidence.js +103 -0
  11. package/dist/counterpart/print-geometry.d.ts +13 -0
  12. package/dist/counterpart/print-geometry.js +181 -0
  13. package/dist/counterpart/remote.js +2 -0
  14. package/dist/counterpart/schemas.d.ts +32 -0
  15. package/dist/counterpart/schemas.js +2 -0
  16. package/dist/counterpart/visual-evidence.d.ts +38 -0
  17. package/dist/counterpart/visual-evidence.js +155 -0
  18. package/dist/index.js +24 -1
  19. package/dist/printers/bambu.d.ts +9 -2
  20. package/dist/printers/bambu.js +32 -6
  21. package/dist/safety/print-preview.d.ts +2 -0
  22. package/dist/safety/print-preview.js +1 -1
  23. package/dist/slicer/3mf-xml.d.ts +7 -0
  24. package/dist/slicer/3mf-xml.js +61 -0
  25. package/dist/stl/stl-manipulator.js +5 -2
  26. package/dist/tool-annotations.js +2 -0
  27. package/package.json +2 -1
  28. package/src/counterpart/flight-record.ts +984 -0
  29. package/src/counterpart/flight-tools.ts +282 -0
  30. package/src/counterpart/fresh-frame.ts +45 -0
  31. package/src/counterpart/make-3mf.ts +1 -5
  32. package/src/counterpart/physical-evidence.ts +185 -0
  33. package/src/counterpart/print-geometry.ts +192 -0
  34. package/src/counterpart/remote.ts +2 -0
  35. package/src/counterpart/schemas.ts +3 -0
  36. package/src/counterpart/visual-evidence.ts +212 -0
  37. package/src/index.ts +25 -2
  38. package/src/printers/bambu.ts +34 -5
  39. package/src/safety/print-preview.ts +1 -1
  40. package/src/slicer/3mf-xml.ts +52 -0
  41. package/src/stl/stl-manipulator.ts +4 -1
  42. package/src/tool-annotations.ts +2 -0
@@ -0,0 +1,13 @@
1
+ /** Expected geometry from the exact selected plate's sliced commands, never printer progress. */
2
+ export interface LayerGeometry {
3
+ layer: number;
4
+ zMm: number;
5
+ boundsMm?: [number, number, number, number];
6
+ }
7
+ export interface PrintGeometry {
8
+ heightMm?: number;
9
+ layers: LayerGeometry[];
10
+ }
11
+ export declare function geometryFromGcode(gcode: string): PrintGeometry;
12
+ /** Best-effort diagnostics only: an unreadable/oversize file cannot fail an already dispatched print. */
13
+ export declare function geometryFromFile(filePath: string): Promise<PrintGeometry | undefined>;
@@ -0,0 +1,181 @@
1
+ import { arcCentre } from "../safety/print-preview.js";
2
+ export function geometryFromGcode(gcode) {
3
+ const layers = [];
4
+ let z, layer;
5
+ let markerCount = 0, currentIndex = 0, previousMarkerZ;
6
+ let x = 0, y = 0, e = 0, relative = false, absoluteXY = true, positionUnknown = false, changingFilament = false, feature = "", executableEnded = false;
7
+ for (const line of gcode.split(/\r?\n/)) {
8
+ if (line === "; EXECUTABLE_BLOCK_END")
9
+ executableEnded = true;
10
+ if (executableEnded)
11
+ break;
12
+ const marker = /^;\s*(?:Z_HEIGHT:|Z:)\s*([\d.]+)/.exec(line);
13
+ if (marker) {
14
+ z = Number(marker[1]);
15
+ if (z !== previousMarkerZ)
16
+ markerCount++;
17
+ previousMarkerZ = z;
18
+ currentIndex = markerCount;
19
+ layer = undefined;
20
+ if (!Number.isFinite(z) || z <= 0 || z > 10000)
21
+ z = undefined;
22
+ }
23
+ const declared = /^;\s*layer num\/total_layer_count:\s*(\d+)\/\d+/.exec(line);
24
+ if (declared)
25
+ currentIndex = Number(declared[1]);
26
+ const featureMatch = /^;\s*(?:FEATURE|TYPE):\s*(.*)/i.exec(line);
27
+ if (featureMatch)
28
+ feature = featureMatch[1].trim().toLowerCase();
29
+ const command = line
30
+ .split(";")[0]
31
+ .trim()
32
+ .toUpperCase()
33
+ .replace(/^N\d+\s*/, "")
34
+ .replace(/\*\d+\s*$/, "");
35
+ const parsed = /^([GMT])(\d+(?:\.\d+)?)/.exec(command);
36
+ if (!parsed)
37
+ continue;
38
+ const word = parsed[1] + String(Number(parsed[2]));
39
+ const values = {};
40
+ for (const match of command
41
+ .slice(parsed[0].length)
42
+ .matchAll(/([A-Z])\s*([+-]?(?:\d+(?:\.\d*)?|\.\d+))/g)) {
43
+ if (values[match[1]] === undefined)
44
+ values[match[1]] = Number(match[2]);
45
+ }
46
+ if (word === "G90") {
47
+ absoluteXY = true;
48
+ continue;
49
+ }
50
+ if (word === "G91") {
51
+ absoluteXY = false;
52
+ continue;
53
+ }
54
+ if (word === "M83") {
55
+ relative = true;
56
+ continue;
57
+ }
58
+ if (word === "M82") {
59
+ relative = false;
60
+ continue;
61
+ }
62
+ // Do not invent bed-coordinate footprints for unsupported unit/work-coordinate changes.
63
+ if (word === "G20" ||
64
+ word === "G18" || word === "G19" || word === "G90.1" ||
65
+ word === "G53" ||
66
+ (word === "G92" && (values.X !== undefined || values.Y !== undefined)))
67
+ return { layers: [] };
68
+ if (word === "G28") {
69
+ positionUnknown = true;
70
+ continue;
71
+ }
72
+ if (Object.values(values).some((v) => !Number.isFinite(v)))
73
+ return { layers: [] };
74
+ if (word === "G92") {
75
+ if (values.E !== undefined)
76
+ e = values.E;
77
+ continue;
78
+ }
79
+ if (word === "M620" && values.S !== undefined) {
80
+ changingFilament = true;
81
+ continue;
82
+ }
83
+ if (word === "M621" && values.S !== undefined) {
84
+ changingFilament = false;
85
+ continue;
86
+ }
87
+ if (!["G0", "G1", "G2", "G3"].includes(word))
88
+ continue;
89
+ const nx = values.X === undefined ? x : absoluteXY ? values.X : x + values.X;
90
+ const ny = values.Y === undefined ? y : absoluteXY ? values.Y : y + values.Y;
91
+ const extrusion = values.E === undefined ? 0 : relative ? values.E : values.E - e;
92
+ if (z !== undefined &&
93
+ extrusion > 0 &&
94
+ word !== "G0" &&
95
+ !changingFilament &&
96
+ feature !== "custom" &&
97
+ (values.X !== undefined || values.Y !== undefined || word === "G2" || word === "G3")) {
98
+ if (positionUnknown)
99
+ return { layers: [] };
100
+ const bounds = motionBounds(x, y, nx, ny, word, values);
101
+ if (!bounds)
102
+ return { layers: [] };
103
+ if (!layer) {
104
+ // Repeated Z values do not create fictitious additional layers.
105
+ layer =
106
+ layers.at(-1)?.zMm === z
107
+ ? layers.at(-1)
108
+ : { layer: currentIndex, zMm: z };
109
+ if (layer && layers.at(-1) !== layer)
110
+ layers.push(layer);
111
+ if (layers.length > 10000)
112
+ return { layers: [] };
113
+ }
114
+ if (layer) {
115
+ const previous = layer.boundsMm;
116
+ layer.boundsMm = [
117
+ Math.min(previous?.[0] ?? bounds[0], bounds[0]),
118
+ Math.min(previous?.[1] ?? bounds[1], bounds[1]),
119
+ Math.max(previous?.[2] ?? bounds[2], bounds[2]),
120
+ Math.max(previous?.[3] ?? bounds[3], bounds[3]),
121
+ ];
122
+ }
123
+ }
124
+ if (absoluteXY && values.X !== undefined && values.Y !== undefined)
125
+ positionUnknown = false;
126
+ x = nx;
127
+ y = ny;
128
+ if (values.E !== undefined)
129
+ e = relative ? e + values.E : values.E;
130
+ }
131
+ return {
132
+ ...(layers.length
133
+ ? { heightMm: Math.max(...layers.map((l) => l.zMm)) }
134
+ : {}),
135
+ layers,
136
+ };
137
+ }
138
+ /** Include the cardinal extrema actually swept by an XY arc, including I/J full circles. */
139
+ function motionBounds(x, y, nx, ny, word, values) {
140
+ const bounds = [Math.min(x, nx), Math.min(y, ny), Math.max(x, nx), Math.max(y, ny)];
141
+ if (!bounds.every(Number.isFinite))
142
+ return;
143
+ if (word !== "G2" && word !== "G3")
144
+ return bounds;
145
+ const clockwise = word === "G2";
146
+ const centre = arcCentre(x, y, nx, ny, clockwise, values.I, values.J, values.R);
147
+ if (!centre || !centre.every(Number.isFinite))
148
+ return;
149
+ const [cx, cy] = centre, radius = Math.hypot(x - cx, y - cy);
150
+ if (!Number.isFinite(radius) || radius <= 0 || Math.abs(Math.hypot(nx - cx, ny - cy) - radius) > Math.max(0.01, radius * 0.001))
151
+ return;
152
+ const turn = 2 * Math.PI;
153
+ const normal = (angle) => ((angle % turn) + turn) % turn;
154
+ const start = Math.atan2(y - cy, x - cx), end = Math.atan2(ny - cy, nx - cx);
155
+ const sweep = normal(clockwise ? start - end : end - start);
156
+ const full = x === nx && y === ny;
157
+ for (const angle of [0, Math.PI / 2, Math.PI, 3 * Math.PI / 2]) {
158
+ const distance = normal(clockwise ? start - angle : angle - start);
159
+ if (!full && distance > sweep + 1e-10)
160
+ continue;
161
+ const px = cx + radius * Math.cos(angle), py = cy + radius * Math.sin(angle);
162
+ bounds[0] = Math.min(bounds[0], px);
163
+ bounds[1] = Math.min(bounds[1], py);
164
+ bounds[2] = Math.max(bounds[2], px);
165
+ bounds[3] = Math.max(bounds[3], py);
166
+ }
167
+ return bounds;
168
+ }
169
+ /** Best-effort diagnostics only: an unreadable/oversize file cannot fail an already dispatched print. */
170
+ export async function geometryFromFile(filePath) {
171
+ try {
172
+ const fs = await import("node:fs/promises");
173
+ const stat = await fs.stat(filePath);
174
+ if (!stat.isFile() || stat.size > 64 * 1024 * 1024)
175
+ return undefined;
176
+ return geometryFromGcode(await fs.readFile(filePath, "utf8"));
177
+ }
178
+ catch {
179
+ return undefined;
180
+ }
181
+ }
@@ -18,6 +18,8 @@ export const REMOTE_SCOPES = {
18
18
  blender_mcp_status: "read",
19
19
  counterpart_printer_info: "read",
20
20
  counterpart_print_progress: "read",
21
+ counterpart_print_record: "read",
22
+ counterpart_print_assess: "control", // local evidence mutation, never a printer command
21
23
  cad_status: "read",
22
24
  cad_examples: "read",
23
25
  design_guidance: "read",
@@ -1,3 +1,4 @@
1
+ import { type PhysicalEvidence } from "./physical-evidence.js";
1
2
  /**
2
3
  * The Counterpart tool contract (counterpart/1): output schemas shared by the
3
4
  * tool list and the tests. mcp-3D-printer-server declares the same results.
@@ -21,6 +22,7 @@ export type Temperature = {
21
22
  target: number;
22
23
  };
23
24
  export type PrintProgress = {
25
+ physical?: PhysicalEvidence;
24
26
  contract: typeof COUNTERPART_CONTRACT;
25
27
  observedAt: string;
26
28
  state: PrintState;
@@ -211,6 +213,36 @@ export declare const PRINTER_INFO_OUTPUT_SCHEMA: {
211
213
  export declare const PRINT_PROGRESS_OUTPUT_SCHEMA: {
212
214
  type: "object";
213
215
  properties: {
216
+ physical: {
217
+ type: string;
218
+ properties: {
219
+ status: {
220
+ type: string;
221
+ enum: string[];
222
+ };
223
+ observedLayer: {
224
+ type: string;
225
+ minimum: number;
226
+ };
227
+ assessment: {
228
+ type: string;
229
+ additionalProperties: boolean;
230
+ };
231
+ evidence: {
232
+ type: string;
233
+ items: {
234
+ type: string;
235
+ };
236
+ };
237
+ limitations: {
238
+ type: string;
239
+ items: {
240
+ type: string;
241
+ };
242
+ };
243
+ };
244
+ required: string[];
245
+ };
214
246
  contract: {
215
247
  type: string;
216
248
  const: string;
@@ -1,3 +1,4 @@
1
+ import { PHYSICAL_EVIDENCE_SCHEMA } from "./physical-evidence.js";
1
2
  /**
2
3
  * The Counterpart tool contract (counterpart/1): output schemas shared by the
3
4
  * tool list and the tests. mcp-3D-printer-server declares the same results.
@@ -61,6 +62,7 @@ export const PRINTER_INFO_OUTPUT_SCHEMA = {
61
62
  export const PRINT_PROGRESS_OUTPUT_SCHEMA = {
62
63
  type: "object",
63
64
  properties: {
65
+ physical: PHYSICAL_EVIDENCE_SCHEMA,
64
66
  contract: { type: "string", const: COUNTERPART_CONTRACT },
65
67
  observedAt: { type: "string", description: "When the printer reported this (MQTT report time), ISO 8601." },
66
68
  state: { type: "string", enum: [...PRINT_STATES] },
@@ -0,0 +1,38 @@
1
+ import type { EvidenceFrame, PhysicalEvidence } from "./physical-evidence.js";
2
+ import type { PrintGeometry } from "./print-geometry.js";
3
+ export declare const VISIBILITIES: readonly ["clear", "dark", "occluded", "out_of_view", "unknown"];
4
+ export type Visibility = (typeof VISIBILITIES)[number];
5
+ export interface VisualSubmission {
6
+ jobId: string;
7
+ artifactSha256: string;
8
+ frameId: string;
9
+ imageSha256: string;
10
+ visibility: Visibility;
11
+ footprintVisible: boolean;
12
+ deposition: "absent" | "present" | "unknown";
13
+ attempted: boolean;
14
+ referenceFrameId?: string;
15
+ referenceVisibility?: Visibility;
16
+ referenceEmpty?: boolean;
17
+ }
18
+ export interface VisualObservation extends VisualSubmission {
19
+ at: string;
20
+ source: "client-vision";
21
+ }
22
+ export declare function validateVisualSubmission(v: VisualSubmission): VisualSubmission;
23
+ /** Unknown checkpoints cannot erase clear empty-footprint evidence for this execution. */
24
+ export declare function assessVisual(frames: EvidenceFrame[], observations: VisualObservation[], expected?: PrintGeometry): PhysicalEvidence | undefined;
25
+ export declare function assessmentRequest(frames: EvidenceFrame[], observations: VisualObservation[], expected?: PrintGeometry): {
26
+ required: boolean;
27
+ frameId: string;
28
+ referenceFrameIds: string[];
29
+ layer: number;
30
+ expectedHeightMm: number;
31
+ expectedFootprintMm: [number, number, number, number];
32
+ instruction: string;
33
+ } | undefined;
34
+ export declare function physicalProblems(physical: PhysicalEvidence, finished?: boolean): {
35
+ code: string;
36
+ severity: "error";
37
+ message: string;
38
+ }[];
@@ -0,0 +1,155 @@
1
+ /** Visual observations come from the client's worker; this module runs no image model or printer I/O. */
2
+ import { frameMatchesReport } from "./physical-evidence.js";
3
+ export const VISIBILITIES = [
4
+ "clear",
5
+ "dark",
6
+ "occluded",
7
+ "out_of_view",
8
+ "unknown",
9
+ ];
10
+ const uuid = /^[a-f\d]{8}(-[a-f\d]{4}){3}-[a-f\d]{12}$/i, sha = /^[a-f\d]{64}$/i;
11
+ export function validateVisualSubmission(v) {
12
+ if (!v ||
13
+ !uuid.test(v.jobId) ||
14
+ !uuid.test(v.frameId) ||
15
+ !sha.test(v.artifactSha256) ||
16
+ !sha.test(v.imageSha256) ||
17
+ !VISIBILITIES.includes(v.visibility) ||
18
+ typeof v.footprintVisible !== "boolean" ||
19
+ typeof v.attempted !== "boolean" ||
20
+ !["absent", "present", "unknown"].includes(v.deposition) ||
21
+ (v.referenceFrameId !== undefined &&
22
+ (!uuid.test(v.referenceFrameId) ||
23
+ !VISIBILITIES.includes(v.referenceVisibility))) ||
24
+ (v.referenceEmpty !== undefined && typeof v.referenceEmpty !== "boolean"))
25
+ throw Error("Invalid visual observation.");
26
+ return {
27
+ jobId: v.jobId,
28
+ artifactSha256: v.artifactSha256,
29
+ frameId: v.frameId,
30
+ imageSha256: v.imageSha256,
31
+ visibility: v.visibility,
32
+ footprintVisible: v.footprintVisible,
33
+ deposition: v.deposition,
34
+ attempted: v.attempted,
35
+ ...(v.referenceFrameId
36
+ ? {
37
+ referenceFrameId: v.referenceFrameId,
38
+ referenceVisibility: v.referenceVisibility,
39
+ referenceEmpty: v.referenceEmpty === true,
40
+ }
41
+ : {}),
42
+ };
43
+ }
44
+ function assessObservation(frames, observation, expected) {
45
+ const limitations = [
46
+ "Firmware completion is separate from physical success.",
47
+ "Image interpretation is supplied by the client vision worker; the MCP runs no vision model.",
48
+ ];
49
+ const unknown = (reason) => ({
50
+ status: "unknown",
51
+ evidence: [],
52
+ limitations: [...limitations, reason],
53
+ });
54
+ const frame = frames.find((f) => f.id === observation.frameId &&
55
+ f.status === "captured" &&
56
+ f.sha256 === observation.imageSha256 &&
57
+ f.role !== "baseline");
58
+ const footprint = expected?.layers.find((l) => l.layer === frame?.layer)?.boundsMm;
59
+ if (!frame ||
60
+ !footprint ||
61
+ !footprint.every(Number.isFinite) ||
62
+ footprint[2] <= footprint[0] ||
63
+ footprint[3] <= footprint[1] ||
64
+ !frameMatchesReport(frame) ||
65
+ !observation.attempted)
66
+ return unknown("Saved frame, expected deposition footprint or attempted-layer evidence is unavailable.");
67
+ if (observation.visibility !== "clear" ||
68
+ !observation.footprintVisible ||
69
+ observation.deposition === "unknown")
70
+ return unknown("The expected footprint is dark, occluded, out of view, unlocatable or unassessed.");
71
+ if (observation.deposition === "present")
72
+ return {
73
+ ...unknown("The client reports visible material; height, coverage and final success remain unverified."),
74
+ observedLayer: frame.layer,
75
+ evidence: [frame.id],
76
+ };
77
+ const reference = frames.find((f) => f.id === observation.referenceFrameId && f.status === "captured");
78
+ const evidence = [frame.id];
79
+ if (reference &&
80
+ observation.referenceVisibility === "clear" &&
81
+ observation.referenceEmpty === true)
82
+ evidence.unshift(reference.id);
83
+ return {
84
+ status: "suspect_no_extrusion",
85
+ observedLayer: frame.layer,
86
+ evidence,
87
+ limitations: [
88
+ ...limitations,
89
+ "The client reports a clear expected footprint with no visible deposited material after deposition was attempted. Check the print; the cause is unverified.",
90
+ ...(evidence.length === 1
91
+ ? [
92
+ "No usable empty-bed reference was supplied; the clear empty-footprint observation is direct evidence.",
93
+ ]
94
+ : [
95
+ "The client compared the frame with the saved empty-bed reference.",
96
+ ]),
97
+ ],
98
+ };
99
+ }
100
+ /** Unknown checkpoints cannot erase clear empty-footprint evidence for this execution. */
101
+ export function assessVisual(frames, observations, expected) {
102
+ let latest;
103
+ let suspect;
104
+ let recovery;
105
+ const ordered = [...observations].sort((a, b) => (frames.find(f => f.id === a.frameId)?.layer ?? 0) - (frames.find(f => f.id === b.frameId)?.layer ?? 0));
106
+ for (const observation of ordered) {
107
+ latest = assessObservation(frames, observation, expected);
108
+ if (latest.status === "suspect_no_extrusion") {
109
+ suspect = latest;
110
+ recovery = undefined;
111
+ }
112
+ else if (suspect && observation.deposition === "present" &&
113
+ latest.evidence.includes(observation.frameId) &&
114
+ (latest.observedLayer ?? 0) > (suspect.observedLayer ?? 0)) {
115
+ suspect = undefined;
116
+ latest.limitations.push("A later clear, visible-footprint present observation at a higher layer supersedes the earlier no-extrusion warning; final physical success remains unverified.");
117
+ recovery = latest;
118
+ }
119
+ }
120
+ if (!suspect)
121
+ return recovery ?? latest;
122
+ return { ...suspect, limitations: [...suspect.limitations,
123
+ "This job's no-extrusion warning stays active through unknown checkpoints and firmware completion. Only a later clear present observation with a visible footprint at a higher layer can supersede it."] };
124
+ }
125
+ export function assessmentRequest(frames, observations, expected) {
126
+ const pending = frames.filter((f) => f.status === "captured" &&
127
+ frameMatchesReport(f) &&
128
+ f.role !== "baseline" &&
129
+ !observations.some((o) => o.frameId === f.id));
130
+ const frame = pending.find((f) => f.role === "first_layer") ?? pending.at(-1);
131
+ const footprint = expected?.layers.find((l) => l.layer === frame?.layer)?.boundsMm;
132
+ if (!frame || !footprint)
133
+ return;
134
+ return {
135
+ required: true,
136
+ frameId: frame.id,
137
+ referenceFrameIds: frames
138
+ .filter((f) => f.role === "baseline" && f.status === "captured")
139
+ .map((f) => f.id),
140
+ layer: frame.layer,
141
+ expectedHeightMm: frame.expectedHeightMm,
142
+ expectedFootprintMm: footprint,
143
+ instruction: "Fetch this frame (and any usable reference) with counterpart_print_record include_frames:true frame_format:images. Have the client vision worker locate the expected footprint. Record its observation with counterpart_print_assess. A clearly empty footprint after attempted printing is suspect_no_extrusion even without a usable reference. Dark/occluded/unlocatable is unknown. Never infer a first layer is down from counters.",
144
+ };
145
+ }
146
+ export function physicalProblems(physical, finished = false) {
147
+ if (physical.status !== "suspect_no_extrusion")
148
+ return [];
149
+ const layer = Number.isInteger(physical.observedLayer) && physical.observedLayer > 0
150
+ ? ` at layer ${physical.observedLayer}` : "";
151
+ const message = finished
152
+ ? `The printer reports finished, but the camera showed the part's area empty${layer}. Check the nozzle and filament path.`
153
+ : `Nothing seems to be coming out of the nozzle: the camera shows the part's area empty${layer}. The printer can still count layers without printing anything. Check the nozzle and filament path.`;
154
+ return [{ code: "physical-no-extrusion", severity: "error", message }];
155
+ }
package/dist/index.js CHANGED
@@ -1,4 +1,7 @@
1
1
  #!/usr/bin/env node
2
+ import { physicalProblems } from "./counterpart/visual-evidence.js";
3
+ import { flightKey } from "./counterpart/flight-record.js";
4
+ import { FLIGHT_RECORD_PROPERTIES, FLIGHT_RECORD_DESCRIPTION, FLIGHT_RECORD_OUTPUT_SCHEMA, flightReadOptions, flightRecordResult, FLIGHT_ASSESS_PROPERTIES, FLIGHT_ASSESS_REQUIRED, FLIGHT_ASSESS_DESCRIPTION, PRINT_EVIDENCE_GUIDANCE, visualSubmission } from "./counterpart/flight-tools.js";
2
5
  import { CAMERA_STREAM_TOOLS } from "./printers/camera-tools.js";
3
6
  import { withAnnotations } from "./tool-annotations.js";
4
7
  import { withRemote } from "./counterpart/remote.js";
@@ -1131,7 +1134,7 @@ class BambuPrinterMCPServer {
1131
1134
  resources: {},
1132
1135
  tools: {}
1133
1136
  },
1134
- instructions: SERVER_INSTRUCTIONS + (CAD_ENABLED ? " For headless dimensioned designs and parameter edits, read the cad_design prompt before using cad_run." : "")
1137
+ instructions: SERVER_INSTRUCTIONS + PRINT_EVIDENCE_GUIDANCE + (CAD_ENABLED ? " For headless dimensioned designs and parameter edits, read the cad_design prompt before using cad_run." : "")
1135
1138
  });
1136
1139
  this.bambu = new BambuImplementation(async (message) => {
1137
1140
  try {
@@ -1559,6 +1562,7 @@ class BambuPrinterMCPServer {
1559
1562
  throw new Error("The printer's SD card or USB stick is no longer ready. Check it and start the print again.");
1560
1563
  }
1561
1564
  assertActive();
1565
+ this.bambu.recordFlightDispatch(devIp, devId, remoteFileName, requirements, resumeFile);
1562
1566
  markPrintCommandSent();
1563
1567
  } });
1564
1568
  assertActive();
@@ -1577,6 +1581,7 @@ class BambuPrinterMCPServer {
1577
1581
  },
1578
1582
  assertDispatchAllowed: method => { if (method === bridgeMethod || method === cloudFallbackMethod) {
1579
1583
  assertActive();
1584
+ this.bambu.recordFlightDispatch(devIp, devId, remoteFileName, requirements, resumeFile);
1580
1585
  markPrintCommandSent();
1581
1586
  } },
1582
1587
  onDispatched: method => { if (method === bridgeMethod || method === cloudFallbackMethod)
@@ -3088,6 +3093,16 @@ class BambuPrinterMCPServer {
3088
3093
  additionalProperties: false
3089
3094
  }
3090
3095
  },
3096
+ {
3097
+ name: "counterpart_print_record", description: FLIGHT_RECORD_DESCRIPTION,
3098
+ inputSchema: { type: "object", properties: { ...FLIGHT_RECORD_PROPERTIES, host: { type: "string", description: "Saved printer hostname or address; used only to select a local record." }, bambu_serial: { type: "string", description: "Saved Bambu printer serial; used only to select a local record." } }, additionalProperties: false },
3099
+ outputSchema: FLIGHT_RECORD_OUTPUT_SCHEMA
3100
+ },
3101
+ {
3102
+ name: "counterpart_print_assess", description: FLIGHT_ASSESS_DESCRIPTION,
3103
+ inputSchema: { type: "object", properties: { ...FLIGHT_ASSESS_PROPERTIES, host: { type: "string", description: "Saved printer hostname or address; used only to select a local record." }, bambu_serial: { type: "string", description: "Saved Bambu printer serial; used only to select a local record." } }, required: FLIGHT_ASSESS_REQUIRED, additionalProperties: false },
3104
+ outputSchema: FLIGHT_RECORD_OUTPUT_SCHEMA
3105
+ },
3091
3106
  {
3092
3107
  name: "counterpart_print_progress",
3093
3108
  description: "Counterpart contract (counterpart/1): the printer's state, current job (name, task id, percent, time left, layers, stage words), temperatures, active filament and problems with Bambu's HMS messages and links. Read from the MQTT report this server keeps, so a held session asks the printer nothing; observedAt is when the printer sent it. An unreachable printer reports state offline. Read-only; not a safety check.",
@@ -4377,11 +4392,19 @@ class BambuPrinterMCPServer {
4377
4392
  choices: options.filter(option => option.available).map(option => option.id), options, savedTo };
4378
4393
  break;
4379
4394
  }
4395
+ case "counterpart_print_assess":
4396
+ return flightRecordResult(this.bambu.flightRecords.submitVisual(flightKey(host, bambuSerial), visualSubmission(args)));
4397
+ case "counterpart_print_record":
4398
+ return flightRecordResult(this.bambu.flightRecords.read(flightKey(host, bambuSerial), flightReadOptions(args)), args?.frame_format === "images");
4380
4399
  case "counterpart_print_progress": {
4381
4400
  const report = await this.bambu.readProgressReport(host, bambuSerial, bambuToken);
4401
+ if (report)
4402
+ void this.bambu.flightRecords.sample(flightKey(host, bambuSerial), after => this.bambu.cameraSnapshot(host, bambuSerial, bambuToken, { bambuModel: this.displayModel(args, bambuSerial), timeoutMs: 8000, capturedAfter: after })).catch(() => undefined);
4382
4403
  result = report
4383
4404
  ? bambuProgress(report.raw, { receivedAt: report.receivedAt, serial: bambuSerial, model: this.displayModel(args, bambuSerial) })
4384
4405
  : offlineProgress(Date.now());
4406
+ const physical = this.bambu.flightRecords.physicalForReport(flightKey(host, bambuSerial), report?.raw);
4407
+ result = { ...result, physical, problems: [...physicalProblems(physical, result.state === "finished"), ...result.problems] };
4385
4408
  break;
4386
4409
  }
4387
4410
  case "counterpart_make_3mf":
@@ -1,3 +1,4 @@
1
+ import { FlightRecords, type PrintGeometry } from "../counterpart/flight-record.js";
1
2
  import { CameraStreams, type FrameOptions } from "./camera-stream.js";
2
3
  import { inspectPrintFile, type PrintFileInspection } from "../safety/print-file.js";
3
4
  import { type PrinterStateRequirements } from "../safety/printer-state.js";
@@ -42,6 +43,7 @@ export type ProgressReport = {
42
43
  /** The inspected bytes and limits of a started job, for the resume prompt and byte check. */
43
44
  export type CheckedFile = {
44
45
  sha256: string;
46
+ expected?: PrintGeometry;
45
47
  /** A project's printed plate: its number and the SHA-256 of its Metadata/plate_<index>.gcode. */
46
48
  plate?: {
47
49
  index: number;
@@ -71,6 +73,7 @@ export type PrintPreflight = {
71
73
  export { cameraFrameParser } from "./camera-wire.js";
72
74
  export declare class BambuImplementation {
73
75
  private readonly confirm?;
76
+ readonly flightRecords: FlightRecords;
74
77
  private printerStore;
75
78
  readonly cameraStreams: CameraStreams;
76
79
  /**
@@ -108,6 +111,8 @@ export declare class BambuImplementation {
108
111
  * verified: a resume then re-reads it if it can and otherwise matches the
109
112
  * unique name, as KAN-216 does for firmware that cannot download a file.
110
113
  */
114
+ /** At the existing send-authorization boundary: record evidence even if the reply/helper is lost. */
115
+ recordFlightDispatch(host: string, serial: string, remotePath: string, requirements: PrinterStateRequirements, file: CheckedFile): void;
111
116
  recordCheckedJob(host: string, serial: string, remotePath: string, requirements: PrinterStateRequirements, file: CheckedFile, uploadedHere?: boolean): void;
112
117
  /** Feed one merged report to the resume record (internal; the client store calls it for every report). */
113
118
  observeReport(host: string, serial: string, raw: Record<string, any> | undefined): void;
@@ -206,7 +211,7 @@ export declare class BambuImplementation {
206
211
  status: string;
207
212
  uploaded: boolean;
208
213
  printRequested: boolean;
209
- dispatch: "started" | "unconfirmed";
214
+ dispatch: "unconfirmed" | "started";
210
215
  remotePath: string;
211
216
  jobName: string;
212
217
  message: string;
@@ -223,7 +228,7 @@ export declare class BambuImplementation {
223
228
  status: string;
224
229
  uploaded: boolean;
225
230
  printRequested: boolean;
226
- dispatch: "started" | "unconfirmed";
231
+ dispatch: "unconfirmed" | "started";
227
232
  remotePath: string;
228
233
  jobName: string;
229
234
  message: string;
@@ -276,6 +281,7 @@ export declare class BambuImplementation {
276
281
  };
277
282
  cameraSnapshot(host: string, _serial: string, token: string, options?: {
278
283
  savePath?: string;
284
+ capturedAfter?: string;
279
285
  timeoutMs?: number;
280
286
  bambuModel?: string;
281
287
  /**
@@ -297,6 +303,7 @@ export declare class BambuImplementation {
297
303
  sizeBytes: number;
298
304
  base64: string;
299
305
  savedTo?: string;
306
+ capturedAt?: string;
300
307
  width?: number;
301
308
  height?: number;
302
309
  note?: string;