Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
36123ae
feat: cite text from proposed plans
casassg Oct 8, 2026
1685703
Merge upstream/main into gerardc/plan-card-citations-upstream
casassg Oct 26, 2026
0f80b28
Merge remote-tracking branch 'upstream/main' into gerardc/plan-card-c…
casassg Oct 28, 2026
e663145
fix: re-expand a cited plan on every citation activation
casassg Oct 28, 2026
6a9030e
Merge remote-tracking branch 'upstream/main' into gerardc/plan-card-c…
casassg Oct 30, 2026
59a3420
fix(web): keep preview ellipsis out of plan citations
maria-rcks Oct 31, 2026
cf25716
fix(web): keep plan preview marker unselectable
maria-rcks Oct 31, 2026
fa522c9
Merge remote-tracking branch 'upstream/main' into gerardc/plan-card-c…
casassg Nov 7, 2026
91c7415
Merge remote-tracking branch 'upstream/main' into gerardc/plan-card-c…
casassg Nov 9, 2026
2e8ab44
chore: format proposed plan preview test
casassg Nov 9, 2026
862eb1b
Merge remote-tracking branch 'github/main' into gerardc/plan-card-cit…
maria-rcks Nov 10, 2026
e96eee1
Merge remote-tracking branch 'upstream/main' into gerardc/plan-card-c…
casassg Nov 11, 2026
9cbe9e6
Merge remote-tracking branch 'upstream/main' into gerardc/plan-card-c…
casassg Nov 12, 2026
bc90400
Merge remote-tracking branch 'upstream/main' into gerardc/plan-card-c…
casassg Nov 13, 2026
5fb675e
fix(web): merge main while preserving plan and sent-message citations
maria-rcks Nov 15, 2026
0d93e5b
Merge remote-tracking branch 'upstream/main' into gerardc/plan-card-c…
casassg Nov 16, 2026
3a17eef
Merge remote-tracking branch 'upstream/main' into gerardc/plan-card-c…
casassg Nov 18, 2026
371963e
Merge remote-tracking branch 'upstream/main' into gerardc/plan-card-c…
casassg Nov 18, 2026
2aedaa6
Merge remote-tracking branch 'upstream/main' into gerardc/plan-card-c…
casassg Nov 19, 2026
9d9798c
Merge remote-tracking branch 'upstream/main' into gerardc/plan-card-c…
casassg Nov 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions apps/web/src/components/chat/MessagesTimeline.logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import type { TurnDiffSummary } from "../../types";
import { describe, expect, it } from "vite-plus/test";
import { MessageId, RunId } from "@t3tools/contracts";
import {
citationSourceId,
computeStableMessagesTimelineRows,
deriveMessagesTimelineRows,
timelineTurnFoldRunIdsByEntryId,
Expand Down Expand Up @@ -5170,3 +5171,11 @@ describe("workEntryReadOutput", () => {
).toBe("/workspace/t3code/src/app.ts\n~/.claude/CLAUDE.md\n~/.gitconfig");
});
});

describe("citationSourceId", () => {
it("identifies messages and proposed plans, not other rows", () => {
expect(citationSourceId({ kind: "message", message: { id: "m1" } })).toBe("m1");
expect(citationSourceId({ kind: "proposed-plan", id: "plan-item" })).toBe("plan-item");
expect(citationSourceId({ kind: "event" })).toBeNull();
});
});
12 changes: 12 additions & 0 deletions apps/web/src/components/chat/MessagesTimeline.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,18 @@ type MessagesTimelineRowContent =
mcpApp: McpAppReference;
};

/** Id a citation uses to find its source: the message id, or the plan row id. */
export function citationSourceId(
row:
| { readonly kind: "message"; readonly message: { readonly id: string } }
| { readonly kind: "proposed-plan" | "sent-message"; readonly id: string }
| { readonly kind: string },
): string | null {
if (row.kind === "message" && "message" in row) return row.message.id;
if ((row.kind === "proposed-plan" || row.kind === "sent-message") && "id" in row) return row.id;
return null;
}

export interface StableMessagesTimelineRowsState {
byId: Map<string, MessagesTimelineRow>;
result: MessagesTimelineRow[];
Expand Down
9 changes: 5 additions & 4 deletions apps/web/src/components/chat/MessagesTimeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ import {
isTimelineMinimapTurnVisible,
resolveTimelineMinimapVisibleRange,
resolveTimelineMinimapHitStripWidth,
citationSourceId,
TIMELINE_MINIMAP_TARGET_OFFSET,
timelineTurnFoldRunIdsByEntryId,
liveAnswerPreview,
Expand Down Expand Up @@ -682,10 +683,10 @@ const ConversationTimeline = memo(function ConversationTimeline({
citationHistory._tag !== "failed"
? timelineEntries.find(
(entry) =>
(entry.kind === "message" &&
entry.message.role === "assistant" &&
entry.message.id === citationRequest.citation.messageId) ||
(entry.kind === "sent-message" && entry.id === citationRequest.citation.messageId),
(entry.kind === "proposed-plan" ||
entry.kind === "sent-message" ||
(entry.kind === "message" && entry.message.role === "assistant")) &&
citationSourceId(entry) === citationRequest.citation.messageId,
)
: undefined;
if (citationRequest && citedEntry) {
Expand Down
38 changes: 28 additions & 10 deletions apps/web/src/components/chat/ProposedPlanCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
type ScopedThreadRef,
} from "@t3tools/contracts";
import {
buildCollapsedProposedPlanPreviewMarkdown,
buildCollapsedProposedPlanPreview,
buildProposedPlanMarkdownFilename,
downloadPlanAsTextFile,
normalizePlanMarkdownForExport,
Expand Down Expand Up @@ -46,17 +46,25 @@ export const ProposedPlanCard = memo(function ProposedPlanCard({
cwd,
workspaceRoot,
findActive = false,
expandKey = null,
}: {
planMarkdown: string;
environmentId: EnvironmentId;
threadRef?: ScopedThreadRef | undefined;
cwd: string | undefined;
workspaceRoot: string | undefined;
findActive?: boolean;
/** Expands the card each time a new citation activation targets it. */
expandKey?: string | null;
}) {
const gt = useGT();
const messages = useMessages();
const [expanded, setExpanded] = useState(false);
const [lastExpandKey, setLastExpandKey] = useState<string | null>(null);
if (expandKey !== lastExpandKey) {
setLastExpandKey(expandKey);
if (expandKey !== null) setExpanded(true);
}
const canWriteFiles = useEnvironmentScope(environmentId, AuthFilesystemWriteScope);
const [isSaveDialogOpen, setIsSaveDialogOpen] = useState(false);
const [lastSavePath, setLastSavePath] = useState("");
Expand Down Expand Up @@ -86,7 +94,7 @@ export const ProposedPlanCard = memo(function ProposedPlanCard({
const canCollapse = planMarkdown.length > 900 || lineCount > 20;
const displayedPlanMarkdown = stripDisplayedPlanMarkdown(planMarkdown);
const collapsedPreview = canCollapse
? buildCollapsedProposedPlanPreviewMarkdown(planMarkdown, { maxLines: 10 }, messages)
? buildCollapsedProposedPlanPreview(planMarkdown, { maxLines: 10 }, messages)
: null;
const isCollapsed = canCollapse && !expanded;
// Mount clipped plans during find to count hidden matches without revealing them.
Expand Down Expand Up @@ -206,14 +214,24 @@ export const ProposedPlanCard = memo(function ProposedPlanCard({
data-thread-find-fold={isCollapsed ? "" : undefined}
>
{showPreview ? (
<ChatMarkdown
text={collapsedPreview ?? ""}
cwd={cwd}
environmentId={environmentId}
threadRef={threadRef}
isStreaming={false}
headingLevelOffset={3}
/>
<>
<ChatMarkdown
text={collapsedPreview?.markdown ?? ""}
cwd={cwd}
environmentId={environmentId}
threadRef={threadRef}
isStreaming={false}
headingLevelOffset={3}
/>
{collapsedPreview?.truncated ? (
<p
aria-hidden="true"
className="mt-[0.65rem] select-none text-sm leading-relaxed text-foreground/[calc(90%+var(--appearance-contrast-boost)/10)]"
>
...
</p>
) : null}
</>
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
) : (
<ChatMarkdown
text={displayedPlanMarkdown}
Expand Down
27 changes: 19 additions & 8 deletions apps/web/src/components/chat/TimelineAssistantRows.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -364,14 +364,25 @@ export function ProposedPlanTimelineRow({

return (
<div className="min-w-0 px-1 py-0.5">
<ProposedPlanCard
planMarkdown={row.proposedPlan.planMarkdown}
environmentId={ctx.activeThreadEnvironmentId}
threadRef={ctx.threadRef ?? undefined}
cwd={ctx.markdownCwd}
workspaceRoot={ctx.workspaceRoot}
findActive={ctx.findActive}
/>
<AssistantCitationSource
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
messageId={MessageId.make(row.id)}
{...(ctx.threadRef ? { threadRef: ctx.threadRef } : {})}
itemKey={row.id}
request={ctx.citationRequest}
listRef={ctx.listRef}
>
<ProposedPlanCard
planMarkdown={row.proposedPlan.planMarkdown}
environmentId={ctx.activeThreadEnvironmentId}
threadRef={ctx.threadRef ?? undefined}
cwd={ctx.markdownCwd}
workspaceRoot={ctx.workspaceRoot}
findActive={ctx.findActive}
expandKey={
ctx.citationRequest?.citation.messageId === row.id ? ctx.citationRequest.key : null
}
/>
</AssistantCitationSource>
</div>
);
}
Expand Down
15 changes: 15 additions & 0 deletions apps/web/src/components/chat/citationProcedure.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,21 @@ describe("resolveCitationPhase", () => {
});
});

it("treats a proposed plan as a citation source", () => {
const planEntry = {
kind: "proposed-plan",
id: "cited",
createdAt: at,
proposedPlan: { runId },
} as TimelineEntry;
const planRow = { kind: "proposed-plan", id: "cited" } as MessagesTimelineRow;
expect(phase({ entries: [planEntry] })).toEqual({ _tag: "expanding" });
expect(phase({ entries: [planEntry], rows: [planRow] })).toEqual({
_tag: "ready",
rowId: "cited",
});
});

it("finds text an agent sent with send_to_user by its item id", () => {
const sent: TimelineEntry = {
kind: "sent-message",
Expand Down
22 changes: 10 additions & 12 deletions apps/web/src/components/chat/citationProcedure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { TimelineEntry } from "../../session-logic";
import { environmentThreadDetails, threadEnvironment } from "../../state/threads";
import { toastManager } from "../ui/toast";
import type { AssistantCitationRequest } from "./AssistantCitationSource";
import type { MessagesTimelineRow } from "./MessagesTimeline.logic";
import { citationSourceId, type MessagesTimelineRow } from "./MessagesTimeline.logic";

/** Whether the cited response is in the loaded history, after paging toward it. */
export type CitedHistory =
Expand Down Expand Up @@ -97,19 +97,16 @@ export function resolveCitationPhase(input: {
readonly rows: ReadonlyArray<MessagesTimelineRow>;
}): CitationPhase {
if (input.history._tag === "failed") return { _tag: "failed" };
const source = input.entries.find(
(entry) =>
(entry.kind === "message" && entry.message.id === input.messageId) ||
(entry.kind === "sent-message" && entry.id === input.messageId),
);
const source = input.entries.find((entry) => citationSourceId(entry) === input.messageId);
// The history store can hold the message a render before the entries do.
if (!source) return { _tag: "loading" };
if (source.kind === "message" && source.message.role !== "assistant") return { _tag: "failed" };
const row = input.rows.find(
(candidate) =>
(candidate.kind === "message" && candidate.message.id === input.messageId) ||
(candidate.kind === "sent-message" && candidate.id === input.messageId),
);
if (
source.kind !== "proposed-plan" &&
source.kind !== "sent-message" &&
(source.kind !== "message" || source.message.role !== "assistant")
)
return { _tag: "failed" };
const row = input.rows.find((candidate) => citationSourceId(candidate) === input.messageId);
if (row) return { _tag: "ready", rowId: row.id };
return { _tag: "expanding" };
}
Expand Down Expand Up @@ -138,6 +135,7 @@ export function citedThreadSnapshot(input: {
// Older pages merge into the visible turn items, not the message list.
const item = input.thread.projection.visibleTurnItems.find(
({ item }) =>
(item.type === "proposed_plan" && item.id === input.messageId) ||
((item.type === "assistant_message" || item.type === "user_message") &&
item.messageId === input.messageId) ||
(item.type === "dynamic_tool" &&
Expand Down
22 changes: 22 additions & 0 deletions apps/web/src/proposedPlan.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { describe, expect, it } from "vite-plus/test";

import { buildCollapsedProposedPlanPreview } from "./proposedPlan";
import {
createAssistantTextSelector,
findAssistantCitationText,
} from "./lib/assistantTextSelection";

describe("proposed plan preview citations", () => {
it("resolves repeated text at the preview boundary after expansion", () => {
const quote = "Repeatable health check.";
const planMarkdown = `Check remote.\n${quote}\nExtended acceptance.\n${quote}`;
const { markdown: preview } = buildCollapsedProposedPlanPreview(planMarkdown, { maxLines: 2 });
const start = preview.indexOf(quote);
const citation = createAssistantTextSelector(preview, start, start + quote.length)!;

expect(findAssistantCitationText(planMarkdown, citation)).toEqual({
start,
end: start + quote.length,
});
});
});
15 changes: 7 additions & 8 deletions apps/web/src/proposedPlan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { msg } from "gt-react";

import { m, type MessageResolver } from "./i18n/messages";

export function buildCollapsedProposedPlanPreviewMarkdown(
export function buildCollapsedProposedPlanPreview(
planMarkdown: string,
options?: {
maxLines?: number;
},
resolve: MessageResolver = m,
): string {
) {
const maxLines = options?.maxLines ?? 8;
const lines = stripDisplayedPlanMarkdown(planMarkdown)
.trimEnd()
Expand All @@ -36,14 +36,13 @@ export function buildCollapsedProposedPlanPreviewMarkdown(
}

if (previewLines.length === 0) {
return proposedPlanTitle(planMarkdown) ?? resolve(msg("Plan preview unavailable."));
return {
markdown: proposedPlanTitle(planMarkdown) ?? resolve(msg("Plan preview unavailable.")),
truncated: false,
};
}

if (hasMoreContent) {
previewLines.push("", "...");
}

return previewLines.join("\n");
return { markdown: previewLines.join("\n"), truncated: hasMoreContent };
}

function sanitizePlanFileSegment(input: string): string {
Expand Down
Loading