Skip to content

Commit 22dca85

Browse files
authored
Merge branch 'main' into fix/ios-dynamic-island-status-wrap
2 parents 58b5e25 + b5a226e commit 22dca85

124 files changed

Lines changed: 8193 additions & 4125 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/pull-requests/PullRequestRouteScreen.tsx‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,18 @@ export function PullRequestRouteScreen({ route }: StaticScreenProps<PullRequestP
299299
const [headerHeight, setHeaderHeight] = useState(0);
300300
const [viewportHeight, setViewportHeight] = useState(0);
301301
const scrollViews = useRef<Partial<Record<typeof section, LegendListRef | null>>>({});
302+
// AnimatedLegendList re-attaches its handle and sets state whenever its ref changes,
303+
// so an inline ref in the tab map loops the screen into "Maximum update depth exceeded".
304+
const [listRefs] = useState(() => {
305+
const listRef = (tab: typeof section) => (list: LegendListRef | null) => {
306+
scrollViews.current[tab] = list;
307+
};
308+
return {
309+
overview: listRef("overview"),
310+
guide: listRef("guide"),
311+
activity: listRef("activity"),
312+
};
313+
});
302314
const selectSection = (next: typeof section) => {
303315
if (next === section) return;
304316
scrollOffsets.current[section] = currentScrollOffset.current;
@@ -545,9 +557,7 @@ export function PullRequestRouteScreen({ route }: StaticScreenProps<PullRequestP
545557
importantForAccessibility={section === tab ? "auto" : "no-hide-descendants"}
546558
>
547559
<AnimatedLegendList
548-
ref={(list) => {
549-
scrollViews.current[tab] = list;
550-
}}
560+
ref={listRefs[tab]}
551561
initialScrollOffset={-insets.top}
552562
onScroll={(event) => {
553563
const offset = event.nativeEvent.contentOffset.y;

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

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,6 +1875,33 @@ function ThreadFeedPlaceholder(props: {
18751875
);
18761876
}
18771877

1878+
// A hook's return value is frozen to the compiler, so ThreadFeed's later
1879+
// hooks can't drag this derivation into an uncached scope.
1880+
function useThreadFeedPresentation(
1881+
props: ThreadFeedProps,
1882+
expandedTurnIds: ReadonlySet<RunId>,
1883+
expandedWorkGroups: Record<string, boolean>,
1884+
) {
1885+
const [feedCache] = useState(createThreadFeedCache);
1886+
return appendPendingThreadMessages(
1887+
deriveThreadFeedPresentation(
1888+
props.feed,
1889+
props.latestRun,
1890+
expandedTurnIds,
1891+
new Set(
1892+
Object.entries(expandedWorkGroups)
1893+
.filter(([, expanded]) => expanded)
1894+
.map(([groupId]) => groupId),
1895+
),
1896+
props.activeWorkStartedAt,
1897+
props.runlessWorkActive ?? false,
1898+
feedCache,
1899+
),
1900+
props.feed,
1901+
props.queuedMessages,
1902+
);
1903+
}
1904+
18781905
export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
18791906
const { listRef, onEndFollowEnabledChange, onHeaderMaterialVisibilityChange } = props;
18801907
const workflowOpening = useWorkflowOpening(props.environmentId, props.threadId);
@@ -1900,7 +1927,6 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
19001927
const disclosureSettleFrameRef = useRef<number | null>(null);
19011928
const disclosureSettleSecondFrameRef = useRef<number | null>(null);
19021929
const disclosureAnchorKeyRef = useRef<string | null>(null);
1903-
const [feedCache] = useState(createThreadFeedCache);
19041930
const previousLatestTurnRef = useRef(props.latestRun);
19051931
const userScrollSettleTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
19061932
const headerMaterialVisibleRef = useRef(false);
@@ -2456,23 +2482,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
24562482
reportHeaderMaterialVisibility(false);
24572483
}, [feedThreadKey, reportHeaderMaterialVisibility]);
24582484

2459-
const presentedFeed = appendPendingThreadMessages(
2460-
deriveThreadFeedPresentation(
2461-
props.feed,
2462-
props.latestRun,
2463-
expandedTurnIds,
2464-
new Set(
2465-
Object.entries(expandedWorkGroups)
2466-
.filter(([, expanded]) => expanded)
2467-
.map(([groupId]) => groupId),
2468-
),
2469-
props.activeWorkStartedAt,
2470-
props.runlessWorkActive ?? false,
2471-
feedCache,
2472-
),
2473-
props.feed,
2474-
props.queuedMessages,
2475-
);
2485+
const presentedFeed = useThreadFeedPresentation(props, expandedTurnIds, expandedWorkGroups);
24762486
const setupAnchorIndex = presentedFeed.findIndex(
24772487
(entry) => entry.type === "message" && entry.message.role === "user",
24782488
);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ describe("resolveMarkdownMediaPreview", () => {
3838
["/tmp/frame%23one.png:12", "/tmp/frame#one.png"],
3939
["/tmp/frame%3Fone.png:12:3", "/tmp/frame?one.png"],
4040
["/tmp/frame%2523one.png:12", "/tmp/frame%23one.png"],
41-
["file://server/share/frame.png", "\\\\server\\share\\frame.png"],
42-
["\\\\server\\share\\frame.png", "\\\\server\\share\\frame.png"],
43-
])("keeps encoded filename and UNC semantics for %s", (href, path) => {
44-
expect(resolveMarkdownMediaPreview(href, input)).toMatchObject({
41+
["file://server/share/frame.png", "\\\\server\\share\\frame.png", "\\\\server\\share"],
42+
["\\\\server\\share\\frame.png", "\\\\server\\share\\frame.png", "\\\\server\\share"],
43+
])("keeps encoded filename and UNC semantics for %s", (href, path, workspaceRoot = "/repo") => {
44+
expect(resolveMarkdownMediaPreview(href, { ...input, workspaceRoot })).toMatchObject({
4545
kind: "image",
4646
source: {
4747
resource: { path },

‎apps/mobile/src/reactCompilerCoverage.test.ts‎

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ interface CompilerEvent {
6666

6767
// babel.config.js is the file Metro loads; the logger rides on the preset's
6868
// own react-compiler option so the plugin runs with Metro's exact settings.
69-
function compilerBailouts(file: string): string[] {
70-
const events: CompilerEvent[] = [];
69+
function compileLikeMetro(file: string, events: CompilerEvent[], output: Record<string, unknown>) {
7170
const babelConfig = requireFromMobile("./babel.config.js")({ cache: () => {} });
7271
const presets = babelConfig.presets.map(([name, options]: [string, object]) =>
7372
name === "babel-preset-expo"
@@ -82,14 +81,20 @@ function compilerBailouts(file: string): string[] {
8281
]
8382
: [name, options],
8483
);
85-
babel.transformFileSync(NodePath.join(mobileRoot, file), {
84+
return babel.transformFileSync(NodePath.join(mobileRoot, file), {
8685
babelrc: false,
8786
configFile: false,
8887
cwd: mobileRoot,
8988
presets,
9089
caller: metroCaller,
9190
code: false,
91+
...output,
9292
});
93+
}
94+
95+
function compilerBailouts(file: string): string[] {
96+
const events: CompilerEvent[] = [];
97+
compileLikeMetro(file, events, {});
9398
return events
9499
.filter((event) => event.kind === "CompileError" || event.kind === "CompileSkip")
95100
.map(
@@ -98,6 +103,47 @@ function compilerBailouts(file: string): string[] {
98103
);
99104
}
100105

106+
interface AstNode {
107+
readonly type: string;
108+
readonly [key: string]: unknown;
109+
}
110+
111+
const isAstNode = (value: unknown): value is AstNode =>
112+
typeof value === "object" && value !== null && "type" in value && typeof value.type === "string";
113+
114+
function walkAst(
115+
value: unknown,
116+
visit: (node: AstNode, ancestors: readonly AstNode[]) => void,
117+
ancestors: readonly AstNode[] = [],
118+
) {
119+
if (typeof value !== "object" || value === null) return;
120+
const node = isAstNode(value) ? value : null;
121+
if (node) visit(node, ancestors);
122+
const childAncestors = node ? [...ancestors, node] : ancestors;
123+
for (const child of Object.values(value)) walkAst(child, visit, childAncestors);
124+
}
125+
126+
// For each call to `callee`, whether it runs only on the cache-miss branch of
127+
// an `if ($[n] !== dep)` block rather than on every render.
128+
function compilerCachedCalls(file: string, callee: string): boolean[] {
129+
const result = compileLikeMetro(file, [], { ast: true });
130+
const cached: boolean[] = [];
131+
if (typeof result !== "object" || result === null || !("ast" in result)) return cached;
132+
walkAst(result.ast, (node, ancestors) => {
133+
if (node.type !== "CallExpression" || !isAstNode(node.callee)) return;
134+
if (node.callee.type !== "Identifier" || node.callee.name !== callee) return;
135+
cached.push(
136+
ancestors.some(
137+
(ancestor, index) =>
138+
ancestor.type === "IfStatement" &&
139+
ancestors[index + 1] === ancestor.consequent &&
140+
JSON.stringify(ancestor.test).includes('"name":"$"'),
141+
),
142+
);
143+
});
144+
return cached;
145+
}
146+
101147
describe("React Compiler coverage", () => {
102148
it("Metro's transformer applies the compiler", async () => {
103149
const { transformer } = await metroConfig;
@@ -137,6 +183,14 @@ describe("React Compiler coverage", () => {
137183
}
138184
});
139185

186+
// The compiler once silently dropped this cache, so every
187+
// ThreadFeed render rebuilt the feed and handed LegendList a new data array.
188+
it("caches the thread feed derivation", () => {
189+
expect(
190+
compilerCachedCalls("src/features/threads/ThreadFeed.tsx", "deriveThreadFeedPresentation"),
191+
).toEqual([true]);
192+
});
193+
140194
it("lists only files that exist", () => {
141195
expect(Object.keys(KNOWN_BAILOUTS).filter((file) => !sourceFiles.includes(file))).toEqual([]);
142196
});

‎apps/server/src/assets/AssetAccess.test.ts‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import * as FileSystem from "effect/FileSystem";
1717
import * as Layer from "effect/Layer";
1818
import * as Redacted from "effect/Redacted";
1919
import * as Path from "effect/Path";
20+
import * as PlatformError from "effect/PlatformError";
2021
import * as Schema from "effect/Schema";
2122
import { HttpClient, HttpClientResponse, HttpServerResponse } from "effect/http";
2223
import { vi } from "vite-plus/test";
@@ -359,6 +360,47 @@ describe("AssetAccess", () => {
359360
}).pipe(Effect.provide(layerTest)),
360361
);
361362

363+
// Resolving `file://attacker.test/share/cat.jpg` from an agent's markdown sent the
364+
// Windows user's NTLM credentials to attacker.test.
365+
it.effect("never resolves a network media path outside the thread's project", () =>
366+
Effect.gen(function* () {
367+
const fs = yield* FileSystem.FileSystem;
368+
const path = yield* Path.Path;
369+
const resolved: Array<string> = [];
370+
const recordingFileSystem = FileSystem.FileSystem.of({
371+
...fs,
372+
realPath: (requestedPath) => {
373+
resolved.push(requestedPath);
374+
return Effect.fail(
375+
PlatformError.systemError({
376+
_tag: "NotFound",
377+
module: "FileSystem",
378+
method: "realPath",
379+
pathOrDescriptor: requestedPath,
380+
}),
381+
);
382+
},
383+
});
384+
const share = "//nas.test/share/project";
385+
for (const resource of [
386+
{
387+
_tag: "media-file",
388+
threadId: ThreadId.make("thread-1"),
389+
path: "//attacker.test/s/a.png",
390+
},
391+
{ _tag: "draft-workspace-file", cwd: share, path: "//attacker.test/s/a.png" },
392+
{ _tag: "media-file", threadId: ThreadId.make("thread-1"), path: `${share}/a.png` },
393+
] as const) {
394+
const error = yield* issueAssetUrl({ resource, workspaceRoot: share }).pipe(
395+
Effect.provideService(FileSystem.FileSystem, recordingFileSystem),
396+
Effect.flip,
397+
);
398+
expect(error._tag).toBe("AssetWorkspaceAssetNotFoundError");
399+
}
400+
expect(resolved).toEqual([path.resolve(`${share}/a.png`)]);
401+
}).pipe(Effect.provide(layerTest)),
402+
);
403+
362404
it.effect.skipIf(!symlinksSupported)(
363405
"rejects non-previewable files, disguised targets, and directories",
364406
() =>

‎apps/server/src/assets/AssetAccess.ts‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
isProjectFaviconPath,
3737
PROJECT_FAVICON_FALLBACK_MARKER,
3838
} from "@t3tools/shared/projectFavicon";
39+
import { isNetworkPath } from "@t3tools/shared/path";
3940
import { MAX_TOOL_OUTPUT_IMAGE_BASE64_LENGTH, toolOutputImages } from "@t3tools/shared/toolOutput";
4041
import * as Clock from "effect/Clock";
4142
import * as Crypto from "effect/Crypto";
@@ -60,6 +61,7 @@ import * as ServerConfig from "../config.ts";
6061
import * as Orchestrator from "../orchestration-v2/Orchestrator.ts";
6162
import { expandHomePath } from "@t3tools/provider-core/server/pathExpansion";
6263
import * as ProjectFaviconResolver from "../project/ProjectFaviconResolver.ts";
64+
import { isWithinRoot } from "../workspace/KnownWorkspaces.ts";
6365
import * as WorkspacePaths from "../workspace/WorkspacePaths.ts";
6466
import * as NativeAppIconResolver from "./NativeAppIconResolver.ts";
6567
import { extractIcnsPng } from "./icns.ts";
@@ -349,11 +351,27 @@ const readImageDimensionsFromHeader = (filePath: string) =>
349351
const finalizeAbsoluteMediaFileAsset = Effect.fn("AssetAccess.finalizeAbsoluteMediaFileAsset")(
350352
function* (input: {
351353
readonly requestedPath: string;
354+
readonly workspaceRoot: string | undefined;
352355
readonly resource: AssetResource;
353356
readonly expiresAt: number;
354357
}) {
355358
const path = yield* Path.Path;
356-
const canonicalFile = yield* resolveCanonicalFile(input.requestedPath).pipe(
359+
// Resolving a network path makes Windows sign in to its host with the
360+
// user's NTLM credentials, so only the thread's own project may be on a share.
361+
// Windows reads a `\\?\` path as written, `..` included, so the lookup gets
362+
// the resolved path this check approved.
363+
const requestedPath = path.resolve(input.requestedPath);
364+
if (
365+
isNetworkPath(input.requestedPath) &&
366+
(input.workspaceRoot === undefined ||
367+
!isWithinRoot(path, requestedPath, path.resolve(input.workspaceRoot)))
368+
) {
369+
return yield* new AssetWorkspaceAssetNotFoundError({
370+
resource: input.resource,
371+
checkedPath: input.requestedPath,
372+
});
373+
}
374+
const canonicalFile = yield* resolveCanonicalFile(requestedPath).pipe(
357375
Effect.mapError(
358376
(cause) => new AssetWorkspaceAssetInspectionError({ resource: input.resource, cause }),
359377
),
@@ -524,6 +542,7 @@ export const issueAssetUrl = Effect.fn("AssetAccess.issueAssetUrl")(function* (i
524542
}
525543
const finalized = yield* finalizeAbsoluteMediaFileAsset({
526544
requestedPath,
545+
workspaceRoot: input.workspaceRoot,
527546
resource: input.resource,
528547
expiresAt,
529548
});
@@ -566,6 +585,7 @@ export const issueAssetUrl = Effect.fn("AssetAccess.issueAssetUrl")(function* (i
566585
if (path.isAbsolute(hostPath)) {
567586
const finalized = yield* finalizeAbsoluteMediaFileAsset({
568587
requestedPath: hostPath,
588+
workspaceRoot: draftWorkspaceRoot,
569589
resource: input.resource,
570590
expiresAt,
571591
});

‎apps/server/src/cli/server.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ import { type CliServerFlags, resolveServerConfig, sharedServerCommandFlags } fr
1313

1414
const encodeCommand = Schema.encodeEffect(Schema.fromJsonString(Schema.String));
1515

16+
// The desktop launcher reads this process's stdout and stderr. Once it is gone,
17+
// every log write fails, and Node turns an unhandled stream error into a crash
18+
// that skips shutdown and leaves the ownership lock and runtime record behind.
19+
function ignoreClosedLauncherPipe(error: NodeJS.ErrnoException): void {
20+
if (error.code !== "EPIPE" && error.code !== "ERR_STREAM_DESTROYED") throw error;
21+
}
22+
1623
const runServerCommand = Effect.fn("server.runServerCommand")(function* (
1724
flags: CliServerFlags,
1825
options?: {
@@ -25,6 +32,10 @@ const runServerCommand = Effect.fn("server.runServerCommand")(function* (
2532
const config = yield* resolveServerConfig(flags, logLevel, options);
2633
const run = runServer.pipe(Effect.provideService(ServerConfig.ServerConfig, config));
2734
if (config.mode !== "desktop" || config.desktopBootstrapToken === undefined) return yield* run;
35+
yield* Effect.sync(() => {
36+
process.stdout.on("error", ignoreClosedLauncherPipe);
37+
process.stderr.on("error", ignoreClosedLauncherPipe);
38+
});
2839
return yield* Effect.raceFirst(
2940
run,
3041
awaitLauncherLoss().pipe(

‎apps/server/src/config.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,9 @@ const makeTest = Effect.fn("ServerConfig.makeTest")(function* (
187187
const baseDir =
188188
typeof baseDirOrPrefix === "string"
189189
? baseDirOrPrefix
190-
: yield* fs.makeTempDirectoryScoped({ prefix: baseDirOrPrefix.prefix });
190+
: // macOS temp dirs live under the /var -> /private/var symlink; storage cleanup's
191+
// symlink guards compare resolved paths, so generated test dirs must be real paths.
192+
yield* fs.realPath(yield* fs.makeTempDirectoryScoped({ prefix: baseDirOrPrefix.prefix }));
191193
const derivedPaths = yield* deriveServerPaths(baseDir, devUrl);
192194
yield* ensureServerDirectories(derivedPaths);
193195

0 commit comments

Comments
 (0)