Skip to content

Commit ccc46f5

Browse files
committed
Merge remote-tracking branch 'origin/main' into t3/fix-search-result-drag-previews
2 parents 2cbf668 + 5f2bb93 commit ccc46f5

29 files changed

Lines changed: 747 additions & 97 deletions

‎apps/mobile/src/features/threads/thread-command-output.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ export function ThreadCommandOutput(props: {
5353
}
5454
return (
5555
<View className="pt-1.5">
56-
{data?.output.truncated ? (
57-
<Text className="pb-0.5 text-3xs text-foreground-subtle">Earlier output not shown</Text>
58-
) : null}
5956
<ScrollView
6057
ref={scrollRef}
6158
nestedScrollEnabled
@@ -73,6 +70,9 @@ export function ThreadCommandOutput(props: {
7370
if (followRef.current) scrollRef.current?.scrollToEnd({ animated: false });
7471
}}
7572
>
73+
{data?.output.truncated ? (
74+
<Text className="pb-0.5 text-3xs text-foreground-subtle">Earlier output not shown</Text>
75+
) : null}
7676
<Text selectable className="font-mono text-2xs leading-normal text-foreground-muted">
7777
{spans.map((span, index) =>
7878
span.style === null ? (

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
AssetWorkspaceRootNormalizationError,
1616
SOURCE_CONTROL_MEDIA_ASSET,
1717
ThreadId,
18-
ToolActivityNativeAppReference,
18+
NativeAppIconReference,
1919
TurnItemId,
2020
} from "@t3tools/contracts";
2121
import {
@@ -152,7 +152,7 @@ const AssetClaimsSchema = Schema.Union([
152152
Schema.Struct({
153153
version: Schema.Literal(1),
154154
kind: Schema.Literal("native-app-icon"),
155-
app: ToolActivityNativeAppReference,
155+
app: NativeAppIconReference,
156156
expiresAt: Schema.Number,
157157
}),
158158
Schema.Struct({
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
2+
import * as NodeServices from "@effect/platform-node/NodeServices";
3+
import { expect, it } from "@effect/vitest";
4+
import * as Effect from "effect/Effect";
5+
import * as FileSystem from "effect/FileSystem";
6+
import * as Layer from "effect/Layer";
7+
import * as Path from "effect/Path";
8+
import { ChildProcessSpawner } from "effect/process";
9+
import * as HostProcess from "@t3tools/shared/HostProcess";
10+
11+
import * as ServerConfig from "../config.ts";
12+
import * as NativeAppIconResolver from "./NativeAppIconResolver.ts";
13+
14+
it.effect("resolves the exact bundle path without Spotlight and caches the converted icon", () =>
15+
Effect.gen(function* () {
16+
const fs = yield* FileSystem.FileSystem;
17+
const path = yield* Path.Path;
18+
const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-bundle-icon-" });
19+
const bundle = path.join(root, "Build Output", "My App.app");
20+
const resources = path.join(bundle, "Contents", "Resources");
21+
yield* fs.makeDirectory(resources, { recursive: true });
22+
yield* fs.writeFileString(path.join(resources, "AppIcon.icns"), "icon");
23+
const commands: string[] = [];
24+
const spawner = Layer.mock(ChildProcessSpawner.ChildProcessSpawner)({
25+
string: (command) =>
26+
Effect.gen(function* () {
27+
if (command._tag !== "StandardCommand") return "";
28+
commands.push(command.command);
29+
if (command.command === "/usr/bin/plutil") return "AppIcon";
30+
if (command.command === "/usr/bin/sips") {
31+
yield* fs.writeFileString(String(command.args.at(-1)), "converted icon");
32+
}
33+
return "";
34+
}),
35+
});
36+
yield* Effect.gen(function* () {
37+
const resolver = yield* NativeAppIconResolver.make;
38+
const reference = { _tag: "app-path" as const, path: bundle };
39+
const icon = yield* resolver.resolve(reference);
40+
expect(icon).not.toBeNull();
41+
if (icon === null) return;
42+
expect(yield* fs.readFileString(icon)).toBe("converted icon");
43+
expect(yield* resolver.resolve(reference)).toBe(icon);
44+
expect(yield* resolver.resolve({ _tag: "app-path", path: "~/Build Output/My App.app" })).toBe(
45+
icon,
46+
);
47+
expect(commands.filter((command) => command === "/usr/bin/sips")).toHaveLength(1);
48+
expect(commands).not.toContain("/usr/bin/mdfind");
49+
expect(yield* resolver.resolve({ _tag: "app-path", path: "relative.app" })).toBeNull();
50+
expect(yield* resolver.resolve({ _tag: "app-path", path: root })).toBeNull();
51+
}).pipe(
52+
Effect.provide(
53+
Layer.mergeAll(
54+
spawner,
55+
ServerConfig.ServerConfig.layerTest(root, { prefix: "t3-native-icon-config-" }),
56+
),
57+
),
58+
Effect.provideService(HostProcess.Platform, "darwin"),
59+
Effect.provideService(HostProcess.HomeDirectory, root),
60+
);
61+
}).pipe(Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
62+
);

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import type { ToolActivityNativeAppReference } from "@t3tools/contracts";
1+
import { expandHomePath } from "@t3tools/provider-core/server/pathExpansion";
2+
import type { NativeAppIconReference } from "@t3tools/contracts";
23
import * as Cache from "effect/Cache";
34
import * as Cause from "effect/Cause";
45
import * as Digest from "effect/crypto/Digest";
@@ -28,16 +29,16 @@ const RESOLUTION_CACHE_MAX_ENTRIES = 256;
2829
export class NativeAppIconResolver extends Context.Service<
2930
NativeAppIconResolver,
3031
{
31-
readonly resolve: (app: ToolActivityNativeAppReference) => Effect.Effect<string | null>;
32+
readonly resolve: (app: NativeAppIconReference) => Effect.Effect<string | null>;
3233
}
3334
>()("t3/assets/NativeAppIconResolver") {}
3435

35-
function appCacheKey(app: ToolActivityNativeAppReference): string {
36+
function appCacheKey(app: NativeAppIconReference): string {
3637
return JSON.stringify(app);
3738
}
3839

39-
function appFromCacheKey(key: string): ToolActivityNativeAppReference {
40-
return JSON.parse(key) as ToolActivityNativeAppReference;
40+
function appFromCacheKey(key: string): NativeAppIconReference {
41+
return JSON.parse(key) as NativeAppIconReference;
4142
}
4243

4344
const existingFile = Effect.fn("NativeAppIconResolver.existingFile")(function* (filePath: string) {
@@ -91,9 +92,13 @@ function containsControlCharacter(value: string): boolean {
9192
}
9293

9394
const resolveApplicationPath = Effect.fn("NativeAppIconResolver.resolveApplicationPath")(function* (
94-
app: ToolActivityNativeAppReference,
95+
app: NativeAppIconReference,
9596
) {
9697
const path = yield* Path.Path;
98+
if (app._tag === "app-path") {
99+
const appPath = expandHomePath(app.path, yield* HostProcess.HomeDirectory);
100+
return path.isAbsolute(appPath) && appPath.endsWith(".app") ? appPath : null;
101+
}
97102
const query =
98103
app._tag === "app-id"
99104
? `kMDItemCFBundleIdentifier == '${app.appId}'`
@@ -131,7 +136,7 @@ const resolveApplicationPath = Effect.fn("NativeAppIconResolver.resolveApplicati
131136
});
132137

133138
const resolveNativeAppIconUncached = Effect.fn("NativeAppIconResolver.resolveUncached")(function* (
134-
app: ToolActivityNativeAppReference,
139+
app: NativeAppIconReference,
135140
) {
136141
const fileSystem = yield* FileSystem.FileSystem;
137142
const path = yield* Path.Path;
@@ -242,7 +247,7 @@ export const make = Effect.gen(function* () {
242247
);
243248

244249
const resolveAttempt = Effect.fn("NativeAppIconResolver.resolve")(function* (
245-
app: ToolActivityNativeAppReference,
250+
app: NativeAppIconReference,
246251
) {
247252
if (
248253
hostPlatform !== "darwin" ||

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,10 +412,14 @@ it.effect("separates host file URLs from readable attachment URLs", () =>
412412
yield* client[WS_METHODS.assetsCreateUrl]({
413413
resource: { _tag: "attachment", attachmentId: "image" },
414414
});
415+
yield* client[WS_METHODS.assetsCreateUrl]({
416+
resource: { _tag: "native-app-icon", app: { _tag: "app-id", appId: "com.apple.calculator" } },
417+
});
415418
for (const resource of [
416419
{ _tag: "workspace-file", threadId: ThreadId.make("thread"), path: "file.txt" },
417420
{ _tag: "media-file", threadId: ThreadId.make("thread"), path: "/repo/image.png" },
418421
{ _tag: "draft-workspace-file", cwd: "/repo", path: "file.txt" },
422+
{ _tag: "native-app-icon", app: { _tag: "app-path", path: "/private/Secret.app" } },
419423
] as const) {
420424
expect(
421425
yield* client[WS_METHODS.assetsCreateUrl]({ resource }).pipe(Effect.flip),
@@ -424,7 +428,7 @@ it.effect("separates host file URLs from readable attachment URLs", () =>
424428
requiredPermission: AuthFilesystemReadScope,
425429
});
426430
}
427-
expect(handled).toBe(1);
431+
expect(handled).toBe(2);
428432
}).pipe(Effect.scoped),
429433
);
430434

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,8 @@ const requiredScopesForRpcCall = (
265265
return [
266266
resource._tag === "workspace-file" ||
267267
resource._tag === "media-file" ||
268-
resource._tag === "draft-workspace-file"
268+
resource._tag === "draft-workspace-file" ||
269+
(resource._tag === "native-app-icon" && resource.app._tag === "app-path")
269270
? AuthFilesystemReadScope
270271
: AuthOrchestrationReadScope,
271272
];

‎apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts‎

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2891,6 +2891,174 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
28912891
}).pipe(Effect.scoped),
28922892
);
28932893

2894+
it.effect("projects successful native todo updates into one checklist", () =>
2895+
Effect.gen(function* () {
2896+
const updates = [
2897+
[
2898+
{ content: " Inspect code ", status: "completed" },
2899+
{ content: "Implement", status: "in_progress" },
2900+
{ content: "Verify", status: "pending" },
2901+
{ content: "Abandoned", status: "cancelled" },
2902+
],
2903+
[{ content: "Inspect code", status: "completed" }],
2904+
[{ content: "Abandoned", status: "cancelled" }],
2905+
[],
2906+
[{ content: "Follow up", status: "pending" }],
2907+
];
2908+
const tool = (id: string) => ({
2909+
sessionID: SESSION,
2910+
assistantMessageID: "msg_assistant",
2911+
id,
2912+
});
2913+
const call = (id: string, todos: unknown): ReadonlyArray<ProviderReplayEntry> => [
2914+
event("session.tool.input.started", { ...tool(id), name: "todowrite" }),
2915+
event("session.tool.called", { ...tool(id), input: { todos }, executed: false }),
2916+
];
2917+
const { runtime, thread } = yield* resumed([
2918+
out("session.prompt", { sessionID: SESSION, text: "<any>" }),
2919+
promptAccepted,
2920+
...call("call-denied", [{ content: "Not saved", status: "pending" }]),
2921+
event(
2922+
"session.tool.failed",
2923+
{
2924+
...tool("call-denied"),
2925+
error: { type: "unknown", message: "Unable to update todos" },
2926+
executed: false,
2927+
},
2928+
undefined,
2929+
2,
2930+
),
2931+
...call("call-malformed", [{ content: "Not saved", status: "pending" }]),
2932+
event(
2933+
"session.tool.success",
2934+
{
2935+
...tool("call-malformed"),
2936+
content: [{ type: "text", text: "Unrecognized todo result" }],
2937+
metadata: { todos: [{ content: "Unknown", status: "new-status" }] },
2938+
executed: false,
2939+
},
2940+
undefined,
2941+
2,
2942+
),
2943+
...updates.flatMap((todos, index) => [
2944+
...call(`call-todo-${index}`, todos),
2945+
event(
2946+
"session.tool.success",
2947+
{
2948+
...tool(`call-todo-${index}`),
2949+
content: [{ type: "text", text: "Todos updated" }],
2950+
metadata: { todos },
2951+
executed: false,
2952+
},
2953+
undefined,
2954+
2,
2955+
),
2956+
]),
2957+
event("session.execution.succeeded", { sessionID: SESSION }),
2958+
]);
2959+
const events = yield* runtime.events.pipe(
2960+
Stream.takeUntil((event) => event.type === "turn.terminal"),
2961+
Stream.runCollect,
2962+
Effect.forkScoped,
2963+
);
2964+
yield* runtime.startTurn(turnInput(thread));
2965+
const collected = yield* Fiber.join(events);
2966+
const plans = collected.flatMap((event) =>
2967+
event.type === "plan.updated" && event.plan.kind === "todo_list" ? [event.plan] : [],
2968+
);
2969+
assert.deepEqual(
2970+
plans.map((plan) => plan.steps.map((step) => [step.text, step.status])),
2971+
[
2972+
[
2973+
["Inspect code", "completed"],
2974+
["Implement", "running"],
2975+
["Verify", "pending"],
2976+
],
2977+
[["Inspect code", "completed"]],
2978+
[],
2979+
[],
2980+
[["Follow up", "pending"]],
2981+
],
2982+
);
2983+
assert.equal(new Set(plans.map((plan) => plan.id)).size, 1);
2984+
assert.equal(plans[0]?.steps[0]?.id, plans[1]?.steps[0]?.id);
2985+
assert.deepEqual(
2986+
plans.map((plan) => plan.status),
2987+
["active", "completed", "completed", "completed", "active"],
2988+
);
2989+
const items = collected.flatMap((event) =>
2990+
event.type === "turn_item.updated" ? [event.turnItem] : [],
2991+
);
2992+
const checklists = items.filter((item) => item.type === "todo_list");
2993+
assert.equal(new Set(checklists.map((item) => item.id)).size, 1);
2994+
assert.deepEqual(
2995+
checklists.map((item) => item.steps),
2996+
plans.map((plan) => plan.steps),
2997+
);
2998+
assert.deepEqual(
2999+
checklists.map((item) => item.status),
3000+
["completed", "completed", "completed", "completed", "completed"],
3001+
);
3002+
assert.isFalse(
3003+
items.some(
3004+
(item) =>
3005+
item.type === "dynamic_tool" && item.nativeItemRef?.nativeId?.startsWith("call-todo-"),
3006+
),
3007+
);
3008+
assert.deepInclude(
3009+
items.find((item) => item.nativeItemRef?.nativeId === "call-denied"),
3010+
{ type: "dynamic_tool", status: "failed" },
3011+
);
3012+
assert.deepInclude(
3013+
items.find((item) => item.nativeItemRef?.nativeId === "call-malformed"),
3014+
{ type: "dynamic_tool", status: "completed" },
3015+
);
3016+
}).pipe(Effect.scoped),
3017+
);
3018+
3019+
it.effect("recovers native todo updates missed during reconnect", () =>
3020+
Effect.gen(function* () {
3021+
const todos = [{ content: "Saved during disconnect", status: "in_progress" }];
3022+
const { runtime, thread } = yield* resumed([
3023+
out("session.prompt", { sessionID: SESSION, id: PROMPT_ID, text: "<any>" }),
3024+
promptAccepted,
3025+
...reconnected({}, "succeeded", {
3026+
content: [
3027+
{
3028+
type: "tool",
3029+
id: "call-todo-gap",
3030+
name: "todowrite",
3031+
executed: false,
3032+
state: {
3033+
status: "completed",
3034+
input: { todos },
3035+
content: [{ type: "text", text: "Todos updated" }],
3036+
metadata: { todos },
3037+
},
3038+
time: { created: 2, ran: 2, completed: 2 },
3039+
},
3040+
],
3041+
}),
3042+
]);
3043+
const events = yield* runtime.events.pipe(
3044+
Stream.takeUntil((event) => event.type === "turn.terminal"),
3045+
Stream.runCollect,
3046+
Effect.forkScoped,
3047+
);
3048+
yield* runtime.startTurn(turnInput(thread));
3049+
const collected = yield* Fiber.join(events);
3050+
const plans = collected.flatMap((event) =>
3051+
event.type === "plan.updated" && event.plan.kind === "todo_list" ? [event.plan] : [],
3052+
);
3053+
assert.equal(plans.length, 1);
3054+
assert.deepEqual(
3055+
plans[0]?.steps.map((step) => [step.text, step.status]),
3056+
[["Saved during disconnect", "running"]],
3057+
);
3058+
assert.include(turnItems(collected), "todo_list:completed");
3059+
}).pipe(Effect.scoped),
3060+
);
3061+
28943062
it.effect("stores a shell command that exits non-zero as failed", () =>
28953063
Effect.gen(function* () {
28963064
const tool = { sessionID: SESSION, assistantMessageID: "msg_assistant", id: "call-exit" };

0 commit comments

Comments
 (0)