The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 03:15 UTC
fix(cli): expand home-relative thread project paths (#30721)
Johan Vaz committed
Nov 6, 2026 at 12:35 UTC
6d5772b33dea46bc8e2211e83b8844ce88e4b0cc
2 files changed
+133
-3
apps/server/src/cli/thread.test.ts
+129
-2
@@ -1,12 +1,139 @@
1
+import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
2
+import * as NodeServices from "@effect/platform-node/NodeServices";
3
import { assert, it } from "@effect/vitest";
2
-import { RunId, ThreadId } from "@t3tools/contracts";
4
+import { AuthSessionId, ProjectId, RunId, ThreadId } from "@t3tools/contracts";
5
+import * as HostProcess from "@t3tools/shared/HostProcess";
6
+import * as NetService from "@t3tools/shared/Net";
7
+import * as ConfigProvider from "effect/ConfigProvider";
8
+import * as DateTime from "effect/DateTime";
9
import * as Effect from "effect/Effect";
10
+import * as FileSystem from "effect/FileSystem";
11
+import * as Layer from "effect/Layer";
12
+import * as Path from "effect/Path";
13
+import * as TestConsole from "effect/testing/TestConsole";
14
+import { Command } from "effect/cli";
15
+import { vi } from "vite-plus/test";
16
5
-import { readLatestMessages, type ThreadTools, titleFromMessage, waitForRun } from "./thread.ts";
17
+import * as McpBridge from "../mcp/AcpMcpStdioBridge.ts";
18
+import {
19
+ makePersistedServerRuntimeState,
20
+ persistServerRuntimeState,
21
+} from "../serverRuntimeState.ts";
22
+import {
23
+ readLatestMessages,
24
+ threadCommand,
25
+ type ThreadTools,
26
+ titleFromMessage,
27
+ waitForRun,
28
+} from "./thread.ts";
29
+
30
+vi.mock("../auth/EnvironmentAuth.ts", async (importOriginal) => {
31
+ const actual = await importOriginal<typeof import("../auth/EnvironmentAuth.ts")>();
32
+ return {
33
+ ...actual,
34
+ layerRuntime: Layer.mock(actual.EnvironmentAuth)({
35
+ issueMcpClientSession: () =>
36
+ Effect.map(DateTime.now, (expiresAt) => ({
37
+ sessionId: AuthSessionId.make("test-session"),
38
+ token: "synthetic-token",
39
+ expiresAt,
40
+ })),
41
+ revokeSession: () => Effect.succeed(true),
42
+ }),
43
+ };
44
+});
45
46
const threadId = ThreadId.make("thread-1");
47
const runId = RunId.make("run-1");
48
49
+it.effect(
50
+ "start resolves home-relative project paths while preserving ids and relative paths",
51
+ () =>
52
+ Effect.gen(function* () {
53
+ const fs = yield* FileSystem.FileSystem;
54
+ const path = yield* Path.Path;
55
+ const root = yield* fs
56
+ .makeTempDirectoryScoped({ prefix: "t3-thread-project-path-" })
57
+ .pipe(Effect.flatMap((directory) => fs.realPath(directory)));
58
+ const home = path.join(root, "home");
59
+ const cwd = path.join(root, "current");
60
+ const workspaceRoot = path.join(home, "My Project");
61
+ const nestedRoot = path.join(workspaceRoot, "nested");
62
+ const baseDir = path.join(root, "state");
63
+ yield* fs.makeDirectory(nestedRoot, { recursive: true });
64
+ yield* fs.makeDirectory(cwd);
65
+ const projects = [
66
+ { id: ProjectId.make("current-project"), title: "Current", workspaceRoot: cwd },
67
+ { id: ProjectId.make("home-project"), title: "Home", workspaceRoot: home },
68
+ { id: ProjectId.make("intended-project"), title: "Intended", workspaceRoot },
69
+ { id: ProjectId.make("nested-project"), title: "Nested", workspaceRoot: nestedRoot },
70
+ { id: ProjectId.make("~/literal-id"), title: "Exact id", workspaceRoot: cwd },
71
+ ];
72
+ yield* persistServerRuntimeState({
73
+ path: path.join(baseDir, "userdata", "server-runtime.json"),
74
+ state: yield* makePersistedServerRuntimeState({
75
+ config: { host: "127.0.0.1", devUrl: undefined },
76
+ port: 3_773,
77
+ }),
78
+ });
79
+ using _session = vi.spyOn(McpBridge, "mcpToolSession").mockReturnValue(
80
+ Effect.succeed({
81
+ call: (tool, args) => {
82
+ switch (tool) {
83
+ case "t3_project_list":
84
+ return Effect.succeed({ structuredContent: { projects, nextCursor: null } });
85
+ case "t3_thread_launch":
86
+ return Effect.succeed({
87
+ structuredContent: { threadId, projectId: args.projectId, runId: null },
88
+ });
89
+ default:
90
+ return Effect.die(`unexpected ${tool} call`);
91
+ }
92
+ },
93
+ }),
94
+ );
95
+
96
+ for (const [identifier, expectedProjectId] of [
97
+ ["intended-project", "intended-project"],
98
+ ["~/literal-id", "~/literal-id"],
99
+ [workspaceRoot, "intended-project"],
100
+ [path.relative(cwd, workspaceRoot), "intended-project"],
101
+ [".", "current-project"],
102
+ ["~/My Project", "intended-project"],
103
+ ["~", "home-project"],
104
+ ["~/My Project/nested", "nested-project"],
105
+ ["~/My Project/missing", "intended-project"],
106
+ ] as const) {
107
+ yield* Command.runWith(threadCommand, { version: "0.0.0" })([
108
+ "start",
109
+ identifier,
110
+ "Inspect this project",
111
+ "--json",
112
+ "--base-dir",
113
+ baseDir,
114
+ ]).pipe(
115
+ Effect.provideService(HostProcess.HomeDirectory, home),
116
+ Effect.provideService(HostProcess.WorkingDirectory, cwd),
117
+ );
118
+ assert.strictEqual(
119
+ (yield* TestConsole.logLines).at(-1),
120
+ JSON.stringify({ threadId, projectId: expectedProjectId, runId: null }),
121
+ identifier,
122
+ );
123
+ }
124
+ }).pipe(
125
+ Effect.scoped,
126
+ Effect.provide(
127
+ Layer.mergeAll(
128
+ NodeServices.layer,
129
+ NodeCrypto.layer,
130
+ NetService.layer,
131
+ ConfigProvider.layer(ConfigProvider.fromEnv({ env: { T3CODE_PORT: "3773" } })),
132
+ ),
133
+ ),
134
+ ),
135
+);
136
+
137
/** Answers each tool call with the next scripted response for that tool. */
138
const scriptedTools = (script: Record<string, Array<unknown>>) => {
139
const calls: Array<{ readonly tool: string; readonly args: unknown }> = [];
apps/server/src/cli/thread.ts
+4
-1
@@ -29,6 +29,7 @@ import { Argument, Command, Flag, GlobalFlag } from "effect/cli";
29
import * as EnvironmentAuth from "../auth/EnvironmentAuth.ts";
30
import * as ServerConfig from "../config.ts";
31
import { mcpToolSession, type McpToolSession } from "../mcp/AcpMcpStdioBridge.ts";
32
+import { expandHomePath } from "../os-jank.ts";
33
import { readPersistedServerRuntimeState } from "../serverRuntimeState.ts";
34
import { projectLocationFlags, resolveCliAuthConfig } from "./config.ts";
35
@@ -287,7 +288,9 @@ const resolveProject = Effect.fn("cli.thread.resolveProject")(function* (
288
// through a symlink (macOS /tmp), so both sides compare as real paths.
289
const realPath = (value: string) =>
290
fileSystem.realPath(value).pipe(Effect.orElseSucceed(() => value));
290
- const target = yield* realPath(path.resolve(yield* HostProcess.WorkingDirectory, identifier));
291
+ const target = yield* realPath(
292
+ path.resolve(yield* HostProcess.WorkingDirectory, yield* expandHomePath(identifier)),
293
+ );
294
const roots = yield* Effect.forEach(projects, (project) =>
295
Effect.map(realPath(project.workspaceRoot), (root) => ({ project, root })),
296
);