Skip to content

Commit 1ba181e

Browse files
authored
Merge branch 'main' into fix/subagent-settle-with-parent
2 parents f4acf04 + 1451e7c commit 1ba181e

165 files changed

Lines changed: 5728 additions & 1096 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/electron/ElectronProtocol.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ describe("ElectronProtocol", () => {
322322
]);
323323
assert.deepEqual(directives["media-src"], ["'self'", "t3code:", "blob:", "http:", "https:"]);
324324
assert.deepEqual(directives["frame-src"], ["'self'", "blob:", "http:", "https:"]);
325+
assert.deepEqual(directives["object-src"], ["'self'", "blob:", "http:", "https:"]);
325326
assert.deepEqual(directives["font-src"], ["'self'", "t3code:", "data:"]);
326327
});
327328
});

‎apps/desktop/src/electron/ElectronProtocol.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ export function makeDesktopContentSecurityPolicy(input: DesktopProtocolRegistrat
9595
`font-src 'self' ${input.scheme}: data:`,
9696
"worker-src 'self' blob:",
9797
"frame-src 'self' blob: http: https:",
98+
"object-src 'self' blob: http: https:",
9899
"form-action 'self'",
99100
].join("; ");
100101
}

‎apps/desktop/src/preview/BrowserSession.test.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ describe("BrowserSession", () => {
180180
for (const permission of [
181181
"clipboard-read",
182182
"clipboard-sanitized-write",
183-
"notifications",
184183
"geolocation",
185184
"fullscreen",
186185
]) {
@@ -194,7 +193,7 @@ describe("BrowserSession", () => {
194193
// `clipboard-write` is not a real Electron permission — the async write API
195194
// uses `clipboard-sanitized-write` — so the stale name must not be granted,
196195
// and unrelated permissions stay denied.
197-
for (const permission of ["clipboard-write", "midi"]) {
196+
for (const permission of ["clipboard-write", "notifications", "midi"]) {
198197
assert.isFalse(requestAllows(permission), `request handler should deny ${permission}`);
199198
assert.isFalse(
200199
checkHandler(null, permission) as boolean,

‎apps/desktop/src/preview/BrowserSession.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ export type BrowserSessionPartitionNamespace = "profile";
3333
const ALLOWED_PREVIEW_PERMISSIONS: ReadonlySet<string> = new Set([
3434
"clipboard-read",
3535
"clipboard-sanitized-write",
36-
"notifications",
3736
"geolocation",
3837
// `DesktopWindow` disables HTML fullscreen window resizing for the app window
3938
// and every preview guest, so a page that goes fullscreen fills its own
@@ -42,6 +41,8 @@ const ALLOWED_PREVIEW_PERMISSIONS: ReadonlySet<string> = new Set([
4241
// Deliberately NOT local-fonts: preview sessions run untrusted web content,
4342
// and silently granting it would hand every page the user's installed-font
4443
// fingerprint (and font file bytes via FontData.blob()).
44+
// Deliberately NOT notifications: a page could post OS notifications branded
45+
// as T3 Code. T3's own come from the app window on the default session.
4546
]);
4647

4748
const NEVER_EXTERNAL_PROTOCOLS: ReadonlySet<string> = new Set([

‎apps/desktop/src/preview/Manager.test.ts‎

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1886,6 +1886,8 @@ describe("PreviewManager", () => {
18861886
const sendCommand = vi.fn<(method: string, params?: unknown) => Promise<unknown>>(
18871887
async () => undefined,
18881888
);
1889+
const detachListeners = new Set<() => void>();
1890+
let chromiumDetaches = 0;
18891891
let destroyed = false;
18901892
const wc = {
18911893
id,
@@ -1914,19 +1916,30 @@ describe("PreviewManager", () => {
19141916
setIgnoreMenuShortcuts: vi.fn(),
19151917
setWindowOpenHandler: vi.fn(),
19161918
debugger: {
1917-
isAttached: () => attach.mock.calls.length > detach.mock.calls.length,
1919+
isAttached: () => attach.mock.calls.length > detach.mock.calls.length + chromiumDetaches,
19181920
attach,
19191921
detach,
19201922
sendCommand,
1921-
on: vi.fn(),
1922-
off: vi.fn(),
1923+
on: (event: string, listener: () => void) => {
1924+
if (event === "detach") detachListeners.add(listener);
1925+
},
1926+
off: (event: string, listener: () => void) => {
1927+
if (event === "detach") detachListeners.delete(listener);
1928+
},
19231929
},
19241930
};
1931+
/** Chromium dropping the debugger without a detach() call. */
1932+
const chromiumDetach = () => {
1933+
chromiumDetaches += 1;
1934+
// Snapshot like an EventEmitter, so a listener added during emit waits for the next one.
1935+
for (const listener of Array.from(detachListeners)) listener();
1936+
};
19251937
return {
19261938
wc: wc as unknown as Electron.WebContents,
19271939
attach,
19281940
detach,
19291941
sendCommand,
1942+
chromiumDetach,
19301943
destroy: () => {
19311944
destroyed = true;
19321945
listeners.get("destroyed")?.();
@@ -1965,6 +1978,24 @@ describe("PreviewManager", () => {
19651978
),
19661979
);
19671980

1981+
effectIt.effect("reattaches a debugger that Chromium dropped on its own", () =>
1982+
withManager((manager) =>
1983+
Effect.gen(function* () {
1984+
const guest = makeAttachingGuest(48);
1985+
fromId.mockReturnValue(guest.wc);
1986+
yield* manager.createTab("tab_detached");
1987+
yield* manager.registerWebview("tab_detached", 48);
1988+
yield* Effect.yieldNow;
1989+
expect(guest.attach).toHaveBeenCalledTimes(1);
1990+
1991+
guest.chromiumDetach();
1992+
yield* Effect.yieldNow;
1993+
yield* Effect.yieldNow;
1994+
expect(guest.attach).toHaveBeenCalledTimes(2);
1995+
}),
1996+
),
1997+
);
1998+
19681999
effectIt.effect("skips a guest destroyed while another guest's session opens", () =>
19692000
withManager((manager) =>
19702001
Effect.gen(function* () {

‎apps/desktop/src/preview/Manager.ts‎

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,13 +1023,22 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
10231023
copy.delete(webContentsId);
10241024
}),
10251025
]);
1026-
if (control) {
1027-
if (closedServerTab) browserHost.detach(closedServerTab);
1028-
for (const tab of (yield* SynchronizedRef.get(tabsRef)).values()) {
1029-
if (tab.webContentsId === webContentsId && tab.serverTab) browserHost.detach(tab.serverTab);
1026+
if (control) yield* releaseControlSession(control, closedServerTab);
1027+
});
1028+
1029+
// Closes a session already removed from `controlSessionsRef`. The server can
1030+
// only drive a tab while the desktop holds its debugger.
1031+
const releaseControlSession = Effect.fnUntraced(function* (
1032+
control: BrowserControlSession,
1033+
closedServerTab?: PreviewTabState["serverTab"],
1034+
) {
1035+
if (closedServerTab) browserHost.detach(closedServerTab);
1036+
for (const tab of (yield* SynchronizedRef.get(tabsRef)).values()) {
1037+
if (tab.webContentsId === control.webContentsId && tab.serverTab) {
1038+
browserHost.detach(tab.serverTab);
10301039
}
1031-
yield* Scope.close(control.scope, Exit.void).pipe(Effect.ignore);
10321040
}
1041+
yield* Scope.close(control.scope, Exit.void).pipe(Effect.ignore);
10331042
});
10341043

10351044
const ensureControlSession = Effect.fn("PreviewManager.ensureControlSession")(function* (
@@ -1141,23 +1150,36 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
11411150
const onMessage: BrowserControlSession["onMessage"] = (_event, method, params) => {
11421151
runFork(handleDebuggerMessage(method, params));
11431152
};
1144-
yield* Scope.addFinalizer(
1145-
scope,
1146-
attempt({ operation: "detachControlSession", webContentsId: wc.id }, () => {
1147-
wcDebugger.off("message", onMessage);
1148-
if (wcDebugger.isAttached()) wcDebugger.detach();
1149-
}).pipe(Effect.ignore),
1150-
);
11511153
const control: BrowserControlSession = {
11521154
webContentsId: wc.id,
11531155
debugger: wcDebugger,
11541156
semaphore,
11551157
scope,
11561158
onMessage,
11571159
};
1160+
// Electron emits `detach` when Chromium closes the debugger session on its
1161+
// own. The cached session would then fail every command until the webview
1162+
// is replaced.
1163+
let dropped = false;
1164+
const onDetach = () => {
1165+
dropped = true;
1166+
runFork(recoverDetachedControlSession(wc, control));
1167+
};
1168+
// The listener comes off before detach() so a detach this manager requested
1169+
// never looks like a dropped one. A dropped session has nothing left to
1170+
// detach: `wc.debugger` is shared, so detaching here would hit a successor.
1171+
yield* Scope.addFinalizer(
1172+
scope,
1173+
attempt({ operation: "detachControlSession", webContentsId: wc.id }, () => {
1174+
wcDebugger.off("message", onMessage);
1175+
wcDebugger.off("detach", onDetach);
1176+
if (!dropped && wcDebugger.isAttached()) wcDebugger.detach();
1177+
}).pipe(Effect.ignore),
1178+
);
11581179
const initialize = Effect.fn("PreviewManager.initializeControlSession")(function* () {
11591180
yield* attempt({ operation: "attachDebuggerListeners", webContentsId: wc.id }, () => {
11601181
wcDebugger.on("message", onMessage);
1182+
wcDebugger.on("detach", onDetach);
11611183
wcDebugger.attach("1.3");
11621184
});
11631185
// Without this, dark-scheme pages with no background of their own (text/plain, e.g.
@@ -2356,6 +2378,30 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
23562378
}
23572379
}).pipe(Effect.ignore);
23582380

2381+
// Only the session that saw the detach is replaced: by the time the event is
2382+
// handled the guest may already hold a newer one, which must stay.
2383+
const recoverDetachedControlSession = Effect.fn("PreviewManager.recoverDetachedControlSession")(
2384+
function* (wc: Electron.WebContents, detached: BrowserControlSession) {
2385+
const removed = yield* SynchronizedRef.modify(controlSessionsRef, (sessions) =>
2386+
sessions.get(wc.id) === detached
2387+
? ([
2388+
true,
2389+
replaceMap(sessions, (copy) => {
2390+
copy.delete(wc.id);
2391+
}),
2392+
] as const)
2393+
: ([false, sessions] as const),
2394+
);
2395+
if (!removed) return;
2396+
yield* releaseControlSession(detached);
2397+
if (wc.isDestroyed()) return;
2398+
const tabId = yield* tabIdForWebContents(wc.id);
2399+
if (tabId === null) return;
2400+
yield* restoreControlSession(tabId, wc);
2401+
},
2402+
(recover) => Effect.ignore(recover),
2403+
);
2404+
23592405
const setColorScheme = Effect.fn("PreviewManager.setColorScheme")(function* (
23602406
tabId: string,
23612407
colorScheme: DesktopPreviewColorScheme,

‎apps/mobile/app.config.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ const config: ExpoConfig = {
317317
},
318318
plugins: [
319319
"expo-asset",
320+
"react-native-pdf-jsi",
320321
[
321322
"expo-font",
322323
{

‎apps/mobile/modules/t3-native-controls/ios/T3NativeControlsModule.swift‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,14 @@ public final class T3NativeControlsModule: Module {
5252
identifier: identifier, promise: promise)
5353
}.runOnQueue(.main)
5454

55-
AsyncFunction("presentFiles") { (urls: [URL], titles: [String], selectedIndex: Int, identifier: String, promise: Promise) in
56-
guard !urls.isEmpty, urls.count == titles.count, urls.indices.contains(selectedIndex) else {
55+
AsyncFunction("presentFiles") { (urls: [URL], titles: [String], selectedIndex: Int, sourceIdentifiers: [String], identifier: String, promise: Promise) in
56+
guard !urls.isEmpty, urls.count == titles.count, urls.count == sourceIdentifiers.count,
57+
urls.indices.contains(selectedIndex)
58+
else {
5759
throw URLError(.badURL)
5860
}
59-
let file = try self.makeFilePresentation(sourceIdentifier: "", identifier: identifier, promise: promise)
61+
let file = try self.makeFilePresentation(sourceIdentifiers: sourceIdentifiers, identifier: identifier,
62+
promise: promise)
6063
guard let presenter = self.appContext?.utilities?.currentViewController() else {
6164
file.dismiss()
6265
return
@@ -241,13 +244,13 @@ public final class T3NativeControlsModule: Module {
241244
if videoPresentation?.identifier == identifier { videoPresentation?.dismiss() }
242245
}
243246

244-
private func makeFilePresentation(sourceIdentifier: String, identifier: String,
247+
private func makeFilePresentation(sourceIdentifiers: [String], identifier: String,
245248
promise: Promise) throws -> T3NativeFilePresentation {
246249
guard filePresentation == nil, videoPresentation == nil,
247250
appContext?.utilities?.currentViewController() != nil
248251
else { throw URLError(.cannotLoadFromNetwork) }
249252
let file = T3NativeFilePresentation(identifier: identifier, sources: presentationSources,
250-
sourceIdentifier: sourceIdentifier) { [weak self] error in
253+
sourceIdentifiers: sourceIdentifiers) { [weak self] error in
251254
self?.filePresentation = nil
252255
if let error { promise.reject(error) } else { promise.resolve(nil) }
253256
}
@@ -257,7 +260,7 @@ public final class T3NativeControlsModule: Module {
257260

258261
private func presentFile(url: URL, title: String, sourceIdentifier: String,
259262
identifier: String, promise: Promise) throws {
260-
let file = try makeFilePresentation(sourceIdentifier: sourceIdentifier, identifier: identifier, promise: promise)
263+
let file = try makeFilePresentation(sourceIdentifiers: [sourceIdentifier], identifier: identifier, promise: promise)
261264
guard let presenter = appContext?.utilities?.currentViewController() else { file.dismiss(); return }
262265
file.present(url: url, title: title, from: presenter)
263266
}

‎apps/mobile/modules/t3-native-controls/ios/T3NativeFilePresentation.swift‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,17 @@ final class T3NativeFilePresentation: NSObject, QLPreviewControllerDataSource,
2424
private var controller: UIViewController?
2525
private let completion: (Error?) -> Void
2626
private weak var sources: T3PresentationSources?
27-
private let sourceIdentifier: String
27+
private let sourceIdentifiers: [String]
2828
private var items: [FilePreviewItem] = []
2929
private var loading: Task<Void, Never>?
3030
private var dismissRequested = false
3131
private var finished = false
3232

33-
init(identifier: String, sources: T3PresentationSources, sourceIdentifier: String, completion: @escaping (Error?) -> Void) {
33+
init(identifier: String, sources: T3PresentationSources, sourceIdentifiers: [String],
34+
completion: @escaping (Error?) -> Void) {
3435
self.identifier = identifier
3536
self.sources = sources
36-
self.sourceIdentifier = sourceIdentifier
37+
self.sourceIdentifiers = sourceIdentifiers
3738
self.completion = completion
3839
super.init()
3940
}
@@ -107,14 +108,21 @@ final class T3NativeFilePresentation: NSObject, QLPreviewControllerDataSource,
107108
items[index]
108109
}
109110

111+
private func sourceView(for item: QLPreviewItem) -> UIView? {
112+
guard !UIAccessibility.isReduceMotionEnabled,
113+
let index = items.firstIndex(where: { $0 === item }),
114+
sourceIdentifiers.indices.contains(index)
115+
else { return nil }
116+
return sources?.view(for: sourceIdentifiers[index])
117+
}
118+
110119
func previewController(_ controller: QLPreviewController, transitionViewFor item: QLPreviewItem) -> UIView? {
111-
guard !UIAccessibility.isReduceMotionEnabled else { return nil }
112-
return sources?.view(for: sourceIdentifier)
120+
sourceView(for: item)
113121
}
114122

115123
func previewController(_ controller: QLPreviewController, frameFor item: QLPreviewItem,
116124
inSourceView view: AutoreleasingUnsafeMutablePointer<UIView?>) -> CGRect {
117-
guard !UIAccessibility.isReduceMotionEnabled, let source = sources?.view(for: sourceIdentifier) else { return .zero }
125+
guard let source = sourceView(for: item) else { return .zero }
118126
view.pointee = source
119127
return source.bounds
120128
}

‎apps/mobile/modules/t3-terminal/android/src/main/java/expo/modules/t3terminal/T3TerminalView.kt‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import android.text.Editable
77
import android.text.InputType
88
import android.text.TextWatcher
99
import android.view.KeyEvent
10+
import android.view.View
1011
import android.view.ViewGroup
1112
import android.view.inputmethod.EditorInfo
1213
import android.view.inputmethod.InputMethodManager
@@ -20,7 +21,12 @@ import kotlin.math.max
2021
class T3TerminalView(context: Context, appContext: AppContext) : ExpoView(context, appContext) {
2122
private val container = FrameLayout(context)
2223
private val terminalCanvas = TerminalCanvasView(context)
23-
private val inputView = EditText(context)
24+
25+
// Newer Android can request autofill even with importantForAutofill=no.
26+
// Reporting no autofill type keeps terminal input out of credential autofill.
27+
private val inputView = object : EditText(context) {
28+
override fun getAutofillType(): Int = View.AUTOFILL_TYPE_NONE
29+
}
2430
private val onInput by EventDispatcher()
2531
private val onResize by EventDispatcher()
2632
private val onCapture by EventDispatcher()

0 commit comments

Comments
 (0)