Skip to content

Commit fdd2173

Browse files
Merge remote-tracking branch 'origin/main' into pr-32334
2 parents 652dcb7 + 1fed70c commit fdd2173

62 files changed

Lines changed: 2494 additions & 256 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/mobile/global.css‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
/* ─── Theme tokens ──────────────────────────────────────────────────── */
66
@layer theme {
77
:root {
8+
/* Native text takes one family name, not Tailwind's font stack. */
9+
@variant ios {
10+
--font-mono: "ui-monospace";
11+
}
812
@variant android {
913
--font-mono: "monospace";
1014
}

‎apps/mobile/src/features/threads/subagent-card-presentation.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe("subagent card", () => {
2222
expect(subagentCardElapsed([unfinished], DateTime.toEpochMillis(later))).toBeNull();
2323
expect(
2424
subagentCardElapsed([{ ...unfinished, status: "running" }], DateTime.toEpochMillis(later)),
25-
).toBe("2m");
25+
).toBe("2m 0s");
2626
expect(
2727
subagentCardElapsed([{ ...unfinished, status: "idle" }], DateTime.toEpochMillis(later)),
2828
).toBeNull();

‎apps/mobile/src/features/threads/thread-work-log.tsx‎

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
useEffect,
2626
useId,
2727
useLayoutEffect,
28+
useMemo,
2829
useRef,
2930
useState,
3031
type ComponentProps,
@@ -36,6 +37,7 @@ import {
3637
Pressable,
3738
ScrollView,
3839
StyleSheet,
40+
Text as RNText,
3941
useAnimatedValue,
4042
View,
4143
} from "react-native";
@@ -54,6 +56,11 @@ import { useAtomCommand } from "../../state/use-atom-command";
5456
import { toolActivityFaviconUrl } from "@t3tools/shared/favicon";
5557
import { isJavaScriptReplTool } from "@t3tools/shared/toolActivity";
5658
import { useMarkdownCodeHighlight } from "./markdownCodeHighlightState";
59+
import { highlightCommand, type HighlightedLines } from "../../lib/highlights";
60+
import {
61+
commandHighlightLanguage,
62+
withVisibleControlCharacters,
63+
} from "@t3tools/client-runtime/work-log/command-label";
5764

5865
import { AppText as Text } from "../../components/ui/AppText";
5966
import { T3Wordmark } from "../../components/T3Wordmark";
@@ -807,6 +814,31 @@ function ToolCodeText({
807814
readonly theme: "light" | "dark";
808815
}) {
809816
const lines = useMarkdownCodeHighlight({ code, language, theme, enabled: true });
817+
return <HighlightedCodeText code={code} lines={lines} />;
818+
}
819+
820+
function CommandCodeText({
821+
command,
822+
theme,
823+
}: {
824+
readonly command: string;
825+
readonly theme: "light" | "dark";
826+
}) {
827+
const code = withVisibleControlCharacters(command.trim());
828+
const lines = useMemo(
829+
() => highlightCommand(code, commandHighlightLanguage(code), theme),
830+
[code, theme],
831+
);
832+
return <HighlightedCodeText code={code} lines={lines} />;
833+
}
834+
835+
function HighlightedCodeText({
836+
code,
837+
lines,
838+
}: {
839+
readonly code: string;
840+
readonly lines: HighlightedLines | null;
841+
}) {
810842
let offset = 0;
811843
const highlighted = lines?.flatMap((line, lineIndex) => {
812844
const separator = lineIndex > 0 ? "\n" : "";
@@ -816,10 +848,11 @@ function ToolCodeText({
816848
...line.map((token) => {
817849
const start = offset;
818850
offset += token.content.length;
851+
// Plain RN Text inherits the mono font; AppText would reset it to sans.
819852
return (
820-
<Text key={start} style={token.color ? { color: token.color } : undefined}>
853+
<RNText key={start} style={token.color ? { color: token.color } : undefined}>
821854
{token.content}
822-
</Text>
855+
</RNText>
823856
);
824857
}),
825858
];
@@ -1179,7 +1212,13 @@ const ThreadWorkLogRow = function ThreadWorkLogRow(
11791212
props.renderReasoning(reasoning.text)
11801213
) : call ? (
11811214
[
1182-
call.command,
1215+
call.command ? (
1216+
<CommandCodeText
1217+
key="command"
1218+
command={call.command}
1219+
theme={props.themeAppearance}
1220+
/>
1221+
) : null,
11831222
...(call.args ?? []).map(([key, value]) => {
11841223
const language =
11851224
key === "html"

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { pierreDark, pierreLight } from "@pierre/highlights/themes";
33
import { describe, expect, it, vi } from "vite-plus/test";
44

55
import { resolveHighlightLanguage } from "./highlightLanguage";
6-
import { highlightCode, tokenizeCode } from "./highlights";
6+
import { highlightCode, highlightCommand, tokenizeCode, type HighlightedLines } from "./highlights";
77

88
vi.mock("react-native-nitro-modules", async () => {
99
const { createWasmHighlightsModule } = await import("./highlights.testing");
@@ -37,6 +37,19 @@ describe("highlightCode", () => {
3737
}
3838
});
3939

40+
it("colors a command's embedded script with that script's grammar", () => {
41+
const body = "import json\r\nprint(json.dumps({'ok': True}))";
42+
const code = `python3 - <<'PY'\r\n${body}\r\nPY`;
43+
const colors = (lines: HighlightedLines) =>
44+
lines.map((line) => line.map(({ content, color }) => [content, color]));
45+
const lines = highlightCommand(code, "shellscript", "dark");
46+
47+
expect(lines.map((line) => line.map((token) => token.content).join(""))).toEqual(
48+
code.split("\r\n"),
49+
);
50+
expect(colors(lines.slice(1, 3))).toEqual(colors(highlightCode(body, "python", "dark")));
51+
});
52+
4053
it("keeps an over-long line as one plain token", () => {
4154
const longLine = `const data = "${"x".repeat(1_000)}";`;
4255
const [first, second] = highlightCode(`let a = 1;\n${longLine}`, "typescript", "dark");

‎apps/mobile/src/lib/highlights.ts‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import {
2+
embeddedScripts,
3+
withEmbeddedScripts,
4+
type SyntaxToken,
5+
} from "@t3tools/client-runtime/work-log/embedded-scripts";
16
import type { T3Highlights } from "@t3tools/mobile-highlights-native";
27
import { NitroModules } from "react-native-nitro-modules";
38

@@ -82,6 +87,46 @@ export function tokenizeCode(code: string, language: string): TokenizedCode {
8287
};
8388
}
8489

90+
/** Shell commands also color the scripts they embed, such as heredocs and `python -c`. */
91+
export function highlightCommand(
92+
code: string,
93+
language: "shellscript" | "powershell",
94+
scheme: HighlightScheme,
95+
): HighlightedLines {
96+
const tokenize = (text: string, lang: string) => {
97+
// A missing grammar keeps the shell colors, as on web.
98+
if (highlightLanguageId(lang) === 0) throw new Error(`No grammar for ${lang}`);
99+
return withOffsets(text, highlightCode(text, lang, scheme));
100+
};
101+
const embedded = language === "shellscript" ? embeddedScripts(code) : [];
102+
return withEmbeddedScripts(code, tokenize(code, language), embedded, tokenize).map((line) =>
103+
line.map((token) => ({
104+
content: token.content,
105+
color: token.color ?? null,
106+
fontStyle: token.fontStyle ?? null,
107+
})),
108+
);
109+
}
110+
111+
function withOffsets(code: string, lines: HighlightedLines): SyntaxToken[][] {
112+
const endings = code.match(/\r?\n/gu) ?? [];
113+
let offset = 0;
114+
return lines.map((line, index) => {
115+
const tokens = line.map((token) => {
116+
const start = offset;
117+
offset += token.content.length;
118+
return {
119+
content: token.content,
120+
offset: start,
121+
...(token.color ? { color: token.color } : {}),
122+
...(token.fontStyle ? { fontStyle: token.fontStyle } : {}),
123+
};
124+
});
125+
offset += endings[index]?.length ?? 0;
126+
return tokens;
127+
});
128+
}
129+
85130
/** LF and CRLF split lines; a trailing line break yields a final empty line. */
86131
export function highlightCode(
87132
code: string,

‎apps/server/src/git/GitWorkflowService.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import { withWorkspaceLease } from "../workspace/workspaceLease.ts";
3737
export class GitWorkflowService extends Context.Service<
3838
GitWorkflowService,
3939
{
40-
readonly isRepository: (cwd: string) => Effect.Effect<boolean, GitManagerServiceError>;
40+
readonly repositoryRoot: (cwd: string) => Effect.Effect<string | null, GitManagerServiceError>;
4141
readonly hasCommit: (input: {
4242
readonly cwd: string;
4343
readonly refName: string;
@@ -271,13 +271,13 @@ export const make = Effect.gen(function* () {
271271
ensureGit(operation, input.cwd).pipe(Effect.andThen(run(input)));
272272

273273
return GitWorkflowService.of({
274-
isRepository: Effect.fn("GitWorkflowService.isRepository")(function (cwd) {
274+
repositoryRoot: Effect.fn("GitWorkflowService.repositoryRoot")(function (cwd) {
275275
return registry.detect({ cwd }).pipe(
276-
Effect.map((handle) => handle?.kind === "git"),
276+
Effect.map((handle) => (handle?.kind === "git" ? handle.repository.rootPath : null)),
277277
Effect.mapError(
278278
(cause) =>
279279
new GitManagerError({
280-
operation: "GitWorkflowService.isRepository",
280+
operation: "GitWorkflowService.repositoryRoot",
281281
cwd,
282282
detail: "Failed to detect a VCS repository for this Git workflow.",
283283
cause,

0 commit comments

Comments
 (0)