Skip to content

Commit 2aad9c1

Browse files
committed
feat(es-app): integrate requester agent on decision items (anomalyco#142)
2 parents 2ee7aa7 + e7589cc commit 2aad9c1

6 files changed

Lines changed: 241 additions & 5 deletions

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { expect, test } from "bun:test"
2+
import type { AttentionRecord } from "./attention"
3+
import { requestAgent, type AgentSources } from "./attention-agent"
4+
5+
const record = (overrides: Partial<AttentionRecord> = {}) => ({
6+
id: "att_1", editspace: "workbench-upgrade", revision: 1, status: "open", lane: "batch-orchestrator", kind: "decision",
7+
title: "Pick a worker", context: "", options: [], producer_session: "ses_joiner", origin_session: "ses_joiner",
8+
gate_key: "gate", source_ref: { session_id: "ses_joiner", directory: "/es/lanes/batch-orchestrator" },
9+
decision: null, delivery_state: "not-requested", created_at: 1, updated_at: 1, ...overrides,
10+
}) as AttentionRecord
11+
12+
const sessions: Record<string, { title?: string; directory?: string }> = {
13+
ses_joiner: { title: "Joiner", directory: "/es/lanes/batch-orchestrator" },
14+
ses_tether: { title: "Tether", directory: "/es/lanes/squadron-v2" },
15+
ses_next: { title: "Joiner (2)", directory: "/es/lanes/batch-orchestrator" },
16+
ses_untitled: { title: "New session - 2026-10-22T10:00:00.000Z" },
17+
ses_brief: { title: "Front desk brief" },
18+
}
19+
const lane = (name: string) => JSON.stringify(["workbench-upgrade", name])
20+
const sources = (overrides: Partial<AgentSources> = {}): AgentSources => ({
21+
session: (id) => sessions[id],
22+
handoffs: [],
23+
owners: [{ lane: lane("batch-orchestrator"), owner: "ses_joiner" }, { lane: lane("squadron-v2"), owner: "ses_tether" }],
24+
...overrides,
25+
})
26+
27+
test("names the requesting agent by its session title and links its own directory", () => {
28+
expect(requestAgent(record(), sources())).toEqual({ session: "ses_joiner", label: "Joiner", named: true,
29+
directory: "/es/lanes/batch-orchestrator", lane: "batch-orchestrator" })
30+
})
31+
32+
test("agents sharing one project are told apart by their own sessions", () => {
33+
const tether = record({ id: "att_2", lane: "squadron-v2", origin_session: "ses_tether", producer_session: "ses_tether",
34+
source_ref: { session_id: "ses_tether", directory: "/es/lanes/squadron-v2" } })
35+
expect([requestAgent(record(), sources()).label, requestAgent(tether, sources()).label]).toEqual(["Joiner", "Tether"])
36+
})
37+
38+
test("an unknown or untitled requester falls back to its lane, then to an explicit unknown", () => {
39+
expect(requestAgent(record({ origin_session: "ses_gone", producer_session: "ses_gone" }), sources())).toMatchObject({
40+
session: "ses_gone", label: "batch-orchestrator", named: false })
41+
expect(requestAgent(record({ origin_session: "ses_untitled", producer_session: "ses_untitled" }), sources()).label).toBe("batch-orchestrator")
42+
expect(requestAgent(record({ lane: null, origin_session: "ses_gone", producer_session: "ses_gone" }), sources())).toMatchObject({
43+
label: "Unknown agent", named: false })
44+
})
45+
46+
test("a handed-off requester stays the requester; the verified successor is where answers now go", () => {
47+
const handoffs = [{ lane: lane("batch-orchestrator"), predecessor: "ses_joiner", successor: "ses_next" }]
48+
const owners = [{ lane: lane("batch-orchestrator"), owner: "ses_next" }]
49+
const agent = requestAgent(record(), sources({ handoffs, owners }))
50+
expect(agent.label).toBe("Joiner")
51+
expect(agent.destination).toEqual({ session: "ses_next", label: "Joiner (2)", named: true, directory: "/es/lanes/batch-orchestrator" })
52+
// Lineage that does not reach the current owner is not trusted.
53+
expect(requestAgent(record(), sources({ handoffs, owners: [{ lane: lane("batch-orchestrator"), owner: "ses_other" }] })).destination).toBeUndefined()
54+
// A matching chain in another editspace's lane is not this record's lane.
55+
const elsewhere = [{ lane: JSON.stringify(["other", "batch-orchestrator"]), predecessor: "ses_joiner", successor: "ses_next" }]
56+
expect(requestAgent(record(), sources({ handoffs: elsewhere, owners: [{ lane: elsewhere[0]!.lane, owner: "ses_next" }] })).destination).toBeUndefined()
57+
})
58+
59+
test("a later content author is listed separately and never replaces the requester", () => {
60+
const agent = requestAgent(record({ producer_session: "ses_brief" }), sources())
61+
expect(agent.label).toBe("Joiner")
62+
expect(agent.author).toMatchObject({ session: "ses_brief", label: "Front desk brief" })
63+
})
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/* Which agent asked: an attention record names its requester by the immutable
2+
* `origin_session`, never by whoever prepared a brief for it. A requester that
3+
* has since handed off still asked the question; where an answer goes now is
4+
* shown separately, and only through verified handoff lineage. */
5+
import type { AttentionRecord } from "./attention"
6+
import { successorFor, type Handoff, type LaneOwner } from "./handoffs"
7+
8+
export type AgentRef = { session: string; label: string; named: boolean; directory?: string }
9+
export type RequestAgent = AgentRef & {
10+
lane?: string
11+
/** Latest content author, when another session updated the request. */
12+
author?: AgentRef
13+
/** Current lane owner reached from the requester by verified handoffs, when it is a different session. */
14+
destination?: AgentRef
15+
}
16+
17+
export type AgentSources = {
18+
session: (id: string) => { title?: string; directory?: string } | undefined
19+
/** Dashboard lineage: lane keys are `JSON.stringify([editspace, lane])`. */
20+
handoffs: readonly Handoff[]
21+
owners: readonly LaneOwner[]
22+
}
23+
24+
const DEFAULT_TITLE = /^(New session - |Child session - )\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/
25+
26+
export const requestAgent = (record: AttentionRecord, sources: AgentSources): RequestAgent => {
27+
const lane = record.lane || undefined
28+
const ref = (session: string, directory?: string): AgentRef => {
29+
const known = sources.session(session)
30+
const title = known?.title?.trim()
31+
const named = !!title && !DEFAULT_TITLE.test(title)
32+
// An untitled session is known by its lane, never by a guessed alias.
33+
return { session, label: named ? title! : lane ?? "Unknown agent", named, directory: known?.directory ?? directory }
34+
}
35+
const origin = record.origin_session
36+
const requester = ref(origin, record.source_ref.session_id === origin ? record.source_ref.directory : undefined)
37+
const author = record.producer_session && record.producer_session !== origin
38+
? ref(record.producer_session, record.source_ref.session_id === record.producer_session ? record.source_ref.directory : undefined)
39+
: undefined
40+
const tip = lane ? successorFor(origin, [...sources.handoffs], [...sources.owners]) : undefined
41+
const destination = tip && tip.lane === JSON.stringify([record.editspace, lane]) && tip.successor !== origin
42+
? ref(tip.successor)
43+
: undefined
44+
return { ...requester, lane, ...(author ? { author } : {}), ...(destination ? { destination } : {}) }
45+
}

‎packages/es-app/src/components/attention-decision.tsx‎

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,44 @@ import { ago, sessionHref, useDashboard } from "../state"
66
import { Glyph } from "./icons"
77
import type { BriefResult } from "../desk"
88
import { answerDraftKey, attentionPath, blockedReason, decisionLabel, deliveryLabel, type createAttention, type AttentionRecord } from "../attention"
9+
import { requestAgent, type AgentRef, type RequestAgent } from "../attention-agent"
910

1011
type Attention = ReturnType<typeof createAttention>
12+
13+
/** Resolves a record's requesting agent from the dashboard's loaded session index and lineage; no fetches. */
14+
export const useRequestAgent = () => {
15+
const dashboard = useDashboard()
16+
return (record: AttentionRecord): RequestAgent => requestAgent(record, {
17+
session: id => dashboard.activity.session(id),
18+
handoffs: dashboard.lineage(),
19+
owners: dashboard.lineageOwners(),
20+
})
21+
}
22+
23+
/** The agent's name, linked to its conversation when its directory is known; the session ID stays in the tooltip. */
24+
export const AgentName = (props: { agent: AgentRef; class?: string }) => {
25+
const title = () => props.agent.named ? props.agent.session : `${props.agent.session} · no session title`
26+
return <Show when={props.agent.directory} fallback={<bdi dir="auto" class={props.class} title={title()} data-agent-session={props.agent.session}>{props.agent.label}</bdi>}>
27+
{directory => <A class={props.class} href={sessionHref(props.agent.session, directory())} title={title()} data-agent-session={props.agent.session}><bdi dir="auto">{props.agent.label}</bdi></A>}
28+
</Show>
29+
}
30+
31+
// Requester first, project second. Who updated it and where answers go now are listed only when they differ.
32+
const Requester = (props: { record: AttentionRecord }) => {
33+
const agentFor = useRequestAgent()
34+
const agent = () => agentFor(props.record)
35+
return <>
36+
<span class="attention-requester"><Glyph name={props.record.kind === "blocker" ? "question" : "comment-discussion"} />
37+
<AgentName agent={agent()} class="attention-agent" /><span class="attention-project"> · <bdi dir="auto">{props.record.editspace}</bdi></span></span>
38+
<Show when={agent().author || agent().destination}>
39+
<span class="attention-routing home-source">
40+
<Show when={agent().author}>{author => <>Updated by <AgentName agent={author()} /></>}</Show>
41+
<Show when={agent().author && agent().destination}> · </Show>
42+
<Show when={agent().destination}>{destination => <>Handed off · answers go to <AgentName agent={destination()} /></>}</Show>
43+
</span>
44+
</Show>
45+
</>
46+
}
1147
export type AttentionView = "open" | "answered" | "recorded" | "snoozed" | "history"
1248

1349
export const canWriteAttention = (attention: Attention, record: AttentionRecord) =>
@@ -116,7 +152,7 @@ export const AttentionDecision = (props: { record: AttentionRecord; attention: A
116152
}
117153
createEffect(() => { if (historyOpen() && history()?.version !== historyVersion(props.record)) void loadHistory(props.record) })
118154
return <article class="home-decision" data-attention-id={props.record.id}>
119-
<div class="home-eyebrow"><span><Glyph name={props.record.kind === "blocker" ? "question" : "comment-discussion"} /><bdi dir="auto">{props.record.editspace}</bdi></span><time dateTime={new Date(props.record.created_at).toISOString()}>{ago(props.record.created_at)}</time><A href={sessionHref(props.record.source_ref.session_id, props.record.source_ref.directory)} aria-label="Open source thread">Open thread</A></div>
155+
<div class="home-eyebrow"><Requester record={props.record} /><time dateTime={new Date(props.record.created_at).toISOString()}>{ago(props.record.created_at)}</time><A href={sessionHref(props.record.source_ref.session_id, props.record.source_ref.directory)} aria-label="Open source thread">Open thread</A></div>
120156
<h3><bdi dir="auto">{props.record.title}</bdi></h3>
121157
<Show when={!props.prepared}><p dir="auto">{props.record.context}</p></Show>
122158
{props.brief}

‎packages/es-app/src/pages/desk.css‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
.desk-queue > .desk-background { margin-block: 8px 0; }
9696
.attention-home legend.sr-only { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
9797
.home-options label .home-source { margin-inline-start: 2px; color: var(--green); }
98-
.home-decision .home-eyebrow a { margin-inline-start: auto; font-size: 11px; }
98+
.home-decision .home-eyebrow > a { margin-inline-start: auto; font-size: 11px; }
9999
.desk-brief-ask { color: var(--text); margin-block: 0 6px !important; }
100100
.home-decision .desk-brief { margin-block: 12px 4px; padding-block: 2px; padding-inline: 12px 0; background: none; }
101101
.attention-home details.desk-brief-detail { font-size: 13px; }
@@ -149,3 +149,10 @@
149149
.desk-more > [role=status] { font-size: 11px; }
150150
.desk-brief:focus { outline: none; }
151151
.desk-brief:focus-visible { outline: 2px solid var(--lavender); outline-offset: 2px; }
152+
153+
/* Decision rows and headers lead with the requesting agent; the project is secondary. */
154+
.desk-item-agent[data-named] { color: var(--text); }
155+
.attention-requester { display: inline-flex; align-items: center; gap: 5px; min-inline-size: 0; }
156+
.attention-agent { font-weight: 600; color: var(--text); }
157+
.attention-project { color: var(--overlay1); }
158+
.attention-routing { flex-basis: 100%; }

‎packages/es-app/src/pages/desk.tsx‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { ago, sessionHref, useDashboard } from "../state"
77
import { AppHeader } from "../components/native-header"
88
import { createAttention, type AttentionRecord } from "../attention"
99
import { createHomeRequests, requestPointers } from "../home-requests"
10-
import { AttentionDecision, type AttentionView } from "../components/attention-decision"
10+
import { AttentionDecision, useRequestAgent, type AttentionView } from "../components/attention-decision"
1111
import { DeskAgents } from "../components/desk-agents"
1212
import { HomePermission, type HomeReplyReceipt } from "../components/home-permission"
1313
import { FailureRetry } from "../components/session-failure"
@@ -201,7 +201,7 @@ export default function Desk() {
201201
return <li><button class="desk-item" aria-pressed={selectedKey() === item.key} data-desk-item={item.key} onClick={() => select(item.key)}>
202202
<bdi dir="auto" class="desk-item-title">{item.title}</bdi>
203203
<span class="home-source" classList={{ "desk-item-old": !!item.failure && !(now() - item.failure.time < OLD_FAILURE_MS) }}><span class="desk-item-kind" data-kind={item.kind}>{item.kind}</span>
204-
<Show when={item.failure} fallback={<><Show when={item.project}> · <bdi dir="auto">{item.project}</bdi></Show>
204+
<Show when={item.failure} fallback={<><Show when={item.record}>{record => <> · <RowAgent record={record()} /></>}</Show><Show when={item.project}> · <bdi dir="auto">{item.project}</bdi></Show>
205205
<Show when={now() - item.checked > STALE_MS}> · <span class="home-blocked">checked {ago(item.checked) || "never"}</span></Show></>}>
206206
{failure => <> · {failureLabel(failure())} · <span data-failure-age>{failureAge(failure().time, now())}</span></>}</Show>
207207
<Show when={rowBrief(job())}>{label => <> · {label()}</>}</Show></span>
@@ -222,7 +222,7 @@ export default function Desk() {
222222
<Show when={historyView() !== "ignored" ? historyView() as AttentionView : undefined}>{view => <ul class="desk-items"><For each={records().filter(record => inView(record, view()))} fallback={<li class="home-muted desk-empty">None.</li>}>{record =>
223223
<li><button class="desk-item" aria-pressed={selectedKey() === recordKey(record)} onClick={() => select(recordKey(record))}>
224224
<bdi dir="auto" class="desk-item-title">{record.title}</bdi>
225-
<span class="home-source"><span class="desk-item-kind" data-kind={record.kind}>{record.kind}</span> · <bdi dir="auto">{record.editspace}</bdi><Show when={record.status === "answered"}> · <span classList={{ "home-blocked": record.delivery_state === "blocked" }}>{record.delivery_state}</span></Show></span>
225+
<span class="home-source"><span class="desk-item-kind" data-kind={record.kind}>{record.kind}</span> · <RowAgent record={record} /> · <bdi dir="auto">{record.editspace}</bdi><Show when={record.status === "answered"}> · <span classList={{ "home-blocked": record.delivery_state === "blocked" }}>{record.delivery_state}</span></Show></span>
226226
</button></li>}</For></ul>}</Show>
227227
</details>
228228
<button class="desk-chat-tab" aria-expanded={memoryOpen()} title="Personal notes the desk reads; never used as permission. ~/.local/share/opencode/front-desk/memory.json" onClick={() => setMemoryOpen(!memoryOpen())}>Memory <span class="home-muted" title="Notes">{memory.document().entries.length}</span></button>
@@ -296,6 +296,13 @@ const DeskStart = (props: { desk: ReturnType<typeof createDeskSession>; director
296296
</Show>
297297
</div>
298298

299+
// Rows are buttons, so the agent is named without a link; the selected header links it.
300+
const RowAgent = (props: { record: AttentionRecord }) => {
301+
const agentFor = useRequestAgent()
302+
const agent = () => agentFor(props.record)
303+
return <bdi dir="auto" class="desk-item-agent" data-named={agent().named ? "true" : undefined} title={agent().session}>{agent().label}</bdi>
304+
}
305+
299306
const Canonical = (props: { item: DeskItem; live: boolean; detail: (question: string) => Promise<string | undefined>; attention: ReturnType<typeof createAttention>; requests: ReturnType<typeof createHomeRequests>; now: number; ignoring: boolean; onIgnore: (failure: SessionFailure) => void; onReceipt: (receipt: HomeReplyReceipt) => void }) => {
300307
const dashboard = useDashboard()
301308
// With a complete brief for this exact revision, the brief leads and the producer's text folds away.

0 commit comments

Comments
 (0)