Skip to content

Commit 0026eac

Browse files
authored
Merge branch 'main' into feat/thread-tags-ui
2 parents eb0fc60 + 9a35ab0 commit 0026eac

20 files changed

Lines changed: 410 additions & 64 deletions

‎apps/desktop/src/settings/DesktopAppSettings.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,28 @@ describe("DesktopSettings", () => {
240240
),
241241
);
242242

243+
it.effect("keeps Local environment off when another value in the file is unreadable", () =>
244+
withSettings(
245+
Effect.gen(function* () {
246+
const environment = yield* DesktopEnvironment.DesktopEnvironment;
247+
const fileSystem = yield* FileSystem.FileSystem;
248+
const settings = yield* DesktopAppSettings.DesktopAppSettings;
249+
yield* fileSystem.makeDirectory(environment.stateDir, { recursive: true });
250+
yield* fileSystem.writeFileString(
251+
environment.desktopSettingsPath,
252+
`{ "localEnvironmentEnabled": false, "serverExposureMode": "tailnet" }\n`,
253+
);
254+
255+
assert.isFalse((yield* settings.load).localEnvironmentEnabled);
256+
yield* settings.setMainWindowBounds({ x: 10, y: 20, width: 800, height: 600 }, false);
257+
assert.include(
258+
yield* fileSystem.readFileString(environment.desktopSettingsPath),
259+
`"localEnvironmentEnabled":false`,
260+
);
261+
}),
262+
),
263+
);
264+
243265
it.effect("rejects window bounds that do not satisfy the domain schema", () =>
244266
withSettings(
245267
Effect.gen(function* () {

‎apps/desktop/src/settings/DesktopAppSettings.ts‎

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,25 @@ const DesktopWindowBoundsDocument = Schema.Struct({
9090
height: Schema.Number,
9191
});
9292

93+
// A value this build cannot read drops only its own key, so the rest of the file
94+
// still loads and is written back instead of every setting resetting to defaults.
95+
const optionalReadableKey = <S extends Schema.Top>(schema: S) =>
96+
Schema.optionalKey(schema.pipe(Schema.catchDecoding(() => Effect.succeedNone)));
97+
9398
const DesktopSettingsDocument = Schema.Struct({
94-
localEnvironmentEnabled: Schema.optionalKey(Schema.Boolean),
95-
linuxPasswordStore: Schema.optionalKey(Schema.Unknown),
96-
mainWindowBounds: Schema.optionalKey(Schema.NullOr(DesktopWindowBoundsDocument)),
97-
mainWindowMaximized: Schema.optionalKey(Schema.Boolean),
98-
serverExposureMode: Schema.optionalKey(DesktopServerExposureModeSchema),
99-
tailscaleServeEnabled: Schema.optionalKey(Schema.Boolean),
100-
tailscaleServePort: Schema.optionalKey(Schema.Number),
101-
updateChannel: Schema.optionalKey(DesktopUpdateChannelSchema),
102-
updateChannelConfiguredByUser: Schema.optionalKey(Schema.Boolean),
103-
wslBackendEnabled: Schema.optionalKey(Schema.Boolean),
104-
wslMode: Schema.optionalKey(Schema.Literals(["local", "wsl"])),
105-
wslDistro: Schema.optionalKey(Schema.NullOr(Schema.String)),
106-
wslOnly: Schema.optionalKey(Schema.Boolean),
99+
localEnvironmentEnabled: optionalReadableKey(Schema.Boolean),
100+
linuxPasswordStore: optionalReadableKey(Schema.Unknown),
101+
mainWindowBounds: optionalReadableKey(Schema.NullOr(DesktopWindowBoundsDocument)),
102+
mainWindowMaximized: optionalReadableKey(Schema.Boolean),
103+
serverExposureMode: optionalReadableKey(DesktopServerExposureModeSchema),
104+
tailscaleServeEnabled: optionalReadableKey(Schema.Boolean),
105+
tailscaleServePort: optionalReadableKey(Schema.Number),
106+
updateChannel: optionalReadableKey(DesktopUpdateChannelSchema),
107+
updateChannelConfiguredByUser: optionalReadableKey(Schema.Boolean),
108+
wslBackendEnabled: optionalReadableKey(Schema.Boolean),
109+
wslMode: optionalReadableKey(Schema.Literals(["local", "wsl"])),
110+
wslDistro: optionalReadableKey(Schema.NullOr(Schema.String)),
111+
wslOnly: optionalReadableKey(Schema.Boolean),
107112
});
108113

109114
type DesktopSettingsDocument = typeof DesktopSettingsDocument.Type;

‎apps/mobile/modules/t3-terminal/ios/T3TerminalView.swift‎

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ public final class T3TerminalView: ExpoView, UITextFieldDelegate, UIEditMenuInte
285285
didSet {
286286
guard oldValue != fontSize else { return }
287287
inputField.font = UIFont.monospacedSystemFont(ofSize: max(fontSize, 13), weight: .regular)
288-
resetSurface()
288+
applyConfigInPlace()
289289
}
290290
}
291291

@@ -321,14 +321,14 @@ public final class T3TerminalView: ExpoView, UITextFieldDelegate, UIEditMenuInte
321321
didSet {
322322
guard oldValue != appearanceScheme else { return }
323323
appearance = TerminalAppearanceScheme(value: appearanceScheme)
324-
resetSurface()
324+
applyConfigInPlace()
325325
}
326326
}
327327

328328
var themeConfig: String = "" {
329329
didSet {
330330
guard oldValue != themeConfig else { return }
331-
resetSurface()
331+
applyConfigInPlace()
332332
}
333333
}
334334

@@ -663,7 +663,8 @@ public final class T3TerminalView: ExpoView, UITextFieldDelegate, UIEditMenuInte
663663
surfaceCreationFailed = true
664664
return
665665
}
666-
loadThemeConfig(into: config)
666+
// Creation proceeds without the file, as before; font_size is also set on the surface config.
667+
_ = loadThemeConfig(into: config)
667668
ghostty_config_finalize(config)
668669
defer { ghostty_config_free(config) }
669670

@@ -710,6 +711,27 @@ public final class T3TerminalView: ExpoView, UITextFieldDelegate, UIEditMenuInte
710711
setNeedsLayout()
711712
}
712713

714+
// Font and theme change in place: a new surface would replay output and re-answer its queries.
715+
private func applyConfigInPlace() {
716+
guard let app, let surface else {
717+
resetSurface()
718+
return
719+
}
720+
guard let config = ghostty_config_new() else { return }
721+
defer { ghostty_config_free(config) }
722+
let loaded = loadThemeConfig(into: config)
723+
ghostty_config_finalize(config)
724+
ghostty_app_set_color_scheme(app, appearance.ghosttyColorScheme)
725+
ghostty_surface_set_color_scheme(surface, appearance.ghosttyColorScheme)
726+
tickApp()
727+
// Without the file, the config lacks font-size and would reset the surface to defaults.
728+
if loaded {
729+
ghostty_surface_update_config(surface, config)
730+
}
731+
resizeSurface()
732+
setNeedsLayout()
733+
}
734+
713735
private func destroySurface() {
714736
// Unblock the io thread before ghostty_surface_free joins it.
715737
tickApp()
@@ -933,16 +955,16 @@ public final class T3TerminalView: ExpoView, UITextFieldDelegate, UIEditMenuInte
933955
terminalViewport.backgroundColor = backgroundColorValue
934956
}
935957

936-
private func loadThemeConfig(into config: ghostty_config_t) {
937-
guard let path = writeThemeConfigFile() else { return }
958+
private func loadThemeConfig(into config: ghostty_config_t) -> Bool {
959+
guard let path = writeThemeConfigFile() else { return false }
938960
path.withCString { cString in
939961
ghostty_config_load_file(config, cString)
940962
}
963+
return true
941964
}
942965

943966
private func writeThemeConfigFile() -> String? {
944-
guard !themeConfig.isEmpty else { return nil }
945-
let configContents = themeConfig
967+
let configContents = "\(themeConfig)\nfont-size = \(String(format: "%g", Double(fontSize)))\n"
946968
let url = URL(fileURLWithPath: NSTemporaryDirectory())
947969
.appendingPathComponent("t3-terminal-theme-\(appearance.rawValue).ghostty")
948970

‎apps/mobile/src/components/ui/AppBar.tsx‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Toolbar } from "./Toolbar";
22
import { AppActivityIndicator } from "./AppActivityIndicator";
33
import type { HeaderBarButtonMailSearchToolbarItem, SearchBarCommands } from "react-native-screens";
4-
import { NavigationContext } from "@react-navigation/native";
5-
import { use, useId, useLayoutEffect, useRef } from "react";
4+
import { NavigationContext, NavigationRouteContext } from "@react-navigation/native";
5+
import { use, useId, useLayoutEffect, useRef, useSyncExternalStore } from "react";
66
import { View } from "react-native";
77
import { createNativeHeaderMenu } from "./nativeHeaderMenu.ios";
88
import { ScreenHeaderButton } from "./ScreenHeaderButton";
@@ -63,6 +63,17 @@ export function AppBar(props: AppBarProps) {
6363
? { ...props.backInSplitView, onPress: splitBackPress }
6464
: null;
6565
const navigation = use(NavigationContext);
66+
const route = use(NavigationRouteContext);
67+
// A thread opened from another thread sits on it, not beside the list, so it keeps Back.
68+
const threadBelow = useSyncExternalStore(
69+
(onChange) => navigation?.addListener("state", onChange) ?? (() => {}),
70+
() => {
71+
const routes = navigation?.getState()?.routes;
72+
const index = routes?.findIndex((candidate) => candidate.key === route?.key) ?? -1;
73+
return route?.name === "Thread" && index > 0 && routes?.[index - 1]?.name === "Thread";
74+
},
75+
);
76+
const listBeside = layout.usesSplitView && props.onBackToList !== undefined && !threadBelow;
6677
const rootBack =
6778
!layout.usesSplitView && props.onBackToList && navigation?.canGoBack() === false
6879
? props.onBackToList
@@ -113,7 +124,7 @@ export function AppBar(props: AppBarProps) {
113124
headerBackVisible:
114125
props.onClose === undefined &&
115126
splitBack === null &&
116-
!(layout.usesSplitView && props.onBackToList) &&
127+
!listBeside &&
117128
!(props.guardBack && props.onBack),
118129
...(props.guardBack ? { gestureEnabled: false } : undefined),
119130
title: props.title,

‎apps/server/src/mcp/McpHttpServer.ts‎

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,21 +1005,16 @@ const withToolAnalytics =
10051005
const scheduledRunOf = (threadId: string, runId: RunId | null) =>
10061006
Option.isNone(threads) || runId === null
10071007
? Effect.succeed(false)
1008-
: threads.value
1009-
.getThreadRecords(ThreadId.make(threadId), ["runs", "messages"], {
1008+
: Effect.gen(function* () {
1009+
const id = ThreadId.make(threadId);
1010+
const { runs } = yield* threads.value.getThreadRecords(id, ["runs"], {
10101011
runIds: [runId],
1011-
messageRoles: ["user"],
1012-
})
1013-
.pipe(
1014-
Effect.map((records) => {
1015-
const run = records.runs.find((candidate) => candidate.id === runId);
1016-
return records.messages.some(
1017-
(message) =>
1018-
message.id === run?.userMessageId && message.scheduledTaskId !== undefined,
1019-
);
1020-
}),
1021-
Effect.orElseSucceed(() => false),
1022-
);
1012+
});
1013+
const run = runs.find((candidate) => candidate.id === runId);
1014+
if (run === undefined) return false;
1015+
const messages = yield* threads.value.getMessagesById(id, [run.userMessageId]);
1016+
return messages.get(run.userMessageId)?.scheduledTaskId !== undefined;
1017+
}).pipe(Effect.orElseSucceed(() => false));
10231018
const record =
10241019
/* Request instrumentation already owns the span; keep this helper in that context. */
10251020
Effect.fnUntraced(

‎apps/server/src/mcp/threadAccess.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import type { ProjectionRecordField } from "../orchestration-v2/ProjectionStore.ts";
1+
import type {
2+
ProjectionRecordField,
3+
ProjectionRecordFilter,
4+
} from "../orchestration-v2/ProjectionStore.ts";
25
import {
36
CommandId,
47
OrchestratorMcpFailure,
@@ -182,7 +185,7 @@ const resolveThreadId = (context: Caller, threadId: ThreadId | undefined) =>
182185

183186
export const readThread = Effect.fn("mcp.readThread")(function* <
184187
K extends ProjectionRecordField = never,
185-
>(threadId?: ThreadId, fields: ReadonlyArray<K> = []) {
188+
>(threadId?: ThreadId, fields: ReadonlyArray<K> = [], filter?: ProjectionRecordFilter) {
186189
const context = yield* readCaller();
187190
const targetId = yield* resolveThreadId(context, threadId);
188191
const shell = yield* context.threads.getThreadShell(targetId).pipe(Effect.mapError(unavailable));
@@ -192,6 +195,7 @@ export const readThread = Effect.fn("mcp.readThread")(function* <
192195
const projection = yield* context.threads
193196
.getProjectThreadRecords({ projectId: shell.projectId, threadId: targetId }, fields, {
194197
turnItemTypes: ["user_input_request"],
198+
...filter,
195199
})
196200
.pipe(
197201
Effect.mapError((error) =>

‎apps/server/src/mcp/toolkits/core.test.ts‎

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import * as ProviderAdapterRegistry from "../../orchestration-v2/ProviderAdapter
4545
import * as ThreadLaunchService from "../../orchestration-v2/ThreadLaunchService.ts";
4646
import * as GitVcsDriver from "../../vcs/GitVcsDriver.ts";
4747
import * as ThreadManagement from "../../orchestration-v2/ThreadManagementService.ts";
48+
import type * as ProjectionStore from "../../orchestration-v2/ProjectionStore.ts";
4849
import * as ThreadSearch from "../../orchestration-v2/ThreadSearch.ts";
4950
import * as PreviewBrowser from "../../preview/PreviewBrowser.ts";
5051
import * as ProjectService from "../../project/ProjectService.ts";
@@ -467,6 +468,101 @@ it.effect("records only failed calls of tools that hand off no work", () => {
467468
);
468469
});
469470

471+
// A thread read whose runs or messages are bounded by nothing but the thread.
472+
const historyReads = (reads: Array<string>) => {
473+
const record = (
474+
fields: ReadonlyArray<string>,
475+
filter: ProjectionStore.ProjectionRecordFilter | undefined,
476+
) => {
477+
if (
478+
fields.includes("runs") &&
479+
filter?.runIds === undefined &&
480+
filter?.runStatuses === undefined
481+
)
482+
reads.push("every run");
483+
if (
484+
fields.includes("messages") &&
485+
filter?.messageIds === undefined &&
486+
filter?.messageRunIds === undefined
487+
)
488+
reads.push("every message");
489+
};
490+
const projection = McpToolAccessTestkit.idleThreadProjection(
491+
McpToolAccessTestkit.liveThreadShell(threadId),
492+
);
493+
return Layer.mock(ThreadManagement.ThreadManagementService)({
494+
getThreadShell: (id) => Effect.succeed(McpToolAccessTestkit.liveThreadShell(id)),
495+
getProjectThreadRecords: (_target, fields, filter) =>
496+
Effect.sync(() => record(fields, filter)).pipe(Effect.as(projection as never)),
497+
getThreadRecords: (_id, fields, filter) =>
498+
Effect.sync(() => record(fields, filter)).pipe(Effect.as(projection as never)),
499+
getMessagesById: () => Effect.succeed(new Map()),
500+
dispatch: () => Effect.succeed({ sequence: 1 } as never),
501+
});
502+
};
503+
504+
it.effect("t3_queue list and read load only the queued runs and their messages", () => {
505+
const reads: Array<string> = [];
506+
return Effect.gen(function* () {
507+
const server = yield* McpServer.McpServer;
508+
const call = (args: Record<string, unknown>) =>
509+
server
510+
.callTool({ name: "t3_queue", arguments: args })
511+
.pipe(
512+
Effect.provideService(McpInvocationContext.McpInvocationContext, scope),
513+
Effect.provideService(McpSchema.McpServerClient, client),
514+
);
515+
yield* call({ action: "list" });
516+
yield* call({ action: "read", queuedRunId: "run:queued" });
517+
expect(reads).toEqual([]);
518+
}).pipe(
519+
Effect.provide(
520+
layerThreadToolkit.pipe(
521+
Layer.provideMerge(McpHttpServer.layerInProcessMcpServer),
522+
Layer.provide(NodeCrypto.layer),
523+
Layer.provide(historyReads(reads)),
524+
),
525+
),
526+
);
527+
});
528+
529+
it.effect("handoff analytics read only the caller's active run and its message", () => {
530+
const reads: Array<string> = [];
531+
const recorded = Deferred.makeUnsafe<void>();
532+
return Effect.gen(function* () {
533+
const server = yield* McpServer.McpServer;
534+
yield* server
535+
.callTool({
536+
name: "t3_queue",
537+
arguments: { action: "edit", queuedRunId: "run:queued", text: "Edited" },
538+
})
539+
.pipe(
540+
Effect.provideService(McpInvocationContext.McpInvocationContext, scope),
541+
Effect.provideService(McpSchema.McpServerClient, client),
542+
);
543+
yield* Deferred.await(recorded);
544+
expect(reads).toEqual([]);
545+
}).pipe(
546+
Effect.provide(
547+
layerThreadToolkit.pipe(
548+
Layer.provideMerge(McpHttpServer.layerInProcessMcpServer),
549+
Layer.provide(NodeCrypto.layer),
550+
Layer.provide(historyReads(reads)),
551+
Layer.provide(
552+
Layer.succeed(
553+
AnalyticsService.AnalyticsService,
554+
AnalyticsService.AnalyticsService.of({
555+
record: () => Deferred.succeed(recorded, undefined).pipe(Effect.asVoid),
556+
flush: Effect.void,
557+
recordOwners: () => Effect.void,
558+
}),
559+
),
560+
),
561+
),
562+
),
563+
);
564+
});
565+
470566
it.effect("rejects an unknown organize target instead of archiving the calling thread", () => {
471567
const dispatched: Array<unknown> = [];
472568
return Effect.gen(function* () {

‎apps/server/src/mcp/toolkits/thread/handlers.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,16 @@ export const layer = McpToolAccess.toLayer(ThreadToolkit, {
269269
(input) => input.action === "list" || input.action === "read",
270270
McpToolAccess.reads((input) =>
271271
Effect.gen(function* () {
272-
const { projection } = yield* readThread(input.threadId, ["runs", "messages"]);
272+
const { threads, projection: queued } = yield* readThread(input.threadId, ["runs"], {
273+
runStatuses: ["queued"],
274+
});
275+
const messages = yield* threads
276+
.getMessagesById(
277+
queued.thread.id,
278+
queued.runs.map((run) => run.userMessageId),
279+
)
280+
.pipe(Effect.mapError(unavailable));
281+
const projection = { runs: queued.runs, messages: [...messages.values()] };
273282
if (input.action === "list") {
274283
const runs = queuedRunsInDeliveryOrder(projection);
275284
const cursor = input.cursor ?? 0;

0 commit comments

Comments
 (0)