Skip to content

Commit 3810805

Browse files
Merge main into fix/issue-24812
2 parents 3a919cb + 5398be0 commit 3810805

7 files changed

Lines changed: 173 additions & 14 deletions

File tree

‎apps/mobile/src/features/workspace/WorkspaceToolbar.ios.tsx‎

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,20 +101,14 @@ export function WorkspaceToolbar(props: {
101101
tab.searchMode !== "resting"
102102
) {
103103
searchRef.current?.setText(tab.query);
104-
if (duoSearch) {
104+
// Integrated search collapses to its button when its screen reappears,
105+
// which would hide the query that still filters the list.
106+
if (NATIVE_LIQUID_GLASS_SUPPORTED) {
105107
searchRef.current?.setActive(true);
106108
if (tab.searchMode === "active") searchRef.current?.focus();
107109
}
108110
}
109-
}, [
110-
searchHostVisible,
111-
duoSearch,
112-
isTabActive,
113-
selectedTab,
114-
tab.searchMode,
115-
tab.query,
116-
searchVisible,
117-
]);
111+
}, [searchHostVisible, isTabActive, selectedTab, tab.searchMode, tab.query, searchVisible]);
118112
useFocusEffect(
119113
useCallback(() => {
120114
const frame = requestAnimationFrame(restoreSearch);

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

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,3 +817,90 @@ it.effect("admits provider and OAuth client credentials and points only clients
817817
}),
818818
).pipe(Effect.provide(NodeHttpServer.layerTest)),
819819
);
820+
821+
it.effect("lists pull request watch tools only to threads that are not delegated children", () =>
822+
Effect.scoped(
823+
Effect.gen(function* () {
824+
const scopeFor = (
825+
token: string,
826+
subagent: boolean,
827+
): McpInvocationContext.McpThreadInvocationScope => ({
828+
environmentId,
829+
requestNamespace: token,
830+
thread: {
831+
threadId: ThreadId.make(`thread-${token}`),
832+
providerSessionId: token,
833+
providerInstanceId: ProviderInstanceId.make("codex"),
834+
subagent,
835+
},
836+
client: undefined,
837+
capabilities: new Set(["pull-requests"]),
838+
issuedAt: 1,
839+
});
840+
const scopes = new Map([
841+
["parentToken", scopeFor("parentToken", false)],
842+
["childToken", scopeFor("childToken", true)],
843+
]);
844+
const serverLayer = McpHttpServer.layerPullRequestsToolkit.pipe(
845+
Layer.provideMerge(McpHttpServer.layerMcpTransport),
846+
Layer.provide(
847+
Layer.mock(McpSessionRegistry.McpSessionRegistry)({
848+
resolve: (token) => Effect.succeed(scopes.get(token)),
849+
}),
850+
),
851+
Layer.provide(
852+
Layer.mergeAll(
853+
McpToolAccessTestkit.liveThreadsLayer,
854+
Layer.mock(ProjectService.ProjectService)({}),
855+
Layer.mock(PullRequestReviewGuideService.PullRequestReviewGuideService)({}),
856+
Layer.mock(Orchestrator.OrchestratorV2)({}),
857+
Layer.mock(ProjectionStore.ProjectionStoreV2)({}),
858+
NodeServices.layer,
859+
),
860+
),
861+
);
862+
yield* HttpRouter.serve(serverLayer, { disableListenLog: true, disableLogger: true }).pipe(
863+
Layer.build,
864+
);
865+
const httpClient = yield* HttpClient.HttpClient;
866+
const listedTools = (token: string) =>
867+
Effect.gen(function* () {
868+
const headers = {
869+
accept: "application/json, text/event-stream",
870+
authorization: `Bearer ${token}`,
871+
};
872+
const initialize = yield* httpClient.post("/mcp", {
873+
headers,
874+
body: HttpBody.text(
875+
`{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"probe","version":"1.0.0"}}}`,
876+
"application/json",
877+
),
878+
});
879+
const listed = yield* httpClient.post("/mcp", {
880+
headers: {
881+
...headers,
882+
"mcp-session-id": initialize.headers["mcp-session-id"]!,
883+
"mcp-protocol-version": "2025-06-18",
884+
},
885+
body: HttpBody.text(
886+
`{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}`,
887+
"application/json",
888+
),
889+
});
890+
const body = (yield* listed.json) as {
891+
readonly result: { readonly tools: ReadonlyArray<{ readonly name: string }> };
892+
};
893+
return body.result.tools.map((tool) => tool.name);
894+
});
895+
896+
const parentTools = yield* listedTools("parentToken");
897+
const childTools = yield* listedTools("childToken");
898+
expect(parentTools).toEqual(
899+
expect.arrayContaining(["link_pull_request", "watch_pull_request", "unwatch_pull_request"]),
900+
);
901+
expect(childTools).toContain("link_pull_request");
902+
expect(childTools).not.toContain("watch_pull_request");
903+
expect(childTools).not.toContain("unwatch_pull_request");
904+
}),
905+
).pipe(Effect.provide(NodeHttpServer.layerTest)),
906+
);

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
} from "@t3tools/contracts";
1111
import * as Context from "effect/Context";
1212
import * as Effect from "effect/Effect";
13+
import * as Fiber from "effect/Fiber";
1314

1415
const ALL_MCP_CAPABILITIES = [
1516
"preview",
@@ -24,6 +25,8 @@ export interface McpThreadCaller {
2425
readonly threadId: ThreadId;
2526
readonly providerSessionId: string;
2627
readonly providerInstanceId: ProviderInstanceId;
28+
/** A delegated child task; its parent owns the work it hands back. */
29+
readonly subagent?: boolean;
2730
}
2831

2932
export interface McpClientCaller {
@@ -51,6 +54,16 @@ export class McpInvocationContext extends Context.Service<
5154
McpInvocationScope
5255
>()("t3/mcp/McpInvocationContext") {}
5356

57+
/**
58+
* `McpSchema.EnabledWhen` for tools a delegated child must not see or call.
59+
* EnabledWhen only receives the MCP client profile, so read the T3 caller from the request fiber.
60+
*/
61+
export const hiddenFromSubagents = (): boolean => {
62+
const fiber = Fiber.getCurrent();
63+
const scope = fiber && Context.getOrUndefined(fiber.context, McpInvocationContext);
64+
return scope?.thread?.subagent !== true;
65+
};
66+
5467
export type McpCapabilityError<C extends McpCapability> = C extends "preview"
5568
? PreviewAutomationUnavailableError
5669
: McpCapabilityUnavailableError;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export interface McpCredentialRequest {
1818
/** False omits the preview capability wherever the token is honored. Defaults to full access. */
1919
readonly browserToolsAvailable?: boolean;
2020
readonly capabilities?: ReadonlySet<McpInvocationContext.McpCapability>;
21+
readonly subagent?: boolean;
2122
}
2223

2324
export interface McpIssuedCredential {
@@ -105,6 +106,7 @@ const makeWithOptions = Effect.fn("McpSessionRegistry.make")(function* (
105106
threadId: ThreadId.make(request.threadId),
106107
providerSessionId,
107108
providerInstanceId: ProviderInstanceId.make(request.providerInstanceId),
109+
subagent: request.subagent === true,
108110
},
109111
client: undefined,
110112
capabilities: new Set<McpInvocationContext.McpCapability>([

‎apps/server/src/mcp/toolkits/pullRequests/tools.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
ThreadId,
1111
} from "@t3tools/contracts";
1212
import * as Schema from "effect/Schema";
13+
import * as McpSchema from "effect/ai/McpSchema";
1314
import * as Tool from "effect/ai/Tool";
1415
import * as Toolkit from "effect/ai/Toolkit";
1516

@@ -326,7 +327,7 @@ const ListThreadPullRequestsTool = Tool.make("list_thread_pull_requests", {
326327

327328
const WatchPullRequestTool = Tool.make("watch_pull_request", {
328329
description:
329-
"Have T3 Code watch an open pull request for this thread, linking it first if needed. T3 Code checks it every two minutes and wakes you with a message when a check fails, the required checks pass, someone else comments or reviews, or the branch starts to conflict with its base. Use this to monitor or babysit a pull request instead of polling, sleeping, or running a watcher. Only comments posted after this call wake you, so handle the existing ones first, then end your turn. A wake is news, not a merge decision: check readiness yourself before merging. While T3 Code watches, the thread stays in the user's Working list, not their inbox. When you hand the work back to the user, call unwatch_pull_request first so the thread returns to their inbox. Watching ends when the pull request merges or closes, when its thread settles or is archived, when T3 Code fails to read it 8 times in a row (a host rate limit only delays it), when the user stops this thread, or when you call unwatch_pull_request. Unsettle the thread before starting a new watch. A subagent cannot watch: its parent thread owns the pull request.",
330+
"Have T3 Code watch an open pull request for this thread, linking it first if needed. T3 Code checks it every two minutes and wakes you with a message when a check fails, the required checks pass, someone else comments or reviews, or the branch starts to conflict with its base. Use this to monitor or babysit a pull request instead of polling, sleeping, or running a watcher. Only comments posted after this call wake you, so handle the existing ones first, then end your turn. A wake is news, not a merge decision: check readiness yourself before merging. While T3 Code watches, the thread stays in the user's Working list, not their inbox. When you hand the work back to the user, call unwatch_pull_request first so the thread returns to their inbox. Watching ends when the pull request merges or closes, when its thread settles or is archived, when T3 Code fails to read it 8 times in a row (a host rate limit only delays it), when the user stops this thread, or when you call unwatch_pull_request. Unsettle the thread before starting a new watch.",
330331
parameters: PullRequestTargetInput,
331332
success: WatchPullRequestResult,
332333
failure: PullRequestToolError,
@@ -336,7 +337,8 @@ const WatchPullRequestTool = Tool.make("watch_pull_request", {
336337
.annotate(Tool.Readonly, false)
337338
.annotate(Tool.Destructive, false)
338339
.annotate(Tool.Idempotent, true)
339-
.annotate(Tool.OpenWorld, false);
340+
.annotate(Tool.OpenWorld, false)
341+
.annotate(McpSchema.EnabledWhen, McpInvocationContext.hiddenFromSubagents);
340342

341343
const UnwatchPullRequestTool = Tool.make("unwatch_pull_request", {
342344
description:
@@ -350,7 +352,8 @@ const UnwatchPullRequestTool = Tool.make("unwatch_pull_request", {
350352
.annotate(Tool.Readonly, false)
351353
.annotate(Tool.Destructive, false)
352354
.annotate(Tool.Idempotent, true)
353-
.annotate(Tool.OpenWorld, false);
355+
.annotate(Tool.OpenWorld, false)
356+
.annotate(McpSchema.EnabledWhen, McpInvocationContext.hiddenFromSubagents);
354357

355358
const GuideTarget = Schema.Struct({
356359
url: PullRequestTargetInput.fields.url,

‎apps/server/src/orchestration-v2/ProviderSessionManager.test.ts‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,6 +1560,59 @@ it.effect(
15601560
}),
15611561
);
15621562

1563+
it.effect.each([
1564+
{ relationshipToParent: null, subagent: false },
1565+
{ relationshipToParent: "subagent", subagent: true },
1566+
] as const)(
1567+
"ProviderSessionManagerV2 marks MCP credentials of delegated children ($relationshipToParent)",
1568+
({ relationshipToParent, subagent }) =>
1569+
Effect.gen(function* () {
1570+
const state = yield* Ref.make(emptyState);
1571+
const mcpConfigs = yield* Ref.make<
1572+
ReadonlyArray<McpProviderSession.McpProviderSessionConfig | undefined>
1573+
>([]);
1574+
const effect = Effect.gen(function* () {
1575+
const eventSink = yield* EventSink.EventSinkV2;
1576+
const idAllocator = yield* IdAllocator.IdAllocatorV2;
1577+
const manager = yield* ProviderSessionManager.ProviderSessionManagerV2;
1578+
const registry = yield* McpSessionRegistry.McpSessionRegistry;
1579+
const now = yield* DateTime.now;
1580+
const threadId = ThreadId.make("thread-provider-session-manager-mcp-lineage");
1581+
const providerSessionId = yield* idAllocator.allocate.providerSession({
1582+
providerInstanceId: modelSelection.instanceId,
1583+
threadId,
1584+
});
1585+
const created = yield* makeThreadCreatedEvent({ idAllocator, threadId, now });
1586+
const parentThreadId = ThreadId.make("thread-provider-session-manager-mcp-parent");
1587+
yield* eventSink.write({
1588+
events: [
1589+
{
1590+
...created,
1591+
payload: {
1592+
...created.payload,
1593+
lineage:
1594+
relationshipToParent === null
1595+
? created.payload.lineage
1596+
: { parentThreadId, relationshipToParent, rootThreadId: parentThreadId },
1597+
},
1598+
},
1599+
],
1600+
});
1601+
yield* manager.open({ threadId, providerSessionId, modelSelection, runtimePolicy });
1602+
1603+
const token = (yield* Ref.get(mcpConfigs))[0]?.authorizationHeader.replace(
1604+
/^Bearer\s+/,
1605+
"",
1606+
);
1607+
assert.isDefined(token);
1608+
assert.equal((yield* registry.resolve(token!))?.thread.subagent, subagent);
1609+
yield* manager.close(providerSessionId);
1610+
});
1611+
1612+
yield* effect.pipe(Effect.provide(layerTest({ state, idleTimeoutMs: 1_000, mcpConfigs })));
1613+
}),
1614+
);
1615+
15631616
it.effect(
15641617
"ProviderSessionManagerV2 withholds the preview capability when agent browser access is off",
15651618
() =>

‎apps/server/src/orchestration-v2/ProviderSessionManager.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,10 @@ export const layerWithOptions = (
430430
>(["orchestration", "worktree", "pull-requests"]);
431431
if (browserToolsAvailable) capabilities.add("preview");
432432
if (deviceToolsAvailable) capabilities.add("device");
433+
const subagent = yield* projectionStore.getThread(threadId).pipe(
434+
Effect.map((thread) => thread.lineage.relationshipToParent === "subagent"),
435+
Effect.orElseSucceed(() => false),
436+
);
433437
const existing = yield* mcpSessions.read(threadId);
434438
if (existing !== undefined) {
435439
// Reserve before async validation so release cannot revoke between validation and reservation.
@@ -450,7 +454,9 @@ export const layerWithOptions = (
450454
resolved.thread.threadId === threadId &&
451455
resolved.thread.providerInstanceId === providerInstanceId &&
452456
resolved.capabilities.has("preview") === browserToolsAvailable &&
453-
resolved.capabilities.has("device") === deviceToolsAvailable
457+
resolved.capabilities.has("device") === deviceToolsAvailable &&
458+
// A credential issued while the lineage read failed is replaced once it works.
459+
(resolved.thread.subagent === true) === subagent
454460
) {
455461
return { mcpCredentialId: existing.providerSessionId, issued: false };
456462
}
@@ -462,6 +468,7 @@ export const layerWithOptions = (
462468
providerInstanceId,
463469
browserToolsAvailable,
464470
capabilities,
471+
subagent,
465472
});
466473
yield* mcpSessions.set(credential.config);
467474
reserveMcpCredential(threadId, credential.config.providerSessionId);

0 commit comments

Comments
 (0)