Skip to content

Commit 5751538

Browse files
Merge remote-tracking branch 'origin/main' into feat/settle-running-thread-v2
# Conflicts: # apps/server/src/mcp/toolkits/thread/tools.ts
2 parents 457b1ae + 1a3f7ad commit 5751538

224 files changed

Lines changed: 12730 additions & 2973 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.

‎.github/workflows/release.yml‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1347,6 +1347,24 @@ jobs:
13471347
args:
13481348
- --filter=@t3tools/scripts...
13491349
1350+
- name: Read published release notes
1351+
if: needs.preflight.outputs.is_prerelease == 'true'
1352+
continue-on-error: true
1353+
env:
1354+
GH_TOKEN: ${{ github.token }}
1355+
GH_REPO: ${{ github.repository }}
1356+
RELEASE_TAG: ${{ needs.preflight.outputs.tag }}
1357+
RELEASE_CHANNEL: ${{ needs.preflight.outputs.release_channel }}
1358+
run: |
1359+
if [ "$RELEASE_CHANNEL" = 'nightly' ]; then
1360+
if ! gh release view "$RELEASE_TAG" --json body --jq '.body // ""' > "$RUNNER_TEMP/discord-release-notes.md"; then
1361+
: > "$RUNNER_TEMP/discord-release-notes.md"
1362+
echo '::warning::Could not read published release notes; announcing without a changelog.'
1363+
fi
1364+
else
1365+
: > "$RUNNER_TEMP/discord-release-notes.md"
1366+
fi
1367+
13501368
- name: Announce prerelease on Discord
13511369
if: needs.preflight.outputs.is_prerelease == 'true'
13521370
continue-on-error: true
@@ -1359,7 +1377,8 @@ jobs:
13591377
--release-name "${{ needs.preflight.outputs.release_name }}" \
13601378
--release-version "${{ needs.preflight.outputs.version }}" \
13611379
--tag "${{ needs.preflight.outputs.tag }}" \
1362-
--release-url "https://github.com/${{ github.repository }}/releases/tag/${{ needs.preflight.outputs.tag }}"
1380+
--release-url "https://github.com/${{ github.repository }}/releases/tag/${{ needs.preflight.outputs.tag }}" \
1381+
--release-notes-file "$RUNNER_TEMP/discord-release-notes.md"
13631382
13641383
- name: Announce latest release on Discord
13651384
if: needs.preflight.outputs.make_latest == 'true'

‎apps/desktop/src/app/DesktopApp.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import * as DesktopApplicationMenu from "../window/DesktopApplicationMenu.ts";
1919
import * as DesktopWindow from "../window/DesktopWindow.ts";
2020
import * as DesktopBackendPool from "../backend/DesktopBackendPool.ts";
2121
import * as DesktopEnvironment from "./DesktopEnvironment.ts";
22+
import * as DesktopLegacyLocalStorage from "./DesktopLegacyLocalStorage.ts";
2223
import * as DesktopLifecycle from "./DesktopLifecycle.ts";
2324
import * as DesktopLinuxUrlHandler from "./DesktopLinuxUrlHandler.ts";
2425
import * as DesktopObservability from "./DesktopObservability.ts";
@@ -179,6 +180,10 @@ const bootstrap = Effect.gen(function* () {
179180
});
180181
yield* installDesktopIpcHandlers();
181182
yield* logBootstrapInfo("bootstrap ipc handlers registered");
183+
// Before any window: the preload merges these items before the app reads storage.
184+
yield* (yield* DesktopLegacyLocalStorage.DesktopLegacyLocalStorage).load(
185+
yield* (yield* DesktopAppIdentity.DesktopAppIdentity).resolveUserDataPath,
186+
);
182187

183188
yield* snapShot.initialize;
184189

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import * as Context from "effect/Context";
2+
import * as Effect from "effect/Effect";
3+
import * as FileSystem from "effect/FileSystem";
4+
import * as Layer from "effect/Layer";
5+
import * as Option from "effect/Option";
6+
import * as Path from "effect/Path";
7+
import * as Ref from "effect/Ref";
8+
9+
import * as ElectronProtocol from "../electron/ElectronProtocol.ts";
10+
import { readChromiumLocalStorage } from "./chromiumLocalStorage.ts";
11+
import * as DesktopEnvironment from "./DesktopEnvironment.ts";
12+
13+
/**
14+
* Carries the renderer's localStorage (prompt stash, unsent drafts, layout,
15+
* theme) over from the V1 desktop profile, which V2 replaced with its own
16+
* `t3code-v2` profile. The V1 profile is only read, never opened by Chromium,
17+
* so this works while V1 is still running.
18+
*
19+
* `load` runs before the window opens; the preload takes the items once,
20+
* merges them into the new profile, and calls `complete`, which writes a
21+
* marker so later launches skip the read. A failed read or merge, or a window
22+
* that never completes, leaves no marker and retries next launch.
23+
*/
24+
export class DesktopLegacyLocalStorage extends Context.Service<
25+
DesktopLegacyLocalStorage,
26+
{
27+
readonly load: (userDataPath: string) => Effect.Effect<void>;
28+
readonly take: Effect.Effect<Option.Option<Readonly<Record<string, string>>>>;
29+
readonly complete: Effect.Effect<void>;
30+
}
31+
>()("@t3tools/desktop/app/DesktopLegacyLocalStorage") {}
32+
33+
const MARKER_FILE_NAME = "v1-local-storage-imported";
34+
// V1 used "T3 Code (Alpha)" when that folder existed and "t3code" otherwise.
35+
const V1_PROFILE_NAMES = ["T3 Code (Alpha)", "t3code"];
36+
37+
const make = Effect.gen(function* () {
38+
const environment = yield* DesktopEnvironment.DesktopEnvironment;
39+
const fs = yield* FileSystem.FileSystem;
40+
const path = yield* Path.Path;
41+
const items = yield* Ref.make(Option.none<Readonly<Record<string, string>>>());
42+
const markerPath = yield* Ref.make(Option.none<string>());
43+
44+
/** Newest file mtime in a directory; appending to a log leaves the directory's own mtime alone. */
45+
const newestFileMtime = (directory: string) =>
46+
Effect.gen(function* () {
47+
let newest = 0;
48+
for (const name of yield* fs.readDirectory(directory)) {
49+
const info = yield* fs.stat(path.join(directory, name)).pipe(Effect.option);
50+
if (Option.isNone(info)) continue;
51+
const mtime = Option.match(info.value.mtime, {
52+
onNone: () => 0,
53+
onSome: (date) => date.getTime(),
54+
});
55+
newest = Math.max(newest, mtime);
56+
}
57+
return newest;
58+
}).pipe(Effect.option);
59+
60+
/** The V1 profile whose Local Storage was written most recently, if any. */
61+
const findV1LocalStorage = Effect.gen(function* () {
62+
let newest: { readonly directory: string; readonly mtime: number } | null = null;
63+
for (const name of V1_PROFILE_NAMES) {
64+
const directory = path.join(environment.appDataDirectory, name, "Local Storage", "leveldb");
65+
const mtime = yield* newestFileMtime(directory);
66+
if (Option.isNone(mtime)) continue;
67+
if (newest === null || mtime.value > newest.mtime) newest = { directory, mtime: mtime.value };
68+
}
69+
return newest?.directory ?? null;
70+
});
71+
72+
const writeMarker = Effect.gen(function* () {
73+
const marker = yield* Ref.get(markerPath);
74+
if (Option.isNone(marker)) return;
75+
yield* fs
76+
.writeFileString(marker.value, "")
77+
.pipe(
78+
Effect.catch((error) =>
79+
Effect.logWarning("Could not record the V1 Local Storage import", error),
80+
),
81+
);
82+
});
83+
84+
const load = Effect.fn("desktop.legacyLocalStorage.load")(function* (userDataPath: string) {
85+
// Development already shares its profile between versions.
86+
if (environment.isDevelopment) return;
87+
const marker = path.join(userDataPath, MARKER_FILE_NAME);
88+
if (yield* fs.exists(marker).pipe(Effect.orElseSucceed(() => true))) return;
89+
yield* Ref.set(markerPath, Option.some(marker));
90+
const directory = yield* findV1LocalStorage;
91+
if (directory === null) return yield* writeMarker;
92+
const origin = ElectronProtocol.getDesktopUrl(false).replace(/\/$/, "");
93+
const read = yield* readChromiumLocalStorage(directory, origin).pipe(
94+
Effect.provideService(FileSystem.FileSystem, fs),
95+
Effect.provideService(Path.Path, path),
96+
Effect.tapError((error) =>
97+
Effect.logWarning("Could not read V1 Local Storage; will retry next launch", error),
98+
),
99+
Effect.option,
100+
);
101+
if (Option.isNone(read)) return;
102+
yield* Effect.logInfo("V1 Local Storage ready to import", {
103+
directory,
104+
keys: read.value.size,
105+
});
106+
yield* Ref.set(items, Option.some(Object.fromEntries(read.value)));
107+
});
108+
109+
return DesktopLegacyLocalStorage.of({
110+
load,
111+
// Taking clears the items, so a reload before `complete` cannot merge twice.
112+
take: Ref.getAndSet(items, Option.none()),
113+
complete: writeMarker,
114+
});
115+
});
116+
117+
export const layer = Layer.effect(DesktopLegacyLocalStorage, make);

0 commit comments

Comments
 (0)