Skip to content

armgit / clipy

Public Imported from GitHub
0

The AI-native screen recorder. Record your screen and talk; the people you share it with and your AI agents both get it.

Merge pull request #960

Claude946ddaacdc1d
diff --cc packages/moments/src/index.ts
index 559944f,1a95505..b02116b
--- a/packages/moments/src/index.ts
+++ b/packages/moments/src/index.ts
@@@ -95,7 -110,8 +110,10 @@@ function thinEdges<T>(events: readonly
const time = (i: number) => (typeof at(i).time_ms === "number" ? (at(i).time_ms as number) : 0);
const ordered = [...edges].sort((a, b) => time(a) - time(b) || a - b);
const kept: number[] = [];
- const units: number[][] = [];
++ // Clicks and keys are sampled separately, clicks first, so a long typing
++ // burst cannot crowd out the clicks that pick frames.
+ const clickUnits: number[][] = [];
+ const keyUnits: number[][] = [];
// Presses waiting for their release, oldest first, per key code or button:
// the index of the press's unit, or CHORD for a chord press, which is kept
// and whose release is kept with it.
@@@ -135,23 -137,11 +153,25 @@@
const pending = openKeys.get(code)!;
if (pending.length === 0) pending.push(CHORD);
} else if (e.kind === "key_down" || e.kind === "down") {
- const open = e.kind === "key_down" ? openKeys : openButtons;
- const id = e.kind === "key_down" ? code : e.button;
+ const isKey = e.kind === "key_down";
+ const open = isKey ? openKeys : openButtons;
+ const units = isKey ? keyUnits : clickUnits;
+ const id = isKey ? code : e.button;
- units.push([i]);
+ // Auto-repeat has one release. Add repeated key-downs to the existing
+ // press so each hold is sampled as one unit.
+ if (e.kind === "key_down" && typeof code === "number") {
+ const pending = openKeys.get(code)?.[0];
+ if (pending === CHORD) {
+ kept.push(i);
+ continue;
+ }
+ if (pending !== undefined) {
+ units[pending].push(i);
+ continue;
+ }
+ }
+ const unit = [i];
+ units.push(unit);
if (!open.has(id)) open.set(id, []);
open.get(id)!.push(units.length - 1);
} else {
diff --cc packages/moments/test/planMoments.test.ts
index 80da983,0852b02..69cda1b
--- a/packages/moments/test/planMoments.test.ts
+++ b/packages/moments/test/planMoments.test.ts
@@@ -629,26 -563,50 +634,68 @@@ describe("long typing sessions", () =>
for (const [down, up] of others) expect(kept.has(down)).toBe(kept.has(up));
expect(others.some(([down]) => kept.has(down))).toBe(true);
});
+
+ it("thins plain typing before clicks and pen strokes", async () => {
+ // The same take with a click every minute and a pen stroke in every pen session.
+ const events = typing().flatMap((e) => {
+ const s = e.time_ms % 60_000;
+ if (e.kind === "key_down" && s === 20_000) {
+ const t = e.time_ms;
+ return [e, { kind: "down", time_ms: t + 10, x: 400, y: 300, button: 1 }, { kind: "up", time_ms: t + 80, x: 400, y: 300, button: 1 }];
+ }
+ if (e.kind === "annotation" && e.active) {
+ const t = e.time_ms;
+ return [e, { kind: "down", time_ms: t + 1_000, x: 200, y: 200, button: 1 }, { kind: "move", time_ms: t + 1_500, x: 260, y: 240 }, { kind: "up", time_ms: t + 2_000, x: 300, y: 260, button: 1 }];
+ }
+ return [e];
+ }) as LocalMomentInput["interactions"];
+ const bounded = boundInteractions(events);
+ expect(bounded.length).toBeLessThanOrEqual(MAX_PLANNER_INTERACTIONS);
+ const kept = new Set(bounded);
+ const buttons = pressesWithReleases(events).filter(([down]) => down.kind === "down");
+ expect(buttons).toHaveLength(40);
+ for (const [down, up] of buttons) expect(kept.has(down) && kept.has(up)).toBe(true);
+ // Typing is what gives way: some plain key pairs are dropped.
+ const plainKeys = events.filter((e) => e.kind === "key_down" && e.key_code !== 59);
+ expect(plainKeys.some((e) => !kept.has(e))).toBe(true);
+ // So the gesture rules see the same pen strokes as with every event.
+ const strokes = (list: LocalMomentInput["interactions"]) =>
+ detectPenStrokes(asCursor(list), detectAnnotationSpans(asCursor(list), 1_200_000), detectFlareSpans(asCursor(list)), (x, y) => ({ x, y })).map(
+ (s) => [s.start_ms, s.end_ms],
+ );
+ expect(strokes(events)).toHaveLength(20);
+ expect(strokes(bounded)).toEqual(strokes(events));
+ // And the planner still frames the clicks.
+ const { plan } = await planMoments({
+ schemaVersion: 2,
+ durationMs: 1_200_000,
+ transcript: [],
+ interactions: events,
+ clickElements: [],
+ interactionSelection: "bounded sample; full stream retained locally",
+ });
+ expect(v2(plan).some((m) => m.source === "click")).toBe(true);
+ });
});
+it("keeps an auto-repeated plain key and its release together when thinning", () => {
+ const events: LocalMomentInput["interactions"] = [
+ { kind: "key_down", time_ms: 0, key_code: 40 },
+ { kind: "key_down", time_ms: 1, key_code: 40 }, // auto-repeat, not a second press
+ { kind: "key_up", time_ms: 2, key_code: 40 },
+ { kind: "key_down", time_ms: 3, key_code: 40 }, // a later press of the same key
+ { kind: "key_up", time_ms: 4, key_code: 40 },
+ ];
+
+ expect(boundInteractions(events, 3)).toEqual(events.slice(0, 3));
+ for (let limit = 1; limit < events.length; limit++) {
+ const kept = new Set(boundInteractions(events, limit));
+ expect(kept.has(events[0])).toBe(kept.has(events[1]));
+ expect(kept.has(events[1])).toBe(kept.has(events[2]));
+ expect(kept.has(events[3])).toBe(kept.has(events[4]));
+ }
+});
+
describe("Control chords when the edges are thinned", () => {
type Event = LocalMomentInput["interactions"][number];
const CONTROL = 59;