Skip to content

Commit f8335c3

Browse files
Merge branch 'main' into fix/coderabbit-button-underline
2 parents a129640 + 6d5ea19 commit f8335c3

65 files changed

Lines changed: 5100 additions & 101 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.

‎apps/mobile/src/features/browser/preview-stream.browser.ts‎

Lines changed: 49 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const AGENT_CURSOR_SVG =
5050
interface Viewer {
5151
readonly stop: () => void;
5252
readonly command: (input: PreviewStreamInput) => void;
53-
readonly togglePictureInPicture: () => Promise<void>;
53+
readonly togglePictureInPicture: () => void;
5454
}
5555

5656
let activeViewer: Viewer | null = null;
@@ -66,7 +66,7 @@ export function command(input: PreviewStreamInput) {
6666
}
6767

6868
export function pictureInPicture() {
69-
void activeViewer?.togglePictureInPicture();
69+
activeViewer?.togglePictureInPicture();
7070
}
7171

7272
export function start(configuration: PreviewStreamConfiguration) {
@@ -147,6 +147,7 @@ export function start(configuration: PreviewStreamConfiguration) {
147147
};
148148
const painter = createPreviewFramePainter(canvas, () => {
149149
if (!streaming && !stopped) reportStatus("streaming");
150+
sendPictureInPictureFrame();
150151
});
151152
const send = (message: PreviewStreamInput) => client?.send(message) ?? false;
152153
const clearInput = () => {
@@ -620,10 +621,16 @@ export function start(configuration: PreviewStreamConfiguration) {
620621
const pictureInPictureSupported =
621622
interactive &&
622623
typeof canvas.captureStream === "function" &&
624+
typeof CanvasCaptureMediaStreamTrack === "function" &&
623625
((document.pictureInPictureEnabled === true &&
624626
typeof videoPrototype.requestPictureInPicture === "function") ||
625627
typeof videoPrototype.webkitSetPresentationMode === "function");
628+
// Since the iOS 17 SDK, WebKit revokes the activation it grants an injected script when
629+
// the script returns, so the native button's request must start before any await. The
630+
// video is ready ahead of the tap: paused, and fed a frame only when it has none or
631+
// floats, so the inline view captures nothing.
626632
let video: PresentationVideo | null = null;
633+
let track: CanvasCaptureMediaStreamTrack | null = null;
627634
const pictureInPictureActive = () =>
628635
video !== null &&
629636
(document.pictureInPictureElement === video ||
@@ -635,16 +642,20 @@ export function start(configuration: PreviewStreamConfiguration) {
635642
active: pictureInPictureActive(),
636643
...(detail ? { detail } : {}),
637644
});
638-
const ensureVideo = () => {
639-
if (video) return video;
645+
// Called after each paint. A frame drawn before the player attached is lost, so retry.
646+
const sendPictureInPictureFrame = () => {
647+
if (video && (video.readyState === HTMLMediaElement.HAVE_NOTHING || pictureInPictureActive())) {
648+
track?.requestFrame();
649+
}
650+
};
651+
if (pictureInPictureSupported) {
652+
const stream = canvas.captureStream(0);
653+
const [captured] = stream.getVideoTracks();
640654
const element: PresentationVideo = document.createElement("video");
641655
element.muted = true;
642656
element.playsInline = true;
643-
element.autoplay = true;
644657
// Under the canvas at full size: WebKit pauses muted video it considers off screen.
645-
element.srcObject = canvas.captureStream();
646-
// A static page sends no new frames; repaint once so the stream has one.
647-
if (canvas.width > 0 && canvas.height > 0) canvas.getContext("2d")?.drawImage(canvas, 0, 0);
658+
element.srcObject = stream;
648659
for (const name of [
649660
"enterpictureinpicture",
650661
"leavepictureinpicture",
@@ -656,25 +667,38 @@ export function start(configuration: PreviewStreamConfiguration) {
656667
});
657668
}
658669
container.prepend(element);
670+
// Covers the letterbox, where a stale frame of another shape would show through.
671+
canvas.style.background = configuration.background;
659672
video = element;
660-
return element;
661-
};
662-
const togglePictureInPicture = async () => {
663-
if (!pictureInPictureSupported) return;
664-
try {
665-
if (pictureInPictureActive()) {
666-
if (document.pictureInPictureElement) await document.exitPictureInPicture();
667-
else video?.webkitSetPresentationMode?.("inline");
668-
return;
669-
}
670-
const element = ensureVideo();
671-
await element.play();
672-
if (document.pictureInPictureEnabled) await element.requestPictureInPicture();
673-
else element.webkitSetPresentationMode?.("picture-in-picture");
674-
} catch (error) {
673+
track = captured instanceof CanvasCaptureMediaStreamTrack ? captured : null;
674+
}
675+
const togglePictureInPicture = () => {
676+
const element = video;
677+
if (!element) return;
678+
if (pictureInPictureActive()) {
679+
if (document.pictureInPictureElement) void document.exitPictureInPicture().catch(() => {});
680+
else element.webkitSetPresentationMode?.("inline");
681+
return;
682+
}
683+
if (element.readyState === HTMLMediaElement.HAVE_NOTHING) {
684+
reportPictureInPicture("The page has not shown yet. Try again in a moment.");
685+
return;
686+
}
687+
// The page may have changed since the video's last frame. WebKit captures only on a draw.
688+
track?.requestFrame();
689+
canvas.getContext("2d")?.drawImage(canvas, 0, 0);
690+
const fail = (error: unknown) => {
691+
element.pause();
675692
reportPictureInPicture(
676693
error instanceof Error ? error.message : "Picture in picture is unavailable.",
677694
);
695+
};
696+
if (document.pictureInPictureEnabled) {
697+
const entering = element.requestPictureInPicture();
698+
void Promise.all([entering, element.play()]).catch(fail);
699+
} else {
700+
element.webkitSetPresentationMode?.("picture-in-picture");
701+
void element.play().catch(fail);
678702
}
679703
};
680704

@@ -691,14 +715,8 @@ export function start(configuration: PreviewStreamConfiguration) {
691715
painter.stop();
692716
client?.stop();
693717
client = null;
694-
if (video) {
695-
for (const track of video.srcObject instanceof MediaStream
696-
? video.srcObject.getTracks()
697-
: []) {
698-
track.stop();
699-
}
700-
video.srcObject = null;
701-
}
718+
track?.stop();
719+
if (video) video.srcObject = null;
702720
},
703721
command: (message) => {
704722
send(message);

‎apps/mobile/src/features/threads/ThreadFeed.tsx‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1719,11 +1719,15 @@ function renderFeedEntry(
17191719
className="mb-5 items-end"
17201720
{...(enterAnimated ? { entering: FadeInUp.duration(220) } : {})}
17211721
>
1722-
{presentation.isAutomation ? (
1722+
{presentation.attribution === "automation" ? (
17231723
<Text className="mb-1 pr-1 font-t3-medium text-2xs text-foreground-muted opacity-60">
17241724
Sent by automation
17251725
</Text>
1726-
) : message.createdBy === "agent" ? (
1726+
) : presentation.attribution === "t3code" ? (
1727+
<Text className="mb-1 pr-1 font-t3-medium text-2xs text-foreground-muted opacity-60">
1728+
Sent by T3 Code
1729+
</Text>
1730+
) : presentation.attribution === "agent" ? (
17271731
<AgentMessageAttribution
17281732
environmentId={props.environmentId}
17291733
senderThreadId={message.senderThreadId}

‎apps/mobile/src/lib/threadActivity.test.ts‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,24 @@ it("shows only the structured path in expanded mobile read details", () => {
8585
expect(withoutPath?.canExpand).toBe(false);
8686
});
8787

88+
it("expands a T3 Code notice to the prompt the agent got", () => {
89+
const item = {
90+
...base("restart-notice", "2026-06-20T00:00:03.000Z", 2),
91+
type: "notification",
92+
source: { kind: "system" },
93+
outcome: "updated",
94+
summary: "T3 Code restarted and resumed this turn",
95+
detail: "Continue where you left off.",
96+
} as OrchestrationV2TurnItem;
97+
const [activity] = buildThreadFeed([projected(item, 0)]).flatMap((entry) =>
98+
entry.type === "activity-group" ? entry.activities : [],
99+
);
100+
101+
expect(activity?.summary).toBe("T3 Code restarted and resumed this turn");
102+
expect(activity?.canExpand).toBe(true);
103+
expect(activity?.getFullDetail()).toBe("Continue where you left off.");
104+
});
105+
88106
it("labels file searches with the adapter title and its search target", () => {
89107
const item: OrchestrationV2TurnItem = {
90108
...base("file-search", "2026-06-20T00:00:03.000Z", 2),
@@ -317,7 +335,7 @@ describe("buildThreadFeed", () => {
317335
expect(messageEntry).toBeDefined();
318336
expect(resolveUserMessagePresentation(messageEntry!.message)).toMatchObject({
319337
text: "Run checks",
320-
isAutomation: true,
338+
attribution: "automation",
321339
});
322340
});
323341

‎apps/mobile/src/lib/threadActivity.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ function itemIcon(item: OrchestrationV2TurnItem): ThreadFeedActivity["icon"] {
521521
case "monitor":
522522
return "eye";
523523
case "background_task":
524+
case "system":
524525
return "zap";
525526
default:
526527
source satisfies never;
@@ -814,7 +815,11 @@ function toFeedActivity(
814815
? collectToolFilePaths(item)
815816
: null;
816817
const getFullDetail = memoizeValue(() =>
817-
readPaths ? readPaths.join("\n") || null : formatItemFullDetail(row, item),
818+
readPaths
819+
? readPaths.join("\n") || null
820+
: item.type === "notification"
821+
? item.detail?.trim() || null
822+
: formatItemFullDetail(row, item),
818823
);
819824
const getCopyText = memoizeValue(() =>
820825
[summary, detail, getFullDetail()]

‎apps/server/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"@t3tools/source-control-bitbucket": "workspace:*",
5050
"@t3tools/source-control-core": "workspace:*",
5151
"@t3tools/source-control-forgejo": "workspace:*",
52+
"@t3tools/source-control-gitcafe": "workspace:*",
5253
"@t3tools/source-control-github": "workspace:*",
5354
"@t3tools/source-control-gitlab": "workspace:*",
5455
"effect": "catalog:",

‎apps/server/src/auth/RpcAuthorization.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ export const RPC_REQUIRED_SCOPES = {
135135
// Read scope like the reads it un-caches: refreshing is part of reading, and a read-only
136136
// client pressing refresh must not be told it may not look again.
137137
[WS_METHODS.pullRequestsInvalidate]: AuthOrchestrationReadScope,
138+
[WS_METHODS.pullRequestsReportState]: AuthOrchestrationReadScope,
138139
[WS_METHODS.pullRequestsSubscribeRefreshes]: AuthOrchestrationReadScope,
139140
// The candidate list is a read like the detail beside it; asking somebody for a review is a
140141
// write like every other one.

‎apps/server/src/observability/RpcInstrumentation.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ const RPC_AGGREGATES = {
118118
[WS_METHODS.pullRequestsSetReaction]: "pull-requests",
119119
[WS_METHODS.pullRequestsSetFilesViewed]: "pull-requests",
120120
[WS_METHODS.pullRequestsInvalidate]: "pull-requests",
121+
[WS_METHODS.pullRequestsReportState]: "pull-requests",
121122
[WS_METHODS.pullRequestsSubscribeRefreshes]: "pull-requests",
122123
[WS_METHODS.pullRequestsReviewerCandidates]: "pull-requests",
123124
[WS_METHODS.pullRequestsRequestReviewers]: "pull-requests",

‎apps/server/src/orchestration-v2/Orchestrator.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4674,11 +4674,17 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
46744674
dispatchMode = { type: "start_immediately" };
46754675
}
46764676
}
4677+
// A restart continuation resumes the interrupted turn, so it starts
4678+
// immediately rather than queueing like other wakes.
46774679
if (
46784680
command.notification !== undefined &&
46794681
(command.createdBy !== "agent" ||
46804682
(command.creationSource !== "server" && command.creationSource !== "provider") ||
4681-
dispatchMode.type !== "queue_after_active")
4683+
(dispatchMode.type !== "queue_after_active" &&
4684+
!(
4685+
command.restartContinuationOfRunId !== undefined &&
4686+
dispatchMode.type === "start_immediately"
4687+
)))
46824688
) {
46834689
return yield* new OrchestratorDispatchError({
46844690
commandId: command.commandId,

‎apps/server/src/orchestration-v2/RestartContinuation.test.ts‎

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
RunAttemptId,
1111
RunId,
1212
ThreadId,
13+
type OrchestrationV2Command,
1314
type OrchestrationV2ThreadProjection,
1415
} from "@t3tools/contracts";
1516
import * as DateTime from "effect/DateTime";
@@ -606,27 +607,32 @@ it.effect("does not cancel or resume a run that completes while shutdown intent
606607
}),
607608
);
608609

609-
const continuationTexts = (projection: OrchestrationV2ThreadProjection) =>
610+
const continuationDispatches = (projection: OrchestrationV2ThreadProjection) =>
610611
Effect.gen(function* () {
611-
const texts: Array<string> = [];
612+
const dispatches: Array<Extract<OrchestrationV2Command, { type: "message.dispatch" }>> = [];
612613
yield* continueRestartedRun({ threadId, sourceRunId: runId }).pipe(
613614
Effect.provide(
614615
Layer.merge(
615616
Layer.mock(ThreadManagementService.ThreadManagementService)({
616617
getThreadRecords: () => Effect.succeed(projection),
617618
recoverDelegatedTask: () => Effect.void,
618619
dispatch: (command) => {
619-
if (command.type === "message.dispatch") texts.push(command.text);
620+
if (command.type === "message.dispatch") dispatches.push(command);
620621
return Effect.succeed({} as never);
621622
},
622623
}),
623624
ServerSettings.layerTest({ continueThreadsAfterServerUpdate: true }),
624625
),
625626
),
626627
);
627-
return texts;
628+
return dispatches;
628629
});
629630

631+
const continuationTexts = (projection: OrchestrationV2ThreadProjection) =>
632+
continuationDispatches(projection).pipe(
633+
Effect.map((dispatches) => dispatches.map((command) => command.text)),
634+
);
635+
630636
const cutMidTurn = (extra: Record<string, unknown> = {}) => {
631637
const base = makeProjection();
632638
return {
@@ -740,6 +746,18 @@ it.effect("tells a turn cut mid-way about the background work it lost", () =>
740746
}),
741747
);
742748

749+
it.effect("shows a continuation as a T3 Code notice whose detail is the prompt", () =>
750+
Effect.gen(function* () {
751+
const [resumed] = yield* continuationDispatches(cutMidTurn());
752+
assert.deepEqual(resumed?.notification, {
753+
source: { kind: "system" },
754+
outcome: "updated",
755+
summary: "T3 Code restarted and resumed this turn",
756+
detail: "Continue where you left off.",
757+
});
758+
}),
759+
);
760+
743761
it.effect(
744762
"carries the note forward when its continuation was cut before reaching the provider",
745763
() =>

‎apps/server/src/orchestration-v2/RestartContinuation.ts‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,17 +153,27 @@ export const continueRestartedRun = Effect.fn("RestartContinuation.continueResta
153153
);
154154
const noteText =
155155
note.work.length === 0 ? undefined : restartCancelledBackgroundWorkNote(note.work);
156+
const text =
157+
noteText === undefined
158+
? CONTINUE_PROMPT
159+
: note.settled
160+
? noteText
161+
: `${noteText}\n\n${CONTINUE_PROMPT}`;
156162
yield* threads.dispatch({
157163
type: "message.dispatch",
158164
commandId: CommandId.make(`command:restart-continuation:${input.sourceRunId}`),
159165
threadId: input.threadId,
160166
messageId,
161-
text:
162-
noteText === undefined
163-
? CONTINUE_PROMPT
164-
: note.settled
165-
? noteText
166-
: `${noteText}\n\n${CONTINUE_PROMPT}`,
167+
text,
168+
// Shown as a work log row; the prompt the agent got is its detail.
169+
notification: {
170+
source: { kind: "system" },
171+
outcome: "updated",
172+
summary: note.settled
173+
? "T3 Code restarted and stopped background work"
174+
: "T3 Code restarted and resumed this turn",
175+
detail: text,
176+
},
167177
attachments: [],
168178
modelSelection: source.modelSelection,
169179
dispatchMode: { type: "start_immediately" },

0 commit comments

Comments
 (0)