Skip to content

Commit 7c85ff7

Browse files
danddanddandclaude
andcommitted
fix(composer): label paste thresholds by size and keep settings decodable
Review follow-ups for the large paste threshold setting: - Label presets as sizes with approximate character counts ("5 KB (~5,000 chars)"). The threshold also counts UTF-8 bytes, so non-Latin text and emoji fold with fewer characters; the settings copy and user docs now say so. - Fall back to the default when a stored threshold is not a current preset, so changing the presets later cannot fail the whole client settings decode. - Select only the threshold from mobile preferences so unrelated preference writes do not re-render the native composer editors. - Cover the 1 KB byte boundary, the labels, the decode fallback, and restore defaults in tests. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 77d9e19 commit 7c85ff7

9 files changed

Lines changed: 80 additions & 30 deletions

File tree

‎apps/mobile/src/features/settings/SettingsLargePastesRouteScreen.tsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ScreenScrollView as ScrollView } from "../../components/ui/ScreenScrollView";
22
import { useAtomSet, useAtomValue } from "@effect/atom-react";
33
import { useNavigation } from "@react-navigation/native";
4+
import { pastedTextThresholdLabel } from "@t3tools/client-runtime/text-paste";
45
import {
56
DEFAULT_PASTED_TEXT_ATTACHMENT_THRESHOLD,
67
type PastedTextAttachmentThreshold,
@@ -57,7 +58,7 @@ export function SettingsLargePastesRouteScreen() {
5758
{THRESHOLD_OPTIONS.map(({ threshold, description }, index) => (
5859
<SettingsChoiceRow
5960
key={threshold}
60-
label={`${threshold.toLocaleString()} characters`}
61+
label={pastedTextThresholdLabel(threshold)}
6162
description={description}
6263
selected={selectedThreshold === threshold}
6364
separated={index > 0}
@@ -67,7 +68,8 @@ export function SettingsLargePastesRouteScreen() {
6768
))}
6869
</SettingsSection>
6970
<Text className="px-2 text-sm text-foreground-muted">
70-
Shorter pastes go into the message as text. With a hardware keyboard, press{" "}
71+
Sizes count bytes, so non-Latin text and emoji become files with fewer characters. Shorter
72+
pastes go into the message as text. With a hardware keyboard, press{" "}
7173
{PASTE_AS_TEXT_SHORTCUT} to paste a long block as text instead.
7274
</Text>
7375
</ScrollView>
Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
import { useAtomValue } from "@effect/atom-react";
2-
import {
3-
DEFAULT_PASTED_TEXT_ATTACHMENT_THRESHOLD,
4-
type PastedTextAttachmentThreshold,
5-
} from "@t3tools/contracts";
2+
import { DEFAULT_PASTED_TEXT_ATTACHMENT_THRESHOLD } from "@t3tools/contracts";
63
import { AsyncResult } from "effect/reactivity";
74

85
import { mobilePreferencesAtom } from "../state/preferences";
96

10-
/** Paste size at which the composer folds clipboard text into a text-file attachment. */
11-
export function usePastedTextAttachmentThreshold(): PastedTextAttachmentThreshold {
12-
const preferences = useAtomValue(mobilePreferencesAtom);
13-
return AsyncResult.isSuccess(preferences)
14-
? (preferences.value.pastedTextAttachmentThreshold ?? DEFAULT_PASTED_TEXT_ATTACHMENT_THRESHOLD)
15-
: DEFAULT_PASTED_TEXT_ATTACHMENT_THRESHOLD;
7+
/**
8+
* Paste size at which the composer folds clipboard text into a text-file
9+
* attachment. Selects only the threshold so unrelated preference writes do not
10+
* re-render the composer editors.
11+
*/
12+
export function usePastedTextAttachmentThreshold() {
13+
return useAtomValue(mobilePreferencesAtom, (preferences) =>
14+
AsyncResult.isSuccess(preferences)
15+
? (preferences.value.pastedTextAttachmentThreshold ??
16+
DEFAULT_PASTED_TEXT_ATTACHMENT_THRESHOLD)
17+
: DEFAULT_PASTED_TEXT_ATTACHMENT_THRESHOLD,
18+
);
1619
}

‎apps/web/src/components/settings/SettingsPanels.restore.browser.test.tsx‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,12 @@ const render = () => act(async () => root.render(<Probe />));
6464

6565
describe("restoring V2 settings", () => {
6666
it.each([
67-
["persistComposerContextStrip", "Composer context"],
68-
["autoResumeLimitedThreads", "Auto-resume limited threads"],
69-
["snoozeLimitedThreads", "Snooze limited threads"],
70-
] as const)("restores %s when it is the only changed setting", async (key, label) => {
71-
state.settings = { ...DEFAULT_UNIFIED_SETTINGS, [key]: true };
67+
["persistComposerContextStrip", true, "Composer context"],
68+
["autoResumeLimitedThreads", true, "Auto-resume limited threads"],
69+
["snoozeLimitedThreads", true, "Snooze limited threads"],
70+
["pastedTextAttachmentThreshold", 1_000, "Large paste threshold"],
71+
] as const)("restores %s when it is the only changed setting", async (key, value, label) => {
72+
state.settings = { ...DEFAULT_UNIFIED_SETTINGS, [key]: value };
7273
await render();
7374

7475
expect(restore.changedSettingLabels).toEqual([label]);

‎apps/web/src/components/settings/SettingsPanels.tsx‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
} from "@t3tools/contracts";
1919
import { scopeThreadRef } from "@t3tools/client-runtime/environment";
2020
import { presentThreadShell } from "@t3tools/client-runtime/state/shell";
21+
import { pastedTextThresholdLabel } from "@t3tools/client-runtime/text-paste";
2122
import {
2223
isAtomCommandInterrupted,
2324
settlePromise,
@@ -257,8 +258,8 @@ const BACKGROUND_ACTIVITY_BOOLEAN_OVERRIDES: ReadonlyArray<{
257258
{ key: "pauseWhenOnBattery", label: "Pause on battery" },
258259
];
259260

260-
function pastedTextThresholdLabel(threshold: PastedTextAttachmentThreshold) {
261-
const label = `${threshold.toLocaleString()} characters`;
261+
function pastedTextThresholdOptionLabel(threshold: PastedTextAttachmentThreshold) {
262+
const label = pastedTextThresholdLabel(threshold);
262263
return threshold === DEFAULT_UNIFIED_SETTINGS.pastedTextAttachmentThreshold
263264
? `${label} (default)`
264265
: label;
@@ -2746,7 +2747,7 @@ export function GeneralSettingsPanel() {
27462747

27472748
<SettingsRow
27482749
{...searchableSetting("large-paste-threshold")}
2749-
description={`Pastes this long or longer become a text file attachment. Press ${modifierLabel} + Shift + V to paste inline instead.`}
2750+
description={`Pastes this size or larger become a text file attachment. Non-Latin text and emoji use more bytes per character, so they reach it sooner. Press ${modifierLabel} + Shift + V to paste inline instead.`}
27502751
resetAction={
27512752
settings.pastedTextAttachmentThreshold !==
27522753
DEFAULT_UNIFIED_SETTINGS.pastedTextAttachmentThreshold ? (
@@ -2777,14 +2778,14 @@ export function GeneralSettingsPanel() {
27772778
aria-label="Large paste threshold"
27782779
>
27792780
<SelectValue>
2780-
{pastedTextThresholdLabel(settings.pastedTextAttachmentThreshold)}
2781+
{pastedTextThresholdOptionLabel(settings.pastedTextAttachmentThreshold)}
27812782
</SelectValue>
27822783
</SelectTrigger>
27832784
<SelectPopup align="end" alignItemWithTrigger={false}>
27842785
{PASTED_TEXT_ATTACHMENT_THRESHOLDS.map((threshold) => (
27852786
<SelectItem key={threshold} value={String(threshold)}>
27862787
<span className="flex items-center justify-between gap-4">
2787-
{pastedTextThresholdLabel(threshold)}
2788+
{pastedTextThresholdOptionLabel(threshold)}
27882789
{settings.pastedTextAttachmentThreshold === threshold && (
27892790
<CheckIcon aria-hidden="true" />
27902791
)}

‎docs/user/composer.md‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ include a skill when the task needs more context.
66
Messages can contain up to 120,000 characters. Longer drafts stay in the composer
77
so you can shorten them or split them into several messages.
88

9-
Pasting 32 KiB or more of text adds that fragment as a text-file attachment so
10-
the agent can inspect it without filling the model context. To fold shorter
11-
pastes, choose 1,000 or 5,000 characters under **Settings → General → Large paste
12-
threshold** on web and desktop, or **Settings → Large pastes** on mobile. A smaller
13-
paste also becomes an attachment when inserting it would exceed the message limit.
14-
On a hardware keyboard, use `Cmd+Shift+V` on Apple devices or `Ctrl+Shift+V`
15-
elsewhere to keep a large paste editable in the composer instead.
9+
Pasting 32 KB (about 32,000 characters) or more of text adds that fragment as a
10+
text-file attachment so the agent can inspect it without filling the model
11+
context. To turn shorter pastes into attachments, choose 1 KB or 5 KB under
12+
**Settings → General → Large paste threshold** on web and desktop, or **Settings
13+
→ Large pastes** on mobile. Sizes count bytes, so non-Latin text and emoji reach
14+
them with fewer characters. A smaller paste also becomes an attachment when
15+
inserting it would exceed the message limit. On a hardware keyboard, use
16+
`Cmd+Shift+V` on Apple devices or `Ctrl+Shift+V` elsewhere to keep a large paste
17+
editable in the composer instead.
1618

1719
## Formatting
1820

‎packages/client-runtime/src/textPaste.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
nextPastedTextFileName,
99
isPasteAsTextShortcut,
1010
pastedTextDisposition,
11+
pastedTextThresholdLabel,
1112
replaceTextSelection,
1213
wouldTextPasteExceedLimit,
1314
} from "./textPaste.ts";
@@ -47,6 +48,14 @@ describe("pasted text disposition", () => {
4748
}
4849
});
4950

51+
it("counts bytes at the 1 KB preset, so non-Latin text folds with fewer characters", () => {
52+
const text = "日本語".repeat(120);
53+
expect(text.length).toBeLessThan(1_000);
54+
expect(pastedTextDisposition({ text, canAttach: true, thresholdBytes: 1_000 })).toBe(
55+
"attachment",
56+
);
57+
});
58+
5059
it("measures UTF-8 bytes instead of UTF-16 characters", () => {
5160
const text = "🙂".repeat(thresholdBytes / 4);
5261
expect(text.length).toBeLessThan(thresholdBytes);
@@ -73,6 +82,16 @@ describe("pasted text disposition", () => {
7382
});
7483
});
7584

85+
describe("pasted text threshold labels", () => {
86+
it("leads with the size and approximates the character count", () => {
87+
expect(PASTED_TEXT_ATTACHMENT_THRESHOLDS.map(pastedTextThresholdLabel)).toEqual([
88+
"1 KB (~1,000 chars)",
89+
"5 KB (~5,000 chars)",
90+
"32 KB (~32,000 chars)",
91+
]);
92+
});
93+
});
94+
7695
describe("pasted text attachment names", () => {
7796
it("uses the first available readable sequence", () => {
7897
expect(nextPastedTextFileName([])).toBe("pasted-text.txt");

‎packages/client-runtime/src/textPaste.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ export function pastedTextDisposition(input: {
3636
: "inline";
3737
}
3838

39+
/**
40+
* Settings label for a `pastedTextAttachmentThreshold` preset, such as
41+
* "5 KB (~5,000 chars)". Sizes come first because the threshold also counts
42+
* UTF-8 bytes, so non-Latin text and emoji fold with fewer characters.
43+
*/
44+
export function pastedTextThresholdLabel(thresholdBytes: number) {
45+
const kilobytes = Math.floor(thresholdBytes / 1000);
46+
return `${kilobytes} KB (~${(kilobytes * 1000).toLocaleString("en-US")} chars)`;
47+
}
48+
3949
export function nextPastedTextFileName(existingNames: ReadonlyArray<string>): string {
4050
const names = new Set(existingNames.map((name) => name.toLowerCase()));
4151
if (!names.has("pasted-text.txt")) {

‎packages/contracts/src/settings.test.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,18 @@ describe("ClientSettings large paste threshold", () => {
160160
expect(encodeClientSettings(decodeClientSettings(preference))).toMatchObject(preference);
161161
});
162162

163-
it("rejects thresholds outside the presets", () => {
163+
it("rejects thresholds outside the presets in patches", () => {
164164
expect(() => decodeClientSettingsPatch({ pastedTextAttachmentThreshold: 2_000 })).toThrow();
165165
});
166+
167+
it("falls back to the default for a stored preset this build no longer offers", () => {
168+
const settings = decodeClientSettings({
169+
pastedTextAttachmentThreshold: 4_000,
170+
sendShortcut: "mod-enter",
171+
});
172+
expect(settings.pastedTextAttachmentThreshold).toBe(32_768);
173+
expect(settings.sendShortcut).toBe("mod-enter");
174+
});
166175
});
167176

168177
describe("ClientSettings rich text composer", () => {

‎packages/contracts/src/settings.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,10 @@ export const ClientSettingsSchema = Schema.Struct({
444444
contextWindowMeterEnabled: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
445445
composerCollapseOnScroll: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
446446
composerRichTextEnabled: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
447+
// A stored preset this build no longer offers falls back to the default
448+
// instead of failing the whole settings decode.
447449
pastedTextAttachmentThreshold: PastedTextAttachmentThreshold.pipe(
450+
Schema.catchDecoding(() => Effect.succeedSome(DEFAULT_PASTED_TEXT_ATTACHMENT_THRESHOLD)),
448451
Schema.withDecodingDefault(Effect.succeed(DEFAULT_PASTED_TEXT_ATTACHMENT_THRESHOLD)),
449452
),
450453
sendShortcut: Schema.Literals(["enter", "mod-enter-multiline", "mod-enter"]).pipe(

0 commit comments

Comments
 (0)