Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

Refresh git status after branch rename and worktree setup (#2005)

Julius Marminge9dcea68bce25
diff --git a/apps/server/src/orchestration/Layers/ProviderCommandReactor.test.ts b/apps/server/src/orchestration/Layers/ProviderCommandReactor.test.ts
index fb4d13f07..7a4913ca3 100644
--- a/apps/server/src/orchestration/Layers/ProviderCommandReactor.test.ts
+++ b/apps/server/src/orchestration/Layers/ProviderCommandReactor.test.ts
@@ -27,6 +27,10 @@ import {
type ProviderServiceShape,
} from "../../provider/Services/ProviderService.ts";
import { GitCore, type GitCoreShape } from "../../git/Services/GitCore.ts";
+import {
+ GitStatusBroadcaster,
+ type GitStatusBroadcasterShape,
+} from "../../git/Services/GitStatusBroadcaster.ts";
import { TextGeneration, type TextGenerationShape } from "../../git/Services/TextGeneration.ts";
import { RepositoryIdentityResolverLive } from "../../project/Layers/RepositoryIdentityResolver.ts";
import { OrchestrationEngineLive } from "./OrchestrationEngine.ts";
@@ -177,6 +181,24 @@ describe("ProviderCommandReactor", () => {
: "renamed-branch",
}),
);
+ const refreshStatus = vi.fn((_: string) =>
+ Effect.succeed({
+ isRepo: true,
+ hasOriginRemote: true,
+ isDefaultBranch: false,
+ branch: "renamed-branch",
+ hasWorkingTreeChanges: false,
+ workingTree: {
+ files: [],
+ insertions: 0,
+ deletions: 0,
+ },
+ hasUpstream: true,
+ aheadCount: 0,
+ behindCount: 0,
+ pr: null,
+ }),
+ );
const generateBranchName = vi.fn<TextGenerationShape["generateBranchName"]>((_) =>
Effect.fail(
new TextGenerationError({
@@ -225,6 +247,15 @@ describe("ProviderCommandReactor", () => {
Layer.provideMerge(orchestrationLayer),
Layer.provideMerge(Layer.succeed(ProviderService, service)),
Layer.provideMerge(Layer.succeed(GitCore, { renameBranch } as unknown as GitCoreShape)),
+ Layer.provideMerge(
+ Layer.succeed(GitStatusBroadcaster, {
+ getStatus: () => Effect.die("getStatus should not be called in this test"),
+ refreshLocalStatus: () =>
+ Effect.die("refreshLocalStatus should not be called in this test"),
+ refreshStatus,
+ streamStatus: () => Stream.die("streamStatus should not be called in this test"),
+ } satisfies GitStatusBroadcasterShape),
+ ),
Layer.provideMerge(
Layer.mock(TextGeneration, {
generateBranchName,
@@ -279,6 +310,7 @@ describe("ProviderCommandReactor", () => {
respondToUserInput,
stopSession,
renameBranch,
+ refreshStatus,
generateBranchName,
generateThreadTitle,
stateDir,
@@ -513,9 +545,11 @@ describe("ProviderCommandReactor", () => {
);
await waitFor(() => harness.generateBranchName.mock.calls.length === 1);
+ await waitFor(() => harness.refreshStatus.mock.calls.length === 1);
expect(harness.generateBranchName.mock.calls[0]?.[0]).toMatchObject({
message: "Add a safer reconnect backoff.",
});
+ expect(harness.refreshStatus.mock.calls[0]?.[0]).toBe("/tmp/provider-project-worktree");
});
it("forwards codex model options through session start and turn send", async () => {
diff --git a/apps/server/src/orchestration/Layers/ProviderCommandReactor.ts b/apps/server/src/orchestration/Layers/ProviderCommandReactor.ts
index 483b99cb3..e4e772dc7 100644
--- a/apps/server/src/orchestration/Layers/ProviderCommandReactor.ts
+++ b/apps/server/src/orchestration/Layers/ProviderCommandReactor.ts
@@ -17,6 +17,7 @@ import { makeDrainableWorker } from "@t3tools/shared/DrainableWorker";
import { resolveThreadWorkspaceCwd } from "../../checkpointing/Utils.ts";
import { GitCore } from "../../git/Services/GitCore.ts";
+import { GitStatusBroadcaster } from "../../git/Services/GitStatusBroadcaster.ts";
import { increment, orchestrationEventsProcessedTotal } from "../../observability/Metrics.ts";
import { ProviderAdapterRequestError, ProviderServiceError } from "../../provider/Errors.ts";
import { TextGeneration } from "../../git/Services/TextGeneration.ts";
@@ -145,6 +146,7 @@ const make = Effect.gen(function* () {
const orchestrationEngine = yield* OrchestrationEngineService;
const providerService = yield* ProviderService;
const git = yield* GitCore;
+ const gitStatusBroadcaster = yield* GitStatusBroadcaster;
const textGeneration = yield* TextGeneration;
const serverSettingsService = yield* ServerSettingsService;
const handledTurnStartKeys = yield* Cache.make<string, true>({
@@ -447,6 +449,7 @@ const make = Effect.gen(function* () {
branch: renamed.branch,
worktreePath: cwd,
});
+ yield* gitStatusBroadcaster.refreshStatus(cwd).pipe(Effect.ignoreCause({ log: true }));
}).pipe(
Effect.catchCause((cause) =>
Effect.logWarning("provider command reactor failed to generate or rename worktree branch", {
diff --git a/apps/server/src/server.test.ts b/apps/server/src/server.test.ts
index c1188495d..5e5b172f4 100644
--- a/apps/server/src/server.test.ts
+++ b/apps/server/src/server.test.ts
@@ -58,6 +58,10 @@ import {
import { GitCore, type GitCoreShape } from "./git/Services/GitCore.ts";
import { GitManager, type GitManagerShape } from "./git/Services/GitManager.ts";
import { GitStatusBroadcasterLive } from "./git/Layers/GitStatusBroadcaster.ts";
+import {
+ GitStatusBroadcaster,
+ type GitStatusBroadcasterShape,
+} from "./git/Services/GitStatusBroadcaster.ts";
import { Keybindings, type KeybindingsShape } from "./keybindings.ts";
import { Open, type OpenShape } from "./open.ts";
import {
@@ -293,6 +297,7 @@ const buildAppUnderTest = (options?: {
open?: Partial<OpenShape>;
gitCore?: Partial<GitCoreShape>;
gitManager?: Partial<GitManagerShape>;
+ gitStatusBroadcaster?: Partial<GitStatusBroadcasterShape>;
projectSetupScriptRunner?: Partial<ProjectSetupScriptRunnerShape>;
terminalManager?: Partial<TerminalManagerShape>;
orchestrationEngine?: Partial<OrchestrationEngineShape>;
@@ -341,7 +346,11 @@ const buildAppUnderTest = (options?: {
const gitManagerLayer = Layer.mock(GitManager)({
...options?.layers?.gitManager,
});
- const gitStatusBroadcasterLayer = GitStatusBroadcasterLive.pipe(Layer.provide(gitManagerLayer));
+ const gitStatusBroadcasterLayer = options?.layers?.gitStatusBroadcaster
+ ? Layer.mock(GitStatusBroadcaster)({
+ ...options.layers.gitStatusBroadcaster,
+ })
+ : GitStatusBroadcasterLive.pipe(Layer.provide(gitManagerLayer));
const servedRoutesLayer = HttpRouter.serve(makeRoutesLayer, {
disableListenLog: true,
@@ -2913,6 +2922,24 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
() =>
Effect.gen(function* () {
const dispatchedCommands: Array<OrchestrationCommand> = [];
+ const refreshStatus = vi.fn((_: string) =>
+ Effect.succeed({
+ isRepo: true,
+ hasOriginRemote: true,
+ isDefaultBranch: false,
+ branch: "t3code/bootstrap-branch",
+ hasWorkingTreeChanges: false,
+ workingTree: {
+ files: [],
+ insertions: 0,
+ deletions: 0,
+ },
+ hasUpstream: true,
+ aheadCount: 0,
+ behindCount: 0,
+ pr: null,
+ }),
+ );
const createWorktree = vi.fn((_: Parameters<GitCoreShape["createWorktree"]>[0]) =>
Effect.succeed({
worktree: {
@@ -2937,6 +2964,9 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
gitCore: {
createWorktree,
},
+ gitStatusBroadcaster: {
+ refreshStatus,
+ },
orchestrationEngine: {
dispatch: (command) =>
Effect.sync(() => {
@@ -3014,6 +3044,7 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
projectCwd: "/tmp/project",
worktreePath: "/tmp/bootstrap-worktree",
});
+ assert.deepEqual(refreshStatus.mock.calls[0]?.[0], "/tmp/bootstrap-worktree");
const setupActivities = dispatchedCommands.filter(
(command): command is Extract<OrchestrationCommand, { type: "thread.activity.append" }> =>
diff --git a/apps/server/src/ws.ts b/apps/server/src/ws.ts
index c3672226e..c685bbc76 100644
--- a/apps/server/src/ws.ts
+++ b/apps/server/src/ws.ts
@@ -464,6 +464,7 @@ const makeWsRpcLayer = (currentSessionId: AuthSessionId) =>
branch: worktree.worktree.branch,
worktreePath: targetWorktreePath,
});
+ yield* refreshGitStatus(targetWorktreePath);
}
yield* runSetupProgram();