67
derivePendingUserInputs,
68
derivePhase,
69
deriveTimelineEntries,
70
+ deriveActiveWorkStartedAt,
71
deriveActivePlanState,
72
findLatestProposedPlan,
73
type PendingApproval,
224
return `${formatTimestamp(createdAt)} • ${duration}`;
225
}
226
227
+function formatWorkingTimer(startIso: string, endIso: string): string | null {
228
+ const startedAtMs = Date.parse(startIso);
229
+ const endedAtMs = Date.parse(endIso);
230
+ if (!Number.isFinite(startedAtMs) || !Number.isFinite(endedAtMs)) {
231
+ return null;
232
+ }
233
+
234
+ const elapsedSeconds = Math.max(0, Math.floor((endedAtMs - startedAtMs) / 1000));
235
+ if (elapsedSeconds < 60) {
236
+ return `${elapsedSeconds}s`;
237
+ }
238
+
239
+ const hours = Math.floor(elapsedSeconds / 3600);
240
+ const minutes = Math.floor((elapsedSeconds % 3600) / 60);
241
+ const seconds = elapsedSeconds % 60;
242
+
243
+ if (hours > 0) {
244
+ return minutes > 0 ? `${hours}h ${minutes}m` : `${hours}h`;
245
+ }
246
+
247
+ return seconds > 0 ? `${minutes}m ${seconds}s` : `${minutes}m`;
248
+}
249
+
250
const LAST_EDITOR_KEY = "t3code:last-editor";
251
const LAST_INVOKED_SCRIPT_BY_PROJECT_KEY = "t3code:last-invoked-script-by-project";
252
const MAX_VISIBLE_WORK_LOG_ENTRIES = 6;
643
Record<ThreadId, string | null>
644
>({});
645
const [sendPhase, setSendPhase] = useState<SendPhase>("idle");
646
+ const [sendStartedAt, setSendStartedAt] = useState<string | null>(null);
647
const [isConnecting, _setIsConnecting] = useState(false);
648
const [isRevertingCheckpoint, setIsRevertingCheckpoint] = useState(false);
649
const [respondingRequestIds, setRespondingRequestIds] = useState<ApprovalRequestId[]>([]);
863
const isPreparingWorktree = sendPhase === "preparing-worktree";
864
const isWorking = phase === "running" || isSendBusy || isConnecting || isRevertingCheckpoint;
865
const nowIso = new Date(nowTick).toISOString();
866
+ const activeWorkStartedAt = deriveActiveWorkStartedAt(
867
+ activeLatestTurn,
868
+ activeThread?.session ?? null,
869
+ sendStartedAt,
870
+ );
871
const threadActivities = activeThread?.activities ?? EMPTY_ACTIVITIES;
872
const workLogEntries = useMemo(
873
() => deriveWorkLogEntries(threadActivities, activeLatestTurn?.turnId ?? undefined),
1973
return [];
1974
});
1975
setSendPhase("idle");
1976
+ setSendStartedAt(null);
1977
setComposerHighlightedItemId(null);
1978
setComposerCursor(promptRef.current.length);
1979
setComposerTrigger(detectComposerTrigger(promptRef.current, promptRef.current.length));
2113
};
2114
}, [phase]);
2115
2116
+ const beginSendPhase = useCallback((nextPhase: Exclude<SendPhase, "idle">) => {
2117
+ setSendStartedAt((current) => current ?? new Date().toISOString());
2118
+ setSendPhase(nextPhase);
2119
+ }, []);
2120
+
2121
+ const resetSendPhase = useCallback(() => {
2122
+ setSendPhase("idle");
2123
+ setSendStartedAt(null);
2124
+ }, []);
2125
+
2126
+ useEffect(() => {
2127
+ if (sendPhase === "idle") {
2128
+ return;
2129
+ }
2130
+ if (
2131
+ phase === "running" ||
2132
+ activePendingApproval !== null ||
2133
+ activePendingUserInput !== null ||
2134
+ activeThread?.error
2135
+ ) {
2136
+ resetSendPhase();
2137
+ }
2138
+ }, [
2139
+ activePendingApproval,
2140
+ activePendingUserInput,
2141
+ activeThread?.error,
2142
+ phase,
2143
+ resetSendPhase,
2144
+ sendPhase,
2145
+ ]);
2146
+
2147
useEffect(() => {
2148
if (!activeThreadId) return;
2149
const previous = terminalOpenByThreadRef.current[activeThreadId] ?? false;
2453
}
2454
2455
sendInFlightRef.current = true;
2394
- setSendPhase(baseBranchForWorktree ? "preparing-worktree" : "sending-turn");
2456
+ beginSendPhase(baseBranchForWorktree ? "preparing-worktree" : "sending-turn");
2457
2458
const composerImagesSnapshot = [...composerImages];
2459
const messageIdForSend = newMessageId();
2504
await (async () => {
2505
// On first message: lock in branch + create worktree if needed.
2506
if (baseBranchForWorktree) {
2445
- setSendPhase("preparing-worktree");
2507
+ beginSendPhase("preparing-worktree");
2508
const newBranch = buildTemporaryWorktreeBranchName();
2509
const result = await createWorktreeMutation.mutateAsync({
2510
cwd: activeProject.cwd,
2609
});
2610
}
2611
2550
- setSendPhase("sending-turn");
2612
+ beginSendPhase("sending-turn");
2613
const turnAttachments = await turnAttachmentsPromise;
2614
await api.orchestration.dispatchCommand({
2615
type: "thread.turn.start",
2671
);
2672
});
2673
sendInFlightRef.current = false;
2612
- setSendPhase("idle");
2674
+ if (!turnStartSucceeded) {
2675
+ resetSendPhase();
2676
+ }
2677
};
2678
2679
const onInterrupt = async () => {
2860
const messageCreatedAt = new Date().toISOString();
2861
2862
sendInFlightRef.current = true;
2799
- setSendPhase("sending-turn");
2863
+ beginSendPhase("sending-turn");
2864
setThreadError(threadIdForSend, null);
2865
setOptimisticUserMessages((existing) => [
2866
...existing,
2909
createdAt: messageCreatedAt,
2910
});
2911
sendInFlightRef.current = false;
2848
- setSendPhase("idle");
2912
} catch (err) {
2913
setOptimisticUserMessages((existing) =>
2914
existing.filter((message) => message.id !== messageIdForSend),
2918
err instanceof Error ? err.message : "Failed to send plan follow-up.",
2919
);
2920
sendInFlightRef.current = false;
2858
- setSendPhase("idle");
2921
+ resetSendPhase();
2922
}
2923
},
2924
[
2925
activeThread,
2926
+ beginSendPhase,
2927
forceStickToBottom,
2928
isConnecting,
2929
isSendBusy,
2930
isServerThread,
2931
persistThreadSettingsForNextTurn,
2932
+ resetSendPhase,
2933
runtimeMode,
2934
selectedModel,
2935
selectedModelOptionsForDispatch,
2967
DEFAULT_MODEL_BY_PROVIDER.codex;
2968
2969
sendInFlightRef.current = true;
2905
- setSendPhase("sending-turn");
2970
+ beginSendPhase("sending-turn");
2971
const finish = () => {
2972
sendInFlightRef.current = false;
2908
- setSendPhase("idle");
2973
+ resetSendPhase();
2974
};
2975
2976
await api.orchestration
3043
activeProject,
3044
activeProposedPlan,
3045
activeThread,
3046
+ beginSendPhase,
3047
isConnecting,
3048
isSendBusy,
3049
isServerThread,
3050
navigate,
3051
+ resetSendPhase,
3052
runtimeMode,
3053
selectedModel,
3054
selectedModelOptionsForDispatch,
3390
activeThreadId={activeThread.id}
3391
activeThreadTitle={activeThread.title}
3392
activeProjectName={activeProject?.name}
3393
+ isGitRepo={isGitRepo}
3394
openInCwd={activeThread.worktreePath ?? activeProject?.cwd ?? null}
3395
activeProjectScripts={activeProject?.scripts}
3396
preferredScriptId={
3434
key={activeThread.id}
3435
hasMessages={timelineEntries.length > 0}
3436
isWorking={isWorking}
3369
- activeTurnInProgress={!latestTurnSettled}
3370
- activeTurnStartedAt={activeLatestTurn?.startedAt ?? null}
3437
+ activeTurnInProgress={isWorking || !latestTurnSettled}
3438
+ activeTurnStartedAt={activeWorkStartedAt}
3439
scrollContainer={messagesScrollElement}
3440
timelineEntries={timelineEntries}
3441
completionDividerBeforeEntryId={completionDividerBeforeEntryId}
3971
activeThreadId: ThreadId;
3972
activeThreadTitle: string;
3973
activeProjectName: string | undefined;
3974
+ isGitRepo: boolean;
3975
openInCwd: string | null;
3976
activeProjectScripts: ProjectScript[] | undefined;
3977
preferredScriptId: string | null;
3990
activeThreadId,
3991
activeThreadTitle,
3992
activeProjectName,
3993
+ isGitRepo,
3994
openInCwd,
3995
activeProjectScripts,
3996
preferredScriptId,
4019
{activeProjectName}
4020
</Badge>
4021
)}
4022
+ {activeProjectName && !isGitRepo && (
4023
+ <Badge variant="outline" className="shrink-0 text-[10px] text-amber-700">
4024
+ No Git
4025
+ </Badge>
4026
+ )}
4027
</div>
4028
<div className="@container/header-actions flex min-w-0 flex-1 items-center justify-end gap-2 @sm/header-actions:gap-3">
4029
{activeProjectScripts && (
4054
aria-label="Toggle diff panel"
4055
variant="outline"
4056
size="xs"
4057
+ disabled={!isGitRepo}
4058
>
4059
<DiffIcon className="size-3" />
4060
</Toggle>
4061
}
4062
/>
4063
<TooltipPopup side="bottom">
3988
- {diffToggleShortcutLabel
3989
- ? `Toggle diff panel (${diffToggleShortcutLabel})`
3990
- : "Toggle diff panel"}
4064
+ {!isGitRepo
4065
+ ? "Diff panel is unavailable because this project is not a git repository."
4066
+ : diffToggleShortcutLabel
4067
+ ? `Toggle diff panel (${diffToggleShortcutLabel})`
4068
+ : "Toggle diff panel"}
4069
</TooltipPopup>
4070
</Tooltip>
4071
</div>
4997
{visibleEntries.map((workEntry) => (
4998
<div key={`work-row:${workEntry.id}`} className="flex items-start gap-2 py-0.5">
4999
<span className="mt-[7px] h-1.5 w-1.5 shrink-0 rounded-full bg-muted-foreground/30" />
4922
- <p
4923
- className={`py-[2px] text-[11px] leading-relaxed ${workToneClass(workEntry.tone)}`}
4924
- >
4925
- {workEntry.detail ? (
4926
- <>
4927
- {workEntry.label}
4928
- <span
4929
- className="ml-1.5 inline-block max-w-[70ch] truncate align-bottom font-mono text-[11px] opacity-60"
5000
+ <div className="min-w-0 flex-1 py-[2px]">
5001
+ <p className={`text-[11px] leading-relaxed ${workToneClass(workEntry.tone)}`}>
5002
+ {workEntry.label}
5003
+ </p>
5004
+ {workEntry.command && (
5005
+ <pre className="mt-1 overflow-x-auto rounded-md border border-border/70 bg-background/80 px-2 py-1 font-mono text-[11px] leading-relaxed text-foreground/80">
5006
+ {workEntry.command}
5007
+ </pre>
5008
+ )}
5009
+ {workEntry.changedFiles && workEntry.changedFiles.length > 0 && (
5010
+ <div className="mt-1 flex flex-wrap gap-1">
5011
+ {workEntry.changedFiles.slice(0, 6).map((filePath) => (
5012
+ <span
5013
+ key={`${workEntry.id}:${filePath}`}
5014
+ className="rounded-md border border-border/70 bg-background/65 px-1.5 py-0.5 font-mono text-[10px] text-muted-foreground/85"
5015
+ title={filePath}
5016
+ >
5017
+ {filePath}
5018
+ </span>
5019
+ ))}
5020
+ {workEntry.changedFiles.length > 6 && (
5021
+ <span className="px-1 text-[10px] text-muted-foreground/65">
5022
+ +{workEntry.changedFiles.length - 6} more
5023
+ </span>
5024
+ )}
5025
+ </div>
5026
+ )}
5027
+ {workEntry.detail &&
5028
+ (!workEntry.command || workEntry.detail !== workEntry.command) && (
5029
+ <p
5030
+ className="mt-1 text-[11px] leading-relaxed text-muted-foreground/75"
5031
title={workEntry.detail}
5032
>
5033
{workEntry.detail}
4933
- </span>
4934
- </>
4935
- ) : (
4936
- workEntry.label
4937
- )}
4938
- </p>
5034
+ </p>
5035
+ )}
5036
+ </div>
5037
</div>
5038
))}
5039
</div>
5219
{row.kind === "working" && (
5220
<div className="flex items-center gap-2 py-0.5 pl-1.5">
5221
<span className="h-1.5 w-1.5 shrink-0 rounded-full bg-muted-foreground/30" />
5124
- <div className="flex items-center pt-1">
5222
+ <div className="flex items-center gap-2 pt-1 text-[11px] text-muted-foreground/70">
5223
<span className="inline-flex items-center gap-[3px]">
5224
<span className="h-1 w-1 rounded-full bg-muted-foreground/30 animate-pulse" />
5225
<span className="h-1 w-1 rounded-full bg-muted-foreground/30 animate-pulse [animation-delay:200ms]" />
5226
<span className="h-1 w-1 rounded-full bg-muted-foreground/30 animate-pulse [animation-delay:400ms]" />
5227
</span>
5228
+ <span>
5229
+ {row.createdAt
5230
+ ? `Working for ${formatWorkingTimer(row.createdAt, nowIso) ?? "0s"}`
5231
+ : "Working..."}
5232
+ </span>
5233
</div>
5234
</div>
5235
)}