Skip to content

Commit e1bf008

Browse files
Merge remote-tracking branch 'origin/main' into L04-18813
2 parents 2b5c6b7 + f34ba43 commit e1bf008

69 files changed

Lines changed: 2138 additions & 478 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/desktop/src/snapShot/SnapShotTransition.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ window.prepareCaptureTransition=async destination=>{
175175
const inner={width:Math.max(1,target.width-borderWidth*2),height:Math.max(1,target.height-borderWidth*2)};
176176
const sourceCenter={x:source.x+source.width/2,y:source.y+source.height/2},targetCenter={x:target.x+target.width/2,y:target.y+target.height/2};
177177
const initial="translate3d("+(sourceCenter.x-targetCenter.x)+"px,"+(sourceCenter.y-targetCenter.y)+"px,0) scale("+(source.width/target.width)+","+(source.height/target.height)+")";
178-
const imageWidth=Math.max(1,snapshot.naturalWidth||source.width),imageHeight=Math.max(1,snapshot.naturalHeight||source.height),cover=Math.max(inner.width/imageWidth,inner.height/imageHeight);
178+
const imageWidth=Math.max(1,snapshot.naturalWidth||source.width),imageHeight=Math.max(1,snapshot.naturalHeight||source.height),fit=Math.min(inner.width/imageWidth,inner.height/imageHeight);
179179
Object.assign(card.style,{left:target.x+"px",top:target.y+"px",width:target.width+"px",height:target.height+"px",borderRadius:destination.cornerRadius+"px",backgroundColor:destination.backgroundColor,boxShadow:"none"});
180180
Object.assign(content.style,{inset:borderWidth+"px",borderRadius:Math.max(0,destination.cornerRadius-borderWidth)+"px"});
181181
Object.assign(border.style,{borderWidth:borderWidth+"px",borderColor:destination.borderColor});
@@ -185,7 +185,7 @@ window.prepareCaptureTransition=async destination=>{
185185
const animations=[
186186
card.animate([{transform:initial},{transform:"translate3d(0,0,0) scale(1)"}],options),
187187
content.animate([{transform:"scale("+(target.width/inner.width)+","+(target.height/inner.height)+")"},{transform:"scale(1)"}],options),
188-
snapshot.animate([{transform:"scale(1)"},{transform:"scale("+((imageWidth*cover)/inner.width)+","+((imageHeight*cover)/inner.height)+")"}],options),
188+
snapshot.animate([{transform:"scale(1)"},{transform:"scale("+((imageWidth*fit)/inner.width)+","+((imageHeight*fit)/inner.height)+")"}],options),
189189
border.animate([{opacity:0},{opacity:1}],options),
190190
details.animate([{opacity:0},{opacity:1}],{delay:Math.max(0,destination.durationMs-125),duration:125,fill:"both",easing:"ease-in"})
191191
];

‎apps/desktop/src/wsl/DesktopWslEnvironment.test.ts‎

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,30 @@
22
import { describe, it } from "@effect/vitest";
33
import { afterAll, expect } from "vite-plus/test";
44
import * as NodeChildProcess from "node:child_process";
5+
import * as Deferred from "effect/Deferred";
56
import * as Duration from "effect/Duration";
67
import * as Effect from "effect/Effect";
78
import * as Fiber from "effect/Fiber";
9+
import * as FileSystem from "effect/FileSystem";
810
import * as Layer from "effect/Layer";
11+
import * as Option from "effect/Option";
12+
import * as Path from "effect/Path";
913
import * as Sink from "effect/Sink";
1014
import * as Stream from "effect/Stream";
1115
import * as TestClock from "effect/testing/TestClock";
1216
import { ChildProcessSpawner } from "effect/process";
1317

18+
import * as DesktopConfig from "../app/DesktopConfig.ts";
19+
import * as DesktopEnvironment from "../app/DesktopEnvironment.ts";
1420
import {
1521
buildWslRuntimeInstallScript,
1622
buildWslRuntimeInvalidateScript,
1723
buildWslRuntimePruneScript,
1824
buildWslRuntimeProbeScript,
1925
DesktopWslDistroListError,
26+
DesktopWslEnvironment,
2027
formatMissingToolsReason,
28+
layer as wslEnvironmentLayer,
2129
parseNodePath,
2230
parseNodeVersion,
2331
parseResolvedPath,
@@ -158,6 +166,102 @@ describe("probeWslDistros", () => {
158166
});
159167
});
160168

169+
describe("WSL command deadlines", () => {
170+
const makeControlledEnvironment = Effect.gen(function* () {
171+
const started = yield* Deferred.make<void>();
172+
const exited = yield* Deferred.make<ChildProcessSpawner.ExitCode>();
173+
const released = yield* Deferred.make<void>();
174+
const spawner = ChildProcessSpawner.make(() =>
175+
Effect.acquireRelease(
176+
Deferred.succeed(started, undefined).pipe(
177+
Effect.as(
178+
ChildProcessSpawner.makeHandle({
179+
pid: ChildProcessSpawner.ProcessId(1),
180+
exitCode: Deferred.await(exited),
181+
isRunning: Deferred.isDone(exited).pipe(Effect.map((done) => !done)),
182+
kill: () => Effect.void,
183+
unref: Effect.succeed(Effect.void),
184+
stdin: Sink.drain,
185+
stdout: Stream.empty,
186+
stderr: Stream.empty,
187+
all: Stream.empty,
188+
getInputFd: () => Sink.drain,
189+
getOutputFd: () => Stream.empty,
190+
}),
191+
),
192+
),
193+
() => Deferred.succeed(released, undefined),
194+
),
195+
);
196+
const environment = yield* DesktopWslEnvironment.pipe(
197+
Effect.provide(
198+
wslEnvironmentLayer.pipe(
199+
Layer.provide([
200+
DesktopEnvironment.layer({
201+
dirname: "/repo/apps/desktop",
202+
homeDirectory: "/home/test",
203+
platform: "win32",
204+
processArch: "x64",
205+
appVersion: "1.2.3",
206+
appPath: "/repo",
207+
isPackaged: true,
208+
resourcesPath: "/repo/resources",
209+
runningUnderArm64Translation: false,
210+
}).pipe(Layer.provide([Path.layer, DesktopConfig.layerTest({})])),
211+
FileSystem.layerNoop({ exists: () => Effect.succeed(true) }),
212+
Layer.succeed(ChildProcessSpawner.ChildProcessSpawner, spawner),
213+
]),
214+
),
215+
),
216+
);
217+
return { environment, started, exited, released };
218+
});
219+
220+
it.effect("waits for a cold distro to finish starting after 15 seconds", () =>
221+
Effect.gen(function* () {
222+
const { environment, started, exited, released } = yield* makeControlledEnvironment;
223+
const fiber = yield* environment.preWarm("Ubuntu").pipe(Effect.forkScoped);
224+
yield* Deferred.await(started);
225+
yield* TestClock.adjust(Duration.seconds(15));
226+
expect(yield* Deferred.isDone(released)).toBe(false);
227+
228+
yield* Deferred.succeed(exited, ChildProcessSpawner.ExitCode(0));
229+
yield* Fiber.join(fiber);
230+
expect(yield* Deferred.isDone(released)).toBe(true);
231+
}),
232+
);
233+
234+
it.effect("releases a stalled warmup process at the 30-second deadline", () =>
235+
Effect.gen(function* () {
236+
const { environment, started, released } = yield* makeControlledEnvironment;
237+
const fiber = yield* environment.preWarm("Ubuntu").pipe(Effect.forkScoped);
238+
yield* Deferred.await(started);
239+
yield* TestClock.adjust(Duration.seconds(29));
240+
expect(yield* Deferred.isDone(released)).toBe(false);
241+
242+
yield* TestClock.adjust(Duration.seconds(1));
243+
yield* Fiber.join(fiber);
244+
expect(yield* Deferred.isDone(released)).toBe(true);
245+
}),
246+
);
247+
248+
it.effect("still gives path conversion only 10 seconds and releases its process", () =>
249+
Effect.gen(function* () {
250+
const { environment, started, released } = yield* makeControlledEnvironment;
251+
const fiber = yield* environment
252+
.windowsToWslPath("Ubuntu", "C:\\project")
253+
.pipe(Effect.forkScoped);
254+
yield* Deferred.await(started);
255+
yield* TestClock.adjust(Duration.seconds(9));
256+
expect(yield* Deferred.isDone(released)).toBe(false);
257+
258+
yield* TestClock.adjust(Duration.seconds(1));
259+
expect(yield* Fiber.join(fiber)).toEqual(Option.none());
260+
expect(yield* Deferred.isDone(released)).toBe(true);
261+
}),
262+
);
263+
});
264+
161265
describe("WSL runtime cache", () => {
162266
it.each([
163267
[

‎apps/desktop/src/wsl/DesktopWslEnvironment.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import { parseWslDistroList, type WslDistro } from "./wslPathParsing.ts";
1717

1818
const PROCESS_TERMINATE_GRACE = Duration.seconds(1);
1919
const LIST_TIMEOUT = Duration.seconds(8);
20-
const PRE_WARM_TIMEOUT = Duration.seconds(10);
20+
// Booting a stopped distro needs more time than converting paths in a running one.
21+
const PRE_WARM_TIMEOUT = Duration.seconds(30);
2122
const WSLPATH_TIMEOUT = Duration.seconds(10);
2223
const PROBE_TIMEOUT = Duration.seconds(10);
2324
const TOOLCHAIN_TIMEOUT = Duration.seconds(10);

‎apps/mobile/src/features/settings/SettingsEnvironmentDetailRouteScreen.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,8 @@ function EnvironmentDetail({ environmentId }: { readonly environmentId: Environm
248248
: "You are up to date."}
249249
</Text>
250250
) : null}
251-
{!supportsEnvironmentUpdate(config.environment.capabilities) ? (
251+
{checkedRelease?.targetVersion &&
252+
!supportsEnvironmentUpdate(config.environment.capabilities) ? (
252253
<Text className="text-sm text-foreground-muted">
253254
{capabilities?.serverSelfUpdate === "desktop-managed"
254255
? "Update the desktop app on this machine."

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

Lines changed: 74 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import { settlePromise, squashAtomCommandFailure } from "@t3tools/client-runtime
22
import { AsyncResult } from "effect/reactivity";
33
import * as Dialog from "../../components/ui/Dialog";
44
import { useAtomValue } from "@effect/atom-react";
5-
import { useChildThreadInputs, useThreadReportedModelSelection } from "../../state/entities";
5+
import {
6+
useChildThreadInputs,
7+
useThreadReportedModelSelection,
8+
useThreadShell,
9+
} from "../../state/entities";
610
import { UsageLimitRecoveryCard } from "./UsageLimitRecoveryCard";
711
import { useNavigation } from "@react-navigation/native";
812
import type { WorktreeSetupCardProps } from "./worktree-setup-card";
@@ -319,6 +323,70 @@ const USER_INPUT_TOGGLE_TIMING = {
319323
easing: Easing.out(Easing.cubic),
320324
};
321325

326+
// The visit watermark follows the shell's updatedAt, which ticks while a run
327+
// streams. Keeping it in a leaf lets the screen read the quiet shell.
328+
function ThreadVisitWatermark(props: {
329+
readonly environmentId: EnvironmentId;
330+
readonly selectedThread: EnvironmentThreadShell;
331+
readonly showContent: boolean;
332+
}) {
333+
const liveThread = useThreadShell({
334+
environmentId: props.environmentId,
335+
threadId: props.selectedThread.id,
336+
});
337+
const thread = liveThread ?? props.selectedThread;
338+
const showContent = props.showContent;
339+
const selectedThreadKey = scopedThreadKey(props.environmentId, thread.id);
340+
const visitThread = useAtomCommand(threadEnvironment.visit, { reportFailure: false });
341+
const lastDispatchedVisitRef = useRef<string | null>(null);
342+
const lastVisitDispatchRef = useRef({ threadKey: selectedThreadKey, at: 0 });
343+
const selectedThreadId = thread.id;
344+
const selectedThreadUpdatedAt = thread.updatedAt;
345+
const selectedThreadLastVisitedAt = thread.lastVisitedAt;
346+
const selectedThreadCompletedAt = thread.latestRun?.completedAt;
347+
useEffect(() => {
348+
if (!showContent || selectedThreadLastVisitedAt === undefined) return;
349+
const threadUpdatedAtMs = Date.parse(selectedThreadUpdatedAt);
350+
if (Number.isNaN(threadUpdatedAtMs)) return;
351+
const lastVisitedAtMs = selectedThreadLastVisitedAt
352+
? Date.parse(selectedThreadLastVisitedAt)
353+
: NaN;
354+
if (!Number.isNaN(lastVisitedAtMs) && lastVisitedAtMs >= threadUpdatedAtMs) return;
355+
const dispatchKey = `${selectedThreadKey}:${selectedThreadUpdatedAt}`;
356+
if (lastDispatchedVisitRef.current === dispatchKey) return;
357+
const dispatch = () => {
358+
lastDispatchedVisitRef.current = dispatchKey;
359+
lastVisitDispatchRef.current = { threadKey: selectedThreadKey, at: Date.now() };
360+
void visitThread({
361+
environmentId: props.environmentId,
362+
input: { threadId: selectedThreadId, visitedAt: selectedThreadUpdatedAt },
363+
});
364+
};
365+
const completedAtMs = selectedThreadCompletedAt ? Date.parse(selectedThreadCompletedAt) : NaN;
366+
const hasUnseenCompletion =
367+
!Number.isNaN(completedAtMs) &&
368+
(Number.isNaN(lastVisitedAtMs) || completedAtMs > lastVisitedAtMs);
369+
const previous = lastVisitDispatchRef.current;
370+
const elapsed = Date.now() - previous.at;
371+
if (previous.threadKey !== selectedThreadKey || hasUnseenCompletion || elapsed >= 10_000) {
372+
dispatch();
373+
return;
374+
}
375+
const timer = setTimeout(dispatch, 10_000 - elapsed);
376+
return () => clearTimeout(timer);
377+
}, [
378+
props.environmentId,
379+
selectedThreadId,
380+
selectedThreadKey,
381+
selectedThreadLastVisitedAt,
382+
selectedThreadCompletedAt,
383+
selectedThreadUpdatedAt,
384+
showContent,
385+
visitThread,
386+
]);
387+
return null;
388+
}
389+
322390
export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetailScreenProps) {
323391
const usesNativeWorkspaceColumns = useNativeWorkspaceColumnsSupported();
324392
const navigation = useNavigation();
@@ -785,54 +853,6 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
785853
setComposerFocused(false);
786854
}, [selectedThreadKey, showContent]);
787855

788-
const visitThread = useAtomCommand(threadEnvironment.visit, { reportFailure: false });
789-
const lastDispatchedVisitRef = useRef<string | null>(null);
790-
const lastVisitDispatchRef = useRef({ threadKey: selectedThreadKey, at: 0 });
791-
const selectedThreadId = props.selectedThread.id;
792-
const selectedThreadUpdatedAt = props.selectedThread.updatedAt;
793-
const selectedThreadLastVisitedAt = props.selectedThread.lastVisitedAt;
794-
const selectedThreadCompletedAt = props.selectedThread.latestRun?.completedAt;
795-
useEffect(() => {
796-
if (!showContent || selectedThreadLastVisitedAt === undefined) return;
797-
const threadUpdatedAtMs = Date.parse(selectedThreadUpdatedAt);
798-
if (Number.isNaN(threadUpdatedAtMs)) return;
799-
const lastVisitedAtMs = selectedThreadLastVisitedAt
800-
? Date.parse(selectedThreadLastVisitedAt)
801-
: NaN;
802-
if (!Number.isNaN(lastVisitedAtMs) && lastVisitedAtMs >= threadUpdatedAtMs) return;
803-
const dispatchKey = `${selectedThreadKey}:${selectedThreadUpdatedAt}`;
804-
if (lastDispatchedVisitRef.current === dispatchKey) return;
805-
const dispatch = () => {
806-
lastDispatchedVisitRef.current = dispatchKey;
807-
lastVisitDispatchRef.current = { threadKey: selectedThreadKey, at: Date.now() };
808-
void visitThread({
809-
environmentId: props.environmentId,
810-
input: { threadId: selectedThreadId, visitedAt: selectedThreadUpdatedAt },
811-
});
812-
};
813-
const completedAtMs = selectedThreadCompletedAt ? Date.parse(selectedThreadCompletedAt) : NaN;
814-
const hasUnseenCompletion =
815-
!Number.isNaN(completedAtMs) &&
816-
(Number.isNaN(lastVisitedAtMs) || completedAtMs > lastVisitedAtMs);
817-
const previous = lastVisitDispatchRef.current;
818-
const elapsed = Date.now() - previous.at;
819-
if (previous.threadKey !== selectedThreadKey || hasUnseenCompletion || elapsed >= 10_000) {
820-
dispatch();
821-
return;
822-
}
823-
const timer = setTimeout(dispatch, 10_000 - elapsed);
824-
return () => clearTimeout(timer);
825-
}, [
826-
props.environmentId,
827-
selectedThreadId,
828-
selectedThreadKey,
829-
selectedThreadLastVisitedAt,
830-
selectedThreadCompletedAt,
831-
selectedThreadUpdatedAt,
832-
showContent,
833-
visitThread,
834-
]);
835-
836856
useEffect(() => {
837857
setAnchorMessageId(null);
838858
setSubmittedMessageId(null);
@@ -1003,6 +1023,11 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
10031023
return (
10041024
<View className="flex-1">
10051025
{!usesNativeWorkspaceColumns ? <NativeLayoutObserver onChange={setScreenMetrics} /> : null}
1026+
<ThreadVisitWatermark
1027+
environmentId={props.environmentId}
1028+
selectedThread={props.selectedThread}
1029+
showContent={showContent}
1030+
/>
10061031
{showContent ? (
10071032
<View
10081033
style={{ flex: 1 }}

0 commit comments

Comments
 (0)