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
2 changes: 1 addition & 1 deletion apps/mobile/src/features/threads/ThreadRouteScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ function ThreadRouteContent(
selectedThread?.worktreePath != null ||
(selectedThreadCreation?.message.creation?.workspaceMode === "worktree" &&
selectedThreadCreation.outcome == null),
turnStarted: setupTurnStartedAt !== null,
runs: selectedThreadDetail?.runs ?? [],
followUpSent:
composer.selectedThreadFeed.filter(
(entry) => entry.type === "message" && entry.message.role === "user",
Expand Down
4 changes: 2 additions & 2 deletions apps/mobile/src/features/threads/use-worktree-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function useWorktreeSetup(input: {
environmentId: EnvironmentId | null;
threadId: ThreadId | null;
preparing: boolean;
turnStarted: boolean;
runs: Parameters<typeof resolveVisibleWorktreeSetup>[0]["runs"];
followUpSent: boolean;
}) {
const key = JSON.stringify([input.environmentId, input.threadId]);
Expand All @@ -35,7 +35,7 @@ export function useWorktreeSetup(input: {
visible: resolveVisibleWorktreeSetup({
live: snapshot,
recorded: null,
turnStarted: input.turnStarted,
runs: input.runs,
followUpSent: input.followUpSent,
}),
};
Expand Down
16 changes: 12 additions & 4 deletions apps/mobile/src/features/threads/worktree-setup-state.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ThreadId, type WorktreeSetupSnapshot } from "@t3tools/contracts";
import { resolveVisibleWorktreeSetup } from "@t3tools/client-runtime/worktree-setup";
import { describe, expect, it } from "vite-plus/test";
import * as DateTime from "effect/DateTime";
import { resolveWorktreeSetupSnapshot } from "./worktree-setup-state";

const threadId = ThreadId.make("setup-thread");
Expand All @@ -27,18 +28,25 @@ describe("mobile worktree setup handoff", () => {
resolveVisibleWorktreeSetup({
live: held,
recorded: null,
turnStarted: false,
runs: [],
followUpSent: false,
}),
).toBe(done);
expect(
resolveVisibleWorktreeSetup({
live: held,
recorded: null,
turnStarted: true,
runs: [{ startedAt: DateTime.makeUnsafe(running.startedAt) }],
followUpSent: false,
}),
).toBeNull();
const afterFirstMessageEdit = {
live: held,
recorded: null,
followUpSent: false,
runs: [{ startedAt: DateTime.makeUnsafe(running.startedAt) }, { startedAt: null }],
};
expect(resolveVisibleWorktreeSetup(afterFirstMessageEdit)).toBeNull();
expect(resolveWorktreeSetupSnapshot(threadId, undefined, held)).toBe(done);
});

Expand All @@ -53,15 +61,15 @@ describe("mobile worktree setup handoff", () => {
resolveVisibleWorktreeSetup({
live: held,
recorded: null,
turnStarted: false,
runs: [],
followUpSent: false,
}),
).toBe(settled);
expect(
resolveVisibleWorktreeSetup({
live: held,
recorded: null,
turnStarted: false,
runs: [],
followUpSent: true,
}),
).toBeNull();
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/chat/useWorktreeSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export function useWorktreeSetup(input: {
const worktreeSetup = resolveVisibleWorktreeSetup({
live: liveSnapshot,
recorded: null,
turnStarted: activityRun?.startedAt != null,
runs: serverProjection?.runs ?? [],
followUpSent,
});
// After agent handoff, sends queue behind setup without awaiting its scripts.
Expand Down
6 changes: 3 additions & 3 deletions packages/client-runtime/src/worktreeSetup.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { WorktreeSetupSnapshot } from "@t3tools/contracts";
import type { OrchestrationV2Run, WorktreeSetupSnapshot } from "@t3tools/contracts";

export function resolveVisibleWorktreeSetup(input: {
live: WorktreeSetupSnapshot | null;
recorded: WorktreeSetupSnapshot | null;
turnStarted: boolean;
runs: ReadonlyArray<Pick<OrchestrationV2Run, "startedAt">>;
followUpSent: boolean;
}): WorktreeSetupSnapshot | null {
const snapshot =
Expand All @@ -14,7 +14,7 @@ export function resolveVisibleWorktreeSetup(input: {
if (snapshot.phase === "running") return snapshot;
if (input.followUpSent) return null;
if (snapshot.phase !== "done") return snapshot;
if (!input.turnStarted) return snapshot;
if (!input.runs.some((run) => run.startedAt !== null)) return snapshot;
return snapshot.stages.some((stage) => stage.status === "failed") ? snapshot : null;
}

Expand Down
Loading