Skip to content

Commit 6db622a

Browse files
committed
Merge remote-tracking branch 'origin/main' into fix/preview-releases-stay-draft
2 parents 0aba844 + bd731da commit 6db622a

112 files changed

Lines changed: 6487 additions & 1616 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/ci.yml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,9 @@ jobs:
504504
T3CODE_TRANSFER_BUDGET_REPORT_PATH: ${{ runner.temp }}/t3code-transfer-budget.md
505505
T3CODE_TRANSFER_BUDGET_RESULT_PATH: ${{ runner.temp }}/thread-transfer-result.json
506506
T3CODE_TRANSFER_BUDGET_SCENARIOS_PATH: ${{ runner.temp }}/thread-transfer-scenarios.json
507+
# One process per file spends ~2s starting before its tests run; one file per vCPU overlaps that.
507508
run: >-
508-
vp run test:cached -- --shard ${{ matrix.shard }}/${{ strategy.job-total }}
509+
vp run test:cached -- --shard ${{ matrix.shard }}/${{ strategy.job-total }} --concurrency 4
509510
--uncached apps/server/integration/transferBudgetV2.integration.test.ts
510511
--verify-hits 1 apps/server
511512
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import type { PreviewAnnotationPoint } from "@t3tools/contracts";
2+
import { describe, expect, it } from "vite-plus/test";
3+
4+
import {
5+
addStrokePoint,
6+
openStrokePath,
7+
startStroke,
8+
strokeBounds,
9+
STROKE_SEGMENTS_PER_PATH,
10+
} from "./AnnotationStroke.ts";
11+
12+
// The Draw tool used to rebuild the whole path and rescan every point on each move.
13+
const fullPath = (points: ReadonlyArray<PreviewAnnotationPoint>): string => {
14+
let path = `M ${points[0]!.x} ${points[0]!.y}`;
15+
for (let index = 1; index < points.length - 1; index += 1) {
16+
const current = points[index]!;
17+
const next = points[index + 1]!;
18+
path += ` Q ${current.x} ${current.y} ${(current.x + next.x) / 2} ${(current.y + next.y) / 2}`;
19+
}
20+
const last = points[points.length - 1]!;
21+
return `${path} L ${last.x} ${last.y}`;
22+
};
23+
24+
const fullBounds = (points: ReadonlyArray<PreviewAnnotationPoint>, width: number) => {
25+
const xs = points.map((point) => point.x);
26+
const ys = points.map((point) => point.y);
27+
const padding = width + 3;
28+
const left = Math.min(...xs) - padding;
29+
const top = Math.min(...ys) - padding;
30+
const right = Math.max(...xs) + padding;
31+
const bottom = Math.max(...ys) + padding;
32+
return { x: left, y: top, width: right - left, height: bottom - top };
33+
};
34+
35+
// Each later path starts with a move to where the previous one ended.
36+
const joinPaths = (paths: ReadonlyArray<string>): string =>
37+
paths
38+
.map((path, index) => {
39+
if (index === 0) return path;
40+
const resume = path.match(/^M (\S+ \S+)/)![1]!;
41+
expect(paths[index - 1]!.endsWith(` ${resume}`)).toBe(true);
42+
return path.slice(`M ${resume}`.length);
43+
})
44+
.join("");
45+
46+
describe("stroke geometry", () => {
47+
it("draws the same curve and bounds as a full rescan at every length", () => {
48+
const points = Array.from({ length: STROKE_SEGMENTS_PER_PATH * 2 + 30 }, (_, index) => ({
49+
x: index * 3 + ((index * 7) % 11),
50+
y: 200 + ((index * 13) % 29) - index,
51+
}));
52+
const geometry = startStroke(points[0]!);
53+
const closedPaths: string[] = [];
54+
for (let index = 1; index < points.length; index += 1) {
55+
const closedPath = addStrokePoint(geometry, points[index]!);
56+
if (closedPath !== null) closedPaths.push(closedPath);
57+
const drawn = points.slice(0, index + 1);
58+
expect(joinPaths([...closedPaths, openStrokePath(geometry)])).toBe(fullPath(drawn));
59+
expect(strokeBounds(geometry, 4)).toEqual(fullBounds(drawn, 4));
60+
}
61+
expect(closedPaths).toHaveLength(2);
62+
expect(geometry.points).toEqual(points);
63+
});
64+
65+
it("keeps the rewritten path short for a stroke past the engine's argument limit", () => {
66+
const geometry = startStroke({ x: 0, y: 0 });
67+
for (let index = 1; index < 250_000; index += 1) {
68+
addStrokePoint(geometry, { x: index % 800, y: index % 600 });
69+
}
70+
expect(strokeBounds(geometry, 4)).toEqual({ x: -7, y: -7, width: 813, height: 613 });
71+
expect(openStrokePath(geometry).length).toBeLessThan(STROKE_SEGMENTS_PER_PATH * 40);
72+
});
73+
});
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import type { PreviewAnnotationPoint, PreviewAnnotationRect } from "@t3tools/contracts";
2+
3+
// Setting a path's `d` makes Chromium parse the whole string again, so a long
4+
// stroke is drawn as a run of paths and only the last one is rewritten per move.
5+
export const STROKE_SEGMENTS_PER_PATH = 100;
6+
7+
export interface StrokeGeometry {
8+
readonly points: PreviewAnnotationPoint[];
9+
minX: number;
10+
minY: number;
11+
maxX: number;
12+
maxY: number;
13+
// The curve through the newest point is still open: where it ends depends on
14+
// the point after it. This holds only the settled segments of the last path.
15+
openPath: string;
16+
openSegments: number;
17+
}
18+
19+
export function startStroke(point: PreviewAnnotationPoint): StrokeGeometry {
20+
return {
21+
points: [point],
22+
minX: point.x,
23+
minY: point.y,
24+
maxX: point.x,
25+
maxY: point.y,
26+
openPath: `M ${point.x} ${point.y}`,
27+
openSegments: 0,
28+
};
29+
}
30+
31+
// Returns the final `d` of the path this point filled, if it filled one.
32+
export function addStrokePoint(
33+
geometry: StrokeGeometry,
34+
point: PreviewAnnotationPoint,
35+
): string | null {
36+
const previous = geometry.points[geometry.points.length - 1]!;
37+
let closedPath: string | null = null;
38+
if (geometry.points.length > 1) {
39+
const midX = (previous.x + point.x) / 2;
40+
const midY = (previous.y + point.y) / 2;
41+
geometry.openPath += ` Q ${previous.x} ${previous.y} ${midX} ${midY}`;
42+
geometry.openSegments += 1;
43+
if (geometry.openSegments === STROKE_SEGMENTS_PER_PATH) {
44+
closedPath = geometry.openPath;
45+
geometry.openPath = `M ${midX} ${midY}`;
46+
geometry.openSegments = 0;
47+
}
48+
}
49+
geometry.points.push(point);
50+
geometry.minX = Math.min(geometry.minX, point.x);
51+
geometry.minY = Math.min(geometry.minY, point.y);
52+
geometry.maxX = Math.max(geometry.maxX, point.x);
53+
geometry.maxY = Math.max(geometry.maxY, point.y);
54+
return closedPath;
55+
}
56+
57+
export function openStrokePath(geometry: StrokeGeometry): string {
58+
const last = geometry.points[geometry.points.length - 1]!;
59+
return `${geometry.openPath} L ${last.x} ${last.y}`;
60+
}
61+
62+
export function strokeBounds(geometry: StrokeGeometry, width: number): PreviewAnnotationRect {
63+
const padding = width + 3;
64+
const left = geometry.minX - padding;
65+
const top = geometry.minY - padding;
66+
const right = geometry.maxX + padding;
67+
const bottom = geometry.maxY + padding;
68+
return { x: left, y: top, width: right - left, height: bottom - top };
69+
}

‎apps/desktop/src/preview/PickPreload.ts‎

Lines changed: 41 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ import type {
2020

2121
import { createAnnotationIdSource } from "./AnnotationIds.ts";
2222
import { resolveAnnotationSubmission } from "./AnnotationKeyboard.ts";
23+
import {
24+
addStrokePoint,
25+
openStrokePath,
26+
startStroke,
27+
strokeBounds,
28+
type StrokeGeometry,
29+
} from "./AnnotationStroke.ts";
2330
import { previewAnnotationStyles } from "./AnnotationStyles.generated.ts";
2431
import { installRecordingCursor } from "./RecordingCursor.ts";
2532
import { DEFAULT_RECORDING_INPUT_OPTIONS } from "./RecordingInput.ts";
@@ -546,34 +553,6 @@ function createUnitInput(unit: string, placeholder = "0"): HTMLInputElement {
546553
return input;
547554
}
548555

549-
function pathFromPoints(points: ReadonlyArray<PreviewAnnotationPoint>): string {
550-
if (points.length === 0) return "";
551-
if (points.length === 1) return `M ${points[0]!.x} ${points[0]!.y} l 0.01 0.01`;
552-
let path = `M ${points[0]!.x} ${points[0]!.y}`;
553-
for (let index = 1; index < points.length - 1; index += 1) {
554-
const current = points[index]!;
555-
const next = points[index + 1]!;
556-
path += ` Q ${current.x} ${current.y} ${(current.x + next.x) / 2} ${(current.y + next.y) / 2}`;
557-
}
558-
const last = points[points.length - 1]!;
559-
path += ` L ${last.x} ${last.y}`;
560-
return path;
561-
}
562-
563-
function strokeBounds(
564-
points: ReadonlyArray<PreviewAnnotationPoint>,
565-
width: number,
566-
): PreviewAnnotationRect {
567-
const xs = points.map((point) => point.x);
568-
const ys = points.map((point) => point.y);
569-
const padding = width + 3;
570-
const left = Math.min(...xs) - padding;
571-
const top = Math.min(...ys) - padding;
572-
const right = Math.max(...xs) + padding;
573-
const bottom = Math.max(...ys) + padding;
574-
return { x: left, y: top, width: right - left, height: bottom - top };
575-
}
576-
577556
function startAnnotation(
578557
sendEnabled: boolean,
579558
voice: DesktopPreviewAnnotationVoiceConfig | undefined,
@@ -910,7 +889,12 @@ function startAnnotation(
910889
}
911890
let tool: AnnotationTool = isPdf ? "marquee" : "select";
912891
let dragStart: PreviewAnnotationPoint | null = null;
913-
let activeStroke: { target: PreviewAnnotationStrokeTarget; path: SVGPathElement } | null = null;
892+
let activeStroke: {
893+
target: PreviewAnnotationStrokeTarget;
894+
geometry: StrokeGeometry;
895+
group: SVGGElement;
896+
path: SVGPathElement;
897+
} | null = null;
914898
let pendingCapture = false;
915899
let editorExpanded = false;
916900
let editorWasShown = false;
@@ -1510,15 +1494,18 @@ function startAnnotation(
15101494
return;
15111495
}
15121496
if (tool === "draw" && activeStroke) {
1513-
activeStroke.target.points = [
1514-
...activeStroke.target.points,
1515-
{ x: event.clientX, y: event.clientY },
1516-
];
1517-
activeStroke.target.bounds = strokeBounds(
1518-
activeStroke.target.points,
1519-
activeStroke.target.width,
1520-
);
1521-
activeStroke.path.setAttribute("d", pathFromPoints(activeStroke.target.points));
1497+
const closedPath = addStrokePoint(activeStroke.geometry, {
1498+
x: event.clientX,
1499+
y: event.clientY,
1500+
});
1501+
activeStroke.target.bounds = strokeBounds(activeStroke.geometry, activeStroke.target.width);
1502+
if (closedPath !== null) {
1503+
activeStroke.path.setAttribute("d", closedPath);
1504+
activeStroke.path = activeStroke.group.appendChild(
1505+
document.createElementNS("http://www.w3.org/2000/svg", "path"),
1506+
);
1507+
}
1508+
activeStroke.path.setAttribute("d", openStrokePath(activeStroke.geometry));
15221509
}
15231510
};
15241511

@@ -1537,23 +1524,27 @@ function startAnnotation(
15371524
}
15381525
dragStart = { x: event.clientX, y: event.clientY };
15391526
if (tool === "draw") {
1527+
const geometry = startStroke(dragStart);
15401528
const stroke: PreviewAnnotationStrokeTarget = {
15411529
id: nextId("stroke"),
15421530
color: annotationTheme?.primary ?? "#2563eb",
15431531
width: 4,
1544-
points: [dragStart],
1532+
points: geometry.points,
15451533
bounds: { x: dragStart.x, y: dragStart.y, width: 1, height: 1 },
15461534
};
1547-
const path = document.createElementNS("http://www.w3.org/2000/svg", "path");
1548-
path.setAttribute(OVERLAY_ATTRIBUTE, "");
1549-
path.setAttribute("data-stroke-id", stroke.id);
1550-
path.setAttribute("fill", "none");
1551-
path.setAttribute("stroke", stroke.color);
1552-
path.setAttribute("stroke-width", String(stroke.width));
1553-
path.setAttribute("stroke-linecap", "round");
1554-
path.setAttribute("stroke-linejoin", "round");
1555-
svg.appendChild(path);
1556-
activeStroke = { target: stroke, path };
1535+
const group = document.createElementNS("http://www.w3.org/2000/svg", "g");
1536+
group.setAttribute(OVERLAY_ATTRIBUTE, "");
1537+
group.setAttribute("data-stroke-id", stroke.id);
1538+
group.setAttribute("fill", "none");
1539+
group.setAttribute("stroke", stroke.color);
1540+
group.setAttribute("stroke-width", String(stroke.width));
1541+
group.setAttribute("stroke-linecap", "round");
1542+
group.setAttribute("stroke-linejoin", "round");
1543+
const path = group.appendChild(
1544+
document.createElementNS("http://www.w3.org/2000/svg", "path"),
1545+
);
1546+
svg.appendChild(group);
1547+
activeStroke = { target: stroke, geometry, group, path };
15571548
}
15581549
};
15591550

@@ -1580,7 +1571,7 @@ function startAnnotation(
15801571
}
15811572
} else if (tool === "draw" && activeStroke) {
15821573
if (activeStroke.target.points.length > 1) strokes.push(activeStroke.target);
1583-
else activeStroke.path.remove();
1574+
else activeStroke.group.remove();
15841575
activeStroke = null;
15851576
}
15861577
dragStart = null;

‎apps/desktop/src/updates/DesktopUpdates.test.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,26 @@ describe("DesktopUpdates", () => {
247247
).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
248248
});
249249

250+
it.effect("checks shortly after startup and then every four hours", () => {
251+
const harness = makeHarness();
252+
253+
return Effect.scoped(
254+
Effect.gen(function* () {
255+
const updates = yield* DesktopUpdates.DesktopUpdates;
256+
yield* updates.configure;
257+
258+
yield* TestClock.adjust("15 seconds");
259+
assert.equal(harness.checkCount(), 1);
260+
261+
yield* TestClock.adjust("3 hours");
262+
assert.equal(harness.checkCount(), 1);
263+
264+
yield* TestClock.adjust("1 hour");
265+
assert.equal(harness.checkCount(), 2);
266+
}),
267+
).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
268+
});
269+
250270
it.effect(
251271
"rejects install while a refresh check is in progress and releases the reservation",
252272
() =>

‎apps/desktop/src/updates/DesktopUpdates.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ import {
6060
const CHANNEL_CHANGE_RETRY_DELAY = Duration.seconds(1);
6161
const CHANNEL_CHANGE_RETRIES = 30;
6262
const AUTO_UPDATE_STARTUP_DELAY = "15 seconds";
63-
const AUTO_UPDATE_POLL_INTERVAL = "4 minutes";
63+
const AUTO_UPDATE_POLL_INTERVAL = "4 hours";
6464
const PREPARED_INSTALL_CHECK_WAIT = Duration.seconds(90);
6565

6666
type UpdateAction = "check" | "download" | "install" | "install-recovery" | "channel";

‎apps/server/scripts/acp-mock-agent.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ const copilotModesProfile = process.env.T3_ACP_COPILOT_MODES === "1";
2323
const copilotModeId = (name: string) =>
2424
`https://agentclientprotocol.com/protocol/session-modes#${name}`;
2525
const modeOptionCategory = process.env.T3_ACP_MODE_OPTION_CATEGORY ?? "mode";
26+
// Comma-separated command names the mock advertises, so `/compact` support is testable.
27+
const advertisedCommandNames = (process.env.T3_ACP_AVAILABLE_COMMANDS ?? "")
28+
.split(",")
29+
.map((name) => name.trim())
30+
.filter((name) => name.length > 0);
31+
const loadedCommandNames = process.env.T3_ACP_LOADED_COMMANDS?.split(",").filter(Boolean);
2632
const emitToolCalls = process.env.T3_ACP_EMIT_TOOL_CALLS === "1";
2733
const emitInterleavedAssistantToolCalls =
2834
process.env.T3_ACP_EMIT_INTERLEAVED_ASSISTANT_TOOL_CALLS === "1";
@@ -610,6 +616,18 @@ const program = Effect.gen(function* () {
610616
if (antigravityProfile) {
611617
yield* publishAntigravityCommands(sessionId);
612618
}
619+
if (advertisedCommandNames.length > 0) {
620+
yield* agent.client.sessionUpdate({
621+
sessionId,
622+
update: {
623+
sessionUpdate: "available_commands_update",
624+
availableCommands: advertisedCommandNames.map((name) => ({
625+
name,
626+
description: `${name} command`,
627+
})),
628+
},
629+
});
630+
}
613631
return {
614632
sessionId,
615633
configOptions: configOptions(),
@@ -665,6 +683,15 @@ const program = Effect.gen(function* () {
665683
yield* agent.handleLoadSession((request) =>
666684
Effect.gen(function* () {
667685
const requestedSessionId = String(request.sessionId ?? sessionId);
686+
if (loadedCommandNames !== undefined) {
687+
yield* agent.client.sessionUpdate({
688+
sessionId: requestedSessionId,
689+
update: {
690+
sessionUpdate: "available_commands_update",
691+
availableCommands: loadedCommandNames.map((name) => ({ name, description: name })),
692+
},
693+
});
694+
}
668695
if (failLoadSession) {
669696
return yield* AcpError.AcpRequestError.internalError("Mock load session failure");
670697
}

0 commit comments

Comments
 (0)