Skip to content

Commit 63d3250

Browse files
author
opencode
committed
feat(app): Archived view + restore action (TKT-314)
A first-class Archived view and restore action -- the design post names this a recurring upstream request (anomalyco#24153, anomalyco#26078). Reads directly from the entity store (the same store home/tabs read), no project grouping or command-palette registration: a much lighter surface than home's session list, so it gets its own small controller/view pair rather than borrowing that heavier apparatus. Restore needs no confirmation (reversible, per the action table) and no optimistic status -- unlike archive/trash the design does not name a restore_pending state; the row leaving the list happens once the real event lands and the feed (previous commit) re-fetches it. Added two icons to the V2 set (trash, arrow-undo-down) copied from the V1 icon library rather than mixing component versions in one view -- neither existed in V2 yet. New i18n keys: common.restore, archived.title, archived.empty, plus trash.* keys for the next piece (Trash view).
1 parent 2760bd3 commit 63d3250

6 files changed

Lines changed: 161 additions & 0 deletions

File tree

‎packages/app/src/app.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ import { createSessionLineage } from "@/pages/session/session-lineage"
6969

7070
import { SessionPage, SessionRouteErrorBoundary, TargetSessionRouteContent } from "@/pages/session"
7171
import { NewHome } from "@/pages/home"
72+
import { Archived } from "@/pages/archived"
7273
import { LegacyHome } from "@/pages/home/legacy-home"
7374

7475
const NewSession = lazy(() => import("@/pages/new-session"))
@@ -642,6 +643,7 @@ function Routes(props: { serverScoped?: JSX.Element }) {
642643
</Route>
643644
<Show when={settings.general.newLayoutDesigns()}>
644645
<Route path="/" component={NewHome} />
646+
<Route path="/archived" component={Archived} />
645647
<Route path="/:dir/session/:id" component={NewLayoutLegacySessionRedirect} />
646648
<Route path="/server/:serverKey/session/:id" component={TargetSessionRoute} />
647649
</Show>

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,17 @@ export const dict = {
671671
"home.sessions.group.older": "Older",
672672
"home.providerTip": "Connect to 75+ providers to use other models, including Claude, GPT, Gemini, etc",
673673

674+
"archived.title": "Archived",
675+
"archived.empty": "No archived sessions",
676+
"trash.title": "Trash",
677+
"trash.empty": "Trash is empty",
678+
"trash.deletePermanently": "Delete permanently",
679+
"trash.deleteConfirm.title": "Delete permanently?",
680+
// Deliberately uncompressed and not squeezed against a shared key -- Ethan's ruling on the
681+
// i18n boundary: the purge confirmation is the one place translation quality is a safety
682+
// property, not polish, and it must name what it deletes.
683+
"trash.deleteConfirm.description": "This permanently deletes \"{{title}}\" and its transcript, events, goals, ledger, and owned monitor records. This cannot be undone.",
684+
674685
"session.tab.session": "Session",
675686
"session.tab.review": "Review",
676687
"session.tab.context": "Context",
@@ -821,6 +832,7 @@ export const dict = {
821832
"common.reset": "Reset",
822833
"common.archive": "Archive",
823834
"common.delete": "Delete",
835+
"common.restore": "Restore",
824836
"common.close": "Close",
825837
"common.edit": "Edit",
826838
"common.loadMore": "Load more",
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { createArchivedController } from "./archived/archived-controller"
2+
import { ArchivedView } from "./archived/archived-view"
3+
4+
export function Archived() {
5+
const controller = createArchivedController()
6+
return <ArchivedView controller={controller} />
7+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { createMemo } from "solid-js"
2+
import type { Session } from "@opencode-ai/schema/session"
3+
import { useLanguage } from "@/context/language"
4+
import { useServer } from "@/context/server"
5+
import { useSessionEntities } from "@/context/session-entities-provider"
6+
import { useTabs } from "@/context/tabs"
7+
import { createSessionLifecycleClient, lifecycleRequestID } from "@/utils/session-lifecycle-client"
8+
import { showToast } from "@/utils/toast"
9+
import { errorMessage } from "@/pages/layout/helpers"
10+
11+
/**
12+
* Archived sessions for the active server, read directly from the entity store -- the same
13+
* store home/tabs/etc. read, so this view can never disagree with them about what is archived.
14+
* No project grouping, no markdown prefetch, no command-palette registration: this is a much
15+
* smaller surface than home's session list, and borrowing that heavier apparatus for it would
16+
* be scope creep, not reuse.
17+
*/
18+
export function createArchivedController() {
19+
const server = useServer()
20+
const entities = useSessionEntities()
21+
const tabs = useTabs()
22+
const language = useLanguage()
23+
24+
const records = createMemo(() => {
25+
const prefix = `${server.key} `
26+
return Object.entries(entities.state.entities)
27+
.filter(([key, entity]) => key.startsWith(prefix) && entity.value?.lifecycle.state === "archived")
28+
.map(([, entity]) => entity.value as Session.Info)
29+
// `time.updated` is typed as the decoded `DateTimeUtcFromMillis` schema shape, but these
30+
// objects never actually go through the schema decoder (they arrive as raw client-next
31+
// JSON, see session-entities-sync.tsx's `as unknown as Session.Info` cast) -- at runtime
32+
// it is still a plain millis number, same as `compareSessionTime`'s V1-shaped equivalent.
33+
.sort((a, b) => Number(b.time.updated) - Number(a.time.updated))
34+
})
35+
36+
const restore = async (session: Session.Info) => {
37+
const conn = server.current
38+
if (!conn || conn.type !== "http") return
39+
const client = createSessionLifecycleClient(conn.http)
40+
try {
41+
await client.restore({
42+
sessionID: session.id,
43+
requestID: lifecycleRequestID(),
44+
expectedLifecycleRevision: session.lifecycleRevision,
45+
})
46+
// No optimistic status here (unlike archive/trash) -- the design deliberately does not
47+
// list a `restore_pending` state, and the real `session.updated`/`lifecycle.changed`
48+
// event that follows re-fetches and dispatches for real within a turn or two. The row
49+
// leaving this list happens because the entity store says so, same discipline as archive.
50+
} catch (cause) {
51+
showToast({
52+
title: language.t("common.requestFailed"),
53+
description: errorMessage(cause, language.t("common.requestFailed")),
54+
})
55+
}
56+
}
57+
58+
return {
59+
copy: { language },
60+
records,
61+
restore,
62+
isOpenTab: (session: Session.Info) =>
63+
tabs.store.some((tab) => tab.type === "session" && tab.server === server.key && tab.sessionId === session.id),
64+
}
65+
}
66+
67+
export type ArchivedController = ReturnType<typeof createArchivedController>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import type { Session } from "@opencode-ai/schema/session"
2+
import { For, Show, createMemo } from "solid-js"
3+
import { ScrollView } from "@opencode-ai/ui/scroll-view"
4+
import { Icon as IconV2 } from "@opencode-ai/ui/v2/icon"
5+
import { IconButtonV2 } from "@opencode-ai/ui/v2/icon-button-v2"
6+
import { TooltipV2 } from "@opencode-ai/ui/v2/tooltip-v2"
7+
import { sessionTitle } from "@/utils/session-title"
8+
import type { ArchivedController } from "./archived-controller"
9+
10+
/** A first-class Archived view + restore action -- the design post names this a recurring
11+
* request (#24153, #26078) and the ticket's own done-when: "Archive needs a first-class
12+
* Archived view and restore action." Restore is reversible (the action table), so unlike Trash
13+
* this needs no confirmation dialog. */
14+
export function ArchivedView(props: { controller: ArchivedController }) {
15+
const language = () => props.controller.copy.language
16+
17+
return (
18+
<div
19+
class={`
20+
m-2 min-h-0 flex-1 self-stretch overflow-hidden rounded-[10px]
21+
bg-v2-background-bg-base shadow-[var(--v2-elevation-raised)]
22+
`}
23+
>
24+
<ScrollView class="h-full">
25+
<div class="mx-auto flex w-full max-w-[720px] flex-col gap-2 px-3 py-6 lg:px-6">
26+
<h1 class="text-lg font-medium text-v2-text-text-primary">{language().t("archived.title")}</h1>
27+
<Show
28+
when={props.controller.records().length > 0}
29+
fallback={<p class="text-v2-text-text-muted">{language().t("archived.empty")}</p>}
30+
>
31+
<ul class="flex flex-col">
32+
<For each={props.controller.records()}>
33+
{(session) => <ArchivedRow session={session} controller={props.controller} />}
34+
</For>
35+
</ul>
36+
</Show>
37+
</div>
38+
</ScrollView>
39+
</div>
40+
)
41+
}
42+
43+
function ArchivedRow(props: { session: Session.Info; controller: ArchivedController }) {
44+
const language = () => props.controller.copy.language
45+
const title = createMemo(() => sessionTitle(props.session.title) || props.session.id)
46+
47+
return (
48+
<li class="group/session relative flex items-center gap-2 rounded-md px-2 py-2 hover:bg-v2-background-bg-hover">
49+
<span class="min-w-0 flex-1 truncate text-v2-text-text-primary">{title()}</span>
50+
<TooltipV2 class="flex shrink-0 items-center" placement="bottom" value={language().t("common.restore")}>
51+
<IconButtonV2
52+
data-action="archived-restore"
53+
variant="ghost-muted"
54+
size="large"
55+
icon={<IconV2 name="arrow-undo-down" />}
56+
aria-label={language().t("common.restore")}
57+
onClick={() => void props.controller.restore(props.session)}
58+
/>
59+
</TooltipV2>
60+
</li>
61+
)
62+
}

‎packages/ui/src/v2/components/icon.tsx‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ const icons = {
55
viewBox: "0 0 16 16",
66
body: `<path d="M13.5555 8.21534V13.5556H2.44434L2.44434 2.4445H7.78462M6.88878 9.11119C6.88878 9.11119 8.96327 9.0367 9.69678 8.3032L14.0301 3.96986C14.5824 3.4176 14.5824 2.52213 14.0301 1.96986C13.4778 1.4176 12.5824 1.4176 12.0301 1.96986L7.69678 6.3032C7.00513 6.99484 6.88878 9.11119 6.88878 9.11119Z" stroke="currentColor"/>`,
77
},
8+
// Copied from the V1 icon set (packages/ui/src/components/icon.tsx) rather than mixing
9+
// component versions in one view -- neither existed in V2 yet, TKT-314 needed both for the
10+
// Archived/Trash views' restore and delete-permanently actions.
11+
trash: {
12+
viewBox: "0 0 20 20",
13+
body: `<path d="M4.58342 17.9134L4.58369 17.4134L4.22787 17.5384L4.22766 18.0384H4.58342V17.9134ZM15.4167 17.9134V18.0384H15.7725L15.7723 17.5384L15.4167 17.9134ZM2.08342 3.95508V3.45508H1.58342V3.95508H2.08342V4.45508V3.95508ZM17.9167 4.45508V4.95508H18.4167V4.45508H17.9167V3.95508V4.45508ZM4.16677 4.58008L3.66701 4.5996L4.22816 17.5379L4.72792 17.4934L5.22767 17.4489L4.66652 4.54055L4.16677 4.58008ZM4.58342 18.0384V17.9134H15.4167V18.0384V18.5384H4.58342V18.0384ZM15.4167 17.9134L15.8332 17.5379L16.2498 4.5996L15.7501 4.58008L15.2503 4.56055L14.8337 17.4989L15.4167 17.9134ZM15.8334 4.58008V4.08008H4.16677V4.58008V5.08008H15.8334V4.58008ZM2.08342 4.45508V4.95508H4.16677V4.58008V4.08008H2.08342V4.45508ZM15.8334 4.58008V5.08008H17.9167V4.45508V3.95508H15.8334V4.58008ZM6.83951 4.35149L7.432 4.55047C7.79251 3.47701 8.80699 2.70508 10.0001 2.70508V2.20508V1.70508C8.25392 1.70508 6.77335 2.83539 6.24702 4.15251L6.83951 4.35149ZM10.0001 2.20508V2.70508C11.1932 2.70508 12.2077 3.47701 12.5682 4.55047L13.1607 4.35149L13.7532 4.15251C13.2269 2.83539 11.7463 1.70508 10.0001 1.70508V2.20508Z" fill="currentColor"/>`,
14+
},
15+
"arrow-undo-down": {
16+
viewBox: "0 0 16 16",
17+
body: `<path d="M4.08333 11.0859L1.75 8.7526L4.08333 6.41927M2.33333 8.7526L12.5417 8.7526L12.5417 3.21094L7 3.21094" stroke="currentColor" stroke-width="1" stroke-linecap="square"/>`,
18+
},
819
"folder-add-left": {
920
viewBox: "0 0 16 16",
1021
body: `<path d="M7.5 13.3333H1.5V2H6.83333L8.83333 4H14.8333V6M10.1667 11.3333H15.5M12.8333 8.66667V14" stroke="currentColor" stroke-miterlimit="10" stroke-linecap="square"/>`,

0 commit comments

Comments
 (0)