Skip to content

Commit 45d284f

Browse files
authored
Merge branch 'main' into fix/file-panel-checkpoint-refresh
2 parents bf4f1f1 + c034f51 commit 45d284f

17 files changed

Lines changed: 446 additions & 69 deletions

‎apps/mobile/modules/t3-markdown-text/src/markdownLinks.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import type { MARKDOWN_FILE_ICON_SOURCES } from "./markdownFileIcons.generated";
33
const WINDOWS_DRIVE_PATH_PATTERN = /^[A-Za-z]:[\\/]/;
44
const WINDOWS_UNC_PATH_PATTERN = /^\\\\/;
55
const RELATIVE_PATH_PREFIX_PATTERN = /^(~\/|\.{1,2}\/)/;
6-
const RELATIVE_FILE_PATH_PATTERN = /^[A-Za-z0-9._-]+(?:\/[A-Za-z0-9._-]+)+(?::\d+){0,2}$/;
7-
const RELATIVE_FILE_NAME_PATTERN = /^[A-Za-z0-9._-]+\.[A-Za-z0-9_-]+(?::\d+){0,2}$/;
6+
const RELATIVE_FILE_PATH_PATTERN =
7+
/^(?:[A-Za-z0-9._-]+(?: +[A-Za-z0-9._-]+)*\/)+[A-Za-z0-9._-]+(?: +[A-Za-z0-9._-]+)*(?::\d+){0,2}$/;
8+
const RELATIVE_FILE_NAME_PATTERN =
9+
/^[A-Za-z0-9._-]+(?: +[A-Za-z0-9._-]+)*\.[A-Za-z0-9_-]+(?::\d+){0,2}$/;
810
const POSITION_SUFFIX_PATTERN = /:\d+(?::\d+)?$/;
911
const POSIX_FILE_ROOT_PREFIXES = [
1012
"/Users/",

‎apps/mobile/src/lib/markdownLinks.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,24 @@ describe("resolveMarkdownLinkPresentation", () => {
5050
});
5151
});
5252

53+
it.each(["md", "html", "xml"])("recognizes a bare spaced .%s filename", (extension) => {
54+
expect(
55+
resolveMarkdownLinkPresentation(`Updated%20cutover%20checklist.${extension}`),
56+
).toMatchObject({
57+
kind: "file",
58+
path: `Updated cutover checklist.${extension}`,
59+
label: `Updated cutover checklist.${extension}`,
60+
});
61+
});
62+
63+
it("recognizes spaced relative paths", () => {
64+
expect(resolveMarkdownLinkPresentation("docs/My%20Folder/checklist.xml")).toMatchObject({
65+
kind: "file",
66+
path: "docs/My Folder/checklist.xml",
67+
label: "checklist.xml",
68+
});
69+
});
70+
5371
it("extracts line fragments from relative file links", () => {
5472
expect(resolveMarkdownLinkPresentation("src/main.ts#L18C2")).toMatchObject({
5573
kind: "file",

‎apps/server/src/orchestration/Layers/ProjectionPipeline.test.ts‎

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,78 @@ it.layer(BaseTestLayer)("OrchestrationProjectionPipeline", (it) => {
174174
assert.equal(row.lastAppliedSequence, 3);
175175
}
176176

177+
yield* sql`CREATE TABLE thread_shell_updates (count INTEGER NOT NULL)`;
178+
yield* sql`INSERT INTO thread_shell_updates (count) VALUES (0)`;
179+
yield* sql`
180+
CREATE TRIGGER count_thread_shell_updates
181+
AFTER UPDATE ON projection_threads
182+
WHEN NEW.thread_id = 'thread-1'
183+
BEGIN
184+
UPDATE thread_shell_updates SET count = count + 1;
185+
END;
186+
`;
187+
188+
yield* eventStore.append({
189+
type: "thread.message-sent",
190+
eventId: EventId.make("evt-assistant-update"),
191+
aggregateKind: "thread",
192+
aggregateId: ThreadId.make("thread-1"),
193+
occurredAt: "2026-01-01T00:00:00.100Z",
194+
commandId: CommandId.make("cmd-assistant-update"),
195+
causationEventId: null,
196+
correlationId: CommandId.make("cmd-assistant-update"),
197+
metadata: {},
198+
payload: {
199+
threadId: ThreadId.make("thread-1"),
200+
messageId: MessageId.make("message-2"),
201+
role: "assistant",
202+
text: "more work",
203+
turnId: null,
204+
streaming: false,
205+
createdAt: "2026-01-01T00:00:00.100Z",
206+
updatedAt: "2026-01-01T00:00:00.100Z",
207+
},
208+
});
209+
yield* projectionPipeline.bootstrap;
210+
211+
let threadShellUpdates = yield* sql<{ readonly count: number }>`
212+
SELECT count FROM thread_shell_updates
213+
`;
214+
assert.deepEqual(threadShellUpdates, [{ count: 1 }]);
215+
216+
yield* sql`UPDATE thread_shell_updates SET count = 0`;
217+
yield* eventStore.append({
218+
type: "thread.activity-appended",
219+
eventId: EventId.make("evt-routine-activity"),
220+
aggregateKind: "thread",
221+
aggregateId: ThreadId.make("thread-1"),
222+
occurredAt: "2026-01-01T00:00:00.200Z",
223+
commandId: CommandId.make("cmd-routine-activity"),
224+
causationEventId: null,
225+
correlationId: CommandId.make("cmd-routine-activity"),
226+
metadata: {},
227+
payload: {
228+
threadId: ThreadId.make("thread-1"),
229+
activity: {
230+
id: EventId.make("activity-routine"),
231+
tone: "tool",
232+
kind: "tool.updated",
233+
summary: "Tool made progress",
234+
payload: {},
235+
turnId: null,
236+
createdAt: "2026-01-01T00:00:00.200Z",
237+
},
238+
},
239+
});
240+
yield* projectionPipeline.bootstrap;
241+
242+
threadShellUpdates = yield* sql<{ readonly count: number }>`
243+
SELECT count FROM thread_shell_updates
244+
`;
245+
assert.deepEqual(threadShellUpdates, [{ count: 1 }]);
246+
yield* sql`DROP TRIGGER count_thread_shell_updates`;
247+
yield* sql`DROP TABLE thread_shell_updates`;
248+
177249
// Settled lifecycle through the DB pipeline: thread.settled writes the
178250
// override + timestamp, thread.unsettled(user) flips to the active pin.
179251
yield* eventStore.append({

‎apps/server/src/orchestration/Layers/ProjectionPipeline.ts‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,29 @@ function isStalePendingApprovalFailureDetail(detail: string | null): boolean {
130130
);
131131
}
132132

133+
// A full refresh loads all thread history, so skip events that cannot change the summary.
134+
function shouldRefreshThreadShellSummary(event: OrchestrationEvent): boolean {
135+
if (event.type === "thread.message-sent") {
136+
return event.payload.role === "user";
137+
}
138+
139+
if (event.type !== "thread.activity-appended") {
140+
return true;
141+
}
142+
143+
switch (event.payload.activity.kind) {
144+
case "approval.requested":
145+
case "approval.resolved":
146+
case "provider.approval.respond.failed":
147+
case "user-input.requested":
148+
case "user-input.resolved":
149+
case "provider.user-input.respond.failed":
150+
return true;
151+
default:
152+
return false;
153+
}
154+
}
155+
133156
function derivePendingUserInputCountFromActivities(
134157
activities: ReadonlyArray<ProjectionThreadActivity>,
135158
): number {
@@ -865,7 +888,9 @@ const makeOrchestrationProjectionPipeline = Effect.fn("makeOrchestrationProjecti
865888
...existingRow.value,
866889
updatedAt: event.occurredAt,
867890
});
868-
yield* refreshThreadShellSummary(event.payload.threadId);
891+
if (shouldRefreshThreadShellSummary(event)) {
892+
yield* refreshThreadShellSummary(event.payload.threadId);
893+
}
869894
return;
870895
}
871896

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

Lines changed: 112 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
1-
import { describe, expect, it } from "vite-plus/test";
1+
import { EnvironmentId } from "@t3tools/contracts";
2+
import { renderToStaticMarkup } from "react-dom/server";
3+
import { describe, expect, it, vi } from "vite-plus/test";
24

3-
import { orderedListGutterStyle } from "./ChatMarkdown";
5+
vi.mock("@effect/atom-react", () => ({ useAtomValue: () => null }));
6+
vi.mock("../hooks/useTheme", () => ({ useTheme: () => ({ resolvedTheme: "dark" }) }));
7+
vi.mock("../state/use-atom-query-runner", () => ({ useAtomQueryRunner: () => vi.fn() }));
8+
vi.mock("../state/use-atom-command", () => ({ useAtomCommand: () => vi.fn() }));
9+
vi.mock("../state/session", async (importOriginal) => ({
10+
...(await importOriginal<typeof import("../state/session")>()),
11+
usePreparedConnection: () => ({ _tag: "Loading" }),
12+
}));
13+
vi.mock("../state/entities", () => ({
14+
useActiveEnvironmentId: () => EnvironmentId.make("env-windows"),
15+
}));
16+
vi.mock("../editorPreferences", () => ({ useOpenInPreferredEditor: () => vi.fn() }));
17+
vi.mock("~/lib/openPullRequestLink", () => ({ useOpenChangeRequestLink: () => vi.fn() }));
18+
19+
import ChatMarkdown, { orderedListGutterStyle } from "./ChatMarkdown";
420

521
describe("orderedListGutterStyle", () => {
622
it("leaves the default gutter alone for single-digit lists", () => {
@@ -42,3 +58,97 @@ describe("orderedListGutterStyle", () => {
4258
expect(orderedListGutterStyle(0, 100)).toEqual({ "--list-gutter": "4ch" });
4359
});
4460
});
61+
62+
describe("ChatMarkdown Windows file links", () => {
63+
it.each([true, false])("preserves drive paths with parseRawHtml=%s", (parseRawHtml) => {
64+
const html = renderToStaticMarkup(
65+
<ChatMarkdown
66+
cwd="C:/Users/shawn/project"
67+
text="[Open](C:/Users/shawn/project/src/main.ts)"
68+
lineBreaks={!parseRawHtml}
69+
parseRawHtml={parseRawHtml}
70+
/>,
71+
);
72+
73+
expect(html).toContain('href="C:/Users/shawn/project/src/main.ts"');
74+
expect(html).toContain("chat-markdown-file-link");
75+
});
76+
77+
it.each([true, false])("normalizes backslashes with parseRawHtml=%s", (parseRawHtml) => {
78+
const html = renderToStaticMarkup(
79+
<ChatMarkdown
80+
cwd="C:/Users/shawn/project"
81+
text={String.raw`[Open](C:\Users\shawn\project\src\main.ts)`}
82+
lineBreaks={!parseRawHtml}
83+
parseRawHtml={parseRawHtml}
84+
/>,
85+
);
86+
87+
expect(html).toContain('href="C:/Users/shawn/project/src/main.ts"');
88+
expect(html).toContain("chat-markdown-file-link");
89+
});
90+
91+
it.each([true, false])(
92+
"distinguishes same-named backslash paths with parseRawHtml=%s",
93+
(parseRawHtml) => {
94+
const html = renderToStaticMarkup(
95+
<ChatMarkdown
96+
cwd="C:/Users/shawn/project"
97+
text={String.raw`[Source](C:\Users\shawn\project\src\index.ts) and [Test](C:\Users\shawn\project\test\index.ts)`}
98+
lineBreaks={!parseRawHtml}
99+
parseRawHtml={parseRawHtml}
100+
/>,
101+
);
102+
103+
expect(html).toContain("index.ts · project/src");
104+
expect(html).toContain("index.ts · project/test");
105+
},
106+
);
107+
108+
it.each([true, false])(
109+
"does not disambiguate the same file in links and inline code with parseRawHtml=%s",
110+
(parseRawHtml) => {
111+
const path = String.raw`C:\Users\shawn\project\src\main.ts`;
112+
const html = renderToStaticMarkup(
113+
<ChatMarkdown
114+
cwd="C:/Users/shawn/project"
115+
text={`[Source](${path}) and \`${path}\``}
116+
lineBreaks={!parseRawHtml}
117+
parseRawHtml={parseRawHtml}
118+
/>,
119+
);
120+
121+
expect(html.match(/chat-markdown-file-link/g)).toHaveLength(2);
122+
expect(html).not.toContain("main.ts ·");
123+
},
124+
);
125+
126+
it.each([true, false])("preserves reference links with parseRawHtml=%s", (parseRawHtml) => {
127+
const html = renderToStaticMarkup(
128+
<ChatMarkdown
129+
cwd="C:/Users/shawn/project"
130+
text={"[Open][source]\n\n[source]: C:/Users/shawn/project/src/main.ts"}
131+
lineBreaks={!parseRawHtml}
132+
parseRawHtml={parseRawHtml}
133+
/>,
134+
);
135+
136+
expect(html).toContain('href="C:/Users/shawn/project/src/main.ts"');
137+
expect(html).toContain("chat-markdown-file-link");
138+
});
139+
140+
it.each([true, false])("still rejects unsafe schemes with parseRawHtml=%s", (parseRawHtml) => {
141+
const html = renderToStaticMarkup(
142+
<ChatMarkdown
143+
cwd="C:/Users/shawn/project"
144+
text="[unsafe](javascript:alert(1)) and [unknown](d:alert(1))"
145+
lineBreaks={!parseRawHtml}
146+
parseRawHtml={parseRawHtml}
147+
/>,
148+
);
149+
150+
expect(html).not.toContain("javascript:");
151+
expect(html).not.toContain("d:alert");
152+
expect(html).not.toContain("chat-markdown-file-link");
153+
});
154+
});

0 commit comments

Comments
 (0)