Skip to content
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
10 changes: 3 additions & 7 deletions apps/mobile/src/lib/threadActivityInspector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import * as DateTime from "effect/DateTime";
import { describe, expect, it } from "vite-plus/test";

import { buildThreadFeed, type ThreadFeedActivity } from "./threadActivity";
import type { ThreadFeedActivity } from "./threadActivity";
import { buildThreadActivityInspector } from "./threadActivityInspector";

const threadId = ThreadId.make("thread-1");
Expand Down Expand Up @@ -43,19 +43,15 @@ function itemBase(id: string) {
};
}

function activityFor(item: OrchestrationV2TurnItem): ThreadFeedActivity {
function activityFor(item: OrchestrationV2TurnItem): Pick<ThreadFeedActivity, "projectedItem"> {
const row: OrchestrationV2ProjectedTurnItem = {
position: 0,
visibility: "inherited",
sourceThreadId,
sourceItemId: item.id,
item,
};
const group = buildThreadFeed([row])[0];
if (group?.type !== "activity-group" || !group.activities[0]) {
throw new Error("Expected an activity group");
}
return group.activities[0];
return { projectedItem: row };
}

describe("buildThreadActivityInspector", () => {
Expand Down
2 changes: 1 addition & 1 deletion apps/mobile/src/lib/threadActivityInspector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function addBlock(
}

export function buildThreadActivityInspector(
activity: ThreadFeedActivity,
activity: Pick<ThreadFeedActivity, "projectedItem">,
support: V2ItemSupport,
currentThreadId: ThreadId,
): ThreadActivityInspectorModel {
Expand Down
20 changes: 20 additions & 0 deletions apps/server/src/orchestration-v2/Orchestrator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { threadPullRequestsOf } from "@t3tools/shared/threadPullRequests";
import {
normalizeThreadPullRequestKey,
visibleThreadPullRequests,
threadPullRequestKeysEqual,
legacyThreadPullRequestKey,
} from "@t3tools/shared/threadPullRequests";
Expand Down Expand Up @@ -1978,7 +1979,26 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
snapshot: null,
stack: null,
};
const branch = thread.branchPullRequest;
const branchKey = branch ? legacyThreadPullRequestKey(branch) : null;
pullRequests = [
...(command.source === "manual" &&
branch &&
branchKey &&
visibleThreadPullRequests(links).length === 0 &&
!threadPullRequestKeysEqual(branchKey, key) &&
!links.some((entry) => threadPullRequestKeysEqual(entry, branchKey))
? [
{
...branchKey,
url: branch.url,
source: "manual" as const,
linkedAt: DateTime.formatIso(now),
snapshot: null,
stack: null,
},
]
: []),
...links.filter((entry) => !threadPullRequestKeysEqual(entry, key)),
link,
];
Expand Down
96 changes: 96 additions & 0 deletions apps/server/src/orchestration-v2/runtimeLayer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1765,6 +1765,102 @@ it.layer(TestLayer)("OrchestrationV2LayerLive lifecycle", (it) => {
}),
);

it.effect("keeps the branch pull request when linking another pull request", () =>
Effect.gen(function* () {
const orchestrator = yield* OrchestratorV2;
const maintenance = yield* ProjectionMaintenanceV2;
const projects = yield* ProjectionProjectRepository;
const threadId = ThreadId.make("branch-pr-link");
const projectId = ProjectId.make("branch-pr-project");
yield* projects.upsert({
projectId,
title: "PR links",
workspaceRoot: "/workspace/pr-links",
defaultModelSelection: null,
defaultThreadEnvMode: null,
autoPull: false,
scripts: [],
createdAt: "2026-09-17T00:00:00.000Z",
updatedAt: "2026-09-17T00:00:00.000Z",
deletedAt: null,
});
yield* orchestrator.dispatch({
type: "thread.create",
createdBy: "user",
creationSource: "web",
commandId: CommandId.make("branch-pr-create"),
threadId,
projectId,
title: "PR links",
modelSelection,
runtimeMode: "full-access",
interactionMode: "default",
branch: "feature/pr-links",
worktreePath: null,
});
const snapshot = yield* orchestrator.getShellSnapshot();
yield* orchestrator.dispatch({
type: "thread.pull-request.sync",
commandId: CommandId.make("branch-pr-discover"),
threadId,
projectId,
snapshotSequence: snapshot.snapshotSequence,
expected: {
workspaceRoot: "/workspace/pr-links",
branch: "feature/pr-links",
worktreePath: null,
linkedPullRequest: null,
branchPullRequest: null,
},
branchPullRequest: {
projectId,
repository: "pingdotgg/t3code",
number: 1,
url: "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/pingdotgg/t3code/pull/1",
},
});
for (const [index, number] of [2, 2, 1, 3].entries()) {
yield* orchestrator.dispatch({
type: "thread.pull-request.link",
commandId: CommandId.make(`branch-pr-link-${index}`),
threadId,
host: "GitHub.com",
repository: "Pingdotgg/T3code",
number,
url: `https://github.com/pingdotgg/t3code/pull/${number}`,
source: "manual",
});
assert.deepEqual(
(yield* orchestrator.getThreadShell(threadId))?.pullRequests?.map((link) => link.number),
number === 3 ? [1, 2, 3] : [1, 2],
);
}
yield* orchestrator.dispatch({
type: "thread.pull-request.unlink",
commandId: CommandId.make("branch-pr-unlink"),
threadId,
host: "github.com",
repository: "pingdotgg/t3code",
number: 1,
});
yield* orchestrator.dispatch({
type: "thread.pull-request.link",
commandId: CommandId.make("branch-pr-link-after-unlink"),
threadId,
host: "github.com",
repository: "pingdotgg/t3code",
number: 4,
url: "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/pingdotgg/t3code/pull/4",
source: "manual",
});
assert.isTrue((yield* maintenance.rebuild).valid);
assert.deepEqual(
(yield* orchestrator.getThreadShell(threadId))?.pullRequests?.map((link) => link.number),
[2, 3, 4],
);
}),
);

it.effect("retains multiple pull requests and dismissed stack members through rebuilds", () =>
Effect.gen(function* () {
const orchestrator = yield* OrchestratorV2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,7 @@ describe("orchestration V2 thread fork", () => {
},
{
type: "checkpoint.rollback",
restoreFiles: false,
commandId: yield* ids.allocate.command({
fixtureName: "thread-fork-native-prior-turn-source-rollback",
commandName: "rollback-source-to-alpha",
Expand Down Expand Up @@ -1361,6 +1362,7 @@ describe("orchestration V2 thread fork", () => {
},
{
type: "checkpoint.rollback",
restoreFiles: false,
commandId: yield* ids.allocate.command({
fixtureName: "thread-fork-native-fork-local-rollback",
commandName: "rollback-fork-to-first",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,7 @@ export function materializeFixtureInput(input: {
});
pushDispatch({
type: "checkpoint.rollback",
restoreFiles: false,
commandId: yield* idAllocator.allocate.command({
fixtureName: input.scenario,
commandName: `rollback-${step.checkpointSuffix}`,
Expand Down
15 changes: 1 addition & 14 deletions apps/server/src/storageCleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,14 @@ import { resolveWorktreeCleanup } from "@t3tools/shared/projectSettings";
import { makeDrainableWorker } from "@t3tools/shared/DrainableWorker";
import * as Cause from "effect/Cause";
import * as Clock from "effect/Clock";
import * as Context from "effect/Context";
import * as DateTime from "effect/DateTime";
import * as Effect from "effect/Effect";
import * as Equal from "effect/Equal";
import * as FileSystem from "effect/FileSystem";
import * as Layer from "effect/Layer";
import * as Option from "effect/Option";
import * as Path from "effect/Path";
import type { PlatformError } from "effect/PlatformError";
import * as Schedule from "effect/Schedule";
import type * as Scope from "effect/Scope";
import * as Stream from "effect/Stream";

import * as ServerConfig from "./config.ts";
Expand All @@ -41,14 +38,6 @@ import * as TerminalManager from "./terminal/Manager.ts";
import * as GitVcsDriver from "./vcs/GitVcsDriver.ts";
import { withWorkspaceLease } from "./workspace/workspaceLease.ts";

export class StorageCleanup extends Context.Service<
StorageCleanup,
{
readonly start: () => Effect.Effect<void, never, Scope.Scope>;
readonly drain: Effect.Effect<void>;
}
>()("t3/storageCleanup") {}

const decodeCleanupThread = Schema.decodeUnknownEffect(
Schema.fromJsonString(OrchestrationV2AppThreadJson),
);
Expand Down Expand Up @@ -508,7 +497,5 @@ export const make = Effect.gen(function* () {
),
);
});
return { start, drain: worker.drain } satisfies StorageCleanup["Service"];
return { start, drain: worker.drain };
});

export const layer = Layer.effect(StorageCleanup, make);
1 change: 1 addition & 0 deletions apps/web/src/components/BranchToolbarBranchSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,7 @@ export function BranchToolbarBranchSelector({
<ThreadPullRequestBadgeControl
variant="ghost"
badge={prBadge}
pullRequests={serverThread?.pullRequests ?? []}
number={prNumber}
url={prUrl}
status={displayedPrStatus}
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1597,6 +1597,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
<ThreadPullRequestBadgeControl
variant="underline"
badge={prBadgeShape}
pullRequests={thread.pullRequests}
number={pr?.number ?? currentLinkedPr?.number}
url={pr?.url ?? currentLinkedPr?.url}
status={prStatus}
Expand Down
13 changes: 12 additions & 1 deletion apps/web/src/components/ThreadStatusIndicators.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ export function resolveThreadPullRequestBadgePresentation({
export function ThreadPullRequestBadgeControl({
variant,
badge,
pullRequests,
number,
url,
status,
Expand All @@ -212,6 +213,7 @@ export function ThreadPullRequestBadgeControl({
}: {
variant: "underline" | "ghost";
badge: ThreadPullRequestBadge | null;
pullRequests: ReadonlyArray<ThreadPullRequestLink>;
number?: number | undefined;
url?: string | undefined;
status: PrStatusIndicator | null;
Expand All @@ -221,6 +223,7 @@ export function ThreadPullRequestBadgeControl({
const presentation = resolveThreadPullRequestBadgePresentation({ badge, number, url, status });
if (presentation === null) return null;
const isStack = badge?.kind === "stack";
const showList = isStack || (badge?.kind === "pull-request" && badge.others > 0);
const className = cn(
variant === "ghost"
? buttonVariants({ variant: "ghost", size: "xs" })
Expand Down Expand Up @@ -266,7 +269,15 @@ export function ThreadPullRequestBadgeControl({
>
{content}
</TooltipTrigger>
<TooltipPopup side="top">{presentation.label}</TooltipPopup>
<TooltipPopup
side="top"
variant={showList ? "glass" : "default"}
className={
showList ? "w-80 max-w-[calc(100vw-2rem)] text-left whitespace-normal" : undefined
}
>
{showList ? <ThreadPullRequestsMiniList pullRequests={pullRequests} /> : presentation.label}
</TooltipPopup>
</Tooltip>
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/client-runtime/src/handoff.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ProviderInstanceId, RunId } from "@t3tools/contracts";
import { describe, expect, it } from "vite-plus/test";
import { resolveHandoffEndpoints, type HandoffTimelineRun } from "./handoff";
import { resolveHandoffEndpoints, type HandoffTimelineRun } from "./handoff.ts";

const from = ProviderInstanceId.make("codex_personal");
const to = ProviderInstanceId.make("claudeAgent");
Expand Down
13 changes: 0 additions & 13 deletions packages/client-runtime/src/work-log/presentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,6 @@ export function toolItemForDisplay(item: OrchestrationV2TurnItem): Orchestration
}
}

/**
* Activities the worktree setup card already represents. The settled record
* is rendered by the card on web and mobile, never as a
* worklog entry, so it is hidden from the activity feed even when it failed.
*/
export function isWorktreeSetupActivity(kind: string): boolean {
return (
kind === "setup-script.requested" ||
kind === "setup-script.started" ||
kind === "worktree-setup"
);
}

export function contextCompactionLabel(
item: Pick<
Extract<OrchestrationV2TurnItem, { type: "compaction" }>,
Expand Down
Loading