Skip to content

Commit 47a19c1

Browse files
committed
fix(approvals): every harness and client labels approvals the same way
1 parent 9246839 commit 47a19c1

5 files changed

Lines changed: 33 additions & 19 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { RequestActionButton } from "./RequestActionButton";
2+
import { approvalRequestLabel } from "@t3tools/client-runtime/state/thread-requests";
23
import { approvalCommandDisplayText } from "@t3tools/client-runtime/work-log/command-label";
34
import type {
45
ProviderApprovalDecision,
@@ -38,7 +39,7 @@ export function PendingApprovalCard(props: PendingApprovalCardProps) {
3839
Approval needed
3940
</Text>
4041
<Text className="font-t3-bold text-lg text-foreground">
41-
{props.approval.appName ?? props.approval.requestKind}
42+
{props.approval.appName ?? approvalRequestLabel(props.approval.requestKind)}
4243
</Text>
4344
{props.approval.title && !props.approval.appName ? (
4445
<Text className="font-sans text-sm leading-normal text-foreground-secondary">

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { approvalRequestLabel } from "@t3tools/client-runtime/state/thread-requests";
12
import { approvalCommandDisplayText } from "@t3tools/client-runtime/work-log/command-label";
23
import { memo } from "react";
34
import { type PendingApproval } from "../../session-logic";
@@ -15,16 +16,7 @@ export const ComposerPendingApprovalPanel = memo(function ComposerPendingApprova
1516
className,
1617
}: ComposerPendingApprovalPanelProps) {
1718
const Detail = approval.requestKind === "mcp-elicitation" ? "span" : "code";
18-
const fallbackLabel =
19-
approval.requestKind === "mcp-elicitation"
20-
? "App access approval"
21-
: approval.requestKind === "command"
22-
? "Command approval"
23-
: approval.requestKind === "file-read"
24-
? "File read approval"
25-
: approval.requestKind === "permission"
26-
? "App permission approval"
27-
: "File change approval";
19+
const fallbackLabel = approvalRequestLabel(approval.requestKind);
2820
const detailAriaLabel =
2921
approval.requestKind === "mcp-elicitation"
3022
? "App access request"

‎packages/client-runtime/src/state/threadRequests.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@ import type {
88
} from "@t3tools/contracts";
99
import * as DateTime from "effect/DateTime";
1010

11+
const APPROVAL_REQUEST_LABELS: Record<ProviderRequestKind, string> = {
12+
command: "Command approval",
13+
"file-read": "File read approval",
14+
"file-change": "File change approval",
15+
"mcp-elicitation": "App access approval",
16+
permission: "App permission approval",
17+
};
18+
19+
/** Names an approval card by what it asks for; web and mobile show the same words. */
20+
export function approvalRequestLabel(requestKind: ProviderRequestKind): string {
21+
return APPROVAL_REQUEST_LABELS[requestKind];
22+
}
23+
1124
export interface ThreadPendingApproval {
1225
readonly requestId: RuntimeRequestId;
1326
readonly requestKind: ProviderRequestKind;

‎packages/provider-opencode/src/server/adapter.ts‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1783,19 +1783,23 @@ export const makeOpenCodeAdapterV2 = Effect.fn("makeOpenCodeAdapterV2")(function
17831783
throw protocolError(`OpenCode request ${pending.requestId} has no native payload`);
17841784
}
17851785
// Patterns split a pipeline into its commands; the command keeps it whole.
1786-
const command = permission.metadata.command;
1786+
const command =
1787+
typeof permission.metadata.command === "string" &&
1788+
permission.metadata.command.trim().length > 0
1789+
? permission.metadata.command
1790+
: undefined;
17871791
return {
17881792
...base,
1789-
title: permission.permission,
1793+
// A title explains a request; "bash" beside its own command explains nothing.
1794+
title: command === undefined ? permission.permission : null,
17901795
type: "approval_request",
17911796
requestId: pending.requestId,
17921797
requestKind: pending.requestKind === "user_input" ? "command" : pending.requestKind,
17931798
prompt:
1794-
typeof command === "string" && command.trim().length > 0
1795-
? command
1796-
: permission.patterns.length === 0
1797-
? permission.permission
1798-
: permission.patterns.join("\n"),
1799+
command ??
1800+
(permission.patterns.length === 0
1801+
? permission.permission
1802+
: permission.patterns.join("\n")),
17991803
};
18001804
};
18011805

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,10 @@ interface PendingPiPrompt {
398398
readonly turnItem: OrchestrationV2TurnItem;
399399
}
400400

401+
const PI_TOOL_GATE_TITLE = /^Allow (\S+)\?$/;
402+
401403
function piApprovalRequestKind(title: string): "command" | "file-change" {
402-
const toolName = /^Allow (\S+)\?$/.exec(title)?.[1];
404+
const toolName = PI_TOOL_GATE_TITLE.exec(title)?.[1];
403405
return toolName !== undefined &&
404406
(PI_FILE_CHANGE_TOOLS as ReadonlyArray<string>).includes(toolName)
405407
? "file-change"
@@ -1324,6 +1326,8 @@ export const makePiAdapterV2 = Effect.fn("makePiAdapterV2")(function* (
13241326
method === "confirm"
13251327
? {
13261328
...itemBase,
1329+
// The tool gate's "Allow bash?" restates the card; other confirms keep their question.
1330+
title: PI_TOOL_GATE_TITLE.test(title) ? null : title,
13271331
type: "approval_request",
13281332
requestId,
13291333
requestKind: piApprovalRequestKind(title),

0 commit comments

Comments
 (0)