@devries-cameron20 / t3code-1 / commits / 31bf2f7f34
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(client-runtime): pasted repository page URLs clone the repository into its own folder (#32681)

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

Julius Marminge committed Nov 10, 2026 at 21:38 UTC 31bf2f7f3404200503300064fec9c6676c55691a
13 files changed +135 -4
apps/web/src/components/CommandPalette.tsx
+1 -2
@@ -2006,7 +2006,7 @@ function OpenCommandPaletteDialog(props: {
2006 function getDefaultCloneDestination(
2007 environmentId: EnvironmentId,
2008 remoteUrl: string,
2009 - repository: string,
2009 + repository?: string,
2010 ): string {
2011 const environment = environments.find((candidate) => candidate.environmentId === environmentId);
2012 return getCloneDestinationPath(
@@ -2061,7 +2061,6 @@ function OpenCommandPaletteDialog(props: {
2061 const destinationPath = getDefaultCloneDestination(
2062 addProjectCloneFlow.environmentId,
2063 remoteUrl,
2064 - rawRepository,
2064 );
2065 setAddProjectCloneFlow({
2066 step: "confirm",
docs/user/source-control.md
+3 -1
@@ -155,7 +155,9 @@ publish it. If Git has no name or email on that machine, the project is created
155 first commit.
156
157 Use **Add Project** in the command palette (`Cmd/Ctrl+K`) to clone a repository. Choose a hosting
158 -provider or paste a Git URL, then choose where to save it. The project opens right away while the
158 +provider or paste a Git URL, then choose where to save it. A branch or file page copied from GitHub,
159 +GitLab, GitCafe, Codeberg or Bitbucket also works: T3 Code clones that repository's default branch.
160 +On other hosts, paste the repository's clone URL. The project opens right away while the
161 clone runs in the background: you can write your first prompt, and sending waits until the files
162 are in place. A toast tracks progress and lets you cancel; if the clone fails, retry it from the
163 toast or from the banner above the composer. When the host refuses the machine's SSH key, T3 Code
packages/client-runtime/src/operations/projects.test.ts
+27
@@ -63,6 +63,33 @@ describe("add project shared logic", () => {
63 );
64 expect(normalizePastedCloneUrl("group/subgroup/project")).toBe("group/subgroup/project");
65 expect(normalizePastedCloneUrl("/srv/git/repo.git")).toBe("/srv/git/repo.git");
66 + for (const gitlabProject of [
67 + "https://gitlab.com/acme/tools/src/branch/worker.git",
68 + "https://scm.example.test/acme/tools/src/branch/worker.git",
69 + "https://scm.example.test/acme/tools/src/branch/worker",
70 + "https://scm.example.test/team/repo/src/branch/main/-/README.md",
71 + "https://forgejo.example.test/a/b/src/branch/mount/team/repo.git",
72 + ]) {
73 + expect(normalizePastedCloneUrl(gitlabProject)).toBe(gitlabProject);
74 + }
75 + });
76 +
77 + it("clones the repository when given a page URL copied from the browser", () => {
78 + for (const [pageUrl, pageRoute, repository] of [
79 + ["https://github.com/pingdotgg/t3code/tree/main", "/tree/", "t3code"],
80 + ["https://gitlab.com/gitlab-org/gitlab-runner/-/tree/main", "/-/", "gitlab-runner"],
81 + ["https://git.cafe/pingdotgg/t3code/tree/main", "/tree/", "t3code"],
82 + ["https://gitlab.example.test/g/p/-/blob/main/src/branch/x", "/-/", "p"],
83 + ["https://code.company.test/g/p/-/tree/main", "/-/", "p"],
84 + ["https://github.com/pingdotgg/t3code/tree/release.git", "/tree/", "t3code"],
85 + ] as const) {
86 + const cloneUrl = normalizePastedCloneUrl(pageUrl);
87 + expect(cloneUrl).not.toContain(pageRoute);
88 + expect(getCloneDirectoryName(cloneUrl)).toBe(repository);
89 + }
90 + expect(
91 + normalizePastedCloneUrl("https://alice:example@bitbucket.org/workspace/repo/src/master/"),
92 + ).toBe("https://alice:example@bitbucket.org/workspace/repo");
93 });
94
95 it("uses HTTPS for repositories selected through a provider", () => {
packages/client-runtime/src/operations/projects.ts
+2 -1
@@ -128,7 +128,8 @@ export function githubIncompleteOwnerRepositoryMessage(
128
129 export function normalizePastedCloneUrl(input: string): string {
130 const trimmed = input.trim();
131 - return REPOSITORY_SHORTHAND.test(trimmed) ? (defaultHostCloneUrl(trimmed) ?? trimmed) : trimmed;
131 + if (REPOSITORY_SHORTHAND.test(trimmed)) return defaultHostCloneUrl(trimmed) ?? trimmed;
132 + return sourceControlClients.repositoryUrlFromPage(trimmed) ?? trimmed;
133 }
134
135 export function getDefaultCloneUrl(
packages/source-control-bitbucket/src/shared/definition.test.ts
+11
@@ -51,6 +51,17 @@ describe("Bitbucket change request URLs", () => {
51 });
52 });
53
54 +describe("Bitbucket repository pages", () => {
55 + it("reads the repository from a source view on Bitbucket hosts only", () => {
56 + const repositoryUrl = (url: string) => definition.repositoryUrlFromPage?.(new URL(url));
57 + expect(repositoryUrl("https://bitbucket.org/workspace/repo/src/main/")).toBe(
58 + "https://bitbucket.org/workspace/repo",
59 + );
60 + expect(repositoryUrl("https://bitbucket.org/workspace/repo")).toBeNull();
61 + expect(repositoryUrl("https://scm.example.test/workspace/repo/src/main/")).toBeNull();
62 + });
63 +});
64 +
65 describe("Bitbucket remotes", () => {
66 const recognize = (url: string) => recognizeRemoteWith(definition, url);
67
packages/source-control-bitbucket/src/shared/definition.ts
+4
@@ -14,6 +14,7 @@ import {
14 isChangeRequestOnProjectHost,
15 parseChangeRequestPath,
16 parseCommitPath,
17 + repositoryUrlFromPagePath,
18 projectChangeRequestHost,
19 } from "@t3tools/source-control-core/shared/definition";
20 import { icon } from "./icon.ts";
@@ -23,6 +24,7 @@ const repositoryName = /^[A-Za-z0-9._-]+\/[A-Za-z0-9._-]+$/;
24
25 const CHANGE_REQUEST_PATH = /^\/([^/]+\/[^/]+)\/pull-requests\/(\d+)(?:\/|$)/u;
26 const COMMIT_PATH = /^\/([^/]+\/[^/]+)\/commits\/([0-9a-f]+)\/?$/iu;
27 +const REPOSITORY_PAGE_PATH = /^\/([^/]+\/[^/]+)\/src\/[^/]/u;
28
29 const KIND = SourceControlProviderKind.make("bitbucket");
30
@@ -96,6 +98,8 @@ export const definition = defineSourceControl({
98 commitUrl: (input) => buildCommitUrl(input, "commits"),
99 parseCommitUrl: (url) =>
100 isBitbucketHost(url.hostname) ? parseCommitPath(url, COMMIT_PATH) : null,
101 + repositoryUrlFromPage: (url) =>
102 + isBitbucketHost(url.hostname) ? repositoryUrlFromPagePath(url, REPOSITORY_PAGE_PATH) : null,
103 changeRequestUrlFromReferenceAutolink: () => null,
104 // No endpoint reopens a declined pull request, and nothing documented moves one in or out of
105 // draft, so neither is offered rather than failing when pressed.
packages/source-control-core/src/shared/definition.ts
+40
@@ -258,6 +258,12 @@ export interface SourceControlDefinition {
258 readonly parseCommitUrl?: (url: URL, known: boolean) => CommitLink | null;
259 /** Null when the URL is not one of this host's change requests. */
260 readonly parseChangeRequestUrl: (url: URL) => ParsedChangeRequestUrl | null;
261 + /**
262 + * The repository URL when `url` is a page inside one of this host's repositories. `known` is set
263 + * when the caller already knows this host serves the URL's repository. Off a known host, return
264 + * `url.href` when the path may already be a clone URL, so no rewrite happens.
265 + */
266 + readonly repositoryUrlFromPage?: (url: URL, known: boolean) => string | null;
267 /**
268 * The change request URL a `reference` autolink might name, such as a GitHub `#123` written
269 * through the issue route. Only a candidate: the caller must read it as a change request
@@ -410,6 +416,18 @@ export function parseChangeRequestPath(url: URL, route: RegExp): ParsedChangeReq
416 : null;
417 }
418
419 +/** Reads a repository page from `url` with `route`, whose first group is the repository path. */
420 +export function repositoryUrlFromPagePath(url: URL, route: RegExp): string | null {
421 + const repository = route.exec(url.pathname)?.[1];
422 + if (!repository) return null;
423 + // Keeps the credentials and port a private clone relies on.
424 + const repositoryUrl = new URL(url);
425 + repositoryUrl.pathname = `/${repository}`;
426 + repositoryUrl.search = "";
427 + repositoryUrl.hash = "";
428 + return repositoryUrl.href;
429 +}
430 +
431 export function changeRequestUrlBelow(webUrl: string, route: string): string {
432 return `${webUrl.replace(/\/+$/u, "")}/${route}`;
433 }
@@ -615,6 +633,8 @@ export interface SourceControlDefinitionRegistry {
633 readonly hostLabelForChangeRequestUrl: (url: string) => string;
634 readonly isSameChangeRequest: (left: string, right: string) => boolean;
635 readonly changeRequestUrlFromReferenceAutolink: (url: string) => string | null;
636 + /** The repository a page URL copied from a browser is in, such as a branch or file view. */
637 + readonly repositoryUrlFromPage: (url: string) => string | null;
638 /**
639 * The host a remote is on, from the first definition in recognition order that claims it, or an
640 * unknown host. Null when the remote names no host.
@@ -683,6 +703,8 @@ export function makeSourceControlDefinitionRegistry(
703 }
704 return undefined;
705 };
706 + const remoteOwner = (remote: GitRemoteHost) =>
707 + recognitionOrder.find((definition) => definition.recognizeRemote(remote) !== null);
708 const parseChangeRequestUrl = (value: string): ParsedChangeRequest | null => {
709 const url = httpUrl(value);
710 if (url === null) return null;
@@ -744,6 +766,24 @@ export function makeSourceControlDefinitionRegistry(
766 }
767 return null;
768 },
769 + repositoryUrlFromPage: (value) => {
770 + const url = httpUrl(value);
771 + if (url === null) return null;
772 + // A recognized host's paths are its own, so another host's any-host route never rewrites them.
773 + const remote = parseGitRemoteHost(value);
774 + const owner = remote === null ? undefined : remoteOwner(remote);
775 + if (owner) return owner.repositoryUrlFromPage?.(url, true) ?? null;
776 + // Elsewhere a path ending in `.git` is already a clone URL, whatever routes it contains.
777 + if (url.pathname.replace(/\/$/u, "").endsWith(".git")) return null;
778 + // On an unrecognized host, only rewrite when every route that matches agrees. A route that
779 + // answers with the page itself says it may already be the clone URL.
780 + const [repositoryUrl, ...others] = new Set(
781 + claimOrder.flatMap((definition) => definition.repositoryUrlFromPage?.(url, false) ?? []),
782 + );
783 + return repositoryUrl !== undefined && repositoryUrl !== url.href && others.length === 0
784 + ? repositoryUrl
785 + : null;
786 + },
787 recognizeRemote: (remoteUrl) => {
788 const remote = parseGitRemoteHost(remoteUrl);
789 if (remote === null) return null;
packages/source-control-forgejo/src/shared/definition.test.ts
+16
@@ -104,6 +104,22 @@ describe("Forgejo change request URLs", () => {
104 });
105 });
106
107 +describe("Forgejo repository pages", () => {
108 + it("reads the repository from branch, tag and commit views", () => {
109 + const repositoryUrl = (url: string) => definition.repositoryUrlFromPage?.(new URL(url), true);
110 + expect(repositoryUrl("https://codeberg.org/forgejo/forgejo/src/branch/forgejo/README.md")).toBe(
111 + "https://codeberg.org/forgejo/forgejo",
112 + );
113 + expect(repositoryUrl("http://git.example.test:3000/git/team/repo/src/tag/v1.0")).toBe(
114 + "http://git.example.test:3000/git/team/repo",
115 + );
116 + expect(repositoryUrl("https://codeberg.org/forgejo/forgejo/src/commit/abc123")).toBe(
117 + "https://codeberg.org/forgejo/forgejo",
118 + );
119 + expect(repositoryUrl("https://codeberg.org/forgejo/forgejo")).toBeNull();
120 + });
121 +});
122 +
123 describe("Forgejo remotes", () => {
124 it("recognises Codeberg and Forgejo or Gitea hosts, keeping an HTTP remote's origin", () => {
125 for (const host of ["codeberg.org", "forgejo.example.test", "gitea.example.test"]) {
packages/source-control-forgejo/src/shared/definition.ts
+9
@@ -10,6 +10,7 @@ import {
10 isChangeRequestOnProjectHost,
11 parseChangeRequestPath,
12 parseCommitPath,
13 + repositoryUrlFromPagePath,
14 projectChangeRequestHost,
15 remoteWebOrigin,
16 } from "@t3tools/source-control-core/shared/definition";
@@ -22,6 +23,7 @@ const CHANGE_REQUEST_REFERENCE =
23 // Forgejo and Gitea run on any hostname, possibly mounted below a path.
24 const CHANGE_REQUEST_PATH = /^\/([^/]+(?:\/[^/]+)+)\/pulls\/(\d+)(?:\/|$)/u;
25 const COMMIT_PATH = /^\/([^/]+(?:\/[^/]+)+)\/commit\/([0-9a-f]+)\/?$/iu;
26 +const REPOSITORY_PAGE_PATH = /^\/([^/]+(?:\/[^/]+)+?)\/src\/(?:branch|tag|commit)\/[^/]/u;
27
28 const KIND = SourceControlProviderKind.make("forgejo");
29
@@ -87,6 +89,13 @@ export const definition = defineSourceControl({
89 changeRequestUrlFromReferenceAutolink: () => null,
90 commitUrl: (input) => buildCommitUrl(input, "commit"),
91 parseCommitUrl: (url) => parseCommitPath(url, COMMIT_PATH),
92 + repositoryUrlFromPage: (url, known) => {
93 + // A mount path may itself contain `src/branch/`, so a `.git` path is always the clone URL.
94 + if (url.pathname.replace(/\/$/u, "").endsWith(".git")) return null;
95 + const repositoryUrl = repositoryUrlFromPagePath(url, REPOSITORY_PAGE_PATH);
96 + // Elsewhere the same path is a GitLab project nested under groups named `src` and `branch`.
97 + return repositoryUrl === null || known ? repositoryUrl : url.href;
98 + },
99 changeRequestActions: new Set(["merge", "close", "reopen", "update-branch"] as const),
100 // Neither `fj` nor `tea` checks out by number.
101 checkoutCommand: ({ number, repositoryUrl }) =>
packages/source-control-gitcafe/src/shared/definition.ts
+6
@@ -14,6 +14,7 @@ import {
14 parseChangeRequestPath,
15 parseCommitPath,
16 projectChangeRequestHost,
17 + repositoryUrlFromPagePath,
18 } from "@t3tools/source-control-core/shared/definition";
19 import { icon } from "./icon.ts";
20
@@ -23,6 +24,7 @@ const GITCAFE_HOSTS = new Set(["git.cafe", "staging.git.cafe"]);
24 /** GitCafe serves pull requests at `/pull/<n>` and redirects the older `/pulls/<n>` there. */
25 const CHANGE_REQUEST_PATH = /^\/([^/]+\/[^/]+)\/pulls?\/(\d+)(?:\/|$)/u;
26 const COMMIT_PATH = /^\/([^/]+\/[^/]+)\/commit\/([0-9a-f]+)\/?$/iu;
27 +const REPOSITORY_PAGE_PATH = /^\/([^/]+\/[^/]+)\/(?:tree|blob)\/[^/]/u;
28
29 function parseChangeRequestUrl(url: URL) {
30 return GITCAFE_HOSTS.has(url.hostname.toLowerCase())
@@ -72,6 +74,10 @@ export const definition = defineSourceControl({
74 commitUrl: (input) => buildCommitUrl(input, "commit"),
75 parseCommitUrl: (url) =>
76 GITCAFE_HOSTS.has(url.hostname.toLowerCase()) ? parseCommitPath(url, COMMIT_PATH) : null,
77 + repositoryUrlFromPage: (url) =>
78 + GITCAFE_HOSTS.has(url.hostname.toLowerCase())
79 + ? repositoryUrlFromPagePath(url, REPOSITORY_PAGE_PATH)
80 + : null,
81 changeRequestUrlFromReferenceAutolink: () => null,
82 changeRequestActions: new Set([
83 "ready",
packages/source-control-github/src/shared/definition.test.ts
+8
@@ -96,6 +96,14 @@ describe("GitHub change request URLs", () => {
96 });
97 });
98
99 +describe("GitHub repository pages", () => {
100 + it("leaves the tree route on other hosts to them", () => {
101 + expect(
102 + definition.repositoryUrlFromPage?.(new URL("https://scm.example.test/o/r/tree/main")),
103 + ).toBeNull();
104 + });
105 +});
106 +
107 describe("GitHub remotes", () => {
108 const recognize = (url: string) => recognizeRemoteWith(definition, url);
109
packages/source-control-github/src/shared/definition.ts
+4
@@ -8,6 +8,7 @@ import {
8 isChangeRequestOnProjectHost,
9 parseChangeRequestPath,
10 parseCommitPath,
11 + repositoryUrlFromPagePath,
12 projectChangeRequestHost,
13 remoteWebOrigin,
14 type SourceControlAppSignIn,
@@ -26,6 +27,7 @@ const CHANGE_REQUEST_REFERENCE =
27 const CHANGE_REQUEST_PATH = /^\/([^/]+\/[^/]+)\/pull\/(\d+)(?:\/|$)/u;
28 const COMMIT_PATH = /^\/([^/]+\/[^/]+)\/(?:commit|pull\/\d+\/commits)\/([0-9a-f]+)\/?$/iu;
29 const ISSUE_PATH = /^\/([^/]+\/[^/]+)\/issues\/(\d+)(?:\/|$)/u;
30 +const REPOSITORY_PAGE_PATH = /^\/([^/]+\/[^/]+)\/(?:tree|blob)\/[^/]/u;
31
32 const KIND = SourceControlProviderKind.make("github");
33
@@ -98,6 +100,8 @@ export const definition = defineSourceControl({
100 parseCommitUrl: (url, known) =>
101 known || isGitHubHost(url.hostname) ? parseCommitPath(url, COMMIT_PATH) : null,
102 parseChangeRequestUrl: (url) => parseChangeRequestPath(url, CHANGE_REQUEST_PATH),
103 + repositoryUrlFromPage: (url) =>
104 + isGitHubHost(url.hostname) ? repositoryUrlFromPagePath(url, REPOSITORY_PAGE_PATH) : null,
105 // GitHub writes every bare reference through `/issues/`, including pull requests.
106 changeRequestUrlFromReferenceAutolink: (url) => {
107 const match = isGitHubHost(url.hostname) ? ISSUE_PATH.exec(url.pathname) : null;
packages/source-control-gitlab/src/shared/definition.ts
+4
@@ -7,6 +7,7 @@ import {
7 isChangeRequestOnProjectHost,
8 parseChangeRequestPath,
9 parseCommitPath,
10 + repositoryUrlFromPagePath,
11 projectChangeRequestHost,
12 remoteWebOrigin,
13 } from "@t3tools/source-control-core/shared/definition";
@@ -20,6 +21,8 @@ const CHANGE_REQUEST_REFERENCE =
21 // Self-managed GitLab runs on any hostname and nests projects in groups.
22 const CHANGE_REQUEST_PATH = /^\/([^/]+(?:\/[^/]+)+)\/-\/merge_requests\/(\d+)(?:\/|$)/u;
23 const COMMIT_PATH = /^\/([^/]+(?:\/[^/]+)+)\/-\/commit\/([0-9a-f]+)\/?$/iu;
24 +// Every GitLab page inside a project sits below its first `/-/`.
25 +const REPOSITORY_PAGE_PATH = /^\/([^/]+(?:\/[^/]+)+?)\/-\//u;
26
27 const KIND = SourceControlProviderKind.make("gitlab");
28
@@ -47,6 +50,7 @@ export const definition = defineSourceControl({
50 parseChangeRequestUrl: (url) => parseChangeRequestPath(url, CHANGE_REQUEST_PATH),
51 commitUrl: (input) => buildCommitUrl(input, "-/commit"),
52 parseCommitUrl: (url) => parseCommitPath(url, COMMIT_PATH),
53 + repositoryUrlFromPage: (url) => repositoryUrlFromPagePath(url, REPOSITORY_PAGE_PATH),
54 // `!12` already links the merge request itself; `#12` is always an issue.
55 changeRequestUrlFromReferenceAutolink: (url) =>
56 CHANGE_REQUEST_PATH.test(url.pathname) ? url.toString() : null,