Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8ccfe3e
Surface environment and repository identity metadata
juliusmarminge Apr 5, 2026
d1437f1
Include client-runtime in release smoke checks
juliusmarminge Apr 5, 2026
deb215e
Treat explicit null environments distinctly
juliusmarminge Apr 6, 2026
a16ee82
Support nested repo remotes and late URL resolution
juliusmarminge Apr 6, 2026
40ab9d9
Require environment IDs in web state sync
juliusmarminge Apr 6, 2026
97ba9f9
Preserve remote scoped state across snapshot syncs
juliusmarminge Apr 6, 2026
74250e9
non empty
juliusmarminge Apr 6, 2026
240438d
fine
juliusmarminge Apr 6, 2026
938f3d6
Cache repository identity lookups by TTL
juliusmarminge Apr 6, 2026
fc2de81
move
juliusmarminge Apr 6, 2026
403ac96
kewl
juliusmarminge Apr 6, 2026
70d3731
Handle ports in remote URL normalization
juliusmarminge Apr 6, 2026
babe73c
Handle empty server URLs and stale sidebar threads
juliusmarminge Apr 6, 2026
54f905c
Adapt multi-environment store to atomic refactor base
juliusmarminge Apr 6, 2026
010f452
Scope thread state by environment
juliusmarminge Apr 7, 2026
24ac444
Add draft routes for logical projects
juliusmarminge Apr 7, 2026
46c3251
Scope web native API and git queries by environment
juliusmarminge Apr 7, 2026
5e27490
Rename native API wrappers to local and environment APIs
juliusmarminge Apr 7, 2026
29b6385
Split local and environment API helpers
juliusmarminge Apr 7, 2026
580fe19
Canonicalize promoted drafts to server thread routes
juliusmarminge Apr 7, 2026
aab603f
Fix server environment test config generation
juliusmarminge Apr 7, 2026
74abf72
Scope bootstrap state to environment keys
juliusmarminge Apr 7, 2026
583f97c
Handle promoted drafts across scoped thread refs
juliusmarminge Apr 7, 2026
3e7db1d
Fix lint suppression comment syntax
juliusmarminge Apr 7, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions apps/desktop/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const UPDATE_DOWNLOAD_CHANNEL = "desktop:update-download";
const UPDATE_INSTALL_CHANNEL = "desktop:update-install";
const UPDATE_CHECK_CHANNEL = "desktop:update-check";
const GET_WS_URL_CHANNEL = "desktop:get-ws-url";
const GET_LOCAL_ENVIRONMENT_BOOTSTRAP_CHANNEL = "desktop:get-local-environment-bootstrap";
const BASE_DIR = process.env.T3CODE_HOME?.trim() || Path.join(OS.homedir(), ".t3");
const STATE_DIR = Path.join(BASE_DIR, "userdata");
const DESKTOP_SCHEME = "t3";
Expand Down Expand Up @@ -1172,6 +1173,14 @@ function registerIpcHandlers(): void {
event.returnValue = backendWsUrl;
});

ipcMain.removeAllListeners(GET_LOCAL_ENVIRONMENT_BOOTSTRAP_CHANNEL);
ipcMain.on(GET_LOCAL_ENVIRONMENT_BOOTSTRAP_CHANNEL, (event) => {
event.returnValue = {
label: "Local environment",
wsUrl: backendWsUrl || null,
} as const;
});

ipcMain.removeHandler(PICK_FOLDER_CHANNEL);
ipcMain.handle(PICK_FOLDER_CHANNEL, async () => {
const owner = BrowserWindow.getFocusedWindow() ?? mainWindow;
Expand Down
8 changes: 8 additions & 0 deletions apps/desktop/src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,20 @@ const UPDATE_CHECK_CHANNEL = "desktop:update-check";
const UPDATE_DOWNLOAD_CHANNEL = "desktop:update-download";
const UPDATE_INSTALL_CHANNEL = "desktop:update-install";
const GET_WS_URL_CHANNEL = "desktop:get-ws-url";
const GET_LOCAL_ENVIRONMENT_BOOTSTRAP_CHANNEL = "desktop:get-local-environment-bootstrap";

contextBridge.exposeInMainWorld("desktopBridge", {
getWsUrl: () => {
const result = ipcRenderer.sendSync(GET_WS_URL_CHANNEL);
return typeof result === "string" ? result : null;
},
getLocalEnvironmentBootstrap: () => {
const result = ipcRenderer.sendSync(GET_LOCAL_ENVIRONMENT_BOOTSTRAP_CHANNEL);
if (typeof result !== "object" || result === null) {
return null;
}
return result as ReturnType<DesktopBridge["getLocalEnvironmentBootstrap"]>;
},
pickFolder: () => ipcRenderer.invoke(PICK_FOLDER_CHANNEL),
confirm: (message) => ipcRenderer.invoke(CONFIRM_CHANNEL, message),
setTheme: (theme) => ipcRenderer.invoke(SET_THEME_CHANNEL, theme),
Expand Down
2 changes: 2 additions & 0 deletions apps/server/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface ServerDerivedPaths {
readonly providerEventLogPath: string;
readonly terminalLogsDir: string;
readonly anonymousIdPath: string;
readonly environmentIdPath: string;
}

/**
Expand Down Expand Up @@ -83,6 +84,7 @@ export const deriveServerPaths = Effect.fn(function* (
providerEventLogPath: join(providerLogsDir, "events.log"),
terminalLogsDir: join(logsDir, "terminals"),
anonymousIdPath: join(stateDir, "anonymous-id"),
environmentIdPath: join(stateDir, "environment-id"),
};
});

Expand Down
124 changes: 124 additions & 0 deletions apps/server/src/environment/Layers/ServerEnvironment.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import * as nodePath from "node:path";
import * as NodeServices from "@effect/platform-node/NodeServices";
import { expect, it } from "@effect/vitest";
import { Effect, Exit, FileSystem, Layer, PlatformError } from "effect";

import { deriveServerPaths, ServerConfig, type ServerConfigShape } from "../../config.ts";
import { ServerEnvironment } from "../Services/ServerEnvironment.ts";
import { ServerEnvironmentLive } from "./ServerEnvironment.ts";

const makeServerEnvironmentLayer = (baseDir: string) =>
ServerEnvironmentLive.pipe(Layer.provide(ServerConfig.layerTest(process.cwd(), baseDir)));

const makeServerConfig = Effect.fn(function* (baseDir: string) {
const derivedPaths = yield* deriveServerPaths(baseDir, undefined);

return {
...derivedPaths,
logLevel: "Error",
traceMinLevel: "Info",
traceTimingEnabled: true,
traceBatchWindowMs: 200,
traceMaxBytes: 10 * 1024 * 1024,
traceMaxFiles: 10,
otlpTracesUrl: undefined,
otlpMetricsUrl: undefined,
otlpExportIntervalMs: 10_000,
otlpServiceName: "t3-server",
cwd: process.cwd(),
baseDir,
mode: "web",
autoBootstrapProjectFromCwd: false,
logWebSocketEvents: false,
port: 0,
host: undefined,
authToken: undefined,
staticDir: undefined,
devUrl: undefined,
noBrowser: false,
} satisfies ServerConfigShape;
});

it.layer(NodeServices.layer)("ServerEnvironmentLive", (it) => {
it.effect("persists the environment id across service restarts", () =>
Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
const baseDir = yield* fileSystem.makeTempDirectoryScoped({
prefix: "t3-server-environment-test-",
});

const first = yield* Effect.gen(function* () {
const serverEnvironment = yield* ServerEnvironment;
return yield* serverEnvironment.getDescriptor;
}).pipe(Effect.provide(makeServerEnvironmentLayer(baseDir)));
const second = yield* Effect.gen(function* () {
const serverEnvironment = yield* ServerEnvironment;
return yield* serverEnvironment.getDescriptor;
}).pipe(Effect.provide(makeServerEnvironmentLayer(baseDir)));

expect(first.environmentId).toBe(second.environmentId);
expect(second.capabilities.repositoryIdentity).toBe(true);
}),
);

it.effect("fails instead of overwriting a persisted id when reading the file errors", () =>
Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
const baseDir = yield* fileSystem.makeTempDirectoryScoped({
prefix: "t3-server-environment-read-error-test-",
});
const serverConfig = yield* makeServerConfig(baseDir);
const environmentIdPath = serverConfig.environmentIdPath;
yield* fileSystem.makeDirectory(nodePath.dirname(environmentIdPath), { recursive: true });
yield* fileSystem.writeFileString(environmentIdPath, "persisted-environment-id\n");
const writeAttempts: string[] = [];
const failingFileSystemLayer = FileSystem.layerNoop({
exists: (path) => Effect.succeed(path === environmentIdPath),
readFileString: (path) =>
path === environmentIdPath
? Effect.fail(
PlatformError.systemError({
_tag: "PermissionDenied",
module: "FileSystem",
method: "readFileString",
description: "permission denied",
pathOrDescriptor: path,
}),
)
: Effect.fail(
PlatformError.systemError({
_tag: "NotFound",
module: "FileSystem",
method: "readFileString",
description: "not found",
pathOrDescriptor: path,
}),
),
writeFileString: (path) => {
writeAttempts.push(path);
return Effect.void;
},
});

const exit = yield* Effect.gen(function* () {
const serverEnvironment = yield* ServerEnvironment;
return yield* serverEnvironment.getDescriptor;
}).pipe(
Effect.provide(
ServerEnvironmentLive.pipe(
Layer.provide(
Layer.merge(Layer.succeed(ServerConfig, serverConfig), failingFileSystemLayer),
),
),
),
Effect.exit,
);

expect(Exit.isFailure(exit)).toBe(true);
expect(writeAttempts).toEqual([]);
expect(yield* fileSystem.readFileString(environmentIdPath)).toBe(
"persisted-environment-id\n",
);
}),
);
});
94 changes: 94 additions & 0 deletions apps/server/src/environment/Layers/ServerEnvironment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { EnvironmentId, type ExecutionEnvironmentDescriptor } from "@t3tools/contracts";
import { Effect, FileSystem, Layer, Path, Random } from "effect";

import { ServerConfig } from "../../config.ts";
import { ServerEnvironment, type ServerEnvironmentShape } from "../Services/ServerEnvironment.ts";
import { version } from "../../../package.json" with { type: "json" };

function platformOs(): ExecutionEnvironmentDescriptor["platform"]["os"] {
switch (process.platform) {
case "darwin":
return "darwin";
case "linux":
return "linux";
case "win32":
return "windows";
default:
return "unknown";
}
}

function platformArch(): ExecutionEnvironmentDescriptor["platform"]["arch"] {
switch (process.arch) {
case "arm64":
return "arm64";
case "x64":
return "x64";
default:
return "other";
}
}

export const makeServerEnvironment = Effect.fn("makeServerEnvironment")(function* () {
const fileSystem = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
const serverConfig = yield* ServerConfig;

const readPersistedEnvironmentId = Effect.gen(function* () {
const exists = yield* fileSystem
.exists(serverConfig.environmentIdPath)
.pipe(Effect.orElseSucceed(() => false));
if (!exists) {
return null;
}

const raw = yield* fileSystem
.readFileString(serverConfig.environmentIdPath)
.pipe(Effect.map((value) => value.trim()));

return raw.length > 0 ? raw : null;
});

const persistEnvironmentId = (value: string) =>
fileSystem.writeFileString(serverConfig.environmentIdPath, `${value}\n`);

const environmentIdRaw = yield* Effect.gen(function* () {
const persisted = yield* readPersistedEnvironmentId;
if (persisted) {
return persisted;
}

const generated = yield* Random.nextUUIDv4;
yield* persistEnvironmentId(generated);
return generated;
});

const environmentId = EnvironmentId.makeUnsafe(environmentIdRaw);
const cwdBaseName = path.basename(serverConfig.cwd).trim();
const label =
serverConfig.mode === "desktop"
? "Local environment"
: cwdBaseName.length > 0
? cwdBaseName
: "T3 environment";

const descriptor: ExecutionEnvironmentDescriptor = {
environmentId,
label,
platform: {
os: platformOs(),
arch: platformArch(),
},
serverVersion: version,
capabilities: {
repositoryIdentity: true,
},
};

return {
getEnvironmentId: Effect.succeed(environmentId),
getDescriptor: Effect.succeed(descriptor),
} satisfies ServerEnvironmentShape;
});

export const ServerEnvironmentLive = Layer.effect(ServerEnvironment, makeServerEnvironment());
13 changes: 13 additions & 0 deletions apps/server/src/environment/Services/ServerEnvironment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { EnvironmentId, ExecutionEnvironmentDescriptor } from "@t3tools/contracts";
import { ServiceMap } from "effect";
import type { Effect } from "effect";

export interface ServerEnvironmentShape {
readonly getEnvironmentId: Effect.Effect<EnvironmentId>;
readonly getDescriptor: Effect.Effect<ExecutionEnvironmentDescriptor>;
}

export class ServerEnvironment extends ServiceMap.Service<
ServerEnvironment,
ServerEnvironmentShape
>()("t3/environment/Services/ServerEnvironment") {}
6 changes: 3 additions & 3 deletions apps/server/src/git/Layers/GitManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
"pr list --head jasonLaster:statemachine --state all --limit 20 --json number,title,url,baseRefName,headRefName,state,mergedAt,updatedAt,isCrossRepository,headRepository,headRepositoryOwner",
);
}),
12_000,
20_000,
);

it.effect(
Expand Down Expand Up @@ -962,7 +962,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
),
).toBe(false);
}),
12_000,
20_000,
);

it.effect("status returns merged PR state when latest PR was merged", () =>
Expand Down Expand Up @@ -1685,7 +1685,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
false,
);
}),
12_000,
20_000,
);

it.effect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ projectionSnapshotLayer("ProjectionSnapshotQuery", (it) => {
id: asProjectId("project-1"),
title: "Project 1",
workspaceRoot: "/tmp/project-1",
repositoryIdentity: null,
defaultModelSelection: {
provider: "codex",
model: "gpt-5-codex",
Expand Down
Loading
Loading