@devries-cameron20 / t3code Mirror · read-only / commits / 81c3da3856
Fork 0

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, 00:45 UTC

fix(server): removed thread worktrees keep their project's skills in the picker (#32471)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Nov 10, 2026 at 09:47 UTC 81c3da3856b10bbe4543185e03ac2be978478747
8 files changed +308 -3
apps/server/src/orchestration-v2/ThreadLaunchService.test.ts
+1
@@ -197,6 +197,7 @@ function makeHarness(options: HarnessOptions = {}) {
197 : Option.none(),
198 ),
199 getByWorkspaceRoot: () => Effect.succeedSome(project),
200 + workspaceScanDirectory: () => Effect.die("unused"),
201 snapshot: Effect.die("unused"),
202 getShell: () => Effect.die("unused"),
203 listShells: () => Effect.die("unused"),
apps/server/src/project/ProjectService.test.ts
+2 -2
@@ -205,8 +205,8 @@ const layerProjectServiceDependencies = Layer.mergeAll(
205 Layer.provideMerge(layerMetadata),
206 Layer.provideMerge(SqlitePersistence.layerMemory),
207 Layer.provideMerge(ServerSettings.layerTest()),
208 - Layer.provide(ServerConfig.layerTest(process.cwd(), { prefix: "project-service-race-" })),
209 - Layer.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),
208 + Layer.provideMerge(ServerConfig.layerTest(process.cwd(), { prefix: "project-service-race-" })),
209 + Layer.provideMerge(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),
210 );
211
212 const waitForProject = Effect.fn("ProjectServiceTest.waitForProject")(function* (
apps/server/src/project/ProjectService.ts
+26
@@ -12,6 +12,7 @@ import * as KeyedLock from "@t3tools/shared/KeyedLock";
12 import * as Context from "effect/Context";
13 import * as DateTime from "effect/DateTime";
14 import * as Effect from "effect/Effect";
15 +import * as FileSystem from "effect/FileSystem";
16 import * as Layer from "effect/Layer";
17 import * as Option from "effect/Option";
18 import * as Result from "effect/Result";
@@ -32,6 +33,7 @@ import * as ProjectStore from "../orchestration-v2/ProjectStore.ts";
33 import * as ThreadCommandExecutor from "../orchestration-v2/ThreadCommandExecutor.ts";
34 import { planThreadDeletion } from "../orchestration-v2/ThreadDeletion.ts";
35 import * as ServerSettings from "../serverSettings.ts";
36 +import { makeIsManagedWorktreePath } from "../worktreesDirectory.ts";
37 import * as ProjectEnrichmentService from "./ProjectEnrichmentService.ts";
38 import * as WorkspacePaths from "../workspace/WorkspacePaths.ts";
39
@@ -142,6 +144,11 @@ export class ProjectService extends Context.Service<
144 workspaceRoot: string,
145 options?: { readonly includeDeleted?: boolean },
146 ) => Effect.Effect<Option.Option<Project>, ProjectOperationError>;
147 + /**
148 + * Where to scan `cwd`'s workspace inventory. A thread's removed managed worktree scans its
149 + * project, which turn start recreates the worktree from; anything else, or a failure, is `cwd`.
150 + */
151 + readonly workspaceScanDirectory: (cwd: string) => Effect.Effect<string>;
152 readonly snapshot: Effect.Effect<ProjectSnapshot, ProjectOperationError>;
153 /**
154 * A page of active projects in creation order, each with its repository
@@ -173,6 +180,8 @@ export const make = Effect.gen(function* () {
180 const legacyImporter = yield* LegacyV1ThreadImporter.LegacyV1ThreadImporter;
181 const threadCommands = yield* ThreadCommandExecutor.ThreadCommandExecutor;
182 const serverSettings = yield* ServerSettings.ServerSettingsService;
183 + const fileSystem = yield* FileSystem.FileSystem;
184 + const isManagedWorktreePath = yield* makeIsManagedWorktreePath;
185 const projectLocks = yield* KeyedLock.make<ProjectId>();
186 const workspaceLocks = yield* KeyedLock.make<string>();
187
@@ -331,6 +340,22 @@ export const make = Effect.gen(function* () {
340 },
341 );
342
343 + const workspaceScanDirectory = Effect.fn("ProjectService.workspaceScanDirectory")(
344 + function* (cwd: string) {
345 + if (yield* fileSystem.exists(cwd).pipe(Effect.orElseSucceed(() => true))) return cwd;
346 + if (!(yield* isManagedWorktreePath(cwd))) return cwd;
347 + const snapshot = yield* Effect.flatten(
348 + threadProjections.readShellSnapshot({ worktreePath: cwd }),
349 + );
350 + const thread = [...snapshot.threads, ...snapshot.archivedThreads].find(
351 + (candidate) => candidate.branch !== null,
352 + );
353 + if (thread === undefined) return cwd;
354 + return Option.getOrUndefined(yield* readRow(thread.projectId))?.workspaceRoot ?? cwd;
355 + },
356 + (effect, cwd) => Effect.orElseSucceed(effect, () => cwd),
357 + );
358 +
359 const getByWorkspaceRoot: ProjectService["Service"]["getByWorkspaceRoot"] = Effect.fn(
360 "ProjectService.getByWorkspaceRoot",
361 )(function* (workspaceRoot, options) {
@@ -611,6 +636,7 @@ export const make = Effect.gen(function* () {
636 delete: deleteProject,
637 getById,
638 getByWorkspaceRoot,
639 + workspaceScanDirectory,
640 snapshot,
641 listPage,
642 getShell,
apps/server/src/provider/ProviderRegistry.test.ts
+91
@@ -1737,6 +1737,97 @@ it.layer(
1737 }),
1738 );
1739
1740 + it.effect("scans scanCwd and keys the workspace snapshot by cwd", () =>
1741 + Effect.gen(function* () {
1742 + const driver = ProviderDriverKind.make("codex");
1743 + const instanceId = ProviderInstanceId.make("codex");
1744 + const provider = {
1745 + instanceId,
1746 + driver,
1747 + status: "ready",
1748 + enabled: true,
1749 + installed: true,
1750 + auth: { status: "authenticated" },
1751 + checkedAt: "2026-06-10T00:00:00.000Z",
1752 + version: "1.0.0",
1753 + models: [],
1754 + slashCommands: [],
1755 + skills: [],
1756 + } as const satisfies ServerProvider;
1757 + const scannedDirectories = yield* Ref.make<ReadonlyArray<string>>([]);
1758 + const instance: ProviderInstance = {
1759 + instanceId,
1760 + driverKind: driver,
1761 + continuationIdentity: { driverKind: driver, continuationKey: "codex:instance:codex" },
1762 + displayName: undefined,
1763 + enabled: true,
1764 + snapshot: {
1765 + resolveMaintenance: () =>
1766 + Effect.succeed(
1767 + makeManualOnlyProviderMaintenanceCapabilities({
1768 + provider: driver,
1769 + packageName: null,
1770 + }),
1771 + ),
1772 + getSnapshot: Effect.succeed(provider),
1773 + refresh: Effect.succeed(provider),
1774 + streamChanges: Stream.empty,
1775 + applyUsageLimits: () => Effect.void,
1776 + },
1777 + snapshotForCwd: (directory) =>
1778 + Ref.update(scannedDirectories, (directories) => [...directories, directory]).pipe(
1779 + Effect.as({
1780 + ...provider,
1781 + skills: [{ name: "finalize", path: `${directory}/finalize`, enabled: true }],
1782 + }),
1783 + ),
1784 + orchestrationAdapter: {} as ProviderInstance["orchestrationAdapter"],
1785 + textGeneration: {} as ProviderInstance["textGeneration"],
1786 + };
1787 + const layerInstanceRegistry = Layer.succeed(
1788 + ProviderInstanceRegistry.ProviderInstanceRegistry,
1789 + {
1790 + getInstance: (requestedId) =>
1791 + Effect.succeed(requestedId === instanceId ? instance : undefined),
1792 + listInstances: Effect.succeed([instance]),
1793 + listUnavailable: Effect.succeed([]),
1794 + streamChanges: Stream.empty,
1795 + subscribeChanges: Effect.flatMap(PubSub.unbounded<void>(), PubSub.subscribe),
1796 + },
1797 + );
1798 + const scope = yield* Scope.make();
1799 + yield* Effect.addFinalizer(() => Scope.close(scope, Exit.void));
1800 + const runtimeServices = yield* Layer.build(
1801 + ProviderRegistry.layer.pipe(
1802 + Layer.provide(layerUnusedMutator),
1803 + Layer.provideMerge(layerInstanceRegistry),
1804 + Layer.provideMerge(
1805 + ServerConfig.layerTest(process.cwd(), {
1806 + prefix: "t3-provider-registry-scan-cwd-",
1807 + }),
1808 + ),
1809 + Layer.provideMerge(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),
1810 + ),
1811 + ).pipe(Scope.provide(scope));
1812 +
1813 + yield* Effect.gen(function* () {
1814 + const registry = yield* ProviderRegistry.ProviderRegistry;
1815 + const providers = yield* registry.refreshWorkspaceSnapshot({
1816 + instanceId,
1817 + cwd: "/worktree",
1818 + scanCwd: "/project",
1819 + });
1820 + assert.deepStrictEqual(yield* Ref.get(scannedDirectories), ["/project"]);
1821 + assert.deepStrictEqual(
1822 + providers[0]?.workspaceSnapshots
1823 + ?.find((snapshot) => snapshot.cwd === "/worktree")
1824 + ?.skills?.map((skill) => skill.path),
1825 + ["/project/finalize"],
1826 + );
1827 + }).pipe(Effect.provide(runtimeServices));
1828 + }),
1829 + );
1830 +
1831 it.effect("publishes workspace skills while machine health is in error", () =>
1832 Effect.gen(function* () {
1833 const driver = ProviderDriverKind.make("codex");
apps/server/src/provider/ProviderRegistry.ts
+4 -1
@@ -78,6 +78,8 @@ export class ProviderRegistry extends Context.Service<
78 readonly refreshWorkspaceSnapshot: (input: {
79 readonly instanceId: ProviderInstanceId;
80 readonly cwd: string;
81 + /** Directory the driver scans; the snapshot stays keyed by `cwd`. Defaults to `cwd`. */
82 + readonly scanCwd?: string;
83 readonly fresh?: boolean;
84 }) => Effect.Effect<ReadonlyArray<ServerProvider>>;
85
@@ -951,6 +953,7 @@ export const layer = Layer.effect(
953 const refreshWorkspaceSnapshot = Effect.fn("refreshWorkspaceSnapshot")(function* (input: {
954 readonly instanceId: ProviderInstanceId;
955 readonly cwd: string;
956 + readonly scanCwd?: string;
957 readonly fresh?: boolean;
958 }) {
959 if (input.fresh) {
@@ -989,7 +992,7 @@ export const layer = Layer.effect(
992 )
993 : Effect.void;
994 const runScan = refreshMachineSnapshot.pipe(
992 - Effect.andThen(instance.snapshotForCwd(input.cwd)),
995 + Effect.andThen(instance.snapshotForCwd(input.scanCwd ?? input.cwd)),
996 // Scans fail on error; returned inventory remains valid even when provider health reports an error.
997 Effect.flatMap((scopedSnapshot) =>
998 instanceRegistry.getInstance(input.instanceId).pipe(
apps/server/src/relay/AgentAwarenessRelay.test.ts
+1
@@ -318,6 +318,7 @@ const makeTestRelay = Effect.fnUntraced(function* (
318 update: unused,
319 delete: unused,
320 getByWorkspaceRoot: unused,
321 + workspaceScanDirectory: unused,
322 snapshot: Effect.succeed({ projects: [project], updatedAt: NOW }),
323 listPage: unused,
324 getShell: unused,
apps/server/src/ws.test.ts
+182
@@ -31,7 +31,9 @@ import * as Effect from "effect/Effect";
31 import * as Exit from "effect/Exit";
32 import * as Cause from "effect/Cause";
33 import * as Fiber from "effect/Fiber";
34 +import * as FileSystem from "effect/FileSystem";
35 import * as Layer from "effect/Layer";
36 +import * as Path from "effect/Path";
37 import * as PubSub from "effect/PubSub";
38 import * as Queue from "effect/Queue";
39 import * as Stream from "effect/Stream";
@@ -132,6 +134,11 @@ import * as ManagedPolicy from "./policy/ManagedPolicy.ts";
134
135 import * as ThreadManagement from "./orchestration-v2/ThreadManagementService.ts";
136 import * as ProjectStore from "./orchestration-v2/ProjectStore.ts";
137 +import * as ProjectionStore from "./orchestration-v2/ProjectionStore.ts";
138 +import * as EventSink from "./orchestration-v2/EventSink.ts";
139 +import * as LegacyV1ThreadImporter from "./orchestration-v2/legacy/LegacyV1ThreadImporter.ts";
140 +import * as ThreadCommandExecutor from "./orchestration-v2/ThreadCommandExecutor.ts";
141 +import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
142 import * as OrchestrationEventStore from "./persistence/OrchestrationEventStore.ts";
143 import * as SqlitePersistence from "./persistence/Sqlite.ts";
144 import * as ExternalLauncher from "./process/externalLauncher.ts";
@@ -1166,6 +1173,9 @@ it.effect("on-demand clients get provider config without workspace snapshots", (
1173 ),
1174 refreshWorkspaceSnapshot: () => Effect.succeed([provider]),
1175 }),
1176 + Layer.mock(ProjectService.ProjectService)({
1177 + workspaceScanDirectory: (cwd) => Effect.succeed(cwd),
1178 + }),
1179 Layer.mock(ProviderInstanceRegistry.ProviderInstanceRegistry)({
1180 listInstances: Effect.sync(() => [
1181 (scansCwd
@@ -1350,6 +1360,178 @@ it.effect("on-demand clients get provider config without workspace snapshots", (
1360 ),
1361 );
1362
1363 +it.effect("a missing thread worktree gets its project's skills in the cwd snapshot", () =>
1364 + Effect.gen(function* () {
1365 + const fileSystem = yield* FileSystem.FileSystem;
1366 + const path = yield* Path.Path;
1367 + const serverConfig = yield* ServerConfigModule.ServerConfig;
1368 + const instanceId = ProviderInstanceId.make("claudeAgent");
1369 + const projectId = ProjectId.make("project:skills");
1370 + const workspaceRoot = yield* fileSystem.makeTempDirectoryScoped({
1371 + prefix: "t3-missing-worktree-project-",
1372 + });
1373 + const skillPath = path.join(workspaceRoot, ".claude", "skills", "finalize", "SKILL.md");
1374 + yield* fileSystem.makeDirectory(path.dirname(skillPath), { recursive: true });
1375 + yield* fileSystem.writeFileString(skillPath, "---\nname: finalize\n---\n");
1376 + // Removed with `git worktree remove`; only the next turn start recreates it.
1377 + const worktreePath = path.join(serverConfig.worktreesDir, "proj", "t3-6f94fb95");
1378 + const thread = {
1379 + id: ThreadId.make("thread:worktree"),
1380 + projectId,
1381 + archivedAt: null,
1382 + worktreePath,
1383 + branch: "t3/reply-ok",
1384 + } as unknown as OrchestrationV2ThreadShell;
1385 + const project = {
1386 + id: projectId,
1387 + title: "proj",
1388 + workspaceRoot,
1389 + defaultModelSelection: null,
1390 + scripts: [],
1391 + createdAt: "2026-11-07T00:00:00.000Z",
1392 + updatedAt: "2026-11-07T00:00:00.000Z",
1393 + } satisfies OrchestrationProjectShell;
1394 + const provider: ServerProvider = {
1395 + instanceId,
1396 + driver: ProviderDriverKind.make("claudeAgent"),
1397 + enabled: true,
1398 + installed: true,
1399 + version: "1.0.0",
1400 + status: "ready",
1401 + auth: { status: "authenticated" },
1402 + checkedAt: "2026-11-07T00:00:00.000Z",
1403 + models: [],
1404 + slashCommands: [],
1405 + skills: [],
1406 + };
1407 + // Like Claude's probe: project skills come from the scanned cwd, and a missing cwd is final.
1408 + const scan = (cwd: string) =>
1409 + fileSystem.exists(path.join(cwd, ".claude", "skills", "finalize", "SKILL.md")).pipe(
1410 + Effect.orDie,
1411 + Effect.map((found) => ({
1412 + cwd,
1413 + checkedAt: "2026-11-07T00:00:00.000Z",
1414 + slashCommands: [],
1415 + slashCommandsPending: false,
1416 + skills: found
1417 + ? [{ name: "finalize", path: path.join(cwd, ".claude/skills/finalize"), enabled: true }]
1418 + : [],
1419 + })),
1420 + );
1421 + const responses = yield* Queue.unbounded<unknown>();
1422 + const services = Layer.mergeAll(
1423 + layerUnusedConfigRpcServices,
1424 + Layer.mock(ProviderRegistry.ProviderRegistry)({
1425 + getProviders: Effect.succeed([provider]),
1426 + refreshWorkspaceSnapshot: (input) =>
1427 + Effect.map(scan(input.scanCwd ?? input.cwd), (snapshot) => [
1428 + { ...provider, workspaceSnapshots: [{ ...snapshot, cwd: input.cwd }] },
1429 + ]),
1430 + }),
1431 + Layer.mock(ProviderInstanceRegistry.ProviderInstanceRegistry)({
1432 + listInstances: Effect.succeed([]),
1433 + getInstance: () => Effect.succeed({ instanceId, snapshotForCwd: scan } as never),
1434 + }),
1435 + Layer.effect(ProjectService.ProjectService, ProjectService.make).pipe(
1436 + Layer.provide(
1437 + Layer.mergeAll(
1438 + Layer.mock(ProjectionStore.ProjectionStoreV2)({
1439 + readShellSnapshot: (options) =>
1440 + Effect.succeed(
1441 + Effect.succeed({
1442 + schemaVersion: 1,
1443 + snapshotSequence: 0,
1444 + threads: [thread].filter(
1445 + (candidate) =>
1446 + options?.worktreePath === undefined ||
1447 + candidate.worktreePath === options.worktreePath,
1448 + ),
1449 + archivedThreads: [],
1450 + } as never),
1451 + ),
1452 + }),
1453 + Layer.mock(ProjectStore.ProjectStoreV2)({
1454 + get: () => Effect.succeedSome(project as never),
1455 + }),
1456 + Layer.mock(ProjectEnrichment.ProjectEnrichmentService)({}),
1457 + Layer.mock(WorkspacePaths.WorkspacePaths)({}),
1458 + Layer.mock(EventSink.EventSinkV2)({}),
1459 + IdAllocator.layer,
1460 + Layer.mock(LegacyV1ThreadImporter.LegacyV1ThreadImporter)({}),
1461 + Layer.mock(ThreadCommandExecutor.ThreadCommandExecutor)({}),
1462 + ),
1463 + ),
1464 + ),
1465 + Layer.mock(UsageLimitSources.UsageLimitSources)({ current: Effect.succeed([]) }),
1466 + Layer.mock(ExternalLauncher.ExternalLauncher)({}),
1467 + Layer.mock(RemoteOpenTargets.RemoteOpenTargets)({}),
1468 + Layer.mock(DirectEndpoints.DirectEndpoints)({}),
1469 + Layer.mock(ManagedProjectFolders.ManagedProjectFolders)({
1470 + scratchRoot: Effect.succeedNone,
1471 + namedProjectsRoot: process.cwd(),
1472 + }),
1473 + Layer.mock(ScratchThreadPromotion.ScratchThreadPromotion)({}),
1474 + Layer.mock(ServerEnvironment.ServerEnvironment)({}),
1475 + Layer.mock(EnvironmentAuth.EnvironmentAuth)({}),
1476 + );
1477 + const server = yield* RpcServer.makeNoSerialization(
1478 + RpcGroup.make(WsServerRefreshProvidersRpc),
1479 + {
1480 + ...WS_RPC_SERVER_OPTIONS,
1481 + onFromServer: (response) =>
1482 + response._tag === "Exit" && response.exit._tag === "Success"
1483 + ? Queue.offer(responses, response.exit.value)
1484 + : response._tag === "Exit"
1485 + ? Queue.offer(responses, response.exit)
1486 + : Effect.void,
1487 + },
1488 + ).pipe(
1489 + Effect.provide(
1490 + layerWsRpc(
1491 + {
1492 + sessionId: AuthSessionId.make("worktree-skills-test"),
1493 + subject: "worktree-skills-test",
1494 + method: "browser-session-cookie",
1495 + scopes: [],
1496 + },
1497 + {},
1498 + yield* ServerBrowser.ServerBrowser,
1499 + () => Effect.void,
1500 + { secretReferences: true },
1501 + ).pipe(Layer.provide(services)),
1502 + ),
1503 + );
1504 +
1505 + yield* server.write(0, {
1506 + _tag: "Request",
1507 + id: RpcMessage.RequestId("refresh"),
1508 + tag: WS_METHODS.serverRefreshProviders,
1509 + payload: { instanceId, cwd: worktreePath, workspaceSnapshotsOnDemand: true },
1510 + headers: Headers.empty,
1511 + });
1512 + const refreshed = (yield* Queue.take(responses)) as {
1513 + readonly providers: ReadonlyArray<ServerProvider>;
1514 + };
1515 + const snapshot = refreshed.providers[0]?.workspaceSnapshots?.find(
1516 + (candidate) => candidate.cwd === worktreePath,
1517 + );
1518 + assert.deepEqual(
1519 + snapshot?.skills?.map((skill) => skill.name),
1520 + ["finalize"],
1521 + "the thread's removed worktree should list the project's skills",
1522 + );
1523 + }).pipe(
1524 + Effect.provide(
1525 + Layer.mergeAll(
1526 + Layer.fresh(layerConfigSources),
1527 + Layer.mock(PreviewAutomationBroker.PreviewAutomationBroker)({}),
1528 + Layer.mock(ServerBrowser.ServerBrowser)({}),
1529 + ),
1530 + ),
1531 + Effect.scoped,
1532 + ),
1533 +);
1534 +
1535 it.effect("a publish whose push fails still refreshes the new remote", () =>
1536 Effect.gen(function* () {
1537 const refreshes = yield* Queue.unbounded<string>();
apps/server/src/ws.ts
+1
@@ -2516,6 +2516,7 @@ export const layerWsRpc = (
2516 ? providerRegistry.refreshWorkspaceSnapshot({
2517 instanceId: input.instanceId,
2518 cwd: input.cwd,
2519 + scanCwd: yield* projectService.workspaceScanDirectory(input.cwd),
2520 fresh: input.fresh === true,
2521 })
2522 : input.reloadSecrets === true