Skip to content
This repository was archived by the owner on Oct 21, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions apps/mobile/src/features/threads/new-task-flow-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import {
setPendingConnectionError,
useSavedRemoteConnections,
} from "../../state/use-remote-environment-registry";
import { sharesRepository } from "@t3tools/client-runtime/state/project-grouping";
import { EnvironmentProject } from "@t3tools/client-runtime/state/shell";
import { type VcsRef } from "@t3tools/client-runtime/state/vcs";
import {
Expand Down Expand Up @@ -341,7 +342,7 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
// whatever unrelated project happens to be first on the other machine. Repository
// identity is the primary signal; projects that haven't reported one yet (still
// indexing) fall back to workspace basename / title so a valid host isn't hidden.
const selectedRepositoryKey = selectedProject?.repositoryIdentity?.canonicalKey ?? null;
const selectedRepositoryIdentity = selectedProject?.repositoryIdentity ?? null;
// `|| null` (not `??`): a pending-task placeholder project can have an empty
// workspaceRoot, and an "" basename would reject every real host below.
const selectedWorkspaceBasename = selectedProject?.workspaceRoot.split("/").at(-1) || null;
Expand All @@ -353,12 +354,11 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
readonly environmentLabel: string;
}> = [];
const hostsSelectedRepository = (project: EnvironmentProject) => {
if (selectedRepositoryKey === null && selectedWorkspaceBasename === null) {
if (selectedRepositoryIdentity === null && selectedWorkspaceBasename === null) {
return true;
}
const projectKey = project.repositoryIdentity?.canonicalKey ?? null;
if (selectedRepositoryKey !== null && projectKey !== null) {
return projectKey === selectedRepositoryKey;
if (selectedRepositoryIdentity !== null && project.repositoryIdentity !== null) {
return sharesRepository({ repositoryIdentity: selectedRepositoryIdentity }, project);
}
return (
project.workspaceRoot.split("/").at(-1) === selectedWorkspaceBasename ||
Expand Down Expand Up @@ -386,7 +386,7 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
}, [
projects,
savedConnectionsById,
selectedRepositoryKey,
selectedRepositoryIdentity,
selectedWorkspaceBasename,
selectedProjectTitle,
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function makeProject(
readonly title?: string;
readonly workspaceRoot?: string;
readonly repositoryKey?: string;
readonly groupKey?: string;
} = {},
): EnvironmentProject {
return {
Expand All @@ -27,6 +28,7 @@ function makeProject(
repositoryIdentity: options.repositoryKey
? {
canonicalKey: options.repositoryKey,
...(options.groupKey ? { groupKey: options.groupKey } : {}),
locator: {
source: "git-remote",
remoteName: "origin",
Expand Down Expand Up @@ -71,6 +73,18 @@ describe("getProjectScopeSelectionTarget", () => {
});

describe("resolveEnvironmentProjectMatch", () => {
it("follows the repository onto a machine whose server predates groupKey", () => {
const selected = makeProject("t3code", "mac", {
repositoryKey: "github.com/julius/t3code",
groupKey: "github.com/t3tools/t3code",
});
const target = [
makeProject("t3code-fork", "server", { repositoryKey: "github.com/julius/other" }),
makeProject("t3code-clone", "server", { repositoryKey: "github.com/julius/t3code" }),
];
expect(resolveEnvironmentProjectMatch(target, selected)).toBe(target[1]);
});

it("follows the same repository onto the target machine", () => {
const selected = makeProject("t3code", "mac", { repositoryKey: "github.com/t3tools/t3code" });
const target = [
Expand Down
17 changes: 8 additions & 9 deletions apps/mobile/src/features/threads/new-task-project-selection.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { sharesRepository } from "@t3tools/client-runtime/state/project-grouping";
import type { EnvironmentProject } from "@t3tools/client-runtime/state/shell";
import type { EnvironmentId } from "@t3tools/contracts";

Expand Down Expand Up @@ -56,22 +57,20 @@ export function resolveEnvironmentProjectMatch(
projectsOnTarget: ReadonlyArray<EnvironmentProject>,
selectedProject: EnvironmentProject | null,
): EnvironmentProject | null {
const repositoryKey = selectedProject?.repositoryIdentity?.canonicalKey ?? null;
const hasRepository = selectedProject?.repositoryIdentity != null;
// `|| null` (not `??`): a pending-task placeholder project can have an empty
// workspaceRoot, and an "" basename would match nothing meaningful.
const workspaceBasename = selectedProject?.workspaceRoot.split("/").at(-1) || null;
// The weaker signals only apply where identity is unknown on at least one
// side; two known, different repositories never match on a shared basename
// or title (mirrors the environment list filter in the new-task flow).
const isKnownMismatch = (project: EnvironmentProject) => {
const projectKey = project.repositoryIdentity?.canonicalKey ?? null;
return repositoryKey !== null && projectKey !== null && projectKey !== repositoryKey;
};
const isKnownMismatch = (project: EnvironmentProject) =>
hasRepository &&
project.repositoryIdentity !== null &&
!sharesRepository(selectedProject, project);
return (
(repositoryKey !== null
? projectsOnTarget.find(
(project) => (project.repositoryIdentity?.canonicalKey ?? null) === repositoryKey,
)
(hasRepository
? projectsOnTarget.find((project) => sharesRepository(selectedProject, project))
: undefined) ??
(workspaceBasename !== null
? projectsOnTarget.find(
Expand Down
2 changes: 2 additions & 0 deletions apps/server/src/project/RepositoryIdentityResolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ it.layer(NodeServices.layer)("RepositoryIdentityResolverLive", (it) => {

expect(identity?.locator.remoteName).toBe("origin");
expect(identity?.canonicalKey).toBe("github.com/julius/t3code");
// Grouping ignores the per-machine gh default.
expect(identity?.groupKey).toBe("github.com/t3tools/t3code");
}).pipe(Effect.provide(RepositoryIdentityResolver.layer)),
);

Expand Down
17 changes: 15 additions & 2 deletions apps/server/src/project/RepositoryIdentityResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,11 @@ function pickPrimaryRemote(
function buildRepositoryIdentity(input: {
readonly remoteName: string;
readonly remoteUrl: string;
readonly groupRemoteUrl: string;
readonly rootPath: string;
}): RepositoryIdentity {
const canonicalKey = normalizeGitRemoteUrl(input.remoteUrl);
const groupKey = normalizeGitRemoteUrl(input.groupRemoteUrl);
const sourceControlProvider = detectSourceControlProviderFromGitRemoteUrl(input.remoteUrl);
const repositoryPath = canonicalKey.split("/").slice(1).join("/");
const repositoryPathSegments = repositoryPath.split("/").filter((segment) => segment.length > 0);
Expand All @@ -116,6 +118,7 @@ function buildRepositoryIdentity(input: {

return {
canonicalKey,
groupKey,
locator: {
source: "git-remote",
remoteName: input.remoteName,
Expand Down Expand Up @@ -173,8 +176,18 @@ const resolveRepositoryIdentityFromCacheKey = Effect.fn(
ghDefaultResult._tag === "Some" && ghDefaultResult.value.code === 0
? parseGhDefaultRemote(ghDefaultResult.value.stdout)
: null;
const remote = pickPrimaryRemote(parseRemoteFetchUrls(remoteResult.value.stdout), ghDefault);
return remote ? buildRepositoryIdentity({ ...remote, rootPath: cacheKey }) : null;
const remotes = parseRemoteFetchUrls(remoteResult.value.stdout);
const remote = pickPrimaryRemote(remotes, ghDefault);
// The gh default is per-machine config, so grouping across environments
// skips it; otherwise one checkout splits in two when machines disagree.
const groupRemote = pickPrimaryRemote(remotes, null);
return remote && groupRemote
? buildRepositoryIdentity({
...remote,
groupRemoteUrl: groupRemote.remoteUrl,
rootPath: cacheKey,
})
: null;
});

export const make = Effect.fn("RepositoryIdentityResolver.make")(function* (
Expand Down
16 changes: 12 additions & 4 deletions apps/web/src/components/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2458,10 +2458,18 @@ export default function ChatView(props: ChatViewProps) {
);
const logicalProjectEnvironments = useMemo(() => {
if (!activeProject) return [];
const logicalKey = deriveLogicalProjectKeyFromSettings(activeProject, projectGroupingSettings);
const memberProjects = allProjects.filter(
(p) => deriveLogicalProjectKeyFromSettings(p, projectGroupingSettings) === logicalKey,
);
// Follow the sidebar's groups, which also merge projects whose servers
// report different repository keys.
const logicalKeyByPhysicalKey = buildPhysicalToLogicalProjectKeyMap({
projects: allProjects,
settings: projectGroupingSettings,
primaryEnvironmentId,
});
const logicalKeyOf = (project: typeof activeProject) =>
logicalKeyByPhysicalKey.get(derivePhysicalProjectKey(project)) ??
deriveLogicalProjectKeyFromSettings(project, projectGroupingSettings);
const logicalKey = logicalKeyOf(activeProject);
const memberProjects = allProjects.filter((p) => logicalKeyOf(p) === logicalKey);
const seen = new Set<string>();
const envs: EnvironmentOption[] = [];
for (const p of memberProjects) {
Expand Down
6 changes: 2 additions & 4 deletions apps/web/src/components/automations/AutomationsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
resolveProviderProfileFallbackModelSelection,
} from "@t3tools/shared/projectSettings";
import { scopeThreadRef } from "@t3tools/client-runtime/environment";
import { sharesRepository } from "@t3tools/client-runtime/state/project-grouping";
import type { EnvironmentProject } from "@t3tools/client-runtime/state/shell";
import {
AUTOMATION_GITHUB_EVENT_LABELS,
Expand Down Expand Up @@ -1170,11 +1171,8 @@ function matchProjectOn(
): ProjectId | null {
if (!from) return null;
const candidates = projects.filter((project) => project.environmentId === environmentId);
const repository = from.repositoryIdentity?.canonicalKey;
const match =
(repository
? candidates.find((project) => project.repositoryIdentity?.canonicalKey === repository)
: undefined) ??
candidates.find((project) => sharesRepository(from, project)) ??
candidates.find((project) => project.workspaceRoot === from.workspaceRoot) ??
candidates.find((project) => project.title === from.title);
return match?.id ?? null;
Expand Down
45 changes: 45 additions & 0 deletions packages/client-runtime/src/state/projectGrouping.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,51 @@ describe("buildProjectGroups", () => {
}
});

it("groups one checkout across environments whose gh default repositories differ", () => {
const fork = {
...repositoryIdentity,
canonicalKey: "github.com/julius/t3code",
groupKey: "github.com/t3tools/t3code",
};
const projects = [
makeProject("linux", "/home/julius/t3code"),
makeProject("mac", "/Users/julius/t3code", {
environmentId: EnvironmentId.make("environment-mac"),
repositoryIdentity: fork,
}),
];

const groups = buildProjectGroups({ projects, settings: settings("repository") });

expect(groups.map((group) => group.members.map((member) => member.project.id))).toEqual([
["linux", "mac"],
]);
});

it("groups one checkout while only one environment's server reports groupKey", () => {
const fork = { ...repositoryIdentity, canonicalKey: "github.com/julius/t3code" };
const mac = EnvironmentId.make("environment-mac");
const projects = [
makeProject("linux", "/home/julius/t3code", {
repositoryIdentity: { ...fork, groupKey: "github.com/t3tools/t3code" },
}),
makeProject("mac", "/Users/julius/t3code", { environmentId: mac, repositoryIdentity: fork }),
];

for (const mode of ["repository", "repository_path"] as const) {
const groups = buildProjectGroups({
projects,
settings: settings(mode),
preferredEnvironmentId: mac,
});

expect(groups).toHaveLength(1);
expect(groups[0]?.key).toBe("github.com/julius/t3code");
expect(groups[0]?.members.map((member) => member.project.id)).toEqual(["linux", "mac"]);
expect(groups[0]?.memberProjectRefs).toHaveLength(2);
}
});

it("uses a shared custom title as the repository group's label", () => {
const projects = [
makeProject("first", "/work/t3code", { title: "Custom project" }),
Expand Down
Loading
Loading