GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(web): citation comments use the composer's editor, menus, links … · adampeterhiggins/t3code@73f4a53

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps
    • server/src/orchestration-v2
      • ProviderTurnControlService.ts
      • ProviderTurnStartService.ts
    • web/src
      • components
        • ChatMarkdown.tsx
        • ChatView.citationComment.browser.test.tsx
        • ComposerPromptEditor.tsx
        • ComposerPromptEditorTiptap.citationDraft.browser.test.tsx
        • ComposerPromptEditorTiptap.tsx
        • chat
          • AssistantCitationChip.browser.test.tsx
          • AssistantCitationChip.tsx
          • AssistantCitationCommentEditor.tsx
          • ChatComposer.tsx
          • ComposerCommandMenuLayer.tsx
          • composerCommandKey.ts
          • composerEventScope.ts
          • composerSend.logic.test.ts
          • composerTextTarget.ts
          • forkComposerContexts.test.ts
          • forkComposerContexts.ts
          • useComposerAttachmentIntake.ts
          • useComposerObjectLinks.ts
          • useThreadLifecycle.tsx
          • workspaceFileDrop.ts
      • lib
        • composerContextReferences.ts
  • docs
    • fork-differences.md
    • user
      • composer.md
  • packages/shared/src
    • assistantCitations.test.ts
    • assistantCitations.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/server/src/orchestration-v2/ProviderTurnControlService.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/ProviderTurnControlService.ts
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { projectComposerContextForProvider } from "@t3tools/shared/composerContextReferences";
1+
import { projectUserMessageForProvider } from "@t3tools/shared/assistantCitations";
22
import {
33
MessageId,
44
type NodeId,
@@ -374,7 +374,7 @@ export const layer: Layer.Layer<
374374
providerTurnId: loaded.providerTurn.id,
375375
message: {
376376
messageId: message.id,
377-
text: projectComposerContextForProvider({
377+
text: projectUserMessageForProvider({
378378
text: message.text,
379379
records: message.context?.records ?? [],
380380
}),
Collapse file

‎apps/server/src/orchestration-v2/ProviderTurnStartService.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/ProviderTurnStartService.ts
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { modelSelectionsEqual } from "@t3tools/shared/model";
22
import { checkoutDirectoriesForTurn, formatLinkedCheckoutPrompt } from "@t3tools/shared/checkouts";
3-
import { projectComposerContextForProvider } from "@t3tools/shared/composerContextReferences";
3+
import { projectUserMessageForProvider } from "@t3tools/shared/assistantCitations";
44
import {
55
CommandId,
66
latestProviderTurnForAttempt,
@@ -583,7 +583,7 @@ export const layer: Layer.Layer<
583583
: yield* Effect.result(
584584
providerAuth.tryHandlePromptCommand({
585585
instanceId: authInstanceId,
586-
text: projectComposerContextForProvider({
586+
text: projectUserMessageForProvider({
587587
text: message.text,
588588
records: message.context?.records ?? [],
589589
}),
@@ -854,7 +854,7 @@ export const layer: Layer.Layer<
854854
let effectiveHandoffs = handoffs;
855855
let resumeFellBack = false;
856856
const contextRecords = message.context?.records ?? [];
857-
const projectedUserText = projectComposerContextForProvider({
857+
const projectedUserText = projectUserMessageForProvider({
858858
text: message.text,
859859
records: contextRecords,
860860
});
Collapse file

‎apps/web/src/components/ChatMarkdown.tsx‎

Copy file name to clipboardExpand all lines: apps/web/src/components/ChatMarkdown.tsx
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1353,7 +1353,13 @@ const CHAT_MARKDOWN_COMPONENTS = {
13531353
const text = use(ChatMarkdownTextContext);
13541354
const citation = href ? parseAssistantCitationHref(href) : null;
13551355
if (citation) {
1356-
return <AssistantCitationChip citation={citation} currentThreadId={threadRef?.threadId} />;
1356+
return (
1357+
<AssistantCitationChip
1358+
citation={citation}
1359+
currentThreadId={threadRef?.threadId}
1360+
renderContextReference={renderContextReference}
1361+
/>
1362+
);
13571363
}
13581364
const threadLink = href ? parseThreadLinkHref(href) : null;
13591365
if (threadLink) {
Collapse file

‎apps/web/src/components/ChatView.citationComment.browser.test.tsx‎

Copy file name to clipboard
+131Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
import { createMemoryHistory } from "@tanstack/react-router";
2+
import { scopeThreadRef } from "@t3tools/client-runtime/environment";
3+
import { MessageId, ThreadId } from "@t3tools/contracts";
4+
import { DEFAULT_CLIENT_SETTINGS } from "@t3tools/contracts/settings";
5+
import {
6+
collectAssistantCitationComments,
7+
serializeAssistantCitation,
8+
} from "@t3tools/shared/assistantCitations";
9+
import { threadContextRecord } from "@t3tools/shared/composerContextReferences";
10+
import type * as Context from "effect/Context";
11+
import { expect, it, vi } from "vite-plus/test";
12+
import { page, userEvent } from "vite-plus/test/browser";
13+
14+
import { AppRoot } from "~/AppRoot";
15+
// The route loads ChatView lazily; importing it here keeps its first transform out of the timeout.
16+
import "~/components/ChatView";
17+
import {
18+
COMPOSER_MENTION_DRAG_TYPE,
19+
composerMentionFromTreePath,
20+
} from "~/components/chat/composerMentionDrag";
21+
import { useComposerDraftStore } from "~/composerDraftStore";
22+
import { __setClientSettingsForTests } from "~/hooks/useSettings";
23+
import { getRouter } from "~/router";
24+
import {
25+
ENVIRONMENT_ID,
26+
installFakeEnvironment,
27+
threadWithHistory,
28+
type FakeDriver,
29+
} from "../../test/fakeEnvironment";
30+
import { render } from "../../test/render";
31+
32+
// The socket is the only fake layer; see test/appScenarios.renders.tsx. The app keeps its
33+
// connection for the whole file, so the threads served here are this file's only fixture.
34+
vi.mock("../../../../packages/client-runtime/src/connection/driver.ts", async (importOriginal) => {
35+
const [actual, { fakeDriver }, Layer] = await Promise.all([
36+
importOriginal<{ readonly ConnectionDriver: Context.Key<unknown, FakeDriver> }>(),
37+
import("../../test/fakeEnvironment"),
38+
import("effect/Layer"),
39+
]);
40+
return { ...actual, layer: Layer.succeed(actual.ConnectionDriver, fakeDriver) };
41+
});
42+
43+
vi.mock(import("~/rpc/requestLatencyState"), async (original) => ({
44+
...(await original()),
45+
trackRpcRequestSent: () => {},
46+
}));
47+
48+
it("a citation comment's @ menu and drops put their chips in the comment", async () => {
49+
using _environment = installFakeEnvironment([
50+
threadWithHistory("alpha", 1),
51+
threadWithHistory("beta", 1),
52+
]);
53+
__setClientSettingsForTests({
54+
...DEFAULT_CLIENT_SETTINGS,
55+
onboardingCompletedAt: "2026-01-01T00:00:00.000Z",
56+
});
57+
localStorage.removeItem("t3code:citation-comment-submit:v1");
58+
const alpha = ThreadId.make("alpha");
59+
const citation = {
60+
version: 1 as const,
61+
environmentId: ENVIRONMENT_ID,
62+
threadId: alpha,
63+
messageId: MessageId.make("alpha-assistant-0"),
64+
text: "Answer 0",
65+
start: 0,
66+
end: 8,
67+
prefix: "",
68+
suffix: "",
69+
};
70+
const threadRef = scopeThreadRef(ENVIRONMENT_ID, alpha);
71+
useComposerDraftStore
72+
.getState()
73+
.setPrompt(threadRef, `See ${serializeAssistantCitation(citation)} `);
74+
75+
const router = getRouter(createMemoryHistory({ initialEntries: [`/${ENVIRONMENT_ID}/alpha`] }));
76+
await router.load();
77+
await using _app = await render(<AppRoot router={router} />, {
78+
// AppRoot brings its own router.
79+
router: false,
80+
});
81+
await page.getByLabelText("Add comment to citation").click();
82+
const comment = page.getByLabelText("Comment on selected text");
83+
await expect.element(comment).toHaveFocus();
84+
await userEvent.keyboard("@beta");
85+
// The fake server never answers a file search, so the menu waits on Files.
86+
await page.getByRole("tab", { name: "Chats" }).click();
87+
await expect.element(page.getByRole("option", { name: /Thread beta/ })).toBeVisible();
88+
// Enter picks from the menu while it is open, and saves the comment once it closed.
89+
await userEvent.keyboard("{Enter}");
90+
await expect.element(comment.getByText("Thread beta")).toBeVisible();
91+
// The chat's own drop target would put it in the prompt.
92+
const dropped = new DataTransfer();
93+
const png = Uint8Array.from(
94+
atob(
95+
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==",
96+
),
97+
(char) => char.charCodeAt(0),
98+
);
99+
dropped.items.add(new File([png], "dot.png", { type: "image/png" }));
100+
for (const type of ["dragenter", "dragover", "drop"]) {
101+
comment
102+
.element()
103+
.dispatchEvent(
104+
new DragEvent(type, { bubbles: true, cancelable: true, dataTransfer: dropped }),
105+
);
106+
}
107+
await expect.element(comment.getByText("dot.png")).toBeVisible();
108+
const mention = new DataTransfer();
109+
mention.setData(COMPOSER_MENTION_DRAG_TYPE, composerMentionFromTreePath("src/tree.ts") ?? "");
110+
for (const type of ["dragenter", "dragover", "drop"]) {
111+
comment
112+
.element()
113+
.dispatchEvent(
114+
new DragEvent(type, { bubbles: true, cancelable: true, dataTransfer: mention }),
115+
);
116+
}
117+
await expect.element(comment.getByText("tree.ts")).toBeVisible();
118+
await userEvent.keyboard("{Enter}");
119+
120+
const prompt = useComposerDraftStore.getState().getComposerDraft(threadRef)?.prompt ?? "";
121+
const [saved] = collectAssistantCitationComments(prompt);
122+
expect(saved).toContain(
123+
threadContextRecord(scopeThreadRef(ENVIRONMENT_ID, ThreadId.make("beta")), "").contextId,
124+
);
125+
expect(useComposerDraftStore.getState().getComposerDraft(threadRef)?.images).toEqual([
126+
expect.objectContaining({ name: "dot.png" }),
127+
]);
128+
// The chips went into the comment, not beside the citation in the prompt.
129+
expect(prompt.startsWith("See [")).toBe(true);
130+
expect(prompt.endsWith(") ")).toBe(true);
131+
});
Collapse file

‎apps/web/src/components/ComposerPromptEditor.tsx‎

Copy file name to clipboardExpand all lines: apps/web/src/components/ComposerPromptEditor.tsx
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { ComposerPromptEditorTiptap } from "./ComposerPromptEditorTiptap";
22
import type { ComposerPromptEditorProps } from "./ComposerPromptEditorTiptap";
33

44
export type {
5+
CitationCommentDropHost,
56
ComposerCitationCommentRequest,
67
ComposerCitationDestinations,
78
ComposerPromptEditorHandle,
Collapse file

‎apps/web/src/components/ComposerPromptEditorTiptap.citationDraft.browser.test.tsx‎

Copy file name to clipboardExpand all lines: apps/web/src/components/ComposerPromptEditorTiptap.citationDraft.browser.test.tsx
+38-2Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import {
33
serializeAssistantCitation,
44
withAssistantCitationComment,
55
} from "@t3tools/shared/assistantCitations";
6+
import {
7+
formatComposerContextReference,
8+
threadContextRecord,
9+
} from "@t3tools/shared/composerContextReferences";
610
import { createRef, useState } from "react";
711
import { expect, it, vi } from "vite-plus/test";
812

@@ -32,12 +36,14 @@ function Composer({
3236
question,
3337
editorRef,
3438
onCitationSubmitAndSend,
39+
initialPrompt = promptBefore,
3540
}: {
3641
question: boolean;
3742
editorRef: React.RefObject<ComposerPromptEditorHandle | null>;
3843
onCitationSubmitAndSend?: (citationText: string) => Promise<boolean>;
44+
initialPrompt?: string;
3945
}) {
40-
const [prompt, setPrompt] = useState(promptBefore);
46+
const [prompt, setPrompt] = useState(initialPrompt);
4147
const [answer, setAnswer] = useState("");
4248
return (
4349
<>
@@ -145,10 +151,40 @@ it("keeps the commented citation in the composer when its send fails", async ()
145151
);
146152
await openCitationComment(editorRef);
147153

148-
await act(async () => userEvent.keyboard("{Enter}"));
154+
await userEvent.keyboard("{Enter}");
149155

150156
expect(send).toHaveBeenCalledOnce();
151157
expect(screen.container.querySelector("output")?.dataset.prompt).toBe(
152158
`See ${serializeAssistantCitation(withAssistantCitationComment(citation, "check this"))} `,
153159
);
154160
});
161+
162+
it("edits a comment's chips in the composer's own editor", async () => {
163+
localStorage.removeItem("t3code:citation-comment-submit:v1");
164+
const chip = formatComposerContextReference(
165+
threadContextRecord(
166+
{ environmentId: citation.environmentId, threadId: ThreadId.make("linked") },
167+
"Linked thread",
168+
),
169+
);
170+
const commented = withAssistantCitationComment(citation, `Compare ${chip}`);
171+
const editorRef = createRef<ComposerPromptEditorHandle>();
172+
await using screen = await render(
173+
<Composer
174+
question={false}
175+
editorRef={editorRef}
176+
initialPrompt={`See ${serializeAssistantCitation(commented)} `}
177+
/>,
178+
);
179+
180+
await page.getByLabelText("Edit citation comment").click();
181+
const comment = page.getByLabelText("Comment on selected text");
182+
await expect.element(comment.getByText("Linked thread")).toBeVisible();
183+
// The panel focuses the comment with its caret after the chip.
184+
await expect.element(comment).toHaveFocus();
185+
await userEvent.keyboard(" too{Enter}");
186+
187+
expect(screen.container.querySelector("output")?.dataset.prompt).toBe(
188+
`See ${serializeAssistantCitation(withAssistantCitationComment(citation, `Compare ${chip} too`))} `,
189+
);
190+
});

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.