Skip to content

Commit 703db47

Browse files
committed
fix(app): stabilize Side bar projects and background Shell activity
1 parent 6d53576 commit 703db47

17 files changed

Lines changed: 890 additions & 302 deletions

File tree

‎packages/app/e2e/regression/home.spec.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,9 @@ test("a server whose saved password changes works with the new password", async
349349
await remote.getByRole("button", { name: "More options", exact: true }).click()
350350
await page.getByRole("menuitem", { name: "Edit", exact: true }).click()
351351
const editor = page.getByRole("dialog", { name: "Edit server" })
352-
await editor.getByPlaceholder("password").fill("new-password")
353-
// The server now rejects the old password, as after `opencode service set password`.
352+
// Rotate first: typing previews the new credentials, and Save reuses that health check.
354353
accepted.password = "new-password"
354+
await editor.getByPlaceholder("password").fill("new-password")
355355
await editor.getByRole("button", { name: "Save", exact: true }).click()
356356
await expect(editor).toHaveCount(0)
357357

‎packages/app/e2e/regression/tabs.spec.ts‎

Lines changed: 426 additions & 51 deletions
Large diffs are not rendered by default.

‎packages/app/src/home/sessions/queries.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export function createSessionIndexes(connections: Accessor<{ conn: ServerConnect
6060
}))
6161

6262
createEffect(() => {
63-
connections().forEach((item) => {
63+
connections().forEach((item, index) => {
6464
onCleanup(
6565
item.ctx.data.on("session.deleted", (event) => {
6666
queryClient.setQueryData<SessionInfo[]>(["home-sessions", item.conn], (current) =>
@@ -71,6 +71,14 @@ export function createSessionIndexes(connections: Accessor<{ conn: ServerConnect
7171
)
7272
}),
7373
)
74+
// A collapsed history row may only have an index snapshot; Data does not refresh unloaded sessions on view.
75+
onCleanup(
76+
item.ctx.data.on("session.viewed", (event) => {
77+
const id = event.data.sessionID
78+
if (item.ctx.data.session.get(id) || !queries[index]?.data?.()?.some((session) => session.id === id)) return
79+
void item.ctx.data.session.sync(id).catch(() => undefined)
80+
}),
81+
)
7482
})
7583
})
7684

‎packages/app/src/runtime/i18n/en.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,11 +767,16 @@ export const dict = {
767767
"sidebar.grouping.project": "By project",
768768
"sidebar.grouping.other": "Other sessions",
769769
"sidebar.recent.title": "Recent sessions",
770+
"sidebar.pinned.title": "Pinned projects",
771+
"sidebar.draft.unsent": "Draft (unsent)",
770772
"sidebar.session.branch": "Branch: {{branch}}",
771773
"sidebar.session.worktree": "Worktree: {{path}}",
772774
"sidebar.project.newSession": "New session in {{project}}",
773775
"sidebar.project.expand": "Expand project {{project}}",
774776
"sidebar.project.collapse": "Collapse project {{project}}",
777+
"sidebar.project.pin": "Pin project {{project}}",
778+
"sidebar.project.unpin": "Unpin project {{project}}",
779+
"sidebar.project.unread": "Unread sessions",
775780
"sidebar.recent.hide": "Hide from recent sessions",
776781
"sidebar.recent.more.one": "More ({{count}})",
777782
"sidebar.recent.more.other": "More ({{count}})",
@@ -784,6 +789,9 @@ export const dict = {
784789
"sidebar.session.lastRun": "Last run ended: {{time}}",
785790
"sidebar.running.title": "Running sessions",
786791
"sidebar.running.empty": "No running sessions",
792+
"sidebar.running.background": "Background work",
793+
"sidebar.running.shells.one": "{{count}} background shell",
794+
"sidebar.running.shells.other": "{{count}} background shells",
787795
"sidebar.running.disconnected": "Some servers are disconnected",
788796
"sidebar.running.count.one": "{{count}} running session",
789797
"sidebar.running.count.other": "{{count}} running sessions",

‎packages/app/src/runtime/server/runtime.tsx‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,15 @@ function createServerController(
227227
remove: (sessionID) => sdk.api.session.remove({ sessionID }),
228228
})
229229

230-
// The active index can arrive before session metadata. Load missing ancestors so a
230+
// Execution and collected Shell activity can arrive before session metadata. Load missing ancestors so a
231231
// descendant still keeps its root busy after reconnecting, without reading transcripts.
232232
createEffect(() => {
233-
new Set(data.session.active().map((id) => data.session.root(id))).forEach((id) => {
234-
if (data.session.get(id)) return
235-
void data.session.sync(id).catch(() => undefined)
236-
})
233+
new Set([...data.session.active(), ...data.shell.activeSessions()].map((id) => data.session.root(id))).forEach(
234+
(id) => {
235+
if (data.session.get(id)) return
236+
void data.session.sync(id).catch(() => undefined)
237+
},
238+
)
237239
})
238240

239241
// Transcripts otherwise stay loaded for every session this window ever opened. Open tabs and the three most

‎packages/app/src/session/header/session-working-indicator.tsx‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,27 @@ import { createStore } from "solid-js/store"
44
import { createAnimatedPresence } from "@/runtime/animated-presence"
55
import { useLanguage } from "@/runtime/i18n/language"
66
import { useServer } from "@/runtime/server/current"
7+
import { sessionBackgroundShells } from "@/shell/layout/project-avatar-state"
78

89
export function SessionWorkingIndicator(props: { sessionID?: string }) {
910
const language = useLanguage()
1011
const server = useServer()
1112
const [elements, setElements] = createStore<{ indicator?: HTMLSpanElement }>({})
13+
const background = () => {
14+
const id = props.sessionID
15+
return (
16+
!!id &&
17+
server.ctx.data.session.status(id) !== "running" &&
18+
sessionBackgroundShells(server.ctx.data, id, true).length > 0
19+
)
20+
}
1221

1322
const presence = createAnimatedPresence(
1423
() => {
1524
const id = props.sessionID
1625

17-
return id && server.ctx.data.session.get(id)?.parentID && server.ctx.data.session.status(id) === "running"
26+
return background() ||
27+
(id && server.ctx.data.session.get(id)?.parentID && server.ctx.data.session.status(id) === "running")
1828
? true
1929
: undefined
2030
},
@@ -27,7 +37,8 @@ export function SessionWorkingIndicator(props: { sessionID?: string }) {
2737
<span
2838
ref={(element) => setElements("indicator", element)}
2939
role="status"
30-
aria-label={language.t("session.timeline.working")}
40+
aria-label={language.t(background() ? "sidebar.running.background" : "session.timeline.working")}
41+
title={language.t(background() ? "sidebar.running.background" : "session.timeline.working")}
3142
data-visible={presence.show()}
3243
// Cancel the header's 2px gap at the end of the collapse so unmounting doesn't nudge the title.
3344
class="ms-1 me-0.5 flex h-4 w-4 shrink-0 items-center justify-center overflow-hidden text-v2-icon-icon-muted duration-200 ease-out data-[visible=false]:ms-0 data-[visible=false]:-me-0.5 data-[visible=false]:w-0 data-[visible=false]:opacity-0 motion-reduce:animate-none motion-reduce:transition-none"

‎packages/app/src/session/timeline/message-timeline.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,10 +576,10 @@ function MessageTimelineView(
576576
</Show>
577577
)}
578578
>
579+
<SessionWorkingIndicator sessionID={sessionID()} />
579580
<Show when={parentID() && childTitle()}>
580581
{(value) => (
581582
<>
582-
<SessionWorkingIndicator sessionID={sessionID()} />
583583
<h1
584584
data-slot="session-title-child"
585585
dir="auto"

‎packages/app/src/shell/layout/project-avatar-state.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ export function sessionRequests(data: ServerData, sessionId: string, root: boole
7070
export function sessionBusy(data: ServerData, sessionId: string) {
7171
return (
7272
data.session.status(sessionId) === "running" ||
73+
sessionBackgroundShells(data, sessionId).length > 0 ||
7374
data.session.pending.list(sessionId).some((item) => item.type !== "synthetic")
7475
)
7576
}
77+
78+
export function sessionBackgroundShells(data: ServerData, sessionID: string, family = false) {
79+
return (family ? [sessionID, ...data.session.family(sessionID)] : [sessionID])
80+
.flatMap((id) => data.shell.listBySession(id))
81+
.filter((shell) => shell.status === "running")
82+
}

‎packages/app/src/shell/titlebar/active-sessions.css‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
flex: none;
44
min-height: 0;
55
flex-direction: column;
6-
padding-block-end: 8px;
7-
margin-block-end: 8px;
8-
border-bottom: 1px solid var(--v2-border-border-muted);
6+
padding-block-start: 8px;
7+
margin-block-start: 8px;
8+
border-top: 1px solid var(--v2-border-border-muted);
99

1010
[data-slot="active-sessions-header"] {
1111
display: flex;
@@ -21,7 +21,8 @@
2121

2222
[data-slot="active-sessions-list"] {
2323
min-height: 0;
24-
max-height: min(288px, 40dvh);
24+
/* Five 36px rows, while preserving project navigation in short windows. */
25+
max-height: min(180px, 30dvh);
2526
overflow-y: auto;
2627
overscroll-behavior: contain;
2728
}

‎packages/app/src/shell/titlebar/active-sessions.tsx‎

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { useLanguage } from "@/runtime/i18n/language"
77
import { ServerConnection, serverName } from "@/runtime/server/registry"
88
import { useGlobal } from "@/runtime/server/runtime"
99
import { projectSettingsKey, useSettings } from "@/settings/model"
10-
import { sessionRequests } from "@/shell/layout/project-avatar-state"
10+
import { sessionBackgroundShells, sessionRequests } from "@/shell/layout/project-avatar-state"
1111
import { useLayout } from "@/shell/state/layout"
1212
import { useTabs } from "@/shell/tabs/tabs"
1313
import { sessionLastRunLabel, sessionTabTitle } from "./tab-title"
@@ -16,7 +16,7 @@ import { createSessionBranches } from "./session-branches"
1616
import { pathKey } from "@/workspaces/path-key"
1717
import "./active-sessions.css"
1818

19-
/** The server-wide active index includes running sessions without an open tab, including child sessions. */
19+
/** Execution and collected Shell activity include sessions without an open tab, including child sessions. */
2020
export function ActiveSessions() {
2121
const global = useGlobal()
2222
const language = useLanguage()
@@ -37,7 +37,7 @@ export function ActiveSessions() {
3737

3838
if (!ctx || ctx.sdk.connection.status() !== "connected") return []
3939

40-
return ctx.data.session.active().map((id) => ({
40+
return [...new Set([...ctx.data.session.active(), ...ctx.data.shell.activeSessions()])].map((id) => ({
4141
key: JSON.stringify([ServerConnection.key(item.conn), id]),
4242
id,
4343
server: ServerConnection.key(item.conn),
@@ -117,8 +117,19 @@ export function ActiveSessions() {
117117
}
118118
const duration = () => {
119119
const value = session()
120-
return value ? workingDuration(value, clock.now, language) : undefined
120+
const starts = [
121+
...(entry().ctx.data.session.status(entry().id) === "running" ? [value?.time.busy ?? 0] : []),
122+
...shells().map((shell) => shell.time.started),
123+
].filter((time) => time > 0)
124+
return starts.length
125+
? workingDuration({ time: { busy: Math.min(...starts) } }, clock.now, language)
126+
: undefined
121127
}
128+
const shells = () => sessionBackgroundShells(entry().ctx.data, entry().id)
129+
const background = () =>
130+
entry().ctx.data.session.status(entry().id) !== "running" && shells().length > 0
131+
const summary = () =>
132+
shells().length ? language.plural("sidebar.running.shells", shells().length) : undefined
122133

123134
const status = createMemo(() => {
124135
const value = entry()
@@ -155,6 +166,8 @@ export function ActiveSessions() {
155166
branch(),
156167
session()?.location.directory,
157168
sessionLastRunLabel(session()?.time, language),
169+
summary(),
170+
...shells().map((shell) => shell.command),
158171
]
159172
.filter(Boolean)
160173
.join("\n")}
@@ -185,7 +198,13 @@ export function ActiveSessions() {
185198
: language.t(`sidebar.inbox.status.${status()}`)
186199
}
187200
>
188-
<span class="sr-only">{language.t(`sidebar.inbox.status.${status()}`)}</span>
201+
<span class="sr-only">
202+
{language.t(
203+
background() && status() === "working"
204+
? "sidebar.running.background"
205+
: `sidebar.inbox.status.${status()}`,
206+
)}
207+
</span>
189208
<span aria-hidden="true">
190209
{status() === "working"
191210
? (duration() ?? language.t("sidebar.inbox.status.working"))
@@ -196,6 +215,12 @@ export function ActiveSessions() {
196215
<Show when={project()} fallback={language.t("common.loading")}>
197216
<span class="min-w-0 truncate">{projectName()}</span>
198217
</Show>
218+
<Show when={background()}>
219+
<span aria-hidden="true">·</span>
220+
<span class="truncate" title={summary()}>
221+
{language.t("sidebar.running.background")}
222+
</span>
223+
</Show>
199224
<Show when={branch() || worktree()}>
200225
<span aria-hidden="true">·</span>
201226
<span class="flex min-w-0 items-center gap-1">

0 commit comments

Comments
 (0)