Skip to content

Commit 061c8c1

Browse files
committed
chore: merge upstream main for provider command compatibility
2 parents a00a8af + 3138f57 commit 061c8c1

72 files changed

Lines changed: 5095 additions & 105 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/mobile/src/components/SourceControlIcon.tsx‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import Svg, { Defs, LinearGradient, Path, Stop } from "react-native-svg";
1+
import Svg, { Circle, Defs, G, LinearGradient, Path, Stop } from "react-native-svg";
22
import { withUniwind } from "uniwind";
33

44
const ThemedSvg = withUniwind(Svg);
55

6-
export type SourceControlIconKind = "github" | "gitlab" | "bitbucket" | "azure-devops";
6+
export type SourceControlIconKind = "github" | "gitlab" | "forgejo" | "bitbucket" | "azure-devops";
77

88
export function SourceControlIcon(props: {
99
readonly kind: SourceControlIconKind;
@@ -14,6 +14,19 @@ export function SourceControlIcon(props: {
1414
const size = props.size ?? 18;
1515

1616
switch (props.kind) {
17+
case "forgejo":
18+
// Official two-color mark from https://forgejo.org/favicon.svg.
19+
return (
20+
<Svg width={size} height={size} viewBox="0 0 212 212">
21+
<G transform="translate(6 6)" fill="none">
22+
<Path d="M58 168 v-98 a50 50 0 0 1 50-50 h20" stroke="#ff6600" strokeWidth={25} />
23+
<Path d="M58 168 v-30 a50 50 0 0 1 50-50 h20" stroke="#d40000" strokeWidth={25} />
24+
<Circle cx={142} cy={20} r={18} stroke="#ff6600" strokeWidth={15} />
25+
<Circle cx={142} cy={88} r={18} stroke="#d40000" strokeWidth={15} />
26+
<Circle cx={58} cy={180} r={18} stroke="#d40000" strokeWidth={15} />
27+
</G>
28+
</Svg>
29+
);
1730
case "github":
1831
return (
1932
<ThemedSvg

‎apps/mobile/src/features/projects/AddProjectRepositoryRoute.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export function AddProjectRepositoryRoute({
1717
const title =
1818
source === "github" ||
1919
source === "gitlab" ||
20+
source === "forgejo" ||
2021
source === "bitbucket" ||
2122
source === "azure-devops"
2223
? addProjectRemoteSourceLabel(source)

‎apps/mobile/src/features/projects/AddProjectScreen.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ function sourceFromParam(value: string | string[] | undefined): AddProjectRemote
110110
source === "url" ||
111111
source === "github" ||
112112
source === "gitlab" ||
113+
source === "forgejo" ||
113114
source === "bitbucket" ||
114115
source === "azure-devops"
115116
) {

‎apps/server/scripts/acp-mock-agent.ts‎

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ const emitXAiAskUserQuestionThenHang =
3030
const emitContentThenHang = process.env.T3_ACP_EMIT_CONTENT_THEN_HANG === "1";
3131
const emitPlanThenHang = process.env.T3_ACP_EMIT_PLAN_THEN_HANG === "1";
3232
const emitActiveToolThenHang = process.env.T3_ACP_EMIT_ACTIVE_TOOL_THEN_HANG === "1";
33+
const emitGrokMonitorPostTurnPoll = process.env.T3_ACP_EMIT_GROK_MONITOR_POST_TURN_POLL === "1";
34+
const emitGrokBackgroundTaskStarted = process.env.T3_ACP_EMIT_GROK_BACKGROUND_TASK_STARTED === "1";
3335
const emitForeignSessionUpdates = process.env.T3_ACP_EMIT_FOREIGN_SESSION_UPDATES === "1";
3436
const waitForResumeRelease = process.env.T3_ACP_WAIT_FOR_RESUME_RELEASE === "1";
3537
const completeFirstPromptOnCancel = process.env.T3_ACP_COMPLETE_FIRST_PROMPT_ON_CANCEL === "1";
@@ -837,6 +839,108 @@ const program = Effect.gen(function* () {
837839
return yield* Effect.never;
838840
}
839841

842+
if (emitGrokMonitorPostTurnPoll) {
843+
const monitorCallId = "call-monitor-1";
844+
const pollCallId = "call-monitor-poll-1";
845+
const taskId = "01a05f41-5107-7550-821e-79e8d1cd7687";
846+
const description = "Watch count-sheet Typst unit until done";
847+
writeJsonRpcNotification("session/update", {
848+
sessionId: requestedSessionId,
849+
update: {
850+
sessionUpdate: "tool_call",
851+
toolCallId: monitorCallId,
852+
title: "monitor",
853+
kind: "other",
854+
status: "pending",
855+
rawInput: { description },
856+
_meta: {
857+
"x.ai/tool": { version: 1, name: "monitor", kind: "task", namespace: "grok_build" },
858+
},
859+
},
860+
});
861+
writeJsonRpcNotification("session/update", {
862+
sessionId: requestedSessionId,
863+
update: {
864+
sessionUpdate: "tool_call_update",
865+
toolCallId: monitorCallId,
866+
status: "completed",
867+
rawInput: { description },
868+
rawOutput: {
869+
type: "Monitor",
870+
taskId,
871+
timeoutMs: 36_000_000,
872+
},
873+
},
874+
});
875+
writeJsonRpcNotification("_x.ai/session/prompt_complete", {
876+
sessionId: requestedSessionId,
877+
promptId: promptIdFromRequestMeta(request) ?? "mock-xai-prompt-1",
878+
stopReason: "end_turn",
879+
agentResult: null,
880+
});
881+
yield* Effect.sleep("120 millis");
882+
writeJsonRpcNotification("session/update", {
883+
sessionId: requestedSessionId,
884+
update: {
885+
sessionUpdate: "tool_call",
886+
toolCallId: pollCallId,
887+
title: "get_command_or_subagent_output",
888+
kind: "other",
889+
status: "completed",
890+
rawInput: { variant: "TaskOutput", task_ids: [taskId], timeout_ms: 0 },
891+
rawOutput: {
892+
type: "TaskOutput",
893+
Result: {
894+
task_id: taskId,
895+
command: `[monitor] ${description}`,
896+
status: "completed",
897+
exit_code: 0,
898+
output: "Monitor finished.",
899+
},
900+
},
901+
},
902+
});
903+
return yield* Effect.never;
904+
}
905+
906+
if (emitGrokBackgroundTaskStarted) {
907+
const toolCallId = "call-fb9d0000-0000-0000-0000-000000000026";
908+
const command = "sleep 40; echo done-a";
909+
writeJsonRpcNotification("session/update", {
910+
sessionId: requestedSessionId,
911+
update: {
912+
sessionUpdate: "tool_call",
913+
toolCallId,
914+
title: "run_terminal_command",
915+
kind: "execute",
916+
status: "in_progress",
917+
rawInput: { command },
918+
},
919+
});
920+
writeJsonRpcNotification("session/update", {
921+
sessionId: requestedSessionId,
922+
update: {
923+
sessionUpdate: "tool_call_update",
924+
toolCallId,
925+
status: "completed",
926+
rawOutput: {
927+
type: "BackgroundTaskStarted",
928+
task_id: toolCallId,
929+
task_type: "bash",
930+
status: "running",
931+
command,
932+
},
933+
},
934+
});
935+
writeJsonRpcNotification("_x.ai/session/prompt_complete", {
936+
sessionId: requestedSessionId,
937+
promptId: promptIdFromRequestMeta(request) ?? "mock-xai-prompt-1",
938+
stopReason: "end_turn",
939+
agentResult: null,
940+
});
941+
return yield* Effect.never;
942+
}
943+
840944
if (emitInterleavedAssistantToolCalls) {
841945
const toolCallId = "tool-call-1";
842946

‎apps/server/src/git/GitManager.test.ts‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ import * as GitVcsDriver from "../vcs/GitVcsDriver.ts";
3737
import * as VcsProcess from "../vcs/VcsProcess.ts";
3838
import * as GitHubSourceControlProvider from "../sourceControl/GitHubSourceControlProvider.ts";
3939
import * as GitLabSourceControlProvider from "../sourceControl/GitLabSourceControlProvider.ts";
40+
import {
41+
ForgejoPullRequestSchema,
42+
toForgejoChangeRequest,
43+
} from "../sourceControl/forgejoPullRequests.ts";
4044
import type { SourceControlProvider } from "../sourceControl/SourceControlProvider.ts";
4145
import * as SourceControlProviderRegistry from "../sourceControl/SourceControlProviderRegistry.ts";
4246
import * as ServerConfig from "../config.ts";
@@ -46,6 +50,7 @@ import * as ServerSettings from "../serverSettings.ts";
4650
import * as GitManager from "./GitManager.ts";
4751

4852
const encodeCliJson = Schema.encodeSync(Schema.fromJsonString(Schema.Unknown));
53+
const decodeForgejoPullRequest = Schema.decodeEffect(ForgejoPullRequestSchema);
4954

5055
interface FakeGhScenario {
5156
prListSequence?: string[];
@@ -3851,6 +3856,69 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
38513856
20_000,
38523857
);
38533858

3859+
it.effect("matches mounted Forgejo heads without confusing forks sharing a branch", () =>
3860+
Effect.gen(function* () {
3861+
for (const owner of ["maria", "reviewer"]) {
3862+
const mapped = toForgejoChangeRequest(
3863+
yield* decodeForgejoPullRequest({
3864+
number: 42,
3865+
title: "Greeting",
3866+
html_url: "https://forgejo.example/forgejo/maria/project/pulls/42",
3867+
state: "open",
3868+
merged: false,
3869+
base: {
3870+
ref: "main",
3871+
sha: "base",
3872+
repo: { full_name: "maria/project", owner: { login: "maria" } },
3873+
},
3874+
head: {
3875+
ref: "greeting",
3876+
sha: "head",
3877+
repo: { full_name: `${owner}/project`, owner: { login: owner } },
3878+
},
3879+
}),
3880+
);
3881+
const pr = {
3882+
...mapped,
3883+
isDraft: mapped.isDraft ?? false,
3884+
closedAt: mapped.closedAt ?? null,
3885+
mergedAt: mapped.mergedAt ?? null,
3886+
};
3887+
const repository = GitManager.parseRepositoryNameWithOwnerFromRemoteUrl(
3888+
`https://forgejo.example/forgejo/${owner}/project.git`,
3889+
"forgejo",
3890+
);
3891+
expect(repository).toBe(`${owner}/project`);
3892+
const context = {
3893+
headBranch: "greeting",
3894+
headRepositoryNameWithOwner: repository,
3895+
headRepositoryOwnerLogin: repository?.split("/")[0] ?? null,
3896+
isCrossRepository: owner !== "maria",
3897+
};
3898+
expect(GitManager.matchesBranchHeadContext(pr, context)).toBe(true);
3899+
expect(
3900+
GitManager.matchesBranchHeadContext(pr, {
3901+
...context,
3902+
headRepositoryNameWithOwner: "other/project",
3903+
headRepositoryOwnerLogin: "other",
3904+
}),
3905+
).toBe(false);
3906+
}
3907+
expect(
3908+
GitManager.parseRepositoryNameWithOwnerFromRemoteUrl(
3909+
"[email protected]:maria/project.git",
3910+
"forgejo",
3911+
),
3912+
).toBe("maria/project");
3913+
expect(
3914+
GitManager.parseRepositoryNameWithOwnerFromRemoteUrl(
3915+
"https://gitlab.example/group/maria/project.git",
3916+
"gitlab",
3917+
),
3918+
).toBe("group/maria/project");
3919+
}),
3920+
);
3921+
38543922
it.effect("rejects same-repo PR metadata when matching a cross-repo head context", () =>
38553923
Effect.sync(() => {
38563924
const headContext = {

‎apps/server/src/git/GitManager.ts‎

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,10 @@ function resolvePullRequestWorktreeLocalBranchName(
277277
return `t3code/pr-${pullRequest.number}/${suffix}`;
278278
}
279279

280-
function parseRepositoryNameWithOwnerFromRemoteUrl(url: string | null): string | null {
280+
export function parseRepositoryNameWithOwnerFromRemoteUrl(
281+
url: string | null,
282+
providerKind?: ChangeRequest["provider"],
283+
): string | null {
281284
const trimmed = url?.trim() ?? "";
282285
if (trimmed.length === 0) {
283286
return null;
@@ -288,6 +291,12 @@ function parseRepositoryNameWithOwnerFromRemoteUrl(url: string | null): string |
288291
trimmed,
289292
);
290293
const repositoryNameWithOwner = match?.[1]?.trim() ?? "";
294+
// Forgejo HTTP paths can include an installation mount; its API always names owner/repo.
295+
if (providerKind === "forgejo" && /^https?:\/\//iu.test(trimmed)) {
296+
return repositoryNameWithOwner.length > 0
297+
? repositoryNameWithOwner.split("/").slice(-2).join("/")
298+
: null;
299+
}
291300
return repositoryNameWithOwner.length > 0 ? repositoryNameWithOwner : null;
292301
}
293302

@@ -1291,7 +1300,15 @@ export const make = Effect.gen(function* () {
12911300
(yield* readConfigValueNullable(cwd, `remote.${preferredRemoteName}.url`)) ??
12921301
(yield* readConfigValueNullable(cwd, "remote.origin.url"));
12931302

1294-
return remoteUrl ? detectSourceControlProviderFromGitRemoteUrl(remoteUrl) : null;
1303+
const provider = remoteUrl ? detectSourceControlProviderFromGitRemoteUrl(remoteUrl) : null;
1304+
if (!remoteUrl || provider?.kind !== "unknown") return provider;
1305+
const handle = yield* sourceControlProviders
1306+
.resolveHandle({
1307+
cwd,
1308+
context: { provider, remoteName: preferredRemoteName, remoteUrl },
1309+
})
1310+
.pipe(Effect.orElseSucceed(() => null));
1311+
return handle?.context?.provider ?? provider;
12951312
});
12961313

12971314
const resolveRemoteRepositoryContext = Effect.fn("resolveRemoteRepositoryContext")(function* (
@@ -1307,7 +1324,22 @@ export const make = Effect.gen(function* () {
13071324
}
13081325

13091326
const remoteUrl = yield* readConfigValueNullable(cwd, `remote.${remoteName}.url`);
1310-
const repositoryNameWithOwner = parseRepositoryNameWithOwnerFromRemoteUrl(remoteUrl);
1327+
let repositoryNameWithOwner = parseRepositoryNameWithOwnerFromRemoteUrl(remoteUrl);
1328+
if (
1329+
remoteUrl !== null &&
1330+
/^https?:\/\//iu.test(remoteUrl) &&
1331+
(repositoryNameWithOwner?.split("/").length ?? 0) > 2
1332+
) {
1333+
const detected = detectSourceControlProviderFromGitRemoteUrl(remoteUrl);
1334+
const kind =
1335+
detected?.kind === "unknown"
1336+
? yield* sourceControlProvider(cwd).pipe(
1337+
Effect.map((provider) => provider.kind),
1338+
Effect.orElseSucceed(() => undefined),
1339+
)
1340+
: detected?.kind;
1341+
repositoryNameWithOwner = parseRepositoryNameWithOwnerFromRemoteUrl(remoteUrl, kind);
1342+
}
13111343
return {
13121344
remoteUrlKey: remoteUrl ? normalizeGitRemoteUrl(remoteUrl) : null,
13131345
repositoryNameWithOwner,

‎apps/server/src/mcp/toolkits/pullRequests/handlers.test.ts‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,40 @@ describe("pull request toolkit handlers", () => {
265265
}),
266266
);
267267

268+
it.effect("links a numeric Forgejo reference with its remote's web origin and mount path", () =>
269+
Effect.gen(function* () {
270+
const harness = yield* makeHarness({
271+
project: makeProject({
272+
canonicalKey: "forge.example/git/owner/repo",
273+
locator: {
274+
source: "git-remote",
275+
remoteName: "origin",
276+
remoteUrl: "http://forge.example:3000/git/owner/repo.git",
277+
},
278+
provider: "forgejo",
279+
displayName: "git/owner/repo",
280+
}),
281+
});
282+
const result = yield* harness.call("link_pull_request", {
283+
repository: "git/owner/repo",
284+
number: 42,
285+
});
286+
expect(result).toEqual({
287+
host: "forge.example:3000",
288+
repository: "git/owner/repo",
289+
number: 42,
290+
url: "http://forge.example:3000/git/owner/repo/pulls/42",
291+
alreadyLinked: false,
292+
});
293+
const other = yield* harness.call("link_pull_request", {
294+
host: "other.example",
295+
repository: "owner/repo",
296+
number: 42,
297+
});
298+
expect(other.url).toBe("https://other.example/owner/repo/pull/42");
299+
}),
300+
);
301+
268302
it.effect("rejects a target that names neither a URL nor repository and number", () =>
269303
Effect.gen(function* () {
270304
const harness = yield* makeHarness();
@@ -334,6 +368,18 @@ describe("pull request toolkit handlers", () => {
334368
}),
335369
);
336370

371+
it("reports an older Forgejo link's HTTP port when listing thread links", () => {
372+
const result = listThreadPullRequests(
373+
makeThread([
374+
makeLink(42, {
375+
host: "forge.example",
376+
url: "http://forge.example:3000/t3tools/t3code/pulls/42",
377+
}),
378+
]),
379+
);
380+
expect(result.pullRequests[0]?.host).toBe("forge.example:3000");
381+
});
382+
337383
it.effect("fails cleanly when the token's thread no longer exists", () =>
338384
Effect.gen(function* () {
339385
const harness = yield* makeHarness({ thread: null });

0 commit comments

Comments
 (0)