Skip to content

The open-source agent harness - the runtime layer that turns an LLM into a working agent.

Add Approval Navigation Banner and Related Functionality (#474)

Govinda Vashishtha555bef0043fe
diff --git a/.changeset/20260909054805-regenerate-sdk-from-openapi.md b/.changeset/20260909054805-regenerate-sdk-from-openapi.md
new file mode 100644
index 000000000..efd8ff00f
--- /dev/null
+++ b/.changeset/20260909054805-regenerate-sdk-from-openapi.md
@@ -0,0 +1,5 @@
+---
+"@truefoundry/trueforge-sdk": patch
+---
+
+Regenerate SDK from updated OpenAPI spec.
diff --git a/.changeset/pre/approval-nav-banner.md b/.changeset/pre/approval-nav-banner.md
new file mode 100644
index 000000000..5f5e16a45
--- /dev/null
+++ b/.changeset/pre/approval-nav-banner.md
@@ -0,0 +1,5 @@
+---
+"@truefoundry/trueforge-ui": minor
+---
+
+Add a composer approval-nav banner (overridable `ApprovalNavBanner` slot) that counts pending tool approvals, pauses the composer, and jumps/expands/flashes the focused approval — including nested subagent tools.
diff --git a/.changeset/relative-sandbox-artifact-downloads.md b/.changeset/relative-sandbox-artifact-downloads.md
new file mode 100644
index 000000000..03b39c703
--- /dev/null
+++ b/.changeset/relative-sandbox-artifact-downloads.md
@@ -0,0 +1,5 @@
+---
+"@truefoundry/trueforge": patch
+---
+
+Allow sandbox artifact downloads to use paths relative to the sandbox working directory.
diff --git a/.github/fern/openapi/openapi.json b/.github/fern/openapi/openapi.json
index 55efcb49e..2483e5ef6 100644
--- a/.github/fern/openapi/openapi.json
+++ b/.github/fern/openapi/openapi.json
@@ -7764,12 +7764,12 @@
}
},
{
- "description": "Absolute path of the file inside the sandbox, as listed in the assistant's `sandbox_artifacts` block.",
+ "description": "Absolute or sandbox-working-directory-relative file path, as listed in the assistant's `sandbox_artifacts` block.",
"in": "query",
"name": "path",
"required": true,
"schema": {
- "description": "Absolute path of the file inside the sandbox, as listed in the assistant's `sandbox_artifacts` block.",
+ "description": "Absolute or sandbox-working-directory-relative file path, as listed in the assistant's `sandbox_artifacts` block.",
"minLength": 1,
"type": "string"
}
diff --git a/docs/openapi.json b/docs/openapi.json
index 55efcb49e..2483e5ef6 100644
--- a/docs/openapi.json
+++ b/docs/openapi.json
@@ -7764,12 +7764,12 @@
}
},
{
- "description": "Absolute path of the file inside the sandbox, as listed in the assistant's `sandbox_artifacts` block.",
+ "description": "Absolute or sandbox-working-directory-relative file path, as listed in the assistant's `sandbox_artifacts` block.",
"in": "query",
"name": "path",
"required": true,
"schema": {
- "description": "Absolute path of the file inside the sandbox, as listed in the assistant's `sandbox_artifacts` block.",
+ "description": "Absolute or sandbox-working-directory-relative file path, as listed in the assistant's `sandbox_artifacts` block.",
"minLength": 1,
"type": "string"
}
diff --git a/packages/trueforge-sdk/src/api/resources/sessions/client/requests/DownloadSandboxFileSessionsRequest.ts b/packages/trueforge-sdk/src/api/resources/sessions/client/requests/DownloadSandboxFileSessionsRequest.ts
index ad9bc6fd0..322b3105e 100644
--- a/packages/trueforge-sdk/src/api/resources/sessions/client/requests/DownloadSandboxFileSessionsRequest.ts
+++ b/packages/trueforge-sdk/src/api/resources/sessions/client/requests/DownloadSandboxFileSessionsRequest.ts
@@ -7,6 +7,6 @@
* }
*/
export interface DownloadSandboxFileSessionsRequest {
- /** Absolute path of the file inside the sandbox, as listed in the assistant's `sandbox_artifacts` block. */
+ /** Absolute or sandbox-working-directory-relative file path, as listed in the assistant's `sandbox_artifacts` block. */
path: string;
}
diff --git a/packages/trueforge-ui/src/atoms/ApprovalNavBanner.tsx b/packages/trueforge-ui/src/atoms/ApprovalNavBanner.tsx
new file mode 100644
index 000000000..804ab53d2
--- /dev/null
+++ b/packages/trueforge-ui/src/atoms/ApprovalNavBanner.tsx
@@ -0,0 +1,85 @@
+'use client';
+
+import { Icon } from '../icons/Icon.js';
+import { cn } from './lib/cn.js';
+
+export type ApprovalNavBannerProps = {
+ total: number;
+ /** 1-based index for display, e.g. 1 in "(1/4)". */
+ current: number;
+ canPrev: boolean;
+ canNext: boolean;
+ onPrev: () => void;
+ onNext: () => void;
+ /** Scroll the thread to the currently selected approval. */
+ onFocusCurrent: () => void;
+ className?: string;
+};
+
+export function ApprovalNavBanner({
+ total,
+ current,
+ canPrev,
+ canNext,
+ onPrev,
+ onNext,
+ onFocusCurrent,
+ className,
+}: ApprovalNavBannerProps) {
+ const label = total === 1 ? '1 tool needs your input' : `${String(total)} tools need your input`;
+
+ return (
+ <div
+ data-slot="aui_approval-nav-banner"
+ role="status"
+ aria-live="polite"
+ aria-label={`${label}. Click to go to approval ${String(current)} of ${String(total)}.`}
+ onClick={onFocusCurrent}
+ className={cn(
+ 'aui-approval-nav-banner border-approval-banner-border bg-approval-banner-bg text-approval-banner-fg flex w-full cursor-pointer items-center justify-between gap-2 border-t px-4 py-1.5 text-sm',
+ 'rounded-t-[var(--composer-radius,1.5rem)]',
+ className,
+ )}
+ >
+ <div className="flex min-w-0 items-center gap-3">
+ <span className="bg-approval-banner-accent size-2 shrink-0 rounded-full" aria-hidden />
+ <span className="truncate font-medium leading-[1.4]">{label}</span>
+ </div>
+ <div className="flex shrink-0 items-center gap-2">
+ <span className="font-medium tabular-nums leading-[1.4]">
+ ({current}/{total})
+ </span>
+ <button
+ type="button"
+ aria-label="Next approval"
+ disabled={!canNext}
+ onClick={event => {
+ event.stopPropagation();
+ onNext();
+ }}
+ className="text-approval-banner-fg hover:bg-approval-banner-border/10 inline-flex size-6 items-center justify-center rounded-sm disabled:pointer-events-none disabled:opacity-40"
+ >
+ <Icon name="arrow-down" size="0.875rem" />
+ </button>
+ <button
+ type="button"
+ aria-label="Previous approval"
+ disabled={!canPrev}
+ onClick={event => {
+ event.stopPropagation();
+ onPrev();
+ }}
+ className="text-approval-banner-fg hover:bg-approval-banner-border/10 inline-flex size-6 items-center justify-center rounded-sm disabled:pointer-events-none disabled:opacity-40"
+ >
+ <Icon name="arrow-up" size="0.875rem" />
+ </button>
+ </div>
+ </div>
+ );
+}
+
+declare module '../theme/SlotsProvider.js' {
+ interface AtomSlots {
+ ApprovalNavBanner: typeof ApprovalNavBanner;
+ }
+}
diff --git a/packages/trueforge-ui/src/atoms/SandboxToolCallCard.tsx b/packages/trueforge-ui/src/atoms/SandboxToolCallCard.tsx
index 1844223fe..772826b73 100644
--- a/packages/trueforge-ui/src/atoms/SandboxToolCallCard.tsx
+++ b/packages/trueforge-ui/src/atoms/SandboxToolCallCard.tsx
@@ -1,5 +1,7 @@
'use client';
+import type { ReactNode } from 'react';
+
import { Icon } from '../icons/Icon.js';
import { useSlot } from '../theme/SlotsProvider.js';
import { cn } from './lib/cn.js';
@@ -20,6 +22,9 @@ export type SandboxToolCallCardProps = {
hasContent?: boolean;
onViewModeChange?: (viewMode: 'terminal' | 'code') => void;
durationText?: string;
+ approvalSlot?: ReactNode;
+ /** When set, this card is the scroll/flash target for approval banner navigation. */
+ approvalId?: string;
dataTestPrefix?: string;
className?: string;
};
@@ -201,6 +206,8 @@ export function SandboxToolCallCard({
hasContent = false,
onViewModeChange,
durationText,
+ approvalSlot,
+ approvalId,
dataTestPrefix,
className,
}: SandboxToolCallCardProps) {
@@ -219,6 +226,8 @@ export function SandboxToolCallCard({
showResponseLine={false}
status={awaiting ? undefined : status}
exitCode={exitCode}
+ approvalSlot={approvalSlot}
+ approvalId={approvalId}
dataTestPrefix={dataTestPrefix}
requestSlot={
<SandboxBody
diff --git a/packages/trueforge-ui/src/atoms/ToolCallCard.tsx b/packages/trueforge-ui/src/atoms/ToolCallCard.tsx
index 54b0e0304..647798d1b 100644
--- a/packages/trueforge-ui/src/atoms/ToolCallCard.tsx
+++ b/packages/trueforge-ui/src/atoms/ToolCallCard.tsx
@@ -1,7 +1,8 @@
'use client';
-import type { ReactNode } from 'react';
+import { useRef, type ReactNode } from 'react';
+import { useOptionalApprovalFocus, useRegisterApprovalTarget } from '../containers/approvalFocus.js';
import { AgentStepRow, type AgentStepStatus } from './agent-chat/AgentStepRow.js';
import { cn } from './lib/cn.js';
@@ -22,6 +23,8 @@ export type ToolCallCardProps = {
showResponseLine?: boolean;
responseIcon?: ReactNode;
approvalSlot?: ReactNode;
+ /** When set, this card is the scroll/flash target for approval banner navigation. */
+ approvalId?: string;
requestSlot?: ReactNode;
responseSlot?: ReactNode;
highlightCard?: boolean;
@@ -46,6 +49,7 @@ export function ToolCallCard({
showExpandChevron = true,
showResponseLine = false,
approvalSlot,
+ approvalId,
requestSlot,
responseSlot,
highlightCard = false,
@@ -53,11 +57,16 @@ export function ToolCallCard({
mcpServerName: _mcpServerName,
dataTestPrefix,
}: ToolCallCardProps) {
+ const rootRef = useRef<HTMLDivElement>(null);
+ const focusApi = useOptionalApprovalFocus();
+ useRegisterApprovalTarget(approvalId, rootRef);
+
const hasApproval = !!approvalSlot;
const hasRequest = !!requestSlot;
const hasResponse = !!responseSlot;
const showConnector = hasApproval || hasRequest || hasResponse;
const isExpandable = showExpandChevron && (hasRequest || hasResponse);
+ const isFlashing = approvalId != null && focusApi?.flashingApprovalId === approvalId;
let derivedStatus: AgentStepStatus = 'idle';
if (explicitStatus) derivedStatus = explicitStatus;
@@ -73,9 +82,12 @@ export function ToolCallCard({
return (
<div
+ ref={rootRef}
+ data-approval-id={approvalId}
className={cn(
'aui-tool-call-card flex min-w-0 flex-col',
- highlightCard ? 'rounded-md p-1 -mx-1' : 'mx-0 mt-2 p-0',
+ approvalId != null || highlightCard ? 'mx-0 mt-2 rounded-md pt-1.5 pr-2 pb-1' : 'mx-0 mt-2 p-0',
+ isFlashing && 'aui-approval-flash',
className,
)}
data-testid={dataTestPrefix ? `${dataTestPrefix}-tool-call-card` : undefined}
diff --git a/packages/trueforge-ui/src/containers/ApprovalNavContainer.tsx b/packages/trueforge-ui/src/containers/ApprovalNavContainer.tsx
new file mode 100644
index 000000000..f0b8b7a11
--- /dev/null
+++ b/packages/trueforge-ui/src/containers/ApprovalNavContainer.tsx
@@ -0,0 +1,24 @@
+'use client';
+
+import { useApprovalNav } from '../hooks/useApprovalNav.js';
+import { useSlot } from '../theme/SlotsProvider.js';
+
+/** Composer banner that navigates pending tool approvals. */
+export function ApprovalNavContainer() {
+ const ApprovalNavBanner = useSlot('ApprovalNavBanner');
+ const { count, index, canPrev, canNext, goPrev, goNext, focusCurrent } = useApprovalNav();
+
+ if (count === 0) return null;
+
+ return (
+ <ApprovalNavBanner
+ total={count}
+ current={index + 1}
+ canPrev={canPrev}
+ canNext={canNext}
+ onPrev={goPrev}
+ onNext={goNext}
+ onFocusCurrent={focusCurrent}
+ />
+ );
+}
diff --git a/packages/trueforge-ui/src/containers/ComposerContainer.tsx b/packages/trueforge-ui/src/containers/ComposerContainer.tsx
index 231d55a9e..348422c4a 100644
--- a/packages/trueforge-ui/src/containers/ComposerContainer.tsx
+++ b/packages/trueforge-ui/src/containers/ComposerContainer.tsx
@@ -9,6 +9,7 @@ import { useComposerBusyState } from '../hooks/useComposerBusyState.js';
import { useComposerPauseView } from '../hooks/useComposerPauseView.js';
import { useOptionalShellMode } from '../server/ShellModeContext.js';
import { SlotsProvider, useSlot, useSlotIsDefault } from '../theme/SlotsProvider.js';
+import { ApprovalNavContainer } from './ApprovalNavContainer.js';
import { AskUserContainer } from './AskUserContainer.js';
import { ComposerAttachmentsContainer } from './AttachmentsContainer.js';
import { CustomActionContainer } from './CustomActionContainer.js';
@@ -18,7 +19,16 @@ export type ComposerContainerProps = {
placeholder?: string;
};
-function ComposerBody({ placeholder }: { placeholder: string }) {
+function ComposerBody({
+ placeholder,
+ forceDisabled = false,
+ connectedToBanner = false,
+}: {
+ placeholder: string;
+ forceDisabled?: boolean;
+ /** Flatten top radius/border so the approval banner sits flush above. */
+ connectedToBanner?: boolean;
+}) {
const ComposerShell = useSlot('ComposerShell');
const aui = useAui();
const shell = useOptionalShellMode();
@@ -30,7 +40,8 @@ function ComposerBody({ placeholder }: { placeholder: string }) {
const { isBusy, send, resetBusy } = useComposerBusyState();
const cancel = useTrueFoundryCancel();
const fileInputRef = useRef<HTMLInputElement>(null);
- const canSubmit = !isBusy && hasText && (!requiresModel || hasModel);
+ const disabled = isBusy || forceDisabled;
+ const canSubmit = !disabled && hasText && (!requiresModel || hasModel);
const submit = () => {
if (!canSubmit) return;
send(() => aui.composer().send());
@@ -54,7 +65,7 @@ function ComposerBody({ placeholder }: { placeholder: string }) {
}}
/>
<ComposerPrimitive.AttachmentDropzone
- disabled={isBusy}
+ disabled={disabled}
data-slot="aui_composer-attachment-dropzone"
className="w-full rounded-[0.75rem] transition-[box-shadow] data-[dragging=true]:ring-focus-ring/20 data-[dragging=true]:ring-3"
>
@@ -68,20 +79,26 @@ function ComposerBody({ placeholder }: { placeholder: string }) {
}}
>
<ComposerShell
+ className={
+ connectedToBanner
+ ? // Banner owns the top accent; composer keeps its normal chrome without a shared blue frame.
+ 'rounded-t-none border-t-0 focus-within:ring-0'
+ : undefined
+ }
attachments={<ComposerAttachmentsContainer />}
input={
<ComposerPrimitive.Input
data-slot="aui_composer-input"
placeholder={placeholder}
- disabled={isBusy}
+ disabled={disabled}
submitMode="enter"
aria-label="Message input"
className="text-text-primary placeholder:text-text-secondary/80 max-h-[10lh] min-h-10 w-full resize-none overflow-y-auto rounded-lg border-none bg-transparent px-1 py-1 text-base leading-normal shadow-none outline-none disabled:cursor-not-allowed"
/>
}
- disabled={isBusy}
+ disabled={disabled}
canSubmit={canSubmit}
- isRunning={isBusy}
+ isRunning={isBusy && !forceDisabled}
onSubmit={submit}
onCancel={() => {
resetBusy();
@@ -95,10 +112,15 @@ function ComposerBody({ placeholder }: { placeholder: string }) {
);
}
-export function ComposerContainer({
- placeholder = 'Ask anything... (Shift+Enter for new line)',
-}: ComposerContainerProps) {
- const pauseView = useComposerPauseView();
+function ComposerWithOptionalDraft({
+ placeholder,
+ forceDisabled = false,
+ connectedToBanner = false,
+}: {
+ placeholder: string;
+ forceDisabled?: boolean;
+ connectedToBanner?: boolean;
+}) {
const shell = useOptionalShellMode();
const parentLeftSection = useSlot('ComposerLeftSection');
const parentRightSection = useSlot('ComposerRightSection');
@@ -108,16 +130,6 @@ export function ComposerContainer({
const DraftComposerRightSection = useSlot('DraftComposerRightSection');
const canMutateSpec = shell?.mode.status === 'active' && shell.mode.isMutable;
- if (pauseView.kind === 'mcp') {
- return <McpAuthContainer />;
- }
- if (pauseView.kind === 'custom') {
- return <CustomActionContainer />;
- }
- if (pauseView.kind === 'ask-user') {
- return <AskUserContainer />;
- }
-
if (canMutateSpec) {
return (
<DraftCatalogProvider>
@@ -127,11 +139,37 @@ export function ComposerContainer({
ComposerRightSection: usesDefaultRightSection ? DraftComposerRightSection : parentRightSection,
}}
>
- <ComposerBody placeholder={placeholder} />
+ <ComposerBody placeholder={placeholder} forceDisabled={forceDisabled} connectedToBanner={connectedToBanner} />
</SlotsProvider>
</DraftCatalogProvider>
);
}
- return <ComposerBody placeholder={placeholder} />;
+ return <ComposerBody placeholder={placeholder} forceDisabled={forceDisabled} connectedToBanner={connectedToBanner} />;
+}
+
+export function ComposerContainer({
+ placeholder = 'Ask anything... (Shift+Enter for new line)',
+}: ComposerContainerProps) {
+ const pauseView = useComposerPauseView();
+
+ if (pauseView.kind === 'mcp') {
+ return <McpAuthContainer />;
+ }
+ if (pauseView.kind === 'custom') {
+ return <CustomActionContainer />;
+ }
+ if (pauseView.kind === 'ask-user') {
+ return <AskUserContainer />;
+ }
+ if (pauseView.kind === 'approval') {
+ return (
+ <div data-slot="aui_composer-approval-pause" className="flex w-full flex-col">
+ <ApprovalNavContainer />
+ <ComposerWithOptionalDraft placeholder={placeholder} forceDisabled connectedToBanner />
+ </div>
+ );
+ }
+
+ return <ComposerWithOptionalDraft placeholder={placeholder} />;
}
diff --git a/packages/trueforge-ui/src/containers/ThreadContainer.tsx b/packages/trueforge-ui/src/containers/ThreadContainer.tsx
index 9d2006fb8..32f5a372f 100644
--- a/packages/trueforge-ui/src/containers/ThreadContainer.tsx
+++ b/packages/trueforge-ui/src/containers/ThreadContainer.tsx
@@ -8,6 +8,7 @@ import { useSyncSessionTitle } from '../hooks/useSyncSessionTitle.js';
import { useOptionalShellMode } from '../server/ShellModeContext.js';
import { useSlot } from '../theme/SlotsProvider.js';
import { isNewChatView } from '../utils/isNewChatView.js';
+import { ApprovalFocusProvider } from './approvalFocus.js';
import { AssistantMessageContainer } from './AssistantMessageContainer.js';
import { HistoryLoaderContainer } from './HistoryLoaderContainer.js';
import { ResumeUnavailableContainer } from './ResumeUnavailableContainer.js';
@@ -65,44 +66,46 @@ export function ThreadContainer({ composer }: ThreadContainerProps) {
return (
<ComposerBusyProvider>
- <ThreadPrimitive.Root asChild>
- <ThreadRootShell>
- <ThreadPrimitive.Viewport asChild autoScroll>
- <ThreadViewportShell isEmpty={isEmpty}>
- {isEmpty && <WelcomeScreen heading={welcomeHeading} />}
- {isEmpty && !isLoading && composer}
- {isLoading ? (
- <MessageListSkeleton />
- ) : (
- !isEmpty && (
- <>
- <HistoryLoaderContainer />
- <MessageGroup>
- <ThreadPrimitive.Messages>
- {({ message }) => (
- <AnimatedMessageShell>
- <ThreadMessage isEditing={message.role === 'user' && message.composer.isEditing} />
- </AnimatedMessageShell>
- )}
- </ThreadPrimitive.Messages>
- <ResumeUnavailableContainer />
- </MessageGroup>
- </>
- )
- )}
- </ThreadViewportShell>
- </ThreadPrimitive.Viewport>
+ <ApprovalFocusProvider>
+ <ThreadPrimitive.Root asChild>
+ <ThreadRootShell>
+ <ThreadPrimitive.Viewport asChild autoScroll>
+ <ThreadViewportShell isEmpty={isEmpty}>
+ {isEmpty && <WelcomeScreen heading={welcomeHeading} />}
+ {isEmpty && !isLoading && composer}
+ {isLoading ? (
+ <MessageListSkeleton />
+ ) : (
+ !isEmpty && (
+ <>
+ <HistoryLoaderContainer />
+ <MessageGroup>
+ <ThreadPrimitive.Messages>
+ {({ message }) => (
+ <AnimatedMessageShell>
+ <ThreadMessage isEditing={message.role === 'user' && message.composer.isEditing} />
+ </AnimatedMessageShell>
+ )}
+ </ThreadPrimitive.Messages>
+ <ResumeUnavailableContainer />
+ </MessageGroup>
+ </>
+ )
+ )}
+ </ThreadViewportShell>
+ </ThreadPrimitive.Viewport>
- {!isLoading && !isEmpty && (
- <ThreadComposerAreaShell isEmpty={isEmpty}>
- <ThreadPrimitive.ScrollToBottom asChild>
- <ScrollToBottomButton />
- </ThreadPrimitive.ScrollToBottom>
- {composer}
- </ThreadComposerAreaShell>
- )}
- </ThreadRootShell>
- </ThreadPrimitive.Root>
+ {!isLoading && !isEmpty && (
+ <ThreadComposerAreaShell isEmpty={isEmpty}>
+ <ThreadPrimitive.ScrollToBottom asChild>
+ <ScrollToBottomButton />
+ </ThreadPrimitive.ScrollToBottom>
+ {composer}
+ </ThreadComposerAreaShell>
+ )}
+ </ThreadRootShell>
+ </ThreadPrimitive.Root>
+ </ApprovalFocusProvider>
</ComposerBusyProvider>
);
}
diff --git a/packages/trueforge-ui/src/containers/ToolCallContainer.tsx b/packages/trueforge-ui/src/containers/ToolCallContainer.tsx
index 6ee8660d7..0a5caf749 100644
--- a/packages/trueforge-ui/src/containers/ToolCallContainer.tsx
+++ b/packages/trueforge-ui/src/containers/ToolCallContainer.tsx
@@ -9,7 +9,7 @@ import {
type ToolCallMessagePartProps,
} from '@assistant-ui/react';
import { useTrueFoundryRespondToToolApproval } from '@truefoundry/assistant-ui-runtime';
-import { useState } from 'react';
+import { useCallback, useState } from 'react';
import { useSlot } from '../theme/SlotsProvider.js';
import {
@@ -32,6 +32,7 @@ import {
resolveSubAgentMeta,
toStatus,
} from '../utils/toolCallParsing.js';
+import { useRegisterApprovalExpand } from './approvalFocus.js';
import { AssistantTextContainer } from './AssistantTextContainer.js';
import { NestedApprovalBridgeContext, useNestedApprovalBridge } from './nestedApprovalBridge.js';
import { SandboxToolCallContainer } from './SandboxToolCallContainer.js';
@@ -153,6 +154,8 @@ export const ToolCallContainer: ToolCallMessagePartComponent = part => {
const durationText = elapsedMs === undefined ? undefined : formatDuration(elapsedMs);
const status = toStatus(part.status?.type);
const onToggle = () => setExpanded(prev => !prev);
+ const expandSubAgent = useCallback(() => setExpanded(true), []);
+ useRegisterApprovalExpand(isSubAgent ? part.toolCallId : '', expandSubAgent);
if (part.toolName === ASK_USER_TOOL_NAME) {
if (hasPendingAskUserResponse(part)) {
@@ -232,6 +235,8 @@ export const ToolCallContainer: ToolCallMessagePartComponent = part => {
argsJson={argsJson}
resultText={resultText}
resultJson={resultJson}
+ approvalSlot={showApproval ? <ToolApprovalSlot part={part} /> : undefined}
+ approvalId={showApproval ? part.approval?.id : undefined}
/>
);
}
@@ -257,6 +262,8 @@ export const ToolCallContainer: ToolCallMessagePartComponent = part => {
showResponseLine={status !== 'running' && !!resultDisplay.data}
mcpServerName={mcpServer}
{...slots}
+ approvalSlot={showApproval ? <ToolApprovalSlot part={part} /> : undefined}
+ approvalId={showApproval ? part.approval?.id : undefined}
/>
);
}
@@ -279,6 +286,7 @@ export const ToolCallContainer: ToolCallMessagePartComponent = part => {
mcpServerName={mcpServer}
{...slots}
approvalSlot={showApproval ? <ToolApprovalSlot part={part} /> : undefined}
+ approvalId={showApproval ? part.approval?.id : undefined}
/>
);
}
@@ -300,6 +308,7 @@ export const ToolCallContainer: ToolCallMessagePartComponent = part => {
showResponseLine={status !== 'running' && resultDisplay.data !== undefined}
{...slots}
approvalSlot={showApproval ? <ToolApprovalSlot part={part} /> : undefined}
+ approvalId={showApproval ? part.approval?.id : undefined}
/>
);
};
diff --git a/packages/trueforge-ui/src/containers/approvalFocus.tsx b/packages/trueforge-ui/src/containers/approvalFocus.tsx
new file mode 100644
index 000000000..78cc600a6
--- /dev/null
+++ b/packages/trueforge-ui/src/containers/approvalFocus.tsx
@@ -0,0 +1,155 @@
+'use client';
+
+import { useAuiState } from '@assistant-ui/react';
+import {
+ createContext,
+ useCallback,
+ useContext,
+ useEffect,
+ useMemo,
+ useRef,
+ useState,
+ type ReactNode,
+ type RefObject,
+} from 'react';
+
+import { findSubAgentAncestorsForApproval } from '../utils/findApprovalAncestors.js';
+
+const FLASH_MS = 2000;
+const MOUNT_RETRY_MS = 50;
+const MOUNT_RETRY_MAX = 12;
+
+type ApprovalFocusApi = {
+ registerTarget: (approvalId: string, getElement: () => HTMLElement | null) => () => void;
+ registerExpand: (toolCallId: string, expand: () => void) => () => void;
+ focus: (approvalId: string) => void;
+ flashingApprovalId: string | null;
+};
+
+const ApprovalFocusContext = createContext<ApprovalFocusApi | null>(null);
+
+export function ApprovalFocusProvider({ children }: { children: ReactNode }) {
+ const targetsRef = useRef(new Map<string, () => HTMLElement | null>());
+ const expandsRef = useRef(new Map<string, () => void>());
+ const flashTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
+ const retryTimerRef = useRef<ReturnType<typeof setInterval> | null>(null);
+ const [flashingApprovalId, setFlashingApprovalId] = useState<string | null>(null);
+ const messages = useAuiState(s => s.thread.messages);
+
+ const registerTarget = useCallback((approvalId: string, getElement: () => HTMLElement | null) => {
+ targetsRef.current.set(approvalId, getElement);
+ return () => {
+ if (targetsRef.current.get(approvalId) === getElement) {
+ targetsRef.current.delete(approvalId);
+ }
+ };
+ }, []);
+
+ const registerExpand = useCallback((toolCallId: string, expand: () => void) => {
+ expandsRef.current.set(toolCallId, expand);
+ return () => {
+ if (expandsRef.current.get(toolCallId) === expand) {
+ expandsRef.current.delete(toolCallId);
+ }
+ };
+ }, []);
+
+ const startFlash = useCallback((approvalId: string) => {
+ if (flashTimerRef.current != null) clearTimeout(flashTimerRef.current);
+ setFlashingApprovalId(approvalId);
+ flashTimerRef.current = setTimeout(() => {
+ setFlashingApprovalId(null);
+ flashTimerRef.current = null;
+ }, FLASH_MS);
+ }, []);
+
+ useEffect(
+ () => () => {
+ if (flashTimerRef.current != null) clearTimeout(flashTimerRef.current);
+ if (retryTimerRef.current != null) clearInterval(retryTimerRef.current);
+ },
+ [],
+ );
+
+ const focus = useCallback(
+ (approvalId: string) => {
+ const ancestors = findSubAgentAncestorsForApproval(messages, approvalId);
+
+ if (retryTimerRef.current != null) {
+ clearInterval(retryTimerRef.current);
+ retryTimerRef.current = null;
+ }
+
+ const tryFocus = (): boolean => {
+ for (const toolCallId of ancestors) {
+ expandsRef.current.get(toolCallId)?.();
+ }
+
+ const el = targetsRef.current.get(approvalId)?.() ?? null;
+ if (el == null) return false;
+ el.scrollIntoView?.({ block: 'center', behavior: 'smooth' });
+ startFlash(approvalId);
+ return true;
+ };
+
+ if (tryFocus()) return;
+
+ let attempts = 0;
+ retryTimerRef.current = setInterval(() => {
+ attempts += 1;
+ if (tryFocus() || attempts >= MOUNT_RETRY_MAX) {
+ if (retryTimerRef.current != null) {
+ clearInterval(retryTimerRef.current);
+ retryTimerRef.current = null;
+ }
+ }
+ }, MOUNT_RETRY_MS);
+ },
+ [messages, startFlash],
+ );
+
+ const api = useMemo<ApprovalFocusApi>(
+ () => ({
+ registerTarget,
+ registerExpand,
+ focus,
+ flashingApprovalId,
+ }),
+ [registerTarget, registerExpand, focus, flashingApprovalId],
+ );
+
+ return <ApprovalFocusContext.Provider value={api}>{children}</ApprovalFocusContext.Provider>;
+}
+
+export function useApprovalFocus(): ApprovalFocusApi {
+ const api = useContext(ApprovalFocusContext);
+ if (api == null) {
+ throw new Error('useApprovalFocus requires ApprovalFocusProvider');
+ }
+ return api;
+}
+
+export function useOptionalApprovalFocus(): ApprovalFocusApi | null {
+ return useContext(ApprovalFocusContext);
+}
+
+export function useRegisterApprovalTarget<T extends HTMLElement>(
+ approvalId: string | undefined,
+ elementRef: RefObject<T | null>,
+): void {
+ const api = useOptionalApprovalFocus();
+
+ useEffect(() => {
+ if (api == null || approvalId == null || approvalId === '') return;
+ return api.registerTarget(approvalId, () => elementRef.current);
+ }, [api, approvalId, elementRef]);
+}
+
+export function useRegisterApprovalExpand(toolCallId: string, expand: () => void): void {
+ const api = useOptionalApprovalFocus();
+
+ useEffect(() => {
+ if (api == null || toolCallId === '') return;
+ return api.registerExpand(toolCallId, expand);
+ }, [api, expand, toolCallId]);
+}
diff --git a/packages/trueforge-ui/src/hooks/useApprovalNav.ts b/packages/trueforge-ui/src/hooks/useApprovalNav.ts
new file mode 100644
index 000000000..7d4c2cf20
--- /dev/null
+++ b/packages/trueforge-ui/src/hooks/useApprovalNav.ts
@@ -0,0 +1,80 @@
+'use client';
+
+import { useTrueFoundryApprovals } from '@truefoundry/assistant-ui-runtime';
+import { useCallback, useEffect, useRef, useState } from 'react';
+
+import { useOptionalApprovalFocus } from '../containers/approvalFocus.js';
+
+export type ApprovalNavState = {
+ count: number;
+ /** 0-based index into pending approvals. */
+ index: number;
+ canPrev: boolean;
+ canNext: boolean;
+ goPrev: () => void;
+ goNext: () => void;
+ /** Scroll to the currently selected approval (e.g. after the user scrolled away). */
+ focusCurrent: () => void;
+};
+
+/**
+ * Tracks the focused pending tool approval for the composer banner.
+ * Auto-focuses #1 when approvals appear; after allow/deny, stays on the same
+ * index so the next pending item fills the slot; chevrons do not wrap.
+ */
+export function useApprovalNav(): ApprovalNavState {
+ const { pending } = useTrueFoundryApprovals();
+ const focusApi = useOptionalApprovalFocus();
+ const [selection, setSelection] = useState<{ approvalId: string | null; index: number }>({
+ approvalId: null,
+ index: 0,
+ });
+ const focusedIdRef = useRef<string | null>(null);
+
+ const count = pending.length;
+ const matchedIndex =
+ selection.approvalId == null ? -1 : pending.findIndex(item => item.approvalId === selection.approvalId);
+ const safeIndex = matchedIndex >= 0 ? matchedIndex : count === 0 ? 0 : Math.min(selection.index, count - 1);
+ const currentId = pending[safeIndex]?.approvalId;
+
+ useEffect(() => {
+ const approvalId = currentId ?? null;
+ if (selection.approvalId === approvalId && selection.index === safeIndex) return;
+ setSelection({ approvalId, index: safeIndex });
+ }, [currentId, safeIndex, selection.approvalId, selection.index]);
+
+ useEffect(() => {
+ if (currentId == null || focusApi == null) {
+ if (currentId == null) focusedIdRef.current = null;
+ return;
+ }
+ if (focusedIdRef.current === currentId) return;
+ focusedIdRef.current = currentId;
+ focusApi.focus(currentId);
+ }, [currentId, focusApi]);
+
+ const goPrev = useCallback(() => {
+ const index = Math.max(0, safeIndex - 1);
+ setSelection({ approvalId: pending[index]?.approvalId ?? null, index });
+ }, [pending, safeIndex]);
+
+ const goNext = useCallback(() => {
+ const index = Math.min(Math.max(count - 1, 0), safeIndex + 1);
+ setSelection({ approvalId: pending[index]?.approvalId ?? null, index });
+ }, [count, pending, safeIndex]);
+
+ const focusCurrent = useCallback(() => {
+ if (currentId == null || focusApi == null) return;
+ focusApi.focus(currentId);
+ }, [currentId, focusApi]);
+
+ return {
+ count,
+ index: safeIndex,
+ canPrev: safeIndex > 0,
+ canNext: safeIndex < count - 1,
+ goPrev,
+ goNext,
+ focusCurrent,
+ };
+}
diff --git a/packages/trueforge-ui/src/hooks/useComposerPauseView.ts b/packages/trueforge-ui/src/hooks/useComposerPauseView.ts
index 884533e54..89bb35dd1 100644
--- a/packages/trueforge-ui/src/hooks/useComposerPauseView.ts
+++ b/packages/trueforge-ui/src/hooks/useComposerPauseView.ts
@@ -1,7 +1,7 @@
'use client';
import { useAuiState } from '@assistant-ui/react';
-import { useTrueFoundryToolResponses } from '@truefoundry/assistant-ui-runtime';
+import { useTrueFoundryApprovals, useTrueFoundryToolResponses } from '@truefoundry/assistant-ui-runtime';
import { useOptionalCustomActionRenderers } from '../server/CustomActionRenderersContext.js';
@@ -25,12 +25,17 @@ export function threadHasPendingMcpAuth(s: ThreadPauseState): boolean {
}
export type ComposerPauseView =
- { kind: 'mcp' } | { kind: 'custom'; toolName: string } | { kind: 'ask-user' } | { kind: 'compose' };
+ | { kind: 'mcp' }
+ | { kind: 'custom'; toolName: string }
+ | { kind: 'ask-user' }
+ | { kind: 'approval' }
+ | { kind: 'compose' };
/** Shared composer pause detection for default and custom composer containers. */
export function useComposerPauseView(): ComposerPauseView {
const mcpPending = useAuiState(threadHasPendingMcpAuth);
const { pending: toolResponsesPending } = useTrueFoundryToolResponses();
+ const { pending: approvalsPending } = useTrueFoundryApprovals();
const customActionRenderers = useOptionalCustomActionRenderers();
if (mcpPending) {
@@ -46,5 +51,9 @@ export function useComposerPauseView(): ComposerPauseView {
return { kind: 'ask-user' };
}
+ if (approvalsPending.length > 0) {
+ return { kind: 'approval' };
+ }
+
return { kind: 'compose' };
}
diff --git a/packages/trueforge-ui/src/index.ts b/packages/trueforge-ui/src/index.ts
index f55cc5014..add5b2110 100644
--- a/packages/trueforge-ui/src/index.ts
+++ b/packages/trueforge-ui/src/index.ts
@@ -190,6 +190,7 @@ export { ToolGroupCard } from './atoms/ToolGroupCard.js';
export type { ToolGroupCardProps } from './atoms/ToolGroupCard.js';
export { AgentStepsContainer } from './containers/AgentStepsContainer.js';
export type { AgentStepsContainerProps } from './containers/AgentStepsContainer.js';
+export { ApprovalNavContainer } from './containers/ApprovalNavContainer.js';
export { AskUserContainer } from './containers/AskUserContainer.js';
export { AssistantMessageContainer } from './containers/AssistantMessageContainer.js';
export { AssistantTextContainer } from './containers/AssistantTextContainer.js';
@@ -231,6 +232,8 @@ export { TrueFoundryChatProvider } from './containers/TrueFoundryChatProvider.js
export type { TrueFoundryChatProviderProps } from './containers/TrueFoundryChatProvider.js';
export { UserEditComposerContainer } from './containers/UserEditComposerContainer.js';
export { UserMessageContainer } from './containers/UserMessageContainer.js';
+export { useApprovalNav } from './hooks/useApprovalNav.js';
+export type { ApprovalNavState } from './hooks/useApprovalNav.js';
export { ComposerBusyProvider, useComposerBusyState } from './hooks/useComposerBusyState.js';
export type { ComposerBusyState } from './hooks/useComposerBusyState.js';
export { threadHasPendingMcpAuth, useComposerPauseView } from './hooks/useComposerPauseView.js';
@@ -249,6 +252,7 @@ export {
trueFoundryAttachmentAdapter,
useTrueFoundryAgentRuntime,
useTrueFoundryAgentSpec,
+ useTrueFoundryApprovals,
useTrueFoundryCancel,
useTrueFoundryDownloadSandboxFile,
useTrueFoundryHistoryPagination,
@@ -452,6 +456,7 @@ export type { SessionTurnView } from './utils/sessionTurnViews.js';
// Utils
export { computeAgentStepsSplit } from './utils/computeAgentStepsSplit.js';
export type { AgentStepPart, AgentStepsSplitResult } from './utils/computeAgentStepsSplit.js';
+export { findSubAgentAncestorsForApproval } from './utils/findApprovalAncestors.js';
export { getErrorMessage } from './utils/getErrorMessage.js';
export { AgentSessionsFilters } from './atoms/agent-details/AgentSessionsFilters.js';
@@ -461,6 +466,8 @@ export { AgentsLibrary } from './atoms/AgentsLibrary.js';
export type { AgentsLibraryProps } from './atoms/AgentsLibrary.js';
export { AgentsLibraryButton } from './atoms/AgentsLibraryButton.js';
export type { AgentsLibraryButtonProps } from './atoms/AgentsLibraryButton.js';
+export { ApprovalNavBanner } from './atoms/ApprovalNavBanner.js';
+export type { ApprovalNavBannerProps } from './atoms/ApprovalNavBanner.js';
export { AgentConfigEditors } from './atoms/draft/AgentConfigEditors.js';
export type { AgentConfigEditor, AgentConfigEditorsProps } from './atoms/draft/AgentConfigEditors.js';
export { AgentConfigPanel, AgentConfigSection } from './atoms/draft/AgentConfigPanel.js';
diff --git a/packages/trueforge-ui/src/styles.css b/packages/trueforge-ui/src/styles.css
index 1da04dadc..8f4701f02 100644
--- a/packages/trueforge-ui/src/styles.css
+++ b/packages/trueforge-ui/src/styles.css
@@ -80,6 +80,11 @@
--failure-text: var(--color-white);
--warning-bg: #d97706;
--warning-text: var(--color-white);
+ /* Figma Agents approval banner (light 6747:4232): blue-50 / blue-500 / blue-600 */
+ --approval-banner-bg: #eff6ff;
+ --approval-banner-border: #3b82f6;
+ --approval-banner-fg: #2563eb;
+ --approval-banner-accent: #3b82f6;
--focus-ring: var(--color-black);
--radius: 0.375rem;
--composer-radius: 1.5rem;
@@ -144,6 +149,11 @@
--failure-text: var(--color-white);
--warning-bg: #fbbf24;
--warning-text: #422006;
+ /* Figma Agents approval banner (dark 6748:1977): #202636 / blue-600 top / Base_gray/750 text */
+ --approval-banner-bg: #202636;
+ --approval-banner-border: #2563eb;
+ --approval-banner-fg: #dfdfe2;
+ --approval-banner-accent: #2563eb;
--focus-ring: var(--color-indigo-500);
--overlay: rgb(0 0 0 / 0.7);
--shadow-color: #000000;
@@ -295,6 +305,10 @@
--color-failure-text: var(--failure-text);
--color-warning-bg: var(--warning-bg);
--color-warning-text: var(--warning-text);
+ --color-approval-banner-bg: var(--approval-banner-bg);
+ --color-approval-banner-border: var(--approval-banner-border);
+ --color-approval-banner-fg: var(--approval-banner-fg);
+ --color-approval-banner-accent: var(--approval-banner-accent);
--color-focus-ring: var(--focus-ring);
--color-white: var(--color-white);
--color-black: var(--color-black);
@@ -358,3 +372,30 @@
transform: translateY(100%);
}
}
+
+/* Tool-approval focus flash (composer banner nav). */
+@keyframes aui-approval-flash {
+ 0%,
+ 100% {
+ background-color: transparent;
+ }
+ 15%,
+ 40%,
+ 65% {
+ background-color: color-mix(in srgb, var(--approval-banner-accent) 18%, transparent);
+ }
+}
+
+@media (prefers-reduced-motion: no-preference) {
+ .aui-approval-flash {
+ animation: aui-approval-flash 2s ease-in-out;
+ border-radius: 0.375rem;
+ }
+}
+
+@media (prefers-reduced-motion: reduce) {
+ .aui-approval-flash {
+ background-color: color-mix(in srgb, var(--approval-banner-accent) 18%, transparent);
+ border-radius: 0.375rem;
+ }
+}
diff --git a/packages/trueforge-ui/src/theme/defaultSlots.ts b/packages/trueforge-ui/src/theme/defaultSlots.ts
index b089a1be9..9fe37eb20 100644
--- a/packages/trueforge-ui/src/theme/defaultSlots.ts
+++ b/packages/trueforge-ui/src/theme/defaultSlots.ts
@@ -32,6 +32,7 @@ import type {
} from '../atoms/agent-details/types.js';
import { AgentLibraryRow, AgentsLibrary } from '../atoms/AgentsLibrary.js';
import { AgentsLibraryButton } from '../atoms/AgentsLibraryButton.js';
+import { ApprovalNavBanner } from '../atoms/ApprovalNavBanner.js';
import { AssistantMessageBubble } from '../atoms/AssistantMessageBubble.js';
import { AttachmentCard } from '../atoms/AttachmentCard.js';
import { AttachmentPickerButton } from '../atoms/AttachmentPickerButton.js';
@@ -200,6 +201,7 @@ export const defaultSlots = {
AgentsLibrary,
AgentLibraryRow,
AgentsLibraryButton,
+ ApprovalNavBanner,
SessionsBrowserButton,
AgentDetailsPage,
AgentDetailsHeader,
diff --git a/packages/trueforge-ui/src/utils/findApprovalAncestors.ts b/packages/trueforge-ui/src/utils/findApprovalAncestors.ts
new file mode 100644
index 000000000..721ff12b1
--- /dev/null
+++ b/packages/trueforge-ui/src/utils/findApprovalAncestors.ts
@@ -0,0 +1,64 @@
+import { SUB_AGENT_TOOL_NAME } from './toolCallParsing.js';
+
+type ApprovalRef = {
+ id?: string;
+ approved?: boolean;
+ resolution?: string;
+};
+
+type ToolCallPart = {
+ type: string;
+ toolCallId?: string;
+ toolName?: string;
+ approval?: ApprovalRef;
+ messages?: readonly {
+ role: string;
+ content: readonly ToolCallPart[];
+ }[];
+};
+
+type ThreadMessageLike = {
+ role: string;
+ content: readonly ToolCallPart[];
+};
+
+function isPendingApproval(approval: ApprovalRef | undefined, approvalId: string): boolean {
+ return approval?.id === approvalId && approval.approved === undefined && approval.resolution === undefined;
+}
+
+/**
+ * Returns `create_sub_agent` toolCallIds that must be expanded for `approvalId`
+ * to mount in the DOM. Empty when the approval is on the root thread.
+ */
+export function findSubAgentAncestorsForApproval(messages: readonly ThreadMessageLike[], approvalId: string): string[] {
+ const path: string[] = [];
+
+ function walk(content: readonly ToolCallPart[], ancestors: readonly string[]): boolean {
+ for (const part of content) {
+ if (part.type !== 'tool-call') continue;
+
+ if (isPendingApproval(part.approval, approvalId)) {
+ path.push(...ancestors);
+ return true;
+ }
+
+ const nextAncestors =
+ part.toolName === SUB_AGENT_TOOL_NAME && part.toolCallId != null && part.toolCallId !== ''
+ ? [...ancestors, part.toolCallId]
+ : ancestors;
+
+ if (part.messages == null) continue;
+ for (const message of part.messages) {
+ if (message.role !== 'assistant') continue;
+ if (walk(message.content, nextAncestors)) return true;
+ }
+ }
+ return false;
+ }
+
+ for (const message of messages) {
+ if (message.role !== 'assistant') continue;
+ if (walk(message.content, [])) return path;
+ }
+ return path;
+}
diff --git a/packages/trueforge-ui/src/utils/sessionShareUrl.ts b/packages/trueforge-ui/src/utils/sessionShareUrl.ts
index a1a783015..a217874d0 100644
--- a/packages/trueforge-ui/src/utils/sessionShareUrl.ts
+++ b/packages/trueforge-ui/src/utils/sessionShareUrl.ts
@@ -79,6 +79,7 @@ export function readSessionShareSearch(search: string): SessionShareSearch {
const endTs = parseMs(params.get(SESSION_END_TIME_QUERY));
const timeWindowMs = parseMs(params.get(SESSION_TIME_WINDOW_QUERY));
const view = params.get(SESSIONS_VIEW_QUERY);
+ const now = Date.now();
return {
sessionId: nonEmpty(params.get(SESSION_ID_QUERY)),
agentId: nonEmpty(params.get(AGENT_ID_QUERY)),
@@ -88,7 +89,7 @@ export function readSessionShareSearch(search: string): SessionShareSearch {
startTs != null && endTs != null
? { startTs, endTs }
: timeWindowMs != null
- ? { startTs: Date.now() - timeWindowMs, endTs: Date.now(), timeWindowMs }
+ ? { startTs: now - timeWindowMs, endTs: now, timeWindowMs }
: null,
};
}
diff --git a/packages/trueforge-ui/test/atoms/ApprovalNavBanner.test.tsx b/packages/trueforge-ui/test/atoms/ApprovalNavBanner.test.tsx
new file mode 100644
index 000000000..2bb5f55b7
--- /dev/null
+++ b/packages/trueforge-ui/test/atoms/ApprovalNavBanner.test.tsx
@@ -0,0 +1,100 @@
+// @vitest-environment jsdom
+import { fireEvent, render, screen } from '@testing-library/react';
+import { describe, expect, it, vi } from 'vitest';
+
+import { ApprovalNavBanner } from '@/atoms/ApprovalNavBanner.js';
+
+describe('ApprovalNavBanner', () => {
+ it('renders the count label and disables chevrons at the ends', () => {
+ const onPrev = vi.fn();
+ const onNext = vi.fn();
+ const onFocusCurrent = vi.fn();
+
+ const { rerender } = render(
+ <ApprovalNavBanner
+ total={4}
+ current={1}
+ canPrev={false}
+ canNext
+ onPrev={onPrev}
+ onNext={onNext}
+ onFocusCurrent={onFocusCurrent}
+ />,
+ );
+
+ expect(screen.getByText('4 tools need your input')).toBeTruthy();
+ expect(screen.getByText('(1/4)')).toBeTruthy();
+ expect(screen.getByRole('button', { name: 'Previous approval' })).toBeDisabled();
+ expect(screen.getByRole('button', { name: 'Next approval' })).not.toBeDisabled();
+
+ fireEvent.click(screen.getByRole('button', { name: 'Next approval' }));
+ expect(onNext).toHaveBeenCalledOnce();
+
+ rerender(
+ <ApprovalNavBanner
+ total={4}
+ current={4}
+ canPrev
+ canNext={false}
+ onPrev={onPrev}
+ onNext={onNext}
+ onFocusCurrent={onFocusCurrent}
+ />,
+ );
+ expect(screen.getByRole('button', { name: 'Next approval' })).toBeDisabled();
+ expect(screen.getByRole('button', { name: 'Previous approval' })).not.toBeDisabled();
+ });
+
+ it('uses singular copy for one pending approval', () => {
+ render(
+ <ApprovalNavBanner
+ total={1}
+ current={1}
+ canPrev={false}
+ canNext={false}
+ onPrev={() => {}}
+ onNext={() => {}}
+ onFocusCurrent={() => {}}
+ />,
+ );
+ expect(screen.getByText('1 tool needs your input')).toBeTruthy();
+ });
+
+ it('focuses the current approval when the banner is clicked', () => {
+ const onFocusCurrent = vi.fn();
+ render(
+ <ApprovalNavBanner
+ total={3}
+ current={2}
+ canPrev
+ canNext
+ onPrev={() => {}}
+ onNext={() => {}}
+ onFocusCurrent={onFocusCurrent}
+ />,
+ );
+
+ fireEvent.click(screen.getByRole('status'));
+ expect(onFocusCurrent).toHaveBeenCalledOnce();
+ });
+
+ it('does not focus when chevrons are clicked', () => {
+ const onFocusCurrent = vi.fn();
+ const onNext = vi.fn();
+ render(
+ <ApprovalNavBanner
+ total={3}
+ current={1}
+ canPrev={false}
+ canNext
+ onPrev={() => {}}
+ onNext={onNext}
+ onFocusCurrent={onFocusCurrent}
+ />,
+ );
+
+ fireEvent.click(screen.getByRole('button', { name: 'Next approval' }));
+ expect(onNext).toHaveBeenCalledOnce();
+ expect(onFocusCurrent).not.toHaveBeenCalled();
+ });
+});
diff --git a/packages/trueforge-ui/test/containers/ComposerContainer.test.tsx b/packages/trueforge-ui/test/containers/ComposerContainer.test.tsx
index 791cd7969..dfc603c2f 100644
--- a/packages/trueforge-ui/test/containers/ComposerContainer.test.tsx
+++ b/packages/trueforge-ui/test/containers/ComposerContainer.test.tsx
@@ -22,9 +22,20 @@ const toolResponsesState = vi.hoisted(() => ({
respond: vi.fn(),
}));
+const approvalsState = vi.hoisted(() => ({
+ pending: [] as Array<{
+ approvalId: string;
+ threadId: string;
+ toolName: string;
+ args: Record<string, unknown>;
+ argsText: string;
+ }>,
+}));
+
vi.mock('@truefoundry/assistant-ui-runtime', () => ({
useTrueFoundryCancel: () => vi.fn(),
useTrueFoundryToolResponses: () => toolResponsesState,
+ useTrueFoundryApprovals: () => approvalsState,
useTrueFoundryAgentSpec: () => ({ agentSpec: agentSpecState.agentSpec }),
}));
@@ -59,6 +70,7 @@ describe('ComposerContainer', () => {
agentSpecState.agentSpec = { model: { name: 'test/model' } };
toolResponsesState.pending = [];
toolResponsesState.respond = vi.fn();
+ approvalsState.pending = [];
});
it('wraps the composer in an attachment dropzone by default', () => {
renderComposer();
@@ -191,4 +203,30 @@ describe('ComposerContainer', () => {
content: 'chosen-secret',
});
});
+
+ it('shows the approval banner above a disabled composer while approvals are pending', () => {
+ approvalsState.pending = [
+ {
+ approvalId: 'appr-1',
+ threadId: 'root',
+ toolName: 'call_tool',
+ args: {},
+ argsText: '{}',
+ },
+ {
+ approvalId: 'appr-2',
+ threadId: 'root',
+ toolName: 'call_tool',
+ args: {},
+ argsText: '{}',
+ },
+ ];
+
+ renderComposer();
+
+ expect(screen.getByText('2 tools need your input')).toBeInTheDocument();
+ expect(screen.getByText('(1/2)')).toBeInTheDocument();
+ expect(screen.getByRole('textbox', { name: 'Message input' })).toBeDisabled();
+ expect(document.querySelector('[data-slot="aui_composer-approval-pause"]')).toBeInTheDocument();
+ });
});
diff --git a/packages/trueforge-ui/test/containers/Thread.test.tsx b/packages/trueforge-ui/test/containers/Thread.test.tsx
index ebdd01907..cd93d466c 100644
--- a/packages/trueforge-ui/test/containers/Thread.test.tsx
+++ b/packages/trueforge-ui/test/containers/Thread.test.tsx
@@ -10,6 +10,7 @@ import { RuntimeHarness } from './RuntimeHarness.js';
vi.mock('@truefoundry/assistant-ui-runtime', () => ({
useTrueFoundryCancel: () => vi.fn(),
useTrueFoundryToolResponses: () => ({ pending: [] }),
+ useTrueFoundryApprovals: () => ({ pending: [] }),
useTrueFoundryAgentSpec: () => ({ agentSpec: { model: { name: 'test/model' } } }),
}));
diff --git a/packages/trueforge-ui/test/containers/ToolCallContainer.test.tsx b/packages/trueforge-ui/test/containers/ToolCallContainer.test.tsx
index 090fc91a6..77c31d8c2 100644
--- a/packages/trueforge-ui/test/containers/ToolCallContainer.test.tsx
+++ b/packages/trueforge-ui/test/containers/ToolCallContainer.test.tsx
@@ -317,6 +317,40 @@ describe('ToolCallContainer', () => {
expect(screen.getByRole('button', { name: 'Deny' })).toBeInTheDocument();
});
+ it('shows the approval bar for a pending sandbox call', () => {
+ renderPendingApprovalMessage([
+ {
+ type: 'tool-call',
+ toolCallId: 'sandbox-1',
+ toolName: 'sandbox_exec',
+ args: {},
+ argsText: '{"command":"rm -rf output"}',
+ interrupt: { type: 'human', payload: {} },
+ approval: { id: 'sandbox-approval', approved: undefined },
+ },
+ ]);
+
+ expect(screen.getByRole('button', { name: 'Allow' })).toBeInTheDocument();
+ expect(screen.getByRole('button', { name: 'Deny' })).toBeInTheDocument();
+ });
+
+ it('shows the approval bar for a pending list_tools call', () => {
+ renderPendingApprovalMessage([
+ {
+ type: 'tool-call',
+ toolCallId: 'list-tools-1',
+ toolName: 'list_tools',
+ args: {},
+ argsText: '{"mcp_server":"github-team"}',
+ interrupt: { type: 'human', payload: {} },
+ approval: { id: 'list-tools-approval', approved: undefined },
+ },
+ ]);
+
+ expect(screen.getByRole('button', { name: 'Allow' })).toBeInTheDocument();
+ expect(screen.getByRole('button', { name: 'Deny' })).toBeInTheDocument();
+ });
+
it('calls onRespondToToolApproval when Allow is clicked', () => {
const onRespondToToolApproval = vi.fn();
renderPendingApprovalMessage(
diff --git a/packages/trueforge-ui/test/containers/TrueForgeUI.test.tsx b/packages/trueforge-ui/test/containers/TrueForgeUI.test.tsx
index 35e7cf5b3..6c5b327b2 100644
--- a/packages/trueforge-ui/test/containers/TrueForgeUI.test.tsx
+++ b/packages/trueforge-ui/test/containers/TrueForgeUI.test.tsx
@@ -16,6 +16,7 @@ vi.mock('@truefoundry/assistant-ui-runtime', () => ({
}),
useTrueFoundryCancel: () => vi.fn(),
useTrueFoundryToolResponses: () => ({ pending: [] }),
+ useTrueFoundryApprovals: () => ({ pending: [] }),
useTrueFoundryRespondToToolApproval: () => vi.fn(),
useTrueFoundryMcpAuth: () => ({ pending: [], connect: vi.fn(), continue: vi.fn() }),
useTrueFoundryHistoryPagination: () => ({
diff --git a/packages/trueforge-ui/test/containers/approvalFocus.test.tsx b/packages/trueforge-ui/test/containers/approvalFocus.test.tsx
new file mode 100644
index 000000000..4ca48a285
--- /dev/null
+++ b/packages/trueforge-ui/test/containers/approvalFocus.test.tsx
@@ -0,0 +1,110 @@
+// @vitest-environment jsdom
+import { act, fireEvent, render, screen } from '@testing-library/react';
+import { useRef, useState } from 'react';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+
+const useAuiState = vi.hoisted(() => vi.fn());
+
+vi.mock('@assistant-ui/react', () => ({
+ useAuiState,
+}));
+
+import {
+ ApprovalFocusProvider,
+ useApprovalFocus,
+ useRegisterApprovalExpand,
+ useRegisterApprovalTarget,
+} from '@/containers/approvalFocus.js';
+
+const messages = [
+ {
+ role: 'assistant',
+ content: [
+ {
+ type: 'tool-call',
+ toolCallId: 'sub-outer',
+ toolName: 'create_sub_agent',
+ messages: [
+ {
+ role: 'assistant',
+ content: [
+ {
+ type: 'tool-call',
+ toolCallId: 'sub-inner',
+ toolName: 'create_sub_agent',
+ messages: [
+ {
+ role: 'assistant',
+ content: [
+ {
+ type: 'tool-call',
+ toolCallId: 'tool',
+ toolName: 'call_tool',
+ approval: { id: 'approval' },
+ },
+ ],
+ },
+ ],
+ },
+ ],
+ },
+ ],
+ },
+ ],
+ },
+];
+
+function InnerTarget() {
+ const [expanded, setExpanded] = useState(false);
+ const targetRef = useRef<HTMLDivElement>(null);
+ useRegisterApprovalExpand('sub-inner', () => setExpanded(true));
+ useRegisterApprovalTarget('approval', targetRef);
+
+ return expanded ? <div ref={targetRef}>approval target</div> : null;
+}
+
+function NestedTarget() {
+ const [expanded, setExpanded] = useState(false);
+ useRegisterApprovalExpand('sub-outer', () => setExpanded(true));
+ return expanded ? <InnerTarget /> : null;
+}
+
+function FocusButton() {
+ const { focus } = useApprovalFocus();
+ return <button onClick={() => focus('approval')}>Focus approval</button>;
+}
+
+describe('ApprovalFocusProvider', () => {
+ const scrollIntoView = vi.fn();
+
+ beforeEach(() => {
+ vi.useFakeTimers();
+ vi.clearAllMocks();
+ useAuiState.mockReturnValue(messages);
+ Object.defineProperty(HTMLElement.prototype, 'scrollIntoView', {
+ configurable: true,
+ value: scrollIntoView,
+ });
+ });
+
+ afterEach(() => {
+ vi.useRealTimers();
+ Reflect.deleteProperty(HTMLElement.prototype, 'scrollIntoView');
+ });
+
+ it('expands newly mounted nested ancestors while retrying focus', () => {
+ render(
+ <ApprovalFocusProvider>
+ <FocusButton />
+ <NestedTarget />
+ </ApprovalFocusProvider>,
+ );
+
+ fireEvent.click(screen.getByRole('button', { name: 'Focus approval' }));
+ act(() => vi.advanceTimersByTime(50));
+ act(() => vi.advanceTimersByTime(50));
+
+ expect(screen.getByText('approval target')).toBeInTheDocument();
+ expect(scrollIntoView).toHaveBeenCalledOnce();
+ });
+});
diff --git a/packages/trueforge-ui/test/hooks/useApprovalNav.test.tsx b/packages/trueforge-ui/test/hooks/useApprovalNav.test.tsx
new file mode 100644
index 000000000..a34e02a52
--- /dev/null
+++ b/packages/trueforge-ui/test/hooks/useApprovalNav.test.tsx
@@ -0,0 +1,71 @@
+// @vitest-environment jsdom
+import { act, renderHook } from '@testing-library/react';
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+
+const useApprovals = vi.hoisted(() => vi.fn());
+const focus = vi.hoisted(() => vi.fn());
+
+vi.mock('@truefoundry/assistant-ui-runtime', () => ({
+ useTrueFoundryApprovals: useApprovals,
+}));
+
+vi.mock('@/containers/approvalFocus.js', () => ({
+ useOptionalApprovalFocus: () => ({ focus }),
+}));
+
+import { useApprovalNav } from '@/hooks/useApprovalNav.js';
+
+type PendingApproval = {
+ approvalId: string;
+};
+
+let pending: PendingApproval[];
+
+describe('useApprovalNav', () => {
+ beforeEach(() => {
+ vi.clearAllMocks();
+ pending = [];
+ useApprovals.mockImplementation(() => ({ pending }));
+ });
+
+ it('keeps the selected approval when an earlier approval resolves', () => {
+ pending = [{ approvalId: 'A' }, { approvalId: 'B' }, { approvalId: 'C' }];
+ const { result, rerender } = renderHook(() => useApprovalNav());
+
+ act(() => result.current.goNext());
+ expect(result.current.index).toBe(1);
+ expect(focus).toHaveBeenCalledTimes(2);
+
+ pending = [{ approvalId: 'B' }, { approvalId: 'C' }];
+ rerender();
+
+ expect(result.current.index).toBe(0);
+ expect(focus).toHaveBeenLastCalledWith('B');
+ expect(focus).toHaveBeenCalledTimes(2);
+ });
+
+ it('keeps the same slot when the selected approval resolves', () => {
+ pending = [{ approvalId: 'A' }, { approvalId: 'B' }, { approvalId: 'C' }];
+ const { result, rerender } = renderHook(() => useApprovalNav());
+
+ act(() => result.current.goNext());
+ pending = [{ approvalId: 'A' }, { approvalId: 'C' }];
+ rerender();
+
+ expect(result.current.index).toBe(1);
+ expect(focus).toHaveBeenLastCalledWith('C');
+ });
+
+ it('starts at the first approval and does not wrap', () => {
+ pending = [{ approvalId: 'A' }, { approvalId: 'B' }];
+ const { result } = renderHook(() => useApprovalNav());
+
+ expect(result.current.index).toBe(0);
+ act(() => result.current.goPrev());
+ expect(result.current.index).toBe(0);
+
+ act(() => result.current.goNext());
+ act(() => result.current.goNext());
+ expect(result.current.index).toBe(1);
+ });
+});
diff --git a/packages/trueforge-ui/test/hooks/useComposerPauseView.test.tsx b/packages/trueforge-ui/test/hooks/useComposerPauseView.test.tsx
index cc10eb600..2d520dbf4 100644
--- a/packages/trueforge-ui/test/hooks/useComposerPauseView.test.tsx
+++ b/packages/trueforge-ui/test/hooks/useComposerPauseView.test.tsx
@@ -5,6 +5,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';
const useAuiState = vi.hoisted(() => vi.fn());
const useToolResponses = vi.hoisted(() => vi.fn());
+const useApprovals = vi.hoisted(() => vi.fn());
vi.mock('@assistant-ui/react', () => ({
useAuiState,
@@ -12,6 +13,7 @@ vi.mock('@assistant-ui/react', () => ({
vi.mock('@truefoundry/assistant-ui-runtime', () => ({
useTrueFoundryToolResponses: useToolResponses,
+ useTrueFoundryApprovals: useApprovals,
}));
import { threadHasPendingMcpAuth, type ThreadPauseState, useComposerPauseView } from '@/hooks/useComposerPauseView.js';
@@ -84,6 +86,7 @@ describe('useComposerPauseView', () => {
vi.clearAllMocks();
useAuiState.mockReturnValue(false);
useToolResponses.mockReturnValue({ pending: [] });
+ useApprovals.mockReturnValue({ pending: [] });
});
it('returns the normal composer when no pause source is pending', () => {
@@ -149,4 +152,25 @@ describe('useComposerPauseView', () => {
expect(result.current).toEqual({ kind: 'custom', toolName: 'ask_user_question' });
});
+
+ it('shows the approval pause when tool approvals are pending', () => {
+ useApprovals.mockReturnValue({
+ pending: [{ approvalId: 'appr-1', threadId: 'root', toolName: 'call_tool', args: {}, argsText: '{}' }],
+ });
+
+ const { result } = renderHook(() => useComposerPauseView());
+
+ expect(result.current).toEqual({ kind: 'approval' });
+ });
+
+ it('gives ask-user precedence over pending tool approvals', () => {
+ useToolResponses.mockReturnValue({ pending: [{ toolCallId: 'question-1', toolName: 'ask_user_question' }] });
+ useApprovals.mockReturnValue({
+ pending: [{ approvalId: 'appr-1', threadId: 'root', toolName: 'call_tool', args: {}, argsText: '{}' }],
+ });
+
+ const { result } = renderHook(() => useComposerPauseView());
+
+ expect(result.current).toEqual({ kind: 'ask-user' });
+ });
});
diff --git a/packages/trueforge-ui/test/publicUiExports.test.ts b/packages/trueforge-ui/test/publicUiExports.test.ts
index 4b5c2b884..4cea0c0f5 100644
--- a/packages/trueforge-ui/test/publicUiExports.test.ts
+++ b/packages/trueforge-ui/test/publicUiExports.test.ts
@@ -34,6 +34,8 @@ const expectedRuntimeExports: Array<keyof typeof sdk> = [
'AgentStepsContainer',
'AgentsLibrary',
'AgentsLibraryButton',
+ 'ApprovalNavBanner',
+ 'ApprovalNavContainer',
'AskUserContainer',
'AssistantMessageBubble',
'AssistantMessageContainer',
@@ -160,6 +162,7 @@ const expectedRuntimeExports: Array<keyof typeof sdk> = [
'computeAgentStepsSplit',
'createTrueFoundryServer',
'defaultSlots',
+ 'findSubAgentAncestorsForApproval',
'getErrorMessage',
'isCreateAgentMetadataValue',
'libraryAgentId',
@@ -173,6 +176,7 @@ const expectedRuntimeExports: Array<keyof typeof sdk> = [
'shellIsMutable',
'threadHasPendingMcpAuth',
'trueFoundryAttachmentAdapter',
+ 'useApprovalNav',
'useAgentMetricsServer',
'useAgentSessionsServer',
'useAui',
@@ -205,6 +209,7 @@ const expectedRuntimeExports: Array<keyof typeof sdk> = [
'useThemeMode',
'useTrueFoundryAgentRuntime',
'useTrueFoundryAgentSpec',
+ 'useTrueFoundryApprovals',
'useTrueFoundryCancel',
'useTrueFoundryDownloadSandboxFile',
'useTrueFoundryHistoryPagination',
diff --git a/packages/trueforge-ui/test/routing/withRouter.integration.test.tsx b/packages/trueforge-ui/test/routing/withRouter.integration.test.tsx
index 968067016..588023db8 100644
--- a/packages/trueforge-ui/test/routing/withRouter.integration.test.tsx
+++ b/packages/trueforge-ui/test/routing/withRouter.integration.test.tsx
@@ -38,6 +38,7 @@ vi.mock('@truefoundry/assistant-ui-runtime', () => ({
},
useTrueFoundryCancel: () => vi.fn(),
useTrueFoundryToolResponses: () => ({ pending: [] }),
+ useTrueFoundryApprovals: () => ({ pending: [] }),
useTrueFoundryRespondToToolApproval: () => vi.fn(),
useTrueFoundryMcpAuth: () => ({ pending: [], connect: vi.fn(), continue: vi.fn() }),
useTrueFoundryHistoryPagination: () => ({
diff --git a/packages/trueforge-ui/test/utils/findApprovalAncestors.test.ts b/packages/trueforge-ui/test/utils/findApprovalAncestors.test.ts
new file mode 100644
index 000000000..1892a55f0
--- /dev/null
+++ b/packages/trueforge-ui/test/utils/findApprovalAncestors.test.ts
@@ -0,0 +1,125 @@
+import { describe, expect, it } from 'vitest';
+
+import { findSubAgentAncestorsForApproval } from '@/utils/findApprovalAncestors.js';
+
+describe('findSubAgentAncestorsForApproval', () => {
+ it('returns empty when the approval is on the root thread', () => {
+ const messages = [
+ {
+ role: 'assistant',
+ content: [
+ {
+ type: 'tool-call',
+ toolCallId: 'tc-root',
+ toolName: 'call_tool',
+ approval: { id: 'appr-1' },
+ },
+ ],
+ },
+ ];
+
+ expect(findSubAgentAncestorsForApproval(messages, 'appr-1')).toEqual([]);
+ });
+
+ it('returns the create_sub_agent toolCallId for a nested pending approval', () => {
+ const messages = [
+ {
+ role: 'assistant',
+ content: [
+ {
+ type: 'tool-call',
+ toolCallId: 'sub-1',
+ toolName: 'create_sub_agent',
+ messages: [
+ {
+ role: 'assistant',
+ content: [
+ {
+ type: 'tool-call',
+ toolCallId: 'tc-nested',
+ toolName: 'call_tool',
+ approval: { id: 'appr-nested' },
+ },
+ ],
+ },
+ ],
+ },
+ ],
+ },
+ ];
+
+ expect(findSubAgentAncestorsForApproval(messages, 'appr-nested')).toEqual(['sub-1']);
+ });
+
+ it('returns nested sub-agent ancestors from outermost to innermost', () => {
+ const messages = [
+ {
+ role: 'assistant',
+ content: [
+ {
+ type: 'tool-call',
+ toolCallId: 'sub-outer',
+ toolName: 'create_sub_agent',
+ messages: [
+ {
+ role: 'assistant',
+ content: [
+ {
+ type: 'tool-call',
+ toolCallId: 'sub-inner',
+ toolName: 'create_sub_agent',
+ messages: [
+ {
+ role: 'assistant',
+ content: [
+ {
+ type: 'tool-call',
+ toolCallId: 'tc-nested',
+ toolName: 'call_tool',
+ approval: { id: 'appr-nested' },
+ },
+ ],
+ },
+ ],
+ },
+ ],
+ },
+ ],
+ },
+ ],
+ },
+ ];
+
+ expect(findSubAgentAncestorsForApproval(messages, 'appr-nested')).toEqual(['sub-outer', 'sub-inner']);
+ });
+
+ it('ignores resolved approvals', () => {
+ const messages = [
+ {
+ role: 'assistant',
+ content: [
+ {
+ type: 'tool-call',
+ toolCallId: 'sub-1',
+ toolName: 'create_sub_agent',
+ messages: [
+ {
+ role: 'assistant',
+ content: [
+ {
+ type: 'tool-call',
+ toolCallId: 'tc-nested',
+ toolName: 'call_tool',
+ approval: { id: 'appr-nested', approved: true },
+ },
+ ],
+ },
+ ],
+ },
+ ],
+ },
+ ];
+
+ expect(findSubAgentAncestorsForApproval(messages, 'appr-nested')).toEqual([]);
+ });
+});
diff --git a/packages/trueforge/src/runtime/sandboxFilePath.ts b/packages/trueforge/src/runtime/sandboxFilePath.ts
index 5db75bc61..e502e15d5 100644
--- a/packages/trueforge/src/runtime/sandboxFilePath.ts
+++ b/packages/trueforge/src/runtime/sandboxFilePath.ts
@@ -26,9 +26,6 @@ const MAX_SEGMENT_BYTES = 255;
* indistinguishable from a real outage.
*/
export function validateSandboxFilePath(path: string): void {
- if (!path.startsWith('/')) {
- throw new SandboxInvalidPathError({ path, reason: 'must be absolute' });
- }
if (path.includes('\0')) {
throw new SandboxInvalidPathError({ path, reason: 'must not contain a NUL byte' });
}
diff --git a/packages/trueforge/src/schemas/turn.ts b/packages/trueforge/src/schemas/turn.ts
index 6071fe053..e771902f1 100644
--- a/packages/trueforge/src/schemas/turn.ts
+++ b/packages/trueforge/src/schemas/turn.ts
@@ -95,7 +95,7 @@ export const DownloadSandboxFileRequestQuerySchema = z
.string()
.min(1)
.describe(
- "Absolute path of the file inside the sandbox, as listed in the assistant's `sandbox_artifacts` block.",
+ "Absolute or sandbox-working-directory-relative file path, as listed in the assistant's `sandbox_artifacts` block.",
),
})
.openapi('DownloadSandboxFileRequestQuery');
diff --git a/packages/trueforge/tests/unit/apis/sandboxFileDownload.test.ts b/packages/trueforge/tests/unit/apis/sandboxFileDownload.test.ts
index 1ee5a0953..5543c9074 100644
--- a/packages/trueforge/tests/unit/apis/sandboxFileDownload.test.ts
+++ b/packages/trueforge/tests/unit/apis/sandboxFileDownload.test.ts
@@ -77,7 +77,7 @@ describe('GET /{session_id}/turns/{turn_id}/download-sandbox-file', () => {
const { app } = await buildApp();
for (const path of [
- 'report.pdf',
+ '../etc/passwd',
'/a/../../etc/passwd',
'/tmp/nul\0.txt',
`/tmp/${'a'.repeat(300)}`,
@@ -89,6 +89,14 @@ describe('GET /{session_id}/turns/{turn_id}/download-sandbox-file', () => {
}
});
+ it('accepts a path relative to the sandbox working directory', async () => {
+ const { app } = await buildApp();
+
+ const response = await app.request(downloadUrl({ sessionId: 'missing', path: 'report.pdf' }));
+
+ expect(response.status).toBe(404);
+ });
+
// PATH_MAX counts the terminating NUL, so 4096 is already too long for the kernel and must be
// rejected here rather than reaching the provider as an opaque backend failure.
it('rejects a path at PATH_MAX but allows one byte shorter', async () => {