@tmhs/screencast-mcp 0.44.2 → 0.46.0

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 (44) hide show
  1. package/README.md +58 -11
  2. package/assets/ui/player.html +9 -0
  3. package/assets/ui/player.js +20 -0
  4. package/dist/index.js +12 -0
  5. package/dist/prompts.js +34 -4
  6. package/dist/server.js +20 -0
  7. package/dist/tools/addMarker.js +89 -0
  8. package/dist/tools/backdrop.js +89 -0
  9. package/dist/tools/bugReport.js +266 -0
  10. package/dist/tools/chapters.js +156 -0
  11. package/dist/tools/contactSheet.js +19 -17
  12. package/dist/tools/cutByTranscript.js +86 -0
  13. package/dist/tools/findText.js +14 -64
  14. package/dist/tools/indexRecording.js +173 -0
  15. package/dist/tools/keystrokeOverlay.js +131 -0
  16. package/dist/tools/pipeline.js +251 -18
  17. package/dist/tools/reviewRecording.js +12 -0
  18. package/dist/tools/saveReplay.js +90 -0
  19. package/dist/tools/searchRecording.js +73 -0
  20. package/dist/tools/startRecording.js +51 -10
  21. package/dist/tools/stepGuide.js +193 -0
  22. package/dist/tools/stopRecording.js +25 -1
  23. package/dist/tools/transcribe.js +4 -3
  24. package/dist/tools/zoom.js +1 -1
  25. package/dist/utils/audio.js +12 -4
  26. package/dist/utils/backdrop.js +151 -0
  27. package/dist/utils/bugReport.js +172 -0
  28. package/dist/utils/captions.js +19 -6
  29. package/dist/utils/chapters.js +227 -0
  30. package/dist/utils/idle.js +10 -3
  31. package/dist/utils/keystrokes.js +155 -0
  32. package/dist/utils/lifecycle.js +11 -2
  33. package/dist/utils/media.js +5 -2
  34. package/dist/utils/ocrScan.js +77 -0
  35. package/dist/utils/pipeline.js +169 -15
  36. package/dist/utils/recipes.js +67 -0
  37. package/dist/utils/recordingIndex.js +266 -0
  38. package/dist/utils/replay.js +278 -0
  39. package/dist/utils/stepGuide.js +205 -0
  40. package/dist/utils/steps.js +88 -0
  41. package/dist/utils/timeline.js +85 -0
  42. package/dist/utils/toolsets.js +32 -6
  43. package/dist/utils/transcriptCut.js +134 -0
  44. package/package.json +1 -1
@@ -82,11 +82,14 @@ export function planFpsSampling(durationSec, fps, maxFrames) {
82
82
  const clampedFps = Math.max(1e-4, Math.floor((maxFrames / durationSec) * 10_000) / 10_000);
83
83
  return { fps: clampedFps, requestedFrames: requested, clamped: true };
84
84
  }
85
- export function buildSampleByFpsArgs(input, fps, outputPattern, maxFrames = DEFAULT_MAX_FRAMES, dedupe = false) {
85
+ export function buildSampleByFpsArgs(input, fps, outputPattern, maxFrames = DEFAULT_MAX_FRAMES, dedupe = false, range) {
86
86
  validatePositive(fps, "fps");
87
87
  const vf = dedupe ? `fps=${fps},mpdecimate` : `fps=${fps}`;
88
+ const seek = range
89
+ ? ["-ss", String(range.start), ...(range.duration !== undefined ? ["-t", String(range.duration)] : [])]
90
+ : [];
88
91
  return [
89
- "-y", "-i", input, "-vf", vf,
92
+ "-y", ...seek, "-i", input, "-vf", vf,
90
93
  ...(dedupe ? ["-fps_mode", "vfr"] : []),
91
94
  "-frames:v", String(maxFrames), outputPattern,
92
95
  ];
@@ -0,0 +1,77 @@
1
+ import { join } from "node:path";
2
+ import { readdirSync } from "node:fs";
3
+ import { ScreencastError } from "./errors.js";
4
+ import { probeMedia, runFfmpeg } from "./ffmpeg.js";
5
+ import { jobTimeoutMs } from "./jobs.js";
6
+ import { buildSampleByFpsArgs, planFpsSampling } from "./media.js";
7
+ import { recognize, mergePasses, findMatches, redactionRects, passScales } from "./ocr.js";
8
+ export async function readFrames(sources, work, signal) {
9
+ const sized = await Promise.all(sources.map(async (source) => {
10
+ const { width, height } = await probeMedia(source);
11
+ if (!width || !height)
12
+ throw new ScreencastError("Could not read the image size.");
13
+ return { source, width, height };
14
+ }));
15
+ const passes = [];
16
+ const passScaleList = [];
17
+ const owner = [];
18
+ for (const [f, { source, width, height }] of sized.entries()) {
19
+ for (const [i, scale] of passScales(width, height).entries()) {
20
+ const out = join(work, `pass${f}-${i}.png`);
21
+ await runFfmpeg(["-y", "-v", "error", "-i", source, "-vf", `scale=iw*${scale}:ih*${scale}:flags=lanczos`, out], 60_000, {
22
+ signal,
23
+ });
24
+ passes.push(out);
25
+ passScaleList.push(scale);
26
+ owner.push(f);
27
+ }
28
+ }
29
+ const results = await recognize(passes, passScaleList);
30
+ return sized.map(({ width, height }, f) => ({
31
+ lines: mergePasses(results.filter((_r, i) => owner[i] === f)),
32
+ width,
33
+ height,
34
+ }));
35
+ }
36
+ export async function scanVideoFrames(input, opts, work, signal) {
37
+ const info = await probeMedia(input);
38
+ const full = info.videoDurationSec ?? info.durationSec;
39
+ const length = opts.range ? opts.range.duration : full;
40
+ const plan = planFpsSampling(length, 1 / opts.everySec, opts.maxFrames);
41
+ await runFfmpeg(buildSampleByFpsArgs(input, plan.fps, join(work, "scan_%05d.png"), opts.maxFrames, false, opts.range), jobTimeoutMs(info.durationSec), { signal });
42
+ const paths = readdirSync(work).filter((f) => f.startsWith("scan_")).sort().map((f) => join(work, f));
43
+ if (paths.length === 0)
44
+ throw new ScreencastError("Could not read any frames from the video.");
45
+ const step = 1 / plan.fps;
46
+ const timeAt = (i) => Math.round(i * step * 1000) / 1000;
47
+ const end = length ?? timeAt(paths.length - 1) + step;
48
+ const read = await readFrames(paths, work, signal);
49
+ return {
50
+ frames: read.map((frame, i) => ({ ...frame, t: timeAt(i), path: paths[i] ?? "" })),
51
+ step,
52
+ end,
53
+ clamped: plan.clamped,
54
+ };
55
+ }
56
+ export function sampleWindow(t, step, end) {
57
+ return {
58
+ start: Math.max(0, Math.round((t - step) * 1000) / 1000),
59
+ end: Math.min(end, Math.round((t + step) * 1000) / 1000),
60
+ };
61
+ }
62
+ export function scanMatches(scan, query, regex, scope = "match") {
63
+ const matches = [];
64
+ const redactRegions = [];
65
+ for (const frame of scan.frames) {
66
+ const hits = findMatches(frame.lines, query, regex);
67
+ const window = sampleWindow(frame.t, scan.step, scan.end);
68
+ const boxes = scope === "line"
69
+ ? [...new Set(hits.map((h) => frame.lines.find((l) => l.text === h.line) ?? h))]
70
+ : hits;
71
+ for (const hit of hits)
72
+ matches.push({ t: frame.t, ...hit });
73
+ for (const rect of redactionRects(boxes, frame))
74
+ redactRegions.push({ ...rect, ...window });
75
+ }
76
+ return { matches, redactRegions };
77
+ }
@@ -2,11 +2,25 @@ import { ScreencastError } from "./errors.js";
2
2
  import { atempoChain, cropFilter, redactSteps, scaleFilter, scaledSize } from "./media.js";
3
3
  import { calloutSteps } from "./callout.js";
4
4
  import { ASPECT_DIMS, exportPresetParts, reframeFilter } from "./produce.js";
5
- import { keyframesToViews, zoomFilter, DEFAULT_TRANSITION_SEC } from "./zoom.js";
5
+ import { keyframesToViews, planClickZoom, zoomFilter, DEFAULT_TRANSITION_SEC } from "./zoom.js";
6
6
  import { resolveQuality } from "./targets.js";
7
+ import { backdropSteps } from "./backdrop.js";
8
+ import { groupBadges, keystrokeSteps, retimeBadges } from "./keystrokes.js";
9
+ import { cutFilters, cutsFor, DEFAULT_KEEP_SEC, DEFAULT_MIN_IDLE_SEC } from "./idle.js";
10
+ import { denoiseFilter, loudnessTarget, loudnormFilter } from "./audio.js";
11
+ import { subtitlesFilter } from "./captions.js";
12
+ import { mapSpans, mapTime } from "./timeline.js";
7
13
  export const MAX_PIPELINE_STEPS = 30;
8
14
  const r3 = (v) => Math.round(v * 1000) / 1000;
9
- export function planPipeline(input, output, steps, src, assets = {}, quality = "standard") {
15
+ export function probeArgs(args, p) {
16
+ const out = [...args];
17
+ const af = out.indexOf("-af");
18
+ if (af !== -1 && p.audio.length > 0)
19
+ out[af + 1] = `${p.audio.join(",")},${out[af + 1]}`;
20
+ out.splice(out.indexOf("-i"), 0, ...p.seek);
21
+ return out;
22
+ }
23
+ export function planPipeline(input, output, steps, src, assets = {}, quality = "standard", opts = {}) {
10
24
  if (steps.length === 0)
11
25
  throw new ScreencastError("Give at least one step.");
12
26
  if (steps.length > MAX_PIPELINE_STEPS)
@@ -23,6 +37,8 @@ export function planPipeline(input, output, steps, src, assets = {}, quality = "
23
37
  "Put redact before zoom, in the source's coordinates.");
24
38
  }
25
39
  const redacts = steps.some((s) => s.op === "redact");
40
+ if (steps.filter((s) => s.op === "cut_idle").length > 1)
41
+ throw new ScreencastError("Use at most one cut_idle step.");
26
42
  let W = src.width;
27
43
  let H = src.height;
28
44
  let fps = src.fps;
@@ -37,6 +53,9 @@ export function planPipeline(input, output, steps, src, assets = {}, quality = "
37
53
  let encode = null;
38
54
  let gif;
39
55
  const summary = [];
56
+ const timeOps = [];
57
+ const pending = [];
58
+ let geo = { sx: 1, sy: 1, ox: 0, oy: 0 };
40
59
  const trimRange = (s, at) => {
41
60
  if (!Number.isFinite(s.start) || s.start < 0)
42
61
  throw new ScreencastError(`step ${at}: trim start must be a non-negative number.`);
@@ -59,6 +78,7 @@ export function planPipeline(input, output, steps, src, assets = {}, quality = "
59
78
  graph.push(`${cur}${filter}${out}`);
60
79
  cur = out;
61
80
  };
81
+ const pend = (kind) => pending.push({ step: i, kind, seek: [...inputArgs], audio: [...audio], ops: [...timeOps] });
62
82
  switch (s.op) {
63
83
  case "trim": {
64
84
  const { start, end } = trimRange(s, at);
@@ -73,17 +93,23 @@ export function planPipeline(input, output, steps, src, assets = {}, quality = "
73
93
  }
74
94
  audioReencode = true;
75
95
  dur = end - start;
96
+ timeOps.push({ op: "trim", start, end });
76
97
  break;
77
98
  }
78
99
  case "crop":
79
100
  chain(cropFilter(s, { width: W, height: H }));
101
+ if (geo)
102
+ geo = { ...geo, ox: geo.ox - s.x, oy: geo.oy - s.y };
80
103
  W = s.width;
81
104
  H = s.height;
82
105
  summary.push(`crop to ${W}x${H}`);
83
106
  break;
84
107
  case "scale": {
85
108
  const f = scaleFilter(s);
109
+ const [w0, h0] = [W, H];
86
110
  ({ width: W, height: H } = scaledSize(W, H, s));
111
+ if (geo)
112
+ geo = { sx: (geo.sx * W) / w0, sy: (geo.sy * H) / h0, ox: (geo.ox * W) / w0, oy: (geo.oy * H) / h0 };
87
113
  chain(f);
88
114
  summary.push(`scale to ${W}x${H}`);
89
115
  break;
@@ -96,6 +122,7 @@ export function planPipeline(input, output, steps, src, assets = {}, quality = "
96
122
  audioReencode = true;
97
123
  if (dur !== null)
98
124
  dur /= s.factor;
125
+ timeOps.push({ op: "speed", factor: s.factor });
99
126
  summary.push(`speed x${s.factor}`);
100
127
  break;
101
128
  case "redact": {
@@ -122,19 +149,143 @@ export function planPipeline(input, output, steps, src, assets = {}, quality = "
122
149
  if (!dim)
123
150
  throw new ScreencastError(`step ${at}: unknown aspect "${s.aspect}".`);
124
151
  chain(`${reframeFilter(dim.w, dim.h, s.fit ?? "pad")},format=yuv420p`);
152
+ geo = null;
125
153
  W = dim.w;
126
154
  H = dim.h;
127
155
  summary.push(`reframe to ${s.aspect} (${s.fit ?? "pad"})`);
128
156
  break;
129
157
  }
130
158
  case "zoom": {
131
- const views = keyframesToViews(s.keyframes, W, H);
132
- chain(zoomFilter(views, { width: W, height: H, fps }, s.transitionSec ?? DEFAULT_TRANSITION_SEC));
133
- summary.push(`zoom ${s.keyframes.length} keyframe(s)`);
159
+ const transition = s.transitionSec ?? DEFAULT_TRANSITION_SEC;
160
+ let kfs = s.keyframes;
161
+ let from = "";
162
+ if (s.follow === "clicks") {
163
+ if (kfs)
164
+ throw new ScreencastError(`step ${at}: zoom takes keyframes or follow, not both.`);
165
+ if (!geo) {
166
+ throw new ScreencastError(`step ${at}: zoom follow "clicks" must come before reframe, backdrop or another zoom; the logged click positions no longer match the frame.`);
167
+ }
168
+ const g = geo;
169
+ const logged = opts.clicks?.[i];
170
+ if (!logged)
171
+ throw new ScreencastError(`Internal: missing clicks for step ${at}.`);
172
+ const clicks = logged.flatMap((c) => {
173
+ const t = mapTime(c.t, timeOps);
174
+ const x = c.x * g.sx + g.ox;
175
+ const y = c.y * g.sy + g.oy;
176
+ return t !== null && x >= 0 && x < W && y >= 0 && y < H ? [{ t, x, y }] : [];
177
+ });
178
+ kfs = planClickZoom(clicks, W, H, { holdSec: s.holdSec, maxZoom: s.maxZoom, transition });
179
+ from = ` from ${clicks.length} click(s)`;
180
+ }
181
+ else if (!kfs || kfs.length === 0) {
182
+ throw new ScreencastError(`step ${at}: zoom needs keyframes, or follow: "clicks".`);
183
+ }
184
+ if (kfs.length === 0) {
185
+ summary.push("zoom: no clicks in this part of the video; skipped");
186
+ break;
187
+ }
188
+ chain(zoomFilter(keyframesToViews(kfs, W, H), { width: W, height: H, fps }, transition));
189
+ geo = null;
190
+ summary.push(`zoom ${kfs.length} keyframe(s)${from}`);
191
+ break;
192
+ }
193
+ case "cut_idle": {
194
+ if (!opts.idle)
195
+ throw new ScreencastError(`Internal: missing idle scan for step ${at}.`);
196
+ const cuts = cutsFor(mapSpans(opts.idle, timeOps), s.minIdleSec ?? DEFAULT_MIN_IDLE_SEC, s.keepSec ?? DEFAULT_KEEP_SEC);
197
+ if (cuts.length === 0) {
198
+ summary.push("cut_idle: no idle stretches here; nothing cut");
199
+ break;
200
+ }
201
+ const f = cutFilters(cuts);
202
+ chain(f.video);
203
+ audio.push(f.audio);
204
+ audioReencode = true;
205
+ const removed = cuts.reduce((sum, c) => sum + (c.end - c.start), 0);
206
+ if (dur !== null)
207
+ dur -= removed;
208
+ timeOps.push({ op: "cut", spans: cuts });
209
+ summary.push(`cut_idle ${cuts.length} stretch(es), ${r3(removed)}s removed`);
210
+ break;
211
+ }
212
+ case "audio": {
213
+ if (s.normalize === undefined && s.denoise === undefined)
214
+ throw new ScreencastError(`step ${at}: audio needs normalize and/or denoise.`);
215
+ if (!src.hasAudio) {
216
+ summary.push("audio: the input has no audio; skipped");
217
+ break;
218
+ }
219
+ const m = opts.audio?.[i];
220
+ const did = [];
221
+ if (s.denoise !== undefined) {
222
+ if (m?.floorDb === undefined)
223
+ pend("noisefloor");
224
+ audio.push(denoiseFilter(s.denoise, m?.floorDb ?? null));
225
+ did.push(`denoise ${s.denoise}`);
226
+ }
227
+ if (s.normalize !== undefined && m?.silent)
228
+ did.push("silent, not normalized");
229
+ else if (s.normalize !== undefined) {
230
+ const t = loudnessTarget(s.normalize);
231
+ if (!m?.loudness)
232
+ pend("loudness");
233
+ audio.push(loudnormFilter(t, m?.loudness), "aresample=48000");
234
+ did.push(`normalize to ${t.i} LUFS${m?.loudness ? ` (measured ${m.loudness.input_i})` : ""}`);
235
+ }
236
+ audioReencode = true;
237
+ summary.push(`audio: ${did.join(", ")}`);
238
+ break;
239
+ }
240
+ case "burn_subtitles": {
241
+ if (!s.subtitles === !s.transcribe)
242
+ throw new ScreencastError(`step ${at}: burn_subtitles takes subtitles (a path) or transcribe: true.`);
243
+ if (s.transcribe && !src.hasAudio)
244
+ throw new ScreencastError(`step ${at}: transcribe needs audio, and the input has none.`);
245
+ const file = opts.subtitles?.[i];
246
+ if (file === "") {
247
+ summary.push("burn_subtitles: no cues in this part of the video; skipped");
248
+ break;
249
+ }
250
+ if (file === undefined)
251
+ pend(s.transcribe ? "transcribe" : "subtitles");
252
+ const ass = !!s.subtitles && /\.(ass|ssa)$/i.test(s.subtitles);
253
+ const style = s.style ?? (ass ? null : "clean");
254
+ chain(subtitlesFilter(file ?? "<subtitles.srt>", opts.fontsDir ?? "<fonts>", style));
255
+ summary.push(`burn_subtitles ${s.transcribe ? "from a transcript" : "from a file"}, ${style ?? "file"} style`);
256
+ break;
257
+ }
258
+ case "backdrop": {
259
+ const { op: _op, ...bo } = s;
260
+ const { steps: st, out: o, extraInputs: ex, layout } = backdropSteps(bo, { width: W, height: H }, cur, nextInput, tag);
261
+ geo = null;
262
+ graph.push(...st);
263
+ extraInputs.push(...ex);
264
+ nextInput += ex.length / 2;
265
+ cur = o;
266
+ W = layout.canvasW;
267
+ H = layout.canvasH;
268
+ summary.push(`backdrop to ${W}x${H}`);
269
+ break;
270
+ }
271
+ case "keystroke_overlay": {
272
+ const k = opts.keystrokes?.[i];
273
+ if (!k)
274
+ throw new ScreencastError(`Internal: missing keystroke badges for step ${at}.`);
275
+ const badges = retimeBadges(k.badges, timeOps);
276
+ if (badges.length === 0) {
277
+ summary.push("keystroke_overlay: no badges in this part of the video");
278
+ break;
279
+ }
280
+ const { steps: st, out: o } = keystrokeSteps(groupBadges(badges), k, s, { height: H }, cur, tag);
281
+ graph.push(...st);
282
+ cur = o;
283
+ summary.push(`keystroke_overlay ${badges.length} badge(s)`);
134
284
  break;
135
285
  }
136
286
  case "export_preset": {
137
287
  const p = exportPresetParts(s.platform, s.fit ?? "pad", tag);
288
+ geo = null;
138
289
  chain(p.vf);
139
290
  if (p.af)
140
291
  audio.push(p.af);
@@ -155,16 +306,17 @@ export function planPipeline(input, output, steps, src, assets = {}, quality = "
155
306
  }
156
307
  });
157
308
  const args = ["-y", ...inputArgs, "-i", input, ...extraInputs];
158
- if (graph.length > 0) {
159
- if (src.hasAudio && audio.length > 0)
160
- graph.push(`[0:a]${audio.join(",")}[aout]`);
161
- args.push("-filter_complex", graph.join(";"), "-map", cur);
162
- }
163
- else {
164
- args.push("-map", "0:v");
165
- }
309
+ const chaptersInput = opts.chaptersFile ? args.filter((a) => a === "-i").length : -1;
310
+ if (opts.chaptersFile)
311
+ args.push("-f", "ffmetadata", "-i", opts.chaptersFile);
312
+ const audioGraph = src.hasAudio && audio.length > 0;
313
+ if (audioGraph)
314
+ graph.push(`[0:a]${audio.join(",")}[aout]`);
315
+ if (graph.length > 0)
316
+ args.push("-filter_complex", graph.join(";"));
317
+ args.push("-map", cur === "[0:v]" ? "0:v" : cur);
166
318
  if (src.hasAudio)
167
- args.push("-map", audio.length > 0 && graph.length > 0 ? "[aout]" : "0:a");
319
+ args.push("-map", audioGraph ? "[aout]" : "0:a");
168
320
  const finalEncode = encode;
169
321
  if (finalEncode) {
170
322
  args.push(...finalEncode);
@@ -175,6 +327,8 @@ export function planPipeline(input, output, steps, src, assets = {}, quality = "
175
327
  args.push(...(audioReencode ? ["-c:a", "aac", "-b:a", "160k"] : ["-c:a", "copy"]));
176
328
  args.push("-movflags", "+faststart");
177
329
  }
330
+ if (chaptersInput !== -1)
331
+ args.push("-map_chapters", String(chaptersInput));
178
332
  args.push(output);
179
- return { args, width: W, height: H, fps, durationSec: dur === null ? null : r3(dur), gif, summary };
333
+ return { args, width: W, height: H, fps, durationSec: dur === null ? null : r3(dur), gif, summary, timeOps, pending };
180
334
  }
@@ -0,0 +1,67 @@
1
+ import { ScreencastError } from "./errors.js";
2
+ export const RECIPES = ["pr_demo", "tutorial", "social_reel"];
3
+ export const PR_DEMO_MAX_BYTES = 10_000_000;
4
+ const EXPORTS = new Set(["export_preset", "export_gif"]);
5
+ export function recipeSteps(recipe, ctx) {
6
+ const notes = [];
7
+ const steps = [{ op: "cut_idle" }];
8
+ if (ctx.hasClicks)
9
+ steps.push({ op: "zoom", follow: "clicks" });
10
+ else
11
+ notes.push("zoom left out: no event log with clicks (record with start_recording events: true).");
12
+ const captions = (style) => {
13
+ if (!ctx.hasAudio)
14
+ return;
15
+ if (ctx.transcribeBlocker)
16
+ notes.push(`captions left out: ${ctx.transcribeBlocker}`);
17
+ else
18
+ steps.push({ op: "burn_subtitles", transcribe: true, style });
19
+ };
20
+ if (!ctx.hasAudio && recipe !== "pr_demo")
21
+ notes.push("audio and captions left out: the input has no audio.");
22
+ switch (recipe) {
23
+ case "pr_demo":
24
+ steps.push({ op: "export_gif", maxBytes: PR_DEMO_MAX_BYTES });
25
+ break;
26
+ case "tutorial":
27
+ if (ctx.hasAudio)
28
+ steps.push({ op: "audio", denoise: "light", normalize: "youtube" });
29
+ captions("clean");
30
+ steps.push({ op: "export_preset", platform: "youtube" });
31
+ break;
32
+ case "social_reel":
33
+ if (ctx.hasAudio)
34
+ steps.push({ op: "audio", normalize: "youtube" });
35
+ steps.push({ op: "reframe", aspect: "9:16" });
36
+ captions("social");
37
+ steps.push({ op: "export_preset", platform: "instagram_reel" });
38
+ break;
39
+ default:
40
+ throw new ScreencastError(`Unknown recipe "${String(recipe)}".`);
41
+ }
42
+ return { steps, notes };
43
+ }
44
+ export function applyOverrides(base, overrides) {
45
+ const out = [...base];
46
+ const tail = out.at(-1) && EXPORTS.has(out.at(-1).op) ? out.pop() : null;
47
+ let exportStep = tail;
48
+ const recipeLen = out.length;
49
+ const replaced = new Set();
50
+ const first = [];
51
+ for (const o of overrides) {
52
+ if (EXPORTS.has(o.op)) {
53
+ exportStep = o;
54
+ continue;
55
+ }
56
+ const i = out.findIndex((s, j) => j < recipeLen && !replaced.has(j) && s.op === o.op);
57
+ if (i === -1 && o.op === "trim")
58
+ first.push(o);
59
+ else if (i === -1)
60
+ out.push(o);
61
+ else {
62
+ out[i] = o;
63
+ replaced.add(i);
64
+ }
65
+ }
66
+ return [...first, ...out, ...(exportStep ? [exportStep] : [])];
67
+ }