Skip to content

Commit 6b565c0

Browse files
authored
feat(ui): show unsent-draft pencil on sidebar session rows (#121476)
* feat(ui): show unsent-draft pencil on sidebar session rows Typed-but-unsent composer text now surfaces as a pencil badge on the owning session's sidebar row (and Home row) once you switch away. Draft persistence now notifies stored-outbox subscribers so the indicator appears and clears live. The active session suppresses the badge since its composer is already visible. * chore: refresh merge ref for CI against current main * chore: refresh merge ref against healed main * fix(ui): notify draft indicator only on presence transitions Unconditional notify on every draft persist let outbox-projection subscribers re-persist a stale pane over a newer draft (chat-state route-fallback invariant). The sidebar pencil only consumes presence, so notify on empty/non-empty transitions only.
1 parent 60e1f40 commit 6b565c0

18 files changed

Lines changed: 208 additions & 21 deletions

‎ui/src/app/app-shell-gateway.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export type StoredOutboxScopeHost = {
2929
};
3030

3131
export type OutboxStoreRuntime = {
32+
listStoredDraftScopes: (state: StoredOutboxScopeHost) => ReadonlySet<string>;
3233
summarizeStoredChatOutboxes: (state: StoredOutboxScopeHost) => {
3334
countsByScope: ReadonlyMap<string, number>;
3435
total: number;

‎ui/src/app/app-shell-view.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040
} from "./settings.ts";
4141

4242
const EMPTY_OUTBOX_COUNT_FOR_SESSION = () => 0;
43+
const EMPTY_SESSION_HAS_DRAFT = () => false;
4344
const PALETTE_SHORTCUT = /Mac|iP(hone|ad|od)/i.test(globalThis.navigator?.platform ?? "")
4445
? "⌘K"
4546
: "Ctrl K";
@@ -100,6 +101,9 @@ export function renderApplicationShell(host: ShellViewHost) {
100101
const storedOutboxes = outboxStoreRuntime
101102
? outboxStoreRuntime.summarizeStoredChatOutboxes(outboxScopeHost)
102103
: null;
104+
const storedDraftScopeKeys = outboxStoreRuntime
105+
? outboxStoreRuntime.listStoredDraftScopes(outboxScopeHost)
106+
: null;
103107
const outboxCountForSession = outboxStoreRuntime
104108
? (sessionKey: string) => {
105109
const scope = outboxStoreRuntime.resolveStoredChatOutboxScope(outboxScopeHost, sessionKey);
@@ -108,6 +112,14 @@ export function renderApplicationShell(host: ShellViewHost) {
108112
);
109113
}
110114
: EMPTY_OUTBOX_COUNT_FOR_SESSION;
115+
const hasSessionDraft = outboxStoreRuntime
116+
? (sessionKey: string) => {
117+
const scope = outboxStoreRuntime.resolveStoredChatOutboxScope(outboxScopeHost, sessionKey);
118+
return (
119+
storedDraftScopeKeys?.has(outboxStoreRuntime.storedChatOutboxScopeKey(scope)) === true
120+
);
121+
}
122+
: EMPTY_SESSION_HAS_DRAFT;
111123
const navigationSnapshot = context.navigation.snapshot;
112124
const overlaySnapshot = context.overlays.snapshot;
113125
const terminalAvailable = isTerminalAvailable(
@@ -200,6 +212,7 @@ export function renderApplicationShell(host: ShellViewHost) {
200212
connected: gatewayConnected,
201213
offline: gatewaySnapshot.offlineStable,
202214
outboxCountForSession,
215+
hasSessionDraft,
203216
terminalAvailable,
204217
catalogOpenTarget: normalizeCatalogOpenTarget(uiSettings.catalogOpenTarget),
205218
canPairDevice: gatewayConnected && (operatorAccess.canAdmin || operatorAccess.canPair),

‎ui/src/components/app-sidebar-base.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export abstract class AppSidebarBase extends OpenClawLightDomContentsElement {
2929
@property({ attribute: false }) connected = false;
3030
@property({ attribute: false }) offline = false;
3131
@property({ attribute: false }) outboxCountForSession: (sessionKey: string) => number = () => 0;
32+
@property({ attribute: false }) hasSessionDraft: (sessionKey: string) => boolean = () => false;
3233
@property({ attribute: false }) terminalAvailable = false;
3334
@property({ attribute: false }) catalogOpenTarget: CatalogOpenTarget = "viewer";
3435
@property({ attribute: false }) canPairDevice = false;

‎ui/src/components/app-sidebar-render.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ export function renderAppSidebarHomeRow(host: AppSidebarRenderHost) {
165165
const active =
166166
isSessionRouteId(host.activeRouteId) &&
167167
areUiSessionKeysEquivalent(host.getRouteSessionKey(), mainKey);
168+
const hasComposerDraft = !active && host.hasSessionDraft(mainKey);
168169
const running = mainRow?.hasActiveRun === true;
169170
const unread = mainRow?.unread === true && !active;
170171
// Home shares the sidebar's leading-slot contract: run state rings its icon
@@ -211,7 +212,7 @@ export function renderAppSidebarHomeRow(host: AppSidebarRenderHost) {
211212
>
212213
</openclaw-tooltip>`
213214
: nothing}
214-
${approvalNeeded || outboxCount > 0
215+
${approvalNeeded || outboxCount > 0 || hasComposerDraft
215216
? html`<span class="nav-item__state sidebar-home-session-states">
216217
${approvalNeeded
217218
? html`<openclaw-tooltip .content=${t("sessionsView.approvalNeeded")}>
@@ -223,7 +224,7 @@ export function renderAppSidebarHomeRow(host: AppSidebarRenderHost) {
223224
>
224225
</openclaw-tooltip>`
225226
: nothing}
226-
${renderSessionRowBadges({ hasAutomation: false, outboxCount })}
227+
${renderSessionRowBadges({ hasAutomation: false, outboxCount, hasComposerDraft })}
227228
</span>`
228229
: nothing}
229230
</a>

‎ui/src/components/app-sidebar-session-navigation-logic.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ function projectSidebarSession(
3737
runtimeSampledAtByRow: new WeakMap(),
3838
loadingChildSessionKeys: new Set(),
3939
outboxCountForSessionKey: () => 0,
40+
hasSessionDraft: () => false,
4041
resolveAttention: () => ({ kind: "none" }),
4142
resolveAgentStatusNote: () => undefined,
4243
});
@@ -263,6 +264,7 @@ it("keeps a prepared worktree session in Coding before canonical metadata arrive
263264
runtimeSampledAtByRow: new WeakMap(),
264265
loadingChildSessionKeys: new Set(),
265266
outboxCountForSessionKey: () => 0,
267+
hasSessionDraft: () => false,
266268
resolveAttention: () => ({ kind: "none" }),
267269
resolveAgentStatusNote: () => undefined,
268270
});

‎ui/src/components/app-sidebar-session-navigation-logic.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ export function buildSidebarSessionNavigationState(input: {
118118
runtimeSampledAtByRow: WeakMap<GatewaySessionRow, number>;
119119
loadingChildSessionKeys: ReadonlySet<string>;
120120
outboxCountForSessionKey: (sessionKey: string) => number;
121+
hasSessionDraft: (sessionKey: string) => boolean;
121122
resolveAttention: (row: GatewaySessionRow) => SidebarRecentSession["attention"];
122123
resolveAgentStatusNote: (row: GatewaySessionRow) => string | undefined;
123124
}): SidebarSessionNavigationState {
@@ -202,6 +203,7 @@ export function buildSidebarSessionNavigationState(input: {
202203
hasAutomation: row.hasAutomation === true,
203204
pullRequest: context?.sessions.pullRequestSummary(row.key),
204205
outboxCount: input.outboxCountForSessionKey(row.key),
206+
hasComposerDraft: input.hasSessionDraft(row.key),
205207
unread: row.archived !== true && row.unread === true,
206208
lastMessagePreview: normalizeOptionalString(row.lastMessagePreview),
207209
lastReadAt: row.lastReadAt,

‎ui/src/components/app-sidebar-session-navigation.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ export class AppSidebarSessionNavigationElement extends AppSidebarBase {
294294
runtimeSampledAtByRow: this.runtimeSampledAtByRow,
295295
loadingChildSessionKeys: this.sessionData.loadingChildSessionKeys,
296296
outboxCountForSessionKey: (sessionKey) => this.outboxCountForSessionKey(sessionKey),
297+
hasSessionDraft: (sessionKey) => this.hasSessionDraft(sessionKey),
297298
resolveAttention: (row) => this.attention.resolveSessionAttention(row),
298299
resolveAgentStatusNote: (row) => this.attention.resolveSessionAgentStatus(row)?.note,
299300
});

‎ui/src/components/app-sidebar-session-row-render.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ export function renderRecentSession(params: {
321321
></openclaw-viewer-facepile>
322322
${renderSessionRowBadges({
323323
...session,
324+
hasComposerDraft: session.hasComposerDraft === true && !session.visuallyActive,
324325
pullRequest: session.pullRequest ?? display?.pullRequest,
325326
hasApproval: sessionHasPendingApproval(
326327
host.sessionData.approvalBadgeSnapshot(),

‎ui/src/components/app-sidebar-session-types.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export type SidebarRecentSession = {
8787
hasAutomation: boolean;
8888
pullRequest?: SessionCatalogPullRequestSummary;
8989
outboxCount?: number;
90+
hasComposerDraft?: boolean;
9091
unread: boolean;
9192
lastMessagePreview?: string;
9293
lastReadAt?: number;

‎ui/src/components/session-row-badges.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export function renderSessionRowBadges(params: {
6060
pullRequest?: SessionCatalogPullRequestSummary;
6161
hasApproval?: boolean;
6262
outboxCount?: number;
63+
hasComposerDraft?: boolean;
6364
placementState?: SessionPlacementState;
6465
workspaceConflictCount?: number;
6566
}) {
@@ -90,6 +91,7 @@ export function renderSessionRowBadges(params: {
9091
!pullRequestLabel &&
9192
!params.hasApproval &&
9293
outboxCount === 0 &&
94+
!params.hasComposerDraft &&
9395
!displayedPlacementState &&
9496
!hasWorkspaceConflict
9597
) {
@@ -145,6 +147,13 @@ export function renderSessionRowBadges(params: {
145147
${outboxCount > 0
146148
? renderSessionRowBadge(outboxLabel, icons.clock, "session-row-badge--queued", outboxCount)
147149
: nothing}
150+
${params.hasComposerDraft
151+
? renderSessionRowBadge(
152+
t("sessionsView.unsentDraft"),
153+
icons.pencil,
154+
"session-row-badge--draft",
155+
)
156+
: nothing}
148157
${displayedPlacementState || hasWorkspaceConflict
149158
? renderSessionRowBadge(
150159
cloudLabel,

0 commit comments

Comments
 (0)