mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-18 15:28:48 +03:00
refactor(app): remove the experimental inbox Home page (#59096)
This commit is contained in:
committed by
GitHub
Unverified
parent
4b83402a29
commit
4703b46cdf
@@ -17,29 +17,16 @@ async function openHome(page: Page, input: Parameters<typeof mockStressTimeline>
|
||||
await page.goto("/")
|
||||
}
|
||||
|
||||
test("Home uses the session list for tabs and the session inbox only when selected in Settings", async ({ page }) => {
|
||||
const replies: { sessionID: string; permissionID: string; body: unknown }[] = []
|
||||
const waiting = { id: "ses_home_waiting", title: "Waiting on approval" }
|
||||
test("Home keeps the session list in every interface mode", async ({ page }) => {
|
||||
const earlier = { id: "ses_home_earlier", title: "Finished earlier" }
|
||||
await mockWorkspace(page, {
|
||||
name: "Home",
|
||||
sessions: [earlier, waiting],
|
||||
sessionStatus: { [waiting.id]: { type: "running" } },
|
||||
sessionPermissions: {
|
||||
[waiting.id]: [
|
||||
{ id: "per_home", sessionID: waiting.id, action: "shell", resources: ["git status"], metadata: {}, save: [] },
|
||||
],
|
||||
},
|
||||
onPermissionReply: (reply) => replies.push(reply),
|
||||
})
|
||||
await mockWorkspace(page, { name: "Home", sessions: [earlier] })
|
||||
await page.goto("/")
|
||||
const search = page.getByRole("textbox", { name: /Search sessions/ })
|
||||
const inbox = page.locator('[data-slot="start-row"]')
|
||||
await expect(search).toBeVisible()
|
||||
await expect(row(page, earlier.title)).toBeVisible()
|
||||
await expect(inbox).toHaveCount(0)
|
||||
|
||||
for (const mode of ["Side tabs", "Inbox", "Top tabs", "Inbox"]) {
|
||||
// The Inbox mode moves session tabs into the sidebar inbox; Home stays the session list.
|
||||
for (const mode of ["Side tabs", "Inbox", "Top tabs"]) {
|
||||
await page.keyboard.press("Control+,")
|
||||
const settings = page.getByTestId("settings-screen")
|
||||
const option = settings.getByRole("radio", { name: mode, exact: true })
|
||||
@@ -47,31 +34,9 @@ test("Home uses the session list for tabs and the session inbox only when select
|
||||
await expect(option).toBeChecked()
|
||||
await settings.getByRole("button", { name: "Back to app", exact: true }).click()
|
||||
await expect(page).toHaveURL("/")
|
||||
|
||||
if (mode === "Inbox") {
|
||||
await expect(inbox.filter({ hasText: earlier.title })).toHaveAttribute("data-status", "ready")
|
||||
await expect(search).toHaveCount(0)
|
||||
await expect(row(page, earlier.title)).toHaveCount(0)
|
||||
continue
|
||||
}
|
||||
|
||||
await expect(search).toBeVisible()
|
||||
await expect(row(page, earlier.title)).toBeVisible()
|
||||
await expect(inbox).toHaveCount(0)
|
||||
}
|
||||
|
||||
await page.reload()
|
||||
const approval = inbox.filter({ hasText: waiting.title })
|
||||
await expect(approval).toHaveAttribute("data-status", "approval")
|
||||
await expect(approval).toContainText("git status")
|
||||
await expect(search).toHaveCount(0)
|
||||
await approval.getByRole("button", { name: "Allow", exact: true }).click()
|
||||
await expect
|
||||
.poll(() => replies)
|
||||
.toEqual([{ sessionID: waiting.id, permissionID: "per_home", body: { decision: "once" } }])
|
||||
await expect(approval).toHaveAttribute("data-status", "working")
|
||||
await inbox.filter({ hasText: earlier.title }).click()
|
||||
await expectPath(page, sessionHref(earlier.id))
|
||||
})
|
||||
|
||||
test("the session context menu renames, exports, and deletes a Home session", async ({ page }) => {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { ScrollView } from "@opencode/ui/scroll-view"
|
||||
import { createMediaQuery } from "@solid-primitives/media"
|
||||
import { Show } from "solid-js"
|
||||
import { useSettings } from "@/settings/model"
|
||||
import { createHomeController } from "./model"
|
||||
import { createHomeProjectsController } from "./projects/controller"
|
||||
import { HomeUtilityNav } from "./projects/view"
|
||||
@@ -10,19 +9,8 @@ import { createHomeScrollController } from "./scroll"
|
||||
import { createHomeSessionSearchController } from "./sessions/search"
|
||||
import { createHomeSessionsController } from "./sessions/controller"
|
||||
import { HomeSessions } from "./sessions/region"
|
||||
import { StartHome } from "./start/start"
|
||||
|
||||
export function Home() {
|
||||
const settings = useSettings()
|
||||
|
||||
return (
|
||||
<Show when={settings.appearance.tabLayout() === "inbox"} fallback={<SessionHome />}>
|
||||
<StartHome />
|
||||
</Show>
|
||||
)
|
||||
}
|
||||
|
||||
function SessionHome() {
|
||||
const mobile = createMediaQuery("(max-width: 767px)")
|
||||
const home = createHomeController()
|
||||
const projects = createHomeProjectsController(home)
|
||||
|
||||
@@ -1,150 +0,0 @@
|
||||
import { createEffect, createMemo, startTransition } from "solid-js"
|
||||
import { useGlobal } from "@/runtime/server/runtime"
|
||||
import { ServerConnection, useServers } from "@/runtime/server/registry"
|
||||
import type { Project } from "@/runtime/server/types"
|
||||
import { useCommand } from "@/shell/commands/command"
|
||||
import { useTabs } from "@/shell/tabs/tabs"
|
||||
import { createSessionInbox, inboxArchived, type InboxEntry } from "@/shell/titlebar/inbox-model"
|
||||
import { pathKey } from "@/workspaces/path-key"
|
||||
|
||||
const EARLIER_LIMIT = 8
|
||||
|
||||
const PROJECT_LIMIT = 10
|
||||
|
||||
export type StartProject = {
|
||||
key: string
|
||||
project: Project
|
||||
waiting: number
|
||||
running: number
|
||||
entries: InboxEntry[]
|
||||
}
|
||||
|
||||
export type StartServer = {
|
||||
key: ServerConnection.Key
|
||||
conn: ServerConnection.Any
|
||||
projects: StartProject[]
|
||||
}
|
||||
|
||||
/**
|
||||
* Home: sessions on every connected server, sorted by what they need from you, and each server's recent projects.
|
||||
* Needs you holds sessions the agent cannot continue without you: an approval, a question, or a failed run.
|
||||
*/
|
||||
export function createStartModel() {
|
||||
const global = useGlobal()
|
||||
const servers = useServers()
|
||||
const tabs = useTabs()
|
||||
const command = useCommand()
|
||||
const inbox = createSessionInbox()
|
||||
|
||||
const live = createMemo(() => inbox.entries().filter((entry) => !inboxArchived(entry)))
|
||||
const byIdle = (a: InboxEntry, b: InboxEntry) => (b.session.time.idle ?? 0) - (a.session.time.idle ?? 0)
|
||||
|
||||
const groups = createMemo(() => {
|
||||
const list = live()
|
||||
|
||||
return {
|
||||
needs: [
|
||||
...list.filter((entry) => entry.status === "approval" || entry.status === "input"),
|
||||
...list.filter((entry) => entry.status === "failed").toSorted(byIdle),
|
||||
],
|
||||
done: list.filter((entry) => entry.status === "done").toSorted(byIdle),
|
||||
working: list.filter((entry) => entry.status === "working"),
|
||||
earlier: list.filter((entry) => entry.status === "ready").slice(0, EARLIER_LIMIT),
|
||||
}
|
||||
})
|
||||
|
||||
const projectOf = (entry: InboxEntry) =>
|
||||
entry.ctx.projects.forSession(entry.session)?.worktree ?? entry.session.location.directory
|
||||
|
||||
// This computer first, then other servers in the order they were added.
|
||||
const ordered = createMemo(() =>
|
||||
servers.visible.toSorted((a, b) => Number(servers.current(b)) - Number(servers.current(a))),
|
||||
)
|
||||
|
||||
// Each server's projects, most recently active first. Projects are added on the server, so Home only lists them.
|
||||
const projectServers = createMemo(() =>
|
||||
ordered()
|
||||
.map((conn): StartServer => {
|
||||
const key = ServerConnection.key(conn)
|
||||
|
||||
return {
|
||||
key,
|
||||
conn,
|
||||
projects: global
|
||||
.ensureServerCtx(conn)
|
||||
.projects.unique()
|
||||
.map((project): StartProject => {
|
||||
const entries = live().filter(
|
||||
(entry) => entry.server === key && pathKey(projectOf(entry)) === pathKey(project.worktree),
|
||||
)
|
||||
|
||||
return {
|
||||
key: `${key}\0${pathKey(project.worktree)}`,
|
||||
project,
|
||||
waiting: entries.filter((entry) => entry.status === "approval" || entry.status === "input").length,
|
||||
running: entries.filter((entry) => entry.status === "working").length,
|
||||
entries,
|
||||
}
|
||||
})
|
||||
.toSorted((a, b) => activity(b) - activity(a))
|
||||
.slice(0, PROJECT_LIMIT),
|
||||
}
|
||||
})
|
||||
.filter((server) => server.projects.length > 0),
|
||||
)
|
||||
|
||||
// A server that does not answer contributes no sessions; say so instead of showing a shorter list.
|
||||
const unreachable = createMemo(() =>
|
||||
ordered().filter((conn) => {
|
||||
const health = global.servers.health[ServerConnection.key(conn)]
|
||||
|
||||
return !!health && !health.checking && !health.healthy
|
||||
}),
|
||||
)
|
||||
|
||||
// The account this computer's server runs as is the best name the app has for the person.
|
||||
const health = () => {
|
||||
const conn = ordered()[0]
|
||||
|
||||
return conn ? global.servers.health[ServerConnection.key(conn)] : undefined
|
||||
}
|
||||
|
||||
const name = createMemo(() => {
|
||||
const account = health()?.username
|
||||
|
||||
return account ? account.charAt(0).toUpperCase() + account.slice(1) : undefined
|
||||
})
|
||||
|
||||
// The client only refreshes `time.idle` for loaded sessions when a run ends, so load every working one.
|
||||
createEffect(() => {
|
||||
groups().working.forEach((entry) => {
|
||||
if (entry.ctx.data.session.get(entry.session.id)) return
|
||||
void entry.ctx.data.session.sync(entry.session.id).catch(() => undefined)
|
||||
})
|
||||
})
|
||||
|
||||
return {
|
||||
inbox,
|
||||
groups,
|
||||
projectServers,
|
||||
unreachable,
|
||||
name,
|
||||
/** The greeting waits for the first health check, so the name never pops in after it. */
|
||||
greeted: () => !!health() && !health()?.checking,
|
||||
loading: inbox.loading,
|
||||
newSession: () => command.trigger("tab.new"),
|
||||
openProject: (server: StartServer, item: StartProject) => {
|
||||
global.ensureServerCtx(server.conn).projects.touch(item.project.worktree)
|
||||
void startTransition(() => {
|
||||
void tabs.newDraft({ server: server.key, directory: item.project.worktree })
|
||||
})
|
||||
},
|
||||
markAllViewed: () => groups().done.forEach(inbox.markViewed),
|
||||
}
|
||||
}
|
||||
|
||||
export type StartModel = ReturnType<typeof createStartModel>
|
||||
|
||||
function activity(item: StartProject) {
|
||||
return Math.max(item.project.time.active, ...item.entries.map((entry) => entry.session.time.updated))
|
||||
}
|
||||
@@ -1,602 +0,0 @@
|
||||
import { Button } from "@opencode/ui/button"
|
||||
import { Icon } from "@opencode/ui/icon"
|
||||
import { IconButton } from "@opencode/ui/icon-button"
|
||||
import { Keybind } from "@opencode/ui/keybind"
|
||||
import {
|
||||
displayName,
|
||||
getProjectAvatarGenerated,
|
||||
getProjectAvatarSource,
|
||||
getProjectAvatarVariant,
|
||||
ProjectAvatar,
|
||||
} from "@opencode/ui/project-avatar"
|
||||
import { TextShimmer } from "@opencode/ui/text-shimmer"
|
||||
import { Tooltip } from "@opencode/ui/tooltip"
|
||||
import { createEffect, createMemo, For, Match, Show, Switch, type JSX } from "solid-js"
|
||||
import { useLanguage } from "@/runtime/i18n/language"
|
||||
import { useGlobal } from "@/runtime/server/runtime"
|
||||
import { ServerConnection, useServers } from "@/runtime/server/registry"
|
||||
import { useSettingsCommand } from "@/settings/command"
|
||||
import { useSettingsSurface } from "@/settings/surface"
|
||||
import { usePlatform } from "@/runtime/platform/platform"
|
||||
import { useCommand } from "@/shell/commands/command"
|
||||
import { SessionTabAvatarView } from "@/shell/layout/session-tab-avatar"
|
||||
import { sessionTabTitle } from "@/shell/titlebar/tab-title"
|
||||
import type { InboxEntry } from "@/shell/titlebar/inbox-model"
|
||||
import { createStartModel, type StartModel, type StartServer } from "./model"
|
||||
|
||||
type Language = ReturnType<typeof useLanguage>
|
||||
|
||||
/** Home: a greeting, every session sorted by what it needs from you, and recent projects beside them. */
|
||||
export function StartHome() {
|
||||
const model = createStartModel()
|
||||
// Settings opens from Home like from a session; the palette is the shell's.
|
||||
useSettingsCommand()
|
||||
|
||||
return (
|
||||
<div
|
||||
data-slot="home-panel"
|
||||
class="@container mx-[var(--shell-inline-inset,8px)] mb-[var(--shell-bottom-inset,8px)] mt-[var(--shell-top-inset,8px)] flex min-h-0 flex-1 flex-col self-stretch overflow-hidden rounded-[10px] bg-v2-background-bg-base shadow-[var(--v2-elevation-raised)]"
|
||||
>
|
||||
<div class="min-h-0 flex-1 overflow-y-auto">
|
||||
<div class="mx-auto grid w-full max-w-[1240px] grid-cols-[minmax(0,880px)] justify-center gap-10 px-6 pb-16 pt-[max(48px,9vh)] @[1180px]:grid-cols-[minmax(0,880px)_240px]">
|
||||
<div class="flex min-w-0 flex-col gap-8">
|
||||
<StartGreeting model={model} />
|
||||
<StartUnreachable model={model} />
|
||||
<StartSections model={model} />
|
||||
</div>
|
||||
<aside class="hidden @[1180px]:block">
|
||||
<div class="sticky top-0 pt-[68px]">
|
||||
<StartProjects model={model} />
|
||||
</div>
|
||||
</aside>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function StartGreeting(props: { model: StartModel }) {
|
||||
const language = useLanguage()
|
||||
const command = useCommand()
|
||||
const platform = usePlatform()
|
||||
const groups = props.model.groups
|
||||
const hour = () => new Date(props.model.inbox.now()).getHours()
|
||||
const period = () => (hour() < 12 ? "morning" : hour() < 18 ? "afternoon" : "evening")
|
||||
|
||||
const greeting = () => {
|
||||
const name = props.model.name()
|
||||
|
||||
return name ? language.t(`start.greeting.${period()}.named`, { name }) : language.t(`start.greeting.${period()}`)
|
||||
}
|
||||
|
||||
// Each count is its own complete phrase, so locales never assemble a sentence from fragments.
|
||||
const summary = createMemo(() =>
|
||||
[
|
||||
groups().needs.length > 0 ? language.plural("start.summary.needsYou", groups().needs.length) : undefined,
|
||||
groups().working.length > 0 ? language.plural("start.summary.running", groups().working.length) : undefined,
|
||||
groups().done.length > 0 ? language.plural("start.summary.done", groups().done.length) : undefined,
|
||||
].filter((item) => item !== undefined),
|
||||
)
|
||||
|
||||
return (
|
||||
<div class="flex items-end justify-between gap-4 px-2">
|
||||
{/* Both lines keep their height while they wait, so nothing below moves when they fill in. */}
|
||||
<div class="min-w-0">
|
||||
<h1
|
||||
class="truncate text-[20px] font-medium leading-7 text-v2-text-text-base transition-opacity duration-200"
|
||||
classList={{ "opacity-0": !props.model.greeted() }}
|
||||
>
|
||||
{greeting()}
|
||||
</h1>
|
||||
<p class="flex h-5 items-center truncate text-[13px] leading-5 text-v2-text-text-muted">
|
||||
<Show when={!props.model.loading()} fallback={<Bar class="w-44" />}>
|
||||
<Show when={summary().length > 0} fallback={language.t("start.caughtUp")}>
|
||||
{summary().join(" · ")}
|
||||
</Show>
|
||||
</Show>
|
||||
</p>
|
||||
</div>
|
||||
<div class="flex shrink-0 items-center gap-1">
|
||||
<Tooltip placement="bottom" value={language.t("sidebar.help")}>
|
||||
<IconButton
|
||||
variant="ghost-muted"
|
||||
size="large"
|
||||
aria-label={language.t("sidebar.help")}
|
||||
icon={<Icon name="help" />}
|
||||
onClick={() => platform.openExternal("https://opencode.ai/desktop-feedback")}
|
||||
/>
|
||||
</Tooltip>
|
||||
<Tooltip
|
||||
placement="bottom"
|
||||
value={
|
||||
<>
|
||||
{language.t("sidebar.settings")}
|
||||
<Show when={command.keybindParts("settings.open").length > 0}>
|
||||
<Keybind keys={command.keybindParts("settings.open")} variant="neutral" />
|
||||
</Show>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<IconButton
|
||||
variant="ghost-muted"
|
||||
size="large"
|
||||
aria-label={language.t("sidebar.settings")}
|
||||
icon={<Icon name="settings-gear" />}
|
||||
onClick={() => command.trigger("settings.open")}
|
||||
/>
|
||||
</Tooltip>
|
||||
<Tooltip
|
||||
placement="bottom"
|
||||
value={
|
||||
<>
|
||||
{language.t("command.session.new")}
|
||||
<Show when={command.keybindParts("tab.new").length > 0}>
|
||||
<Keybind keys={command.keybindParts("tab.new")} variant="neutral" />
|
||||
</Show>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<Button variant="neutral" icon="plus" class="ms-1" onClick={props.model.newSession}>
|
||||
{language.t("command.session.new")}
|
||||
</Button>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/** Servers that do not answer leave their sessions out of every list, so each gets a line saying so. */
|
||||
function StartUnreachable(props: { model: StartModel }) {
|
||||
const language = useLanguage()
|
||||
const servers = useServers()
|
||||
const global = useGlobal()
|
||||
const settings = useSettingsSurface()
|
||||
|
||||
return (
|
||||
<Show when={props.model.unreachable().length > 0}>
|
||||
<div class="flex flex-col gap-1">
|
||||
<For each={props.model.unreachable()}>
|
||||
{(conn) => (
|
||||
<div class="flex h-9 items-center gap-3 rounded-[8px] bg-v2-background-bg-layer-01 pe-1.5 ps-2 text-[13px] leading-4">
|
||||
<span class="flex size-4 shrink-0 items-center justify-center">
|
||||
<Icon name="server" size="small" class="text-v2-icon-icon-muted" />
|
||||
</span>
|
||||
<span class="min-w-0 flex-1 truncate text-v2-text-text-muted">
|
||||
{language.t(
|
||||
global.servers.health[ServerConnection.key(conn)]?.unauthorized
|
||||
? "start.server.unauthorized"
|
||||
: "start.server.unreachable",
|
||||
{ server: servers.label(conn) },
|
||||
)}
|
||||
</span>
|
||||
<Button
|
||||
size="small"
|
||||
variant="ghost-muted"
|
||||
onClick={() => settings.openServers(ServerConnection.key(conn))}
|
||||
>
|
||||
{language.t("start.server.manage")}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</For>
|
||||
</div>
|
||||
</Show>
|
||||
)
|
||||
}
|
||||
|
||||
/** Needs you, then results waiting to be read, then work in flight, then everything already read. */
|
||||
function StartSections(props: { model: StartModel }) {
|
||||
const language = useLanguage()
|
||||
const groups = props.model.groups
|
||||
|
||||
createEffect(() =>
|
||||
props.model.inbox.loadBranches([...groups().needs, ...groups().done, ...groups().working, ...groups().earlier]),
|
||||
)
|
||||
|
||||
return (
|
||||
<Show when={!props.model.loading()} fallback={<Skeleton />}>
|
||||
<div class="flex flex-col gap-6">
|
||||
<Show when={groups().needs.length > 0} fallback={<InboxZero />}>
|
||||
<Section title={language.t("start.section.needsYou")} count={groups().needs.length} icon="warning">
|
||||
<For each={groups().needs}>{(entry) => <StartRow model={props.model} entry={entry} />}</For>
|
||||
</Section>
|
||||
</Show>
|
||||
<Show when={groups().done.length > 0}>
|
||||
<Section
|
||||
title={language.t("start.section.done")}
|
||||
count={groups().done.length}
|
||||
icon="circle-check"
|
||||
action={
|
||||
<Button size="small" variant="ghost-muted" onClick={props.model.markAllViewed}>
|
||||
{language.t("start.markAllRead")}
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
<For each={groups().done}>{(entry) => <StartRow model={props.model} entry={entry} />}</For>
|
||||
</Section>
|
||||
</Show>
|
||||
<Show when={groups().working.length > 0}>
|
||||
<Section title={language.t("start.section.running")} count={groups().working.length} icon="status-active">
|
||||
<For each={groups().working}>{(entry) => <StartRow model={props.model} entry={entry} />}</For>
|
||||
</Section>
|
||||
</Show>
|
||||
<Show when={groups().earlier.length > 0}>
|
||||
<Section title={language.t("start.section.earlier")} icon="reset">
|
||||
<For each={groups().earlier}>{(entry) => <StartRow model={props.model} entry={entry} />}</For>
|
||||
</Section>
|
||||
</Show>
|
||||
</div>
|
||||
</Show>
|
||||
)
|
||||
}
|
||||
|
||||
/** Row-shaped placeholders while the first load settles; claiming inbox zero before then would be wrong. */
|
||||
function Skeleton() {
|
||||
return (
|
||||
<div class="flex flex-col gap-1" aria-hidden="true">
|
||||
<div class="flex h-7 items-center gap-3 px-2">
|
||||
<span class="size-4 shrink-0" />
|
||||
<Bar class="w-20" />
|
||||
</div>
|
||||
<For each={[56, 44, 64, 38]}>
|
||||
{(width) => (
|
||||
<div class="flex h-12 items-center gap-3 px-2">
|
||||
<span class="size-4 shrink-0 animate-pulse rounded-[4px] bg-v2-background-bg-layer-03" />
|
||||
<div class="flex min-w-0 flex-1 flex-col gap-1.5">
|
||||
<Bar style={{ width: `${width}%` }} />
|
||||
<Bar class="w-28" />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</For>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function Bar(props: { class?: string; style?: JSX.CSSProperties }) {
|
||||
return (
|
||||
<span
|
||||
class={`block h-2.5 max-w-full animate-pulse rounded-full bg-v2-background-bg-layer-03 ${props.class ?? ""}`}
|
||||
style={props.style}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
/** Recent projects per server. Choosing one starts a session there; projects are added on the server, not here. */
|
||||
function StartProjects(props: { model: StartModel }) {
|
||||
const language = useLanguage()
|
||||
const servers = useServers()
|
||||
const several = () => props.model.projectServers().length > 1
|
||||
|
||||
return (
|
||||
<div class="flex flex-col gap-4">
|
||||
<For each={props.model.projectServers()}>
|
||||
{(server, index) => (
|
||||
<div class="flex flex-col gap-1">
|
||||
<div class="flex h-7 items-center gap-1.5 px-2 text-[12px] leading-4 font-medium text-v2-text-text-muted">
|
||||
<Show when={several()} fallback={language.t("start.projects")}>
|
||||
<Icon
|
||||
name={servers.current(server.conn) ? "monitor" : "server"}
|
||||
size="small"
|
||||
class="shrink-0 text-v2-icon-icon-faint"
|
||||
/>
|
||||
<span class="min-w-0 truncate">{servers.label(server.conn)}</span>
|
||||
</Show>
|
||||
<Show when={!several() && index() === 0 && servers.tag(server.conn)}>
|
||||
{(name) => <span class="min-w-0 truncate text-v2-text-text-faint">{name()}</span>}
|
||||
</Show>
|
||||
</div>
|
||||
<ProjectList model={props.model} server={server} />
|
||||
</div>
|
||||
)}
|
||||
</For>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function ProjectList(props: { model: StartModel; server: StartServer }) {
|
||||
const language = useLanguage()
|
||||
|
||||
// Projects that share a name, like a repository and its worktrees, are told apart by their parent folder.
|
||||
const repeated = createMemo(() => {
|
||||
const names = props.server.projects.map((item) => displayName(item.project))
|
||||
|
||||
return new Set(names.filter((name, index) => names.indexOf(name) !== index))
|
||||
})
|
||||
|
||||
const parent = (worktree: string) =>
|
||||
worktree
|
||||
.replace(/[/\\]+$/, "")
|
||||
.split(/[/\\]/)
|
||||
.at(-2)
|
||||
|
||||
return (
|
||||
<For each={props.server.projects}>
|
||||
{(item) => (
|
||||
<button
|
||||
type="button"
|
||||
aria-label={language.t("start.projects.newSession", { project: displayName(item.project) })}
|
||||
class="flex h-8 w-full items-center gap-2 rounded-[6px] px-2 text-start text-[13px] leading-4 hover:bg-v2-overlay-simple-overlay-hover focus-visible:bg-v2-overlay-simple-overlay-hover focus-visible:outline-none"
|
||||
onClick={() => props.model.openProject(props.server, item)}
|
||||
>
|
||||
<ProjectAvatar
|
||||
class="shrink-0"
|
||||
fallback={displayName(item.project)}
|
||||
src={getProjectAvatarSource(item.project.id, item.project.icon)}
|
||||
variant={getProjectAvatarVariant(item.project.icon?.color)}
|
||||
generated={getProjectAvatarGenerated(item.project)}
|
||||
/>
|
||||
<Tooltip value={item.project.worktree} placement="left" class="flex min-w-0 flex-1" openDelay={800}>
|
||||
<span class="flex min-w-0 items-baseline gap-1.5">
|
||||
<span class="min-w-0 truncate text-v2-text-text-base">{displayName(item.project)}</span>
|
||||
<Show when={repeated().has(displayName(item.project))}>
|
||||
<span class="min-w-0 shrink-[10] truncate text-[12px] text-v2-text-text-faint">
|
||||
{parent(item.project.worktree)}
|
||||
</span>
|
||||
</Show>
|
||||
</span>
|
||||
</Tooltip>
|
||||
<ProjectCounts waiting={item.waiting} running={item.running} />
|
||||
</button>
|
||||
)}
|
||||
</For>
|
||||
)
|
||||
}
|
||||
|
||||
function ProjectCounts(props: { waiting: number; running: number }) {
|
||||
const language = useLanguage()
|
||||
|
||||
return (
|
||||
<span class="flex shrink-0 items-center gap-2 text-[12px] leading-4 tabular-nums">
|
||||
<Show when={props.waiting}>
|
||||
<Tooltip value={language.plural("start.projects.waiting", props.waiting)} placement="top" class="flex">
|
||||
<span class="text-v2-state-fg-warning">{props.waiting}</span>
|
||||
</Tooltip>
|
||||
</Show>
|
||||
<Show when={props.running}>
|
||||
<Tooltip value={language.plural("start.projects.running", props.running)} placement="top" class="flex">
|
||||
<span class="text-v2-text-text-faint">{props.running}</span>
|
||||
</Tooltip>
|
||||
</Show>
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
function Section(props: { title: string; count?: number; icon: string; action?: JSX.Element; children: JSX.Element }) {
|
||||
return (
|
||||
<section class="flex flex-col gap-1">
|
||||
{/* The icon sits in the rows' 16px avatar column so the label lines up with the session titles. */}
|
||||
<div class="flex h-7 items-center gap-3 px-2 text-[12px] leading-4 font-medium text-v2-text-text-muted">
|
||||
<span class="flex size-4 shrink-0 items-center justify-center">
|
||||
<Icon name={props.icon} size="small" class="text-v2-icon-icon-faint" />
|
||||
</span>
|
||||
<span class="flex items-center gap-1.5">
|
||||
{props.title}
|
||||
<Show when={props.count}>
|
||||
<span class="tabular-nums text-v2-text-text-faint">{props.count}</span>
|
||||
</Show>
|
||||
</span>
|
||||
<Show when={props.action}>
|
||||
<span class="ms-auto flex items-center">{props.action}</span>
|
||||
</Show>
|
||||
</div>
|
||||
<div class="flex flex-col gap-px">{props.children}</div>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
/** Nothing is waiting on you: the one state worth celebrating, so it takes Needs you's place instead of an empty list. */
|
||||
function InboxZero() {
|
||||
const language = useLanguage()
|
||||
|
||||
return (
|
||||
<div data-slot="start-inbox-zero" class="flex h-12 items-center gap-3 rounded-[8px] px-2">
|
||||
<span class="flex size-4 shrink-0 items-center justify-center motion-safe:animate-in motion-safe:zoom-in-50 motion-safe:fade-in motion-safe:duration-300">
|
||||
<Icon name="circle-check" class="text-v2-state-fg-success" />
|
||||
</span>
|
||||
<div class="flex min-w-0 flex-col gap-0.5">
|
||||
<span class="text-[13px] font-medium leading-4 text-v2-text-text-base">{language.t("start.inboxZero")}</span>
|
||||
<span class="text-[12px] leading-4 text-v2-text-text-faint">{language.t("start.inboxZero.description")}</span>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function StartRow(props: { model: StartModel; entry: InboxEntry }) {
|
||||
const language = useLanguage()
|
||||
const inbox = props.model.inbox
|
||||
const loud = () => props.entry.status !== "ready"
|
||||
|
||||
return (
|
||||
<div
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
data-slot="start-row"
|
||||
data-status={props.entry.status}
|
||||
class="group flex h-12 cursor-default items-center gap-3 rounded-[8px] px-2 hover:bg-v2-overlay-simple-overlay-hover focus-visible:bg-v2-overlay-simple-overlay-hover focus-visible:outline-none"
|
||||
onClick={() => inbox.open(props.entry)}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key !== "Enter" && event.key !== " ") return
|
||||
event.preventDefault()
|
||||
inbox.open(props.entry)
|
||||
}}
|
||||
>
|
||||
<SessionAvatar entry={props.entry} />
|
||||
<div class="flex min-w-0 flex-1 flex-col gap-0.5">
|
||||
<span
|
||||
dir="auto"
|
||||
class="min-w-0 truncate text-[13px] leading-4"
|
||||
classList={{ "font-medium text-v2-text-text-base": loud(), "text-v2-text-text-muted": !loud() }}
|
||||
>
|
||||
{sessionTabTitle(props.entry.session.title, language.t("session.tab.session"))}
|
||||
</span>
|
||||
<Meta model={props.model} entry={props.entry} />
|
||||
</div>
|
||||
<div class="flex shrink-0 items-center gap-3 text-[12px] leading-4" onClick={(event) => event.stopPropagation()}>
|
||||
<RowActions model={props.model} entry={props.entry} />
|
||||
<span class="flex w-16 justify-end">
|
||||
<Status model={props.model} entry={props.entry} />
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function RowActions(props: { model: StartModel; entry: InboxEntry }) {
|
||||
const language = useLanguage()
|
||||
const inbox = props.model.inbox
|
||||
|
||||
return (
|
||||
<Switch>
|
||||
<Match when={props.entry.status === "approval"}>
|
||||
<div class="flex items-center gap-1">
|
||||
<Button size="small" variant="contrast" onClick={() => inbox.decide(props.entry, "once")}>
|
||||
{language.t("start.allow")}
|
||||
</Button>
|
||||
<Button size="small" variant="ghost-muted" onClick={() => inbox.decide(props.entry, "reject")}>
|
||||
{language.t("start.deny")}
|
||||
</Button>
|
||||
</div>
|
||||
</Match>
|
||||
<Match when={props.entry.status === "input"}>
|
||||
<Button size="small" variant="neutral" onClick={() => inbox.open(props.entry)}>
|
||||
{language.t("start.answer")}
|
||||
</Button>
|
||||
</Match>
|
||||
<Match when={props.entry.status === "done" || props.entry.status === "failed"}>
|
||||
<Tooltip value={language.t("start.markRead")} placement="top">
|
||||
<IconButton
|
||||
variant="ghost-muted"
|
||||
size="small"
|
||||
class="opacity-0 group-hover:opacity-100 focus-visible:opacity-100"
|
||||
aria-label={language.t("start.markRead")}
|
||||
icon={<Icon name="check" size="small" />}
|
||||
onClick={() => inbox.markViewed(props.entry)}
|
||||
/>
|
||||
</Tooltip>
|
||||
</Match>
|
||||
</Switch>
|
||||
)
|
||||
}
|
||||
|
||||
function Meta(props: { model: StartModel; entry: InboxEntry }) {
|
||||
const language = useLanguage()
|
||||
const servers = useServers()
|
||||
const inbox = props.model.inbox
|
||||
const project = () => props.entry.ctx.projects.forSession(props.entry.session)
|
||||
const branch = () => inbox.branch(props.entry)
|
||||
const permission = () => (props.entry.status === "approval" ? inbox.permission(props.entry) : undefined)
|
||||
const form = () => (props.entry.status === "input" ? inbox.form(props.entry) : undefined)
|
||||
|
||||
return (
|
||||
<span class="flex h-4 min-w-0 items-center gap-2 text-[12px] leading-4 text-v2-text-text-faint">
|
||||
{/* Sessions on this computer are not marked. */}
|
||||
<Show when={servers.tag(props.entry.conn)}>
|
||||
{(name) => (
|
||||
<span class="flex min-w-0 shrink items-center gap-1">
|
||||
<Icon name="server" size="small" class="shrink-0" />
|
||||
<span class="min-w-0 truncate">{name()}</span>
|
||||
</span>
|
||||
)}
|
||||
</Show>
|
||||
<span class="shrink-0">{displayName(project() ?? { worktree: props.entry.session.location.directory })}</span>
|
||||
<Show when={branch()}>
|
||||
{(name) => (
|
||||
<span class="flex min-w-0 shrink items-center gap-1">
|
||||
<Icon name={inbox.inWorktree(props.entry) ? "outline-worktree" : "branch"} size="small" class="shrink-0" />
|
||||
<span dir="ltr" class="min-w-0 truncate">
|
||||
{name()}
|
||||
</span>
|
||||
</span>
|
||||
)}
|
||||
</Show>
|
||||
<Show when={permission()}>
|
||||
{(request) => (
|
||||
<span class="flex min-w-0 items-center gap-1.5">
|
||||
<Icon name="shield" size="small" class="shrink-0" />
|
||||
<span class="min-w-0 truncate font-mono">{request().resources.join(" ") || request().action}</span>
|
||||
</span>
|
||||
)}
|
||||
</Show>
|
||||
<Show when={form()}>
|
||||
{(request) => (
|
||||
<span class="flex min-w-0 items-center gap-1.5">
|
||||
<Icon name="speech-bubble" size="small" class="shrink-0" />
|
||||
<span class="min-w-0 truncate">{request().title || language.t("start.question")}</span>
|
||||
</span>
|
||||
)}
|
||||
</Show>
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
function Status(props: { model: StartModel; entry: InboxEntry }) {
|
||||
const language = useLanguage()
|
||||
const now = props.model.inbox.now
|
||||
const status = () => props.entry.status
|
||||
|
||||
return (
|
||||
<Switch>
|
||||
<Match when={status() === "working"}>
|
||||
<span class="tabular-nums [&_[data-component=text-shimmer]]:[--text-shimmer-base-color:var(--v2-state-fg-info)]">
|
||||
<span class="sr-only">{language.t("sidebar.inbox.status.working")}</span>
|
||||
<span aria-hidden="true" class="text-v2-state-fg-info">
|
||||
<TextShimmer text={elapsed(language, now(), props.entry.session.time.updated)} active />
|
||||
</span>
|
||||
</span>
|
||||
</Match>
|
||||
<Match when={status() === "ready"}>
|
||||
<span class="text-v2-text-text-faint tabular-nums">
|
||||
{age(language, now(), props.entry.session.time.idle ?? props.entry.session.time.updated)}
|
||||
</span>
|
||||
</Match>
|
||||
<Match when={true}>
|
||||
<span
|
||||
classList={{
|
||||
"text-v2-state-fg-warning": status() === "approval" || status() === "input",
|
||||
"text-v2-state-fg-danger": status() === "failed",
|
||||
"text-v2-text-text-muted": status() === "done",
|
||||
}}
|
||||
>
|
||||
{
|
||||
// SAFETY: working and ready matched above, so the remaining statuses each have a label.
|
||||
language.t(`sidebar.inbox.status.${status() as "approval" | "input" | "failed" | "done"}`)
|
||||
}
|
||||
</span>
|
||||
</Match>
|
||||
</Switch>
|
||||
)
|
||||
}
|
||||
|
||||
function SessionAvatar(props: { entry: InboxEntry }) {
|
||||
return (
|
||||
<span class="flex size-4 shrink-0 items-center justify-center">
|
||||
<SessionTabAvatarView
|
||||
project={props.entry.ctx.projects.forSession(props.entry.session)}
|
||||
directory={props.entry.session.location.directory}
|
||||
unread={props.entry.status !== "ready" && props.entry.status !== "working"}
|
||||
loading={props.entry.status === "working"}
|
||||
/>
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
function compact(language: Language, seconds: number) {
|
||||
if (seconds < 3600) return language.plural("sidebar.inbox.elapsed.minutes", Math.floor(seconds / 60))
|
||||
|
||||
if (seconds < 86_400) return language.plural("sidebar.inbox.elapsed.hours", Math.floor(seconds / 3600))
|
||||
|
||||
return language.plural("sidebar.inbox.elapsed.days", Math.floor(seconds / 86_400))
|
||||
}
|
||||
|
||||
function elapsed(language: Language, now: number, from: number) {
|
||||
const seconds = Math.max(0, Math.floor((now - from) / 1000))
|
||||
|
||||
return seconds < 60 ? language.plural("sidebar.inbox.elapsed.seconds", seconds) : compact(language, seconds)
|
||||
}
|
||||
|
||||
function age(language: Language, now: number, from: number) {
|
||||
const seconds = Math.max(0, Math.floor((now - from) / 1000))
|
||||
|
||||
return seconds < 60 ? language.t("sidebar.inbox.time.now") : compact(language, seconds)
|
||||
}
|
||||
@@ -731,40 +731,6 @@ export const dict = {
|
||||
"sidebar.inbox.elapsed.days.one": "{{count}}d",
|
||||
"sidebar.inbox.elapsed.days.other": "{{count}}d",
|
||||
"sidebar.inbox.time.now": "now",
|
||||
"start.section.needsYou": "Needs you",
|
||||
"start.section.done": "Done",
|
||||
"start.section.running": "Running",
|
||||
"start.section.earlier": "Earlier",
|
||||
"start.projects": "Projects",
|
||||
"start.projects.waiting.one": "{{count}} waiting",
|
||||
"start.projects.waiting.other": "{{count}} waiting",
|
||||
"start.projects.running.one": "{{count}} running",
|
||||
"start.projects.running.other": "{{count}} running",
|
||||
"start.projects.newSession": "New session in {{project}}",
|
||||
"start.server.unreachable": "Can't reach {{server}}. Its sessions aren't shown.",
|
||||
"start.server.unauthorized": "{{server}} needs you to sign in again. Its sessions aren't shown.",
|
||||
"start.server.manage": "Manage",
|
||||
"start.allow": "Allow",
|
||||
"start.deny": "Deny",
|
||||
"start.answer": "Answer",
|
||||
"start.markRead": "Mark as read",
|
||||
"start.markAllRead": "Mark all as read",
|
||||
"start.question": "Waiting for your answer",
|
||||
"start.caughtUp": "You're all caught up",
|
||||
"start.inboxZero": "Inbox zero",
|
||||
"start.inboxZero.description": "Nothing is waiting on you right now",
|
||||
"start.greeting.morning": "Good morning",
|
||||
"start.greeting.afternoon": "Good afternoon",
|
||||
"start.greeting.evening": "Good evening",
|
||||
"start.greeting.morning.named": "Good morning, {{name}}",
|
||||
"start.greeting.afternoon.named": "Good afternoon, {{name}}",
|
||||
"start.greeting.evening.named": "Good evening, {{name}}",
|
||||
"start.summary.needsYou.one": "{{count}} session needs you",
|
||||
"start.summary.needsYou.other": "{{count}} sessions need you",
|
||||
"start.summary.running.one": "{{count}} running",
|
||||
"start.summary.running.other": "{{count}} running",
|
||||
"start.summary.done.one": "{{count}} finished",
|
||||
"start.summary.done.other": "{{count}} finished",
|
||||
"sidebar.project.recentSessions": "Recent sessions",
|
||||
"sidebar.project.clearNotifications": "Clear notifications",
|
||||
|
||||
|
||||
@@ -10,8 +10,6 @@ export type ServerHealth = {
|
||||
version?: string
|
||||
/** The server machine's name, when the server reports one. */
|
||||
hostname?: string
|
||||
/** The OS account the server runs as, when the server reports one. */
|
||||
username?: string
|
||||
incompatible?: boolean
|
||||
checking?: boolean
|
||||
unauthorized?: boolean
|
||||
@@ -127,7 +125,7 @@ export async function checkServerHealth(
|
||||
})
|
||||
.server.info({ signal })
|
||||
.then((status) => ({
|
||||
data: { healthy: true as const, version: status.version, hostname: status.hostname, username: status.username },
|
||||
data: { healthy: true as const, version: status.version, hostname: status.hostname },
|
||||
}))
|
||||
.catch((error) => ({ error }))
|
||||
|
||||
|
||||
Generated
-1
@@ -47,7 +47,6 @@ export type ServerInfoOutput = {
|
||||
readonly version: string
|
||||
readonly pid: number
|
||||
readonly hostname?: string | undefined
|
||||
readonly username?: string | undefined
|
||||
readonly urls: ReadonlyArray<string>
|
||||
readonly paths: { readonly tmp: string }
|
||||
readonly capabilities?: { readonly persistentPty?: boolean | undefined } | undefined
|
||||
|
||||
-1
@@ -4,7 +4,6 @@ export type ServerInfo = {
|
||||
version: string
|
||||
pid: number
|
||||
hostname?: string | undefined
|
||||
username?: string | undefined
|
||||
urls: Array<string>
|
||||
paths: { tmp: string }
|
||||
capabilities?: { persistentPty?: boolean | undefined } | undefined
|
||||
|
||||
Generated
-10
@@ -19157,16 +19157,6 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"username": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
},
|
||||
"urls": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
|
||||
@@ -8,8 +8,6 @@ export const ServerInfo = Schema.Struct({
|
||||
pid: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
|
||||
// The machine's name, absent where the runtime has none (e.g. workerd).
|
||||
hostname: Schema.optional(Schema.String),
|
||||
// The OS account the server runs as, absent where the runtime has none (e.g. workerd).
|
||||
username: Schema.optional(Schema.String),
|
||||
urls: Schema.Array(Schema.String),
|
||||
paths: Schema.Struct({
|
||||
tmp: Schema.String,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { hostname, userInfo } from "node:os"
|
||||
import { hostname } from "node:os"
|
||||
import { Duration, Effect } from "effect"
|
||||
import { HttpServerRequest, HttpServerResponse } from "effect/http"
|
||||
import { HttpApiBuilder } from "effect/http-api"
|
||||
@@ -22,7 +22,6 @@ export const ServerHandler = HttpApiBuilder.group(Api, "server.server", (handler
|
||||
version: info.app.version ?? "unknown",
|
||||
pid: process.pid ?? 0,
|
||||
hostname: hostname() || undefined,
|
||||
username: account(),
|
||||
urls: info.urls(),
|
||||
paths: info.paths,
|
||||
capabilities: { persistentPty: PersistentPty.available },
|
||||
@@ -57,12 +56,3 @@ export const ServerHandler = HttpApiBuilder.group(Api, "server.server", (handler
|
||||
)
|
||||
}),
|
||||
)
|
||||
|
||||
// userInfo throws when the process has no account entry, e.g. some containers.
|
||||
function account() {
|
||||
try {
|
||||
return userInfo().username || undefined
|
||||
} catch {
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user