@tmhs/screencast-mcp 0.49.1 → 0.50.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.
- package/README.md +13 -8
- package/dist/index.js +550 -106
- package/dist/wgcRecorder.js +15 -139
- package/package.json +8 -4
- package/assets/.gitkeep +0 -0
- package/assets/icon.png +0 -0
- package/dist/cli.js +0 -516
- package/dist/context.js +0 -50
- package/dist/prompts.js +0 -95
- package/dist/resources.js +0 -93
- package/dist/server.js +0 -174
- package/dist/setup.js +0 -438
- package/dist/tools/addMarker.js +0 -93
- package/dist/tools/assembleHighlights.js +0 -69
- package/dist/tools/backdrop.js +0 -79
- package/dist/tools/bugReport.js +0 -243
- package/dist/tools/burnSubtitles.js +0 -56
- package/dist/tools/callout.js +0 -62
- package/dist/tools/chapters.js +0 -156
- package/dist/tools/clip.js +0 -52
- package/dist/tools/compress.js +0 -51
- package/dist/tools/concat.js +0 -67
- package/dist/tools/contactSheet.js +0 -113
- package/dist/tools/convert.js +0 -46
- package/dist/tools/crop.js +0 -43
- package/dist/tools/cursor.js +0 -67
- package/dist/tools/cutByTranscript.js +0 -86
- package/dist/tools/cutIdle.js +0 -84
- package/dist/tools/deleteRecording.js +0 -119
- package/dist/tools/denoise.js +0 -60
- package/dist/tools/doctor.js +0 -146
- package/dist/tools/exportGif.js +0 -57
- package/dist/tools/exportPreset.js +0 -48
- package/dist/tools/extractAudio.js +0 -65
- package/dist/tools/findText.js +0 -194
- package/dist/tools/getMediaInfo.js +0 -36
- package/dist/tools/getSession.js +0 -40
- package/dist/tools/indexRecording.js +0 -195
- package/dist/tools/keystrokeOverlay.js +0 -90
- package/dist/tools/listAudioDevices.js +0 -35
- package/dist/tools/listSessions.js +0 -28
- package/dist/tools/listTargets.js +0 -76
- package/dist/tools/listVideoDevices.js +0 -26
- package/dist/tools/musicBed.js +0 -55
- package/dist/tools/narrate.js +0 -86
- package/dist/tools/normalizeAudio.js +0 -59
- package/dist/tools/overlay.js +0 -62
- package/dist/tools/pauseRecording.js +0 -44
- package/dist/tools/pipeline.js +0 -397
- package/dist/tools/readEvents.js +0 -98
- package/dist/tools/redactRegion.js +0 -62
- package/dist/tools/reframe.js +0 -46
- package/dist/tools/resumeRecording.js +0 -46
- package/dist/tools/reviewRecording.js +0 -163
- package/dist/tools/sampleFrames.js +0 -200
- package/dist/tools/saveReplay.js +0 -90
- package/dist/tools/scale.js +0 -44
- package/dist/tools/screenDiff.js +0 -86
- package/dist/tools/screenshot.js +0 -76
- package/dist/tools/searchRecording.js +0 -79
- package/dist/tools/speed.js +0 -46
- package/dist/tools/startRecording.js +0 -398
- package/dist/tools/stepGuide.js +0 -249
- package/dist/tools/stopRecording.js +0 -132
- package/dist/tools/titleCard.js +0 -67
- package/dist/tools/transcribe.js +0 -66
- package/dist/tools/trim.js +0 -57
- package/dist/tools/waitForChange.js +0 -142
- package/dist/tools/xfadeTransition.js +0 -58
- package/dist/tools/zoom.js +0 -134
- package/dist/utils/anim.js +0 -54
- package/dist/utils/animExport.js +0 -56
- package/dist/utils/argPaths.js +0 -39
- package/dist/utils/audio.js +0 -117
- package/dist/utils/audioDevices.js +0 -107
- package/dist/utils/backdrop.js +0 -162
- package/dist/utils/bugReport.js +0 -195
- package/dist/utils/callout.js +0 -132
- package/dist/utils/calloutAssets.js +0 -42
- package/dist/utils/capabilities.js +0 -96
- package/dist/utils/captions.js +0 -104
- package/dist/utils/chapters.js +0 -227
- package/dist/utils/consent.js +0 -29
- package/dist/utils/cursor.js +0 -338
- package/dist/utils/diff.js +0 -186
- package/dist/utils/errors.js +0 -29
- package/dist/utils/events.js +0 -403
- package/dist/utils/expr.js +0 -11
- package/dist/utils/ffmpeg.js +0 -285
- package/dist/utils/fontCoverage.js +0 -177
- package/dist/utils/fonts.js +0 -154
- package/dist/utils/frameQueue.js +0 -50
- package/dist/utils/gpu.js +0 -219
- package/dist/utils/idle.js +0 -91
- package/dist/utils/images.js +0 -38
- package/dist/utils/jobs.js +0 -129
- package/dist/utils/keystrokes.js +0 -198
- package/dist/utils/lifecycle.js +0 -233
- package/dist/utils/logging.js +0 -75
- package/dist/utils/media.js +0 -584
- package/dist/utils/monitors.js +0 -124
- package/dist/utils/narrate.js +0 -233
- package/dist/utils/ocr.js +0 -222
- package/dist/utils/ocrScan.js +0 -93
- package/dist/utils/paths.js +0 -155
- package/dist/utils/pause.js +0 -190
- package/dist/utils/pipeline.js +0 -361
- package/dist/utils/player.js +0 -85
- package/dist/utils/pool.js +0 -29
- package/dist/utils/produce.js +0 -300
- package/dist/utils/recipes.js +0 -71
- package/dist/utils/recorder.js +0 -173
- package/dist/utils/recordingFiles.js +0 -32
- package/dist/utils/recordingIndex.js +0 -312
- package/dist/utils/replay.js +0 -283
- package/dist/utils/resolveTarget.js +0 -25
- package/dist/utils/retention.js +0 -48
- package/dist/utils/roots.js +0 -43
- package/dist/utils/sessions.js +0 -499
- package/dist/utils/sheet.js +0 -82
- package/dist/utils/stepGuide.js +0 -231
- package/dist/utils/steps.js +0 -88
- package/dist/utils/still.js +0 -38
- package/dist/utils/targetList.js +0 -64
- package/dist/utils/targets.js +0 -265
- package/dist/utils/timeline.js +0 -85
- package/dist/utils/toolSpec.js +0 -31
- package/dist/utils/toolsets.js +0 -134
- package/dist/utils/transcriptCut.js +0 -149
- package/dist/utils/validate.js +0 -23
- package/dist/utils/waitLoop.js +0 -50
- package/dist/utils/wgc.js +0 -84
- package/dist/utils/windows.js +0 -192
- package/dist/utils/zoom.js +0 -252
package/dist/utils/diff.js
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import { ScreencastError } from "./errors.js";
|
|
2
|
-
import { targetInputArgs } from "./targets.js";
|
|
3
|
-
import { stillOutput } from "./paths.js";
|
|
4
|
-
export const ANALYSIS_WIDTH = 320;
|
|
5
|
-
export const SOURCE_PX_PER_ANALYSIS_PX = 4;
|
|
6
|
-
export const MAX_DETECTION_WIDTH = 1600;
|
|
7
|
-
export const CELL = 8;
|
|
8
|
-
export const DEFAULT_PIXEL_THRESHOLD = 12;
|
|
9
|
-
export function analysisSize(width, height) {
|
|
10
|
-
if (!(width > 0) || !(height > 0))
|
|
11
|
-
throw new ScreencastError("Image has no size.");
|
|
12
|
-
const w = Math.min(ANALYSIS_WIDTH, width);
|
|
13
|
-
const h = Math.max(2, Math.round((height * w) / width / 2) * 2);
|
|
14
|
-
return { width: Math.max(2, Math.round(w / 2) * 2), height: h };
|
|
15
|
-
}
|
|
16
|
-
export function detectionSize(width, height) {
|
|
17
|
-
if (!(width > 0) || !(height > 0))
|
|
18
|
-
throw new ScreencastError("Image has no size.");
|
|
19
|
-
const w = Math.min(width, Math.max(ANALYSIS_WIDTH, Math.min(MAX_DETECTION_WIDTH, Math.ceil(width / SOURCE_PX_PER_ANALYSIS_PX))));
|
|
20
|
-
const h = Math.max(2, Math.round((height * w) / width / 2) * 2);
|
|
21
|
-
return { width: Math.max(2, Math.round(w / 2) * 2), height: h };
|
|
22
|
-
}
|
|
23
|
-
export function targetSize(target, monitors) {
|
|
24
|
-
switch (target.kind) {
|
|
25
|
-
case "region":
|
|
26
|
-
return { x: target.x, y: target.y, width: target.w, height: target.h };
|
|
27
|
-
case "monitor": {
|
|
28
|
-
const m = monitors.find((mm) => mm.index === target.index);
|
|
29
|
-
if (!m)
|
|
30
|
-
throw new ScreencastError(`No monitor ${target.index}.`);
|
|
31
|
-
return { x: m.x, y: m.y, width: m.width, height: m.height };
|
|
32
|
-
}
|
|
33
|
-
case "full": {
|
|
34
|
-
if (monitors.length === 0)
|
|
35
|
-
throw new ScreencastError("No monitors found.");
|
|
36
|
-
const left = Math.min(...monitors.map((m) => m.x));
|
|
37
|
-
const top = Math.min(...monitors.map((m) => m.y));
|
|
38
|
-
const right = Math.max(...monitors.map((m) => m.x + m.width));
|
|
39
|
-
const bottom = Math.max(...monitors.map((m) => m.y + m.height));
|
|
40
|
-
return { x: left, y: top, width: right - left, height: bottom - top };
|
|
41
|
-
}
|
|
42
|
-
default:
|
|
43
|
-
throw new ScreencastError("Internal: resolve window targets to a region first.");
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
export function meanDifference(a, b) {
|
|
47
|
-
if (a.length !== b.length || a.length === 0)
|
|
48
|
-
throw new ScreencastError("Frames differ in size.");
|
|
49
|
-
let sum = 0;
|
|
50
|
-
for (let i = 0; i < a.length; i++)
|
|
51
|
-
sum += Math.abs(a[i] - b[i]);
|
|
52
|
-
return sum / a.length / 255;
|
|
53
|
-
}
|
|
54
|
-
export function diffFrames(a, b, width, height, opts = {}) {
|
|
55
|
-
if (a.length !== width * height || b.length !== width * height) {
|
|
56
|
-
throw new ScreencastError("Frame size does not match its dimensions.");
|
|
57
|
-
}
|
|
58
|
-
const threshold = opts.pixelThreshold ?? DEFAULT_PIXEL_THRESHOLD;
|
|
59
|
-
const cols = Math.ceil(width / CELL);
|
|
60
|
-
const rows = Math.ceil(height / CELL);
|
|
61
|
-
const changed = new Uint8Array(cols * rows);
|
|
62
|
-
for (let cy = 0; cy < rows; cy++) {
|
|
63
|
-
for (let cx = 0; cx < cols; cx++) {
|
|
64
|
-
let sum = 0;
|
|
65
|
-
let n = 0;
|
|
66
|
-
for (let y = cy * CELL; y < Math.min(height, (cy + 1) * CELL); y++) {
|
|
67
|
-
for (let x = cx * CELL; x < Math.min(width, (cx + 1) * CELL); x++) {
|
|
68
|
-
const i = y * width + x;
|
|
69
|
-
sum += Math.abs(a[i] - b[i]);
|
|
70
|
-
n++;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
if (sum / n > threshold)
|
|
74
|
-
changed[cy * cols + cx] = 1;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
const seen = new Uint8Array(cols * rows);
|
|
78
|
-
const boxes = [];
|
|
79
|
-
for (let start = 0; start < changed.length; start++) {
|
|
80
|
-
if (!changed[start] || seen[start])
|
|
81
|
-
continue;
|
|
82
|
-
const box = { x0: Infinity, y0: Infinity, x1: -1, y1: -1, cells: 0 };
|
|
83
|
-
const stack = [start];
|
|
84
|
-
seen[start] = 1;
|
|
85
|
-
while (stack.length > 0) {
|
|
86
|
-
const c = stack.pop();
|
|
87
|
-
const cx = c % cols;
|
|
88
|
-
const cy = Math.floor(c / cols);
|
|
89
|
-
box.x0 = Math.min(box.x0, cx);
|
|
90
|
-
box.y0 = Math.min(box.y0, cy);
|
|
91
|
-
box.x1 = Math.max(box.x1, cx);
|
|
92
|
-
box.y1 = Math.max(box.y1, cy);
|
|
93
|
-
box.cells++;
|
|
94
|
-
for (let dy = -1; dy <= 1; dy++) {
|
|
95
|
-
for (let dx = -1; dx <= 1; dx++) {
|
|
96
|
-
const nx = cx + dx;
|
|
97
|
-
const ny = cy + dy;
|
|
98
|
-
if (nx < 0 || ny < 0 || nx >= cols || ny >= rows)
|
|
99
|
-
continue;
|
|
100
|
-
const nc = ny * cols + nx;
|
|
101
|
-
if (changed[nc] && !seen[nc]) {
|
|
102
|
-
seen[nc] = 1;
|
|
103
|
-
stack.push(nc);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
boxes.push(box);
|
|
109
|
-
}
|
|
110
|
-
const sx = opts.scaleX ?? opts.scale ?? 1;
|
|
111
|
-
const sy = opts.scaleY ?? opts.scale ?? 1;
|
|
112
|
-
const ox = opts.origin?.x ?? 0;
|
|
113
|
-
const oy = opts.origin?.y ?? 0;
|
|
114
|
-
const regions = boxes
|
|
115
|
-
.sort((p, q) => q.cells - p.cells)
|
|
116
|
-
.slice(0, opts.maxRegions ?? 20)
|
|
117
|
-
.map((bx) => {
|
|
118
|
-
const x = bx.x0 * CELL;
|
|
119
|
-
const y = bx.y0 * CELL;
|
|
120
|
-
const w = Math.min(width, (bx.x1 + 1) * CELL) - x;
|
|
121
|
-
const h = Math.min(height, (bx.y1 + 1) * CELL) - y;
|
|
122
|
-
return {
|
|
123
|
-
x: ox + Math.round(x * sx),
|
|
124
|
-
y: oy + Math.round(y * sy),
|
|
125
|
-
width: Math.round(w * sx),
|
|
126
|
-
height: Math.round(h * sy),
|
|
127
|
-
};
|
|
128
|
-
});
|
|
129
|
-
const changedCount = changed.reduce((s, v) => s + v, 0);
|
|
130
|
-
return { meanDiff: meanDifference(a, b), changedFraction: changedCount / changed.length, regions };
|
|
131
|
-
}
|
|
132
|
-
export function targetDiffOptions(area, size, pixelThreshold) {
|
|
133
|
-
return { scaleX: area.width / size.width, scaleY: area.height / size.height, pixelThreshold };
|
|
134
|
-
}
|
|
135
|
-
export class SettleTracker {
|
|
136
|
-
width;
|
|
137
|
-
height;
|
|
138
|
-
opts;
|
|
139
|
-
previous;
|
|
140
|
-
anchor;
|
|
141
|
-
constructor(first, width, height, opts = {}) {
|
|
142
|
-
this.width = width;
|
|
143
|
-
this.height = height;
|
|
144
|
-
this.opts = opts;
|
|
145
|
-
this.previous = first;
|
|
146
|
-
this.anchor = first;
|
|
147
|
-
}
|
|
148
|
-
push(frame) {
|
|
149
|
-
const step = diffFrames(this.previous, frame, this.width, this.height, this.opts).regions;
|
|
150
|
-
const drift = step.length > 0 ? step : diffFrames(this.anchor, frame, this.width, this.height, this.opts).regions;
|
|
151
|
-
this.previous = frame;
|
|
152
|
-
if (drift.length > 0)
|
|
153
|
-
this.anchor = frame;
|
|
154
|
-
return drift;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
export function buildRawFrameArgs(input, size) {
|
|
158
|
-
return [
|
|
159
|
-
"-v", "error", "-i", input, "-frames:v", "1",
|
|
160
|
-
"-vf", `scale=${size.width}:${size.height}:flags=area,format=gray`,
|
|
161
|
-
"-f", "rawvideo", "-",
|
|
162
|
-
];
|
|
163
|
-
}
|
|
164
|
-
export function buildRawStreamArgs(target, monitors, size, fps) {
|
|
165
|
-
return [
|
|
166
|
-
"-v", "error",
|
|
167
|
-
"-probesize", "32", "-analyzeduration", "0",
|
|
168
|
-
"-f", "gdigrab", "-framerate", String(Math.round(fps * 1000) / 1000),
|
|
169
|
-
...targetInputArgs(target, monitors),
|
|
170
|
-
"-vf", `scale=${size.width}:${size.height}:flags=area,format=gray`,
|
|
171
|
-
"-flush_packets", "1",
|
|
172
|
-
"-f", "rawvideo", "-",
|
|
173
|
-
];
|
|
174
|
-
}
|
|
175
|
-
export function buildSsimArgs(a, b, size) {
|
|
176
|
-
const s = `scale=${size.width}:${size.height}:flags=area,format=gray`;
|
|
177
|
-
return ["-v", "info", "-i", a, "-i", b, "-lavfi", `[0]${s}[x];[1]${s}[y];[x][y]ssim`, "-frames:v", "1", "-f", "null", "-"];
|
|
178
|
-
}
|
|
179
|
-
export function buildHighlightArgs(input, regions, output) {
|
|
180
|
-
const boxes = regions.map((r) => `drawbox=x=${r.x}:y=${r.y}:w=${r.width}:h=${r.height}:color=red@0.9:t=3`);
|
|
181
|
-
return ["-y", "-v", "error", "-i", input, "-frames:v", "1", ...(boxes.length ? ["-vf", boxes.join(",")] : []), ...stillOutput(output)];
|
|
182
|
-
}
|
|
183
|
-
export function parseSsim(stderr) {
|
|
184
|
-
const m = stderr.match(/All:([\d.]+)/);
|
|
185
|
-
return m ? Number(m[1]) : null;
|
|
186
|
-
}
|
package/dist/utils/errors.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
export class ScreencastError extends Error {
|
|
2
|
-
hint;
|
|
3
|
-
constructor(message, hint) {
|
|
4
|
-
super(message);
|
|
5
|
-
this.name = "ScreencastError";
|
|
6
|
-
this.hint = hint;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
export function errorMessage(error) {
|
|
10
|
-
return error instanceof Error ? error.message : String(error);
|
|
11
|
-
}
|
|
12
|
-
export function okResponse(value, images = []) {
|
|
13
|
-
const text = typeof value === "string" ? value : JSON.stringify(value, null, 2);
|
|
14
|
-
const result = { content: [{ type: "text", text }, ...images] };
|
|
15
|
-
if (value !== null && typeof value === "object" && !Array.isArray(value)) {
|
|
16
|
-
result.structuredContent = JSON.parse(text);
|
|
17
|
-
}
|
|
18
|
-
return result;
|
|
19
|
-
}
|
|
20
|
-
export function errorResponse(error) {
|
|
21
|
-
let message;
|
|
22
|
-
if (error instanceof ScreencastError) {
|
|
23
|
-
message = error.hint ? `${error.message}\n\n${error.hint}` : error.message;
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
message = errorMessage(error);
|
|
27
|
-
}
|
|
28
|
-
return { content: [{ type: "text", text: message }], isError: true };
|
|
29
|
-
}
|
package/dist/utils/events.js
DELETED
|
@@ -1,403 +0,0 @@
|
|
|
1
|
-
import { spawn } from "node:child_process";
|
|
2
|
-
import { existsSync, readFileSync, writeFileSync, unlinkSync, rmSync } from "node:fs";
|
|
3
|
-
import { ScreencastError } from "./errors.js";
|
|
4
|
-
export const DEFAULT_KEY_MODE = "masked";
|
|
5
|
-
export const EVENT_TYPES = ["down", "up", "move", "wheel", "key", "typing", "gap"];
|
|
6
|
-
export const MOVE_SAMPLE_MS = 33;
|
|
7
|
-
export function parseCaptureStart(stderr, inputIndex = 0) {
|
|
8
|
-
const input = stderr.indexOf(`Input #${inputIndex},`);
|
|
9
|
-
if (input < 0)
|
|
10
|
-
return null;
|
|
11
|
-
const next = stderr.indexOf("Input #", input + 1);
|
|
12
|
-
const m = /start: (\d{9,}\.\d+)/.exec(stderr.slice(input, next < 0 ? undefined : next));
|
|
13
|
-
return m ? Math.round(Number(m[1]) * 1000) : null;
|
|
14
|
-
}
|
|
15
|
-
export function videoTimeSec(epochMs, spans) {
|
|
16
|
-
const first = spans[0];
|
|
17
|
-
if (!first)
|
|
18
|
-
return null;
|
|
19
|
-
if (epochMs < first.startMs)
|
|
20
|
-
return (epochMs - first.startMs) / 1000;
|
|
21
|
-
for (const s of spans) {
|
|
22
|
-
const rel = (epochMs - s.startMs) / 1000;
|
|
23
|
-
if (rel >= 0 && (s.durationSec === undefined || rel <= s.durationSec))
|
|
24
|
-
return s.offsetSec + rel;
|
|
25
|
-
}
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
export function convertEvents(raw, opts) {
|
|
29
|
-
const spans = opts.spans && opts.spans.length > 0 ? opts.spans : null;
|
|
30
|
-
const out = [];
|
|
31
|
-
const beats = [];
|
|
32
|
-
let missFrom = null;
|
|
33
|
-
const gap = (t, x, y, untilSec, reason) => {
|
|
34
|
-
const from = Math.max(0, t);
|
|
35
|
-
const until = opts.endSec !== undefined ? Math.min(untilSec, opts.endSec) : untilSec;
|
|
36
|
-
if (until > from)
|
|
37
|
-
out.push({ t: r3(from), type: "gap", x, y, inFrame: false, durationSec: r3(until - from), reason });
|
|
38
|
-
};
|
|
39
|
-
for (const line of raw.split(/\r?\n/)) {
|
|
40
|
-
const parts = line.split(",");
|
|
41
|
-
if (parts.length < 4)
|
|
42
|
-
continue;
|
|
43
|
-
const [ms, type, xs, ys, data = ""] = parts;
|
|
44
|
-
const epoch = Number(ms);
|
|
45
|
-
const dx = Number(xs);
|
|
46
|
-
const dy = Number(ys);
|
|
47
|
-
if (!Number.isFinite(epoch) || !Number.isFinite(dx) || !Number.isFinite(dy))
|
|
48
|
-
continue;
|
|
49
|
-
const vt = spans ? videoTimeSec(epoch, spans) : (epoch - opts.startMs) / 1000;
|
|
50
|
-
if (vt === null)
|
|
51
|
-
continue;
|
|
52
|
-
const t = Math.round(vt * 1000) / 1000;
|
|
53
|
-
if (type === "hb") {
|
|
54
|
-
beats.push(t);
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
if (type === "miss") {
|
|
58
|
-
missFrom ??= { t, x: dx - opts.frame.x, y: dy - opts.frame.y };
|
|
59
|
-
continue;
|
|
60
|
-
}
|
|
61
|
-
if (type === "resume") {
|
|
62
|
-
if (missFrom)
|
|
63
|
-
gap(missFrom.t, missFrom.x, missFrom.y, t, "input_not_seen");
|
|
64
|
-
missFrom = null;
|
|
65
|
-
continue;
|
|
66
|
-
}
|
|
67
|
-
if (type === undefined || type === "gap" || !EVENT_TYPES.includes(type))
|
|
68
|
-
continue;
|
|
69
|
-
if (t < 0 || (opts.endSec !== undefined && t > opts.endSec))
|
|
70
|
-
continue;
|
|
71
|
-
const x = dx - opts.frame.x;
|
|
72
|
-
const y = dy - opts.frame.y;
|
|
73
|
-
const ev = {
|
|
74
|
-
t,
|
|
75
|
-
type: type,
|
|
76
|
-
x,
|
|
77
|
-
y,
|
|
78
|
-
inFrame: x >= 0 && y >= 0 && x < opts.frame.w && y < opts.frame.h,
|
|
79
|
-
};
|
|
80
|
-
if (type === "down" || type === "up")
|
|
81
|
-
ev.button = data || "left";
|
|
82
|
-
if (type === "wheel") {
|
|
83
|
-
const [axis, notches] = data.split(":");
|
|
84
|
-
ev.axis = axis === "h" ? "horizontal" : "vertical";
|
|
85
|
-
ev.delta = Number(notches) || 0;
|
|
86
|
-
}
|
|
87
|
-
if (type === "key" && data)
|
|
88
|
-
ev.keys = data;
|
|
89
|
-
if (type === "typing")
|
|
90
|
-
ev.durationSec = r3((Number(data) || 0) / 1000);
|
|
91
|
-
out.push(ev);
|
|
92
|
-
}
|
|
93
|
-
const lastSec = opts.endSec ?? Math.max(0, ...out.map((e) => e.t), ...beats);
|
|
94
|
-
if (missFrom)
|
|
95
|
-
gap(missFrom.t, missFrom.x, missFrom.y, lastSec, "input_not_seen");
|
|
96
|
-
beats.sort((a, b) => a - b);
|
|
97
|
-
const last = beats.at(-1);
|
|
98
|
-
if (last !== undefined) {
|
|
99
|
-
beats.reduce((prev, beat) => {
|
|
100
|
-
if (beat - prev > HEARTBEAT_GAP_SEC)
|
|
101
|
-
gap(prev, 0, 0, beat, "helper_stalled");
|
|
102
|
-
return beat;
|
|
103
|
-
});
|
|
104
|
-
if (opts.endSec !== undefined && opts.endSec - last > HEARTBEAT_GAP_SEC)
|
|
105
|
-
gap(last, 0, 0, opts.endSec, "helper_stopped");
|
|
106
|
-
}
|
|
107
|
-
return out.sort((a, b) => a.t - b.t);
|
|
108
|
-
}
|
|
109
|
-
const r3 = (n) => Math.round(n * 1000) / 1000;
|
|
110
|
-
export function eventGaps(events) {
|
|
111
|
-
return events
|
|
112
|
-
.filter((e) => e.type === "gap")
|
|
113
|
-
.map((e) => ({ t: e.t, durationSec: e.durationSec ?? 0, reason: e.reason ?? "input_not_seen" }));
|
|
114
|
-
}
|
|
115
|
-
export function formatEventsJsonl(events) {
|
|
116
|
-
return events.map((e) => JSON.stringify(e)).join("\n") + (events.length ? "\n" : "");
|
|
117
|
-
}
|
|
118
|
-
export function parseEventsJsonl(text) {
|
|
119
|
-
const out = [];
|
|
120
|
-
for (const line of text.split(/\r?\n/)) {
|
|
121
|
-
if (!line.trim())
|
|
122
|
-
continue;
|
|
123
|
-
try {
|
|
124
|
-
out.push(JSON.parse(line));
|
|
125
|
-
}
|
|
126
|
-
catch {
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
return out;
|
|
130
|
-
}
|
|
131
|
-
export function selectEvents(events, q) {
|
|
132
|
-
return events.filter((e) => (q.from === undefined || e.t >= q.from) &&
|
|
133
|
-
(q.to === undefined || e.t <= q.to) &&
|
|
134
|
-
(!q.types || q.types.includes(e.type)) &&
|
|
135
|
-
(!q.inFrameOnly || e.inFrame));
|
|
136
|
-
}
|
|
137
|
-
export function summarizeEvents(events) {
|
|
138
|
-
const counts = {};
|
|
139
|
-
for (const e of events) {
|
|
140
|
-
const key = e.type === "down" ? "clicks"
|
|
141
|
-
: e.type === "move" ? "moves"
|
|
142
|
-
: e.type === "key" ? "shortcuts"
|
|
143
|
-
: e.type === "typing" ? "typingBursts"
|
|
144
|
-
: e.type === "wheel" ? "scrolls"
|
|
145
|
-
: e.type === "gap" ? "gaps"
|
|
146
|
-
: null;
|
|
147
|
-
if (key)
|
|
148
|
-
counts[key] = (counts[key] ?? 0) + 1;
|
|
149
|
-
}
|
|
150
|
-
return counts;
|
|
151
|
-
}
|
|
152
|
-
export const TYPING_GRAIN_MS = 500;
|
|
153
|
-
export const TYPING_GAP_MS = 1000;
|
|
154
|
-
export const MISSED_INPUT_MS = 2000;
|
|
155
|
-
export const HEARTBEAT_GAP_SEC = 3;
|
|
156
|
-
const PS_HOOK = `
|
|
157
|
-
$ErrorActionPreference='Stop'
|
|
158
|
-
$ProgressPreference='SilentlyContinue'
|
|
159
|
-
Add-Type @"
|
|
160
|
-
#pragma warning disable 649
|
|
161
|
-
using System;using System.IO;using System.Text;using System.Threading;using System.Diagnostics;using System.Collections.Generic;using System.Runtime.InteropServices;
|
|
162
|
-
public static class ScEvents{
|
|
163
|
-
delegate IntPtr Proc(int n,IntPtr w,IntPtr l);
|
|
164
|
-
[DllImport("user32.dll")] static extern IntPtr SetWindowsHookEx(int id,Proc p,IntPtr mod,uint tid);
|
|
165
|
-
[DllImport("user32.dll")] static extern IntPtr CallNextHookEx(IntPtr h,int n,IntPtr w,IntPtr l);
|
|
166
|
-
[DllImport("user32.dll")] static extern int GetMessage(out MSG m,IntPtr h,uint a,uint b);
|
|
167
|
-
[DllImport("user32.dll")] static extern short GetAsyncKeyState(int vk);
|
|
168
|
-
[DllImport("user32.dll")] static extern IntPtr SetProcessDpiAwarenessContext(IntPtr v);
|
|
169
|
-
[DllImport("kernel32.dll")] static extern IntPtr GetModuleHandle(string n);
|
|
170
|
-
[DllImport("kernel32.dll")] static extern void GetSystemTimePreciseAsFileTime(out long t);
|
|
171
|
-
struct MSG{public IntPtr h;public uint m;public IntPtr w;public IntPtr l;public uint t;public int x;public int y;}
|
|
172
|
-
struct MS{public int x;public int y;public uint data;public uint flags;public uint time;public IntPtr extra;}
|
|
173
|
-
struct KB{public uint vk;public uint scan;public uint flags;public uint time;public IntPtr extra;}
|
|
174
|
-
[DllImport("user32.dll")] static extern bool GetLastInputInfo(ref LII i);
|
|
175
|
-
[DllImport("user32.dll")] static extern IntPtr GetForegroundWindow();
|
|
176
|
-
[DllImport("user32.dll")] static extern uint GetWindowThreadProcessId(IntPtr h,IntPtr p);
|
|
177
|
-
[DllImport("user32.dll")] static extern IntPtr GetKeyboardLayout(uint t);
|
|
178
|
-
[DllImport("user32.dll")] static extern int ToUnicodeEx(uint vk,uint scan,byte[] ks,[Out,MarshalAs(UnmanagedType.LPWStr)] StringBuilder b,int n,uint f,IntPtr hkl);
|
|
179
|
-
struct LII{public uint cb;public uint t;}
|
|
180
|
-
static Proc mp,kp;static StreamWriter w;static bool sc;static double lastMove;static int cx,cy;
|
|
181
|
-
static readonly object wl=new object();static string P;public static int Rot;static int lastRot;
|
|
182
|
-
static HashSet<uint> held=new HashSet<uint>();
|
|
183
|
-
static readonly object q=new object();static StringBuilder buf=new StringBuilder();
|
|
184
|
-
static double typeStart=-1,typeLast;static int lastHook=Environment.TickCount;static bool missing;
|
|
185
|
-
static readonly IFormatProvider Inv=System.Globalization.CultureInfo.InvariantCulture;
|
|
186
|
-
static double Now(){long t;GetSystemTimePreciseAsFileTime(out t);return (t-116444736000000000L)/10000.0;}
|
|
187
|
-
// The hooks only append to a buffer; the pump thread writes it. Slow file
|
|
188
|
-
// I/O inside a hook makes Windows drop the hook without notice (#210).
|
|
189
|
-
static void Line(double t,string type,int x,int y,string data){lock(q){buf.Append(t.ToString("F1",Inv)).Append(',').Append(type).Append(',').Append(x).Append(',').Append(y).Append(',').Append(data).Append('\\n');}}
|
|
190
|
-
static void Put(string type,int x,int y,string data){Line(Now(),type,x,y,data);}
|
|
191
|
-
static bool Down(int vk){return (GetAsyncKeyState(vk)&0x8000)!=0;}
|
|
192
|
-
static void Seen(){lastHook=Environment.TickCount;if(missing){missing=false;Put("resume",cx,cy,"");}}
|
|
193
|
-
// Typed keys become bursts on a ${TYPING_GRAIN_MS} ms grid, so the log holds no per-key timing.
|
|
194
|
-
static void Typed(){double t=Now();lock(q){if(typeStart<0)typeStart=t;typeLast=t;}}
|
|
195
|
-
static void EndTyping(bool force){double s,e;lock(q){if(typeStart<0||(!force&&Now()-typeLast<${TYPING_GAP_MS}))return;s=typeStart;e=typeLast;typeStart=-1;}
|
|
196
|
-
double g=${TYPING_GRAIN_MS};double s2=Math.Floor(s/g)*g,e2=Math.Max(s2+g,Math.Ceiling(e/g)*g);Line(s2,"typing",cx,cy,(e2-s2).ToString("F0",Inv));}
|
|
197
|
-
static void Drain(){lock(wl){string s;lock(q){s=buf.ToString();buf.Clear();}if(s.Length>0){w.Write(s);w.Flush();}}}
|
|
198
|
-
static void Quit(){EndTyping(true);Drain();lock(wl){w.Close();}Process.GetCurrentProcess().Kill();}
|
|
199
|
-
// Replay buffers (#258): every Rot ms the log becomes path.1 (replacing the one before), so it never holds much more than two periods.
|
|
200
|
-
static void Rotate(){lock(wl){w.Close();try{string old=P+".1";if(File.Exists(old))File.Delete(old);File.Move(P,old);}catch{}w=new StreamWriter(P,true,new UTF8Encoding(false));}}
|
|
201
|
-
static void Pump(string stop){int tick=0;while(true){Thread.Sleep(250);tick++;
|
|
202
|
-
EndTyping(false);
|
|
203
|
-
lock(held){foreach(uint vk in new List<uint>(held)){if(!Down((int)vk))held.Remove(vk);}}
|
|
204
|
-
LII li=new LII();li.cb=8;if(!missing&&GetLastInputInfo(ref li)&&unchecked((int)li.t-lastHook)>${MISSED_INPUT_MS}){missing=true;Put("miss",cx,cy,"");}
|
|
205
|
-
if(tick%4==0)Put("hb",0,0,"");
|
|
206
|
-
if(File.Exists(stop))Quit();
|
|
207
|
-
Drain();
|
|
208
|
-
if(Rot>0&&unchecked(Environment.TickCount-lastRot)>=Rot){lastRot=Environment.TickCount;Rotate();}}}
|
|
209
|
-
static IntPtr Mouse(int n,IntPtr wp,IntPtr lp){
|
|
210
|
-
if(n>=0){Seen();MS s=(MS)Marshal.PtrToStructure(lp,typeof(MS));int m=(int)wp;cx=s.x;cy=s.y;
|
|
211
|
-
if(m==0x200){double t=Now();if(t-lastMove>=${MOVE_SAMPLE_MS}){lastMove=t;Put("move",s.x,s.y,"");}}
|
|
212
|
-
else if(m==0x201)Put("down",s.x,s.y,"left");else if(m==0x202)Put("up",s.x,s.y,"left");
|
|
213
|
-
else if(m==0x204)Put("down",s.x,s.y,"right");else if(m==0x205)Put("up",s.x,s.y,"right");
|
|
214
|
-
else if(m==0x207)Put("down",s.x,s.y,"middle");else if(m==0x208)Put("up",s.x,s.y,"middle");
|
|
215
|
-
else if(m==0x20B||m==0x20C){string b=((s.data>>16)==1)?"x1":"x2";Put(m==0x20B?"down":"up",s.x,s.y,b);}
|
|
216
|
-
else if(m==0x20A||m==0x20E){short d=(short)(s.data>>16);Put("wheel",s.x,s.y,(m==0x20E?"h:":"v:")+(d/120.0).ToString(System.Globalization.CultureInfo.InvariantCulture));}}
|
|
217
|
-
return CallNextHookEx(IntPtr.Zero,n,wp,lp);}
|
|
218
|
-
static string Name(uint vk){
|
|
219
|
-
if(vk>=0x41&&vk<=0x5A)return ((char)vk).ToString();if(vk>=0x30&&vk<=0x39)return ((char)vk).ToString();
|
|
220
|
-
if(vk>=0x70&&vk<=0x87)return "F"+(vk-0x6F);
|
|
221
|
-
switch(vk){case 0x0D:return "Enter";case 0x09:return "Tab";case 0x1B:return "Esc";case 0x20:return "Space";case 0x08:return "Backspace";case 0x2E:return "Delete";case 0x2D:return "Insert";
|
|
222
|
-
case 0x25:return "Left";case 0x26:return "Up";case 0x27:return "Right";case 0x28:return "Down";case 0x24:return "Home";case 0x23:return "End";case 0x21:return "PageUp";case 0x22:return "PageDown";
|
|
223
|
-
case 0xBB:return "=";case 0xBD:return "-";case 0xBC:return ",";case 0xBE:return ".";case 0xBF:return "/";case 0xC0:return "\`";case 0xDB:return "[";case 0xDD:return "]";case 0xBA:return ";";case 0xDE:return "'";case 0xDC:return "\\\\";}
|
|
224
|
-
return null;}
|
|
225
|
-
static bool IsMod(uint vk){return vk==0x10||vk==0x11||vk==0x12||(vk>=0xA0&&vk<=0xA5)||vk==0x5B||vk==0x5C;}
|
|
226
|
-
// Ctrl+Alt+key types a character on AltGr layouts (Polish, German...): that is text, not a chord.
|
|
227
|
-
static bool Types(KB k,bool shift){var ks=new byte[256];ks[0x11]=ks[0xA2]=ks[0x12]=ks[0xA4]=0x80;if(shift)ks[0x10]=ks[0xA0]=0x80;
|
|
228
|
-
var b=new StringBuilder(8);int r=ToUnicodeEx(k.vk,k.scan,ks,b,8,4,GetKeyboardLayout(GetWindowThreadProcessId(GetForegroundWindow(),IntPtr.Zero)));
|
|
229
|
-
return r<0||(r>0&&b.Length>0&&!char.IsControl(b[0]));}
|
|
230
|
-
static IntPtr Key(int n,IntPtr wp,IntPtr lp){
|
|
231
|
-
if(n>=0){Seen();KB k=(KB)Marshal.PtrToStructure(lp,typeof(KB));int m=(int)wp;bool fresh;
|
|
232
|
-
if(m==0x101||m==0x105){lock(held){held.Remove(k.vk);}}
|
|
233
|
-
else if(m==0x100||m==0x104){lock(held){fresh=!IsMod(k.vk)&&held.Add(k.vk);}
|
|
234
|
-
if(fresh){string chord="";
|
|
235
|
-
if(sc&&!Down(0xA5)){bool ctl=Down(0x11),alt=Down(0x12),win=Down(0x5B)||Down(0x5C),sh=Down(0x10);string nm=Name(k.vk);
|
|
236
|
-
if((ctl||alt||win)&&nm!=null&&!(ctl&&alt&&!win&&Types(k,sh))){chord=(ctl?"Ctrl+":"")+(alt?"Alt+":"")+(sh?"Shift+":"")+(win?"Win+":"")+nm;}}
|
|
237
|
-
if(chord.Length>0)Put("key",cx,cy,chord);else Typed();}}}
|
|
238
|
-
return CallNextHookEx(IntPtr.Zero,n,wp,lp);}
|
|
239
|
-
public static void Run(string path,bool shortcuts,int parent){
|
|
240
|
-
try{SetProcessDpiAwarenessContext(new IntPtr(-4));}catch{}
|
|
241
|
-
sc=shortcuts;P=path;lastRot=Environment.TickCount;w=new StreamWriter(path,true,new UTF8Encoding(false));
|
|
242
|
-
IntPtr mod=GetModuleHandle(null);mp=Mouse;kp=Key;
|
|
243
|
-
if(SetWindowsHookEx(14,mp,mod,0)==IntPtr.Zero||SetWindowsHookEx(13,kp,mod,0)==IntPtr.Zero)throw new Exception("SetWindowsHookEx failed: "+Marshal.GetLastWin32Error());
|
|
244
|
-
var watch=new Thread(()=>{while(true){Thread.Sleep(500);bool gone;try{gone=Process.GetProcessById(parent).HasExited;}catch{gone=true;}if(gone)Quit();}});
|
|
245
|
-
watch.IsBackground=true;watch.Start();
|
|
246
|
-
var pump=new Thread(()=>Pump(path+".stop"));pump.IsBackground=true;pump.Start();
|
|
247
|
-
Console.Out.WriteLine("ready");Console.Out.Flush();
|
|
248
|
-
MSG msg;while(GetMessage(out msg,IntPtr.Zero,0,0)>0){}
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
"@
|
|
252
|
-
[ScEvents]::Rot=__ROTATE__
|
|
253
|
-
[ScEvents]::Run([Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('__PATH__')), [bool]__MODE__, __PARENT__)
|
|
254
|
-
`;
|
|
255
|
-
export function buildHookScript(rawPath, mode, parentPid, rotateSec = 0) {
|
|
256
|
-
const rotateMs = Math.max(0, Math.round(rotateSec * 1000));
|
|
257
|
-
return PS_HOOK.replace("__PATH__", Buffer.from(rawPath, "utf8").toString("base64"))
|
|
258
|
-
.replace("__MODE__", mode === "shortcuts" ? "1" : "0")
|
|
259
|
-
.replace("__PARENT__", String(parentPid))
|
|
260
|
-
.replace("__ROTATE__", String(rotateMs));
|
|
261
|
-
}
|
|
262
|
-
export function rotatedLogPath(rawPath) {
|
|
263
|
-
return `${rawPath}.1`;
|
|
264
|
-
}
|
|
265
|
-
export function rawLinesSince(raw, sinceMs) {
|
|
266
|
-
return raw
|
|
267
|
-
.split(/\r?\n/)
|
|
268
|
-
.filter((line) => {
|
|
269
|
-
const comma = line.indexOf(",");
|
|
270
|
-
const ms = comma > 0 ? Number(line.slice(0, comma)) : NaN;
|
|
271
|
-
return Number.isFinite(ms) && ms >= sinceMs;
|
|
272
|
-
})
|
|
273
|
-
.join("\n");
|
|
274
|
-
}
|
|
275
|
-
export function readRawEventLog(rawPath, sinceMs = -Infinity) {
|
|
276
|
-
const read = (p) => {
|
|
277
|
-
try {
|
|
278
|
-
return existsSync(p) ? readFileSync(p, "utf8") : "";
|
|
279
|
-
}
|
|
280
|
-
catch {
|
|
281
|
-
return "";
|
|
282
|
-
}
|
|
283
|
-
};
|
|
284
|
-
const text = `${read(rotatedLogPath(rawPath))}\n${read(rawPath)}`;
|
|
285
|
-
return sinceMs === -Infinity ? text : rawLinesSince(text, sinceMs);
|
|
286
|
-
}
|
|
287
|
-
export function cleanPsError(stderr) {
|
|
288
|
-
if (!stderr.startsWith("#< CLIXML"))
|
|
289
|
-
return stderr.trim();
|
|
290
|
-
const parts = [...stderr.matchAll(/<S S="Error">([^<]*)<\/S>/g)].map((m) => m[1]);
|
|
291
|
-
return parts
|
|
292
|
-
.join("")
|
|
293
|
-
.replace(/_x000D__x000A_/g, "\n")
|
|
294
|
-
.replace(/>/g, ">")
|
|
295
|
-
.replace(/</g, "<")
|
|
296
|
-
.replace(/&/g, "&")
|
|
297
|
-
.trim();
|
|
298
|
-
}
|
|
299
|
-
export const LOGGER_READY_TIMEOUT_MS = 20_000;
|
|
300
|
-
export async function startEventLogger(rawPath, mode, opts = {}) {
|
|
301
|
-
if (process.platform !== "win32") {
|
|
302
|
-
throw new ScreencastError("The input event log is implemented for Windows only.");
|
|
303
|
-
}
|
|
304
|
-
rmSync(`${rawPath}.stop`, { force: true });
|
|
305
|
-
const encoded = Buffer.from(buildHookScript(rawPath, mode, process.pid, opts.rotateSec), "utf16le").toString("base64");
|
|
306
|
-
const child = spawn("powershell", ["-NoProfile", "-NonInteractive", "-EncodedCommand", encoded], {
|
|
307
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
308
|
-
windowsHide: true,
|
|
309
|
-
});
|
|
310
|
-
let stderr = "";
|
|
311
|
-
child.stderr?.on("data", (d) => {
|
|
312
|
-
stderr = (stderr + d.toString()).slice(-2000);
|
|
313
|
-
});
|
|
314
|
-
await new Promise((resolve, reject) => {
|
|
315
|
-
let settled = false;
|
|
316
|
-
const fail = (why) => {
|
|
317
|
-
if (settled)
|
|
318
|
-
return;
|
|
319
|
-
settled = true;
|
|
320
|
-
clearTimeout(timer);
|
|
321
|
-
child.kill();
|
|
322
|
-
reject(new ScreencastError(`Could not start the input event log: ${why}`));
|
|
323
|
-
};
|
|
324
|
-
const timer = setTimeout(() => fail(`no response in ${LOGGER_READY_TIMEOUT_MS / 1000}s`), LOGGER_READY_TIMEOUT_MS);
|
|
325
|
-
child.stdout?.on("data", (d) => {
|
|
326
|
-
if (!settled && d.toString().includes("ready")) {
|
|
327
|
-
settled = true;
|
|
328
|
-
clearTimeout(timer);
|
|
329
|
-
resolve();
|
|
330
|
-
}
|
|
331
|
-
});
|
|
332
|
-
child.on("error", (err) => fail(err.message));
|
|
333
|
-
child.on("exit", (code) => fail(cleanPsError(stderr) || `helper exited with code ${code}`));
|
|
334
|
-
});
|
|
335
|
-
stopFiles.set(child, `${rawPath}.stop`);
|
|
336
|
-
return child;
|
|
337
|
-
}
|
|
338
|
-
const stopFiles = new WeakMap();
|
|
339
|
-
export const LOGGER_STOP_GRACE_MS = 2_000;
|
|
340
|
-
export function stopEventLogger(child) {
|
|
341
|
-
if (child.exitCode !== null || child.signalCode !== null)
|
|
342
|
-
return Promise.resolve();
|
|
343
|
-
let stop = stopFiles.get(child);
|
|
344
|
-
if (stop) {
|
|
345
|
-
try {
|
|
346
|
-
writeFileSync(stop, "");
|
|
347
|
-
}
|
|
348
|
-
catch {
|
|
349
|
-
stop = undefined;
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
return new Promise((resolve) => {
|
|
353
|
-
const kill = setTimeout(() => child.kill(), stop ? LOGGER_STOP_GRACE_MS : 0);
|
|
354
|
-
const done = setTimeout(resolve, LOGGER_STOP_GRACE_MS + 5_000);
|
|
355
|
-
child.once("exit", () => {
|
|
356
|
-
clearTimeout(kill);
|
|
357
|
-
clearTimeout(done);
|
|
358
|
-
resolve();
|
|
359
|
-
});
|
|
360
|
-
}).finally(() => {
|
|
361
|
-
if (stop)
|
|
362
|
-
rmSync(stop, { force: true });
|
|
363
|
-
});
|
|
364
|
-
}
|
|
365
|
-
export function eventPaths(recording) {
|
|
366
|
-
const base = recording.replace(/\.[^./\\]+$/, "");
|
|
367
|
-
return { raw: `${base}.events.raw`, jsonl: `${base}.events.jsonl` };
|
|
368
|
-
}
|
|
369
|
-
export function prepareEventPaths(paths, overwrite = false) {
|
|
370
|
-
if (!overwrite) {
|
|
371
|
-
const existing = [paths.jsonl, paths.raw].find((p) => existsSync(p));
|
|
372
|
-
if (existing) {
|
|
373
|
-
throw new ScreencastError(`Event log already exists: ${existing}. Pass overwrite: true to replace it, or choose a different output path.`);
|
|
374
|
-
}
|
|
375
|
-
return;
|
|
376
|
-
}
|
|
377
|
-
rmSync(paths.raw, { force: true });
|
|
378
|
-
}
|
|
379
|
-
export function writeEventsFile(paths, opts) {
|
|
380
|
-
const raw = existsSync(paths.raw) ? readFileSync(paths.raw, "utf8") : "";
|
|
381
|
-
const events = convertEvents(raw, opts);
|
|
382
|
-
writeFileSync(paths.jsonl, formatEventsJsonl(events));
|
|
383
|
-
try {
|
|
384
|
-
unlinkSync(paths.raw);
|
|
385
|
-
}
|
|
386
|
-
catch {
|
|
387
|
-
}
|
|
388
|
-
return events;
|
|
389
|
-
}
|
|
390
|
-
const finalizers = new Map();
|
|
391
|
-
export function trackFinalizer(sessionId, done) {
|
|
392
|
-
finalizers.set(sessionId, done);
|
|
393
|
-
void done.finally(() => {
|
|
394
|
-
if (finalizers.get(sessionId) === done)
|
|
395
|
-
finalizers.delete(sessionId);
|
|
396
|
-
});
|
|
397
|
-
}
|
|
398
|
-
export async function whenFinalized(sessionId, timeoutMs = 10_000) {
|
|
399
|
-
const done = finalizers.get(sessionId);
|
|
400
|
-
if (!done)
|
|
401
|
-
return;
|
|
402
|
-
await Promise.race([done, new Promise((r) => setTimeout(r, timeoutMs))]);
|
|
403
|
-
}
|
package/dist/utils/expr.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export const SUM_GROUP = 50;
|
|
2
|
-
export function sumExpr(terms) {
|
|
3
|
-
if (terms.length === 0)
|
|
4
|
-
return "0";
|
|
5
|
-
if (terms.length <= SUM_GROUP)
|
|
6
|
-
return terms.join("+");
|
|
7
|
-
const groups = [];
|
|
8
|
-
for (let i = 0; i < terms.length; i += SUM_GROUP)
|
|
9
|
-
groups.push(`(${terms.slice(i, i + SUM_GROUP).join("+")})`);
|
|
10
|
-
return sumExpr(groups);
|
|
11
|
-
}
|