Compare commits
9
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9c93f3fdf5 | ||
|
|
00a4f8bd3d | ||
|
|
89c53d63d8 | ||
|
|
1b17c244dd | ||
|
|
5988af8179 | ||
|
|
59338a38aa | ||
|
|
cdb78361bc | ||
|
|
7192bbef24 | ||
|
|
f68dc6c161 |
No files matched your search
@@ -29,6 +29,7 @@ const clientSettings: ClientSettings = {
|
||||
fontSizeTerminal: 12,
|
||||
fontSmoothing: true,
|
||||
glassOpacity: 80,
|
||||
onboardingCompletedAt: null,
|
||||
planModeEnabled: false,
|
||||
providerModelPreferences: {},
|
||||
sidebarAutoSettleAfterDays: 3,
|
||||
|
||||
@@ -82,6 +82,7 @@ export const RPC_REQUIRED_SCOPES = {
|
||||
[WS_METHODS.projectsWriteFile]: AuthOrchestrationOperateScope,
|
||||
[WS_METHODS.shellOpenInEditor]: AuthOrchestrationOperateScope,
|
||||
[WS_METHODS.filesystemBrowse]: AuthOrchestrationReadScope,
|
||||
[WS_METHODS.agentSessionsScan]: AuthOrchestrationReadScope,
|
||||
[WS_METHODS.assetsCreateUrl]: AuthOrchestrationReadScope,
|
||||
[WS_METHODS.subscribeVcsStatus]: AuthOrchestrationReadScope,
|
||||
[WS_METHODS.subscribeResourceTelemetry]: AuthOrchestrationReadScope,
|
||||
|
||||
@@ -0,0 +1,424 @@
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
import { describe, expect, it } from "@effect/vitest";
|
||||
import { type OrchestrationProjectShell, ProjectId } from "@t3tools/contracts";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Path from "effect/Path";
|
||||
|
||||
import * as ServerConfig from "../config.ts";
|
||||
import * as ProjectionSnapshotQuery from "../orchestration/Services/ProjectionSnapshotQuery.ts";
|
||||
import * as ServerSettings from "../serverSettings.ts";
|
||||
import * as AgentSessionScanner from "./AgentSessionScanner.ts";
|
||||
|
||||
const makeProjectShell = (workspaceRoot: string): OrchestrationProjectShell => ({
|
||||
id: ProjectId.make("project-1"),
|
||||
title: "Imported",
|
||||
workspaceRoot,
|
||||
defaultModelSelection: null,
|
||||
scripts: [],
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
updatedAt: "2026-01-01T00:00:00.000Z",
|
||||
});
|
||||
|
||||
/** Only `getShellSnapshot` is exercised; the rest must not be called. */
|
||||
const makeProjectionSnapshotQueryLayer = (importedWorkspaceRoots: ReadonlyArray<string>) =>
|
||||
Layer.succeed(ProjectionSnapshotQuery.ProjectionSnapshotQuery, {
|
||||
getCommandReadModel: () => Effect.die("unused"),
|
||||
getSnapshot: () => Effect.die("unused"),
|
||||
getShellSnapshot: () =>
|
||||
Effect.succeed({
|
||||
snapshotSequence: 0,
|
||||
projects: importedWorkspaceRoots.map((workspaceRoot) => makeProjectShell(workspaceRoot)),
|
||||
threads: [],
|
||||
updatedAt: "2026-01-01T00:00:00.000Z",
|
||||
}),
|
||||
getArchivedShellSnapshot: () => Effect.die("unused"),
|
||||
getSnapshotSequence: () => Effect.die("unused"),
|
||||
getCounts: () => Effect.die("unused"),
|
||||
getActiveProjectByWorkspaceRoot: () => Effect.die("unused"),
|
||||
getProjectShellById: () => Effect.die("unused"),
|
||||
getFirstActiveThreadIdByProjectId: () => Effect.die("unused"),
|
||||
getThreadCheckpointContext: () => Effect.die("unused"),
|
||||
getFullThreadDiffContext: () => Effect.die("unused"),
|
||||
getThreadShellById: () => Effect.die("unused"),
|
||||
getThreadDetailById: () => Effect.die("unused"),
|
||||
getThreadDetailSnapshot: () => Effect.die("unused"),
|
||||
searchThreads: () => Effect.die("unused"),
|
||||
});
|
||||
|
||||
/**
|
||||
* Run a scan against the given homes. Homes are temp dirs created inside the
|
||||
* test, so the layer is built per run rather than shared.
|
||||
*/
|
||||
const runScan = (input: {
|
||||
readonly claudeHomePath: string;
|
||||
readonly codexHomePath: string;
|
||||
readonly importedWorkspaceRoots?: ReadonlyArray<string>;
|
||||
/** Base dir for the test ServerConfig; worktreesDir derives from it. */
|
||||
readonly configBaseDir?: string;
|
||||
}) =>
|
||||
Effect.gen(function* () {
|
||||
const scanner = yield* AgentSessionScanner.AgentSessionScanner;
|
||||
return yield* scanner.scan;
|
||||
}).pipe(
|
||||
Effect.provide(
|
||||
AgentSessionScanner.layer.pipe(
|
||||
Layer.provide(
|
||||
Layer.mergeAll(
|
||||
ServerSettings.layerTest({
|
||||
providers: {
|
||||
claudeAgent: { homePath: input.claudeHomePath },
|
||||
codex: { homePath: input.codexHomePath },
|
||||
},
|
||||
}),
|
||||
ServerConfig.layerTest(
|
||||
input.claudeHomePath,
|
||||
input.configBaseDir ?? { prefix: "t3code-scanner-config-" },
|
||||
),
|
||||
makeProjectionSnapshotQueryLayer(input.importedWorkspaceRoots ?? []),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
const makeTempDir = Effect.fn("AgentSessionScanner.test.makeTempDir")(function* (prefix: string) {
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
return yield* fileSystem.makeTempDirectoryScoped({ prefix });
|
||||
});
|
||||
|
||||
const writeTranscript = Effect.fn("AgentSessionScanner.test.writeTranscript")(function* (input: {
|
||||
readonly filePath: string;
|
||||
readonly contents: string;
|
||||
/** Epoch millis, so ordering assertions never depend on write timing. */
|
||||
readonly mtimeMs: number;
|
||||
}) {
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
yield* fileSystem.makeDirectory(path.dirname(input.filePath), { recursive: true });
|
||||
yield* fileSystem.writeFileString(input.filePath, input.contents);
|
||||
// Numeric utimes arguments are seconds, not milliseconds.
|
||||
const seconds = input.mtimeMs / 1000;
|
||||
yield* fileSystem.utimes(input.filePath, seconds, seconds);
|
||||
});
|
||||
|
||||
/** Claude session line: the first record carries the real `cwd`. */
|
||||
const claudeSessionLine = (cwd: string) =>
|
||||
`${JSON.stringify({ type: "user", cwd, sessionId: "s1" })}\n${JSON.stringify({ type: "assistant" })}\n`;
|
||||
|
||||
/** Codex rollout line: session metadata is nested under `payload`. */
|
||||
const codexRolloutLine = (cwd: string) =>
|
||||
`${JSON.stringify({ timestamp: "2026-01-01T00:00:00.000Z", type: "session_meta", payload: { id: "r1", cwd } })}\n`;
|
||||
|
||||
it.layer(NodeServices.layer)("AgentSessionScanner", (it) => {
|
||||
describe("scan", () => {
|
||||
it.effect("reads Claude project cwds from transcripts, newest first", () =>
|
||||
Effect.gen(function* () {
|
||||
const path = yield* Path.Path;
|
||||
const claudeHomePath = yield* makeTempDir("t3code-claude-home-");
|
||||
const codexHomePath = yield* makeTempDir("t3code-codex-home-");
|
||||
const olderWorkspace = yield* makeTempDir("t3code-workspace-older-");
|
||||
const newerWorkspace = yield* makeTempDir("t3code-workspace-newer-");
|
||||
|
||||
// Slugs are intentionally lossy; the scanner must not decode them.
|
||||
yield* writeTranscript({
|
||||
filePath: path.join(claudeHomePath, "projects", "-slug-older", "a.jsonl"),
|
||||
contents: claudeSessionLine(olderWorkspace),
|
||||
mtimeMs: Date.parse("2026-01-01T00:00:00.000Z"),
|
||||
});
|
||||
yield* writeTranscript({
|
||||
filePath: path.join(claudeHomePath, "projects", "-slug-older", "b.jsonl"),
|
||||
contents: claudeSessionLine(olderWorkspace),
|
||||
mtimeMs: Date.parse("2026-01-02T00:00:00.000Z"),
|
||||
});
|
||||
yield* writeTranscript({
|
||||
filePath: path.join(claudeHomePath, "projects", "-slug-newer", "c.jsonl"),
|
||||
contents: claudeSessionLine(newerWorkspace),
|
||||
mtimeMs: Date.parse("2026-03-01T00:00:00.000Z"),
|
||||
});
|
||||
|
||||
const result = yield* runScan({ claudeHomePath, codexHomePath });
|
||||
|
||||
expect(result.candidates).toEqual([
|
||||
{
|
||||
path: newerWorkspace,
|
||||
title: path.basename(newerWorkspace),
|
||||
sources: ["claudeAgent"],
|
||||
threadCount: 1,
|
||||
lastActiveAt: "2026-03-01T00:00:00.000Z",
|
||||
alreadyImported: false,
|
||||
},
|
||||
{
|
||||
path: olderWorkspace,
|
||||
title: path.basename(olderWorkspace),
|
||||
sources: ["claudeAgent"],
|
||||
threadCount: 2,
|
||||
lastActiveAt: "2026-01-02T00:00:00.000Z",
|
||||
alreadyImported: false,
|
||||
},
|
||||
]);
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("groups Codex rollouts by cwd across date directories", () =>
|
||||
Effect.gen(function* () {
|
||||
const path = yield* Path.Path;
|
||||
const claudeHomePath = yield* makeTempDir("t3code-claude-home-");
|
||||
const codexHomePath = yield* makeTempDir("t3code-codex-home-");
|
||||
const workspace = yield* makeTempDir("t3code-workspace-");
|
||||
const otherWorkspace = yield* makeTempDir("t3code-workspace-other-");
|
||||
|
||||
const rollout = (year: string, month: string, day: string, name: string) =>
|
||||
path.join(codexHomePath, "sessions", year, month, day, name);
|
||||
|
||||
yield* writeTranscript({
|
||||
filePath: rollout("2026", "01", "05", "rollout-2026-01-05T10-00-00-aaa.jsonl"),
|
||||
contents: codexRolloutLine(workspace),
|
||||
mtimeMs: Date.parse("2026-01-05T10:00:00.000Z"),
|
||||
});
|
||||
yield* writeTranscript({
|
||||
filePath: rollout("2026", "02", "09", "rollout-2026-02-09T10-00-00-bbb.jsonl"),
|
||||
contents: codexRolloutLine(workspace),
|
||||
mtimeMs: Date.parse("2026-02-09T10:00:00.000Z"),
|
||||
});
|
||||
yield* writeTranscript({
|
||||
filePath: rollout("2026", "02", "09", "rollout-2026-02-09T11-00-00-ccc.jsonl"),
|
||||
contents: codexRolloutLine(otherWorkspace),
|
||||
mtimeMs: Date.parse("2026-02-09T11:00:00.000Z"),
|
||||
});
|
||||
|
||||
const result = yield* runScan({ claudeHomePath, codexHomePath });
|
||||
|
||||
expect(result.candidates).toEqual([
|
||||
{
|
||||
path: otherWorkspace,
|
||||
title: path.basename(otherWorkspace),
|
||||
sources: ["codex"],
|
||||
threadCount: 1,
|
||||
lastActiveAt: "2026-02-09T11:00:00.000Z",
|
||||
alreadyImported: false,
|
||||
},
|
||||
{
|
||||
path: workspace,
|
||||
title: path.basename(workspace),
|
||||
sources: ["codex"],
|
||||
threadCount: 2,
|
||||
lastActiveAt: "2026-02-09T10:00:00.000Z",
|
||||
alreadyImported: false,
|
||||
},
|
||||
]);
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("merges the same cwd seen by both agents and flags imported projects", () =>
|
||||
Effect.gen(function* () {
|
||||
const path = yield* Path.Path;
|
||||
const claudeHomePath = yield* makeTempDir("t3code-claude-home-");
|
||||
const codexHomePath = yield* makeTempDir("t3code-codex-home-");
|
||||
const workspace = yield* makeTempDir("t3code-workspace-");
|
||||
|
||||
yield* writeTranscript({
|
||||
filePath: path.join(claudeHomePath, "projects", "-slug", "a.jsonl"),
|
||||
contents: claudeSessionLine(workspace),
|
||||
mtimeMs: Date.parse("2026-01-01T00:00:00.000Z"),
|
||||
});
|
||||
yield* writeTranscript({
|
||||
filePath: path.join(
|
||||
codexHomePath,
|
||||
"sessions",
|
||||
"2026",
|
||||
"04",
|
||||
"01",
|
||||
"rollout-2026-04-01T09-00-00-aaa.jsonl",
|
||||
),
|
||||
contents: codexRolloutLine(workspace),
|
||||
mtimeMs: Date.parse("2026-04-01T09:00:00.000Z"),
|
||||
});
|
||||
|
||||
const result = yield* runScan({
|
||||
claudeHomePath,
|
||||
codexHomePath,
|
||||
importedWorkspaceRoots: [workspace],
|
||||
});
|
||||
|
||||
expect(result.candidates).toEqual([
|
||||
{
|
||||
path: workspace,
|
||||
title: path.basename(workspace),
|
||||
sources: ["claudeAgent", "codex"],
|
||||
threadCount: 2,
|
||||
lastActiveAt: "2026-04-01T09:00:00.000Z",
|
||||
alreadyImported: true,
|
||||
},
|
||||
]);
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("drops candidates whose directory no longer exists", () =>
|
||||
Effect.gen(function* () {
|
||||
const path = yield* Path.Path;
|
||||
const claudeHomePath = yield* makeTempDir("t3code-claude-home-");
|
||||
const codexHomePath = yield* makeTempDir("t3code-codex-home-");
|
||||
|
||||
yield* writeTranscript({
|
||||
filePath: path.join(claudeHomePath, "projects", "-slug", "a.jsonl"),
|
||||
contents: claudeSessionLine(path.join(claudeHomePath, "does-not-exist")),
|
||||
mtimeMs: Date.parse("2026-01-01T00:00:00.000Z"),
|
||||
});
|
||||
|
||||
const result = yield* runScan({ claudeHomePath, codexHomePath });
|
||||
|
||||
expect(result.candidates).toEqual([]);
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("excludes T3-managed worktree sandboxes", () =>
|
||||
Effect.gen(function* () {
|
||||
const path = yield* Path.Path;
|
||||
const claudeHomePath = yield* makeTempDir("t3code-claude-home-");
|
||||
const codexHomePath = yield* makeTempDir("t3code-codex-home-");
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
|
||||
const worktreeCwd = path.join(claudeHomePath, ".t3", "worktrees", "t3code", "wt-1");
|
||||
yield* fileSystem.makeDirectory(worktreeCwd, { recursive: true });
|
||||
yield* writeTranscript({
|
||||
filePath: path.join(claudeHomePath, "projects", "-slug", "a.jsonl"),
|
||||
contents: claudeSessionLine(worktreeCwd),
|
||||
mtimeMs: Date.parse("2026-01-01T00:00:00.000Z"),
|
||||
});
|
||||
|
||||
const result = yield* runScan({ claudeHomePath, codexHomePath });
|
||||
|
||||
expect(result.candidates).toEqual([]);
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("excludes sandboxes under the configured worktrees dir without .t3 in the path", () =>
|
||||
Effect.gen(function* () {
|
||||
const path = yield* Path.Path;
|
||||
const claudeHomePath = yield* makeTempDir("t3code-claude-home-");
|
||||
const codexHomePath = yield* makeTempDir("t3code-codex-home-");
|
||||
const configBaseDir = yield* makeTempDir("t3code-scanner-base-");
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
|
||||
// worktreesDir derives as `<baseDir>/worktrees`, and the temp base
|
||||
// dir contains no `.t3` segment — only the config-based prefix match
|
||||
// can exclude this one.
|
||||
const worktreeCwd = path.join(configBaseDir, "worktrees", "t3code", "wt-2");
|
||||
yield* fileSystem.makeDirectory(worktreeCwd, { recursive: true });
|
||||
yield* writeTranscript({
|
||||
filePath: path.join(claudeHomePath, "projects", "-slug", "a.jsonl"),
|
||||
contents: claudeSessionLine(worktreeCwd),
|
||||
mtimeMs: Date.parse("2026-01-01T00:00:00.000Z"),
|
||||
});
|
||||
|
||||
const result = yield* runScan({ claudeHomePath, codexHomePath, configBaseDir });
|
||||
|
||||
expect(result.candidates).toEqual([]);
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("excludes sandboxes reached through a symlink into the worktrees dir", () =>
|
||||
Effect.gen(function* () {
|
||||
const path = yield* Path.Path;
|
||||
const claudeHomePath = yield* makeTempDir("t3code-claude-home-");
|
||||
const codexHomePath = yield* makeTempDir("t3code-codex-home-");
|
||||
const configBaseDir = yield* makeTempDir("t3code-scanner-base-");
|
||||
const linkParent = yield* makeTempDir("t3code-scanner-links-");
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
|
||||
// The recorded cwd is a symlink whose own spelling looks harmless;
|
||||
// only its realpath reveals the managed sandbox.
|
||||
const worktreeCwd = path.join(configBaseDir, "worktrees", "t3code", "wt-3");
|
||||
yield* fileSystem.makeDirectory(worktreeCwd, { recursive: true });
|
||||
const symlinkCwd = path.join(linkParent, "innocent-project");
|
||||
yield* fileSystem.symlink(worktreeCwd, symlinkCwd);
|
||||
yield* writeTranscript({
|
||||
filePath: path.join(claudeHomePath, "projects", "-slug", "a.jsonl"),
|
||||
contents: claudeSessionLine(symlinkCwd),
|
||||
mtimeMs: Date.parse("2026-01-01T00:00:00.000Z"),
|
||||
});
|
||||
|
||||
const result = yield* runScan({ claudeHomePath, codexHomePath, configBaseDir });
|
||||
|
||||
expect(result.candidates).toEqual([]);
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("finds the cwd on a later line when the first records carry none", () =>
|
||||
Effect.gen(function* () {
|
||||
const path = yield* Path.Path;
|
||||
const claudeHomePath = yield* makeTempDir("t3code-claude-home-");
|
||||
const codexHomePath = yield* makeTempDir("t3code-codex-home-");
|
||||
const workspace = yield* makeTempDir("t3code-workspace-");
|
||||
|
||||
// Claude transcripts often open with records that have no cwd.
|
||||
const contents = `{"type":"file-history-snapshot","messageId":"m1"}\n{"type":"queue-operation","operation":"enqueue"}\n${claudeSessionLine(workspace)}`;
|
||||
yield* writeTranscript({
|
||||
filePath: path.join(claudeHomePath, "projects", "-slug", "a.jsonl"),
|
||||
contents,
|
||||
mtimeMs: Date.parse("2026-01-01T00:00:00.000Z"),
|
||||
});
|
||||
|
||||
const result = yield* runScan({ claudeHomePath, codexHomePath });
|
||||
|
||||
expect(result.candidates.map((candidate) => candidate.path)).toEqual([workspace]);
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("skips malformed transcripts without failing the scan", () =>
|
||||
Effect.gen(function* () {
|
||||
const path = yield* Path.Path;
|
||||
const claudeHomePath = yield* makeTempDir("t3code-claude-home-");
|
||||
const codexHomePath = yield* makeTempDir("t3code-codex-home-");
|
||||
const workspace = yield* makeTempDir("t3code-workspace-");
|
||||
|
||||
yield* writeTranscript({
|
||||
filePath: path.join(claudeHomePath, "projects", "-broken", "a.jsonl"),
|
||||
contents: "not json at all\n",
|
||||
mtimeMs: Date.parse("2026-05-01T00:00:00.000Z"),
|
||||
});
|
||||
// Valid JSON, but no cwd anywhere in the record.
|
||||
yield* writeTranscript({
|
||||
filePath: path.join(claudeHomePath, "projects", "-no-cwd", "a.jsonl"),
|
||||
contents: `{"type":"summary"}\n`,
|
||||
mtimeMs: Date.parse("2026-05-02T00:00:00.000Z"),
|
||||
});
|
||||
yield* writeTranscript({
|
||||
filePath: path.join(claudeHomePath, "projects", "-good", "a.jsonl"),
|
||||
contents: claudeSessionLine(workspace),
|
||||
mtimeMs: Date.parse("2026-05-03T00:00:00.000Z"),
|
||||
});
|
||||
|
||||
const result = yield* runScan({ claudeHomePath, codexHomePath });
|
||||
|
||||
expect(result.candidates).toEqual([
|
||||
{
|
||||
path: workspace,
|
||||
title: path.basename(workspace),
|
||||
sources: ["claudeAgent"],
|
||||
threadCount: 1,
|
||||
lastActiveAt: "2026-05-03T00:00:00.000Z",
|
||||
alreadyImported: false,
|
||||
},
|
||||
]);
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("returns an empty result when neither home directory exists", () =>
|
||||
Effect.gen(function* () {
|
||||
const path = yield* Path.Path;
|
||||
const root = yield* makeTempDir("t3code-missing-homes-");
|
||||
|
||||
const result = yield* runScan({
|
||||
claudeHomePath: path.join(root, "no-claude"),
|
||||
codexHomePath: path.join(root, "no-codex"),
|
||||
});
|
||||
|
||||
expect(result.candidates).toEqual([]);
|
||||
expect(result.scannedAt).toMatch(/^\d{4}-\d{2}-\d{2}T/);
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,469 @@
|
||||
/**
|
||||
* AgentSessionScanner - discovery of projects a user already works on.
|
||||
*
|
||||
* Claude Code and Codex both keep a per-session transcript on disk, and each
|
||||
* transcript records the directory the session ran in. Reading those `cwd`
|
||||
* values gives us the set of directories worth offering as projects during
|
||||
* onboarding, without asking the user to browse the filesystem.
|
||||
*
|
||||
* The scan is read-only and best-effort: an unreadable home, a malformed
|
||||
* transcript, or a directory that has since been deleted is skipped rather
|
||||
* than failing the scan. Project creation stays with the client, which
|
||||
* dispatches `project.create` for whichever candidates the user picks.
|
||||
*
|
||||
* @module project/AgentSessionScanner
|
||||
*/
|
||||
import * as NodeOS from "node:os";
|
||||
|
||||
import {
|
||||
AgentSessionScanError,
|
||||
type AgentSessionProjectCandidate,
|
||||
type AgentSessionScanResult,
|
||||
} from "@t3tools/contracts";
|
||||
import * as Context from "effect/Context";
|
||||
import * as DateTime from "effect/DateTime";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Path from "effect/Path";
|
||||
|
||||
import { HostProcessEnvironment, HostProcessPlatform } from "@t3tools/shared/hostProcess";
|
||||
import { normalizeProjectPathForComparison } from "@t3tools/shared/path";
|
||||
|
||||
import * as ServerConfig from "../config.ts";
|
||||
import * as ProjectionSnapshotQuery from "../orchestration/Services/ProjectionSnapshotQuery.ts";
|
||||
import { resolveCodexHomeLayout } from "../provider/Drivers/CodexHomeLayout.ts";
|
||||
import { expandHomePath } from "../pathExpansion.ts";
|
||||
import * as ServerSettings from "../serverSettings.ts";
|
||||
|
||||
/**
|
||||
* Bytes read from the head of each transcript. Session metadata (including
|
||||
* `cwd`) is written in the first record, so reading a prefix keeps the scan
|
||||
* cheap even when a transcript is hundreds of megabytes.
|
||||
*/
|
||||
const TRANSCRIPT_PREFIX_BYTES = 32 * 1024;
|
||||
|
||||
/**
|
||||
* Upper bound on transcripts inspected (first line read) per source.
|
||||
* Newest-first ordering means the cap drops only stale sessions when a home
|
||||
* directory is unusually large.
|
||||
*/
|
||||
const MAX_TRANSCRIPTS_PER_SOURCE = 5000;
|
||||
|
||||
/**
|
||||
* Upper bound on `stat` calls per source. Newest-first ordering needs mtimes
|
||||
* before the read cap can be applied, so stats get their own larger budget;
|
||||
* once it runs out the scan stops rather than walking a pathological home
|
||||
* indefinitely.
|
||||
*/
|
||||
const MAX_STATS_PER_SOURCE = MAX_TRANSCRIPTS_PER_SOURCE * 4;
|
||||
|
||||
/** Service tag for agent session discovery. */
|
||||
export class AgentSessionScanner extends Context.Service<
|
||||
AgentSessionScanner,
|
||||
{
|
||||
/**
|
||||
* Discover every directory the configured Claude and Codex homes have run
|
||||
* a session in. Candidates are returned newest-first; the client decides
|
||||
* which ones to import and how far back to look. Fails with the contract
|
||||
* error directly — there is no server-local context worth wrapping.
|
||||
*/
|
||||
readonly scan: Effect.Effect<AgentSessionScanResult, AgentSessionScanError>;
|
||||
}
|
||||
>()("t3/project/AgentSessionScanner") {}
|
||||
|
||||
type AgentSessionSource = AgentSessionProjectCandidate["sources"][number];
|
||||
|
||||
/** A single directory's worth of evidence from one source. */
|
||||
interface RawCandidate {
|
||||
readonly cwd: string;
|
||||
readonly source: AgentSessionSource;
|
||||
readonly threadCount: number;
|
||||
readonly lastActiveAtMs: number | null;
|
||||
}
|
||||
|
||||
const decoder = new TextDecoder();
|
||||
|
||||
/**
|
||||
* T3 Code runs its own agent sessions inside disposable worktrees. Their
|
||||
* transcripts look exactly like user sessions, but re-importing the app's own
|
||||
* sandboxes as projects is never right. Matches this server's configured
|
||||
* worktrees directory plus the conventional `.t3/worktrees` layout, which
|
||||
* also catches sandboxes from other T3 homes on the same machine. Separators
|
||||
* are normalized (and, on Windows, case folded) so the prefix match holds
|
||||
* there too. Callers check both the recorded spelling and its realpath so a
|
||||
* symlink into the worktrees directory cannot bypass the filter.
|
||||
*/
|
||||
function normalizeForWorktreeMatch(value: string, caseFold: boolean): string {
|
||||
const normalized = `${value.replaceAll("\\", "/")}/`;
|
||||
return caseFold ? normalized.toLowerCase() : normalized;
|
||||
}
|
||||
|
||||
function isT3ManagedWorktree(
|
||||
candidatePath: string,
|
||||
worktreesDir: string,
|
||||
caseFold: boolean,
|
||||
): boolean {
|
||||
const normalized = normalizeForWorktreeMatch(candidatePath, caseFold);
|
||||
return (
|
||||
normalized.startsWith(normalizeForWorktreeMatch(worktreesDir, caseFold)) ||
|
||||
normalized.includes("/.t3/worktrees/")
|
||||
);
|
||||
}
|
||||
|
||||
/** Extract `cwd` from a session-meta record, tolerating the shapes each CLI writes. */
|
||||
function extractCwd(line: string): string | null {
|
||||
let parsed: unknown;
|
||||
try {
|
||||
parsed = JSON.parse(line);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
if (typeof parsed !== "object" || parsed === null) return null;
|
||||
|
||||
const record = parsed as Record<string, unknown>;
|
||||
if (typeof record.cwd === "string" && record.cwd.trim().length > 0) {
|
||||
return record.cwd;
|
||||
}
|
||||
// Codex nests session metadata under `payload`.
|
||||
const payload = record.payload;
|
||||
if (typeof payload === "object" && payload !== null) {
|
||||
const nested = (payload as Record<string, unknown>).cwd;
|
||||
if (typeof nested === "string" && nested.trim().length > 0) {
|
||||
return nested;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export const make = Effect.gen(function* () {
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const serverConfig = yield* ServerConfig.ServerConfig;
|
||||
const serverSettings = yield* ServerSettings.ServerSettingsService;
|
||||
const projectionSnapshotQuery = yield* ProjectionSnapshotQuery.ProjectionSnapshotQuery;
|
||||
const worktreesDir = path.resolve(serverConfig.worktreesDir);
|
||||
// Windows filesystems are case-insensitive, so path prefix checks there
|
||||
// must case fold.
|
||||
const foldWorktreeCase = (yield* HostProcessPlatform) === "win32";
|
||||
const hostEnvironment = yield* HostProcessEnvironment;
|
||||
|
||||
const listDirectory = (directory: string) =>
|
||||
fileSystem.readDirectory(directory).pipe(Effect.orElseSucceed((): ReadonlyArray<string> => []));
|
||||
|
||||
const statOption = (target: string) =>
|
||||
fileSystem.stat(target).pipe(Effect.map(Option.some), Effect.orElseSucceed(Option.none));
|
||||
|
||||
/**
|
||||
* Read the head of a transcript and return its complete lines. Returns an
|
||||
* empty list when the file is unreadable; a trailing partial line (cut by
|
||||
* the prefix cap) is dropped rather than parsed as truncated JSON.
|
||||
*/
|
||||
const readHeadLines = Effect.fn("AgentSessionScanner.readHeadLines")(function* (
|
||||
filePath: string,
|
||||
): Effect.fn.Return<ReadonlyArray<string>> {
|
||||
const prefix = yield* Effect.scoped(
|
||||
fileSystem
|
||||
.open(filePath, { flag: "r" })
|
||||
.pipe(Effect.flatMap((file) => file.readAlloc(TRANSCRIPT_PREFIX_BYTES))),
|
||||
).pipe(Effect.orElseSucceed(Option.none<Uint8Array>));
|
||||
if (Option.isNone(prefix)) return [];
|
||||
|
||||
const text = decoder.decode(prefix.value);
|
||||
const lines = text.split("\n");
|
||||
// A prefix-capped read may end mid-line; only a file smaller than the cap
|
||||
// is guaranteed to have a complete final line.
|
||||
if (prefix.value.length >= TRANSCRIPT_PREFIX_BYTES) {
|
||||
lines.pop();
|
||||
}
|
||||
return lines;
|
||||
});
|
||||
|
||||
// Transcripts often open with records that carry no cwd (Claude writes
|
||||
// file-history snapshots and queue operations first), so scan every
|
||||
// complete line in the prefix for the first one that names a directory.
|
||||
const readCwd = Effect.fn("AgentSessionScanner.readCwd")(function* (filePath: string) {
|
||||
const lines = yield* readHeadLines(filePath);
|
||||
for (const line of lines) {
|
||||
const cwd = extractCwd(line.trim());
|
||||
if (cwd !== null) return cwd;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
const latestMtimeMs = Effect.fn("AgentSessionScanner.latestMtimeMs")(function* (
|
||||
filePaths: ReadonlyArray<string>,
|
||||
) {
|
||||
let latest: number | null = null;
|
||||
for (const filePath of filePaths) {
|
||||
const stats = yield* statOption(filePath);
|
||||
if (Option.isNone(stats)) continue;
|
||||
const mtime = stats.value.mtime;
|
||||
if (Option.isNone(mtime)) continue;
|
||||
const value = mtime.value.getTime();
|
||||
if (latest === null || value > latest) {
|
||||
latest = value;
|
||||
}
|
||||
}
|
||||
return latest;
|
||||
});
|
||||
|
||||
/**
|
||||
* Resolve the Claude config directory the CLI would use, matching the
|
||||
* precedence the spawned CLI sees: the instance's `homePath` (exported as
|
||||
* `CLAUDE_CONFIG_DIR`), then a `CLAUDE_CONFIG_DIR` already in the
|
||||
* environment, then `~/.claude`.
|
||||
*/
|
||||
const resolveClaudeConfigDir = (homePath: string): string => {
|
||||
const configured = homePath.trim();
|
||||
if (configured.length > 0) {
|
||||
return path.resolve(expandHomePath(configured));
|
||||
}
|
||||
const fromEnvironment = hostEnvironment.CLAUDE_CONFIG_DIR?.trim() ?? "";
|
||||
if (fromEnvironment.length > 0) {
|
||||
return path.resolve(expandHomePath(fromEnvironment));
|
||||
}
|
||||
return path.join(NodeOS.homedir(), ".claude");
|
||||
};
|
||||
|
||||
/**
|
||||
* Claude keeps one directory per project under `projects/`, named after a
|
||||
* lossy slug of the path. The slug can't be decoded (both `/` and `.` become
|
||||
* `-`), so the real path comes from the `cwd` recorded in the newest
|
||||
* transcript inside it.
|
||||
*/
|
||||
const scanClaude = Effect.fn("AgentSessionScanner.scanClaude")(function* (homePath: string) {
|
||||
const projectsDir = path.join(resolveClaudeConfigDir(homePath), "projects");
|
||||
const projectDirectories = yield* listDirectory(projectsDir);
|
||||
const candidates: Array<RawCandidate> = [];
|
||||
let readBudget = MAX_TRANSCRIPTS_PER_SOURCE;
|
||||
let statBudget = MAX_STATS_PER_SOURCE;
|
||||
|
||||
for (const projectDirectory of projectDirectories) {
|
||||
if (readBudget <= 0 || statBudget <= 0) break;
|
||||
const directory = path.join(projectsDir, projectDirectory);
|
||||
const transcripts = (yield* listDirectory(directory))
|
||||
.filter((entry) => entry.endsWith(".jsonl"))
|
||||
.map((entry) => path.join(directory, entry));
|
||||
if (transcripts.length === 0) continue;
|
||||
|
||||
// Stat (bounded), then spend the read budget newest-first, so the cap
|
||||
// only ever drops the oldest transcripts.
|
||||
const statted = transcripts.slice(0, statBudget);
|
||||
statBudget -= statted.length;
|
||||
const withMtimes: Array<{ filePath: string; mtimeMs: number }> = [];
|
||||
for (const filePath of statted) {
|
||||
const stats = yield* statOption(filePath);
|
||||
if (Option.isNone(stats) || Option.isNone(stats.value.mtime)) continue;
|
||||
withMtimes.push({ filePath, mtimeMs: stats.value.mtime.value.getTime() });
|
||||
}
|
||||
withMtimes.sort((left, right) => right.mtimeMs - left.mtimeMs);
|
||||
withMtimes.splice(readBudget);
|
||||
readBudget -= withMtimes.length;
|
||||
|
||||
// The slug is lossy (`/a/b.c` and `/a/b/c` share a directory), so a
|
||||
// directory can hold sessions from several distinct paths — group by
|
||||
// the recorded cwd like the Codex scan does.
|
||||
const byCwd = new Map<string, { threadCount: number; lastActiveAtMs: number }>();
|
||||
for (const entry of withMtimes) {
|
||||
const cwd = yield* readCwd(entry.filePath);
|
||||
if (cwd === null) continue;
|
||||
const existing = byCwd.get(cwd);
|
||||
if (existing) {
|
||||
existing.threadCount += 1;
|
||||
existing.lastActiveAtMs = Math.max(existing.lastActiveAtMs, entry.mtimeMs);
|
||||
} else {
|
||||
byCwd.set(cwd, { threadCount: 1, lastActiveAtMs: entry.mtimeMs });
|
||||
}
|
||||
}
|
||||
for (const [cwd, group] of byCwd) {
|
||||
candidates.push({
|
||||
cwd,
|
||||
source: "claudeAgent",
|
||||
threadCount: group.threadCount,
|
||||
lastActiveAtMs: group.lastActiveAtMs,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return candidates;
|
||||
});
|
||||
|
||||
/**
|
||||
* Codex writes `sessions/YYYY/MM/DD/rollout-*.jsonl`. Always scan the shared
|
||||
* home: in auth-overlay mode the effective home only symlinks to it.
|
||||
*/
|
||||
const scanCodex = Effect.fn("AgentSessionScanner.scanCodex")(function* (
|
||||
codexSettings: Parameters<typeof resolveCodexHomeLayout>[0],
|
||||
) {
|
||||
const layout = yield* resolveCodexHomeLayout(codexSettings).pipe(
|
||||
Effect.provideService(Path.Path, path),
|
||||
);
|
||||
const sessionsDir = path.join(layout.sharedHomePath, "sessions");
|
||||
|
||||
const rollouts: Array<string> = [];
|
||||
// Date-partitioned directories sort chronologically, so walking them in
|
||||
// reverse keeps the newest sessions when the budget runs out.
|
||||
for (const year of (yield* listDirectory(sessionsDir)).toSorted().toReversed()) {
|
||||
for (const month of (yield* listDirectory(path.join(sessionsDir, year)))
|
||||
.toSorted()
|
||||
.toReversed()) {
|
||||
for (const day of (yield* listDirectory(path.join(sessionsDir, year, month)))
|
||||
.toSorted()
|
||||
.toReversed()) {
|
||||
const directory = path.join(sessionsDir, year, month, day);
|
||||
for (const entry of (yield* listDirectory(directory)).toSorted().toReversed()) {
|
||||
if (!entry.startsWith("rollout-") || !entry.endsWith(".jsonl")) continue;
|
||||
rollouts.push(path.join(directory, entry));
|
||||
if (rollouts.length >= MAX_TRANSCRIPTS_PER_SOURCE) break;
|
||||
}
|
||||
if (rollouts.length >= MAX_TRANSCRIPTS_PER_SOURCE) break;
|
||||
}
|
||||
if (rollouts.length >= MAX_TRANSCRIPTS_PER_SOURCE) break;
|
||||
}
|
||||
if (rollouts.length >= MAX_TRANSCRIPTS_PER_SOURCE) break;
|
||||
}
|
||||
|
||||
const byCwd = new Map<string, Array<string>>();
|
||||
for (const rollout of rollouts) {
|
||||
const cwd = yield* readCwd(rollout);
|
||||
if (cwd === null) continue;
|
||||
const existing = byCwd.get(cwd);
|
||||
if (existing) {
|
||||
existing.push(rollout);
|
||||
} else {
|
||||
byCwd.set(cwd, [rollout]);
|
||||
}
|
||||
}
|
||||
|
||||
const candidates: Array<RawCandidate> = [];
|
||||
for (const [cwd, filePaths] of byCwd) {
|
||||
candidates.push({
|
||||
cwd,
|
||||
source: "codex",
|
||||
threadCount: filePaths.length,
|
||||
lastActiveAtMs: yield* latestMtimeMs(filePaths),
|
||||
});
|
||||
}
|
||||
return candidates;
|
||||
});
|
||||
|
||||
const scan: AgentSessionScanner["Service"]["scan"] = Effect.gen(function* () {
|
||||
const settings = yield* serverSettings.getSettings.pipe(
|
||||
Effect.mapError((cause) => new AgentSessionScanError({ operation: "read-settings", cause })),
|
||||
);
|
||||
|
||||
const raw = [
|
||||
...(yield* scanClaude(settings.providers.claudeAgent.homePath)),
|
||||
...(yield* scanCodex(settings.providers.codex)),
|
||||
];
|
||||
|
||||
// Merge by resolved path first so both sources agree on a key, then by
|
||||
// realpath so a symlinked home and its target collapse into one candidate.
|
||||
const merged = new Map<
|
||||
string,
|
||||
{
|
||||
path: string;
|
||||
sources: Array<AgentSessionSource>;
|
||||
threadCount: number;
|
||||
lastActiveAtMs: number | null;
|
||||
}
|
||||
>();
|
||||
const realPathKeys = new Map<string, string>();
|
||||
|
||||
for (const candidate of raw) {
|
||||
const resolved = path.resolve(expandHomePath(candidate.cwd.trim()));
|
||||
if (isT3ManagedWorktree(resolved, worktreesDir, foldWorktreeCase)) continue;
|
||||
let key = realPathKeys.get(resolved);
|
||||
if (key === undefined) {
|
||||
const stats = yield* statOption(resolved);
|
||||
// Directories that no longer exist can't be imported.
|
||||
if (Option.isNone(stats) || stats.value.type !== "Directory") {
|
||||
realPathKeys.set(resolved, "");
|
||||
continue;
|
||||
}
|
||||
key = yield* fileSystem.realPath(resolved).pipe(Effect.orElseSucceed(() => resolved));
|
||||
// A symlink can point into the worktrees directory even when its own
|
||||
// spelling doesn't; check again with links resolved.
|
||||
if (isT3ManagedWorktree(key, worktreesDir, foldWorktreeCase)) {
|
||||
key = "";
|
||||
}
|
||||
realPathKeys.set(resolved, key);
|
||||
}
|
||||
if (key === "") continue;
|
||||
|
||||
const existing = merged.get(key);
|
||||
if (!existing) {
|
||||
merged.set(key, {
|
||||
path: resolved,
|
||||
sources: [candidate.source],
|
||||
threadCount: candidate.threadCount,
|
||||
lastActiveAtMs: candidate.lastActiveAtMs,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
if (!existing.sources.includes(candidate.source)) {
|
||||
existing.sources.push(candidate.source);
|
||||
}
|
||||
existing.threadCount += candidate.threadCount;
|
||||
existing.lastActiveAtMs =
|
||||
existing.lastActiveAtMs === null || candidate.lastActiveAtMs === null
|
||||
? (existing.lastActiveAtMs ?? candidate.lastActiveAtMs)
|
||||
: Math.max(existing.lastActiveAtMs, candidate.lastActiveAtMs);
|
||||
}
|
||||
|
||||
// One snapshot read, compared with the same normalization the
|
||||
// project.create invariant uses, so a root that differs only by case or
|
||||
// separators is still recognized as imported.
|
||||
const shellSnapshot = yield* projectionSnapshotQuery
|
||||
.getShellSnapshot()
|
||||
.pipe(
|
||||
Effect.mapError(
|
||||
(cause) => new AgentSessionScanError({ operation: "read-projects", cause }),
|
||||
),
|
||||
);
|
||||
const importedRoots = new Set(
|
||||
shellSnapshot.projects.map((project) =>
|
||||
normalizeProjectPathForComparison(project.workspaceRoot),
|
||||
),
|
||||
);
|
||||
|
||||
const candidates: Array<AgentSessionProjectCandidate> = [];
|
||||
for (const [key, entry] of merged.entries()) {
|
||||
// Projects may have been created under either the recorded spelling or
|
||||
// the resolved realpath (e.g. a symlinked home) — check both.
|
||||
const alreadyImported =
|
||||
importedRoots.has(normalizeProjectPathForComparison(entry.path)) ||
|
||||
importedRoots.has(normalizeProjectPathForComparison(key));
|
||||
candidates.push({
|
||||
path: entry.path,
|
||||
title: path.basename(entry.path) || entry.path,
|
||||
sources: entry.sources,
|
||||
threadCount: entry.threadCount,
|
||||
lastActiveAt:
|
||||
entry.lastActiveAtMs === null
|
||||
? null
|
||||
: DateTime.formatIso(DateTime.makeUnsafe(entry.lastActiveAtMs)),
|
||||
alreadyImported,
|
||||
});
|
||||
}
|
||||
|
||||
// Newest first, undated candidates last.
|
||||
candidates.sort((left, right) => {
|
||||
if (left.lastActiveAt === right.lastActiveAt) return left.path.localeCompare(right.path);
|
||||
if (left.lastActiveAt === null) return 1;
|
||||
if (right.lastActiveAt === null) return -1;
|
||||
return right.lastActiveAt.localeCompare(left.lastActiveAt);
|
||||
});
|
||||
|
||||
return {
|
||||
candidates,
|
||||
scannedAt: DateTime.formatIso(yield* DateTime.now),
|
||||
};
|
||||
});
|
||||
|
||||
return AgentSessionScanner.of({ scan });
|
||||
});
|
||||
|
||||
export const layer = Layer.effect(AgentSessionScanner, make);
|
||||
@@ -98,6 +98,7 @@ import * as VcsProvisioningService from "./vcs/VcsProvisioningService.ts";
|
||||
import * as GitWorkflowService from "./git/GitWorkflowService.ts";
|
||||
import * as ReviewService from "./review/ReviewService.ts";
|
||||
import * as ProjectSetupScriptRunner from "./project/ProjectSetupScriptRunner.ts";
|
||||
import * as AgentSessionScanner from "./project/AgentSessionScanner.ts";
|
||||
import * as ServerEnvironment from "./environment/ServerEnvironment.ts";
|
||||
import * as BackgroundPolicy from "./background/BackgroundPolicy.ts";
|
||||
import * as EnvironmentAuth from "./auth/EnvironmentAuth.ts";
|
||||
@@ -378,6 +379,7 @@ const makeWsRpcLayer = (
|
||||
const workspaceEntries = yield* WorkspaceEntries.WorkspaceEntries;
|
||||
const workspaceFileSystem = yield* WorkspaceFileSystem.WorkspaceFileSystem;
|
||||
const projectSetupScriptRunner = yield* ProjectSetupScriptRunner.ProjectSetupScriptRunner;
|
||||
const agentSessionScanner = yield* AgentSessionScanner.AgentSessionScanner;
|
||||
const serverEnvironment = yield* ServerEnvironment.ServerEnvironment;
|
||||
const backgroundPolicy = yield* BackgroundPolicy.BackgroundPolicy;
|
||||
const rpcClientIds = yield* Ref.make(new Set<RpcClientId>());
|
||||
@@ -1839,6 +1841,10 @@ const makeWsRpcLayer = (
|
||||
),
|
||||
{ "rpc.aggregate": "workspace" },
|
||||
),
|
||||
[WS_METHODS.agentSessionsScan]: () =>
|
||||
observeRpcEffect(WS_METHODS.agentSessionsScan, agentSessionScanner.scan, {
|
||||
"rpc.aggregate": "workspace",
|
||||
}),
|
||||
[WS_METHODS.assetsCreateUrl]: (input) =>
|
||||
observeRpcEffect(
|
||||
WS_METHODS.assetsCreateUrl,
|
||||
@@ -2309,6 +2315,7 @@ export const websocketRpcRouteLayer = Layer.unwrap(
|
||||
Effect.provide(
|
||||
makeWsRpcLayer(session, previewAutomationBroker).pipe(
|
||||
Layer.provideMerge(RpcSerialization.layerJson),
|
||||
Layer.provide(AgentSessionScanner.layer),
|
||||
Layer.provide(ProviderMaintenanceRunner.layer),
|
||||
Layer.provide(Layer.succeed(ServerSelfUpdate.ServerSelfUpdate, serverSelfUpdate)),
|
||||
// One server-lifetime service means clients share the same PR caches, and a WS
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
import { useAtomValue } from "@effect/atom-react";
|
||||
import { useNavigate } from "@tanstack/react-router";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
import { useClientSettings, useClientSettingsHydrated } from "../../hooks/useSettings";
|
||||
import {
|
||||
useAllEnvironmentShellsBootstrapped,
|
||||
useProjects,
|
||||
useThreadShells,
|
||||
} from "../../state/entities";
|
||||
import { primaryServerConfigAtom } from "../../state/server";
|
||||
|
||||
/**
|
||||
* Holds back the authenticated app tree until the first-run decision is known,
|
||||
* so a fresh install never flashes the main screen before the welcome wizard.
|
||||
* Nothing renders while pending — no shell, no EventRouter (whose welcome
|
||||
* payload would otherwise navigate into a thread), no dialogs.
|
||||
*
|
||||
* Decision order: a set `onboardingCompletedAt` resolves to the app as soon as
|
||||
* settings hydrate (the common case, no server round-trip). A `null` flag also
|
||||
* covers installs that predate the field, so it alone is not enough — the gate
|
||||
* waits for environment shells to bootstrap and inspects the workspace. A
|
||||
* timeout guards the pathological case where shells never bootstrap
|
||||
* (unreachable server): after it, the app renders as usual.
|
||||
*/
|
||||
|
||||
const FIRST_RUN_DECISION_TIMEOUT_MS = 4_000;
|
||||
|
||||
type FirstRunDecision = "pending" | "app" | "wizard";
|
||||
|
||||
export function FirstRunGate({
|
||||
enabled,
|
||||
children,
|
||||
}: {
|
||||
/**
|
||||
* Only an authenticated primary-server session gates. Hosted-static has no
|
||||
* primary server config to inspect and its empty state handles onboarding
|
||||
* itself; gating it would just add a decision timeout to every load.
|
||||
*/
|
||||
readonly enabled: boolean;
|
||||
readonly children: React.ReactNode;
|
||||
}) {
|
||||
const navigate = useNavigate();
|
||||
const hydrated = useClientSettingsHydrated();
|
||||
const onboardingCompletedAt = useClientSettings((settings) => settings.onboardingCompletedAt);
|
||||
const bootstrapped = useAllEnvironmentShellsBootstrapped();
|
||||
const projects = useProjects();
|
||||
const threads = useThreadShells();
|
||||
const serverConfig = useAtomValue(primaryServerConfigAtom);
|
||||
// Within a session settings stay hydrated, so remounts (e.g. returning from
|
||||
// the wizard) resolve synchronously instead of blanking a frame.
|
||||
const [decision, setDecision] = useState<FirstRunDecision>(() =>
|
||||
!enabled || (hydrated && onboardingCompletedAt !== null) ? "app" : "pending",
|
||||
);
|
||||
|
||||
// A workspace still counts as fresh when its only content is the server's
|
||||
// own cwd auto-bootstrap: web mode creates a project + thread from cwd at
|
||||
// startup (`autoBootstrapProjectFromCwd` defaults on there), so "no
|
||||
// projects at all" would mean `npx t3` users never see the wizard. Any
|
||||
// other project, more than one thread, or state in a non-primary
|
||||
// environment is real user state — the aggregate hooks span every
|
||||
// environment, and a saved remote's project must never read as "the
|
||||
// bootstrap project" just because its root string matches the primary cwd.
|
||||
const serverCwd = serverConfig?.cwd ?? null;
|
||||
const primaryEnvironmentId = serverConfig?.environment.environmentId ?? null;
|
||||
const workspaceFresh =
|
||||
projects.every(
|
||||
(project) =>
|
||||
project.environmentId === primaryEnvironmentId && project.workspaceRoot === serverCwd,
|
||||
) &&
|
||||
threads.length <= 1 &&
|
||||
threads.every((thread) => thread.environmentId === primaryEnvironmentId);
|
||||
|
||||
useEffect(() => {
|
||||
if (decision !== "pending" || !hydrated) return;
|
||||
if (!enabled || onboardingCompletedAt !== null) {
|
||||
setDecision("app");
|
||||
return;
|
||||
}
|
||||
// Both shells AND the server config must be in before the workspace can
|
||||
// be judged: shells bootstrap and config load independently, and a
|
||||
// disconnected environment reports bootstrapped with empty projections.
|
||||
// Without the config a fresh cwd-bootstrapped install would read as
|
||||
// non-fresh (projects but no cwd yet), and an offline existing install
|
||||
// would read as fresh (nothing at all). Config never arriving means the
|
||||
// timeout below falls back to the app.
|
||||
if (!bootstrapped || serverConfig === null) return;
|
||||
setDecision(workspaceFresh ? "wizard" : "app");
|
||||
}, [
|
||||
bootstrapped,
|
||||
decision,
|
||||
enabled,
|
||||
hydrated,
|
||||
onboardingCompletedAt,
|
||||
serverConfig,
|
||||
workspaceFresh,
|
||||
]);
|
||||
|
||||
// The fallback only guards a stalled *server* read. It must not start
|
||||
// before settings hydrate, or slow hydration would resolve to the app
|
||||
// without the decision effect ever seeing `onboardingCompletedAt`.
|
||||
useEffect(() => {
|
||||
if (decision !== "pending" || !hydrated) return;
|
||||
const timer = window.setTimeout(() => setDecision("app"), FIRST_RUN_DECISION_TIMEOUT_MS);
|
||||
return () => window.clearTimeout(timer);
|
||||
}, [decision, hydrated]);
|
||||
|
||||
useEffect(() => {
|
||||
if (decision === "wizard") {
|
||||
void navigate({ to: "/welcome", replace: true });
|
||||
}
|
||||
}, [decision, navigate]);
|
||||
|
||||
if (decision !== "app") {
|
||||
return null;
|
||||
}
|
||||
return children;
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,15 @@
|
||||
import { useCallback } from "react";
|
||||
|
||||
import { useUpdateClientSettings } from "../hooks/useSettings";
|
||||
|
||||
/**
|
||||
* Marks first-run onboarding finished (or skipped) so FirstRunGate never
|
||||
* routes to the welcome wizard again. The gate itself lives in
|
||||
* `components/onboarding/FirstRunGate.tsx`.
|
||||
*/
|
||||
export function useCompleteOnboarding(): () => void {
|
||||
const updateClientSettings = useUpdateClientSettings();
|
||||
return useCallback(() => {
|
||||
updateClientSettings({ onboardingCompletedAt: new Date().toISOString() });
|
||||
}, [updateClientSettings]);
|
||||
}
|
||||
@@ -9,6 +9,7 @@
|
||||
// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified.
|
||||
|
||||
import { Route as rootRouteImport } from './routes/__root'
|
||||
import { Route as WelcomeRouteImport } from './routes/welcome'
|
||||
import { Route as UsageRouteImport } from './routes/usage'
|
||||
import { Route as SettingsRouteImport } from './routes/settings'
|
||||
import { Route as PairRouteImport } from './routes/pair'
|
||||
@@ -29,6 +30,11 @@ import { Route as ChatPullRequestsRouteImport } from './routes/_chat.pull-reques
|
||||
import { Route as ChatDraftDraftIdRouteImport } from './routes/_chat.draft.$draftId'
|
||||
import { Route as ChatEnvironmentIdThreadIdRouteImport } from './routes/_chat.$environmentId.$threadId'
|
||||
|
||||
const WelcomeRoute = WelcomeRouteImport.update({
|
||||
id: '/welcome',
|
||||
path: '/welcome',
|
||||
getParentRoute: () => rootRouteImport,
|
||||
} as any)
|
||||
const UsageRoute = UsageRouteImport.update({
|
||||
id: '/usage',
|
||||
path: '/usage',
|
||||
@@ -131,6 +137,7 @@ export interface FileRoutesByFullPath {
|
||||
'/pair': typeof PairRoute
|
||||
'/settings': typeof SettingsRouteWithChildren
|
||||
'/usage': typeof UsageRoute
|
||||
'/welcome': typeof WelcomeRoute
|
||||
'/pull-requests': typeof ChatPullRequestsRoute
|
||||
'/connect/callback': typeof ConnectCallbackRoute
|
||||
'/projects/$projectKey': typeof ProjectsProjectKeyRoute
|
||||
@@ -150,6 +157,7 @@ export interface FileRoutesByTo {
|
||||
'/pair': typeof PairRoute
|
||||
'/settings': typeof SettingsRouteWithChildren
|
||||
'/usage': typeof UsageRoute
|
||||
'/welcome': typeof WelcomeRoute
|
||||
'/pull-requests': typeof ChatPullRequestsRoute
|
||||
'/connect/callback': typeof ConnectCallbackRoute
|
||||
'/projects/$projectKey': typeof ProjectsProjectKeyRoute
|
||||
@@ -172,6 +180,7 @@ export interface FileRoutesById {
|
||||
'/pair': typeof PairRoute
|
||||
'/settings': typeof SettingsRouteWithChildren
|
||||
'/usage': typeof UsageRoute
|
||||
'/welcome': typeof WelcomeRoute
|
||||
'/_chat/pull-requests': typeof ChatPullRequestsRoute
|
||||
'/connect_/callback': typeof ConnectCallbackRoute
|
||||
'/projects/$projectKey': typeof ProjectsProjectKeyRoute
|
||||
@@ -195,6 +204,7 @@ export interface FileRouteTypes {
|
||||
| '/pair'
|
||||
| '/settings'
|
||||
| '/usage'
|
||||
| '/welcome'
|
||||
| '/pull-requests'
|
||||
| '/connect/callback'
|
||||
| '/projects/$projectKey'
|
||||
@@ -214,6 +224,7 @@ export interface FileRouteTypes {
|
||||
| '/pair'
|
||||
| '/settings'
|
||||
| '/usage'
|
||||
| '/welcome'
|
||||
| '/pull-requests'
|
||||
| '/connect/callback'
|
||||
| '/projects/$projectKey'
|
||||
@@ -235,6 +246,7 @@ export interface FileRouteTypes {
|
||||
| '/pair'
|
||||
| '/settings'
|
||||
| '/usage'
|
||||
| '/welcome'
|
||||
| '/_chat/pull-requests'
|
||||
| '/connect_/callback'
|
||||
| '/projects/$projectKey'
|
||||
@@ -257,12 +269,20 @@ export interface RootRouteChildren {
|
||||
PairRoute: typeof PairRoute
|
||||
SettingsRoute: typeof SettingsRouteWithChildren
|
||||
UsageRoute: typeof UsageRoute
|
||||
WelcomeRoute: typeof WelcomeRoute
|
||||
ConnectCallbackRoute: typeof ConnectCallbackRoute
|
||||
ProjectsProjectKeyRoute: typeof ProjectsProjectKeyRoute
|
||||
}
|
||||
|
||||
declare module '@tanstack/react-router' {
|
||||
interface FileRoutesByPath {
|
||||
'/welcome': {
|
||||
id: '/welcome'
|
||||
path: '/welcome'
|
||||
fullPath: '/welcome'
|
||||
preLoaderRoute: typeof WelcomeRouteImport
|
||||
parentRoute: typeof rootRouteImport
|
||||
}
|
||||
'/usage': {
|
||||
id: '/usage'
|
||||
path: '/usage'
|
||||
@@ -447,6 +467,7 @@ const rootRouteChildren: RootRouteChildren = {
|
||||
PairRoute: PairRoute,
|
||||
SettingsRoute: SettingsRouteWithChildren,
|
||||
UsageRoute: UsageRoute,
|
||||
WelcomeRoute: WelcomeRoute,
|
||||
ConnectCallbackRoute: ConnectCallbackRoute,
|
||||
ProjectsProjectKeyRoute: ProjectsProjectKeyRoute,
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import { resolveServerBackedAppDisplayName } from "../branding.logic";
|
||||
import { AppSidebarLayout } from "../components/AppSidebarLayout";
|
||||
import { CommandPalette } from "../components/CommandPalette";
|
||||
import { ConfirmDialogHost } from "../components/ConfirmDialogHost";
|
||||
import { FirstRunGate } from "../components/onboarding/FirstRunGate";
|
||||
import { ConnectOnboardingDialog } from "../components/cloud/ConnectOnboardingDialog";
|
||||
import { RelayClientInstallDialog } from "../components/cloud/RelayClientInstallDialog";
|
||||
import { SshPasswordPromptDialog } from "../components/desktop/SshPasswordPromptDialog";
|
||||
@@ -109,6 +110,17 @@ function RootRouteView() {
|
||||
);
|
||||
}
|
||||
|
||||
// The welcome wizard is full-screen like /pair, but keeps toasts so its
|
||||
// connect/import actions can report failures.
|
||||
if (pathname === "/welcome") {
|
||||
return (
|
||||
<ToastProvider>
|
||||
<DocumentTitleSync />
|
||||
<Outlet />
|
||||
</ToastProvider>
|
||||
);
|
||||
}
|
||||
|
||||
if (authGateState.status !== "authenticated" && authGateState.status !== "hosted-static") {
|
||||
return (
|
||||
<>
|
||||
@@ -126,25 +138,31 @@ function RootRouteView() {
|
||||
</CommandPalette>
|
||||
);
|
||||
|
||||
// FirstRunGate holds back everything below it — including EventRouter,
|
||||
// whose welcome payload navigates into a thread — until the first-run
|
||||
// decision is known, so a fresh install renders nothing (not the shell,
|
||||
// not a flash of threads) before landing on the welcome wizard.
|
||||
return (
|
||||
<ToastProvider>
|
||||
<AnchoredToastProvider>
|
||||
<DocumentTitleSync />
|
||||
<GlassAppearanceSync />
|
||||
<FontAppearanceSync />
|
||||
{primaryEnvironmentAuthenticated ? <AuthenticatedTracingBootstrap /> : null}
|
||||
<RelayClientInstallDialog />
|
||||
<ConnectOnboardingDialog />
|
||||
<SshPasswordPromptDialog />
|
||||
<ConfirmDialogHost />
|
||||
<SlowRpcRequestToastCoordinator />
|
||||
<HostedStaticEnvironmentBootstrap />
|
||||
{primaryEnvironmentAuthenticated ? <EventRouter /> : null}
|
||||
{primaryEnvironmentAuthenticated ? <ProviderUpdateLaunchNotification /> : null}
|
||||
{appShell}
|
||||
{/* Above the router: a theme draft is judged by walking the app, so the
|
||||
editor has to survive navigation away from settings. */}
|
||||
<ThemeEditorHost />
|
||||
<FirstRunGate enabled={primaryEnvironmentAuthenticated}>
|
||||
{primaryEnvironmentAuthenticated ? <AuthenticatedTracingBootstrap /> : null}
|
||||
<RelayClientInstallDialog />
|
||||
<ConnectOnboardingDialog />
|
||||
<SshPasswordPromptDialog />
|
||||
<ConfirmDialogHost />
|
||||
<SlowRpcRequestToastCoordinator />
|
||||
<HostedStaticEnvironmentBootstrap />
|
||||
{primaryEnvironmentAuthenticated ? <EventRouter /> : null}
|
||||
{primaryEnvironmentAuthenticated ? <ProviderUpdateLaunchNotification /> : null}
|
||||
{appShell}
|
||||
{/* Above the router: a theme draft is judged by walking the app, so the
|
||||
editor has to survive navigation away from settings. */}
|
||||
<ThemeEditorHost />
|
||||
</FirstRunGate>
|
||||
</AnchoredToastProvider>
|
||||
</ToastProvider>
|
||||
);
|
||||
|
||||
@@ -80,6 +80,8 @@ function IndexDraftLanding() {
|
||||
/>
|
||||
) : null;
|
||||
}
|
||||
// First-run routing to the welcome wizard happens in FirstRunGate at the
|
||||
// root, before this route ever renders.
|
||||
return <NoProjectsHero />;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import { createFileRoute, redirect, useNavigate } from "@tanstack/react-router";
|
||||
|
||||
import { WelcomeWizard } from "../components/onboarding/WelcomeWizard";
|
||||
|
||||
/**
|
||||
* First-run welcome wizard. Full-screen, outside the sidebar shell (the root
|
||||
* route mounts this path bare, like /pair). Reached only via the first-run
|
||||
* gate on the index route; visiting it directly after onboarding is harmless —
|
||||
* finishing again just refreshes the completion flag.
|
||||
*/
|
||||
export const Route = createFileRoute("/welcome")({
|
||||
beforeLoad: ({ context }) => {
|
||||
const { authGateState } = context;
|
||||
if (authGateState.status !== "authenticated" && authGateState.status !== "hosted-static") {
|
||||
throw redirect({ to: "/pair", replace: true });
|
||||
}
|
||||
},
|
||||
component: WelcomeRouteView,
|
||||
});
|
||||
|
||||
function WelcomeRouteView() {
|
||||
const { authGateState } = Route.useRouteContext();
|
||||
const navigate = useNavigate();
|
||||
// An authenticated gate means a primary server is serving this app —
|
||||
// desktop, `npx t3`, or a dev server — and that server is "this machine"
|
||||
// no matter what hostname the browser used. Only hosted-static has no
|
||||
// local server to offer.
|
||||
const localAvailable = authGateState.status === "authenticated";
|
||||
return (
|
||||
<WelcomeWizard
|
||||
localAvailable={localAvailable}
|
||||
onDone={() => {
|
||||
void navigate({ to: "/", replace: true });
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { WS_METHODS } from "@t3tools/contracts";
|
||||
import { createEnvironmentRpcQueryAtomFamily } from "@t3tools/client-runtime/state/runtime";
|
||||
|
||||
import { connectionAtomRuntime } from "../connection/runtime";
|
||||
|
||||
/**
|
||||
* Scan of Claude Code / Codex home directories on an environment, surfacing
|
||||
* project candidates for the welcome wizard's import step. The scan walks the
|
||||
* filesystem server-side, so results are cached briefly and refreshed when the
|
||||
* import step remounts.
|
||||
*/
|
||||
export const agentSessionScan = createEnvironmentRpcQueryAtomFamily(connectionAtomRuntime, {
|
||||
label: "environment-data:agent-sessions:scan",
|
||||
tag: WS_METHODS.agentSessionsScan,
|
||||
staleTimeMs: 30_000,
|
||||
idleTtlMs: 5 * 60_000,
|
||||
});
|
||||
@@ -0,0 +1,36 @@
|
||||
# Welcome Wizard
|
||||
|
||||
On a fresh install, T3 Code opens a short setup flow before the main app.
|
||||
Installs with existing projects or completed onboarding skip it.
|
||||
|
||||
## Choose how to connect
|
||||
|
||||
- **Local Only** — agents run on this machine. No account needed. Shown on the
|
||||
desktop app and locally served web app.
|
||||
- **T3 Connect** — sign in and reach any of your machines from anywhere.
|
||||
Machines signed into your account connect automatically. If none are
|
||||
connected yet, the wizard shows the command to run on the machine with your
|
||||
code (`npx t3 connect`); the machine appears in the list once it signs in,
|
||||
and **Continue** becomes available.
|
||||
- **Direct** — connect to a server by URL. Works over LAN and Tailscale. Run
|
||||
`npx t3 pair` on the server and paste the pairing URL it prints.
|
||||
|
||||
## Set up your agents
|
||||
|
||||
The wizard checks the connected machine for Claude Code and Codex and shows
|
||||
their install and sign-in status. If one is missing, an inline terminal opens
|
||||
with the install command pre-typed — press Enter to run it, then click
|
||||
**Done**. Once the agent is detected, its card offers **Sign in**, which opens
|
||||
a fresh terminal with the CLI's login command ready to run. Other supported
|
||||
agents are configured in Settings → Providers.
|
||||
|
||||
## Import your projects
|
||||
|
||||
T3 Code scans the connected machine for directories where Claude Code or Codex
|
||||
have already run and offers them as projects. The default imports projects
|
||||
active in the last 30 days; **Choose** lists everything found. Imports create
|
||||
projects only — thread history import is coming later.
|
||||
|
||||
The agent and import steps can be skipped, and the remote paths offer Back to
|
||||
choose a different connection. Projects can always be added later from the
|
||||
command palette.
|
||||
@@ -0,0 +1,46 @@
|
||||
import * as Schema from "effect/Schema";
|
||||
import { IsoDateTime, NonNegativeInt, TrimmedNonEmptyString } from "./baseSchemas.ts";
|
||||
|
||||
/** Coding agent home directories the scanner knows how to read. */
|
||||
export const AgentSessionSource = Schema.Literals(["claudeAgent", "codex"]);
|
||||
export type AgentSessionSource = typeof AgentSessionSource.Type;
|
||||
|
||||
/**
|
||||
* Empty for now. Kept as a struct so future scan options (source filters,
|
||||
* explicit roots) can be added without a new method.
|
||||
*/
|
||||
export const AgentSessionScanInput = Schema.Struct({});
|
||||
export type AgentSessionScanInput = typeof AgentSessionScanInput.Type;
|
||||
|
||||
/**
|
||||
* A directory that at least one agent CLI has run in, suitable for import as a
|
||||
* T3 Code project. `alreadyImported` marks candidates that already have an
|
||||
* active project rooted at the same path.
|
||||
*/
|
||||
export const AgentSessionProjectCandidate = Schema.Struct({
|
||||
path: TrimmedNonEmptyString,
|
||||
title: TrimmedNonEmptyString,
|
||||
sources: Schema.Array(AgentSessionSource),
|
||||
threadCount: NonNegativeInt,
|
||||
lastActiveAt: Schema.NullOr(IsoDateTime),
|
||||
alreadyImported: Schema.Boolean,
|
||||
});
|
||||
export type AgentSessionProjectCandidate = typeof AgentSessionProjectCandidate.Type;
|
||||
|
||||
export const AgentSessionScanResult = Schema.Struct({
|
||||
candidates: Schema.Array(AgentSessionProjectCandidate),
|
||||
scannedAt: IsoDateTime,
|
||||
});
|
||||
export type AgentSessionScanResult = typeof AgentSessionScanResult.Type;
|
||||
|
||||
export class AgentSessionScanError extends Schema.TaggedErrorClass<AgentSessionScanError>()(
|
||||
"AgentSessionScanError",
|
||||
{
|
||||
operation: Schema.Literals(["read-settings", "read-projects"]),
|
||||
cause: Schema.Defect(),
|
||||
},
|
||||
) {
|
||||
override get message(): string {
|
||||
return `Failed to scan agent sessions during ${this.operation}.`;
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,7 @@ export * from "./t3ProjectFile.ts";
|
||||
export * from "./editor.ts";
|
||||
export * from "./project.ts";
|
||||
export * from "./filesystem.ts";
|
||||
export * from "./agentSessions.ts";
|
||||
export * from "./assets.ts";
|
||||
export * from "./review.ts";
|
||||
export * from "./preview.ts";
|
||||
|
||||
@@ -18,6 +18,11 @@ import {
|
||||
FilesystemBrowseResult,
|
||||
FilesystemBrowseError,
|
||||
} from "./filesystem.ts";
|
||||
import {
|
||||
AgentSessionScanInput,
|
||||
AgentSessionScanResult,
|
||||
AgentSessionScanError,
|
||||
} from "./agentSessions.ts";
|
||||
import { AssetAccessError, AssetCreateUrlInput, AssetCreateUrlResult } from "./assets.ts";
|
||||
import {
|
||||
GitActionProgressEvent,
|
||||
@@ -207,6 +212,7 @@ export const WS_METHODS = {
|
||||
|
||||
// Filesystem methods
|
||||
filesystemBrowse: "filesystem.browse",
|
||||
agentSessionsScan: "agentSessions.scan",
|
||||
assetsCreateUrl: "assets.createUrl",
|
||||
|
||||
// VCS methods
|
||||
@@ -650,6 +656,12 @@ export const WsFilesystemBrowseRpc = Rpc.make(WS_METHODS.filesystemBrowse, {
|
||||
error: Schema.Union([FilesystemBrowseError, EnvironmentAuthorizationError]),
|
||||
});
|
||||
|
||||
export const WsAgentSessionsScanRpc = Rpc.make(WS_METHODS.agentSessionsScan, {
|
||||
payload: AgentSessionScanInput,
|
||||
success: AgentSessionScanResult,
|
||||
error: Schema.Union([AgentSessionScanError, EnvironmentAuthorizationError]),
|
||||
});
|
||||
|
||||
export const WsAssetsCreateUrlRpc = Rpc.make(WS_METHODS.assetsCreateUrl, {
|
||||
payload: AssetCreateUrlInput,
|
||||
success: AssetCreateUrlResult,
|
||||
@@ -1023,6 +1035,7 @@ export const WsRpcGroup = RpcGroup.make(
|
||||
WsProjectsWriteFileRpc,
|
||||
WsShellOpenInEditorRpc,
|
||||
WsFilesystemBrowseRpc,
|
||||
WsAgentSessionsScanRpc,
|
||||
WsAssetsCreateUrlRpc,
|
||||
WsSubscribeVcsStatusRpc,
|
||||
WsVcsPullRpc,
|
||||
|
||||
@@ -143,6 +143,13 @@ export const ClientSettingsSchema = Schema.Struct({
|
||||
// Grayscale `-webkit-font-smoothing: antialiased` (thinner strokes);
|
||||
// disabling restores the platform's heavier default. No effect off macOS.
|
||||
fontSmoothing: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
|
||||
// When the first-run welcome wizard finished (or was skipped), as an ISO
|
||||
// timestamp. `null` alone does not mean "show the wizard" — every install
|
||||
// that predates this field decodes to `null` — so the gate also requires an
|
||||
// empty workspace before it treats the client as a fresh install.
|
||||
onboardingCompletedAt: Schema.NullOr(Schema.String).pipe(
|
||||
Schema.withDecodingDefault(Effect.succeed(null)),
|
||||
),
|
||||
// Model favorites. Historically keyed by provider kind, now
|
||||
// widened to `ProviderInstanceId` so users can favorite a specific model
|
||||
// on a custom provider instance (e.g. "Codex Personal · gpt-5") without
|
||||
@@ -761,6 +768,7 @@ export const ClientSettingsPatch = Schema.Struct({
|
||||
diffIgnoreWhitespace: Schema.optionalKey(Schema.Boolean),
|
||||
environmentIdentificationMode: Schema.optionalKey(EnvironmentIdentificationMode),
|
||||
glassOpacity: Schema.optionalKey(GlassOpacity),
|
||||
onboardingCompletedAt: Schema.optionalKey(Schema.NullOr(Schema.String)),
|
||||
fontSizeInterface: Schema.optionalKey(InterfaceFontSize),
|
||||
fontSizePrompt: Schema.optionalKey(PromptFontSize),
|
||||
fontSizeCode: Schema.optionalKey(CodeFontSize),
|
||||
|
||||
Reference in new issue
Block a user