GeezerVison is showing github.com — feat: added configurable base directory. (#826) · aaditagrawal/t3code@d10016d
This repository was archived by the owner on Oct 10, 2026. It is now read-only.
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: .docs/scripts.md +1-1Lines changed: 1 addition & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| 5 | 5 | - `bun run dev:web` — Starts just the Vite dev server for the web app. | 6 | 6 | - Dev commands default `T3CODE_STATE_DIR` to `~/.t3/dev` to keep dev state isolated from desktop/prod state. | 7 | 7 | - Override server CLI-equivalent flags from root dev commands with `--`, for example: | 8 | | - `bun run dev -- --state-dir ~/.t3/another-dev-state` | | 8 | + `bun run dev -- --base-dir ~/.t3-2` | 9 | 9 | - `bun run start` — Runs the production server (serves built web app as static files). | 10 | 10 | - `bun run build` — Builds contracts, web app, and server through Turbo. | 11 | 11 | - `bun run typecheck` — Strict TypeScript checks for all packages. | |
Collapse file Copy file name to clipboardExpand all lines: REMOTE.md +1-1Lines changed: 1 addition & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -11,7 +11,7 @@ The T3 Code CLI accepts the following configuration options, available either as | 11 | 11 | | `--mode <web\|desktop>` | `T3CODE_MODE` | Runtime mode. | | 12 | 12 | | `--port <number>` | `T3CODE_PORT` | HTTP/WebSocket port. | | 13 | 13 | | `--host <address>` | `T3CODE_HOST` | Bind interface/address. | | 14 | | -| `--state-dir <path>` | `T3CODE_STATE_DIR` | State directory. | | | 14 | +| `--base-dir <path>` | `T3CODE_HOME` | Base directory. | | 15 | 15 | | `--dev-url <url>` | `VITE_DEV_SERVER_URL` | Dev web URL redirect/proxy target. | | 16 | 16 | | `--no-browser` | `T3CODE_NO_BROWSER` | Disable auto-open browser. | | 17 | 17 | | `--auth-token <token>` | `T3CODE_AUTH_TOKEN` | WebSocket auth token. | | |
Collapse file Copy file name to clipboardExpand all lines: apps/desktop/src/main.ts +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -61,8 +61,8 @@ const LOG_DIR_CHANNEL = "desktop:log-dir"; | 61 | 61 | const LOG_LIST_CHANNEL = "desktop:log-list"; | 62 | 62 | const LOG_READ_CHANNEL = "desktop:log-read"; | 63 | 63 | const LOG_OPEN_DIR_CHANNEL = "desktop:log-open-dir"; | 64 | | -const STATE_DIR = | 65 | | - process.env.T3CODE_STATE_DIR?.trim() || Path.join(OS.homedir(), ".t3", "userdata"); | | 64 | +const BASE_DIR = process.env.T3CODE_HOME?.trim() || Path.join(OS.homedir(), ".t3"); | | 65 | +const STATE_DIR = Path.join(BASE_DIR, "userdata"); | 66 | 66 | const DESKTOP_SCHEME = "t3"; | 67 | 67 | const ROOT_DIR = Path.resolve(__dirname, "../../.."); | 68 | 68 | const isDevelopment = Boolean(process.env.VITE_DEV_SERVER_URL); | @@ -929,7 +929,7 @@ function backendEnv(): NodeJS.ProcessEnv { | 929 | 929 | T3CODE_MODE: "desktop", | 930 | 930 | T3CODE_NO_BROWSER: "1", | 931 | 931 | T3CODE_PORT: String(backendPort), | 932 | | - T3CODE_STATE_DIR: STATE_DIR, | | 932 | + T3CODE_HOME: BASE_DIR, | 933 | 933 | T3CODE_AUTH_TOKEN: backendAuthToken, | 934 | 934 | }; | 935 | 935 | } | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/integration/OrchestrationEngineHarness.integration.ts +24-24Lines changed: 24 additions & 24 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -import fs from "node:fs"; | 2 | | -import os from "node:os"; | 3 | | -import path from "node:path"; | 4 | 1 | import { execFileSync } from "node:child_process"; | 5 | 2 |
| 6 | 3 | import * as NodeServices from "@effect/platform-node/NodeServices"; | @@ -13,9 +10,11 @@ import { | 13 | 10 | import { | 14 | 11 | Effect, | 15 | 12 | Exit, | | 13 | + FileSystem, | 16 | 14 | Layer, | 17 | 15 | ManagedRuntime, | 18 | 16 | Option, | | 17 | + Path, | 19 | 18 | Ref, | 20 | 19 | Schedule, | 21 | 20 | Schema, | @@ -66,7 +65,7 @@ import { | 66 | 65 | makeTestProviderAdapterHarness, | 67 | 66 | type TestProviderAdapterHarness, | 68 | 67 | } from "./TestProviderAdapter.integration.ts"; | 69 | | -import { ServerConfig } from "../src/config.ts"; | | 68 | +import { deriveServerPaths, ServerConfig } from "../src/config.ts"; | 70 | 69 |
| 71 | 70 | function runGit(cwd: string, args: ReadonlyArray<string>) { | 72 | 71 | return execFileSync("git", args, { | @@ -76,14 +75,16 @@ function runGit(cwd: string, args: ReadonlyArray<string>) { | 76 | 75 | }); | 77 | 76 | } | 78 | 77 |
| 79 | | -function initializeGitWorkspace(cwd: string) { | | 78 | +const initializeGitWorkspace = Effect.fn(function* (cwd: string) { | 80 | 79 | runGit(cwd, ["init", "--initial-branch=main"]); | 81 | 80 | | 82 | 81 | runGit(cwd, ["config", "user.name", "Test User"]); | 83 | | - fs.writeFileSync(path.join(cwd, "README.md"), "v1\n", "utf8"); | | 82 | + const fileSystem = yield* FileSystem.FileSystem; | | 83 | + const { join } = yield* Path.Path; | | 84 | + yield* fileSystem.writeFileString(join(cwd, "README.md"), "v1\n"); | 84 | 85 | runGit(cwd, ["add", "."]); | 85 | 86 | runGit(cwd, ["commit", "-m", "Initial"]); | 86 | | -} | | 87 | +}); | 87 | 88 |
| 88 | 89 | export function gitRefExists(cwd: string, ref: string): boolean { | 89 | 90 | try { | @@ -214,7 +215,9 @@ export const makeOrchestrationIntegrationHarness = ( | 214 | 215 | options?: MakeOrchestrationIntegrationHarnessOptions, | 215 | 216 | ) => | 216 | 217 | Effect.gen(function* () { | 217 | | - const sleep = (ms: number) => Effect.sleep(ms); | | 218 | + const path = yield* Path.Path; | | 219 | + const fileSystem = yield* FileSystem.FileSystem; | | 220 | + | 218 | 221 | const provider = options?.provider ?? "codex"; | 219 | 222 | const useRealCodex = options?.realCodex === true; | 220 | 223 | const adapterHarness = useRealCodex | @@ -231,13 +234,16 @@ export const makeOrchestrationIntegrationHarness = ( | 231 | 234 | listProviders: () => Effect.succeed([adapterHarness.provider]), | 232 | 235 | } as typeof ProviderAdapterRegistry.Service) | 233 | 236 | : null; | 234 | | - const rootDir = fs.mkdtempSync(path.join(os.tmpdir(), "t3-orchestration-integration-")); | | 237 | + const rootDir = yield* fileSystem.makeTempDirectoryScoped({ | | 238 | + prefix: "t3-orchestration-integration-", | | 239 | + }); | 235 | 240 | const workspaceDir = path.join(rootDir, "workspace"); | 236 | | - const stateDir = path.join(rootDir, "state"); | 237 | | - const dbPath = path.join(stateDir, "state.sqlite"); | 238 | | - fs.mkdirSync(workspaceDir, { recursive: true }); | 239 | | - fs.mkdirSync(stateDir, { recursive: true }); | 240 | | - initializeGitWorkspace(workspaceDir); | | 241 | + const { stateDir, dbPath } = yield* deriveServerPaths(rootDir, undefined).pipe( | | 242 | + Effect.provideService(Path.Path, path), | | 243 | + ); | | 244 | + yield* fileSystem.makeDirectory(workspaceDir, { recursive: true }); | | 245 | + yield* fileSystem.makeDirectory(stateDir, { recursive: true }); | | 246 | + yield* initializeGitWorkspace(workspaceDir); | 241 | 247 |
| 242 | 248 | const persistenceLayer = makeSqlitePersistenceLive(dbPath); | 243 | 249 | const orchestrationLayer = OrchestrationEngineLive.pipe( | @@ -262,7 +268,7 @@ export const makeOrchestrationIntegrationHarness = ( | 262 | 268 | }), | 263 | 269 | ).pipe( | 264 | 270 | Layer.provide(makeCodexAdapterLive()), | 265 | | - Layer.provideMerge(ServerConfig.layerTest(workspaceDir, stateDir)), | | 271 | + Layer.provideMerge(ServerConfig.layerTest(workspaceDir, rootDir)), | 266 | 272 | Layer.provideMerge(NodeServices.layer), | 267 | 273 | Layer.provideMerge(providerSessionDirectoryLayer), | 268 | 274 | ); | @@ -312,7 +318,7 @@ export const makeOrchestrationIntegrationHarness = ( | 312 | 318 | ); | 313 | 319 | const layer = orchestrationReactorLayer.pipe( | 314 | 320 | Layer.provide(persistenceLayer), | 315 | | - Layer.provideMerge(ServerConfig.layerTest(workspaceDir, stateDir)), | | 321 | + Layer.provideMerge(ServerConfig.layerTest(workspaceDir, rootDir)), | 316 | 322 | Layer.provideMerge(NodeServices.layer), | 317 | 323 | ); | 318 | 324 |
| @@ -352,7 +358,7 @@ export const makeOrchestrationIntegrationHarness = ( | 352 | 358 | yield* Stream.runForEach(runtimeReceiptBus.stream, (receipt) => | 353 | 359 | Ref.update(receiptHistory, (history) => [...history, receipt]).pipe(Effect.asVoid), | 354 | 360 | ).pipe(Effect.forkIn(scope)); | 355 | | - yield* sleep(10); | | 361 | + yield* Effect.sleep(10); | 356 | 362 |
| 357 | 363 | const waitForThread: OrchestrationIntegrationHarness["waitForThread"] = ( | 358 | 364 | threadId, | @@ -469,13 +475,7 @@ export const makeOrchestrationIntegrationHarness = ( | 469 | 475 | } | 470 | 476 | }); | 471 | 477 |
| 472 | | - yield* shutdown.pipe( | 473 | | - Effect.ensuring( | 474 | | - Effect.sync(() => { | 475 | | - fs.rmSync(rootDir, { recursive: true, force: true }); | 476 | | - }), | 477 | | - ), | 478 | | - ); | | 478 | + yield* shutdown; | 479 | 479 | }); | 480 | 480 |
| 481 | 481 | return { | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/integration/orchestrationEngine.integration.test.ts +4-5Lines changed: 4 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -27,6 +27,7 @@ import type { | 27 | 27 | CheckpointDiffFinalizedReceipt, | 28 | 28 | TurnProcessingQuiescedReceipt, | 29 | 29 | } from "../src/orchestration/Services/RuntimeReceiptBus.ts"; | | 30 | +import * as NodeServices from "@effect/platform-node/NodeServices"; | 30 | 31 |
| 31 | 32 | const asMessageId = (value: string): MessageId => MessageId.makeUnsafe(value); | 32 | 33 | const asProjectId = (value: string): ProjectId => ProjectId.makeUnsafe(value); | @@ -51,8 +52,6 @@ class IntegrationWaitTimeoutError extends Schema.TaggedErrorClass<IntegrationWai | 51 | 52 | }, | 52 | 53 | ) {} | 53 | 54 |
| 54 | | -const sleep = (ms: number) => Effect.sleep(ms); | 55 | | - | 56 | 55 | function waitForSync<A>( | 57 | 56 | read: () => A, | 58 | 57 | predicate: (value: A) => boolean, | @@ -70,7 +69,7 @@ function waitForSync<A>( | 70 | 69 | if (Date.now() >= deadline) { | 71 | 70 | return yield* Effect.die(new IntegrationWaitTimeoutError({ description })); | 72 | 71 | } | 73 | | - yield* sleep(10); | | 72 | + yield* Effect.sleep(10); | 74 | 73 | } | 75 | 74 | }); | 76 | 75 | } | @@ -91,7 +90,7 @@ function withHarness<A, E>( | 91 | 90 | makeOrchestrationIntegrationHarness({ provider }), | 92 | 91 | use, | 93 | 92 | (harness) => harness.dispose, | 94 | | - ); | | 93 | + ).pipe(Effect.provide(NodeServices.layer)); | 95 | 94 | } | 96 | 95 |
| 97 | 96 | function withRealCodexHarness<A, E>( | @@ -101,7 +100,7 @@ function withRealCodexHarness<A, E>( | 101 | 100 | makeOrchestrationIntegrationHarness({ provider: "codex", realCodex: true }), | 102 | 101 | use, | 103 | 102 | (harness) => harness.dispose, | 104 | | - ); | | 103 | + ).pipe(Effect.provide(NodeServices.layer)); | 105 | 104 | } | 106 | 105 |
| 107 | 106 | const seedProjectAndThread = (harness: OrchestrationIntegrationHarness) => | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/attachmentPaths.ts +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -11,15 +11,15 @@ export function normalizeAttachmentRelativePath(rawRelativePath: string): string | 11 | 11 | } | 12 | 12 |
| 13 | 13 | export function resolveAttachmentRelativePath(input: { | 14 | | - readonly stateDir: string; | | 14 | + readonly attachmentsDir: string; | 15 | 15 | readonly relativePath: string; | 16 | 16 | }): string | null { | 17 | 17 | const normalizedRelativePath = normalizeAttachmentRelativePath(input.relativePath); | 18 | 18 | if (!normalizedRelativePath) { | 19 | 19 | return null; | 20 | 20 | } | 21 | 21 |
| 22 | | - const attachmentsRoot = path.resolve(path.join(input.stateDir, "attachments")); | | 22 | + const attachmentsRoot = path.resolve(input.attachmentsDir); | 23 | 23 | const filePath = path.resolve(path.join(attachmentsRoot, normalizedRelativePath)); | 24 | 24 | if (!filePath.startsWith(`${attachmentsRoot}${path.sep}`)) { | 25 | 25 | return null; | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/attachmentStore.test.ts +6-8Lines changed: 6 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -44,34 +44,32 @@ describe("attachmentStore", () => { | 44 | 44 | }); | 45 | 45 |
| 46 | 46 | it("resolves attachment path by id using the extension that exists on disk", () => { | 47 | | - const stateDir = fs.mkdtempSync(path.join(os.tmpdir(), "t3code-attachment-store-")); | | 47 | + const attachmentsDir = fs.mkdtempSync(path.join(os.tmpdir(), "t3code-attachment-store-")); | 48 | 48 | try { | 49 | 49 | const attachmentId = "thread-1-attachment"; | 50 | | - const attachmentsDir = path.join(stateDir, "attachments"); | 51 | | - fs.mkdirSync(attachmentsDir, { recursive: true }); | 52 | 50 | const pngPath = path.join(attachmentsDir, `${attachmentId}.png`); | 53 | 51 | fs.writeFileSync(pngPath, Buffer.from("hello")); | 54 | 52 |
| 55 | 53 | const resolved = resolveAttachmentPathById({ | 56 | | - stateDir, | | 54 | + attachmentsDir, | 57 | 55 | attachmentId, | 58 | 56 | }); | 59 | 57 | expect(resolved).toBe(pngPath); | 60 | 58 | } finally { | 61 | | - fs.rmSync(stateDir, { recursive: true, force: true }); | | 59 | + fs.rmSync(attachmentsDir, { recursive: true, force: true }); | 62 | 60 | } | 63 | 61 | }); | 64 | 62 |
| 65 | 63 | it("returns null when no attachment file exists for the id", () => { | 66 | | - const stateDir = fs.mkdtempSync(path.join(os.tmpdir(), "t3code-attachment-store-")); | | 64 | + const attachmentsDir = fs.mkdtempSync(path.join(os.tmpdir(), "t3code-attachment-store-")); | 67 | 65 | try { | 68 | 66 | const resolved = resolveAttachmentPathById({ | 69 | | - stateDir, | | 67 | + attachmentsDir, | 70 | 68 | attachmentId: "thread-1-missing", | 71 | 69 | }); | 72 | 70 | expect(resolved).toBeNull(); | 73 | 71 | } finally { | 74 | | - fs.rmSync(stateDir, { recursive: true, force: true }); | | 72 | + fs.rmSync(attachmentsDir, { recursive: true, force: true }); | 75 | 73 | } | 76 | 74 | }); | 77 | 75 | }); |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/attachmentStore.ts +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -66,17 +66,17 @@ export function attachmentRelativePath(attachment: ChatAttachment): string { | 66 | 66 | } | 67 | 67 |
| 68 | 68 | export function resolveAttachmentPath(input: { | 69 | | - readonly stateDir: string; | | 69 | + readonly attachmentsDir: string; | 70 | 70 | readonly attachment: ChatAttachment; | 71 | 71 | }): string | null { | 72 | 72 | return resolveAttachmentRelativePath({ | 73 | | - stateDir: input.stateDir, | | 73 | + attachmentsDir: input.attachmentsDir, | 74 | 74 | relativePath: attachmentRelativePath(input.attachment), | 75 | 75 | }); | 76 | 76 | } | 77 | 77 |
| 78 | 78 | export function resolveAttachmentPathById(input: { | 79 | | - readonly stateDir: string; | | 79 | + readonly attachmentsDir: string; | 80 | 80 | readonly attachmentId: string; | 81 | 81 | }): string | null { | 82 | 82 | const normalizedId = normalizeAttachmentRelativePath(input.attachmentId); | @@ -85,7 +85,7 @@ export function resolveAttachmentPathById(input: { | 85 | 85 | } | 86 | 86 | for (const extension of ATTACHMENT_FILENAME_EXTENSIONS) { | 87 | 87 | const maybePath = resolveAttachmentRelativePath({ | 88 | | - stateDir: input.stateDir, | | 88 | + attachmentsDir: input.attachmentsDir, | 89 | 89 | relativePath: `${normalizedId}${extension}`, | 90 | 90 | }); | 91 | 91 | if (maybePath && existsSync(maybePath)) { | |
|