Skip to content

Commit 9417b48

Browse files
committed
fix(approvals): keep shell options, pi tool args, and codex reasons visible
1 parent aaa6b49 commit 9417b48

7 files changed

Lines changed: 49 additions & 12 deletions

File tree

‎apps/mobile/src/features/threads/PendingApprovalCard.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { RequestActionButton } from "./RequestActionButton";
2-
import { commandDisplayText } from "@t3tools/client-runtime/work-log/command-label";
2+
import { approvalCommandDisplayText } from "@t3tools/client-runtime/work-log/command-label";
33
import type {
44
ProviderApprovalDecision,
55
ProviderApprovalOption,
@@ -50,7 +50,7 @@ export function PendingApprovalCard(props: PendingApprovalCardProps) {
5050
{props.approval.detail ? (
5151
props.approval.requestKind === "command" ? (
5252
<Text className="font-mono text-sm leading-normal text-foreground" selectable>
53-
{commandDisplayText(props.approval.detail)}
53+
{approvalCommandDisplayText(props.approval.detail)}
5454
</Text>
5555
) : (
5656
<Text className="font-sans text-sm leading-normal text-foreground-secondary">

‎apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5163,8 +5163,10 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
51635163
nativeItemId: payload.itemId,
51645164
nativeRequestId,
51655165
requestKind: "command",
5166-
...(payload.command === undefined ? {} : { prompt: payload.command }),
5167-
title: payload.reason,
5166+
// Without a command, the reason is all there is to show.
5167+
...(payload.command
5168+
? { prompt: payload.command, title: payload.reason }
5169+
: { prompt: payload.reason ?? null }),
51685170
});
51695171
const decision = yield* Deferred.make<ProviderApprovalDecision, never>();
51705172
yield* Ref.update(pendingRuntimeRequests, (current) => {

‎apps/web/src/components/chat/ComposerPendingApprovalPanel.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { commandDisplayText } from "@t3tools/client-runtime/work-log/command-label";
1+
import { approvalCommandDisplayText } from "@t3tools/client-runtime/work-log/command-label";
22
import { memo } from "react";
33
import { type PendingApproval } from "../../session-logic";
44
import { cn } from "~/lib/utils";
@@ -66,7 +66,7 @@ export const ComposerPendingApprovalPanel = memo(function ComposerPendingApprova
6666
? "Provider process is gone — interrupt or restart the run to respond."
6767
: approval.detail
6868
? approval.requestKind === "command"
69-
? commandDisplayText(approval.detail)
69+
? approvalCommandDisplayText(approval.detail)
7070
: approval.detail
7171
: fallbackLabel}
7272
</Detail>

‎apps/web/src/session-logic.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
} from "@t3tools/shared/toolActivity";
2525
import type { HtmlRenderReference } from "@t3tools/shared/htmlRender";
2626
import { turnItemDetailRevision } from "@t3tools/client-runtime/work-log/item-detail";
27-
import { commandDisplayText } from "@t3tools/client-runtime/work-log/command-label";
27+
import { approvalCommandDisplayText } from "@t3tools/client-runtime/work-log/command-label";
2828
import type { McpAppReference } from "@t3tools/shared/mcpApp";
2929
import { htmlRenderFromToolItem, mcpAppFromToolItem } from "@t3tools/shared/toolOutput";
3030
import {
@@ -551,7 +551,7 @@ function projectedWorkEntry(row: OrchestrationV2ProjectedTurnItem): WorkLogEntry
551551
label: title ?? "Approval requested",
552552
detail: item.prompt
553553
? item.requestKind === "command"
554-
? commandDisplayText(item.prompt)
554+
? approvalCommandDisplayText(item.prompt)
555555
: item.prompt
556556
: item.requestKind,
557557
toolData: item,

‎packages/client-runtime/src/work-log/commandLabel.test.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { describe, expect, it } from "vite-plus/test";
22

33
import {
4+
approvalCommandDisplayText,
45
commandDisplayText,
56
commandHighlightLanguage,
67
commandProgramName,
@@ -498,6 +499,21 @@ describe("commandDisplayText", () => {
498499
});
499500
});
500501

502+
describe("approvalCommandDisplayText", () => {
503+
it.each([
504+
[
505+
"/bin/bash -lc 'curl -sI https://example.com | head -n 1'",
506+
"curl -sI https://example.com | head -n 1",
507+
],
508+
["bash --rcfile /tmp/init.sh -ic 'git status'", "bash --rcfile /tmp/init.sh -ic 'git status'"],
509+
["zsh -lc 'echo $1' name value", "zsh -lc 'echo $1' name value"],
510+
["zsh -lc 'pwd'; rm -rf build", "zsh -lc 'pwd'; rm -rf build"],
511+
["git status", "git status"],
512+
])("unwraps only a bare shell wrapper: %s", (input, expected) => {
513+
expect(approvalCommandDisplayText(input)).toBe(expected);
514+
});
515+
});
516+
501517
describe("commands recorded from each provider", () => {
502518
// Inputs are copied from the recorded replay transcripts in
503519
// apps/server/src/orchestration-v2/testkit/fixtures (turn_interrupt_mid_tool,

‎packages/client-runtime/src/work-log/commandLabel.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,6 +1382,23 @@ export function commandDisplayText(command: string): string {
13821382
return withVisibleControlCharacters(withoutShellWrapper(command));
13831383
}
13841384

1385+
/**
1386+
* The command an approval asks about. Only a bare `<shell> -c` or `-lc`
1387+
* wrapper is removed, so no shell option that changes what runs is hidden.
1388+
*/
1389+
export function approvalCommandDisplayText(command: string): string {
1390+
const trimmed = command.trim();
1391+
const tokens = tokenizeShellCommand(trimmed);
1392+
const program = tokens?.[0]?.split(/[\\/]/u).at(-1);
1393+
const bare =
1394+
tokens?.length === 3 &&
1395+
program !== undefined &&
1396+
SHELL_PROGRAMS.has(program) &&
1397+
/^-l?c$/u.test(tokens[1]!) &&
1398+
splitFirstShellCommand(trimmed).remainingCommand === null;
1399+
return withVisibleControlCharacters(bare ? tokens[2]!.trim() || trimmed : trimmed);
1400+
}
1401+
13851402
/** Replaces each control character with its control picture; the length does not change. */
13861403
export function withVisibleControlCharacters(text: string): string {
13871404
return text.replace(CONTROL_CHARACTERS, (character) =>

‎packages/provider-pi/src/server/mcpExtensionSource.ts‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,12 @@ function runtimeMode(): RuntimeMode {
7272
: "full-access";
7373
}
7474
75-
function toolInputSummary(input: unknown): string {
76-
// A shell tool's approval shows the command itself, not its JSON arguments.
75+
function toolInputSummary(toolName: string, input: unknown): string {
76+
// The bash tool's approval shows the command itself, not its JSON arguments.
7777
const command = (input as { command?: unknown } | null)?.command;
78-
if (typeof command === "string" && command.trim().length > 0) return command.slice(0, 4_000);
78+
if (toolName === "bash" && typeof command === "string" && command.trim().length > 0) {
79+
return command.slice(0, 4_000);
80+
}
7981
try {
8082
return JSON.stringify(input, null, 2).slice(0, 4_000);
8183
} catch {
@@ -335,7 +337,7 @@ export default async function t3McpExtension(pi: ExtensionAPI) {
335337
}
336338
const approved = await ctx.ui.confirm(
337339
\`Allow \${event.toolName}?\`,
338-
toolInputSummary(event.input),
340+
toolInputSummary(event.toolName, event.input),
339341
{ signal: ctx.signal },
340342
);
341343
if (!approved) {

0 commit comments

Comments
 (0)