Skip to content

An open-source, faster Devin alternative

TypeScript

web: session status is a required, typed field, shown as a dot and a word in Details

Igor Zalutski via Computerbea640a55c96
diff --git a/web/src/managed-agents/work/Item.tsx b/web/src/managed-agents/work/Item.tsx
index 8f301b7b..c4501bbe 100644
--- a/web/src/managed-agents/work/Item.tsx
+++ b/web/src/managed-agents/work/Item.tsx
@@ -30,6 +30,7 @@ import {
pullLabel,
pullStateWord,
resolveAgainst,
+ sessionStatusWord,
} from './board'
import {
AttentionMark,
@@ -332,7 +333,7 @@ function Details({ item }: { item: Item }) {
{item.sessions.map((s) => (
<li key={s.id} className="flex items-start gap-2">
<span className="flex h-5 w-5 shrink-0 items-center justify-center">
- {s.status ? <StatusDot status={s.status} /> : null}
+ <StatusDot status={s.status} />
</span>
<div className="min-w-0">
<Link
@@ -342,7 +343,9 @@ function Details({ item }: { item: Item }) {
{s.title || 'Untitled session'}
</Link>
<p className="text-muted-foreground text-xs leading-4">
- {[s.ownerName, s.status].filter(Boolean).join(' · ')}
+ {[s.ownerName, sessionStatusWord(s.status)]
+ .filter(Boolean)
+ .join(' · ')}
</p>
</div>
</li>
diff --git a/web/src/managed-agents/work/api.ts b/web/src/managed-agents/work/api.ts
index 1cad0b7a..5fcbdf3f 100644
--- a/web/src/managed-agents/work/api.ts
+++ b/web/src/managed-agents/work/api.ts
@@ -53,13 +53,21 @@ export const AttentionSchema = z.looseObject({
})
export type Attention = z.infer<typeof AttentionSchema>
+export const SessionStatusSchema = z.enum([
+ 'starting',
+ 'running',
+ 'waiting',
+ 'idle',
+ 'suspended',
+])
+export type SessionStatus = z.infer<typeof SessionStatusSchema>
+
const ItemSessionSchema = z.looseObject({
id: z.string(),
title: z.string().nullable(),
ownerName: z.string().nullable(),
- // Not in the contract (3.10 lists id, title, ownerName): the session's
- // lifecycle status, shown when the server sends it. See WORK_WEB_NOTES.md.
- status: z.string().nullable().optional(),
+ // The session's lifecycle status, as the sessions API names it.
+ status: SessionStatusSchema,
})
export type ItemSession = z.infer<typeof ItemSessionSchema>
diff --git a/web/src/managed-agents/work/board.test.ts b/web/src/managed-agents/work/board.test.ts
index 404180f9..c25b4674 100644
--- a/web/src/managed-agents/work/board.test.ts
+++ b/web/src/managed-agents/work/board.test.ts
@@ -10,6 +10,7 @@ import {
readyToClose,
repositoryProblem,
resolveAgainst,
+ sessionStatusWord,
staleDays,
} from './board'
import { makeItem, minutesAgo, NOW } from './fixtures'
@@ -132,6 +133,14 @@ describe('card wording', () => {
expect(staleDays(makeItem({ updatedAt: null }), NOW)).toBeNull()
})
+ it('words a session status the way the sessions screens do', () => {
+ expect(sessionStatusWord('running')).toBe('working')
+ expect(sessionStatusWord('starting')).toBe('starting')
+ expect(sessionStatusWord('waiting')).toBe('waiting for an answer')
+ expect(sessionStatusWord('idle')).toBe('idle')
+ expect(sessionStatusWord('suspended')).toBe('asleep')
+ })
+
it('names a pull request by its number', () => {
expect(
pullLabel({
diff --git a/web/src/managed-agents/work/board.ts b/web/src/managed-agents/work/board.ts
index e401ed2e..a66a3c61 100644
--- a/web/src/managed-agents/work/board.ts
+++ b/web/src/managed-agents/work/board.ts
@@ -1,4 +1,10 @@
-import type { Item, PullRequest, PullState, Repository } from './api'
+import type {
+ Item,
+ PullRequest,
+ PullState,
+ Repository,
+ SessionStatus,
+} from './api'
// How the board lays out what the API returns (ux-spec 4.1). Nothing here
// decides a stage, readiness or attention: those are the item's own fields.
@@ -113,6 +119,20 @@ export function plural(n: number, one: string, many = `${one}s`) {
return `${n} ${n === 1 ? one : many}`
}
+// The sessions screens' words, lower case; "waiting" says what it waits for,
+// because the session may be someone else's.
+const SESSION_STATUS_WORD: Record<SessionStatus, string> = {
+ starting: 'starting',
+ running: 'working',
+ waiting: 'waiting for an answer',
+ idle: 'idle',
+ suspended: 'asleep',
+}
+
+export function sessionStatusWord(status: SessionStatus) {
+ return SESSION_STATUS_WORD[status] ?? status
+}
+
export function pullStateWord(state: PullState) {
return state ?? 'state unknown'
}
diff --git a/web/src/managed-agents/work/screens.test.tsx b/web/src/managed-agents/work/screens.test.tsx
index 19c21ef7..b57f9a08 100644
--- a/web/src/managed-agents/work/screens.test.tsx
+++ b/web/src/managed-agents/work/screens.test.tsx
@@ -344,6 +344,7 @@ describe('item page', () => {
expect(
container.querySelector('a[href="/computer/sessions/cs_1"]')?.textContent,
).toBe('Meter minutes')
+ expect(container.textContent).toContain('Igor · idle')
expect(container.textContent).toContain('#41 Meter')
expect(container.textContent).toContain('merged')
expect(workApi.getHistory).not.toHaveBeenCalled()