From caef8c3847be4580aa035279e5a7f86e89e458a5 Mon Sep 17 00:00:00 2001 From: Marker-bit <63698566+Marker-bit@users.noreply.github.com> Date: Mon, 16 Nov 2026 20:43:10 +0300 Subject: [PATCH 1/2] fix(composer): show local command actions while running (#32912) Co-authored-by: maria-rcks Co-authored-by: Julius Marminge Co-authored-by: Marker-bit --- .../src/features/threads/ThreadComposer.tsx | 43 ++++++++++++------- apps/mobile/src/lib/composerContext.test.ts | 2 +- apps/mobile/src/lib/composerContext.ts | 4 +- apps/web/src/components/chat/ChatComposer.tsx | 24 ++++++++--- .../src/state/composerDispatch.test.ts | 26 ++++++++++- .../src/state/composerDispatch.ts | 23 ++++++++++ 6 files changed, 97 insertions(+), 25 deletions(-) diff --git a/apps/mobile/src/features/threads/ThreadComposer.tsx b/apps/mobile/src/features/threads/ThreadComposer.tsx index 27551a83afa41..3894ab61a4af3 100644 --- a/apps/mobile/src/features/threads/ThreadComposer.tsx +++ b/apps/mobile/src/features/threads/ThreadComposer.tsx @@ -30,7 +30,6 @@ import { hasProviderUsageLimits, isUsageLimitsCommand, } from "@t3tools/shared/usageLimits"; -import { parseSideChatCommand } from "@t3tools/shared/composerTrigger"; import { StackActions, useFocusEffect, useNavigation } from "@react-navigation/native"; import type { ReactNode } from "react"; import { useEffect, useEffectEvent, useRef, useState, type RefObject } from "react"; @@ -101,7 +100,10 @@ import { useComposerTextRole, type ScaledTextRole } from "../settings/appearance import type { RemoteClientConnectionState } from "../../lib/connection"; import { MOBILE_TYPOGRAPHY } from "../../lib/typography"; import { Menu } from "../../components/ui/Menu"; -import type { ActiveTurnComposerAction } from "@t3tools/client-runtime/state/composer-dispatch"; +import { + composerRunsDraftLocally, + type ActiveTurnComposerAction, +} from "@t3tools/client-runtime/state/composer-dispatch"; import type { FollowUpBehavior } from "../../lib/followUpBehavior"; import { resolveComposerSendPresentation, @@ -502,7 +504,11 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps const [previewVideo, setPreviewVideo] = useState(null); const composerOwnerKey = scopedThreadKey(props.environmentId, props.selectedThread.id); const composerDraftKey = props.draftKey ?? composerOwnerKey; - const { text: draftMessage, attachments: draftAttachments } = useComposerDraft(composerDraftKey); + const { + text: draftMessage, + attachments: draftAttachments, + context: draftContext, + } = useComposerDraft(composerDraftKey); const queuedEdit = props.queuedEdit ?? null; const hasContent = draftMessage.trim().length > 0 || @@ -534,18 +540,6 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps serverConfig: props.serverConfig, states: uploadStates, }); - const sendPresentation = resolveComposerSendPresentation({ - editingQueuedMessage: queuedEdit !== null, - // A side-chat command starts a side chat; it never queues or steers the running turn. - running: - props.activeThreadBusy && - (props.redirectsApproval || parseSideChatCommand(draftMessage) === null), - canSteer: props.canSteerActiveTurn, - followUpBehavior: props.followUpBehavior, - deliveryDeferred: - props.connectionState !== "connected" || props.queueCount > 0 || attachmentsUploading, - }); - const sendLabel = sendPresentation.label; const currentModelSelection = props.selectedThread.modelSelection; const modelUnavailable = props.connectionState === "connected" && @@ -582,6 +576,25 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps props.serverConfig?.providers ?? [], props.serverConfig?.usageLimitSources ?? [], ); + const draftRunsLocally = composerRunsDraftLocally({ + text: draftMessage, + holdsOnlyText: draftAttachments.length === 0, + // A redirect's text answers its approval, so `/side` there is that text. + sideChat: !props.redirectsApproval, + usageLimits: usageLimitsOffered, + codexFeedback: selectedProviderStatus?.driver === "codex", + freshSession: props.onFreshSession !== undefined && draftContext === undefined, + }); + const sendPresentation = resolveComposerSendPresentation({ + editingQueuedMessage: queuedEdit !== null, + running: props.activeThreadBusy && !draftRunsLocally, + canSteer: props.canSteerActiveTurn, + followUpBehavior: props.followUpBehavior, + deliveryDeferred: + !draftRunsLocally && + (props.connectionState !== "connected" || props.queueCount > 0 || attachmentsUploading), + }); + const sendLabel = sendPresentation.label; const openUsageLimits = () => { const report = collectProviderUsageLimits( currentModelSelection.instanceId, diff --git a/apps/mobile/src/lib/composerContext.test.ts b/apps/mobile/src/lib/composerContext.test.ts index 2e1ee64831d08..9d4d7274cfd22 100644 --- a/apps/mobile/src/lib/composerContext.test.ts +++ b/apps/mobile/src/lib/composerContext.test.ts @@ -154,7 +154,7 @@ describe("mobile composer context", () => { expect(restore("deleted", initial)).toBeUndefined(); expect(restore(source)?.records).toEqual(initial.records); expect(restore("deleted")?.records ?? []).toEqual([]); - expect(createComposerContextHistory()(source)?.records).toEqual([]); + expect(createComposerContextHistory()(source)).toBeUndefined(); }); it("chips a model reference only once it is complete and names a known model", () => { const known = new Set(["model:codex/gpt-6.1"]); diff --git a/apps/mobile/src/lib/composerContext.ts b/apps/mobile/src/lib/composerContext.ts index 53494209362af..d96704b9a61c2 100644 --- a/apps/mobile/src/lib/composerContext.ts +++ b/apps/mobile/src/lib/composerContext.ts @@ -233,8 +233,8 @@ export function referencedComposerContext(text: string, context?: OrchestrationM } } const records = context.records.filter((record) => ids.has(record.contextId)); - if (records.length === context.records.length) return context; - return records.length ? { version: 1 as const, records } : undefined; + if (records.length === 0) return undefined; + return records.length === context.records.length ? context : { version: 1 as const, records }; } /** Uploads change attachment ids; keep context bindings attached to the same ordered file. */ diff --git a/apps/web/src/components/chat/ChatComposer.tsx b/apps/web/src/components/chat/ChatComposer.tsx index 83bd2f63883e7..be3144efb40b9 100644 --- a/apps/web/src/components/chat/ChatComposer.tsx +++ b/apps/web/src/components/chat/ChatComposer.tsx @@ -53,7 +53,7 @@ import * as Schema from "effect/Schema"; import { formatComposerModelMention } from "@t3tools/client-runtime/composer-model-mentions"; import { isPasteAsTextShortcut } from "@t3tools/client-runtime/text-paste"; import { scopedThreadKey, scopeThreadRef } from "@t3tools/client-runtime/environment"; -import { parseSideChatCommand, serializeComposerFileLink } from "@t3tools/shared/composerTrigger"; +import { serializeComposerFileLink } from "@t3tools/shared/composerTrigger"; import { type FolderDropTarget, folderDropTarget, resolveDroppedFolderPath } from "./folderDrop"; import { splitTransferredFiles } from "./workspaceFileDrop"; import { createModelSelection, normalizeModelSlug } from "@t3tools/shared/model"; @@ -253,6 +253,7 @@ import { type ComposerPromptHistoryPosition } from "./composerPromptHistory"; import { usePendingUserInputDraft } from "./usePendingThreadRequests"; import type { PendingApproval, PendingUserInput, TimelineEntry } from "../../session-logic"; import { + composerRunsDraftLocally, resolveComposerDispatchMode, type ComposerDispatchMode, } from "@t3tools/client-runtime/state/composer-dispatch"; @@ -2489,6 +2490,21 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps) // An open question owns the space above the composer. Only a machine problem, // which is why an answer could not go through, stays beside it. const replyTo = composerDraft?.replyTo ?? null; + const draftRunsLocally = composerRunsDraftLocally({ + text: prompt, + holdsOnlyText: + composerImages.length + composerFiles.length === 0 && + composerSendState.sendableTerminalContexts.length === 0 && + composerPreviewAnnotations.length === 0 && + composerReviewComments.length === 0 && + composerThreadContexts.length === 0 && + composerEnvironmentContexts.length === 0 && + replyTo === null, + sideChat: props.sideChatAvailable === true || (props.sideChatDisabledReason ?? null) !== null, + usageLimits: props.onUsageLimitsCommand !== undefined, + codexFeedback: selectedProvider === "codex" && multipleModelSelections === null, + freshSession: props.onFreshSession !== undefined, + }); const replyBannerItems: readonly ComposerBannerStackItem[] = replyTo ? [ { @@ -3737,11 +3753,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps) compact={isComposerPrimaryActionsCompact} canOperateThread={canOperateThread} pendingAction={pendingPrimaryAction} - // A side-chat command starts a side chat; it never queues or steers the turn. - isRunning={ - (phase === "running" || phase === "connecting") && - !(props.sideChatAvailable === true && parseSideChatCommand(prompt) !== null) - } + isRunning={(phase === "running" || phase === "connecting") && !draftRunsLocally} canInterrupt={canInterrupt} runId={activeThread?.runtime?.activeRunId ?? null} followUpBehavior={followUpBehavior} diff --git a/packages/client-runtime/src/state/composerDispatch.test.ts b/packages/client-runtime/src/state/composerDispatch.test.ts index 936ae33111ef4..2eb4728012a94 100644 --- a/packages/client-runtime/src/state/composerDispatch.test.ts +++ b/packages/client-runtime/src/state/composerDispatch.test.ts @@ -1,6 +1,6 @@ import { expect, it } from "vite-plus/test"; -import { compactionBlocksSteering } from "./composerDispatch.ts"; +import { compactionBlocksSteering, composerRunsDraftLocally } from "./composerDispatch.ts"; it("blocks steering for explicit compaction, and for automatic compaction unless the provider takes steers then", () => { const during = ( @@ -47,3 +47,27 @@ it("blocks steering for explicit compaction, and for automatic compaction unless }), ).toBe(false); }); + +it("treats only the commands the composer runs itself as local", () => { + const none = { + holdsOnlyText: true, + sideChat: false, + usageLimits: false, + codexFeedback: false, + freshSession: false, + }; + const all = { + ...none, + sideChat: true, + usageLimits: true, + codexFeedback: true, + freshSession: true, + }; + for (const text of ["/btw why?", "/usage-limits", "/feedback slow", "/clear"]) { + expect(composerRunsDraftLocally({ ...all, text })).toBe(true); + expect(composerRunsDraftLocally({ ...none, text })).toBe(false); + } + expect(composerRunsDraftLocally({ ...all, text: "fix the bug" })).toBe(false); + expect(composerRunsDraftLocally({ ...all, holdsOnlyText: false, text: "/clear" })).toBe(false); + expect(composerRunsDraftLocally({ ...all, holdsOnlyText: false, text: "/side why?" })).toBe(true); +}); diff --git a/packages/client-runtime/src/state/composerDispatch.ts b/packages/client-runtime/src/state/composerDispatch.ts index c24bb95628d97..3860bfc529ded 100644 --- a/packages/client-runtime/src/state/composerDispatch.ts +++ b/packages/client-runtime/src/state/composerDispatch.ts @@ -1,3 +1,8 @@ +import { isClearComposerCommand, parseSideChatCommand } from "@t3tools/shared/composerTrigger"; +import { isUsageLimitsCommand } from "@t3tools/shared/usageLimits"; + +import { parseCodexFeedbackCommand } from "./threadFeedback.ts"; + export type ComposerDispatchMode = "auto" | "queue" | "steer" | "restart"; export type ActiveTurnComposerAction = Exclude; @@ -49,3 +54,21 @@ export function alternateComposerDispatchAction( ...(activeTurnDefault === undefined ? {} : { activeTurnDefault }), }) as ActiveTurnComposerAction; } + +/** The composer runs these drafts itself, so they never queue for or steer a running turn. */ +export function composerRunsDraftLocally(input: { + readonly text: string; + readonly holdsOnlyText: boolean; + readonly sideChat: boolean; + readonly usageLimits: boolean; + readonly codexFeedback: boolean; + readonly freshSession: boolean; +}): boolean { + if (input.sideChat && parseSideChatCommand(input.text) !== null) return true; + if (!input.holdsOnlyText) return false; + return ( + (input.usageLimits && isUsageLimitsCommand(input.text)) || + (input.codexFeedback && parseCodexFeedbackCommand(input.text) !== null) || + (input.freshSession && isClearComposerCommand(input.text)) + ); +} From b0f0c44d228552eb1ce3d43f21b0272ce5fc985f Mon Sep 17 00:00:00 2001 From: Arav Jain Date: Mon, 16 Nov 2026 12:08:31 -0600 Subject: [PATCH 2/2] fix(shared): open Forgejo and Gitea /pulls/ tab and commit links (#37703) Co-authored-by: Julius Marminge --- packages/shared/src/pullRequestAnchor.test.ts | 3 +++ packages/shared/src/pullRequestAnchor.ts | 7 ++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/shared/src/pullRequestAnchor.test.ts b/packages/shared/src/pullRequestAnchor.test.ts index 6ea826924a992..08bb25e75f477 100644 --- a/packages/shared/src/pullRequestAnchor.test.ts +++ b/packages/shared/src/pullRequestAnchor.test.ts @@ -9,6 +9,7 @@ import { } from "./pullRequestAnchor.ts"; const gitlab = "https://gitlab.com/group/repo/-/merge_requests/7"; +const forgejo = "https://codeberg.org/owner/repo/pulls/7"; const url = "https://github.com/owner/repo/pull/7"; it.each(["discussion_r123", "r123", "discussion-diff-123R5-L9", "discussion-diff-123"])( @@ -107,6 +108,7 @@ it("handles encoded hashes and rejects invalid line numbers and URLs", () => { it("keeps the commit scope of a PR diff permalink", () => { const sha = "a".repeat(40); expect(pullRequestLinkCommit(`${url}/commits/${sha}#diff-abcR5`)).toBe(sha); + expect(pullRequestLinkCommit(`${forgejo}/commits/${sha}#diff-abcR5`)).toBe(sha); expect(pullRequestLinkCommit(`${url}/files#diff-abcR5`)).toBeNull(); expect(pullRequestLinkCommit(`${gitlab}/diffs?commit_id=${sha}#${"b".repeat(40)}`)).toBe(sha); expect(pullRequestLinkCommit(`${gitlab}/diffs?commit_id=main`)).toBeNull(); @@ -153,6 +155,7 @@ it.each([ [`${url}/commits/${"a".repeat(40)}`, "code"], [`${url}/commits`, "commits"], [`${url}/checks?check_run_id=1`, "checks"], + [`${forgejo}/files`, "code"], [`${gitlab}/diffs`, "code"], [`${gitlab}/commits`, "commits"], [`${gitlab}/pipelines`, "checks"], diff --git a/packages/shared/src/pullRequestAnchor.ts b/packages/shared/src/pullRequestAnchor.ts index a16e7ced305a3..3e02f0f383424 100644 --- a/packages/shared/src/pullRequestAnchor.ts +++ b/packages/shared/src/pullRequestAnchor.ts @@ -39,9 +39,10 @@ function normalizePullRequestCommentAnchor(anchor: string): string { ); } -// GitHub pull request tabs and their GitLab merge request equivalents. +// GitHub pull request tabs and their GitLab merge request equivalents. Forgejo and Gitea spell the +// path `/pulls/`. function pullRequestPathTab(pathname: string): PullRequestAnchor | null { - const tab = /\/(?:pull|-\/merge_requests)\/\d+\/([a-z]+)(?:\/(.*))?$/i.exec(pathname); + const tab = /\/(?:pulls?|-\/merge_requests)\/\d+\/([a-z]+)(?:\/(.*))?$/i.exec(pathname); const rest = tab?.[2] ?? ""; switch (tab?.[1]?.toLowerCase()) { case "files": @@ -206,7 +207,7 @@ export function pullRequestLinkCommit(url: string | null | undefined): string | const { pathname, searchParams } = new URL(url); const commit = /\/-\/merge_requests\/\d+\/diffs\/?$/i.test(pathname) ? searchParams.get("commit_id") - : /\/pull\/\d+\/commits\/([a-f0-9]{40})\/?$/i.exec(pathname)?.[1]; + : /\/pulls?\/\d+\/commits\/([a-f0-9]{40})\/?$/i.exec(pathname)?.[1]; return commit && /^[a-f0-9]{40}$/i.test(commit) ? commit : null; } catch { return null;