@devries-cameron20 / t3code-1 / commits / 70f475f511
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

feat(clients): surface child approvals in parent threads (#28516)

Yash Singh committed Nov 1, 2026 at 04:03 UTC 70f475f51127d3e8025777b6582e75556b974675
12 files changed +613 -119
apps/mobile/src/features/threads/ChildThreadApprovals.tsx new
+88
@@ -0,0 +1,88 @@
1 +import { useAtomValue } from "@effect/atom-react";
2 +import { AuthOrchestrationOperateScope, type ScopedThreadRef } from "@t3tools/contracts";
3 +import type { ChildThreadApproval } from "@t3tools/client-runtime/state/thread-requests";
4 +import {
5 + isAtomCommandInterrupted,
6 + squashAtomCommandFailure,
7 +} from "@t3tools/client-runtime/state/runtime";
8 +import { useState } from "react";
9 +import { useEnvironmentScope } from "../../state/session";
10 +import { ScrollView, View } from "react-native";
11 +import Animated, { useAnimatedStyle, type DerivedValue } from "react-native-reanimated";
12 +import { AppText } from "../../components/ui/AppText";
13 +import { childThreadApprovalsAtom, threadEnvironment } from "../../state/threads";
14 +import { useAtomCommand } from "../../state/use-atom-command";
15 +import { PendingApprovalCard } from "./PendingApprovalCard";
16 +
17 +function ChildApproval({ entry }: { entry: ChildThreadApproval }) {
18 + const canRespond = useEnvironmentScope(entry.thread.environmentId, AuthOrchestrationOperateScope);
19 + const respond = useAtomCommand(threadEnvironment.respondToApproval, { reportFailure: false });
20 + const [responding, setResponding] = useState(false);
21 + const [error, setError] = useState<string | null>(null);
22 + return (
23 + <View className="mx-3.5 my-2 gap-2">
24 + <AppText className="font-t3-bold text-sm text-foreground">
25 + Approval from {entry.title}
26 + </AppText>
27 + <PendingApprovalCard
28 + canOperateThread={canRespond}
29 + approval={entry.approval}
30 + respondingApprovalId={responding ? entry.approval.requestId : null}
31 + onRespond={async (requestId, decision) => {
32 + if (!canRespond || responding) return;
33 + setResponding(true);
34 + setError(null);
35 + const result = await respond({
36 + environmentId: entry.thread.environmentId,
37 + input: { threadId: entry.thread.threadId, requestId, decision },
38 + });
39 + if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
40 + const failure = squashAtomCommandFailure(result);
41 + setError(
42 + failure instanceof Error ? failure.message : "Failed to submit approval decision.",
43 + );
44 + }
45 + setResponding(false);
46 + return result;
47 + }}
48 + />
49 + {error !== null ? (
50 + <AppText
51 + accessibilityRole="alert"
52 + accessibilityLiveRegion="polite"
53 + className="font-sans text-sm text-danger-foreground"
54 + >
55 + {error}
56 + </AppText>
57 + ) : null}
58 + </View>
59 + );
60 +}
61 +
62 +export function ChildThreadApprovals({
63 + threadRef,
64 + maxHeight,
65 +}: {
66 + threadRef: ScopedThreadRef | null;
67 + maxHeight: DerivedValue<number>;
68 +}) {
69 + const approvals = useAtomValue(childThreadApprovalsAtom(threadRef));
70 + const heightStyle = useAnimatedStyle(() => ({ maxHeight: Math.min(320, maxHeight.value / 2) }));
71 + if (approvals.length === 0) return null;
72 + return (
73 + <Animated.View style={heightStyle} className="overflow-hidden">
74 + <ScrollView keyboardShouldPersistTaps="handled" nestedScrollEnabled style={{ flexShrink: 1 }}>
75 + {approvals.map((entry) => (
76 + <ChildApproval
77 + key={JSON.stringify([
78 + entry.thread.environmentId,
79 + entry.thread.threadId,
80 + entry.approval.requestId,
81 + ])}
82 + entry={entry}
83 + />
84 + ))}
85 + </ScrollView>
86 + </Animated.View>
87 + );
88 +}
apps/mobile/src/features/threads/ThreadDetailScreen.tsx
+133 -115
@@ -1,3 +1,4 @@
1 +import { ChildThreadApprovals } from "./ChildThreadApprovals";
2 import { useOpenThreadInspector } from "./thread-inspector-navigation";
3 import { useSidebarWorkspaceTabs } from "../workspace/useSystemWorkspaceTabBar";
4 import { useWorkspaceTabs } from "../workspace/WorkspaceTabsContext";
@@ -306,6 +307,8 @@ export interface ThreadDetailScreenProps {
307 readonly showContent?: boolean;
308 }
309
310 +// iOS questions overlay the controls; Android questions stack with child approvals.
311 +const ComposerPanels = Platform.OS === "android" ? Animated.ScrollView : Animated.View;
312 const USAGE_LIMITS_PANEL_GAP = 12;
313 const USAGE_LIMITS_PANEL_MIN_HEIGHT = 44;
314
@@ -960,6 +963,10 @@ function ThreadDetailBody(props: ThreadDetailScreenProps) {
963 composerOverlapHeight: composerBottomInset,
964 }),
965 );
966 + const composerPanelsHeightStyle = useAnimatedStyle(() => ({
967 + maxHeight: pendingUserInputMaxHeight.value,
968 + flexGrow: 0,
969 + }));
970 // The usage panel stacks with the composer and any approval card, so it gets
971 // whatever room they leave below the header. Measured only while it is open
972 // so typing in the composer does not re-render the screen.
@@ -1504,130 +1511,141 @@ function ThreadDetailBody(props: ThreadDetailScreenProps) {
1511 });
1512 }}
1513 />
1507 - {props.queuedRunEdit !== null ? (
1508 - <Animated.View
1509 - className="shrink-0"
1510 - entering={FadeInDown.duration(180)}
1511 - exiting={FadeOut.duration(120)}
1512 - >
1513 - <ComposerQueuedEditBanner
1514 - saving={props.isSavingQueuedEdit}
1515 - onCancel={() => {
1516 - voiceInputSession.cancel(props.composerDraftKey);
1517 - props.onCancelQueuedRunEdit();
1518 - }}
1519 - />
1520 - </Animated.View>
1521 - ) : null}
1522 - <UsageLimitRecoveryCard
1523 - key={props.selectedThread.latestRun?.runId}
1524 - thread={props.selectedThread}
1525 - environmentId={props.environmentId}
1526 - />
1527 - <ChatGptUsageLimitNotice
1528 - key={`chatgpt-limit:${props.selectedThread.latestRun?.runId}`}
1529 - thread={props.selectedThread}
1530 - />
1531 - <ThreadGuestShareBar
1532 - threadRef={props.selectedThreadDetailRef}
1533 - canOperateThread={props.canOperateThread}
1534 - />
1535 - {props.draftMode ? null : (
1536 - <ThreadSideChatsRow
1514 + <ComposerPanels
1515 + className="w-full"
1516 + style={Platform.OS === "android" ? composerPanelsHeightStyle : undefined}
1517 + keyboardShouldPersistTaps="handled"
1518 + nestedScrollEnabled
1519 + >
1520 + {props.queuedRunEdit !== null ? (
1521 + <Animated.View
1522 + className="shrink-0"
1523 + entering={FadeInDown.duration(180)}
1524 + exiting={FadeOut.duration(120)}
1525 + >
1526 + <ComposerQueuedEditBanner
1527 + saving={props.isSavingQueuedEdit}
1528 + onCancel={() => {
1529 + voiceInputSession.cancel(props.composerDraftKey);
1530 + props.onCancelQueuedRunEdit();
1531 + }}
1532 + />
1533 + </Animated.View>
1534 + ) : null}
1535 + <UsageLimitRecoveryCard
1536 + key={props.selectedThread.latestRun?.runId}
1537 + thread={props.selectedThread}
1538 environmentId={props.environmentId}
1538 - threadId={props.selectedThread.id}
1539 />
1540 - )}
1541 - {props.feedbackSubmissions.map((submission) => (
1542 - <ComposerFeedback
1543 - key={submission.id}
1544 - submission={submission}
1545 - onDismiss={() => props.onDismissFeedback(submission.id)}
1540 + <ChatGptUsageLimitNotice
1541 + key={`chatgpt-limit:${props.selectedThread.latestRun?.runId}`}
1542 + thread={props.selectedThread}
1543 />
1547 - ))}
1548 - {composerError !== null ? (
1549 - <Animated.View
1550 - className="shrink-0"
1551 - entering={FadeInDown.duration(180)}
1552 - exiting={FadeOut.duration(120)}
1553 - >
1554 - <ComposerErrorNotice
1555 - message={composerError}
1556 - onDismiss={() => clearThreadComposerError(selectedThreadKey)}
1557 - />
1558 - </Animated.View>
1559 - ) : null}
1560 - {usageLimitsReport && activeUserInputRequestId === null ? (
1561 - <Animated.View
1562 - className="shrink-0 px-4"
1563 - style={{ paddingBottom: USAGE_LIMITS_PANEL_GAP }}
1564 - onLayout={handleUsageLimitsLayout}
1565 - entering={FadeInDown.duration(220)}
1566 - exiting={FadeOut.duration(140)}
1567 - >
1568 - <ComposerUsageLimits
1569 - report={usageLimitsReport}
1544 + <ChildThreadApprovals
1545 + threadRef={props.selectedThreadDetailRef}
1546 + maxHeight={pendingUserInputMaxHeight}
1547 + />
1548 + <ThreadGuestShareBar
1549 + threadRef={props.selectedThreadDetailRef}
1550 + canOperateThread={props.canOperateThread}
1551 + />
1552 + {props.draftMode ? null : (
1553 + <ThreadSideChatsRow
1554 environmentId={props.environmentId}
1571 - maxHeight={usageLimitsMaxHeight}
1572 - onClose={dismissUsageLimits}
1555 + threadId={props.selectedThread.id}
1556 />
1574 - </Animated.View>
1575 - ) : null}
1576 - {props.creationState?.kind === "failed" ? (
1577 - <Animated.View
1578 - className="shrink-0 px-4"
1579 - style={{ paddingBottom: composerBottomInset }}
1580 - entering={FadeInDown.duration(220)}
1581 - exiting={FadeOut.duration(140)}
1582 - >
1583 - <ThreadCreationFailedCard
1584 - reason={props.creationState.reason}
1585 - onEditTask={props.creationState.onEditTask}
1557 + )}
1558 + {props.feedbackSubmissions.map((submission) => (
1559 + <ComposerFeedback
1560 + key={submission.id}
1561 + submission={submission}
1562 + onDismiss={() => props.onDismissFeedback(submission.id)}
1563 />
1587 - </Animated.View>
1588 - ) : null}
1589 - {props.activePendingApproval || props.activePendingUserInput ? (
1590 - <Animated.View
1591 - className="shrink-0 gap-3 px-4 pb-3"
1592 - style={
1593 - activeUserInputRequestId !== null
1594 - ? { paddingBottom: composerBottomInset }
1595 - : undefined
1596 - }
1597 - entering={FadeInDown.duration(220)}
1598 - exiting={FadeOut.duration(140)}
1599 - >
1600 - {props.activePendingApproval ? (
1601 - <PendingApprovalCard
1602 - canOperateThread={props.canOperateThread}
1603 - approval={props.activePendingApproval}
1604 - respondingApprovalId={props.respondingApprovalId}
1605 - onRespond={props.onRespondToApproval}
1564 + ))}
1565 + {composerError !== null ? (
1566 + <Animated.View
1567 + className="shrink-0"
1568 + entering={FadeInDown.duration(180)}
1569 + exiting={FadeOut.duration(120)}
1570 + >
1571 + <ComposerErrorNotice
1572 + message={composerError}
1573 + onDismiss={() => clearThreadComposerError(selectedThreadKey)}
1574 />
1607 - ) : null}
1608 - {props.activePendingUserInput ? (
1609 - <PendingUserInputCard
1575 + </Animated.View>
1576 + ) : null}
1577 + {usageLimitsReport && activeUserInputRequestId === null ? (
1578 + <Animated.View
1579 + className="shrink-0 px-4"
1580 + style={{ paddingBottom: USAGE_LIMITS_PANEL_GAP }}
1581 + onLayout={handleUsageLimitsLayout}
1582 + entering={FadeInDown.duration(220)}
1583 + exiting={FadeOut.duration(140)}
1584 + >
1585 + <ComposerUsageLimits
1586 + report={usageLimitsReport}
1587 environmentId={props.environmentId}
1611 - canOperateThread={props.canOperateThread}
1612 - pendingUserInput={props.activePendingUserInput}
1613 - maxHeight={pendingUserInputMaxHeight}
1614 - collapsed={userInputCollapsed}
1615 - onToggleCollapsed={handleToggleUserInputCollapsed}
1616 - onStopThread={props.onStopThread}
1617 - cardProgress={userInputCardProgress}
1618 - cardCoverage={userInputCardCoverage}
1619 - onInputFocusChange={handleOwnedInputFocusChange}
1620 - drafts={props.activePendingUserInputDrafts}
1621 - answers={props.activePendingUserInputAnswers}
1622 - respondingUserInputId={props.respondingUserInputId}
1623 - onSelectOption={props.onSelectUserInputOption}
1624 - onChangeCustomAnswer={props.onChangeUserInputCustomAnswer}
1625 - onSubmit={props.onSubmitUserInput}
1626 - onDismiss={props.onDismissUserInput}
1588 + maxHeight={usageLimitsMaxHeight}
1589 + onClose={dismissUsageLimits}
1590 />
1628 - ) : null}
1629 - </Animated.View>
1630 - ) : null}
1591 + </Animated.View>
1592 + ) : null}
1593 + {props.creationState?.kind === "failed" ? (
1594 + <Animated.View
1595 + className="shrink-0 px-4"
1596 + style={{ paddingBottom: composerBottomInset }}
1597 + entering={FadeInDown.duration(220)}
1598 + exiting={FadeOut.duration(140)}
1599 + >
1600 + <ThreadCreationFailedCard
1601 + reason={props.creationState.reason}
1602 + onEditTask={props.creationState.onEditTask}
1603 + />
1604 + </Animated.View>
1605 + ) : null}
1606 + {props.activePendingApproval || props.activePendingUserInput ? (
1607 + <Animated.View
1608 + className="shrink-0 gap-3 px-4 pb-3"
1609 + style={
1610 + activeUserInputRequestId !== null
1611 + ? { paddingBottom: composerBottomInset }
1612 + : undefined
1613 + }
1614 + entering={FadeInDown.duration(220)}
1615 + exiting={FadeOut.duration(140)}
1616 + >
1617 + {props.activePendingApproval ? (
1618 + <PendingApprovalCard
1619 + canOperateThread={props.canOperateThread}
1620 + approval={props.activePendingApproval}
1621 + respondingApprovalId={props.respondingApprovalId}
1622 + onRespond={props.onRespondToApproval}
1623 + />
1624 + ) : null}
1625 + {props.activePendingUserInput ? (
1626 + <PendingUserInputCard
1627 + environmentId={props.environmentId}
1628 + canOperateThread={props.canOperateThread}
1629 + pendingUserInput={props.activePendingUserInput}
1630 + maxHeight={pendingUserInputMaxHeight}
1631 + collapsed={userInputCollapsed}
1632 + onToggleCollapsed={handleToggleUserInputCollapsed}
1633 + onStopThread={props.onStopThread}
1634 + cardProgress={userInputCardProgress}
1635 + cardCoverage={userInputCardCoverage}
1636 + onInputFocusChange={handleOwnedInputFocusChange}
1637 + drafts={props.activePendingUserInputDrafts}
1638 + answers={props.activePendingUserInputAnswers}
1639 + respondingUserInputId={props.respondingUserInputId}
1640 + onSelectOption={props.onSelectUserInputOption}
1641 + onChangeCustomAnswer={props.onChangeUserInputCustomAnswer}
1642 + onSubmit={props.onSubmitUserInput}
1643 + onDismiss={props.onDismissUserInput}
1644 + />
1645 + ) : null}
1646 + </Animated.View>
1647 + ) : null}
1648 + </ComposerPanels>
1649 </View>
1650
1651 <View style={composerSlotHidden ? { display: "none" } : undefined}>
apps/mobile/src/state/threads.ts
+5
@@ -1,3 +1,4 @@
1 +import { createChildThreadApprovalsAtom } from "@t3tools/client-runtime/state/thread-requests";
2 import { useAtomValue } from "@effect/atom-react";
3 import {
4 createEnvironmentThreadDetailAtoms,
@@ -43,6 +44,10 @@ export const environmentThreadShells = createEnvironmentThreadShellAtoms({
44 catalogValueAtom: environmentCatalog.catalogValueAtom,
45 snapshotAtom: threadEnvironment.snapshotAtom,
46 });
47 +export const childThreadApprovalsAtom = createChildThreadApprovalsAtom({
48 + childThreadInputsAtom: environmentThreadShells.childThreadInputsAtom,
49 + pendingRequestsAtom: environmentThreadDetails.pendingRequestsAtom,
50 +});
51
52 // Long enough for the opened screen to subscribe; its subscription keeps the thread after this.
53 const OPENING_THREAD_HOLD_MS = 3_000;
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
+94
@@ -1512,6 +1512,74 @@ describe("ClaudeAdapterV2 resume compaction", () => {
1512 assert.isFunction(callback);
1513 const canUseTool = openedOptions?.canUseTool;
1514 assert.isFunction(canUseTool);
1515 + const shellSafetyReason =
1516 + "Dangerous rm operation not ruled out — the shell may read this command differently than it was parsed";
1517 + for (const [safetyIndex, { askRule, reason }] of [
1518 + { askRule: false, reason: shellSafetyReason },
1519 + { askRule: true, reason: shellSafetyReason },
1520 + {
1521 + askRule: false,
1522 + reason:
1523 + "Dangerous rm operation on possibly-empty variable path: $TARGET\nUse a literal absolute path instead.",
1524 + },
1525 + { askRule: false, reason: "This shell -c script runs rm and could not be checked" },
1526 + { askRule: false, reason: "A permission rule denies a command in this shell -c script" },
1527 + ].entries()) {
1528 + const safetyRequest = yield* runtime.events.pipe(
1529 + Stream.filter((event) => event.type === "runtime_request.updated"),
1530 + Stream.runHead,
1531 + Effect.forkScoped,
1532 + );
1533 + const safetySignal = yield* Effect.abortSignal;
1534 + const safetyDecision = yield* Effect.promise(() =>
1535 + canUseTool!(
1536 + "Bash",
1537 + { command: "for pair in a b; do echo $pair; done" },
1538 + {
1539 + signal: safetySignal,
1540 + toolUseID: `tool-shell-safety-${safetyIndex}`,
1541 + requestId: `request-shell-safety-${safetyIndex}`,
1542 + decisionReason: `\u001b[33m${reason}\u001b[39m`,
1543 + suppressAlwaysAllowRule: true,
1544 + ...(askRule
1545 + ? {
1546 + matchedAskRule: {
1547 + source: "userSettings" as const,
1548 + toolName: "Bash",
1549 + ruleContent: "*",
1550 + },
1551 + }
1552 + : {}),
1553 + },
1554 + ),
1555 + ).pipe(Effect.forkScoped);
1556 + const safety = yield* Effect.raceFirst(
1557 + Fiber.join(safetyDecision).pipe(
1558 + Effect.map((result) => ({ type: "decision", result }) as const),
1559 + ),
1560 + Fiber.join(safetyRequest).pipe(
1561 + Effect.map((event) => ({ type: "approval", event }) as const),
1562 + ),
1563 + );
1564 + assert.equal(safety.type, askRule ? "approval" : "decision");
1565 + if (safety.type === "decision") {
1566 + assert.equal(safety.result?.behavior, "deny");
1567 + if (safety.result?.behavior === "deny") {
1568 + assert.include(safety.result.message, reason);
1569 + assert.notInclude(safety.result.message, "\u001b[");
1570 + }
1571 + } else if (
1572 + Option.isSome(safety.event) &&
1573 + safety.event.value.type === "runtime_request.updated"
1574 + ) {
1575 + yield* runtime.respondToRuntimeRequest({
1576 + requestId: safety.event.value.runtimeRequest.id,
1577 + decision: "decline",
1578 + });
1579 + assert.equal((yield* Fiber.join(safetyDecision))?.behavior, "deny");
1580 + }
1581 + yield* Fiber.interrupt(safetyRequest);
1582 + }
1583 const longQuestion = `Choose a deployment target: ${"region ".repeat(80)}`;
1584 const questionRequestEvent = yield* runtime.events.pipe(
1585 Stream.filter((event) => event.type === "runtime_request.updated"),
@@ -3877,6 +3945,32 @@ describe("ClaudeAdapterV2 background wake turns", () => {
3945 assert.equal((yield* Fiber.join(forwardedDecision))?.behavior, "deny");
3946 yield* harness.offerAndWait(frame);
3947 }
3948 + const fallbackDecision = yield* Effect.promise(() =>
3949 + harness.getOpenedOptions()!.canUseTool!(
3950 + "Bash",
3951 + { command: "echo checked" },
3952 + {
3953 + signal: new AbortController().signal,
3954 + toolUseID: "safety-check-after-downgrade",
3955 + requestId: "request-safety-check-after-downgrade",
3956 + decisionReason:
3957 + "Dangerous rm operation not ruled out — the shell may read this command differently than it was parsed",
3958 + },
3959 + ),
3960 + ).pipe(Effect.forkScoped);
3961 + const fallbackFirst = yield* Effect.raceFirst(
3962 + Queue.take(harness.runtimeRequestReceipts).pipe(
3963 + Effect.map((event) => ({ type: "request", event }) as const),
3964 + ),
3965 + Fiber.join(fallbackDecision).pipe(Effect.map(() => ({ type: "decision" }) as const)),
3966 + );
3967 + assert.equal(fallbackFirst.type, "request");
3968 + if (fallbackFirst.type !== "request") return;
3969 + yield* harness.runtime.respondToRuntimeRequest({
3970 + requestId: fallbackFirst.event.runtimeRequest.id,
3971 + decision: "decline",
3972 + });
3973 + assert.equal((yield* Fiber.join(fallbackDecision))?.behavior, "deny");
3974 yield* finish;
3975 const unrestrictedOptions = harness.getOpenedOptions();
3976 yield* start("/unrestricted");
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+21
@@ -9763,6 +9763,27 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
9763 } satisfies PermissionResult;
9764 }
9765
9766 + const activePermissionMode =
9767 + (yield* Ref.get(queryContext))?.permissionMode ?? context.queryPolicy.permissionMode;
9768 + const safetyReason = NodeUtil.stripVTControlCharacters(
9769 + callbackOptions.decisionReason ?? "",
9770 + ).trim();
9771 + // The SDK omits the CLI's dangerousRemoval discriminator, so match its removal warnings.
9772 + if (
9773 + toolName === "Bash" &&
9774 + activePermissionMode === "bypassPermissions" &&
9775 + callbackOptions.matchedAskRule === undefined &&
9776 + (/^Dangerous rm(?:dir)?\b/i.test(safetyReason) ||
9777 + safetyReason === "This shell -c script runs rm and could not be checked" ||
9778 + safetyReason === "A permission rule denies a command in this shell -c script")
9779 + ) {
9780 + return {
9781 + behavior: "deny",
9782 + message: `Claude Code's removal safety check denied this command; the user did not reject it. The command did not run. Do not bypass the check by splitting the removal, putting it in a script, or using another tool or shell. If the warning below supplies a safe rewrite, use it and let the same check evaluate it. Otherwise continue the rest of the task without the removal and tell the user what you needed to delete and why. Warning: ${safetyReason}`,
9783 + toolUseID: callbackOptions.toolUseID,
9784 + } satisfies PermissionResult;
9785 + }
9786 +
9787 const requestKind = providerRequestKindFromClaudeTool(toolName);
9788 // The user approves the command itself; Claude's title and description only summarize it.
9789 const command = inputRecordValue(nativeToolInput, "command");
apps/web/src/components/ChatView.tsx
+2
@@ -1,3 +1,4 @@
1 +import { ChildThreadApprovals } from "./chat/ChildThreadApprovals";
2 import { workspaceAreaProps } from "../lib/workspaceFocus";
3 import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
4 import { resolveNewThreadModelSelection } from "@t3tools/shared/usageLimits";
@@ -3539,6 +3540,7 @@ export default function ChatView(props: ChatViewProps) {
3540 : undefined
3541 }
3542 >
3543 + <ChildThreadApprovals threadRef={activeThreadRef} />
3544 <ComposerSurface.Shell contextRow={showComposerContextStrip}>
3545 <ComposerSurface.Host
3546 inert={queuedRunEdit.isSaving}
apps/web/src/components/chat/ChildThreadApprovals.browser.test.tsx new
+52
@@ -0,0 +1,52 @@
1 +import type { ChildThreadApproval } from "@t3tools/client-runtime/state/thread-requests";
2 +import { EnvironmentId, RuntimeRequestId, ThreadId } from "@t3tools/contracts";
3 +import * as Cause from "effect/Cause";
4 +import { AsyncResult, Atom } from "effect/reactivity";
5 +import { expect, it, vi } from "vite-plus/test";
6 +
7 +import { render } from "../../../test/render";
8 +
9 +const state = vi.hoisted(() => ({ respond: vi.fn(), approvalsAtom: null as unknown }));
10 +
11 +vi.mock("../../state/session", () => ({ useEnvironmentScope: () => true }));
12 +vi.mock("../../state/use-atom-command", () => ({ useAtomCommand: () => state.respond }));
13 +vi.mock("../../state/threads", () => ({
14 + childThreadApprovalsAtom: () => state.approvalsAtom,
15 + threadEnvironment: { respondToApproval: {} },
16 +}));
17 +
18 +import { ChildThreadApprovals } from "./ChildThreadApprovals";
19 +
20 +function setup() {
21 + state.respond.mockReset();
22 + state.respond
23 + .mockResolvedValueOnce(AsyncResult.failure(Cause.fail(new Error("Child environment offline"))))
24 + .mockResolvedValueOnce(AsyncResult.success(undefined));
25 + const thread = {
26 + environmentId: EnvironmentId.make("child-env"),
27 + threadId: ThreadId.make("child"),
28 + };
29 + state.approvalsAtom = Atom.make<ReadonlyArray<ChildThreadApproval>>([
30 + {
31 + thread,
32 + title: "Compile task",
33 + approval: {
34 + requestId: RuntimeRequestId.make("approval"),
35 + requestKind: "command",
36 + detail: "Run compiler",
37 + createdAt: "2026-11-01T00:00:00.000Z",
38 + responseCapability: "live",
39 + },
40 + },
41 + ]);
42 + return thread;
43 +}
44 +
45 +it("shows a failed decision and clears the error when the user retries", async () => {
46 + const thread = setup();
47 + await using screen = await render(<ChildThreadApprovals threadRef={thread} />);
48 + await screen.getByRole("button", { name: "Approve", exact: true }).click();
49 + await expect.element(screen.getByRole("alert")).toHaveTextContent("Child environment offline");
50 + await screen.getByRole("button", { name: "Approve", exact: true }).click();
51 + await expect.element(screen.getByRole("alert")).not.toBeInTheDocument();
52 +});
apps/web/src/components/chat/ChildThreadApprovals.tsx new
+95
@@ -0,0 +1,95 @@
1 +import { useAtomValue } from "@effect/atom-react";
2 +import { AuthOrchestrationOperateScope, type ScopedThreadRef } from "@t3tools/contracts";
3 +import type { ChildThreadApproval } from "@t3tools/client-runtime/state/thread-requests";
4 +import { fullAccessOverrideExplanation } from "@t3tools/client-runtime/state/thread-requests";
5 +import {
6 + isAtomCommandInterrupted,
7 + squashAtomCommandFailure,
8 +} from "@t3tools/client-runtime/state/runtime";
9 +import { useState } from "react";
10 +import { useEnvironmentScope } from "../../state/session";
11 +import { childThreadApprovalsAtom, threadEnvironment } from "../../state/threads";
12 +import { useAtomCommand } from "../../state/use-atom-command";
13 +import { ComposerPendingApprovalActions } from "./ComposerPendingApprovalActions";
14 +
15 +function ChildApproval({ entry }: { entry: ChildThreadApproval }) {
16 + const canRespond = useEnvironmentScope(entry.thread.environmentId, AuthOrchestrationOperateScope);
17 + const respond = useAtomCommand(threadEnvironment.respondToApproval, { reportFailure: false });
18 + const [responding, setResponding] = useState(false);
19 + const [error, setError] = useState<string | null>(null);
20 + const { approval } = entry;
21 + return (
22 + <section
23 + aria-label={`Approval from ${entry.title}`}
24 + className="rounded-lg border border-border bg-background p-3 text-xs"
25 + >
26 + <p className="mb-2 font-medium">Approval needed from {entry.title}</p>
27 + <pre className="max-h-40 overflow-auto whitespace-pre-wrap break-words font-mono">
28 + {approval.detail || approval.requestKind}
29 + </pre>
30 + {approval.appName ? <p className="mt-2 text-muted-foreground">{approval.appName}</p> : null}
31 + {approval.responseCapability !== "live" ? (
32 + <p className="mt-2 text-warning">
33 + Provider process is gone. Interrupt or restart the child thread to respond.
34 + </p>
35 + ) : null}
36 + {approval.reason ? <p className="mt-2 text-muted-foreground">{approval.reason}</p> : null}
37 + {approval.fullAccessOverride ? (
38 + <p className="mt-2 text-muted-foreground">
39 + {fullAccessOverrideExplanation(approval.fullAccessOverride)}
40 + </p>
41 + ) : null}
42 + <div className="mt-2 flex flex-wrap gap-2">
43 + <ComposerPendingApprovalActions
44 + presentation="inline"
45 + requestId={approval.requestId}
46 + isResponding={responding}
47 + canRespond={approval.responseCapability === "live"}
48 + disabled={!canRespond}
49 + options={approval.options}
50 + onRespondToApproval={async (requestId, decision) => {
51 + if (!canRespond || responding) return;
52 + setResponding(true);
53 + setError(null);
54 + const result = await respond({
55 + environmentId: entry.thread.environmentId,
56 + input: { threadId: entry.thread.threadId, requestId, decision },
57 + });
58 + if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
59 + const failure = squashAtomCommandFailure(result);
60 + setError(
61 + failure instanceof Error ? failure.message : "Failed to submit approval decision.",
62 + );
63 + }
64 + setResponding(false);
65 + return result;
66 + }}
67 + />
68 + </div>
69 + {error !== null ? (
70 + <p role="alert" className="mt-2 text-destructive">
71 + {error}
72 + </p>
73 + ) : null}
74 + </section>
75 + );
76 +}
77 +
78 +export function ChildThreadApprovals({ threadRef }: { threadRef: ScopedThreadRef | null }) {
79 + const approvals = useAtomValue(childThreadApprovalsAtom(threadRef));
80 + if (approvals.length === 0) return null;
81 + return (
82 + <div className="mb-2 flex max-h-80 flex-col gap-2 overflow-auto">
83 + {approvals.map((entry) => (
84 + <ChildApproval
85 + key={JSON.stringify([
86 + entry.thread.environmentId,
87 + entry.thread.threadId,
88 + entry.approval.requestId,
89 + ])}
90 + entry={entry}
91 + />
92 + ))}
93 + </div>
94 + );
95 +}
apps/web/src/state/threads.ts
+5
@@ -1,3 +1,4 @@
1 +import { createChildThreadApprovalsAtom } from "@t3tools/client-runtime/state/thread-requests";
2 import { useAtomValue } from "@effect/atom-react";
3 import { enabledEnvironmentIds } from "@t3tools/client-runtime/state/connections";
4 import { arrayElementsEqual } from "@t3tools/client-runtime/state/entities";
@@ -39,6 +40,10 @@ export const environmentThreadShells = createEnvironmentThreadShellAtoms({
40 catalogValueAtom: environmentCatalog.catalogValueAtom,
41 snapshotAtom: threadEnvironment.snapshotAtom,
42 });
43 +export const childThreadApprovalsAtom = createChildThreadApprovalsAtom({
44 + childThreadInputsAtom: environmentThreadShells.childThreadInputsAtom,
45 + pendingRequestsAtom: environmentThreadDetails.pendingRequestsAtom,
46 +});
47
48 const EMPTY_THREAD_STATE_ATOM = Atom.make(AsyncResult.success(EMPTY_ENVIRONMENT_THREAD_STATE)).pipe(
49 Atom.withLabel("web-environment-thread:empty"),
docs/user/permission-modes.md
+5 -2
@@ -18,7 +18,8 @@ and modes you choose in a draft keep their permissions.
18 | **Full access** | Allows commands and edits without approval prompts. |
19
20 Approve or reject requests in the conversation to let the agent continue. Permission modes do
21 -not prevent the agent from asking questions about the task.
21 +not prevent the agent from asking questions about the task. Subagent approval requests appear in
22 +the parent conversation with the subagent's name, so you can respond without switching threads.
23
24 ## Provider differences
25
@@ -41,7 +42,9 @@ ACP Registry agents run their own tools in their own mode; T3 Code answers their
42 by the permission mode. See [ACP Registry permissions](./providers-acp.md#permissions-and-terminals).
43
44 Claude can still ask in **Full access** when its settings disable bypass permissions or require
44 -approval for an action.
45 +approval for an action. Dangerous-removal safety checks in bypass mode reject the command with
46 +the original warning. Claude can use a safe rewrite when the warning supplies one; otherwise it
47 +continues without the removal and tells you what it skipped.
48 While a Claude approval is pending, type a text reply to decline that request and give feedback
49 directly to the agent that asked, including a subagent. Other pending requests stay unanswered.
50
packages/client-runtime/src/state/threadRequests.test.ts
+64 -2
@@ -1,5 +1,9 @@
1 +import { presentThreadShell } from "./models.ts";
2 +import { threadKey } from "./entities.ts";
3 import {
4 EnvironmentId,
5 + ThreadId,
6 + type ScopedThreadRef,
7 NodeId,
8 ProviderSessionId,
9 RuntimeRequestId,
@@ -7,11 +11,13 @@ import {
11 type OrchestrationV2ThreadProjection,
12 } from "@t3tools/contracts";
13 import { describe, expect, it, vi } from "vite-plus/test";
10 -import { AsyncResult } from "effect/reactivity";
14 +import { Atom, AtomRegistry, AsyncResult } from "effect/reactivity";
15 import * as Cause from "effect/Cause";
12 -import { v2Now, v2Projection } from "./orchestrationV2TestFixtures.ts";
16 +import { v2Now, v2Projection, v2ThreadShell } from "./orchestrationV2TestFixtures.ts";
17 import {
18 createQuestionHistoryProjector,
19 + createChildThreadApprovalsAtom,
20 + type PendingThreadRequests,
21 derivePendingThreadRequests,
22 declinePendingApprovals,
23 sendApprovalFeedback,
@@ -353,3 +359,59 @@ it("restores old text answers without mutating history or replacing unchanged ro
359 expect(project(answered)).toBe(result);
360 expect(project({ ...answered, visibleTurnItems: [...rows] })[0]).toBe(result[0]);
361 });
362 +
363 +it("loads only child approvals and retains their destination across environments", () => {
364 + const local = EnvironmentId.make("local");
365 + const remote = EnvironmentId.make("remote");
366 + const parent = { environmentId: local, threadId: ThreadId.make("parent") };
367 + const childId = ThreadId.make("child");
368 + const children = Atom.make(
369 + [local, remote].map((environmentId) => ({
370 + ...presentThreadShell(environmentId, v2ThreadShell),
371 + id: childId,
372 + title: environmentId,
373 + hasPendingApprovals: true,
374 + })),
375 + );
376 + const details = Atom.family((key: string) =>
377 + Atom.make<PendingThreadRequests | null>({
378 + approvals: [
379 + {
380 + requestId: RuntimeRequestId.make(key),
381 + requestKind: "command",
382 + createdAt: "2026-10-19T00:00:00Z",
383 + responseCapability: "live",
384 + },
385 + ],
386 + userInputs: [],
387 + }),
388 + );
389 + const readDetails = vi.fn((ref: ScopedThreadRef) => details(threadKey(ref)));
390 + const approvalsAtom = createChildThreadApprovalsAtom({
391 + childThreadInputsAtom: () => children,
392 + pendingRequestsAtom: readDetails,
393 + });
394 + const registry = AtomRegistry.make();
395 + const unmount = registry.mount(approvalsAtom(parent));
396 + const pending = registry.get(approvalsAtom(parent));
397 + expect(pending.map((entry) => entry.thread)).toEqual(
398 + [local, remote].map((environmentId) => ({ environmentId, threadId: childId })),
399 + );
400 + expect(pending.map((entry) => entry.title)).toEqual(["local", "remote"]);
401 + registry.set(details(threadKey({ environmentId: remote, threadId: childId })), {
402 + approvals: [],
403 + userInputs: [],
404 + });
405 + expect(registry.get(approvalsAtom(parent))).toEqual([pending[0]]);
406 + readDetails.mockClear();
407 + registry.set(
408 + children,
409 + registry
410 + .get(children)
411 + .map((child) => ({ ...child, hasPendingApprovals: false, hasPendingUserInput: true })),
412 + );
413 + expect(registry.get(approvalsAtom(parent))).toEqual([]);
414 + expect(readDetails).not.toHaveBeenCalled();
415 + unmount();
416 + registry.dispose();
417 +});
packages/client-runtime/src/state/threadRequests.ts
+49
@@ -1,5 +1,6 @@
1 import type {
2 EnvironmentId,
3 + ScopedThreadRef,
4 ThreadId,
5 OrchestrationV2ThreadProjection,
6 OrchestrationV2RuntimeRequest,
@@ -10,6 +11,9 @@ import type {
11 ProviderRequestKind,
12 RuntimeRequestId,
13 } from "@t3tools/contracts";
14 +import { Atom } from "effect/reactivity";
15 +import { parseThreadKey, threadKey } from "./entities.ts";
16 +import type { EnvironmentThreadShell } from "./models.ts";
17 import * as DateTime from "effect/DateTime";
18 import type { AtomCommandResult } from "./runtime.ts";
19 import type { ThreadStructure, ThreadStructureVisibleTurnItem } from "./models.ts";
@@ -339,3 +343,48 @@ export function createQuestionHistoryProjector<
343 return previousResult;
344 };
345 }
346 +
347 +export interface ChildThreadApproval {
348 + readonly thread: ScopedThreadRef;
349 + readonly title: string;
350 + readonly approval: ThreadPendingApproval;
351 +}
352 +
353 +export function createChildThreadApprovalsAtom(input: {
354 + readonly childThreadInputsAtom: (
355 + ref: ScopedThreadRef,
356 + ) => Atom.Atom<ReadonlyArray<EnvironmentThreadShell>>;
357 + readonly pendingRequestsAtom: (ref: ScopedThreadRef) => Atom.Atom<PendingThreadRequests | null>;
358 +}) {
359 + const family = Atom.family((key: string) => {
360 + let previous: ReadonlyArray<ChildThreadApproval> = [];
361 + return Atom.make((get) => {
362 + const next = get(input.childThreadInputsAtom(parseThreadKey(key))).flatMap((child) => {
363 + if (!child.hasPendingApprovals) return [];
364 + const thread = { environmentId: child.environmentId, threadId: child.id };
365 + // Only children asking for approval need a detail subscription.
366 + return (get(input.pendingRequestsAtom(thread))?.approvals ?? []).map((approval) => ({
367 + thread,
368 + title: child.title,
369 + approval,
370 + }));
371 + });
372 + if (
373 + next.length === previous.length &&
374 + next.every((entry, index) => {
375 + const old = previous[index]!;
376 + return (
377 + old.approval === entry.approval &&
378 + old.title === entry.title &&
379 + threadKey(old.thread) === threadKey(entry.thread)
380 + );
381 + })
382 + )
383 + return previous;
384 + previous = next;
385 + return next;
386 + });
387 + });
388 + const empty = Atom.make<ReadonlyArray<ChildThreadApproval>>([]);
389 + return (ref: ScopedThreadRef | null) => (ref === null ? empty : family(threadKey(ref)));
390 +}