GeezerVison is showing github.com — Merge remote-tracking branch 'github/main' into takeover-24205 · pingdotgg/t3code@7c223ec
File treeExpand file treeCollapse file tree Open diff view settings server/src/orchestration-v2/Adapters
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/files/FileMarkdownPreview.tsx +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -2,6 +2,7 @@ import { settlePromise } from "@t3tools/client-runtime/state/runtime"; | 2 | 2 | import type { EnvironmentId, ThreadId } from "@t3tools/contracts"; | 3 | 3 | import { resolveMobileMarkdownMediaSource } from "../../lib/markdownMediaSource"; | 4 | 4 | import { getBrowseDirectoryPath } from "@t3tools/client-runtime/state/projects"; | | 5 | +import { maskMarkdownFrontmatter } from "@t3tools/shared/markdownFrontmatter"; | 5 | 6 | import { useState } from "react"; | 6 | 7 | import { StackActions, useNavigation } from "@react-navigation/native"; | 7 | 8 | import { RefreshControl, ScrollView, View } from "react-native"; | @@ -235,7 +236,7 @@ export function FileMarkdownPreview(props: { | 235 | 236 | > | 236 | 237 | <View className="mx-auto w-full max-w-[760px]"> | 237 | 238 | <SelectableMarkdownText | 238 | | - markdown={props.markdown} | | 239 | + markdown={maskMarkdownFrontmatter(props.markdown)} | 239 | 240 | fileEmbedLabel={(href) => | 240 | 241 | markdownFileEmbedLabel( | 241 | 242 | href, | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/lib/markdownDocument.ts +54-4Lines changed: 54 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import type { Root, RootContent } from "mdast"; | 2 | | -import { unified } from "unified"; | | 2 | +import { unified, type Processor } from "unified"; | 3 | 3 | import remarkParse from "remark-parse"; | 4 | 4 | import remarkGfm from "remark-gfm"; | | 5 | +import { isWindowsAbsolutePath } from "@t3tools/shared/path"; | 5 | 6 |
| 6 | 7 | const parser = unified().use(remarkParse).use(remarkGfm); | 7 | 8 | export type MarkdownNode = Root | RootContent; | @@ -382,13 +383,62 @@ export function markdownWithTableBreaks(markdown: string): string { | 382 | 383 | return transformNativeMarkdown(markdown, undefined, true); | 383 | 384 | } | 384 | 385 |
| | 386 | +// `>` covers a destination continued on a blockquote line. | | 387 | +const WINDOWS_DESTINATION = /\](?:\(|:)[\s>]*<?(?:[A-Za-z]:[\\/]|\\\\)/; | | 388 | + | | 389 | +interface DestinationToken { | | 390 | + readonly start: { readonly offset: number }; | | 391 | + readonly end: { readonly offset: number }; | | 392 | +} | | 393 | + | | 394 | +/** | | 395 | + * Markdown reads `C:\work\.t3` as `C:\work.t3`. Web keeps authored Windows destinations | | 396 | + * literally (see `remarkKeepWindowsPaths` in shared), so escape their backslashes to give | | 397 | + * both parsers here the same path. `\&` stays an escape, as `markdownWithHtml` emits it. | | 398 | + * Expects authored Markdown: already escaped output would be escaped twice. | | 399 | + */ | | 400 | +function markdownWithWindowsPathDestinations(markdown: string): string { | | 401 | + // Skips the extra parse for the common message that has no Windows destination. | | 402 | + if (!WINDOWS_DESTINATION.test(markdown)) return markdown; | | 403 | + const edits: MarkdownEdit[] = []; | | 404 | + function record( | | 405 | + this: { resume(): string; sliceSerialize(token: DestinationToken): string }, | | 406 | + token: DestinationToken, | | 407 | + ) { | | 408 | + this.resume(); | | 409 | + const authored = this.sliceSerialize(token); | | 410 | + if (!isWindowsAbsolutePath(authored) || !authored.includes("\\") || /[<>]/.test(authored)) | | 411 | + return; | | 412 | + const start = token.start.offset; | | 413 | + const end = token.end.offset; | | 414 | + const escaped = authored.replace(/\\(?!&)/g, "\\\\"); | | 415 | + // A bare destination ends at an unescaped `)`, so wrap it to keep `\)` inside. | | 416 | + const angled = markdown[start - 1] === "<"; | | 417 | + edits.push({ start, end, content: angled ? escaped : `<${escaped}>` }); | | 418 | + } | | 419 | + unified() | | 420 | + .use(remarkParse) | | 421 | + .use(remarkGfm) | | 422 | + .use(function (this: Processor) { | | 423 | + (this.data().fromMarkdownExtensions ??= []).push({ | | 424 | + exit: { resourceDestinationString: record, definitionDestinationString: record }, | | 425 | + }); | | 426 | + }) | | 427 | + .parse(markdown); | | 428 | + return applyMarkdownEdits(markdown, edits); | | 429 | +} | | 430 | + | | 431 | +// HTML wrappers can expose Markdown that wasn't in the first AST, so normalize them first. | | 432 | +export function markdownForNativeParsing(markdown: string): string { | | 433 | + return markdownWithWindowsPathDestinations(markdownWithHtml(markdown)); | | 434 | +} | | 435 | + | 385 | 436 | export function parseMarkdownDocument(markdown: string): Root { | 386 | | - return parser.parse(markdownWithHtml(markdown)); | | 437 | + return parser.parse(markdownForNativeParsing(markdown)); | 387 | 438 | } | 388 | 439 |
| 389 | 440 | export function markdownForNativeRendering(markdown: string, fileLink: RegExp): string { | 390 | | - // HTML wrappers can expose Markdown that wasn't in the first AST, so normalize them first. | 391 | | - return transformNativeMarkdown(markdownWithHtml(markdown), fileLink, true); | | 441 | + return transformNativeMarkdown(markdownForNativeParsing(markdown), fileLink, true); | 392 | 442 | } | 393 | 443 |
| 394 | 444 | /** Native media slots only cover standalone images; nested file embeds must become links. */ | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/lib/markdownHtml.test.ts +34Lines changed: 34 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { describe, expect, it } from "vite-plus/test"; | 2 | 2 | import { | | 3 | + markdownForNativeRendering, | 3 | 4 | markdownHtmlContent, | 4 | 5 | markdownWithHtml, | 5 | 6 | markdownWithFileEmbeds, | @@ -9,6 +10,7 @@ import { | 9 | 10 | import { markdownImageSources } from "./markdownImageSources"; | 10 | 11 | import { markdownFileEmbedLabel, resolveMarkdownMediaPreview } from "./markdownMedia"; | 11 | 12 | import { resolveMarkdownLinkPresentation } from "./markdownLinks"; | | 13 | +import { ENRICHED_INLINE_FILE_LINK_REGEX } from "./enrichedLinkPresentation"; | 12 | 14 | import { EnvironmentId, ThreadId } from "@t3tools/contracts"; | 13 | 15 | import { parseMarkdown } from "react-native-enriched-markdown/src/web/parseMarkdown"; | 14 | 16 |
| @@ -296,3 +298,35 @@ describe("file embeds in native thread and file Markdown", () => { | 296 | 298 | expect(converted.fileHrefs.has(href)).toBe(true); | 297 | 299 | }); | 298 | 300 | }); | | 301 | + | | 302 | +describe("Windows paths in native Markdown", () => { | | 303 | + // regression: #23722 Markdown escapes ate the separator before `.t3` and `_build` | | 304 | + it("keeps backslashes in Windows image and link destinations", async () => { | | 305 | + const image = String.raw`C:\work\.t3\_build\shot.png`; | | 306 | + const link = String.raw`\\server\share\.t3\notes.md`; | | 307 | + const markdown = [ | | 308 | + ``, | | 309 | + String.raw`b.png)`, | | 310 | + `[notes](<${link}>)`, | | 311 | + `<img src="${image}">`, | | 312 | + String.raw``, | | 313 | + String.raw`<img src="C:\R&D\.t3\b.png">`, | | 314 | + "> ", | | 315 | + ].join("\n\n"); | | 316 | + | | 317 | + const native = await parseMarkdown( | | 318 | + markdownForNativeRendering(markdown, ENRICHED_INLINE_FILE_LINK_REGEX), | | 319 | + ); | | 320 | + const urls: string[] = []; | | 321 | + const collect = (node: { attributes?: { url?: string }; children?: unknown[] }) => { | | 322 | + if (node.attributes?.url) urls.push(node.attributes.url); | | 323 | + node.children?.forEach((child) => collect(child as typeof node)); | | 324 | + }; | | 325 | + collect(native); | | 326 | + const paren = String.raw`C:\a\)b.png`; | | 327 | + const amp = String.raw`C:\R&D\.t3\a&b.png`; | | 328 | + const htmlAmp = String.raw`C:\R&D\.t3\b.png`; | | 329 | + expect(urls).toEqual([image, paren, link, image, amp, htmlAmp, image]); | | 330 | + expect(markdownImageSources(markdown)).toEqual([image, paren, amp, htmlAmp]); | | 331 | + }); | | 332 | +}); |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/lib/markdownInlineFileLinks.test.ts +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -7,7 +7,6 @@ import { ENRICHED_INLINE_FILE_LINK_REGEX } from "./enrichedLinkPresentation"; | 7 | 7 | import { | 8 | 8 | markdownForNativeRendering, | 9 | 9 | markdownWithInlineFileLinks, | 10 | | - parseMarkdownDocument, | 11 | 10 | markdownWithHtml, | 12 | 11 | } from "./markdownDocument"; | 13 | 12 |
| @@ -87,7 +86,7 @@ describe("inline code that names a file", () => { | 87 | 86 |
| 88 | 87 | it("links to the exact path when it holds backslashes or ampersands", () => { | 89 | 88 | for (const path of ["C:\\repo\\_private\\file.ts", "./src/a©.ts", "./src/[id].ts"]) { | 90 | | - const paragraph = parseMarkdownDocument(rewrite(`\`${path}\``)).children[0]; | | 89 | + const paragraph = parser.parse(rewrite(`\`${path}\``)).children[0]; | 91 | 90 | const link = paragraph?.type === "paragraph" ? paragraph.children[0] : undefined; | 92 | 91 | expect(link?.type === "link" && link.url).toBe(path); | 93 | 92 | expect( | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/lib/markdownLinks.ts +1-5Lines changed: 1 addition & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -265,11 +265,7 @@ export function resolveMarkdownLinkPresentation(href: string): MarkdownLinkPrese | 265 | 265 | } | 266 | 266 | } catch {} | 267 | 267 |
| 268 | | - const target = | 269 | | - parseMarkdownFileLink(normalized) ?? | 270 | | - (/^(?:[A-Za-z0-9._-]+(?: +[A-Za-z0-9._-]+)*\/)+$/.test(normalized) | 271 | | - ? { path: normalized } | 272 | | - : null); | | 268 | + const target = parseMarkdownFileLink(normalized); | 273 | 269 | if (target) { | 274 | 270 | return { | 275 | 271 | kind: "file", | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/native/EnrichedMarkdownText.tsx +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 7 | 7 | import { | 8 | 8 | markdownForNativeRendering, | 9 | 9 | markdownWithFileEmbeds, | 10 | | - markdownWithHtml, | | 10 | + markdownForNativeParsing, | 11 | 11 | markdownWithInlineFileLinks, | 12 | 12 | markdownWithTableBreaks, | 13 | 13 | } from "../lib/markdownDocument"; | @@ -165,7 +165,7 @@ export function MobileEnrichedMarkdownText(props: SelectableMarkdownTextProps) { | 165 | 165 | }; | 166 | 166 | } | 167 | 167 | const content = markdownWithInlineFileLinks( | 168 | | - markdownWithHtml(props.markdown), | | 168 | + markdownForNativeParsing(props.markdown), | 169 | 169 | ENRICHED_INLINE_FILE_LINK_REGEX, | 170 | 170 | ); | 171 | 171 | const files = markdownWithFileEmbeds(content, fileEmbedLabel); | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts +132Lines changed: 132 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -5077,6 +5077,138 @@ describe("ClaudeAdapterV2 background wake turns", () => { | 5077 | 5077 | ), | 5078 | 5078 | ); | 5079 | 5079 |
| | 5080 | + it.effect("an interrupted turn after a rollback stops resuming at the rolled-back head", () => | | 5081 | + Effect.gen(function* () { | | 5082 | + const harness = yield* makeWakeHarnessWithOptions({ | | 5083 | + close: (sdkMessages) => Queue.shutdown(sdkMessages), | | 5084 | + freshQueueOnReopen: true, | | 5085 | + }); | | 5086 | + const now = yield* DateTime.now; | | 5087 | + const pinnedHead = "00000000-0000-4000-8000-000000025510"; | | 5088 | + const pinnedThread = { | | 5089 | + ...harness.providerThread, | | 5090 | + nativeConversationHeadRef: { | | 5091 | + driver: ClaudeAdapterV2.CLAUDE_PROVIDER, | | 5092 | + nativeId: pinnedHead, | | 5093 | + strength: "weak" as const, | | 5094 | + }, | | 5095 | + }; | | 5096 | + const interruptedInput = makeClaudeTestTurnInput({ | | 5097 | + threadId: harness.threadId, | | 5098 | + providerThread: pinnedThread, | | 5099 | + now, | | 5100 | + attemptId: RunAttemptId.make("attempt-claude-interrupt-after-rollback"), | | 5101 | + text: "The secret word is apricot-25510. Then run sleep 60.", | | 5102 | + attachments: [], | | 5103 | + providerTurnOrdinal: 2, | | 5104 | + nativeThreadHasTurns: true, | | 5105 | + }); | | 5106 | + yield* harness.runtime.startTurn(interruptedInput); | | 5107 | + assert.equal(harness.getOpenedOptions()?.resumeSessionAt, pinnedHead); | | 5108 | + yield* harness.offerAndWait( | | 5109 | + makeAssistantTextFrame({ | | 5110 | + uuid: "00000000-0000-4000-8000-000000025511", | | 5111 | + text: "Noted apricot-25510. Running sleep.", | | 5112 | + }), | | 5113 | + ); | | 5114 | + yield* harness.runtime.interruptTurn({ | | 5115 | + providerThread: pinnedThread, | | 5116 | + providerTurnId: (yield* IdAllocator.IdAllocatorV2).derive.providerTurn({ | | 5117 | + driver: ClaudeAdapterV2.CLAUDE_PROVIDER, | | 5118 | + nativeTurnId: `turn:${interruptedInput.attemptId}`, | | 5119 | + }), | | 5120 | + }); | | 5121 | + assert.equal((yield* Queue.take(harness.terminalReceipts)).status, "interrupted"); | | 5122 | + const afterInterrupt = harness.events.findLast( | | 5123 | + (event) => event.type === "provider_thread.updated", | | 5124 | + )?.providerThread; | | 5125 | + assert.isDefined(afterInterrupt); | | 5126 | + assert.isNull(afterInterrupt.nativeConversationHeadRef); | | 5127 | + | | 5128 | + yield* harness.runtime.startTurn( | | 5129 | + makeClaudeTestTurnInput({ | | 5130 | + threadId: harness.threadId, | | 5131 | + providerThread: afterInterrupt, | | 5132 | + now, | | 5133 | + attemptId: RunAttemptId.make("attempt-claude-after-interrupt"), | | 5134 | + text: "What is the secret word?", | | 5135 | + attachments: [], | | 5136 | + providerTurnOrdinal: 3, | | 5137 | + nativeThreadHasTurns: true, | | 5138 | + }), | | 5139 | + ); | | 5140 | + assert.equal(harness.processQueues.length, 2); | | 5141 | + assert.isUndefined(harness.getOpenedOptions()?.resumeSessionAt); | | 5142 | + }).pipe( | | 5143 | + Effect.provide( | | 5144 | + Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer), | | 5145 | + ), | | 5146 | + ), | | 5147 | + ); | | 5148 | + | | 5149 | + it.effect("an interrupted turn with no assistant output keeps the rolled-back head", () => | | 5150 | + Effect.gen(function* () { | | 5151 | + const harness = yield* makeWakeHarnessWithOptions({ | | 5152 | + close: (sdkMessages) => Queue.shutdown(sdkMessages), | | 5153 | + freshQueueOnReopen: true, | | 5154 | + }); | | 5155 | + const now = yield* DateTime.now; | | 5156 | + const pinnedHead = "00000000-0000-4000-8000-000000025510"; | | 5157 | + const pinnedThread = { | | 5158 | + ...harness.providerThread, | | 5159 | + nativeConversationHeadRef: { | | 5160 | + driver: ClaudeAdapterV2.CLAUDE_PROVIDER, | | 5161 | + nativeId: pinnedHead, | | 5162 | + strength: "weak" as const, | | 5163 | + }, | | 5164 | + }; | | 5165 | + const interruptedInput = makeClaudeTestTurnInput({ | | 5166 | + threadId: harness.threadId, | | 5167 | + providerThread: pinnedThread, | | 5168 | + now, | | 5169 | + attemptId: RunAttemptId.make("attempt-claude-silent-interrupt-after-rollback"), | | 5170 | + text: "The secret word is apricot-25510. Then run sleep 60.", | | 5171 | + attachments: [], | | 5172 | + providerTurnOrdinal: 2, | | 5173 | + nativeThreadHasTurns: true, | | 5174 | + }); | | 5175 | + yield* harness.runtime.startTurn(interruptedInput); | | 5176 | + assert.equal(harness.getOpenedOptions()?.resumeSessionAt, pinnedHead); | | 5177 | + yield* harness.runtime.interruptTurn({ | | 5178 | + providerThread: pinnedThread, | | 5179 | + providerTurnId: (yield* IdAllocator.IdAllocatorV2).derive.providerTurn({ | | 5180 | + driver: ClaudeAdapterV2.CLAUDE_PROVIDER, | | 5181 | + nativeTurnId: `turn:${interruptedInput.attemptId}`, | | 5182 | + }), | | 5183 | + }); | | 5184 | + assert.equal((yield* Queue.take(harness.terminalReceipts)).status, "interrupted"); | | 5185 | + const afterInterrupt = harness.events.findLast( | | 5186 | + (event) => event.type === "provider_thread.updated", | | 5187 | + )?.providerThread; | | 5188 | + assert.isDefined(afterInterrupt); | | 5189 | + assert.equal(afterInterrupt.nativeConversationHeadRef?.nativeId, pinnedHead); | | 5190 | + | | 5191 | + yield* harness.runtime.startTurn( | | 5192 | + makeClaudeTestTurnInput({ | | 5193 | + threadId: harness.threadId, | | 5194 | + providerThread: afterInterrupt, | | 5195 | + now, | | 5196 | + attemptId: RunAttemptId.make("attempt-claude-after-silent-interrupt"), | | 5197 | + text: "What is the secret word?", | | 5198 | + attachments: [], | | 5199 | + providerTurnOrdinal: 3, | | 5200 | + nativeThreadHasTurns: true, | | 5201 | + }), | | 5202 | + ); | | 5203 | + assert.equal(harness.processQueues.length, 2); | | 5204 | + assert.equal(harness.getOpenedOptions()?.resumeSessionAt, pinnedHead); | | 5205 | + }).pipe( | | 5206 | + Effect.provide( | | 5207 | + Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer), | | 5208 | + ), | | 5209 | + ), | | 5210 | + ); | | 5211 | + | 5080 | 5212 | it.effect("never records a subagent uuid for a turn with no main-thread assistant message", () => | 5081 | 5213 | Effect.gen(function* () { | 5082 | 5214 | const harness = yield* makeWakeHarnessWithOptions({ | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -7257,8 +7257,9 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( | 7257 | 7257 | yield* Ref.get(awaitedBackgroundTasksByNativeThread), | 7258 | 7258 | nativeThreadId, | 7259 | 7259 | ); | | 7260 | + // A stopped turn that wrote to the transcript moved past the pinned head. | 7260 | 7261 | const clearConversationHead = | 7261 | | - input.status === "completed" && | | 7262 | + (input.status === "completed" || input.context.nativeMessageCursor !== null) && | 7262 | 7263 | input.context.input.providerThread.nativeConversationHeadRef !== null; | 7263 | 7264 | const goal = | 7264 | 7265 | nativeThreadId === null ? undefined : goalsByNativeThread.get(nativeThreadId); | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/chat/ComposerPrimaryActions.tsx +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -378,8 +378,8 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({ | 378 | 378 | } | 379 | 379 | > | 380 | 380 | <Minimize2Icon aria-hidden="true" /> | 381 | | - {/* The token count lives in the tooltip so the permission label keeps its room. */} | 382 | | - {keepFullHistory ? "Keep full" : "Compact next"} | | 381 | + {keepFullHistory ? "Keep" : "Compact"} | | 382 | + <span className="text-muted-foreground">{compactTokens}</span> | 383 | 383 | </TooltipTrigger> | 384 | 384 | <TooltipPopup> | 385 | 385 | <div> | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/files/AttachmentFilePreview.tsx +6-1Lines changed: 6 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -16,6 +16,7 @@ import { lazy, Suspense, useEffect, useRef, useState } from "react"; | 16 | 16 |
| 17 | 17 | import { useAssetUrlRefresh } from "~/assets/assetUrls"; | 18 | 18 | import ChatMarkdown from "~/components/ChatMarkdown"; | | 19 | +import { maskMarkdownFrontmatter } from "@t3tools/shared/markdownFrontmatter"; | 19 | 20 | import { MorphIcon } from "~/components/MorphIcon"; | 20 | 21 | import { ScrollArea } from "~/components/ui/scroll-area"; | 21 | 22 | import { toastManager } from "~/components/ui/toast"; | @@ -281,7 +282,11 @@ export function AttachmentFilePreview(props: { | 281 | 282 | </Suspense> | 282 | 283 | ) : kind === "markdown" && rendered ? ( | 283 | 284 | <ScrollArea className="min-h-0 flex-1"> | 284 | | - <ChatMarkdown text={content.text} cwd={undefined} className="mx-auto max-w-4xl px-6 py-5" /> | | 285 | + <ChatMarkdown | | 286 | + text={maskMarkdownFrontmatter(content.text)} | | 287 | + cwd={undefined} | | 288 | + className="mx-auto max-w-4xl px-6 py-5" | | 289 | + /> | 285 | 290 | </ScrollArea> | 286 | 291 | ) : ( | 287 | 292 | <ReadOnlySourcePreview name={props.name} text={content.text} /> | |
|