Skip to content

Commit ae7a9e7

Browse files
committed
fix(server): repair worktree cleanup test types on main
2 parents 254eca7 + 4ee6bfd commit ae7a9e7

382 files changed

Lines changed: 19723 additions & 3829 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/desktop/src/main.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ for (const stream of [process.stdout, process.stderr]) {
88
import * as NodeHttpClient from "@effect/platform-node/NodeHttpClient";
99
import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
1010
import * as NodeServices from "@effect/platform-node/NodeServices";
11+
// @effect-diagnostics-next-line nodeBuiltinImport:off - Version output must flush before Electron exits, without acquiring the runtime.
12+
import * as NodeFS from "node:fs";
1113
import * as NodeOS from "node:os";
1214
import * as Effect from "effect/Effect";
1315
import * as Layer from "effect/Layer";
@@ -69,6 +71,15 @@ import * as DesktopWslBackend from "./wsl/DesktopWslBackend.ts";
6971
import * as DesktopWslEnvironment from "./wsl/DesktopWslEnvironment.ts";
7072
import * as DesktopWslServerTree from "./wsl/DesktopWslServerTree.ts";
7173

74+
if (process.argv.includes("--version")) {
75+
try {
76+
NodeFS.writeSync(process.stdout.fd, `${Electron.app.getVersion()}\n`);
77+
} catch (error) {
78+
if (!(error instanceof Error) || !("code" in error) || error.code !== "EPIPE") throw error;
79+
}
80+
Electron.app.exit(0);
81+
}
82+
7283
const desktopEnvironmentLayer = Layer.unwrap(
7384
Effect.gen(function* () {
7485
const metadata = yield* Effect.service(ElectronApp.ElectronApp).pipe(

‎apps/desktop/src/settings/DesktopAppSettings.test.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,34 @@ describe("DesktopSettings", () => {
357357
),
358358
);
359359

360+
it.effect("saves through a symlinked settings file without replacing the link", () =>
361+
withSettings(
362+
Effect.gen(function* () {
363+
const environment = yield* DesktopEnvironment.DesktopEnvironment;
364+
const fileSystem = yield* FileSystem.FileSystem;
365+
const settings = yield* DesktopAppSettings.DesktopAppSettings;
366+
const dotfiles = yield* fileSystem.makeTempDirectoryScoped({
367+
prefix: "t3-desktop-settings-dotfiles-",
368+
});
369+
const linkedSettingsPath = `${dotfiles}/desktop-settings.json`;
370+
yield* fileSystem.writeFileString(linkedSettingsPath, "{}\n");
371+
yield* fileSystem.makeDirectory(environment.stateDir, { recursive: true });
372+
yield* fileSystem.symlink(linkedSettingsPath, environment.desktopSettingsPath);
373+
374+
yield* settings.setServerExposureMode("network-accessible");
375+
376+
assert.equal(
377+
yield* fileSystem.readLink(environment.desktopSettingsPath),
378+
linkedSettingsPath,
379+
);
380+
const persisted = yield* decodeDesktopSettingsPatch(
381+
yield* fileSystem.readFileString(linkedSettingsPath),
382+
);
383+
assert.equal(persisted.serverExposureMode, "network-accessible");
384+
}),
385+
),
386+
);
387+
360388
it.effect("migrates legacy implicit update channels to the runtime default", () =>
361389
withSettings(
362390
Effect.gen(function* () {

‎apps/desktop/src/settings/DesktopAppSettings.ts‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
type DesktopUpdateChannel,
66
} from "@t3tools/contracts";
77
import { fromLenientJson } from "@t3tools/shared/schemaJson";
8+
import { resolveSymlinkTarget } from "@t3tools/shared/symlink";
89
import * as Context from "effect/Context";
910
import * as Crypto from "effect/Crypto";
1011
import * as Effect from "effect/Effect";
@@ -130,6 +131,7 @@ const settingsChange = (settings: DesktopSettings, changed: boolean): DesktopSet
130131

131132
const DesktopSettingsWriteOperation = Schema.Literals([
132133
"create-temporary-file-name",
134+
"resolve-symlink",
133135
"encode-document",
134136
"create-directory",
135137
"write-temporary-file",
@@ -421,8 +423,20 @@ const writeSettings = Effect.fn("desktop.settings.writeSettings")(function* (inp
421423
readonly defaultSettings: DesktopSettings;
422424
readonly suffix: string;
423425
}): Effect.fn.Return<void, DesktopSettingsWriteError> {
424-
const directory = input.path.dirname(input.settingsPath);
425-
const tempPath = `${input.settingsPath}.${process.pid}.${input.suffix}.tmp`;
426+
const targetPath = yield* resolveSymlinkTarget(input.settingsPath).pipe(
427+
Effect.provideService(FileSystem.FileSystem, input.fileSystem),
428+
Effect.provideService(Path.Path, input.path),
429+
Effect.mapError(
430+
(cause) =>
431+
new DesktopSettingsWriteError({
432+
operation: "resolve-symlink",
433+
path: input.settingsPath,
434+
cause,
435+
}),
436+
),
437+
);
438+
const directory = input.path.dirname(targetPath);
439+
const tempPath = `${targetPath}.${process.pid}.${input.suffix}.tmp`;
426440
const encoded = yield* encodeDesktopSettingsJson(
427441
toDesktopSettingsDocument(input.settings, input.defaultSettings),
428442
).pipe(
@@ -455,7 +469,7 @@ const writeSettings = Effect.fn("desktop.settings.writeSettings")(function* (inp
455469
}),
456470
),
457471
);
458-
yield* input.fileSystem.rename(tempPath, input.settingsPath).pipe(
472+
yield* input.fileSystem.rename(tempPath, targetPath).pipe(
459473
Effect.mapError(
460474
(cause) =>
461475
new DesktopSettingsWriteError({

‎apps/desktop/src/settings/DesktopClientSettings.test.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,34 @@ describe("DesktopClientSettings", () => {
149149
),
150150
);
151151

152+
it.effect("saves through a symlinked client settings file without replacing the link", () =>
153+
withClientSettings(
154+
Effect.gen(function* () {
155+
const environment = yield* DesktopEnvironment.DesktopEnvironment;
156+
const fileSystem = yield* FileSystem.FileSystem;
157+
const settings = yield* DesktopClientSettings.DesktopClientSettings;
158+
const dotfiles = yield* fileSystem.makeTempDirectoryScoped({
159+
prefix: "t3-desktop-client-settings-dotfiles-",
160+
});
161+
const linkedSettingsPath = `${dotfiles}/client-settings.json`;
162+
yield* fileSystem.writeFileString(linkedSettingsPath, "{}\n");
163+
yield* fileSystem.makeDirectory(environment.stateDir, { recursive: true });
164+
yield* fileSystem.symlink(linkedSettingsPath, environment.clientSettingsPath);
165+
166+
yield* settings.set(clientSettings);
167+
168+
assert.equal(
169+
yield* fileSystem.readLink(environment.clientSettingsPath),
170+
linkedSettingsPath,
171+
);
172+
assert.deepEqual(
173+
yield* decodeClientSettingsJson(yield* fileSystem.readFileString(linkedSettingsPath)),
174+
clientSettings,
175+
);
176+
}),
177+
),
178+
);
179+
152180
it.effect.each([
153181
{ label: "permission", reason: "PermissionDenied" },
154182
{ label: "I/O", reason: "Unknown" },

‎apps/desktop/src/settings/DesktopClientSettings.ts‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ClientSettingsSchema, type ClientSettings } from "@t3tools/contracts";
22
import { fromLenientJson } from "@t3tools/shared/schemaJson";
3+
import { resolveSymlinkTarget } from "@t3tools/shared/symlink";
34
import * as Context from "effect/Context";
45
import * as Crypto from "effect/Crypto";
56
import * as Effect from "effect/Effect";
@@ -41,6 +42,7 @@ export class DesktopClientSettingsReadError extends Schema.TaggedError<DesktopCl
4142

4243
const DesktopClientSettingsWriteOperation = Schema.Literals([
4344
"create-temporary-file-name",
45+
"resolve-symlink",
4446
"encode-document",
4547
"create-directory",
4648
"write-temporary-file",
@@ -126,8 +128,20 @@ const writeClientSettings = Effect.fnUntraced(function* (input: {
126128
readonly settings: ClientSettings;
127129
readonly suffix: string;
128130
}): Effect.fn.Return<void, DesktopClientSettingsWriteError> {
129-
const directory = input.path.dirname(input.settingsPath);
130-
const tempPath = `${input.settingsPath}.${process.pid}.${input.suffix}.tmp`;
131+
const targetPath = yield* resolveSymlinkTarget(input.settingsPath).pipe(
132+
Effect.provideService(FileSystem.FileSystem, input.fileSystem),
133+
Effect.provideService(Path.Path, input.path),
134+
Effect.mapError(
135+
(cause) =>
136+
new DesktopClientSettingsWriteError({
137+
operation: "resolve-symlink",
138+
path: input.settingsPath,
139+
cause,
140+
}),
141+
),
142+
);
143+
const directory = input.path.dirname(targetPath);
144+
const tempPath = `${targetPath}.${process.pid}.${input.suffix}.tmp`;
131145
const encoded = yield* encodeClientSettingsJson(input.settings).pipe(
132146
Effect.mapError(
133147
(cause) =>
@@ -158,7 +172,7 @@ const writeClientSettings = Effect.fnUntraced(function* (input: {
158172
}),
159173
),
160174
);
161-
yield* input.fileSystem.rename(tempPath, input.settingsPath).pipe(
175+
yield* input.fileSystem.rename(tempPath, targetPath).pipe(
162176
Effect.mapError(
163177
(cause) =>
164178
new DesktopClientSettingsWriteError({

‎apps/mobile/app.config.ts‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ const config: ExpoConfig = {
306306
// JS back handling survives it via react-native's Android 16 shim plus
307307
// withAndroidPredictiveBackCompat on Android 13-15.
308308
predictiveBackGestureEnabled: true,
309+
// expo-sensors declares this for its pedometer, which the app does not use.
310+
blockedPermissions: ["android.permission.ACTIVITY_RECOGNITION"],
309311
},
310312
web: {
311313
favicon: variant.assets.appIcon,
@@ -418,7 +420,16 @@ const config: ExpoConfig = {
418420
minSdkVersion: 24,
419421
// kotlinx-io uses Kotlin 2.3's return-value checker annotation, while
420422
// SDK 58 builds with Kotlin 2.2. It has no runtime behavior.
421-
extraProguardRules: "-dontwarn kotlin.MustUseReturnValues",
423+
//
424+
// WorkManager 2.9 keeps InputMerger classes but not their constructors,
425+
// and R8 full mode no longer keeps a default constructor implicitly.
426+
// Without it no work request can start, so the Glance session behind
427+
// the widget never renders and it stays on "Loading widget". WorkManager
428+
// 2.10 ships this rule itself; drop it once the resolved version gets there.
429+
extraProguardRules: [
430+
"-dontwarn kotlin.MustUseReturnValues",
431+
"-keep class * extends androidx.work.InputMerger { <init>(); }",
432+
].join("\n"),
422433
},
423434
ios: {
424435
deploymentTarget: "18.0",
@@ -431,6 +442,9 @@ const config: ExpoConfig = {
431442
},
432443
],
433444
"./plugins/withIosCocoaPodsUuidCache.cjs",
445+
// Only the accelerometer is used (device viewer shake). Compile out the
446+
// pedometer so iOS needs no motion purpose string.
447+
["expo-sensors", { motionPermission: false }],
434448
// Must be listed BEFORE expo-widgets: same-type mods run last-registered-
435449
// first, so registering earlier makes this plugin's mods run AFTER
436450
// expo-widgets' — its dangerous mod wipes ios/ExpoWidgetsTarget/ (which

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

Lines changed: 72 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { MarkdownNode } from "react-native-nitro-markdown/headless";
2+
import { isMarkdownFileLinkLabel } from "@t3tools/client-runtime/markdown-links";
23
import { collectComposerInlineTokens } from "@t3tools/shared/composerInlineTokens";
34
import { imageMimeType } from "@t3tools/shared/image";
45
import { isWindowsAbsolutePath } from "@t3tools/shared/path";
@@ -109,19 +110,34 @@ export function nativeMarkdownContextCopyRanges(
109110
}>,
110111
) {
111112
let offset = 0;
112-
return runs.flatMap(({ run, text, inlineImageLength }) => {
113+
const ranges: Array<{ start: number; end: number; text: string }> = [];
114+
for (const [index, { run, text, inlineImageLength }] of runs.entries()) {
113115
const start = offset;
114116
offset += text.length + inlineImageLength;
115117
const reference = parseComposerContextHref(run.href ?? "");
116118
const source = reference
117119
? formatComposerContextReference({ ...reference, label: run.text })
118120
: run.skillName
119121
? `$${run.skillName}`
120-
: run.fileIcon && run.href
121-
? (run.sourceText ?? `[${run.text}](<${run.href}>)`)
122-
: null;
123-
return source === null ? [] : [{ start, end: offset, text: source }];
124-
});
122+
: run.sourceText !== undefined
123+
? run.sourceText
124+
: run.fileIcon && run.href
125+
? `[${run.text}](<${run.href}>)`
126+
: null;
127+
if (source === null) continue;
128+
const previous = ranges.at(-1);
129+
if (
130+
run.sourceText !== undefined &&
131+
!runs[index - 1]?.run.fileIcon &&
132+
previous?.end === start &&
133+
previous.text === source
134+
) {
135+
previous.end = offset;
136+
} else {
137+
ranges.push({ start, end: offset, text: source });
138+
}
139+
}
140+
return ranges;
125141
}
126142

127143
import type { SelectableMarkdownSkill } from "./SelectableMarkdownText.types";
@@ -181,6 +197,7 @@ interface RunContext {
181197
readonly href?: string;
182198
readonly externalHost?: string;
183199
readonly fileIcon?: MarkdownFileIcon;
200+
readonly sourceText?: string;
184201
readonly role?: NativeMarkdownTextRun["role"];
185202
readonly headingLevel?: number;
186203
readonly depth?: number;
@@ -268,6 +285,7 @@ function sameRunStyle(left: NativeMarkdownTextRun, right: NativeMarkdownTextRun)
268285
left.href === right.href &&
269286
left.externalHost === right.externalHost &&
270287
left.fileIcon === right.fileIcon &&
288+
left.sourceText === right.sourceText &&
271289
left.skillName === right.skillName &&
272290
left.skillLabel === right.skillLabel &&
273291
left.role === right.role &&
@@ -298,6 +316,7 @@ function appendRun(
298316
...(context.href ? { href: context.href } : {}),
299317
...(context.externalHost ? { externalHost: context.externalHost } : {}),
300318
...(context.fileIcon ? { fileIcon: context.fileIcon } : {}),
319+
...(context.sourceText !== undefined ? { sourceText: context.sourceText } : {}),
301320
...(context.role ? { role: context.role } : {}),
302321
...(context.headingLevel ? { headingLevel: context.headingLevel } : {}),
303322
...(context.depth ? { depth: context.depth } : {}),
@@ -432,6 +451,36 @@ function nodeTextContent(node: MarkdownNode): string {
432451
return (node.children ?? []).map(nodeTextContent).join("");
433452
}
434453

454+
function fileLinkLabelMarkdown(node: MarkdownNode): string {
455+
const children = (node.children ?? []).map(fileLinkLabelMarkdown).join("");
456+
switch (node.type) {
457+
case "bold":
458+
return `**${children}**`;
459+
case "italic":
460+
return `*${children}*`;
461+
case "strikethrough":
462+
return `~~${children}~~`;
463+
case "code_inline": {
464+
const content = nodeTextContent(node);
465+
const fence = "`".repeat(
466+
Math.max(0, ...(content.match(/`+/g) ?? []).map((run) => run.length)) + 1,
467+
);
468+
const padding = /^`|`$|^ .* $/.test(content) && content.trim().length > 0 ? " " : "";
469+
return `${fence}${padding}${content}${padding}${fence}`;
470+
}
471+
case "soft_break":
472+
return "\n";
473+
case "line_break":
474+
return " \n";
475+
case "text":
476+
return textNodeContent(nodeTextContent(node)).replace(/[\\[\]*_`~]/g, "\\$&");
477+
case "image":
478+
return `![${(node.alt ?? "").replace(/[\\[\]]/g, "\\$&")}](<${node.href ?? ""}>)`;
479+
default:
480+
return node.content ?? children;
481+
}
482+
}
483+
435484
function appendNode(
436485
runs: NativeMarkdownTextRun[],
437486
node: MarkdownNode,
@@ -482,6 +531,23 @@ function appendNode(
482531
}
483532
const presentation = resolveMarkdownLinkPresentation(node.href ?? "");
484533
if (presentation.kind === "file") {
534+
const label = textNodeContent(nodeTextContent(node));
535+
if (!isMarkdownFileLinkLabel(label, presentation.href)) {
536+
const fileRuns: NativeMarkdownTextRun[] = [];
537+
const fileContext = {
538+
...context,
539+
href: presentation.href,
540+
sourceText: `[${fileLinkLabelMarkdown(node)}](<${presentation.href}>)`,
541+
};
542+
appendChildren(fileRuns, node, fileContext);
543+
appendRun(fileRuns, " ", fileContext);
544+
appendRun(fileRuns, presentation.label, {
545+
...fileContext,
546+
fileIcon: presentation.icon,
547+
});
548+
runs.push(...fileRuns);
549+
return runs;
550+
}
485551
return appendRun(runs, presentation.label, {
486552
...context,
487553
href: presentation.href,

‎apps/mobile/modules/t3-native-controls/android/src/main/java/expo/modules/t3nativecontrols/T3KeyboardCommandsModule.kt‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,21 @@ class T3KeyboardCommandsView(
2929
var enabledCommands = emptySet<String>()
3030

3131
override fun dispatchKeyEvent(event: KeyEvent): Boolean {
32-
val copiesThreadReference =
33-
event.action == KeyEvent.ACTION_DOWN &&
34-
event.repeatCount == 0 &&
35-
event.keyCode == KeyEvent.KEYCODE_C &&
36-
event.isCtrlPressed &&
37-
event.isShiftPressed &&
38-
!event.isAltPressed &&
39-
enabledCommands.contains("copyThreadReference")
40-
if (copiesThreadReference) {
41-
onCommand(mapOf("command" to "copyThreadReference"))
42-
return true
32+
val command = commandFor(event)?.takeIf { enabledCommands.contains(it) }
33+
if (command != null) onCommand(mapOf("command" to command))
34+
return command != null || super.dispatchKeyEvent(event)
35+
}
36+
37+
private fun commandFor(event: KeyEvent): String? {
38+
if (event.action != KeyEvent.ACTION_DOWN || event.repeatCount != 0 || !event.isCtrlPressed) {
39+
return null
40+
}
41+
return when {
42+
event.keyCode == KeyEvent.KEYCODE_C && event.isShiftPressed && !event.isAltPressed ->
43+
"copyThreadReference"
44+
event.keyCode == KeyEvent.KEYCODE_H && event.isShiftPressed && !event.isAltPressed ->
45+
"cycleHost"
46+
else -> null
4347
}
44-
return super.dispatchKeyEvent(event)
4548
}
4649
}

0 commit comments

Comments
 (0)